xref: /netbsd-src/sys/dev/acpi/acpivar.h (revision 7f21db1c0118155e0dd40b75182e30c589d9f63e)
1 /*	$NetBSD: acpivar.h,v 1.40 2010/01/31 11:26:20 jruoho Exp $	*/
2 
3 /*
4  * Copyright 2001 Wasabi Systems, Inc.
5  * All rights reserved.
6  *
7  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *	This product includes software developed for the NetBSD Project by
20  *	Wasabi Systems, Inc.
21  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22  *    or promote products derived from this software without specific prior
23  *    written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 /*
39  * This file defines the ACPI interface provided to the rest of the
40  * kernel, as well as the autoconfiguration structures for ACPI
41  * support.
42  */
43 
44 #include <sys/bus.h>
45 #include <dev/pci/pcivar.h>
46 #include <dev/isa/isavar.h>
47 
48 #include <dev/acpi/acpica.h>
49 
50 #include <dev/sysmon/sysmonvar.h>
51 
52 /*
53  * acpibus_attach_args:
54  *
55  *	This structure is used to attach the ACPI "bus".
56  */
57 struct acpibus_attach_args {
58 	bus_space_tag_t aa_iot;		/* PCI I/O space tag */
59 	bus_space_tag_t aa_memt;	/* PCI MEM space tag */
60 	pci_chipset_tag_t aa_pc;	/* PCI chipset */
61 	int aa_pciflags;		/* PCI bus flags */
62 	isa_chipset_tag_t aa_ic;	/* ISA chipset */
63 };
64 
65 /*
66  * Types of switches that ACPI understands.
67  */
68 #define	ACPI_SWITCH_POWERBUTTON		0
69 #define	ACPI_SWITCH_SLEEPBUTTON		1
70 #define	ACPI_SWITCH_LID			2
71 #define	ACPI_NSWITCHES			3
72 
73 /*
74  * acpi_devnode:
75  *
76  *	An ACPI device node.
77  */
78 struct acpi_devnode {
79 	TAILQ_ENTRY(acpi_devnode) ad_list;
80 	ACPI_HANDLE	ad_handle;	/* our ACPI handle */
81 	uint32_t	ad_level;	/* ACPI level */
82 	uint32_t	ad_type;	/* ACPI object type */
83 	ACPI_DEVICE_INFO *ad_devinfo;	/* our ACPI device info */
84 	struct acpi_scope *ad_scope;	/* backpointer to scope */
85 	device_t	ad_device;	/* pointer to configured device */
86 	char		ad_name[5];	/* Human-readable device name */
87 };
88 
89 /*
90  * acpi_scope:
91  *
92  *	Description of an ACPI scope.
93  */
94 struct acpi_scope {
95 	TAILQ_ENTRY(acpi_scope) as_list;
96 	const char *as_name;		/* scope name */
97 	/*
98 	 * Device nodes we manage.
99 	 */
100 	TAILQ_HEAD(, acpi_devnode) as_devnodes;
101 };
102 
103 /*
104  * acpi_softc:
105  *
106  *	Software state of the ACPI subsystem.
107  */
108 struct acpi_softc {
109 	device_t sc_dev;		/* base device info */
110 	bus_space_tag_t sc_iot;		/* PCI I/O space tag */
111 	bus_space_tag_t sc_memt;	/* PCI MEM space tag */
112 	pci_chipset_tag_t sc_pc;	/* PCI chipset tag */
113 	int sc_pciflags;		/* PCI bus flags */
114 	int sc_pci_bus;			/* internal PCI fixup */
115 	isa_chipset_tag_t sc_ic;	/* ISA chipset tag */
116 
117 	void *sc_sdhook;		/* shutdown hook */
118 
119 	/*
120 	 * Power switch handlers for fixed-feature buttons.
121 	 */
122 	struct sysmon_pswitch sc_smpsw_power;
123 	struct sysmon_pswitch sc_smpsw_sleep;
124 
125 	/*
126 	 * Sleep state to transition to when a given
127 	 * switch is activated.
128 	 */
129 	int sc_switch_sleep[ACPI_NSWITCHES];
130 
131 	int sc_sleepstate;		/* current sleep state */
132 
133 	int sc_quirks;
134 
135 	/*
136 	 * Scopes we manage.
137 	 */
138 	TAILQ_HEAD(, acpi_scope) sc_scopes;
139 	device_t	sc_apmbus;
140 };
141 
142 /*
143  * acpi_attach_args:
144  *
145  *	Used to attach a device instance to the acpi "bus".
146  */
147 struct acpi_attach_args {
148 	struct acpi_devnode *aa_node;	/* ACPI device node */
149 	bus_space_tag_t aa_iot;		/* PCI I/O space tag */
150 	bus_space_tag_t aa_memt;	/* PCI MEM space tag */
151 	pci_chipset_tag_t aa_pc;	/* PCI chipset tag */
152 	int aa_pciflags;		/* PCI bus flags */
153 	isa_chipset_tag_t aa_ic;	/* ISA chipset */
154 };
155 
156 /*
157  * ACPI resources:
158  *
159  *	acpi_io		I/O ports
160  *	acpi_iorange	I/O port range
161  *	acpi_mem	memory region
162  *	acpi_memrange	memory range
163  *	acpi_irq	Interrupt Request
164  *	acpi_drq	DMA request
165  */
166 
167 struct acpi_io {
168 	SIMPLEQ_ENTRY(acpi_io) ar_list;
169 	int		ar_index;
170 	uint32_t	ar_base;
171 	uint32_t	ar_length;
172 };
173 
174 struct acpi_iorange {
175 	SIMPLEQ_ENTRY(acpi_iorange) ar_list;
176 	int		ar_index;
177 	uint32_t	ar_low;
178 	uint32_t	ar_high;
179 	uint32_t	ar_length;
180 	uint32_t	ar_align;
181 };
182 
183 struct acpi_mem {
184 	SIMPLEQ_ENTRY(acpi_mem) ar_list;
185 	int		ar_index;
186 	uint32_t	ar_base;
187 	uint32_t	ar_length;
188 };
189 
190 struct acpi_memrange {
191 	SIMPLEQ_ENTRY(acpi_memrange) ar_list;
192 	int		ar_index;
193 	uint32_t	ar_low;
194 	uint32_t	ar_high;
195 	uint32_t	ar_length;
196 	uint32_t	ar_align;
197 };
198 
199 struct acpi_irq {
200 	SIMPLEQ_ENTRY(acpi_irq) ar_list;
201 	int		ar_index;
202 	uint32_t	ar_irq;
203 	uint32_t	ar_type;
204 };
205 
206 struct acpi_drq {
207 	SIMPLEQ_ENTRY(acpi_drq) ar_list;
208 	int		ar_index;
209 	uint32_t	ar_drq;
210 };
211 
212 struct acpi_resources {
213 	SIMPLEQ_HEAD(, acpi_io) ar_io;
214 	int ar_nio;
215 
216 	SIMPLEQ_HEAD(, acpi_iorange) ar_iorange;
217 	int ar_niorange;
218 
219 	SIMPLEQ_HEAD(, acpi_mem) ar_mem;
220 	int ar_nmem;
221 
222 	SIMPLEQ_HEAD(, acpi_memrange) ar_memrange;
223 	int ar_nmemrange;
224 
225 	SIMPLEQ_HEAD(, acpi_irq) ar_irq;
226 	int ar_nirq;
227 
228 	SIMPLEQ_HEAD(, acpi_drq) ar_drq;
229 	int ar_ndrq;
230 };
231 
232 /*
233  * acpi_resource_parse_ops:
234  *
235  *	The client of ACPI resources specifies these operations
236  *	when the resources are parsed.
237  */
238 struct acpi_resource_parse_ops {
239 	void	(*init)(device_t, void *, void **);
240 	void	(*fini)(device_t, void *);
241 
242 	void	(*ioport)(device_t, void *, uint32_t, uint32_t);
243 	void	(*iorange)(device_t, void *, uint32_t, uint32_t,
244 		    uint32_t, uint32_t);
245 
246 	void	(*memory)(device_t, void *, uint32_t, uint32_t);
247 	void	(*memrange)(device_t, void *, uint32_t, uint32_t,
248 		    uint32_t, uint32_t);
249 
250 	void	(*irq)(device_t, void *, uint32_t, uint32_t);
251 	void	(*drq)(device_t, void *, uint32_t);
252 
253 	void	(*start_dep)(device_t, void *, int);
254 	void	(*end_dep)(device_t, void *);
255 };
256 
257 extern struct acpi_softc *acpi_softc;
258 extern int acpi_active;
259 
260 extern const struct acpi_resource_parse_ops acpi_resource_parse_ops_default;
261 
262 int		acpi_check(device_t, const char *);
263 int		acpi_probe(void);
264 ACPI_PHYSICAL_ADDRESS	acpi_OsGetRootPointer(void);
265 int		acpi_match_hid(ACPI_DEVICE_INFO *, const char * const *);
266 void		acpi_set_wake_gpe(ACPI_HANDLE);
267 void		acpi_clear_wake_gpe(ACPI_HANDLE);
268 
269 ACPI_STATUS	acpi_eval_integer(ACPI_HANDLE, const char *, ACPI_INTEGER *);
270 ACPI_STATUS	acpi_eval_set_integer(ACPI_HANDLE handle, const char *path,
271 		    ACPI_INTEGER arg);
272 ACPI_STATUS	acpi_eval_string(ACPI_HANDLE, const char *, char **);
273 ACPI_STATUS	acpi_eval_struct(ACPI_HANDLE, const char *, ACPI_BUFFER *);
274 ACPI_STATUS	acpi_eval_reference_handle(ACPI_OBJECT *, ACPI_HANDLE *);
275 
276 ACPI_STATUS	acpi_foreach_package_object(ACPI_OBJECT *,
277 		    ACPI_STATUS (*)(ACPI_OBJECT *, void *), void *);
278 ACPI_STATUS	acpi_get(ACPI_HANDLE, ACPI_BUFFER *,
279 		    ACPI_STATUS (*)(ACPI_HANDLE, ACPI_BUFFER *));
280 const char*	acpi_name(ACPI_HANDLE);
281 
282 ACPI_STATUS	acpi_resource_parse(device_t, ACPI_HANDLE, const char *,
283 		    void *, const struct acpi_resource_parse_ops *);
284 void		acpi_resource_print(device_t, struct acpi_resources *);
285 void		acpi_resource_cleanup(struct acpi_resources *);
286 ACPI_STATUS	acpi_allocate_resources(ACPI_HANDLE);
287 
288 ACPI_STATUS	acpi_pwr_switch_consumer(ACPI_HANDLE, int);
289 
290 void *		acpi_pci_link_devbyhandle(ACPI_HANDLE);
291 void		acpi_pci_link_add_reference(void *, int, int, int, int);
292 int		acpi_pci_link_route_interrupt(void *, int, int *, int *, int *);
293 char *		acpi_pci_link_name(void *);
294 ACPI_HANDLE	acpi_pci_link_handle(void *);
295 void		acpi_pci_link_state(void);
296 void		acpi_pci_link_resume(void);
297 
298 struct acpi_io		*acpi_res_io(struct acpi_resources *, int);
299 struct acpi_iorange	*acpi_res_iorange(struct acpi_resources *, int);
300 struct acpi_mem		*acpi_res_mem(struct acpi_resources *, int);
301 struct acpi_memrange	*acpi_res_memrange(struct acpi_resources *, int);
302 struct acpi_irq		*acpi_res_irq(struct acpi_resources *, int);
303 struct acpi_drq		*acpi_res_drq(struct acpi_resources *, int);
304 
305 /*
306  * power state transition
307  */
308 ACPI_STATUS	acpi_enter_sleep_state(struct acpi_softc *, int);
309 
310 /*
311  * quirk handling
312  */
313 struct acpi_quirk {
314 	const char *aq_tabletype; /* what type of table (FADT, DSDT, etc) */
315 	const char *aq_oemid;	/* compared against the table OemId */
316 	int aq_oemrev;		/* compared against the table OemRev */
317 	int aq_cmpop;		/* how to compare the oemrev number */
318 	const char *aq_tabid;	/* compared against the table TableId */
319 	int aq_quirks;		/* the actual quirks */
320 };
321 
322 #define AQ_GT		0	/* > */
323 #define AQ_LT		1	/* < */
324 #define AQ_GTE		2	/* >= */
325 #define AQ_LTE		3	/* <= */
326 #define AQ_EQ		4	/* == */
327 
328 #define ACPI_QUIRK_BROKEN	0x00000001	/* totally broken */
329 #define ACPI_QUIRK_BADPCI	0x00000002	/* bad PCI hierarchy */
330 #define ACPI_QUIRK_BADBBN	0x00000004	/* _BBN broken */
331 #define ACPI_QUIRK_IRQ0		0x00000008	/* bad 0->2 irq override */
332 
333 int acpi_find_quirks(void);
334 
335 #ifdef ACPI_DEBUG
336 void acpi_debug_init(void);
337 #endif
338