acpivar.h revision 1.66 1 /* $NetBSD: acpivar.h,v 1.66 2011/01/13 05:14:48 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 #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 struct acpi_devnode *sc_root; /* root of the device tree */
153
154 bus_space_tag_t sc_iot; /* PCI I/O space tag */
155 bus_space_tag_t sc_memt; /* PCI MEM space tag */
156 pci_chipset_tag_t sc_pc; /* PCI chipset tag */
157 int sc_pciflags; /* PCI bus flags */
158 int sc_pci_bus; /* internal PCI fixup */
159 isa_chipset_tag_t sc_ic; /* ISA chipset tag */
160
161 void *sc_sdhook; /* shutdown hook */
162
163 int sc_quirks;
164 int sc_sleepstate;
165 int sc_sleepstates;
166
167 struct sysmon_pswitch sc_smpsw_power;
168 struct sysmon_pswitch sc_smpsw_sleep;
169
170 SIMPLEQ_HEAD(, acpi_devnode) ad_head;
171 };
172
173 /*
174 * acpi_attach_args:
175 *
176 * Used to attach a device instance to the acpi "bus".
177 */
178 struct acpi_attach_args {
179 struct acpi_devnode *aa_node; /* ACPI device node */
180 bus_space_tag_t aa_iot; /* PCI I/O space tag */
181 bus_space_tag_t aa_memt; /* PCI MEM space tag */
182 pci_chipset_tag_t aa_pc; /* PCI chipset tag */
183 int aa_pciflags; /* PCI bus flags */
184 isa_chipset_tag_t aa_ic; /* ISA chipset */
185 };
186
187 /*
188 * ACPI resources:
189 *
190 * acpi_io I/O ports
191 * acpi_iorange I/O port range
192 * acpi_mem memory region
193 * acpi_memrange memory range
194 * acpi_irq Interrupt Request
195 * acpi_drq DMA request
196 */
197 struct acpi_io {
198 SIMPLEQ_ENTRY(acpi_io) ar_list;
199 int ar_index;
200 uint32_t ar_base;
201 uint32_t ar_length;
202 };
203
204 struct acpi_iorange {
205 SIMPLEQ_ENTRY(acpi_iorange) ar_list;
206 int ar_index;
207 uint32_t ar_low;
208 uint32_t ar_high;
209 uint32_t ar_length;
210 uint32_t ar_align;
211 };
212
213 struct acpi_mem {
214 SIMPLEQ_ENTRY(acpi_mem) ar_list;
215 int ar_index;
216 uint32_t ar_base;
217 uint32_t ar_length;
218 };
219
220 struct acpi_memrange {
221 SIMPLEQ_ENTRY(acpi_memrange) ar_list;
222 int ar_index;
223 uint32_t ar_low;
224 uint32_t ar_high;
225 uint32_t ar_length;
226 uint32_t ar_align;
227 };
228
229 struct acpi_irq {
230 SIMPLEQ_ENTRY(acpi_irq) ar_list;
231 int ar_index;
232 uint32_t ar_irq;
233 uint32_t ar_type;
234 };
235
236 struct acpi_drq {
237 SIMPLEQ_ENTRY(acpi_drq) ar_list;
238 int ar_index;
239 uint32_t ar_drq;
240 };
241
242 struct acpi_resources {
243 SIMPLEQ_HEAD(, acpi_io) ar_io;
244 int ar_nio;
245
246 SIMPLEQ_HEAD(, acpi_iorange) ar_iorange;
247 int ar_niorange;
248
249 SIMPLEQ_HEAD(, acpi_mem) ar_mem;
250 int ar_nmem;
251
252 SIMPLEQ_HEAD(, acpi_memrange) ar_memrange;
253 int ar_nmemrange;
254
255 SIMPLEQ_HEAD(, acpi_irq) ar_irq;
256 int ar_nirq;
257
258 SIMPLEQ_HEAD(, acpi_drq) ar_drq;
259 int ar_ndrq;
260 };
261
262 /*
263 * acpi_resource_parse_ops:
264 *
265 * The client of ACPI resources specifies these operations
266 * when the resources are parsed.
267 */
268 struct acpi_resource_parse_ops {
269 void (*init)(device_t, void *, void **);
270 void (*fini)(device_t, void *);
271
272 void (*ioport)(device_t, void *, uint32_t, uint32_t);
273 void (*iorange)(device_t, void *, uint32_t, uint32_t,
274 uint32_t, uint32_t);
275
276 void (*memory)(device_t, void *, uint32_t, uint32_t);
277 void (*memrange)(device_t, void *, uint32_t, uint32_t,
278 uint32_t, uint32_t);
279
280 void (*irq)(device_t, void *, uint32_t, uint32_t);
281 void (*drq)(device_t, void *, uint32_t);
282
283 void (*start_dep)(device_t, void *, int);
284 void (*end_dep)(device_t, void *);
285 };
286
287 extern struct acpi_softc *acpi_softc;
288 extern int acpi_active;
289
290 extern const struct acpi_resource_parse_ops acpi_resource_parse_ops_default;
291
292 int acpi_probe(void);
293 void acpi_disable(void);
294 int acpi_check(device_t, const char *);
295
296 ACPI_PHYSICAL_ADDRESS acpi_OsGetRootPointer(void);
297
298 bool acpi_register_notify(struct acpi_devnode *,
299 ACPI_NOTIFY_HANDLER);
300 void acpi_deregister_notify(struct acpi_devnode *);
301
302 ACPI_STATUS acpi_resource_parse(device_t, ACPI_HANDLE, const char *,
303 void *, const struct acpi_resource_parse_ops *);
304 void acpi_resource_print(device_t, struct acpi_resources *);
305 void acpi_resource_cleanup(struct acpi_resources *);
306
307 void * acpi_pci_link_devbyhandle(ACPI_HANDLE);
308 void acpi_pci_link_add_reference(void *, int, int, int, int);
309 int acpi_pci_link_route_interrupt(void *, int, int *, int *, int *);
310 char * acpi_pci_link_name(void *);
311 ACPI_HANDLE acpi_pci_link_handle(void *);
312 void acpi_pci_link_state(void);
313 void acpi_pci_link_resume(void);
314
315 struct acpi_io *acpi_res_io(struct acpi_resources *, int);
316 struct acpi_iorange *acpi_res_iorange(struct acpi_resources *, int);
317 struct acpi_mem *acpi_res_mem(struct acpi_resources *, int);
318 struct acpi_memrange *acpi_res_memrange(struct acpi_resources *, int);
319 struct acpi_irq *acpi_res_irq(struct acpi_resources *, int);
320 struct acpi_drq *acpi_res_drq(struct acpi_resources *, int);
321
322 /*
323 * Sleep state transition.
324 */
325 void acpi_enter_sleep_state(int);
326
327 /*
328 * MADT.
329 */
330 #define ACPI_PLATFORM_INT_PMI 1
331 #define ACPI_PLATFORM_INT_INIT 2
332 #define ACPI_PLATFORM_INT_CERR 3
333
334 ACPI_STATUS acpi_madt_map(void);
335 void acpi_madt_unmap(void);
336 void acpi_madt_walk(ACPI_STATUS (*)(ACPI_SUBTABLE_HEADER *,
337 void *), void *);
338
339 /*
340 * Quirk handling.
341 */
342 struct acpi_quirk {
343 const char *aq_tabletype; /* what type of table (FADT, DSDT, etc) */
344 const char *aq_oemid; /* compared against the table OemId */
345 int aq_oemrev; /* compared against the table OemRev */
346 int aq_cmpop; /* how to compare the oemrev number */
347 const char *aq_tabid; /* compared against the table TableId */
348 int aq_quirks; /* the actual quirks */
349 };
350
351 #define ACPI_QUIRK_BROKEN 0x00000001 /* totally broken */
352 #define ACPI_QUIRK_BADPCI 0x00000002 /* bad PCI hierarchy */
353 #define ACPI_QUIRK_BADBBN 0x00000004 /* _BBN broken */
354 #define ACPI_QUIRK_IRQ0 0x00000008 /* bad 0->2 irq override */
355 #define ACPI_QUIRK_OLDBIOS 0x00000010 /* BIOS date blacklisted */
356
357 int acpi_find_quirks(void);
358
359 #ifdef ACPI_DEBUG
360 void acpi_debug_init(void);
361 #endif
362
363 /*
364 * Misc routines with vectors updated by acpiverbose module.
365 */
366 extern void (*acpi_print_verbose)(struct acpi_softc *);
367 extern void (*acpi_print_dev)(const char *);
368
369 void acpi_load_verbose(void);
370 extern int acpi_verbose_loaded;
371
372 #endif /* !_SYS_DEV_ACPI_ACPIVAR_H */
373