acpivar.h revision 1.48 1 /* $NetBSD: acpivar.h,v 1.48 2010/04/15 07:02:24 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 * ACPI driver capabilities.
69 */
70 #define ACPI_DEVICE_POWER __BIT(0)
71 #define ACPI_DEVICE_WAKEUP __BIT(1)
72
73 /*
74 * An ACPI device node.
75 *
76 * Note that this is available for all nodes, meaning that e.g.
77 * the device_t (ad_device) may be NULL for unattached devices.
78 */
79 struct acpi_devnode {
80 device_t ad_device; /* Device */
81 device_t ad_parent; /* Backpointer to the parent */
82 ACPI_NOTIFY_HANDLER ad_notify; /* Device notify */
83 ACPI_DEVICE_INFO *ad_devinfo; /* Device info */
84 ACPI_HANDLE ad_handle; /* Device handle */
85 char ad_name[5]; /* Device name */
86 uint32_t ad_flags; /* Device flags */
87 uint32_t ad_type; /* Device type */
88 int ad_wake; /* Device wakeup */
89
90 SIMPLEQ_ENTRY(acpi_devnode) ad_list;
91 };
92
93 /*
94 * Software state of the ACPI subsystem.
95 */
96 struct acpi_softc {
97 device_t sc_dev; /* base device info */
98 bus_space_tag_t sc_iot; /* PCI I/O space tag */
99 bus_space_tag_t sc_memt; /* PCI MEM space tag */
100 pci_chipset_tag_t sc_pc; /* PCI chipset tag */
101 int sc_pciflags; /* PCI bus flags */
102 int sc_pci_bus; /* internal PCI fixup */
103 isa_chipset_tag_t sc_ic; /* ISA chipset tag */
104
105 void *sc_sdhook; /* shutdown hook */
106
107 /*
108 * Power switch handlers for fixed-feature buttons.
109 */
110 struct sysmon_pswitch sc_smpsw_power;
111 struct sysmon_pswitch sc_smpsw_sleep;
112
113 int sc_sleepstate; /* current sleep state */
114 int sc_sleepstates; /* supported sleep states */
115
116 int sc_quirks;
117
118 device_t sc_apmbus;
119
120 SIMPLEQ_HEAD(, acpi_devnode) sc_devnodes; /* devices */
121 };
122
123 /*
124 * acpi_attach_args:
125 *
126 * Used to attach a device instance to the acpi "bus".
127 */
128 struct acpi_attach_args {
129 struct acpi_devnode *aa_node; /* ACPI device node */
130 bus_space_tag_t aa_iot; /* PCI I/O space tag */
131 bus_space_tag_t aa_memt; /* PCI MEM space tag */
132 pci_chipset_tag_t aa_pc; /* PCI chipset tag */
133 int aa_pciflags; /* PCI bus flags */
134 isa_chipset_tag_t aa_ic; /* ISA chipset */
135 };
136
137 /*
138 * ACPI resources:
139 *
140 * acpi_io I/O ports
141 * acpi_iorange I/O port range
142 * acpi_mem memory region
143 * acpi_memrange memory range
144 * acpi_irq Interrupt Request
145 * acpi_drq DMA request
146 */
147
148 struct acpi_io {
149 SIMPLEQ_ENTRY(acpi_io) ar_list;
150 int ar_index;
151 uint32_t ar_base;
152 uint32_t ar_length;
153 };
154
155 struct acpi_iorange {
156 SIMPLEQ_ENTRY(acpi_iorange) ar_list;
157 int ar_index;
158 uint32_t ar_low;
159 uint32_t ar_high;
160 uint32_t ar_length;
161 uint32_t ar_align;
162 };
163
164 struct acpi_mem {
165 SIMPLEQ_ENTRY(acpi_mem) ar_list;
166 int ar_index;
167 uint32_t ar_base;
168 uint32_t ar_length;
169 };
170
171 struct acpi_memrange {
172 SIMPLEQ_ENTRY(acpi_memrange) ar_list;
173 int ar_index;
174 uint32_t ar_low;
175 uint32_t ar_high;
176 uint32_t ar_length;
177 uint32_t ar_align;
178 };
179
180 struct acpi_irq {
181 SIMPLEQ_ENTRY(acpi_irq) ar_list;
182 int ar_index;
183 uint32_t ar_irq;
184 uint32_t ar_type;
185 };
186
187 struct acpi_drq {
188 SIMPLEQ_ENTRY(acpi_drq) ar_list;
189 int ar_index;
190 uint32_t ar_drq;
191 };
192
193 struct acpi_resources {
194 SIMPLEQ_HEAD(, acpi_io) ar_io;
195 int ar_nio;
196
197 SIMPLEQ_HEAD(, acpi_iorange) ar_iorange;
198 int ar_niorange;
199
200 SIMPLEQ_HEAD(, acpi_mem) ar_mem;
201 int ar_nmem;
202
203 SIMPLEQ_HEAD(, acpi_memrange) ar_memrange;
204 int ar_nmemrange;
205
206 SIMPLEQ_HEAD(, acpi_irq) ar_irq;
207 int ar_nirq;
208
209 SIMPLEQ_HEAD(, acpi_drq) ar_drq;
210 int ar_ndrq;
211 };
212
213 /*
214 * acpi_resource_parse_ops:
215 *
216 * The client of ACPI resources specifies these operations
217 * when the resources are parsed.
218 */
219 struct acpi_resource_parse_ops {
220 void (*init)(device_t, void *, void **);
221 void (*fini)(device_t, void *);
222
223 void (*ioport)(device_t, void *, uint32_t, uint32_t);
224 void (*iorange)(device_t, void *, uint32_t, uint32_t,
225 uint32_t, uint32_t);
226
227 void (*memory)(device_t, void *, uint32_t, uint32_t);
228 void (*memrange)(device_t, void *, uint32_t, uint32_t,
229 uint32_t, uint32_t);
230
231 void (*irq)(device_t, void *, uint32_t, uint32_t);
232 void (*drq)(device_t, void *, uint32_t);
233
234 void (*start_dep)(device_t, void *, int);
235 void (*end_dep)(device_t, void *);
236 };
237
238 extern struct acpi_softc *acpi_softc;
239 extern int acpi_active;
240
241 extern const struct acpi_resource_parse_ops acpi_resource_parse_ops_default;
242
243 int acpi_probe(void);
244 int acpi_check(device_t, const char *);
245
246 ACPI_PHYSICAL_ADDRESS acpi_OsGetRootPointer(void);
247
248 bool acpi_register_notify(struct acpi_devnode *,
249 ACPI_NOTIFY_HANDLER);
250 void acpi_deregister_notify(struct acpi_devnode *);
251
252 ACPI_STATUS acpi_resource_parse(device_t, ACPI_HANDLE, const char *,
253 void *, const struct acpi_resource_parse_ops *);
254 void acpi_resource_print(device_t, struct acpi_resources *);
255 void acpi_resource_cleanup(struct acpi_resources *);
256
257 ACPI_STATUS acpi_pwr_switch_consumer(ACPI_HANDLE, int);
258
259 void * acpi_pci_link_devbyhandle(ACPI_HANDLE);
260 void acpi_pci_link_add_reference(void *, int, int, int, int);
261 int acpi_pci_link_route_interrupt(void *, int, int *, int *, int *);
262 char * acpi_pci_link_name(void *);
263 ACPI_HANDLE acpi_pci_link_handle(void *);
264 void acpi_pci_link_state(void);
265 void acpi_pci_link_resume(void);
266
267 struct acpi_io *acpi_res_io(struct acpi_resources *, int);
268 struct acpi_iorange *acpi_res_iorange(struct acpi_resources *, int);
269 struct acpi_mem *acpi_res_mem(struct acpi_resources *, int);
270 struct acpi_memrange *acpi_res_memrange(struct acpi_resources *, int);
271 struct acpi_irq *acpi_res_irq(struct acpi_resources *, int);
272 struct acpi_drq *acpi_res_drq(struct acpi_resources *, int);
273
274 /*
275 * Sleep state transition.
276 */
277 ACPI_STATUS acpi_enter_sleep_state(struct acpi_softc *, int);
278
279 /*
280 * Quirk handling.
281 */
282 struct acpi_quirk {
283 const char *aq_tabletype; /* what type of table (FADT, DSDT, etc) */
284 const char *aq_oemid; /* compared against the table OemId */
285 int aq_oemrev; /* compared against the table OemRev */
286 int aq_cmpop; /* how to compare the oemrev number */
287 const char *aq_tabid; /* compared against the table TableId */
288 int aq_quirks; /* the actual quirks */
289 };
290
291 #define ACPI_QUIRK_BROKEN 0x00000001 /* totally broken */
292 #define ACPI_QUIRK_BADPCI 0x00000002 /* bad PCI hierarchy */
293 #define ACPI_QUIRK_BADBBN 0x00000004 /* _BBN broken */
294 #define ACPI_QUIRK_IRQ0 0x00000008 /* bad 0->2 irq override */
295
296 int acpi_find_quirks(void);
297
298 #ifdef ACPI_DEBUG
299 void acpi_debug_init(void);
300 #endif
301
302 #endif /* !_SYS_DEV_ACPI_ACPIVAR_H */
303