nsxfeval.c revision 107325
1/******************************************************************************* 2 * 3 * Module Name: nsxfeval - Public interfaces to the ACPI subsystem 4 * ACPI Object evaluation interfaces 5 * $Revision: 4 $ 6 * 7 ******************************************************************************/ 8 9/****************************************************************************** 10 * 11 * 1. Copyright Notice 12 * 13 * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp. 14 * All rights reserved. 15 * 16 * 2. License 17 * 18 * 2.1. This is your license from Intel Corp. under its intellectual property 19 * rights. You may have additional license terms from the party that provided 20 * you this software, covering your right to use that party's intellectual 21 * property rights. 22 * 23 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 24 * copy of the source code appearing in this file ("Covered Code") an 25 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 26 * base code distributed originally by Intel ("Original Intel Code") to copy, 27 * make derivatives, distribute, use and display any portion of the Covered 28 * Code in any form, with the right to sublicense such rights; and 29 * 30 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 31 * license (with the right to sublicense), under only those claims of Intel 32 * patents that are infringed by the Original Intel Code, to make, use, sell, 33 * offer to sell, and import the Covered Code and derivative works thereof 34 * solely to the minimum extent necessary to exercise the above copyright 35 * license, and in no event shall the patent license extend to any additions 36 * to or modifications of the Original Intel Code. No other license or right 37 * is granted directly or by implication, estoppel or otherwise; 38 * 39 * The above copyright and patent license is granted only if the following 40 * conditions are met: 41 * 42 * 3. Conditions 43 * 44 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 45 * Redistribution of source code of any substantial portion of the Covered 46 * Code or modification with rights to further distribute source must include 47 * the above Copyright Notice, the above License, this list of Conditions, 48 * and the following Disclaimer and Export Compliance provision. In addition, 49 * Licensee must cause all Covered Code to which Licensee contributes to 50 * contain a file documenting the changes Licensee made to create that Covered 51 * Code and the date of any change. Licensee must include in that file the 52 * documentation of any changes made by any predecessor Licensee. Licensee 53 * must include a prominent statement that the modification is derived, 54 * directly or indirectly, from Original Intel Code. 55 * 56 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 57 * Redistribution of source code of any substantial portion of the Covered 58 * Code or modification without rights to further distribute source must 59 * include the following Disclaimer and Export Compliance provision in the 60 * documentation and/or other materials provided with distribution. In 61 * addition, Licensee may not authorize further sublicense of source of any 62 * portion of the Covered Code, and must include terms to the effect that the 63 * license from Licensee to its licensee is limited to the intellectual 64 * property embodied in the software Licensee provides to its licensee, and 65 * not to intellectual property embodied in modifications its licensee may 66 * make. 67 * 68 * 3.3. Redistribution of Executable. Redistribution in executable form of any 69 * substantial portion of the Covered Code or modification must reproduce the 70 * above Copyright Notice, and the following Disclaimer and Export Compliance 71 * provision in the documentation and/or other materials provided with the 72 * distribution. 73 * 74 * 3.4. Intel retains all right, title, and interest in and to the Original 75 * Intel Code. 76 * 77 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 78 * Intel shall be used in advertising or otherwise to promote the sale, use or 79 * other dealings in products derived from or relating to the Covered Code 80 * without prior written authorization from Intel. 81 * 82 * 4. Disclaimer and Export Compliance 83 * 84 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 85 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 86 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 87 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 88 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 89 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 90 * PARTICULAR PURPOSE. 91 * 92 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 93 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 94 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 95 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 96 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 97 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 98 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 99 * LIMITED REMEDY. 100 * 101 * 4.3. Licensee shall not export, either directly or indirectly, any of this 102 * software or system incorporating such software without first obtaining any 103 * required license or other approval from the U. S. Department of Commerce or 104 * any other agency or department of the United States Government. In the 105 * event Licensee exports any such software from the United States or 106 * re-exports any such software from a foreign destination, Licensee shall 107 * ensure that the distribution and export/re-export of the software is in 108 * compliance with all laws, regulations, orders, or other restrictions of the 109 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 110 * any of its subsidiaries will export/re-export any technical data, process, 111 * software, or service, directly or indirectly, to any country for which the 112 * United States government or any agency thereof requires an export license, 113 * other governmental approval, or letter of assurance, without first obtaining 114 * such license, approval or letter. 115 * 116 *****************************************************************************/ 117 118 119#define __NSXFEVAL_C__ 120 121#include "acpi.h" 122#include "acnamesp.h" 123 124 125#define _COMPONENT ACPI_NAMESPACE 126 ACPI_MODULE_NAME ("nsxfeval") 127 128 129/******************************************************************************* 130 * 131 * FUNCTION: AcpiEvaluateObjectTyped 132 * 133 * PARAMETERS: Handle - Object handle (optional) 134 * *Pathname - Object pathname (optional) 135 * **ExternalParams - List of parameters to pass to method, 136 * terminated by NULL. May be NULL 137 * if no parameters are being passed. 138 * *ReturnBuffer - Where to put method's return value (if 139 * any). If NULL, no value is returned. 140 * ReturnType - Expected type of return object 141 * 142 * RETURN: Status 143 * 144 * DESCRIPTION: Find and evaluate the given object, passing the given 145 * parameters if necessary. One of "Handle" or "Pathname" must 146 * be valid (non-null) 147 * 148 ******************************************************************************/ 149 150ACPI_STATUS 151AcpiEvaluateObjectTyped ( 152 ACPI_HANDLE Handle, 153 ACPI_STRING Pathname, 154 ACPI_OBJECT_LIST *ExternalParams, 155 ACPI_BUFFER *ReturnBuffer, 156 ACPI_OBJECT_TYPE ReturnType) 157{ 158 ACPI_STATUS Status; 159 BOOLEAN MustFree = FALSE; 160 161 162 ACPI_FUNCTION_TRACE ("AcpiEvaluateObjectTyped"); 163 164 165 /* Return buffer must be valid */ 166 167 if (!ReturnBuffer) 168 { 169 return_ACPI_STATUS (AE_BAD_PARAMETER); 170 } 171 172 if (ReturnBuffer->Length == ACPI_ALLOCATE_BUFFER) 173 { 174 MustFree = TRUE; 175 } 176 177 /* Evaluate the object */ 178 179 Status = AcpiEvaluateObject (Handle, Pathname, ExternalParams, ReturnBuffer); 180 if (ACPI_FAILURE (Status)) 181 { 182 return_ACPI_STATUS (Status); 183 } 184 185 /* Type ANY means "don't care" */ 186 187 if (ReturnType == ACPI_TYPE_ANY) 188 { 189 return_ACPI_STATUS (AE_OK); 190 } 191 192 if (ReturnBuffer->Length == 0) 193 { 194 /* Error because caller specifically asked for a return value */ 195 196 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 197 "No return value\n")); 198 199 return_ACPI_STATUS (AE_NULL_OBJECT); 200 } 201 202 /* Examine the object type returned from EvaluateObject */ 203 204 if (((ACPI_OBJECT *) ReturnBuffer->Pointer)->Type == ReturnType) 205 { 206 return_ACPI_STATUS (AE_OK); 207 } 208 209 /* Return object type does not match requested type */ 210 211 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 212 "Incorrect return type [%s] requested [%s]\n", 213 AcpiUtGetTypeName (((ACPI_OBJECT *) ReturnBuffer->Pointer)->Type), 214 AcpiUtGetTypeName (ReturnType))); 215 216 if (MustFree) 217 { 218 /* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */ 219 220 AcpiOsFree (ReturnBuffer->Pointer); 221 ReturnBuffer->Pointer = NULL; 222 } 223 224 ReturnBuffer->Length = 0; 225 return_ACPI_STATUS (AE_TYPE); 226} 227 228 229/******************************************************************************* 230 * 231 * FUNCTION: AcpiEvaluateObject 232 * 233 * PARAMETERS: Handle - Object handle (optional) 234 * *Pathname - Object pathname (optional) 235 * **ExternalParams - List of parameters to pass to method, 236 * terminated by NULL. May be NULL 237 * if no parameters are being passed. 238 * *ReturnBuffer - Where to put method's return value (if 239 * any). If NULL, no value is returned. 240 * 241 * RETURN: Status 242 * 243 * DESCRIPTION: Find and evaluate the given object, passing the given 244 * parameters if necessary. One of "Handle" or "Pathname" must 245 * be valid (non-null) 246 * 247 ******************************************************************************/ 248 249ACPI_STATUS 250AcpiEvaluateObject ( 251 ACPI_HANDLE Handle, 252 ACPI_STRING Pathname, 253 ACPI_OBJECT_LIST *ExternalParams, 254 ACPI_BUFFER *ReturnBuffer) 255{ 256 ACPI_STATUS Status; 257 ACPI_OPERAND_OBJECT **InternalParams = NULL; 258 ACPI_OPERAND_OBJECT *InternalReturnObj = NULL; 259 ACPI_SIZE BufferSpaceNeeded; 260 UINT32 i; 261 262 263 ACPI_FUNCTION_TRACE ("AcpiEvaluateObject"); 264 265 266 /* 267 * If there are parameters to be passed to the object 268 * (which must be a control method), the external objects 269 * must be converted to internal objects 270 */ 271 if (ExternalParams && ExternalParams->Count) 272 { 273 /* 274 * Allocate a new parameter block for the internal objects 275 * Add 1 to count to allow for null terminated internal list 276 */ 277 InternalParams = ACPI_MEM_CALLOCATE (((ACPI_SIZE) ExternalParams->Count + 1) * 278 sizeof (void *)); 279 if (!InternalParams) 280 { 281 return_ACPI_STATUS (AE_NO_MEMORY); 282 } 283 284 /* 285 * Convert each external object in the list to an 286 * internal object 287 */ 288 for (i = 0; i < ExternalParams->Count; i++) 289 { 290 Status = AcpiUtCopyEobjectToIobject (&ExternalParams->Pointer[i], 291 &InternalParams[i]); 292 if (ACPI_FAILURE (Status)) 293 { 294 AcpiUtDeleteInternalObjectList (InternalParams); 295 return_ACPI_STATUS (Status); 296 } 297 } 298 InternalParams[ExternalParams->Count] = NULL; 299 } 300 301 /* 302 * Three major cases: 303 * 1) Fully qualified pathname 304 * 2) No handle, not fully qualified pathname (error) 305 * 3) Valid handle 306 */ 307 if ((Pathname) && 308 (AcpiNsValidRootPrefix (Pathname[0]))) 309 { 310 /* 311 * The path is fully qualified, just evaluate by name 312 */ 313 Status = AcpiNsEvaluateByName (Pathname, InternalParams, 314 &InternalReturnObj); 315 } 316 else if (!Handle) 317 { 318 /* 319 * A handle is optional iff a fully qualified pathname 320 * is specified. Since we've already handled fully 321 * qualified names above, this is an error 322 */ 323 if (!Pathname) 324 { 325 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 326 "Both Handle and Pathname are NULL\n")); 327 } 328 else 329 { 330 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 331 "Handle is NULL and Pathname is relative\n")); 332 } 333 334 Status = AE_BAD_PARAMETER; 335 } 336 else 337 { 338 /* 339 * We get here if we have a handle -- and if we have a 340 * pathname it is relative. The handle will be validated 341 * in the lower procedures 342 */ 343 if (!Pathname) 344 { 345 /* 346 * The null pathname case means the handle is for 347 * the actual object to be evaluated 348 */ 349 Status = AcpiNsEvaluateByHandle (Handle, InternalParams, 350 &InternalReturnObj); 351 } 352 else 353 { 354 /* 355 * Both a Handle and a relative Pathname 356 */ 357 Status = AcpiNsEvaluateRelative (Handle, Pathname, InternalParams, 358 &InternalReturnObj); 359 } 360 } 361 362 363 /* 364 * If we are expecting a return value, and all went well above, 365 * copy the return value to an external object. 366 */ 367 if (ReturnBuffer) 368 { 369 if (!InternalReturnObj) 370 { 371 ReturnBuffer->Length = 0; 372 } 373 else 374 { 375 if (ACPI_GET_DESCRIPTOR_TYPE (InternalReturnObj) == ACPI_DESC_TYPE_NAMED) 376 { 377 /* 378 * If we received a NS Node as a return object, this means that 379 * the object we are evaluating has nothing interesting to 380 * return (such as a mutex, etc.) We return an error because 381 * these types are essentially unsupported by this interface. 382 * We don't check up front because this makes it easier to add 383 * support for various types at a later date if necessary. 384 */ 385 Status = AE_TYPE; 386 InternalReturnObj = NULL; /* No need to delete a NS Node */ 387 ReturnBuffer->Length = 0; 388 } 389 390 if (ACPI_SUCCESS (Status)) 391 { 392 /* 393 * Find out how large a buffer is needed 394 * to contain the returned object 395 */ 396 Status = AcpiUtGetObjectSize (InternalReturnObj, 397 &BufferSpaceNeeded); 398 if (ACPI_SUCCESS (Status)) 399 { 400 /* Validate/Allocate/Clear caller buffer */ 401 402 Status = AcpiUtInitializeBuffer (ReturnBuffer, BufferSpaceNeeded); 403 if (ACPI_FAILURE (Status)) 404 { 405 /* 406 * Caller's buffer is too small or a new one can't be allocated 407 */ 408 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 409 "Needed buffer size %X, %s\n", 410 (UINT32) BufferSpaceNeeded, AcpiFormatException (Status))); 411 } 412 else 413 { 414 /* 415 * We have enough space for the object, build it 416 */ 417 Status = AcpiUtCopyIobjectToEobject (InternalReturnObj, 418 ReturnBuffer); 419 } 420 } 421 } 422 } 423 } 424 425 /* Delete the return and parameter objects */ 426 427 if (InternalReturnObj) 428 { 429 /* 430 * Delete the internal return object. (Or at least 431 * decrement the reference count by one) 432 */ 433 AcpiUtRemoveReference (InternalReturnObj); 434 } 435 436 /* 437 * Free the input parameter list (if we created one), 438 */ 439 if (InternalParams) 440 { 441 /* Free the allocated parameter block */ 442 443 AcpiUtDeleteInternalObjectList (InternalParams); 444 } 445 446 return_ACPI_STATUS (Status); 447} 448 449 450/******************************************************************************* 451 * 452 * FUNCTION: AcpiWalkNamespace 453 * 454 * PARAMETERS: Type - ACPI_OBJECT_TYPE to search for 455 * StartObject - Handle in namespace where search begins 456 * MaxDepth - Depth to which search is to reach 457 * UserFunction - Called when an object of "Type" is found 458 * Context - Passed to user function 459 * ReturnValue - Location where return value of 460 * UserFunction is put if terminated early 461 * 462 * RETURNS Return value from the UserFunction if terminated early. 463 * Otherwise, returns NULL. 464 * 465 * DESCRIPTION: Performs a modified depth-first walk of the namespace tree, 466 * starting (and ending) at the object specified by StartHandle. 467 * The UserFunction is called whenever an object that matches 468 * the type parameter is found. If the user function returns 469 * a non-zero value, the search is terminated immediately and this 470 * value is returned to the caller. 471 * 472 * The point of this procedure is to provide a generic namespace 473 * walk routine that can be called from multiple places to 474 * provide multiple services; the User Function can be tailored 475 * to each task, whether it is a print function, a compare 476 * function, etc. 477 * 478 ******************************************************************************/ 479 480ACPI_STATUS 481AcpiWalkNamespace ( 482 ACPI_OBJECT_TYPE Type, 483 ACPI_HANDLE StartObject, 484 UINT32 MaxDepth, 485 ACPI_WALK_CALLBACK UserFunction, 486 void *Context, 487 void **ReturnValue) 488{ 489 ACPI_STATUS Status; 490 491 492 ACPI_FUNCTION_TRACE ("AcpiWalkNamespace"); 493 494 495 /* Parameter validation */ 496 497 if ((Type > ACPI_TYPE_EXTERNAL_MAX) || 498 (!MaxDepth) || 499 (!UserFunction)) 500 { 501 return_ACPI_STATUS (AE_BAD_PARAMETER); 502 } 503 504 /* 505 * Lock the namespace around the walk. 506 * The namespace will be unlocked/locked around each call 507 * to the user function - since this function 508 * must be allowed to make Acpi calls itself. 509 */ 510 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 511 if (ACPI_FAILURE (Status)) 512 { 513 return_ACPI_STATUS (Status); 514 } 515 516 Status = AcpiNsWalkNamespace (Type, StartObject, MaxDepth, ACPI_NS_WALK_UNLOCK, 517 UserFunction, Context, ReturnValue); 518 519 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 520 return_ACPI_STATUS (Status); 521} 522 523 524/******************************************************************************* 525 * 526 * FUNCTION: AcpiNsGetDeviceCallback 527 * 528 * PARAMETERS: Callback from AcpiGetDevice 529 * 530 * RETURN: Status 531 * 532 * DESCRIPTION: Takes callbacks from WalkNamespace and filters out all non- 533 * present devices, or if they specified a HID, it filters based 534 * on that. 535 * 536 ******************************************************************************/ 537 538static ACPI_STATUS 539AcpiNsGetDeviceCallback ( 540 ACPI_HANDLE ObjHandle, 541 UINT32 NestingLevel, 542 void *Context, 543 void **ReturnValue) 544{ 545 ACPI_STATUS Status; 546 ACPI_NAMESPACE_NODE *Node; 547 UINT32 Flags; 548 ACPI_DEVICE_ID Hid; 549 ACPI_DEVICE_ID Cid; 550 ACPI_GET_DEVICES_INFO *Info; 551 552 553 Info = Context; 554 555 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 556 if (ACPI_FAILURE (Status)) 557 { 558 return (Status); 559 } 560 561 Node = AcpiNsMapHandleToNode (ObjHandle); 562 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 563 if (ACPI_FAILURE (Status)) 564 { 565 return (Status); 566 } 567 568 if (!Node) 569 { 570 return (AE_BAD_PARAMETER); 571 } 572 573 /* 574 * Run _STA to determine if device is present 575 */ 576 Status = AcpiUtExecute_STA (Node, &Flags); 577 if (ACPI_FAILURE (Status)) 578 { 579 return (AE_CTRL_DEPTH); 580 } 581 582 if (!(Flags & 0x01)) 583 { 584 /* Don't return at the device or children of the device if not there */ 585 return (AE_CTRL_DEPTH); 586 } 587 588 /* 589 * Filter based on device HID & CID 590 */ 591 if (Info->Hid != NULL) 592 { 593 Status = AcpiUtExecute_HID (Node, &Hid); 594 if (Status == AE_NOT_FOUND) 595 { 596 return (AE_OK); 597 } 598 else if (ACPI_FAILURE (Status)) 599 { 600 return (AE_CTRL_DEPTH); 601 } 602 603 if (ACPI_STRNCMP (Hid.Buffer, Info->Hid, sizeof (Hid.Buffer)) != 0) 604 { 605 Status = AcpiUtExecute_CID (Node, &Cid); 606 if (Status == AE_NOT_FOUND) 607 { 608 return (AE_OK); 609 } 610 else if (ACPI_FAILURE (Status)) 611 { 612 return (AE_CTRL_DEPTH); 613 } 614 615 /* TBD: Handle CID packages */ 616 617 if (ACPI_STRNCMP (Cid.Buffer, Info->Hid, sizeof (Cid.Buffer)) != 0) 618 { 619 return (AE_OK); 620 } 621 } 622 } 623 624 Status = Info->UserFunction (ObjHandle, NestingLevel, Info->Context, ReturnValue); 625 return (Status); 626} 627 628 629/******************************************************************************* 630 * 631 * FUNCTION: AcpiGetDevices 632 * 633 * PARAMETERS: HID - HID to search for. Can be NULL. 634 * UserFunction - Called when a matching object is found 635 * Context - Passed to user function 636 * ReturnValue - Location where return value of 637 * UserFunction is put if terminated early 638 * 639 * RETURNS Return value from the UserFunction if terminated early. 640 * Otherwise, returns NULL. 641 * 642 * DESCRIPTION: Performs a modified depth-first walk of the namespace tree, 643 * starting (and ending) at the object specified by StartHandle. 644 * The UserFunction is called whenever an object that matches 645 * the type parameter is found. If the user function returns 646 * a non-zero value, the search is terminated immediately and this 647 * value is returned to the caller. 648 * 649 * This is a wrapper for WalkNamespace, but the callback performs 650 * additional filtering. Please see AcpiGetDeviceCallback. 651 * 652 ******************************************************************************/ 653 654ACPI_STATUS 655AcpiGetDevices ( 656 NATIVE_CHAR *HID, 657 ACPI_WALK_CALLBACK UserFunction, 658 void *Context, 659 void **ReturnValue) 660{ 661 ACPI_STATUS Status; 662 ACPI_GET_DEVICES_INFO Info; 663 664 665 ACPI_FUNCTION_TRACE ("AcpiGetDevices"); 666 667 668 /* Parameter validation */ 669 670 if (!UserFunction) 671 { 672 return_ACPI_STATUS (AE_BAD_PARAMETER); 673 } 674 675 /* 676 * We're going to call their callback from OUR callback, so we need 677 * to know what it is, and their context parameter. 678 */ 679 Info.Context = Context; 680 Info.UserFunction = UserFunction; 681 Info.Hid = HID; 682 683 /* 684 * Lock the namespace around the walk. 685 * The namespace will be unlocked/locked around each call 686 * to the user function - since this function 687 * must be allowed to make Acpi calls itself. 688 */ 689 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 690 if (ACPI_FAILURE (Status)) 691 { 692 return_ACPI_STATUS (Status); 693 } 694 695 Status = AcpiNsWalkNamespace (ACPI_TYPE_DEVICE, 696 ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, 697 ACPI_NS_WALK_UNLOCK, 698 AcpiNsGetDeviceCallback, &Info, 699 ReturnValue); 700 701 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 702 return_ACPI_STATUS (Status); 703} 704 705 706/******************************************************************************* 707 * 708 * FUNCTION: AcpiAttachData 709 * 710 * PARAMETERS: ObjHandle - Namespace node 711 * Handler - Handler for this attachment 712 * Data - Pointer to data to be attached 713 * 714 * RETURN: Status 715 * 716 * DESCRIPTION: Attach arbitrary data and handler to a namespace node. 717 * 718 ******************************************************************************/ 719 720ACPI_STATUS 721AcpiAttachData ( 722 ACPI_HANDLE ObjHandle, 723 ACPI_OBJECT_HANDLER Handler, 724 void *Data) 725{ 726 ACPI_NAMESPACE_NODE *Node; 727 ACPI_STATUS Status; 728 729 730 /* Parameter validation */ 731 732 if (!ObjHandle || 733 !Handler || 734 !Data) 735 { 736 return (AE_BAD_PARAMETER); 737 } 738 739 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 740 if (ACPI_FAILURE (Status)) 741 { 742 return (Status); 743 } 744 745 /* Convert and validate the handle */ 746 747 Node = AcpiNsMapHandleToNode (ObjHandle); 748 if (!Node) 749 { 750 Status = AE_BAD_PARAMETER; 751 goto UnlockAndExit; 752 } 753 754 Status = AcpiNsAttachData (Node, Handler, Data); 755 756UnlockAndExit: 757 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 758 return (Status); 759} 760 761 762/******************************************************************************* 763 * 764 * FUNCTION: AcpiDetachData 765 * 766 * PARAMETERS: ObjHandle - Namespace node handle 767 * Handler - Handler used in call to AcpiAttachData 768 * 769 * RETURN: Status 770 * 771 * DESCRIPTION: Remove data that was previously attached to a node. 772 * 773 ******************************************************************************/ 774 775ACPI_STATUS 776AcpiDetachData ( 777 ACPI_HANDLE ObjHandle, 778 ACPI_OBJECT_HANDLER Handler) 779{ 780 ACPI_NAMESPACE_NODE *Node; 781 ACPI_STATUS Status; 782 783 784 /* Parameter validation */ 785 786 if (!ObjHandle || 787 !Handler) 788 { 789 return (AE_BAD_PARAMETER); 790 } 791 792 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 793 if (ACPI_FAILURE (Status)) 794 { 795 return (Status); 796 } 797 798 /* Convert and validate the handle */ 799 800 Node = AcpiNsMapHandleToNode (ObjHandle); 801 if (!Node) 802 { 803 Status = AE_BAD_PARAMETER; 804 goto UnlockAndExit; 805 } 806 807 Status = AcpiNsDetachData (Node, Handler); 808 809UnlockAndExit: 810 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 811 return (Status); 812} 813 814 815/******************************************************************************* 816 * 817 * FUNCTION: AcpiGetData 818 * 819 * PARAMETERS: ObjHandle - Namespace node 820 * Handler - Handler used in call to AttachData 821 * Data - Where the data is returned 822 * 823 * RETURN: Status 824 * 825 * DESCRIPTION: Retrieve data that was previously attached to a namespace node. 826 * 827 ******************************************************************************/ 828 829ACPI_STATUS 830AcpiGetData ( 831 ACPI_HANDLE ObjHandle, 832 ACPI_OBJECT_HANDLER Handler, 833 void **Data) 834{ 835 ACPI_NAMESPACE_NODE *Node; 836 ACPI_STATUS Status; 837 838 839 /* Parameter validation */ 840 841 if (!ObjHandle || 842 !Handler || 843 !Data) 844 { 845 return (AE_BAD_PARAMETER); 846 } 847 848 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 849 if (ACPI_FAILURE (Status)) 850 { 851 return (Status); 852 } 853 854 /* Convert and validate the handle */ 855 856 Node = AcpiNsMapHandleToNode (ObjHandle); 857 if (!Node) 858 { 859 Status = AE_BAD_PARAMETER; 860 goto UnlockAndExit; 861 } 862 863 Status = AcpiNsGetAttachedData (Node, Handler, Data); 864 865UnlockAndExit: 866 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 867 return (Status); 868} 869 870 871