xref: /netbsd-src/sys/dev/acpi/acpivar.h (revision c2f76ff004a2cb67efe5b12d97bd3ef7fe89e18d)
1 /*	$NetBSD: acpivar.h,v 1.67 2011/01/17 15:49:13 jmcneill 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 #ifndef _SYS_DEV_ACPI_ACPIVAR_H
39 #define _SYS_DEV_ACPI_ACPIVAR_H
40 
41 /*
42  * This file defines the ACPI interface provided to the rest of the
43  * kernel, as well as the autoconfiguration structures for ACPI
44  * support.
45  */
46 
47 #include <sys/bus.h>
48 #include <dev/pci/pcivar.h>
49 #include <dev/isa/isavar.h>
50 
51 #include <dev/acpi/acpica.h>
52 #include <dev/acpi/acpi_util.h>
53 
54 #include <dev/sysmon/sysmonvar.h>
55 
56 /*
57  * This structure is used to attach the ACPI "bus".
58  */
59 struct acpibus_attach_args {
60 	bus_space_tag_t		 aa_iot;	/* PCI I/O space tag */
61 	bus_space_tag_t		 aa_memt;	/* PCI MEM space tag */
62 	pci_chipset_tag_t	 aa_pc;		/* PCI chipset */
63 	int			 aa_pciflags;	/* PCI bus flags */
64 	isa_chipset_tag_t	 aa_ic;		/* ISA chipset */
65 };
66 
67 /*
68  * PCI information for ACPI device nodes that correspond to PCI devices.
69  *
70  * Remarks:
71  *
72  *	ap_bus		<= 255
73  *	ap_device	<= 31
74  *	ap_function	<= 7		or	ap_function == 0xFFFF
75  *	ap_downbus	<= 255
76  *
77  * Validity of some fields depends on the value of ap_flags:
78  *
79  *	ap_segment				always valid
80  *	ap_bus, ap_device, ap_function		valid for PCI devices
81  *	ap_downbus				valid for PCI bridges
82  *
83  * The device and function numbers are encoded in the value returned by
84  * _ADR.  A function number of 0xFFFF is used to refer to all the
85  * functions on a PCI device (ACPI 4.0a, p. 200).
86  */
87 struct acpi_pci_info {
88 	uint16_t		 ap_flags;	/* Flags (cf. below) */
89 	uint16_t		 ap_segment;	/* PCI segment group */
90 	uint16_t		 ap_bus;	/* PCI bus */
91 	uint16_t		 ap_device;	/* PCI device */
92 	uint16_t		 ap_function;	/* PCI function */
93 	uint16_t		 ap_downbus;	/* PCI bridge downstream bus */
94 };
95 
96 /*
97  * Flags for PCI information.
98  */
99 #define ACPI_PCI_INFO_DEVICE	__BIT(0)	/* PCI device */
100 #define ACPI_PCI_INFO_BRIDGE	__BIT(1)	/* PCI bridge */
101 
102 /*
103  * An ACPI device node.
104  *
105  * Remarks:
106  *
107  *	ad_device	NULL if no device has attached to the node
108  *	ad_root		never NULL
109  *	ad_parent	only NULL if root of the tree ("\")
110  *	ad_pciinfo	NULL if not a PCI device
111  *	ad_notify	NULL if there is no notify handler
112  *	ad_devinfo	never NULL
113  *	ad_handle	never NULL
114  *
115  * Each ACPI device node is associated with its handle. The function
116  * acpi_get_node() can be used to get the node structure from a handle.
117  */
118 struct acpi_devnode {
119 	device_t		 ad_device;	/* Device */
120 	device_t		 ad_root;	/* Backpointer to acpi_softc */
121 	struct acpi_devnode	*ad_parent;	/* Backpointer to parent */
122 	struct acpi_pci_info	*ad_pciinfo;	/* PCI info */
123 	ACPI_NOTIFY_HANDLER	 ad_notify;	/* Device notify */
124 	ACPI_DEVICE_INFO	*ad_devinfo;	/* Device info */
125 	ACPI_HANDLE		 ad_handle;	/* Device handle */
126 	char			 ad_name[5];	/* Device name */
127 	uint32_t		 ad_flags;	/* Device flags */
128 	uint32_t		 ad_type;	/* Device type */
129 	int			 ad_state;	/* Device power state */
130 	int			 ad_wake;	/* Device wakeup */
131 
132 	SIMPLEQ_ENTRY(acpi_devnode)	ad_list;
133 	SIMPLEQ_ENTRY(acpi_devnode)	ad_child_list;
134 	SIMPLEQ_HEAD(, acpi_devnode)	ad_child_head;
135 };
136 
137 /*
138  * ACPI driver capabilities (ad_flags).
139  */
140 #define ACPI_DEVICE_POWER	__BIT(0)	/* Support for D-states  */
141 #define ACPI_DEVICE_WAKEUP	__BIT(1)	/* Support for wake-up */
142 #define ACPI_DEVICE_EJECT	__BIT(2)	/* Support for "ejection" */
143 #define ACPI_DEVICE_DOCK	__BIT(3)	/* Support for docking */
144 
145 /*
146  * Software state of the ACPI subsystem.
147  */
148 struct acpi_softc {
149 	device_t		 sc_dev;	/* base device info */
150 	device_t		 sc_apmbus;	/* APM pseudo-bus */
151 
152 	device_t		 sc_wdrt;	/* WDRT watchdog */
153 
154 	struct acpi_devnode	*sc_root;	/* root of the device tree */
155 
156 	bus_space_tag_t		 sc_iot;	/* PCI I/O space tag */
157 	bus_space_tag_t		 sc_memt;	/* PCI MEM space tag */
158 	pci_chipset_tag_t	 sc_pc;		/* PCI chipset tag */
159 	int			 sc_pciflags;	/* PCI bus flags */
160 	int			 sc_pci_bus;	/* internal PCI fixup */
161 	isa_chipset_tag_t	 sc_ic;		/* ISA chipset tag */
162 
163 	void			*sc_sdhook;	/* shutdown hook */
164 
165 	int			 sc_quirks;
166 	int			 sc_sleepstate;
167 	int			 sc_sleepstates;
168 
169 	struct sysmon_pswitch	 sc_smpsw_power;
170 	struct sysmon_pswitch	 sc_smpsw_sleep;
171 
172 	SIMPLEQ_HEAD(, acpi_devnode)	ad_head;
173 };
174 
175 /*
176  * acpi_attach_args:
177  *
178  *	Used to attach a device instance to the acpi "bus".
179  */
180 struct acpi_attach_args {
181 	struct acpi_devnode *aa_node;	/* ACPI device node */
182 	bus_space_tag_t aa_iot;		/* PCI I/O space tag */
183 	bus_space_tag_t aa_memt;	/* PCI MEM space tag */
184 	pci_chipset_tag_t aa_pc;	/* PCI chipset tag */
185 	int aa_pciflags;		/* PCI bus flags */
186 	isa_chipset_tag_t aa_ic;	/* ISA chipset */
187 };
188 
189 /*
190  * ACPI resources:
191  *
192  *	acpi_io		I/O ports
193  *	acpi_iorange	I/O port range
194  *	acpi_mem	memory region
195  *	acpi_memrange	memory range
196  *	acpi_irq	Interrupt Request
197  *	acpi_drq	DMA request
198  */
199 struct acpi_io {
200 	SIMPLEQ_ENTRY(acpi_io) ar_list;
201 	int		ar_index;
202 	uint32_t	ar_base;
203 	uint32_t	ar_length;
204 };
205 
206 struct acpi_iorange {
207 	SIMPLEQ_ENTRY(acpi_iorange) ar_list;
208 	int		ar_index;
209 	uint32_t	ar_low;
210 	uint32_t	ar_high;
211 	uint32_t	ar_length;
212 	uint32_t	ar_align;
213 };
214 
215 struct acpi_mem {
216 	SIMPLEQ_ENTRY(acpi_mem) ar_list;
217 	int		ar_index;
218 	uint32_t	ar_base;
219 	uint32_t	ar_length;
220 };
221 
222 struct acpi_memrange {
223 	SIMPLEQ_ENTRY(acpi_memrange) ar_list;
224 	int		ar_index;
225 	uint32_t	ar_low;
226 	uint32_t	ar_high;
227 	uint32_t	ar_length;
228 	uint32_t	ar_align;
229 };
230 
231 struct acpi_irq {
232 	SIMPLEQ_ENTRY(acpi_irq) ar_list;
233 	int		ar_index;
234 	uint32_t	ar_irq;
235 	uint32_t	ar_type;
236 };
237 
238 struct acpi_drq {
239 	SIMPLEQ_ENTRY(acpi_drq) ar_list;
240 	int		ar_index;
241 	uint32_t	ar_drq;
242 };
243 
244 struct acpi_resources {
245 	SIMPLEQ_HEAD(, acpi_io) ar_io;
246 	int ar_nio;
247 
248 	SIMPLEQ_HEAD(, acpi_iorange) ar_iorange;
249 	int ar_niorange;
250 
251 	SIMPLEQ_HEAD(, acpi_mem) ar_mem;
252 	int ar_nmem;
253 
254 	SIMPLEQ_HEAD(, acpi_memrange) ar_memrange;
255 	int ar_nmemrange;
256 
257 	SIMPLEQ_HEAD(, acpi_irq) ar_irq;
258 	int ar_nirq;
259 
260 	SIMPLEQ_HEAD(, acpi_drq) ar_drq;
261 	int ar_ndrq;
262 };
263 
264 /*
265  * acpi_resource_parse_ops:
266  *
267  *	The client of ACPI resources specifies these operations
268  *	when the resources are parsed.
269  */
270 struct acpi_resource_parse_ops {
271 	void	(*init)(device_t, void *, void **);
272 	void	(*fini)(device_t, void *);
273 
274 	void	(*ioport)(device_t, void *, uint32_t, uint32_t);
275 	void	(*iorange)(device_t, void *, uint32_t, uint32_t,
276 		    uint32_t, uint32_t);
277 
278 	void	(*memory)(device_t, void *, uint32_t, uint32_t);
279 	void	(*memrange)(device_t, void *, uint32_t, uint32_t,
280 		    uint32_t, uint32_t);
281 
282 	void	(*irq)(device_t, void *, uint32_t, uint32_t);
283 	void	(*drq)(device_t, void *, uint32_t);
284 
285 	void	(*start_dep)(device_t, void *, int);
286 	void	(*end_dep)(device_t, void *);
287 };
288 
289 extern struct acpi_softc *acpi_softc;
290 extern int acpi_active;
291 
292 extern const struct acpi_resource_parse_ops acpi_resource_parse_ops_default;
293 
294 int		acpi_probe(void);
295 void		acpi_disable(void);
296 int		acpi_check(device_t, const char *);
297 
298 ACPI_PHYSICAL_ADDRESS	acpi_OsGetRootPointer(void);
299 
300 bool		acpi_register_notify(struct acpi_devnode *,
301 				     ACPI_NOTIFY_HANDLER);
302 void		acpi_deregister_notify(struct acpi_devnode *);
303 
304 ACPI_STATUS	acpi_resource_parse(device_t, ACPI_HANDLE, const char *,
305 		    void *, const struct acpi_resource_parse_ops *);
306 void		acpi_resource_print(device_t, struct acpi_resources *);
307 void		acpi_resource_cleanup(struct acpi_resources *);
308 
309 void *		acpi_pci_link_devbyhandle(ACPI_HANDLE);
310 void		acpi_pci_link_add_reference(void *, int, int, int, int);
311 int		acpi_pci_link_route_interrupt(void *, int, int *, int *, int *);
312 char *		acpi_pci_link_name(void *);
313 ACPI_HANDLE	acpi_pci_link_handle(void *);
314 void		acpi_pci_link_state(void);
315 void		acpi_pci_link_resume(void);
316 
317 struct acpi_io		*acpi_res_io(struct acpi_resources *, int);
318 struct acpi_iorange	*acpi_res_iorange(struct acpi_resources *, int);
319 struct acpi_mem		*acpi_res_mem(struct acpi_resources *, int);
320 struct acpi_memrange	*acpi_res_memrange(struct acpi_resources *, int);
321 struct acpi_irq		*acpi_res_irq(struct acpi_resources *, int);
322 struct acpi_drq		*acpi_res_drq(struct acpi_resources *, int);
323 
324 /*
325  * Sleep state transition.
326  */
327 void			acpi_enter_sleep_state(int);
328 
329 /*
330  * MADT.
331  */
332 #define ACPI_PLATFORM_INT_PMI	1
333 #define ACPI_PLATFORM_INT_INIT	2
334 #define ACPI_PLATFORM_INT_CERR	3
335 
336 ACPI_STATUS		acpi_madt_map(void);
337 void			acpi_madt_unmap(void);
338 void			acpi_madt_walk(ACPI_STATUS (*)(ACPI_SUBTABLE_HEADER *,
339 				       void *), void *);
340 
341 /*
342  * Quirk handling.
343  */
344 struct acpi_quirk {
345 	const char *aq_tabletype; /* what type of table (FADT, DSDT, etc) */
346 	const char *aq_oemid;	/* compared against the table OemId */
347 	int aq_oemrev;		/* compared against the table OemRev */
348 	int aq_cmpop;		/* how to compare the oemrev number */
349 	const char *aq_tabid;	/* compared against the table TableId */
350 	int aq_quirks;		/* the actual quirks */
351 };
352 
353 #define ACPI_QUIRK_BROKEN	0x00000001	/* totally broken */
354 #define ACPI_QUIRK_BADPCI	0x00000002	/* bad PCI hierarchy */
355 #define ACPI_QUIRK_BADBBN	0x00000004	/* _BBN broken */
356 #define ACPI_QUIRK_IRQ0		0x00000008	/* bad 0->2 irq override */
357 #define ACPI_QUIRK_OLDBIOS	0x00000010	/* BIOS date blacklisted */
358 
359 int acpi_find_quirks(void);
360 
361 #ifdef ACPI_DEBUG
362 void acpi_debug_init(void);
363 #endif
364 
365 /*
366  * Misc routines with vectors updated by acpiverbose module.
367  */
368 extern void	(*acpi_print_verbose)(struct acpi_softc *);
369 extern void	(*acpi_print_dev)(const char *);
370 
371 void		acpi_load_verbose(void);
372 extern int	acpi_verbose_loaded;
373 
374 #endif	/* !_SYS_DEV_ACPI_ACPIVAR_H */
375