Fri Sep 19 11:19:33 2008 UTC ()
Revert previous.


(jmcneill)
diff -r1.119 -r1.120 src/sys/dev/acpi/acpi.c

cvs diff -r1.119 -r1.120 src/sys/dev/acpi/acpi.c (switch to unified diff)

--- src/sys/dev/acpi/acpi.c 2008/09/10 03:56:12 1.119
+++ src/sys/dev/acpi/acpi.c 2008/09/19 11:19:33 1.120
@@ -1,1506 +1,1504 @@ @@ -1,1506 +1,1504 @@
1/* $NetBSD: acpi.c,v 1.119 2008/09/10 03:56:12 jmcneill Exp $ */ 1/* $NetBSD: acpi.c,v 1.120 2008/09/19 11:19:33 jmcneill 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 2001, 2003 Wasabi Systems, Inc. 33 * Copyright 2001, 2003 Wasabi Systems, Inc.
34 * All rights reserved. 34 * All rights reserved.
35 * 35 *
36 * Written by Jason R. Thorpe for Wasabi Systems, Inc. 36 * Written by Jason R. Thorpe 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 * Autoconfiguration support for the Intel ACPI Component Architecture 68 * Autoconfiguration support for the Intel ACPI Component Architecture
69 * ACPI reference implementation. 69 * ACPI reference implementation.
70 */ 70 */
71 71
72#include <sys/cdefs.h> 72#include <sys/cdefs.h>
73__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.119 2008/09/10 03:56:12 jmcneill Exp $"); 73__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.120 2008/09/19 11:19:33 jmcneill Exp $");
74 74
75#include "opt_acpi.h" 75#include "opt_acpi.h"
76#include "opt_pcifixup.h" 76#include "opt_pcifixup.h"
77 77
78#include <sys/param.h> 78#include <sys/param.h>
79#include <sys/systm.h> 79#include <sys/systm.h>
80#include <sys/device.h> 80#include <sys/device.h>
81#include <sys/malloc.h> 81#include <sys/malloc.h>
82#include <sys/mutex.h> 82#include <sys/mutex.h>
83#include <sys/kernel.h> 83#include <sys/kernel.h>
84#include <sys/proc.h> 84#include <sys/proc.h>
85#include <sys/sysctl.h> 85#include <sys/sysctl.h>
86 86
87#include <dev/acpi/acpica.h> 87#include <dev/acpi/acpica.h>
88#include <dev/acpi/acpireg.h> 88#include <dev/acpi/acpireg.h>
89#include <dev/acpi/acpivar.h> 89#include <dev/acpi/acpivar.h>
90#include <dev/acpi/acpi_osd.h> 90#include <dev/acpi/acpi_osd.h>
91#include <dev/acpi/acpi_timer.h> 91#include <dev/acpi/acpi_timer.h>
92#ifdef ACPIVERBOSE 92#ifdef ACPIVERBOSE
93#include <dev/acpi/acpidevs_data.h> 93#include <dev/acpi/acpidevs_data.h>
94#endif 94#endif
95 95
96#if defined(ACPI_PCI_FIXUP) 96#if defined(ACPI_PCI_FIXUP)
97#error The option ACPI_PCI_FIXUP has been obsoleted by PCI_INTR_FIXUP_DISABLED. Please adjust your kernel configuration file. 97#error The option ACPI_PCI_FIXUP has been obsoleted by PCI_INTR_FIXUP_DISABLED. Please adjust your kernel configuration file.
98#endif 98#endif
99 99
100#ifdef PCI_INTR_FIXUP_DISABLED 100#ifdef PCI_INTR_FIXUP_DISABLED
101#include <dev/pci/pcidevs.h> 101#include <dev/pci/pcidevs.h>
102#endif 102#endif
103 103
104MALLOC_DECLARE(M_ACPI); 104MALLOC_DECLARE(M_ACPI);
105 105
106#include <machine/acpi_machdep.h> 106#include <machine/acpi_machdep.h>
107 107
108#ifdef ACPI_DEBUGGER 108#ifdef ACPI_DEBUGGER
109#define ACPI_DBGR_INIT 0x01 109#define ACPI_DBGR_INIT 0x01
110#define ACPI_DBGR_TABLES 0x02 110#define ACPI_DBGR_TABLES 0x02
111#define ACPI_DBGR_ENABLE 0x04 111#define ACPI_DBGR_ENABLE 0x04
112#define ACPI_DBGR_PROBE 0x08 112#define ACPI_DBGR_PROBE 0x08
113#define ACPI_DBGR_RUNNING 0x10 113#define ACPI_DBGR_RUNNING 0x10
114 114
115static int acpi_dbgr = 0x00; 115static int acpi_dbgr = 0x00;
116#endif 116#endif
117 117
118static ACPI_TABLE_DESC acpi_initial_tables[128]; 118static ACPI_TABLE_DESC acpi_initial_tables[128];
119 119
120static int acpi_match(device_t, struct cfdata *, void *); 120static int acpi_match(device_t, struct cfdata *, void *);
121static void acpi_attach(device_t, device_t, void *); 121static void acpi_attach(device_t, device_t, void *);
122static void acpi_childdet(device_t, device_t); 122static void acpi_childdet(device_t, device_t);
123 123
124static int acpi_print(void *aux, const char *); 124static int acpi_print(void *aux, const char *);
125 125
126static int sysctl_hw_acpi_sleepstate(SYSCTLFN_ARGS); 126static int sysctl_hw_acpi_sleepstate(SYSCTLFN_ARGS);
127 127
128extern struct cfdriver acpi_cd; 128extern struct cfdriver acpi_cd;
129 129
130CFATTACH_DECL2_NEW(acpi, sizeof(struct acpi_softc), 130CFATTACH_DECL2_NEW(acpi, sizeof(struct acpi_softc),
131 acpi_match, acpi_attach, NULL, NULL, NULL, acpi_childdet); 131 acpi_match, acpi_attach, NULL, NULL, NULL, acpi_childdet);
132 132
133/* 133/*
134 * This is a flag we set when the ACPI subsystem is active. Machine 134 * This is a flag we set when the ACPI subsystem is active. Machine
135 * dependent code may wish to skip other steps (such as attaching 135 * dependent code may wish to skip other steps (such as attaching
136 * subsystems that ACPI supercedes) when ACPI is active. 136 * subsystems that ACPI supercedes) when ACPI is active.
137 */ 137 */
138int acpi_active; 138int acpi_active;
139int acpi_force_load; 139int acpi_force_load;
140 140
141/* 141/*
142 * Pointer to the ACPI subsystem's state. There can be only 142 * Pointer to the ACPI subsystem's state. There can be only
143 * one ACPI instance. 143 * one ACPI instance.
144 */ 144 */
145struct acpi_softc *acpi_softc; 145struct acpi_softc *acpi_softc;
146 146
147/* 147/*
148 * Locking stuff. 148 * Locking stuff.
149 */ 149 */
150static kmutex_t acpi_slock; 150static kmutex_t acpi_slock;
151static int acpi_locked; 151static int acpi_locked;
152extern kmutex_t acpi_interrupt_list_mtx; 152extern kmutex_t acpi_interrupt_list_mtx;
153 153
154/* 154/*
155 * Ignored HIDs 155 * Ignored HIDs
156 */ 156 */
157static const char * const acpi_ignored_ids[] = { 157static const char * const acpi_ignored_ids[] = {
158#if defined(i386) || defined(x86_64) 158#if defined(i386) || defined(x86_64)
159 "PNP0000", /* AT interrupt controller is handled internally */ 159 "PNP0000", /* AT interrupt controller is handled internally */
160 "PNP0200", /* AT DMA controller is handled internally */ 160 "PNP0200", /* AT DMA controller is handled internally */
161 "PNP0A??", /* Busses aren't enumerated with ACPI yet */ 161 "PNP0A??", /* Busses aren't enumerated with ACPI yet */
162 "PNP0B00", /* AT RTC is handled internally */ 162 "PNP0B00", /* AT RTC is handled internally */
163 "PNP0C01", /* No "System Board" driver */ 163 "PNP0C01", /* No "System Board" driver */
164 "PNP0C02", /* No "PnP motherboard register resources" driver */ 164 "PNP0C02", /* No "PnP motherboard register resources" driver */
165 "PNP0C0F", /* ACPI PCI link devices are handled internally */ 165 "PNP0C0F", /* ACPI PCI link devices are handled internally */
166#endif 166#endif
167#if defined(x86_64) 167#if defined(x86_64)
168 "PNP0C04", /* FPU is handled internally */ 168 "PNP0C04", /* FPU is handled internally */
169#endif 169#endif
170 NULL 170 NULL
171}; 171};
172 172
173/* 173/*
174 * sysctl-related information 174 * sysctl-related information
175 */ 175 */
176 176
177static uint64_t acpi_root_pointer; /* found as hw.acpi.root */ 177static uint64_t acpi_root_pointer; /* found as hw.acpi.root */
178static int acpi_sleepstate = ACPI_STATE_S0; 178static int acpi_sleepstate = ACPI_STATE_S0;
179static char acpi_supported_states[3 * 6 + 1] = "";; 179static char acpi_supported_states[3 * 6 + 1] = "";;
180 180
181/* 181/*
182 * Prototypes. 182 * Prototypes.
183 */ 183 */
184static void acpi_build_tree(struct acpi_softc *); 184static void acpi_build_tree(struct acpi_softc *);
185static ACPI_STATUS acpi_make_devnode(ACPI_HANDLE, UINT32, void *, void **); 185static ACPI_STATUS acpi_make_devnode(ACPI_HANDLE, UINT32, void *, void **);
186 186
187static void acpi_enable_fixed_events(struct acpi_softc *); 187static void acpi_enable_fixed_events(struct acpi_softc *);
188 188
189static ACPI_TABLE_HEADER *acpi_map_rsdt(void); 189static ACPI_TABLE_HEADER *acpi_map_rsdt(void);
190static void acpi_unmap_rsdt(ACPI_TABLE_HEADER *); 190static void acpi_unmap_rsdt(ACPI_TABLE_HEADER *);
191static int is_available_state(struct acpi_softc *, int); 191static int is_available_state(struct acpi_softc *, int);
192 192
193/* 193/*
194 * acpi_probe: 194 * acpi_probe:
195 * 195 *
196 * Probe for ACPI support. This is called by the 196 * Probe for ACPI support. This is called by the
197 * machine-dependent ACPI front-end. All of the 197 * machine-dependent ACPI front-end. All of the
198 * actual work is done by ACPICA. 198 * actual work is done by ACPICA.
199 * 199 *
200 * NOTE: This is not an autoconfiguration interface function. 200 * NOTE: This is not an autoconfiguration interface function.
201 */ 201 */
202int 202int
203acpi_probe(void) 203acpi_probe(void)
204{ 204{
205 static int beenhere; 205 static int beenhere;
206 ACPI_TABLE_HEADER *rsdt; 206 ACPI_TABLE_HEADER *rsdt;
207 ACPI_STATUS rv; 207 ACPI_STATUS rv;
208 208
209 if (beenhere != 0) 209 if (beenhere != 0)
210 panic("acpi_probe: ACPI has already been probed"); 210 panic("acpi_probe: ACPI has already been probed");
211 beenhere = 1; 211 beenhere = 1;
212 212
213 mutex_init(&acpi_slock, MUTEX_DEFAULT, IPL_NONE); 213 mutex_init(&acpi_slock, MUTEX_DEFAULT, IPL_NONE);
214 mutex_init(&acpi_interrupt_list_mtx, MUTEX_DEFAULT, IPL_NONE); 214 mutex_init(&acpi_interrupt_list_mtx, MUTEX_DEFAULT, IPL_NONE);
215 acpi_locked = 0; 215 acpi_locked = 0;
216 216
217 /* 217 /*
218 * Start up ACPICA. 218 * Start up ACPICA.
219 */ 219 */
220#ifdef ACPI_DEBUGGER 220#ifdef ACPI_DEBUGGER
221 if (acpi_dbgr & ACPI_DBGR_INIT) 221 if (acpi_dbgr & ACPI_DBGR_INIT)
222 acpi_osd_debugger(); 222 acpi_osd_debugger();
223#endif 223#endif
224 224
225 AcpiGbl_AllMethodsSerialized = FALSE; 225 AcpiGbl_AllMethodsSerialized = FALSE;
226 AcpiGbl_EnableInterpreterSlack = TRUE; 226 AcpiGbl_EnableInterpreterSlack = TRUE;
227 227
228 rv = AcpiInitializeSubsystem(); 228 rv = AcpiInitializeSubsystem();
229 if (ACPI_FAILURE(rv)) { 229 if (ACPI_FAILURE(rv)) {
230 printf("ACPI: unable to initialize ACPICA: %s\n", 230 printf("ACPI: unable to initialize ACPICA: %s\n",
231 AcpiFormatException(rv)); 231 AcpiFormatException(rv));
232 return 0; 232 return 0;
233 } 233 }
234 234
235 rv = AcpiInitializeTables(acpi_initial_tables, 128, 0); 235 rv = AcpiInitializeTables(acpi_initial_tables, 128, 0);
236 if (ACPI_FAILURE(rv)) { 236 if (ACPI_FAILURE(rv)) {
237 printf("ACPI: unable to initialize ACPI tables: %s\n", 237 printf("ACPI: unable to initialize ACPI tables: %s\n",
238 AcpiFormatException(rv)); 238 AcpiFormatException(rv));
239 return 0; 239 return 0;
240 } 240 }
241 241
242 rv = AcpiReallocateRootTable(); 242 rv = AcpiReallocateRootTable();
243 if (ACPI_FAILURE(rv)) { 243 if (ACPI_FAILURE(rv)) {
244 printf("ACPI: unable to reallocate root table: %s\n", 244 printf("ACPI: unable to reallocate root table: %s\n",
245 AcpiFormatException(rv)); 245 AcpiFormatException(rv));
246 return 0; 246 return 0;
247 } 247 }
248 248
249#ifdef ACPI_DEBUGGER 249#ifdef ACPI_DEBUGGER
250 if (acpi_dbgr & ACPI_DBGR_TABLES) 250 if (acpi_dbgr & ACPI_DBGR_TABLES)
251 acpi_osd_debugger(); 251 acpi_osd_debugger();
252#endif 252#endif
253 253
254 rv = AcpiLoadTables(); 254 rv = AcpiLoadTables();
255 if (ACPI_FAILURE(rv)) { 255 if (ACPI_FAILURE(rv)) {
256 printf("ACPI: unable to load tables: %s\n", 256 printf("ACPI: unable to load tables: %s\n",
257 AcpiFormatException(rv)); 257 AcpiFormatException(rv));
258 return 0; 258 return 0;
259 } 259 }
260 260
261 rsdt = acpi_map_rsdt(); 261 rsdt = acpi_map_rsdt();
262 if (rsdt == NULL) { 262 if (rsdt == NULL) {
263 printf("ACPI: unable to map RSDT\n"); 263 printf("ACPI: unable to map RSDT\n");
264 return 0; 264 return 0;
265 } 265 }
266 266
267 if (!acpi_force_load && (acpi_find_quirks() & ACPI_QUIRK_BROKEN)) { 267 if (!acpi_force_load && (acpi_find_quirks() & ACPI_QUIRK_BROKEN)) {
268 printf("ACPI: BIOS implementation in listed as broken:\n"); 268 printf("ACPI: BIOS implementation in listed as broken:\n");
269 printf("ACPI: X/RSDT: OemId <%6.6s,%8.8s,%08x>, " 269 printf("ACPI: X/RSDT: OemId <%6.6s,%8.8s,%08x>, "
270 "AslId <%4.4s,%08x>\n", 270 "AslId <%4.4s,%08x>\n",
271 rsdt->OemId, rsdt->OemTableId, 271 rsdt->OemId, rsdt->OemTableId,
272 rsdt->OemRevision, 272 rsdt->OemRevision,
273 rsdt->AslCompilerId, 273 rsdt->AslCompilerId,
274 rsdt->AslCompilerRevision); 274 rsdt->AslCompilerRevision);
275 printf("ACPI: not used. set acpi_force_load to use anyway.\n"); 275 printf("ACPI: not used. set acpi_force_load to use anyway.\n");
276 acpi_unmap_rsdt(rsdt); 276 acpi_unmap_rsdt(rsdt);
277 return 0; 277 return 0;
278 } 278 }
279 279
280 acpi_unmap_rsdt(rsdt); 280 acpi_unmap_rsdt(rsdt);
281 281
282#if notyet 282#if notyet
283 /* Install the default address space handlers. */ 283 /* Install the default address space handlers. */
284 rv = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT, 284 rv = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
285 ACPI_ADR_SPACE_SYSTEM_MEMORY, ACPI_DEFAULT_HANDLER, NULL, NULL); 285 ACPI_ADR_SPACE_SYSTEM_MEMORY, ACPI_DEFAULT_HANDLER, NULL, NULL);
286 if (ACPI_FAILURE(rv)) { 286 if (ACPI_FAILURE(rv)) {
287 printf("ACPI: unable to initialise SystemMemory handler: %s\n", 287 printf("ACPI: unable to initialise SystemMemory handler: %s\n",
288 AcpiFormatException(rv)); 288 AcpiFormatException(rv));
289 return 0; 289 return 0;
290 } 290 }
291 rv = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT, 291 rv = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
292 ACPI_ADR_SPACE_SYSTEM_IO, ACPI_DEFAULT_HANDLER, NULL, NULL); 292 ACPI_ADR_SPACE_SYSTEM_IO, ACPI_DEFAULT_HANDLER, NULL, NULL);
293 if (ACPI_FAILURE(rv)) { 293 if (ACPI_FAILURE(rv)) {
294 printf("ACPI: unable to initialise SystemIO handler: %s\n", 294 printf("ACPI: unable to initialise SystemIO handler: %s\n",
295 AcpiFormatException(rv)); 295 AcpiFormatException(rv));
296 return 0; 296 return 0;
297 } 297 }
298 rv = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT, 298 rv = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
299 ACPI_ADR_SPACE_PCI_CONFIG, ACPI_DEFAULT_HANDLER, NULL, NULL); 299 ACPI_ADR_SPACE_PCI_CONFIG, ACPI_DEFAULT_HANDLER, NULL, NULL);
300 if (ACPI_FAILURE(rv)) { 300 if (ACPI_FAILURE(rv)) {
301 printf("ACPI: unabled to initialise PciConfig handler: %s\n", 301 printf("ACPI: unabled to initialise PciConfig handler: %s\n",
302 AcpiFormatException(rv)); 302 AcpiFormatException(rv));
303 return 0; 303 return 0;
304 } 304 }
305#endif 305#endif
306 306
307 rv = AcpiEnableSubsystem(~(ACPI_NO_HARDWARE_INIT|ACPI_NO_ACPI_ENABLE)); 307 rv = AcpiEnableSubsystem(~(ACPI_NO_HARDWARE_INIT|ACPI_NO_ACPI_ENABLE));
308 if (ACPI_FAILURE(rv)) { 308 if (ACPI_FAILURE(rv)) {
309 printf("ACPI: unable to enable: %s\n", AcpiFormatException(rv)); 309 printf("ACPI: unable to enable: %s\n", AcpiFormatException(rv));
310 return 0; 310 return 0;
311 } 311 }
312 312
313 /* 313 /*
314 * Looks like we have ACPI! 314 * Looks like we have ACPI!
315 */ 315 */
316 316
317 return 1; 317 return 1;
318} 318}
319 319
320static int 320static int
321acpi_submatch(device_t parent, cfdata_t cf, const int *locs, void *aux) 321acpi_submatch(device_t parent, cfdata_t cf, const int *locs, void *aux)
322{ 322{
323 struct cfattach *ca; 323 struct cfattach *ca;
324 324
325 ca = config_cfattach_lookup(cf->cf_name, cf->cf_atname); 325 ca = config_cfattach_lookup(cf->cf_name, cf->cf_atname);
326 return (ca == &acpi_ca); 326 return (ca == &acpi_ca);
327} 327}
328 328
329int 329int
330acpi_check(device_t parent, const char *ifattr) 330acpi_check(device_t parent, const char *ifattr)
331{ 331{
332 return (config_search_ia(acpi_submatch, parent, ifattr, NULL) != NULL); 332 return (config_search_ia(acpi_submatch, parent, ifattr, NULL) != NULL);
333} 333}
334 334
335ACPI_PHYSICAL_ADDRESS 335ACPI_PHYSICAL_ADDRESS
336acpi_OsGetRootPointer(void) 336acpi_OsGetRootPointer(void)
337{ 337{
338 ACPI_PHYSICAL_ADDRESS PhysicalAddress; 338 ACPI_PHYSICAL_ADDRESS PhysicalAddress;
339 339
340 /* 340 /*
341 * IA-32: Use AcpiFindRootPointer() to locate the RSDP. 341 * IA-32: Use AcpiFindRootPointer() to locate the RSDP.
342 * 342 *
343 * IA-64: Use the EFI. 343 * IA-64: Use the EFI.
344 * 344 *
345 * We let MD code handle this since there are multiple 345 * We let MD code handle this since there are multiple
346 * ways to do it. 346 * ways to do it.
347 */ 347 */
348 348
349 PhysicalAddress = acpi_md_OsGetRootPointer(); 349 PhysicalAddress = acpi_md_OsGetRootPointer();
350 350
351 if (acpi_root_pointer == 0) 351 if (acpi_root_pointer == 0)
352 acpi_root_pointer = PhysicalAddress; 352 acpi_root_pointer = PhysicalAddress;
353 353
354 return PhysicalAddress; 354 return PhysicalAddress;
355} 355}
356 356
357/* 357/*
358 * acpi_match: 358 * acpi_match:
359 * 359 *
360 * Autoconfiguration `match' routine. 360 * Autoconfiguration `match' routine.
361 */ 361 */
362static int 362static int
363acpi_match(device_t parent, struct cfdata *match, void *aux) 363acpi_match(device_t parent, struct cfdata *match, void *aux)
364{ 364{
365 /* 365 /*
366 * XXX Check other locators? Hard to know -- machine 366 * XXX Check other locators? Hard to know -- machine
367 * dependent code has already checked for the presence 367 * dependent code has already checked for the presence
368 * of ACPI by calling acpi_probe(), so I suppose we 368 * of ACPI by calling acpi_probe(), so I suppose we
369 * don't really have to do anything else. 369 * don't really have to do anything else.
370 */ 370 */
371 return 1; 371 return 1;
372} 372}
373 373
374/* Remove references to child devices. 374/* Remove references to child devices.
375 * 375 *
376 * XXX Need to reclaim any resources? 376 * XXX Need to reclaim any resources?
377 */ 377 */
378static void 378static void
379acpi_childdet(device_t self, device_t child) 379acpi_childdet(device_t self, device_t child)
380{ 380{
381 struct acpi_softc *sc = device_private(self); 381 struct acpi_softc *sc = device_private(self);
382 struct acpi_scope *as; 382 struct acpi_scope *as;
383 struct acpi_devnode *ad; 383 struct acpi_devnode *ad;
384 384
385 TAILQ_FOREACH(as, &sc->sc_scopes, as_list) { 385 TAILQ_FOREACH(as, &sc->sc_scopes, as_list) {
386 TAILQ_FOREACH(ad, &as->as_devnodes, ad_list) { 386 TAILQ_FOREACH(ad, &as->as_devnodes, ad_list) {
387 if (ad->ad_device == child) 387 if (ad->ad_device == child)
388 ad->ad_device = NULL; 388 ad->ad_device = NULL;
389 } 389 }
390 } 390 }
391} 391}
392 392
393/* 393/*
394 * acpi_attach: 394 * acpi_attach:
395 * 395 *
396 * Autoconfiguration `attach' routine. Finish initializing 396 * Autoconfiguration `attach' routine. Finish initializing
397 * ACPICA (some initialization was done in acpi_probe(), 397 * ACPICA (some initialization was done in acpi_probe(),
398 * which was required to check for the presence of ACPI), 398 * which was required to check for the presence of ACPI),
399 * and enable the ACPI subsystem. 399 * and enable the ACPI subsystem.
400 */ 400 */
401static void 401static void
402acpi_attach(device_t parent, device_t self, void *aux) 402acpi_attach(device_t parent, device_t self, void *aux)
403{ 403{
404 struct acpi_softc *sc = device_private(self); 404 struct acpi_softc *sc = device_private(self);
405 struct acpibus_attach_args *aa = aux; 405 struct acpibus_attach_args *aa = aux;
406 ACPI_STATUS rv; 406 ACPI_STATUS rv;
407 ACPI_TABLE_HEADER *rsdt; 407 ACPI_TABLE_HEADER *rsdt;
408 408
409 aprint_naive("\n"); 409 aprint_naive("\n");
410 aprint_normal(": Intel ACPICA %08x\n", ACPI_CA_VERSION); 410 aprint_normal(": Intel ACPICA %08x\n", ACPI_CA_VERSION);
411 411
412 if (acpi_softc != NULL) 412 if (acpi_softc != NULL)
413 panic("acpi_attach: ACPI has already been attached"); 413 panic("acpi_attach: ACPI has already been attached");
414 414
415 sysmon_power_settype("acpi"); 415 sysmon_power_settype("acpi");
416 416
417 rsdt = acpi_map_rsdt(); 417 rsdt = acpi_map_rsdt();
418 if (rsdt) { 418 if (rsdt) {
419 aprint_verbose_dev( 419 aprint_verbose_dev(
420 self, 420 self,
421 "X/RSDT: OemId <%6.6s,%8.8s,%08x>, AslId <%4.4s,%08x>\n", 421 "X/RSDT: OemId <%6.6s,%8.8s,%08x>, AslId <%4.4s,%08x>\n",
422 rsdt->OemId, rsdt->OemTableId, 422 rsdt->OemId, rsdt->OemTableId,
423 rsdt->OemRevision, 423 rsdt->OemRevision,
424 rsdt->AslCompilerId, rsdt->AslCompilerRevision); 424 rsdt->AslCompilerId, rsdt->AslCompilerRevision);
425 } else 425 } else
426 aprint_error_dev(self, "X/RSDT: Not found\n"); 426 aprint_error_dev(self, "X/RSDT: Not found\n");
427 acpi_unmap_rsdt(rsdt); 427 acpi_unmap_rsdt(rsdt);
428 428
429 sc->sc_dev = self; 429 sc->sc_dev = self;
430 sc->sc_quirks = acpi_find_quirks(); 430 sc->sc_quirks = acpi_find_quirks();
431 431
432 sc->sc_iot = aa->aa_iot; 432 sc->sc_iot = aa->aa_iot;
433 sc->sc_memt = aa->aa_memt; 433 sc->sc_memt = aa->aa_memt;
434 sc->sc_pc = aa->aa_pc; 434 sc->sc_pc = aa->aa_pc;
435 sc->sc_pciflags = aa->aa_pciflags; 435 sc->sc_pciflags = aa->aa_pciflags;
436 sc->sc_ic = aa->aa_ic; 436 sc->sc_ic = aa->aa_ic;
437 437
438 acpi_softc = sc; 438 acpi_softc = sc;
439 439
440 /* 440 /*
441 * Register null power management handler 441 * Register null power management handler
442 */ 442 */
443 if (!pmf_device_register(self, NULL, NULL)) 443 if (!pmf_device_register(self, NULL, NULL))
444 aprint_error_dev(self, "couldn't establish power handler\n"); 444 aprint_error_dev(self, "couldn't establish power handler\n");
445 445
446 /* 446 /*
447 * Bring ACPI on-line. 447 * Bring ACPI on-line.
448 */ 448 */
449#ifdef ACPI_DEBUGGER 449#ifdef ACPI_DEBUGGER
450 if (acpi_dbgr & ACPI_DBGR_ENABLE) 450 if (acpi_dbgr & ACPI_DBGR_ENABLE)
451 acpi_osd_debugger(); 451 acpi_osd_debugger();
452#endif 452#endif
453 453
454#define ACPI_ENABLE_PHASE1 \ 454#define ACPI_ENABLE_PHASE1 \
455 (ACPI_NO_HANDLER_INIT | ACPI_NO_EVENT_INIT) 455 (ACPI_NO_HANDLER_INIT | ACPI_NO_EVENT_INIT)
456#define ACPI_ENABLE_PHASE2 \ 456#define ACPI_ENABLE_PHASE2 \
457 (ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE | \ 457 (ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE | \
458 ACPI_NO_ADDRESS_SPACE_INIT) 458 ACPI_NO_ADDRESS_SPACE_INIT)
459 459
460 rv = AcpiEnableSubsystem(ACPI_ENABLE_PHASE1); 460 rv = AcpiEnableSubsystem(ACPI_ENABLE_PHASE1);
461 if (ACPI_FAILURE(rv)) { 461 if (ACPI_FAILURE(rv)) {
462 aprint_error_dev(self, "unable to enable ACPI: %s\n", 462 aprint_error_dev(self, "unable to enable ACPI: %s\n",
463 AcpiFormatException(rv)); 463 AcpiFormatException(rv));
464 return; 464 return;
465 } 465 }
466 466
467 acpi_md_callback(); 467 acpi_md_callback();
468 468
469 rv = AcpiEnableSubsystem(ACPI_ENABLE_PHASE2); 469 rv = AcpiEnableSubsystem(ACPI_ENABLE_PHASE2);
470 if (ACPI_FAILURE(rv)) { 470 if (ACPI_FAILURE(rv)) {
471 aprint_error_dev(self, "unable to enable ACPI: %s\n", 471 aprint_error_dev(self, "unable to enable ACPI: %s\n",
472 AcpiFormatException(rv)); 472 AcpiFormatException(rv));
473 return; 473 return;
474 } 474 }
475 475
476 /* early EC handler initialization if ECDT table is available */ 476 /* early EC handler initialization if ECDT table is available */
477 config_found_ia(self, "acpiecdtbus", NULL, NULL); 477 config_found_ia(self, "acpiecdtbus", NULL, NULL);
478 478
479 rv = AcpiInitializeObjects(ACPI_FULL_INITIALIZATION); 479 rv = AcpiInitializeObjects(ACPI_FULL_INITIALIZATION);
480 if (ACPI_FAILURE(rv)) { 480 if (ACPI_FAILURE(rv)) {
481 aprint_error_dev(self, 481 aprint_error_dev(self,
482 "unable to initialize ACPI objects: %s\n", 482 "unable to initialize ACPI objects: %s\n",
483 AcpiFormatException(rv)); 483 AcpiFormatException(rv));
484 return; 484 return;
485 } 485 }
486 acpi_active = 1; 486 acpi_active = 1;
487 487
488 /* Our current state is "awake". */ 488 /* Our current state is "awake". */
489 sc->sc_sleepstate = ACPI_STATE_S0; 489 sc->sc_sleepstate = ACPI_STATE_S0;
490 490
491 /* Show SCI interrupt. */ 491 /* Show SCI interrupt. */
492 aprint_verbose_dev(self, "SCI interrupting at int %d\n", 492 aprint_verbose_dev(self, "SCI interrupting at int %d\n",
493 AcpiGbl_FADT.SciInterrupt); 493 AcpiGbl_FADT.SciInterrupt);
494 494
495 /* 495 /*
496 * Check for fixed-hardware features. 496 * Check for fixed-hardware features.
497 */ 497 */
498 acpi_enable_fixed_events(sc); 498 acpi_enable_fixed_events(sc);
499 acpitimer_init(); 499 acpitimer_init();
500 500
501 /* 501 /*
502 * Scan the namespace and build our device tree. 502 * Scan the namespace and build our device tree.
503 */ 503 */
504#ifdef ACPI_DEBUGGER 504#ifdef ACPI_DEBUGGER
505 if (acpi_dbgr & ACPI_DBGR_PROBE) 505 if (acpi_dbgr & ACPI_DBGR_PROBE)
506 acpi_osd_debugger(); 506 acpi_osd_debugger();
507#endif 507#endif
508 acpi_build_tree(sc); 508 acpi_build_tree(sc);
509 509
510 sprintf(acpi_supported_states, "%s%s%s%s%s%s", 510 sprintf(acpi_supported_states, "%s%s%s%s%s%s",
511 is_available_state(sc, ACPI_STATE_S0) ? "S0 " : "", 511 is_available_state(sc, ACPI_STATE_S0) ? "S0 " : "",
512 is_available_state(sc, ACPI_STATE_S1) ? "S1 " : "", 512 is_available_state(sc, ACPI_STATE_S1) ? "S1 " : "",
513 is_available_state(sc, ACPI_STATE_S2) ? "S2 " : "", 513 is_available_state(sc, ACPI_STATE_S2) ? "S2 " : "",
514 is_available_state(sc, ACPI_STATE_S3) ? "S3 " : "", 514 is_available_state(sc, ACPI_STATE_S3) ? "S3 " : "",
515 is_available_state(sc, ACPI_STATE_S4) ? "S4 " : "", 515 is_available_state(sc, ACPI_STATE_S4) ? "S4 " : "",
516 is_available_state(sc, ACPI_STATE_S5) ? "S5 " : ""); 516 is_available_state(sc, ACPI_STATE_S5) ? "S5 " : "");
517 517
518#ifdef ACPI_DEBUGGER 518#ifdef ACPI_DEBUGGER
519 if (acpi_dbgr & ACPI_DBGR_RUNNING) 519 if (acpi_dbgr & ACPI_DBGR_RUNNING)
520 acpi_osd_debugger(); 520 acpi_osd_debugger();
521#endif 521#endif
522} 522}
523 523
524#if 0 524#if 0
525/* 525/*
526 * acpi_disable: 526 * acpi_disable:
527 * 527 *
528 * Disable ACPI. 528 * Disable ACPI.
529 */ 529 */
530static ACPI_STATUS 530static ACPI_STATUS
531acpi_disable(struct acpi_softc *sc) 531acpi_disable(struct acpi_softc *sc)
532{ 532{
533 ACPI_STATUS rv = AE_OK; 533 ACPI_STATUS rv = AE_OK;
534 534
535 if (acpi_active) { 535 if (acpi_active) {
536 rv = AcpiDisable(); 536 rv = AcpiDisable();
537 if (ACPI_SUCCESS(rv)) 537 if (ACPI_SUCCESS(rv))
538 acpi_active = 0; 538 acpi_active = 0;
539 } 539 }
540 return rv; 540 return rv;
541} 541}
542#endif 542#endif
543 543
544struct acpi_make_devnode_state { 544struct acpi_make_devnode_state {
545 struct acpi_softc *softc; 545 struct acpi_softc *softc;
546 struct acpi_scope *scope; 546 struct acpi_scope *scope;
547}; 547};
548 548
549/* 549/*
550 * acpi_build_tree: 550 * acpi_build_tree:
551 * 551 *
552 * Scan relevant portions of the ACPI namespace and attach 552 * Scan relevant portions of the ACPI namespace and attach
553 * child devices. 553 * child devices.
554 */ 554 */
555static void 555static void
556acpi_build_tree(struct acpi_softc *sc) 556acpi_build_tree(struct acpi_softc *sc)
557{ 557{
558 static const char *scopes[] = { 558 static const char *scopes[] = {
559 "\\_PR_", /* ACPI 1.0 processor namespace */ 559 "\\_PR_", /* ACPI 1.0 processor namespace */
560 "\\_SB_", /* system bus namespace */ 560 "\\_SB_", /* system bus namespace */
561 "\\_SI_", /* system indicator namespace */ 561 "\\_SI_", /* system indicator namespace */
562 "\\_TZ_", /* ACPI 1.0 thermal zone namespace */ 562 "\\_TZ_", /* ACPI 1.0 thermal zone namespace */
563 NULL, 563 NULL,
564 }; 564 };
565 struct acpi_attach_args aa; 565 struct acpi_attach_args aa;
566 struct acpi_make_devnode_state state; 566 struct acpi_make_devnode_state state;
567 struct acpi_scope *as; 567 struct acpi_scope *as;
568 struct acpi_devnode *ad; 568 struct acpi_devnode *ad;
569 ACPI_HANDLE parent; 569 ACPI_HANDLE parent;
570 ACPI_STATUS rv; 570 ACPI_STATUS rv;
571 int i; 571 int i;
572 572
573 TAILQ_INIT(&sc->sc_scopes); 573 TAILQ_INIT(&sc->sc_scopes);
574 574
575 state.softc = sc; 575 state.softc = sc;
576 576
577 /* 577 /*
578 * Scan the namespace and build our tree. 578 * Scan the namespace and build our tree.
579 */ 579 */
580 for (i = 0; scopes[i] != NULL; i++) { 580 for (i = 0; scopes[i] != NULL; i++) {
581 as = malloc(sizeof(*as), M_ACPI, M_WAITOK); 581 as = malloc(sizeof(*as), M_ACPI, M_WAITOK);
582 as->as_name = scopes[i]; 582 as->as_name = scopes[i];
583 TAILQ_INIT(&as->as_devnodes); 583 TAILQ_INIT(&as->as_devnodes);
584 584
585 TAILQ_INSERT_TAIL(&sc->sc_scopes, as, as_list); 585 TAILQ_INSERT_TAIL(&sc->sc_scopes, as, as_list);
586 586
587 state.scope = as; 587 state.scope = as;
588 588
589 rv = AcpiGetHandle(ACPI_ROOT_OBJECT, scopes[i], 589 rv = AcpiGetHandle(ACPI_ROOT_OBJECT, scopes[i],
590 &parent); 590 &parent);
591 if (ACPI_SUCCESS(rv)) { 591 if (ACPI_SUCCESS(rv)) {
592 AcpiWalkNamespace(ACPI_TYPE_ANY, parent, 100, 592 AcpiWalkNamespace(ACPI_TYPE_ANY, parent, 100,
593 acpi_make_devnode, &state, NULL); 593 acpi_make_devnode, &state, NULL);
594 } 594 }
595 595
596 /* Now, for this namespace, try and attach the devices. */ 596 /* Now, for this namespace, try and attach the devices. */
597 TAILQ_FOREACH(ad, &as->as_devnodes, ad_list) { 597 TAILQ_FOREACH(ad, &as->as_devnodes, ad_list) {
598 aa.aa_node = ad; 598 aa.aa_node = ad;
599 aa.aa_iot = sc->sc_iot; 599 aa.aa_iot = sc->sc_iot;
600 aa.aa_memt = sc->sc_memt; 600 aa.aa_memt = sc->sc_memt;
601 aa.aa_pc = sc->sc_pc; 601 aa.aa_pc = sc->sc_pc;
602 aa.aa_pciflags = sc->sc_pciflags; 602 aa.aa_pciflags = sc->sc_pciflags;
603 aa.aa_ic = sc->sc_ic; 603 aa.aa_ic = sc->sc_ic;
604 604
605 if (ad->ad_devinfo->Type == ACPI_TYPE_DEVICE) { 605 if (ad->ad_devinfo->Type == ACPI_TYPE_DEVICE) {
606 /* 606 /*
607 * XXX We only attach devices which are: 607 * XXX We only attach devices which are:
608 * 608 *
609 * - present 609 * - present
610 * - enabled 610 * - enabled
611 * - functioning properly 611 * - functioning properly
612 * 612 *
613 * However, if enabled, it's decoding resources, 613 * However, if enabled, it's decoding resources,
614 * so we should claim them, if possible. 614 * so we should claim them, if possible.
615 * Requires changes to bus_space(9). 615 * Requires changes to bus_space(9).
616 */ 616 */
617 if ((ad->ad_devinfo->Valid & ACPI_VALID_STA) == 617 if ((ad->ad_devinfo->Valid & ACPI_VALID_STA) ==
618 ACPI_VALID_STA && 618 ACPI_VALID_STA &&
619 (ad->ad_devinfo->CurrentStatus & 619 (ad->ad_devinfo->CurrentStatus &
620 (ACPI_STA_DEV_PRESENT|ACPI_STA_DEV_ENABLED| 620 (ACPI_STA_DEV_PRESENT|ACPI_STA_DEV_ENABLED|
621 ACPI_STA_DEV_OK)) != 621 ACPI_STA_DEV_OK)) !=
622 (ACPI_STA_DEV_PRESENT|ACPI_STA_DEV_ENABLED| 622 (ACPI_STA_DEV_PRESENT|ACPI_STA_DEV_ENABLED|
623 ACPI_STA_DEV_OK)) 623 ACPI_STA_DEV_OK))
624 continue; 624 continue;
625 } 625 }
626 626
627 /* 627 /*
628 * XXX Same problem as above... 628 * XXX Same problem as above...
629 * 629 *
630 * Do this check only for devices, as e.g. 630 * Do this check only for devices, as e.g.
631 * a Thermal Zone doesn't have a HID. 631 * a Thermal Zone doesn't have a HID.
632 */ 632 */
633 if (ad->ad_devinfo->Type == ACPI_TYPE_DEVICE && 633 if (ad->ad_devinfo->Type == ACPI_TYPE_DEVICE &&
634 (ad->ad_devinfo->Valid & ACPI_VALID_HID) == 0) 634 (ad->ad_devinfo->Valid & ACPI_VALID_HID) == 0)
635 continue; 635 continue;
636 636
637 /* 637 /*
638 * Handled internally 638 * Handled internally
639 */ 639 */
640 if (ad->ad_devinfo->Type == ACPI_TYPE_PROCESSOR || 640 if (ad->ad_devinfo->Type == ACPI_TYPE_PROCESSOR ||
641 ad->ad_devinfo->Type == ACPI_TYPE_POWER) 641 ad->ad_devinfo->Type == ACPI_TYPE_POWER)
642 continue; 642 continue;
643 643
644 /* 644 /*
645 * Skip ignored HIDs 645 * Skip ignored HIDs
646 */ 646 */
647 if (acpi_match_hid(ad->ad_devinfo, acpi_ignored_ids)) 647 if (acpi_match_hid(ad->ad_devinfo, acpi_ignored_ids))
648 continue; 648 continue;
649 649
650 ad->ad_device = config_found_ia(sc->sc_dev, 650 ad->ad_device = config_found_ia(sc->sc_dev,
651 "acpinodebus", &aa, acpi_print); 651 "acpinodebus", &aa, acpi_print);
652 } 652 }
653 } 653 }
654 config_found_ia(sc->sc_dev, "acpiapmbus", NULL, NULL); 654 config_found_ia(sc->sc_dev, "acpiapmbus", NULL, NULL);
655} 655}
656 656
657#ifdef ACPI_ACTIVATE_DEV 657#ifdef ACPI_ACTIVATE_DEV
658static void 658static void
659acpi_activate_device(ACPI_HANDLE handle, ACPI_DEVICE_INFO **di) 659acpi_activate_device(ACPI_HANDLE handle, ACPI_DEVICE_INFO **di)
660{ 660{
661 ACPI_STATUS rv; 661 ACPI_STATUS rv;
662 ACPI_BUFFER buf; 662 ACPI_BUFFER buf;
663 663
664 buf.Pointer = NULL; 664 buf.Pointer = NULL;
665 buf.Length = ACPI_ALLOCATE_BUFFER; 665 buf.Length = ACPI_ALLOCATE_BUFFER;
666 666
667#ifdef ACPI_DEBUG 667#ifdef ACPI_DEBUG
668 aprint_normal("acpi_activate_device: %s, old status=%x\n", 668 aprint_normal("acpi_activate_device: %s, old status=%x\n",
669 (*di)->HardwareId.Value, (*di)->CurrentStatus); 669 (*di)->HardwareId.Value, (*di)->CurrentStatus);
670#endif 670#endif
671 671
672 rv = acpi_allocate_resources(handle); 672 rv = acpi_allocate_resources(handle);
673 if (ACPI_FAILURE(rv)) { 673 if (ACPI_FAILURE(rv)) {
674 aprint_error("acpi: activate failed for %s\n", 674 aprint_error("acpi: activate failed for %s\n",
675 (*di)->HardwareId.Value); 675 (*di)->HardwareId.Value);
676 } else { 676 } else {
677 aprint_verbose("acpi: activated %s\n", 677 aprint_verbose("acpi: activated %s\n",
678 (*di)->HardwareId.Value); 678 (*di)->HardwareId.Value);
679 } 679 }
680 680
681 (void)AcpiGetObjectInfo(handle, &buf); 681 (void)AcpiGetObjectInfo(handle, &buf);
682 AcpiOsFree(*di); 682 AcpiOsFree(*di);
683 *di = buf.Pointer; 683 *di = buf.Pointer;
684 684
685#ifdef ACPI_DEBUG 685#ifdef ACPI_DEBUG
686 aprint_normal("acpi_activate_device: %s, new status=%x\n", 686 aprint_normal("acpi_activate_device: %s, new status=%x\n",
687 (*di)->HardwareId.Value, (*di)->CurrentStatus); 687 (*di)->HardwareId.Value, (*di)->CurrentStatus);
688#endif 688#endif
689} 689}
690#endif /* ACPI_ACTIVATE_DEV */ 690#endif /* ACPI_ACTIVATE_DEV */
691 691
692/* 692/*
693 * acpi_make_devnode: 693 * acpi_make_devnode:
694 * 694 *
695 * Make an ACPI devnode. 695 * Make an ACPI devnode.
696 */ 696 */
697static ACPI_STATUS 697static ACPI_STATUS
698acpi_make_devnode(ACPI_HANDLE handle, UINT32 level, void *context, 698acpi_make_devnode(ACPI_HANDLE handle, UINT32 level, void *context,
699 void **status) 699 void **status)
700{ 700{
701 struct acpi_make_devnode_state *state = context; 701 struct acpi_make_devnode_state *state = context;
702#if defined(ACPI_DEBUG) || defined(ACPI_EXTRA_DEBUG) 702#if defined(ACPI_DEBUG) || defined(ACPI_EXTRA_DEBUG)
703 struct acpi_softc *sc = state->softc; 703 struct acpi_softc *sc = state->softc;
704#endif 704#endif
705 struct acpi_scope *as = state->scope; 705 struct acpi_scope *as = state->scope;
706 struct acpi_devnode *ad; 706 struct acpi_devnode *ad;
707 ACPI_OBJECT_TYPE type; 707 ACPI_OBJECT_TYPE type;
708 ACPI_BUFFER buf; 708 ACPI_BUFFER buf;
709 ACPI_DEVICE_INFO *devinfo; 709 ACPI_DEVICE_INFO *devinfo;
710 ACPI_STATUS rv; 710 ACPI_STATUS rv;
711 ACPI_NAME_UNION *anu; 711 ACPI_NAME_UNION *anu;
712 int i, clear = 0; 712 int i, clear = 0;
713 713
714 rv = AcpiGetType(handle, &type); 714 rv = AcpiGetType(handle, &type);
715 if (ACPI_SUCCESS(rv)) { 715 if (ACPI_SUCCESS(rv)) {
716 buf.Pointer = NULL; 716 buf.Pointer = NULL;
717 buf.Length = ACPI_ALLOCATE_BUFFER; 717 buf.Length = ACPI_ALLOCATE_BUFFER;
718 rv = AcpiGetObjectInfo(handle, &buf); 718 rv = AcpiGetObjectInfo(handle, &buf);
719 if (ACPI_FAILURE(rv)) { 719 if (ACPI_FAILURE(rv)) {
720#ifdef ACPI_DEBUG 720#ifdef ACPI_DEBUG
721 aprint_normal_dev(sc->sc_dev, 721 aprint_normal_dev(sc->sc_dev,
722 "AcpiGetObjectInfo failed: %s\n", 722 "AcpiGetObjectInfo failed: %s\n",
723 AcpiFormatException(rv)); 723 AcpiFormatException(rv));
724#endif 724#endif
725 goto out; /* XXX why return OK */ 725 goto out; /* XXX why return OK */
726 } 726 }
727 727
728 devinfo = buf.Pointer; 728 devinfo = buf.Pointer;
729 729
730 switch (type) { 730 switch (type) {
731 case ACPI_TYPE_DEVICE: 731 case ACPI_TYPE_DEVICE:
732#ifdef ACPI_ACTIVATE_DEV 732#ifdef ACPI_ACTIVATE_DEV
733 if ((devinfo->Valid & (ACPI_VALID_STA|ACPI_VALID_HID)) == 733 if ((devinfo->Valid & (ACPI_VALID_STA|ACPI_VALID_HID)) ==
734 (ACPI_VALID_STA|ACPI_VALID_HID) && 734 (ACPI_VALID_STA|ACPI_VALID_HID) &&
735 (devinfo->CurrentStatus & 735 (devinfo->CurrentStatus &
736 (ACPI_STA_DEV_PRESENT|ACPI_STA_DEV_ENABLED)) == 736 (ACPI_STA_DEV_PRESENT|ACPI_STA_DEV_ENABLED)) ==
737 ACPI_STA_DEV_PRESENT) 737 ACPI_STA_DEV_PRESENT)
738 acpi_activate_device(handle, &devinfo); 738 acpi_activate_device(handle, &devinfo);
739 739
740 /* FALLTHROUGH */ 740 /* FALLTHROUGH */
741#endif 741#endif
742 742
743 case ACPI_TYPE_PROCESSOR: 743 case ACPI_TYPE_PROCESSOR:
744 case ACPI_TYPE_THERMAL: 744 case ACPI_TYPE_THERMAL:
745 case ACPI_TYPE_POWER: 745 case ACPI_TYPE_POWER:
746 ad = malloc(sizeof(*ad), M_ACPI, M_NOWAIT|M_ZERO); 746 ad = malloc(sizeof(*ad), M_ACPI, M_NOWAIT|M_ZERO);
747 if (ad == NULL) 747 if (ad == NULL)
748 return AE_NO_MEMORY; 748 return AE_NO_MEMORY;
749 749
750 ad->ad_devinfo = devinfo; 750 ad->ad_devinfo = devinfo;
751 ad->ad_handle = handle; 751 ad->ad_handle = handle;
752 ad->ad_level = level; 752 ad->ad_level = level;
753 ad->ad_scope = as; 753 ad->ad_scope = as;
754 ad->ad_type = type; 754 ad->ad_type = type;
755 755
756 anu = (ACPI_NAME_UNION *)&devinfo->Name; 756 anu = (ACPI_NAME_UNION *)&devinfo->Name;
757 ad->ad_name[4] = '\0'; 757 ad->ad_name[4] = '\0';
758 for (i = 3, clear = 0; i >= 0; i--) { 758 for (i = 3, clear = 0; i >= 0; i--) {
759 if (!clear && anu->Ascii[i] == '_') 759 if (!clear && anu->Ascii[i] == '_')
760 ad->ad_name[i] = '\0'; 760 ad->ad_name[i] = '\0';
761 else { 761 else {
762 ad->ad_name[i] = anu->Ascii[i]; 762 ad->ad_name[i] = anu->Ascii[i];
763 clear = 1; 763 clear = 1;
764 } 764 }
765 } 765 }
766 if (ad->ad_name[0] == '\0') 766 if (ad->ad_name[0] == '\0')
767 ad->ad_name[0] = '_'; 767 ad->ad_name[0] = '_';
768 768
769 TAILQ_INSERT_TAIL(&as->as_devnodes, ad, ad_list); 769 TAILQ_INSERT_TAIL(&as->as_devnodes, ad, ad_list);
770 770
771 if (type == ACPI_TYPE_DEVICE && 771 if (type == ACPI_TYPE_DEVICE &&
772 (ad->ad_devinfo->Valid & ACPI_VALID_HID) == 0) 772 (ad->ad_devinfo->Valid & ACPI_VALID_HID) == 0)
773 goto out; 773 goto out;
774 774
775#ifdef ACPI_EXTRA_DEBUG 775#ifdef ACPI_EXTRA_DEBUG
776 aprint_normal_dev(sc->sc_dev, 776 aprint_normal_dev(sc->sc_dev,
777 "HID %s found in scope %s level %d\n", 777 "HID %s found in scope %s level %d\n",
778 ad->ad_devinfo->HardwareId.Value, 778 ad->ad_devinfo->HardwareId.Value,
779 as->as_name, ad->ad_level); 779 as->as_name, ad->ad_level);
780 if (ad->ad_devinfo->Valid & ACPI_VALID_UID) 780 if (ad->ad_devinfo->Valid & ACPI_VALID_UID)
781 aprint_normal(" UID %s\n", 781 aprint_normal(" UID %s\n",
782 ad->ad_devinfo->UniqueId.Value); 782 ad->ad_devinfo->UniqueId.Value);
783 if (ad->ad_devinfo->Valid & ACPI_VALID_ADR) 783 if (ad->ad_devinfo->Valid & ACPI_VALID_ADR)
784 aprint_normal(" ADR 0x%016" PRIx64 "\n", 784 aprint_normal(" ADR 0x%016" PRIx64 "\n",
785 ad->ad_devinfo->Address); 785 ad->ad_devinfo->Address);
786 if (ad->ad_devinfo->Valid & ACPI_VALID_STA) 786 if (ad->ad_devinfo->Valid & ACPI_VALID_STA)
787 aprint_normal(" STA 0x%08x\n", 787 aprint_normal(" STA 0x%08x\n",
788 ad->ad_devinfo->CurrentStatus); 788 ad->ad_devinfo->CurrentStatus);
789#endif 789#endif
790 } 790 }
791 } 791 }
792 out: 792 out:
793 return AE_OK; 793 return AE_OK;
794} 794}
795 795
796/* 796/*
797 * acpi_print: 797 * acpi_print:
798 * 798 *
799 * Autoconfiguration print routine for ACPI node bus. 799 * Autoconfiguration print routine for ACPI node bus.
800 */ 800 */
801static int 801static int
802acpi_print(void *aux, const char *pnp) 802acpi_print(void *aux, const char *pnp)
803{ 803{
804 struct acpi_attach_args *aa = aux; 804 struct acpi_attach_args *aa = aux;
805 ACPI_STATUS rv; 805 ACPI_STATUS rv;
806 806
807 if (pnp) { 807 if (pnp) {
808 if (aa->aa_node->ad_devinfo->Valid & ACPI_VALID_HID) { 808 if (aa->aa_node->ad_devinfo->Valid & ACPI_VALID_HID) {
809 char *pnpstr = 809 char *pnpstr =
810 aa->aa_node->ad_devinfo->HardwareId.Value; 810 aa->aa_node->ad_devinfo->HardwareId.Value;
811 char *str; 811 char *str;
812 812
813 aprint_normal("%s (%s) ", aa->aa_node->ad_name, 813 aprint_normal("%s (%s) ", aa->aa_node->ad_name,
814 pnpstr); 814 pnpstr);
815 rv = acpi_eval_string(aa->aa_node->ad_handle, 815 rv = acpi_eval_string(aa->aa_node->ad_handle,
816 "_STR", &str); 816 "_STR", &str);
817 if (ACPI_SUCCESS(rv)) { 817 if (ACPI_SUCCESS(rv)) {
818 aprint_normal("[%s] ", str); 818 aprint_normal("[%s] ", str);
819 AcpiOsFree(str); 819 AcpiOsFree(str);
820 } 820 }
821#ifdef ACPIVERBOSE 821#ifdef ACPIVERBOSE
822 else { 822 else {
823 int i; 823 int i;
824 824
825 for (i = 0; i < sizeof(acpi_knowndevs) / 825 for (i = 0; i < sizeof(acpi_knowndevs) /
826 sizeof(acpi_knowndevs[0]); i++) { 826 sizeof(acpi_knowndevs[0]); i++) {
827 if (strcmp(acpi_knowndevs[i].pnp, 827 if (strcmp(acpi_knowndevs[i].pnp,
828 pnpstr) == 0) { 828 pnpstr) == 0) {
829 aprint_normal("[%s] ", 829 aprint_normal("[%s] ",
830 acpi_knowndevs[i].str); 830 acpi_knowndevs[i].str);
831 } 831 }
832 } 832 }
833 } 833 }
834 834
835#endif 835#endif
836 aprint_normal("at %s", pnp); 836 aprint_normal("at %s", pnp);
837 } else if (aa->aa_node->ad_devinfo->Type != ACPI_TYPE_DEVICE) { 837 } else if (aa->aa_node->ad_devinfo->Type != ACPI_TYPE_DEVICE) {
838 aprint_normal("%s (ACPI Object Type '%s' " 838 aprint_normal("%s (ACPI Object Type '%s' "
839 "[0x%02x]) ", aa->aa_node->ad_name, 839 "[0x%02x]) ", aa->aa_node->ad_name,
840 AcpiUtGetTypeName(aa->aa_node->ad_devinfo->Type), 840 AcpiUtGetTypeName(aa->aa_node->ad_devinfo->Type),
841 aa->aa_node->ad_devinfo->Type); 841 aa->aa_node->ad_devinfo->Type);
842 aprint_normal("at %s", pnp); 842 aprint_normal("at %s", pnp);
843 } else 843 } else
844 return 0; 844 return 0;
845 } else { 845 } else {
846 aprint_normal(" (%s", aa->aa_node->ad_name); 846 aprint_normal(" (%s", aa->aa_node->ad_name);
847 if (aa->aa_node->ad_devinfo->Valid & ACPI_VALID_HID) { 847 if (aa->aa_node->ad_devinfo->Valid & ACPI_VALID_HID) {
848 aprint_normal(", %s", aa->aa_node->ad_devinfo->HardwareId.Value); 848 aprint_normal(", %s", aa->aa_node->ad_devinfo->HardwareId.Value);
849 if (aa->aa_node->ad_devinfo->Valid & ACPI_VALID_UID) { 849 if (aa->aa_node->ad_devinfo->Valid & ACPI_VALID_UID) {
850 const char *uid; 850 const char *uid;
851 851
852 uid = aa->aa_node->ad_devinfo->UniqueId.Value; 852 uid = aa->aa_node->ad_devinfo->UniqueId.Value;
853 if (uid[0] == '\0') 853 if (uid[0] == '\0')
854 uid = "<null>"; 854 uid = "<null>";
855 aprint_normal("-%s", uid); 855 aprint_normal("-%s", uid);
856 } 856 }
857 } 857 }
858 aprint_normal(")"); 858 aprint_normal(")");
859 } 859 }
860 860
861 return UNCONF; 861 return UNCONF;
862} 862}
863 863
864/***************************************************************************** 864/*****************************************************************************
865 * ACPI fixed-hardware feature handlers 865 * ACPI fixed-hardware feature handlers
866 *****************************************************************************/ 866 *****************************************************************************/
867 867
868static UINT32 acpi_fixed_button_handler(void *); 868static UINT32 acpi_fixed_button_handler(void *);
869static void acpi_fixed_button_pressed(void *); 869static void acpi_fixed_button_pressed(void *);
870 870
871/* 871/*
872 * acpi_enable_fixed_events: 872 * acpi_enable_fixed_events:
873 * 873 *
874 * Enable any fixed-hardware feature handlers. 874 * Enable any fixed-hardware feature handlers.
875 */ 875 */
876static void 876static void
877acpi_enable_fixed_events(struct acpi_softc *sc) 877acpi_enable_fixed_events(struct acpi_softc *sc)
878{ 878{
879 static int beenhere; 879 static int beenhere;
880 ACPI_STATUS rv; 880 ACPI_STATUS rv;
881 881
882 KASSERT(beenhere == 0); 882 KASSERT(beenhere == 0);
883 beenhere = 1; 883 beenhere = 1;
884 884
885 /* 885 /*
886 * Check for fixed-hardware buttons. 886 * Check for fixed-hardware buttons.
887 */ 887 */
888 888
889 if ((AcpiGbl_FADT.Flags & ACPI_FADT_POWER_BUTTON) == 0) { 889 if ((AcpiGbl_FADT.Flags & ACPI_FADT_POWER_BUTTON) == 0) {
890 aprint_verbose_dev(sc->sc_dev, 890 aprint_verbose_dev(sc->sc_dev,
891 "fixed-feature power button present\n"); 891 "fixed-feature power button present\n");
892 sc->sc_smpsw_power.smpsw_name = device_xname(sc->sc_dev); 892 sc->sc_smpsw_power.smpsw_name = device_xname(sc->sc_dev);
893 sc->sc_smpsw_power.smpsw_type = PSWITCH_TYPE_POWER; 893 sc->sc_smpsw_power.smpsw_type = PSWITCH_TYPE_POWER;
894 if (sysmon_pswitch_register(&sc->sc_smpsw_power) != 0) { 894 if (sysmon_pswitch_register(&sc->sc_smpsw_power) != 0) {
895 aprint_error_dev(sc->sc_dev, 895 aprint_error_dev(sc->sc_dev,
896 "unable to register fixed power " 896 "unable to register fixed power "
897 "button with sysmon\n"); 897 "button with sysmon\n");
898 } else { 898 } else {
899 rv = AcpiInstallFixedEventHandler( 899 rv = AcpiInstallFixedEventHandler(
900 ACPI_EVENT_POWER_BUTTON, 900 ACPI_EVENT_POWER_BUTTON,
901 acpi_fixed_button_handler, &sc->sc_smpsw_power); 901 acpi_fixed_button_handler, &sc->sc_smpsw_power);
902 if (ACPI_FAILURE(rv)) { 902 if (ACPI_FAILURE(rv)) {
903 aprint_error_dev(sc->sc_dev, 903 aprint_error_dev(sc->sc_dev,
904 "unable to install handler " 904 "unable to install handler "
905 "for fixed power button: %s\n", 905 "for fixed power button: %s\n",
906 AcpiFormatException(rv)); 906 AcpiFormatException(rv));
907 } 907 }
908 } 908 }
909 } 909 }
910 910
911 if ((AcpiGbl_FADT.Flags & ACPI_FADT_SLEEP_BUTTON) == 0) { 911 if ((AcpiGbl_FADT.Flags & ACPI_FADT_SLEEP_BUTTON) == 0) {
912 aprint_verbose_dev(sc->sc_dev, 912 aprint_verbose_dev(sc->sc_dev,
913 "fixed-feature sleep button present\n"); 913 "fixed-feature sleep button present\n");
914 sc->sc_smpsw_sleep.smpsw_name = device_xname(sc->sc_dev); 914 sc->sc_smpsw_sleep.smpsw_name = device_xname(sc->sc_dev);
915 sc->sc_smpsw_sleep.smpsw_type = PSWITCH_TYPE_SLEEP; 915 sc->sc_smpsw_sleep.smpsw_type = PSWITCH_TYPE_SLEEP;
916 if (sysmon_pswitch_register(&sc->sc_smpsw_power) != 0) { 916 if (sysmon_pswitch_register(&sc->sc_smpsw_power) != 0) {
917 aprint_error_dev(sc->sc_dev, 917 aprint_error_dev(sc->sc_dev,
918 "unable to register fixed sleep " 918 "unable to register fixed sleep "
919 "button with sysmon\n"); 919 "button with sysmon\n");
920 } else { 920 } else {
921 rv = AcpiInstallFixedEventHandler( 921 rv = AcpiInstallFixedEventHandler(
922 ACPI_EVENT_SLEEP_BUTTON, 922 ACPI_EVENT_SLEEP_BUTTON,
923 acpi_fixed_button_handler, &sc->sc_smpsw_sleep); 923 acpi_fixed_button_handler, &sc->sc_smpsw_sleep);
924 if (ACPI_FAILURE(rv)) { 924 if (ACPI_FAILURE(rv)) {
925 aprint_error_dev(sc->sc_dev, 925 aprint_error_dev(sc->sc_dev,
926 "unable to install handler " 926 "unable to install handler "
927 "for fixed sleep button: %s\n", 927 "for fixed sleep button: %s\n",
928 AcpiFormatException(rv)); 928 AcpiFormatException(rv));
929 } 929 }
930 } 930 }
931 } 931 }
932} 932}
933 933
934/* 934/*
935 * acpi_fixed_button_handler: 935 * acpi_fixed_button_handler:
936 * 936 *
937 * Event handler for the fixed buttons. 937 * Event handler for the fixed buttons.
938 */ 938 */
939static UINT32 939static UINT32
940acpi_fixed_button_handler(void *context) 940acpi_fixed_button_handler(void *context)
941{ 941{
942 struct sysmon_pswitch *smpsw = context; 942 struct sysmon_pswitch *smpsw = context;
943 int rv; 943 int rv;
944 944
945#ifdef ACPI_BUT_DEBUG 945#ifdef ACPI_BUT_DEBUG
946 printf("%s: fixed button handler\n", smpsw->smpsw_name); 946 printf("%s: fixed button handler\n", smpsw->smpsw_name);
947#endif 947#endif
948 948
949 rv = AcpiOsExecute(OSL_NOTIFY_HANDLER, 949 rv = AcpiOsExecute(OSL_NOTIFY_HANDLER,
950 acpi_fixed_button_pressed, smpsw); 950 acpi_fixed_button_pressed, smpsw);
951 if (ACPI_FAILURE(rv)) 951 if (ACPI_FAILURE(rv))
952 printf("%s: WARNING: unable to queue fixed button pressed " 952 printf("%s: WARNING: unable to queue fixed button pressed "
953 "callback: %s\n", smpsw->smpsw_name, 953 "callback: %s\n", smpsw->smpsw_name,
954 AcpiFormatException(rv)); 954 AcpiFormatException(rv));
955 955
956 return ACPI_INTERRUPT_HANDLED; 956 return ACPI_INTERRUPT_HANDLED;
957} 957}
958 958
959/* 959/*
960 * acpi_fixed_button_pressed: 960 * acpi_fixed_button_pressed:
961 * 961 *
962 * Deal with a fixed button being pressed. 962 * Deal with a fixed button being pressed.
963 */ 963 */
964static void 964static void
965acpi_fixed_button_pressed(void *context) 965acpi_fixed_button_pressed(void *context)
966{ 966{
967 struct sysmon_pswitch *smpsw = context; 967 struct sysmon_pswitch *smpsw = context;
968 968
969#ifdef ACPI_BUT_DEBUG 969#ifdef ACPI_BUT_DEBUG
970 printf("%s: fixed button pressed, calling sysmon\n", 970 printf("%s: fixed button pressed, calling sysmon\n",
971 smpsw->smpsw_name); 971 smpsw->smpsw_name);
972#endif 972#endif
973 973
974 sysmon_pswitch_event(smpsw, PSWITCH_EVENT_PRESSED); 974 sysmon_pswitch_event(smpsw, PSWITCH_EVENT_PRESSED);
975} 975}
976 976
977/***************************************************************************** 977/*****************************************************************************
978 * ACPI utility routines. 978 * ACPI utility routines.
979 *****************************************************************************/ 979 *****************************************************************************/
980 980
981/* 981/*
982 * acpi_eval_integer: 982 * acpi_eval_integer:
983 * 983 *
984 * Evaluate an integer object. 984 * Evaluate an integer object.
985 */ 985 */
986ACPI_STATUS 986ACPI_STATUS
987acpi_eval_integer(ACPI_HANDLE handle, const char *path, ACPI_INTEGER *valp) 987acpi_eval_integer(ACPI_HANDLE handle, const char *path, ACPI_INTEGER *valp)
988{ 988{
989 ACPI_STATUS rv; 989 ACPI_STATUS rv;
990 ACPI_BUFFER buf; 990 ACPI_BUFFER buf;
991 ACPI_OBJECT param; 991 ACPI_OBJECT param;
992 992
993 if (handle == NULL) 993 if (handle == NULL)
994 handle = ACPI_ROOT_OBJECT; 994 handle = ACPI_ROOT_OBJECT;
995 995
996 buf.Pointer = &param; 996 buf.Pointer = &param;
997 buf.Length = sizeof(param); 997 buf.Length = sizeof(param);
998 998
999 rv = AcpiEvaluateObjectTyped(handle, path, NULL, &buf, ACPI_TYPE_INTEGER); 999 rv = AcpiEvaluateObjectTyped(handle, path, NULL, &buf, ACPI_TYPE_INTEGER);
1000 if (ACPI_SUCCESS(rv)) 1000 if (ACPI_SUCCESS(rv))
1001 *valp = param.Integer.Value; 1001 *valp = param.Integer.Value;
1002 1002
1003 return rv; 1003 return rv;
1004} 1004}
1005 1005
1006/* 1006/*
1007 * acpi_eval_string: 1007 * acpi_eval_string:
1008 * 1008 *
1009 * Evaluate a (Unicode) string object. 1009 * Evaluate a (Unicode) string object.
1010 */ 1010 */
1011ACPI_STATUS 1011ACPI_STATUS
1012acpi_eval_string(ACPI_HANDLE handle, const char *path, char **stringp) 1012acpi_eval_string(ACPI_HANDLE handle, const char *path, char **stringp)
1013{ 1013{
1014 ACPI_STATUS rv; 1014 ACPI_STATUS rv;
1015 ACPI_BUFFER buf; 1015 ACPI_BUFFER buf;
1016 1016
1017 if (handle == NULL) 1017 if (handle == NULL)
1018 handle = ACPI_ROOT_OBJECT; 1018 handle = ACPI_ROOT_OBJECT;
1019 1019
1020 buf.Pointer = NULL; 1020 buf.Pointer = NULL;
1021 buf.Length = ACPI_ALLOCATE_BUFFER; 1021 buf.Length = ACPI_ALLOCATE_BUFFER;
1022 1022
1023 rv = AcpiEvaluateObjectTyped(handle, path, NULL, &buf, ACPI_TYPE_STRING); 1023 rv = AcpiEvaluateObjectTyped(handle, path, NULL, &buf, ACPI_TYPE_STRING);
1024 if (ACPI_SUCCESS(rv)) { 1024 if (ACPI_SUCCESS(rv)) {
1025 ACPI_OBJECT *param = buf.Pointer; 1025 ACPI_OBJECT *param = buf.Pointer;
1026 const char *ptr = param->String.Pointer; 1026 const char *ptr = param->String.Pointer;
1027 size_t len = param->String.Length; 1027 size_t len = param->String.Length;
1028 if ((*stringp = AcpiOsAllocate(len)) == NULL) 1028 if ((*stringp = AcpiOsAllocate(len)) == NULL)
1029 rv = AE_NO_MEMORY; 1029 rv = AE_NO_MEMORY;
1030 else 1030 else
1031 (void)memcpy(*stringp, ptr, len); 1031 (void)memcpy(*stringp, ptr, len);
1032 AcpiOsFree(param); 1032 AcpiOsFree(param);
1033 } 1033 }
1034 1034
1035 return rv; 1035 return rv;
1036} 1036}
1037 1037
1038 1038
1039/* 1039/*
1040 * acpi_eval_struct: 1040 * acpi_eval_struct:
1041 * 1041 *
1042 * Evaluate a more complex structure. 1042 * Evaluate a more complex structure.
1043 * Caller must free buf.Pointer by AcpiOsFree(). 1043 * Caller must free buf.Pointer by AcpiOsFree().
1044 */ 1044 */
1045ACPI_STATUS 1045ACPI_STATUS
1046acpi_eval_struct(ACPI_HANDLE handle, const char *path, ACPI_BUFFER *bufp) 1046acpi_eval_struct(ACPI_HANDLE handle, const char *path, ACPI_BUFFER *bufp)
1047{ 1047{
1048 ACPI_STATUS rv; 1048 ACPI_STATUS rv;
1049 1049
1050 if (handle == NULL) 1050 if (handle == NULL)
1051 handle = ACPI_ROOT_OBJECT; 1051 handle = ACPI_ROOT_OBJECT;
1052 1052
1053 bufp->Pointer = NULL; 1053 bufp->Pointer = NULL;
1054 bufp->Length = ACPI_ALLOCATE_BUFFER; 1054 bufp->Length = ACPI_ALLOCATE_BUFFER;
1055 1055
1056 rv = AcpiEvaluateObject(handle, path, NULL, bufp); 1056 rv = AcpiEvaluateObject(handle, path, NULL, bufp);
1057 1057
1058 return rv; 1058 return rv;
1059} 1059}
1060 1060
1061/* 1061/*
1062 * acpi_foreach_package_object: 1062 * acpi_foreach_package_object:
1063 * 1063 *
1064 * Iterate over all objects in a in a packages and pass then all 1064 * Iterate over all objects in a in a packages and pass then all
1065 * to a function. If the called function returns non AE_OK, the 1065 * to a function. If the called function returns non AE_OK, the
1066 * iteration is stopped and that value is returned. 1066 * iteration is stopped and that value is returned.
1067 */ 1067 */
1068 1068
1069ACPI_STATUS 1069ACPI_STATUS
1070acpi_foreach_package_object(ACPI_OBJECT *pkg, 1070acpi_foreach_package_object(ACPI_OBJECT *pkg,
1071 ACPI_STATUS (*func)(ACPI_OBJECT *, void *), 1071 ACPI_STATUS (*func)(ACPI_OBJECT *, void *),
1072 void *arg) 1072 void *arg)
1073{ 1073{
1074 ACPI_STATUS rv = AE_OK; 1074 ACPI_STATUS rv = AE_OK;
1075 int i; 1075 int i;
1076 1076
1077 if (pkg == NULL || pkg->Type != ACPI_TYPE_PACKAGE) 1077 if (pkg == NULL || pkg->Type != ACPI_TYPE_PACKAGE)
1078 return AE_BAD_PARAMETER; 1078 return AE_BAD_PARAMETER;
1079 1079
1080 for (i = 0; i < pkg->Package.Count; i++) { 1080 for (i = 0; i < pkg->Package.Count; i++) {
1081 rv = (*func)(&pkg->Package.Elements[i], arg); 1081 rv = (*func)(&pkg->Package.Elements[i], arg);
1082 if (ACPI_FAILURE(rv)) 1082 if (ACPI_FAILURE(rv))
1083 break; 1083 break;
1084 } 1084 }
1085 1085
1086 return rv; 1086 return rv;
1087} 1087}
1088 1088
1089const char * 1089const char *
1090acpi_name(ACPI_HANDLE handle) 1090acpi_name(ACPI_HANDLE handle)
1091{ 1091{
1092 static char buffer[80]; 1092 static char buffer[80];
1093 ACPI_BUFFER buf; 1093 ACPI_BUFFER buf;
1094 ACPI_STATUS rv; 1094 ACPI_STATUS rv;
1095 1095
1096 buf.Length = sizeof(buffer); 1096 buf.Length = sizeof(buffer);
1097 buf.Pointer = buffer; 1097 buf.Pointer = buffer;
1098 1098
1099 rv = AcpiGetName(handle, ACPI_FULL_PATHNAME, &buf); 1099 rv = AcpiGetName(handle, ACPI_FULL_PATHNAME, &buf);
1100 if (ACPI_FAILURE(rv)) 1100 if (ACPI_FAILURE(rv))
1101 return "(unknown acpi path)"; 1101 return "(unknown acpi path)";
1102 return buffer; 1102 return buffer;
1103} 1103}
1104 1104
1105/* 1105/*
1106 * acpi_get: 1106 * acpi_get:
1107 * 1107 *
1108 * Fetch data info the specified (empty) ACPI buffer. 1108 * Fetch data info the specified (empty) ACPI buffer.
1109 * Caller must free buf.Pointer by AcpiOsFree(). 1109 * Caller must free buf.Pointer by AcpiOsFree().
1110 */ 1110 */
1111ACPI_STATUS 1111ACPI_STATUS
1112acpi_get(ACPI_HANDLE handle, ACPI_BUFFER *buf, 1112acpi_get(ACPI_HANDLE handle, ACPI_BUFFER *buf,
1113 ACPI_STATUS (*getit)(ACPI_HANDLE, ACPI_BUFFER *)) 1113 ACPI_STATUS (*getit)(ACPI_HANDLE, ACPI_BUFFER *))
1114{ 1114{
1115 buf->Pointer = NULL; 1115 buf->Pointer = NULL;
1116 buf->Length = ACPI_ALLOCATE_BUFFER; 1116 buf->Length = ACPI_ALLOCATE_BUFFER;
1117 1117
1118 return (*getit)(handle, buf); 1118 return (*getit)(handle, buf);
1119} 1119}
1120 1120
1121 1121
1122/* 1122/*
1123 * acpi_match_hid 1123 * acpi_match_hid
1124 * 1124 *
1125 * Match given ids against _HID and _CIDs 1125 * Match given ids against _HID and _CIDs
1126 */ 1126 */
1127int 1127int
1128acpi_match_hid(ACPI_DEVICE_INFO *ad, const char * const *ids) 1128acpi_match_hid(ACPI_DEVICE_INFO *ad, const char * const *ids)
1129{ 1129{
1130 int i; 1130 int i;
1131 1131
1132 while (*ids) { 1132 while (*ids) {
1133 if (ad->Valid & ACPI_VALID_HID) { 1133 if (ad->Valid & ACPI_VALID_HID) {
1134 if (pmatch(ad->HardwareId.Value, *ids, NULL) == 2) 1134 if (pmatch(ad->HardwareId.Value, *ids, NULL) == 2)
1135 return 1; 1135 return 1;
1136 } 1136 }
1137 1137
1138 if (ad->Valid & ACPI_VALID_CID) { 1138 if (ad->Valid & ACPI_VALID_CID) {
1139 for (i = 0; i < ad->CompatibilityId.Count; i++) { 1139 for (i = 0; i < ad->CompatibilityId.Count; i++) {
1140 if (pmatch(ad->CompatibilityId.Id[i].Value, *ids, NULL) == 2) 1140 if (pmatch(ad->CompatibilityId.Id[i].Value, *ids, NULL) == 2)
1141 return 1; 1141 return 1;
1142 } 1142 }
1143 } 1143 }
1144 ids++; 1144 ids++;
1145 } 1145 }
1146 1146
1147 return 0; 1147 return 0;
1148} 1148}
1149 1149
1150/* 1150/*
1151 * acpi_wake_gpe_helper 1151 * acpi_wake_gpe_helper
1152 * 1152 *
1153 * Set/unset GPE as both Runtime and Wake 1153 * Set/unset GPE as both Runtime and Wake
1154 */ 1154 */
1155static void 1155static void
1156acpi_wake_gpe_helper(ACPI_HANDLE handle, bool enable) 1156acpi_wake_gpe_helper(ACPI_HANDLE handle, bool enable)
1157{ 1157{
1158 ACPI_BUFFER buf; 1158 ACPI_BUFFER buf;
1159 ACPI_STATUS rv; 1159 ACPI_STATUS rv;
1160 ACPI_OBJECT *p, *elt; 1160 ACPI_OBJECT *p, *elt;
1161 1161
1162 rv = acpi_eval_struct(handle, METHOD_NAME__PRW, &buf); 1162 rv = acpi_eval_struct(handle, METHOD_NAME__PRW, &buf);
1163 if (ACPI_FAILURE(rv)) 1163 if (ACPI_FAILURE(rv))
1164 return; /* just ignore */ 1164 return; /* just ignore */
1165 1165
1166 p = buf.Pointer; 1166 p = buf.Pointer;
1167 if (p->Type != ACPI_TYPE_PACKAGE || p->Package.Count < 2) 1167 if (p->Type != ACPI_TYPE_PACKAGE || p->Package.Count < 2)
1168 goto out; /* just ignore */ 1168 goto out; /* just ignore */
1169 1169
1170 elt = p->Package.Elements; 1170 elt = p->Package.Elements;
1171 1171
1172 /* TBD: package support */ 1172 /* TBD: package support */
1173 if (enable) { 1173 if (enable) {
1174 AcpiSetGpeType(NULL, elt[0].Integer.Value, 1174 AcpiSetGpeType(NULL, elt[0].Integer.Value,
1175 ACPI_GPE_TYPE_WAKE_RUN); 1175 ACPI_GPE_TYPE_WAKE_RUN);
1176 AcpiEnableGpe(NULL, elt[0].Integer.Value, ACPI_NOT_ISR); 1176 AcpiEnableGpe(NULL, elt[0].Integer.Value, ACPI_NOT_ISR);
1177 } else 1177 } else
1178 AcpiDisableGpe(NULL, elt[0].Integer.Value, ACPI_NOT_ISR); 1178 AcpiDisableGpe(NULL, elt[0].Integer.Value, ACPI_NOT_ISR);
1179 1179
1180 out: 1180 out:
1181 AcpiOsFree(buf.Pointer); 1181 AcpiOsFree(buf.Pointer);
1182} 1182}
1183 1183
1184/* 1184/*
1185 * acpi_clear_wake_gpe 1185 * acpi_clear_wake_gpe
1186 * 1186 *
1187 * Clear GPE as both Runtime and Wake 1187 * Clear GPE as both Runtime and Wake
1188 */ 1188 */
1189void 1189void
1190acpi_clear_wake_gpe(ACPI_HANDLE handle) 1190acpi_clear_wake_gpe(ACPI_HANDLE handle)
1191{ 1191{
1192 acpi_wake_gpe_helper(handle, false); 1192 acpi_wake_gpe_helper(handle, false);
1193} 1193}
1194 1194
1195/* 1195/*
1196 * acpi_set_wake_gpe 1196 * acpi_set_wake_gpe
1197 * 1197 *
1198 * Set GPE as both Runtime and Wake 1198 * Set GPE as both Runtime and Wake
1199 */ 1199 */
1200void 1200void
1201acpi_set_wake_gpe(ACPI_HANDLE handle) 1201acpi_set_wake_gpe(ACPI_HANDLE handle)
1202{ 1202{
1203 acpi_wake_gpe_helper(handle, true); 1203 acpi_wake_gpe_helper(handle, true);
1204} 1204}
1205 1205
1206 1206
1207/***************************************************************************** 1207/*****************************************************************************
1208 * ACPI sleep support. 1208 * ACPI sleep support.
1209 *****************************************************************************/ 1209 *****************************************************************************/
1210 1210
1211static int 1211static int
1212is_available_state(struct acpi_softc *sc, int state) 1212is_available_state(struct acpi_softc *sc, int state)
1213{ 1213{
1214 UINT8 type_a, type_b; 1214 UINT8 type_a, type_b;
1215 1215
1216 return ACPI_SUCCESS(AcpiGetSleepTypeData((UINT8)state, 1216 return ACPI_SUCCESS(AcpiGetSleepTypeData((UINT8)state,
1217 &type_a, &type_b)); 1217 &type_a, &type_b));
1218} 1218}
1219 1219
1220/* 1220/*
1221 * acpi_enter_sleep_state: 1221 * acpi_enter_sleep_state:
1222 * 1222 *
1223 * enter to the specified sleep state. 1223 * enter to the specified sleep state.
1224 */ 1224 */
1225 1225
1226ACPI_STATUS 1226ACPI_STATUS
1227acpi_enter_sleep_state(struct acpi_softc *sc, int state) 1227acpi_enter_sleep_state(struct acpi_softc *sc, int state)
1228{ 1228{
1229 int err; 1229 int err;
1230 ACPI_STATUS ret = AE_OK; 1230 ACPI_STATUS ret = AE_OK;
1231 1231
1232 if (state == acpi_sleepstate) 1232 if (state == acpi_sleepstate)
1233 return AE_OK; 1233 return AE_OK;
1234 1234
1235 aprint_normal_dev(sc->sc_dev, "entering state %d\n", state); 1235 aprint_normal_dev(sc->sc_dev, "entering state %d\n", state);
1236 1236
1237 switch (state) { 1237 switch (state) {
1238 case ACPI_STATE_S0: 1238 case ACPI_STATE_S0:
1239 break; 1239 break;
1240 case ACPI_STATE_S1: 1240 case ACPI_STATE_S1:
1241 case ACPI_STATE_S2: 1241 case ACPI_STATE_S2:
1242 case ACPI_STATE_S3: 1242 case ACPI_STATE_S3:
1243 case ACPI_STATE_S4: 1243 case ACPI_STATE_S4:
1244 if (!is_available_state(sc, state)) { 1244 if (!is_available_state(sc, state)) {
1245 aprint_error_dev(sc->sc_dev, 1245 aprint_error_dev(sc->sc_dev,
1246 "ACPI S%d not available on this platform\n", state); 1246 "ACPI S%d not available on this platform\n", state);
1247 break; 1247 break;
1248 } 1248 }
1249 1249
1250 if (state != ACPI_STATE_S1 && !pmf_system_suspend(PMF_F_NONE)) { 1250 if (state != ACPI_STATE_S1 && !pmf_system_suspend(PMF_F_NONE)) {
1251 aprint_error_dev(sc->sc_dev, "aborting suspend\n"); 1251 aprint_error_dev(sc->sc_dev, "aborting suspend\n");
1252 break; 1252 break;
1253 } 1253 }
1254 1254
1255 ret = AcpiEnterSleepStatePrep(state); 1255 ret = AcpiEnterSleepStatePrep(state);
1256 if (ACPI_FAILURE(ret)) { 1256 if (ACPI_FAILURE(ret)) {
1257 aprint_error_dev(sc->sc_dev, 1257 aprint_error_dev(sc->sc_dev,
1258 "failed preparing to sleep (%s)\n", 1258 "failed preparing to sleep (%s)\n",
1259 AcpiFormatException(ret)); 1259 AcpiFormatException(ret));
1260 break; 1260 break;
1261 } 1261 }
1262 1262
1263 acpi_sleepstate = state; 1263 acpi_sleepstate = state;
1264 if (state == ACPI_STATE_S1) { 1264 if (state == ACPI_STATE_S1) {
1265 /* just enter the state */ 1265 /* just enter the state */
1266 acpi_md_OsDisableInterrupt(); 1266 acpi_md_OsDisableInterrupt();
1267 ret = AcpiEnterSleepState((UINT8)state); 1267 ret = AcpiEnterSleepState((UINT8)state);
1268 if (ACPI_FAILURE(ret)) 1268 if (ACPI_FAILURE(ret))
1269 aprint_error_dev(sc->sc_dev, 1269 aprint_error_dev(sc->sc_dev,
1270 "failed to enter sleep state S1: %s\n", 1270 "failed to enter sleep state S1: %s\n",
1271 AcpiFormatException(ret)); 1271 AcpiFormatException(ret));
1272 AcpiLeaveSleepState((UINT8)state); 1272 AcpiLeaveSleepState((UINT8)state);
1273 } else { 1273 } else {
1274 int s = splhigh(); 
1275 err = acpi_md_sleep(state); 1274 err = acpi_md_sleep(state);
1276 if (state == ACPI_STATE_S4) 1275 if (state == ACPI_STATE_S4)
1277 AcpiEnable(); 1276 AcpiEnable();
1278 pmf_system_bus_resume(PMF_F_NONE); 1277 pmf_system_bus_resume(PMF_F_NONE);
1279 AcpiLeaveSleepState((UINT8)state); 1278 AcpiLeaveSleepState((UINT8)state);
1280 splx(s); 
1281 pmf_system_resume(PMF_F_NONE); 1279 pmf_system_resume(PMF_F_NONE);
1282 } 1280 }
1283 1281
1284 break; 1282 break;
1285 case ACPI_STATE_S5: 1283 case ACPI_STATE_S5:
1286 ret = AcpiEnterSleepStatePrep(ACPI_STATE_S5); 1284 ret = AcpiEnterSleepStatePrep(ACPI_STATE_S5);
1287 if (ACPI_FAILURE(ret)) { 1285 if (ACPI_FAILURE(ret)) {
1288 aprint_error_dev(sc->sc_dev, 1286 aprint_error_dev(sc->sc_dev,
1289 "failed preparing to sleep (%s)\n", 1287 "failed preparing to sleep (%s)\n",
1290 AcpiFormatException(ret)); 1288 AcpiFormatException(ret));
1291 break; 1289 break;
1292 } 1290 }
1293 DELAY(1000000); 1291 DELAY(1000000);
1294 acpi_sleepstate = state; 1292 acpi_sleepstate = state;
1295 acpi_md_OsDisableInterrupt(); 1293 acpi_md_OsDisableInterrupt();
1296 AcpiEnterSleepState(ACPI_STATE_S5); 1294 AcpiEnterSleepState(ACPI_STATE_S5);
1297 aprint_error_dev(sc->sc_dev, "WARNING powerdown failed!\n"); 1295 aprint_error_dev(sc->sc_dev, "WARNING powerdown failed!\n");
1298 break; 1296 break;
1299 } 1297 }
1300 1298
1301 acpi_sleepstate = ACPI_STATE_S0; 1299 acpi_sleepstate = ACPI_STATE_S0;
1302 return ret; 1300 return ret;
1303} 1301}
1304 1302
1305#if defined(ACPI_ACTIVATE_DEV) 1303#if defined(ACPI_ACTIVATE_DEV)
1306/* XXX This very incomplete */ 1304/* XXX This very incomplete */
1307ACPI_STATUS 1305ACPI_STATUS
1308acpi_allocate_resources(ACPI_HANDLE handle) 1306acpi_allocate_resources(ACPI_HANDLE handle)
1309{ 1307{
1310 ACPI_BUFFER bufp, bufc, bufn; 1308 ACPI_BUFFER bufp, bufc, bufn;
1311 ACPI_RESOURCE *resp, *resc, *resn; 1309 ACPI_RESOURCE *resp, *resc, *resn;
1312 ACPI_RESOURCE_IRQ *irq; 1310 ACPI_RESOURCE_IRQ *irq;
1313 ACPI_RESOURCE_EXTENDED_IRQ *xirq; 1311 ACPI_RESOURCE_EXTENDED_IRQ *xirq;
1314 ACPI_STATUS rv; 1312 ACPI_STATUS rv;
1315 uint delta; 1313 uint delta;
1316 1314
1317 rv = acpi_get(handle, &bufp, AcpiGetPossibleResources); 1315 rv = acpi_get(handle, &bufp, AcpiGetPossibleResources);
1318 if (ACPI_FAILURE(rv)) 1316 if (ACPI_FAILURE(rv))
1319 goto out; 1317 goto out;
1320 rv = acpi_get(handle, &bufc, AcpiGetCurrentResources); 1318 rv = acpi_get(handle, &bufc, AcpiGetCurrentResources);
1321 if (ACPI_FAILURE(rv)) { 1319 if (ACPI_FAILURE(rv)) {
1322 goto out1; 1320 goto out1;
1323 } 1321 }
1324 1322
1325 bufn.Length = 1000; 1323 bufn.Length = 1000;
1326 bufn.Pointer = resn = malloc(bufn.Length, M_ACPI, M_WAITOK); 1324 bufn.Pointer = resn = malloc(bufn.Length, M_ACPI, M_WAITOK);
1327 resp = bufp.Pointer; 1325 resp = bufp.Pointer;
1328 resc = bufc.Pointer; 1326 resc = bufc.Pointer;
1329 while (resc->Type != ACPI_RESOURCE_TYPE_END_TAG && 1327 while (resc->Type != ACPI_RESOURCE_TYPE_END_TAG &&
1330 resp->Type != ACPI_RESOURCE_TYPE_END_TAG) { 1328 resp->Type != ACPI_RESOURCE_TYPE_END_TAG) {
1331 while (resc->Type != resp->Type && resp->Type != ACPI_RESOURCE_TYPE_END_TAG) 1329 while (resc->Type != resp->Type && resp->Type != ACPI_RESOURCE_TYPE_END_TAG)
1332 resp = ACPI_NEXT_RESOURCE(resp); 1330 resp = ACPI_NEXT_RESOURCE(resp);
1333 if (resp->Type == ACPI_RESOURCE_TYPE_END_TAG) 1331 if (resp->Type == ACPI_RESOURCE_TYPE_END_TAG)
1334 break; 1332 break;
1335 /* Found identical Id */ 1333 /* Found identical Id */
1336 resn->Type = resc->Type; 1334 resn->Type = resc->Type;
1337 switch (resc->Type) { 1335 switch (resc->Type) {
1338 case ACPI_RESOURCE_TYPE_IRQ: 1336 case ACPI_RESOURCE_TYPE_IRQ:
1339 memcpy(&resn->Data, &resp->Data, 1337 memcpy(&resn->Data, &resp->Data,
1340 sizeof(ACPI_RESOURCE_IRQ)); 1338 sizeof(ACPI_RESOURCE_IRQ));
1341 irq = (ACPI_RESOURCE_IRQ *)&resn->Data; 1339 irq = (ACPI_RESOURCE_IRQ *)&resn->Data;
1342 irq->Interrupts[0] = 1340 irq->Interrupts[0] =
1343 ((ACPI_RESOURCE_IRQ *)&resp->Data)-> 1341 ((ACPI_RESOURCE_IRQ *)&resp->Data)->
1344 Interrupts[irq->InterruptCount-1]; 1342 Interrupts[irq->InterruptCount-1];
1345 irq->InterruptCount = 1; 1343 irq->InterruptCount = 1;
1346 resn->Length = ACPI_RS_SIZE(ACPI_RESOURCE_IRQ); 1344 resn->Length = ACPI_RS_SIZE(ACPI_RESOURCE_IRQ);
1347 break; 1345 break;
1348 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: 1346 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
1349 memcpy(&resn->Data, &resp->Data, 1347 memcpy(&resn->Data, &resp->Data,
1350 sizeof(ACPI_RESOURCE_EXTENDED_IRQ)); 1348 sizeof(ACPI_RESOURCE_EXTENDED_IRQ));
1351 xirq = (ACPI_RESOURCE_EXTENDED_IRQ *)&resn->Data; 1349 xirq = (ACPI_RESOURCE_EXTENDED_IRQ *)&resn->Data;
1352#if 0 1350#if 0
1353 /* 1351 /*
1354 * XXX not duplicating the interrupt logic above 1352 * XXX not duplicating the interrupt logic above
1355 * because its not clear what it accomplishes. 1353 * because its not clear what it accomplishes.
1356 */ 1354 */
1357 xirq->Interrupts[0] = 1355 xirq->Interrupts[0] =
1358 ((ACPI_RESOURCE_EXT_IRQ *)&resp->Data)-> 1356 ((ACPI_RESOURCE_EXT_IRQ *)&resp->Data)->
1359 Interrupts[irq->NumberOfInterrupts-1]; 1357 Interrupts[irq->NumberOfInterrupts-1];
1360 xirq->NumberOfInterrupts = 1; 1358 xirq->NumberOfInterrupts = 1;
1361#endif 1359#endif
1362 resn->Length = ACPI_RS_SIZE(ACPI_RESOURCE_EXTENDED_IRQ); 1360 resn->Length = ACPI_RS_SIZE(ACPI_RESOURCE_EXTENDED_IRQ);
1363 break; 1361 break;
1364 case ACPI_RESOURCE_TYPE_IO: 1362 case ACPI_RESOURCE_TYPE_IO:
1365 memcpy(&resn->Data, &resp->Data, 1363 memcpy(&resn->Data, &resp->Data,
1366 sizeof(ACPI_RESOURCE_IO)); 1364 sizeof(ACPI_RESOURCE_IO));
1367 resn->Length = resp->Length; 1365 resn->Length = resp->Length;
1368 break; 1366 break;
1369 default: 1367 default:
1370 printf("acpi_allocate_resources: res=%d\n", resc->Type); 1368 printf("acpi_allocate_resources: res=%d\n", resc->Type);
1371 rv = AE_BAD_DATA; 1369 rv = AE_BAD_DATA;
1372 goto out2; 1370 goto out2;
1373 } 1371 }
1374 resc = ACPI_NEXT_RESOURCE(resc); 1372 resc = ACPI_NEXT_RESOURCE(resc);
1375 resn = ACPI_NEXT_RESOURCE(resn); 1373 resn = ACPI_NEXT_RESOURCE(resn);
1376 resp = ACPI_NEXT_RESOURCE(resp); 1374 resp = ACPI_NEXT_RESOURCE(resp);
1377 delta = (UINT8 *)resn - (UINT8 *)bufn.Pointer; 1375 delta = (UINT8 *)resn - (UINT8 *)bufn.Pointer;
1378 if (delta >= 1376 if (delta >=
1379 bufn.Length-ACPI_RS_SIZE(ACPI_RESOURCE_DATA)) { 1377 bufn.Length-ACPI_RS_SIZE(ACPI_RESOURCE_DATA)) {
1380 bufn.Length *= 2; 1378 bufn.Length *= 2;
1381 bufn.Pointer = realloc(bufn.Pointer, bufn.Length, 1379 bufn.Pointer = realloc(bufn.Pointer, bufn.Length,
1382 M_ACPI, M_WAITOK); 1380 M_ACPI, M_WAITOK);
1383 resn = (ACPI_RESOURCE *)((UINT8 *)bufn.Pointer + delta); 1381 resn = (ACPI_RESOURCE *)((UINT8 *)bufn.Pointer + delta);
1384 } 1382 }
1385 } 1383 }
1386 if (resc->Type != ACPI_RESOURCE_TYPE_END_TAG) { 1384 if (resc->Type != ACPI_RESOURCE_TYPE_END_TAG) {
1387 printf("acpi_allocate_resources: resc not exhausted\n"); 1385 printf("acpi_allocate_resources: resc not exhausted\n");
1388 rv = AE_BAD_DATA; 1386 rv = AE_BAD_DATA;
1389 goto out3; 1387 goto out3;
1390 } 1388 }
1391 1389
1392 resn->Type = ACPI_RESOURCE_TYPE_END_TAG; 1390 resn->Type = ACPI_RESOURCE_TYPE_END_TAG;
1393 rv = AcpiSetCurrentResources(handle, &bufn); 1391 rv = AcpiSetCurrentResources(handle, &bufn);
1394 if (ACPI_FAILURE(rv)) { 1392 if (ACPI_FAILURE(rv)) {
1395 printf("acpi_allocate_resources: AcpiSetCurrentResources %s\n", 1393 printf("acpi_allocate_resources: AcpiSetCurrentResources %s\n",
1396 AcpiFormatException(rv)); 1394 AcpiFormatException(rv));
1397 } 1395 }
1398 1396
1399out3: 1397out3:
1400 free(bufn.Pointer, M_ACPI); 1398 free(bufn.Pointer, M_ACPI);
1401out2: 1399out2:
1402 AcpiOsFree(bufc.Pointer); 1400 AcpiOsFree(bufc.Pointer);
1403out1: 1401out1:
1404 AcpiOsFree(bufp.Pointer); 1402 AcpiOsFree(bufp.Pointer);
1405out: 1403out:
1406 return rv; 1404 return rv;
1407} 1405}
1408#endif /* ACPI_ACTIVATE_DEV */ 1406#endif /* ACPI_ACTIVATE_DEV */
1409 1407
1410SYSCTL_SETUP(sysctl_acpi_setup, "sysctl hw.acpi subtree setup") 1408SYSCTL_SETUP(sysctl_acpi_setup, "sysctl hw.acpi subtree setup")
1411{ 1409{
1412 const struct sysctlnode *node; 1410 const struct sysctlnode *node;
1413 const struct sysctlnode *ssnode; 1411 const struct sysctlnode *ssnode;
1414 1412
1415 if (sysctl_createv(clog, 0, NULL, NULL, 1413 if (sysctl_createv(clog, 0, NULL, NULL,
1416 CTLFLAG_PERMANENT, 1414 CTLFLAG_PERMANENT,
1417 CTLTYPE_NODE, "hw", NULL, 1415 CTLTYPE_NODE, "hw", NULL,
1418 NULL, 0, NULL, 0, 1416 NULL, 0, NULL, 0,
1419 CTL_HW, CTL_EOL) != 0) 1417 CTL_HW, CTL_EOL) != 0)
1420 return; 1418 return;
1421 1419
1422 if (sysctl_createv(clog, 0, NULL, &node, 1420 if (sysctl_createv(clog, 0, NULL, &node,
1423 CTLFLAG_PERMANENT, 1421 CTLFLAG_PERMANENT,
1424 CTLTYPE_NODE, "acpi", NULL, 1422 CTLTYPE_NODE, "acpi", NULL,
1425 NULL, 0, NULL, 0, 1423 NULL, 0, NULL, 0,
1426 CTL_HW, CTL_CREATE, CTL_EOL) != 0) 1424 CTL_HW, CTL_CREATE, CTL_EOL) != 0)
1427 return; 1425 return;
1428 1426
1429 sysctl_createv(NULL, 0, NULL, NULL, CTLFLAG_READONLY, 1427 sysctl_createv(NULL, 0, NULL, NULL, CTLFLAG_READONLY,
1430 CTLTYPE_QUAD, "root", 1428 CTLTYPE_QUAD, "root",
1431 SYSCTL_DESCR("ACPI root pointer"), 1429 SYSCTL_DESCR("ACPI root pointer"),
1432 NULL, 0, &acpi_root_pointer, sizeof(acpi_root_pointer), 1430 NULL, 0, &acpi_root_pointer, sizeof(acpi_root_pointer),
1433 CTL_HW, node->sysctl_num, CTL_CREATE, CTL_EOL); 1431 CTL_HW, node->sysctl_num, CTL_CREATE, CTL_EOL);
1434 sysctl_createv(NULL, 0, NULL, NULL, CTLFLAG_READONLY, 1432 sysctl_createv(NULL, 0, NULL, NULL, CTLFLAG_READONLY,
1435 CTLTYPE_STRING, "supported_states", 1433 CTLTYPE_STRING, "supported_states",
1436 SYSCTL_DESCR("Supported ACPI system states"), 1434 SYSCTL_DESCR("Supported ACPI system states"),
1437 NULL, 0, acpi_supported_states, 0, 1435 NULL, 0, acpi_supported_states, 0,
1438 CTL_HW, node->sysctl_num, CTL_CREATE, CTL_EOL); 1436 CTL_HW, node->sysctl_num, CTL_CREATE, CTL_EOL);
1439 1437
1440 /* ACPI sleepstate sysctl */ 1438 /* ACPI sleepstate sysctl */
1441 if (sysctl_createv(NULL, 0, NULL, &node, 1439 if (sysctl_createv(NULL, 0, NULL, &node,
1442 CTLFLAG_PERMANENT, 1440 CTLFLAG_PERMANENT,
1443 CTLTYPE_NODE, "machdep", NULL, 1441 CTLTYPE_NODE, "machdep", NULL,
1444 NULL, 0, NULL, 0, CTL_MACHDEP, CTL_EOL) != 0) 1442 NULL, 0, NULL, 0, CTL_MACHDEP, CTL_EOL) != 0)
1445 return; 1443 return;
1446 if (sysctl_createv(NULL, 0, &node, &ssnode, 1444 if (sysctl_createv(NULL, 0, &node, &ssnode,
1447 CTLFLAG_READWRITE, CTLTYPE_INT, "sleep_state", 1445 CTLFLAG_READWRITE, CTLTYPE_INT, "sleep_state",
1448 NULL, sysctl_hw_acpi_sleepstate, 0, NULL, 0, CTL_CREATE, 1446 NULL, sysctl_hw_acpi_sleepstate, 0, NULL, 0, CTL_CREATE,
1449 CTL_EOL) != 0) 1447 CTL_EOL) != 0)
1450 return; 1448 return;
1451} 1449}
1452 1450
1453static int 1451static int
1454sysctl_hw_acpi_sleepstate(SYSCTLFN_ARGS) 1452sysctl_hw_acpi_sleepstate(SYSCTLFN_ARGS)
1455{ 1453{
1456 int error, t; 1454 int error, t;
1457 struct sysctlnode node; 1455 struct sysctlnode node;
1458 1456
1459 node = *rnode; 1457 node = *rnode;
1460 t = acpi_sleepstate; 1458 t = acpi_sleepstate;
1461 node.sysctl_data = &t; 1459 node.sysctl_data = &t;
1462 error = sysctl_lookup(SYSCTLFN_CALL(&node)); 1460 error = sysctl_lookup(SYSCTLFN_CALL(&node));
1463 if (error || newp == NULL) 1461 if (error || newp == NULL)
1464 return error; 1462 return error;
1465 1463
1466 if (acpi_softc == NULL) 1464 if (acpi_softc == NULL)
1467 return ENOSYS; 1465 return ENOSYS;
1468 1466
1469 acpi_enter_sleep_state(acpi_softc, t); 1467 acpi_enter_sleep_state(acpi_softc, t);
1470 1468
1471 return 0; 1469 return 0;
1472} 1470}
1473 1471
1474static ACPI_TABLE_HEADER * 1472static ACPI_TABLE_HEADER *
1475acpi_map_rsdt(void) 1473acpi_map_rsdt(void)
1476{ 1474{
1477 ACPI_PHYSICAL_ADDRESS paddr; 1475 ACPI_PHYSICAL_ADDRESS paddr;
1478 ACPI_TABLE_RSDP *rsdp; 1476 ACPI_TABLE_RSDP *rsdp;
1479 1477
1480 paddr = AcpiOsGetRootPointer(); 1478 paddr = AcpiOsGetRootPointer();
1481 if (paddr == 0) { 1479 if (paddr == 0) {
1482 printf("ACPI: couldn't get root pointer\n"); 1480 printf("ACPI: couldn't get root pointer\n");
1483 return NULL; 1481 return NULL;
1484 } 1482 }
1485 rsdp = AcpiOsMapMemory(paddr, sizeof(ACPI_TABLE_RSDP)); 1483 rsdp = AcpiOsMapMemory(paddr, sizeof(ACPI_TABLE_RSDP));
1486 if (rsdp == NULL) { 1484 if (rsdp == NULL) {
1487 printf("ACPI: couldn't map RSDP\n"); 1485 printf("ACPI: couldn't map RSDP\n");
1488 return NULL; 1486 return NULL;
1489 } 1487 }
1490 if (rsdp->Revision > 1 && rsdp->XsdtPhysicalAddress) 1488 if (rsdp->Revision > 1 && rsdp->XsdtPhysicalAddress)
1491 paddr = (ACPI_PHYSICAL_ADDRESS)rsdp->XsdtPhysicalAddress; 1489 paddr = (ACPI_PHYSICAL_ADDRESS)rsdp->XsdtPhysicalAddress;
1492 else 1490 else
1493 paddr = (ACPI_PHYSICAL_ADDRESS)rsdp->RsdtPhysicalAddress; 1491 paddr = (ACPI_PHYSICAL_ADDRESS)rsdp->RsdtPhysicalAddress;
1494 AcpiOsUnmapMemory(rsdp, sizeof(ACPI_TABLE_RSDP)); 1492 AcpiOsUnmapMemory(rsdp, sizeof(ACPI_TABLE_RSDP));
1495 1493
1496 return AcpiOsMapMemory(paddr, sizeof(ACPI_TABLE_HEADER)); 1494 return AcpiOsMapMemory(paddr, sizeof(ACPI_TABLE_HEADER));
1497} 1495}
1498 1496
1499static void 1497static void
1500acpi_unmap_rsdt(ACPI_TABLE_HEADER *rsdt) 1498acpi_unmap_rsdt(ACPI_TABLE_HEADER *rsdt)
1501{ 1499{
1502 if (rsdt == NULL) 1500 if (rsdt == NULL)
1503 return; 1501 return;
1504 1502
1505 AcpiOsUnmapMemory(rsdt, sizeof(ACPI_TABLE_HEADER)); 1503 AcpiOsUnmapMemory(rsdt, sizeof(ACPI_TABLE_HEADER));
1506} 1504}