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