blob: 82bec40d4508e8162eb94a1ea0ccec61f45d2919 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2 *
3 * Module Name: nsxfeval - Public interfaces to the ACPI subsystem
4 * ACPI Object evaluation interfaces
5 *
6 ******************************************************************************/
7
8/*
Bob Moore25f044e2013-01-25 05:38:56 +00009 * Copyright (C) 2000 - 2013, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
Paul Gortmaker214f2c92011-10-26 16:22:14 -040045#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050047#include "accommon.h"
48#include "acnamesp.h"
49#include "acinterp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#define _COMPONENT ACPI_NAMESPACE
Len Brown4be44fc2005-08-05 00:44:28 -040052ACPI_MODULE_NAME("nsxfeval")
Lin Mingbbc24132008-08-04 13:22:10 +080053
54/* Local prototypes */
55static void acpi_ns_resolve_references(struct acpi_evaluate_info *info);
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057/*******************************************************************************
58 *
59 * FUNCTION: acpi_evaluate_object_typed
60 *
Bob Mooreba494be2012-07-12 09:40:10 +080061 * PARAMETERS: handle - Object handle (optional)
62 * pathname - Object pathname (optional)
Robert Moore44f6c012005-04-18 22:49:35 -040063 * external_params - List of parameters to pass to method,
Bob Moore73a30902012-10-31 02:26:55 +000064 * terminated by NULL. May be NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 * if no parameters are being passed.
Robert Moore44f6c012005-04-18 22:49:35 -040066 * return_buffer - Where to put method's return value (if
Bob Moore73a30902012-10-31 02:26:55 +000067 * any). If NULL, no value is returned.
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 * return_type - Expected type of return object
69 *
70 * RETURN: Status
71 *
72 * DESCRIPTION: Find and evaluate the given object, passing the given
Bob Moore73a30902012-10-31 02:26:55 +000073 * parameters if necessary. One of "Handle" or "Pathname" must
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 * be valid (non-null)
75 *
76 ******************************************************************************/
Lin Mingbbc24132008-08-04 13:22:10 +080077
Linus Torvalds1da177e2005-04-16 15:20:36 -070078acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040079acpi_evaluate_object_typed(acpi_handle handle,
80 acpi_string pathname,
Len Brownfd350942007-05-09 23:34:35 -040081 struct acpi_object_list *external_params,
82 struct acpi_buffer *return_buffer,
Len Brown4be44fc2005-08-05 00:44:28 -040083 acpi_object_type return_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
Len Brown4be44fc2005-08-05 00:44:28 -040085 acpi_status status;
86 u8 must_free = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Bob Mooreb229cf92006-04-21 17:15:00 -040088 ACPI_FUNCTION_TRACE(acpi_evaluate_object_typed);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90 /* Return buffer must be valid */
91
92 if (!return_buffer) {
Len Brown4be44fc2005-08-05 00:44:28 -040093 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 }
95
96 if (return_buffer->length == ACPI_ALLOCATE_BUFFER) {
97 must_free = TRUE;
98 }
99
100 /* Evaluate the object */
101
Len Brown4be44fc2005-08-05 00:44:28 -0400102 status =
103 acpi_evaluate_object(handle, pathname, external_params,
104 return_buffer);
105 if (ACPI_FAILURE(status)) {
106 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 }
108
109 /* Type ANY means "don't care" */
110
111 if (return_type == ACPI_TYPE_ANY) {
Len Brown4be44fc2005-08-05 00:44:28 -0400112 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 }
114
115 if (return_buffer->length == 0) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 /* Error because caller specifically asked for a return value */
118
Bob Mooreb8e4d892006-01-27 16:43:00 -0500119 ACPI_ERROR((AE_INFO, "No return value"));
Len Brown4be44fc2005-08-05 00:44:28 -0400120 return_ACPI_STATUS(AE_NULL_OBJECT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 }
122
123 /* Examine the object type returned from evaluate_object */
124
Len Brown4be44fc2005-08-05 00:44:28 -0400125 if (((union acpi_object *)return_buffer->pointer)->type == return_type) {
126 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 }
128
129 /* Return object type does not match requested type */
130
Bob Mooreb8e4d892006-01-27 16:43:00 -0500131 ACPI_ERROR((AE_INFO,
132 "Incorrect return type [%s] requested [%s]",
133 acpi_ut_get_type_name(((union acpi_object *)return_buffer->
134 pointer)->type),
135 acpi_ut_get_type_name(return_type)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137 if (must_free) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 /* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */
140
Len Brown02438d82006-06-30 03:19:10 -0400141 ACPI_FREE(return_buffer->pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 return_buffer->pointer = NULL;
143 }
144
145 return_buffer->length = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400146 return_ACPI_STATUS(AE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147}
Bob Moore83135242006-10-03 00:00:00 -0400148
149ACPI_EXPORT_SYMBOL(acpi_evaluate_object_typed)
Luca Tettamanti2c03d072009-04-07 15:32:59 +0200150
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151/*******************************************************************************
152 *
153 * FUNCTION: acpi_evaluate_object
154 *
Bob Mooreba494be2012-07-12 09:40:10 +0800155 * PARAMETERS: handle - Object handle (optional)
156 * pathname - Object pathname (optional)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 * external_params - List of parameters to pass to method,
Bob Moore73a30902012-10-31 02:26:55 +0000158 * terminated by NULL. May be NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 * if no parameters are being passed.
160 * return_buffer - Where to put method's return value (if
Bob Moore73a30902012-10-31 02:26:55 +0000161 * any). If NULL, no value is returned.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 *
163 * RETURN: Status
164 *
165 * DESCRIPTION: Find and evaluate the given object, passing the given
Bob Moore73a30902012-10-31 02:26:55 +0000166 * parameters if necessary. One of "Handle" or "Pathname" must
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 * be valid (non-null)
168 *
169 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400171acpi_evaluate_object(acpi_handle handle,
172 acpi_string pathname,
173 struct acpi_object_list *external_params,
174 struct acpi_buffer *return_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175{
Len Brown4be44fc2005-08-05 00:44:28 -0400176 acpi_status status;
Bob Moore41195322006-05-26 16:36:00 -0400177 struct acpi_evaluate_info *info;
Len Brown4be44fc2005-08-05 00:44:28 -0400178 acpi_size buffer_space_needed;
179 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Bob Mooreb229cf92006-04-21 17:15:00 -0400181 ACPI_FUNCTION_TRACE(acpi_evaluate_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
Bob Moore41195322006-05-26 16:36:00 -0400183 /* Allocate and initialize the evaluation information block */
184
185 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
186 if (!info) {
187 return_ACPI_STATUS(AE_NO_MEMORY);
188 }
189
Bob Moore41195322006-05-26 16:36:00 -0400190 /* Convert and validate the device handle */
191
Bob Mooref24b6642009-12-11 14:57:00 +0800192 info->prefix_node = acpi_ns_validate_handle(handle);
Bob Moore41195322006-05-26 16:36:00 -0400193 if (!info->prefix_node) {
194 status = AE_BAD_PARAMETER;
195 goto cleanup;
196 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
198 /*
Bob Moore29a241c2013-05-30 10:00:01 +0800199 * Get the actual namespace node for the target object.
200 * Handles these cases:
201 *
202 * 1) Null node, valid pathname from root (absolute path)
203 * 2) Node and valid pathname (path relative to Node)
204 * 3) Node, Null pathname
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 */
Bob Moore04a81dc2012-12-31 00:05:17 +0000206 if ((pathname) && (ACPI_IS_ROOT_PREFIX(pathname[0]))) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400207
208 /* The path is fully qualified, just evaluate by name */
209
Bob Moore41195322006-05-26 16:36:00 -0400210 info->prefix_node = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400211 } else if (!handle) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 /*
Bob Moore41195322006-05-26 16:36:00 -0400213 * A handle is optional iff a fully qualified pathname is specified.
214 * Since we've already handled fully qualified names above, this is
Bob Moore29a241c2013-05-30 10:00:01 +0800215 * an error.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 */
217 if (!pathname) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400218 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
219 "Both Handle and Pathname are NULL"));
Len Brown4be44fc2005-08-05 00:44:28 -0400220 } else {
Bob Moore52fc0b02006-10-02 00:00:00 -0400221 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
222 "Null Handle with relative pathname [%s]",
223 pathname));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 }
225
226 status = AE_BAD_PARAMETER;
Bob Moore29a241c2013-05-30 10:00:01 +0800227 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 }
229
Bob Moore29a241c2013-05-30 10:00:01 +0800230 info->relative_pathname = pathname;
231
232 /*
233 * Convert all external objects passed as arguments to the
234 * internal version(s).
235 */
236 if (external_params && external_params->count) {
237 info->param_count = (u16)external_params->count;
238
239 /* Warn on impossible argument count */
240
241 if (info->param_count > ACPI_METHOD_NUM_ARGS) {
242 ACPI_WARN_PREDEFINED((AE_INFO, pathname,
243 ACPI_WARN_ALWAYS,
244 "Excess arguments (%u) - using only %u",
245 info->param_count,
246 ACPI_METHOD_NUM_ARGS));
247
248 info->param_count = ACPI_METHOD_NUM_ARGS;
249 }
250
251 /*
252 * Allocate a new parameter block for the internal objects
253 * Add 1 to count to allow for null terminated internal list
254 */
255 info->parameters = ACPI_ALLOCATE_ZEROED(((acpi_size) info->
256 param_count +
257 1) * sizeof(void *));
258 if (!info->parameters) {
259 status = AE_NO_MEMORY;
260 goto cleanup;
261 }
262
263 /* Convert each external object in the list to an internal object */
264
265 for (i = 0; i < info->param_count; i++) {
266 status =
267 acpi_ut_copy_eobject_to_iobject(&external_params->
268 pointer[i],
269 &info->
270 parameters[i]);
271 if (ACPI_FAILURE(status)) {
272 goto cleanup;
273 }
274 }
275
276 info->parameters[info->param_count] = NULL;
277 }
278
279#if 0
280
281 /*
282 * Begin incoming argument count analysis. Check for too few args
283 * and too many args.
284 */
285
286 switch (acpi_ns_get_type(info->node)) {
287 case ACPI_TYPE_METHOD:
288
289 /* Check incoming argument count against the method definition */
290
291 if (info->obj_desc->method.param_count > info->param_count) {
292 ACPI_ERROR((AE_INFO,
293 "Insufficient arguments (%u) - %u are required",
294 info->param_count,
295 info->obj_desc->method.param_count));
296
297 status = AE_MISSING_ARGUMENTS;
298 goto cleanup;
299 }
300
301 else if (info->obj_desc->method.param_count < info->param_count) {
302 ACPI_WARNING((AE_INFO,
303 "Excess arguments (%u) - only %u are required",
304 info->param_count,
305 info->obj_desc->method.param_count));
306
307 /* Just pass the required number of arguments */
308
309 info->param_count = info->obj_desc->method.param_count;
310 }
311
312 /*
313 * Any incoming external objects to be passed as arguments to the
314 * method must be converted to internal objects
315 */
316 if (info->param_count) {
317 /*
318 * Allocate a new parameter block for the internal objects
319 * Add 1 to count to allow for null terminated internal list
320 */
321 info->parameters = ACPI_ALLOCATE_ZEROED(((acpi_size)
322 info->
323 param_count +
324 1) *
325 sizeof(void *));
326 if (!info->parameters) {
327 status = AE_NO_MEMORY;
328 goto cleanup;
329 }
330
331 /* Convert each external object in the list to an internal object */
332
333 for (i = 0; i < info->param_count; i++) {
334 status =
335 acpi_ut_copy_eobject_to_iobject
336 (&external_params->pointer[i],
337 &info->parameters[i]);
338 if (ACPI_FAILURE(status)) {
339 goto cleanup;
340 }
341 }
342
343 info->parameters[info->param_count] = NULL;
344 }
345 break;
346
347 default:
348
349 /* Warn if arguments passed to an object that is not a method */
350
351 if (info->param_count) {
352 ACPI_WARNING((AE_INFO,
353 "%u arguments were passed to a non-method ACPI object",
354 info->param_count));
355 }
356 break;
357 }
358
359#endif
360
361 /* Now we can evaluate the object */
362
363 status = acpi_ns_evaluate(info);
364
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 /*
366 * If we are expecting a return value, and all went well above,
367 * copy the return value to an external object.
368 */
369 if (return_buffer) {
Bob Moore41195322006-05-26 16:36:00 -0400370 if (!info->return_object) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 return_buffer->length = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400372 } else {
Bob Moore41195322006-05-26 16:36:00 -0400373 if (ACPI_GET_DESCRIPTOR_TYPE(info->return_object) ==
Len Brown4be44fc2005-08-05 00:44:28 -0400374 ACPI_DESC_TYPE_NAMED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 /*
376 * If we received a NS Node as a return object, this means that
377 * the object we are evaluating has nothing interesting to
378 * return (such as a mutex, etc.) We return an error because
379 * these types are essentially unsupported by this interface.
380 * We don't check up front because this makes it easier to add
381 * support for various types at a later date if necessary.
382 */
383 status = AE_TYPE;
Bob Moore41195322006-05-26 16:36:00 -0400384 info->return_object = NULL; /* No need to delete a NS Node */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 return_buffer->length = 0;
386 }
387
Len Brown4be44fc2005-08-05 00:44:28 -0400388 if (ACPI_SUCCESS(status)) {
Bob Moore41195322006-05-26 16:36:00 -0400389
Lin Mingbbc24132008-08-04 13:22:10 +0800390 /* Dereference Index and ref_of references */
391
392 acpi_ns_resolve_references(info);
393
Bob Moore41195322006-05-26 16:36:00 -0400394 /* Get the size of the returned object */
395
Len Brown4be44fc2005-08-05 00:44:28 -0400396 status =
Bob Moore41195322006-05-26 16:36:00 -0400397 acpi_ut_get_object_size(info->return_object,
Len Brown4be44fc2005-08-05 00:44:28 -0400398 &buffer_space_needed);
399 if (ACPI_SUCCESS(status)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400400
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 /* Validate/Allocate/Clear caller buffer */
402
Len Brown4be44fc2005-08-05 00:44:28 -0400403 status =
404 acpi_ut_initialize_buffer
405 (return_buffer,
406 buffer_space_needed);
407 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 /*
Bob Moore52fc0b02006-10-02 00:00:00 -0400409 * Caller's buffer is too small or a new one can't
410 * be allocated
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 */
Len Brown4be44fc2005-08-05 00:44:28 -0400412 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
413 "Needed buffer size %X, %s\n",
414 (u32)
415 buffer_space_needed,
416 acpi_format_exception
417 (status)));
418 } else {
Bob Moore52fc0b02006-10-02 00:00:00 -0400419 /* We have enough space for the object, build it */
420
Len Brown4be44fc2005-08-05 00:44:28 -0400421 status =
422 acpi_ut_copy_iobject_to_eobject
Bob Moore41195322006-05-26 16:36:00 -0400423 (info->return_object,
Len Brown4be44fc2005-08-05 00:44:28 -0400424 return_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 }
426 }
427 }
428 }
429 }
430
Bob Moore41195322006-05-26 16:36:00 -0400431 if (info->return_object) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 /*
Bob Moore41195322006-05-26 16:36:00 -0400433 * Delete the internal return object. NOTE: Interpreter must be
434 * locked to avoid race condition.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 */
Len Brown4d2acd92007-05-09 22:56:38 -0400436 acpi_ex_enter_interpreter();
Bob Moore41195322006-05-26 16:36:00 -0400437
Len Brown4d2acd92007-05-09 22:56:38 -0400438 /* Remove one reference on the return object (should delete it) */
Bob Moore41195322006-05-26 16:36:00 -0400439
Len Brown4d2acd92007-05-09 22:56:38 -0400440 acpi_ut_remove_reference(info->return_object);
441 acpi_ex_exit_interpreter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 }
443
Bob Moore41195322006-05-26 16:36:00 -0400444 cleanup:
445
Bob Moore52fc0b02006-10-02 00:00:00 -0400446 /* Free the input parameter list (if we created one) */
447
Bob Moore41195322006-05-26 16:36:00 -0400448 if (info->parameters) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400449
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 /* Free the allocated parameter block */
451
Bob Moore41195322006-05-26 16:36:00 -0400452 acpi_ut_delete_internal_object_list(info->parameters);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 }
454
Bob Moore41195322006-05-26 16:36:00 -0400455 ACPI_FREE(info);
Len Brown4be44fc2005-08-05 00:44:28 -0400456 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
Bob Moore83135242006-10-03 00:00:00 -0400459ACPI_EXPORT_SYMBOL(acpi_evaluate_object)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
461/*******************************************************************************
462 *
Lin Mingbbc24132008-08-04 13:22:10 +0800463 * FUNCTION: acpi_ns_resolve_references
464 *
Bob Mooreba494be2012-07-12 09:40:10 +0800465 * PARAMETERS: info - Evaluation info block
Lin Mingbbc24132008-08-04 13:22:10 +0800466 *
467 * RETURN: Info->return_object is replaced with the dereferenced object
468 *
469 * DESCRIPTION: Dereference certain reference objects. Called before an
470 * internal return object is converted to an external union acpi_object.
471 *
472 * Performs an automatic dereference of Index and ref_of reference objects.
473 * These reference objects are not supported by the union acpi_object, so this is a
474 * last resort effort to return something useful. Also, provides compatibility
475 * with other ACPI implementations.
476 *
477 * NOTE: does not handle references within returned package objects or nested
478 * references, but this support could be added later if found to be necessary.
479 *
480 ******************************************************************************/
481static void acpi_ns_resolve_references(struct acpi_evaluate_info *info)
482{
483 union acpi_operand_object *obj_desc = NULL;
484 struct acpi_namespace_node *node;
485
486 /* We are interested in reference objects only */
487
Bob Moore3371c192009-02-18 14:44:03 +0800488 if ((info->return_object)->common.type != ACPI_TYPE_LOCAL_REFERENCE) {
Lin Mingbbc24132008-08-04 13:22:10 +0800489 return;
490 }
491
492 /*
493 * Two types of references are supported - those created by Index and
494 * ref_of operators. A name reference (AML_NAMEPATH_OP) can be converted
495 * to an union acpi_object, so it is not dereferenced here. A ddb_handle
496 * (AML_LOAD_OP) cannot be dereferenced, nor can it be converted to
497 * an union acpi_object.
498 */
Bob Moore1044f1f2008-09-27 11:08:41 +0800499 switch (info->return_object->reference.class) {
500 case ACPI_REFCLASS_INDEX:
Lin Mingbbc24132008-08-04 13:22:10 +0800501
502 obj_desc = *(info->return_object->reference.where);
503 break;
504
Bob Moore1044f1f2008-09-27 11:08:41 +0800505 case ACPI_REFCLASS_REFOF:
Lin Mingbbc24132008-08-04 13:22:10 +0800506
507 node = info->return_object->reference.object;
508 if (node) {
509 obj_desc = node->object;
510 }
511 break;
512
513 default:
514 return;
515 }
516
517 /* Replace the existing reference object */
518
519 if (obj_desc) {
520 acpi_ut_add_reference(obj_desc);
521 acpi_ut_remove_reference(info->return_object);
522 info->return_object = obj_desc;
523 }
524
525 return;
526}
527
528/*******************************************************************************
529 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 * FUNCTION: acpi_walk_namespace
531 *
Bob Mooreba494be2012-07-12 09:40:10 +0800532 * PARAMETERS: type - acpi_object_type to search for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 * start_object - Handle in namespace where search begins
534 * max_depth - Depth to which search is to reach
Lin Ming22635762009-11-13 10:06:08 +0800535 * pre_order_visit - Called during tree pre-order visit
536 * when an object of "Type" is found
537 * post_order_visit - Called during tree post-order visit
538 * when an object of "Type" is found
Bob Mooreba494be2012-07-12 09:40:10 +0800539 * context - Passed to user function(s) above
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 * return_value - Location where return value of
541 * user_function is put if terminated early
542 *
543 * RETURNS Return value from the user_function if terminated early.
544 * Otherwise, returns NULL.
545 *
546 * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
547 * starting (and ending) at the object specified by start_handle.
Lin Ming22635762009-11-13 10:06:08 +0800548 * The callback function is called whenever an object that matches
549 * the type parameter is found. If the callback function returns
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 * a non-zero value, the search is terminated immediately and this
551 * value is returned to the caller.
552 *
553 * The point of this procedure is to provide a generic namespace
554 * walk routine that can be called from multiple places to
Lin Ming22635762009-11-13 10:06:08 +0800555 * provide multiple services; the callback function(s) can be
556 * tailored to each task, whether it is a print function,
557 * a compare function, etc.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 *
559 ******************************************************************************/
Lin Mingbbc24132008-08-04 13:22:10 +0800560
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400562acpi_walk_namespace(acpi_object_type type,
563 acpi_handle start_object,
564 u32 max_depth,
Lin Ming22635762009-11-13 10:06:08 +0800565 acpi_walk_callback pre_order_visit,
566 acpi_walk_callback post_order_visit,
Len Brown4be44fc2005-08-05 00:44:28 -0400567 void *context, void **return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568{
Len Brown4be44fc2005-08-05 00:44:28 -0400569 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
Bob Mooreb229cf92006-04-21 17:15:00 -0400571 ACPI_FUNCTION_TRACE(acpi_walk_namespace);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
573 /* Parameter validation */
574
Lin Ming22635762009-11-13 10:06:08 +0800575 if ((type > ACPI_TYPE_LOCAL_MAX) ||
576 (!max_depth) || (!pre_order_visit && !post_order_visit)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400577 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 }
579
580 /*
Bob Moore8a335a232009-03-09 16:31:04 +0800581 * Need to acquire the namespace reader lock to prevent interference
582 * with any concurrent table unloads (which causes the deletion of
583 * namespace objects). We cannot allow the deletion of a namespace node
584 * while the user function is using it. The exception to this are the
585 * nodes created and deleted during control method execution -- these
586 * nodes are marked as temporary nodes and are ignored by the namespace
587 * walk. Thus, control methods can be executed while holding the
588 * namespace deletion lock (and the user function can execute control
589 * methods.)
590 */
591 status = acpi_ut_acquire_read_lock(&acpi_gbl_namespace_rw_lock);
592 if (ACPI_FAILURE(status)) {
Lv Zheng7b6afb62012-12-19 05:37:29 +0000593 return_ACPI_STATUS(status);
Bob Moore8a335a232009-03-09 16:31:04 +0800594 }
595
596 /*
597 * Lock the namespace around the walk. The namespace will be
598 * unlocked/locked around each call to the user function - since the user
599 * function must be allowed to make ACPICA calls itself (for example, it
600 * will typically execute control methods during device enumeration.)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 */
Len Brown4be44fc2005-08-05 00:44:28 -0400602 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
603 if (ACPI_FAILURE(status)) {
Bob Moore8a335a232009-03-09 16:31:04 +0800604 goto unlock_and_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 }
606
Len Brown4be44fc2005-08-05 00:44:28 -0400607 status = acpi_ns_walk_namespace(type, start_object, max_depth,
Lin Ming22635762009-11-13 10:06:08 +0800608 ACPI_NS_WALK_UNLOCK, pre_order_visit,
609 post_order_visit, context,
610 return_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
Len Brown4be44fc2005-08-05 00:44:28 -0400612 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Bob Moore8a335a232009-03-09 16:31:04 +0800613
614 unlock_and_exit:
615 (void)acpi_ut_release_read_lock(&acpi_gbl_namespace_rw_lock);
Len Brown4be44fc2005-08-05 00:44:28 -0400616 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618
Bob Moore83135242006-10-03 00:00:00 -0400619ACPI_EXPORT_SYMBOL(acpi_walk_namespace)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620
621/*******************************************************************************
622 *
623 * FUNCTION: acpi_ns_get_device_callback
624 *
625 * PARAMETERS: Callback from acpi_get_device
626 *
627 * RETURN: Status
628 *
629 * DESCRIPTION: Takes callbacks from walk_namespace and filters out all non-
630 * present devices, or if they specified a HID, it filters based
631 * on that.
632 *
633 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400635acpi_ns_get_device_callback(acpi_handle obj_handle,
636 u32 nesting_level,
637 void *context, void **return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638{
Len Brown4be44fc2005-08-05 00:44:28 -0400639 struct acpi_get_devices_info *info = context;
640 acpi_status status;
641 struct acpi_namespace_node *node;
642 u32 flags;
Lv Zheng78e25fe2012-10-31 02:25:24 +0000643 struct acpi_pnp_device_id *hid;
644 struct acpi_pnp_device_id_list *cid;
Bob Moore67a119f2008-06-10 13:42:13 +0800645 u32 i;
Bob Moore15b8dd52009-06-29 13:39:29 +0800646 u8 found;
647 int no_match;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648
Len Brown4be44fc2005-08-05 00:44:28 -0400649 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
650 if (ACPI_FAILURE(status)) {
Lv Zheng7b6afb62012-12-19 05:37:29 +0000651 return (status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 }
653
Bob Mooref24b6642009-12-11 14:57:00 +0800654 node = acpi_ns_validate_handle(obj_handle);
Len Brown4be44fc2005-08-05 00:44:28 -0400655 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
656 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 return (status);
658 }
659
660 if (!node) {
661 return (AE_BAD_PARAMETER);
662 }
663
Lin Ming5f8902ac2010-01-21 09:15:20 +0800664 /*
665 * First, filter based on the device HID and CID.
666 *
667 * 01/2010: For this case where a specific HID is requested, we don't
668 * want to run _STA until we have an actual HID match. Thus, we will
669 * not unnecessarily execute _STA on devices for which the caller
670 * doesn't care about. Previously, _STA was executed unconditionally
671 * on all devices found here.
672 *
673 * A side-effect of this change is that now we will continue to search
674 * for a matching HID even under device trees where the parent device
675 * would have returned a _STA that indicates it is not present or
676 * not functioning (thus aborting the search on that branch).
677 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 if (info->hid != NULL) {
Len Brown4be44fc2005-08-05 00:44:28 -0400679 status = acpi_ut_execute_HID(node, &hid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 if (status == AE_NOT_FOUND) {
681 return (AE_OK);
Len Brown4be44fc2005-08-05 00:44:28 -0400682 } else if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 return (AE_CTRL_DEPTH);
684 }
685
Bob Moore15b8dd52009-06-29 13:39:29 +0800686 no_match = ACPI_STRCMP(hid->string, info->hid);
687 ACPI_FREE(hid);
Bob Moore52fc0b02006-10-02 00:00:00 -0400688
Bob Moore15b8dd52009-06-29 13:39:29 +0800689 if (no_match) {
690 /*
691 * HID does not match, attempt match within the
692 * list of Compatible IDs (CIDs)
693 */
Len Brown4be44fc2005-08-05 00:44:28 -0400694 status = acpi_ut_execute_CID(node, &cid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 if (status == AE_NOT_FOUND) {
696 return (AE_OK);
Len Brown4be44fc2005-08-05 00:44:28 -0400697 } else if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 return (AE_CTRL_DEPTH);
699 }
700
701 /* Walk the CID list */
702
Lv Zheng739dcbb2012-12-20 01:07:26 +0000703 found = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 for (i = 0; i < cid->count; i++) {
Bob Moore15b8dd52009-06-29 13:39:29 +0800705 if (ACPI_STRCMP(cid->ids[i].string, info->hid)
706 == 0) {
Lv Zheng3e8214e2012-12-19 05:37:15 +0000707
Lv Zheng75c80442012-12-19 05:36:49 +0000708 /* Found a matching CID */
Lv Zheng3e8214e2012-12-19 05:37:15 +0000709
Lv Zheng739dcbb2012-12-20 01:07:26 +0000710 found = TRUE;
Andrew Patterson02f8a852008-01-22 17:18:22 -0700711 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 }
713 }
Lv Zheng739dcbb2012-12-20 01:07:26 +0000714
Bob Moore83135242006-10-03 00:00:00 -0400715 ACPI_FREE(cid);
Lv Zheng739dcbb2012-12-20 01:07:26 +0000716 if (!found) {
Andrew Patterson02f8a852008-01-22 17:18:22 -0700717 return (AE_OK);
Lv Zheng739dcbb2012-12-20 01:07:26 +0000718 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 }
720 }
721
Lin Ming5f8902ac2010-01-21 09:15:20 +0800722 /* Run _STA to determine if device is present */
723
724 status = acpi_ut_execute_STA(node, &flags);
725 if (ACPI_FAILURE(status)) {
726 return (AE_CTRL_DEPTH);
727 }
728
729 if (!(flags & ACPI_STA_DEVICE_PRESENT) &&
730 !(flags & ACPI_STA_DEVICE_FUNCTIONING)) {
731 /*
732 * Don't examine the children of the device only when the
733 * device is neither present nor functional. See ACPI spec,
734 * description of _STA for more information.
735 */
736 return (AE_CTRL_DEPTH);
737 }
738
739 /* We have a valid device, invoke the user function */
740
Len Brown4be44fc2005-08-05 00:44:28 -0400741 status = info->user_function(obj_handle, nesting_level, info->context,
742 return_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 return (status);
744}
745
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746/*******************************************************************************
747 *
748 * FUNCTION: acpi_get_devices
749 *
750 * PARAMETERS: HID - HID to search for. Can be NULL.
751 * user_function - Called when a matching object is found
Bob Mooreba494be2012-07-12 09:40:10 +0800752 * context - Passed to user function
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 * return_value - Location where return value of
754 * user_function is put if terminated early
755 *
756 * RETURNS Return value from the user_function if terminated early.
757 * Otherwise, returns NULL.
758 *
759 * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
760 * starting (and ending) at the object specified by start_handle.
761 * The user_function is called whenever an object of type
Bob Moore73a30902012-10-31 02:26:55 +0000762 * Device is found. If the user function returns
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 * a non-zero value, the search is terminated immediately and this
764 * value is returned to the caller.
765 *
766 * This is a wrapper for walk_namespace, but the callback performs
Bob Moore549f4602008-04-10 19:06:41 +0400767 * additional filtering. Please see acpi_ns_get_device_callback.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 *
769 ******************************************************************************/
770
771acpi_status
Al Viro70b30fb2007-08-21 16:18:20 +0100772acpi_get_devices(const char *HID,
Len Brown4be44fc2005-08-05 00:44:28 -0400773 acpi_walk_callback user_function,
774 void *context, void **return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775{
Len Brown4be44fc2005-08-05 00:44:28 -0400776 acpi_status status;
777 struct acpi_get_devices_info info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
Bob Mooreb229cf92006-04-21 17:15:00 -0400779 ACPI_FUNCTION_TRACE(acpi_get_devices);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
781 /* Parameter validation */
782
783 if (!user_function) {
Len Brown4be44fc2005-08-05 00:44:28 -0400784 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 }
786
787 /*
788 * We're going to call their callback from OUR callback, so we need
789 * to know what it is, and their context parameter.
790 */
Bob Moore52fc0b02006-10-02 00:00:00 -0400791 info.hid = HID;
Len Brown4be44fc2005-08-05 00:44:28 -0400792 info.context = context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 info.user_function = user_function;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794
795 /*
796 * Lock the namespace around the walk.
797 * The namespace will be unlocked/locked around each call
798 * to the user function - since this function
799 * must be allowed to make Acpi calls itself.
800 */
Len Brown4be44fc2005-08-05 00:44:28 -0400801 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
802 if (ACPI_FAILURE(status)) {
803 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 }
805
Bob Moore52fc0b02006-10-02 00:00:00 -0400806 status = acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
807 ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK,
Lin Ming22635762009-11-13 10:06:08 +0800808 acpi_ns_get_device_callback, NULL,
809 &info, return_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810
Len Brown4be44fc2005-08-05 00:44:28 -0400811 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
812 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
Bob Moore83135242006-10-03 00:00:00 -0400815ACPI_EXPORT_SYMBOL(acpi_get_devices)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
817/*******************************************************************************
818 *
819 * FUNCTION: acpi_attach_data
820 *
821 * PARAMETERS: obj_handle - Namespace node
Bob Mooreba494be2012-07-12 09:40:10 +0800822 * handler - Handler for this attachment
823 * data - Pointer to data to be attached
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 *
825 * RETURN: Status
826 *
827 * DESCRIPTION: Attach arbitrary data and handler to a namespace node.
828 *
829 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400831acpi_attach_data(acpi_handle obj_handle,
832 acpi_object_handler handler, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833{
Len Brown4be44fc2005-08-05 00:44:28 -0400834 struct acpi_namespace_node *node;
835 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
837 /* Parameter validation */
838
Len Brown4be44fc2005-08-05 00:44:28 -0400839 if (!obj_handle || !handler || !data) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 return (AE_BAD_PARAMETER);
841 }
842
Len Brown4be44fc2005-08-05 00:44:28 -0400843 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
844 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 return (status);
846 }
847
848 /* Convert and validate the handle */
849
Bob Mooref24b6642009-12-11 14:57:00 +0800850 node = acpi_ns_validate_handle(obj_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 if (!node) {
852 status = AE_BAD_PARAMETER;
853 goto unlock_and_exit;
854 }
855
Len Brown4be44fc2005-08-05 00:44:28 -0400856 status = acpi_ns_attach_data(node, handler, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
Len Brown4be44fc2005-08-05 00:44:28 -0400858 unlock_and_exit:
859 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 return (status);
861}
862
Bob Moore83135242006-10-03 00:00:00 -0400863ACPI_EXPORT_SYMBOL(acpi_attach_data)
864
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865/*******************************************************************************
866 *
867 * FUNCTION: acpi_detach_data
868 *
869 * PARAMETERS: obj_handle - Namespace node handle
Bob Mooreba494be2012-07-12 09:40:10 +0800870 * handler - Handler used in call to acpi_attach_data
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 *
872 * RETURN: Status
873 *
874 * DESCRIPTION: Remove data that was previously attached to a node.
875 *
876 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400878acpi_detach_data(acpi_handle obj_handle, acpi_object_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879{
Len Brown4be44fc2005-08-05 00:44:28 -0400880 struct acpi_namespace_node *node;
881 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
883 /* Parameter validation */
884
Len Brown4be44fc2005-08-05 00:44:28 -0400885 if (!obj_handle || !handler) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 return (AE_BAD_PARAMETER);
887 }
888
Len Brown4be44fc2005-08-05 00:44:28 -0400889 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
890 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 return (status);
892 }
893
894 /* Convert and validate the handle */
895
Bob Mooref24b6642009-12-11 14:57:00 +0800896 node = acpi_ns_validate_handle(obj_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 if (!node) {
898 status = AE_BAD_PARAMETER;
899 goto unlock_and_exit;
900 }
901
Len Brown4be44fc2005-08-05 00:44:28 -0400902 status = acpi_ns_detach_data(node, handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
Len Brown4be44fc2005-08-05 00:44:28 -0400904 unlock_and_exit:
905 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 return (status);
907}
908
Bob Moore83135242006-10-03 00:00:00 -0400909ACPI_EXPORT_SYMBOL(acpi_detach_data)
910
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911/*******************************************************************************
912 *
913 * FUNCTION: acpi_get_data
914 *
915 * PARAMETERS: obj_handle - Namespace node
Bob Mooreba494be2012-07-12 09:40:10 +0800916 * handler - Handler used in call to attach_data
917 * data - Where the data is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 *
919 * RETURN: Status
920 *
921 * DESCRIPTION: Retrieve data that was previously attached to a namespace node.
922 *
923 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400925acpi_get_data(acpi_handle obj_handle, acpi_object_handler handler, void **data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926{
Len Brown4be44fc2005-08-05 00:44:28 -0400927 struct acpi_namespace_node *node;
928 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
930 /* Parameter validation */
931
Len Brown4be44fc2005-08-05 00:44:28 -0400932 if (!obj_handle || !handler || !data) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 return (AE_BAD_PARAMETER);
934 }
935
Len Brown4be44fc2005-08-05 00:44:28 -0400936 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
937 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 return (status);
939 }
940
941 /* Convert and validate the handle */
942
Bob Mooref24b6642009-12-11 14:57:00 +0800943 node = acpi_ns_validate_handle(obj_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 if (!node) {
945 status = AE_BAD_PARAMETER;
946 goto unlock_and_exit;
947 }
948
Len Brown4be44fc2005-08-05 00:44:28 -0400949 status = acpi_ns_get_attached_data(node, handler, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950
Len Brown4be44fc2005-08-05 00:44:28 -0400951 unlock_and_exit:
952 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 return (status);
954}
Bob Moore83135242006-10-03 00:00:00 -0400955
956ACPI_EXPORT_SYMBOL(acpi_get_data)