1 /******************************************************************************* 2 * 3 * Module Name: nsxfeval - Public interfaces to the ACPI subsystem 4 * ACPI Object evaluation interfaces 5 * 6 ******************************************************************************/ 7 8 /* 9 * Copyright (C) 2000 - 2013, Intel Corp. 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 #define EXPORT_ACPI_INTERFACES 46 47 #include <acpi/acpi.h> 48 #include "accommon.h" 49 #include "acnamesp.h" 50 #include "acinterp.h" 51 52 #define _COMPONENT ACPI_NAMESPACE 53 ACPI_MODULE_NAME("nsxfeval") 54 55 /* Local prototypes */ 56 static void acpi_ns_resolve_references(struct acpi_evaluate_info *info); 57 58 /******************************************************************************* 59 * 60 * FUNCTION: acpi_evaluate_object_typed 61 * 62 * PARAMETERS: handle - Object handle (optional) 63 * pathname - Object pathname (optional) 64 * external_params - List of parameters to pass to method, 65 * terminated by NULL. May be NULL 66 * if no parameters are being passed. 67 * return_buffer - Where to put method's return value (if 68 * any). If NULL, no value is returned. 69 * return_type - Expected type of return object 70 * 71 * RETURN: Status 72 * 73 * DESCRIPTION: Find and evaluate the given object, passing the given 74 * parameters if necessary. One of "Handle" or "Pathname" must 75 * be valid (non-null) 76 * 77 ******************************************************************************/ 78 79 acpi_status 80 acpi_evaluate_object_typed(acpi_handle handle, 81 acpi_string pathname, 82 struct acpi_object_list *external_params, 83 struct acpi_buffer *return_buffer, 84 acpi_object_type return_type) 85 { 86 acpi_status status; 87 u8 must_free = FALSE; 88 89 ACPI_FUNCTION_TRACE(acpi_evaluate_object_typed); 90 91 /* Return buffer must be valid */ 92 93 if (!return_buffer) { 94 return_ACPI_STATUS(AE_BAD_PARAMETER); 95 } 96 97 if (return_buffer->length == ACPI_ALLOCATE_BUFFER) { 98 must_free = TRUE; 99 } 100 101 /* Evaluate the object */ 102 103 status = 104 acpi_evaluate_object(handle, pathname, external_params, 105 return_buffer); 106 if (ACPI_FAILURE(status)) { 107 return_ACPI_STATUS(status); 108 } 109 110 /* Type ANY means "don't care" */ 111 112 if (return_type == ACPI_TYPE_ANY) { 113 return_ACPI_STATUS(AE_OK); 114 } 115 116 if (return_buffer->length == 0) { 117 118 /* Error because caller specifically asked for a return value */ 119 120 ACPI_ERROR((AE_INFO, "No return value")); 121 return_ACPI_STATUS(AE_NULL_OBJECT); 122 } 123 124 /* Examine the object type returned from evaluate_object */ 125 126 if (((union acpi_object *)return_buffer->pointer)->type == return_type) { 127 return_ACPI_STATUS(AE_OK); 128 } 129 130 /* Return object type does not match requested type */ 131 132 ACPI_ERROR((AE_INFO, 133 "Incorrect return type [%s] requested [%s]", 134 acpi_ut_get_type_name(((union acpi_object *)return_buffer-> 135 pointer)->type), 136 acpi_ut_get_type_name(return_type))); 137 138 if (must_free) { 139 140 /* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */ 141 142 ACPI_FREE_BUFFER(*return_buffer); 143 return_buffer->pointer = NULL; 144 } 145 146 return_buffer->length = 0; 147 return_ACPI_STATUS(AE_TYPE); 148 } 149 150 ACPI_EXPORT_SYMBOL(acpi_evaluate_object_typed) 151 152 /******************************************************************************* 153 * 154 * FUNCTION: acpi_evaluate_object 155 * 156 * PARAMETERS: handle - Object handle (optional) 157 * pathname - Object pathname (optional) 158 * external_params - List of parameters to pass to method, 159 * terminated by NULL. May be NULL 160 * if no parameters are being passed. 161 * return_buffer - Where to put method's return value (if 162 * any). If NULL, no value is returned. 163 * 164 * RETURN: Status 165 * 166 * DESCRIPTION: Find and evaluate the given object, passing the given 167 * parameters if necessary. One of "Handle" or "Pathname" must 168 * be valid (non-null) 169 * 170 ******************************************************************************/ 171 acpi_status 172 acpi_evaluate_object(acpi_handle handle, 173 acpi_string pathname, 174 struct acpi_object_list *external_params, 175 struct acpi_buffer *return_buffer) 176 { 177 acpi_status status; 178 struct acpi_evaluate_info *info; 179 acpi_size buffer_space_needed; 180 u32 i; 181 182 ACPI_FUNCTION_TRACE(acpi_evaluate_object); 183 184 /* Allocate and initialize the evaluation information block */ 185 186 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info)); 187 if (!info) { 188 return_ACPI_STATUS(AE_NO_MEMORY); 189 } 190 191 /* Convert and validate the device handle */ 192 193 info->prefix_node = acpi_ns_validate_handle(handle); 194 if (!info->prefix_node) { 195 status = AE_BAD_PARAMETER; 196 goto cleanup; 197 } 198 199 /* 200 * Get the actual namespace node for the target object. 201 * Handles these cases: 202 * 203 * 1) Null node, valid pathname from root (absolute path) 204 * 2) Node and valid pathname (path relative to Node) 205 * 3) Node, Null pathname 206 */ 207 if ((pathname) && (ACPI_IS_ROOT_PREFIX(pathname[0]))) { 208 209 /* The path is fully qualified, just evaluate by name */ 210 211 info->prefix_node = NULL; 212 } else if (!handle) { 213 /* 214 * A handle is optional iff a fully qualified pathname is specified. 215 * Since we've already handled fully qualified names above, this is 216 * an error. 217 */ 218 if (!pathname) { 219 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 220 "Both Handle and Pathname are NULL")); 221 } else { 222 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 223 "Null Handle with relative pathname [%s]", 224 pathname)); 225 } 226 227 status = AE_BAD_PARAMETER; 228 goto cleanup; 229 } 230 231 info->relative_pathname = pathname; 232 233 /* 234 * Convert all external objects passed as arguments to the 235 * internal version(s). 236 */ 237 if (external_params && external_params->count) { 238 info->param_count = (u16)external_params->count; 239 240 /* Warn on impossible argument count */ 241 242 if (info->param_count > ACPI_METHOD_NUM_ARGS) { 243 ACPI_WARN_PREDEFINED((AE_INFO, pathname, 244 ACPI_WARN_ALWAYS, 245 "Excess arguments (%u) - using only %u", 246 info->param_count, 247 ACPI_METHOD_NUM_ARGS)); 248 249 info->param_count = ACPI_METHOD_NUM_ARGS; 250 } 251 252 /* 253 * Allocate a new parameter block for the internal objects 254 * Add 1 to count to allow for null terminated internal list 255 */ 256 info->parameters = ACPI_ALLOCATE_ZEROED(((acpi_size) info-> 257 param_count + 258 1) * sizeof(void *)); 259 if (!info->parameters) { 260 status = AE_NO_MEMORY; 261 goto cleanup; 262 } 263 264 /* Convert each external object in the list to an internal object */ 265 266 for (i = 0; i < info->param_count; i++) { 267 status = 268 acpi_ut_copy_eobject_to_iobject(&external_params-> 269 pointer[i], 270 &info-> 271 parameters[i]); 272 if (ACPI_FAILURE(status)) { 273 goto cleanup; 274 } 275 } 276 277 info->parameters[info->param_count] = NULL; 278 } 279 280 #if 0 281 282 /* 283 * Begin incoming argument count analysis. Check for too few args 284 * and too many args. 285 */ 286 287 switch (acpi_ns_get_type(info->node)) { 288 case ACPI_TYPE_METHOD: 289 290 /* Check incoming argument count against the method definition */ 291 292 if (info->obj_desc->method.param_count > info->param_count) { 293 ACPI_ERROR((AE_INFO, 294 "Insufficient arguments (%u) - %u are required", 295 info->param_count, 296 info->obj_desc->method.param_count)); 297 298 status = AE_MISSING_ARGUMENTS; 299 goto cleanup; 300 } 301 302 else if (info->obj_desc->method.param_count < info->param_count) { 303 ACPI_WARNING((AE_INFO, 304 "Excess arguments (%u) - only %u are required", 305 info->param_count, 306 info->obj_desc->method.param_count)); 307 308 /* Just pass the required number of arguments */ 309 310 info->param_count = info->obj_desc->method.param_count; 311 } 312 313 /* 314 * Any incoming external objects to be passed as arguments to the 315 * method must be converted to internal objects 316 */ 317 if (info->param_count) { 318 /* 319 * Allocate a new parameter block for the internal objects 320 * Add 1 to count to allow for null terminated internal list 321 */ 322 info->parameters = ACPI_ALLOCATE_ZEROED(((acpi_size) 323 info-> 324 param_count + 325 1) * 326 sizeof(void *)); 327 if (!info->parameters) { 328 status = AE_NO_MEMORY; 329 goto cleanup; 330 } 331 332 /* Convert each external object in the list to an internal object */ 333 334 for (i = 0; i < info->param_count; i++) { 335 status = 336 acpi_ut_copy_eobject_to_iobject 337 (&external_params->pointer[i], 338 &info->parameters[i]); 339 if (ACPI_FAILURE(status)) { 340 goto cleanup; 341 } 342 } 343 344 info->parameters[info->param_count] = NULL; 345 } 346 break; 347 348 default: 349 350 /* Warn if arguments passed to an object that is not a method */ 351 352 if (info->param_count) { 353 ACPI_WARNING((AE_INFO, 354 "%u arguments were passed to a non-method ACPI object", 355 info->param_count)); 356 } 357 break; 358 } 359 360 #endif 361 362 /* Now we can evaluate the object */ 363 364 status = acpi_ns_evaluate(info); 365 366 /* 367 * If we are expecting a return value, and all went well above, 368 * copy the return value to an external object. 369 */ 370 if (return_buffer) { 371 if (!info->return_object) { 372 return_buffer->length = 0; 373 } else { 374 if (ACPI_GET_DESCRIPTOR_TYPE(info->return_object) == 375 ACPI_DESC_TYPE_NAMED) { 376 /* 377 * If we received a NS Node as a return object, this means that 378 * the object we are evaluating has nothing interesting to 379 * return (such as a mutex, etc.) We return an error because 380 * these types are essentially unsupported by this interface. 381 * We don't check up front because this makes it easier to add 382 * support for various types at a later date if necessary. 383 */ 384 status = AE_TYPE; 385 info->return_object = NULL; /* No need to delete a NS Node */ 386 return_buffer->length = 0; 387 } 388 389 if (ACPI_SUCCESS(status)) { 390 391 /* Dereference Index and ref_of references */ 392 393 acpi_ns_resolve_references(info); 394 395 /* Get the size of the returned object */ 396 397 status = 398 acpi_ut_get_object_size(info->return_object, 399 &buffer_space_needed); 400 if (ACPI_SUCCESS(status)) { 401 402 /* Validate/Allocate/Clear caller buffer */ 403 404 status = 405 acpi_ut_initialize_buffer 406 (return_buffer, 407 buffer_space_needed); 408 if (ACPI_FAILURE(status)) { 409 /* 410 * Caller's buffer is too small or a new one can't 411 * be allocated 412 */ 413 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 414 "Needed buffer size %X, %s\n", 415 (u32) 416 buffer_space_needed, 417 acpi_format_exception 418 (status))); 419 } else { 420 /* We have enough space for the object, build it */ 421 422 status = 423 acpi_ut_copy_iobject_to_eobject 424 (info->return_object, 425 return_buffer); 426 } 427 } 428 } 429 } 430 } 431 432 if (info->return_object) { 433 /* 434 * Delete the internal return object. NOTE: Interpreter must be 435 * locked to avoid race condition. 436 */ 437 acpi_ex_enter_interpreter(); 438 439 /* Remove one reference on the return object (should delete it) */ 440 441 acpi_ut_remove_reference(info->return_object); 442 acpi_ex_exit_interpreter(); 443 } 444 445 cleanup: 446 447 /* Free the input parameter list (if we created one) */ 448 449 if (info->parameters) { 450 451 /* Free the allocated parameter block */ 452 453 acpi_ut_delete_internal_object_list(info->parameters); 454 } 455 456 ACPI_FREE(info); 457 return_ACPI_STATUS(status); 458 } 459 460 ACPI_EXPORT_SYMBOL(acpi_evaluate_object) 461 462 /******************************************************************************* 463 * 464 * FUNCTION: acpi_ns_resolve_references 465 * 466 * PARAMETERS: info - Evaluation info block 467 * 468 * RETURN: Info->return_object is replaced with the dereferenced object 469 * 470 * DESCRIPTION: Dereference certain reference objects. Called before an 471 * internal return object is converted to an external union acpi_object. 472 * 473 * Performs an automatic dereference of Index and ref_of reference objects. 474 * These reference objects are not supported by the union acpi_object, so this is a 475 * last resort effort to return something useful. Also, provides compatibility 476 * with other ACPI implementations. 477 * 478 * NOTE: does not handle references within returned package objects or nested 479 * references, but this support could be added later if found to be necessary. 480 * 481 ******************************************************************************/ 482 static void acpi_ns_resolve_references(struct acpi_evaluate_info *info) 483 { 484 union acpi_operand_object *obj_desc = NULL; 485 struct acpi_namespace_node *node; 486 487 /* We are interested in reference objects only */ 488 489 if ((info->return_object)->common.type != ACPI_TYPE_LOCAL_REFERENCE) { 490 return; 491 } 492 493 /* 494 * Two types of references are supported - those created by Index and 495 * ref_of operators. A name reference (AML_NAMEPATH_OP) can be converted 496 * to an union acpi_object, so it is not dereferenced here. A ddb_handle 497 * (AML_LOAD_OP) cannot be dereferenced, nor can it be converted to 498 * an union acpi_object. 499 */ 500 switch (info->return_object->reference.class) { 501 case ACPI_REFCLASS_INDEX: 502 503 obj_desc = *(info->return_object->reference.where); 504 break; 505 506 case ACPI_REFCLASS_REFOF: 507 508 node = info->return_object->reference.object; 509 if (node) { 510 obj_desc = node->object; 511 } 512 break; 513 514 default: 515 516 return; 517 } 518 519 /* Replace the existing reference object */ 520 521 if (obj_desc) { 522 acpi_ut_add_reference(obj_desc); 523 acpi_ut_remove_reference(info->return_object); 524 info->return_object = obj_desc; 525 } 526 527 return; 528 } 529 530 /******************************************************************************* 531 * 532 * FUNCTION: acpi_walk_namespace 533 * 534 * PARAMETERS: type - acpi_object_type to search for 535 * start_object - Handle in namespace where search begins 536 * max_depth - Depth to which search is to reach 537 * descending_callback - Called during tree descent 538 * when an object of "Type" is found 539 * ascending_callback - Called during tree ascent 540 * when an object of "Type" is found 541 * context - Passed to user function(s) above 542 * return_value - Location where return value of 543 * user_function is put if terminated early 544 * 545 * RETURNS Return value from the user_function if terminated early. 546 * Otherwise, returns NULL. 547 * 548 * DESCRIPTION: Performs a modified depth-first walk of the namespace tree, 549 * starting (and ending) at the object specified by start_handle. 550 * The callback function is called whenever an object that matches 551 * the type parameter is found. If the callback function returns 552 * a non-zero value, the search is terminated immediately and this 553 * value is returned to the caller. 554 * 555 * The point of this procedure is to provide a generic namespace 556 * walk routine that can be called from multiple places to 557 * provide multiple services; the callback function(s) can be 558 * tailored to each task, whether it is a print function, 559 * a compare function, etc. 560 * 561 ******************************************************************************/ 562 563 acpi_status 564 acpi_walk_namespace(acpi_object_type type, 565 acpi_handle start_object, 566 u32 max_depth, 567 acpi_walk_callback descending_callback, 568 acpi_walk_callback ascending_callback, 569 void *context, void **return_value) 570 { 571 acpi_status status; 572 573 ACPI_FUNCTION_TRACE(acpi_walk_namespace); 574 575 /* Parameter validation */ 576 577 if ((type > ACPI_TYPE_LOCAL_MAX) || 578 (!max_depth) || (!descending_callback && !ascending_callback)) { 579 return_ACPI_STATUS(AE_BAD_PARAMETER); 580 } 581 582 /* 583 * Need to acquire the namespace reader lock to prevent interference 584 * with any concurrent table unloads (which causes the deletion of 585 * namespace objects). We cannot allow the deletion of a namespace node 586 * while the user function is using it. The exception to this are the 587 * nodes created and deleted during control method execution -- these 588 * nodes are marked as temporary nodes and are ignored by the namespace 589 * walk. Thus, control methods can be executed while holding the 590 * namespace deletion lock (and the user function can execute control 591 * methods.) 592 */ 593 status = acpi_ut_acquire_read_lock(&acpi_gbl_namespace_rw_lock); 594 if (ACPI_FAILURE(status)) { 595 return_ACPI_STATUS(status); 596 } 597 598 /* 599 * Lock the namespace around the walk. The namespace will be 600 * unlocked/locked around each call to the user function - since the user 601 * function must be allowed to make ACPICA calls itself (for example, it 602 * will typically execute control methods during device enumeration.) 603 */ 604 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 605 if (ACPI_FAILURE(status)) { 606 goto unlock_and_exit; 607 } 608 609 /* Now we can validate the starting node */ 610 611 if (!acpi_ns_validate_handle(start_object)) { 612 status = AE_BAD_PARAMETER; 613 goto unlock_and_exit2; 614 } 615 616 status = acpi_ns_walk_namespace(type, start_object, max_depth, 617 ACPI_NS_WALK_UNLOCK, 618 descending_callback, ascending_callback, 619 context, return_value); 620 621 unlock_and_exit2: 622 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 623 624 unlock_and_exit: 625 (void)acpi_ut_release_read_lock(&acpi_gbl_namespace_rw_lock); 626 return_ACPI_STATUS(status); 627 } 628 629 ACPI_EXPORT_SYMBOL(acpi_walk_namespace) 630 631 /******************************************************************************* 632 * 633 * FUNCTION: acpi_ns_get_device_callback 634 * 635 * PARAMETERS: Callback from acpi_get_device 636 * 637 * RETURN: Status 638 * 639 * DESCRIPTION: Takes callbacks from walk_namespace and filters out all non- 640 * present devices, or if they specified a HID, it filters based 641 * on that. 642 * 643 ******************************************************************************/ 644 static acpi_status 645 acpi_ns_get_device_callback(acpi_handle obj_handle, 646 u32 nesting_level, 647 void *context, void **return_value) 648 { 649 struct acpi_get_devices_info *info = context; 650 acpi_status status; 651 struct acpi_namespace_node *node; 652 u32 flags; 653 struct acpi_pnp_device_id *hid; 654 struct acpi_pnp_device_id_list *cid; 655 u32 i; 656 u8 found; 657 int no_match; 658 659 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 660 if (ACPI_FAILURE(status)) { 661 return (status); 662 } 663 664 node = acpi_ns_validate_handle(obj_handle); 665 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 666 if (ACPI_FAILURE(status)) { 667 return (status); 668 } 669 670 if (!node) { 671 return (AE_BAD_PARAMETER); 672 } 673 674 /* 675 * First, filter based on the device HID and CID. 676 * 677 * 01/2010: For this case where a specific HID is requested, we don't 678 * want to run _STA until we have an actual HID match. Thus, we will 679 * not unnecessarily execute _STA on devices for which the caller 680 * doesn't care about. Previously, _STA was executed unconditionally 681 * on all devices found here. 682 * 683 * A side-effect of this change is that now we will continue to search 684 * for a matching HID even under device trees where the parent device 685 * would have returned a _STA that indicates it is not present or 686 * not functioning (thus aborting the search on that branch). 687 */ 688 if (info->hid != NULL) { 689 status = acpi_ut_execute_HID(node, &hid); 690 if (status == AE_NOT_FOUND) { 691 return (AE_OK); 692 } else if (ACPI_FAILURE(status)) { 693 return (AE_CTRL_DEPTH); 694 } 695 696 no_match = ACPI_STRCMP(hid->string, info->hid); 697 ACPI_FREE(hid); 698 699 if (no_match) { 700 /* 701 * HID does not match, attempt match within the 702 * list of Compatible IDs (CIDs) 703 */ 704 status = acpi_ut_execute_CID(node, &cid); 705 if (status == AE_NOT_FOUND) { 706 return (AE_OK); 707 } else if (ACPI_FAILURE(status)) { 708 return (AE_CTRL_DEPTH); 709 } 710 711 /* Walk the CID list */ 712 713 found = FALSE; 714 for (i = 0; i < cid->count; i++) { 715 if (ACPI_STRCMP(cid->ids[i].string, info->hid) 716 == 0) { 717 718 /* Found a matching CID */ 719 720 found = TRUE; 721 break; 722 } 723 } 724 725 ACPI_FREE(cid); 726 if (!found) { 727 return (AE_OK); 728 } 729 } 730 } 731 732 /* Run _STA to determine if device is present */ 733 734 status = acpi_ut_execute_STA(node, &flags); 735 if (ACPI_FAILURE(status)) { 736 return (AE_CTRL_DEPTH); 737 } 738 739 if (!(flags & ACPI_STA_DEVICE_PRESENT) && 740 !(flags & ACPI_STA_DEVICE_FUNCTIONING)) { 741 /* 742 * Don't examine the children of the device only when the 743 * device is neither present nor functional. See ACPI spec, 744 * description of _STA for more information. 745 */ 746 return (AE_CTRL_DEPTH); 747 } 748 749 /* We have a valid device, invoke the user function */ 750 751 status = info->user_function(obj_handle, nesting_level, info->context, 752 return_value); 753 return (status); 754 } 755 756 /******************************************************************************* 757 * 758 * FUNCTION: acpi_get_devices 759 * 760 * PARAMETERS: HID - HID to search for. Can be NULL. 761 * user_function - Called when a matching object is found 762 * context - Passed to user function 763 * return_value - Location where return value of 764 * user_function is put if terminated early 765 * 766 * RETURNS Return value from the user_function if terminated early. 767 * Otherwise, returns NULL. 768 * 769 * DESCRIPTION: Performs a modified depth-first walk of the namespace tree, 770 * starting (and ending) at the object specified by start_handle. 771 * The user_function is called whenever an object of type 772 * Device is found. If the user function returns 773 * a non-zero value, the search is terminated immediately and this 774 * value is returned to the caller. 775 * 776 * This is a wrapper for walk_namespace, but the callback performs 777 * additional filtering. Please see acpi_ns_get_device_callback. 778 * 779 ******************************************************************************/ 780 781 acpi_status 782 acpi_get_devices(const char *HID, 783 acpi_walk_callback user_function, 784 void *context, void **return_value) 785 { 786 acpi_status status; 787 struct acpi_get_devices_info info; 788 789 ACPI_FUNCTION_TRACE(acpi_get_devices); 790 791 /* Parameter validation */ 792 793 if (!user_function) { 794 return_ACPI_STATUS(AE_BAD_PARAMETER); 795 } 796 797 /* 798 * We're going to call their callback from OUR callback, so we need 799 * to know what it is, and their context parameter. 800 */ 801 info.hid = HID; 802 info.context = context; 803 info.user_function = user_function; 804 805 /* 806 * Lock the namespace around the walk. 807 * The namespace will be unlocked/locked around each call 808 * to the user function - since this function 809 * must be allowed to make Acpi calls itself. 810 */ 811 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 812 if (ACPI_FAILURE(status)) { 813 return_ACPI_STATUS(status); 814 } 815 816 status = acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, 817 ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK, 818 acpi_ns_get_device_callback, NULL, 819 &info, return_value); 820 821 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 822 return_ACPI_STATUS(status); 823 } 824 825 ACPI_EXPORT_SYMBOL(acpi_get_devices) 826 827 /******************************************************************************* 828 * 829 * FUNCTION: acpi_attach_data 830 * 831 * PARAMETERS: obj_handle - Namespace node 832 * handler - Handler for this attachment 833 * data - Pointer to data to be attached 834 * 835 * RETURN: Status 836 * 837 * DESCRIPTION: Attach arbitrary data and handler to a namespace node. 838 * 839 ******************************************************************************/ 840 acpi_status 841 acpi_attach_data(acpi_handle obj_handle, 842 acpi_object_handler handler, void *data) 843 { 844 struct acpi_namespace_node *node; 845 acpi_status status; 846 847 /* Parameter validation */ 848 849 if (!obj_handle || !handler || !data) { 850 return (AE_BAD_PARAMETER); 851 } 852 853 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 854 if (ACPI_FAILURE(status)) { 855 return (status); 856 } 857 858 /* Convert and validate the handle */ 859 860 node = acpi_ns_validate_handle(obj_handle); 861 if (!node) { 862 status = AE_BAD_PARAMETER; 863 goto unlock_and_exit; 864 } 865 866 status = acpi_ns_attach_data(node, handler, data); 867 868 unlock_and_exit: 869 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 870 return (status); 871 } 872 873 ACPI_EXPORT_SYMBOL(acpi_attach_data) 874 875 /******************************************************************************* 876 * 877 * FUNCTION: acpi_detach_data 878 * 879 * PARAMETERS: obj_handle - Namespace node handle 880 * handler - Handler used in call to acpi_attach_data 881 * 882 * RETURN: Status 883 * 884 * DESCRIPTION: Remove data that was previously attached to a node. 885 * 886 ******************************************************************************/ 887 acpi_status 888 acpi_detach_data(acpi_handle obj_handle, acpi_object_handler handler) 889 { 890 struct acpi_namespace_node *node; 891 acpi_status status; 892 893 /* Parameter validation */ 894 895 if (!obj_handle || !handler) { 896 return (AE_BAD_PARAMETER); 897 } 898 899 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 900 if (ACPI_FAILURE(status)) { 901 return (status); 902 } 903 904 /* Convert and validate the handle */ 905 906 node = acpi_ns_validate_handle(obj_handle); 907 if (!node) { 908 status = AE_BAD_PARAMETER; 909 goto unlock_and_exit; 910 } 911 912 status = acpi_ns_detach_data(node, handler); 913 914 unlock_and_exit: 915 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 916 return (status); 917 } 918 919 ACPI_EXPORT_SYMBOL(acpi_detach_data) 920 921 /******************************************************************************* 922 * 923 * FUNCTION: acpi_get_data 924 * 925 * PARAMETERS: obj_handle - Namespace node 926 * handler - Handler used in call to attach_data 927 * data - Where the data is returned 928 * 929 * RETURN: Status 930 * 931 * DESCRIPTION: Retrieve data that was previously attached to a namespace node. 932 * 933 ******************************************************************************/ 934 acpi_status 935 acpi_get_data(acpi_handle obj_handle, acpi_object_handler handler, void **data) 936 { 937 struct acpi_namespace_node *node; 938 acpi_status status; 939 940 /* Parameter validation */ 941 942 if (!obj_handle || !handler || !data) { 943 return (AE_BAD_PARAMETER); 944 } 945 946 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 947 if (ACPI_FAILURE(status)) { 948 return (status); 949 } 950 951 /* Convert and validate the handle */ 952 953 node = acpi_ns_validate_handle(obj_handle); 954 if (!node) { 955 status = AE_BAD_PARAMETER; 956 goto unlock_and_exit; 957 } 958 959 status = acpi_ns_get_attached_data(node, handler, data); 960 961 unlock_and_exit: 962 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 963 return (status); 964 } 965 966 ACPI_EXPORT_SYMBOL(acpi_get_data) 967