blob: 8167af1fa57b89933f7d32683e360b64f70403d0 [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/*
9 * Copyright (C) 2000 - 2005, R. Byron Moore
10 * 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
45#include <linux/module.h>
46
47#include <acpi/acpi.h>
48#include <acpi/acnamesp.h>
49#include <acpi/acinterp.h>
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#define _COMPONENT ACPI_NAMESPACE
Len Brown4be44fc2005-08-05 00:44:28 -040052ACPI_MODULE_NAME("nsxfeval")
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54/*******************************************************************************
55 *
56 * FUNCTION: acpi_evaluate_object_typed
57 *
58 * PARAMETERS: Handle - Object handle (optional)
Robert Moore44f6c012005-04-18 22:49:35 -040059 * Pathname - Object pathname (optional)
60 * external_params - List of parameters to pass to method,
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 * terminated by NULL. May be NULL
62 * if no parameters are being passed.
Robert Moore44f6c012005-04-18 22:49:35 -040063 * return_buffer - Where to put method's return value (if
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 * any). If NULL, no value is returned.
65 * return_type - Expected type of return object
66 *
67 * RETURN: Status
68 *
69 * DESCRIPTION: Find and evaluate the given object, passing the given
70 * parameters if necessary. One of "Handle" or "Pathname" must
71 * be valid (non-null)
72 *
73 ******************************************************************************/
74#ifdef ACPI_FUTURE_USAGE
75acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040076acpi_evaluate_object_typed(acpi_handle handle,
77 acpi_string pathname,
78 struct acpi_object_list *external_params,
79 struct acpi_buffer *return_buffer,
80 acpi_object_type return_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081{
Len Brown4be44fc2005-08-05 00:44:28 -040082 acpi_status status;
83 u8 must_free = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Len Brown4be44fc2005-08-05 00:44:28 -040085 ACPI_FUNCTION_TRACE("acpi_evaluate_object_typed");
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87 /* Return buffer must be valid */
88
89 if (!return_buffer) {
Len Brown4be44fc2005-08-05 00:44:28 -040090 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 }
92
93 if (return_buffer->length == ACPI_ALLOCATE_BUFFER) {
94 must_free = TRUE;
95 }
96
97 /* Evaluate the object */
98
Len Brown4be44fc2005-08-05 00:44:28 -040099 status =
100 acpi_evaluate_object(handle, pathname, external_params,
101 return_buffer);
102 if (ACPI_FAILURE(status)) {
103 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 }
105
106 /* Type ANY means "don't care" */
107
108 if (return_type == ACPI_TYPE_ANY) {
Len Brown4be44fc2005-08-05 00:44:28 -0400109 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 }
111
112 if (return_buffer->length == 0) {
113 /* Error because caller specifically asked for a return value */
114
Len Brown4be44fc2005-08-05 00:44:28 -0400115 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "No return value\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Len Brown4be44fc2005-08-05 00:44:28 -0400117 return_ACPI_STATUS(AE_NULL_OBJECT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 }
119
120 /* Examine the object type returned from evaluate_object */
121
Len Brown4be44fc2005-08-05 00:44:28 -0400122 if (((union acpi_object *)return_buffer->pointer)->type == return_type) {
123 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 }
125
126 /* Return object type does not match requested type */
127
Len Brown4be44fc2005-08-05 00:44:28 -0400128 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
129 "Incorrect return type [%s] requested [%s]\n",
130 acpi_ut_get_type_name(((union acpi_object *)
131 return_buffer->pointer)->type),
132 acpi_ut_get_type_name(return_type)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134 if (must_free) {
135 /* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */
136
Len Brown4be44fc2005-08-05 00:44:28 -0400137 acpi_os_free(return_buffer->pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 return_buffer->pointer = NULL;
139 }
140
141 return_buffer->length = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400142 return_ACPI_STATUS(AE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143}
Len Brown4be44fc2005-08-05 00:44:28 -0400144#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
146/*******************************************************************************
147 *
148 * FUNCTION: acpi_evaluate_object
149 *
150 * PARAMETERS: Handle - Object handle (optional)
151 * Pathname - Object pathname (optional)
152 * external_params - List of parameters to pass to method,
153 * terminated by NULL. May be NULL
154 * if no parameters are being passed.
155 * return_buffer - Where to put method's return value (if
156 * any). If NULL, no value is returned.
157 *
158 * RETURN: Status
159 *
160 * DESCRIPTION: Find and evaluate the given object, passing the given
161 * parameters if necessary. One of "Handle" or "Pathname" must
162 * be valid (non-null)
163 *
164 ******************************************************************************/
165
166acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400167acpi_evaluate_object(acpi_handle handle,
168 acpi_string pathname,
169 struct acpi_object_list *external_params,
170 struct acpi_buffer *return_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171{
Len Brown4be44fc2005-08-05 00:44:28 -0400172 acpi_status status;
173 acpi_status status2;
174 struct acpi_parameter_info info;
175 acpi_size buffer_space_needed;
176 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Len Brown4be44fc2005-08-05 00:44:28 -0400178 ACPI_FUNCTION_TRACE("acpi_evaluate_object");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180 info.node = handle;
181 info.parameters = NULL;
182 info.return_object = NULL;
183 info.parameter_type = ACPI_PARAM_ARGS;
184
185 /*
186 * If there are parameters to be passed to the object
187 * (which must be a control method), the external objects
188 * must be converted to internal objects
189 */
190 if (external_params && external_params->count) {
191 /*
192 * Allocate a new parameter block for the internal objects
193 * Add 1 to count to allow for null terminated internal list
194 */
Len Brown4be44fc2005-08-05 00:44:28 -0400195 info.parameters = ACPI_MEM_CALLOCATE(((acpi_size)
196 external_params->count +
197 1) * sizeof(void *));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 if (!info.parameters) {
Len Brown4be44fc2005-08-05 00:44:28 -0400199 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 }
201
202 /*
203 * Convert each external object in the list to an
204 * internal object
205 */
206 for (i = 0; i < external_params->count; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400207 status =
208 acpi_ut_copy_eobject_to_iobject(&external_params->
209 pointer[i],
210 &info.
211 parameters[i]);
212 if (ACPI_FAILURE(status)) {
213 acpi_ut_delete_internal_object_list(info.
214 parameters);
215 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 }
217 }
218 info.parameters[external_params->count] = NULL;
219 }
220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 /*
222 * Three major cases:
223 * 1) Fully qualified pathname
224 * 2) No handle, not fully qualified pathname (error)
225 * 3) Valid handle
226 */
Len Brown4be44fc2005-08-05 00:44:28 -0400227 if ((pathname) && (acpi_ns_valid_root_prefix(pathname[0]))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 /*
229 * The path is fully qualified, just evaluate by name
230 */
Len Brown4be44fc2005-08-05 00:44:28 -0400231 status = acpi_ns_evaluate_by_name(pathname, &info);
232 } else if (!handle) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 /*
234 * A handle is optional iff a fully qualified pathname
235 * is specified. Since we've already handled fully
236 * qualified names above, this is an error
237 */
238 if (!pathname) {
Len Brown4be44fc2005-08-05 00:44:28 -0400239 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
240 "Both Handle and Pathname are NULL\n"));
241 } else {
242 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
243 "Handle is NULL and Pathname is relative\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 }
245
246 status = AE_BAD_PARAMETER;
Len Brown4be44fc2005-08-05 00:44:28 -0400247 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 /*
249 * We get here if we have a handle -- and if we have a
250 * pathname it is relative. The handle will be validated
251 * in the lower procedures
252 */
253 if (!pathname) {
254 /*
255 * The null pathname case means the handle is for
256 * the actual object to be evaluated
257 */
Len Brown4be44fc2005-08-05 00:44:28 -0400258 status = acpi_ns_evaluate_by_handle(&info);
259 } else {
260 /*
261 * Both a Handle and a relative Pathname
262 */
263 status = acpi_ns_evaluate_relative(pathname, &info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 }
265 }
266
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 /*
268 * If we are expecting a return value, and all went well above,
269 * copy the return value to an external object.
270 */
271 if (return_buffer) {
272 if (!info.return_object) {
273 return_buffer->length = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400274 } else {
275 if (ACPI_GET_DESCRIPTOR_TYPE(info.return_object) ==
276 ACPI_DESC_TYPE_NAMED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 /*
278 * If we received a NS Node as a return object, this means that
279 * the object we are evaluating has nothing interesting to
280 * return (such as a mutex, etc.) We return an error because
281 * these types are essentially unsupported by this interface.
282 * We don't check up front because this makes it easier to add
283 * support for various types at a later date if necessary.
284 */
285 status = AE_TYPE;
Len Brown4be44fc2005-08-05 00:44:28 -0400286 info.return_object = NULL; /* No need to delete a NS Node */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 return_buffer->length = 0;
288 }
289
Len Brown4be44fc2005-08-05 00:44:28 -0400290 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 /*
292 * Find out how large a buffer is needed
293 * to contain the returned object
294 */
Len Brown4be44fc2005-08-05 00:44:28 -0400295 status =
296 acpi_ut_get_object_size(info.return_object,
297 &buffer_space_needed);
298 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 /* Validate/Allocate/Clear caller buffer */
300
Len Brown4be44fc2005-08-05 00:44:28 -0400301 status =
302 acpi_ut_initialize_buffer
303 (return_buffer,
304 buffer_space_needed);
305 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 /*
307 * Caller's buffer is too small or a new one can't be allocated
308 */
Len Brown4be44fc2005-08-05 00:44:28 -0400309 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
310 "Needed buffer size %X, %s\n",
311 (u32)
312 buffer_space_needed,
313 acpi_format_exception
314 (status)));
315 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 /*
317 * We have enough space for the object, build it
318 */
Len Brown4be44fc2005-08-05 00:44:28 -0400319 status =
320 acpi_ut_copy_iobject_to_eobject
321 (info.return_object,
322 return_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 }
324 }
325 }
326 }
327 }
328
329 if (info.return_object) {
330 /*
331 * Delete the internal return object. NOTE: Interpreter
332 * must be locked to avoid race condition.
333 */
Len Brown4be44fc2005-08-05 00:44:28 -0400334 status2 = acpi_ex_enter_interpreter();
335 if (ACPI_SUCCESS(status2)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 /*
337 * Delete the internal return object. (Or at least
338 * decrement the reference count by one)
339 */
Len Brown4be44fc2005-08-05 00:44:28 -0400340 acpi_ut_remove_reference(info.return_object);
341 acpi_ex_exit_interpreter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 }
343 }
344
345 /*
346 * Free the input parameter list (if we created one),
347 */
348 if (info.parameters) {
349 /* Free the allocated parameter block */
350
Len Brown4be44fc2005-08-05 00:44:28 -0400351 acpi_ut_delete_internal_object_list(info.parameters);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 }
353
Len Brown4be44fc2005-08-05 00:44:28 -0400354 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
Len Brown4be44fc2005-08-05 00:44:28 -0400357EXPORT_SYMBOL(acpi_evaluate_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
359/*******************************************************************************
360 *
361 * FUNCTION: acpi_walk_namespace
362 *
363 * PARAMETERS: Type - acpi_object_type to search for
364 * start_object - Handle in namespace where search begins
365 * max_depth - Depth to which search is to reach
366 * user_function - Called when an object of "Type" is found
367 * Context - Passed to user function
368 * return_value - Location where return value of
369 * user_function is put if terminated early
370 *
371 * RETURNS Return value from the user_function if terminated early.
372 * Otherwise, returns NULL.
373 *
374 * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
375 * starting (and ending) at the object specified by start_handle.
376 * The user_function is called whenever an object that matches
377 * the type parameter is found. If the user function returns
378 * a non-zero value, the search is terminated immediately and this
379 * value is returned to the caller.
380 *
381 * The point of this procedure is to provide a generic namespace
382 * walk routine that can be called from multiple places to
383 * provide multiple services; the User Function can be tailored
384 * to each task, whether it is a print function, a compare
385 * function, etc.
386 *
387 ******************************************************************************/
388
389acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400390acpi_walk_namespace(acpi_object_type type,
391 acpi_handle start_object,
392 u32 max_depth,
393 acpi_walk_callback user_function,
394 void *context, void **return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395{
Len Brown4be44fc2005-08-05 00:44:28 -0400396 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
Len Brown4be44fc2005-08-05 00:44:28 -0400398 ACPI_FUNCTION_TRACE("acpi_walk_namespace");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
400 /* Parameter validation */
401
Bob Moore96db2552005-11-02 00:00:00 -0500402 if ((type > ACPI_TYPE_LOCAL_MAX) || (!max_depth) || (!user_function)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400403 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 }
405
406 /*
407 * Lock the namespace around the walk.
408 * The namespace will be unlocked/locked around each call
409 * to the user function - since this function
410 * must be allowed to make Acpi calls itself.
411 */
Len Brown4be44fc2005-08-05 00:44:28 -0400412 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
413 if (ACPI_FAILURE(status)) {
414 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 }
416
Len Brown4be44fc2005-08-05 00:44:28 -0400417 status = acpi_ns_walk_namespace(type, start_object, max_depth,
418 ACPI_NS_WALK_UNLOCK,
419 user_function, context, return_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
Len Brown4be44fc2005-08-05 00:44:28 -0400421 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
422 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
Len Brown4be44fc2005-08-05 00:44:28 -0400425EXPORT_SYMBOL(acpi_walk_namespace);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
427/*******************************************************************************
428 *
429 * FUNCTION: acpi_ns_get_device_callback
430 *
431 * PARAMETERS: Callback from acpi_get_device
432 *
433 * RETURN: Status
434 *
435 * DESCRIPTION: Takes callbacks from walk_namespace and filters out all non-
436 * present devices, or if they specified a HID, it filters based
437 * on that.
438 *
439 ******************************************************************************/
440
441static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400442acpi_ns_get_device_callback(acpi_handle obj_handle,
443 u32 nesting_level,
444 void *context, void **return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445{
Len Brown4be44fc2005-08-05 00:44:28 -0400446 struct acpi_get_devices_info *info = context;
447 acpi_status status;
448 struct acpi_namespace_node *node;
449 u32 flags;
450 struct acpi_device_id hid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 struct acpi_compatible_id_list *cid;
Len Brown4be44fc2005-08-05 00:44:28 -0400452 acpi_native_uint i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
Len Brown4be44fc2005-08-05 00:44:28 -0400454 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
455 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 return (status);
457 }
458
Len Brown4be44fc2005-08-05 00:44:28 -0400459 node = acpi_ns_map_handle_to_node(obj_handle);
460 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
461 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 return (status);
463 }
464
465 if (!node) {
466 return (AE_BAD_PARAMETER);
467 }
468
469 /* Run _STA to determine if device is present */
470
Len Brown4be44fc2005-08-05 00:44:28 -0400471 status = acpi_ut_execute_STA(node, &flags);
472 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 return (AE_CTRL_DEPTH);
474 }
475
476 if (!(flags & 0x01)) {
477 /* Don't return at the device or children of the device if not there */
478
479 return (AE_CTRL_DEPTH);
480 }
481
482 /* Filter based on device HID & CID */
483
484 if (info->hid != NULL) {
Len Brown4be44fc2005-08-05 00:44:28 -0400485 status = acpi_ut_execute_HID(node, &hid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 if (status == AE_NOT_FOUND) {
487 return (AE_OK);
Len Brown4be44fc2005-08-05 00:44:28 -0400488 } else if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 return (AE_CTRL_DEPTH);
490 }
491
Len Brown4be44fc2005-08-05 00:44:28 -0400492 if (ACPI_STRNCMP(hid.value, info->hid, sizeof(hid.value)) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 /* Get the list of Compatible IDs */
494
Len Brown4be44fc2005-08-05 00:44:28 -0400495 status = acpi_ut_execute_CID(node, &cid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 if (status == AE_NOT_FOUND) {
497 return (AE_OK);
Len Brown4be44fc2005-08-05 00:44:28 -0400498 } else if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 return (AE_CTRL_DEPTH);
500 }
501
502 /* Walk the CID list */
503
504 for (i = 0; i < cid->count; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400505 if (ACPI_STRNCMP(cid->id[i].value, info->hid,
506 sizeof(struct
507 acpi_compatible_id)) !=
508 0) {
509 ACPI_MEM_FREE(cid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 return (AE_OK);
511 }
512 }
Len Brown4be44fc2005-08-05 00:44:28 -0400513 ACPI_MEM_FREE(cid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 }
515 }
516
Len Brown4be44fc2005-08-05 00:44:28 -0400517 status = info->user_function(obj_handle, nesting_level, info->context,
518 return_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 return (status);
520}
521
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522/*******************************************************************************
523 *
524 * FUNCTION: acpi_get_devices
525 *
526 * PARAMETERS: HID - HID to search for. Can be NULL.
527 * user_function - Called when a matching object is found
528 * Context - Passed to user function
529 * return_value - Location where return value of
530 * user_function is put if terminated early
531 *
532 * RETURNS Return value from the user_function if terminated early.
533 * Otherwise, returns NULL.
534 *
535 * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
536 * starting (and ending) at the object specified by start_handle.
537 * The user_function is called whenever an object of type
538 * Device is found. If the user function returns
539 * a non-zero value, the search is terminated immediately and this
540 * value is returned to the caller.
541 *
542 * This is a wrapper for walk_namespace, but the callback performs
543 * additional filtering. Please see acpi_get_device_callback.
544 *
545 ******************************************************************************/
546
547acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400548acpi_get_devices(char *HID,
549 acpi_walk_callback user_function,
550 void *context, void **return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551{
Len Brown4be44fc2005-08-05 00:44:28 -0400552 acpi_status status;
553 struct acpi_get_devices_info info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
Len Brown4be44fc2005-08-05 00:44:28 -0400555 ACPI_FUNCTION_TRACE("acpi_get_devices");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
557 /* Parameter validation */
558
559 if (!user_function) {
Len Brown4be44fc2005-08-05 00:44:28 -0400560 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 }
562
563 /*
564 * We're going to call their callback from OUR callback, so we need
565 * to know what it is, and their context parameter.
566 */
Len Brown4be44fc2005-08-05 00:44:28 -0400567 info.context = context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 info.user_function = user_function;
Len Brown4be44fc2005-08-05 00:44:28 -0400569 info.hid = HID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
571 /*
572 * Lock the namespace around the walk.
573 * The namespace will be unlocked/locked around each call
574 * to the user function - since this function
575 * must be allowed to make Acpi calls itself.
576 */
Len Brown4be44fc2005-08-05 00:44:28 -0400577 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
578 if (ACPI_FAILURE(status)) {
579 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 }
581
Len Brown4be44fc2005-08-05 00:44:28 -0400582 status = acpi_ns_walk_namespace(ACPI_TYPE_DEVICE,
583 ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
584 ACPI_NS_WALK_UNLOCK,
585 acpi_ns_get_device_callback, &info,
586 return_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
Len Brown4be44fc2005-08-05 00:44:28 -0400588 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
589 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
Len Brown4be44fc2005-08-05 00:44:28 -0400592EXPORT_SYMBOL(acpi_get_devices);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593
594/*******************************************************************************
595 *
596 * FUNCTION: acpi_attach_data
597 *
598 * PARAMETERS: obj_handle - Namespace node
599 * Handler - Handler for this attachment
600 * Data - Pointer to data to be attached
601 *
602 * RETURN: Status
603 *
604 * DESCRIPTION: Attach arbitrary data and handler to a namespace node.
605 *
606 ******************************************************************************/
607
608acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400609acpi_attach_data(acpi_handle obj_handle,
610 acpi_object_handler handler, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611{
Len Brown4be44fc2005-08-05 00:44:28 -0400612 struct acpi_namespace_node *node;
613 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
615 /* Parameter validation */
616
Len Brown4be44fc2005-08-05 00:44:28 -0400617 if (!obj_handle || !handler || !data) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 return (AE_BAD_PARAMETER);
619 }
620
Len Brown4be44fc2005-08-05 00:44:28 -0400621 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
622 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 return (status);
624 }
625
626 /* Convert and validate the handle */
627
Len Brown4be44fc2005-08-05 00:44:28 -0400628 node = acpi_ns_map_handle_to_node(obj_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 if (!node) {
630 status = AE_BAD_PARAMETER;
631 goto unlock_and_exit;
632 }
633
Len Brown4be44fc2005-08-05 00:44:28 -0400634 status = acpi_ns_attach_data(node, handler, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
Len Brown4be44fc2005-08-05 00:44:28 -0400636 unlock_and_exit:
637 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 return (status);
639}
640
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641/*******************************************************************************
642 *
643 * FUNCTION: acpi_detach_data
644 *
645 * PARAMETERS: obj_handle - Namespace node handle
646 * Handler - Handler used in call to acpi_attach_data
647 *
648 * RETURN: Status
649 *
650 * DESCRIPTION: Remove data that was previously attached to a node.
651 *
652 ******************************************************************************/
653
654acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400655acpi_detach_data(acpi_handle obj_handle, acpi_object_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656{
Len Brown4be44fc2005-08-05 00:44:28 -0400657 struct acpi_namespace_node *node;
658 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
660 /* Parameter validation */
661
Len Brown4be44fc2005-08-05 00:44:28 -0400662 if (!obj_handle || !handler) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 return (AE_BAD_PARAMETER);
664 }
665
Len Brown4be44fc2005-08-05 00:44:28 -0400666 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
667 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 return (status);
669 }
670
671 /* Convert and validate the handle */
672
Len Brown4be44fc2005-08-05 00:44:28 -0400673 node = acpi_ns_map_handle_to_node(obj_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 if (!node) {
675 status = AE_BAD_PARAMETER;
676 goto unlock_and_exit;
677 }
678
Len Brown4be44fc2005-08-05 00:44:28 -0400679 status = acpi_ns_detach_data(node, handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680
Len Brown4be44fc2005-08-05 00:44:28 -0400681 unlock_and_exit:
682 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 return (status);
684}
685
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686/*******************************************************************************
687 *
688 * FUNCTION: acpi_get_data
689 *
690 * PARAMETERS: obj_handle - Namespace node
691 * Handler - Handler used in call to attach_data
692 * Data - Where the data is returned
693 *
694 * RETURN: Status
695 *
696 * DESCRIPTION: Retrieve data that was previously attached to a namespace node.
697 *
698 ******************************************************************************/
699
700acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400701acpi_get_data(acpi_handle obj_handle, acpi_object_handler handler, void **data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702{
Len Brown4be44fc2005-08-05 00:44:28 -0400703 struct acpi_namespace_node *node;
704 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
706 /* Parameter validation */
707
Len Brown4be44fc2005-08-05 00:44:28 -0400708 if (!obj_handle || !handler || !data) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 return (AE_BAD_PARAMETER);
710 }
711
Len Brown4be44fc2005-08-05 00:44:28 -0400712 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
713 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 return (status);
715 }
716
717 /* Convert and validate the handle */
718
Len Brown4be44fc2005-08-05 00:44:28 -0400719 node = acpi_ns_map_handle_to_node(obj_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 if (!node) {
721 status = AE_BAD_PARAMETER;
722 goto unlock_and_exit;
723 }
724
Len Brown4be44fc2005-08-05 00:44:28 -0400725 status = acpi_ns_get_attached_data(node, handler, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726
Len Brown4be44fc2005-08-05 00:44:28 -0400727 unlock_and_exit:
728 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 return (status);
730}