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