1 /******************************************************************************* 2 * 3 * Module Name: dsmthdat - control method arguments and local variables 4 * 5 ******************************************************************************/ 6 7 /****************************************************************************** 8 * 9 * 1. Copyright Notice 10 * 11 * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp. 12 * All rights reserved. 13 * 14 * 2. License 15 * 16 * 2.1. This is your license from Intel Corp. under its intellectual property 17 * rights. You may have additional license terms from the party that provided 18 * you this software, covering your right to use that party's intellectual 19 * property rights. 20 * 21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22 * copy of the source code appearing in this file ("Covered Code") an 23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24 * base code distributed originally by Intel ("Original Intel Code") to copy, 25 * make derivatives, distribute, use and display any portion of the Covered 26 * Code in any form, with the right to sublicense such rights; and 27 * 28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29 * license (with the right to sublicense), under only those claims of Intel 30 * patents that are infringed by the Original Intel Code, to make, use, sell, 31 * offer to sell, and import the Covered Code and derivative works thereof 32 * solely to the minimum extent necessary to exercise the above copyright 33 * license, and in no event shall the patent license extend to any additions 34 * to or modifications of the Original Intel Code. No other license or right 35 * is granted directly or by implication, estoppel or otherwise; 36 * 37 * The above copyright and patent license is granted only if the following 38 * conditions are met: 39 * 40 * 3. Conditions 41 * 42 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43 * Redistribution of source code of any substantial portion of the Covered 44 * Code or modification with rights to further distribute source must include 45 * the above Copyright Notice, the above License, this list of Conditions, 46 * and the following Disclaimer and Export Compliance provision. In addition, 47 * Licensee must cause all Covered Code to which Licensee contributes to 48 * contain a file documenting the changes Licensee made to create that Covered 49 * Code and the date of any change. Licensee must include in that file the 50 * documentation of any changes made by any predecessor Licensee. Licensee 51 * must include a prominent statement that the modification is derived, 52 * directly or indirectly, from Original Intel Code. 53 * 54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55 * Redistribution of source code of any substantial portion of the Covered 56 * Code or modification without rights to further distribute source must 57 * include the following Disclaimer and Export Compliance provision in the 58 * documentation and/or other materials provided with distribution. In 59 * addition, Licensee may not authorize further sublicense of source of any 60 * portion of the Covered Code, and must include terms to the effect that the 61 * license from Licensee to its licensee is limited to the intellectual 62 * property embodied in the software Licensee provides to its licensee, and 63 * not to intellectual property embodied in modifications its licensee may 64 * make. 65 * 66 * 3.3. Redistribution of Executable. Redistribution in executable form of any 67 * substantial portion of the Covered Code or modification must reproduce the 68 * above Copyright Notice, and the following Disclaimer and Export Compliance 69 * provision in the documentation and/or other materials provided with the 70 * distribution. 71 * 72 * 3.4. Intel retains all right, title, and interest in and to the Original 73 * Intel Code. 74 * 75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76 * Intel shall be used in advertising or otherwise to promote the sale, use or 77 * other dealings in products derived from or relating to the Covered Code 78 * without prior written authorization from Intel. 79 * 80 * 4. Disclaimer and Export Compliance 81 * 82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88 * PARTICULAR PURPOSE. 89 * 90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97 * LIMITED REMEDY. 98 * 99 * 4.3. Licensee shall not export, either directly or indirectly, any of this 100 * software or system incorporating such software without first obtaining any 101 * required license or other approval from the U. S. Department of Commerce or 102 * any other agency or department of the United States Government. In the 103 * event Licensee exports any such software from the United States or 104 * re-exports any such software from a foreign destination, Licensee shall 105 * ensure that the distribution and export/re-export of the software is in 106 * compliance with all laws, regulations, orders, or other restrictions of the 107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108 * any of its subsidiaries will export/re-export any technical data, process, 109 * software, or service, directly or indirectly, to any country for which the 110 * United States government or any agency thereof requires an export license, 111 * other governmental approval, or letter of assurance, without first obtaining 112 * such license, approval or letter. 113 * 114 ***************************************************************************** 115 * 116 * Alternatively, you may choose to be licensed under the terms of the 117 * following license: 118 * 119 * Redistribution and use in source and binary forms, with or without 120 * modification, are permitted provided that the following conditions 121 * are met: 122 * 1. Redistributions of source code must retain the above copyright 123 * notice, this list of conditions, and the following disclaimer, 124 * without modification. 125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126 * substantially similar to the "NO WARRANTY" disclaimer below 127 * ("Disclaimer") and any redistribution must be conditioned upon 128 * including a substantially similar Disclaimer requirement for further 129 * binary redistribution. 130 * 3. Neither the names of the above-listed copyright holders nor the names 131 * of any contributors may be used to endorse or promote products derived 132 * from this software without specific prior written permission. 133 * 134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145 * 146 * Alternatively, you may choose to be licensed under the terms of the 147 * GNU General Public License ("GPL") version 2 as published by the Free 148 * Software Foundation. 149 * 150 *****************************************************************************/ 151 152 #include <contrib/dev/acpica/include/acpi.h> 153 #include <contrib/dev/acpica/include/accommon.h> 154 #include <contrib/dev/acpica/include/acdispat.h> 155 #include <contrib/dev/acpica/include/acnamesp.h> 156 #include <contrib/dev/acpica/include/acinterp.h> 157 158 159 #define _COMPONENT ACPI_DISPATCHER 160 ACPI_MODULE_NAME ("dsmthdat") 161 162 /* Local prototypes */ 163 164 static void 165 AcpiDsMethodDataDeleteValue ( 166 UINT8 Type, 167 UINT32 Index, 168 ACPI_WALK_STATE *WalkState); 169 170 static ACPI_STATUS 171 AcpiDsMethodDataSetValue ( 172 UINT8 Type, 173 UINT32 Index, 174 ACPI_OPERAND_OBJECT *Object, 175 ACPI_WALK_STATE *WalkState); 176 177 #ifdef ACPI_OBSOLETE_FUNCTIONS 178 ACPI_OBJECT_TYPE 179 AcpiDsMethodDataGetType ( 180 UINT16 Opcode, 181 UINT32 Index, 182 ACPI_WALK_STATE *WalkState); 183 #endif 184 185 186 /******************************************************************************* 187 * 188 * FUNCTION: AcpiDsMethodDataInit 189 * 190 * PARAMETERS: WalkState - Current walk state object 191 * 192 * RETURN: Status 193 * 194 * DESCRIPTION: Initialize the data structures that hold the method's arguments 195 * and locals. The data struct is an array of namespace nodes for 196 * each - this allows RefOf and DeRefOf to work properly for these 197 * special data types. 198 * 199 * NOTES: WalkState fields are initialized to zero by the 200 * ACPI_ALLOCATE_ZEROED(). 201 * 202 * A pseudo-Namespace Node is assigned to each argument and local 203 * so that RefOf() can return a pointer to the Node. 204 * 205 ******************************************************************************/ 206 207 void 208 AcpiDsMethodDataInit ( 209 ACPI_WALK_STATE *WalkState) 210 { 211 UINT32 i; 212 213 214 ACPI_FUNCTION_TRACE (DsMethodDataInit); 215 216 217 /* Init the method arguments */ 218 219 for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++) 220 { 221 ACPI_MOVE_32_TO_32 (&WalkState->Arguments[i].Name, 222 NAMEOF_ARG_NTE); 223 224 WalkState->Arguments[i].Name.Integer |= (i << 24); 225 WalkState->Arguments[i].DescriptorType = ACPI_DESC_TYPE_NAMED; 226 WalkState->Arguments[i].Type = ACPI_TYPE_ANY; 227 WalkState->Arguments[i].Flags = ANOBJ_METHOD_ARG; 228 } 229 230 /* Init the method locals */ 231 232 for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++) 233 { 234 ACPI_MOVE_32_TO_32 (&WalkState->LocalVariables[i].Name, 235 NAMEOF_LOCAL_NTE); 236 237 WalkState->LocalVariables[i].Name.Integer |= (i << 24); 238 WalkState->LocalVariables[i].DescriptorType = ACPI_DESC_TYPE_NAMED; 239 WalkState->LocalVariables[i].Type = ACPI_TYPE_ANY; 240 WalkState->LocalVariables[i].Flags = ANOBJ_METHOD_LOCAL; 241 } 242 243 return_VOID; 244 } 245 246 247 /******************************************************************************* 248 * 249 * FUNCTION: AcpiDsMethodDataDeleteAll 250 * 251 * PARAMETERS: WalkState - Current walk state object 252 * 253 * RETURN: None 254 * 255 * DESCRIPTION: Delete method locals and arguments. Arguments are only 256 * deleted if this method was called from another method. 257 * 258 ******************************************************************************/ 259 260 void 261 AcpiDsMethodDataDeleteAll ( 262 ACPI_WALK_STATE *WalkState) 263 { 264 UINT32 Index; 265 266 267 ACPI_FUNCTION_TRACE (DsMethodDataDeleteAll); 268 269 270 /* Detach the locals */ 271 272 for (Index = 0; Index < ACPI_METHOD_NUM_LOCALS; Index++) 273 { 274 if (WalkState->LocalVariables[Index].Object) 275 { 276 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Local%u=%p\n", 277 Index, WalkState->LocalVariables[Index].Object)); 278 279 /* Detach object (if present) and remove a reference */ 280 281 AcpiNsDetachObject (&WalkState->LocalVariables[Index]); 282 } 283 } 284 285 /* Detach the arguments */ 286 287 for (Index = 0; Index < ACPI_METHOD_NUM_ARGS; Index++) 288 { 289 if (WalkState->Arguments[Index].Object) 290 { 291 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Arg%u=%p\n", 292 Index, WalkState->Arguments[Index].Object)); 293 294 /* Detach object (if present) and remove a reference */ 295 296 AcpiNsDetachObject (&WalkState->Arguments[Index]); 297 } 298 } 299 300 return_VOID; 301 } 302 303 304 /******************************************************************************* 305 * 306 * FUNCTION: AcpiDsMethodDataInitArgs 307 * 308 * PARAMETERS: *Params - Pointer to a parameter list for the method 309 * MaxParamCount - The arg count for this method 310 * WalkState - Current walk state object 311 * 312 * RETURN: Status 313 * 314 * DESCRIPTION: Initialize arguments for a method. The parameter list is a list 315 * of ACPI operand objects, either null terminated or whose length 316 * is defined by MaxParamCount. 317 * 318 ******************************************************************************/ 319 320 ACPI_STATUS 321 AcpiDsMethodDataInitArgs ( 322 ACPI_OPERAND_OBJECT **Params, 323 UINT32 MaxParamCount, 324 ACPI_WALK_STATE *WalkState) 325 { 326 ACPI_STATUS Status; 327 UINT32 Index = 0; 328 329 330 ACPI_FUNCTION_TRACE_PTR (DsMethodDataInitArgs, Params); 331 332 333 if (!Params) 334 { 335 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 336 "No parameter list passed to method\n")); 337 return_ACPI_STATUS (AE_OK); 338 } 339 340 /* Copy passed parameters into the new method stack frame */ 341 342 while ((Index < ACPI_METHOD_NUM_ARGS) && 343 (Index < MaxParamCount) && 344 Params[Index]) 345 { 346 /* 347 * A valid parameter. 348 * Store the argument in the method/walk descriptor. 349 * Do not copy the arg in order to implement call by reference 350 */ 351 Status = AcpiDsMethodDataSetValue ( 352 ACPI_REFCLASS_ARG, Index, Params[Index], WalkState); 353 if (ACPI_FAILURE (Status)) 354 { 355 return_ACPI_STATUS (Status); 356 } 357 358 Index++; 359 } 360 361 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%u args passed to method\n", Index)); 362 return_ACPI_STATUS (AE_OK); 363 } 364 365 366 /******************************************************************************* 367 * 368 * FUNCTION: AcpiDsMethodDataGetNode 369 * 370 * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or 371 * ACPI_REFCLASS_ARG 372 * Index - Which Local or Arg whose type to get 373 * WalkState - Current walk state object 374 * Node - Where the node is returned. 375 * 376 * RETURN: Status and node 377 * 378 * DESCRIPTION: Get the Node associated with a local or arg. 379 * 380 ******************************************************************************/ 381 382 ACPI_STATUS 383 AcpiDsMethodDataGetNode ( 384 UINT8 Type, 385 UINT32 Index, 386 ACPI_WALK_STATE *WalkState, 387 ACPI_NAMESPACE_NODE **Node) 388 { 389 ACPI_FUNCTION_TRACE (DsMethodDataGetNode); 390 391 392 /* 393 * Method Locals and Arguments are supported 394 */ 395 switch (Type) 396 { 397 case ACPI_REFCLASS_LOCAL: 398 399 if (Index > ACPI_METHOD_MAX_LOCAL) 400 { 401 ACPI_ERROR ((AE_INFO, 402 "Local index %u is invalid (max %u)", 403 Index, ACPI_METHOD_MAX_LOCAL)); 404 return_ACPI_STATUS (AE_AML_INVALID_INDEX); 405 } 406 407 /* Return a pointer to the pseudo-node */ 408 409 *Node = &WalkState->LocalVariables[Index]; 410 break; 411 412 case ACPI_REFCLASS_ARG: 413 414 if (Index > ACPI_METHOD_MAX_ARG) 415 { 416 ACPI_ERROR ((AE_INFO, 417 "Arg index %u is invalid (max %u)", 418 Index, ACPI_METHOD_MAX_ARG)); 419 return_ACPI_STATUS (AE_AML_INVALID_INDEX); 420 } 421 422 /* Return a pointer to the pseudo-node */ 423 424 *Node = &WalkState->Arguments[Index]; 425 break; 426 427 default: 428 429 ACPI_ERROR ((AE_INFO, "Type %u is invalid", Type)); 430 return_ACPI_STATUS (AE_TYPE); 431 } 432 433 return_ACPI_STATUS (AE_OK); 434 } 435 436 437 /******************************************************************************* 438 * 439 * FUNCTION: AcpiDsMethodDataSetValue 440 * 441 * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or 442 * ACPI_REFCLASS_ARG 443 * Index - Which Local or Arg to get 444 * Object - Object to be inserted into the stack entry 445 * WalkState - Current walk state object 446 * 447 * RETURN: Status 448 * 449 * DESCRIPTION: Insert an object onto the method stack at entry Opcode:Index. 450 * Note: There is no "implicit conversion" for locals. 451 * 452 ******************************************************************************/ 453 454 static ACPI_STATUS 455 AcpiDsMethodDataSetValue ( 456 UINT8 Type, 457 UINT32 Index, 458 ACPI_OPERAND_OBJECT *Object, 459 ACPI_WALK_STATE *WalkState) 460 { 461 ACPI_STATUS Status; 462 ACPI_NAMESPACE_NODE *Node; 463 464 465 ACPI_FUNCTION_TRACE (DsMethodDataSetValue); 466 467 468 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 469 "NewObj %p Type %2.2X, Refs=%u [%s]\n", Object, 470 Type, Object->Common.ReferenceCount, 471 AcpiUtGetTypeName (Object->Common.Type))); 472 473 /* Get the namespace node for the arg/local */ 474 475 Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node); 476 if (ACPI_FAILURE (Status)) 477 { 478 return_ACPI_STATUS (Status); 479 } 480 481 /* 482 * Increment ref count so object can't be deleted while installed. 483 * NOTE: We do not copy the object in order to preserve the call by 484 * reference semantics of ACPI Control Method invocation. 485 * (See ACPI Specification 2.0C) 486 */ 487 AcpiUtAddReference (Object); 488 489 /* Install the object */ 490 491 Node->Object = Object; 492 return_ACPI_STATUS (Status); 493 } 494 495 496 /******************************************************************************* 497 * 498 * FUNCTION: AcpiDsMethodDataGetValue 499 * 500 * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or 501 * ACPI_REFCLASS_ARG 502 * Index - Which localVar or argument to get 503 * WalkState - Current walk state object 504 * DestDesc - Where Arg or Local value is returned 505 * 506 * RETURN: Status 507 * 508 * DESCRIPTION: Retrieve value of selected Arg or Local for this method 509 * Used only in AcpiExResolveToValue(). 510 * 511 ******************************************************************************/ 512 513 ACPI_STATUS 514 AcpiDsMethodDataGetValue ( 515 UINT8 Type, 516 UINT32 Index, 517 ACPI_WALK_STATE *WalkState, 518 ACPI_OPERAND_OBJECT **DestDesc) 519 { 520 ACPI_STATUS Status; 521 ACPI_NAMESPACE_NODE *Node; 522 ACPI_OPERAND_OBJECT *Object; 523 524 525 ACPI_FUNCTION_TRACE (DsMethodDataGetValue); 526 527 528 /* Validate the object descriptor */ 529 530 if (!DestDesc) 531 { 532 ACPI_ERROR ((AE_INFO, "Null object descriptor pointer")); 533 return_ACPI_STATUS (AE_BAD_PARAMETER); 534 } 535 536 /* Get the namespace node for the arg/local */ 537 538 Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node); 539 if (ACPI_FAILURE (Status)) 540 { 541 return_ACPI_STATUS (Status); 542 } 543 544 /* Get the object from the node */ 545 546 Object = Node->Object; 547 548 /* Examine the returned object, it must be valid. */ 549 550 if (!Object) 551 { 552 /* 553 * Index points to uninitialized object. 554 * This means that either 1) The expected argument was 555 * not passed to the method, or 2) A local variable 556 * was referenced by the method (via the ASL) 557 * before it was initialized. Either case is an error. 558 */ 559 560 /* If slack enabled, init the LocalX/ArgX to an Integer of value zero */ 561 562 if (AcpiGbl_EnableInterpreterSlack) 563 { 564 Object = AcpiUtCreateIntegerObject ((UINT64) 0); 565 if (!Object) 566 { 567 return_ACPI_STATUS (AE_NO_MEMORY); 568 } 569 570 Node->Object = Object; 571 } 572 573 /* Otherwise, return the error */ 574 575 else switch (Type) 576 { 577 case ACPI_REFCLASS_ARG: 578 579 ACPI_ERROR ((AE_INFO, 580 "Uninitialized Arg[%u] at node %p", 581 Index, Node)); 582 583 return_ACPI_STATUS (AE_AML_UNINITIALIZED_ARG); 584 585 case ACPI_REFCLASS_LOCAL: 586 /* 587 * No error message for this case, will be trapped again later to 588 * detect and ignore cases of Store(LocalX,LocalX) 589 */ 590 return_ACPI_STATUS (AE_AML_UNINITIALIZED_LOCAL); 591 592 default: 593 594 ACPI_ERROR ((AE_INFO, "Not a Arg/Local opcode: 0x%X", Type)); 595 return_ACPI_STATUS (AE_AML_INTERNAL); 596 } 597 } 598 599 /* 600 * The Index points to an initialized and valid object. 601 * Return an additional reference to the object 602 */ 603 *DestDesc = Object; 604 AcpiUtAddReference (Object); 605 606 return_ACPI_STATUS (AE_OK); 607 } 608 609 610 /******************************************************************************* 611 * 612 * FUNCTION: AcpiDsMethodDataDeleteValue 613 * 614 * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or 615 * ACPI_REFCLASS_ARG 616 * Index - Which localVar or argument to delete 617 * WalkState - Current walk state object 618 * 619 * RETURN: None 620 * 621 * DESCRIPTION: Delete the entry at Opcode:Index. Inserts 622 * a null into the stack slot after the object is deleted. 623 * 624 ******************************************************************************/ 625 626 static void 627 AcpiDsMethodDataDeleteValue ( 628 UINT8 Type, 629 UINT32 Index, 630 ACPI_WALK_STATE *WalkState) 631 { 632 ACPI_STATUS Status; 633 ACPI_NAMESPACE_NODE *Node; 634 ACPI_OPERAND_OBJECT *Object; 635 636 637 ACPI_FUNCTION_TRACE (DsMethodDataDeleteValue); 638 639 640 /* Get the namespace node for the arg/local */ 641 642 Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node); 643 if (ACPI_FAILURE (Status)) 644 { 645 return_VOID; 646 } 647 648 /* Get the associated object */ 649 650 Object = AcpiNsGetAttachedObject (Node); 651 652 /* 653 * Undefine the Arg or Local by setting its descriptor 654 * pointer to NULL. Locals/Args can contain both 655 * ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs 656 */ 657 Node->Object = NULL; 658 659 if ((Object) && 660 (ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_OPERAND)) 661 { 662 /* 663 * There is a valid object. 664 * Decrement the reference count by one to balance the 665 * increment when the object was stored. 666 */ 667 AcpiUtRemoveReference (Object); 668 } 669 670 return_VOID; 671 } 672 673 674 /******************************************************************************* 675 * 676 * FUNCTION: AcpiDsStoreObjectToLocal 677 * 678 * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or 679 * ACPI_REFCLASS_ARG 680 * Index - Which Local or Arg to set 681 * ObjDesc - Value to be stored 682 * WalkState - Current walk state 683 * 684 * RETURN: Status 685 * 686 * DESCRIPTION: Store a value in an Arg or Local. The ObjDesc is installed 687 * as the new value for the Arg or Local and the reference count 688 * for ObjDesc is incremented. 689 * 690 ******************************************************************************/ 691 692 ACPI_STATUS 693 AcpiDsStoreObjectToLocal ( 694 UINT8 Type, 695 UINT32 Index, 696 ACPI_OPERAND_OBJECT *ObjDesc, 697 ACPI_WALK_STATE *WalkState) 698 { 699 ACPI_STATUS Status; 700 ACPI_NAMESPACE_NODE *Node; 701 ACPI_OPERAND_OBJECT *CurrentObjDesc; 702 ACPI_OPERAND_OBJECT *NewObjDesc; 703 704 705 ACPI_FUNCTION_TRACE (DsStoreObjectToLocal); 706 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Type=%2.2X Index=%u Obj=%p\n", 707 Type, Index, ObjDesc)); 708 709 /* Parameter validation */ 710 711 if (!ObjDesc) 712 { 713 return_ACPI_STATUS (AE_BAD_PARAMETER); 714 } 715 716 /* Get the namespace node for the arg/local */ 717 718 Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node); 719 if (ACPI_FAILURE (Status)) 720 { 721 return_ACPI_STATUS (Status); 722 } 723 724 CurrentObjDesc = AcpiNsGetAttachedObject (Node); 725 if (CurrentObjDesc == ObjDesc) 726 { 727 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p already installed!\n", 728 ObjDesc)); 729 return_ACPI_STATUS (Status); 730 } 731 732 /* 733 * If the reference count on the object is more than one, we must 734 * take a copy of the object before we store. A reference count 735 * of exactly 1 means that the object was just created during the 736 * evaluation of an expression, and we can safely use it since it 737 * is not used anywhere else. 738 */ 739 NewObjDesc = ObjDesc; 740 if (ObjDesc->Common.ReferenceCount > 1) 741 { 742 Status = AcpiUtCopyIobjectToIobject ( 743 ObjDesc, &NewObjDesc, WalkState); 744 if (ACPI_FAILURE (Status)) 745 { 746 return_ACPI_STATUS (Status); 747 } 748 } 749 750 /* 751 * If there is an object already in this slot, we either 752 * have to delete it, or if this is an argument and there 753 * is an object reference stored there, we have to do 754 * an indirect store! 755 */ 756 if (CurrentObjDesc) 757 { 758 /* 759 * Check for an indirect store if an argument 760 * contains an object reference (stored as an Node). 761 * We don't allow this automatic dereferencing for 762 * locals, since a store to a local should overwrite 763 * anything there, including an object reference. 764 * 765 * If both Arg0 and Local0 contain RefOf (Local4): 766 * 767 * Store (1, Arg0) - Causes indirect store to local4 768 * Store (1, Local0) - Stores 1 in local0, overwriting 769 * the reference to local4 770 * Store (1, DeRefof (Local0)) - Causes indirect store to local4 771 * 772 * Weird, but true. 773 */ 774 if (Type == ACPI_REFCLASS_ARG) 775 { 776 /* 777 * If we have a valid reference object that came from RefOf(), 778 * do the indirect store 779 */ 780 if ((ACPI_GET_DESCRIPTOR_TYPE (CurrentObjDesc) == 781 ACPI_DESC_TYPE_OPERAND) && 782 (CurrentObjDesc->Common.Type == 783 ACPI_TYPE_LOCAL_REFERENCE) && 784 (CurrentObjDesc->Reference.Class == 785 ACPI_REFCLASS_REFOF)) 786 { 787 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 788 "Arg (%p) is an ObjRef(Node), storing in node %p\n", 789 NewObjDesc, CurrentObjDesc)); 790 791 /* 792 * Store this object to the Node (perform the indirect store) 793 * NOTE: No implicit conversion is performed, as per the ACPI 794 * specification rules on storing to Locals/Args. 795 */ 796 Status = AcpiExStoreObjectToNode (NewObjDesc, 797 CurrentObjDesc->Reference.Object, WalkState, 798 ACPI_NO_IMPLICIT_CONVERSION); 799 800 /* Remove local reference if we copied the object above */ 801 802 if (NewObjDesc != ObjDesc) 803 { 804 AcpiUtRemoveReference (NewObjDesc); 805 } 806 807 return_ACPI_STATUS (Status); 808 } 809 } 810 811 /* Delete the existing object before storing the new one */ 812 813 AcpiDsMethodDataDeleteValue (Type, Index, WalkState); 814 } 815 816 /* 817 * Install the Obj descriptor (*NewObjDesc) into 818 * the descriptor for the Arg or Local. 819 * (increments the object reference count by one) 820 */ 821 Status = AcpiDsMethodDataSetValue (Type, Index, NewObjDesc, WalkState); 822 823 /* Remove local reference if we copied the object above */ 824 825 if (NewObjDesc != ObjDesc) 826 { 827 AcpiUtRemoveReference (NewObjDesc); 828 } 829 830 return_ACPI_STATUS (Status); 831 } 832 833 834 #ifdef ACPI_OBSOLETE_FUNCTIONS 835 /******************************************************************************* 836 * 837 * FUNCTION: AcpiDsMethodDataGetType 838 * 839 * PARAMETERS: Opcode - Either AML_FIRST LOCAL_OP or 840 * AML_FIRST_ARG_OP 841 * Index - Which Local or Arg whose type to get 842 * WalkState - Current walk state object 843 * 844 * RETURN: Data type of current value of the selected Arg or Local 845 * 846 * DESCRIPTION: Get the type of the object stored in the Local or Arg 847 * 848 ******************************************************************************/ 849 850 ACPI_OBJECT_TYPE 851 AcpiDsMethodDataGetType ( 852 UINT16 Opcode, 853 UINT32 Index, 854 ACPI_WALK_STATE *WalkState) 855 { 856 ACPI_STATUS Status; 857 ACPI_NAMESPACE_NODE *Node; 858 ACPI_OPERAND_OBJECT *Object; 859 860 861 ACPI_FUNCTION_TRACE (DsMethodDataGetType); 862 863 864 /* Get the namespace node for the arg/local */ 865 866 Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node); 867 if (ACPI_FAILURE (Status)) 868 { 869 return_VALUE ((ACPI_TYPE_NOT_FOUND)); 870 } 871 872 /* Get the object */ 873 874 Object = AcpiNsGetAttachedObject (Node); 875 if (!Object) 876 { 877 /* Uninitialized local/arg, return TYPE_ANY */ 878 879 return_VALUE (ACPI_TYPE_ANY); 880 } 881 882 /* Get the object type */ 883 884 return_VALUE (Object->Type); 885 } 886 #endif 887