acpi.c revision 1.148.2.4 1 1.148.2.4 uebayasi /* $NetBSD: acpi.c,v 1.148.2.4 2010/11/06 08:08:27 uebayasi Exp $ */
2 1.50 mycroft
3 1.50 mycroft /*-
4 1.101 ad * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
5 1.50 mycroft * All rights reserved.
6 1.50 mycroft *
7 1.50 mycroft * This code is derived from software contributed to The NetBSD Foundation
8 1.50 mycroft * by Charles M. Hannum of By Noon Software, Inc.
9 1.50 mycroft *
10 1.50 mycroft * Redistribution and use in source and binary forms, with or without
11 1.50 mycroft * modification, are permitted provided that the following conditions
12 1.50 mycroft * are met:
13 1.50 mycroft * 1. Redistributions of source code must retain the above copyright
14 1.50 mycroft * notice, this list of conditions and the following disclaimer.
15 1.50 mycroft * 2. Redistributions in binary form must reproduce the above copyright
16 1.50 mycroft * notice, this list of conditions and the following disclaimer in the
17 1.50 mycroft * documentation and/or other materials provided with the distribution.
18 1.50 mycroft *
19 1.50 mycroft * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.50 mycroft * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.50 mycroft * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.50 mycroft * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.50 mycroft * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.50 mycroft * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.50 mycroft * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.50 mycroft * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.50 mycroft * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.50 mycroft * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.50 mycroft * POSSIBILITY OF SUCH DAMAGE.
30 1.50 mycroft */
31 1.1 thorpej
32 1.1 thorpej /*
33 1.148.2.2 uebayasi * Copyright (c) 2003 Wasabi Systems, Inc.
34 1.148.2.2 uebayasi * All rights reserved.
35 1.148.2.2 uebayasi *
36 1.148.2.2 uebayasi * Written by Frank van der Linden for Wasabi Systems, Inc.
37 1.148.2.2 uebayasi *
38 1.148.2.2 uebayasi * Redistribution and use in source and binary forms, with or without
39 1.148.2.2 uebayasi * modification, are permitted provided that the following conditions
40 1.148.2.2 uebayasi * are met:
41 1.148.2.2 uebayasi * 1. Redistributions of source code must retain the above copyright
42 1.148.2.2 uebayasi * notice, this list of conditions and the following disclaimer.
43 1.148.2.2 uebayasi * 2. Redistributions in binary form must reproduce the above copyright
44 1.148.2.2 uebayasi * notice, this list of conditions and the following disclaimer in the
45 1.148.2.2 uebayasi * documentation and/or other materials provided with the distribution.
46 1.148.2.2 uebayasi * 3. All advertising materials mentioning features or use of this software
47 1.148.2.2 uebayasi * must display the following acknowledgement:
48 1.148.2.2 uebayasi * This product includes software developed for the NetBSD Project by
49 1.148.2.2 uebayasi * Wasabi Systems, Inc.
50 1.148.2.2 uebayasi * 4. The name of Wasabi Systems, Inc. may not be used to endorse
51 1.148.2.2 uebayasi * or promote products derived from this software without specific prior
52 1.148.2.2 uebayasi * written permission.
53 1.148.2.2 uebayasi *
54 1.148.2.2 uebayasi * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
55 1.148.2.2 uebayasi * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
56 1.148.2.2 uebayasi * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
57 1.148.2.2 uebayasi * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
58 1.148.2.2 uebayasi * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
59 1.148.2.2 uebayasi * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
60 1.148.2.2 uebayasi * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
61 1.148.2.2 uebayasi * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
62 1.148.2.2 uebayasi * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
63 1.148.2.2 uebayasi * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
64 1.148.2.2 uebayasi * POSSIBILITY OF SUCH DAMAGE.
65 1.148.2.2 uebayasi */
66 1.148.2.2 uebayasi
67 1.148.2.2 uebayasi /*
68 1.34 thorpej * Copyright 2001, 2003 Wasabi Systems, Inc.
69 1.1 thorpej * All rights reserved.
70 1.1 thorpej *
71 1.1 thorpej * Written by Jason R. Thorpe for Wasabi Systems, Inc.
72 1.1 thorpej *
73 1.1 thorpej * Redistribution and use in source and binary forms, with or without
74 1.1 thorpej * modification, are permitted provided that the following conditions
75 1.1 thorpej * are met:
76 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
77 1.1 thorpej * notice, this list of conditions and the following disclaimer.
78 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
79 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
80 1.1 thorpej * documentation and/or other materials provided with the distribution.
81 1.1 thorpej * 3. All advertising materials mentioning features or use of this software
82 1.1 thorpej * must display the following acknowledgement:
83 1.1 thorpej * This product includes software developed for the NetBSD Project by
84 1.1 thorpej * Wasabi Systems, Inc.
85 1.1 thorpej * 4. The name of Wasabi Systems, Inc. may not be used to endorse
86 1.1 thorpej * or promote products derived from this software without specific prior
87 1.1 thorpej * written permission.
88 1.1 thorpej *
89 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
90 1.1 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
91 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
92 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
93 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
94 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
95 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
96 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
97 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
98 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
99 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
100 1.1 thorpej */
101 1.1 thorpej
102 1.5 lukem #include <sys/cdefs.h>
103 1.148.2.4 uebayasi __KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.148.2.4 2010/11/06 08:08:27 uebayasi Exp $");
104 1.27 christos
105 1.27 christos #include "opt_acpi.h"
106 1.73 sekiya #include "opt_pcifixup.h"
107 1.1 thorpej
108 1.1 thorpej #include <sys/param.h>
109 1.1 thorpej #include <sys/device.h>
110 1.148.2.1 uebayasi #include <sys/kernel.h>
111 1.1 thorpej #include <sys/malloc.h>
112 1.148.2.2 uebayasi #include <sys/module.h>
113 1.100 xtraeme #include <sys/mutex.h>
114 1.78 cube #include <sys/sysctl.h>
115 1.148.2.1 uebayasi #include <sys/systm.h>
116 1.148.2.2 uebayasi #include <sys/timetc.h>
117 1.1 thorpej
118 1.1 thorpej #include <dev/acpi/acpireg.h>
119 1.1 thorpej #include <dev/acpi/acpivar.h>
120 1.1 thorpej #include <dev/acpi/acpi_osd.h>
121 1.148.2.1 uebayasi #include <dev/acpi/acpi_pci.h>
122 1.148.2.1 uebayasi #include <dev/acpi/acpi_power.h>
123 1.90 drochner #include <dev/acpi/acpi_timer.h>
124 1.127 jmcneill #include <dev/acpi/acpi_wakedev.h>
125 1.148.2.1 uebayasi
126 1.148.2.1 uebayasi #define _COMPONENT ACPI_BUS_COMPONENT
127 1.148.2.1 uebayasi ACPI_MODULE_NAME ("acpi")
128 1.132 mlelstv
129 1.74 sekiya #if defined(ACPI_PCI_FIXUP)
130 1.93 christos #error The option ACPI_PCI_FIXUP has been obsoleted by PCI_INTR_FIXUP_DISABLED. Please adjust your kernel configuration file.
131 1.74 sekiya #endif
132 1.74 sekiya
133 1.93 christos #ifdef PCI_INTR_FIXUP_DISABLED
134 1.13 augustss #include <dev/pci/pcidevs.h>
135 1.13 augustss #endif
136 1.13 augustss
137 1.33 christos MALLOC_DECLARE(M_ACPI);
138 1.33 christos
139 1.10 tshiozak #include <machine/acpi_machdep.h>
140 1.39 kochi
141 1.40 kochi #ifdef ACPI_DEBUGGER
142 1.1 thorpej #define ACPI_DBGR_INIT 0x01
143 1.1 thorpej #define ACPI_DBGR_TABLES 0x02
144 1.1 thorpej #define ACPI_DBGR_ENABLE 0x04
145 1.1 thorpej #define ACPI_DBGR_PROBE 0x08
146 1.1 thorpej #define ACPI_DBGR_RUNNING 0x10
147 1.1 thorpej
148 1.82 kochi static int acpi_dbgr = 0x00;
149 1.1 thorpej #endif
150 1.1 thorpej
151 1.1 thorpej /*
152 1.1 thorpej * This is a flag we set when the ACPI subsystem is active. Machine
153 1.1 thorpej * dependent code may wish to skip other steps (such as attaching
154 1.1 thorpej * subsystems that ACPI supercedes) when ACPI is active.
155 1.1 thorpej */
156 1.1 thorpej int acpi_active;
157 1.148.2.3 uebayasi
158 1.148.2.3 uebayasi int acpi_force_load = 0;
159 1.123 jmcneill int acpi_suspended = 0;
160 1.148.2.2 uebayasi int acpi_verbose_loaded = 0;
161 1.1 thorpej
162 1.148.2.2 uebayasi struct acpi_softc *acpi_softc;
163 1.148.2.2 uebayasi static uint64_t acpi_root_pointer;
164 1.148.2.2 uebayasi extern kmutex_t acpi_interrupt_list_mtx;
165 1.148.2.2 uebayasi extern struct cfdriver acpi_cd;
166 1.148.2.2 uebayasi static ACPI_HANDLE acpi_scopes[4];
167 1.148.2.2 uebayasi ACPI_TABLE_HEADER *madt_header;
168 1.1 thorpej
169 1.32 tshiozak /*
170 1.148.2.1 uebayasi * This structure provides a context for the ACPI
171 1.148.2.1 uebayasi * namespace walk performed in acpi_build_tree().
172 1.32 tshiozak */
173 1.148.2.1 uebayasi struct acpi_walkcontext {
174 1.148.2.1 uebayasi struct acpi_softc *aw_sc;
175 1.148.2.1 uebayasi struct acpi_devnode *aw_parent;
176 1.148.2.1 uebayasi };
177 1.32 tshiozak
178 1.79 cube /*
179 1.147 jruoho * Ignored HIDs.
180 1.116 jmcneill */
181 1.116 jmcneill static const char * const acpi_ignored_ids[] = {
182 1.116 jmcneill #if defined(i386) || defined(x86_64)
183 1.116 jmcneill "PNP0000", /* AT interrupt controller is handled internally */
184 1.116 jmcneill "PNP0200", /* AT DMA controller is handled internally */
185 1.137 cegger "PNP0A??", /* PCI Busses are handled internally */
186 1.116 jmcneill "PNP0B00", /* AT RTC is handled internally */
187 1.116 jmcneill "PNP0C0F", /* ACPI PCI link devices are handled internally */
188 1.116 jmcneill #endif
189 1.116 jmcneill #if defined(x86_64)
190 1.116 jmcneill "PNP0C04", /* FPU is handled internally */
191 1.116 jmcneill #endif
192 1.116 jmcneill NULL
193 1.116 jmcneill };
194 1.116 jmcneill
195 1.148.2.1 uebayasi static int acpi_match(device_t, cfdata_t, void *);
196 1.148.2.1 uebayasi static int acpi_submatch(device_t, cfdata_t, const int *, void *);
197 1.148.2.1 uebayasi static void acpi_attach(device_t, device_t, void *);
198 1.148.2.1 uebayasi static int acpi_detach(device_t, int);
199 1.148.2.1 uebayasi static void acpi_childdet(device_t, device_t);
200 1.148.2.1 uebayasi static bool acpi_suspend(device_t, const pmf_qual_t *);
201 1.148.2.1 uebayasi static bool acpi_resume(device_t, const pmf_qual_t *);
202 1.78 cube
203 1.64 kochi static void acpi_build_tree(struct acpi_softc *);
204 1.148.2.1 uebayasi static ACPI_STATUS acpi_make_devnode(ACPI_HANDLE, uint32_t,
205 1.148.2.1 uebayasi void *, void **);
206 1.148.2.1 uebayasi static ACPI_STATUS acpi_make_devnode_post(ACPI_HANDLE, uint32_t,
207 1.148.2.1 uebayasi void *, void **);
208 1.148.2.1 uebayasi
209 1.148.2.1 uebayasi #ifdef ACPI_ACTIVATE_DEV
210 1.148.2.1 uebayasi static void acpi_activate_device(ACPI_HANDLE, ACPI_DEVICE_INFO **);
211 1.148.2.1 uebayasi static ACPI_STATUS acpi_allocate_resources(ACPI_HANDLE);
212 1.148.2.1 uebayasi #endif
213 1.148.2.1 uebayasi
214 1.148.2.1 uebayasi static int acpi_rescan(device_t, const char *, const int *);
215 1.148.2.1 uebayasi static void acpi_rescan_nodes(struct acpi_softc *);
216 1.148.2.1 uebayasi static void acpi_rescan_capabilities(struct acpi_softc *);
217 1.148.2.1 uebayasi static int acpi_print(void *aux, const char *);
218 1.148.2.1 uebayasi
219 1.148.2.1 uebayasi static void acpi_notify_handler(ACPI_HANDLE, uint32_t, void *);
220 1.148.2.1 uebayasi
221 1.148.2.1 uebayasi static void acpi_register_fixed_button(struct acpi_softc *, int);
222 1.148.2.1 uebayasi static void acpi_deregister_fixed_button(struct acpi_softc *, int);
223 1.148.2.1 uebayasi static uint32_t acpi_fixed_button_handler(void *);
224 1.148.2.1 uebayasi static void acpi_fixed_button_pressed(void *);
225 1.148.2.1 uebayasi
226 1.148.2.1 uebayasi static void acpi_sleep_init(struct acpi_softc *);
227 1.1 thorpej
228 1.148.2.2 uebayasi static int sysctl_hw_acpi_fixedstats(SYSCTLFN_PROTO);
229 1.148.2.2 uebayasi static int sysctl_hw_acpi_sleepstate(SYSCTLFN_PROTO);
230 1.148.2.2 uebayasi static int sysctl_hw_acpi_sleepstates(SYSCTLFN_PROTO);
231 1.1 thorpej
232 1.148.2.1 uebayasi static bool acpi_is_scope(struct acpi_devnode *);
233 1.108 jmcneill static ACPI_TABLE_HEADER *acpi_map_rsdt(void);
234 1.148.2.1 uebayasi static void acpi_unmap_rsdt(ACPI_TABLE_HEADER *);
235 1.108 jmcneill
236 1.148.2.2 uebayasi void acpi_print_verbose_stub(struct acpi_softc *);
237 1.148.2.2 uebayasi void acpi_print_dev_stub(const char *);
238 1.148.2.2 uebayasi
239 1.148.2.2 uebayasi void (*acpi_print_verbose)(struct acpi_softc *) = acpi_print_verbose_stub;
240 1.148.2.2 uebayasi void (*acpi_print_dev)(const char *) = acpi_print_dev_stub;
241 1.148.2.1 uebayasi
242 1.148.2.1 uebayasi CFATTACH_DECL2_NEW(acpi, sizeof(struct acpi_softc),
243 1.148.2.1 uebayasi acpi_match, acpi_attach, acpi_detach, NULL, acpi_rescan, acpi_childdet);
244 1.123 jmcneill
245 1.1 thorpej /*
246 1.148.2.1 uebayasi * Probe for ACPI support.
247 1.1 thorpej *
248 1.148.2.1 uebayasi * This is called by the machine-dependent ACPI front-end.
249 1.148.2.1 uebayasi * Note: this is not an autoconfiguration interface function.
250 1.1 thorpej */
251 1.1 thorpej int
252 1.1 thorpej acpi_probe(void)
253 1.1 thorpej {
254 1.108 jmcneill ACPI_TABLE_HEADER *rsdt;
255 1.148.2.1 uebayasi const char *func;
256 1.148.2.1 uebayasi static int once;
257 1.148.2.1 uebayasi bool initialized;
258 1.1 thorpej ACPI_STATUS rv;
259 1.1 thorpej
260 1.148.2.1 uebayasi if (once != 0)
261 1.148.2.1 uebayasi panic("%s: already probed", __func__);
262 1.148.2.1 uebayasi
263 1.148.2.1 uebayasi once = 1;
264 1.148.2.1 uebayasi func = NULL;
265 1.148.2.4 uebayasi acpi_softc = NULL;
266 1.148.2.1 uebayasi initialized = false;
267 1.1 thorpej
268 1.103 ad mutex_init(&acpi_interrupt_list_mtx, MUTEX_DEFAULT, IPL_NONE);
269 1.32 tshiozak
270 1.1 thorpej /*
271 1.1 thorpej * Start up ACPICA.
272 1.1 thorpej */
273 1.40 kochi #ifdef ACPI_DEBUGGER
274 1.1 thorpej if (acpi_dbgr & ACPI_DBGR_INIT)
275 1.1 thorpej acpi_osd_debugger();
276 1.1 thorpej #endif
277 1.1 thorpej
278 1.148.2.1 uebayasi CTASSERT(TRUE == true);
279 1.148.2.1 uebayasi CTASSERT(FALSE == false);
280 1.148.2.1 uebayasi
281 1.148.2.1 uebayasi AcpiGbl_AllMethodsSerialized = false;
282 1.148.2.1 uebayasi AcpiGbl_EnableInterpreterSlack = true;
283 1.104 jmcneill
284 1.1 thorpej rv = AcpiInitializeSubsystem();
285 1.1 thorpej
286 1.148.2.1 uebayasi if (ACPI_SUCCESS(rv))
287 1.148.2.1 uebayasi initialized = true;
288 1.148.2.1 uebayasi else {
289 1.148.2.1 uebayasi func = "AcpiInitializeSubsystem()";
290 1.148.2.1 uebayasi goto fail;
291 1.104 jmcneill }
292 1.104 jmcneill
293 1.148.2.1 uebayasi /*
294 1.148.2.1 uebayasi * Allocate space for RSDT/XSDT and DSDT,
295 1.148.2.1 uebayasi * but allow resizing if more tables exist.
296 1.148.2.1 uebayasi */
297 1.148.2.1 uebayasi rv = AcpiInitializeTables(NULL, 2, true);
298 1.148.2.1 uebayasi
299 1.104 jmcneill if (ACPI_FAILURE(rv)) {
300 1.148.2.1 uebayasi func = "AcpiInitializeTables()";
301 1.148.2.1 uebayasi goto fail;
302 1.104 jmcneill }
303 1.104 jmcneill
304 1.40 kochi #ifdef ACPI_DEBUGGER
305 1.1 thorpej if (acpi_dbgr & ACPI_DBGR_TABLES)
306 1.1 thorpej acpi_osd_debugger();
307 1.1 thorpej #endif
308 1.1 thorpej
309 1.1 thorpej rv = AcpiLoadTables();
310 1.148.2.1 uebayasi
311 1.56 mycroft if (ACPI_FAILURE(rv)) {
312 1.148.2.1 uebayasi func = "AcpiLoadTables()";
313 1.148.2.1 uebayasi goto fail;
314 1.1 thorpej }
315 1.1 thorpej
316 1.108 jmcneill rsdt = acpi_map_rsdt();
317 1.148.2.1 uebayasi
318 1.108 jmcneill if (rsdt == NULL) {
319 1.148.2.1 uebayasi func = "acpi_map_rsdt()";
320 1.148.2.1 uebayasi rv = AE_ERROR;
321 1.148.2.1 uebayasi goto fail;
322 1.108 jmcneill }
323 1.107 jmcneill
324 1.148.2.1 uebayasi if (acpi_force_load == 0 && (acpi_find_quirks() & ACPI_QUIRK_BROKEN)) {
325 1.148.2.1 uebayasi aprint_normal("ACPI: BIOS is listed as broken:\n");
326 1.148.2.1 uebayasi aprint_normal("ACPI: X/RSDT: OemId <%6.6s,%8.8s,%08x>, "
327 1.93 christos "AslId <%4.4s,%08x>\n",
328 1.108 jmcneill rsdt->OemId, rsdt->OemTableId,
329 1.108 jmcneill rsdt->OemRevision,
330 1.108 jmcneill rsdt->AslCompilerId,
331 1.108 jmcneill rsdt->AslCompilerRevision);
332 1.148.2.1 uebayasi aprint_normal("ACPI: Not used. Set acpi_force_load to use.\n");
333 1.108 jmcneill acpi_unmap_rsdt(rsdt);
334 1.130 jmcneill AcpiTerminate();
335 1.93 christos return 0;
336 1.93 christos }
337 1.148.2.3 uebayasi if (acpi_force_load == 0 && (acpi_find_quirks() & ACPI_QUIRK_OLDBIOS)) {
338 1.148.2.3 uebayasi aprint_normal("ACPI: BIOS is too old (%s). Set acpi_force_load to use.\n",
339 1.148.2.3 uebayasi pmf_get_platform("firmware-date"));
340 1.148.2.3 uebayasi acpi_unmap_rsdt(rsdt);
341 1.148.2.3 uebayasi AcpiTerminate();
342 1.148.2.3 uebayasi return 0;
343 1.148.2.3 uebayasi }
344 1.93 christos
345 1.108 jmcneill acpi_unmap_rsdt(rsdt);
346 1.108 jmcneill
347 1.104 jmcneill rv = AcpiEnableSubsystem(~(ACPI_NO_HARDWARE_INIT|ACPI_NO_ACPI_ENABLE));
348 1.148.2.1 uebayasi
349 1.104 jmcneill if (ACPI_FAILURE(rv)) {
350 1.148.2.1 uebayasi func = "AcpiEnableSubsystem()";
351 1.148.2.1 uebayasi goto fail;
352 1.104 jmcneill }
353 1.104 jmcneill
354 1.1 thorpej /*
355 1.1 thorpej * Looks like we have ACPI!
356 1.1 thorpej */
357 1.63 kochi return 1;
358 1.1 thorpej
359 1.148.2.1 uebayasi fail:
360 1.148.2.1 uebayasi KASSERT(rv != AE_OK);
361 1.148.2.1 uebayasi KASSERT(func != NULL);
362 1.98 cube
363 1.148.2.1 uebayasi aprint_error("%s: failed to probe ACPI: %s\n",
364 1.148.2.1 uebayasi func, AcpiFormatException(rv));
365 1.148.2.1 uebayasi
366 1.148.2.1 uebayasi if (initialized != false)
367 1.148.2.1 uebayasi (void)AcpiTerminate();
368 1.148.2.1 uebayasi
369 1.148.2.1 uebayasi return 0;
370 1.98 cube }
371 1.98 cube
372 1.148.2.2 uebayasi void
373 1.148.2.2 uebayasi acpi_disable(void)
374 1.148.2.2 uebayasi {
375 1.148.2.2 uebayasi
376 1.148.2.4 uebayasi if (acpi_softc == NULL)
377 1.148.2.4 uebayasi return;
378 1.148.2.4 uebayasi
379 1.148.2.4 uebayasi KASSERT(acpi_active != 0);
380 1.148.2.4 uebayasi
381 1.148.2.2 uebayasi if (AcpiGbl_FADT.SmiCommand != 0)
382 1.148.2.2 uebayasi AcpiDisable();
383 1.148.2.2 uebayasi }
384 1.148.2.2 uebayasi
385 1.98 cube int
386 1.98 cube acpi_check(device_t parent, const char *ifattr)
387 1.98 cube {
388 1.98 cube return (config_search_ia(acpi_submatch, parent, ifattr, NULL) != NULL);
389 1.98 cube }
390 1.98 cube
391 1.1 thorpej /*
392 1.148.2.1 uebayasi * Autoconfiguration.
393 1.1 thorpej */
394 1.64 kochi static int
395 1.126 cegger acpi_match(device_t parent, cfdata_t match, void *aux)
396 1.1 thorpej {
397 1.1 thorpej /*
398 1.148.2.1 uebayasi * XXX: Nada; MD code has called acpi_probe().
399 1.1 thorpej */
400 1.63 kochi return 1;
401 1.1 thorpej }
402 1.1 thorpej
403 1.148.2.1 uebayasi static int
404 1.148.2.1 uebayasi acpi_submatch(device_t parent, cfdata_t cf, const int *locs, void *aux)
405 1.111 dyoung {
406 1.148.2.1 uebayasi struct cfattach *ca;
407 1.111 dyoung
408 1.148.2.1 uebayasi ca = config_cfattach_lookup(cf->cf_name, cf->cf_atname);
409 1.124 dyoung
410 1.148.2.1 uebayasi return (ca == &acpi_ca);
411 1.111 dyoung }
412 1.111 dyoung
413 1.64 kochi static void
414 1.111 dyoung acpi_attach(device_t parent, device_t self, void *aux)
415 1.1 thorpej {
416 1.111 dyoung struct acpi_softc *sc = device_private(self);
417 1.1 thorpej struct acpibus_attach_args *aa = aux;
418 1.108 jmcneill ACPI_TABLE_HEADER *rsdt;
419 1.148.2.1 uebayasi ACPI_STATUS rv;
420 1.1 thorpej
421 1.116 jmcneill aprint_naive("\n");
422 1.116 jmcneill aprint_normal(": Intel ACPICA %08x\n", ACPI_CA_VERSION);
423 1.1 thorpej
424 1.1 thorpej if (acpi_softc != NULL)
425 1.148.2.1 uebayasi panic("%s: already attached", __func__);
426 1.37 kochi
427 1.108 jmcneill rsdt = acpi_map_rsdt();
428 1.148.2.1 uebayasi
429 1.148.2.1 uebayasi if (rsdt == NULL)
430 1.148.2.1 uebayasi aprint_error_dev(self, "X/RSDT: Not found\n");
431 1.148.2.1 uebayasi else {
432 1.148.2.1 uebayasi aprint_verbose_dev(self,
433 1.111 dyoung "X/RSDT: OemId <%6.6s,%8.8s,%08x>, AslId <%4.4s,%08x>\n",
434 1.108 jmcneill rsdt->OemId, rsdt->OemTableId,
435 1.108 jmcneill rsdt->OemRevision,
436 1.108 jmcneill rsdt->AslCompilerId, rsdt->AslCompilerRevision);
437 1.148.2.1 uebayasi }
438 1.148.2.1 uebayasi
439 1.108 jmcneill acpi_unmap_rsdt(rsdt);
440 1.1 thorpej
441 1.113 jmcneill sc->sc_dev = self;
442 1.148.2.1 uebayasi sc->sc_root = NULL;
443 1.148.2.1 uebayasi
444 1.148.2.1 uebayasi sc->sc_sleepstate = ACPI_STATE_S0;
445 1.36 fvdl sc->sc_quirks = acpi_find_quirks();
446 1.36 fvdl
447 1.148.2.1 uebayasi sysmon_power_settype("acpi");
448 1.148.2.1 uebayasi
449 1.1 thorpej sc->sc_iot = aa->aa_iot;
450 1.1 thorpej sc->sc_memt = aa->aa_memt;
451 1.1 thorpej sc->sc_pc = aa->aa_pc;
452 1.1 thorpej sc->sc_pciflags = aa->aa_pciflags;
453 1.19 jmcneill sc->sc_ic = aa->aa_ic;
454 1.1 thorpej
455 1.148.2.1 uebayasi SIMPLEQ_INIT(&sc->ad_head);
456 1.148.2.1 uebayasi
457 1.1 thorpej acpi_softc = sc;
458 1.1 thorpej
459 1.148.2.1 uebayasi if (pmf_device_register(self, acpi_suspend, acpi_resume) != true)
460 1.104 jmcneill aprint_error_dev(self, "couldn't establish power handler\n");
461 1.104 jmcneill
462 1.104 jmcneill /*
463 1.1 thorpej * Bring ACPI on-line.
464 1.1 thorpej */
465 1.40 kochi #ifdef ACPI_DEBUGGER
466 1.1 thorpej if (acpi_dbgr & ACPI_DBGR_ENABLE)
467 1.1 thorpej acpi_osd_debugger();
468 1.1 thorpej #endif
469 1.47 mycroft
470 1.104 jmcneill #define ACPI_ENABLE_PHASE1 \
471 1.104 jmcneill (ACPI_NO_HANDLER_INIT | ACPI_NO_EVENT_INIT)
472 1.104 jmcneill #define ACPI_ENABLE_PHASE2 \
473 1.104 jmcneill (ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE | \
474 1.104 jmcneill ACPI_NO_ADDRESS_SPACE_INIT)
475 1.104 jmcneill
476 1.104 jmcneill rv = AcpiEnableSubsystem(ACPI_ENABLE_PHASE1);
477 1.148.2.1 uebayasi
478 1.148.2.1 uebayasi if (ACPI_FAILURE(rv))
479 1.148.2.1 uebayasi goto fail;
480 1.104 jmcneill
481 1.104 jmcneill acpi_md_callback();
482 1.104 jmcneill
483 1.104 jmcneill rv = AcpiEnableSubsystem(ACPI_ENABLE_PHASE2);
484 1.60 kochi
485 1.148.2.1 uebayasi if (ACPI_FAILURE(rv))
486 1.148.2.1 uebayasi goto fail;
487 1.148.2.1 uebayasi
488 1.148.2.1 uebayasi /*
489 1.148.2.1 uebayasi * Early EC handler initialization if ECDT table is available.
490 1.148.2.1 uebayasi */
491 1.148.2.1 uebayasi config_found_ia(self, "acpiecdtbus", aa, NULL);
492 1.60 kochi
493 1.104 jmcneill rv = AcpiInitializeObjects(ACPI_FULL_INITIALIZATION);
494 1.1 thorpej
495 1.148.2.1 uebayasi if (ACPI_FAILURE(rv))
496 1.148.2.1 uebayasi goto fail;
497 1.148.2.1 uebayasi
498 1.148.2.1 uebayasi /*
499 1.148.2.1 uebayasi * Install global notify handlers.
500 1.148.2.1 uebayasi */
501 1.148.2.1 uebayasi rv = AcpiInstallNotifyHandler(ACPI_ROOT_OBJECT,
502 1.148.2.1 uebayasi ACPI_SYSTEM_NOTIFY, acpi_notify_handler, NULL);
503 1.148.2.1 uebayasi
504 1.148.2.1 uebayasi if (ACPI_FAILURE(rv))
505 1.148.2.1 uebayasi goto fail;
506 1.148.2.1 uebayasi
507 1.148.2.1 uebayasi rv = AcpiInstallNotifyHandler(ACPI_ROOT_OBJECT,
508 1.148.2.1 uebayasi ACPI_DEVICE_NOTIFY, acpi_notify_handler, NULL);
509 1.148.2.1 uebayasi
510 1.148.2.1 uebayasi if (ACPI_FAILURE(rv))
511 1.148.2.1 uebayasi goto fail;
512 1.148.2.1 uebayasi
513 1.148.2.1 uebayasi acpi_active = 1;
514 1.1 thorpej
515 1.9 kanaoka /* Show SCI interrupt. */
516 1.148.2.1 uebayasi aprint_verbose_dev(self, "SCI interrupting at int %u\n",
517 1.111 dyoung AcpiGbl_FADT.SciInterrupt);
518 1.104 jmcneill
519 1.1 thorpej /*
520 1.148.2.1 uebayasi * Install fixed-event handlers.
521 1.1 thorpej */
522 1.148.2.1 uebayasi acpi_register_fixed_button(sc, ACPI_EVENT_POWER_BUTTON);
523 1.148.2.1 uebayasi acpi_register_fixed_button(sc, ACPI_EVENT_SLEEP_BUTTON);
524 1.148.2.1 uebayasi
525 1.148.2.2 uebayasi acpitimer_init(sc);
526 1.1 thorpej
527 1.40 kochi #ifdef ACPI_DEBUGGER
528 1.1 thorpej if (acpi_dbgr & ACPI_DBGR_PROBE)
529 1.1 thorpej acpi_osd_debugger();
530 1.1 thorpej #endif
531 1.1 thorpej
532 1.148.2.1 uebayasi /*
533 1.148.2.1 uebayasi * Scan the namespace and build our device tree.
534 1.148.2.1 uebayasi */
535 1.148.2.1 uebayasi acpi_build_tree(sc);
536 1.148.2.1 uebayasi acpi_sleep_init(sc);
537 1.78 cube
538 1.40 kochi #ifdef ACPI_DEBUGGER
539 1.1 thorpej if (acpi_dbgr & ACPI_DBGR_RUNNING)
540 1.1 thorpej acpi_osd_debugger();
541 1.1 thorpej #endif
542 1.148 jruoho
543 1.148 jruoho #ifdef ACPI_DEBUG
544 1.148 jruoho acpi_debug_init();
545 1.148 jruoho #endif
546 1.148.2.1 uebayasi
547 1.148.2.2 uebayasi /*
548 1.148.2.2 uebayasi * Print debug information.
549 1.148.2.2 uebayasi */
550 1.148.2.2 uebayasi acpi_print_verbose(sc);
551 1.148.2.2 uebayasi
552 1.148.2.1 uebayasi return;
553 1.148.2.1 uebayasi
554 1.148.2.1 uebayasi fail:
555 1.148.2.1 uebayasi aprint_error("%s: failed to initialize ACPI: %s\n",
556 1.148.2.1 uebayasi __func__, AcpiFormatException(rv));
557 1.1 thorpej }
558 1.1 thorpej
559 1.148.2.1 uebayasi /*
560 1.148.2.1 uebayasi * XXX: This is incomplete.
561 1.148.2.1 uebayasi */
562 1.124 dyoung static int
563 1.124 dyoung acpi_detach(device_t self, int flags)
564 1.124 dyoung {
565 1.148.2.1 uebayasi struct acpi_softc *sc = device_private(self);
566 1.148.2.1 uebayasi ACPI_STATUS rv;
567 1.124 dyoung int rc;
568 1.124 dyoung
569 1.148.2.1 uebayasi rv = AcpiRemoveNotifyHandler(ACPI_ROOT_OBJECT,
570 1.148.2.1 uebayasi ACPI_SYSTEM_NOTIFY, acpi_notify_handler);
571 1.148.2.1 uebayasi
572 1.148.2.1 uebayasi if (ACPI_FAILURE(rv))
573 1.148.2.1 uebayasi return EBUSY;
574 1.148.2.1 uebayasi
575 1.148.2.1 uebayasi rv = AcpiRemoveNotifyHandler(ACPI_ROOT_OBJECT,
576 1.148.2.1 uebayasi ACPI_DEVICE_NOTIFY, acpi_notify_handler);
577 1.148.2.1 uebayasi
578 1.148.2.1 uebayasi if (ACPI_FAILURE(rv))
579 1.148.2.1 uebayasi return EBUSY;
580 1.124 dyoung
581 1.124 dyoung if ((rc = config_detach_children(self, flags)) != 0)
582 1.124 dyoung return rc;
583 1.124 dyoung
584 1.124 dyoung if ((rc = acpitimer_detach()) != 0)
585 1.124 dyoung return rc;
586 1.124 dyoung
587 1.148.2.1 uebayasi acpi_deregister_fixed_button(sc, ACPI_EVENT_POWER_BUTTON);
588 1.148.2.1 uebayasi acpi_deregister_fixed_button(sc, ACPI_EVENT_SLEEP_BUTTON);
589 1.124 dyoung
590 1.148.2.1 uebayasi pmf_device_deregister(self);
591 1.124 dyoung
592 1.148.2.1 uebayasi acpi_softc = NULL;
593 1.124 dyoung
594 1.148.2.1 uebayasi return 0;
595 1.148.2.1 uebayasi }
596 1.124 dyoung
597 1.148.2.1 uebayasi /*
598 1.148.2.1 uebayasi * XXX: Need to reclaim any resources? Yes.
599 1.148.2.1 uebayasi */
600 1.148.2.1 uebayasi static void
601 1.148.2.1 uebayasi acpi_childdet(device_t self, device_t child)
602 1.148.2.1 uebayasi {
603 1.148.2.1 uebayasi struct acpi_softc *sc = device_private(self);
604 1.148.2.1 uebayasi struct acpi_devnode *ad;
605 1.124 dyoung
606 1.148.2.1 uebayasi if (sc->sc_apmbus == child)
607 1.148.2.1 uebayasi sc->sc_apmbus = NULL;
608 1.124 dyoung
609 1.148.2.1 uebayasi SIMPLEQ_FOREACH(ad, &sc->ad_head, ad_list) {
610 1.124 dyoung
611 1.148.2.1 uebayasi if (ad->ad_device == child)
612 1.148.2.1 uebayasi ad->ad_device = NULL;
613 1.148.2.1 uebayasi }
614 1.124 dyoung }
615 1.124 dyoung
616 1.123 jmcneill static bool
617 1.148.2.1 uebayasi acpi_suspend(device_t dv, const pmf_qual_t *qual)
618 1.123 jmcneill {
619 1.148.2.1 uebayasi
620 1.123 jmcneill acpi_suspended = 1;
621 1.148.2.1 uebayasi
622 1.123 jmcneill return true;
623 1.123 jmcneill }
624 1.123 jmcneill
625 1.123 jmcneill static bool
626 1.148.2.1 uebayasi acpi_resume(device_t dv, const pmf_qual_t *qual)
627 1.123 jmcneill {
628 1.148.2.1 uebayasi
629 1.123 jmcneill acpi_suspended = 0;
630 1.148.2.1 uebayasi
631 1.123 jmcneill return true;
632 1.123 jmcneill }
633 1.123 jmcneill
634 1.1 thorpej /*
635 1.148.2.1 uebayasi * Namespace scan.
636 1.1 thorpej */
637 1.148.2.1 uebayasi static void
638 1.148.2.1 uebayasi acpi_build_tree(struct acpi_softc *sc)
639 1.148.2.1 uebayasi {
640 1.148.2.1 uebayasi struct acpi_walkcontext awc;
641 1.148.2.1 uebayasi
642 1.148.2.1 uebayasi /*
643 1.148.2.1 uebayasi * Get the root scope handles.
644 1.148.2.1 uebayasi */
645 1.148.2.1 uebayasi KASSERT(__arraycount(acpi_scopes) == 4);
646 1.148.2.1 uebayasi
647 1.148.2.1 uebayasi (void)AcpiGetHandle(ACPI_ROOT_OBJECT, "\\_PR_", &acpi_scopes[0]);
648 1.148.2.1 uebayasi (void)AcpiGetHandle(ACPI_ROOT_OBJECT, "\\_SB_", &acpi_scopes[1]);
649 1.148.2.1 uebayasi (void)AcpiGetHandle(ACPI_ROOT_OBJECT, "\\_SI_", &acpi_scopes[2]);
650 1.148.2.1 uebayasi (void)AcpiGetHandle(ACPI_ROOT_OBJECT, "\\_TZ_", &acpi_scopes[3]);
651 1.148.2.1 uebayasi
652 1.148.2.1 uebayasi /*
653 1.148.2.1 uebayasi * Make the root node.
654 1.148.2.1 uebayasi */
655 1.148.2.1 uebayasi awc.aw_sc = sc;
656 1.148.2.1 uebayasi awc.aw_parent = NULL;
657 1.148.2.1 uebayasi
658 1.148.2.1 uebayasi (void)acpi_make_devnode(ACPI_ROOT_OBJECT, 0, &awc, NULL);
659 1.148.2.1 uebayasi
660 1.148.2.1 uebayasi KASSERT(sc->sc_root == NULL);
661 1.148.2.1 uebayasi KASSERT(awc.aw_parent != NULL);
662 1.148.2.1 uebayasi
663 1.148.2.1 uebayasi sc->sc_root = awc.aw_parent;
664 1.148.2.1 uebayasi
665 1.148.2.1 uebayasi /*
666 1.148.2.1 uebayasi * Build the internal namespace.
667 1.148.2.1 uebayasi */
668 1.148.2.1 uebayasi (void)AcpiWalkNamespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, UINT32_MAX,
669 1.148.2.1 uebayasi acpi_make_devnode, acpi_make_devnode_post, &awc, NULL);
670 1.148.2.1 uebayasi
671 1.148.2.1 uebayasi /*
672 1.148.2.1 uebayasi * Scan the internal namespace.
673 1.148.2.1 uebayasi */
674 1.148.2.3 uebayasi (void)acpi_pcidev_scan(sc->sc_root);
675 1.148.2.2 uebayasi (void)acpi_rescan(sc->sc_dev, NULL, NULL);
676 1.148.2.2 uebayasi
677 1.148.2.1 uebayasi acpi_rescan_capabilities(sc);
678 1.148.2.1 uebayasi }
679 1.148.2.1 uebayasi
680 1.64 kochi static ACPI_STATUS
681 1.148.2.1 uebayasi acpi_make_devnode(ACPI_HANDLE handle, uint32_t level,
682 1.148.2.1 uebayasi void *context, void **status)
683 1.1 thorpej {
684 1.148.2.1 uebayasi struct acpi_walkcontext *awc = context;
685 1.148.2.1 uebayasi struct acpi_softc *sc = awc->aw_sc;
686 1.148.2.1 uebayasi struct acpi_devnode *ad;
687 1.148.2.1 uebayasi ACPI_DEVICE_INFO *devinfo;
688 1.148.2.1 uebayasi ACPI_OBJECT_TYPE type;
689 1.148.2.1 uebayasi ACPI_NAME_UNION *anu;
690 1.148.2.1 uebayasi ACPI_STATUS rv;
691 1.148.2.1 uebayasi int clear, i;
692 1.1 thorpej
693 1.148.2.1 uebayasi rv = AcpiGetObjectInfo(handle, &devinfo);
694 1.148.2.1 uebayasi
695 1.148.2.1 uebayasi if (ACPI_FAILURE(rv))
696 1.148.2.1 uebayasi return AE_OK; /* Do not terminate the walk. */
697 1.148.2.1 uebayasi
698 1.148.2.1 uebayasi type = devinfo->Type;
699 1.148.2.1 uebayasi
700 1.148.2.1 uebayasi switch (type) {
701 1.148.2.1 uebayasi
702 1.148.2.1 uebayasi case ACPI_TYPE_DEVICE:
703 1.148.2.1 uebayasi
704 1.148.2.1 uebayasi #ifdef ACPI_ACTIVATE_DEV
705 1.148.2.1 uebayasi acpi_activate_device(handle, &devinfo);
706 1.148.2.1 uebayasi #endif
707 1.148.2.1 uebayasi
708 1.148.2.1 uebayasi case ACPI_TYPE_PROCESSOR:
709 1.148.2.1 uebayasi case ACPI_TYPE_THERMAL:
710 1.148.2.1 uebayasi case ACPI_TYPE_POWER:
711 1.148.2.1 uebayasi
712 1.148.2.1 uebayasi ad = malloc(sizeof(*ad), M_ACPI, M_NOWAIT | M_ZERO);
713 1.148.2.1 uebayasi
714 1.148.2.1 uebayasi if (ad == NULL)
715 1.148.2.1 uebayasi return AE_NO_MEMORY;
716 1.148.2.1 uebayasi
717 1.148.2.1 uebayasi ad->ad_device = NULL;
718 1.148.2.1 uebayasi ad->ad_notify = NULL;
719 1.148.2.1 uebayasi ad->ad_pciinfo = NULL;
720 1.148.2.1 uebayasi
721 1.148.2.1 uebayasi ad->ad_type = type;
722 1.148.2.1 uebayasi ad->ad_handle = handle;
723 1.148.2.1 uebayasi ad->ad_devinfo = devinfo;
724 1.148.2.1 uebayasi
725 1.148.2.1 uebayasi ad->ad_root = sc->sc_dev;
726 1.148.2.1 uebayasi ad->ad_parent = awc->aw_parent;
727 1.148.2.1 uebayasi
728 1.148.2.1 uebayasi anu = (ACPI_NAME_UNION *)&devinfo->Name;
729 1.148.2.1 uebayasi ad->ad_name[4] = '\0';
730 1.148.2.1 uebayasi
731 1.148.2.1 uebayasi for (i = 3, clear = 0; i >= 0; i--) {
732 1.148.2.1 uebayasi
733 1.148.2.1 uebayasi if (clear == 0 && anu->Ascii[i] == '_')
734 1.148.2.1 uebayasi ad->ad_name[i] = '\0';
735 1.148.2.1 uebayasi else {
736 1.148.2.1 uebayasi ad->ad_name[i] = anu->Ascii[i];
737 1.148.2.1 uebayasi clear = 1;
738 1.148.2.1 uebayasi }
739 1.148.2.1 uebayasi }
740 1.148.2.1 uebayasi
741 1.148.2.1 uebayasi if (ad->ad_name[0] == '\0')
742 1.148.2.1 uebayasi ad->ad_name[0] = '_';
743 1.148.2.1 uebayasi
744 1.148.2.1 uebayasi SIMPLEQ_INIT(&ad->ad_child_head);
745 1.148.2.1 uebayasi SIMPLEQ_INSERT_TAIL(&sc->ad_head, ad, ad_list);
746 1.148.2.1 uebayasi
747 1.148.2.2 uebayasi acpi_set_node(ad);
748 1.148.2.2 uebayasi
749 1.148.2.1 uebayasi if (ad->ad_parent != NULL) {
750 1.148.2.1 uebayasi
751 1.148.2.1 uebayasi SIMPLEQ_INSERT_TAIL(&ad->ad_parent->ad_child_head,
752 1.148.2.1 uebayasi ad, ad_child_list);
753 1.148.2.1 uebayasi }
754 1.148.2.1 uebayasi
755 1.148.2.1 uebayasi awc->aw_parent = ad;
756 1.1 thorpej }
757 1.148.2.1 uebayasi
758 1.148.2.1 uebayasi return AE_OK;
759 1.1 thorpej }
760 1.1 thorpej
761 1.148.2.1 uebayasi static ACPI_STATUS
762 1.148.2.1 uebayasi acpi_make_devnode_post(ACPI_HANDLE handle, uint32_t level,
763 1.148.2.1 uebayasi void *context, void **status)
764 1.148.2.1 uebayasi {
765 1.148.2.1 uebayasi struct acpi_walkcontext *awc = context;
766 1.1 thorpej
767 1.148.2.1 uebayasi KASSERT(awc != NULL);
768 1.148.2.1 uebayasi KASSERT(awc->aw_parent != NULL);
769 1.148.2.1 uebayasi
770 1.148.2.1 uebayasi if (handle == awc->aw_parent->ad_handle)
771 1.148.2.1 uebayasi awc->aw_parent = awc->aw_parent->ad_parent;
772 1.148.2.1 uebayasi
773 1.148.2.1 uebayasi return AE_OK;
774 1.148.2.1 uebayasi }
775 1.148.2.1 uebayasi
776 1.148.2.1 uebayasi #ifdef ACPI_ACTIVATE_DEV
777 1.64 kochi static void
778 1.148.2.1 uebayasi acpi_activate_device(ACPI_HANDLE handle, ACPI_DEVICE_INFO **di)
779 1.1 thorpej {
780 1.148.2.1 uebayasi static const int valid = ACPI_VALID_STA | ACPI_VALID_HID;
781 1.148.2.1 uebayasi ACPI_DEVICE_INFO *newdi;
782 1.56 mycroft ACPI_STATUS rv;
783 1.148.2.1 uebayasi uint32_t old;
784 1.1 thorpej
785 1.1 thorpej /*
786 1.148.2.1 uebayasi * If the device is valid and present,
787 1.148.2.1 uebayasi * but not enabled, try to activate it.
788 1.1 thorpej */
789 1.148.2.1 uebayasi if (((*di)->Valid & valid) != valid)
790 1.148.2.1 uebayasi return;
791 1.148.2.1 uebayasi
792 1.148.2.1 uebayasi old = (*di)->CurrentStatus;
793 1.1 thorpej
794 1.148.2.1 uebayasi if ((old & (ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED)) !=
795 1.148.2.1 uebayasi ACPI_STA_DEVICE_PRESENT)
796 1.148.2.1 uebayasi return;
797 1.1 thorpej
798 1.148.2.1 uebayasi rv = acpi_allocate_resources(handle);
799 1.1 thorpej
800 1.148.2.1 uebayasi if (ACPI_FAILURE(rv))
801 1.148.2.1 uebayasi goto fail;
802 1.148.2.1 uebayasi
803 1.148.2.1 uebayasi rv = AcpiGetObjectInfo(handle, &newdi);
804 1.148.2.1 uebayasi
805 1.148.2.1 uebayasi if (ACPI_FAILURE(rv))
806 1.148.2.1 uebayasi goto fail;
807 1.148.2.1 uebayasi
808 1.148.2.1 uebayasi ACPI_FREE(*di);
809 1.148.2.1 uebayasi *di = newdi;
810 1.148.2.1 uebayasi
811 1.148.2.1 uebayasi aprint_verbose_dev(acpi_softc->sc_dev,
812 1.148.2.1 uebayasi "%s activated, STA 0x%08X -> STA 0x%08X\n",
813 1.148.2.1 uebayasi (*di)->HardwareId.String, old, (*di)->CurrentStatus);
814 1.148.2.1 uebayasi
815 1.148.2.1 uebayasi return;
816 1.148.2.1 uebayasi
817 1.148.2.1 uebayasi fail:
818 1.148.2.1 uebayasi aprint_error_dev(acpi_softc->sc_dev, "failed to "
819 1.148.2.1 uebayasi "activate %s\n", (*di)->HardwareId.String);
820 1.148.2.1 uebayasi }
821 1.148.2.1 uebayasi
822 1.148.2.1 uebayasi /*
823 1.148.2.1 uebayasi * XXX: This very incomplete.
824 1.148.2.1 uebayasi */
825 1.148.2.1 uebayasi ACPI_STATUS
826 1.148.2.1 uebayasi acpi_allocate_resources(ACPI_HANDLE handle)
827 1.148.2.1 uebayasi {
828 1.148.2.1 uebayasi ACPI_BUFFER bufp, bufc, bufn;
829 1.148.2.1 uebayasi ACPI_RESOURCE *resp, *resc, *resn;
830 1.148.2.1 uebayasi ACPI_RESOURCE_IRQ *irq;
831 1.148.2.1 uebayasi ACPI_RESOURCE_EXTENDED_IRQ *xirq;
832 1.148.2.1 uebayasi ACPI_STATUS rv;
833 1.148.2.1 uebayasi uint delta;
834 1.148.2.1 uebayasi
835 1.148.2.1 uebayasi rv = acpi_get(handle, &bufp, AcpiGetPossibleResources);
836 1.148.2.1 uebayasi if (ACPI_FAILURE(rv))
837 1.148.2.1 uebayasi goto out;
838 1.148.2.1 uebayasi rv = acpi_get(handle, &bufc, AcpiGetCurrentResources);
839 1.148.2.1 uebayasi if (ACPI_FAILURE(rv)) {
840 1.148.2.1 uebayasi goto out1;
841 1.148.2.1 uebayasi }
842 1.148.2.1 uebayasi
843 1.148.2.1 uebayasi bufn.Length = 1000;
844 1.148.2.1 uebayasi bufn.Pointer = resn = malloc(bufn.Length, M_ACPI, M_WAITOK);
845 1.148.2.1 uebayasi resp = bufp.Pointer;
846 1.148.2.1 uebayasi resc = bufc.Pointer;
847 1.148.2.1 uebayasi while (resc->Type != ACPI_RESOURCE_TYPE_END_TAG &&
848 1.148.2.1 uebayasi resp->Type != ACPI_RESOURCE_TYPE_END_TAG) {
849 1.148.2.1 uebayasi while (resc->Type != resp->Type && resp->Type != ACPI_RESOURCE_TYPE_END_TAG)
850 1.148.2.1 uebayasi resp = ACPI_NEXT_RESOURCE(resp);
851 1.148.2.1 uebayasi if (resp->Type == ACPI_RESOURCE_TYPE_END_TAG)
852 1.148.2.1 uebayasi break;
853 1.148.2.1 uebayasi /* Found identical Id */
854 1.148.2.1 uebayasi resn->Type = resc->Type;
855 1.148.2.1 uebayasi switch (resc->Type) {
856 1.148.2.1 uebayasi case ACPI_RESOURCE_TYPE_IRQ:
857 1.148.2.1 uebayasi memcpy(&resn->Data, &resp->Data,
858 1.148.2.1 uebayasi sizeof(ACPI_RESOURCE_IRQ));
859 1.148.2.1 uebayasi irq = (ACPI_RESOURCE_IRQ *)&resn->Data;
860 1.148.2.1 uebayasi irq->Interrupts[0] =
861 1.148.2.1 uebayasi ((ACPI_RESOURCE_IRQ *)&resp->Data)->
862 1.148.2.1 uebayasi Interrupts[irq->InterruptCount-1];
863 1.148.2.1 uebayasi irq->InterruptCount = 1;
864 1.148.2.1 uebayasi resn->Length = ACPI_RS_SIZE(ACPI_RESOURCE_IRQ);
865 1.148.2.1 uebayasi break;
866 1.148.2.1 uebayasi case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
867 1.148.2.1 uebayasi memcpy(&resn->Data, &resp->Data,
868 1.148.2.1 uebayasi sizeof(ACPI_RESOURCE_EXTENDED_IRQ));
869 1.148.2.1 uebayasi xirq = (ACPI_RESOURCE_EXTENDED_IRQ *)&resn->Data;
870 1.148.2.1 uebayasi #if 0
871 1.148.2.1 uebayasi /*
872 1.148.2.1 uebayasi * XXX: Not duplicating the interrupt logic above
873 1.148.2.1 uebayasi * because its not clear what it accomplishes.
874 1.148.2.1 uebayasi */
875 1.148.2.1 uebayasi xirq->Interrupts[0] =
876 1.148.2.1 uebayasi ((ACPI_RESOURCE_EXT_IRQ *)&resp->Data)->
877 1.148.2.1 uebayasi Interrupts[irq->NumberOfInterrupts-1];
878 1.148.2.1 uebayasi xirq->NumberOfInterrupts = 1;
879 1.148.2.1 uebayasi #endif
880 1.148.2.1 uebayasi resn->Length = ACPI_RS_SIZE(ACPI_RESOURCE_EXTENDED_IRQ);
881 1.148.2.1 uebayasi break;
882 1.148.2.1 uebayasi case ACPI_RESOURCE_TYPE_IO:
883 1.148.2.1 uebayasi memcpy(&resn->Data, &resp->Data,
884 1.148.2.1 uebayasi sizeof(ACPI_RESOURCE_IO));
885 1.148.2.1 uebayasi resn->Length = resp->Length;
886 1.148.2.1 uebayasi break;
887 1.148.2.1 uebayasi default:
888 1.148.2.1 uebayasi aprint_error_dev(acpi_softc->sc_dev,
889 1.148.2.1 uebayasi "%s: invalid type %u\n", __func__, resc->Type);
890 1.148.2.1 uebayasi rv = AE_BAD_DATA;
891 1.148.2.1 uebayasi goto out2;
892 1.148.2.1 uebayasi }
893 1.148.2.1 uebayasi resc = ACPI_NEXT_RESOURCE(resc);
894 1.148.2.1 uebayasi resn = ACPI_NEXT_RESOURCE(resn);
895 1.148.2.1 uebayasi resp = ACPI_NEXT_RESOURCE(resp);
896 1.148.2.1 uebayasi delta = (uint8_t *)resn - (uint8_t *)bufn.Pointer;
897 1.148.2.1 uebayasi if (delta >=
898 1.148.2.1 uebayasi bufn.Length-ACPI_RS_SIZE(ACPI_RESOURCE_DATA)) {
899 1.148.2.1 uebayasi bufn.Length *= 2;
900 1.148.2.1 uebayasi bufn.Pointer = realloc(bufn.Pointer, bufn.Length,
901 1.148.2.1 uebayasi M_ACPI, M_WAITOK);
902 1.148.2.1 uebayasi resn = (ACPI_RESOURCE *)((uint8_t *)bufn.Pointer +
903 1.148.2.1 uebayasi delta);
904 1.1 thorpej }
905 1.124 dyoung }
906 1.124 dyoung
907 1.148.2.1 uebayasi if (resc->Type != ACPI_RESOURCE_TYPE_END_TAG) {
908 1.148.2.1 uebayasi aprint_error_dev(acpi_softc->sc_dev,
909 1.148.2.1 uebayasi "%s: resc not exhausted\n", __func__);
910 1.148.2.1 uebayasi rv = AE_BAD_DATA;
911 1.148.2.1 uebayasi goto out3;
912 1.148.2.1 uebayasi }
913 1.127 jmcneill
914 1.148.2.1 uebayasi resn->Type = ACPI_RESOURCE_TYPE_END_TAG;
915 1.148.2.1 uebayasi rv = AcpiSetCurrentResources(handle, &bufn);
916 1.148.2.1 uebayasi
917 1.148.2.1 uebayasi if (ACPI_FAILURE(rv))
918 1.148.2.1 uebayasi aprint_error_dev(acpi_softc->sc_dev, "%s: failed to set "
919 1.148.2.1 uebayasi "resources: %s\n", __func__, AcpiFormatException(rv));
920 1.137 cegger
921 1.148.2.1 uebayasi out3:
922 1.148.2.1 uebayasi free(bufn.Pointer, M_ACPI);
923 1.148.2.1 uebayasi out2:
924 1.148.2.1 uebayasi ACPI_FREE(bufc.Pointer);
925 1.148.2.1 uebayasi out1:
926 1.148.2.1 uebayasi ACPI_FREE(bufp.Pointer);
927 1.148.2.1 uebayasi out:
928 1.148.2.1 uebayasi return rv;
929 1.124 dyoung }
930 1.148.2.1 uebayasi #endif /* ACPI_ACTIVATE_DEV */
931 1.1 thorpej
932 1.148.2.1 uebayasi /*
933 1.148.2.1 uebayasi * Device attachment.
934 1.148.2.1 uebayasi */
935 1.124 dyoung static int
936 1.124 dyoung acpi_rescan(device_t self, const char *ifattr, const int *locators)
937 1.124 dyoung {
938 1.124 dyoung struct acpi_softc *sc = device_private(self);
939 1.124 dyoung
940 1.124 dyoung if (ifattr_match(ifattr, "acpinodebus"))
941 1.124 dyoung acpi_rescan_nodes(sc);
942 1.124 dyoung
943 1.148.2.1 uebayasi if (ifattr_match(ifattr, "acpiapmbus") && sc->sc_apmbus == NULL)
944 1.148.2.1 uebayasi sc->sc_apmbus = config_found_ia(sc->sc_dev,
945 1.148.2.1 uebayasi "acpiapmbus", NULL, NULL);
946 1.148.2.2 uebayasi
947 1.148.2.2 uebayasi return 0;
948 1.124 dyoung }
949 1.124 dyoung
950 1.124 dyoung static void
951 1.124 dyoung acpi_rescan_nodes(struct acpi_softc *sc)
952 1.124 dyoung {
953 1.148.2.1 uebayasi struct acpi_attach_args aa;
954 1.148.2.1 uebayasi struct acpi_devnode *ad;
955 1.148.2.1 uebayasi ACPI_DEVICE_INFO *di;
956 1.124 dyoung
957 1.148.2.1 uebayasi SIMPLEQ_FOREACH(ad, &sc->ad_head, ad_list) {
958 1.124 dyoung
959 1.148.2.1 uebayasi if (ad->ad_device != NULL)
960 1.148.2.1 uebayasi continue;
961 1.124 dyoung
962 1.148.2.1 uebayasi /*
963 1.148.2.1 uebayasi * There is a bug in ACPICA: it defines the type
964 1.148.2.1 uebayasi * of the scopes incorrectly for its own reasons.
965 1.148.2.1 uebayasi */
966 1.148.2.1 uebayasi if (acpi_is_scope(ad) != false)
967 1.148.2.1 uebayasi continue;
968 1.148.2.1 uebayasi
969 1.148.2.1 uebayasi di = ad->ad_devinfo;
970 1.148.2.1 uebayasi
971 1.148.2.1 uebayasi /*
972 1.148.2.1 uebayasi * We only attach devices which are present, enabled, and
973 1.148.2.1 uebayasi * functioning properly. However, if a device is enabled,
974 1.148.2.1 uebayasi * it is decoding resources and we should claim these,
975 1.148.2.1 uebayasi * if possible. This requires changes to bus_space(9).
976 1.148.2.2 uebayasi * Note: there is a possible race condition, because _STA
977 1.148.2.2 uebayasi * may have changed since di->CurrentStatus was set.
978 1.148.2.1 uebayasi */
979 1.148.2.1 uebayasi if (di->Type == ACPI_TYPE_DEVICE) {
980 1.25 jmcneill
981 1.148.2.1 uebayasi if ((di->Valid & ACPI_VALID_STA) != 0 &&
982 1.148.2.1 uebayasi (di->CurrentStatus & ACPI_STA_OK) != ACPI_STA_OK)
983 1.104 jmcneill continue;
984 1.148.2.1 uebayasi }
985 1.1 thorpej
986 1.148.2.1 uebayasi /*
987 1.148.2.1 uebayasi * Handled internally.
988 1.148.2.1 uebayasi */
989 1.148.2.2 uebayasi if (di->Type == ACPI_TYPE_POWER)
990 1.148.2.1 uebayasi continue;
991 1.116 jmcneill
992 1.148.2.1 uebayasi /*
993 1.148.2.1 uebayasi * Skip ignored HIDs.
994 1.148.2.1 uebayasi */
995 1.148.2.1 uebayasi if (acpi_match_hid(di, acpi_ignored_ids))
996 1.148.2.1 uebayasi continue;
997 1.148.2.1 uebayasi
998 1.148.2.1 uebayasi aa.aa_node = ad;
999 1.148.2.1 uebayasi aa.aa_iot = sc->sc_iot;
1000 1.148.2.1 uebayasi aa.aa_memt = sc->sc_memt;
1001 1.148.2.1 uebayasi aa.aa_pc = sc->sc_pc;
1002 1.148.2.1 uebayasi aa.aa_pciflags = sc->sc_pciflags;
1003 1.148.2.1 uebayasi aa.aa_ic = sc->sc_ic;
1004 1.116 jmcneill
1005 1.148.2.1 uebayasi ad->ad_device = config_found_ia(sc->sc_dev,
1006 1.148.2.1 uebayasi "acpinodebus", &aa, acpi_print);
1007 1.1 thorpej }
1008 1.1 thorpej }
1009 1.1 thorpej
1010 1.15 augustss static void
1011 1.148.2.1 uebayasi acpi_rescan_capabilities(struct acpi_softc *sc)
1012 1.15 augustss {
1013 1.148.2.1 uebayasi struct acpi_devnode *ad;
1014 1.148.2.1 uebayasi ACPI_HANDLE tmp;
1015 1.15 augustss ACPI_STATUS rv;
1016 1.15 augustss
1017 1.148.2.1 uebayasi SIMPLEQ_FOREACH(ad, &sc->ad_head, ad_list) {
1018 1.15 augustss
1019 1.148.2.2 uebayasi if (ad->ad_devinfo->Type != ACPI_TYPE_DEVICE)
1020 1.148.2.1 uebayasi continue;
1021 1.148.2.1 uebayasi
1022 1.148.2.1 uebayasi /*
1023 1.148.2.1 uebayasi * Scan power resource capabilities.
1024 1.148.2.1 uebayasi *
1025 1.148.2.1 uebayasi * If any power states are supported,
1026 1.148.2.1 uebayasi * at least _PR0 and _PR3 must be present.
1027 1.148.2.1 uebayasi */
1028 1.148.2.1 uebayasi rv = AcpiGetHandle(ad->ad_handle, "_PR0", &tmp);
1029 1.1 thorpej
1030 1.148.2.1 uebayasi if (ACPI_SUCCESS(rv)) {
1031 1.148.2.1 uebayasi ad->ad_flags |= ACPI_DEVICE_POWER;
1032 1.148.2.1 uebayasi acpi_power_add(ad);
1033 1.15 augustss }
1034 1.15 augustss
1035 1.148.2.1 uebayasi /*
1036 1.148.2.1 uebayasi * Scan wake-up capabilities.
1037 1.148.2.1 uebayasi */
1038 1.148.2.1 uebayasi rv = AcpiGetHandle(ad->ad_handle, "_PRW", &tmp);
1039 1.43 mycroft
1040 1.148.2.1 uebayasi if (ACPI_SUCCESS(rv)) {
1041 1.148.2.1 uebayasi ad->ad_flags |= ACPI_DEVICE_WAKEUP;
1042 1.148.2.1 uebayasi acpi_wakedev_add(ad);
1043 1.1 thorpej }
1044 1.1 thorpej }
1045 1.1 thorpej }
1046 1.1 thorpej
1047 1.64 kochi static int
1048 1.1 thorpej acpi_print(void *aux, const char *pnp)
1049 1.1 thorpej {
1050 1.1 thorpej struct acpi_attach_args *aa = aux;
1051 1.56 mycroft ACPI_STATUS rv;
1052 1.1 thorpej
1053 1.4 thorpej if (pnp) {
1054 1.54 kochi if (aa->aa_node->ad_devinfo->Valid & ACPI_VALID_HID) {
1055 1.54 kochi char *pnpstr =
1056 1.128 jmcneill aa->aa_node->ad_devinfo->HardwareId.String;
1057 1.121 mlelstv ACPI_BUFFER buf;
1058 1.27 christos
1059 1.102 cube aprint_normal("%s (%s) ", aa->aa_node->ad_name,
1060 1.102 cube pnpstr);
1061 1.121 mlelstv
1062 1.140 jruoho rv = acpi_eval_struct(aa->aa_node->ad_handle,
1063 1.140 jruoho "_STR", &buf);
1064 1.56 mycroft if (ACPI_SUCCESS(rv)) {
1065 1.121 mlelstv ACPI_OBJECT *obj = buf.Pointer;
1066 1.121 mlelstv switch (obj->Type) {
1067 1.121 mlelstv case ACPI_TYPE_STRING:
1068 1.121 mlelstv aprint_normal("[%s] ", obj->String.Pointer);
1069 1.121 mlelstv break;
1070 1.121 mlelstv case ACPI_TYPE_BUFFER:
1071 1.121 mlelstv aprint_normal("buffer %p ", obj->Buffer.Pointer);
1072 1.121 mlelstv break;
1073 1.121 mlelstv default:
1074 1.148.2.1 uebayasi aprint_normal("type %u ",obj->Type);
1075 1.121 mlelstv break;
1076 1.121 mlelstv }
1077 1.132 mlelstv ACPI_FREE(buf.Pointer);
1078 1.27 christos }
1079 1.148.2.2 uebayasi else
1080 1.148.2.2 uebayasi acpi_print_dev(pnpstr);
1081 1.62 kochi
1082 1.104 jmcneill aprint_normal("at %s", pnp);
1083 1.104 jmcneill } else if (aa->aa_node->ad_devinfo->Type != ACPI_TYPE_DEVICE) {
1084 1.102 cube aprint_normal("%s (ACPI Object Type '%s' "
1085 1.102 cube "[0x%02x]) ", aa->aa_node->ad_name,
1086 1.102 cube AcpiUtGetTypeName(aa->aa_node->ad_devinfo->Type),
1087 1.102 cube aa->aa_node->ad_devinfo->Type);
1088 1.104 jmcneill aprint_normal("at %s", pnp);
1089 1.104 jmcneill } else
1090 1.104 jmcneill return 0;
1091 1.21 matt } else {
1092 1.102 cube aprint_normal(" (%s", aa->aa_node->ad_name);
1093 1.54 kochi if (aa->aa_node->ad_devinfo->Valid & ACPI_VALID_HID) {
1094 1.128 jmcneill aprint_normal(", %s", aa->aa_node->ad_devinfo->HardwareId.String);
1095 1.54 kochi if (aa->aa_node->ad_devinfo->Valid & ACPI_VALID_UID) {
1096 1.70 christos const char *uid;
1097 1.41 kochi
1098 1.128 jmcneill uid = aa->aa_node->ad_devinfo->UniqueId.String;
1099 1.48 mycroft if (uid[0] == '\0')
1100 1.41 kochi uid = "<null>";
1101 1.41 kochi aprint_normal("-%s", uid);
1102 1.41 kochi }
1103 1.22 jmcneill }
1104 1.102 cube aprint_normal(")");
1105 1.4 thorpej }
1106 1.1 thorpej
1107 1.63 kochi return UNCONF;
1108 1.1 thorpej }
1109 1.1 thorpej
1110 1.147 jruoho /*
1111 1.148.2.1 uebayasi * Notify.
1112 1.147 jruoho */
1113 1.148.2.1 uebayasi static void
1114 1.148.2.1 uebayasi acpi_notify_handler(ACPI_HANDLE handle, uint32_t event, void *aux)
1115 1.136 cegger {
1116 1.148.2.1 uebayasi struct acpi_softc *sc = acpi_softc;
1117 1.148.2.1 uebayasi struct acpi_devnode *ad;
1118 1.136 cegger
1119 1.148.2.1 uebayasi KASSERT(sc != NULL);
1120 1.148.2.1 uebayasi KASSERT(aux == NULL);
1121 1.148.2.1 uebayasi KASSERT(acpi_active != 0);
1122 1.136 cegger
1123 1.148.2.1 uebayasi if (acpi_suspended != 0)
1124 1.148.2.1 uebayasi return;
1125 1.136 cegger
1126 1.148.2.1 uebayasi /*
1127 1.148.2.1 uebayasi * System: 0x00 - 0x7F.
1128 1.148.2.1 uebayasi * Device: 0x80 - 0xFF.
1129 1.148.2.1 uebayasi */
1130 1.148.2.1 uebayasi switch (event) {
1131 1.136 cegger
1132 1.148.2.1 uebayasi case ACPI_NOTIFY_BUS_CHECK:
1133 1.148.2.1 uebayasi case ACPI_NOTIFY_DEVICE_CHECK:
1134 1.148.2.1 uebayasi case ACPI_NOTIFY_DEVICE_WAKE:
1135 1.148.2.1 uebayasi case ACPI_NOTIFY_EJECT_REQUEST:
1136 1.148.2.1 uebayasi case ACPI_NOTIFY_DEVICE_CHECK_LIGHT:
1137 1.148.2.1 uebayasi case ACPI_NOTIFY_FREQUENCY_MISMATCH:
1138 1.148.2.1 uebayasi case ACPI_NOTIFY_BUS_MODE_MISMATCH:
1139 1.148.2.1 uebayasi case ACPI_NOTIFY_POWER_FAULT:
1140 1.148.2.1 uebayasi case ACPI_NOTIFY_CAPABILITIES_CHECK:
1141 1.148.2.1 uebayasi case ACPI_NOTIFY_DEVICE_PLD_CHECK:
1142 1.148.2.1 uebayasi case ACPI_NOTIFY_RESERVED:
1143 1.148.2.1 uebayasi case ACPI_NOTIFY_LOCALITY_UPDATE:
1144 1.148.2.1 uebayasi break;
1145 1.148.2.1 uebayasi }
1146 1.136 cegger
1147 1.148.2.1 uebayasi ACPI_DEBUG_PRINT((ACPI_DB_INFO, "notification 0x%02X for "
1148 1.148.2.1 uebayasi "%s (%p)\n", event, acpi_name(handle), handle));
1149 1.4 thorpej
1150 1.148.2.1 uebayasi /*
1151 1.148.2.1 uebayasi * We deliver notifications only to drivers
1152 1.148.2.1 uebayasi * that have been succesfully attached and
1153 1.148.2.1 uebayasi * that have registered a handler with us.
1154 1.148.2.1 uebayasi * The opaque pointer is always the device_t.
1155 1.148.2.1 uebayasi */
1156 1.148.2.1 uebayasi SIMPLEQ_FOREACH(ad, &sc->ad_head, ad_list) {
1157 1.145 jruoho
1158 1.148.2.1 uebayasi if (ad->ad_device == NULL)
1159 1.148.2.1 uebayasi continue;
1160 1.145 jruoho
1161 1.148.2.1 uebayasi if (ad->ad_notify == NULL)
1162 1.148.2.1 uebayasi continue;
1163 1.145 jruoho
1164 1.148.2.1 uebayasi if (ad->ad_handle != handle)
1165 1.148.2.1 uebayasi continue;
1166 1.145 jruoho
1167 1.148.2.1 uebayasi (*ad->ad_notify)(ad->ad_handle, event, ad->ad_device);
1168 1.148.2.1 uebayasi
1169 1.148.2.1 uebayasi return;
1170 1.145 jruoho }
1171 1.4 thorpej
1172 1.148.2.1 uebayasi aprint_debug_dev(sc->sc_dev, "unhandled notify 0x%02X "
1173 1.148.2.1 uebayasi "for %s (%p)\n", event, acpi_name(handle), handle);
1174 1.148.2.1 uebayasi }
1175 1.4 thorpej
1176 1.148.2.1 uebayasi bool
1177 1.148.2.1 uebayasi acpi_register_notify(struct acpi_devnode *ad, ACPI_NOTIFY_HANDLER notify)
1178 1.148.2.1 uebayasi {
1179 1.148.2.1 uebayasi struct acpi_softc *sc = acpi_softc;
1180 1.46 mycroft
1181 1.148.2.1 uebayasi KASSERT(sc != NULL);
1182 1.148.2.1 uebayasi KASSERT(acpi_active != 0);
1183 1.145 jruoho
1184 1.148.2.1 uebayasi if (acpi_suspended != 0)
1185 1.148.2.1 uebayasi goto fail;
1186 1.145 jruoho
1187 1.148.2.1 uebayasi if (ad == NULL || notify == NULL)
1188 1.148.2.1 uebayasi goto fail;
1189 1.145 jruoho
1190 1.148.2.1 uebayasi ad->ad_notify = notify;
1191 1.7 sommerfe
1192 1.148.2.1 uebayasi return true;
1193 1.7 sommerfe
1194 1.148.2.1 uebayasi fail:
1195 1.148.2.1 uebayasi aprint_error_dev(sc->sc_dev, "failed to register notify "
1196 1.148.2.1 uebayasi "handler for %s (%p)\n", ad->ad_name, ad->ad_handle);
1197 1.7 sommerfe
1198 1.148.2.1 uebayasi return false;
1199 1.148.2.1 uebayasi }
1200 1.7 sommerfe
1201 1.148.2.1 uebayasi void
1202 1.148.2.1 uebayasi acpi_deregister_notify(struct acpi_devnode *ad)
1203 1.148.2.1 uebayasi {
1204 1.7 sommerfe
1205 1.148.2.1 uebayasi ad->ad_notify = NULL;
1206 1.2 thorpej }
1207 1.2 thorpej
1208 1.2 thorpej /*
1209 1.148.2.1 uebayasi * Fixed buttons.
1210 1.146 jruoho */
1211 1.148.2.1 uebayasi static void
1212 1.148.2.1 uebayasi acpi_register_fixed_button(struct acpi_softc *sc, int event)
1213 1.146 jruoho {
1214 1.148.2.1 uebayasi struct sysmon_pswitch *smpsw;
1215 1.148.2.1 uebayasi ACPI_STATUS rv;
1216 1.148.2.1 uebayasi int type;
1217 1.146 jruoho
1218 1.148.2.1 uebayasi switch (event) {
1219 1.146 jruoho
1220 1.148.2.1 uebayasi case ACPI_EVENT_POWER_BUTTON:
1221 1.146 jruoho
1222 1.148.2.1 uebayasi if ((AcpiGbl_FADT.Flags & ACPI_FADT_POWER_BUTTON) != 0)
1223 1.148.2.1 uebayasi return;
1224 1.146 jruoho
1225 1.148.2.1 uebayasi type = PSWITCH_TYPE_POWER;
1226 1.148.2.1 uebayasi smpsw = &sc->sc_smpsw_power;
1227 1.148.2.1 uebayasi break;
1228 1.146 jruoho
1229 1.148.2.1 uebayasi case ACPI_EVENT_SLEEP_BUTTON:
1230 1.146 jruoho
1231 1.148.2.1 uebayasi if ((AcpiGbl_FADT.Flags & ACPI_FADT_SLEEP_BUTTON) != 0)
1232 1.148.2.1 uebayasi return;
1233 1.146 jruoho
1234 1.148.2.1 uebayasi type = PSWITCH_TYPE_SLEEP;
1235 1.148.2.1 uebayasi smpsw = &sc->sc_smpsw_sleep;
1236 1.148.2.1 uebayasi break;
1237 1.146 jruoho
1238 1.146 jruoho default:
1239 1.148.2.1 uebayasi rv = AE_TYPE;
1240 1.148.2.1 uebayasi goto fail;
1241 1.146 jruoho }
1242 1.146 jruoho
1243 1.148.2.1 uebayasi smpsw->smpsw_type = type;
1244 1.148.2.1 uebayasi smpsw->smpsw_name = device_xname(sc->sc_dev);
1245 1.65 kochi
1246 1.148.2.1 uebayasi if (sysmon_pswitch_register(smpsw) != 0) {
1247 1.148.2.1 uebayasi rv = AE_ERROR;
1248 1.148.2.1 uebayasi goto fail;
1249 1.65 kochi }
1250 1.65 kochi
1251 1.148.2.1 uebayasi rv = AcpiInstallFixedEventHandler(event,
1252 1.148.2.1 uebayasi acpi_fixed_button_handler, smpsw);
1253 1.65 kochi
1254 1.148.2.2 uebayasi if (ACPI_FAILURE(rv)) {
1255 1.148.2.2 uebayasi sysmon_pswitch_unregister(smpsw);
1256 1.148.2.1 uebayasi goto fail;
1257 1.148.2.2 uebayasi }
1258 1.65 kochi
1259 1.148.2.1 uebayasi aprint_debug_dev(sc->sc_dev, "fixed %s button present\n",
1260 1.148.2.1 uebayasi (type != ACPI_EVENT_SLEEP_BUTTON) ? "power" : "sleep");
1261 1.54 kochi
1262 1.148.2.1 uebayasi return;
1263 1.54 kochi
1264 1.148.2.1 uebayasi fail:
1265 1.148.2.1 uebayasi aprint_error_dev(sc->sc_dev, "failed to register "
1266 1.148.2.1 uebayasi "fixed event: %s\n", AcpiFormatException(rv));
1267 1.10 tshiozak }
1268 1.10 tshiozak
1269 1.118 dyoung static void
1270 1.148.2.1 uebayasi acpi_deregister_fixed_button(struct acpi_softc *sc, int event)
1271 1.69 kochi {
1272 1.148.2.1 uebayasi struct sysmon_pswitch *smpsw;
1273 1.69 kochi ACPI_STATUS rv;
1274 1.69 kochi
1275 1.148.2.1 uebayasi switch (event) {
1276 1.144 jruoho
1277 1.148.2.1 uebayasi case ACPI_EVENT_POWER_BUTTON:
1278 1.148.2.1 uebayasi smpsw = &sc->sc_smpsw_power;
1279 1.144 jruoho
1280 1.148.2.1 uebayasi if ((AcpiGbl_FADT.Flags & ACPI_FADT_POWER_BUTTON) != 0) {
1281 1.148.2.1 uebayasi KASSERT(smpsw->smpsw_type != PSWITCH_TYPE_POWER);
1282 1.148.2.1 uebayasi return;
1283 1.148.2.1 uebayasi }
1284 1.144 jruoho
1285 1.148.2.1 uebayasi break;
1286 1.144 jruoho
1287 1.148.2.1 uebayasi case ACPI_EVENT_SLEEP_BUTTON:
1288 1.148.2.1 uebayasi smpsw = &sc->sc_smpsw_sleep;
1289 1.144 jruoho
1290 1.148.2.1 uebayasi if ((AcpiGbl_FADT.Flags & ACPI_FADT_SLEEP_BUTTON) != 0) {
1291 1.148.2.1 uebayasi KASSERT(smpsw->smpsw_type != PSWITCH_TYPE_SLEEP);
1292 1.148.2.1 uebayasi return;
1293 1.148.2.1 uebayasi }
1294 1.69 kochi
1295 1.144 jruoho break;
1296 1.69 kochi
1297 1.144 jruoho default:
1298 1.148.2.1 uebayasi rv = AE_TYPE;
1299 1.148.2.1 uebayasi goto fail;
1300 1.144 jruoho }
1301 1.69 kochi
1302 1.148.2.1 uebayasi rv = AcpiRemoveFixedEventHandler(event, acpi_fixed_button_handler);
1303 1.69 kochi
1304 1.148.2.1 uebayasi if (ACPI_SUCCESS(rv)) {
1305 1.148.2.1 uebayasi sysmon_pswitch_unregister(smpsw);
1306 1.148.2.1 uebayasi return;
1307 1.148.2.1 uebayasi }
1308 1.69 kochi
1309 1.148.2.1 uebayasi fail:
1310 1.148.2.1 uebayasi aprint_error_dev(sc->sc_dev, "failed to deregister "
1311 1.148.2.1 uebayasi "fixed event: %s\n", AcpiFormatException(rv));
1312 1.118 dyoung }
1313 1.118 dyoung
1314 1.148.2.1 uebayasi static uint32_t
1315 1.148.2.1 uebayasi acpi_fixed_button_handler(void *context)
1316 1.118 dyoung {
1317 1.148.2.1 uebayasi static const int handler = OSL_NOTIFY_HANDLER;
1318 1.148.2.1 uebayasi struct sysmon_pswitch *smpsw = context;
1319 1.118 dyoung
1320 1.148.2.1 uebayasi (void)AcpiOsExecute(handler, acpi_fixed_button_pressed, smpsw);
1321 1.10 tshiozak
1322 1.148.2.1 uebayasi return ACPI_INTERRUPT_HANDLED;
1323 1.148.2.1 uebayasi }
1324 1.148.2.1 uebayasi
1325 1.148.2.1 uebayasi static void
1326 1.148.2.1 uebayasi acpi_fixed_button_pressed(void *context)
1327 1.10 tshiozak {
1328 1.148.2.1 uebayasi struct sysmon_pswitch *smpsw = context;
1329 1.10 tshiozak
1330 1.148.2.2 uebayasi ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s fixed button pressed\n",
1331 1.148.2.2 uebayasi (smpsw->smpsw_type != ACPI_EVENT_SLEEP_BUTTON) ?
1332 1.148.2.2 uebayasi "power" : "sleep"));
1333 1.148.2.1 uebayasi
1334 1.148.2.1 uebayasi sysmon_pswitch_event(smpsw, PSWITCH_EVENT_PRESSED);
1335 1.10 tshiozak }
1336 1.10 tshiozak
1337 1.10 tshiozak /*
1338 1.148.2.1 uebayasi * Sleep.
1339 1.10 tshiozak */
1340 1.148.2.1 uebayasi static void
1341 1.148.2.1 uebayasi acpi_sleep_init(struct acpi_softc *sc)
1342 1.148.2.1 uebayasi {
1343 1.148.2.1 uebayasi uint8_t a, b, i;
1344 1.148.2.1 uebayasi ACPI_STATUS rv;
1345 1.10 tshiozak
1346 1.148.2.1 uebayasi CTASSERT(ACPI_STATE_S0 == 0 && ACPI_STATE_S1 == 1);
1347 1.148.2.1 uebayasi CTASSERT(ACPI_STATE_S2 == 2 && ACPI_STATE_S3 == 3);
1348 1.148.2.1 uebayasi CTASSERT(ACPI_STATE_S4 == 4 && ACPI_STATE_S5 == 5);
1349 1.148.2.1 uebayasi
1350 1.148.2.1 uebayasi /*
1351 1.148.2.1 uebayasi * Evaluate supported sleep states.
1352 1.148.2.1 uebayasi */
1353 1.148.2.1 uebayasi for (i = ACPI_STATE_S0; i <= ACPI_STATE_S5; i++) {
1354 1.148.2.1 uebayasi
1355 1.148.2.1 uebayasi rv = AcpiGetSleepTypeData(i, &a, &b);
1356 1.148.2.1 uebayasi
1357 1.148.2.1 uebayasi if (ACPI_SUCCESS(rv))
1358 1.148.2.1 uebayasi sc->sc_sleepstates |= __BIT(i);
1359 1.148.2.1 uebayasi }
1360 1.148.2.1 uebayasi }
1361 1.148.2.1 uebayasi
1362 1.148.2.1 uebayasi void
1363 1.148.2.4 uebayasi acpi_enter_sleep_state(int state)
1364 1.10 tshiozak {
1365 1.148.2.4 uebayasi struct acpi_softc *sc = acpi_softc;
1366 1.148.2.1 uebayasi ACPI_STATUS rv;
1367 1.104 jmcneill int err;
1368 1.10 tshiozak
1369 1.148.2.4 uebayasi if (acpi_softc == NULL)
1370 1.148.2.4 uebayasi return;
1371 1.148.2.4 uebayasi
1372 1.148.2.1 uebayasi if (state == sc->sc_sleepstate)
1373 1.148.2.1 uebayasi return;
1374 1.92 christos
1375 1.148.2.4 uebayasi if (state < ACPI_STATE_S0 || state > ACPI_STATE_S5)
1376 1.148.2.4 uebayasi return;
1377 1.148.2.4 uebayasi
1378 1.148.2.1 uebayasi aprint_normal_dev(sc->sc_dev, "entering state S%d\n", state);
1379 1.92 christos
1380 1.10 tshiozak switch (state) {
1381 1.148.2.1 uebayasi
1382 1.10 tshiozak case ACPI_STATE_S0:
1383 1.148.2.1 uebayasi sc->sc_sleepstate = ACPI_STATE_S0;
1384 1.148.2.1 uebayasi return;
1385 1.148.2.1 uebayasi
1386 1.10 tshiozak case ACPI_STATE_S1:
1387 1.10 tshiozak case ACPI_STATE_S2:
1388 1.10 tshiozak case ACPI_STATE_S3:
1389 1.10 tshiozak case ACPI_STATE_S4:
1390 1.148.2.1 uebayasi
1391 1.148.2.1 uebayasi if ((sc->sc_sleepstates & __BIT(state)) == 0) {
1392 1.148.2.1 uebayasi aprint_error_dev(sc->sc_dev, "sleep state "
1393 1.148.2.1 uebayasi "S%d is not available\n", state);
1394 1.148.2.1 uebayasi return;
1395 1.10 tshiozak }
1396 1.104 jmcneill
1397 1.148.2.1 uebayasi /*
1398 1.148.2.1 uebayasi * Evaluate the _TTS method. This should be done before
1399 1.148.2.1 uebayasi * pmf_system_suspend(9) and the evaluation of _PTS.
1400 1.148.2.1 uebayasi * We should also re-evaluate this once we return to
1401 1.148.2.1 uebayasi * S0 or if we abort the sleep state transition in the
1402 1.148.2.1 uebayasi * middle (see ACPI 3.0, section 7.3.6). In reality,
1403 1.148.2.1 uebayasi * however, the _TTS method is seldom seen in the field.
1404 1.148.2.1 uebayasi */
1405 1.148.2.1 uebayasi rv = acpi_eval_set_integer(NULL, "\\_TTS", state);
1406 1.148.2.1 uebayasi
1407 1.148.2.1 uebayasi if (ACPI_SUCCESS(rv))
1408 1.148.2.1 uebayasi aprint_debug_dev(sc->sc_dev, "evaluated _TTS\n");
1409 1.148.2.1 uebayasi
1410 1.148.2.1 uebayasi if (state != ACPI_STATE_S1 &&
1411 1.148.2.1 uebayasi pmf_system_suspend(PMF_Q_NONE) != true) {
1412 1.113 jmcneill aprint_error_dev(sc->sc_dev, "aborting suspend\n");
1413 1.104 jmcneill break;
1414 1.104 jmcneill }
1415 1.104 jmcneill
1416 1.148.2.1 uebayasi /*
1417 1.148.2.1 uebayasi * This will evaluate the _PTS and _SST methods,
1418 1.148.2.1 uebayasi * but unlike the documentation claims, not _GTS,
1419 1.148.2.1 uebayasi * which is evaluated in AcpiEnterSleepState().
1420 1.148.2.1 uebayasi * This must be called with interrupts enabled.
1421 1.148.2.1 uebayasi */
1422 1.148.2.1 uebayasi rv = AcpiEnterSleepStatePrep(state);
1423 1.148.2.1 uebayasi
1424 1.148.2.1 uebayasi if (ACPI_FAILURE(rv)) {
1425 1.148.2.1 uebayasi aprint_error_dev(sc->sc_dev, "failed to prepare "
1426 1.148.2.1 uebayasi "S%d: %s\n", state, AcpiFormatException(rv));
1427 1.10 tshiozak break;
1428 1.10 tshiozak }
1429 1.104 jmcneill
1430 1.148.2.2 uebayasi /*
1431 1.148.2.2 uebayasi * After the _PTS method has been evaluated, we can
1432 1.148.2.2 uebayasi * enable wake and evaluate _PSW (ACPI 4.0, p. 284).
1433 1.148.2.2 uebayasi */
1434 1.148.2.2 uebayasi acpi_wakedev_commit(sc, state);
1435 1.148.2.2 uebayasi
1436 1.148.2.1 uebayasi sc->sc_sleepstate = state;
1437 1.148.2.1 uebayasi
1438 1.92 christos if (state == ACPI_STATE_S1) {
1439 1.148.2.1 uebayasi
1440 1.148.2.1 uebayasi /* Just enter the state. */
1441 1.12 kanaoka acpi_md_OsDisableInterrupt();
1442 1.148.2.1 uebayasi rv = AcpiEnterSleepState(state);
1443 1.148.2.1 uebayasi
1444 1.148.2.1 uebayasi if (ACPI_FAILURE(rv))
1445 1.148.2.1 uebayasi aprint_error_dev(sc->sc_dev, "failed to "
1446 1.148.2.1 uebayasi "enter S1: %s\n", AcpiFormatException(rv));
1447 1.148.2.1 uebayasi
1448 1.148.2.1 uebayasi (void)AcpiLeaveSleepState(state);
1449 1.148.2.1 uebayasi
1450 1.10 tshiozak } else {
1451 1.148.2.1 uebayasi
1452 1.104 jmcneill err = acpi_md_sleep(state);
1453 1.148.2.1 uebayasi
1454 1.104 jmcneill if (state == ACPI_STATE_S4)
1455 1.10 tshiozak AcpiEnable();
1456 1.148.2.1 uebayasi
1457 1.133 dyoung pmf_system_bus_resume(PMF_Q_NONE);
1458 1.148.2.1 uebayasi (void)AcpiLeaveSleepState(state);
1459 1.133 dyoung pmf_system_resume(PMF_Q_NONE);
1460 1.10 tshiozak }
1461 1.104 jmcneill
1462 1.10 tshiozak break;
1463 1.148.2.1 uebayasi
1464 1.10 tshiozak case ACPI_STATE_S5:
1465 1.148.2.1 uebayasi
1466 1.148.2.1 uebayasi (void)acpi_eval_set_integer(NULL, "\\_TTS", ACPI_STATE_S5);
1467 1.148.2.1 uebayasi
1468 1.148.2.1 uebayasi rv = AcpiEnterSleepStatePrep(ACPI_STATE_S5);
1469 1.148.2.1 uebayasi
1470 1.148.2.1 uebayasi if (ACPI_FAILURE(rv)) {
1471 1.148.2.1 uebayasi aprint_error_dev(sc->sc_dev, "failed to prepare "
1472 1.148.2.1 uebayasi "S%d: %s\n", state, AcpiFormatException(rv));
1473 1.42 kochi break;
1474 1.42 kochi }
1475 1.148.2.1 uebayasi
1476 1.104 jmcneill DELAY(1000000);
1477 1.10 tshiozak
1478 1.148.2.1 uebayasi sc->sc_sleepstate = state;
1479 1.148.2.1 uebayasi acpi_md_OsDisableInterrupt();
1480 1.13 augustss
1481 1.148.2.1 uebayasi (void)AcpiEnterSleepState(ACPI_STATE_S5);
1482 1.13 augustss
1483 1.148.2.1 uebayasi aprint_error_dev(sc->sc_dev, "WARNING: powerdown failed!\n");
1484 1.13 augustss
1485 1.148.2.1 uebayasi break;
1486 1.13 augustss }
1487 1.13 augustss
1488 1.148.2.1 uebayasi sc->sc_sleepstate = ACPI_STATE_S0;
1489 1.13 augustss
1490 1.148.2.1 uebayasi (void)acpi_eval_set_integer(NULL, "\\_TTS", ACPI_STATE_S0);
1491 1.13 augustss }
1492 1.79 cube
1493 1.148.2.1 uebayasi /*
1494 1.148.2.1 uebayasi * Sysctl.
1495 1.148.2.1 uebayasi */
1496 1.79 cube SYSCTL_SETUP(sysctl_acpi_setup, "sysctl hw.acpi subtree setup")
1497 1.79 cube {
1498 1.148.2.1 uebayasi const struct sysctlnode *mnode, *rnode;
1499 1.148.2.1 uebayasi int err;
1500 1.79 cube
1501 1.148.2.1 uebayasi err = sysctl_createv(clog, 0, NULL, &rnode,
1502 1.148.2.1 uebayasi CTLFLAG_PERMANENT, CTLTYPE_NODE, "hw",
1503 1.148.2.1 uebayasi NULL, NULL, 0, NULL, 0,
1504 1.148.2.1 uebayasi CTL_HW, CTL_EOL);
1505 1.148.2.1 uebayasi
1506 1.148.2.1 uebayasi if (err != 0)
1507 1.79 cube return;
1508 1.79 cube
1509 1.148.2.1 uebayasi err = sysctl_createv(clog, 0, &rnode, &rnode,
1510 1.148.2.1 uebayasi CTLFLAG_PERMANENT, CTLTYPE_NODE,
1511 1.148.2.1 uebayasi "acpi", SYSCTL_DESCR("ACPI subsystem parameters"),
1512 1.79 cube NULL, 0, NULL, 0,
1513 1.148.2.1 uebayasi CTL_CREATE, CTL_EOL);
1514 1.148.2.1 uebayasi
1515 1.148.2.1 uebayasi if (err != 0)
1516 1.79 cube return;
1517 1.79 cube
1518 1.148.2.1 uebayasi (void)sysctl_createv(NULL, 0, &rnode, NULL,
1519 1.148.2.1 uebayasi CTLFLAG_PERMANENT | CTLFLAG_READONLY, CTLTYPE_QUAD,
1520 1.148.2.1 uebayasi "root", SYSCTL_DESCR("ACPI root pointer"),
1521 1.109 jmcneill NULL, 0, &acpi_root_pointer, sizeof(acpi_root_pointer),
1522 1.148.2.1 uebayasi CTL_CREATE, CTL_EOL);
1523 1.148.2.1 uebayasi
1524 1.148.2.1 uebayasi (void)sysctl_createv(NULL, 0, &rnode, NULL,
1525 1.148.2.1 uebayasi CTLFLAG_PERMANENT | CTLFLAG_READONLY, CTLTYPE_STRING,
1526 1.148.2.1 uebayasi "supported_states", SYSCTL_DESCR("Supported system states"),
1527 1.148.2.1 uebayasi sysctl_hw_acpi_sleepstates, 0, NULL, 0,
1528 1.148.2.1 uebayasi CTL_CREATE, CTL_EOL);
1529 1.148.2.1 uebayasi
1530 1.148.2.1 uebayasi err = sysctl_createv(NULL, 0, NULL, &mnode,
1531 1.148.2.1 uebayasi CTLFLAG_PERMANENT, CTLTYPE_NODE, "machdep",
1532 1.148.2.1 uebayasi NULL, NULL, 0, NULL, 0,
1533 1.148.2.1 uebayasi CTL_MACHDEP, CTL_EOL);
1534 1.148.2.1 uebayasi
1535 1.148.2.1 uebayasi if (err == 0) {
1536 1.148.2.1 uebayasi
1537 1.148.2.1 uebayasi (void)sysctl_createv(NULL, 0, &mnode, NULL,
1538 1.148.2.1 uebayasi CTLFLAG_PERMANENT | CTLFLAG_READWRITE, CTLTYPE_INT,
1539 1.148.2.1 uebayasi "sleep_state", SYSCTL_DESCR("System sleep state"),
1540 1.148.2.1 uebayasi sysctl_hw_acpi_sleepstate, 0, NULL, 0,
1541 1.148.2.1 uebayasi CTL_CREATE, CTL_EOL);
1542 1.148.2.1 uebayasi }
1543 1.148.2.1 uebayasi
1544 1.148.2.1 uebayasi err = sysctl_createv(clog, 0, &rnode, &rnode,
1545 1.148.2.1 uebayasi CTLFLAG_PERMANENT, CTLTYPE_NODE,
1546 1.148.2.1 uebayasi "stat", SYSCTL_DESCR("ACPI statistics"),
1547 1.148.2.1 uebayasi NULL, 0, NULL, 0,
1548 1.148.2.1 uebayasi CTL_CREATE, CTL_EOL);
1549 1.148.2.1 uebayasi
1550 1.148.2.1 uebayasi if (err != 0)
1551 1.86 jmcneill return;
1552 1.148.2.1 uebayasi
1553 1.148.2.1 uebayasi (void)sysctl_createv(clog, 0, &rnode, NULL,
1554 1.148.2.1 uebayasi CTLFLAG_PERMANENT | CTLFLAG_READONLY, CTLTYPE_QUAD,
1555 1.148.2.1 uebayasi "gpe", SYSCTL_DESCR("Number of dispatched GPEs"),
1556 1.148.2.1 uebayasi NULL, 0, &AcpiGpeCount, sizeof(AcpiGpeCount),
1557 1.148.2.1 uebayasi CTL_CREATE, CTL_EOL);
1558 1.148.2.1 uebayasi
1559 1.148.2.1 uebayasi (void)sysctl_createv(clog, 0, &rnode, NULL,
1560 1.148.2.1 uebayasi CTLFLAG_PERMANENT | CTLFLAG_READONLY, CTLTYPE_QUAD,
1561 1.148.2.1 uebayasi "sci", SYSCTL_DESCR("Number of SCI interrupts"),
1562 1.148.2.1 uebayasi NULL, 0, &AcpiSciCount, sizeof(AcpiSciCount),
1563 1.148.2.1 uebayasi CTL_CREATE, CTL_EOL);
1564 1.148.2.1 uebayasi
1565 1.148.2.1 uebayasi (void)sysctl_createv(clog, 0, &rnode, NULL,
1566 1.148.2.1 uebayasi CTLFLAG_PERMANENT | CTLFLAG_READONLY, CTLTYPE_QUAD,
1567 1.148.2.1 uebayasi "fixed", SYSCTL_DESCR("Number of fixed events"),
1568 1.148.2.1 uebayasi sysctl_hw_acpi_fixedstats, 0, NULL, 0,
1569 1.148.2.1 uebayasi CTL_CREATE, CTL_EOL);
1570 1.148.2.1 uebayasi
1571 1.148.2.1 uebayasi (void)sysctl_createv(clog, 0, &rnode, NULL,
1572 1.148.2.1 uebayasi CTLFLAG_PERMANENT | CTLFLAG_READONLY, CTLTYPE_QUAD,
1573 1.148.2.1 uebayasi "method", SYSCTL_DESCR("Number of methods executed"),
1574 1.148.2.1 uebayasi NULL, 0, &AcpiMethodCount, sizeof(AcpiMethodCount),
1575 1.148.2.1 uebayasi CTL_CREATE, CTL_EOL);
1576 1.148.2.1 uebayasi
1577 1.148.2.1 uebayasi CTASSERT(sizeof(AcpiGpeCount) == sizeof(uint64_t));
1578 1.148.2.1 uebayasi CTASSERT(sizeof(AcpiSciCount) == sizeof(uint64_t));
1579 1.148.2.1 uebayasi }
1580 1.148.2.1 uebayasi
1581 1.148.2.1 uebayasi static int
1582 1.148.2.1 uebayasi sysctl_hw_acpi_fixedstats(SYSCTLFN_ARGS)
1583 1.148.2.1 uebayasi {
1584 1.148.2.1 uebayasi struct sysctlnode node;
1585 1.148.2.1 uebayasi uint64_t t;
1586 1.148.2.1 uebayasi int err, i;
1587 1.148.2.1 uebayasi
1588 1.148.2.1 uebayasi for (i = t = 0; i < __arraycount(AcpiFixedEventCount); i++)
1589 1.148.2.1 uebayasi t += AcpiFixedEventCount[i];
1590 1.148.2.1 uebayasi
1591 1.148.2.1 uebayasi node = *rnode;
1592 1.148.2.1 uebayasi node.sysctl_data = &t;
1593 1.148.2.1 uebayasi
1594 1.148.2.1 uebayasi err = sysctl_lookup(SYSCTLFN_CALL(&node));
1595 1.148.2.1 uebayasi
1596 1.148.2.1 uebayasi if (err || newp == NULL)
1597 1.148.2.1 uebayasi return err;
1598 1.148.2.1 uebayasi
1599 1.148.2.1 uebayasi return 0;
1600 1.86 jmcneill }
1601 1.86 jmcneill
1602 1.86 jmcneill static int
1603 1.86 jmcneill sysctl_hw_acpi_sleepstate(SYSCTLFN_ARGS)
1604 1.86 jmcneill {
1605 1.148.2.1 uebayasi struct acpi_softc *sc = acpi_softc;
1606 1.86 jmcneill struct sysctlnode node;
1607 1.148.2.1 uebayasi int err, t;
1608 1.148.2.1 uebayasi
1609 1.148.2.1 uebayasi if (acpi_softc == NULL)
1610 1.148.2.1 uebayasi return ENOSYS;
1611 1.86 jmcneill
1612 1.86 jmcneill node = *rnode;
1613 1.148.2.1 uebayasi t = sc->sc_sleepstate;
1614 1.86 jmcneill node.sysctl_data = &t;
1615 1.148.2.1 uebayasi
1616 1.148.2.1 uebayasi err = sysctl_lookup(SYSCTLFN_CALL(&node));
1617 1.148.2.1 uebayasi
1618 1.148.2.1 uebayasi if (err || newp == NULL)
1619 1.148.2.1 uebayasi return err;
1620 1.148.2.1 uebayasi
1621 1.148.2.1 uebayasi if (t < ACPI_STATE_S0 || t > ACPI_STATE_S5)
1622 1.148.2.1 uebayasi return EINVAL;
1623 1.148.2.1 uebayasi
1624 1.148.2.4 uebayasi acpi_enter_sleep_state(t);
1625 1.148.2.1 uebayasi
1626 1.148.2.1 uebayasi return 0;
1627 1.148.2.1 uebayasi }
1628 1.148.2.1 uebayasi
1629 1.148.2.1 uebayasi static int
1630 1.148.2.1 uebayasi sysctl_hw_acpi_sleepstates(SYSCTLFN_ARGS)
1631 1.148.2.1 uebayasi {
1632 1.148.2.1 uebayasi struct acpi_softc *sc = acpi_softc;
1633 1.148.2.1 uebayasi struct sysctlnode node;
1634 1.148.2.1 uebayasi char t[3 * 6 + 1];
1635 1.148.2.1 uebayasi int err;
1636 1.86 jmcneill
1637 1.92 christos if (acpi_softc == NULL)
1638 1.92 christos return ENOSYS;
1639 1.86 jmcneill
1640 1.148.2.1 uebayasi (void)memset(t, '\0', sizeof(t));
1641 1.148.2.1 uebayasi
1642 1.148.2.1 uebayasi (void)snprintf(t, sizeof(t), "%s%s%s%s%s%s",
1643 1.148.2.1 uebayasi ((sc->sc_sleepstates & __BIT(0)) != 0) ? "S0 " : "",
1644 1.148.2.1 uebayasi ((sc->sc_sleepstates & __BIT(1)) != 0) ? "S1 " : "",
1645 1.148.2.1 uebayasi ((sc->sc_sleepstates & __BIT(2)) != 0) ? "S2 " : "",
1646 1.148.2.1 uebayasi ((sc->sc_sleepstates & __BIT(3)) != 0) ? "S3 " : "",
1647 1.148.2.1 uebayasi ((sc->sc_sleepstates & __BIT(4)) != 0) ? "S4 " : "",
1648 1.148.2.1 uebayasi ((sc->sc_sleepstates & __BIT(5)) != 0) ? "S5 " : "");
1649 1.148.2.1 uebayasi
1650 1.148.2.1 uebayasi node = *rnode;
1651 1.148.2.1 uebayasi node.sysctl_data = &t;
1652 1.148.2.1 uebayasi
1653 1.148.2.1 uebayasi err = sysctl_lookup(SYSCTLFN_CALL(&node));
1654 1.148.2.1 uebayasi
1655 1.148.2.1 uebayasi if (err || newp == NULL)
1656 1.148.2.1 uebayasi return err;
1657 1.86 jmcneill
1658 1.86 jmcneill return 0;
1659 1.79 cube }
1660 1.108 jmcneill
1661 1.148.2.1 uebayasi /*
1662 1.148.2.2 uebayasi * Tables.
1663 1.148.2.1 uebayasi */
1664 1.148.2.1 uebayasi ACPI_PHYSICAL_ADDRESS
1665 1.148.2.1 uebayasi acpi_OsGetRootPointer(void)
1666 1.148.2.1 uebayasi {
1667 1.148.2.1 uebayasi ACPI_PHYSICAL_ADDRESS PhysicalAddress;
1668 1.148.2.1 uebayasi
1669 1.148.2.1 uebayasi /*
1670 1.148.2.1 uebayasi * We let MD code handle this since there are multiple ways to do it:
1671 1.148.2.1 uebayasi *
1672 1.148.2.1 uebayasi * IA-32: Use AcpiFindRootPointer() to locate the RSDP.
1673 1.148.2.1 uebayasi *
1674 1.148.2.1 uebayasi * IA-64: Use the EFI.
1675 1.148.2.1 uebayasi */
1676 1.148.2.1 uebayasi PhysicalAddress = acpi_md_OsGetRootPointer();
1677 1.148.2.1 uebayasi
1678 1.148.2.1 uebayasi if (acpi_root_pointer == 0)
1679 1.148.2.1 uebayasi acpi_root_pointer = PhysicalAddress;
1680 1.148.2.1 uebayasi
1681 1.148.2.1 uebayasi return PhysicalAddress;
1682 1.148.2.1 uebayasi }
1683 1.148.2.1 uebayasi
1684 1.108 jmcneill static ACPI_TABLE_HEADER *
1685 1.108 jmcneill acpi_map_rsdt(void)
1686 1.108 jmcneill {
1687 1.108 jmcneill ACPI_PHYSICAL_ADDRESS paddr;
1688 1.108 jmcneill ACPI_TABLE_RSDP *rsdp;
1689 1.108 jmcneill
1690 1.108 jmcneill paddr = AcpiOsGetRootPointer();
1691 1.148.2.1 uebayasi
1692 1.148.2.1 uebayasi if (paddr == 0)
1693 1.108 jmcneill return NULL;
1694 1.148.2.1 uebayasi
1695 1.108 jmcneill rsdp = AcpiOsMapMemory(paddr, sizeof(ACPI_TABLE_RSDP));
1696 1.148.2.1 uebayasi
1697 1.148.2.1 uebayasi if (rsdp == NULL)
1698 1.108 jmcneill return NULL;
1699 1.148.2.1 uebayasi
1700 1.108 jmcneill if (rsdp->Revision > 1 && rsdp->XsdtPhysicalAddress)
1701 1.148.2.1 uebayasi paddr = rsdp->XsdtPhysicalAddress;
1702 1.108 jmcneill else
1703 1.148.2.1 uebayasi paddr = rsdp->RsdtPhysicalAddress;
1704 1.148.2.1 uebayasi
1705 1.108 jmcneill AcpiOsUnmapMemory(rsdp, sizeof(ACPI_TABLE_RSDP));
1706 1.108 jmcneill
1707 1.108 jmcneill return AcpiOsMapMemory(paddr, sizeof(ACPI_TABLE_HEADER));
1708 1.108 jmcneill }
1709 1.108 jmcneill
1710 1.108 jmcneill static void
1711 1.108 jmcneill acpi_unmap_rsdt(ACPI_TABLE_HEADER *rsdt)
1712 1.108 jmcneill {
1713 1.148.2.1 uebayasi
1714 1.108 jmcneill if (rsdt == NULL)
1715 1.108 jmcneill return;
1716 1.108 jmcneill
1717 1.108 jmcneill AcpiOsUnmapMemory(rsdt, sizeof(ACPI_TABLE_HEADER));
1718 1.108 jmcneill }
1719 1.148.2.2 uebayasi
1720 1.148.2.2 uebayasi /*
1721 1.148.2.2 uebayasi * XXX: Refactor to be a generic function that maps tables.
1722 1.148.2.2 uebayasi */
1723 1.148.2.2 uebayasi ACPI_STATUS
1724 1.148.2.2 uebayasi acpi_madt_map(void)
1725 1.148.2.2 uebayasi {
1726 1.148.2.2 uebayasi ACPI_STATUS rv;
1727 1.148.2.2 uebayasi
1728 1.148.2.2 uebayasi if (madt_header != NULL)
1729 1.148.2.2 uebayasi return AE_ALREADY_EXISTS;
1730 1.148.2.2 uebayasi
1731 1.148.2.2 uebayasi rv = AcpiGetTable(ACPI_SIG_MADT, 1, &madt_header);
1732 1.148.2.2 uebayasi
1733 1.148.2.2 uebayasi if (ACPI_FAILURE(rv))
1734 1.148.2.2 uebayasi return rv;
1735 1.148.2.2 uebayasi
1736 1.148.2.2 uebayasi return AE_OK;
1737 1.148.2.2 uebayasi }
1738 1.148.2.2 uebayasi
1739 1.148.2.2 uebayasi void
1740 1.148.2.2 uebayasi acpi_madt_unmap(void)
1741 1.148.2.2 uebayasi {
1742 1.148.2.2 uebayasi madt_header = NULL;
1743 1.148.2.2 uebayasi }
1744 1.148.2.2 uebayasi
1745 1.148.2.2 uebayasi /*
1746 1.148.2.2 uebayasi * XXX: Refactor to be a generic function that walks tables.
1747 1.148.2.2 uebayasi */
1748 1.148.2.2 uebayasi void
1749 1.148.2.2 uebayasi acpi_madt_walk(ACPI_STATUS (*func)(ACPI_SUBTABLE_HEADER *, void *), void *aux)
1750 1.148.2.2 uebayasi {
1751 1.148.2.2 uebayasi ACPI_SUBTABLE_HEADER *hdrp;
1752 1.148.2.2 uebayasi char *madtend, *where;
1753 1.148.2.2 uebayasi
1754 1.148.2.2 uebayasi madtend = (char *)madt_header + madt_header->Length;
1755 1.148.2.2 uebayasi where = (char *)madt_header + sizeof (ACPI_TABLE_MADT);
1756 1.148.2.2 uebayasi
1757 1.148.2.2 uebayasi while (where < madtend) {
1758 1.148.2.2 uebayasi
1759 1.148.2.2 uebayasi hdrp = (ACPI_SUBTABLE_HEADER *)where;
1760 1.148.2.2 uebayasi
1761 1.148.2.2 uebayasi if (ACPI_FAILURE(func(hdrp, aux)))
1762 1.148.2.2 uebayasi break;
1763 1.148.2.2 uebayasi
1764 1.148.2.2 uebayasi where += hdrp->Length;
1765 1.148.2.2 uebayasi }
1766 1.148.2.2 uebayasi }
1767 1.148.2.2 uebayasi
1768 1.148.2.2 uebayasi /*
1769 1.148.2.2 uebayasi * Miscellaneous.
1770 1.148.2.2 uebayasi */
1771 1.148.2.2 uebayasi static bool
1772 1.148.2.2 uebayasi acpi_is_scope(struct acpi_devnode *ad)
1773 1.148.2.2 uebayasi {
1774 1.148.2.2 uebayasi int i;
1775 1.148.2.2 uebayasi
1776 1.148.2.2 uebayasi /*
1777 1.148.2.2 uebayasi * Return true if the node is a root scope.
1778 1.148.2.2 uebayasi */
1779 1.148.2.2 uebayasi if (ad->ad_parent == NULL)
1780 1.148.2.2 uebayasi return false;
1781 1.148.2.2 uebayasi
1782 1.148.2.2 uebayasi if (ad->ad_parent->ad_handle != ACPI_ROOT_OBJECT)
1783 1.148.2.2 uebayasi return false;
1784 1.148.2.2 uebayasi
1785 1.148.2.2 uebayasi for (i = 0; i < __arraycount(acpi_scopes); i++) {
1786 1.148.2.2 uebayasi
1787 1.148.2.2 uebayasi if (acpi_scopes[i] == NULL)
1788 1.148.2.2 uebayasi continue;
1789 1.148.2.2 uebayasi
1790 1.148.2.2 uebayasi if (ad->ad_handle == acpi_scopes[i])
1791 1.148.2.2 uebayasi return true;
1792 1.148.2.2 uebayasi }
1793 1.148.2.2 uebayasi
1794 1.148.2.2 uebayasi return false;
1795 1.148.2.2 uebayasi }
1796 1.148.2.2 uebayasi
1797 1.148.2.2 uebayasi /*
1798 1.148.2.2 uebayasi * ACPIVERBOSE.
1799 1.148.2.2 uebayasi */
1800 1.148.2.2 uebayasi void
1801 1.148.2.2 uebayasi acpi_load_verbose(void)
1802 1.148.2.2 uebayasi {
1803 1.148.2.2 uebayasi
1804 1.148.2.3 uebayasi if (acpi_verbose_loaded == 0)
1805 1.148.2.2 uebayasi module_autoload("acpiverbose", MODULE_CLASS_MISC);
1806 1.148.2.2 uebayasi }
1807 1.148.2.2 uebayasi
1808 1.148.2.2 uebayasi void
1809 1.148.2.2 uebayasi acpi_print_verbose_stub(struct acpi_softc *sc)
1810 1.148.2.2 uebayasi {
1811 1.148.2.2 uebayasi
1812 1.148.2.2 uebayasi acpi_load_verbose();
1813 1.148.2.2 uebayasi
1814 1.148.2.2 uebayasi if (acpi_verbose_loaded != 0)
1815 1.148.2.2 uebayasi acpi_print_verbose(sc);
1816 1.148.2.2 uebayasi }
1817 1.148.2.2 uebayasi
1818 1.148.2.2 uebayasi void
1819 1.148.2.2 uebayasi acpi_print_dev_stub(const char *pnpstr)
1820 1.148.2.2 uebayasi {
1821 1.148.2.2 uebayasi
1822 1.148.2.2 uebayasi acpi_load_verbose();
1823 1.148.2.2 uebayasi
1824 1.148.2.2 uebayasi if (acpi_verbose_loaded != 0)
1825 1.148.2.2 uebayasi acpi_print_dev(pnpstr);
1826 1.148.2.2 uebayasi }
1827