| @@ -1,1165 +1,1165 @@ | | | @@ -1,1165 +1,1165 @@ |
1 | /* $NetBSD: acpi.c,v 1.212 2010/08/07 09:41:19 jruoho Exp $ */ | | 1 | /* $NetBSD: acpi.c,v 1.213 2010/08/07 17:12:55 jruoho Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Charles M. Hannum of By Noon Software, Inc. | | 8 | * by Charles M. Hannum of By Noon Software, Inc. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
15 | * 2. Redistributions in binary form must reproduce the above copyright | | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in the | | 16 | * notice, this list of conditions and the following disclaimer in the |
17 | * documentation and/or other materials provided with the distribution. | | 17 | * documentation and/or other materials provided with the distribution. |
18 | * | | 18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | | 19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | /* | | 32 | /* |
33 | * Copyright (c) 2003 Wasabi Systems, Inc. | | 33 | * Copyright (c) 2003 Wasabi Systems, Inc. |
34 | * All rights reserved. | | 34 | * All rights reserved. |
35 | * | | 35 | * |
36 | * Written by Frank van der Linden for Wasabi Systems, Inc. | | 36 | * Written by Frank van der Linden for Wasabi Systems, Inc. |
37 | * | | 37 | * |
38 | * Redistribution and use in source and binary forms, with or without | | 38 | * Redistribution and use in source and binary forms, with or without |
39 | * modification, are permitted provided that the following conditions | | 39 | * modification, are permitted provided that the following conditions |
40 | * are met: | | 40 | * are met: |
41 | * 1. Redistributions of source code must retain the above copyright | | 41 | * 1. Redistributions of source code must retain the above copyright |
42 | * notice, this list of conditions and the following disclaimer. | | 42 | * notice, this list of conditions and the following disclaimer. |
43 | * 2. Redistributions in binary form must reproduce the above copyright | | 43 | * 2. Redistributions in binary form must reproduce the above copyright |
44 | * notice, this list of conditions and the following disclaimer in the | | 44 | * notice, this list of conditions and the following disclaimer in the |
45 | * documentation and/or other materials provided with the distribution. | | 45 | * documentation and/or other materials provided with the distribution. |
46 | * 3. All advertising materials mentioning features or use of this software | | 46 | * 3. All advertising materials mentioning features or use of this software |
47 | * must display the following acknowledgement: | | 47 | * must display the following acknowledgement: |
48 | * This product includes software developed for the NetBSD Project by | | 48 | * This product includes software developed for the NetBSD Project by |
49 | * Wasabi Systems, Inc. | | 49 | * Wasabi Systems, Inc. |
50 | * 4. The name of Wasabi Systems, Inc. may not be used to endorse | | 50 | * 4. The name of Wasabi Systems, Inc. may not be used to endorse |
51 | * or promote products derived from this software without specific prior | | 51 | * or promote products derived from this software without specific prior |
52 | * written permission. | | 52 | * written permission. |
53 | * | | 53 | * |
54 | * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND | | 54 | * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND |
55 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 55 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
56 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 56 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
57 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC | | 57 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC |
58 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 58 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
59 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 59 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
60 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 60 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
61 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 61 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
62 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 62 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
63 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 63 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
64 | * POSSIBILITY OF SUCH DAMAGE. | | 64 | * POSSIBILITY OF SUCH DAMAGE. |
65 | */ | | 65 | */ |
66 | | | 66 | |
67 | /* | | 67 | /* |
68 | * Copyright 2001, 2003 Wasabi Systems, Inc. | | 68 | * Copyright 2001, 2003 Wasabi Systems, Inc. |
69 | * All rights reserved. | | 69 | * All rights reserved. |
70 | * | | 70 | * |
71 | * Written by Jason R. Thorpe for Wasabi Systems, Inc. | | 71 | * Written by Jason R. Thorpe for Wasabi Systems, Inc. |
72 | * | | 72 | * |
73 | * Redistribution and use in source and binary forms, with or without | | 73 | * Redistribution and use in source and binary forms, with or without |
74 | * modification, are permitted provided that the following conditions | | 74 | * modification, are permitted provided that the following conditions |
75 | * are met: | | 75 | * are met: |
76 | * 1. Redistributions of source code must retain the above copyright | | 76 | * 1. Redistributions of source code must retain the above copyright |
77 | * notice, this list of conditions and the following disclaimer. | | 77 | * notice, this list of conditions and the following disclaimer. |
78 | * 2. Redistributions in binary form must reproduce the above copyright | | 78 | * 2. Redistributions in binary form must reproduce the above copyright |
79 | * notice, this list of conditions and the following disclaimer in the | | 79 | * notice, this list of conditions and the following disclaimer in the |
80 | * documentation and/or other materials provided with the distribution. | | 80 | * documentation and/or other materials provided with the distribution. |
81 | * 3. All advertising materials mentioning features or use of this software | | 81 | * 3. All advertising materials mentioning features or use of this software |
82 | * must display the following acknowledgement: | | 82 | * must display the following acknowledgement: |
83 | * This product includes software developed for the NetBSD Project by | | 83 | * This product includes software developed for the NetBSD Project by |
84 | * Wasabi Systems, Inc. | | 84 | * Wasabi Systems, Inc. |
85 | * 4. The name of Wasabi Systems, Inc. may not be used to endorse | | 85 | * 4. The name of Wasabi Systems, Inc. may not be used to endorse |
86 | * or promote products derived from this software without specific prior | | 86 | * or promote products derived from this software without specific prior |
87 | * written permission. | | 87 | * written permission. |
88 | * | | 88 | * |
89 | * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND | | 89 | * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND |
90 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 90 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
91 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 91 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
92 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC | | 92 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC |
93 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 93 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
94 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 94 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
95 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 95 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
96 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 96 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
97 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 97 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
98 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 98 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
99 | * POSSIBILITY OF SUCH DAMAGE. | | 99 | * POSSIBILITY OF SUCH DAMAGE. |
100 | */ | | 100 | */ |
101 | | | 101 | |
102 | #include <sys/cdefs.h> | | 102 | #include <sys/cdefs.h> |
103 | __KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.212 2010/08/07 09:41:19 jruoho Exp $"); | | 103 | __KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.213 2010/08/07 17:12:55 jruoho Exp $"); |
104 | | | 104 | |
105 | #include "opt_acpi.h" | | 105 | #include "opt_acpi.h" |
106 | #include "opt_pcifixup.h" | | 106 | #include "opt_pcifixup.h" |
107 | | | 107 | |
108 | #include <sys/param.h> | | 108 | #include <sys/param.h> |
109 | #include <sys/device.h> | | 109 | #include <sys/device.h> |
110 | #include <sys/kernel.h> | | 110 | #include <sys/kernel.h> |
111 | #include <sys/malloc.h> | | 111 | #include <sys/malloc.h> |
112 | #include <sys/module.h> | | 112 | #include <sys/module.h> |
113 | #include <sys/mutex.h> | | 113 | #include <sys/mutex.h> |
114 | #include <sys/sysctl.h> | | 114 | #include <sys/sysctl.h> |
115 | #include <sys/systm.h> | | 115 | #include <sys/systm.h> |
116 | #include <sys/timetc.h> | | 116 | #include <sys/timetc.h> |
117 | | | 117 | |
118 | #include <dev/acpi/acpireg.h> | | 118 | #include <dev/acpi/acpireg.h> |
119 | #include <dev/acpi/acpivar.h> | | 119 | #include <dev/acpi/acpivar.h> |
120 | #include <dev/acpi/acpi_osd.h> | | 120 | #include <dev/acpi/acpi_osd.h> |
121 | #include <dev/acpi/acpi_pci.h> | | 121 | #include <dev/acpi/acpi_pci.h> |
122 | #include <dev/acpi/acpi_power.h> | | 122 | #include <dev/acpi/acpi_power.h> |
123 | #include <dev/acpi/acpi_timer.h> | | 123 | #include <dev/acpi/acpi_timer.h> |
124 | #include <dev/acpi/acpi_wakedev.h> | | 124 | #include <dev/acpi/acpi_wakedev.h> |
125 | | | 125 | |
126 | #define _COMPONENT ACPI_BUS_COMPONENT | | 126 | #define _COMPONENT ACPI_BUS_COMPONENT |
127 | ACPI_MODULE_NAME ("acpi") | | 127 | ACPI_MODULE_NAME ("acpi") |
128 | | | 128 | |
129 | #if defined(ACPI_PCI_FIXUP) | | 129 | #if defined(ACPI_PCI_FIXUP) |
130 | #error The option ACPI_PCI_FIXUP has been obsoleted by PCI_INTR_FIXUP_DISABLED. Please adjust your kernel configuration file. | | 130 | #error The option ACPI_PCI_FIXUP has been obsoleted by PCI_INTR_FIXUP_DISABLED. Please adjust your kernel configuration file. |
131 | #endif | | 131 | #endif |
132 | | | 132 | |
133 | #ifdef PCI_INTR_FIXUP_DISABLED | | 133 | #ifdef PCI_INTR_FIXUP_DISABLED |
134 | #include <dev/pci/pcidevs.h> | | 134 | #include <dev/pci/pcidevs.h> |
135 | #endif | | 135 | #endif |
136 | | | 136 | |
137 | MALLOC_DECLARE(M_ACPI); | | 137 | MALLOC_DECLARE(M_ACPI); |
138 | | | 138 | |
139 | #include <machine/acpi_machdep.h> | | 139 | #include <machine/acpi_machdep.h> |
140 | | | 140 | |
141 | #ifdef ACPI_DEBUGGER | | 141 | #ifdef ACPI_DEBUGGER |
142 | #define ACPI_DBGR_INIT 0x01 | | 142 | #define ACPI_DBGR_INIT 0x01 |
143 | #define ACPI_DBGR_TABLES 0x02 | | 143 | #define ACPI_DBGR_TABLES 0x02 |
144 | #define ACPI_DBGR_ENABLE 0x04 | | 144 | #define ACPI_DBGR_ENABLE 0x04 |
145 | #define ACPI_DBGR_PROBE 0x08 | | 145 | #define ACPI_DBGR_PROBE 0x08 |
146 | #define ACPI_DBGR_RUNNING 0x10 | | 146 | #define ACPI_DBGR_RUNNING 0x10 |
147 | | | 147 | |
148 | static int acpi_dbgr = 0x00; | | 148 | static int acpi_dbgr = 0x00; |
149 | #endif | | 149 | #endif |
150 | | | 150 | |
151 | /* | | 151 | /* |
152 | * This is a flag we set when the ACPI subsystem is active. Machine | | 152 | * This is a flag we set when the ACPI subsystem is active. Machine |
153 | * dependent code may wish to skip other steps (such as attaching | | 153 | * dependent code may wish to skip other steps (such as attaching |
154 | * subsystems that ACPI supercedes) when ACPI is active. | | 154 | * subsystems that ACPI supercedes) when ACPI is active. |
155 | */ | | 155 | */ |
156 | int acpi_active; | | 156 | int acpi_active; |
157 | int acpi_force_load; | | 157 | int acpi_force_load; |
158 | int acpi_suspended = 0; | | 158 | int acpi_suspended = 0; |
159 | int acpi_verbose_loaded = 0; | | 159 | int acpi_verbose_loaded = 0; |
160 | | | 160 | |
161 | struct acpi_softc *acpi_softc; | | 161 | struct acpi_softc *acpi_softc; |
162 | static uint64_t acpi_root_pointer; | | 162 | static uint64_t acpi_root_pointer; |
163 | extern kmutex_t acpi_interrupt_list_mtx; | | 163 | extern kmutex_t acpi_interrupt_list_mtx; |
164 | extern struct cfdriver acpi_cd; | | 164 | extern struct cfdriver acpi_cd; |
165 | static ACPI_HANDLE acpi_scopes[4]; | | 165 | static ACPI_HANDLE acpi_scopes[4]; |
166 | static ACPI_TABLE_HEADER *madt_header; | | 166 | ACPI_TABLE_HEADER *madt_header; |
167 | | | 167 | |
168 | /* | | 168 | /* |
169 | * This structure provides a context for the ACPI | | 169 | * This structure provides a context for the ACPI |
170 | * namespace walk performed in acpi_build_tree(). | | 170 | * namespace walk performed in acpi_build_tree(). |
171 | */ | | 171 | */ |
172 | struct acpi_walkcontext { | | 172 | struct acpi_walkcontext { |
173 | struct acpi_softc *aw_sc; | | 173 | struct acpi_softc *aw_sc; |
174 | struct acpi_devnode *aw_parent; | | 174 | struct acpi_devnode *aw_parent; |
175 | }; | | 175 | }; |
176 | | | 176 | |
177 | /* | | 177 | /* |
178 | * Ignored HIDs. | | 178 | * Ignored HIDs. |
179 | */ | | 179 | */ |
180 | static const char * const acpi_ignored_ids[] = { | | 180 | static const char * const acpi_ignored_ids[] = { |
181 | #if defined(i386) || defined(x86_64) | | 181 | #if defined(i386) || defined(x86_64) |
182 | "PNP0000", /* AT interrupt controller is handled internally */ | | 182 | "PNP0000", /* AT interrupt controller is handled internally */ |
183 | "PNP0200", /* AT DMA controller is handled internally */ | | 183 | "PNP0200", /* AT DMA controller is handled internally */ |
184 | "PNP0A??", /* PCI Busses are handled internally */ | | 184 | "PNP0A??", /* PCI Busses are handled internally */ |
185 | "PNP0B00", /* AT RTC is handled internally */ | | 185 | "PNP0B00", /* AT RTC is handled internally */ |
186 | "PNP0C0B", /* No need for "ACPI fan" driver */ | | 186 | "PNP0C0B", /* No need for "ACPI fan" driver */ |
187 | "PNP0C0F", /* ACPI PCI link devices are handled internally */ | | 187 | "PNP0C0F", /* ACPI PCI link devices are handled internally */ |
188 | "IFX0102", /* No driver for Infineon TPM */ | | 188 | "IFX0102", /* No driver for Infineon TPM */ |
189 | "INT0800", /* No driver for Intel Firmware Hub device */ | | 189 | "INT0800", /* No driver for Intel Firmware Hub device */ |
190 | #endif | | 190 | #endif |
191 | #if defined(x86_64) | | 191 | #if defined(x86_64) |
192 | "PNP0C04", /* FPU is handled internally */ | | 192 | "PNP0C04", /* FPU is handled internally */ |
193 | #endif | | 193 | #endif |
194 | NULL | | 194 | NULL |
195 | }; | | 195 | }; |
196 | | | 196 | |
197 | static int acpi_match(device_t, cfdata_t, void *); | | 197 | static int acpi_match(device_t, cfdata_t, void *); |
198 | static int acpi_submatch(device_t, cfdata_t, const int *, void *); | | 198 | static int acpi_submatch(device_t, cfdata_t, const int *, void *); |
199 | static void acpi_attach(device_t, device_t, void *); | | 199 | static void acpi_attach(device_t, device_t, void *); |
200 | static int acpi_detach(device_t, int); | | 200 | static int acpi_detach(device_t, int); |
201 | static void acpi_childdet(device_t, device_t); | | 201 | static void acpi_childdet(device_t, device_t); |
202 | static bool acpi_suspend(device_t, const pmf_qual_t *); | | 202 | static bool acpi_suspend(device_t, const pmf_qual_t *); |
203 | static bool acpi_resume(device_t, const pmf_qual_t *); | | 203 | static bool acpi_resume(device_t, const pmf_qual_t *); |
204 | | | 204 | |
205 | static void acpi_build_tree(struct acpi_softc *); | | 205 | static void acpi_build_tree(struct acpi_softc *); |
206 | static ACPI_STATUS acpi_make_devnode(ACPI_HANDLE, uint32_t, | | 206 | static ACPI_STATUS acpi_make_devnode(ACPI_HANDLE, uint32_t, |
207 | void *, void **); | | 207 | void *, void **); |
208 | static ACPI_STATUS acpi_make_devnode_post(ACPI_HANDLE, uint32_t, | | 208 | static ACPI_STATUS acpi_make_devnode_post(ACPI_HANDLE, uint32_t, |
209 | void *, void **); | | 209 | void *, void **); |
210 | | | 210 | |
211 | #ifdef ACPI_ACTIVATE_DEV | | 211 | #ifdef ACPI_ACTIVATE_DEV |
212 | static void acpi_activate_device(ACPI_HANDLE, ACPI_DEVICE_INFO **); | | 212 | static void acpi_activate_device(ACPI_HANDLE, ACPI_DEVICE_INFO **); |
213 | static ACPI_STATUS acpi_allocate_resources(ACPI_HANDLE); | | 213 | static ACPI_STATUS acpi_allocate_resources(ACPI_HANDLE); |
214 | #endif | | 214 | #endif |
215 | | | 215 | |
216 | static int acpi_rescan(device_t, const char *, const int *); | | 216 | static int acpi_rescan(device_t, const char *, const int *); |
217 | static void acpi_rescan_nodes(struct acpi_softc *); | | 217 | static void acpi_rescan_nodes(struct acpi_softc *); |
218 | static void acpi_rescan_capabilities(struct acpi_softc *); | | 218 | static void acpi_rescan_capabilities(struct acpi_softc *); |
219 | static int acpi_print(void *aux, const char *); | | 219 | static int acpi_print(void *aux, const char *); |
220 | | | 220 | |
221 | static void acpi_notify_handler(ACPI_HANDLE, uint32_t, void *); | | 221 | static void acpi_notify_handler(ACPI_HANDLE, uint32_t, void *); |
222 | | | 222 | |
223 | static void acpi_register_fixed_button(struct acpi_softc *, int); | | 223 | static void acpi_register_fixed_button(struct acpi_softc *, int); |
224 | static void acpi_deregister_fixed_button(struct acpi_softc *, int); | | 224 | static void acpi_deregister_fixed_button(struct acpi_softc *, int); |
225 | static uint32_t acpi_fixed_button_handler(void *); | | 225 | static uint32_t acpi_fixed_button_handler(void *); |
226 | static void acpi_fixed_button_pressed(void *); | | 226 | static void acpi_fixed_button_pressed(void *); |
227 | | | 227 | |
228 | static void acpi_sleep_init(struct acpi_softc *); | | 228 | static void acpi_sleep_init(struct acpi_softc *); |
229 | | | 229 | |
230 | static int sysctl_hw_acpi_fixedstats(SYSCTLFN_PROTO); | | 230 | static int sysctl_hw_acpi_fixedstats(SYSCTLFN_PROTO); |
231 | static int sysctl_hw_acpi_sleepstate(SYSCTLFN_PROTO); | | 231 | static int sysctl_hw_acpi_sleepstate(SYSCTLFN_PROTO); |
232 | static int sysctl_hw_acpi_sleepstates(SYSCTLFN_PROTO); | | 232 | static int sysctl_hw_acpi_sleepstates(SYSCTLFN_PROTO); |
233 | | | 233 | |
234 | static bool acpi_is_scope(struct acpi_devnode *); | | 234 | static bool acpi_is_scope(struct acpi_devnode *); |
235 | static ACPI_TABLE_HEADER *acpi_map_rsdt(void); | | 235 | static ACPI_TABLE_HEADER *acpi_map_rsdt(void); |
236 | static void acpi_unmap_rsdt(ACPI_TABLE_HEADER *); | | 236 | static void acpi_unmap_rsdt(ACPI_TABLE_HEADER *); |
237 | | | 237 | |
238 | void acpi_print_verbose_stub(struct acpi_softc *); | | 238 | void acpi_print_verbose_stub(struct acpi_softc *); |
239 | void acpi_print_dev_stub(const char *); | | 239 | void acpi_print_dev_stub(const char *); |
240 | | | 240 | |
241 | void (*acpi_print_verbose)(struct acpi_softc *) = acpi_print_verbose_stub; | | 241 | void (*acpi_print_verbose)(struct acpi_softc *) = acpi_print_verbose_stub; |
242 | void (*acpi_print_dev)(const char *) = acpi_print_dev_stub; | | 242 | void (*acpi_print_dev)(const char *) = acpi_print_dev_stub; |
243 | | | 243 | |
244 | CFATTACH_DECL2_NEW(acpi, sizeof(struct acpi_softc), | | 244 | CFATTACH_DECL2_NEW(acpi, sizeof(struct acpi_softc), |
245 | acpi_match, acpi_attach, acpi_detach, NULL, acpi_rescan, acpi_childdet); | | 245 | acpi_match, acpi_attach, acpi_detach, NULL, acpi_rescan, acpi_childdet); |
246 | | | 246 | |
247 | /* | | 247 | /* |
248 | * Probe for ACPI support. | | 248 | * Probe for ACPI support. |
249 | * | | 249 | * |
250 | * This is called by the machine-dependent ACPI front-end. | | 250 | * This is called by the machine-dependent ACPI front-end. |
251 | * Note: this is not an autoconfiguration interface function. | | 251 | * Note: this is not an autoconfiguration interface function. |
252 | */ | | 252 | */ |
253 | int | | 253 | int |
254 | acpi_probe(void) | | 254 | acpi_probe(void) |
255 | { | | 255 | { |
256 | ACPI_TABLE_HEADER *rsdt; | | 256 | ACPI_TABLE_HEADER *rsdt; |
257 | const char *func; | | 257 | const char *func; |
258 | static int once; | | 258 | static int once; |
259 | bool initialized; | | 259 | bool initialized; |
260 | ACPI_STATUS rv; | | 260 | ACPI_STATUS rv; |
261 | | | 261 | |
262 | if (once != 0) | | 262 | if (once != 0) |
263 | panic("%s: already probed", __func__); | | 263 | panic("%s: already probed", __func__); |
264 | | | 264 | |
265 | once = 1; | | 265 | once = 1; |
266 | func = NULL; | | 266 | func = NULL; |
267 | initialized = false; | | 267 | initialized = false; |
268 | | | 268 | |
269 | mutex_init(&acpi_interrupt_list_mtx, MUTEX_DEFAULT, IPL_NONE); | | 269 | mutex_init(&acpi_interrupt_list_mtx, MUTEX_DEFAULT, IPL_NONE); |
270 | | | 270 | |
271 | /* | | 271 | /* |
272 | * Start up ACPICA. | | 272 | * Start up ACPICA. |
273 | */ | | 273 | */ |
274 | #ifdef ACPI_DEBUGGER | | 274 | #ifdef ACPI_DEBUGGER |
275 | if (acpi_dbgr & ACPI_DBGR_INIT) | | 275 | if (acpi_dbgr & ACPI_DBGR_INIT) |
276 | acpi_osd_debugger(); | | 276 | acpi_osd_debugger(); |
277 | #endif | | 277 | #endif |
278 | | | 278 | |
279 | CTASSERT(TRUE == true); | | 279 | CTASSERT(TRUE == true); |
280 | CTASSERT(FALSE == false); | | 280 | CTASSERT(FALSE == false); |
281 | | | 281 | |
282 | AcpiGbl_AllMethodsSerialized = false; | | 282 | AcpiGbl_AllMethodsSerialized = false; |
283 | AcpiGbl_EnableInterpreterSlack = true; | | 283 | AcpiGbl_EnableInterpreterSlack = true; |
284 | | | 284 | |
285 | rv = AcpiInitializeSubsystem(); | | 285 | rv = AcpiInitializeSubsystem(); |
286 | | | 286 | |
287 | if (ACPI_SUCCESS(rv)) | | 287 | if (ACPI_SUCCESS(rv)) |
288 | initialized = true; | | 288 | initialized = true; |
289 | else { | | 289 | else { |
290 | func = "AcpiInitializeSubsystem()"; | | 290 | func = "AcpiInitializeSubsystem()"; |
291 | goto fail; | | 291 | goto fail; |
292 | } | | 292 | } |
293 | | | 293 | |
294 | /* | | 294 | /* |
295 | * Allocate space for RSDT/XSDT and DSDT, | | 295 | * Allocate space for RSDT/XSDT and DSDT, |
296 | * but allow resizing if more tables exist. | | 296 | * but allow resizing if more tables exist. |
297 | */ | | 297 | */ |
298 | rv = AcpiInitializeTables(NULL, 2, true); | | 298 | rv = AcpiInitializeTables(NULL, 2, true); |
299 | | | 299 | |
300 | if (ACPI_FAILURE(rv)) { | | 300 | if (ACPI_FAILURE(rv)) { |
301 | func = "AcpiInitializeTables()"; | | 301 | func = "AcpiInitializeTables()"; |
302 | goto fail; | | 302 | goto fail; |
303 | } | | 303 | } |
304 | | | 304 | |
305 | #ifdef ACPI_DEBUGGER | | 305 | #ifdef ACPI_DEBUGGER |
306 | if (acpi_dbgr & ACPI_DBGR_TABLES) | | 306 | if (acpi_dbgr & ACPI_DBGR_TABLES) |
307 | acpi_osd_debugger(); | | 307 | acpi_osd_debugger(); |
308 | #endif | | 308 | #endif |
309 | | | 309 | |
310 | rv = AcpiLoadTables(); | | 310 | rv = AcpiLoadTables(); |
311 | | | 311 | |
312 | if (ACPI_FAILURE(rv)) { | | 312 | if (ACPI_FAILURE(rv)) { |
313 | func = "AcpiLoadTables()"; | | 313 | func = "AcpiLoadTables()"; |
314 | goto fail; | | 314 | goto fail; |
315 | } | | 315 | } |
316 | | | 316 | |
317 | rsdt = acpi_map_rsdt(); | | 317 | rsdt = acpi_map_rsdt(); |
318 | | | 318 | |
319 | if (rsdt == NULL) { | | 319 | if (rsdt == NULL) { |
320 | func = "acpi_map_rsdt()"; | | 320 | func = "acpi_map_rsdt()"; |
321 | rv = AE_ERROR; | | 321 | rv = AE_ERROR; |
322 | goto fail; | | 322 | goto fail; |
323 | } | | 323 | } |
324 | | | 324 | |
325 | if (acpi_force_load == 0 && (acpi_find_quirks() & ACPI_QUIRK_BROKEN)) { | | 325 | if (acpi_force_load == 0 && (acpi_find_quirks() & ACPI_QUIRK_BROKEN)) { |
326 | aprint_normal("ACPI: BIOS is listed as broken:\n"); | | 326 | aprint_normal("ACPI: BIOS is listed as broken:\n"); |
327 | aprint_normal("ACPI: X/RSDT: OemId <%6.6s,%8.8s,%08x>, " | | 327 | aprint_normal("ACPI: X/RSDT: OemId <%6.6s,%8.8s,%08x>, " |
328 | "AslId <%4.4s,%08x>\n", | | 328 | "AslId <%4.4s,%08x>\n", |
329 | rsdt->OemId, rsdt->OemTableId, | | 329 | rsdt->OemId, rsdt->OemTableId, |
330 | rsdt->OemRevision, | | 330 | rsdt->OemRevision, |
331 | rsdt->AslCompilerId, | | 331 | rsdt->AslCompilerId, |
332 | rsdt->AslCompilerRevision); | | 332 | rsdt->AslCompilerRevision); |
333 | aprint_normal("ACPI: Not used. Set acpi_force_load to use.\n"); | | 333 | aprint_normal("ACPI: Not used. Set acpi_force_load to use.\n"); |
334 | acpi_unmap_rsdt(rsdt); | | 334 | acpi_unmap_rsdt(rsdt); |
335 | AcpiTerminate(); | | 335 | AcpiTerminate(); |
336 | return 0; | | 336 | return 0; |
337 | } | | 337 | } |
338 | | | 338 | |
339 | acpi_unmap_rsdt(rsdt); | | 339 | acpi_unmap_rsdt(rsdt); |
340 | | | 340 | |
341 | rv = AcpiEnableSubsystem(~(ACPI_NO_HARDWARE_INIT|ACPI_NO_ACPI_ENABLE)); | | 341 | rv = AcpiEnableSubsystem(~(ACPI_NO_HARDWARE_INIT|ACPI_NO_ACPI_ENABLE)); |
342 | | | 342 | |
343 | if (ACPI_FAILURE(rv)) { | | 343 | if (ACPI_FAILURE(rv)) { |
344 | func = "AcpiEnableSubsystem()"; | | 344 | func = "AcpiEnableSubsystem()"; |
345 | goto fail; | | 345 | goto fail; |
346 | } | | 346 | } |
347 | | | 347 | |
348 | /* | | 348 | /* |
349 | * Looks like we have ACPI! | | 349 | * Looks like we have ACPI! |
350 | */ | | 350 | */ |
351 | return 1; | | 351 | return 1; |
352 | | | 352 | |
353 | fail: | | 353 | fail: |
354 | KASSERT(rv != AE_OK); | | 354 | KASSERT(rv != AE_OK); |
355 | KASSERT(func != NULL); | | 355 | KASSERT(func != NULL); |
356 | | | 356 | |
357 | aprint_error("%s: failed to probe ACPI: %s\n", | | 357 | aprint_error("%s: failed to probe ACPI: %s\n", |
358 | func, AcpiFormatException(rv)); | | 358 | func, AcpiFormatException(rv)); |
359 | | | 359 | |
360 | if (initialized != false) | | 360 | if (initialized != false) |
361 | (void)AcpiTerminate(); | | 361 | (void)AcpiTerminate(); |
362 | | | 362 | |
363 | return 0; | | 363 | return 0; |
364 | } | | 364 | } |
365 | | | 365 | |
366 | int | | 366 | int |
367 | acpi_check(device_t parent, const char *ifattr) | | 367 | acpi_check(device_t parent, const char *ifattr) |
368 | { | | 368 | { |
369 | return (config_search_ia(acpi_submatch, parent, ifattr, NULL) != NULL); | | 369 | return (config_search_ia(acpi_submatch, parent, ifattr, NULL) != NULL); |
370 | } | | 370 | } |
371 | | | 371 | |
372 | /* | | 372 | /* |
373 | * Autoconfiguration. | | 373 | * Autoconfiguration. |
374 | */ | | 374 | */ |
375 | static int | | 375 | static int |
376 | acpi_match(device_t parent, cfdata_t match, void *aux) | | 376 | acpi_match(device_t parent, cfdata_t match, void *aux) |
377 | { | | 377 | { |
378 | /* | | 378 | /* |
379 | * XXX: Nada; MD code has called acpi_probe(). | | 379 | * XXX: Nada; MD code has called acpi_probe(). |
380 | */ | | 380 | */ |
381 | return 1; | | 381 | return 1; |
382 | } | | 382 | } |
383 | | | 383 | |
384 | static int | | 384 | static int |
385 | acpi_submatch(device_t parent, cfdata_t cf, const int *locs, void *aux) | | 385 | acpi_submatch(device_t parent, cfdata_t cf, const int *locs, void *aux) |
386 | { | | 386 | { |
387 | struct cfattach *ca; | | 387 | struct cfattach *ca; |
388 | | | 388 | |
389 | ca = config_cfattach_lookup(cf->cf_name, cf->cf_atname); | | 389 | ca = config_cfattach_lookup(cf->cf_name, cf->cf_atname); |
390 | | | 390 | |
391 | return (ca == &acpi_ca); | | 391 | return (ca == &acpi_ca); |
392 | } | | 392 | } |
393 | | | 393 | |
394 | static void | | 394 | static void |
395 | acpi_attach(device_t parent, device_t self, void *aux) | | 395 | acpi_attach(device_t parent, device_t self, void *aux) |
396 | { | | 396 | { |
397 | struct acpi_softc *sc = device_private(self); | | 397 | struct acpi_softc *sc = device_private(self); |
398 | struct acpibus_attach_args *aa = aux; | | 398 | struct acpibus_attach_args *aa = aux; |
399 | ACPI_TABLE_HEADER *rsdt; | | 399 | ACPI_TABLE_HEADER *rsdt; |
400 | ACPI_STATUS rv; | | 400 | ACPI_STATUS rv; |
401 | | | 401 | |
402 | aprint_naive("\n"); | | 402 | aprint_naive("\n"); |
403 | aprint_normal(": Intel ACPICA %08x\n", ACPI_CA_VERSION); | | 403 | aprint_normal(": Intel ACPICA %08x\n", ACPI_CA_VERSION); |
404 | | | 404 | |
405 | if (acpi_softc != NULL) | | 405 | if (acpi_softc != NULL) |
406 | panic("%s: already attached", __func__); | | 406 | panic("%s: already attached", __func__); |
407 | | | 407 | |
408 | rsdt = acpi_map_rsdt(); | | 408 | rsdt = acpi_map_rsdt(); |
409 | | | 409 | |
410 | if (rsdt == NULL) | | 410 | if (rsdt == NULL) |
411 | aprint_error_dev(self, "X/RSDT: Not found\n"); | | 411 | aprint_error_dev(self, "X/RSDT: Not found\n"); |
412 | else { | | 412 | else { |
413 | aprint_verbose_dev(self, | | 413 | aprint_verbose_dev(self, |
414 | "X/RSDT: OemId <%6.6s,%8.8s,%08x>, AslId <%4.4s,%08x>\n", | | 414 | "X/RSDT: OemId <%6.6s,%8.8s,%08x>, AslId <%4.4s,%08x>\n", |
415 | rsdt->OemId, rsdt->OemTableId, | | 415 | rsdt->OemId, rsdt->OemTableId, |
416 | rsdt->OemRevision, | | 416 | rsdt->OemRevision, |
417 | rsdt->AslCompilerId, rsdt->AslCompilerRevision); | | 417 | rsdt->AslCompilerId, rsdt->AslCompilerRevision); |
418 | } | | 418 | } |
419 | | | 419 | |
420 | acpi_unmap_rsdt(rsdt); | | 420 | acpi_unmap_rsdt(rsdt); |
421 | | | 421 | |
422 | sc->sc_dev = self; | | 422 | sc->sc_dev = self; |
423 | sc->sc_root = NULL; | | 423 | sc->sc_root = NULL; |
424 | | | 424 | |
425 | sc->sc_sleepstate = ACPI_STATE_S0; | | 425 | sc->sc_sleepstate = ACPI_STATE_S0; |
426 | sc->sc_quirks = acpi_find_quirks(); | | 426 | sc->sc_quirks = acpi_find_quirks(); |
427 | | | 427 | |
428 | sysmon_power_settype("acpi"); | | 428 | sysmon_power_settype("acpi"); |
429 | | | 429 | |
430 | sc->sc_iot = aa->aa_iot; | | 430 | sc->sc_iot = aa->aa_iot; |
431 | sc->sc_memt = aa->aa_memt; | | 431 | sc->sc_memt = aa->aa_memt; |
432 | sc->sc_pc = aa->aa_pc; | | 432 | sc->sc_pc = aa->aa_pc; |
433 | sc->sc_pciflags = aa->aa_pciflags; | | 433 | sc->sc_pciflags = aa->aa_pciflags; |
434 | sc->sc_ic = aa->aa_ic; | | 434 | sc->sc_ic = aa->aa_ic; |
435 | | | 435 | |
436 | SIMPLEQ_INIT(&sc->ad_head); | | 436 | SIMPLEQ_INIT(&sc->ad_head); |
437 | | | 437 | |
438 | acpi_softc = sc; | | 438 | acpi_softc = sc; |
439 | | | 439 | |
440 | if (pmf_device_register(self, acpi_suspend, acpi_resume) != true) | | 440 | if (pmf_device_register(self, acpi_suspend, acpi_resume) != true) |
441 | aprint_error_dev(self, "couldn't establish power handler\n"); | | 441 | aprint_error_dev(self, "couldn't establish power handler\n"); |
442 | | | 442 | |
443 | /* | | 443 | /* |
444 | * Bring ACPI on-line. | | 444 | * Bring ACPI on-line. |
445 | */ | | 445 | */ |
446 | #ifdef ACPI_DEBUGGER | | 446 | #ifdef ACPI_DEBUGGER |
447 | if (acpi_dbgr & ACPI_DBGR_ENABLE) | | 447 | if (acpi_dbgr & ACPI_DBGR_ENABLE) |
448 | acpi_osd_debugger(); | | 448 | acpi_osd_debugger(); |
449 | #endif | | 449 | #endif |
450 | | | 450 | |
451 | #define ACPI_ENABLE_PHASE1 \ | | 451 | #define ACPI_ENABLE_PHASE1 \ |
452 | (ACPI_NO_HANDLER_INIT | ACPI_NO_EVENT_INIT) | | 452 | (ACPI_NO_HANDLER_INIT | ACPI_NO_EVENT_INIT) |
453 | #define ACPI_ENABLE_PHASE2 \ | | 453 | #define ACPI_ENABLE_PHASE2 \ |
454 | (ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE | \ | | 454 | (ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE | \ |
455 | ACPI_NO_ADDRESS_SPACE_INIT) | | 455 | ACPI_NO_ADDRESS_SPACE_INIT) |
456 | | | 456 | |
457 | rv = AcpiEnableSubsystem(ACPI_ENABLE_PHASE1); | | 457 | rv = AcpiEnableSubsystem(ACPI_ENABLE_PHASE1); |
458 | | | 458 | |
459 | if (ACPI_FAILURE(rv)) | | 459 | if (ACPI_FAILURE(rv)) |
460 | goto fail; | | 460 | goto fail; |
461 | | | 461 | |
462 | acpi_md_callback(); | | 462 | acpi_md_callback(); |
463 | | | 463 | |
464 | rv = AcpiEnableSubsystem(ACPI_ENABLE_PHASE2); | | 464 | rv = AcpiEnableSubsystem(ACPI_ENABLE_PHASE2); |
465 | | | 465 | |
466 | if (ACPI_FAILURE(rv)) | | 466 | if (ACPI_FAILURE(rv)) |
467 | goto fail; | | 467 | goto fail; |
468 | | | 468 | |
469 | /* | | 469 | /* |
470 | * Early EC handler initialization if ECDT table is available. | | 470 | * Early EC handler initialization if ECDT table is available. |
471 | */ | | 471 | */ |
472 | config_found_ia(self, "acpiecdtbus", aa, NULL); | | 472 | config_found_ia(self, "acpiecdtbus", aa, NULL); |
473 | | | 473 | |
474 | rv = AcpiInitializeObjects(ACPI_FULL_INITIALIZATION); | | 474 | rv = AcpiInitializeObjects(ACPI_FULL_INITIALIZATION); |
475 | | | 475 | |
476 | if (ACPI_FAILURE(rv)) | | 476 | if (ACPI_FAILURE(rv)) |
477 | goto fail; | | 477 | goto fail; |
478 | | | 478 | |
479 | /* | | 479 | /* |
480 | * Install global notify handlers. | | 480 | * Install global notify handlers. |
481 | */ | | 481 | */ |
482 | rv = AcpiInstallNotifyHandler(ACPI_ROOT_OBJECT, | | 482 | rv = AcpiInstallNotifyHandler(ACPI_ROOT_OBJECT, |
483 | ACPI_SYSTEM_NOTIFY, acpi_notify_handler, NULL); | | 483 | ACPI_SYSTEM_NOTIFY, acpi_notify_handler, NULL); |
484 | | | 484 | |
485 | if (ACPI_FAILURE(rv)) | | 485 | if (ACPI_FAILURE(rv)) |
486 | goto fail; | | 486 | goto fail; |
487 | | | 487 | |
488 | rv = AcpiInstallNotifyHandler(ACPI_ROOT_OBJECT, | | 488 | rv = AcpiInstallNotifyHandler(ACPI_ROOT_OBJECT, |
489 | ACPI_DEVICE_NOTIFY, acpi_notify_handler, NULL); | | 489 | ACPI_DEVICE_NOTIFY, acpi_notify_handler, NULL); |
490 | | | 490 | |
491 | if (ACPI_FAILURE(rv)) | | 491 | if (ACPI_FAILURE(rv)) |
492 | goto fail; | | 492 | goto fail; |
493 | | | 493 | |
494 | acpi_active = 1; | | 494 | acpi_active = 1; |
495 | | | 495 | |
496 | /* Show SCI interrupt. */ | | 496 | /* Show SCI interrupt. */ |
497 | aprint_verbose_dev(self, "SCI interrupting at int %u\n", | | 497 | aprint_verbose_dev(self, "SCI interrupting at int %u\n", |
498 | AcpiGbl_FADT.SciInterrupt); | | 498 | AcpiGbl_FADT.SciInterrupt); |
499 | | | 499 | |
500 | /* | | 500 | /* |
501 | * Install fixed-event handlers. | | 501 | * Install fixed-event handlers. |
502 | */ | | 502 | */ |
503 | acpi_register_fixed_button(sc, ACPI_EVENT_POWER_BUTTON); | | 503 | acpi_register_fixed_button(sc, ACPI_EVENT_POWER_BUTTON); |
504 | acpi_register_fixed_button(sc, ACPI_EVENT_SLEEP_BUTTON); | | 504 | acpi_register_fixed_button(sc, ACPI_EVENT_SLEEP_BUTTON); |
505 | | | 505 | |
506 | acpitimer_init(sc); | | 506 | acpitimer_init(sc); |
507 | | | 507 | |
508 | #ifdef ACPI_DEBUGGER | | 508 | #ifdef ACPI_DEBUGGER |
509 | if (acpi_dbgr & ACPI_DBGR_PROBE) | | 509 | if (acpi_dbgr & ACPI_DBGR_PROBE) |
510 | acpi_osd_debugger(); | | 510 | acpi_osd_debugger(); |
511 | #endif | | 511 | #endif |
512 | | | 512 | |
513 | /* | | 513 | /* |
514 | * Scan the namespace and build our device tree. | | 514 | * Scan the namespace and build our device tree. |
515 | */ | | 515 | */ |
516 | acpi_build_tree(sc); | | 516 | acpi_build_tree(sc); |
517 | acpi_sleep_init(sc); | | 517 | acpi_sleep_init(sc); |
518 | | | 518 | |
519 | #ifdef ACPI_DEBUGGER | | 519 | #ifdef ACPI_DEBUGGER |
520 | if (acpi_dbgr & ACPI_DBGR_RUNNING) | | 520 | if (acpi_dbgr & ACPI_DBGR_RUNNING) |
521 | acpi_osd_debugger(); | | 521 | acpi_osd_debugger(); |
522 | #endif | | 522 | #endif |
523 | | | 523 | |
524 | #ifdef ACPI_DEBUG | | 524 | #ifdef ACPI_DEBUG |
525 | acpi_debug_init(); | | 525 | acpi_debug_init(); |
526 | #endif | | 526 | #endif |
527 | | | 527 | |
528 | /* | | 528 | /* |
529 | * Print debug information. | | 529 | * Print debug information. |
530 | */ | | 530 | */ |
531 | acpi_print_verbose(sc); | | 531 | acpi_print_verbose(sc); |
532 | | | 532 | |
533 | return; | | 533 | return; |
534 | | | 534 | |
535 | fail: | | 535 | fail: |
536 | aprint_error("%s: failed to initialize ACPI: %s\n", | | 536 | aprint_error("%s: failed to initialize ACPI: %s\n", |
537 | __func__, AcpiFormatException(rv)); | | 537 | __func__, AcpiFormatException(rv)); |
538 | } | | 538 | } |
539 | | | 539 | |
540 | /* | | 540 | /* |
541 | * XXX: This is incomplete. | | 541 | * XXX: This is incomplete. |
542 | */ | | 542 | */ |
543 | static int | | 543 | static int |
544 | acpi_detach(device_t self, int flags) | | 544 | acpi_detach(device_t self, int flags) |
545 | { | | 545 | { |
546 | struct acpi_softc *sc = device_private(self); | | 546 | struct acpi_softc *sc = device_private(self); |
547 | ACPI_STATUS rv; | | 547 | ACPI_STATUS rv; |
548 | int rc; | | 548 | int rc; |
549 | | | 549 | |
550 | rv = AcpiRemoveNotifyHandler(ACPI_ROOT_OBJECT, | | 550 | rv = AcpiRemoveNotifyHandler(ACPI_ROOT_OBJECT, |
551 | ACPI_SYSTEM_NOTIFY, acpi_notify_handler); | | 551 | ACPI_SYSTEM_NOTIFY, acpi_notify_handler); |
552 | | | 552 | |
553 | if (ACPI_FAILURE(rv)) | | 553 | if (ACPI_FAILURE(rv)) |
554 | return EBUSY; | | 554 | return EBUSY; |
555 | | | 555 | |
556 | rv = AcpiRemoveNotifyHandler(ACPI_ROOT_OBJECT, | | 556 | rv = AcpiRemoveNotifyHandler(ACPI_ROOT_OBJECT, |
557 | ACPI_DEVICE_NOTIFY, acpi_notify_handler); | | 557 | ACPI_DEVICE_NOTIFY, acpi_notify_handler); |
558 | | | 558 | |
559 | if (ACPI_FAILURE(rv)) | | 559 | if (ACPI_FAILURE(rv)) |
560 | return EBUSY; | | 560 | return EBUSY; |
561 | | | 561 | |
562 | if ((rc = config_detach_children(self, flags)) != 0) | | 562 | if ((rc = config_detach_children(self, flags)) != 0) |
563 | return rc; | | 563 | return rc; |
564 | | | 564 | |
565 | if ((rc = acpitimer_detach()) != 0) | | 565 | if ((rc = acpitimer_detach()) != 0) |
566 | return rc; | | 566 | return rc; |
567 | | | 567 | |
568 | acpi_deregister_fixed_button(sc, ACPI_EVENT_POWER_BUTTON); | | 568 | acpi_deregister_fixed_button(sc, ACPI_EVENT_POWER_BUTTON); |
569 | acpi_deregister_fixed_button(sc, ACPI_EVENT_SLEEP_BUTTON); | | 569 | acpi_deregister_fixed_button(sc, ACPI_EVENT_SLEEP_BUTTON); |
570 | | | 570 | |
571 | pmf_device_deregister(self); | | 571 | pmf_device_deregister(self); |
572 | | | 572 | |
573 | acpi_softc = NULL; | | 573 | acpi_softc = NULL; |
574 | | | 574 | |
575 | return 0; | | 575 | return 0; |
576 | } | | 576 | } |
577 | | | 577 | |
578 | /* | | 578 | /* |
579 | * XXX: Need to reclaim any resources? Yes. | | 579 | * XXX: Need to reclaim any resources? Yes. |
580 | */ | | 580 | */ |
581 | static void | | 581 | static void |
582 | acpi_childdet(device_t self, device_t child) | | 582 | acpi_childdet(device_t self, device_t child) |
583 | { | | 583 | { |
584 | struct acpi_softc *sc = device_private(self); | | 584 | struct acpi_softc *sc = device_private(self); |
585 | struct acpi_devnode *ad; | | 585 | struct acpi_devnode *ad; |
586 | | | 586 | |
587 | if (sc->sc_apmbus == child) | | 587 | if (sc->sc_apmbus == child) |
588 | sc->sc_apmbus = NULL; | | 588 | sc->sc_apmbus = NULL; |
589 | | | 589 | |
590 | SIMPLEQ_FOREACH(ad, &sc->ad_head, ad_list) { | | 590 | SIMPLEQ_FOREACH(ad, &sc->ad_head, ad_list) { |
591 | | | 591 | |
592 | if (ad->ad_device == child) | | 592 | if (ad->ad_device == child) |
593 | ad->ad_device = NULL; | | 593 | ad->ad_device = NULL; |
594 | } | | 594 | } |
595 | } | | 595 | } |
596 | | | 596 | |
597 | static bool | | 597 | static bool |
598 | acpi_suspend(device_t dv, const pmf_qual_t *qual) | | 598 | acpi_suspend(device_t dv, const pmf_qual_t *qual) |
599 | { | | 599 | { |
600 | | | 600 | |
601 | acpi_suspended = 1; | | 601 | acpi_suspended = 1; |
602 | | | 602 | |
603 | return true; | | 603 | return true; |
604 | } | | 604 | } |
605 | | | 605 | |
606 | static bool | | 606 | static bool |
607 | acpi_resume(device_t dv, const pmf_qual_t *qual) | | 607 | acpi_resume(device_t dv, const pmf_qual_t *qual) |
608 | { | | 608 | { |
609 | | | 609 | |
610 | acpi_suspended = 0; | | 610 | acpi_suspended = 0; |
611 | | | 611 | |
612 | return true; | | 612 | return true; |
613 | } | | 613 | } |
614 | | | 614 | |
615 | /* | | 615 | /* |
616 | * Namespace scan. | | 616 | * Namespace scan. |
617 | */ | | 617 | */ |
618 | static void | | 618 | static void |
619 | acpi_build_tree(struct acpi_softc *sc) | | 619 | acpi_build_tree(struct acpi_softc *sc) |
620 | { | | 620 | { |
621 | struct acpi_walkcontext awc; | | 621 | struct acpi_walkcontext awc; |
622 | | | 622 | |
623 | /* | | 623 | /* |
624 | * Get the root scope handles. | | 624 | * Get the root scope handles. |
625 | */ | | 625 | */ |
626 | KASSERT(__arraycount(acpi_scopes) == 4); | | 626 | KASSERT(__arraycount(acpi_scopes) == 4); |
627 | | | 627 | |
628 | (void)AcpiGetHandle(ACPI_ROOT_OBJECT, "\\_PR_", &acpi_scopes[0]); | | 628 | (void)AcpiGetHandle(ACPI_ROOT_OBJECT, "\\_PR_", &acpi_scopes[0]); |
629 | (void)AcpiGetHandle(ACPI_ROOT_OBJECT, "\\_SB_", &acpi_scopes[1]); | | 629 | (void)AcpiGetHandle(ACPI_ROOT_OBJECT, "\\_SB_", &acpi_scopes[1]); |
630 | (void)AcpiGetHandle(ACPI_ROOT_OBJECT, "\\_SI_", &acpi_scopes[2]); | | 630 | (void)AcpiGetHandle(ACPI_ROOT_OBJECT, "\\_SI_", &acpi_scopes[2]); |
631 | (void)AcpiGetHandle(ACPI_ROOT_OBJECT, "\\_TZ_", &acpi_scopes[3]); | | 631 | (void)AcpiGetHandle(ACPI_ROOT_OBJECT, "\\_TZ_", &acpi_scopes[3]); |
632 | | | 632 | |
633 | /* | | 633 | /* |
634 | * Make the root node. | | 634 | * Make the root node. |
635 | */ | | 635 | */ |
636 | awc.aw_sc = sc; | | 636 | awc.aw_sc = sc; |
637 | awc.aw_parent = NULL; | | 637 | awc.aw_parent = NULL; |
638 | | | 638 | |
639 | (void)acpi_make_devnode(ACPI_ROOT_OBJECT, 0, &awc, NULL); | | 639 | (void)acpi_make_devnode(ACPI_ROOT_OBJECT, 0, &awc, NULL); |
640 | | | 640 | |
641 | KASSERT(sc->sc_root == NULL); | | 641 | KASSERT(sc->sc_root == NULL); |
642 | KASSERT(awc.aw_parent != NULL); | | 642 | KASSERT(awc.aw_parent != NULL); |
643 | | | 643 | |
644 | sc->sc_root = awc.aw_parent; | | 644 | sc->sc_root = awc.aw_parent; |
645 | | | 645 | |
646 | /* | | 646 | /* |
647 | * Build the internal namespace. | | 647 | * Build the internal namespace. |
648 | */ | | 648 | */ |
649 | (void)AcpiWalkNamespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, UINT32_MAX, | | 649 | (void)AcpiWalkNamespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, UINT32_MAX, |
650 | acpi_make_devnode, acpi_make_devnode_post, &awc, NULL); | | 650 | acpi_make_devnode, acpi_make_devnode_post, &awc, NULL); |
651 | | | 651 | |
652 | /* | | 652 | /* |
653 | * Scan the internal namespace. | | 653 | * Scan the internal namespace. |
654 | */ | | 654 | */ |
655 | (void)acpi_rescan(sc->sc_dev, NULL, NULL); | | 655 | (void)acpi_rescan(sc->sc_dev, NULL, NULL); |
656 | | | 656 | |
657 | acpi_rescan_capabilities(sc); | | 657 | acpi_rescan_capabilities(sc); |
658 | | | 658 | |
659 | (void)acpi_pcidev_scan(sc->sc_root); | | 659 | (void)acpi_pcidev_scan(sc->sc_root); |
660 | } | | 660 | } |
661 | | | 661 | |
662 | static ACPI_STATUS | | 662 | static ACPI_STATUS |
663 | acpi_make_devnode(ACPI_HANDLE handle, uint32_t level, | | 663 | acpi_make_devnode(ACPI_HANDLE handle, uint32_t level, |
664 | void *context, void **status) | | 664 | void *context, void **status) |
665 | { | | 665 | { |
666 | struct acpi_walkcontext *awc = context; | | 666 | struct acpi_walkcontext *awc = context; |
667 | struct acpi_softc *sc = awc->aw_sc; | | 667 | struct acpi_softc *sc = awc->aw_sc; |
668 | struct acpi_devnode *ad; | | 668 | struct acpi_devnode *ad; |
669 | ACPI_DEVICE_INFO *devinfo; | | 669 | ACPI_DEVICE_INFO *devinfo; |
670 | ACPI_OBJECT_TYPE type; | | 670 | ACPI_OBJECT_TYPE type; |
671 | ACPI_NAME_UNION *anu; | | 671 | ACPI_NAME_UNION *anu; |
672 | ACPI_STATUS rv; | | 672 | ACPI_STATUS rv; |
673 | int clear, i; | | 673 | int clear, i; |
674 | | | 674 | |
675 | rv = AcpiGetObjectInfo(handle, &devinfo); | | 675 | rv = AcpiGetObjectInfo(handle, &devinfo); |
676 | | | 676 | |
677 | if (ACPI_FAILURE(rv)) | | 677 | if (ACPI_FAILURE(rv)) |
678 | return AE_OK; /* Do not terminate the walk. */ | | 678 | return AE_OK; /* Do not terminate the walk. */ |
679 | | | 679 | |
680 | type = devinfo->Type; | | 680 | type = devinfo->Type; |
681 | | | 681 | |
682 | switch (type) { | | 682 | switch (type) { |
683 | | | 683 | |
684 | case ACPI_TYPE_DEVICE: | | 684 | case ACPI_TYPE_DEVICE: |
685 | | | 685 | |
686 | #ifdef ACPI_ACTIVATE_DEV | | 686 | #ifdef ACPI_ACTIVATE_DEV |
687 | acpi_activate_device(handle, &devinfo); | | 687 | acpi_activate_device(handle, &devinfo); |
688 | #endif | | 688 | #endif |
689 | | | 689 | |
690 | case ACPI_TYPE_PROCESSOR: | | 690 | case ACPI_TYPE_PROCESSOR: |
691 | case ACPI_TYPE_THERMAL: | | 691 | case ACPI_TYPE_THERMAL: |
692 | case ACPI_TYPE_POWER: | | 692 | case ACPI_TYPE_POWER: |
693 | | | 693 | |
694 | ad = malloc(sizeof(*ad), M_ACPI, M_NOWAIT | M_ZERO); | | 694 | ad = malloc(sizeof(*ad), M_ACPI, M_NOWAIT | M_ZERO); |
695 | | | 695 | |
696 | if (ad == NULL) | | 696 | if (ad == NULL) |
697 | return AE_NO_MEMORY; | | 697 | return AE_NO_MEMORY; |
698 | | | 698 | |
699 | ad->ad_device = NULL; | | 699 | ad->ad_device = NULL; |
700 | ad->ad_notify = NULL; | | 700 | ad->ad_notify = NULL; |
701 | ad->ad_pciinfo = NULL; | | 701 | ad->ad_pciinfo = NULL; |
702 | | | 702 | |
703 | ad->ad_type = type; | | 703 | ad->ad_type = type; |
704 | ad->ad_handle = handle; | | 704 | ad->ad_handle = handle; |
705 | ad->ad_devinfo = devinfo; | | 705 | ad->ad_devinfo = devinfo; |
706 | | | 706 | |
707 | ad->ad_root = sc->sc_dev; | | 707 | ad->ad_root = sc->sc_dev; |
708 | ad->ad_parent = awc->aw_parent; | | 708 | ad->ad_parent = awc->aw_parent; |
709 | | | 709 | |
710 | anu = (ACPI_NAME_UNION *)&devinfo->Name; | | 710 | anu = (ACPI_NAME_UNION *)&devinfo->Name; |
711 | ad->ad_name[4] = '\0'; | | 711 | ad->ad_name[4] = '\0'; |
712 | | | 712 | |
713 | for (i = 3, clear = 0; i >= 0; i--) { | | 713 | for (i = 3, clear = 0; i >= 0; i--) { |
714 | | | 714 | |
715 | if (clear == 0 && anu->Ascii[i] == '_') | | 715 | if (clear == 0 && anu->Ascii[i] == '_') |
716 | ad->ad_name[i] = '\0'; | | 716 | ad->ad_name[i] = '\0'; |
717 | else { | | 717 | else { |
718 | ad->ad_name[i] = anu->Ascii[i]; | | 718 | ad->ad_name[i] = anu->Ascii[i]; |
719 | clear = 1; | | 719 | clear = 1; |
720 | } | | 720 | } |
721 | } | | 721 | } |
722 | | | 722 | |
723 | if (ad->ad_name[0] == '\0') | | 723 | if (ad->ad_name[0] == '\0') |
724 | ad->ad_name[0] = '_'; | | 724 | ad->ad_name[0] = '_'; |
725 | | | 725 | |
726 | SIMPLEQ_INIT(&ad->ad_child_head); | | 726 | SIMPLEQ_INIT(&ad->ad_child_head); |
727 | SIMPLEQ_INSERT_TAIL(&sc->ad_head, ad, ad_list); | | 727 | SIMPLEQ_INSERT_TAIL(&sc->ad_head, ad, ad_list); |
728 | | | 728 | |
729 | acpi_set_node(ad); | | 729 | acpi_set_node(ad); |
730 | | | 730 | |
731 | if (ad->ad_parent != NULL) { | | 731 | if (ad->ad_parent != NULL) { |
732 | | | 732 | |
733 | SIMPLEQ_INSERT_TAIL(&ad->ad_parent->ad_child_head, | | 733 | SIMPLEQ_INSERT_TAIL(&ad->ad_parent->ad_child_head, |
734 | ad, ad_child_list); | | 734 | ad, ad_child_list); |
735 | } | | 735 | } |
736 | | | 736 | |
737 | awc->aw_parent = ad; | | 737 | awc->aw_parent = ad; |
738 | } | | 738 | } |
739 | | | 739 | |
740 | return AE_OK; | | 740 | return AE_OK; |
741 | } | | 741 | } |
742 | | | 742 | |
743 | static ACPI_STATUS | | 743 | static ACPI_STATUS |
744 | acpi_make_devnode_post(ACPI_HANDLE handle, uint32_t level, | | 744 | acpi_make_devnode_post(ACPI_HANDLE handle, uint32_t level, |
745 | void *context, void **status) | | 745 | void *context, void **status) |
746 | { | | 746 | { |
747 | struct acpi_walkcontext *awc = context; | | 747 | struct acpi_walkcontext *awc = context; |
748 | | | 748 | |
749 | KASSERT(awc != NULL); | | 749 | KASSERT(awc != NULL); |
750 | KASSERT(awc->aw_parent != NULL); | | 750 | KASSERT(awc->aw_parent != NULL); |
751 | | | 751 | |
752 | if (handle == awc->aw_parent->ad_handle) | | 752 | if (handle == awc->aw_parent->ad_handle) |
753 | awc->aw_parent = awc->aw_parent->ad_parent; | | 753 | awc->aw_parent = awc->aw_parent->ad_parent; |
754 | | | 754 | |
755 | return AE_OK; | | 755 | return AE_OK; |
756 | } | | 756 | } |
757 | | | 757 | |
758 | #ifdef ACPI_ACTIVATE_DEV | | 758 | #ifdef ACPI_ACTIVATE_DEV |
759 | static void | | 759 | static void |
760 | acpi_activate_device(ACPI_HANDLE handle, ACPI_DEVICE_INFO **di) | | 760 | acpi_activate_device(ACPI_HANDLE handle, ACPI_DEVICE_INFO **di) |
761 | { | | 761 | { |
762 | static const int valid = ACPI_VALID_STA | ACPI_VALID_HID; | | 762 | static const int valid = ACPI_VALID_STA | ACPI_VALID_HID; |
763 | ACPI_DEVICE_INFO *newdi; | | 763 | ACPI_DEVICE_INFO *newdi; |
764 | ACPI_STATUS rv; | | 764 | ACPI_STATUS rv; |
765 | uint32_t old; | | 765 | uint32_t old; |
766 | | | 766 | |
767 | /* | | 767 | /* |
768 | * If the device is valid and present, | | 768 | * If the device is valid and present, |
769 | * but not enabled, try to activate it. | | 769 | * but not enabled, try to activate it. |
770 | */ | | 770 | */ |
771 | if (((*di)->Valid & valid) != valid) | | 771 | if (((*di)->Valid & valid) != valid) |
772 | return; | | 772 | return; |
773 | | | 773 | |
774 | old = (*di)->CurrentStatus; | | 774 | old = (*di)->CurrentStatus; |
775 | | | 775 | |
776 | if ((old & (ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED)) != | | 776 | if ((old & (ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED)) != |
777 | ACPI_STA_DEVICE_PRESENT) | | 777 | ACPI_STA_DEVICE_PRESENT) |
778 | return; | | 778 | return; |
779 | | | 779 | |
780 | rv = acpi_allocate_resources(handle); | | 780 | rv = acpi_allocate_resources(handle); |
781 | | | 781 | |
782 | if (ACPI_FAILURE(rv)) | | 782 | if (ACPI_FAILURE(rv)) |
783 | goto fail; | | 783 | goto fail; |
784 | | | 784 | |
785 | rv = AcpiGetObjectInfo(handle, &newdi); | | 785 | rv = AcpiGetObjectInfo(handle, &newdi); |
786 | | | 786 | |
787 | if (ACPI_FAILURE(rv)) | | 787 | if (ACPI_FAILURE(rv)) |
788 | goto fail; | | 788 | goto fail; |
789 | | | 789 | |
790 | ACPI_FREE(*di); | | 790 | ACPI_FREE(*di); |
791 | *di = newdi; | | 791 | *di = newdi; |
792 | | | 792 | |
793 | aprint_verbose_dev(acpi_softc->sc_dev, | | 793 | aprint_verbose_dev(acpi_softc->sc_dev, |
794 | "%s activated, STA 0x%08X -> STA 0x%08X\n", | | 794 | "%s activated, STA 0x%08X -> STA 0x%08X\n", |
795 | (*di)->HardwareId.String, old, (*di)->CurrentStatus); | | 795 | (*di)->HardwareId.String, old, (*di)->CurrentStatus); |
796 | | | 796 | |
797 | return; | | 797 | return; |
798 | | | 798 | |
799 | fail: | | 799 | fail: |
800 | aprint_error_dev(acpi_softc->sc_dev, "failed to " | | 800 | aprint_error_dev(acpi_softc->sc_dev, "failed to " |
801 | "activate %s\n", (*di)->HardwareId.String); | | 801 | "activate %s\n", (*di)->HardwareId.String); |
802 | } | | 802 | } |
803 | | | 803 | |
804 | /* | | 804 | /* |
805 | * XXX: This very incomplete. | | 805 | * XXX: This very incomplete. |
806 | */ | | 806 | */ |
807 | ACPI_STATUS | | 807 | ACPI_STATUS |
808 | acpi_allocate_resources(ACPI_HANDLE handle) | | 808 | acpi_allocate_resources(ACPI_HANDLE handle) |
809 | { | | 809 | { |
810 | ACPI_BUFFER bufp, bufc, bufn; | | 810 | ACPI_BUFFER bufp, bufc, bufn; |
811 | ACPI_RESOURCE *resp, *resc, *resn; | | 811 | ACPI_RESOURCE *resp, *resc, *resn; |
812 | ACPI_RESOURCE_IRQ *irq; | | 812 | ACPI_RESOURCE_IRQ *irq; |
813 | ACPI_RESOURCE_EXTENDED_IRQ *xirq; | | 813 | ACPI_RESOURCE_EXTENDED_IRQ *xirq; |
814 | ACPI_STATUS rv; | | 814 | ACPI_STATUS rv; |
815 | uint delta; | | 815 | uint delta; |
816 | | | 816 | |
817 | rv = acpi_get(handle, &bufp, AcpiGetPossibleResources); | | 817 | rv = acpi_get(handle, &bufp, AcpiGetPossibleResources); |
818 | if (ACPI_FAILURE(rv)) | | 818 | if (ACPI_FAILURE(rv)) |
819 | goto out; | | 819 | goto out; |
820 | rv = acpi_get(handle, &bufc, AcpiGetCurrentResources); | | 820 | rv = acpi_get(handle, &bufc, AcpiGetCurrentResources); |
821 | if (ACPI_FAILURE(rv)) { | | 821 | if (ACPI_FAILURE(rv)) { |
822 | goto out1; | | 822 | goto out1; |
823 | } | | 823 | } |
824 | | | 824 | |
825 | bufn.Length = 1000; | | 825 | bufn.Length = 1000; |
826 | bufn.Pointer = resn = malloc(bufn.Length, M_ACPI, M_WAITOK); | | 826 | bufn.Pointer = resn = malloc(bufn.Length, M_ACPI, M_WAITOK); |
827 | resp = bufp.Pointer; | | 827 | resp = bufp.Pointer; |
828 | resc = bufc.Pointer; | | 828 | resc = bufc.Pointer; |
829 | while (resc->Type != ACPI_RESOURCE_TYPE_END_TAG && | | 829 | while (resc->Type != ACPI_RESOURCE_TYPE_END_TAG && |
830 | resp->Type != ACPI_RESOURCE_TYPE_END_TAG) { | | 830 | resp->Type != ACPI_RESOURCE_TYPE_END_TAG) { |
831 | while (resc->Type != resp->Type && resp->Type != ACPI_RESOURCE_TYPE_END_TAG) | | 831 | while (resc->Type != resp->Type && resp->Type != ACPI_RESOURCE_TYPE_END_TAG) |
832 | resp = ACPI_NEXT_RESOURCE(resp); | | 832 | resp = ACPI_NEXT_RESOURCE(resp); |
833 | if (resp->Type == ACPI_RESOURCE_TYPE_END_TAG) | | 833 | if (resp->Type == ACPI_RESOURCE_TYPE_END_TAG) |
834 | break; | | 834 | break; |
835 | /* Found identical Id */ | | 835 | /* Found identical Id */ |
836 | resn->Type = resc->Type; | | 836 | resn->Type = resc->Type; |
837 | switch (resc->Type) { | | 837 | switch (resc->Type) { |
838 | case ACPI_RESOURCE_TYPE_IRQ: | | 838 | case ACPI_RESOURCE_TYPE_IRQ: |
839 | memcpy(&resn->Data, &resp->Data, | | 839 | memcpy(&resn->Data, &resp->Data, |
840 | sizeof(ACPI_RESOURCE_IRQ)); | | 840 | sizeof(ACPI_RESOURCE_IRQ)); |
841 | irq = (ACPI_RESOURCE_IRQ *)&resn->Data; | | 841 | irq = (ACPI_RESOURCE_IRQ *)&resn->Data; |
842 | irq->Interrupts[0] = | | 842 | irq->Interrupts[0] = |
843 | ((ACPI_RESOURCE_IRQ *)&resp->Data)-> | | 843 | ((ACPI_RESOURCE_IRQ *)&resp->Data)-> |
844 | Interrupts[irq->InterruptCount-1]; | | 844 | Interrupts[irq->InterruptCount-1]; |
845 | irq->InterruptCount = 1; | | 845 | irq->InterruptCount = 1; |
846 | resn->Length = ACPI_RS_SIZE(ACPI_RESOURCE_IRQ); | | 846 | resn->Length = ACPI_RS_SIZE(ACPI_RESOURCE_IRQ); |
847 | break; | | 847 | break; |
848 | case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: | | 848 | case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: |
849 | memcpy(&resn->Data, &resp->Data, | | 849 | memcpy(&resn->Data, &resp->Data, |
850 | sizeof(ACPI_RESOURCE_EXTENDED_IRQ)); | | 850 | sizeof(ACPI_RESOURCE_EXTENDED_IRQ)); |
851 | xirq = (ACPI_RESOURCE_EXTENDED_IRQ *)&resn->Data; | | 851 | xirq = (ACPI_RESOURCE_EXTENDED_IRQ *)&resn->Data; |
852 | #if 0 | | 852 | #if 0 |
853 | /* | | 853 | /* |
854 | * XXX: Not duplicating the interrupt logic above | | 854 | * XXX: Not duplicating the interrupt logic above |
855 | * because its not clear what it accomplishes. | | 855 | * because its not clear what it accomplishes. |
856 | */ | | 856 | */ |
857 | xirq->Interrupts[0] = | | 857 | xirq->Interrupts[0] = |
858 | ((ACPI_RESOURCE_EXT_IRQ *)&resp->Data)-> | | 858 | ((ACPI_RESOURCE_EXT_IRQ *)&resp->Data)-> |
859 | Interrupts[irq->NumberOfInterrupts-1]; | | 859 | Interrupts[irq->NumberOfInterrupts-1]; |
860 | xirq->NumberOfInterrupts = 1; | | 860 | xirq->NumberOfInterrupts = 1; |
861 | #endif | | 861 | #endif |
862 | resn->Length = ACPI_RS_SIZE(ACPI_RESOURCE_EXTENDED_IRQ); | | 862 | resn->Length = ACPI_RS_SIZE(ACPI_RESOURCE_EXTENDED_IRQ); |
863 | break; | | 863 | break; |
864 | case ACPI_RESOURCE_TYPE_IO: | | 864 | case ACPI_RESOURCE_TYPE_IO: |
865 | memcpy(&resn->Data, &resp->Data, | | 865 | memcpy(&resn->Data, &resp->Data, |
866 | sizeof(ACPI_RESOURCE_IO)); | | 866 | sizeof(ACPI_RESOURCE_IO)); |
867 | resn->Length = resp->Length; | | 867 | resn->Length = resp->Length; |
868 | break; | | 868 | break; |
869 | default: | | 869 | default: |
870 | aprint_error_dev(acpi_softc->sc_dev, | | 870 | aprint_error_dev(acpi_softc->sc_dev, |
871 | "%s: invalid type %u\n", __func__, resc->Type); | | 871 | "%s: invalid type %u\n", __func__, resc->Type); |
872 | rv = AE_BAD_DATA; | | 872 | rv = AE_BAD_DATA; |
873 | goto out2; | | 873 | goto out2; |
874 | } | | 874 | } |
875 | resc = ACPI_NEXT_RESOURCE(resc); | | 875 | resc = ACPI_NEXT_RESOURCE(resc); |
876 | resn = ACPI_NEXT_RESOURCE(resn); | | 876 | resn = ACPI_NEXT_RESOURCE(resn); |
877 | resp = ACPI_NEXT_RESOURCE(resp); | | 877 | resp = ACPI_NEXT_RESOURCE(resp); |
878 | delta = (uint8_t *)resn - (uint8_t *)bufn.Pointer; | | 878 | delta = (uint8_t *)resn - (uint8_t *)bufn.Pointer; |
879 | if (delta >= | | 879 | if (delta >= |
880 | bufn.Length-ACPI_RS_SIZE(ACPI_RESOURCE_DATA)) { | | 880 | bufn.Length-ACPI_RS_SIZE(ACPI_RESOURCE_DATA)) { |
881 | bufn.Length *= 2; | | 881 | bufn.Length *= 2; |
882 | bufn.Pointer = realloc(bufn.Pointer, bufn.Length, | | 882 | bufn.Pointer = realloc(bufn.Pointer, bufn.Length, |
883 | M_ACPI, M_WAITOK); | | 883 | M_ACPI, M_WAITOK); |
884 | resn = (ACPI_RESOURCE *)((uint8_t *)bufn.Pointer + | | 884 | resn = (ACPI_RESOURCE *)((uint8_t *)bufn.Pointer + |
885 | delta); | | 885 | delta); |
886 | } | | 886 | } |
887 | } | | 887 | } |
888 | | | 888 | |
889 | if (resc->Type != ACPI_RESOURCE_TYPE_END_TAG) { | | 889 | if (resc->Type != ACPI_RESOURCE_TYPE_END_TAG) { |
890 | aprint_error_dev(acpi_softc->sc_dev, | | 890 | aprint_error_dev(acpi_softc->sc_dev, |
891 | "%s: resc not exhausted\n", __func__); | | 891 | "%s: resc not exhausted\n", __func__); |
892 | rv = AE_BAD_DATA; | | 892 | rv = AE_BAD_DATA; |
893 | goto out3; | | 893 | goto out3; |
894 | } | | 894 | } |
895 | | | 895 | |
896 | resn->Type = ACPI_RESOURCE_TYPE_END_TAG; | | 896 | resn->Type = ACPI_RESOURCE_TYPE_END_TAG; |
897 | rv = AcpiSetCurrentResources(handle, &bufn); | | 897 | rv = AcpiSetCurrentResources(handle, &bufn); |
898 | | | 898 | |
899 | if (ACPI_FAILURE(rv)) | | 899 | if (ACPI_FAILURE(rv)) |
900 | aprint_error_dev(acpi_softc->sc_dev, "%s: failed to set " | | 900 | aprint_error_dev(acpi_softc->sc_dev, "%s: failed to set " |
901 | "resources: %s\n", __func__, AcpiFormatException(rv)); | | 901 | "resources: %s\n", __func__, AcpiFormatException(rv)); |
902 | | | 902 | |
903 | out3: | | 903 | out3: |
904 | free(bufn.Pointer, M_ACPI); | | 904 | free(bufn.Pointer, M_ACPI); |
905 | out2: | | 905 | out2: |
906 | ACPI_FREE(bufc.Pointer); | | 906 | ACPI_FREE(bufc.Pointer); |
907 | out1: | | 907 | out1: |
908 | ACPI_FREE(bufp.Pointer); | | 908 | ACPI_FREE(bufp.Pointer); |
909 | out: | | 909 | out: |
910 | return rv; | | 910 | return rv; |
911 | } | | 911 | } |
912 | #endif /* ACPI_ACTIVATE_DEV */ | | 912 | #endif /* ACPI_ACTIVATE_DEV */ |
913 | | | 913 | |
914 | /* | | 914 | /* |
915 | * Device attachment. | | 915 | * Device attachment. |
916 | */ | | 916 | */ |
917 | static int | | 917 | static int |
918 | acpi_rescan(device_t self, const char *ifattr, const int *locators) | | 918 | acpi_rescan(device_t self, const char *ifattr, const int *locators) |
919 | { | | 919 | { |
920 | struct acpi_softc *sc = device_private(self); | | 920 | struct acpi_softc *sc = device_private(self); |
921 | | | 921 | |
922 | if (ifattr_match(ifattr, "acpinodebus")) | | 922 | if (ifattr_match(ifattr, "acpinodebus")) |
923 | acpi_rescan_nodes(sc); | | 923 | acpi_rescan_nodes(sc); |
924 | | | 924 | |
925 | if (ifattr_match(ifattr, "acpiapmbus") && sc->sc_apmbus == NULL) | | 925 | if (ifattr_match(ifattr, "acpiapmbus") && sc->sc_apmbus == NULL) |
926 | sc->sc_apmbus = config_found_ia(sc->sc_dev, | | 926 | sc->sc_apmbus = config_found_ia(sc->sc_dev, |
927 | "acpiapmbus", NULL, NULL); | | 927 | "acpiapmbus", NULL, NULL); |
928 | | | 928 | |
929 | return 0; | | 929 | return 0; |
930 | } | | 930 | } |
931 | | | 931 | |
932 | static void | | 932 | static void |
933 | acpi_rescan_nodes(struct acpi_softc *sc) | | 933 | acpi_rescan_nodes(struct acpi_softc *sc) |
934 | { | | 934 | { |
935 | struct acpi_attach_args aa; | | 935 | struct acpi_attach_args aa; |
936 | struct acpi_devnode *ad; | | 936 | struct acpi_devnode *ad; |
937 | ACPI_DEVICE_INFO *di; | | 937 | ACPI_DEVICE_INFO *di; |
938 | | | 938 | |
939 | SIMPLEQ_FOREACH(ad, &sc->ad_head, ad_list) { | | 939 | SIMPLEQ_FOREACH(ad, &sc->ad_head, ad_list) { |
940 | | | 940 | |
941 | if (ad->ad_device != NULL) | | 941 | if (ad->ad_device != NULL) |
942 | continue; | | 942 | continue; |
943 | | | 943 | |
944 | /* | | 944 | /* |
945 | * There is a bug in ACPICA: it defines the type | | 945 | * There is a bug in ACPICA: it defines the type |
946 | * of the scopes incorrectly for its own reasons. | | 946 | * of the scopes incorrectly for its own reasons. |
947 | */ | | 947 | */ |
948 | if (acpi_is_scope(ad) != false) | | 948 | if (acpi_is_scope(ad) != false) |
949 | continue; | | 949 | continue; |
950 | | | 950 | |
951 | di = ad->ad_devinfo; | | 951 | di = ad->ad_devinfo; |
952 | | | 952 | |
953 | /* | | 953 | /* |
954 | * We only attach devices which are present, enabled, and | | 954 | * We only attach devices which are present, enabled, and |
955 | * functioning properly. However, if a device is enabled, | | 955 | * functioning properly. However, if a device is enabled, |
956 | * it is decoding resources and we should claim these, | | 956 | * it is decoding resources and we should claim these, |
957 | * if possible. This requires changes to bus_space(9). | | 957 | * if possible. This requires changes to bus_space(9). |
958 | */ | | 958 | */ |
959 | if (di->Type == ACPI_TYPE_DEVICE) { | | 959 | if (di->Type == ACPI_TYPE_DEVICE) { |
960 | | | 960 | |
961 | if ((di->Valid & ACPI_VALID_STA) != 0 && | | 961 | if ((di->Valid & ACPI_VALID_STA) != 0 && |
962 | (di->CurrentStatus & ACPI_STA_OK) != ACPI_STA_OK) | | 962 | (di->CurrentStatus & ACPI_STA_OK) != ACPI_STA_OK) |
963 | continue; | | 963 | continue; |
964 | } | | 964 | } |
965 | | | 965 | |
966 | /* | | 966 | /* |
967 | * The same problem as above. As for example | | 967 | * The same problem as above. As for example |
968 | * thermal zones and power resources do not | | 968 | * thermal zones and power resources do not |
969 | * have a valid HID, only evaluate devices. | | 969 | * have a valid HID, only evaluate devices. |
970 | */ | | 970 | */ |
971 | if (di->Type == ACPI_TYPE_DEVICE && | | 971 | if (di->Type == ACPI_TYPE_DEVICE && |
972 | (di->Valid & ACPI_VALID_HID) == 0) | | 972 | (di->Valid & ACPI_VALID_HID) == 0) |
973 | continue; | | 973 | continue; |
974 | | | 974 | |
975 | /* | | 975 | /* |
976 | * Handled internally. | | 976 | * Handled internally. |
977 | */ | | 977 | */ |
978 | if (di->Type == ACPI_TYPE_POWER) | | 978 | if (di->Type == ACPI_TYPE_POWER) |
979 | continue; | | 979 | continue; |
980 | | | 980 | |
981 | /* | | 981 | /* |
982 | * Skip ignored HIDs. | | 982 | * Skip ignored HIDs. |
983 | */ | | 983 | */ |
984 | if (acpi_match_hid(di, acpi_ignored_ids)) | | 984 | if (acpi_match_hid(di, acpi_ignored_ids)) |
985 | continue; | | 985 | continue; |
986 | | | 986 | |
987 | aa.aa_node = ad; | | 987 | aa.aa_node = ad; |
988 | aa.aa_iot = sc->sc_iot; | | 988 | aa.aa_iot = sc->sc_iot; |
989 | aa.aa_memt = sc->sc_memt; | | 989 | aa.aa_memt = sc->sc_memt; |
990 | aa.aa_pc = sc->sc_pc; | | 990 | aa.aa_pc = sc->sc_pc; |
991 | aa.aa_pciflags = sc->sc_pciflags; | | 991 | aa.aa_pciflags = sc->sc_pciflags; |
992 | aa.aa_ic = sc->sc_ic; | | 992 | aa.aa_ic = sc->sc_ic; |
993 | | | 993 | |
994 | ad->ad_device = config_found_ia(sc->sc_dev, | | 994 | ad->ad_device = config_found_ia(sc->sc_dev, |
995 | "acpinodebus", &aa, acpi_print); | | 995 | "acpinodebus", &aa, acpi_print); |
996 | } | | 996 | } |
997 | } | | 997 | } |
998 | | | 998 | |
999 | static void | | 999 | static void |
1000 | acpi_rescan_capabilities(struct acpi_softc *sc) | | 1000 | acpi_rescan_capabilities(struct acpi_softc *sc) |
1001 | { | | 1001 | { |
1002 | struct acpi_devnode *ad; | | 1002 | struct acpi_devnode *ad; |
1003 | ACPI_HANDLE tmp; | | 1003 | ACPI_HANDLE tmp; |
1004 | ACPI_STATUS rv; | | 1004 | ACPI_STATUS rv; |
1005 | | | 1005 | |
1006 | SIMPLEQ_FOREACH(ad, &sc->ad_head, ad_list) { | | 1006 | SIMPLEQ_FOREACH(ad, &sc->ad_head, ad_list) { |
1007 | | | 1007 | |
1008 | if (ad->ad_devinfo->Type != ACPI_TYPE_DEVICE) | | 1008 | if (ad->ad_devinfo->Type != ACPI_TYPE_DEVICE) |
1009 | continue; | | 1009 | continue; |
1010 | | | 1010 | |
1011 | /* | | 1011 | /* |
1012 | * Scan power resource capabilities. | | 1012 | * Scan power resource capabilities. |
1013 | * | | 1013 | * |
1014 | * If any power states are supported, | | 1014 | * If any power states are supported, |
1015 | * at least _PR0 and _PR3 must be present. | | 1015 | * at least _PR0 and _PR3 must be present. |
1016 | */ | | 1016 | */ |
1017 | rv = AcpiGetHandle(ad->ad_handle, "_PR0", &tmp); | | 1017 | rv = AcpiGetHandle(ad->ad_handle, "_PR0", &tmp); |
1018 | | | 1018 | |
1019 | if (ACPI_SUCCESS(rv)) { | | 1019 | if (ACPI_SUCCESS(rv)) { |
1020 | ad->ad_flags |= ACPI_DEVICE_POWER; | | 1020 | ad->ad_flags |= ACPI_DEVICE_POWER; |
1021 | acpi_power_add(ad); | | 1021 | acpi_power_add(ad); |
1022 | } | | 1022 | } |
1023 | | | 1023 | |
1024 | /* | | 1024 | /* |
1025 | * Scan wake-up capabilities. | | 1025 | * Scan wake-up capabilities. |
1026 | */ | | 1026 | */ |
1027 | rv = AcpiGetHandle(ad->ad_handle, "_PRW", &tmp); | | 1027 | rv = AcpiGetHandle(ad->ad_handle, "_PRW", &tmp); |
1028 | | | 1028 | |
1029 | if (ACPI_SUCCESS(rv)) { | | 1029 | if (ACPI_SUCCESS(rv)) { |
1030 | ad->ad_flags |= ACPI_DEVICE_WAKEUP; | | 1030 | ad->ad_flags |= ACPI_DEVICE_WAKEUP; |
1031 | acpi_wakedev_add(ad); | | 1031 | acpi_wakedev_add(ad); |
1032 | } | | 1032 | } |
1033 | } | | 1033 | } |
1034 | } | | 1034 | } |
1035 | | | 1035 | |
1036 | static int | | 1036 | static int |
1037 | acpi_print(void *aux, const char *pnp) | | 1037 | acpi_print(void *aux, const char *pnp) |
1038 | { | | 1038 | { |
1039 | struct acpi_attach_args *aa = aux; | | 1039 | struct acpi_attach_args *aa = aux; |
1040 | ACPI_STATUS rv; | | 1040 | ACPI_STATUS rv; |
1041 | | | 1041 | |
1042 | if (pnp) { | | 1042 | if (pnp) { |
1043 | if (aa->aa_node->ad_devinfo->Valid & ACPI_VALID_HID) { | | 1043 | if (aa->aa_node->ad_devinfo->Valid & ACPI_VALID_HID) { |
1044 | char *pnpstr = | | 1044 | char *pnpstr = |
1045 | aa->aa_node->ad_devinfo->HardwareId.String; | | 1045 | aa->aa_node->ad_devinfo->HardwareId.String; |
1046 | ACPI_BUFFER buf; | | 1046 | ACPI_BUFFER buf; |
1047 | | | 1047 | |
1048 | aprint_normal("%s (%s) ", aa->aa_node->ad_name, | | 1048 | aprint_normal("%s (%s) ", aa->aa_node->ad_name, |
1049 | pnpstr); | | 1049 | pnpstr); |
1050 | | | 1050 | |
1051 | rv = acpi_eval_struct(aa->aa_node->ad_handle, | | 1051 | rv = acpi_eval_struct(aa->aa_node->ad_handle, |
1052 | "_STR", &buf); | | 1052 | "_STR", &buf); |
1053 | if (ACPI_SUCCESS(rv)) { | | 1053 | if (ACPI_SUCCESS(rv)) { |
1054 | ACPI_OBJECT *obj = buf.Pointer; | | 1054 | ACPI_OBJECT *obj = buf.Pointer; |
1055 | switch (obj->Type) { | | 1055 | switch (obj->Type) { |
1056 | case ACPI_TYPE_STRING: | | 1056 | case ACPI_TYPE_STRING: |
1057 | aprint_normal("[%s] ", obj->String.Pointer); | | 1057 | aprint_normal("[%s] ", obj->String.Pointer); |
1058 | break; | | 1058 | break; |
1059 | case ACPI_TYPE_BUFFER: | | 1059 | case ACPI_TYPE_BUFFER: |
1060 | aprint_normal("buffer %p ", obj->Buffer.Pointer); | | 1060 | aprint_normal("buffer %p ", obj->Buffer.Pointer); |
1061 | break; | | 1061 | break; |
1062 | default: | | 1062 | default: |
1063 | aprint_normal("type %u ",obj->Type); | | 1063 | aprint_normal("type %u ",obj->Type); |
1064 | break; | | 1064 | break; |
1065 | } | | 1065 | } |
1066 | ACPI_FREE(buf.Pointer); | | 1066 | ACPI_FREE(buf.Pointer); |
1067 | } | | 1067 | } |
1068 | else | | 1068 | else |
1069 | acpi_print_dev(pnpstr); | | 1069 | acpi_print_dev(pnpstr); |
1070 | | | 1070 | |
1071 | aprint_normal("at %s", pnp); | | 1071 | aprint_normal("at %s", pnp); |
1072 | } else if (aa->aa_node->ad_devinfo->Type != ACPI_TYPE_DEVICE) { | | 1072 | } else if (aa->aa_node->ad_devinfo->Type != ACPI_TYPE_DEVICE) { |
1073 | aprint_normal("%s (ACPI Object Type '%s' " | | 1073 | aprint_normal("%s (ACPI Object Type '%s' " |
1074 | "[0x%02x]) ", aa->aa_node->ad_name, | | 1074 | "[0x%02x]) ", aa->aa_node->ad_name, |
1075 | AcpiUtGetTypeName(aa->aa_node->ad_devinfo->Type), | | 1075 | AcpiUtGetTypeName(aa->aa_node->ad_devinfo->Type), |
1076 | aa->aa_node->ad_devinfo->Type); | | 1076 | aa->aa_node->ad_devinfo->Type); |
1077 | aprint_normal("at %s", pnp); | | 1077 | aprint_normal("at %s", pnp); |
1078 | } else | | 1078 | } else |
1079 | return 0; | | 1079 | return 0; |
1080 | } else { | | 1080 | } else { |
1081 | aprint_normal(" (%s", aa->aa_node->ad_name); | | 1081 | aprint_normal(" (%s", aa->aa_node->ad_name); |
1082 | if (aa->aa_node->ad_devinfo->Valid & ACPI_VALID_HID) { | | 1082 | if (aa->aa_node->ad_devinfo->Valid & ACPI_VALID_HID) { |
1083 | aprint_normal(", %s", aa->aa_node->ad_devinfo->HardwareId.String); | | 1083 | aprint_normal(", %s", aa->aa_node->ad_devinfo->HardwareId.String); |
1084 | if (aa->aa_node->ad_devinfo->Valid & ACPI_VALID_UID) { | | 1084 | if (aa->aa_node->ad_devinfo->Valid & ACPI_VALID_UID) { |
1085 | const char *uid; | | 1085 | const char *uid; |
1086 | | | 1086 | |
1087 | uid = aa->aa_node->ad_devinfo->UniqueId.String; | | 1087 | uid = aa->aa_node->ad_devinfo->UniqueId.String; |
1088 | if (uid[0] == '\0') | | 1088 | if (uid[0] == '\0') |
1089 | uid = "<null>"; | | 1089 | uid = "<null>"; |
1090 | aprint_normal("-%s", uid); | | 1090 | aprint_normal("-%s", uid); |
1091 | } | | 1091 | } |
1092 | } | | 1092 | } |
1093 | aprint_normal(")"); | | 1093 | aprint_normal(")"); |
1094 | } | | 1094 | } |
1095 | | | 1095 | |
1096 | return UNCONF; | | 1096 | return UNCONF; |
1097 | } | | 1097 | } |
1098 | | | 1098 | |
1099 | /* | | 1099 | /* |
1100 | * Notify. | | 1100 | * Notify. |
1101 | */ | | 1101 | */ |
1102 | static void | | 1102 | static void |
1103 | acpi_notify_handler(ACPI_HANDLE handle, uint32_t event, void *aux) | | 1103 | acpi_notify_handler(ACPI_HANDLE handle, uint32_t event, void *aux) |
1104 | { | | 1104 | { |
1105 | struct acpi_softc *sc = acpi_softc; | | 1105 | struct acpi_softc *sc = acpi_softc; |
1106 | struct acpi_devnode *ad; | | 1106 | struct acpi_devnode *ad; |
1107 | | | 1107 | |
1108 | KASSERT(sc != NULL); | | 1108 | KASSERT(sc != NULL); |
1109 | KASSERT(aux == NULL); | | 1109 | KASSERT(aux == NULL); |
1110 | KASSERT(acpi_active != 0); | | 1110 | KASSERT(acpi_active != 0); |
1111 | | | 1111 | |
1112 | if (acpi_suspended != 0) | | 1112 | if (acpi_suspended != 0) |
1113 | return; | | 1113 | return; |
1114 | | | 1114 | |
1115 | /* | | 1115 | /* |
1116 | * System: 0x00 - 0x7F. | | 1116 | * System: 0x00 - 0x7F. |
1117 | * Device: 0x80 - 0xFF. | | 1117 | * Device: 0x80 - 0xFF. |
1118 | */ | | 1118 | */ |
1119 | switch (event) { | | 1119 | switch (event) { |
1120 | | | 1120 | |
1121 | case ACPI_NOTIFY_BUS_CHECK: | | 1121 | case ACPI_NOTIFY_BUS_CHECK: |
1122 | case ACPI_NOTIFY_DEVICE_CHECK: | | 1122 | case ACPI_NOTIFY_DEVICE_CHECK: |
1123 | case ACPI_NOTIFY_DEVICE_WAKE: | | 1123 | case ACPI_NOTIFY_DEVICE_WAKE: |
1124 | case ACPI_NOTIFY_EJECT_REQUEST: | | 1124 | case ACPI_NOTIFY_EJECT_REQUEST: |
1125 | case ACPI_NOTIFY_DEVICE_CHECK_LIGHT: | | 1125 | case ACPI_NOTIFY_DEVICE_CHECK_LIGHT: |
1126 | case ACPI_NOTIFY_FREQUENCY_MISMATCH: | | 1126 | case ACPI_NOTIFY_FREQUENCY_MISMATCH: |
1127 | case ACPI_NOTIFY_BUS_MODE_MISMATCH: | | 1127 | case ACPI_NOTIFY_BUS_MODE_MISMATCH: |
1128 | case ACPI_NOTIFY_POWER_FAULT: | | 1128 | case ACPI_NOTIFY_POWER_FAULT: |
1129 | case ACPI_NOTIFY_CAPABILITIES_CHECK: | | 1129 | case ACPI_NOTIFY_CAPABILITIES_CHECK: |
1130 | case ACPI_NOTIFY_DEVICE_PLD_CHECK: | | 1130 | case ACPI_NOTIFY_DEVICE_PLD_CHECK: |
1131 | case ACPI_NOTIFY_RESERVED: | | 1131 | case ACPI_NOTIFY_RESERVED: |
1132 | case ACPI_NOTIFY_LOCALITY_UPDATE: | | 1132 | case ACPI_NOTIFY_LOCALITY_UPDATE: |
1133 | break; | | 1133 | break; |
1134 | } | | 1134 | } |
1135 | | | 1135 | |
1136 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "notification 0x%02X for " | | 1136 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "notification 0x%02X for " |
1137 | "%s (%p)\n", event, acpi_name(handle), handle)); | | 1137 | "%s (%p)\n", event, acpi_name(handle), handle)); |
1138 | | | 1138 | |
1139 | /* | | 1139 | /* |
1140 | * We deliver notifications only to drivers | | 1140 | * We deliver notifications only to drivers |
1141 | * that have been succesfully attached and | | 1141 | * that have been succesfully attached and |
1142 | * that have registered a handler with us. | | 1142 | * that have registered a handler with us. |
1143 | * The opaque pointer is always the device_t. | | 1143 | * The opaque pointer is always the device_t. |
1144 | */ | | 1144 | */ |
1145 | SIMPLEQ_FOREACH(ad, &sc->ad_head, ad_list) { | | 1145 | SIMPLEQ_FOREACH(ad, &sc->ad_head, ad_list) { |
1146 | | | 1146 | |
1147 | if (ad->ad_device == NULL) | | 1147 | if (ad->ad_device == NULL) |
1148 | continue; | | 1148 | continue; |
1149 | | | 1149 | |
1150 | if (ad->ad_notify == NULL) | | 1150 | if (ad->ad_notify == NULL) |
1151 | continue; | | 1151 | continue; |
1152 | | | 1152 | |
1153 | if (ad->ad_handle != handle) | | 1153 | if (ad->ad_handle != handle) |
1154 | continue; | | 1154 | continue; |
1155 | | | 1155 | |
1156 | (*ad->ad_notify)(ad->ad_handle, event, ad->ad_device); | | 1156 | (*ad->ad_notify)(ad->ad_handle, event, ad->ad_device); |
1157 | | | 1157 | |
1158 | return; | | 1158 | return; |
1159 | } | | 1159 | } |
1160 | | | 1160 | |
1161 | aprint_debug_dev(sc->sc_dev, "unhandled notify 0x%02X " | | 1161 | aprint_debug_dev(sc->sc_dev, "unhandled notify 0x%02X " |
1162 | "for %s (%p)\n", event, acpi_name(handle), handle); | | 1162 | "for %s (%p)\n", event, acpi_name(handle), handle); |
1163 | } | | 1163 | } |
1164 | | | 1164 | |
1165 | bool | | 1165 | bool |