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