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 - 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/acparser.h> 155 #include <contrib/dev/acpica/include/amlcode.h> 156 #include <contrib/dev/acpica/include/acconvert.h> 157 158 #define _COMPONENT ACPI_PARSER 159 ACPI_MODULE_NAME ("psobject") 160 161 162 /* Local prototypes */ 163 164 static ACPI_STATUS 165 AcpiPsGetAmlOpcode ( 166 ACPI_WALK_STATE *WalkState); 167 168 169 /******************************************************************************* 170 * 171 * FUNCTION: AcpiPsGetAmlOpcode 172 * 173 * PARAMETERS: WalkState - Current state 174 * 175 * RETURN: Status 176 * 177 * DESCRIPTION: Extract the next AML opcode from the input stream. 178 * 179 ******************************************************************************/ 180 181 static ACPI_STATUS 182 AcpiPsGetAmlOpcode ( 183 ACPI_WALK_STATE *WalkState) 184 { 185 UINT32 AmlOffset; 186 187 188 ACPI_FUNCTION_TRACE_PTR (PsGetAmlOpcode, WalkState); 189 190 191 WalkState->Aml = WalkState->ParserState.Aml; 192 WalkState->Opcode = AcpiPsPeekOpcode (&(WalkState->ParserState)); 193 194 /* 195 * First cut to determine what we have found: 196 * 1) A valid AML opcode 197 * 2) A name string 198 * 3) An unknown/invalid opcode 199 */ 200 WalkState->OpInfo = AcpiPsGetOpcodeInfo (WalkState->Opcode); 201 202 switch (WalkState->OpInfo->Class) 203 { 204 case AML_CLASS_ASCII: 205 case AML_CLASS_PREFIX: 206 /* 207 * Starts with a valid prefix or ASCII char, this is a name 208 * string. Convert the bare name string to a namepath. 209 */ 210 WalkState->Opcode = AML_INT_NAMEPATH_OP; 211 WalkState->ArgTypes = ARGP_NAMESTRING; 212 break; 213 214 case AML_CLASS_UNKNOWN: 215 216 /* The opcode is unrecognized. Complain and skip unknown opcodes */ 217 218 if (WalkState->PassNumber == 2) 219 { 220 AmlOffset = (UINT32) ACPI_PTR_DIFF (WalkState->Aml, 221 WalkState->ParserState.AmlStart); 222 223 ACPI_ERROR ((AE_INFO, 224 "Unknown opcode 0x%.2X at table offset 0x%.4X, ignoring", 225 WalkState->Opcode, 226 (UINT32) (AmlOffset + sizeof (ACPI_TABLE_HEADER)))); 227 228 ACPI_DUMP_BUFFER ((WalkState->ParserState.Aml - 16), 48); 229 230 #ifdef ACPI_ASL_COMPILER 231 /* 232 * This is executed for the disassembler only. Output goes 233 * to the disassembled ASL output file. 234 */ 235 AcpiOsPrintf ( 236 "/*\nError: Unknown opcode 0x%.2X at table offset 0x%.4X, context:\n", 237 WalkState->Opcode, 238 (UINT32) (AmlOffset + sizeof (ACPI_TABLE_HEADER))); 239 240 ACPI_ERROR ((AE_INFO, 241 "Aborting disassembly, AML byte code is corrupt")); 242 243 /* Dump the context surrounding the invalid opcode */ 244 245 AcpiUtDumpBuffer (((UINT8 *) WalkState->ParserState.Aml - 16), 246 48, DB_BYTE_DISPLAY, 247 (AmlOffset + sizeof (ACPI_TABLE_HEADER) - 16)); 248 AcpiOsPrintf (" */\n"); 249 250 /* 251 * Just abort the disassembly, cannot continue because the 252 * parser is essentially lost. The disassembler can then 253 * randomly fail because an ill-constructed parse tree 254 * can result. 255 */ 256 return_ACPI_STATUS (AE_AML_BAD_OPCODE); 257 #endif 258 } 259 260 /* Increment past one-byte or two-byte opcode */ 261 262 WalkState->ParserState.Aml++; 263 if (WalkState->Opcode > 0xFF) /* Can only happen if first byte is 0x5B */ 264 { 265 WalkState->ParserState.Aml++; 266 } 267 268 return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE); 269 270 default: 271 272 /* Found opcode info, this is a normal opcode */ 273 274 WalkState->ParserState.Aml += 275 AcpiPsGetOpcodeSize (WalkState->Opcode); 276 WalkState->ArgTypes = WalkState->OpInfo->ParseArgs; 277 break; 278 } 279 280 return_ACPI_STATUS (AE_OK); 281 } 282 283 284 /******************************************************************************* 285 * 286 * FUNCTION: AcpiPsBuildNamedOp 287 * 288 * PARAMETERS: WalkState - Current state 289 * AmlOpStart - Begin of named Op in AML 290 * UnnamedOp - Early Op (not a named Op) 291 * Op - Returned Op 292 * 293 * RETURN: Status 294 * 295 * DESCRIPTION: Parse a named Op 296 * 297 ******************************************************************************/ 298 299 ACPI_STATUS 300 AcpiPsBuildNamedOp ( 301 ACPI_WALK_STATE *WalkState, 302 UINT8 *AmlOpStart, 303 ACPI_PARSE_OBJECT *UnnamedOp, 304 ACPI_PARSE_OBJECT **Op) 305 { 306 ACPI_STATUS Status = AE_OK; 307 ACPI_PARSE_OBJECT *Arg = NULL; 308 309 310 ACPI_FUNCTION_TRACE_PTR (PsBuildNamedOp, WalkState); 311 312 313 UnnamedOp->Common.Value.Arg = NULL; 314 UnnamedOp->Common.ArgListLength = 0; 315 UnnamedOp->Common.AmlOpcode = WalkState->Opcode; 316 317 /* 318 * Get and append arguments until we find the node that contains 319 * the name (the type ARGP_NAME). 320 */ 321 while (GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) && 322 (GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) != ARGP_NAME)) 323 { 324 ASL_CV_CAPTURE_COMMENTS (WalkState); 325 Status = AcpiPsGetNextArg (WalkState, &(WalkState->ParserState), 326 GET_CURRENT_ARG_TYPE (WalkState->ArgTypes), &Arg); 327 if (ACPI_FAILURE (Status)) 328 { 329 return_ACPI_STATUS (Status); 330 } 331 332 AcpiPsAppendArg (UnnamedOp, Arg); 333 INCREMENT_ARG_LIST (WalkState->ArgTypes); 334 } 335 336 /* are there any inline comments associated with the NameSeg?? If so, save this. */ 337 338 ASL_CV_CAPTURE_COMMENTS (WalkState); 339 340 #ifdef ACPI_ASL_COMPILER 341 if (AcpiGbl_CurrentInlineComment != NULL) 342 { 343 UnnamedOp->Common.NameComment = AcpiGbl_CurrentInlineComment; 344 AcpiGbl_CurrentInlineComment = NULL; 345 } 346 #endif 347 348 /* 349 * Make sure that we found a NAME and didn't run out of arguments 350 */ 351 if (!GET_CURRENT_ARG_TYPE (WalkState->ArgTypes)) 352 { 353 return_ACPI_STATUS (AE_AML_NO_OPERAND); 354 } 355 356 /* We know that this arg is a name, move to next arg */ 357 358 INCREMENT_ARG_LIST (WalkState->ArgTypes); 359 360 /* 361 * Find the object. This will either insert the object into 362 * the namespace or simply look it up 363 */ 364 WalkState->Op = NULL; 365 366 Status = WalkState->DescendingCallback (WalkState, Op); 367 if (ACPI_FAILURE (Status)) 368 { 369 if (Status != AE_CTRL_TERMINATE) 370 { 371 ACPI_EXCEPTION ((AE_INFO, Status, "During name lookup/catalog")); 372 } 373 return_ACPI_STATUS (Status); 374 } 375 376 if (!*Op) 377 { 378 return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE); 379 } 380 381 Status = AcpiPsNextParseState (WalkState, *Op, Status); 382 if (ACPI_FAILURE (Status)) 383 { 384 if (Status == AE_CTRL_PENDING) 385 { 386 Status = AE_CTRL_PARSE_PENDING; 387 } 388 return_ACPI_STATUS (Status); 389 } 390 391 AcpiPsAppendArg (*Op, UnnamedOp->Common.Value.Arg); 392 393 #ifdef ACPI_ASL_COMPILER 394 395 /* save any comments that might be associated with UnnamedOp. */ 396 397 (*Op)->Common.InlineComment = UnnamedOp->Common.InlineComment; 398 (*Op)->Common.EndNodeComment = UnnamedOp->Common.EndNodeComment; 399 (*Op)->Common.CloseBraceComment = UnnamedOp->Common.CloseBraceComment; 400 (*Op)->Common.NameComment = UnnamedOp->Common.NameComment; 401 (*Op)->Common.CommentList = UnnamedOp->Common.CommentList; 402 (*Op)->Common.EndBlkComment = UnnamedOp->Common.EndBlkComment; 403 (*Op)->Common.CvFilename = UnnamedOp->Common.CvFilename; 404 (*Op)->Common.CvParentFilename = UnnamedOp->Common.CvParentFilename; 405 (*Op)->Named.Aml = UnnamedOp->Common.Aml; 406 407 UnnamedOp->Common.InlineComment = NULL; 408 UnnamedOp->Common.EndNodeComment = NULL; 409 UnnamedOp->Common.CloseBraceComment = NULL; 410 UnnamedOp->Common.NameComment = NULL; 411 UnnamedOp->Common.CommentList = NULL; 412 UnnamedOp->Common.EndBlkComment = NULL; 413 #endif 414 415 if ((*Op)->Common.AmlOpcode == AML_REGION_OP || 416 (*Op)->Common.AmlOpcode == AML_DATA_REGION_OP) 417 { 418 /* 419 * Defer final parsing of an OperationRegion body, because we don't 420 * have enough info in the first pass to parse it correctly (i.e., 421 * there may be method calls within the TermArg elements of the body.) 422 * 423 * However, we must continue parsing because the opregion is not a 424 * standalone package -- we don't know where the end is at this point. 425 * 426 * (Length is unknown until parse of the body complete) 427 */ 428 (*Op)->Named.Data = AmlOpStart; 429 (*Op)->Named.Length = 0; 430 } 431 432 return_ACPI_STATUS (AE_OK); 433 } 434 435 436 /******************************************************************************* 437 * 438 * FUNCTION: AcpiPsCreateOp 439 * 440 * PARAMETERS: WalkState - Current state 441 * AmlOpStart - Op start in AML 442 * NewOp - Returned Op 443 * 444 * RETURN: Status 445 * 446 * DESCRIPTION: Get Op from AML 447 * 448 ******************************************************************************/ 449 450 ACPI_STATUS 451 AcpiPsCreateOp ( 452 ACPI_WALK_STATE *WalkState, 453 UINT8 *AmlOpStart, 454 ACPI_PARSE_OBJECT **NewOp) 455 { 456 ACPI_STATUS Status = AE_OK; 457 ACPI_PARSE_OBJECT *Op; 458 ACPI_PARSE_OBJECT *NamedOp = NULL; 459 ACPI_PARSE_OBJECT *ParentScope; 460 UINT8 ArgumentCount; 461 const ACPI_OPCODE_INFO *OpInfo; 462 463 464 ACPI_FUNCTION_TRACE_PTR (PsCreateOp, WalkState); 465 466 467 Status = AcpiPsGetAmlOpcode (WalkState); 468 if (Status == AE_CTRL_PARSE_CONTINUE) 469 { 470 return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE); 471 } 472 if (ACPI_FAILURE (Status)) 473 { 474 return_ACPI_STATUS (Status); 475 } 476 477 /* Create Op structure and append to parent's argument list */ 478 479 WalkState->OpInfo = AcpiPsGetOpcodeInfo (WalkState->Opcode); 480 Op = AcpiPsAllocOp (WalkState->Opcode, AmlOpStart); 481 if (!Op) 482 { 483 return_ACPI_STATUS (AE_NO_MEMORY); 484 } 485 486 if (WalkState->OpInfo->Flags & AML_NAMED) 487 { 488 Status = AcpiPsBuildNamedOp (WalkState, AmlOpStart, Op, &NamedOp); 489 AcpiPsFreeOp (Op); 490 491 #ifdef ACPI_ASL_COMPILER 492 if (AcpiGbl_DisasmFlag && WalkState->Opcode == AML_EXTERNAL_OP && 493 Status == AE_NOT_FOUND) 494 { 495 /* 496 * If parsing of AML_EXTERNAL_OP's name path fails, then skip 497 * past this opcode and keep parsing. This is a much better 498 * alternative than to abort the entire disassembler. At this 499 * point, the ParserState is at the end of the namepath of the 500 * external declaration opcode. Setting WalkState->Aml to 501 * WalkState->ParserState.Aml + 2 moves increments the 502 * WalkState->Aml past the object type and the paramcount of the 503 * external opcode. For the error message, only print the AML 504 * offset. We could attempt to print the name but this may cause 505 * a segmentation fault when printing the namepath because the 506 * AML may be incorrect. 507 */ 508 AcpiOsPrintf ( 509 "// Invalid external declaration at AML offset 0x%x.\n", 510 WalkState->Aml - WalkState->ParserState.AmlStart); 511 WalkState->Aml = WalkState->ParserState.Aml + 2; 512 return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE); 513 } 514 #endif 515 if (ACPI_FAILURE (Status)) 516 { 517 return_ACPI_STATUS (Status); 518 } 519 520 *NewOp = NamedOp; 521 return_ACPI_STATUS (AE_OK); 522 } 523 524 /* Not a named opcode, just allocate Op and append to parent */ 525 526 if (WalkState->OpInfo->Flags & AML_CREATE) 527 { 528 /* 529 * Backup to beginning of CreateXXXfield declaration 530 * BodyLength is unknown until we parse the body 531 */ 532 Op->Named.Data = AmlOpStart; 533 Op->Named.Length = 0; 534 } 535 536 if (WalkState->Opcode == AML_BANK_FIELD_OP) 537 { 538 /* 539 * Backup to beginning of BankField declaration 540 * BodyLength is unknown until we parse the body 541 */ 542 Op->Named.Data = AmlOpStart; 543 Op->Named.Length = 0; 544 } 545 546 ParentScope = AcpiPsGetParentScope (&(WalkState->ParserState)); 547 AcpiPsAppendArg (ParentScope, Op); 548 549 if (ParentScope) 550 { 551 OpInfo = AcpiPsGetOpcodeInfo (ParentScope->Common.AmlOpcode); 552 if (OpInfo->Flags & AML_HAS_TARGET) 553 { 554 ArgumentCount = AcpiPsGetArgumentCount (OpInfo->Type); 555 if (ParentScope->Common.ArgListLength > ArgumentCount) 556 { 557 Op->Common.Flags |= ACPI_PARSEOP_TARGET; 558 } 559 } 560 561 /* 562 * Special case for both Increment() and Decrement(), where 563 * the lone argument is both a source and a target. 564 */ 565 else if ((ParentScope->Common.AmlOpcode == AML_INCREMENT_OP) || 566 (ParentScope->Common.AmlOpcode == AML_DECREMENT_OP)) 567 { 568 Op->Common.Flags |= ACPI_PARSEOP_TARGET; 569 } 570 } 571 572 if (WalkState->DescendingCallback != NULL) 573 { 574 /* 575 * Find the object. This will either insert the object into 576 * the namespace or simply look it up 577 */ 578 WalkState->Op = *NewOp = Op; 579 580 Status = WalkState->DescendingCallback (WalkState, &Op); 581 Status = AcpiPsNextParseState (WalkState, Op, Status); 582 if (Status == AE_CTRL_PENDING) 583 { 584 Status = AE_CTRL_PARSE_PENDING; 585 } 586 } 587 588 return_ACPI_STATUS (Status); 589 } 590 591 592 /******************************************************************************* 593 * 594 * FUNCTION: AcpiPsCompleteOp 595 * 596 * PARAMETERS: WalkState - Current state 597 * Op - Returned Op 598 * Status - Parse status before complete Op 599 * 600 * RETURN: Status 601 * 602 * DESCRIPTION: Complete Op 603 * 604 ******************************************************************************/ 605 606 ACPI_STATUS 607 AcpiPsCompleteOp ( 608 ACPI_WALK_STATE *WalkState, 609 ACPI_PARSE_OBJECT **Op, 610 ACPI_STATUS Status) 611 { 612 ACPI_STATUS Status2; 613 614 615 ACPI_FUNCTION_TRACE_PTR (PsCompleteOp, WalkState); 616 617 618 /* 619 * Finished one argument of the containing scope 620 */ 621 WalkState->ParserState.Scope->ParseScope.ArgCount--; 622 623 /* Close this Op (will result in parse subtree deletion) */ 624 625 Status2 = AcpiPsCompleteThisOp (WalkState, *Op); 626 if (ACPI_FAILURE (Status2)) 627 { 628 return_ACPI_STATUS (Status2); 629 } 630 631 *Op = NULL; 632 633 switch (Status) 634 { 635 case AE_OK: 636 637 break; 638 639 case AE_CTRL_TRANSFER: 640 641 /* We are about to transfer to a called method */ 642 643 WalkState->PrevOp = NULL; 644 WalkState->PrevArgTypes = WalkState->ArgTypes; 645 return_ACPI_STATUS (Status); 646 647 case AE_CTRL_END: 648 649 AcpiPsPopScope (&(WalkState->ParserState), Op, 650 &WalkState->ArgTypes, &WalkState->ArgCount); 651 652 if (*Op) 653 { 654 WalkState->Op = *Op; 655 WalkState->OpInfo = AcpiPsGetOpcodeInfo ((*Op)->Common.AmlOpcode); 656 WalkState->Opcode = (*Op)->Common.AmlOpcode; 657 658 Status = WalkState->AscendingCallback (WalkState); 659 Status = AcpiPsNextParseState (WalkState, *Op, Status); 660 661 Status2 = AcpiPsCompleteThisOp (WalkState, *Op); 662 if (ACPI_FAILURE (Status2)) 663 { 664 return_ACPI_STATUS (Status2); 665 } 666 } 667 668 Status = AE_OK; 669 break; 670 671 case AE_CTRL_BREAK: 672 case AE_CTRL_CONTINUE: 673 674 /* Pop off scopes until we find the While */ 675 676 while (!(*Op) || ((*Op)->Common.AmlOpcode != AML_WHILE_OP)) 677 { 678 AcpiPsPopScope (&(WalkState->ParserState), Op, 679 &WalkState->ArgTypes, &WalkState->ArgCount); 680 } 681 682 /* Close this iteration of the While loop */ 683 684 WalkState->Op = *Op; 685 WalkState->OpInfo = AcpiPsGetOpcodeInfo ((*Op)->Common.AmlOpcode); 686 WalkState->Opcode = (*Op)->Common.AmlOpcode; 687 688 Status = WalkState->AscendingCallback (WalkState); 689 Status = AcpiPsNextParseState (WalkState, *Op, Status); 690 691 Status2 = AcpiPsCompleteThisOp (WalkState, *Op); 692 if (ACPI_FAILURE (Status2)) 693 { 694 return_ACPI_STATUS (Status2); 695 } 696 697 Status = AE_OK; 698 break; 699 700 case AE_CTRL_TERMINATE: 701 702 /* Clean up */ 703 do 704 { 705 if (*Op) 706 { 707 Status2 = AcpiPsCompleteThisOp (WalkState, *Op); 708 if (ACPI_FAILURE (Status2)) 709 { 710 return_ACPI_STATUS (Status2); 711 } 712 713 AcpiUtDeleteGenericState ( 714 AcpiUtPopGenericState (&WalkState->ControlState)); 715 } 716 717 AcpiPsPopScope (&(WalkState->ParserState), Op, 718 &WalkState->ArgTypes, &WalkState->ArgCount); 719 720 } while (*Op); 721 722 return_ACPI_STATUS (AE_OK); 723 724 default: /* All other non-AE_OK status */ 725 726 do 727 { 728 if (*Op) 729 { 730 Status2 = AcpiPsCompleteThisOp (WalkState, *Op); 731 if (ACPI_FAILURE (Status2)) 732 { 733 return_ACPI_STATUS (Status2); 734 } 735 } 736 737 AcpiPsPopScope (&(WalkState->ParserState), Op, 738 &WalkState->ArgTypes, &WalkState->ArgCount); 739 740 } while (*Op); 741 742 743 #if 0 744 /* 745 * TBD: Cleanup parse ops on error 746 */ 747 if (*Op == NULL) 748 { 749 AcpiPsPopScope (ParserState, Op, 750 &WalkState->ArgTypes, &WalkState->ArgCount); 751 } 752 #endif 753 WalkState->PrevOp = NULL; 754 WalkState->PrevArgTypes = WalkState->ArgTypes; 755 return_ACPI_STATUS (Status); 756 } 757 758 /* This scope complete? */ 759 760 if (AcpiPsHasCompletedScope (&(WalkState->ParserState))) 761 { 762 AcpiPsPopScope (&(WalkState->ParserState), Op, 763 &WalkState->ArgTypes, &WalkState->ArgCount); 764 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Popped scope, Op=%p\n", *Op)); 765 } 766 else 767 { 768 *Op = NULL; 769 } 770 771 return_ACPI_STATUS (AE_OK); 772 } 773 774 775 /******************************************************************************* 776 * 777 * FUNCTION: AcpiPsCompleteFinalOp 778 * 779 * PARAMETERS: WalkState - Current state 780 * Op - Current Op 781 * Status - Current parse status before complete last 782 * Op 783 * 784 * RETURN: Status 785 * 786 * DESCRIPTION: Complete last Op. 787 * 788 ******************************************************************************/ 789 790 ACPI_STATUS 791 AcpiPsCompleteFinalOp ( 792 ACPI_WALK_STATE *WalkState, 793 ACPI_PARSE_OBJECT *Op, 794 ACPI_STATUS Status) 795 { 796 ACPI_STATUS Status2; 797 798 799 ACPI_FUNCTION_TRACE_PTR (PsCompleteFinalOp, WalkState); 800 801 802 /* 803 * Complete the last Op (if not completed), and clear the scope stack. 804 * It is easily possible to end an AML "package" with an unbounded number 805 * of open scopes (such as when several ASL blocks are closed with 806 * sequential closing braces). We want to terminate each one cleanly. 807 */ 808 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "AML package complete at Op %p\n", Op)); 809 do 810 { 811 if (Op) 812 { 813 if (WalkState->AscendingCallback != NULL) 814 { 815 WalkState->Op = Op; 816 WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode); 817 WalkState->Opcode = Op->Common.AmlOpcode; 818 819 Status = WalkState->AscendingCallback (WalkState); 820 Status = AcpiPsNextParseState (WalkState, Op, Status); 821 if (Status == AE_CTRL_PENDING) 822 { 823 Status = AcpiPsCompleteOp (WalkState, &Op, AE_OK); 824 if (ACPI_FAILURE (Status)) 825 { 826 return_ACPI_STATUS (Status); 827 } 828 } 829 830 if (Status == AE_CTRL_TERMINATE) 831 { 832 Status = AE_OK; 833 834 /* Clean up */ 835 do 836 { 837 if (Op) 838 { 839 Status2 = AcpiPsCompleteThisOp (WalkState, Op); 840 if (ACPI_FAILURE (Status2)) 841 { 842 return_ACPI_STATUS (Status2); 843 } 844 } 845 846 AcpiPsPopScope (&(WalkState->ParserState), &Op, 847 &WalkState->ArgTypes, &WalkState->ArgCount); 848 849 } while (Op); 850 851 return_ACPI_STATUS (Status); 852 } 853 854 else if (ACPI_FAILURE (Status)) 855 { 856 /* First error is most important */ 857 858 (void) AcpiPsCompleteThisOp (WalkState, Op); 859 return_ACPI_STATUS (Status); 860 } 861 } 862 863 Status2 = AcpiPsCompleteThisOp (WalkState, Op); 864 if (ACPI_FAILURE (Status2)) 865 { 866 return_ACPI_STATUS (Status2); 867 } 868 } 869 870 AcpiPsPopScope (&(WalkState->ParserState), &Op, &WalkState->ArgTypes, 871 &WalkState->ArgCount); 872 873 } while (Op); 874 875 return_ACPI_STATUS (Status); 876 } 877