acpi.c revision 1.2 1 1.2 thorpej /* $NetBSD: acpi.c,v 1.2 2001/09/29 05:34:00 thorpej Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*
4 1.1 thorpej * Copyright 2001 Wasabi Systems, Inc.
5 1.1 thorpej * All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 1.1 thorpej *
9 1.1 thorpej * Redistribution and use in source and binary forms, with or without
10 1.1 thorpej * modification, are permitted provided that the following conditions
11 1.1 thorpej * are met:
12 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
13 1.1 thorpej * notice, this list of conditions and the following disclaimer.
14 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
16 1.1 thorpej * documentation and/or other materials provided with the distribution.
17 1.1 thorpej * 3. All advertising materials mentioning features or use of this software
18 1.1 thorpej * must display the following acknowledgement:
19 1.1 thorpej * This product includes software developed for the NetBSD Project by
20 1.1 thorpej * Wasabi Systems, Inc.
21 1.1 thorpej * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.1 thorpej * or promote products derived from this software without specific prior
23 1.1 thorpej * written permission.
24 1.1 thorpej *
25 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.1 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
36 1.1 thorpej */
37 1.1 thorpej
38 1.1 thorpej /*
39 1.1 thorpej * Autoconfiguration support for the Intel ACPI Component Architecture
40 1.1 thorpej * ACPI reference implementation.
41 1.1 thorpej */
42 1.1 thorpej
43 1.1 thorpej #include <sys/param.h>
44 1.1 thorpej #include <sys/systm.h>
45 1.1 thorpej #include <sys/device.h>
46 1.1 thorpej #include <sys/malloc.h>
47 1.1 thorpej
48 1.1 thorpej #include <dev/acpi/acpica.h>
49 1.1 thorpej #include <dev/acpi/acpireg.h>
50 1.1 thorpej #include <dev/acpi/acpivar.h>
51 1.1 thorpej #include <dev/acpi/acpi_osd.h>
52 1.1 thorpej
53 1.1 thorpej #ifdef ENABLE_DEBUGGER
54 1.1 thorpej #define ACPI_DBGR_INIT 0x01
55 1.1 thorpej #define ACPI_DBGR_TABLES 0x02
56 1.1 thorpej #define ACPI_DBGR_ENABLE 0x04
57 1.1 thorpej #define ACPI_DBGR_PROBE 0x08
58 1.1 thorpej #define ACPI_DBGR_RUNNING 0x10
59 1.1 thorpej
60 1.1 thorpej int acpi_dbgr = 0x00;
61 1.1 thorpej #endif
62 1.1 thorpej
63 1.1 thorpej int acpi_match(struct device *, struct cfdata *, void *);
64 1.1 thorpej void acpi_attach(struct device *, struct device *, void *);
65 1.1 thorpej
66 1.1 thorpej int acpi_print(void *aux, const char *);
67 1.1 thorpej
68 1.1 thorpej extern struct cfdriver acpi_cd;
69 1.1 thorpej
70 1.1 thorpej struct cfattach acpi_ca = {
71 1.1 thorpej sizeof(struct acpi_softc), acpi_match, acpi_attach,
72 1.1 thorpej };
73 1.1 thorpej
74 1.1 thorpej /*
75 1.1 thorpej * This is a flag we set when the ACPI subsystem is active. Machine
76 1.1 thorpej * dependent code may wish to skip other steps (such as attaching
77 1.1 thorpej * subsystems that ACPI supercedes) when ACPI is active.
78 1.1 thorpej */
79 1.1 thorpej int acpi_active;
80 1.1 thorpej
81 1.1 thorpej /*
82 1.1 thorpej * Pointer to the ACPI subsystem's state. There can be only
83 1.1 thorpej * one ACPI instance.
84 1.1 thorpej */
85 1.1 thorpej struct acpi_softc *acpi_softc;
86 1.1 thorpej
87 1.1 thorpej void acpi_shutdown(void *);
88 1.1 thorpej ACPI_STATUS acpi_disable(struct acpi_softc *sc);
89 1.1 thorpej void acpi_build_tree(struct acpi_softc *);
90 1.1 thorpej ACPI_STATUS acpi_make_devnode(ACPI_HANDLE, UINT32, void *, void **);
91 1.1 thorpej
92 1.1 thorpej void acpi_system_notify_handler(ACPI_HANDLE, UINT32, void *);
93 1.1 thorpej
94 1.1 thorpej void acpi_enable_fixed_events(struct acpi_softc *);
95 1.1 thorpej
96 1.1 thorpej /*
97 1.1 thorpej * acpi_probe:
98 1.1 thorpej *
99 1.1 thorpej * Probe for ACPI support. This is called by the
100 1.1 thorpej * machine-dependent ACPI front-end. All of the
101 1.1 thorpej * actual work is done by ACPICA.
102 1.1 thorpej *
103 1.1 thorpej * NOTE: This is not an autoconfiguration interface function.
104 1.1 thorpej */
105 1.1 thorpej int
106 1.1 thorpej acpi_probe(void)
107 1.1 thorpej {
108 1.1 thorpej static int beenhere;
109 1.1 thorpej ACPI_STATUS rv;
110 1.1 thorpej
111 1.1 thorpej if (beenhere != 0)
112 1.1 thorpej panic("acpi_probe: ACPI has already been probed");
113 1.1 thorpej beenhere = 1;
114 1.1 thorpej
115 1.1 thorpej /*
116 1.1 thorpej * Start up ACPICA.
117 1.1 thorpej */
118 1.1 thorpej #ifdef ENABLE_DEBUGGER
119 1.1 thorpej if (acpi_dbgr & ACPI_DBGR_INIT)
120 1.1 thorpej acpi_osd_debugger();
121 1.1 thorpej #endif
122 1.1 thorpej
123 1.1 thorpej rv = AcpiInitializeSubsystem();
124 1.1 thorpej if (rv != AE_OK) {
125 1.1 thorpej printf("ACPI: unable to initialize ACPICA: %d\n", rv);
126 1.1 thorpej return (0);
127 1.1 thorpej }
128 1.1 thorpej
129 1.1 thorpej #ifdef ENABLE_DEBUGGER
130 1.1 thorpej if (acpi_dbgr & ACPI_DBGR_TABLES)
131 1.1 thorpej acpi_osd_debugger();
132 1.1 thorpej #endif
133 1.1 thorpej
134 1.1 thorpej rv = AcpiLoadTables();
135 1.1 thorpej if (rv != AE_OK) {
136 1.1 thorpej printf("ACPI: unable to load tables: %d\n", rv);
137 1.1 thorpej return (0);
138 1.1 thorpej }
139 1.1 thorpej
140 1.1 thorpej /*
141 1.1 thorpej * Looks like we have ACPI!
142 1.1 thorpej */
143 1.1 thorpej
144 1.1 thorpej return (1);
145 1.1 thorpej }
146 1.1 thorpej
147 1.1 thorpej /*
148 1.1 thorpej * acpi_match:
149 1.1 thorpej *
150 1.1 thorpej * Autoconfiguration `match' routine.
151 1.1 thorpej */
152 1.1 thorpej int
153 1.1 thorpej acpi_match(struct device *parent, struct cfdata *match, void *aux)
154 1.1 thorpej {
155 1.1 thorpej struct acpibus_attach_args *aa = aux;
156 1.1 thorpej
157 1.1 thorpej if (strcmp(aa->aa_busname, acpi_cd.cd_name) != 0)
158 1.1 thorpej return (0);
159 1.1 thorpej
160 1.1 thorpej /*
161 1.1 thorpej * XXX Check other locators? Hard to know -- machine
162 1.1 thorpej * dependent code has already checked for the presence
163 1.1 thorpej * of ACPI by calling acpi_probe(), so I suppose we
164 1.1 thorpej * don't really have to do anything else.
165 1.1 thorpej */
166 1.1 thorpej return (1);
167 1.1 thorpej }
168 1.1 thorpej
169 1.1 thorpej /*
170 1.1 thorpej * acpi_attach:
171 1.1 thorpej *
172 1.1 thorpej * Autoconfiguration `attach' routine. Finish initializing
173 1.1 thorpej * ACPICA (some initialization was done in acpi_probe(),
174 1.1 thorpej * which was required to check for the presence of ACPI),
175 1.1 thorpej * and enable the ACPI subsystem.
176 1.1 thorpej */
177 1.1 thorpej void
178 1.1 thorpej acpi_attach(struct device *parent, struct device *self, void *aux)
179 1.1 thorpej {
180 1.1 thorpej struct acpi_softc *sc = (void *) self;
181 1.1 thorpej struct acpibus_attach_args *aa = aux;
182 1.1 thorpej ACPI_STATUS rv;
183 1.1 thorpej
184 1.1 thorpej printf("\n");
185 1.1 thorpej
186 1.1 thorpej if (acpi_softc != NULL)
187 1.1 thorpej panic("acpi_attach: ACPI has already been attached");
188 1.1 thorpej
189 1.1 thorpej sc->sc_iot = aa->aa_iot;
190 1.1 thorpej sc->sc_memt = aa->aa_memt;
191 1.1 thorpej sc->sc_pc = aa->aa_pc;
192 1.1 thorpej sc->sc_pciflags = aa->aa_pciflags;
193 1.1 thorpej
194 1.1 thorpej acpi_softc = sc;
195 1.1 thorpej
196 1.1 thorpej /*
197 1.1 thorpej * Install the default address space handlers.
198 1.1 thorpej */
199 1.1 thorpej
200 1.1 thorpej rv = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
201 1.1 thorpej ACPI_ADR_SPACE_SYSTEM_MEMORY, ACPI_DEFAULT_HANDLER, NULL, NULL);
202 1.1 thorpej if (rv != AE_OK) {
203 1.1 thorpej printf("%s: unable to install SYSTEM MEMORY handler: %d\n",
204 1.1 thorpej sc->sc_dev.dv_xname, rv);
205 1.1 thorpej return;
206 1.1 thorpej }
207 1.1 thorpej
208 1.1 thorpej rv = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
209 1.1 thorpej ACPI_ADR_SPACE_SYSTEM_IO, ACPI_DEFAULT_HANDLER, NULL, NULL);
210 1.1 thorpej if (rv != AE_OK) {
211 1.1 thorpej printf("%s: unable to install SYSTEM IO handler: %d\n",
212 1.1 thorpej sc->sc_dev.dv_xname, rv);
213 1.1 thorpej return;
214 1.1 thorpej }
215 1.1 thorpej
216 1.1 thorpej rv = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
217 1.1 thorpej ACPI_ADR_SPACE_PCI_CONFIG, ACPI_DEFAULT_HANDLER, NULL, NULL);
218 1.1 thorpej if (rv != AE_OK) {
219 1.1 thorpej printf("%s: unable to install PCI CONFIG handler: %d\n",
220 1.1 thorpej sc->sc_dev.dv_xname, rv);
221 1.1 thorpej return;
222 1.1 thorpej }
223 1.1 thorpej
224 1.1 thorpej /*
225 1.1 thorpej * Bring ACPI on-line.
226 1.1 thorpej *
227 1.1 thorpej * Note that we request that _STA (device init) and _INI (object init)
228 1.1 thorpej * methods not be run.
229 1.1 thorpej *
230 1.1 thorpej * XXX We need to arrange for the object init pass after we have
231 1.1 thorpej * XXX attached all of our children.
232 1.1 thorpej */
233 1.1 thorpej #ifdef ENABLE_DEBUGGER
234 1.1 thorpej if (acpi_dbgr & ACPI_DBGR_ENABLE)
235 1.1 thorpej acpi_osd_debugger();
236 1.1 thorpej #endif
237 1.1 thorpej rv = AcpiEnableSubsystem(ACPI_NO_DEVICE_INIT | ACPI_NO_OBJECT_INIT);
238 1.1 thorpej if (rv != AE_OK) {
239 1.1 thorpej printf("%s: unable to enable ACPI: %d\n",
240 1.1 thorpej sc->sc_dev.dv_xname, rv);
241 1.1 thorpej return;
242 1.1 thorpej }
243 1.1 thorpej acpi_active = 1;
244 1.1 thorpej
245 1.1 thorpej /*
246 1.1 thorpej * Set up the default sleep state to enter when various
247 1.1 thorpej * switches are activated.
248 1.1 thorpej */
249 1.1 thorpej sc->sc_switch_sleep[ACPI_SWITCH_POWERBUTTON] = ACPI_STATE_S5;
250 1.1 thorpej sc->sc_switch_sleep[ACPI_SWITCH_SLEEPBUTTON] = ACPI_STATE_S1;
251 1.1 thorpej sc->sc_switch_sleep[ACPI_SWITCH_LID] = ACPI_STATE_S1;
252 1.1 thorpej
253 1.1 thorpej /* Our current state is "awake". */
254 1.1 thorpej sc->sc_sleepstate = ACPI_STATE_S0;
255 1.1 thorpej
256 1.1 thorpej /*
257 1.1 thorpej * We want to install a single system notify handler.
258 1.1 thorpej */
259 1.1 thorpej rv = AcpiInstallNotifyHandler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
260 1.1 thorpej acpi_system_notify_handler, sc);
261 1.1 thorpej if (rv != AE_OK)
262 1.1 thorpej printf("%s: WARNING: unable to install system notify "
263 1.1 thorpej "handler: %d\n", sc->sc_dev.dv_xname, rv);
264 1.1 thorpej
265 1.1 thorpej /*
266 1.1 thorpej * Check for fixed-hardware features.
267 1.1 thorpej */
268 1.1 thorpej acpi_enable_fixed_events(sc);
269 1.1 thorpej
270 1.1 thorpej /*
271 1.1 thorpej * Scan the namespace and build our device tree.
272 1.1 thorpej */
273 1.1 thorpej #ifdef ENABLE_DEBUGGER
274 1.1 thorpej if (acpi_dbgr & ACPI_DBGR_PROBE)
275 1.1 thorpej acpi_osd_debugger();
276 1.1 thorpej #endif
277 1.1 thorpej acpi_build_tree(sc);
278 1.1 thorpej
279 1.1 thorpej /*
280 1.1 thorpej * Register a shutdown hook that disables certain ACPI
281 1.1 thorpej * events that might happen and confuse us while we're
282 1.1 thorpej * trying to shut down.
283 1.1 thorpej */
284 1.1 thorpej sc->sc_sdhook = shutdownhook_establish(acpi_shutdown, sc);
285 1.1 thorpej if (sc->sc_sdhook == NULL)
286 1.1 thorpej printf("%s: WARNING: unable to register shutdown hook\n",
287 1.1 thorpej sc->sc_dev.dv_xname);
288 1.1 thorpej
289 1.1 thorpej #ifdef ENABLE_DEBUGGER
290 1.1 thorpej if (acpi_dbgr & ACPI_DBGR_RUNNING)
291 1.1 thorpej acpi_osd_debugger();
292 1.1 thorpej #endif
293 1.1 thorpej }
294 1.1 thorpej
295 1.1 thorpej /*
296 1.1 thorpej * acpi_shutdown:
297 1.1 thorpej *
298 1.1 thorpej * Shutdown hook for ACPI -- disable some events that
299 1.1 thorpej * might confuse us.
300 1.1 thorpej */
301 1.1 thorpej void
302 1.1 thorpej acpi_shutdown(void *arg)
303 1.1 thorpej {
304 1.1 thorpej struct acpi_softc *sc = arg;
305 1.1 thorpej
306 1.1 thorpej if (acpi_disable(sc) != AE_OK)
307 1.1 thorpej printf("%s: WARNING: unable to disable ACPI\n",
308 1.1 thorpej sc->sc_dev.dv_xname);
309 1.1 thorpej }
310 1.1 thorpej
311 1.1 thorpej /*
312 1.1 thorpej * acpi_disable:
313 1.1 thorpej *
314 1.1 thorpej * Disable ACPI.
315 1.1 thorpej */
316 1.1 thorpej ACPI_STATUS
317 1.1 thorpej acpi_disable(struct acpi_softc *sc)
318 1.1 thorpej {
319 1.1 thorpej ACPI_STATUS rv = AE_OK;
320 1.1 thorpej
321 1.1 thorpej if (acpi_active) {
322 1.1 thorpej rv = AcpiDisable();
323 1.1 thorpej if (rv == AE_OK)
324 1.1 thorpej acpi_active = 0;
325 1.1 thorpej }
326 1.1 thorpej return (rv);
327 1.1 thorpej }
328 1.1 thorpej
329 1.1 thorpej struct acpi_make_devnode_state {
330 1.1 thorpej struct acpi_softc *softc;
331 1.1 thorpej struct acpi_scope *scope;
332 1.1 thorpej };
333 1.1 thorpej
334 1.1 thorpej /*
335 1.1 thorpej * acpi_build_tree:
336 1.1 thorpej *
337 1.1 thorpej * Scan relevant portions of the ACPI namespace and attach
338 1.1 thorpej * child devices.
339 1.1 thorpej */
340 1.1 thorpej void
341 1.1 thorpej acpi_build_tree(struct acpi_softc *sc)
342 1.1 thorpej {
343 1.1 thorpej static const char *scopes[] = {
344 1.1 thorpej "\\_PR_", /* ACPI 1.0 processor namespace */
345 1.1 thorpej "\\_SB_", /* system bus namespace */
346 1.1 thorpej "\\_SI_", /* system idicator namespace */
347 1.1 thorpej "\\_TZ_", /* ACPI 1.0 thermal zone namespace */
348 1.1 thorpej NULL,
349 1.1 thorpej };
350 1.1 thorpej struct acpi_attach_args aa;
351 1.1 thorpej struct acpi_make_devnode_state state;
352 1.1 thorpej struct acpi_scope *as;
353 1.1 thorpej struct acpi_devnode *ad;
354 1.1 thorpej ACPI_HANDLE parent;
355 1.1 thorpej int i;
356 1.1 thorpej
357 1.1 thorpej TAILQ_INIT(&sc->sc_scopes);
358 1.1 thorpej
359 1.1 thorpej state.softc = sc;
360 1.1 thorpej
361 1.1 thorpej /*
362 1.1 thorpej * Scan the namespace and build our tree.
363 1.1 thorpej */
364 1.1 thorpej for (i = 0; scopes[i] != NULL; i++) {
365 1.1 thorpej as = malloc(sizeof(*as), M_DEVBUF, M_WAITOK);
366 1.1 thorpej as->as_name = scopes[i];
367 1.1 thorpej TAILQ_INIT(&as->as_devnodes);
368 1.1 thorpej
369 1.1 thorpej TAILQ_INSERT_TAIL(&sc->sc_scopes, as, as_list);
370 1.1 thorpej
371 1.1 thorpej state.scope = as;
372 1.1 thorpej
373 1.1 thorpej if (AcpiGetHandle(ACPI_ROOT_OBJECT, (char *) scopes[i],
374 1.1 thorpej &parent) == AE_OK) {
375 1.1 thorpej AcpiWalkNamespace(ACPI_TYPE_ANY, parent, 100,
376 1.1 thorpej acpi_make_devnode, &state, NULL);
377 1.1 thorpej }
378 1.1 thorpej
379 1.1 thorpej /* Now, for this namespace, try and attach the devices. */
380 1.1 thorpej TAILQ_FOREACH(ad, &as->as_devnodes, ad_list) {
381 1.1 thorpej aa.aa_node = ad;
382 1.1 thorpej aa.aa_iot = sc->sc_iot;
383 1.1 thorpej aa.aa_memt = sc->sc_memt;
384 1.1 thorpej aa.aa_pc = sc->sc_pc;
385 1.1 thorpej aa.aa_pciflags = sc->sc_pciflags;
386 1.1 thorpej
387 1.1 thorpej /*
388 1.1 thorpej * XXX We only attach devices which are:
389 1.1 thorpej *
390 1.1 thorpej * - present
391 1.1 thorpej * - enabled
392 1.1 thorpej * - to be shown
393 1.1 thorpej * - functioning properly
394 1.1 thorpej *
395 1.1 thorpej * However, if enabled, it's decoding resources,
396 1.1 thorpej * so we should claim them, if possible. Requires
397 1.1 thorpej * changes to bus_space(9).
398 1.1 thorpej */
399 1.1 thorpej if ((ad->ad_devinfo.CurrentStatus &
400 1.1 thorpej (ACPI_STA_DEV_PRESENT|ACPI_STA_DEV_ENABLED|
401 1.1 thorpej ACPI_STA_DEV_SHOW|ACPI_STA_DEV_OK)) !=
402 1.1 thorpej (ACPI_STA_DEV_PRESENT|ACPI_STA_DEV_ENABLED|
403 1.1 thorpej ACPI_STA_DEV_SHOW|ACPI_STA_DEV_OK))
404 1.1 thorpej continue;
405 1.1 thorpej
406 1.1 thorpej /*
407 1.1 thorpej * XXX Same problem as above...
408 1.1 thorpej */
409 1.1 thorpej if ((ad->ad_devinfo.Valid & ACPI_VALID_HID) == 0)
410 1.1 thorpej continue;
411 1.1 thorpej
412 1.1 thorpej ad->ad_device = config_found(&sc->sc_dev,
413 1.1 thorpej &aa, acpi_print);
414 1.1 thorpej }
415 1.1 thorpej }
416 1.1 thorpej }
417 1.1 thorpej
418 1.1 thorpej /*
419 1.1 thorpej * acpi_make_devnode:
420 1.1 thorpej *
421 1.1 thorpej * Make an ACPI devnode.
422 1.1 thorpej */
423 1.1 thorpej ACPI_STATUS
424 1.1 thorpej acpi_make_devnode(ACPI_HANDLE handle, UINT32 level, void *context,
425 1.1 thorpej void **status)
426 1.1 thorpej {
427 1.1 thorpej struct acpi_make_devnode_state *state = context;
428 1.1 thorpej struct acpi_softc *sc = state->softc;
429 1.1 thorpej struct acpi_scope *as = state->scope;
430 1.1 thorpej struct acpi_devnode *ad;
431 1.1 thorpej ACPI_OBJECT_TYPE type;
432 1.1 thorpej ACPI_STATUS rv;
433 1.1 thorpej
434 1.1 thorpej if (AcpiGetType(handle, &type) == AE_OK) {
435 1.1 thorpej switch (type) {
436 1.1 thorpej case ACPI_TYPE_DEVICE:
437 1.1 thorpej case ACPI_TYPE_PROCESSOR:
438 1.1 thorpej case ACPI_TYPE_THERMAL:
439 1.1 thorpej case ACPI_TYPE_POWER:
440 1.1 thorpej ad = malloc(sizeof(*ad), M_DEVBUF, M_NOWAIT);
441 1.1 thorpej if (ad == NULL)
442 1.1 thorpej return (AE_NO_MEMORY);
443 1.1 thorpej memset(ad, 0, sizeof(*ad));
444 1.1 thorpej
445 1.1 thorpej ad->ad_handle = handle;
446 1.1 thorpej ad->ad_level = level;
447 1.1 thorpej ad->ad_scope = as;
448 1.1 thorpej ad->ad_type = type;
449 1.1 thorpej
450 1.1 thorpej TAILQ_INSERT_TAIL(&as->as_devnodes, ad, ad_list);
451 1.1 thorpej
452 1.1 thorpej rv = AcpiGetObjectInfo(handle, &ad->ad_devinfo);
453 1.1 thorpej if (rv != AE_OK)
454 1.1 thorpej goto out;
455 1.1 thorpej
456 1.1 thorpej if ((ad->ad_devinfo.Valid & ACPI_VALID_HID) == 0)
457 1.1 thorpej goto out;
458 1.1 thorpej
459 1.1 thorpej #ifdef ACPI_DEBUG
460 1.1 thorpej printf("%s: HID %s found in scope %s level %d\n",
461 1.1 thorpej sc->sc_dev.dv_xname, ad->ad_devinfo.HardwareId,
462 1.1 thorpej as->as_name, ad->ad_level);
463 1.1 thorpej if (ad->ad_devinfo.Valid & ACPI_VALID_UID)
464 1.1 thorpej printf(" UID %s\n",
465 1.1 thorpej ad->ad_devinfo.UniqueId);
466 1.1 thorpej if (ad->ad_devinfo.Valid & ACPI_VALID_ADR)
467 1.1 thorpej printf(" ADR 0x%016qx\n",
468 1.1 thorpej ad->ad_devinfo.Address);
469 1.1 thorpej if (ad->ad_devinfo.Valid & ACPI_VALID_STA)
470 1.1 thorpej printf(" STA 0x%08x\n",
471 1.1 thorpej ad->ad_devinfo.CurrentStatus);
472 1.1 thorpej #endif
473 1.1 thorpej }
474 1.1 thorpej }
475 1.1 thorpej out:
476 1.1 thorpej return (AE_OK);
477 1.1 thorpej }
478 1.1 thorpej
479 1.1 thorpej /*
480 1.1 thorpej * acpi_print:
481 1.1 thorpej *
482 1.1 thorpej * Autoconfiguration print routine.
483 1.1 thorpej */
484 1.1 thorpej int
485 1.1 thorpej acpi_print(void *aux, const char *pnp)
486 1.1 thorpej {
487 1.1 thorpej struct acpi_attach_args *aa = aux;
488 1.1 thorpej
489 1.1 thorpej if (pnp)
490 1.1 thorpej printf("%s at %s", aa->aa_node->ad_devinfo.HardwareId, pnp);
491 1.1 thorpej
492 1.1 thorpej return (UNCONF);
493 1.1 thorpej }
494 1.1 thorpej
495 1.1 thorpej /*****************************************************************************
496 1.1 thorpej * ACPI fixed-hardware feature handlers
497 1.1 thorpej *****************************************************************************/
498 1.1 thorpej
499 1.1 thorpej UINT32 acpi_fixed_power_button_handler(void *);
500 1.1 thorpej UINT32 acpi_fixed_sleep_button_handler(void *);
501 1.1 thorpej
502 1.1 thorpej /*
503 1.1 thorpej * acpi_enable_fixed_events:
504 1.1 thorpej *
505 1.1 thorpej * Enable any fixed-hardware feature handlers.
506 1.1 thorpej */
507 1.1 thorpej void
508 1.1 thorpej acpi_enable_fixed_events(struct acpi_softc *sc)
509 1.1 thorpej {
510 1.1 thorpej static int beenhere;
511 1.1 thorpej ACPI_STATUS rv;
512 1.1 thorpej
513 1.1 thorpej /*
514 1.1 thorpej * Check for fixed-hardware buttons.
515 1.1 thorpej */
516 1.1 thorpej
517 1.1 thorpej if (AcpiGbl_FADT != NULL && AcpiGbl_FADT->PwrButton == 0) {
518 1.1 thorpej if (beenhere == 0)
519 1.1 thorpej printf("%s: fixed-feature power button present\n",
520 1.1 thorpej sc->sc_dev.dv_xname);
521 1.1 thorpej rv = AcpiInstallFixedEventHandler(ACPI_EVENT_POWER_BUTTON,
522 1.1 thorpej acpi_fixed_power_button_handler, sc);
523 1.1 thorpej if (rv != AE_OK)
524 1.1 thorpej printf("%s: unable to install handler for fixed "
525 1.1 thorpej "power button: %d\n", sc->sc_dev.dv_xname, rv);
526 1.1 thorpej }
527 1.1 thorpej
528 1.1 thorpej if (AcpiGbl_FADT != NULL && AcpiGbl_FADT->SleepButton == 0) {
529 1.1 thorpej if (beenhere == 0)
530 1.1 thorpej printf("%s: fixed-feature sleep button present\n",
531 1.1 thorpej sc->sc_dev.dv_xname);
532 1.1 thorpej rv = AcpiInstallFixedEventHandler(ACPI_EVENT_SLEEP_BUTTON,
533 1.1 thorpej acpi_fixed_sleep_button_handler, sc);
534 1.1 thorpej if (rv != AE_OK)
535 1.1 thorpej printf("%s: unable to install handler for fixed "
536 1.1 thorpej "power button: %d\n", sc->sc_dev.dv_xname, rv);
537 1.1 thorpej }
538 1.1 thorpej
539 1.1 thorpej beenhere = 1;
540 1.1 thorpej }
541 1.1 thorpej
542 1.1 thorpej /*
543 1.1 thorpej * acpi_fixed_power_button_handler:
544 1.1 thorpej *
545 1.1 thorpej * Fixed event handler for the power button.
546 1.1 thorpej */
547 1.1 thorpej UINT32
548 1.1 thorpej acpi_fixed_power_button_handler(void *context)
549 1.1 thorpej {
550 1.1 thorpej struct acpi_softc *sc = context;
551 1.1 thorpej
552 1.1 thorpej /* XXX XXX XXX */
553 1.1 thorpej
554 1.1 thorpej printf("%s: fixed power button pressed\n", sc->sc_dev.dv_xname);
555 1.1 thorpej
556 1.1 thorpej return (INTERRUPT_HANDLED);
557 1.1 thorpej }
558 1.1 thorpej
559 1.1 thorpej /*
560 1.1 thorpej * acpi_fixed_sleep_button_handler:
561 1.1 thorpej *
562 1.1 thorpej * Fixed event handler for the sleep button.
563 1.1 thorpej */
564 1.1 thorpej UINT32
565 1.1 thorpej acpi_fixed_sleep_button_handler(void *context)
566 1.1 thorpej {
567 1.1 thorpej struct acpi_softc *sc = context;
568 1.1 thorpej
569 1.1 thorpej /* XXX XXX XXX */
570 1.1 thorpej
571 1.1 thorpej printf("%s: fixed sleep button pressed\n", sc->sc_dev.dv_xname);
572 1.1 thorpej
573 1.1 thorpej return (INTERRUPT_HANDLED);
574 1.1 thorpej }
575 1.1 thorpej
576 1.1 thorpej /*****************************************************************************
577 1.1 thorpej * ACPI system notification handlers
578 1.1 thorpej *****************************************************************************/
579 1.1 thorpej
580 1.1 thorpej void
581 1.1 thorpej acpi_system_notify_handler(ACPI_HANDLE handle, UINT32 notify, void *context)
582 1.1 thorpej {
583 1.1 thorpej struct acpi_softc *sc = context;
584 1.1 thorpej
585 1.1 thorpej /* XXX XXX XXX */
586 1.1 thorpej
587 1.1 thorpej printf("%s: received system notify message 0x%x for handle %p\n",
588 1.1 thorpej sc->sc_dev.dv_xname, notify, handle);
589 1.1 thorpej }
590 1.1 thorpej
591 1.1 thorpej /*****************************************************************************
592 1.1 thorpej * ACPI utility routines.
593 1.1 thorpej *****************************************************************************/
594 1.1 thorpej
595 1.2 thorpej /*
596 1.2 thorpej * acpi_eval_integer:
597 1.2 thorpej *
598 1.2 thorpej * Evaluate an integer object.
599 1.2 thorpej */
600 1.1 thorpej ACPI_STATUS
601 1.1 thorpej acpi_eval_integer(ACPI_HANDLE handle, char *path, int *valp)
602 1.1 thorpej {
603 1.1 thorpej ACPI_STATUS rv;
604 1.1 thorpej ACPI_BUFFER buf;
605 1.1 thorpej ACPI_OBJECT param;
606 1.1 thorpej
607 1.1 thorpej if (handle == NULL)
608 1.1 thorpej handle = ACPI_ROOT_OBJECT;
609 1.1 thorpej
610 1.1 thorpej buf.Pointer = ¶m;
611 1.1 thorpej buf.Length = sizeof(param);
612 1.1 thorpej
613 1.1 thorpej rv = AcpiEvaluateObject(handle, path, NULL, &buf);
614 1.1 thorpej if (rv == AE_OK) {
615 1.1 thorpej if (param.Type == ACPI_TYPE_INTEGER)
616 1.1 thorpej *valp = param.Integer.Value;
617 1.1 thorpej else
618 1.1 thorpej rv = AE_TYPE;
619 1.1 thorpej }
620 1.1 thorpej
621 1.1 thorpej return (rv);
622 1.2 thorpej }
623 1.2 thorpej
624 1.2 thorpej /*
625 1.2 thorpej * acpi_get:
626 1.2 thorpej *
627 1.2 thorpej * Fetch data info the specified (empty) ACPI buffer.
628 1.2 thorpej */
629 1.2 thorpej ACPI_STATUS
630 1.2 thorpej acpi_get(ACPI_HANDLE handle, ACPI_BUFFER *buf,
631 1.2 thorpej ACPI_STATUS (*getit)(ACPI_HANDLE, ACPI_BUFFER *))
632 1.2 thorpej {
633 1.2 thorpej ACPI_STATUS rv;
634 1.2 thorpej
635 1.2 thorpej buf->Pointer = NULL;
636 1.2 thorpej buf->Length = 0;
637 1.2 thorpej
638 1.2 thorpej rv = (*getit)(handle, buf);
639 1.2 thorpej if (rv != AE_BUFFER_OVERFLOW)
640 1.2 thorpej return (rv);
641 1.2 thorpej
642 1.2 thorpej buf->Pointer = AcpiOsCallocate(buf->Length);
643 1.2 thorpej if (buf->Pointer == NULL)
644 1.2 thorpej return (AE_NO_MEMORY);
645 1.2 thorpej
646 1.2 thorpej return ((*getit)(handle, buf));
647 1.1 thorpej }
648