xref: /illumos-gate/usr/src/uts/i86pc/sys/psm_common.h (revision ddb365bfc9e868ad24ccdcb0dc91af18b10df082)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_PSM_COMMON_H
27 #define	_SYS_PSM_COMMON_H
28 
29 #include <sys/types.h>
30 #include <sys/param.h>
31 #include <sys/cmn_err.h>
32 #include <sys/acpi/acpi.h>
33 #include <sys/acpica.h>
34 
35 #include <sys/sunddi.h>
36 #include <sys/ddi.h>
37 #include <sys/ddi_impldefs.h>
38 #include <sys/pci.h>
39 #include <sys/debug.h>
40 
41 #ifdef	__cplusplus
42 extern "C" {
43 #endif
44 
45 
46 /* private data used in psm_common */
47 typedef struct acpi_prs_private {
48 	uchar_t		prs_irqflags;
49 	uchar_t		prs_type;
50 } acpi_prs_private_t;
51 
52 
53 typedef struct acpi_psm_lnk {
54 	ACPI_HANDLE	lnkobj;
55 	acpi_prs_private_t acpi_prs_prv;
56 	uchar_t		device_status;
57 } acpi_psm_lnk_t;
58 
59 typedef void (*intr_exit_fn_t)(int prev_ipl, int irq);
60 
61 /*
62  * status definition for device_status (as returned by _STA)
63  */
64 #define	STA_PRESENT	0x1
65 #define	STA_ENABLE	0x2
66 
67 
68 /*
69  * irq_cache_t: Entry for irq cache to map pci bus/dev/ipin or ACPI object
70  * referencing an interrupt link device the configured irq for the device.
71  * It is assumed that the acpi object that references the link device is
72  * the same for all devices that reference the same link device.
73  */
74 typedef struct irq_cache {
75 	uchar_t bus, dev;
76 	uchar_t ipin;
77 	uchar_t irq;
78 	iflag_t flags;
79 	ACPI_HANDLE	lnkobj;
80 } irq_cache_t;
81 
82 
83 typedef struct acpi_irqlist {
84 	acpi_prs_private_t acpi_prs_prv;
85 	iflag_t intr_flags;
86 	uint32_t *irqs;
87 	int num_irqs;
88 	struct acpi_irqlist *next;
89 } acpi_irqlist_t;
90 
91 
92 #define	MAX_ISA_IRQ 15
93 
94 #define	ELCR_PORT1	0x4D0
95 #define	ELCR_PORT2	0x4D1
96 
97 #define	ELCR_LEVEL(elcrval, irq)	(elcrval & (0x1 << irq))
98 #define	ELCR_EDGE(elcrval, irq)		((elcrval & (0x1 << irq)) == 0)
99 
100 
101 #define	ACPI_PSM_SUCCESS	0
102 #define	ACPI_PSM_FAILURE	-1
103 #define	ACPI_PSM_PARTIAL 	-2
104 
105 /* verbose flags definitions */
106 #define	PSM_VERBOSE_IRQ_FLAG			0x00000001
107 #define	PSM_VERBOSE_POWEROFF_FLAG		0x00000002
108 #define	PSM_VERBOSE_POWEROFF_PAUSE_FLAG		0x00000004
109 
110 extern int acpi_psm_init(char *module_name, int verbose_flags);
111 
112 extern void build_reserved_irqlist(uchar_t *reserved_irqs_table);
113 
114 extern int acpi_translate_pci_irq(dev_info_t *dip, int ipin, int *pci_irqp,
115     iflag_t *intr_flagp, acpi_psm_lnk_t *acpipsmlnkp);
116 
117 extern int acpi_set_irq_resource(acpi_psm_lnk_t *acpipsmlnkp, int irq);
118 
119 extern int acpi_get_current_irq_resource(acpi_psm_lnk_t *acpipsmlnkp,
120     int *pci_irqp, iflag_t *intr_flagp);
121 
122 extern int acpi_irqlist_find_irq(acpi_irqlist_t *irqlistp, int irq,
123     iflag_t *intr_flagp);
124 
125 extern void acpi_free_irqlist(acpi_irqlist_t *irqlistp);
126 
127 extern int acpi_get_possible_irq_resources(acpi_psm_lnk_t *acpipsmlnkp,
128     acpi_irqlist_t **irqlistp);
129 
130 extern void acpi_new_irq_cache_ent(int bus, int dev, int ipin, int pci_irq,
131     iflag_t *intr_flagp, acpi_psm_lnk_t *acpipsmlnkp);
132 
133 extern int acpi_get_irq_cache_ent(uchar_t bus, uchar_t dev, int ipin,
134     int *pci_irqp, iflag_t *intr_flagp);
135 
136 extern void acpi_restore_link_devices(void);
137 
138 extern int acpi_poweroff(void);
139 
140 extern void psm_set_elcr(int vecno, int val);
141 extern int psm_get_elcr(int vecno);
142 extern intr_exit_fn_t psm_intr_exit_fn(void);
143 
144 #ifdef	__cplusplus
145 }
146 #endif
147 
148 #endif	/* _SYS_PSM_COMMON_H */
149