acpi_util.c revision 1.23 1 1.23 thorpej /* $NetBSD: acpi_util.c,v 1.23 2021/01/27 05:11:54 thorpej Exp $ */
2 1.1 jruoho
3 1.1 jruoho /*-
4 1.20 thorpej * Copyright (c) 2003, 2007, 2021 The NetBSD Foundation, Inc.
5 1.1 jruoho * All rights reserved.
6 1.1 jruoho *
7 1.1 jruoho * This code is derived from software contributed to The NetBSD Foundation
8 1.1 jruoho * by Charles M. Hannum of By Noon Software, Inc.
9 1.1 jruoho *
10 1.1 jruoho * Redistribution and use in source and binary forms, with or without
11 1.1 jruoho * modification, are permitted provided that the following conditions
12 1.1 jruoho * are met:
13 1.1 jruoho * 1. Redistributions of source code must retain the above copyright
14 1.1 jruoho * notice, this list of conditions and the following disclaimer.
15 1.1 jruoho * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 jruoho * notice, this list of conditions and the following disclaimer in the
17 1.1 jruoho * documentation and/or other materials provided with the distribution.
18 1.1 jruoho *
19 1.1 jruoho * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 jruoho * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 jruoho * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 jruoho * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 jruoho * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 jruoho * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 jruoho * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 jruoho * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 jruoho * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 jruoho * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 jruoho * POSSIBILITY OF SUCH DAMAGE.
30 1.1 jruoho */
31 1.1 jruoho
32 1.1 jruoho /*
33 1.1 jruoho * Copyright 2001, 2003 Wasabi Systems, Inc.
34 1.1 jruoho * All rights reserved.
35 1.1 jruoho *
36 1.1 jruoho * Written by Jason R. Thorpe for Wasabi Systems, Inc.
37 1.1 jruoho *
38 1.1 jruoho * Redistribution and use in source and binary forms, with or without
39 1.1 jruoho * modification, are permitted provided that the following conditions
40 1.1 jruoho * are met:
41 1.1 jruoho * 1. Redistributions of source code must retain the above copyright
42 1.1 jruoho * notice, this list of conditions and the following disclaimer.
43 1.1 jruoho * 2. Redistributions in binary form must reproduce the above copyright
44 1.1 jruoho * notice, this list of conditions and the following disclaimer in the
45 1.1 jruoho * documentation and/or other materials provided with the distribution.
46 1.1 jruoho * 3. All advertising materials mentioning features or use of this software
47 1.1 jruoho * must display the following acknowledgement:
48 1.1 jruoho * This product includes software developed for the NetBSD Project by
49 1.1 jruoho * Wasabi Systems, Inc.
50 1.1 jruoho * 4. The name of Wasabi Systems, Inc. may not be used to endorse
51 1.1 jruoho * or promote products derived from this software without specific prior
52 1.1 jruoho * written permission.
53 1.1 jruoho *
54 1.1 jruoho * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
55 1.1 jruoho * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
56 1.1 jruoho * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
57 1.1 jruoho * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
58 1.1 jruoho * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
59 1.1 jruoho * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
60 1.1 jruoho * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
61 1.1 jruoho * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
62 1.1 jruoho * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
63 1.1 jruoho * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
64 1.1 jruoho * POSSIBILITY OF SUCH DAMAGE.
65 1.1 jruoho */
66 1.1 jruoho
67 1.1 jruoho #include <sys/cdefs.h>
68 1.23 thorpej __KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.23 2021/01/27 05:11:54 thorpej Exp $");
69 1.1 jruoho
70 1.1 jruoho #include <sys/param.h>
71 1.9 bouyer #include <sys/kmem.h>
72 1.12 jmcneill #include <sys/cpu.h>
73 1.1 jruoho
74 1.1 jruoho #include <dev/acpi/acpireg.h>
75 1.1 jruoho #include <dev/acpi/acpivar.h>
76 1.9 bouyer #include <dev/acpi/acpi_intr.h>
77 1.1 jruoho
78 1.14 jmcneill #include <machine/acpi_machdep.h>
79 1.14 jmcneill
80 1.7 jruoho #define _COMPONENT ACPI_BUS_COMPONENT
81 1.7 jruoho ACPI_MODULE_NAME ("acpi_util")
82 1.1 jruoho
83 1.7 jruoho static void acpi_clean_node(ACPI_HANDLE, void *);
84 1.7 jruoho
85 1.7 jruoho static const char * const acpicpu_ids[] = {
86 1.7 jruoho "ACPI0007",
87 1.7 jruoho NULL
88 1.7 jruoho };
89 1.5 jruoho
90 1.1 jruoho /*
91 1.2 jruoho * Evaluate an integer object.
92 1.1 jruoho */
93 1.1 jruoho ACPI_STATUS
94 1.1 jruoho acpi_eval_integer(ACPI_HANDLE handle, const char *path, ACPI_INTEGER *valp)
95 1.1 jruoho {
96 1.1 jruoho ACPI_OBJECT obj;
97 1.1 jruoho ACPI_BUFFER buf;
98 1.1 jruoho ACPI_STATUS rv;
99 1.1 jruoho
100 1.1 jruoho if (handle == NULL)
101 1.1 jruoho handle = ACPI_ROOT_OBJECT;
102 1.1 jruoho
103 1.6 gsutre (void)memset(&obj, 0, sizeof(obj));
104 1.1 jruoho buf.Pointer = &obj;
105 1.1 jruoho buf.Length = sizeof(obj);
106 1.1 jruoho
107 1.1 jruoho rv = AcpiEvaluateObject(handle, path, NULL, &buf);
108 1.1 jruoho
109 1.1 jruoho if (ACPI_FAILURE(rv))
110 1.1 jruoho return rv;
111 1.1 jruoho
112 1.6 gsutre /* Check that evaluation produced a return value. */
113 1.6 gsutre if (buf.Length == 0)
114 1.6 gsutre return AE_NULL_OBJECT;
115 1.6 gsutre
116 1.1 jruoho if (obj.Type != ACPI_TYPE_INTEGER)
117 1.1 jruoho return AE_TYPE;
118 1.1 jruoho
119 1.1 jruoho if (valp != NULL)
120 1.1 jruoho *valp = obj.Integer.Value;
121 1.1 jruoho
122 1.1 jruoho return AE_OK;
123 1.1 jruoho }
124 1.1 jruoho
125 1.1 jruoho /*
126 1.2 jruoho * Evaluate an integer object with a single integer input parameter.
127 1.1 jruoho */
128 1.1 jruoho ACPI_STATUS
129 1.1 jruoho acpi_eval_set_integer(ACPI_HANDLE handle, const char *path, ACPI_INTEGER val)
130 1.1 jruoho {
131 1.1 jruoho ACPI_OBJECT_LIST arg;
132 1.1 jruoho ACPI_OBJECT obj;
133 1.1 jruoho
134 1.1 jruoho if (handle == NULL)
135 1.1 jruoho handle = ACPI_ROOT_OBJECT;
136 1.1 jruoho
137 1.1 jruoho obj.Type = ACPI_TYPE_INTEGER;
138 1.1 jruoho obj.Integer.Value = val;
139 1.1 jruoho
140 1.1 jruoho arg.Count = 1;
141 1.1 jruoho arg.Pointer = &obj;
142 1.1 jruoho
143 1.1 jruoho return AcpiEvaluateObject(handle, path, &arg, NULL);
144 1.1 jruoho }
145 1.1 jruoho
146 1.1 jruoho /*
147 1.2 jruoho * Evaluate a (Unicode) string object.
148 1.1 jruoho */
149 1.1 jruoho ACPI_STATUS
150 1.1 jruoho acpi_eval_string(ACPI_HANDLE handle, const char *path, char **stringp)
151 1.1 jruoho {
152 1.1 jruoho ACPI_OBJECT *obj;
153 1.1 jruoho ACPI_BUFFER buf;
154 1.1 jruoho ACPI_STATUS rv;
155 1.1 jruoho
156 1.1 jruoho rv = acpi_eval_struct(handle, path, &buf);
157 1.1 jruoho
158 1.1 jruoho if (ACPI_FAILURE(rv))
159 1.1 jruoho return rv;
160 1.1 jruoho
161 1.1 jruoho obj = buf.Pointer;
162 1.1 jruoho
163 1.1 jruoho if (obj->Type != ACPI_TYPE_STRING) {
164 1.1 jruoho rv = AE_TYPE;
165 1.1 jruoho goto out;
166 1.1 jruoho }
167 1.1 jruoho
168 1.1 jruoho if (obj->String.Length == 0) {
169 1.1 jruoho rv = AE_BAD_DATA;
170 1.1 jruoho goto out;
171 1.1 jruoho }
172 1.1 jruoho
173 1.1 jruoho *stringp = ACPI_ALLOCATE(obj->String.Length + 1);
174 1.1 jruoho
175 1.1 jruoho if (*stringp == NULL) {
176 1.1 jruoho rv = AE_NO_MEMORY;
177 1.1 jruoho goto out;
178 1.1 jruoho }
179 1.1 jruoho
180 1.1 jruoho (void)memcpy(*stringp, obj->String.Pointer, obj->String.Length);
181 1.1 jruoho
182 1.1 jruoho (*stringp)[obj->String.Length] = '\0';
183 1.1 jruoho
184 1.1 jruoho out:
185 1.1 jruoho ACPI_FREE(buf.Pointer);
186 1.1 jruoho
187 1.1 jruoho return rv;
188 1.1 jruoho }
189 1.1 jruoho
190 1.1 jruoho /*
191 1.2 jruoho * Evaluate a structure. Caller must free buf.Pointer by ACPI_FREE().
192 1.1 jruoho */
193 1.1 jruoho ACPI_STATUS
194 1.1 jruoho acpi_eval_struct(ACPI_HANDLE handle, const char *path, ACPI_BUFFER *buf)
195 1.1 jruoho {
196 1.1 jruoho
197 1.1 jruoho if (handle == NULL)
198 1.1 jruoho handle = ACPI_ROOT_OBJECT;
199 1.1 jruoho
200 1.1 jruoho buf->Pointer = NULL;
201 1.1 jruoho buf->Length = ACPI_ALLOCATE_LOCAL_BUFFER;
202 1.1 jruoho
203 1.1 jruoho return AcpiEvaluateObject(handle, path, NULL, buf);
204 1.1 jruoho }
205 1.1 jruoho
206 1.1 jruoho /*
207 1.2 jruoho * Evaluate a reference handle from an element in a package.
208 1.1 jruoho */
209 1.1 jruoho ACPI_STATUS
210 1.1 jruoho acpi_eval_reference_handle(ACPI_OBJECT *elm, ACPI_HANDLE *handle)
211 1.1 jruoho {
212 1.1 jruoho
213 1.1 jruoho if (elm == NULL || handle == NULL)
214 1.1 jruoho return AE_BAD_PARAMETER;
215 1.1 jruoho
216 1.1 jruoho switch (elm->Type) {
217 1.1 jruoho
218 1.1 jruoho case ACPI_TYPE_ANY:
219 1.1 jruoho case ACPI_TYPE_LOCAL_REFERENCE:
220 1.1 jruoho
221 1.1 jruoho if (elm->Reference.Handle == NULL)
222 1.1 jruoho return AE_NULL_ENTRY;
223 1.1 jruoho
224 1.1 jruoho *handle = elm->Reference.Handle;
225 1.1 jruoho
226 1.1 jruoho return AE_OK;
227 1.1 jruoho
228 1.1 jruoho case ACPI_TYPE_STRING:
229 1.1 jruoho return AcpiGetHandle(NULL, elm->String.Pointer, handle);
230 1.1 jruoho
231 1.1 jruoho default:
232 1.1 jruoho return AE_TYPE;
233 1.1 jruoho }
234 1.1 jruoho }
235 1.1 jruoho
236 1.1 jruoho /*
237 1.2 jruoho * Iterate over all objects in a package, and pass them all
238 1.2 jruoho * to a function. If the called function returns non-AE_OK,
239 1.2 jruoho * the iteration is stopped and that value is returned.
240 1.1 jruoho */
241 1.1 jruoho ACPI_STATUS
242 1.1 jruoho acpi_foreach_package_object(ACPI_OBJECT *pkg,
243 1.1 jruoho ACPI_STATUS (*func)(ACPI_OBJECT *, void *), void *arg)
244 1.1 jruoho {
245 1.1 jruoho ACPI_STATUS rv = AE_OK;
246 1.1 jruoho uint32_t i;
247 1.1 jruoho
248 1.4 jruoho if (pkg == NULL)
249 1.1 jruoho return AE_BAD_PARAMETER;
250 1.1 jruoho
251 1.4 jruoho if (pkg->Type != ACPI_TYPE_PACKAGE)
252 1.4 jruoho return AE_TYPE;
253 1.4 jruoho
254 1.1 jruoho for (i = 0; i < pkg->Package.Count; i++) {
255 1.1 jruoho
256 1.1 jruoho rv = (*func)(&pkg->Package.Elements[i], arg);
257 1.1 jruoho
258 1.1 jruoho if (ACPI_FAILURE(rv))
259 1.1 jruoho break;
260 1.1 jruoho }
261 1.1 jruoho
262 1.1 jruoho return rv;
263 1.1 jruoho }
264 1.1 jruoho
265 1.1 jruoho /*
266 1.2 jruoho * Fetch data info the specified (empty) ACPI buffer.
267 1.2 jruoho * Caller must free buf.Pointer by ACPI_FREE().
268 1.1 jruoho */
269 1.1 jruoho ACPI_STATUS
270 1.1 jruoho acpi_get(ACPI_HANDLE handle, ACPI_BUFFER *buf,
271 1.1 jruoho ACPI_STATUS (*getit)(ACPI_HANDLE, ACPI_BUFFER *))
272 1.1 jruoho {
273 1.1 jruoho
274 1.1 jruoho buf->Pointer = NULL;
275 1.1 jruoho buf->Length = ACPI_ALLOCATE_LOCAL_BUFFER;
276 1.1 jruoho
277 1.1 jruoho return (*getit)(handle, buf);
278 1.1 jruoho }
279 1.1 jruoho
280 1.1 jruoho /*
281 1.2 jruoho * Return a complete pathname from a handle.
282 1.1 jruoho *
283 1.2 jruoho * Note that the function uses static data storage;
284 1.2 jruoho * if the data is needed for future use, it should be
285 1.2 jruoho * copied before any subsequent calls overwrite it.
286 1.1 jruoho */
287 1.1 jruoho const char *
288 1.1 jruoho acpi_name(ACPI_HANDLE handle)
289 1.1 jruoho {
290 1.1 jruoho static char name[80];
291 1.1 jruoho ACPI_BUFFER buf;
292 1.1 jruoho ACPI_STATUS rv;
293 1.1 jruoho
294 1.4 jruoho if (handle == NULL)
295 1.4 jruoho handle = ACPI_ROOT_OBJECT;
296 1.4 jruoho
297 1.1 jruoho buf.Pointer = name;
298 1.1 jruoho buf.Length = sizeof(name);
299 1.1 jruoho
300 1.1 jruoho rv = AcpiGetName(handle, ACPI_FULL_PATHNAME, &buf);
301 1.1 jruoho
302 1.1 jruoho if (ACPI_FAILURE(rv))
303 1.1 jruoho return "UNKNOWN";
304 1.1 jruoho
305 1.1 jruoho return name;
306 1.1 jruoho }
307 1.1 jruoho
308 1.1 jruoho /*
309 1.23 thorpej * Pack _HID and _CID ID strings into an OpenFirmware-style
310 1.20 thorpej * string list.
311 1.20 thorpej */
312 1.20 thorpej char *
313 1.20 thorpej acpi_pack_compat_list(ACPI_DEVICE_INFO *ad, size_t *sizep)
314 1.20 thorpej {
315 1.20 thorpej KASSERT(sizep != NULL);
316 1.20 thorpej
317 1.23 thorpej char *sl = NULL;
318 1.23 thorpej size_t slsize = 0;
319 1.20 thorpej uint32_t i;
320 1.20 thorpej
321 1.20 thorpej if ((ad->Valid & ACPI_VALID_HID) != 0) {
322 1.23 thorpej strlist_append(&sl, &slsize, ad->HardwareId.String);
323 1.20 thorpej }
324 1.20 thorpej
325 1.20 thorpej if ((ad->Valid & ACPI_VALID_CID) != 0) {
326 1.20 thorpej for (i = 0; i < ad->CompatibleIdList.Count; i++) {
327 1.23 thorpej strlist_append(&sl, &slsize,
328 1.23 thorpej ad->CompatibleIdList.Ids[i].String);
329 1.20 thorpej }
330 1.20 thorpej }
331 1.20 thorpej
332 1.23 thorpej *sizep = slsize;
333 1.23 thorpej return sl;
334 1.23 thorpej }
335 1.23 thorpej
336 1.23 thorpej /*
337 1.23 thorpej * The ACPI_PNP_DEVICE_ID type is somewhat inconvenient for us to
338 1.23 thorpej * use. We'll need some temporary space to pack it into an array
339 1.23 thorpej * of C strings. Room for 8 should be plenty, but we can allocate
340 1.23 thorpej * more if necessary.
341 1.23 thorpej */
342 1.23 thorpej #define ACPI_COMPATSTR_MAX 8
343 1.23 thorpej
344 1.23 thorpej static const char **
345 1.23 thorpej acpi_compatible_alloc_strarray(ACPI_PNP_DEVICE_ID *ids,
346 1.23 thorpej unsigned int count, const char **buf)
347 1.23 thorpej {
348 1.23 thorpej unsigned int i;
349 1.23 thorpej
350 1.23 thorpej buf = kmem_tmpbuf_alloc(count * sizeof(const char *),
351 1.23 thorpej buf, ACPI_COMPATSTR_MAX * sizeof(const char *), KM_SLEEP);
352 1.23 thorpej for (i = 0; i < count; i++) {
353 1.23 thorpej buf[i] = ids[i].String;
354 1.23 thorpej }
355 1.23 thorpej return buf;
356 1.23 thorpej }
357 1.23 thorpej
358 1.23 thorpej static void
359 1.23 thorpej acpi_compatible_free_strarray(const char **cpp, unsigned int count,
360 1.23 thorpej const char **buf)
361 1.23 thorpej {
362 1.23 thorpej kmem_tmpbuf_free(cpp, count * sizeof(const char *), buf);
363 1.23 thorpej }
364 1.23 thorpej
365 1.23 thorpej /*
366 1.23 thorpej * acpi_compatible_match --
367 1.23 thorpej *
368 1.23 thorpej * Returns a weighted match value, comparing the _HID and _CID
369 1.23 thorpej * IDs against a driver's compatbility data.
370 1.23 thorpej */
371 1.23 thorpej int
372 1.23 thorpej acpi_compatible_match(const struct acpi_attach_args * const aa,
373 1.23 thorpej const struct device_compatible_entry * const dce)
374 1.23 thorpej {
375 1.23 thorpej const char *strings[ACPI_COMPATSTR_MAX * sizeof(const char *)];
376 1.23 thorpej const char **cpp;
377 1.23 thorpej
378 1.23 thorpej if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE) {
379 1.23 thorpej return 0;
380 1.20 thorpej }
381 1.20 thorpej
382 1.23 thorpej ACPI_DEVICE_INFO *ad = aa->aa_node->ad_devinfo;
383 1.20 thorpej
384 1.20 thorpej if ((ad->Valid & ACPI_VALID_HID) != 0) {
385 1.23 thorpej strings[0] = ad->HardwareId.String;
386 1.23 thorpej
387 1.23 thorpej /* Matching _HID wins big. */
388 1.23 thorpej if (device_compatible_pmatch(strings, 1, dce) != 0) {
389 1.23 thorpej return ACPI_MATCHSCORE_HID;
390 1.23 thorpej }
391 1.20 thorpej }
392 1.20 thorpej
393 1.20 thorpej if ((ad->Valid & ACPI_VALID_CID) != 0) {
394 1.23 thorpej cpp = acpi_compatible_alloc_strarray(ad->CompatibleIdList.Ids,
395 1.23 thorpej ad->CompatibleIdList.Count, strings);
396 1.23 thorpej int rv;
397 1.23 thorpej
398 1.23 thorpej rv = device_compatible_pmatch(cpp,
399 1.23 thorpej ad->CompatibleIdList.Count, dce);
400 1.23 thorpej acpi_compatible_free_strarray(cpp, ad->CompatibleIdList.Count,
401 1.23 thorpej strings);
402 1.23 thorpej if (rv) {
403 1.23 thorpej rv = (rv - 1) + ACPI_MATCHSCORE_CID;
404 1.23 thorpej if (rv > ACPI_MATCHSCORE_CID_MAX) {
405 1.23 thorpej rv = ACPI_MATCHSCORE_CID_MAX;
406 1.23 thorpej }
407 1.23 thorpej return rv;
408 1.20 thorpej }
409 1.20 thorpej }
410 1.20 thorpej
411 1.23 thorpej return 0;
412 1.23 thorpej }
413 1.23 thorpej
414 1.23 thorpej /*
415 1.23 thorpej * acpi_compatible_lookup --
416 1.23 thorpej *
417 1.23 thorpej * Returns the device_compatible_entry that matches the _HID
418 1.23 thorpej * or _CID ID.
419 1.23 thorpej */
420 1.23 thorpej const struct device_compatible_entry *
421 1.23 thorpej acpi_compatible_lookup(const struct acpi_attach_args * const aa,
422 1.23 thorpej const struct device_compatible_entry * const dce)
423 1.23 thorpej {
424 1.23 thorpej const struct device_compatible_entry *rv = NULL;
425 1.23 thorpej const char *strings[ACPI_COMPATSTR_MAX];
426 1.23 thorpej const char **cpp;
427 1.23 thorpej
428 1.23 thorpej if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE) {
429 1.23 thorpej return NULL;
430 1.23 thorpej }
431 1.20 thorpej
432 1.23 thorpej ACPI_DEVICE_INFO *ad = aa->aa_node->ad_devinfo;
433 1.23 thorpej
434 1.23 thorpej if ((ad->Valid & ACPI_VALID_HID) != 0) {
435 1.23 thorpej strings[0] = ad->HardwareId.String;
436 1.23 thorpej
437 1.23 thorpej rv = device_compatible_plookup(strings, 1, dce);
438 1.23 thorpej if (rv != NULL)
439 1.23 thorpej return rv;
440 1.23 thorpej }
441 1.23 thorpej
442 1.23 thorpej if ((ad->Valid & ACPI_VALID_CID) != 0) {
443 1.23 thorpej cpp = acpi_compatible_alloc_strarray(ad->CompatibleIdList.Ids,
444 1.23 thorpej ad->CompatibleIdList.Count, strings);
445 1.23 thorpej
446 1.23 thorpej rv = device_compatible_plookup(cpp,
447 1.23 thorpej ad->CompatibleIdList.Count, dce);
448 1.23 thorpej acpi_compatible_free_strarray(cpp, ad->CompatibleIdList.Count,
449 1.23 thorpej strings);
450 1.23 thorpej }
451 1.23 thorpej
452 1.23 thorpej return rv;
453 1.20 thorpej }
454 1.20 thorpej
455 1.20 thorpej /*
456 1.2 jruoho * Match given IDs against _HID and _CIDs.
457 1.1 jruoho */
458 1.1 jruoho int
459 1.1 jruoho acpi_match_hid(ACPI_DEVICE_INFO *ad, const char * const *ids)
460 1.1 jruoho {
461 1.1 jruoho uint32_t i, n;
462 1.1 jruoho char *id;
463 1.1 jruoho
464 1.1 jruoho while (*ids) {
465 1.1 jruoho
466 1.1 jruoho if ((ad->Valid & ACPI_VALID_HID) != 0) {
467 1.1 jruoho
468 1.1 jruoho if (pmatch(ad->HardwareId.String, *ids, NULL) == 2)
469 1.1 jruoho return 1;
470 1.1 jruoho }
471 1.1 jruoho
472 1.1 jruoho if ((ad->Valid & ACPI_VALID_CID) != 0) {
473 1.1 jruoho
474 1.1 jruoho n = ad->CompatibleIdList.Count;
475 1.1 jruoho
476 1.1 jruoho for (i = 0; i < n; i++) {
477 1.1 jruoho
478 1.1 jruoho id = ad->CompatibleIdList.Ids[i].String;
479 1.1 jruoho
480 1.1 jruoho if (pmatch(id, *ids, NULL) == 2)
481 1.1 jruoho return 1;
482 1.1 jruoho }
483 1.1 jruoho }
484 1.1 jruoho
485 1.1 jruoho ids++;
486 1.1 jruoho }
487 1.1 jruoho
488 1.1 jruoho return 0;
489 1.1 jruoho }
490 1.1 jruoho
491 1.7 jruoho /*
492 1.13 jmcneill * Match a PCI-defined bass-class, sub-class, and programming interface
493 1.13 jmcneill * against a handle's _CLS object.
494 1.13 jmcneill */
495 1.13 jmcneill int
496 1.13 jmcneill acpi_match_class(ACPI_HANDLE handle, uint8_t pci_class, uint8_t pci_subclass,
497 1.13 jmcneill uint8_t pci_interface)
498 1.13 jmcneill {
499 1.13 jmcneill ACPI_BUFFER buf;
500 1.13 jmcneill ACPI_OBJECT *obj;
501 1.13 jmcneill ACPI_STATUS rv;
502 1.13 jmcneill int match = 0;
503 1.13 jmcneill
504 1.13 jmcneill rv = acpi_eval_struct(handle, "_CLS", &buf);
505 1.13 jmcneill if (ACPI_FAILURE(rv))
506 1.13 jmcneill goto done;
507 1.13 jmcneill
508 1.13 jmcneill obj = buf.Pointer;
509 1.13 jmcneill if (obj->Type != ACPI_TYPE_PACKAGE)
510 1.13 jmcneill goto done;
511 1.13 jmcneill if (obj->Package.Count != 3)
512 1.13 jmcneill goto done;
513 1.13 jmcneill if (obj->Package.Elements[0].Type != ACPI_TYPE_INTEGER ||
514 1.13 jmcneill obj->Package.Elements[1].Type != ACPI_TYPE_INTEGER ||
515 1.13 jmcneill obj->Package.Elements[2].Type != ACPI_TYPE_INTEGER)
516 1.13 jmcneill goto done;
517 1.13 jmcneill
518 1.13 jmcneill match = obj->Package.Elements[0].Integer.Value == pci_class &&
519 1.13 jmcneill obj->Package.Elements[1].Integer.Value == pci_subclass &&
520 1.13 jmcneill obj->Package.Elements[2].Integer.Value == pci_interface;
521 1.13 jmcneill
522 1.13 jmcneill done:
523 1.13 jmcneill if (buf.Pointer)
524 1.13 jmcneill ACPI_FREE(buf.Pointer);
525 1.23 thorpej return match ? ACPI_MATCHSCORE_CLS : 0;
526 1.13 jmcneill }
527 1.13 jmcneill
528 1.13 jmcneill /*
529 1.8 jruoho * Match a device node from a handle.
530 1.8 jruoho */
531 1.8 jruoho struct acpi_devnode *
532 1.8 jruoho acpi_match_node(ACPI_HANDLE handle)
533 1.8 jruoho {
534 1.8 jruoho struct acpi_devnode *ad;
535 1.8 jruoho ACPI_STATUS rv;
536 1.8 jruoho
537 1.8 jruoho if (handle == NULL)
538 1.8 jruoho return NULL;
539 1.8 jruoho
540 1.8 jruoho rv = AcpiGetData(handle, acpi_clean_node, (void **)&ad);
541 1.8 jruoho
542 1.8 jruoho if (ACPI_FAILURE(rv))
543 1.8 jruoho return NULL;
544 1.8 jruoho
545 1.8 jruoho return ad;
546 1.8 jruoho }
547 1.8 jruoho
548 1.8 jruoho /*
549 1.8 jruoho * Permanently associate a device node with a handle.
550 1.8 jruoho */
551 1.8 jruoho void
552 1.8 jruoho acpi_match_node_init(struct acpi_devnode *ad)
553 1.8 jruoho {
554 1.8 jruoho (void)AcpiAttachData(ad->ad_handle, acpi_clean_node, ad);
555 1.8 jruoho }
556 1.8 jruoho
557 1.8 jruoho static void
558 1.8 jruoho acpi_clean_node(ACPI_HANDLE handle, void *aux)
559 1.8 jruoho {
560 1.8 jruoho /* Nothing. */
561 1.8 jruoho }
562 1.8 jruoho
563 1.8 jruoho /*
564 1.7 jruoho * Match a handle from a cpu_info. Returns NULL on failure.
565 1.7 jruoho *
566 1.8 jruoho * Note that acpi_match_node() can be used if the device node
567 1.8 jruoho * is also required.
568 1.7 jruoho */
569 1.7 jruoho ACPI_HANDLE
570 1.7 jruoho acpi_match_cpu_info(struct cpu_info *ci)
571 1.7 jruoho {
572 1.7 jruoho struct acpi_softc *sc = acpi_softc;
573 1.7 jruoho struct acpi_devnode *ad;
574 1.7 jruoho ACPI_INTEGER val;
575 1.7 jruoho ACPI_OBJECT *obj;
576 1.7 jruoho ACPI_BUFFER buf;
577 1.7 jruoho ACPI_HANDLE hdl;
578 1.7 jruoho ACPI_STATUS rv;
579 1.7 jruoho
580 1.7 jruoho if (sc == NULL || acpi_active == 0)
581 1.7 jruoho return NULL;
582 1.7 jruoho
583 1.7 jruoho /*
584 1.7 jruoho * CPUs are declared in the ACPI namespace
585 1.7 jruoho * either as a Processor() or as a Device().
586 1.7 jruoho * In both cases the MADT entries are used
587 1.7 jruoho * for the match (see ACPI 4.0, section 8.4).
588 1.7 jruoho */
589 1.7 jruoho SIMPLEQ_FOREACH(ad, &sc->ad_head, ad_list) {
590 1.7 jruoho
591 1.7 jruoho hdl = ad->ad_handle;
592 1.7 jruoho
593 1.7 jruoho switch (ad->ad_type) {
594 1.7 jruoho
595 1.7 jruoho case ACPI_TYPE_DEVICE:
596 1.7 jruoho
597 1.7 jruoho if (acpi_match_hid(ad->ad_devinfo, acpicpu_ids) == 0)
598 1.7 jruoho break;
599 1.7 jruoho
600 1.7 jruoho rv = acpi_eval_integer(hdl, "_UID", &val);
601 1.7 jruoho
602 1.7 jruoho if (ACPI_SUCCESS(rv) && val == ci->ci_acpiid)
603 1.7 jruoho return hdl;
604 1.7 jruoho
605 1.7 jruoho break;
606 1.7 jruoho
607 1.7 jruoho case ACPI_TYPE_PROCESSOR:
608 1.7 jruoho
609 1.7 jruoho rv = acpi_eval_struct(hdl, NULL, &buf);
610 1.7 jruoho
611 1.7 jruoho if (ACPI_FAILURE(rv))
612 1.7 jruoho break;
613 1.7 jruoho
614 1.7 jruoho obj = buf.Pointer;
615 1.7 jruoho
616 1.7 jruoho if (obj->Processor.ProcId == ci->ci_acpiid) {
617 1.7 jruoho ACPI_FREE(buf.Pointer);
618 1.7 jruoho return hdl;
619 1.7 jruoho }
620 1.7 jruoho
621 1.7 jruoho ACPI_FREE(buf.Pointer);
622 1.7 jruoho break;
623 1.7 jruoho }
624 1.7 jruoho }
625 1.7 jruoho
626 1.7 jruoho return NULL;
627 1.7 jruoho }
628 1.7 jruoho
629 1.7 jruoho /*
630 1.7 jruoho * Match a CPU from a handle. Returns NULL on failure.
631 1.7 jruoho */
632 1.7 jruoho struct cpu_info *
633 1.7 jruoho acpi_match_cpu_handle(ACPI_HANDLE hdl)
634 1.7 jruoho {
635 1.7 jruoho struct cpu_info *ci;
636 1.7 jruoho ACPI_DEVICE_INFO *di;
637 1.7 jruoho CPU_INFO_ITERATOR cii;
638 1.7 jruoho ACPI_INTEGER val;
639 1.7 jruoho ACPI_OBJECT *obj;
640 1.7 jruoho ACPI_BUFFER buf;
641 1.7 jruoho ACPI_STATUS rv;
642 1.7 jruoho
643 1.7 jruoho ci = NULL;
644 1.7 jruoho di = NULL;
645 1.7 jruoho buf.Pointer = NULL;
646 1.7 jruoho
647 1.7 jruoho rv = AcpiGetObjectInfo(hdl, &di);
648 1.7 jruoho
649 1.7 jruoho if (ACPI_FAILURE(rv))
650 1.7 jruoho return NULL;
651 1.7 jruoho
652 1.7 jruoho switch (di->Type) {
653 1.7 jruoho
654 1.7 jruoho case ACPI_TYPE_DEVICE:
655 1.7 jruoho
656 1.7 jruoho if (acpi_match_hid(di, acpicpu_ids) == 0)
657 1.7 jruoho goto out;
658 1.7 jruoho
659 1.7 jruoho rv = acpi_eval_integer(hdl, "_UID", &val);
660 1.7 jruoho
661 1.7 jruoho if (ACPI_FAILURE(rv))
662 1.7 jruoho goto out;
663 1.7 jruoho
664 1.7 jruoho break;
665 1.7 jruoho
666 1.7 jruoho case ACPI_TYPE_PROCESSOR:
667 1.7 jruoho
668 1.7 jruoho rv = acpi_eval_struct(hdl, NULL, &buf);
669 1.7 jruoho
670 1.7 jruoho if (ACPI_FAILURE(rv))
671 1.7 jruoho goto out;
672 1.7 jruoho
673 1.7 jruoho obj = buf.Pointer;
674 1.7 jruoho val = obj->Processor.ProcId;
675 1.7 jruoho break;
676 1.7 jruoho
677 1.7 jruoho default:
678 1.7 jruoho goto out;
679 1.7 jruoho }
680 1.7 jruoho
681 1.7 jruoho for (CPU_INFO_FOREACH(cii, ci)) {
682 1.7 jruoho
683 1.7 jruoho if (ci->ci_acpiid == val)
684 1.7 jruoho goto out;
685 1.7 jruoho }
686 1.7 jruoho
687 1.7 jruoho ci = NULL;
688 1.7 jruoho
689 1.7 jruoho out:
690 1.7 jruoho if (di != NULL)
691 1.7 jruoho ACPI_FREE(di);
692 1.7 jruoho
693 1.7 jruoho if (buf.Pointer != NULL)
694 1.7 jruoho ACPI_FREE(buf.Pointer);
695 1.7 jruoho
696 1.7 jruoho return ci;
697 1.7 jruoho }
698 1.9 bouyer
699 1.9 bouyer struct acpi_irq_handler {
700 1.9 bouyer uint32_t aih_irq;
701 1.14 jmcneill void *aih_ih;
702 1.9 bouyer };
703 1.9 bouyer
704 1.9 bouyer void *
705 1.14 jmcneill acpi_intr_establish(device_t dev, uint64_t c, int ipl, bool mpsafe,
706 1.14 jmcneill int (*intr)(void *), void *iarg, const char *xname)
707 1.9 bouyer {
708 1.9 bouyer ACPI_STATUS rv;
709 1.10 bouyer ACPI_HANDLE hdl = (void *)(uintptr_t)c;
710 1.9 bouyer struct acpi_resources res;
711 1.9 bouyer struct acpi_irq *irq;
712 1.19 jmcneill void *aih = NULL;
713 1.9 bouyer
714 1.9 bouyer rv = acpi_resource_parse(dev, hdl, "_CRS", &res,
715 1.9 bouyer &acpi_resource_parse_ops_quiet);
716 1.9 bouyer if (ACPI_FAILURE(rv))
717 1.9 bouyer return NULL;
718 1.9 bouyer
719 1.9 bouyer irq = acpi_res_irq(&res, 0);
720 1.9 bouyer if (irq == NULL)
721 1.9 bouyer goto end;
722 1.9 bouyer
723 1.19 jmcneill aih = acpi_intr_establish_irq(dev, irq, ipl, mpsafe,
724 1.19 jmcneill intr, iarg, xname);
725 1.19 jmcneill
726 1.19 jmcneill end:
727 1.19 jmcneill acpi_resource_cleanup(&res);
728 1.19 jmcneill
729 1.19 jmcneill return aih;
730 1.19 jmcneill }
731 1.19 jmcneill
732 1.19 jmcneill void *
733 1.19 jmcneill acpi_intr_establish_irq(device_t dev, struct acpi_irq *irq, int ipl,
734 1.19 jmcneill bool mpsafe, int (*intr)(void *), void *iarg, const char *xname)
735 1.19 jmcneill {
736 1.19 jmcneill struct acpi_irq_handler *aih;
737 1.19 jmcneill void *ih;
738 1.19 jmcneill
739 1.14 jmcneill const int type = (irq->ar_type == ACPI_EDGE_SENSITIVE) ? IST_EDGE : IST_LEVEL;
740 1.14 jmcneill ih = acpi_md_intr_establish(irq->ar_irq, ipl, type, intr, iarg, mpsafe, xname);
741 1.14 jmcneill if (ih == NULL)
742 1.19 jmcneill return NULL;
743 1.9 bouyer
744 1.14 jmcneill aih = kmem_alloc(sizeof(struct acpi_irq_handler), KM_SLEEP);
745 1.9 bouyer aih->aih_irq = irq->ar_irq;
746 1.14 jmcneill aih->aih_ih = ih;
747 1.14 jmcneill
748 1.9 bouyer return aih;
749 1.9 bouyer }
750 1.9 bouyer
751 1.9 bouyer void
752 1.16 thorpej acpi_intr_mask(void *c)
753 1.16 thorpej {
754 1.16 thorpej struct acpi_irq_handler * const aih = c;
755 1.16 thorpej
756 1.16 thorpej acpi_md_intr_mask(aih->aih_ih);
757 1.16 thorpej }
758 1.16 thorpej
759 1.16 thorpej void
760 1.16 thorpej acpi_intr_unmask(void *c)
761 1.16 thorpej {
762 1.16 thorpej struct acpi_irq_handler * const aih = c;
763 1.16 thorpej
764 1.16 thorpej acpi_md_intr_unmask(aih->aih_ih);
765 1.16 thorpej }
766 1.16 thorpej
767 1.16 thorpej void
768 1.14 jmcneill acpi_intr_disestablish(void *c)
769 1.9 bouyer {
770 1.9 bouyer struct acpi_irq_handler *aih = c;
771 1.9 bouyer
772 1.14 jmcneill acpi_md_intr_disestablish(aih->aih_ih);
773 1.9 bouyer kmem_free(aih, sizeof(struct acpi_irq_handler));
774 1.9 bouyer }
775 1.9 bouyer
776 1.9 bouyer const char *
777 1.9 bouyer acpi_intr_string(void *c, char *buf, size_t size)
778 1.9 bouyer {
779 1.9 bouyer struct acpi_irq_handler *aih = c;
780 1.9 bouyer intr_handle_t ih = aih->aih_irq;
781 1.9 bouyer
782 1.9 bouyer return intr_string(ih, buf, size);
783 1.9 bouyer }
784 1.15 jmcneill
785 1.15 jmcneill /*
786 1.20 thorpej * Device-Specific Data (_DSD) support
787 1.15 jmcneill */
788 1.15 jmcneill
789 1.15 jmcneill static UINT8 acpi_dsd_uuid[ACPI_UUID_LENGTH] = {
790 1.15 jmcneill 0x14, 0xd8, 0xff, 0xda, 0xba, 0x6e, 0x8c, 0x4d,
791 1.15 jmcneill 0x8a, 0x91, 0xbc, 0x9b, 0xbf, 0x4a, 0xa3, 0x01
792 1.15 jmcneill };
793 1.15 jmcneill
794 1.17 jmcneill static ACPI_STATUS
795 1.17 jmcneill acpi_dsd_property(ACPI_HANDLE handle, const char *prop, ACPI_BUFFER *pbuf, ACPI_OBJECT_TYPE type, ACPI_OBJECT **ret)
796 1.15 jmcneill {
797 1.15 jmcneill ACPI_OBJECT *obj, *uuid, *props, *pobj, *propkey, *propval;
798 1.15 jmcneill ACPI_STATUS rv;
799 1.15 jmcneill int n;
800 1.15 jmcneill
801 1.17 jmcneill rv = AcpiEvaluateObjectTyped(handle, "_DSD", NULL, pbuf, ACPI_TYPE_PACKAGE);
802 1.15 jmcneill if (ACPI_FAILURE(rv))
803 1.15 jmcneill return rv;
804 1.15 jmcneill
805 1.15 jmcneill props = NULL;
806 1.17 jmcneill obj = (ACPI_OBJECT *)pbuf->Pointer;
807 1.15 jmcneill for (n = 0; (n + 1) < obj->Package.Count; n += 2) {
808 1.15 jmcneill uuid = &obj->Package.Elements[n];
809 1.15 jmcneill if (uuid->Buffer.Length == ACPI_UUID_LENGTH &&
810 1.15 jmcneill memcmp(uuid->Buffer.Pointer, acpi_dsd_uuid, ACPI_UUID_LENGTH) == 0) {
811 1.15 jmcneill props = &obj->Package.Elements[n + 1];
812 1.15 jmcneill break;
813 1.15 jmcneill }
814 1.15 jmcneill }
815 1.17 jmcneill if (props == NULL)
816 1.17 jmcneill return AE_NOT_FOUND;
817 1.15 jmcneill
818 1.15 jmcneill for (n = 0; n < props->Package.Count; n++) {
819 1.15 jmcneill pobj = &props->Package.Elements[n];
820 1.15 jmcneill if (pobj->Type != ACPI_TYPE_PACKAGE || pobj->Package.Count != 2)
821 1.15 jmcneill continue;
822 1.15 jmcneill propkey = (ACPI_OBJECT *)&pobj->Package.Elements[0];
823 1.15 jmcneill propval = (ACPI_OBJECT *)&pobj->Package.Elements[1];
824 1.15 jmcneill if (propkey->Type != ACPI_TYPE_STRING)
825 1.15 jmcneill continue;
826 1.15 jmcneill if (strcmp(propkey->String.Pointer, prop) != 0)
827 1.15 jmcneill continue;
828 1.15 jmcneill
829 1.17 jmcneill if (propval->Type != type) {
830 1.17 jmcneill return AE_TYPE;
831 1.15 jmcneill } else {
832 1.17 jmcneill *ret = propval;
833 1.17 jmcneill return AE_OK;
834 1.15 jmcneill }
835 1.15 jmcneill break;
836 1.15 jmcneill }
837 1.15 jmcneill
838 1.17 jmcneill return AE_NOT_FOUND;
839 1.17 jmcneill }
840 1.17 jmcneill
841 1.17 jmcneill ACPI_STATUS
842 1.17 jmcneill acpi_dsd_integer(ACPI_HANDLE handle, const char *prop, ACPI_INTEGER *val)
843 1.17 jmcneill {
844 1.17 jmcneill ACPI_OBJECT *propval;
845 1.17 jmcneill ACPI_STATUS rv;
846 1.17 jmcneill ACPI_BUFFER buf;
847 1.17 jmcneill
848 1.17 jmcneill buf.Pointer = NULL;
849 1.17 jmcneill buf.Length = ACPI_ALLOCATE_BUFFER;
850 1.17 jmcneill
851 1.17 jmcneill rv = acpi_dsd_property(handle, prop, &buf, ACPI_TYPE_INTEGER, &propval);
852 1.17 jmcneill if (ACPI_SUCCESS(rv))
853 1.17 jmcneill *val = propval->Integer.Value;
854 1.17 jmcneill
855 1.18 mlelstv if (buf.Pointer != NULL)
856 1.18 mlelstv ACPI_FREE(buf.Pointer);
857 1.17 jmcneill return rv;
858 1.17 jmcneill }
859 1.17 jmcneill
860 1.17 jmcneill ACPI_STATUS
861 1.17 jmcneill acpi_dsd_string(ACPI_HANDLE handle, const char *prop, char **val)
862 1.17 jmcneill {
863 1.17 jmcneill ACPI_OBJECT *propval;
864 1.17 jmcneill ACPI_STATUS rv;
865 1.17 jmcneill ACPI_BUFFER buf;
866 1.17 jmcneill
867 1.17 jmcneill buf.Pointer = NULL;
868 1.17 jmcneill buf.Length = ACPI_ALLOCATE_BUFFER;
869 1.17 jmcneill
870 1.17 jmcneill rv = acpi_dsd_property(handle, prop, &buf, ACPI_TYPE_STRING, &propval);
871 1.17 jmcneill if (ACPI_SUCCESS(rv))
872 1.17 jmcneill *val = kmem_strdup(propval->String.Pointer, KM_SLEEP);
873 1.17 jmcneill
874 1.18 mlelstv if (buf.Pointer != NULL)
875 1.18 mlelstv ACPI_FREE(buf.Pointer);
876 1.15 jmcneill return rv;
877 1.15 jmcneill }
878 1.20 thorpej
879 1.20 thorpej /*
880 1.20 thorpej * Device Specific Method (_DSM) support
881 1.20 thorpej */
882 1.20 thorpej
883 1.20 thorpej ACPI_STATUS
884 1.20 thorpej acpi_dsm_typed(ACPI_HANDLE handle, uint8_t *uuid, ACPI_INTEGER rev,
885 1.20 thorpej ACPI_INTEGER func, const ACPI_OBJECT *arg3, ACPI_OBJECT_TYPE return_type,
886 1.20 thorpej ACPI_OBJECT **return_obj)
887 1.20 thorpej {
888 1.20 thorpej ACPI_OBJECT_LIST arg;
889 1.20 thorpej ACPI_OBJECT obj[4];
890 1.20 thorpej ACPI_BUFFER buf;
891 1.20 thorpej ACPI_STATUS status;
892 1.20 thorpej
893 1.20 thorpej arg.Count = 4;
894 1.20 thorpej arg.Pointer = obj;
895 1.20 thorpej
896 1.20 thorpej obj[0].Type = ACPI_TYPE_BUFFER;
897 1.20 thorpej obj[0].Buffer.Length = ACPI_UUID_LENGTH;
898 1.20 thorpej obj[0].Buffer.Pointer = uuid;
899 1.20 thorpej
900 1.20 thorpej obj[1].Type = ACPI_TYPE_INTEGER;
901 1.20 thorpej obj[1].Integer.Value = rev;
902 1.20 thorpej
903 1.20 thorpej obj[2].Type = ACPI_TYPE_INTEGER;
904 1.20 thorpej obj[2].Integer.Value = func;
905 1.20 thorpej
906 1.20 thorpej if (arg3 != NULL) {
907 1.20 thorpej obj[3] = *arg3;
908 1.20 thorpej } else {
909 1.20 thorpej obj[3].Type = ACPI_TYPE_PACKAGE;
910 1.20 thorpej obj[3].Package.Count = 0;
911 1.20 thorpej obj[3].Package.Elements = NULL;
912 1.20 thorpej }
913 1.20 thorpej
914 1.20 thorpej buf.Pointer = NULL;
915 1.20 thorpej buf.Length = ACPI_ALLOCATE_BUFFER;
916 1.20 thorpej
917 1.20 thorpej if (return_obj == NULL && return_type == ACPI_TYPE_ANY) {
918 1.20 thorpej status = AcpiEvaluateObject(handle, "_DSM", &arg, NULL);
919 1.20 thorpej } else {
920 1.20 thorpej *return_obj = NULL;
921 1.20 thorpej status = AcpiEvaluateObjectTyped(handle, "_DSM", &arg, &buf,
922 1.20 thorpej return_type);
923 1.20 thorpej }
924 1.20 thorpej if (ACPI_FAILURE(status)) {
925 1.20 thorpej return status;
926 1.20 thorpej }
927 1.20 thorpej if (return_obj != NULL) {
928 1.20 thorpej *return_obj = buf.Pointer;
929 1.20 thorpej } else if (buf.Pointer != NULL) {
930 1.20 thorpej ACPI_FREE(buf.Pointer);
931 1.20 thorpej }
932 1.20 thorpej return AE_OK;
933 1.20 thorpej }
934 1.20 thorpej
935 1.20 thorpej ACPI_STATUS
936 1.20 thorpej acpi_dsm_integer(ACPI_HANDLE handle, uint8_t *uuid, ACPI_INTEGER rev,
937 1.20 thorpej ACPI_INTEGER func, const ACPI_OBJECT *arg3, ACPI_INTEGER *ret)
938 1.20 thorpej {
939 1.20 thorpej ACPI_OBJECT *obj;
940 1.20 thorpej ACPI_STATUS status;
941 1.20 thorpej
942 1.20 thorpej status = acpi_dsm_typed(handle, uuid, rev, func, arg3,
943 1.20 thorpej ACPI_TYPE_INTEGER, &obj);
944 1.20 thorpej if (ACPI_FAILURE(status)) {
945 1.20 thorpej return status;
946 1.20 thorpej }
947 1.20 thorpej
948 1.20 thorpej *ret = obj->Integer.Value;
949 1.20 thorpej ACPI_FREE(obj);
950 1.20 thorpej
951 1.20 thorpej return AE_OK;
952 1.20 thorpej }
953 1.20 thorpej
954 1.20 thorpej ACPI_STATUS
955 1.20 thorpej acpi_dsm(ACPI_HANDLE handle, uint8_t *uuid, ACPI_INTEGER rev,
956 1.20 thorpej ACPI_INTEGER func, const ACPI_OBJECT *arg3, ACPI_OBJECT **return_obj)
957 1.20 thorpej {
958 1.20 thorpej return acpi_dsm_typed(handle, uuid, rev, func, arg3, ACPI_TYPE_ANY,
959 1.20 thorpej return_obj);
960 1.20 thorpej }
961 1.21 jmcneill
962 1.21 jmcneill ACPI_STATUS
963 1.21 jmcneill acpi_claim_childdevs(device_t dev, struct acpi_devnode *devnode)
964 1.21 jmcneill {
965 1.21 jmcneill struct acpi_devnode *ad;
966 1.21 jmcneill
967 1.21 jmcneill SIMPLEQ_FOREACH(ad, &devnode->ad_child_head, ad_child_list) {
968 1.21 jmcneill if (ad->ad_device != NULL)
969 1.21 jmcneill continue;
970 1.22 jmcneill aprint_debug_dev(dev, "claiming %s\n",
971 1.22 jmcneill acpi_name(ad->ad_handle));
972 1.21 jmcneill ad->ad_device = dev;
973 1.21 jmcneill acpi_claim_childdevs(dev, ad);
974 1.21 jmcneill }
975 1.21 jmcneill
976 1.21 jmcneill return AE_OK;
977 1.21 jmcneill }
978