blob: 71e7769d7dafcf66653cbb0d9ebb0f9e34c9b9c7 [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) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 /* Error because caller specifically asked for a return value */
115
Bob Mooreb8e4d892006-01-27 16:43:00 -0500116 ACPI_ERROR((AE_INFO, "No return value"));
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
Bob Mooreb8e4d892006-01-27 16:43:00 -0500128 ACPI_ERROR((AE_INFO,
129 "Incorrect return type [%s] requested [%s]",
130 acpi_ut_get_type_name(((union acpi_object *)return_buffer->
131 pointer)->type),
132 acpi_ut_get_type_name(return_type)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134 if (must_free) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 /* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */
137
Len Brown4be44fc2005-08-05 00:44:28 -0400138 acpi_os_free(return_buffer->pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 return_buffer->pointer = NULL;
140 }
141
142 return_buffer->length = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400143 return_ACPI_STATUS(AE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144}
Len Brown4be44fc2005-08-05 00:44:28 -0400145#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
147/*******************************************************************************
148 *
149 * FUNCTION: acpi_evaluate_object
150 *
151 * PARAMETERS: Handle - Object handle (optional)
152 * Pathname - Object pathname (optional)
153 * external_params - List of parameters to pass to method,
154 * terminated by NULL. May be NULL
155 * if no parameters are being passed.
156 * return_buffer - Where to put method's return value (if
157 * any). If NULL, no value is returned.
158 *
159 * RETURN: Status
160 *
161 * DESCRIPTION: Find and evaluate the given object, passing the given
162 * parameters if necessary. One of "Handle" or "Pathname" must
163 * be valid (non-null)
164 *
165 ******************************************************************************/
166
167acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400168acpi_evaluate_object(acpi_handle handle,
169 acpi_string pathname,
170 struct acpi_object_list *external_params,
171 struct acpi_buffer *return_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172{
Len Brown4be44fc2005-08-05 00:44:28 -0400173 acpi_status status;
174 acpi_status status2;
175 struct acpi_parameter_info info;
176 acpi_size buffer_space_needed;
177 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
Len Brown4be44fc2005-08-05 00:44:28 -0400179 ACPI_FUNCTION_TRACE("acpi_evaluate_object");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
181 info.node = handle;
182 info.parameters = NULL;
183 info.return_object = NULL;
184 info.parameter_type = ACPI_PARAM_ARGS;
185
186 /*
187 * If there are parameters to be passed to the object
188 * (which must be a control method), the external objects
189 * must be converted to internal objects
190 */
191 if (external_params && external_params->count) {
192 /*
193 * Allocate a new parameter block for the internal objects
194 * Add 1 to count to allow for null terminated internal list
195 */
Len Brown4be44fc2005-08-05 00:44:28 -0400196 info.parameters = ACPI_MEM_CALLOCATE(((acpi_size)
197 external_params->count +
198 1) * sizeof(void *));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 if (!info.parameters) {
Len Brown4be44fc2005-08-05 00:44:28 -0400200 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 }
202
203 /*
204 * Convert each external object in the list to an
205 * internal object
206 */
207 for (i = 0; i < external_params->count; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400208 status =
209 acpi_ut_copy_eobject_to_iobject(&external_params->
210 pointer[i],
211 &info.
212 parameters[i]);
213 if (ACPI_FAILURE(status)) {
214 acpi_ut_delete_internal_object_list(info.
215 parameters);
216 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 }
218 }
219 info.parameters[external_params->count] = NULL;
220 }
221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 /*
223 * Three major cases:
224 * 1) Fully qualified pathname
225 * 2) No handle, not fully qualified pathname (error)
226 * 3) Valid handle
227 */
Len Brown4be44fc2005-08-05 00:44:28 -0400228 if ((pathname) && (acpi_ns_valid_root_prefix(pathname[0]))) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400229
230 /* The path is fully qualified, just evaluate by name */
231
Len Brown4be44fc2005-08-05 00:44:28 -0400232 status = acpi_ns_evaluate_by_name(pathname, &info);
233 } else if (!handle) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 /*
235 * A handle is optional iff a fully qualified pathname
236 * is specified. Since we've already handled fully
237 * qualified names above, this is an error
238 */
239 if (!pathname) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400240 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
241 "Both Handle and Pathname are NULL"));
Len Brown4be44fc2005-08-05 00:44:28 -0400242 } else {
Bob Moore52fc0b02006-10-02 00:00:00 -0400243 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
244 "Null Handle with relative pathname [%s]",
245 pathname));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 }
247
248 status = AE_BAD_PARAMETER;
Len Brown4be44fc2005-08-05 00:44:28 -0400249 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 /*
251 * We get here if we have a handle -- and if we have a
252 * pathname it is relative. The handle will be validated
253 * in the lower procedures
254 */
255 if (!pathname) {
256 /*
257 * The null pathname case means the handle is for
258 * the actual object to be evaluated
259 */
Len Brown4be44fc2005-08-05 00:44:28 -0400260 status = acpi_ns_evaluate_by_handle(&info);
261 } else {
Bob Moore52fc0b02006-10-02 00:00:00 -0400262 /* Both a Handle and a relative Pathname */
263
Len Brown4be44fc2005-08-05 00:44:28 -0400264 status = acpi_ns_evaluate_relative(pathname, &info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 }
266 }
267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 /*
269 * If we are expecting a return value, and all went well above,
270 * copy the return value to an external object.
271 */
272 if (return_buffer) {
273 if (!info.return_object) {
274 return_buffer->length = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400275 } else {
276 if (ACPI_GET_DESCRIPTOR_TYPE(info.return_object) ==
277 ACPI_DESC_TYPE_NAMED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 /*
279 * If we received a NS Node as a return object, this means that
280 * the object we are evaluating has nothing interesting to
281 * return (such as a mutex, etc.) We return an error because
282 * these types are essentially unsupported by this interface.
283 * We don't check up front because this makes it easier to add
284 * support for various types at a later date if necessary.
285 */
286 status = AE_TYPE;
Len Brown4be44fc2005-08-05 00:44:28 -0400287 info.return_object = NULL; /* No need to delete a NS Node */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 return_buffer->length = 0;
289 }
290
Len Brown4be44fc2005-08-05 00:44:28 -0400291 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 /*
293 * Find out how large a buffer is needed
294 * to contain the returned object
295 */
Len Brown4be44fc2005-08-05 00:44:28 -0400296 status =
297 acpi_ut_get_object_size(info.return_object,
298 &buffer_space_needed);
299 if (ACPI_SUCCESS(status)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 /* Validate/Allocate/Clear caller buffer */
302
Len Brown4be44fc2005-08-05 00:44:28 -0400303 status =
304 acpi_ut_initialize_buffer
305 (return_buffer,
306 buffer_space_needed);
307 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 /*
Bob Moore52fc0b02006-10-02 00:00:00 -0400309 * Caller's buffer is too small or a new one can't
310 * be allocated
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 */
Len Brown4be44fc2005-08-05 00:44:28 -0400312 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
313 "Needed buffer size %X, %s\n",
314 (u32)
315 buffer_space_needed,
316 acpi_format_exception
317 (status)));
318 } else {
Bob Moore52fc0b02006-10-02 00:00:00 -0400319 /* We have enough space for the object, build it */
320
Len Brown4be44fc2005-08-05 00:44:28 -0400321 status =
322 acpi_ut_copy_iobject_to_eobject
323 (info.return_object,
324 return_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 }
326 }
327 }
328 }
329 }
330
331 if (info.return_object) {
332 /*
333 * Delete the internal return object. NOTE: Interpreter
334 * must be locked to avoid race condition.
335 */
Len Brown4be44fc2005-08-05 00:44:28 -0400336 status2 = acpi_ex_enter_interpreter();
337 if (ACPI_SUCCESS(status2)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 /*
339 * Delete the internal return object. (Or at least
340 * decrement the reference count by one)
341 */
Len Brown4be44fc2005-08-05 00:44:28 -0400342 acpi_ut_remove_reference(info.return_object);
343 acpi_ex_exit_interpreter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 }
345 }
346
Bob Moore52fc0b02006-10-02 00:00:00 -0400347 /* Free the input parameter list (if we created one) */
348
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 if (info.parameters) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 /* Free the allocated parameter block */
352
Len Brown4be44fc2005-08-05 00:44:28 -0400353 acpi_ut_delete_internal_object_list(info.parameters);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 }
355
Len Brown4be44fc2005-08-05 00:44:28 -0400356 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
Len Brown4be44fc2005-08-05 00:44:28 -0400359EXPORT_SYMBOL(acpi_evaluate_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
361/*******************************************************************************
362 *
363 * FUNCTION: acpi_walk_namespace
364 *
365 * PARAMETERS: Type - acpi_object_type to search for
366 * start_object - Handle in namespace where search begins
367 * max_depth - Depth to which search is to reach
368 * user_function - Called when an object of "Type" is found
369 * Context - Passed to user function
370 * return_value - Location where return value of
371 * user_function is put if terminated early
372 *
373 * RETURNS Return value from the user_function if terminated early.
374 * Otherwise, returns NULL.
375 *
376 * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
377 * starting (and ending) at the object specified by start_handle.
378 * The user_function is called whenever an object that matches
379 * the type parameter is found. If the user function returns
380 * a non-zero value, the search is terminated immediately and this
381 * value is returned to the caller.
382 *
383 * The point of this procedure is to provide a generic namespace
384 * walk routine that can be called from multiple places to
385 * provide multiple services; the User Function can be tailored
386 * to each task, whether it is a print function, a compare
387 * function, etc.
388 *
389 ******************************************************************************/
390
391acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400392acpi_walk_namespace(acpi_object_type type,
393 acpi_handle start_object,
394 u32 max_depth,
395 acpi_walk_callback user_function,
396 void *context, void **return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397{
Len Brown4be44fc2005-08-05 00:44:28 -0400398 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Len Brown4be44fc2005-08-05 00:44:28 -0400400 ACPI_FUNCTION_TRACE("acpi_walk_namespace");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
402 /* Parameter validation */
403
Bob Moore96db2552005-11-02 00:00:00 -0500404 if ((type > ACPI_TYPE_LOCAL_MAX) || (!max_depth) || (!user_function)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400405 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 }
407
408 /*
409 * Lock the namespace around the walk.
410 * The namespace will be unlocked/locked around each call
411 * to the user function - since this function
412 * must be allowed to make Acpi calls itself.
413 */
Len Brown4be44fc2005-08-05 00:44:28 -0400414 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
415 if (ACPI_FAILURE(status)) {
416 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 }
418
Len Brown4be44fc2005-08-05 00:44:28 -0400419 status = acpi_ns_walk_namespace(type, start_object, max_depth,
420 ACPI_NS_WALK_UNLOCK,
421 user_function, context, return_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Len Brown4be44fc2005-08-05 00:44:28 -0400423 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
424 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
Len Brown4be44fc2005-08-05 00:44:28 -0400427EXPORT_SYMBOL(acpi_walk_namespace);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
429/*******************************************************************************
430 *
431 * FUNCTION: acpi_ns_get_device_callback
432 *
433 * PARAMETERS: Callback from acpi_get_device
434 *
435 * RETURN: Status
436 *
437 * DESCRIPTION: Takes callbacks from walk_namespace and filters out all non-
438 * present devices, or if they specified a HID, it filters based
439 * on that.
440 *
441 ******************************************************************************/
442
443static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400444acpi_ns_get_device_callback(acpi_handle obj_handle,
445 u32 nesting_level,
446 void *context, void **return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447{
Len Brown4be44fc2005-08-05 00:44:28 -0400448 struct acpi_get_devices_info *info = context;
449 acpi_status status;
450 struct acpi_namespace_node *node;
451 u32 flags;
452 struct acpi_device_id hid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 struct acpi_compatible_id_list *cid;
Len Brown4be44fc2005-08-05 00:44:28 -0400454 acpi_native_uint i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
Len Brown4be44fc2005-08-05 00:44:28 -0400456 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
457 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 return (status);
459 }
460
Len Brown4be44fc2005-08-05 00:44:28 -0400461 node = acpi_ns_map_handle_to_node(obj_handle);
462 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
463 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 return (status);
465 }
466
467 if (!node) {
468 return (AE_BAD_PARAMETER);
469 }
470
471 /* Run _STA to determine if device is present */
472
Len Brown4be44fc2005-08-05 00:44:28 -0400473 status = acpi_ut_execute_STA(node, &flags);
474 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 return (AE_CTRL_DEPTH);
476 }
477
Bob Mooredefba1d2005-12-16 17:05:00 -0500478 if (!(flags & ACPI_STA_DEVICE_PRESENT)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400479
Bob Mooredefba1d2005-12-16 17:05:00 -0500480 /* Don't examine children of the device if not present */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
482 return (AE_CTRL_DEPTH);
483 }
484
485 /* Filter based on device HID & CID */
486
487 if (info->hid != NULL) {
Len Brown4be44fc2005-08-05 00:44:28 -0400488 status = acpi_ut_execute_HID(node, &hid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 if (status == AE_NOT_FOUND) {
490 return (AE_OK);
Len Brown4be44fc2005-08-05 00:44:28 -0400491 } else if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 return (AE_CTRL_DEPTH);
493 }
494
Len Brown4be44fc2005-08-05 00:44:28 -0400495 if (ACPI_STRNCMP(hid.value, info->hid, sizeof(hid.value)) != 0) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400496
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 /* Get the list of Compatible IDs */
498
Len Brown4be44fc2005-08-05 00:44:28 -0400499 status = acpi_ut_execute_CID(node, &cid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 if (status == AE_NOT_FOUND) {
501 return (AE_OK);
Len Brown4be44fc2005-08-05 00:44:28 -0400502 } else if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 return (AE_CTRL_DEPTH);
504 }
505
506 /* Walk the CID list */
507
508 for (i = 0; i < cid->count; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400509 if (ACPI_STRNCMP(cid->id[i].value, info->hid,
510 sizeof(struct
511 acpi_compatible_id)) !=
512 0) {
513 ACPI_MEM_FREE(cid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 return (AE_OK);
515 }
516 }
Len Brown4be44fc2005-08-05 00:44:28 -0400517 ACPI_MEM_FREE(cid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 }
519 }
520
Len Brown4be44fc2005-08-05 00:44:28 -0400521 status = info->user_function(obj_handle, nesting_level, info->context,
522 return_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 return (status);
524}
525
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526/*******************************************************************************
527 *
528 * FUNCTION: acpi_get_devices
529 *
530 * PARAMETERS: HID - HID to search for. Can be NULL.
531 * user_function - Called when a matching object is found
532 * Context - Passed to user function
533 * return_value - Location where return value of
534 * user_function is put if terminated early
535 *
536 * RETURNS Return value from the user_function if terminated early.
537 * Otherwise, returns NULL.
538 *
539 * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
540 * starting (and ending) at the object specified by start_handle.
541 * The user_function is called whenever an object of type
542 * Device is found. If the user function returns
543 * a non-zero value, the search is terminated immediately and this
544 * value is returned to the caller.
545 *
546 * This is a wrapper for walk_namespace, but the callback performs
547 * additional filtering. Please see acpi_get_device_callback.
548 *
549 ******************************************************************************/
550
551acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400552acpi_get_devices(char *HID,
553 acpi_walk_callback user_function,
554 void *context, void **return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555{
Len Brown4be44fc2005-08-05 00:44:28 -0400556 acpi_status status;
557 struct acpi_get_devices_info info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
Len Brown4be44fc2005-08-05 00:44:28 -0400559 ACPI_FUNCTION_TRACE("acpi_get_devices");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
561 /* Parameter validation */
562
563 if (!user_function) {
Len Brown4be44fc2005-08-05 00:44:28 -0400564 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 }
566
567 /*
568 * We're going to call their callback from OUR callback, so we need
569 * to know what it is, and their context parameter.
570 */
Bob Moore52fc0b02006-10-02 00:00:00 -0400571 info.hid = HID;
Len Brown4be44fc2005-08-05 00:44:28 -0400572 info.context = context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 info.user_function = user_function;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
575 /*
576 * Lock the namespace around the walk.
577 * The namespace will be unlocked/locked around each call
578 * to the user function - since this function
579 * must be allowed to make Acpi calls itself.
580 */
Len Brown4be44fc2005-08-05 00:44:28 -0400581 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
582 if (ACPI_FAILURE(status)) {
583 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 }
585
Bob Moore52fc0b02006-10-02 00:00:00 -0400586 status = acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
587 ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK,
Len Brown4be44fc2005-08-05 00:44:28 -0400588 acpi_ns_get_device_callback, &info,
589 return_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
Len Brown4be44fc2005-08-05 00:44:28 -0400591 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
592 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
Len Brown4be44fc2005-08-05 00:44:28 -0400595EXPORT_SYMBOL(acpi_get_devices);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
597/*******************************************************************************
598 *
599 * FUNCTION: acpi_attach_data
600 *
601 * PARAMETERS: obj_handle - Namespace node
602 * Handler - Handler for this attachment
603 * Data - Pointer to data to be attached
604 *
605 * RETURN: Status
606 *
607 * DESCRIPTION: Attach arbitrary data and handler to a namespace node.
608 *
609 ******************************************************************************/
610
611acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400612acpi_attach_data(acpi_handle obj_handle,
613 acpi_object_handler handler, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614{
Len Brown4be44fc2005-08-05 00:44:28 -0400615 struct acpi_namespace_node *node;
616 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
618 /* Parameter validation */
619
Len Brown4be44fc2005-08-05 00:44:28 -0400620 if (!obj_handle || !handler || !data) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 return (AE_BAD_PARAMETER);
622 }
623
Len Brown4be44fc2005-08-05 00:44:28 -0400624 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
625 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 return (status);
627 }
628
629 /* Convert and validate the handle */
630
Len Brown4be44fc2005-08-05 00:44:28 -0400631 node = acpi_ns_map_handle_to_node(obj_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 if (!node) {
633 status = AE_BAD_PARAMETER;
634 goto unlock_and_exit;
635 }
636
Len Brown4be44fc2005-08-05 00:44:28 -0400637 status = acpi_ns_attach_data(node, handler, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
Len Brown4be44fc2005-08-05 00:44:28 -0400639 unlock_and_exit:
640 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 return (status);
642}
643
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644/*******************************************************************************
645 *
646 * FUNCTION: acpi_detach_data
647 *
648 * PARAMETERS: obj_handle - Namespace node handle
649 * Handler - Handler used in call to acpi_attach_data
650 *
651 * RETURN: Status
652 *
653 * DESCRIPTION: Remove data that was previously attached to a node.
654 *
655 ******************************************************************************/
656
657acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400658acpi_detach_data(acpi_handle obj_handle, acpi_object_handler handler)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659{
Len Brown4be44fc2005-08-05 00:44:28 -0400660 struct acpi_namespace_node *node;
661 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
663 /* Parameter validation */
664
Len Brown4be44fc2005-08-05 00:44:28 -0400665 if (!obj_handle || !handler) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 return (AE_BAD_PARAMETER);
667 }
668
Len Brown4be44fc2005-08-05 00:44:28 -0400669 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
670 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 return (status);
672 }
673
674 /* Convert and validate the handle */
675
Len Brown4be44fc2005-08-05 00:44:28 -0400676 node = acpi_ns_map_handle_to_node(obj_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 if (!node) {
678 status = AE_BAD_PARAMETER;
679 goto unlock_and_exit;
680 }
681
Len Brown4be44fc2005-08-05 00:44:28 -0400682 status = acpi_ns_detach_data(node, handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
Len Brown4be44fc2005-08-05 00:44:28 -0400684 unlock_and_exit:
685 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 return (status);
687}
688
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689/*******************************************************************************
690 *
691 * FUNCTION: acpi_get_data
692 *
693 * PARAMETERS: obj_handle - Namespace node
694 * Handler - Handler used in call to attach_data
695 * Data - Where the data is returned
696 *
697 * RETURN: Status
698 *
699 * DESCRIPTION: Retrieve data that was previously attached to a namespace node.
700 *
701 ******************************************************************************/
702
703acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400704acpi_get_data(acpi_handle obj_handle, acpi_object_handler handler, void **data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705{
Len Brown4be44fc2005-08-05 00:44:28 -0400706 struct acpi_namespace_node *node;
707 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
709 /* Parameter validation */
710
Len Brown4be44fc2005-08-05 00:44:28 -0400711 if (!obj_handle || !handler || !data) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 return (AE_BAD_PARAMETER);
713 }
714
Len Brown4be44fc2005-08-05 00:44:28 -0400715 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
716 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 return (status);
718 }
719
720 /* Convert and validate the handle */
721
Len Brown4be44fc2005-08-05 00:44:28 -0400722 node = acpi_ns_map_handle_to_node(obj_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 if (!node) {
724 status = AE_BAD_PARAMETER;
725 goto unlock_and_exit;
726 }
727
Len Brown4be44fc2005-08-05 00:44:28 -0400728 status = acpi_ns_get_attached_data(node, handler, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
Len Brown4be44fc2005-08-05 00:44:28 -0400730 unlock_and_exit:
731 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 return (status);
733}