1 /****************************************************************************** 2 * 3 * Module Name: psparse - Parser top level AML parse routines 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 /* 153 * Parse the AML and build an operation tree as most interpreters, 154 * like Perl, do. Parsing is done by hand rather than with a YACC 155 * generated parser to tightly constrain stack and dynamic memory 156 * usage. At the same time, parsing is kept flexible and the code 157 * fairly compact by parsing based on a list of AML opcode 158 * templates in AmlOpInfo[] 159 */ 160 161 #include <contrib/dev/acpica/include/acpi.h> 162 #include <contrib/dev/acpica/include/accommon.h> 163 #include <contrib/dev/acpica/include/acparser.h> 164 #include <contrib/dev/acpica/include/acdispat.h> 165 #include <contrib/dev/acpica/include/amlcode.h> 166 #include <contrib/dev/acpica/include/acinterp.h> 167 168 #define _COMPONENT ACPI_PARSER 169 ACPI_MODULE_NAME ("psparse") 170 171 172 /******************************************************************************* 173 * 174 * FUNCTION: AcpiPsGetOpcodeSize 175 * 176 * PARAMETERS: Opcode - An AML opcode 177 * 178 * RETURN: Size of the opcode, in bytes (1 or 2) 179 * 180 * DESCRIPTION: Get the size of the current opcode. 181 * 182 ******************************************************************************/ 183 184 UINT32 185 AcpiPsGetOpcodeSize ( 186 UINT32 Opcode) 187 { 188 189 /* Extended (2-byte) opcode if > 255 */ 190 191 if (Opcode > 0x00FF) 192 { 193 return (2); 194 } 195 196 /* Otherwise, just a single byte opcode */ 197 198 return (1); 199 } 200 201 202 /******************************************************************************* 203 * 204 * FUNCTION: AcpiPsPeekOpcode 205 * 206 * PARAMETERS: ParserState - A parser state object 207 * 208 * RETURN: Next AML opcode 209 * 210 * DESCRIPTION: Get next AML opcode (without incrementing AML pointer) 211 * 212 ******************************************************************************/ 213 214 UINT16 215 AcpiPsPeekOpcode ( 216 ACPI_PARSE_STATE *ParserState) 217 { 218 UINT8 *Aml; 219 UINT16 Opcode; 220 221 222 Aml = ParserState->Aml; 223 Opcode = (UINT16) ACPI_GET8 (Aml); 224 225 if (Opcode == AML_EXTENDED_PREFIX) 226 { 227 /* Extended opcode, get the second opcode byte */ 228 229 Aml++; 230 Opcode = (UINT16) ((Opcode << 8) | ACPI_GET8 (Aml)); 231 } 232 233 return (Opcode); 234 } 235 236 237 /******************************************************************************* 238 * 239 * FUNCTION: AcpiPsCompleteThisOp 240 * 241 * PARAMETERS: WalkState - Current State 242 * Op - Op to complete 243 * 244 * RETURN: Status 245 * 246 * DESCRIPTION: Perform any cleanup at the completion of an Op. 247 * 248 ******************************************************************************/ 249 250 ACPI_STATUS 251 AcpiPsCompleteThisOp ( 252 ACPI_WALK_STATE *WalkState, 253 ACPI_PARSE_OBJECT *Op) 254 { 255 ACPI_PARSE_OBJECT *Prev; 256 ACPI_PARSE_OBJECT *Next; 257 const ACPI_OPCODE_INFO *ParentInfo; 258 ACPI_PARSE_OBJECT *ReplacementOp = NULL; 259 ACPI_STATUS Status = AE_OK; 260 261 262 ACPI_FUNCTION_TRACE_PTR (PsCompleteThisOp, Op); 263 264 265 /* Check for null Op, can happen if AML code is corrupt */ 266 267 if (!Op) 268 { 269 return_ACPI_STATUS (AE_OK); /* OK for now */ 270 } 271 272 AcpiExStopTraceOpcode (Op, WalkState); 273 274 /* Delete this op and the subtree below it if asked to */ 275 276 if (((WalkState->ParseFlags & ACPI_PARSE_TREE_MASK) != ACPI_PARSE_DELETE_TREE) || 277 (WalkState->OpInfo->Class == AML_CLASS_ARGUMENT)) 278 { 279 return_ACPI_STATUS (AE_OK); 280 } 281 282 /* Make sure that we only delete this subtree */ 283 284 if (Op->Common.Parent) 285 { 286 Prev = Op->Common.Parent->Common.Value.Arg; 287 if (!Prev) 288 { 289 /* Nothing more to do */ 290 291 goto Cleanup; 292 } 293 294 /* 295 * Check if we need to replace the operator and its subtree 296 * with a return value op (placeholder op) 297 */ 298 ParentInfo = AcpiPsGetOpcodeInfo (Op->Common.Parent->Common.AmlOpcode); 299 300 switch (ParentInfo->Class) 301 { 302 case AML_CLASS_CONTROL: 303 304 break; 305 306 case AML_CLASS_CREATE: 307 /* 308 * These opcodes contain TermArg operands. The current 309 * op must be replaced by a placeholder return op 310 */ 311 ReplacementOp = AcpiPsAllocOp ( 312 AML_INT_RETURN_VALUE_OP, Op->Common.Aml); 313 if (!ReplacementOp) 314 { 315 Status = AE_NO_MEMORY; 316 } 317 break; 318 319 case AML_CLASS_NAMED_OBJECT: 320 /* 321 * These opcodes contain TermArg operands. The current 322 * op must be replaced by a placeholder return op 323 */ 324 if ((Op->Common.Parent->Common.AmlOpcode == AML_REGION_OP) || 325 (Op->Common.Parent->Common.AmlOpcode == AML_DATA_REGION_OP) || 326 (Op->Common.Parent->Common.AmlOpcode == AML_BUFFER_OP) || 327 (Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) || 328 (Op->Common.Parent->Common.AmlOpcode == AML_BANK_FIELD_OP) || 329 (Op->Common.Parent->Common.AmlOpcode == AML_VARIABLE_PACKAGE_OP)) 330 { 331 ReplacementOp = AcpiPsAllocOp ( 332 AML_INT_RETURN_VALUE_OP, Op->Common.Aml); 333 if (!ReplacementOp) 334 { 335 Status = AE_NO_MEMORY; 336 } 337 } 338 else if ((Op->Common.Parent->Common.AmlOpcode == AML_NAME_OP) && 339 (WalkState->PassNumber <= ACPI_IMODE_LOAD_PASS2)) 340 { 341 if ((Op->Common.AmlOpcode == AML_BUFFER_OP) || 342 (Op->Common.AmlOpcode == AML_PACKAGE_OP) || 343 (Op->Common.AmlOpcode == AML_VARIABLE_PACKAGE_OP)) 344 { 345 ReplacementOp = AcpiPsAllocOp (Op->Common.AmlOpcode, 346 Op->Common.Aml); 347 if (!ReplacementOp) 348 { 349 Status = AE_NO_MEMORY; 350 } 351 else 352 { 353 ReplacementOp->Named.Data = Op->Named.Data; 354 ReplacementOp->Named.Length = Op->Named.Length; 355 } 356 } 357 } 358 break; 359 360 default: 361 362 ReplacementOp = AcpiPsAllocOp ( 363 AML_INT_RETURN_VALUE_OP, Op->Common.Aml); 364 if (!ReplacementOp) 365 { 366 Status = AE_NO_MEMORY; 367 } 368 } 369 370 /* We must unlink this op from the parent tree */ 371 372 if (Prev == Op) 373 { 374 /* This op is the first in the list */ 375 376 if (ReplacementOp) 377 { 378 ReplacementOp->Common.Parent = Op->Common.Parent; 379 ReplacementOp->Common.Value.Arg = NULL; 380 ReplacementOp->Common.Node = Op->Common.Node; 381 Op->Common.Parent->Common.Value.Arg = ReplacementOp; 382 ReplacementOp->Common.Next = Op->Common.Next; 383 } 384 else 385 { 386 Op->Common.Parent->Common.Value.Arg = Op->Common.Next; 387 } 388 } 389 390 /* Search the parent list */ 391 392 else while (Prev) 393 { 394 /* Traverse all siblings in the parent's argument list */ 395 396 Next = Prev->Common.Next; 397 if (Next == Op) 398 { 399 if (ReplacementOp) 400 { 401 ReplacementOp->Common.Parent = Op->Common.Parent; 402 ReplacementOp->Common.Value.Arg = NULL; 403 ReplacementOp->Common.Node = Op->Common.Node; 404 Prev->Common.Next = ReplacementOp; 405 ReplacementOp->Common.Next = Op->Common.Next; 406 Next = NULL; 407 } 408 else 409 { 410 Prev->Common.Next = Op->Common.Next; 411 Next = NULL; 412 } 413 } 414 Prev = Next; 415 } 416 } 417 418 419 Cleanup: 420 421 /* Now we can actually delete the subtree rooted at Op */ 422 423 AcpiPsDeleteParseTree (Op); 424 return_ACPI_STATUS (Status); 425 } 426 427 428 /******************************************************************************* 429 * 430 * FUNCTION: AcpiPsNextParseState 431 * 432 * PARAMETERS: WalkState - Current state 433 * Op - Current parse op 434 * CallbackStatus - Status from previous operation 435 * 436 * RETURN: Status 437 * 438 * DESCRIPTION: Update the parser state based upon the return exception from 439 * the parser callback. 440 * 441 ******************************************************************************/ 442 443 ACPI_STATUS 444 AcpiPsNextParseState ( 445 ACPI_WALK_STATE *WalkState, 446 ACPI_PARSE_OBJECT *Op, 447 ACPI_STATUS CallbackStatus) 448 { 449 ACPI_PARSE_STATE *ParserState = &WalkState->ParserState; 450 ACPI_STATUS Status = AE_CTRL_PENDING; 451 452 453 ACPI_FUNCTION_TRACE_PTR (PsNextParseState, Op); 454 455 456 switch (CallbackStatus) 457 { 458 case AE_CTRL_TERMINATE: 459 /* 460 * A control method was terminated via a RETURN statement. 461 * The walk of this method is complete. 462 */ 463 ParserState->Aml = ParserState->AmlEnd; 464 Status = AE_CTRL_TERMINATE; 465 break; 466 467 case AE_CTRL_BREAK: 468 469 ParserState->Aml = WalkState->AmlLastWhile; 470 WalkState->ControlState->Common.Value = FALSE; 471 Status = AE_CTRL_BREAK; 472 break; 473 474 case AE_CTRL_CONTINUE: 475 476 ParserState->Aml = WalkState->AmlLastWhile; 477 Status = AE_CTRL_CONTINUE; 478 break; 479 480 case AE_CTRL_PENDING: 481 482 ParserState->Aml = WalkState->AmlLastWhile; 483 break; 484 485 #if 0 486 case AE_CTRL_SKIP: 487 488 ParserState->Aml = ParserState->Scope->ParseScope.PkgEnd; 489 Status = AE_OK; 490 break; 491 #endif 492 493 case AE_CTRL_TRUE: 494 /* 495 * Predicate of an IF was true, and we are at the matching ELSE. 496 * Just close out this package 497 */ 498 ParserState->Aml = AcpiPsGetNextPackageEnd (ParserState); 499 Status = AE_CTRL_PENDING; 500 break; 501 502 case AE_CTRL_FALSE: 503 /* 504 * Either an IF/WHILE Predicate was false or we encountered a BREAK 505 * opcode. In both cases, we do not execute the rest of the 506 * package; We simply close out the parent (finishing the walk of 507 * this branch of the tree) and continue execution at the parent 508 * level. 509 */ 510 ParserState->Aml = ParserState->Scope->ParseScope.PkgEnd; 511 512 /* In the case of a BREAK, just force a predicate (if any) to FALSE */ 513 514 WalkState->ControlState->Common.Value = FALSE; 515 Status = AE_CTRL_END; 516 break; 517 518 case AE_CTRL_TRANSFER: 519 520 /* A method call (invocation) -- transfer control */ 521 522 Status = AE_CTRL_TRANSFER; 523 WalkState->PrevOp = Op; 524 WalkState->MethodCallOp = Op; 525 WalkState->MethodCallNode = (Op->Common.Value.Arg)->Common.Node; 526 527 /* Will return value (if any) be used by the caller? */ 528 529 WalkState->ReturnUsed = AcpiDsIsResultUsed (Op, WalkState); 530 break; 531 532 default: 533 534 Status = CallbackStatus; 535 if ((CallbackStatus & AE_CODE_MASK) == AE_CODE_CONTROL) 536 { 537 Status = AE_OK; 538 } 539 break; 540 } 541 542 return_ACPI_STATUS (Status); 543 } 544 545 546 /******************************************************************************* 547 * 548 * FUNCTION: AcpiPsParseAml 549 * 550 * PARAMETERS: WalkState - Current state 551 * 552 * 553 * RETURN: Status 554 * 555 * DESCRIPTION: Parse raw AML and return a tree of ops 556 * 557 ******************************************************************************/ 558 559 ACPI_STATUS 560 AcpiPsParseAml ( 561 ACPI_WALK_STATE *WalkState) 562 { 563 ACPI_STATUS Status; 564 ACPI_THREAD_STATE *Thread; 565 ACPI_THREAD_STATE *PrevWalkList = AcpiGbl_CurrentWalkList; 566 ACPI_WALK_STATE *PreviousWalkState; 567 568 569 ACPI_FUNCTION_TRACE (PsParseAml); 570 571 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, 572 "Entered with WalkState=%p Aml=%p size=%X\n", 573 WalkState, WalkState->ParserState.Aml, 574 WalkState->ParserState.AmlSize)); 575 576 if (!WalkState->ParserState.Aml) 577 { 578 return_ACPI_STATUS (AE_NULL_OBJECT); 579 } 580 581 /* Create and initialize a new thread state */ 582 583 Thread = AcpiUtCreateThreadState (); 584 if (!Thread) 585 { 586 if (WalkState->MethodDesc) 587 { 588 /* Executing a control method - additional cleanup */ 589 590 AcpiDsTerminateControlMethod (WalkState->MethodDesc, WalkState); 591 } 592 593 AcpiDsDeleteWalkState (WalkState); 594 return_ACPI_STATUS (AE_NO_MEMORY); 595 } 596 597 WalkState->Thread = Thread; 598 599 /* 600 * If executing a method, the starting SyncLevel is this method's 601 * SyncLevel 602 */ 603 if (WalkState->MethodDesc) 604 { 605 WalkState->Thread->CurrentSyncLevel = 606 WalkState->MethodDesc->Method.SyncLevel; 607 } 608 609 AcpiDsPushWalkState (WalkState, Thread); 610 611 /* 612 * This global allows the AML debugger to get a handle to the currently 613 * executing control method. 614 */ 615 AcpiGbl_CurrentWalkList = Thread; 616 617 /* 618 * Execute the walk loop as long as there is a valid Walk State. This 619 * handles nested control method invocations without recursion. 620 */ 621 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "State=%p\n", WalkState)); 622 623 Status = AE_OK; 624 while (WalkState) 625 { 626 if (ACPI_SUCCESS (Status)) 627 { 628 /* 629 * The ParseLoop executes AML until the method terminates 630 * or calls another method. 631 */ 632 Status = AcpiPsParseLoop (WalkState); 633 } 634 635 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, 636 "Completed one call to walk loop, %s State=%p\n", 637 AcpiFormatException (Status), WalkState)); 638 639 if (Status == AE_CTRL_TRANSFER) 640 { 641 /* 642 * A method call was detected. 643 * Transfer control to the called control method 644 */ 645 Status = AcpiDsCallControlMethod (Thread, WalkState, NULL); 646 if (ACPI_FAILURE (Status)) 647 { 648 Status = AcpiDsMethodError (Status, WalkState); 649 } 650 651 /* 652 * If the transfer to the new method method call worked 653 *, a new walk state was created -- get it 654 */ 655 WalkState = AcpiDsGetCurrentWalkState (Thread); 656 continue; 657 } 658 else if (Status == AE_CTRL_TERMINATE) 659 { 660 Status = AE_OK; 661 } 662 else if ((Status != AE_OK) && (WalkState->MethodDesc)) 663 { 664 /* Either the method parse or actual execution failed */ 665 666 AcpiExExitInterpreter (); 667 ACPI_ERROR_METHOD ("Method parse/execution failed", 668 WalkState->MethodNode, NULL, Status); 669 AcpiExEnterInterpreter (); 670 671 /* Check for possible multi-thread reentrancy problem */ 672 673 if ((Status == AE_ALREADY_EXISTS) && 674 (!(WalkState->MethodDesc->Method.InfoFlags & 675 ACPI_METHOD_SERIALIZED))) 676 { 677 /* 678 * Method is not serialized and tried to create an object 679 * twice. The probable cause is that the method cannot 680 * handle reentrancy. Mark as "pending serialized" now, and 681 * then mark "serialized" when the last thread exits. 682 */ 683 WalkState->MethodDesc->Method.InfoFlags |= 684 ACPI_METHOD_SERIALIZED_PENDING; 685 } 686 } 687 688 /* We are done with this walk, move on to the parent if any */ 689 690 WalkState = AcpiDsPopWalkState (Thread); 691 692 /* Reset the current scope to the beginning of scope stack */ 693 694 AcpiDsScopeStackClear (WalkState); 695 696 /* 697 * If we just returned from the execution of a control method or if we 698 * encountered an error during the method parse phase, there's lots of 699 * cleanup to do 700 */ 701 if (((WalkState->ParseFlags & ACPI_PARSE_MODE_MASK) == 702 ACPI_PARSE_EXECUTE && 703 !(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL)) || 704 (ACPI_FAILURE (Status))) 705 { 706 AcpiDsTerminateControlMethod (WalkState->MethodDesc, WalkState); 707 } 708 709 /* Delete this walk state and all linked control states */ 710 711 AcpiPsCleanupScope (&WalkState->ParserState); 712 PreviousWalkState = WalkState; 713 714 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, 715 "ReturnValue=%p, ImplicitValue=%p State=%p\n", 716 WalkState->ReturnDesc, WalkState->ImplicitReturnObj, WalkState)); 717 718 /* Check if we have restarted a preempted walk */ 719 720 WalkState = AcpiDsGetCurrentWalkState (Thread); 721 if (WalkState) 722 { 723 if (ACPI_SUCCESS (Status)) 724 { 725 /* 726 * There is another walk state, restart it. 727 * If the method return value is not used by the parent, 728 * The object is deleted 729 */ 730 if (!PreviousWalkState->ReturnDesc) 731 { 732 /* 733 * In slack mode execution, if there is no return value 734 * we should implicitly return zero (0) as a default value. 735 */ 736 if (AcpiGbl_EnableInterpreterSlack && 737 !PreviousWalkState->ImplicitReturnObj) 738 { 739 PreviousWalkState->ImplicitReturnObj = 740 AcpiUtCreateIntegerObject ((UINT64) 0); 741 if (!PreviousWalkState->ImplicitReturnObj) 742 { 743 return_ACPI_STATUS (AE_NO_MEMORY); 744 } 745 } 746 747 /* Restart the calling control method */ 748 749 Status = AcpiDsRestartControlMethod (WalkState, 750 PreviousWalkState->ImplicitReturnObj); 751 } 752 else 753 { 754 /* 755 * We have a valid return value, delete any implicit 756 * return value. 757 */ 758 AcpiDsClearImplicitReturn (PreviousWalkState); 759 760 Status = AcpiDsRestartControlMethod (WalkState, 761 PreviousWalkState->ReturnDesc); 762 } 763 if (ACPI_SUCCESS (Status)) 764 { 765 WalkState->WalkType |= ACPI_WALK_METHOD_RESTART; 766 } 767 } 768 else 769 { 770 /* On error, delete any return object or implicit return */ 771 772 AcpiUtRemoveReference (PreviousWalkState->ReturnDesc); 773 AcpiDsClearImplicitReturn (PreviousWalkState); 774 } 775 } 776 777 /* 778 * Just completed a 1st-level method, save the final internal return 779 * value (if any) 780 */ 781 else if (PreviousWalkState->CallerReturnDesc) 782 { 783 if (PreviousWalkState->ImplicitReturnObj) 784 { 785 *(PreviousWalkState->CallerReturnDesc) = 786 PreviousWalkState->ImplicitReturnObj; 787 } 788 else 789 { 790 /* NULL if no return value */ 791 792 *(PreviousWalkState->CallerReturnDesc) = 793 PreviousWalkState->ReturnDesc; 794 } 795 } 796 else 797 { 798 if (PreviousWalkState->ReturnDesc) 799 { 800 /* Caller doesn't want it, must delete it */ 801 802 AcpiUtRemoveReference (PreviousWalkState->ReturnDesc); 803 } 804 if (PreviousWalkState->ImplicitReturnObj) 805 { 806 /* Caller doesn't want it, must delete it */ 807 808 AcpiUtRemoveReference (PreviousWalkState->ImplicitReturnObj); 809 } 810 } 811 812 AcpiDsDeleteWalkState (PreviousWalkState); 813 } 814 815 /* Normal exit */ 816 817 AcpiExReleaseAllMutexes (Thread); 818 AcpiUtDeleteGenericState (ACPI_CAST_PTR (ACPI_GENERIC_STATE, Thread)); 819 AcpiGbl_CurrentWalkList = PrevWalkList; 820 return_ACPI_STATUS (Status); 821 } 822