blob: a95f636dc35d454e16865732cff8e4c57ab3731f [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 Moore4a90c7e2006-01-13 16:22:00 -05009 * Copyright (C) 2000 - 2006, R. Byron Moore
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
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
Bob Mooreb8e4d892006-01-27 16:43:00 -0500115 ACPI_ERROR((AE_INFO, "No return value"));
Len Brown4be44fc2005-08-05 00:44:28 -0400116 return_ACPI_STATUS(AE_NULL_OBJECT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 }
118
119 /* Examine the object type returned from evaluate_object */
120
Len Brown4be44fc2005-08-05 00:44:28 -0400121 if (((union acpi_object *)return_buffer->pointer)->type == return_type) {
122 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 }
124
125 /* Return object type does not match requested type */
126
Bob Mooreb8e4d892006-01-27 16:43:00 -0500127 ACPI_ERROR((AE_INFO,
128 "Incorrect return type [%s] requested [%s]",
129 acpi_ut_get_type_name(((union acpi_object *)return_buffer->
130 pointer)->type),
131 acpi_ut_get_type_name(return_type)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133 if (must_free) {
134 /* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */
135
Len Brown4be44fc2005-08-05 00:44:28 -0400136 acpi_os_free(return_buffer->pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 return_buffer->pointer = NULL;
138 }
139
140 return_buffer->length = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400141 return_ACPI_STATUS(AE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142}
Len Brown4be44fc2005-08-05 00:44:28 -0400143#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145/*******************************************************************************
146 *
147 * FUNCTION: acpi_evaluate_object
148 *
149 * PARAMETERS: Handle - Object handle (optional)
150 * Pathname - Object pathname (optional)
151 * external_params - List of parameters to pass to method,
152 * terminated by NULL. May be NULL
153 * if no parameters are being passed.
154 * return_buffer - Where to put method's return value (if
155 * any). If NULL, no value is returned.
156 *
157 * RETURN: Status
158 *
159 * DESCRIPTION: Find and evaluate the given object, passing the given
160 * parameters if necessary. One of "Handle" or "Pathname" must
161 * be valid (non-null)
162 *
163 ******************************************************************************/
164
165acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400166acpi_evaluate_object(acpi_handle handle,
167 acpi_string pathname,
168 struct acpi_object_list *external_params,
169 struct acpi_buffer *return_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170{
Len Brown4be44fc2005-08-05 00:44:28 -0400171 acpi_status status;
172 acpi_status status2;
173 struct acpi_parameter_info info;
174 acpi_size buffer_space_needed;
175 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
Len Brown4be44fc2005-08-05 00:44:28 -0400177 ACPI_FUNCTION_TRACE("acpi_evaluate_object");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
179 info.node = handle;
180 info.parameters = NULL;
181 info.return_object = NULL;
182 info.parameter_type = ACPI_PARAM_ARGS;
183
184 /*
185 * If there are parameters to be passed to the object
186 * (which must be a control method), the external objects
187 * must be converted to internal objects
188 */
189 if (external_params && external_params->count) {
190 /*
191 * Allocate a new parameter block for the internal objects
192 * Add 1 to count to allow for null terminated internal list
193 */
Len Brown4be44fc2005-08-05 00:44:28 -0400194 info.parameters = ACPI_MEM_CALLOCATE(((acpi_size)
195 external_params->count +
196 1) * sizeof(void *));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 if (!info.parameters) {
Len Brown4be44fc2005-08-05 00:44:28 -0400198 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 }
200
201 /*
202 * Convert each external object in the list to an
203 * internal object
204 */
205 for (i = 0; i < external_params->count; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400206 status =
207 acpi_ut_copy_eobject_to_iobject(&external_params->
208 pointer[i],
209 &info.
210 parameters[i]);
211 if (ACPI_FAILURE(status)) {
212 acpi_ut_delete_internal_object_list(info.
213 parameters);
214 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 }
216 }
217 info.parameters[external_params->count] = NULL;
218 }
219
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 /*
221 * Three major cases:
222 * 1) Fully qualified pathname
223 * 2) No handle, not fully qualified pathname (error)
224 * 3) Valid handle
225 */
Len Brown4be44fc2005-08-05 00:44:28 -0400226 if ((pathname) && (acpi_ns_valid_root_prefix(pathname[0]))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 /*
228 * The path is fully qualified, just evaluate by name
229 */
Len Brown4be44fc2005-08-05 00:44:28 -0400230 status = acpi_ns_evaluate_by_name(pathname, &info);
231 } else if (!handle) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 /*
233 * A handle is optional iff a fully qualified pathname
234 * is specified. Since we've already handled fully
235 * qualified names above, this is an error
236 */
237 if (!pathname) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500238 ACPI_ERROR((AE_INFO,
239 "Both Handle and Pathname are NULL"));
Len Brown4be44fc2005-08-05 00:44:28 -0400240 } else {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500241 ACPI_ERROR((AE_INFO,
242 "Handle is NULL and Pathname is relative"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 }
244
245 status = AE_BAD_PARAMETER;
Len Brown4be44fc2005-08-05 00:44:28 -0400246 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 /*
248 * We get here if we have a handle -- and if we have a
249 * pathname it is relative. The handle will be validated
250 * in the lower procedures
251 */
252 if (!pathname) {
253 /*
254 * The null pathname case means the handle is for
255 * the actual object to be evaluated
256 */
Len Brown4be44fc2005-08-05 00:44:28 -0400257 status = acpi_ns_evaluate_by_handle(&info);
258 } else {
259 /*
260 * Both a Handle and a relative Pathname
261 */
262 status = acpi_ns_evaluate_relative(pathname, &info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 }
264 }
265
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 /*
267 * If we are expecting a return value, and all went well above,
268 * copy the return value to an external object.
269 */
270 if (return_buffer) {
271 if (!info.return_object) {
272 return_buffer->length = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400273 } else {
274 if (ACPI_GET_DESCRIPTOR_TYPE(info.return_object) ==
275 ACPI_DESC_TYPE_NAMED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 /*
277 * If we received a NS Node as a return object, this means that
278 * the object we are evaluating has nothing interesting to
279 * return (such as a mutex, etc.) We return an error because
280 * these types are essentially unsupported by this interface.
281 * We don't check up front because this makes it easier to add
282 * support for various types at a later date if necessary.
283 */
284 status = AE_TYPE;
Len Brown4be44fc2005-08-05 00:44:28 -0400285 info.return_object = NULL; /* No need to delete a NS Node */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 return_buffer->length = 0;
287 }
288
Len Brown4be44fc2005-08-05 00:44:28 -0400289 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 /*
291 * Find out how large a buffer is needed
292 * to contain the returned object
293 */
Len Brown4be44fc2005-08-05 00:44:28 -0400294 status =
295 acpi_ut_get_object_size(info.return_object,
296 &buffer_space_needed);
297 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 /* Validate/Allocate/Clear caller buffer */
299
Len Brown4be44fc2005-08-05 00:44:28 -0400300 status =
301 acpi_ut_initialize_buffer
302 (return_buffer,
303 buffer_space_needed);
304 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 /*
306 * Caller's buffer is too small or a new one can't be allocated
307 */
Len Brown4be44fc2005-08-05 00:44:28 -0400308 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
309 "Needed buffer size %X, %s\n",
310 (u32)
311 buffer_space_needed,
312 acpi_format_exception
313 (status)));
314 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 /*
316 * We have enough space for the object, build it
317 */
Len Brown4be44fc2005-08-05 00:44:28 -0400318 status =
319 acpi_ut_copy_iobject_to_eobject
320 (info.return_object,
321 return_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 }
323 }
324 }
325 }
326 }
327
328 if (info.return_object) {
329 /*
330 * Delete the internal return object. NOTE: Interpreter
331 * must be locked to avoid race condition.
332 */
Len Brown4be44fc2005-08-05 00:44:28 -0400333 status2 = acpi_ex_enter_interpreter();
334 if (ACPI_SUCCESS(status2)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 /*
336 * Delete the internal return object. (Or at least
337 * decrement the reference count by one)
338 */
Len Brown4be44fc2005-08-05 00:44:28 -0400339 acpi_ut_remove_reference(info.return_object);
340 acpi_ex_exit_interpreter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 }
342 }
343
344 /*
345 * Free the input parameter list (if we created one),
346 */
347 if (info.parameters) {
348 /* Free the allocated parameter block */
349
Len Brown4be44fc2005-08-05 00:44:28 -0400350 acpi_ut_delete_internal_object_list(info.parameters);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 }
352
Len Brown4be44fc2005-08-05 00:44:28 -0400353 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
Len Brown4be44fc2005-08-05 00:44:28 -0400356EXPORT_SYMBOL(acpi_evaluate_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
358/*******************************************************************************
359 *
360 * FUNCTION: acpi_walk_namespace
361 *
362 * PARAMETERS: Type - acpi_object_type to search for
363 * start_object - Handle in namespace where search begins
364 * max_depth - Depth to which search is to reach
365 * user_function - Called when an object of "Type" is found
366 * Context - Passed to user function
367 * return_value - Location where return value of
368 * user_function is put if terminated early
369 *
370 * RETURNS Return value from the user_function if terminated early.
371 * Otherwise, returns NULL.
372 *
373 * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
374 * starting (and ending) at the object specified by start_handle.
375 * The user_function is called whenever an object that matches
376 * the type parameter is found. If the user function returns
377 * a non-zero value, the search is terminated immediately and this
378 * value is returned to the caller.
379 *
380 * The point of this procedure is to provide a generic namespace
381 * walk routine that can be called from multiple places to
382 * provide multiple services; the User Function can be tailored
383 * to each task, whether it is a print function, a compare
384 * function, etc.
385 *
386 ******************************************************************************/
387
388acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400389acpi_walk_namespace(acpi_object_type type,
390 acpi_handle start_object,
391 u32 max_depth,
392 acpi_walk_callback user_function,
393 void *context, void **return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394{
Len Brown4be44fc2005-08-05 00:44:28 -0400395 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
Len Brown4be44fc2005-08-05 00:44:28 -0400397 ACPI_FUNCTION_TRACE("acpi_walk_namespace");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
399 /* Parameter validation */
400
Bob Moore96db2552005-11-02 00:00:00 -0500401 if ((type > ACPI_TYPE_LOCAL_MAX) || (!max_depth) || (!user_function)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400402 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 }
404
405 /*
406 * Lock the namespace around the walk.
407 * The namespace will be unlocked/locked around each call
408 * to the user function - since this function
409 * must be allowed to make Acpi calls itself.
410 */
Len Brown4be44fc2005-08-05 00:44:28 -0400411 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
412 if (ACPI_FAILURE(status)) {
413 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 }
415
Len Brown4be44fc2005-08-05 00:44:28 -0400416 status = acpi_ns_walk_namespace(type, start_object, max_depth,
417 ACPI_NS_WALK_UNLOCK,
418 user_function, context, return_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
Len Brown4be44fc2005-08-05 00:44:28 -0400420 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
421 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Len Brown4be44fc2005-08-05 00:44:28 -0400424EXPORT_SYMBOL(acpi_walk_namespace);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
426/*******************************************************************************
427 *
428 * FUNCTION: acpi_ns_get_device_callback
429 *
430 * PARAMETERS: Callback from acpi_get_device
431 *
432 * RETURN: Status
433 *
434 * DESCRIPTION: Takes callbacks from walk_namespace and filters out all non-
435 * present devices, or if they specified a HID, it filters based
436 * on that.
437 *
438 ******************************************************************************/
439
440static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400441acpi_ns_get_device_callback(acpi_handle obj_handle,
442 u32 nesting_level,
443 void *context, void **return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444{
Len Brown4be44fc2005-08-05 00:44:28 -0400445 struct acpi_get_devices_info *info = context;
446 acpi_status status;
447 struct acpi_namespace_node *node;
448 u32 flags;
449 struct acpi_device_id hid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 struct acpi_compatible_id_list *cid;
Len Brown4be44fc2005-08-05 00:44:28 -0400451 acpi_native_uint i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
Len Brown4be44fc2005-08-05 00:44:28 -0400453 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
454 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 return (status);
456 }
457
Len Brown4be44fc2005-08-05 00:44:28 -0400458 node = acpi_ns_map_handle_to_node(obj_handle);
459 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
460 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 return (status);
462 }
463
464 if (!node) {
465 return (AE_BAD_PARAMETER);
466 }
467
468 /* Run _STA to determine if device is present */
469
Len Brown4be44fc2005-08-05 00:44:28 -0400470 status = acpi_ut_execute_STA(node, &flags);
471 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 return (AE_CTRL_DEPTH);
473 }
474
Bob Mooredefba1d2005-12-16 17:05:00 -0500475 if (!(flags & ACPI_STA_DEVICE_PRESENT)) {
476 /* Don't examine children of the device if not present */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
478 return (AE_CTRL_DEPTH);
479 }
480
481 /* Filter based on device HID & CID */
482
483 if (info->hid != NULL) {
Len Brown4be44fc2005-08-05 00:44:28 -0400484 status = acpi_ut_execute_HID(node, &hid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 if (status == AE_NOT_FOUND) {
486 return (AE_OK);
Len Brown4be44fc2005-08-05 00:44:28 -0400487 } else if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 return (AE_CTRL_DEPTH);
489 }
490
Len Brown4be44fc2005-08-05 00:44:28 -0400491 if (ACPI_STRNCMP(hid.value, info->hid, sizeof(hid.value)) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 /* Get the list of Compatible IDs */
493
Len Brown4be44fc2005-08-05 00:44:28 -0400494 status = acpi_ut_execute_CID(node, &cid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 if (status == AE_NOT_FOUND) {
496 return (AE_OK);
Len Brown4be44fc2005-08-05 00:44:28 -0400497 } else if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 return (AE_CTRL_DEPTH);
499 }
500
501 /* Walk the CID list */
502
503 for (i = 0; i < cid->count; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400504 if (ACPI_STRNCMP(cid->id[i].value, info->hid,
505 sizeof(struct
506 acpi_compatible_id)) !=
507 0) {
508 ACPI_MEM_FREE(cid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 return (AE_OK);
510 }
511 }
Len Brown4be44fc2005-08-05 00:44:28 -0400512 ACPI_MEM_FREE(cid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 }
514 }
515
Len Brown4be44fc2005-08-05 00:44:28 -0400516 status = info->user_function(obj_handle, nesting_level, info->context,
517 return_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 return (status);
519}
520
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521/*******************************************************************************
522 *
523 * FUNCTION: acpi_get_devices
524 *
525 * PARAMETERS: HID - HID to search for. Can be NULL.
526 * user_function - Called when a matching object is found
527 * Context - Passed to user function
528 * return_value - Location where return value of
529 * user_function is put if terminated early
530 *
531 * RETURNS Return value from the user_function if terminated early.
532 * Otherwise, returns NULL.
533 *
534 * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
535 * starting (and ending) at the object specified by start_handle.
536 * The user_function is called whenever an object of type
537 * Device is found. If the user function returns
538 * a non-zero value, the search is terminated immediately and this
539 * value is returned to the caller.
540 *
541 * This is a wrapper for walk_namespace, but the callback performs
542 * additional filtering. Please see acpi_get_device_callback.
543 *
544 ******************************************************************************/
545
546acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400547acpi_get_devices(char *HID,
548 acpi_walk_callback user_function,
549 void *context, void **return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550{
Len Brown4be44fc2005-08-05 00:44:28 -0400551 acpi_status status;
552 struct acpi_get_devices_info info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
Len Brown4be44fc2005-08-05 00:44:28 -0400554 ACPI_FUNCTION_TRACE("acpi_get_devices");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
556 /* Parameter validation */
557
558 if (!user_function) {
Len Brown4be44fc2005-08-05 00:44:28 -0400559 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 }
561
562 /*
563 * We're going to call their callback from OUR callback, so we need
564 * to know what it is, and their context parameter.
565 */
Len Brown4be44fc2005-08-05 00:44:28 -0400566 info.context = context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 info.user_function = user_function;
Len Brown4be44fc2005-08-05 00:44:28 -0400568 info.hid = HID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
570 /*
571 * Lock the namespace around the walk.
572 * The namespace will be unlocked/locked around each call
573 * to the user function - since this function
574 * must be allowed to make Acpi calls itself.
575 */
Len Brown4be44fc2005-08-05 00:44:28 -0400576 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
577 if (ACPI_FAILURE(status)) {
578 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 }
580
Len Brown4be44fc2005-08-05 00:44:28 -0400581 status = acpi_ns_walk_namespace(ACPI_TYPE_DEVICE,
582 ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
583 ACPI_NS_WALK_UNLOCK,
584 acpi_ns_get_device_callback, &info,
585 return_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
Len Brown4be44fc2005-08-05 00:44:28 -0400587 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
588 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
Len Brown4be44fc2005-08-05 00:44:28 -0400591EXPORT_SYMBOL(acpi_get_devices);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
593/*******************************************************************************
594 *
595 * FUNCTION: acpi_attach_data
596 *
597 * PARAMETERS: obj_handle - Namespace node
598 * Handler - Handler for this attachment
599 * Data - Pointer to data to be attached
600 *
601 * RETURN: Status
602 *
603 * DESCRIPTION: Attach arbitrary data and handler to a namespace node.
604 *
605 ******************************************************************************/
606
607acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400608acpi_attach_data(acpi_handle obj_handle,
609 acpi_object_handler handler, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610{
Len Brown4be44fc2005-08-05 00:44:28 -0400611 struct acpi_namespace_node *node;
612 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
614 /* Parameter validation */
615
Len Brown4be44fc2005-08-05 00:44:28 -0400616 if (!obj_handle || !handler || !data) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 return (AE_BAD_PARAMETER);
618 }
619
Len Brown4be44fc2005-08-05 00:44:28 -0400620 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
621 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 return (status);
623 }
624
625 /* Convert and validate the handle */
626
Len Brown4be44fc2005-08-05 00:44:28 -0400627 node = acpi_ns_map_handle_to_node(obj_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 if (!node) {
629 status = AE_BAD_PARAMETER;
630 goto unlock_and_exit;
631 }
632
Len Brown4be44fc2005-08-05 00:44:28 -0400633 status = acpi_ns_attach_data(node, handler, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
Len Brown4be44fc2005-08-05 00:44:28 -0400635 unlock_and_exit:
636 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 return (status);
638}
639
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640/*******************************************************************************
641 *
642 * FUNCTION: acpi_detach_data
643 *
644 * PARAMETERS: obj_handle - Namespace node handle
645 * Handler - Handler used in call to acpi_attach_data
646 *
647 * RETURN: Status
648 *
649 * DESCRIPTION: Remove data that was previously attached to a node.
650 *
651 ******************************************************************************/
652
653acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400654acpi_detach_data(acpi_handle obj_handle, acpi_object_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655{
Len Brown4be44fc2005-08-05 00:44:28 -0400656 struct acpi_namespace_node *node;
657 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
659 /* Parameter validation */
660
Len Brown4be44fc2005-08-05 00:44:28 -0400661 if (!obj_handle || !handler) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 return (AE_BAD_PARAMETER);
663 }
664
Len Brown4be44fc2005-08-05 00:44:28 -0400665 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
666 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 return (status);
668 }
669
670 /* Convert and validate the handle */
671
Len Brown4be44fc2005-08-05 00:44:28 -0400672 node = acpi_ns_map_handle_to_node(obj_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 if (!node) {
674 status = AE_BAD_PARAMETER;
675 goto unlock_and_exit;
676 }
677
Len Brown4be44fc2005-08-05 00:44:28 -0400678 status = acpi_ns_detach_data(node, handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
Len Brown4be44fc2005-08-05 00:44:28 -0400680 unlock_and_exit:
681 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 return (status);
683}
684
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685/*******************************************************************************
686 *
687 * FUNCTION: acpi_get_data
688 *
689 * PARAMETERS: obj_handle - Namespace node
690 * Handler - Handler used in call to attach_data
691 * Data - Where the data is returned
692 *
693 * RETURN: Status
694 *
695 * DESCRIPTION: Retrieve data that was previously attached to a namespace node.
696 *
697 ******************************************************************************/
698
699acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400700acpi_get_data(acpi_handle obj_handle, acpi_object_handler handler, void **data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701{
Len Brown4be44fc2005-08-05 00:44:28 -0400702 struct acpi_namespace_node *node;
703 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
705 /* Parameter validation */
706
Len Brown4be44fc2005-08-05 00:44:28 -0400707 if (!obj_handle || !handler || !data) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 return (AE_BAD_PARAMETER);
709 }
710
Len Brown4be44fc2005-08-05 00:44:28 -0400711 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
712 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 return (status);
714 }
715
716 /* Convert and validate the handle */
717
Len Brown4be44fc2005-08-05 00:44:28 -0400718 node = acpi_ns_map_handle_to_node(obj_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 if (!node) {
720 status = AE_BAD_PARAMETER;
721 goto unlock_and_exit;
722 }
723
Len Brown4be44fc2005-08-05 00:44:28 -0400724 status = acpi_ns_get_attached_data(node, handler, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
Len Brown4be44fc2005-08-05 00:44:28 -0400726 unlock_and_exit:
727 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 return (status);
729}