acpi_util.c revision 1.6.6.1 1 1.6.6.1 cherry /* $NetBSD: acpi_util.c,v 1.6.6.1 2011/06/23 14:19:56 cherry Exp $ */
2 1.1 jruoho
3 1.1 jruoho /*-
4 1.1 jruoho * Copyright (c) 2003, 2007 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.6.6.1 cherry __KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.6.6.1 2011/06/23 14:19:56 cherry Exp $");
69 1.1 jruoho
70 1.1 jruoho #include <sys/param.h>
71 1.1 jruoho
72 1.1 jruoho #include <dev/acpi/acpireg.h>
73 1.1 jruoho #include <dev/acpi/acpivar.h>
74 1.1 jruoho
75 1.6.6.1 cherry #define _COMPONENT ACPI_BUS_COMPONENT
76 1.6.6.1 cherry ACPI_MODULE_NAME ("acpi_util")
77 1.1 jruoho
78 1.6.6.1 cherry static void acpi_clean_node(ACPI_HANDLE, void *);
79 1.6.6.1 cherry
80 1.6.6.1 cherry static const char * const acpicpu_ids[] = {
81 1.6.6.1 cherry "ACPI0007",
82 1.6.6.1 cherry NULL
83 1.6.6.1 cherry };
84 1.5 jruoho
85 1.1 jruoho /*
86 1.2 jruoho * Evaluate an integer object.
87 1.1 jruoho */
88 1.1 jruoho ACPI_STATUS
89 1.1 jruoho acpi_eval_integer(ACPI_HANDLE handle, const char *path, ACPI_INTEGER *valp)
90 1.1 jruoho {
91 1.1 jruoho ACPI_OBJECT obj;
92 1.1 jruoho ACPI_BUFFER buf;
93 1.1 jruoho ACPI_STATUS rv;
94 1.1 jruoho
95 1.1 jruoho if (handle == NULL)
96 1.1 jruoho handle = ACPI_ROOT_OBJECT;
97 1.1 jruoho
98 1.6 gsutre (void)memset(&obj, 0, sizeof(obj));
99 1.1 jruoho buf.Pointer = &obj;
100 1.1 jruoho buf.Length = sizeof(obj);
101 1.1 jruoho
102 1.1 jruoho rv = AcpiEvaluateObject(handle, path, NULL, &buf);
103 1.1 jruoho
104 1.1 jruoho if (ACPI_FAILURE(rv))
105 1.1 jruoho return rv;
106 1.1 jruoho
107 1.6 gsutre /* Check that evaluation produced a return value. */
108 1.6 gsutre if (buf.Length == 0)
109 1.6 gsutre return AE_NULL_OBJECT;
110 1.6 gsutre
111 1.1 jruoho if (obj.Type != ACPI_TYPE_INTEGER)
112 1.1 jruoho return AE_TYPE;
113 1.1 jruoho
114 1.1 jruoho if (valp != NULL)
115 1.1 jruoho *valp = obj.Integer.Value;
116 1.1 jruoho
117 1.1 jruoho return AE_OK;
118 1.1 jruoho }
119 1.1 jruoho
120 1.1 jruoho /*
121 1.2 jruoho * Evaluate an integer object with a single integer input parameter.
122 1.1 jruoho */
123 1.1 jruoho ACPI_STATUS
124 1.1 jruoho acpi_eval_set_integer(ACPI_HANDLE handle, const char *path, ACPI_INTEGER val)
125 1.1 jruoho {
126 1.1 jruoho ACPI_OBJECT_LIST arg;
127 1.1 jruoho ACPI_OBJECT obj;
128 1.1 jruoho
129 1.1 jruoho if (handle == NULL)
130 1.1 jruoho handle = ACPI_ROOT_OBJECT;
131 1.1 jruoho
132 1.1 jruoho obj.Type = ACPI_TYPE_INTEGER;
133 1.1 jruoho obj.Integer.Value = val;
134 1.1 jruoho
135 1.1 jruoho arg.Count = 1;
136 1.1 jruoho arg.Pointer = &obj;
137 1.1 jruoho
138 1.1 jruoho return AcpiEvaluateObject(handle, path, &arg, NULL);
139 1.1 jruoho }
140 1.1 jruoho
141 1.1 jruoho /*
142 1.2 jruoho * Evaluate a (Unicode) string object.
143 1.1 jruoho */
144 1.1 jruoho ACPI_STATUS
145 1.1 jruoho acpi_eval_string(ACPI_HANDLE handle, const char *path, char **stringp)
146 1.1 jruoho {
147 1.1 jruoho ACPI_OBJECT *obj;
148 1.1 jruoho ACPI_BUFFER buf;
149 1.1 jruoho ACPI_STATUS rv;
150 1.1 jruoho
151 1.1 jruoho rv = acpi_eval_struct(handle, path, &buf);
152 1.1 jruoho
153 1.1 jruoho if (ACPI_FAILURE(rv))
154 1.1 jruoho return rv;
155 1.1 jruoho
156 1.1 jruoho obj = buf.Pointer;
157 1.1 jruoho
158 1.1 jruoho if (obj->Type != ACPI_TYPE_STRING) {
159 1.1 jruoho rv = AE_TYPE;
160 1.1 jruoho goto out;
161 1.1 jruoho }
162 1.1 jruoho
163 1.1 jruoho if (obj->String.Length == 0) {
164 1.1 jruoho rv = AE_BAD_DATA;
165 1.1 jruoho goto out;
166 1.1 jruoho }
167 1.1 jruoho
168 1.1 jruoho *stringp = ACPI_ALLOCATE(obj->String.Length + 1);
169 1.1 jruoho
170 1.1 jruoho if (*stringp == NULL) {
171 1.1 jruoho rv = AE_NO_MEMORY;
172 1.1 jruoho goto out;
173 1.1 jruoho }
174 1.1 jruoho
175 1.1 jruoho (void)memcpy(*stringp, obj->String.Pointer, obj->String.Length);
176 1.1 jruoho
177 1.1 jruoho (*stringp)[obj->String.Length] = '\0';
178 1.1 jruoho
179 1.1 jruoho out:
180 1.1 jruoho ACPI_FREE(buf.Pointer);
181 1.1 jruoho
182 1.1 jruoho return rv;
183 1.1 jruoho }
184 1.1 jruoho
185 1.1 jruoho /*
186 1.2 jruoho * Evaluate a structure. Caller must free buf.Pointer by ACPI_FREE().
187 1.1 jruoho */
188 1.1 jruoho ACPI_STATUS
189 1.1 jruoho acpi_eval_struct(ACPI_HANDLE handle, const char *path, ACPI_BUFFER *buf)
190 1.1 jruoho {
191 1.1 jruoho
192 1.1 jruoho if (handle == NULL)
193 1.1 jruoho handle = ACPI_ROOT_OBJECT;
194 1.1 jruoho
195 1.1 jruoho buf->Pointer = NULL;
196 1.1 jruoho buf->Length = ACPI_ALLOCATE_LOCAL_BUFFER;
197 1.1 jruoho
198 1.1 jruoho return AcpiEvaluateObject(handle, path, NULL, buf);
199 1.1 jruoho }
200 1.1 jruoho
201 1.1 jruoho /*
202 1.2 jruoho * Evaluate a reference handle from an element in a package.
203 1.1 jruoho */
204 1.1 jruoho ACPI_STATUS
205 1.1 jruoho acpi_eval_reference_handle(ACPI_OBJECT *elm, ACPI_HANDLE *handle)
206 1.1 jruoho {
207 1.1 jruoho
208 1.1 jruoho if (elm == NULL || handle == NULL)
209 1.1 jruoho return AE_BAD_PARAMETER;
210 1.1 jruoho
211 1.1 jruoho switch (elm->Type) {
212 1.1 jruoho
213 1.1 jruoho case ACPI_TYPE_ANY:
214 1.1 jruoho case ACPI_TYPE_LOCAL_REFERENCE:
215 1.1 jruoho
216 1.1 jruoho if (elm->Reference.Handle == NULL)
217 1.1 jruoho return AE_NULL_ENTRY;
218 1.1 jruoho
219 1.1 jruoho *handle = elm->Reference.Handle;
220 1.1 jruoho
221 1.1 jruoho return AE_OK;
222 1.1 jruoho
223 1.1 jruoho case ACPI_TYPE_STRING:
224 1.1 jruoho return AcpiGetHandle(NULL, elm->String.Pointer, handle);
225 1.1 jruoho
226 1.1 jruoho default:
227 1.1 jruoho return AE_TYPE;
228 1.1 jruoho }
229 1.1 jruoho }
230 1.1 jruoho
231 1.1 jruoho /*
232 1.2 jruoho * Iterate over all objects in a package, and pass them all
233 1.2 jruoho * to a function. If the called function returns non-AE_OK,
234 1.2 jruoho * the iteration is stopped and that value is returned.
235 1.1 jruoho */
236 1.1 jruoho ACPI_STATUS
237 1.1 jruoho acpi_foreach_package_object(ACPI_OBJECT *pkg,
238 1.1 jruoho ACPI_STATUS (*func)(ACPI_OBJECT *, void *), void *arg)
239 1.1 jruoho {
240 1.1 jruoho ACPI_STATUS rv = AE_OK;
241 1.1 jruoho uint32_t i;
242 1.1 jruoho
243 1.4 jruoho if (pkg == NULL)
244 1.1 jruoho return AE_BAD_PARAMETER;
245 1.1 jruoho
246 1.4 jruoho if (pkg->Type != ACPI_TYPE_PACKAGE)
247 1.4 jruoho return AE_TYPE;
248 1.4 jruoho
249 1.1 jruoho for (i = 0; i < pkg->Package.Count; i++) {
250 1.1 jruoho
251 1.1 jruoho rv = (*func)(&pkg->Package.Elements[i], arg);
252 1.1 jruoho
253 1.1 jruoho if (ACPI_FAILURE(rv))
254 1.1 jruoho break;
255 1.1 jruoho }
256 1.1 jruoho
257 1.1 jruoho return rv;
258 1.1 jruoho }
259 1.1 jruoho
260 1.1 jruoho /*
261 1.2 jruoho * Fetch data info the specified (empty) ACPI buffer.
262 1.2 jruoho * Caller must free buf.Pointer by ACPI_FREE().
263 1.1 jruoho */
264 1.1 jruoho ACPI_STATUS
265 1.1 jruoho acpi_get(ACPI_HANDLE handle, ACPI_BUFFER *buf,
266 1.1 jruoho ACPI_STATUS (*getit)(ACPI_HANDLE, ACPI_BUFFER *))
267 1.1 jruoho {
268 1.1 jruoho
269 1.1 jruoho buf->Pointer = NULL;
270 1.1 jruoho buf->Length = ACPI_ALLOCATE_LOCAL_BUFFER;
271 1.1 jruoho
272 1.1 jruoho return (*getit)(handle, buf);
273 1.1 jruoho }
274 1.1 jruoho
275 1.1 jruoho /*
276 1.2 jruoho * Return a complete pathname from a handle.
277 1.1 jruoho *
278 1.2 jruoho * Note that the function uses static data storage;
279 1.2 jruoho * if the data is needed for future use, it should be
280 1.2 jruoho * copied before any subsequent calls overwrite it.
281 1.1 jruoho */
282 1.1 jruoho const char *
283 1.1 jruoho acpi_name(ACPI_HANDLE handle)
284 1.1 jruoho {
285 1.1 jruoho static char name[80];
286 1.1 jruoho ACPI_BUFFER buf;
287 1.1 jruoho ACPI_STATUS rv;
288 1.1 jruoho
289 1.4 jruoho if (handle == NULL)
290 1.4 jruoho handle = ACPI_ROOT_OBJECT;
291 1.4 jruoho
292 1.1 jruoho buf.Pointer = name;
293 1.1 jruoho buf.Length = sizeof(name);
294 1.1 jruoho
295 1.1 jruoho rv = AcpiGetName(handle, ACPI_FULL_PATHNAME, &buf);
296 1.1 jruoho
297 1.1 jruoho if (ACPI_FAILURE(rv))
298 1.1 jruoho return "UNKNOWN";
299 1.1 jruoho
300 1.1 jruoho return name;
301 1.1 jruoho }
302 1.1 jruoho
303 1.1 jruoho /*
304 1.2 jruoho * Match given IDs against _HID and _CIDs.
305 1.1 jruoho */
306 1.1 jruoho int
307 1.1 jruoho acpi_match_hid(ACPI_DEVICE_INFO *ad, const char * const *ids)
308 1.1 jruoho {
309 1.1 jruoho uint32_t i, n;
310 1.1 jruoho char *id;
311 1.1 jruoho
312 1.1 jruoho while (*ids) {
313 1.1 jruoho
314 1.1 jruoho if ((ad->Valid & ACPI_VALID_HID) != 0) {
315 1.1 jruoho
316 1.1 jruoho if (pmatch(ad->HardwareId.String, *ids, NULL) == 2)
317 1.1 jruoho return 1;
318 1.1 jruoho }
319 1.1 jruoho
320 1.1 jruoho if ((ad->Valid & ACPI_VALID_CID) != 0) {
321 1.1 jruoho
322 1.1 jruoho n = ad->CompatibleIdList.Count;
323 1.1 jruoho
324 1.1 jruoho for (i = 0; i < n; i++) {
325 1.1 jruoho
326 1.1 jruoho id = ad->CompatibleIdList.Ids[i].String;
327 1.1 jruoho
328 1.1 jruoho if (pmatch(id, *ids, NULL) == 2)
329 1.1 jruoho return 1;
330 1.1 jruoho }
331 1.1 jruoho }
332 1.1 jruoho
333 1.1 jruoho ids++;
334 1.1 jruoho }
335 1.1 jruoho
336 1.1 jruoho return 0;
337 1.1 jruoho }
338 1.1 jruoho
339 1.6.6.1 cherry /*
340 1.6.6.1 cherry * Match a device node from a handle.
341 1.6.6.1 cherry */
342 1.6.6.1 cherry struct acpi_devnode *
343 1.6.6.1 cherry acpi_match_node(ACPI_HANDLE handle)
344 1.6.6.1 cherry {
345 1.6.6.1 cherry struct acpi_devnode *ad;
346 1.6.6.1 cherry ACPI_STATUS rv;
347 1.6.6.1 cherry
348 1.6.6.1 cherry if (handle == NULL)
349 1.6.6.1 cherry return NULL;
350 1.6.6.1 cherry
351 1.6.6.1 cherry rv = AcpiGetData(handle, acpi_clean_node, (void **)&ad);
352 1.6.6.1 cherry
353 1.6.6.1 cherry if (ACPI_FAILURE(rv))
354 1.6.6.1 cherry return NULL;
355 1.6.6.1 cherry
356 1.6.6.1 cherry return ad;
357 1.6.6.1 cherry }
358 1.6.6.1 cherry
359 1.6.6.1 cherry /*
360 1.6.6.1 cherry * Permanently associate a device node with a handle.
361 1.6.6.1 cherry */
362 1.6.6.1 cherry void
363 1.6.6.1 cherry acpi_match_node_init(struct acpi_devnode *ad)
364 1.6.6.1 cherry {
365 1.6.6.1 cherry (void)AcpiAttachData(ad->ad_handle, acpi_clean_node, ad);
366 1.6.6.1 cherry }
367 1.6.6.1 cherry
368 1.6.6.1 cherry static void
369 1.6.6.1 cherry acpi_clean_node(ACPI_HANDLE handle, void *aux)
370 1.6.6.1 cherry {
371 1.6.6.1 cherry /* Nothing. */
372 1.6.6.1 cherry }
373 1.6.6.1 cherry
374 1.6.6.1 cherry /*
375 1.6.6.1 cherry * Match a handle from a cpu_info. Returns NULL on failure.
376 1.6.6.1 cherry *
377 1.6.6.1 cherry * Note that acpi_match_node() can be used if the device node
378 1.6.6.1 cherry * is also required.
379 1.6.6.1 cherry */
380 1.6.6.1 cherry ACPI_HANDLE
381 1.6.6.1 cherry acpi_match_cpu_info(struct cpu_info *ci)
382 1.6.6.1 cherry {
383 1.6.6.1 cherry struct acpi_softc *sc = acpi_softc;
384 1.6.6.1 cherry struct acpi_devnode *ad;
385 1.6.6.1 cherry ACPI_INTEGER val;
386 1.6.6.1 cherry ACPI_OBJECT *obj;
387 1.6.6.1 cherry ACPI_BUFFER buf;
388 1.6.6.1 cherry ACPI_HANDLE hdl;
389 1.6.6.1 cherry ACPI_STATUS rv;
390 1.6.6.1 cherry
391 1.6.6.1 cherry if (sc == NULL || acpi_active == 0)
392 1.6.6.1 cherry return NULL;
393 1.6.6.1 cherry
394 1.6.6.1 cherry /*
395 1.6.6.1 cherry * CPUs are declared in the ACPI namespace
396 1.6.6.1 cherry * either as a Processor() or as a Device().
397 1.6.6.1 cherry * In both cases the MADT entries are used
398 1.6.6.1 cherry * for the match (see ACPI 4.0, section 8.4).
399 1.6.6.1 cherry */
400 1.6.6.1 cherry SIMPLEQ_FOREACH(ad, &sc->ad_head, ad_list) {
401 1.6.6.1 cherry
402 1.6.6.1 cherry hdl = ad->ad_handle;
403 1.6.6.1 cherry
404 1.6.6.1 cherry switch (ad->ad_type) {
405 1.6.6.1 cherry
406 1.6.6.1 cherry case ACPI_TYPE_DEVICE:
407 1.6.6.1 cherry
408 1.6.6.1 cherry if (acpi_match_hid(ad->ad_devinfo, acpicpu_ids) == 0)
409 1.6.6.1 cherry break;
410 1.6.6.1 cherry
411 1.6.6.1 cherry rv = acpi_eval_integer(hdl, "_UID", &val);
412 1.6.6.1 cherry
413 1.6.6.1 cherry if (ACPI_SUCCESS(rv) && val == ci->ci_acpiid)
414 1.6.6.1 cherry return hdl;
415 1.6.6.1 cherry
416 1.6.6.1 cherry break;
417 1.6.6.1 cherry
418 1.6.6.1 cherry case ACPI_TYPE_PROCESSOR:
419 1.6.6.1 cherry
420 1.6.6.1 cherry rv = acpi_eval_struct(hdl, NULL, &buf);
421 1.6.6.1 cherry
422 1.6.6.1 cherry if (ACPI_FAILURE(rv))
423 1.6.6.1 cherry break;
424 1.6.6.1 cherry
425 1.6.6.1 cherry obj = buf.Pointer;
426 1.6.6.1 cherry
427 1.6.6.1 cherry if (obj->Processor.ProcId == ci->ci_acpiid) {
428 1.6.6.1 cherry ACPI_FREE(buf.Pointer);
429 1.6.6.1 cherry return hdl;
430 1.6.6.1 cherry }
431 1.6.6.1 cherry
432 1.6.6.1 cherry ACPI_FREE(buf.Pointer);
433 1.6.6.1 cherry break;
434 1.6.6.1 cherry }
435 1.6.6.1 cherry }
436 1.6.6.1 cherry
437 1.6.6.1 cherry return NULL;
438 1.6.6.1 cherry }
439 1.6.6.1 cherry
440 1.6.6.1 cherry /*
441 1.6.6.1 cherry * Match a CPU from a handle. Returns NULL on failure.
442 1.6.6.1 cherry */
443 1.6.6.1 cherry struct cpu_info *
444 1.6.6.1 cherry acpi_match_cpu_handle(ACPI_HANDLE hdl)
445 1.6.6.1 cherry {
446 1.6.6.1 cherry struct cpu_info *ci;
447 1.6.6.1 cherry ACPI_DEVICE_INFO *di;
448 1.6.6.1 cherry CPU_INFO_ITERATOR cii;
449 1.6.6.1 cherry ACPI_INTEGER val;
450 1.6.6.1 cherry ACPI_OBJECT *obj;
451 1.6.6.1 cherry ACPI_BUFFER buf;
452 1.6.6.1 cherry ACPI_STATUS rv;
453 1.6.6.1 cherry
454 1.6.6.1 cherry ci = NULL;
455 1.6.6.1 cherry di = NULL;
456 1.6.6.1 cherry buf.Pointer = NULL;
457 1.6.6.1 cherry
458 1.6.6.1 cherry rv = AcpiGetObjectInfo(hdl, &di);
459 1.6.6.1 cherry
460 1.6.6.1 cherry if (ACPI_FAILURE(rv))
461 1.6.6.1 cherry return NULL;
462 1.6.6.1 cherry
463 1.6.6.1 cherry switch (di->Type) {
464 1.6.6.1 cherry
465 1.6.6.1 cherry case ACPI_TYPE_DEVICE:
466 1.6.6.1 cherry
467 1.6.6.1 cherry if (acpi_match_hid(di, acpicpu_ids) == 0)
468 1.6.6.1 cherry goto out;
469 1.6.6.1 cherry
470 1.6.6.1 cherry rv = acpi_eval_integer(hdl, "_UID", &val);
471 1.6.6.1 cherry
472 1.6.6.1 cherry if (ACPI_FAILURE(rv))
473 1.6.6.1 cherry goto out;
474 1.6.6.1 cherry
475 1.6.6.1 cherry break;
476 1.6.6.1 cherry
477 1.6.6.1 cherry case ACPI_TYPE_PROCESSOR:
478 1.6.6.1 cherry
479 1.6.6.1 cherry rv = acpi_eval_struct(hdl, NULL, &buf);
480 1.6.6.1 cherry
481 1.6.6.1 cherry if (ACPI_FAILURE(rv))
482 1.6.6.1 cherry goto out;
483 1.6.6.1 cherry
484 1.6.6.1 cherry obj = buf.Pointer;
485 1.6.6.1 cherry val = obj->Processor.ProcId;
486 1.6.6.1 cherry break;
487 1.6.6.1 cherry
488 1.6.6.1 cherry default:
489 1.6.6.1 cherry goto out;
490 1.6.6.1 cherry }
491 1.6.6.1 cherry
492 1.6.6.1 cherry for (CPU_INFO_FOREACH(cii, ci)) {
493 1.6.6.1 cherry
494 1.6.6.1 cherry if (ci->ci_acpiid == val)
495 1.6.6.1 cherry goto out;
496 1.6.6.1 cherry }
497 1.6.6.1 cherry
498 1.6.6.1 cherry ci = NULL;
499 1.6.6.1 cherry
500 1.6.6.1 cherry out:
501 1.6.6.1 cherry if (di != NULL)
502 1.6.6.1 cherry ACPI_FREE(di);
503 1.6.6.1 cherry
504 1.6.6.1 cherry if (buf.Pointer != NULL)
505 1.6.6.1 cherry ACPI_FREE(buf.Pointer);
506 1.6.6.1 cherry
507 1.6.6.1 cherry return ci;
508 1.6.6.1 cherry }
509