Revert "[PATCH] ACPI: fix vendor resource length computation"
[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
b8e4d893 115 ACPI_ERROR((AE_INFO, "No return value"));
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
b8e4d893
BM
127 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)));
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) {
b8e4d893
BM
238 ACPI_ERROR((AE_INFO,
239 "Both Handle and Pathname are NULL"));
4be44fcd 240 } else {
b8e4d893
BM
241 ACPI_ERROR((AE_INFO,
242 "Handle is NULL and Pathname is relative"));
1da177e4
LT
243 }
244
245 status = AE_BAD_PARAMETER;
4be44fcd 246 } else {
1da177e4
LT
247 /*
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 */
4be44fcd
LB
257 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);
1da177e4
LT
263 }
264 }
265
1da177e4
LT
266 /*
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;
4be44fcd
LB
273 } else {
274 if (ACPI_GET_DESCRIPTOR_TYPE(info.return_object) ==
275 ACPI_DESC_TYPE_NAMED) {
1da177e4
LT
276 /*
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;
4be44fcd 285 info.return_object = NULL; /* No need to delete a NS Node */
1da177e4
LT
286 return_buffer->length = 0;
287 }
288
4be44fcd 289 if (ACPI_SUCCESS(status)) {
1da177e4
LT
290 /*
291 * Find out how large a buffer is needed
292 * to contain the returned object
293 */
4be44fcd
LB
294 status =
295 acpi_ut_get_object_size(info.return_object,
296 &buffer_space_needed);
297 if (ACPI_SUCCESS(status)) {
1da177e4
LT
298 /* Validate/Allocate/Clear caller buffer */
299
4be44fcd
LB
300 status =
301 acpi_ut_initialize_buffer
302 (return_buffer,
303 buffer_space_needed);
304 if (ACPI_FAILURE(status)) {
1da177e4
LT
305 /*
306 * Caller's buffer is too small or a new one can't be allocated
307 */
4be44fcd
LB
308 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 {
1da177e4
LT
315 /*
316 * We have enough space for the object, build it
317 */
4be44fcd
LB
318 status =
319 acpi_ut_copy_iobject_to_eobject
320 (info.return_object,
321 return_buffer);
1da177e4
LT
322 }
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 */
4be44fcd
LB
333 status2 = acpi_ex_enter_interpreter();
334 if (ACPI_SUCCESS(status2)) {
1da177e4
LT
335 /*
336 * Delete the internal return object. (Or at least
337 * decrement the reference count by one)
338 */
4be44fcd
LB
339 acpi_ut_remove_reference(info.return_object);
340 acpi_ex_exit_interpreter();
1da177e4
LT
341 }
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
4be44fcd 350 acpi_ut_delete_internal_object_list(info.parameters);
1da177e4
LT
351 }
352
4be44fcd 353 return_ACPI_STATUS(status);
1da177e4 354}
1da177e4 355
4be44fcd 356EXPORT_SYMBOL(acpi_evaluate_object);
1da177e4
LT
357
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
4be44fcd
LB
389acpi_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)
1da177e4 394{
4be44fcd 395 acpi_status status;
1da177e4 396
4be44fcd 397 ACPI_FUNCTION_TRACE("acpi_walk_namespace");
1da177e4
LT
398
399 /* Parameter validation */
400
96db255c 401 if ((type > ACPI_TYPE_LOCAL_MAX) || (!max_depth) || (!user_function)) {
4be44fcd 402 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
403 }
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 */
4be44fcd
LB
411 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
412 if (ACPI_FAILURE(status)) {
413 return_ACPI_STATUS(status);
1da177e4
LT
414 }
415
4be44fcd
LB
416 status = acpi_ns_walk_namespace(type, start_object, max_depth,
417 ACPI_NS_WALK_UNLOCK,
418 user_function, context, return_value);
1da177e4 419
4be44fcd
LB
420 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
421 return_ACPI_STATUS(status);
1da177e4 422}
1da177e4 423
4be44fcd 424EXPORT_SYMBOL(acpi_walk_namespace);
1da177e4
LT
425
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
4be44fcd
LB
441acpi_ns_get_device_callback(acpi_handle obj_handle,
442 u32 nesting_level,
443 void *context, void **return_value)
1da177e4 444{
4be44fcd
LB
445 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;
1da177e4 450 struct acpi_compatible_id_list *cid;
4be44fcd 451 acpi_native_uint i;
1da177e4 452
4be44fcd
LB
453 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
454 if (ACPI_FAILURE(status)) {
1da177e4
LT
455 return (status);
456 }
457
4be44fcd
LB
458 node = acpi_ns_map_handle_to_node(obj_handle);
459 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
460 if (ACPI_FAILURE(status)) {
1da177e4
LT
461 return (status);
462 }
463
464 if (!node) {
465 return (AE_BAD_PARAMETER);
466 }
467
468 /* Run _STA to determine if device is present */
469
4be44fcd
LB
470 status = acpi_ut_execute_STA(node, &flags);
471 if (ACPI_FAILURE(status)) {
1da177e4
LT
472 return (AE_CTRL_DEPTH);
473 }
474
defba1d8
BM
475 if (!(flags & ACPI_STA_DEVICE_PRESENT)) {
476 /* Don't examine children of the device if not present */
1da177e4
LT
477
478 return (AE_CTRL_DEPTH);
479 }
480
481 /* Filter based on device HID & CID */
482
483 if (info->hid != NULL) {
4be44fcd 484 status = acpi_ut_execute_HID(node, &hid);
1da177e4
LT
485 if (status == AE_NOT_FOUND) {
486 return (AE_OK);
4be44fcd 487 } else if (ACPI_FAILURE(status)) {
1da177e4
LT
488 return (AE_CTRL_DEPTH);
489 }
490
4be44fcd 491 if (ACPI_STRNCMP(hid.value, info->hid, sizeof(hid.value)) != 0) {
1da177e4
LT
492 /* Get the list of Compatible IDs */
493
4be44fcd 494 status = acpi_ut_execute_CID(node, &cid);
1da177e4
LT
495 if (status == AE_NOT_FOUND) {
496 return (AE_OK);
4be44fcd 497 } else if (ACPI_FAILURE(status)) {
1da177e4
LT
498 return (AE_CTRL_DEPTH);
499 }
500
501 /* Walk the CID list */
502
503 for (i = 0; i < cid->count; i++) {
4be44fcd
LB
504 if (ACPI_STRNCMP(cid->id[i].value, info->hid,
505 sizeof(struct
506 acpi_compatible_id)) !=
507 0) {
508 ACPI_MEM_FREE(cid);
1da177e4
LT
509 return (AE_OK);
510 }
511 }
4be44fcd 512 ACPI_MEM_FREE(cid);
1da177e4
LT
513 }
514 }
515
4be44fcd
LB
516 status = info->user_function(obj_handle, nesting_level, info->context,
517 return_value);
1da177e4
LT
518 return (status);
519}
520
1da177e4
LT
521/*******************************************************************************
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
4be44fcd
LB
547acpi_get_devices(char *HID,
548 acpi_walk_callback user_function,
549 void *context, void **return_value)
1da177e4 550{
4be44fcd
LB
551 acpi_status status;
552 struct acpi_get_devices_info info;
1da177e4 553
4be44fcd 554 ACPI_FUNCTION_TRACE("acpi_get_devices");
1da177e4
LT
555
556 /* Parameter validation */
557
558 if (!user_function) {
4be44fcd 559 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
560 }
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 */
4be44fcd 566 info.context = context;
1da177e4 567 info.user_function = user_function;
4be44fcd 568 info.hid = HID;
1da177e4
LT
569
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 */
4be44fcd
LB
576 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
577 if (ACPI_FAILURE(status)) {
578 return_ACPI_STATUS(status);
1da177e4
LT
579 }
580
4be44fcd
LB
581 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);
1da177e4 586
4be44fcd
LB
587 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
588 return_ACPI_STATUS(status);
1da177e4 589}
1da177e4 590
4be44fcd 591EXPORT_SYMBOL(acpi_get_devices);
1da177e4
LT
592
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
4be44fcd
LB
608acpi_attach_data(acpi_handle obj_handle,
609 acpi_object_handler handler, void *data)
1da177e4 610{
4be44fcd
LB
611 struct acpi_namespace_node *node;
612 acpi_status status;
1da177e4
LT
613
614 /* Parameter validation */
615
4be44fcd 616 if (!obj_handle || !handler || !data) {
1da177e4
LT
617 return (AE_BAD_PARAMETER);
618 }
619
4be44fcd
LB
620 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
621 if (ACPI_FAILURE(status)) {
1da177e4
LT
622 return (status);
623 }
624
625 /* Convert and validate the handle */
626
4be44fcd 627 node = acpi_ns_map_handle_to_node(obj_handle);
1da177e4
LT
628 if (!node) {
629 status = AE_BAD_PARAMETER;
630 goto unlock_and_exit;
631 }
632
4be44fcd 633 status = acpi_ns_attach_data(node, handler, data);
1da177e4 634
4be44fcd
LB
635 unlock_and_exit:
636 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
1da177e4
LT
637 return (status);
638}
639
1da177e4
LT
640/*******************************************************************************
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
4be44fcd 654acpi_detach_data(acpi_handle obj_handle, acpi_object_handler handler)
1da177e4 655{
4be44fcd
LB
656 struct acpi_namespace_node *node;
657 acpi_status status;
1da177e4
LT
658
659 /* Parameter validation */
660
4be44fcd 661 if (!obj_handle || !handler) {
1da177e4
LT
662 return (AE_BAD_PARAMETER);
663 }
664
4be44fcd
LB
665 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
666 if (ACPI_FAILURE(status)) {
1da177e4
LT
667 return (status);
668 }
669
670 /* Convert and validate the handle */
671
4be44fcd 672 node = acpi_ns_map_handle_to_node(obj_handle);
1da177e4
LT
673 if (!node) {
674 status = AE_BAD_PARAMETER;
675 goto unlock_and_exit;
676 }
677
4be44fcd 678 status = acpi_ns_detach_data(node, handler);
1da177e4 679
4be44fcd
LB
680 unlock_and_exit:
681 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
1da177e4
LT
682 return (status);
683}
684
1da177e4
LT
685/*******************************************************************************
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
4be44fcd 700acpi_get_data(acpi_handle obj_handle, acpi_object_handler handler, void **data)
1da177e4 701{
4be44fcd
LB
702 struct acpi_namespace_node *node;
703 acpi_status status;
1da177e4
LT
704
705 /* Parameter validation */
706
4be44fcd 707 if (!obj_handle || !handler || !data) {
1da177e4
LT
708 return (AE_BAD_PARAMETER);
709 }
710
4be44fcd
LB
711 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
712 if (ACPI_FAILURE(status)) {
1da177e4
LT
713 return (status);
714 }
715
716 /* Convert and validate the handle */
717
4be44fcd 718 node = acpi_ns_map_handle_to_node(obj_handle);
1da177e4
LT
719 if (!node) {
720 status = AE_BAD_PARAMETER;
721 goto unlock_and_exit;
722 }
723
4be44fcd 724 status = acpi_ns_get_attached_data(node, handler, data);
1da177e4 725
4be44fcd
LB
726 unlock_and_exit:
727 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
1da177e4
LT
728 return (status);
729}
This page took 0.169922 seconds and 5 git commands to generate.