1 /****************************************************************************** 2 * 3 * Module Name: psobject - Support for parse objects 4 * 5 *****************************************************************************/ 6 7 /****************************************************************************** 8 * 9 * 1. Copyright Notice 10 * 11 * Some or all of this work - Copyright (c) 1999 - 2013, 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 117 #include "acpi.h" 118 #include "accommon.h" 119 #include "acparser.h" 120 #include "amlcode.h" 121 122 #define _COMPONENT ACPI_PARSER 123 ACPI_MODULE_NAME ("psobject") 124 125 126 /* Local prototypes */ 127 128 static ACPI_STATUS 129 AcpiPsGetAmlOpcode ( 130 ACPI_WALK_STATE *WalkState); 131 132 133 /******************************************************************************* 134 * 135 * FUNCTION: AcpiPsGetAmlOpcode 136 * 137 * PARAMETERS: WalkState - Current state 138 * 139 * RETURN: Status 140 * 141 * DESCRIPTION: Extract the next AML opcode from the input stream. 142 * 143 ******************************************************************************/ 144 145 static ACPI_STATUS 146 AcpiPsGetAmlOpcode ( 147 ACPI_WALK_STATE *WalkState) 148 { 149 150 ACPI_FUNCTION_TRACE_PTR (PsGetAmlOpcode, WalkState); 151 152 153 WalkState->AmlOffset = (UINT32) ACPI_PTR_DIFF (WalkState->ParserState.Aml, 154 WalkState->ParserState.AmlStart); 155 WalkState->Opcode = AcpiPsPeekOpcode (&(WalkState->ParserState)); 156 157 /* 158 * First cut to determine what we have found: 159 * 1) A valid AML opcode 160 * 2) A name string 161 * 3) An unknown/invalid opcode 162 */ 163 WalkState->OpInfo = AcpiPsGetOpcodeInfo (WalkState->Opcode); 164 165 switch (WalkState->OpInfo->Class) 166 { 167 case AML_CLASS_ASCII: 168 case AML_CLASS_PREFIX: 169 /* 170 * Starts with a valid prefix or ASCII char, this is a name 171 * string. Convert the bare name string to a namepath. 172 */ 173 WalkState->Opcode = AML_INT_NAMEPATH_OP; 174 WalkState->ArgTypes = ARGP_NAMESTRING; 175 break; 176 177 case AML_CLASS_UNKNOWN: 178 179 /* The opcode is unrecognized. Complain and skip unknown opcodes */ 180 181 if (WalkState->PassNumber == 2) 182 { 183 ACPI_ERROR ((AE_INFO, 184 "Unknown opcode 0x%.2X at table offset 0x%.4X, ignoring", 185 WalkState->Opcode, 186 (UINT32) (WalkState->AmlOffset + sizeof (ACPI_TABLE_HEADER)))); 187 188 ACPI_DUMP_BUFFER ((WalkState->ParserState.Aml - 16), 48); 189 190 #ifdef ACPI_ASL_COMPILER 191 /* 192 * This is executed for the disassembler only. Output goes 193 * to the disassembled ASL output file. 194 */ 195 AcpiOsPrintf ( 196 "/*\nError: Unknown opcode 0x%.2X at table offset 0x%.4X, context:\n", 197 WalkState->Opcode, 198 (UINT32) (WalkState->AmlOffset + sizeof (ACPI_TABLE_HEADER))); 199 200 /* Dump the context surrounding the invalid opcode */ 201 202 AcpiUtDumpBuffer (((UINT8 *) WalkState->ParserState.Aml - 16), 203 48, DB_BYTE_DISPLAY, 204 (WalkState->AmlOffset + sizeof (ACPI_TABLE_HEADER) - 16)); 205 AcpiOsPrintf (" */\n"); 206 #endif 207 } 208 209 /* Increment past one-byte or two-byte opcode */ 210 211 WalkState->ParserState.Aml++; 212 if (WalkState->Opcode > 0xFF) /* Can only happen if first byte is 0x5B */ 213 { 214 WalkState->ParserState.Aml++; 215 } 216 217 return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE); 218 219 default: 220 221 /* Found opcode info, this is a normal opcode */ 222 223 WalkState->ParserState.Aml += AcpiPsGetOpcodeSize (WalkState->Opcode); 224 WalkState->ArgTypes = WalkState->OpInfo->ParseArgs; 225 break; 226 } 227 228 return_ACPI_STATUS (AE_OK); 229 } 230 231 232 /******************************************************************************* 233 * 234 * FUNCTION: AcpiPsBuildNamedOp 235 * 236 * PARAMETERS: WalkState - Current state 237 * AmlOpStart - Begin of named Op in AML 238 * UnnamedOp - Early Op (not a named Op) 239 * Op - Returned Op 240 * 241 * RETURN: Status 242 * 243 * DESCRIPTION: Parse a named Op 244 * 245 ******************************************************************************/ 246 247 ACPI_STATUS 248 AcpiPsBuildNamedOp ( 249 ACPI_WALK_STATE *WalkState, 250 UINT8 *AmlOpStart, 251 ACPI_PARSE_OBJECT *UnnamedOp, 252 ACPI_PARSE_OBJECT **Op) 253 { 254 ACPI_STATUS Status = AE_OK; 255 ACPI_PARSE_OBJECT *Arg = NULL; 256 257 258 ACPI_FUNCTION_TRACE_PTR (PsBuildNamedOp, WalkState); 259 260 261 UnnamedOp->Common.Value.Arg = NULL; 262 UnnamedOp->Common.ArgListLength = 0; 263 UnnamedOp->Common.AmlOpcode = WalkState->Opcode; 264 265 /* 266 * Get and append arguments until we find the node that contains 267 * the name (the type ARGP_NAME). 268 */ 269 while (GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) && 270 (GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) != ARGP_NAME)) 271 { 272 Status = AcpiPsGetNextArg (WalkState, &(WalkState->ParserState), 273 GET_CURRENT_ARG_TYPE (WalkState->ArgTypes), &Arg); 274 if (ACPI_FAILURE (Status)) 275 { 276 return_ACPI_STATUS (Status); 277 } 278 279 AcpiPsAppendArg (UnnamedOp, Arg); 280 INCREMENT_ARG_LIST (WalkState->ArgTypes); 281 } 282 283 /* 284 * Make sure that we found a NAME and didn't run out of arguments 285 */ 286 if (!GET_CURRENT_ARG_TYPE (WalkState->ArgTypes)) 287 { 288 return_ACPI_STATUS (AE_AML_NO_OPERAND); 289 } 290 291 /* We know that this arg is a name, move to next arg */ 292 293 INCREMENT_ARG_LIST (WalkState->ArgTypes); 294 295 /* 296 * Find the object. This will either insert the object into 297 * the namespace or simply look it up 298 */ 299 WalkState->Op = NULL; 300 301 Status = WalkState->DescendingCallback (WalkState, Op); 302 if (ACPI_FAILURE (Status)) 303 { 304 ACPI_EXCEPTION ((AE_INFO, Status, "During name lookup/catalog")); 305 return_ACPI_STATUS (Status); 306 } 307 308 if (!*Op) 309 { 310 return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE); 311 } 312 313 Status = AcpiPsNextParseState (WalkState, *Op, Status); 314 if (ACPI_FAILURE (Status)) 315 { 316 if (Status == AE_CTRL_PENDING) 317 { 318 return_ACPI_STATUS (AE_CTRL_PARSE_PENDING); 319 } 320 return_ACPI_STATUS (Status); 321 } 322 323 AcpiPsAppendArg (*Op, UnnamedOp->Common.Value.Arg); 324 325 if ((*Op)->Common.AmlOpcode == AML_REGION_OP || 326 (*Op)->Common.AmlOpcode == AML_DATA_REGION_OP) 327 { 328 /* 329 * Defer final parsing of an OperationRegion body, because we don't 330 * have enough info in the first pass to parse it correctly (i.e., 331 * there may be method calls within the TermArg elements of the body.) 332 * 333 * However, we must continue parsing because the opregion is not a 334 * standalone package -- we don't know where the end is at this point. 335 * 336 * (Length is unknown until parse of the body complete) 337 */ 338 (*Op)->Named.Data = AmlOpStart; 339 (*Op)->Named.Length = 0; 340 } 341 342 return_ACPI_STATUS (AE_OK); 343 } 344 345 346 /******************************************************************************* 347 * 348 * FUNCTION: AcpiPsCreateOp 349 * 350 * PARAMETERS: WalkState - Current state 351 * AmlOpStart - Op start in AML 352 * NewOp - Returned Op 353 * 354 * RETURN: Status 355 * 356 * DESCRIPTION: Get Op from AML 357 * 358 ******************************************************************************/ 359 360 ACPI_STATUS 361 AcpiPsCreateOp ( 362 ACPI_WALK_STATE *WalkState, 363 UINT8 *AmlOpStart, 364 ACPI_PARSE_OBJECT **NewOp) 365 { 366 ACPI_STATUS Status = AE_OK; 367 ACPI_PARSE_OBJECT *Op; 368 ACPI_PARSE_OBJECT *NamedOp = NULL; 369 ACPI_PARSE_OBJECT *ParentScope; 370 UINT8 ArgumentCount; 371 const ACPI_OPCODE_INFO *OpInfo; 372 373 374 ACPI_FUNCTION_TRACE_PTR (PsCreateOp, WalkState); 375 376 377 Status = AcpiPsGetAmlOpcode (WalkState); 378 if (Status == AE_CTRL_PARSE_CONTINUE) 379 { 380 return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE); 381 } 382 383 /* Create Op structure and append to parent's argument list */ 384 385 WalkState->OpInfo = AcpiPsGetOpcodeInfo (WalkState->Opcode); 386 Op = AcpiPsAllocOp (WalkState->Opcode); 387 if (!Op) 388 { 389 return_ACPI_STATUS (AE_NO_MEMORY); 390 } 391 392 if (WalkState->OpInfo->Flags & AML_NAMED) 393 { 394 Status = AcpiPsBuildNamedOp (WalkState, AmlOpStart, Op, &NamedOp); 395 AcpiPsFreeOp (Op); 396 if (ACPI_FAILURE (Status)) 397 { 398 return_ACPI_STATUS (Status); 399 } 400 401 *NewOp = NamedOp; 402 return_ACPI_STATUS (AE_OK); 403 } 404 405 /* Not a named opcode, just allocate Op and append to parent */ 406 407 if (WalkState->OpInfo->Flags & AML_CREATE) 408 { 409 /* 410 * Backup to beginning of CreateXXXfield declaration 411 * BodyLength is unknown until we parse the body 412 */ 413 Op->Named.Data = AmlOpStart; 414 Op->Named.Length = 0; 415 } 416 417 if (WalkState->Opcode == AML_BANK_FIELD_OP) 418 { 419 /* 420 * Backup to beginning of BankField declaration 421 * BodyLength is unknown until we parse the body 422 */ 423 Op->Named.Data = AmlOpStart; 424 Op->Named.Length = 0; 425 } 426 427 ParentScope = AcpiPsGetParentScope (&(WalkState->ParserState)); 428 AcpiPsAppendArg (ParentScope, Op); 429 430 if (ParentScope) 431 { 432 OpInfo = AcpiPsGetOpcodeInfo (ParentScope->Common.AmlOpcode); 433 if (OpInfo->Flags & AML_HAS_TARGET) 434 { 435 ArgumentCount = AcpiPsGetArgumentCount (OpInfo->Type); 436 if (ParentScope->Common.ArgListLength > ArgumentCount) 437 { 438 Op->Common.Flags |= ACPI_PARSEOP_TARGET; 439 } 440 } 441 else if (ParentScope->Common.AmlOpcode == AML_INCREMENT_OP) 442 { 443 Op->Common.Flags |= ACPI_PARSEOP_TARGET; 444 } 445 } 446 447 if (WalkState->DescendingCallback != NULL) 448 { 449 /* 450 * Find the object. This will either insert the object into 451 * the namespace or simply look it up 452 */ 453 WalkState->Op = *NewOp = Op; 454 455 Status = WalkState->DescendingCallback (WalkState, &Op); 456 Status = AcpiPsNextParseState (WalkState, Op, Status); 457 if (Status == AE_CTRL_PENDING) 458 { 459 Status = AE_CTRL_PARSE_PENDING; 460 } 461 } 462 463 return_ACPI_STATUS (Status); 464 } 465 466 467 /******************************************************************************* 468 * 469 * FUNCTION: AcpiPsCompleteOp 470 * 471 * PARAMETERS: WalkState - Current state 472 * Op - Returned Op 473 * Status - Parse status before complete Op 474 * 475 * RETURN: Status 476 * 477 * DESCRIPTION: Complete Op 478 * 479 ******************************************************************************/ 480 481 ACPI_STATUS 482 AcpiPsCompleteOp ( 483 ACPI_WALK_STATE *WalkState, 484 ACPI_PARSE_OBJECT **Op, 485 ACPI_STATUS Status) 486 { 487 ACPI_STATUS Status2; 488 489 490 ACPI_FUNCTION_TRACE_PTR (PsCompleteOp, WalkState); 491 492 493 /* 494 * Finished one argument of the containing scope 495 */ 496 WalkState->ParserState.Scope->ParseScope.ArgCount--; 497 498 /* Close this Op (will result in parse subtree deletion) */ 499 500 Status2 = AcpiPsCompleteThisOp (WalkState, *Op); 501 if (ACPI_FAILURE (Status2)) 502 { 503 return_ACPI_STATUS (Status2); 504 } 505 506 *Op = NULL; 507 508 switch (Status) 509 { 510 case AE_OK: 511 512 break; 513 514 case AE_CTRL_TRANSFER: 515 516 /* We are about to transfer to a called method */ 517 518 WalkState->PrevOp = NULL; 519 WalkState->PrevArgTypes = WalkState->ArgTypes; 520 return_ACPI_STATUS (Status); 521 522 case AE_CTRL_END: 523 524 AcpiPsPopScope (&(WalkState->ParserState), Op, 525 &WalkState->ArgTypes, &WalkState->ArgCount); 526 527 if (*Op) 528 { 529 WalkState->Op = *Op; 530 WalkState->OpInfo = AcpiPsGetOpcodeInfo ((*Op)->Common.AmlOpcode); 531 WalkState->Opcode = (*Op)->Common.AmlOpcode; 532 533 Status = WalkState->AscendingCallback (WalkState); 534 Status = AcpiPsNextParseState (WalkState, *Op, Status); 535 536 Status2 = AcpiPsCompleteThisOp (WalkState, *Op); 537 if (ACPI_FAILURE (Status2)) 538 { 539 return_ACPI_STATUS (Status2); 540 } 541 } 542 543 Status = AE_OK; 544 break; 545 546 case AE_CTRL_BREAK: 547 case AE_CTRL_CONTINUE: 548 549 /* Pop off scopes until we find the While */ 550 551 while (!(*Op) || ((*Op)->Common.AmlOpcode != AML_WHILE_OP)) 552 { 553 AcpiPsPopScope (&(WalkState->ParserState), Op, 554 &WalkState->ArgTypes, &WalkState->ArgCount); 555 } 556 557 /* Close this iteration of the While loop */ 558 559 WalkState->Op = *Op; 560 WalkState->OpInfo = AcpiPsGetOpcodeInfo ((*Op)->Common.AmlOpcode); 561 WalkState->Opcode = (*Op)->Common.AmlOpcode; 562 563 Status = WalkState->AscendingCallback (WalkState); 564 Status = AcpiPsNextParseState (WalkState, *Op, Status); 565 566 Status2 = AcpiPsCompleteThisOp (WalkState, *Op); 567 if (ACPI_FAILURE (Status2)) 568 { 569 return_ACPI_STATUS (Status2); 570 } 571 572 Status = AE_OK; 573 break; 574 575 case AE_CTRL_TERMINATE: 576 577 /* Clean up */ 578 do 579 { 580 if (*Op) 581 { 582 Status2 = AcpiPsCompleteThisOp (WalkState, *Op); 583 if (ACPI_FAILURE (Status2)) 584 { 585 return_ACPI_STATUS (Status2); 586 } 587 588 AcpiUtDeleteGenericState ( 589 AcpiUtPopGenericState (&WalkState->ControlState)); 590 } 591 592 AcpiPsPopScope (&(WalkState->ParserState), Op, 593 &WalkState->ArgTypes, &WalkState->ArgCount); 594 595 } while (*Op); 596 597 return_ACPI_STATUS (AE_OK); 598 599 default: /* All other non-AE_OK status */ 600 601 do 602 { 603 if (*Op) 604 { 605 Status2 = AcpiPsCompleteThisOp (WalkState, *Op); 606 if (ACPI_FAILURE (Status2)) 607 { 608 return_ACPI_STATUS (Status2); 609 } 610 } 611 612 AcpiPsPopScope (&(WalkState->ParserState), Op, 613 &WalkState->ArgTypes, &WalkState->ArgCount); 614 615 } while (*Op); 616 617 618 #if 0 619 /* 620 * TBD: Cleanup parse ops on error 621 */ 622 if (*Op == NULL) 623 { 624 AcpiPsPopScope (ParserState, Op, 625 &WalkState->ArgTypes, &WalkState->ArgCount); 626 } 627 #endif 628 WalkState->PrevOp = NULL; 629 WalkState->PrevArgTypes = WalkState->ArgTypes; 630 return_ACPI_STATUS (Status); 631 } 632 633 /* This scope complete? */ 634 635 if (AcpiPsHasCompletedScope (&(WalkState->ParserState))) 636 { 637 AcpiPsPopScope (&(WalkState->ParserState), Op, 638 &WalkState->ArgTypes, &WalkState->ArgCount); 639 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Popped scope, Op=%p\n", *Op)); 640 } 641 else 642 { 643 *Op = NULL; 644 } 645 646 return_ACPI_STATUS (AE_OK); 647 } 648 649 650 /******************************************************************************* 651 * 652 * FUNCTION: AcpiPsCompleteFinalOp 653 * 654 * PARAMETERS: WalkState - Current state 655 * Op - Current Op 656 * Status - Current parse status before complete last 657 * Op 658 * 659 * RETURN: Status 660 * 661 * DESCRIPTION: Complete last Op. 662 * 663 ******************************************************************************/ 664 665 ACPI_STATUS 666 AcpiPsCompleteFinalOp ( 667 ACPI_WALK_STATE *WalkState, 668 ACPI_PARSE_OBJECT *Op, 669 ACPI_STATUS Status) 670 { 671 ACPI_STATUS Status2; 672 673 674 ACPI_FUNCTION_TRACE_PTR (PsCompleteFinalOp, WalkState); 675 676 677 /* 678 * Complete the last Op (if not completed), and clear the scope stack. 679 * It is easily possible to end an AML "package" with an unbounded number 680 * of open scopes (such as when several ASL blocks are closed with 681 * sequential closing braces). We want to terminate each one cleanly. 682 */ 683 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "AML package complete at Op %p\n", Op)); 684 do 685 { 686 if (Op) 687 { 688 if (WalkState->AscendingCallback != NULL) 689 { 690 WalkState->Op = Op; 691 WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode); 692 WalkState->Opcode = Op->Common.AmlOpcode; 693 694 Status = WalkState->AscendingCallback (WalkState); 695 Status = AcpiPsNextParseState (WalkState, Op, Status); 696 if (Status == AE_CTRL_PENDING) 697 { 698 Status = AcpiPsCompleteOp (WalkState, &Op, AE_OK); 699 if (ACPI_FAILURE (Status)) 700 { 701 return_ACPI_STATUS (Status); 702 } 703 } 704 705 if (Status == AE_CTRL_TERMINATE) 706 { 707 Status = AE_OK; 708 709 /* Clean up */ 710 do 711 { 712 if (Op) 713 { 714 Status2 = AcpiPsCompleteThisOp (WalkState, Op); 715 if (ACPI_FAILURE (Status2)) 716 { 717 return_ACPI_STATUS (Status2); 718 } 719 } 720 721 AcpiPsPopScope (&(WalkState->ParserState), &Op, 722 &WalkState->ArgTypes, &WalkState->ArgCount); 723 724 } while (Op); 725 726 return_ACPI_STATUS (Status); 727 } 728 729 else if (ACPI_FAILURE (Status)) 730 { 731 /* First error is most important */ 732 733 (void) AcpiPsCompleteThisOp (WalkState, Op); 734 return_ACPI_STATUS (Status); 735 } 736 } 737 738 Status2 = AcpiPsCompleteThisOp (WalkState, Op); 739 if (ACPI_FAILURE (Status2)) 740 { 741 return_ACPI_STATUS (Status2); 742 } 743 } 744 745 AcpiPsPopScope (&(WalkState->ParserState), &Op, &WalkState->ArgTypes, 746 &WalkState->ArgCount); 747 748 } while (Op); 749 750 return_ACPI_STATUS (Status); 751 } 752