[ACPI] ACPICA 20060113
[deliverable/linux.git] / drivers / acpi / namespace / nsxfeval.c
CommitLineData
1da177e4
LT
1/*******************************************************************************
2 *
3 * Module Name: nsxfeval - Public interfaces to the ACPI subsystem
4 * ACPI Object evaluation interfaces
5 *
6 ******************************************************************************/
7
8/*
4a90c7e8 9 * Copyright (C) 2000 - 2006, R. Byron Moore
1da177e4
LT
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
1da177e4 51#define _COMPONENT ACPI_NAMESPACE
4be44fcd 52ACPI_MODULE_NAME("nsxfeval")
1da177e4
LT
53
54/*******************************************************************************
55 *
56 * FUNCTION: acpi_evaluate_object_typed
57 *
58 * PARAMETERS: Handle - Object handle (optional)
44f6c012
RM
59 * Pathname - Object pathname (optional)
60 * external_params - List of parameters to pass to method,
1da177e4
LT
61 * terminated by NULL. May be NULL
62 * if no parameters are being passed.
44f6c012 63 * return_buffer - Where to put method's return value (if
1da177e4
LT
64 * 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
4be44fcd
LB
76acpi_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)
1da177e4 81{
4be44fcd
LB
82 acpi_status status;
83 u8 must_free = FALSE;
1da177e4 84
4be44fcd 85 ACPI_FUNCTION_TRACE("acpi_evaluate_object_typed");
1da177e4
LT
86
87 /* Return buffer must be valid */
88
89 if (!return_buffer) {
4be44fcd 90 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
91 }
92
93 if (return_buffer->length == ACPI_ALLOCATE_BUFFER) {
94 must_free = TRUE;
95 }
96
97 /* Evaluate the object */
98
4be44fcd
LB
99 status =
100 acpi_evaluate_object(handle, pathname, external_params,
101 return_buffer);
102 if (ACPI_FAILURE(status)) {
103 return_ACPI_STATUS(status);
1da177e4
LT
104 }
105
106 /* Type ANY means "don't care" */
107
108 if (return_type == ACPI_TYPE_ANY) {
4be44fcd 109 return_ACPI_STATUS(AE_OK);
1da177e4
LT
110 }
111
112 if (return_buffer->length == 0) {
113 /* Error because caller specifically asked for a return value */
114
4a90c7e8 115 ACPI_REPORT_ERROR(("No return value\n"));
4be44fcd 116 return_ACPI_STATUS(AE_NULL_OBJECT);
1da177e4
LT
117 }
118
119 /* Examine the object type returned from evaluate_object */
120
4be44fcd
LB
121 if (((union acpi_object *)return_buffer->pointer)->type == return_type) {
122 return_ACPI_STATUS(AE_OK);
1da177e4
LT
123 }
124
125 /* Return object type does not match requested type */
126
4a90c7e8
BM
127 ACPI_REPORT_ERROR(("Incorrect return type [%s] requested [%s]\n",
128 acpi_ut_get_type_name(((union acpi_object *)
129 return_buffer->pointer)->
130 type),
131 acpi_ut_get_type_name(return_type)));
1da177e4
LT
132
133 if (must_free) {
134 /* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */
135
4be44fcd 136 acpi_os_free(return_buffer->pointer);
1da177e4
LT
137 return_buffer->pointer = NULL;
138 }
139
140 return_buffer->length = 0;
4be44fcd 141 return_ACPI_STATUS(AE_TYPE);
1da177e4 142}
4be44fcd 143#endif /* ACPI_FUTURE_USAGE */
1da177e4
LT
144
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
4be44fcd
LB
166acpi_evaluate_object(acpi_handle handle,
167 acpi_string pathname,
168 struct acpi_object_list *external_params,
169 struct acpi_buffer *return_buffer)
1da177e4 170{
4be44fcd
LB
171 acpi_status status;
172 acpi_status status2;
173 struct acpi_parameter_info info;
174 acpi_size buffer_space_needed;
175 u32 i;
1da177e4 176
4be44fcd 177 ACPI_FUNCTION_TRACE("acpi_evaluate_object");
1da177e4
LT
178
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 */
4be44fcd
LB
194 info.parameters = ACPI_MEM_CALLOCATE(((acpi_size)
195 external_params->count +
196 1) * sizeof(void *));
1da177e4 197 if (!info.parameters) {
4be44fcd 198 return_ACPI_STATUS(AE_NO_MEMORY);
1da177e4
LT
199 }
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++) {
4be44fcd
LB
206 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);
1da177e4
LT
215 }
216 }
217 info.parameters[external_params->count] = NULL;
218 }
219
1da177e4
LT
220 /*
221 * Three major cases:
222 * 1) Fully qualified pathname
223 * 2) No handle, not fully qualified pathname (error)
224 * 3) Valid handle
225 */
4be44fcd 226 if ((pathname) && (acpi_ns_valid_root_prefix(pathname[0]))) {
1da177e4
LT
227 /*
228 * The path is fully qualified, just evaluate by name
229 */
4be44fcd
LB
230 status = acpi_ns_evaluate_by_name(pathname, &info);
231 } else if (!handle) {
1da177e4
LT
232 /*
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) {
4a90c7e8 238 ACPI_REPORT_ERROR(("Both Handle and Pathname are NULL\n"));
4be44fcd 239 } else {
4a90c7e8 240 ACPI_REPORT_ERROR(("Handle is NULL and Pathname is relative\n"));
1da177e4
LT
241 }
242
243 status = AE_BAD_PARAMETER;
4be44fcd 244 } else {
1da177e4
LT
245 /*
246 * We get here if we have a handle -- and if we have a
247 * pathname it is relative. The handle will be validated
248 * in the lower procedures
249 */
250 if (!pathname) {
251 /*
252 * The null pathname case means the handle is for
253 * the actual object to be evaluated
254 */
4be44fcd
LB
255 status = acpi_ns_evaluate_by_handle(&info);
256 } else {
257 /*
258 * Both a Handle and a relative Pathname
259 */
260 status = acpi_ns_evaluate_relative(pathname, &info);
1da177e4
LT
261 }
262 }
263
1da177e4
LT
264 /*
265 * If we are expecting a return value, and all went well above,
266 * copy the return value to an external object.
267 */
268 if (return_buffer) {
269 if (!info.return_object) {
270 return_buffer->length = 0;
4be44fcd
LB
271 } else {
272 if (ACPI_GET_DESCRIPTOR_TYPE(info.return_object) ==
273 ACPI_DESC_TYPE_NAMED) {
1da177e4
LT
274 /*
275 * If we received a NS Node as a return object, this means that
276 * the object we are evaluating has nothing interesting to
277 * return (such as a mutex, etc.) We return an error because
278 * these types are essentially unsupported by this interface.
279 * We don't check up front because this makes it easier to add
280 * support for various types at a later date if necessary.
281 */
282 status = AE_TYPE;
4be44fcd 283 info.return_object = NULL; /* No need to delete a NS Node */
1da177e4
LT
284 return_buffer->length = 0;
285 }
286
4be44fcd 287 if (ACPI_SUCCESS(status)) {
1da177e4
LT
288 /*
289 * Find out how large a buffer is needed
290 * to contain the returned object
291 */
4be44fcd
LB
292 status =
293 acpi_ut_get_object_size(info.return_object,
294 &buffer_space_needed);
295 if (ACPI_SUCCESS(status)) {
1da177e4
LT
296 /* Validate/Allocate/Clear caller buffer */
297
4be44fcd
LB
298 status =
299 acpi_ut_initialize_buffer
300 (return_buffer,
301 buffer_space_needed);
302 if (ACPI_FAILURE(status)) {
1da177e4
LT
303 /*
304 * Caller's buffer is too small or a new one can't be allocated
305 */
4be44fcd
LB
306 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
307 "Needed buffer size %X, %s\n",
308 (u32)
309 buffer_space_needed,
310 acpi_format_exception
311 (status)));
312 } else {
1da177e4
LT
313 /*
314 * We have enough space for the object, build it
315 */
4be44fcd
LB
316 status =
317 acpi_ut_copy_iobject_to_eobject
318 (info.return_object,
319 return_buffer);
1da177e4
LT
320 }
321 }
322 }
323 }
324 }
325
326 if (info.return_object) {
327 /*
328 * Delete the internal return object. NOTE: Interpreter
329 * must be locked to avoid race condition.
330 */
4be44fcd
LB
331 status2 = acpi_ex_enter_interpreter();
332 if (ACPI_SUCCESS(status2)) {
1da177e4
LT
333 /*
334 * Delete the internal return object. (Or at least
335 * decrement the reference count by one)
336 */
4be44fcd
LB
337 acpi_ut_remove_reference(info.return_object);
338 acpi_ex_exit_interpreter();
1da177e4
LT
339 }
340 }
341
342 /*
343 * Free the input parameter list (if we created one),
344 */
345 if (info.parameters) {
346 /* Free the allocated parameter block */
347
4be44fcd 348 acpi_ut_delete_internal_object_list(info.parameters);
1da177e4
LT
349 }
350
4be44fcd 351 return_ACPI_STATUS(status);
1da177e4 352}
1da177e4 353
4be44fcd 354EXPORT_SYMBOL(acpi_evaluate_object);
1da177e4
LT
355
356/*******************************************************************************
357 *
358 * FUNCTION: acpi_walk_namespace
359 *
360 * PARAMETERS: Type - acpi_object_type to search for
361 * start_object - Handle in namespace where search begins
362 * max_depth - Depth to which search is to reach
363 * user_function - Called when an object of "Type" is found
364 * Context - Passed to user function
365 * return_value - Location where return value of
366 * user_function is put if terminated early
367 *
368 * RETURNS Return value from the user_function if terminated early.
369 * Otherwise, returns NULL.
370 *
371 * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
372 * starting (and ending) at the object specified by start_handle.
373 * The user_function is called whenever an object that matches
374 * the type parameter is found. If the user function returns
375 * a non-zero value, the search is terminated immediately and this
376 * value is returned to the caller.
377 *
378 * The point of this procedure is to provide a generic namespace
379 * walk routine that can be called from multiple places to
380 * provide multiple services; the User Function can be tailored
381 * to each task, whether it is a print function, a compare
382 * function, etc.
383 *
384 ******************************************************************************/
385
386acpi_status
4be44fcd
LB
387acpi_walk_namespace(acpi_object_type type,
388 acpi_handle start_object,
389 u32 max_depth,
390 acpi_walk_callback user_function,
391 void *context, void **return_value)
1da177e4 392{
4be44fcd 393 acpi_status status;
1da177e4 394
4be44fcd 395 ACPI_FUNCTION_TRACE("acpi_walk_namespace");
1da177e4
LT
396
397 /* Parameter validation */
398
96db255c 399 if ((type > ACPI_TYPE_LOCAL_MAX) || (!max_depth) || (!user_function)) {
4be44fcd 400 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
401 }
402
403 /*
404 * Lock the namespace around the walk.
405 * The namespace will be unlocked/locked around each call
406 * to the user function - since this function
407 * must be allowed to make Acpi calls itself.
408 */
4be44fcd
LB
409 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
410 if (ACPI_FAILURE(status)) {
411 return_ACPI_STATUS(status);
1da177e4
LT
412 }
413
4be44fcd
LB
414 status = acpi_ns_walk_namespace(type, start_object, max_depth,
415 ACPI_NS_WALK_UNLOCK,
416 user_function, context, return_value);
1da177e4 417
4be44fcd
LB
418 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
419 return_ACPI_STATUS(status);
1da177e4 420}
1da177e4 421
4be44fcd 422EXPORT_SYMBOL(acpi_walk_namespace);
1da177e4
LT
423
424/*******************************************************************************
425 *
426 * FUNCTION: acpi_ns_get_device_callback
427 *
428 * PARAMETERS: Callback from acpi_get_device
429 *
430 * RETURN: Status
431 *
432 * DESCRIPTION: Takes callbacks from walk_namespace and filters out all non-
433 * present devices, or if they specified a HID, it filters based
434 * on that.
435 *
436 ******************************************************************************/
437
438static acpi_status
4be44fcd
LB
439acpi_ns_get_device_callback(acpi_handle obj_handle,
440 u32 nesting_level,
441 void *context, void **return_value)
1da177e4 442{
4be44fcd
LB
443 struct acpi_get_devices_info *info = context;
444 acpi_status status;
445 struct acpi_namespace_node *node;
446 u32 flags;
447 struct acpi_device_id hid;
1da177e4 448 struct acpi_compatible_id_list *cid;
4be44fcd 449 acpi_native_uint i;
1da177e4 450
4be44fcd
LB
451 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
452 if (ACPI_FAILURE(status)) {
1da177e4
LT
453 return (status);
454 }
455
4be44fcd
LB
456 node = acpi_ns_map_handle_to_node(obj_handle);
457 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
458 if (ACPI_FAILURE(status)) {
1da177e4
LT
459 return (status);
460 }
461
462 if (!node) {
463 return (AE_BAD_PARAMETER);
464 }
465
466 /* Run _STA to determine if device is present */
467
4be44fcd
LB
468 status = acpi_ut_execute_STA(node, &flags);
469 if (ACPI_FAILURE(status)) {
1da177e4
LT
470 return (AE_CTRL_DEPTH);
471 }
472
defba1d8
BM
473 if (!(flags & ACPI_STA_DEVICE_PRESENT)) {
474 /* Don't examine children of the device if not present */
1da177e4
LT
475
476 return (AE_CTRL_DEPTH);
477 }
478
479 /* Filter based on device HID & CID */
480
481 if (info->hid != NULL) {
4be44fcd 482 status = acpi_ut_execute_HID(node, &hid);
1da177e4
LT
483 if (status == AE_NOT_FOUND) {
484 return (AE_OK);
4be44fcd 485 } else if (ACPI_FAILURE(status)) {
1da177e4
LT
486 return (AE_CTRL_DEPTH);
487 }
488
4be44fcd 489 if (ACPI_STRNCMP(hid.value, info->hid, sizeof(hid.value)) != 0) {
1da177e4
LT
490 /* Get the list of Compatible IDs */
491
4be44fcd 492 status = acpi_ut_execute_CID(node, &cid);
1da177e4
LT
493 if (status == AE_NOT_FOUND) {
494 return (AE_OK);
4be44fcd 495 } else if (ACPI_FAILURE(status)) {
1da177e4
LT
496 return (AE_CTRL_DEPTH);
497 }
498
499 /* Walk the CID list */
500
501 for (i = 0; i < cid->count; i++) {
4be44fcd
LB
502 if (ACPI_STRNCMP(cid->id[i].value, info->hid,
503 sizeof(struct
504 acpi_compatible_id)) !=
505 0) {
506 ACPI_MEM_FREE(cid);
1da177e4
LT
507 return (AE_OK);
508 }
509 }
4be44fcd 510 ACPI_MEM_FREE(cid);
1da177e4
LT
511 }
512 }
513
4be44fcd
LB
514 status = info->user_function(obj_handle, nesting_level, info->context,
515 return_value);
1da177e4
LT
516 return (status);
517}
518
1da177e4
LT
519/*******************************************************************************
520 *
521 * FUNCTION: acpi_get_devices
522 *
523 * PARAMETERS: HID - HID to search for. Can be NULL.
524 * user_function - Called when a matching object is found
525 * Context - Passed to user function
526 * return_value - Location where return value of
527 * user_function is put if terminated early
528 *
529 * RETURNS Return value from the user_function if terminated early.
530 * Otherwise, returns NULL.
531 *
532 * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
533 * starting (and ending) at the object specified by start_handle.
534 * The user_function is called whenever an object of type
535 * Device is found. If the user function returns
536 * a non-zero value, the search is terminated immediately and this
537 * value is returned to the caller.
538 *
539 * This is a wrapper for walk_namespace, but the callback performs
540 * additional filtering. Please see acpi_get_device_callback.
541 *
542 ******************************************************************************/
543
544acpi_status
4be44fcd
LB
545acpi_get_devices(char *HID,
546 acpi_walk_callback user_function,
547 void *context, void **return_value)
1da177e4 548{
4be44fcd
LB
549 acpi_status status;
550 struct acpi_get_devices_info info;
1da177e4 551
4be44fcd 552 ACPI_FUNCTION_TRACE("acpi_get_devices");
1da177e4
LT
553
554 /* Parameter validation */
555
556 if (!user_function) {
4be44fcd 557 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
558 }
559
560 /*
561 * We're going to call their callback from OUR callback, so we need
562 * to know what it is, and their context parameter.
563 */
4be44fcd 564 info.context = context;
1da177e4 565 info.user_function = user_function;
4be44fcd 566 info.hid = HID;
1da177e4
LT
567
568 /*
569 * Lock the namespace around the walk.
570 * The namespace will be unlocked/locked around each call
571 * to the user function - since this function
572 * must be allowed to make Acpi calls itself.
573 */
4be44fcd
LB
574 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
575 if (ACPI_FAILURE(status)) {
576 return_ACPI_STATUS(status);
1da177e4
LT
577 }
578
4be44fcd
LB
579 status = acpi_ns_walk_namespace(ACPI_TYPE_DEVICE,
580 ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
581 ACPI_NS_WALK_UNLOCK,
582 acpi_ns_get_device_callback, &info,
583 return_value);
1da177e4 584
4be44fcd
LB
585 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
586 return_ACPI_STATUS(status);
1da177e4 587}
1da177e4 588
4be44fcd 589EXPORT_SYMBOL(acpi_get_devices);
1da177e4
LT
590
591/*******************************************************************************
592 *
593 * FUNCTION: acpi_attach_data
594 *
595 * PARAMETERS: obj_handle - Namespace node
596 * Handler - Handler for this attachment
597 * Data - Pointer to data to be attached
598 *
599 * RETURN: Status
600 *
601 * DESCRIPTION: Attach arbitrary data and handler to a namespace node.
602 *
603 ******************************************************************************/
604
605acpi_status
4be44fcd
LB
606acpi_attach_data(acpi_handle obj_handle,
607 acpi_object_handler handler, void *data)
1da177e4 608{
4be44fcd
LB
609 struct acpi_namespace_node *node;
610 acpi_status status;
1da177e4
LT
611
612 /* Parameter validation */
613
4be44fcd 614 if (!obj_handle || !handler || !data) {
1da177e4
LT
615 return (AE_BAD_PARAMETER);
616 }
617
4be44fcd
LB
618 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
619 if (ACPI_FAILURE(status)) {
1da177e4
LT
620 return (status);
621 }
622
623 /* Convert and validate the handle */
624
4be44fcd 625 node = acpi_ns_map_handle_to_node(obj_handle);
1da177e4
LT
626 if (!node) {
627 status = AE_BAD_PARAMETER;
628 goto unlock_and_exit;
629 }
630
4be44fcd 631 status = acpi_ns_attach_data(node, handler, data);
1da177e4 632
4be44fcd
LB
633 unlock_and_exit:
634 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
1da177e4
LT
635 return (status);
636}
637
1da177e4
LT
638/*******************************************************************************
639 *
640 * FUNCTION: acpi_detach_data
641 *
642 * PARAMETERS: obj_handle - Namespace node handle
643 * Handler - Handler used in call to acpi_attach_data
644 *
645 * RETURN: Status
646 *
647 * DESCRIPTION: Remove data that was previously attached to a node.
648 *
649 ******************************************************************************/
650
651acpi_status
4be44fcd 652acpi_detach_data(acpi_handle obj_handle, acpi_object_handler handler)
1da177e4 653{
4be44fcd
LB
654 struct acpi_namespace_node *node;
655 acpi_status status;
1da177e4
LT
656
657 /* Parameter validation */
658
4be44fcd 659 if (!obj_handle || !handler) {
1da177e4
LT
660 return (AE_BAD_PARAMETER);
661 }
662
4be44fcd
LB
663 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
664 if (ACPI_FAILURE(status)) {
1da177e4
LT
665 return (status);
666 }
667
668 /* Convert and validate the handle */
669
4be44fcd 670 node = acpi_ns_map_handle_to_node(obj_handle);
1da177e4
LT
671 if (!node) {
672 status = AE_BAD_PARAMETER;
673 goto unlock_and_exit;
674 }
675
4be44fcd 676 status = acpi_ns_detach_data(node, handler);
1da177e4 677
4be44fcd
LB
678 unlock_and_exit:
679 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
1da177e4
LT
680 return (status);
681}
682
1da177e4
LT
683/*******************************************************************************
684 *
685 * FUNCTION: acpi_get_data
686 *
687 * PARAMETERS: obj_handle - Namespace node
688 * Handler - Handler used in call to attach_data
689 * Data - Where the data is returned
690 *
691 * RETURN: Status
692 *
693 * DESCRIPTION: Retrieve data that was previously attached to a namespace node.
694 *
695 ******************************************************************************/
696
697acpi_status
4be44fcd 698acpi_get_data(acpi_handle obj_handle, acpi_object_handler handler, void **data)
1da177e4 699{
4be44fcd
LB
700 struct acpi_namespace_node *node;
701 acpi_status status;
1da177e4
LT
702
703 /* Parameter validation */
704
4be44fcd 705 if (!obj_handle || !handler || !data) {
1da177e4
LT
706 return (AE_BAD_PARAMETER);
707 }
708
4be44fcd
LB
709 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
710 if (ACPI_FAILURE(status)) {
1da177e4
LT
711 return (status);
712 }
713
714 /* Convert and validate the handle */
715
4be44fcd 716 node = acpi_ns_map_handle_to_node(obj_handle);
1da177e4
LT
717 if (!node) {
718 status = AE_BAD_PARAMETER;
719 goto unlock_and_exit;
720 }
721
4be44fcd 722 status = acpi_ns_get_attached_data(node, handler, data);
1da177e4 723
4be44fcd
LB
724 unlock_and_exit:
725 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
1da177e4
LT
726 return (status);
727}
This page took 0.081892 seconds and 5 git commands to generate.