dsutils.c revision 193249
1/******************************************************************************* 2 * 3 * Module Name: dsutils - Dispatcher utilities 4 * $Revision: 1.124 $ 5 * 6 ******************************************************************************/ 7 8/****************************************************************************** 9 * 10 * 1. Copyright Notice 11 * 12 * Some or all of this work - Copyright (c) 1999 - 2007, Intel Corp. 13 * All rights reserved. 14 * 15 * 2. License 16 * 17 * 2.1. This is your license from Intel Corp. under its intellectual property 18 * rights. You may have additional license terms from the party that provided 19 * you this software, covering your right to use that party's intellectual 20 * property rights. 21 * 22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 23 * copy of the source code appearing in this file ("Covered Code") an 24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 25 * base code distributed originally by Intel ("Original Intel Code") to copy, 26 * make derivatives, distribute, use and display any portion of the Covered 27 * Code in any form, with the right to sublicense such rights; and 28 * 29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 30 * license (with the right to sublicense), under only those claims of Intel 31 * patents that are infringed by the Original Intel Code, to make, use, sell, 32 * offer to sell, and import the Covered Code and derivative works thereof 33 * solely to the minimum extent necessary to exercise the above copyright 34 * license, and in no event shall the patent license extend to any additions 35 * to or modifications of the Original Intel Code. No other license or right 36 * is granted directly or by implication, estoppel or otherwise; 37 * 38 * The above copyright and patent license is granted only if the following 39 * conditions are met: 40 * 41 * 3. Conditions 42 * 43 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 44 * Redistribution of source code of any substantial portion of the Covered 45 * Code or modification with rights to further distribute source must include 46 * the above Copyright Notice, the above License, this list of Conditions, 47 * and the following Disclaimer and Export Compliance provision. In addition, 48 * Licensee must cause all Covered Code to which Licensee contributes to 49 * contain a file documenting the changes Licensee made to create that Covered 50 * Code and the date of any change. Licensee must include in that file the 51 * documentation of any changes made by any predecessor Licensee. Licensee 52 * must include a prominent statement that the modification is derived, 53 * directly or indirectly, from Original Intel Code. 54 * 55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 56 * Redistribution of source code of any substantial portion of the Covered 57 * Code or modification without rights to further distribute source must 58 * include the following Disclaimer and Export Compliance provision in the 59 * documentation and/or other materials provided with distribution. In 60 * addition, Licensee may not authorize further sublicense of source of any 61 * portion of the Covered Code, and must include terms to the effect that the 62 * license from Licensee to its licensee is limited to the intellectual 63 * property embodied in the software Licensee provides to its licensee, and 64 * not to intellectual property embodied in modifications its licensee may 65 * make. 66 * 67 * 3.3. Redistribution of Executable. Redistribution in executable form of any 68 * substantial portion of the Covered Code or modification must reproduce the 69 * above Copyright Notice, and the following Disclaimer and Export Compliance 70 * provision in the documentation and/or other materials provided with the 71 * distribution. 72 * 73 * 3.4. Intel retains all right, title, and interest in and to the Original 74 * Intel Code. 75 * 76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 77 * Intel shall be used in advertising or otherwise to promote the sale, use or 78 * other dealings in products derived from or relating to the Covered Code 79 * without prior written authorization from Intel. 80 * 81 * 4. Disclaimer and Export Compliance 82 * 83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 89 * PARTICULAR PURPOSE. 90 * 91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 98 * LIMITED REMEDY. 99 * 100 * 4.3. Licensee shall not export, either directly or indirectly, any of this 101 * software or system incorporating such software without first obtaining any 102 * required license or other approval from the U. S. Department of Commerce or 103 * any other agency or department of the United States Government. In the 104 * event Licensee exports any such software from the United States or 105 * re-exports any such software from a foreign destination, Licensee shall 106 * ensure that the distribution and export/re-export of the software is in 107 * compliance with all laws, regulations, orders, or other restrictions of the 108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 109 * any of its subsidiaries will export/re-export any technical data, process, 110 * software, or service, directly or indirectly, to any country for which the 111 * United States government or any agency thereof requires an export license, 112 * other governmental approval, or letter of assurance, without first obtaining 113 * such license, approval or letter. 114 * 115 *****************************************************************************/ 116 117#define __DSUTILS_C__ 118 119#include <contrib/dev/acpica/acpi.h> 120#include <contrib/dev/acpica/acparser.h> 121#include <contrib/dev/acpica/amlcode.h> 122#include <contrib/dev/acpica/acdispat.h> 123#include <contrib/dev/acpica/acinterp.h> 124#include <contrib/dev/acpica/acnamesp.h> 125#include <contrib/dev/acpica/acdebug.h> 126 127#define _COMPONENT ACPI_DISPATCHER 128 ACPI_MODULE_NAME ("dsutils") 129 130 131/******************************************************************************* 132 * 133 * FUNCTION: AcpiDsClearImplicitReturn 134 * 135 * PARAMETERS: WalkState - Current State 136 * 137 * RETURN: None. 138 * 139 * DESCRIPTION: Clear and remove a reference on an implicit return value. Used 140 * to delete "stale" return values (if enabled, the return value 141 * from every operator is saved at least momentarily, in case the 142 * parent method exits.) 143 * 144 ******************************************************************************/ 145 146void 147AcpiDsClearImplicitReturn ( 148 ACPI_WALK_STATE *WalkState) 149{ 150 ACPI_FUNCTION_NAME (DsClearImplicitReturn); 151 152 153 /* 154 * Slack must be enabled for this feature 155 */ 156 if (!AcpiGbl_EnableInterpreterSlack) 157 { 158 return; 159 } 160 161 if (WalkState->ImplicitReturnObj) 162 { 163 /* 164 * Delete any "stale" implicit return. However, in 165 * complex statements, the implicit return value can be 166 * bubbled up several levels. 167 */ 168 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, 169 "Removing reference on stale implicit return obj %p\n", 170 WalkState->ImplicitReturnObj)); 171 172 AcpiUtRemoveReference (WalkState->ImplicitReturnObj); 173 WalkState->ImplicitReturnObj = NULL; 174 } 175} 176 177 178#ifndef ACPI_NO_METHOD_EXECUTION 179/******************************************************************************* 180 * 181 * FUNCTION: AcpiDsDoImplicitReturn 182 * 183 * PARAMETERS: ReturnDesc - The return value 184 * WalkState - Current State 185 * AddReference - True if a reference should be added to the 186 * return object 187 * 188 * RETURN: TRUE if implicit return enabled, FALSE otherwise 189 * 190 * DESCRIPTION: Implements the optional "implicit return". We save the result 191 * of every ASL operator and control method invocation in case the 192 * parent method exit. Before storing a new return value, we 193 * delete the previous return value. 194 * 195 ******************************************************************************/ 196 197BOOLEAN 198AcpiDsDoImplicitReturn ( 199 ACPI_OPERAND_OBJECT *ReturnDesc, 200 ACPI_WALK_STATE *WalkState, 201 BOOLEAN AddReference) 202{ 203 ACPI_FUNCTION_NAME (DsDoImplicitReturn); 204 205 206 /* 207 * Slack must be enabled for this feature, and we must 208 * have a valid return object 209 */ 210 if ((!AcpiGbl_EnableInterpreterSlack) || 211 (!ReturnDesc)) 212 { 213 return (FALSE); 214 } 215 216 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, 217 "Result %p will be implicitly returned; Prev=%p\n", 218 ReturnDesc, 219 WalkState->ImplicitReturnObj)); 220 221 /* 222 * Delete any "stale" implicit return value first. However, in 223 * complex statements, the implicit return value can be 224 * bubbled up several levels, so we don't clear the value if it 225 * is the same as the ReturnDesc. 226 */ 227 if (WalkState->ImplicitReturnObj) 228 { 229 if (WalkState->ImplicitReturnObj == ReturnDesc) 230 { 231 return (TRUE); 232 } 233 AcpiDsClearImplicitReturn (WalkState); 234 } 235 236 /* Save the implicit return value, add a reference if requested */ 237 238 WalkState->ImplicitReturnObj = ReturnDesc; 239 if (AddReference) 240 { 241 AcpiUtAddReference (ReturnDesc); 242 } 243 244 return (TRUE); 245} 246 247 248/******************************************************************************* 249 * 250 * FUNCTION: AcpiDsIsResultUsed 251 * 252 * PARAMETERS: Op - Current Op 253 * WalkState - Current State 254 * 255 * RETURN: TRUE if result is used, FALSE otherwise 256 * 257 * DESCRIPTION: Check if a result object will be used by the parent 258 * 259 ******************************************************************************/ 260 261BOOLEAN 262AcpiDsIsResultUsed ( 263 ACPI_PARSE_OBJECT *Op, 264 ACPI_WALK_STATE *WalkState) 265{ 266 const ACPI_OPCODE_INFO *ParentInfo; 267 268 ACPI_FUNCTION_TRACE_PTR (DsIsResultUsed, Op); 269 270 271 /* Must have both an Op and a Result Object */ 272 273 if (!Op) 274 { 275 ACPI_ERROR ((AE_INFO, "Null Op")); 276 return_UINT8 (TRUE); 277 } 278 279 /* 280 * We know that this operator is not a 281 * Return() operator (would not come here.) The following code is the 282 * optional support for a so-called "implicit return". Some AML code 283 * assumes that the last value of the method is "implicitly" returned 284 * to the caller. Just save the last result as the return value. 285 * NOTE: this is optional because the ASL language does not actually 286 * support this behavior. 287 */ 288 (void) AcpiDsDoImplicitReturn (WalkState->ResultObj, WalkState, TRUE); 289 290 /* 291 * Now determine if the parent will use the result 292 * 293 * If there is no parent, or the parent is a ScopeOp, we are executing 294 * at the method level. An executing method typically has no parent, 295 * since each method is parsed separately. A method invoked externally 296 * via ExecuteControlMethod has a ScopeOp as the parent. 297 */ 298 if ((!Op->Common.Parent) || 299 (Op->Common.Parent->Common.AmlOpcode == AML_SCOPE_OP)) 300 { 301 /* No parent, the return value cannot possibly be used */ 302 303 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, 304 "At Method level, result of [%s] not used\n", 305 AcpiPsGetOpcodeName (Op->Common.AmlOpcode))); 306 return_UINT8 (FALSE); 307 } 308 309 /* Get info on the parent. The RootOp is AML_SCOPE */ 310 311 ParentInfo = AcpiPsGetOpcodeInfo (Op->Common.Parent->Common.AmlOpcode); 312 if (ParentInfo->Class == AML_CLASS_UNKNOWN) 313 { 314 ACPI_ERROR ((AE_INFO, 315 "Unknown parent opcode Op=%p", Op)); 316 return_UINT8 (FALSE); 317 } 318 319 /* 320 * Decide what to do with the result based on the parent. If 321 * the parent opcode will not use the result, delete the object. 322 * Otherwise leave it as is, it will be deleted when it is used 323 * as an operand later. 324 */ 325 switch (ParentInfo->Class) 326 { 327 case AML_CLASS_CONTROL: 328 329 switch (Op->Common.Parent->Common.AmlOpcode) 330 { 331 case AML_RETURN_OP: 332 333 /* Never delete the return value associated with a return opcode */ 334 335 goto ResultUsed; 336 337 case AML_IF_OP: 338 case AML_WHILE_OP: 339 340 /* 341 * If we are executing the predicate AND this is the predicate op, 342 * we will use the return value 343 */ 344 if ((WalkState->ControlState->Common.State == ACPI_CONTROL_PREDICATE_EXECUTING) && 345 (WalkState->ControlState->Control.PredicateOp == Op)) 346 { 347 goto ResultUsed; 348 } 349 break; 350 351 default: 352 /* Ignore other control opcodes */ 353 break; 354 } 355 356 /* The general control opcode returns no result */ 357 358 goto ResultNotUsed; 359 360 361 case AML_CLASS_CREATE: 362 363 /* 364 * These opcodes allow TermArg(s) as operands and therefore 365 * the operands can be method calls. The result is used. 366 */ 367 goto ResultUsed; 368 369 370 case AML_CLASS_NAMED_OBJECT: 371 372 if ((Op->Common.Parent->Common.AmlOpcode == AML_REGION_OP) || 373 (Op->Common.Parent->Common.AmlOpcode == AML_DATA_REGION_OP) || 374 (Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) || 375 (Op->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP) || 376 (Op->Common.Parent->Common.AmlOpcode == AML_BUFFER_OP) || 377 (Op->Common.Parent->Common.AmlOpcode == AML_INT_EVAL_SUBTREE_OP)) 378 { 379 /* 380 * These opcodes allow TermArg(s) as operands and therefore 381 * the operands can be method calls. The result is used. 382 */ 383 goto ResultUsed; 384 } 385 386 goto ResultNotUsed; 387 388 389 default: 390 391 /* 392 * In all other cases. the parent will actually use the return 393 * object, so keep it. 394 */ 395 goto ResultUsed; 396 } 397 398 399ResultUsed: 400 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, 401 "Result of [%s] used by Parent [%s] Op=%p\n", 402 AcpiPsGetOpcodeName (Op->Common.AmlOpcode), 403 AcpiPsGetOpcodeName (Op->Common.Parent->Common.AmlOpcode), Op)); 404 405 return_UINT8 (TRUE); 406 407 408ResultNotUsed: 409 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, 410 "Result of [%s] not used by Parent [%s] Op=%p\n", 411 AcpiPsGetOpcodeName (Op->Common.AmlOpcode), 412 AcpiPsGetOpcodeName (Op->Common.Parent->Common.AmlOpcode), Op)); 413 414 return_UINT8 (FALSE); 415} 416 417 418/******************************************************************************* 419 * 420 * FUNCTION: AcpiDsDeleteResultIfNotUsed 421 * 422 * PARAMETERS: Op - Current parse Op 423 * ResultObj - Result of the operation 424 * WalkState - Current state 425 * 426 * RETURN: Status 427 * 428 * DESCRIPTION: Used after interpretation of an opcode. If there is an internal 429 * result descriptor, check if the parent opcode will actually use 430 * this result. If not, delete the result now so that it will 431 * not become orphaned. 432 * 433 ******************************************************************************/ 434 435void 436AcpiDsDeleteResultIfNotUsed ( 437 ACPI_PARSE_OBJECT *Op, 438 ACPI_OPERAND_OBJECT *ResultObj, 439 ACPI_WALK_STATE *WalkState) 440{ 441 ACPI_OPERAND_OBJECT *ObjDesc; 442 ACPI_STATUS Status; 443 444 445 ACPI_FUNCTION_TRACE_PTR (DsDeleteResultIfNotUsed, ResultObj); 446 447 448 if (!Op) 449 { 450 ACPI_ERROR ((AE_INFO, "Null Op")); 451 return_VOID; 452 } 453 454 if (!ResultObj) 455 { 456 return_VOID; 457 } 458 459 if (!AcpiDsIsResultUsed (Op, WalkState)) 460 { 461 /* Must pop the result stack (ObjDesc should be equal to ResultObj) */ 462 463 Status = AcpiDsResultPop (&ObjDesc, WalkState); 464 if (ACPI_SUCCESS (Status)) 465 { 466 AcpiUtRemoveReference (ResultObj); 467 } 468 } 469 470 return_VOID; 471} 472 473 474/******************************************************************************* 475 * 476 * FUNCTION: AcpiDsResolveOperands 477 * 478 * PARAMETERS: WalkState - Current walk state with operands on stack 479 * 480 * RETURN: Status 481 * 482 * DESCRIPTION: Resolve all operands to their values. Used to prepare 483 * arguments to a control method invocation (a call from one 484 * method to another.) 485 * 486 ******************************************************************************/ 487 488ACPI_STATUS 489AcpiDsResolveOperands ( 490 ACPI_WALK_STATE *WalkState) 491{ 492 UINT32 i; 493 ACPI_STATUS Status = AE_OK; 494 495 496 ACPI_FUNCTION_TRACE_PTR (DsResolveOperands, WalkState); 497 498 499 /* 500 * Attempt to resolve each of the valid operands 501 * Method arguments are passed by reference, not by value. This means 502 * that the actual objects are passed, not copies of the objects. 503 */ 504 for (i = 0; i < WalkState->NumOperands; i++) 505 { 506 Status = AcpiExResolveToValue (&WalkState->Operands[i], WalkState); 507 if (ACPI_FAILURE (Status)) 508 { 509 break; 510 } 511 } 512 513 return_ACPI_STATUS (Status); 514} 515 516 517/******************************************************************************* 518 * 519 * FUNCTION: AcpiDsClearOperands 520 * 521 * PARAMETERS: WalkState - Current walk state with operands on stack 522 * 523 * RETURN: None 524 * 525 * DESCRIPTION: Clear all operands on the current walk state operand stack. 526 * 527 ******************************************************************************/ 528 529void 530AcpiDsClearOperands ( 531 ACPI_WALK_STATE *WalkState) 532{ 533 UINT32 i; 534 535 536 ACPI_FUNCTION_TRACE_PTR (DsClearOperands, WalkState); 537 538 539 /* Remove a reference on each operand on the stack */ 540 541 for (i = 0; i < WalkState->NumOperands; i++) 542 { 543 /* 544 * Remove a reference to all operands, including both 545 * "Arguments" and "Targets". 546 */ 547 AcpiUtRemoveReference (WalkState->Operands[i]); 548 WalkState->Operands[i] = NULL; 549 } 550 551 WalkState->NumOperands = 0; 552 return_VOID; 553} 554#endif 555 556 557/******************************************************************************* 558 * 559 * FUNCTION: AcpiDsCreateOperand 560 * 561 * PARAMETERS: WalkState - Current walk state 562 * Arg - Parse object for the argument 563 * ArgIndex - Which argument (zero based) 564 * 565 * RETURN: Status 566 * 567 * DESCRIPTION: Translate a parse tree object that is an argument to an AML 568 * opcode to the equivalent interpreter object. This may include 569 * looking up a name or entering a new name into the internal 570 * namespace. 571 * 572 ******************************************************************************/ 573 574ACPI_STATUS 575AcpiDsCreateOperand ( 576 ACPI_WALK_STATE *WalkState, 577 ACPI_PARSE_OBJECT *Arg, 578 UINT32 ArgIndex) 579{ 580 ACPI_STATUS Status = AE_OK; 581 char *NameString; 582 UINT32 NameLength; 583 ACPI_OPERAND_OBJECT *ObjDesc; 584 ACPI_PARSE_OBJECT *ParentOp; 585 UINT16 Opcode; 586 ACPI_INTERPRETER_MODE InterpreterMode; 587 const ACPI_OPCODE_INFO *OpInfo; 588 589 590 ACPI_FUNCTION_TRACE_PTR (DsCreateOperand, Arg); 591 592 593 /* A valid name must be looked up in the namespace */ 594 595 if ((Arg->Common.AmlOpcode == AML_INT_NAMEPATH_OP) && 596 (Arg->Common.Value.String) && 597 !(Arg->Common.Flags & ACPI_PARSEOP_IN_STACK)) 598 { 599 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Getting a name: Arg=%p\n", Arg)); 600 601 /* Get the entire name string from the AML stream */ 602 603 Status = AcpiExGetNameString (ACPI_TYPE_ANY, Arg->Common.Value.Buffer, 604 &NameString, &NameLength); 605 606 if (ACPI_FAILURE (Status)) 607 { 608 return_ACPI_STATUS (Status); 609 } 610 611 /* All prefixes have been handled, and the name is in NameString */ 612 613 /* 614 * Special handling for BufferField declarations. This is a deferred 615 * opcode that unfortunately defines the field name as the last 616 * parameter instead of the first. We get here when we are performing 617 * the deferred execution, so the actual name of the field is already 618 * in the namespace. We don't want to attempt to look it up again 619 * because we may be executing in a different scope than where the 620 * actual opcode exists. 621 */ 622 if ((WalkState->DeferredNode) && 623 (WalkState->DeferredNode->Type == ACPI_TYPE_BUFFER_FIELD) && 624 (ArgIndex == (UINT32) ((WalkState->Opcode == AML_CREATE_FIELD_OP) ? 3 : 2))) 625 { 626 ObjDesc = ACPI_CAST_PTR ( 627 ACPI_OPERAND_OBJECT, WalkState->DeferredNode); 628 Status = AE_OK; 629 } 630 else /* All other opcodes */ 631 { 632 /* 633 * Differentiate between a namespace "create" operation 634 * versus a "lookup" operation (IMODE_LOAD_PASS2 vs. 635 * IMODE_EXECUTE) in order to support the creation of 636 * namespace objects during the execution of control methods. 637 */ 638 ParentOp = Arg->Common.Parent; 639 OpInfo = AcpiPsGetOpcodeInfo (ParentOp->Common.AmlOpcode); 640 if ((OpInfo->Flags & AML_NSNODE) && 641 (ParentOp->Common.AmlOpcode != AML_INT_METHODCALL_OP) && 642 (ParentOp->Common.AmlOpcode != AML_REGION_OP) && 643 (ParentOp->Common.AmlOpcode != AML_INT_NAMEPATH_OP)) 644 { 645 /* Enter name into namespace if not found */ 646 647 InterpreterMode = ACPI_IMODE_LOAD_PASS2; 648 } 649 else 650 { 651 /* Return a failure if name not found */ 652 653 InterpreterMode = ACPI_IMODE_EXECUTE; 654 } 655 656 Status = AcpiNsLookup (WalkState->ScopeInfo, NameString, 657 ACPI_TYPE_ANY, InterpreterMode, 658 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, 659 WalkState, 660 ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, &ObjDesc)); 661 /* 662 * The only case where we pass through (ignore) a NOT_FOUND 663 * error is for the CondRefOf opcode. 664 */ 665 if (Status == AE_NOT_FOUND) 666 { 667 if (ParentOp->Common.AmlOpcode == AML_COND_REF_OF_OP) 668 { 669 /* 670 * For the Conditional Reference op, it's OK if 671 * the name is not found; We just need a way to 672 * indicate this to the interpreter, set the 673 * object to the root 674 */ 675 ObjDesc = ACPI_CAST_PTR ( 676 ACPI_OPERAND_OBJECT, AcpiGbl_RootNode); 677 Status = AE_OK; 678 } 679 else 680 { 681 /* 682 * We just plain didn't find it -- which is a 683 * very serious error at this point 684 */ 685 Status = AE_AML_NAME_NOT_FOUND; 686 } 687 } 688 689 if (ACPI_FAILURE (Status)) 690 { 691 ACPI_ERROR_NAMESPACE (NameString, Status); 692 } 693 } 694 695 /* Free the namestring created above */ 696 697 ACPI_FREE (NameString); 698 699 /* Check status from the lookup */ 700 701 if (ACPI_FAILURE (Status)) 702 { 703 return_ACPI_STATUS (Status); 704 } 705 706 /* Put the resulting object onto the current object stack */ 707 708 Status = AcpiDsObjStackPush (ObjDesc, WalkState); 709 if (ACPI_FAILURE (Status)) 710 { 711 return_ACPI_STATUS (Status); 712 } 713 ACPI_DEBUGGER_EXEC (AcpiDbDisplayArgumentObject (ObjDesc, WalkState)); 714 } 715 else 716 { 717 /* Check for null name case */ 718 719 if ((Arg->Common.AmlOpcode == AML_INT_NAMEPATH_OP) && 720 !(Arg->Common.Flags & ACPI_PARSEOP_IN_STACK)) 721 { 722 /* 723 * If the name is null, this means that this is an 724 * optional result parameter that was not specified 725 * in the original ASL. Create a Zero Constant for a 726 * placeholder. (Store to a constant is a Noop.) 727 */ 728 Opcode = AML_ZERO_OP; /* Has no arguments! */ 729 730 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, 731 "Null namepath: Arg=%p\n", Arg)); 732 } 733 else 734 { 735 Opcode = Arg->Common.AmlOpcode; 736 } 737 738 /* Get the object type of the argument */ 739 740 OpInfo = AcpiPsGetOpcodeInfo (Opcode); 741 if (OpInfo->ObjectType == ACPI_TYPE_INVALID) 742 { 743 return_ACPI_STATUS (AE_NOT_IMPLEMENTED); 744 } 745 746 if ((OpInfo->Flags & AML_HAS_RETVAL) || (Arg->Common.Flags & ACPI_PARSEOP_IN_STACK)) 747 { 748 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, 749 "Argument previously created, already stacked\n")); 750 751 ACPI_DEBUGGER_EXEC (AcpiDbDisplayArgumentObject ( 752 WalkState->Operands [WalkState->NumOperands - 1], WalkState)); 753 754 /* 755 * Use value that was already previously returned 756 * by the evaluation of this argument 757 */ 758 Status = AcpiDsResultPop (&ObjDesc, WalkState); 759 if (ACPI_FAILURE (Status)) 760 { 761 /* 762 * Only error is underflow, and this indicates 763 * a missing or null operand! 764 */ 765 ACPI_EXCEPTION ((AE_INFO, Status, 766 "Missing or null operand")); 767 return_ACPI_STATUS (Status); 768 } 769 } 770 else 771 { 772 /* Create an ACPI_INTERNAL_OBJECT for the argument */ 773 774 ObjDesc = AcpiUtCreateInternalObject (OpInfo->ObjectType); 775 if (!ObjDesc) 776 { 777 return_ACPI_STATUS (AE_NO_MEMORY); 778 } 779 780 /* Initialize the new object */ 781 782 Status = AcpiDsInitObjectFromOp ( 783 WalkState, Arg, Opcode, &ObjDesc); 784 if (ACPI_FAILURE (Status)) 785 { 786 AcpiUtDeleteObjectDesc (ObjDesc); 787 return_ACPI_STATUS (Status); 788 } 789 } 790 791 /* Put the operand object on the object stack */ 792 793 Status = AcpiDsObjStackPush (ObjDesc, WalkState); 794 if (ACPI_FAILURE (Status)) 795 { 796 return_ACPI_STATUS (Status); 797 } 798 799 ACPI_DEBUGGER_EXEC (AcpiDbDisplayArgumentObject (ObjDesc, WalkState)); 800 } 801 802 return_ACPI_STATUS (AE_OK); 803} 804 805 806/******************************************************************************* 807 * 808 * FUNCTION: AcpiDsCreateOperands 809 * 810 * PARAMETERS: WalkState - Current state 811 * FirstArg - First argument of a parser argument tree 812 * 813 * RETURN: Status 814 * 815 * DESCRIPTION: Convert an operator's arguments from a parse tree format to 816 * namespace objects and place those argument object on the object 817 * stack in preparation for evaluation by the interpreter. 818 * 819 ******************************************************************************/ 820 821ACPI_STATUS 822AcpiDsCreateOperands ( 823 ACPI_WALK_STATE *WalkState, 824 ACPI_PARSE_OBJECT *FirstArg) 825{ 826 ACPI_STATUS Status = AE_OK; 827 ACPI_PARSE_OBJECT *Arg; 828 ACPI_PARSE_OBJECT *Arguments[ACPI_OBJ_NUM_OPERANDS]; 829 UINT8 ArgCount = 0; 830 UINT8 Count = 0; 831 UINT8 Index = WalkState->NumOperands; 832 UINT8 i; 833 834 835 ACPI_FUNCTION_TRACE_PTR (DsCreateOperands, FirstArg); 836 837 838 /* Get all arguments in the list */ 839 840 Arg = FirstArg; 841 while (Arg) 842 { 843 if (Index >= ACPI_OBJ_NUM_OPERANDS) 844 { 845 return_ACPI_STATUS (AE_BAD_DATA); 846 } 847 848 Arguments[Index] = Arg; 849 WalkState->Operands [Index] = NULL; 850 851 /* Move on to next argument, if any */ 852 853 Arg = Arg->Common.Next; 854 ArgCount++; 855 Index++; 856 } 857 858 Index--; 859 860 /* It is the appropriate order to get objects from the Result stack */ 861 862 for (i = 0; i < ArgCount; i++) 863 { 864 Arg = Arguments[Index]; 865 866 /* Force the filling of the operand stack in inverse order */ 867 868 WalkState->OperandIndex = Index; 869 870 Status = AcpiDsCreateOperand (WalkState, Arg, Index); 871 if (ACPI_FAILURE (Status)) 872 { 873 goto Cleanup; 874 } 875 876 Count++; 877 Index--; 878 879 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Arg #%d (%p) done, Arg1=%p\n", 880 Index, Arg, FirstArg)); 881 } 882 883 return_ACPI_STATUS (Status); 884 885 886Cleanup: 887 /* 888 * We must undo everything done above; meaning that we must 889 * pop everything off of the operand stack and delete those 890 * objects 891 */ 892 AcpiDsObjStackPopAndDelete (ArgCount, WalkState); 893 894 ACPI_EXCEPTION ((AE_INFO, Status, "While creating Arg %d", Index)); 895 return_ACPI_STATUS (Status); 896} 897 898 899/***************************************************************************** 900 * 901 * FUNCTION: AcpiDsEvaluateNamePath 902 * 903 * PARAMETERS: WalkState - Current state of the parse tree walk, 904 * the opcode of current operation should be 905 * AML_INT_NAMEPATH_OP 906 * 907 * RETURN: Status 908 * 909 * DESCRIPTION: Translate the -NamePath- parse tree object to the equivalent 910 * interpreter object, convert it to value, if needed, duplicate 911 * it, if needed, and push it onto the current result stack. 912 * 913 ****************************************************************************/ 914 915ACPI_STATUS 916AcpiDsEvaluateNamePath ( 917 ACPI_WALK_STATE *WalkState) 918{ 919 ACPI_STATUS Status = AE_OK; 920 ACPI_PARSE_OBJECT *Op = WalkState->Op; 921 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0]; 922 ACPI_OPERAND_OBJECT *NewObjDesc; 923 UINT8 Type; 924 925 926 ACPI_FUNCTION_TRACE_PTR (DsEvaluateNamePath, WalkState); 927 928 929 if (!Op->Common.Parent) 930 { 931 /* This happens after certain exception processing */ 932 933 goto Exit; 934 } 935 936 if ((Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) || 937 (Op->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP) || 938 (Op->Common.Parent->Common.AmlOpcode == AML_REF_OF_OP)) 939 { 940 /* TBD: Should we specify this feature as a bit of OpInfo->Flags of these opcodes? */ 941 942 goto Exit; 943 } 944 945 Status = AcpiDsCreateOperand (WalkState, Op, 0); 946 if (ACPI_FAILURE (Status)) 947 { 948 goto Exit; 949 } 950 951 if (Op->Common.Flags & ACPI_PARSEOP_TARGET) 952 { 953 NewObjDesc = *Operand; 954 goto PushResult; 955 } 956 957 Type = ACPI_GET_OBJECT_TYPE (*Operand); 958 959 Status = AcpiExResolveToValue (Operand, WalkState); 960 if (ACPI_FAILURE (Status)) 961 { 962 goto Exit; 963 } 964 965 if (Type == ACPI_TYPE_INTEGER) 966 { 967 /* It was incremented by AcpiExResolveToValue */ 968 969 AcpiUtRemoveReference (*Operand); 970 971 Status = AcpiUtCopyIobjectToIobject (*Operand, &NewObjDesc, WalkState); 972 if (ACPI_FAILURE (Status)) 973 { 974 goto Exit; 975 } 976 } 977 else 978 { 979 /* 980 * The object either was anew created or is 981 * a Namespace node - don't decrement it. 982 */ 983 NewObjDesc = *Operand; 984 } 985 986 /* Cleanup for name-path operand */ 987 988 Status = AcpiDsObjStackPop (1, WalkState); 989 if (ACPI_FAILURE (Status)) 990 { 991 WalkState->ResultObj = NewObjDesc; 992 goto Exit; 993 } 994 995PushResult: 996 997 WalkState->ResultObj = NewObjDesc; 998 999 Status = AcpiDsResultPush (WalkState->ResultObj, WalkState); 1000 if (ACPI_SUCCESS (Status)) 1001 { 1002 /* Force to take it from stack */ 1003 1004 Op->Common.Flags |= ACPI_PARSEOP_IN_STACK; 1005 } 1006 1007Exit: 1008 1009 return_ACPI_STATUS (Status); 1010} 1011