xref: /reactos/drivers/bus/acpi/acpica/parser/psloop.c (revision cc439606)
1 /******************************************************************************
2  *
3  * Module Name: psloop - Main AML parse loop
4  *
5  *****************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2018, Intel Corp.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions, and the following disclaimer,
16  *    without modification.
17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18  *    substantially similar to the "NO WARRANTY" disclaimer below
19  *    ("Disclaimer") and any redistribution must be conditioned upon
20  *    including a substantially similar Disclaimer requirement for further
21  *    binary redistribution.
22  * 3. Neither the names of the above-listed copyright holders nor the names
23  *    of any contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * Alternatively, this software may be distributed under the terms of the
27  * GNU General Public License ("GPL") version 2 as published by the Free
28  * Software Foundation.
29  *
30  * NO WARRANTY
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41  * POSSIBILITY OF SUCH DAMAGES.
42  */
43 
44 /*
45  * Parse the AML and build an operation tree as most interpreters, (such as
46  * Perl) do. Parsing is done by hand rather than with a YACC generated parser
47  * to tightly constrain stack and dynamic memory usage. Parsing is kept
48  * flexible and the code fairly compact by parsing based on a list of AML
49  * opcode templates in AmlOpInfo[].
50  */
51 
52 #include "acpi.h"
53 #include "accommon.h"
54 #include "acinterp.h"
55 #include "acparser.h"
56 #include "acdispat.h"
57 #include "amlcode.h"
58 #include "acconvert.h"
59 #include "acnamesp.h"
60 
61 #define _COMPONENT          ACPI_PARSER
62         ACPI_MODULE_NAME    ("psloop")
63 
64 
65 /* Local prototypes */
66 
67 static ACPI_STATUS
68 AcpiPsGetArguments (
69     ACPI_WALK_STATE         *WalkState,
70     UINT8                   *AmlOpStart,
71     ACPI_PARSE_OBJECT       *Op);
72 
73 static void
74 AcpiPsLinkModuleCode (
75     ACPI_PARSE_OBJECT       *ParentOp,
76     UINT8                   *AmlStart,
77     UINT32                  AmlLength,
78     ACPI_OWNER_ID           OwnerId);
79 
80 
81 /*******************************************************************************
82  *
83  * FUNCTION:    AcpiPsGetArguments
84  *
85  * PARAMETERS:  WalkState           - Current state
86  *              AmlOpStart          - Op start in AML
87  *              Op                  - Current Op
88  *
89  * RETURN:      Status
90  *
91  * DESCRIPTION: Get arguments for passed Op.
92  *
93  ******************************************************************************/
94 
95 static ACPI_STATUS
96 AcpiPsGetArguments (
97     ACPI_WALK_STATE         *WalkState,
98     UINT8                   *AmlOpStart,
99     ACPI_PARSE_OBJECT       *Op)
100 {
101     ACPI_STATUS             Status = AE_OK;
102     ACPI_PARSE_OBJECT       *Arg = NULL;
103     const ACPI_OPCODE_INFO  *OpInfo;
104 
105 
106     ACPI_FUNCTION_TRACE_PTR (PsGetArguments, WalkState);
107 
108 
109     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
110         "Get arguments for opcode [%s]\n", Op->Common.AmlOpName));
111 
112     switch (Op->Common.AmlOpcode)
113     {
114     case AML_BYTE_OP:       /* AML_BYTEDATA_ARG */
115     case AML_WORD_OP:       /* AML_WORDDATA_ARG */
116     case AML_DWORD_OP:      /* AML_DWORDATA_ARG */
117     case AML_QWORD_OP:      /* AML_QWORDATA_ARG */
118     case AML_STRING_OP:     /* AML_ASCIICHARLIST_ARG */
119 
120         /* Fill in constant or string argument directly */
121 
122         AcpiPsGetNextSimpleArg (&(WalkState->ParserState),
123             GET_CURRENT_ARG_TYPE (WalkState->ArgTypes), Op);
124         break;
125 
126     case AML_INT_NAMEPATH_OP:   /* AML_NAMESTRING_ARG */
127 
128         Status = AcpiPsGetNextNamepath (WalkState,
129             &(WalkState->ParserState), Op, ACPI_POSSIBLE_METHOD_CALL);
130         if (ACPI_FAILURE (Status))
131         {
132             return_ACPI_STATUS (Status);
133         }
134 
135         WalkState->ArgTypes = 0;
136         break;
137 
138     default:
139         /*
140          * Op is not a constant or string, append each argument to the Op
141          */
142         while (GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) &&
143             !WalkState->ArgCount)
144         {
145             WalkState->Aml = WalkState->ParserState.Aml;
146 
147             switch (Op->Common.AmlOpcode)
148             {
149             case AML_METHOD_OP:
150             case AML_BUFFER_OP:
151             case AML_PACKAGE_OP:
152             case AML_VARIABLE_PACKAGE_OP:
153             case AML_WHILE_OP:
154 
155                 break;
156 
157             default:
158 
159                 ASL_CV_CAPTURE_COMMENTS (WalkState);
160                 break;
161             }
162 
163             Status = AcpiPsGetNextArg (WalkState, &(WalkState->ParserState),
164                 GET_CURRENT_ARG_TYPE (WalkState->ArgTypes), &Arg);
165             if (ACPI_FAILURE (Status))
166             {
167                 return_ACPI_STATUS (Status);
168             }
169 
170             if (Arg)
171             {
172                 AcpiPsAppendArg (Op, Arg);
173             }
174 
175             INCREMENT_ARG_LIST (WalkState->ArgTypes);
176         }
177 
178         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
179             "Final argument count: %8.8X pass %u\n",
180             WalkState->ArgCount, WalkState->PassNumber));
181 
182         /*
183          * This case handles the legacy option that groups all module-level
184          * code blocks together and defers execution until all of the tables
185          * are loaded. Execute all of these blocks at this time.
186          * Execute any module-level code that was detected during the table
187          * load phase.
188          *
189          * Note: this option is deprecated and will be eliminated in the
190          * future. Use of this option can cause problems with AML code that
191          * depends upon in-order immediate execution of module-level code.
192          */
193         if (AcpiGbl_GroupModuleLevelCode &&
194             (WalkState->PassNumber <= ACPI_IMODE_LOAD_PASS2) &&
195             ((WalkState->ParseFlags & ACPI_PARSE_DISASSEMBLE) == 0))
196         {
197             /*
198              * We want to skip If/Else/While constructs during Pass1 because we
199              * want to actually conditionally execute the code during Pass2.
200              *
201              * Except for disassembly, where we always want to walk the
202              * If/Else/While packages
203              */
204             switch (Op->Common.AmlOpcode)
205             {
206             case AML_IF_OP:
207             case AML_ELSE_OP:
208             case AML_WHILE_OP:
209                 /*
210                  * Currently supported module-level opcodes are:
211                  * IF/ELSE/WHILE. These appear to be the most common,
212                  * and easiest to support since they open an AML
213                  * package.
214                  */
215                 if (WalkState->PassNumber == ACPI_IMODE_LOAD_PASS1)
216                 {
217                     AcpiPsLinkModuleCode (Op->Common.Parent, AmlOpStart,
218                         (UINT32) (WalkState->ParserState.PkgEnd - AmlOpStart),
219                         WalkState->OwnerId);
220                 }
221 
222                 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
223                     "Pass1: Skipping an If/Else/While body\n"));
224 
225                 /* Skip body of if/else/while in pass 1 */
226 
227                 WalkState->ParserState.Aml = WalkState->ParserState.PkgEnd;
228                 WalkState->ArgCount = 0;
229                 break;
230 
231             default:
232                 /*
233                  * Check for an unsupported executable opcode at module
234                  * level. We must be in PASS1, the parent must be a SCOPE,
235                  * The opcode class must be EXECUTE, and the opcode must
236                  * not be an argument to another opcode.
237                  */
238                 if ((WalkState->PassNumber == ACPI_IMODE_LOAD_PASS1) &&
239                     (Op->Common.Parent->Common.AmlOpcode == AML_SCOPE_OP))
240                 {
241                     OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
242                     if ((OpInfo->Class == AML_CLASS_EXECUTE) &&
243                         (!Arg))
244                     {
245                         ACPI_WARNING ((AE_INFO,
246                             "Unsupported module-level executable opcode "
247                             "0x%.2X at table offset 0x%.4X",
248                             Op->Common.AmlOpcode,
249                             (UINT32) (ACPI_PTR_DIFF (AmlOpStart,
250                                 WalkState->ParserState.AmlStart) +
251                                 sizeof (ACPI_TABLE_HEADER))));
252                     }
253                 }
254                 break;
255             }
256         }
257 
258         /* Special processing for certain opcodes */
259 
260         switch (Op->Common.AmlOpcode)
261         {
262         case AML_METHOD_OP:
263             /*
264              * Skip parsing of control method because we don't have enough
265              * info in the first pass to parse it correctly.
266              *
267              * Save the length and address of the body
268              */
269             Op->Named.Data = WalkState->ParserState.Aml;
270             Op->Named.Length = (UINT32)
271                 (WalkState->ParserState.PkgEnd - WalkState->ParserState.Aml);
272 
273             /* Skip body of method */
274 
275             WalkState->ParserState.Aml = WalkState->ParserState.PkgEnd;
276             WalkState->ArgCount = 0;
277             break;
278 
279         case AML_BUFFER_OP:
280         case AML_PACKAGE_OP:
281         case AML_VARIABLE_PACKAGE_OP:
282 
283             if ((Op->Common.Parent) &&
284                 (Op->Common.Parent->Common.AmlOpcode == AML_NAME_OP) &&
285                 (WalkState->PassNumber <= ACPI_IMODE_LOAD_PASS2))
286             {
287                 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
288                     "Setup Package/Buffer: Pass %u, AML Ptr: %p\n",
289                     WalkState->PassNumber, AmlOpStart));
290 
291                 /*
292                  * Skip parsing of Buffers and Packages because we don't have
293                  * enough info in the first pass to parse them correctly.
294                  */
295                 Op->Named.Data = AmlOpStart;
296                 Op->Named.Length = (UINT32)
297                     (WalkState->ParserState.PkgEnd - AmlOpStart);
298 
299                 /* Skip body */
300 
301                 WalkState->ParserState.Aml = WalkState->ParserState.PkgEnd;
302                 WalkState->ArgCount = 0;
303             }
304             break;
305 
306         case AML_WHILE_OP:
307 
308             if (WalkState->ControlState)
309             {
310                 WalkState->ControlState->Control.PackageEnd =
311                     WalkState->ParserState.PkgEnd;
312             }
313             break;
314 
315         default:
316 
317             /* No action for all other opcodes */
318 
319             break;
320         }
321 
322         break;
323     }
324 
325     return_ACPI_STATUS (AE_OK);
326 }
327 
328 
329 /*******************************************************************************
330  *
331  * FUNCTION:    AcpiPsLinkModuleCode
332  *
333  * PARAMETERS:  ParentOp            - Parent parser op
334  *              AmlStart            - Pointer to the AML
335  *              AmlLength           - Length of executable AML
336  *              OwnerId             - OwnerId of module level code
337  *
338  * RETURN:      None.
339  *
340  * DESCRIPTION: Wrap the module-level code with a method object and link the
341  *              object to the global list. Note, the mutex field of the method
342  *              object is used to link multiple module-level code objects.
343  *
344  * NOTE: In this legacy option, each block of detected executable AML
345  * code that is outside of any control method is wrapped with a temporary
346  * control method object and placed on a global list below.
347  *
348  * This function executes the module-level code for all tables only after
349  * all of the tables have been loaded. It is a legacy option and is
350  * not compatible with other ACPI implementations. See AcpiNsLoadTable.
351  *
352  * This function will be removed when the legacy option is removed.
353  *
354  ******************************************************************************/
355 
356 static void
357 AcpiPsLinkModuleCode (
358     ACPI_PARSE_OBJECT       *ParentOp,
359     UINT8                   *AmlStart,
360     UINT32                  AmlLength,
361     ACPI_OWNER_ID           OwnerId)
362 {
363     ACPI_OPERAND_OBJECT     *Prev;
364     ACPI_OPERAND_OBJECT     *Next;
365     ACPI_OPERAND_OBJECT     *MethodObj;
366     ACPI_NAMESPACE_NODE     *ParentNode;
367 
368 
369     ACPI_FUNCTION_TRACE (PsLinkModuleCode);
370 
371 
372     /* Get the tail of the list */
373 
374     Prev = Next = AcpiGbl_ModuleCodeList;
375     while (Next)
376     {
377         Prev = Next;
378         Next = Next->Method.Mutex;
379     }
380 
381     /*
382      * Insert the module level code into the list. Merge it if it is
383      * adjacent to the previous element.
384      */
385     if (!Prev ||
386        ((Prev->Method.AmlStart + Prev->Method.AmlLength) != AmlStart))
387     {
388         /* Create, initialize, and link a new temporary method object */
389 
390         MethodObj = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);
391         if (!MethodObj)
392         {
393             return_VOID;
394         }
395 
396         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
397             "Create/Link new code block: %p\n", MethodObj));
398 
399         if (ParentOp->Common.Node)
400         {
401             ParentNode = ParentOp->Common.Node;
402         }
403         else
404         {
405             ParentNode = AcpiGbl_RootNode;
406         }
407 
408         MethodObj->Method.AmlStart = AmlStart;
409         MethodObj->Method.AmlLength = AmlLength;
410         MethodObj->Method.OwnerId = OwnerId;
411         MethodObj->Method.InfoFlags |= ACPI_METHOD_MODULE_LEVEL;
412 
413         /*
414          * Save the parent node in NextObject. This is cheating, but we
415          * don't want to expand the method object.
416          */
417         MethodObj->Method.NextObject =
418             ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, ParentNode);
419 
420         if (!Prev)
421         {
422             AcpiGbl_ModuleCodeList = MethodObj;
423         }
424         else
425         {
426             Prev->Method.Mutex = MethodObj;
427         }
428     }
429     else
430     {
431         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
432             "Appending to existing code block: %p\n", Prev));
433 
434         Prev->Method.AmlLength += AmlLength;
435     }
436 
437     return_VOID;
438 }
439 
440 /*******************************************************************************
441  *
442  * FUNCTION:    AcpiPsParseLoop
443  *
444  * PARAMETERS:  WalkState           - Current state
445  *
446  * RETURN:      Status
447  *
448  * DESCRIPTION: Parse AML (pointed to by the current parser state) and return
449  *              a tree of ops.
450  *
451  ******************************************************************************/
452 
453 ACPI_STATUS
454 AcpiPsParseLoop (
455     ACPI_WALK_STATE         *WalkState)
456 {
457     ACPI_STATUS             Status = AE_OK;
458     ACPI_PARSE_OBJECT       *Op = NULL;     /* current op */
459     ACPI_PARSE_STATE        *ParserState;
460     UINT8                   *AmlOpStart = NULL;
461 
462 
463     ACPI_FUNCTION_TRACE_PTR (PsParseLoop, WalkState);
464 
465 
466     if (WalkState->DescendingCallback == NULL)
467     {
468         return_ACPI_STATUS (AE_BAD_PARAMETER);
469     }
470 
471     ParserState = &WalkState->ParserState;
472     WalkState->ArgTypes = 0;
473 
474 #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
475 
476     if (WalkState->WalkType & ACPI_WALK_METHOD_RESTART)
477     {
478         /* We are restarting a preempted control method */
479 
480         if (AcpiPsHasCompletedScope (ParserState))
481         {
482             /*
483              * We must check if a predicate to an IF or WHILE statement
484              * was just completed
485              */
486             if ((ParserState->Scope->ParseScope.Op) &&
487                ((ParserState->Scope->ParseScope.Op->Common.AmlOpcode == AML_IF_OP) ||
488                 (ParserState->Scope->ParseScope.Op->Common.AmlOpcode == AML_WHILE_OP)) &&
489                 (WalkState->ControlState) &&
490                 (WalkState->ControlState->Common.State ==
491                     ACPI_CONTROL_PREDICATE_EXECUTING))
492             {
493                 /*
494                  * A predicate was just completed, get the value of the
495                  * predicate and branch based on that value
496                  */
497                 WalkState->Op = NULL;
498                 Status = AcpiDsGetPredicateValue (WalkState, ACPI_TO_POINTER (TRUE));
499                 if (ACPI_FAILURE (Status) &&
500                     ((Status & AE_CODE_MASK) != AE_CODE_CONTROL))
501                 {
502                     if (Status == AE_AML_NO_RETURN_VALUE)
503                     {
504                         ACPI_EXCEPTION ((AE_INFO, Status,
505                             "Invoked method did not return a value"));
506                     }
507 
508                     ACPI_EXCEPTION ((AE_INFO, Status, "GetPredicate Failed"));
509                     return_ACPI_STATUS (Status);
510                 }
511 
512                 Status = AcpiPsNextParseState (WalkState, Op, Status);
513             }
514 
515             AcpiPsPopScope (ParserState, &Op,
516                 &WalkState->ArgTypes, &WalkState->ArgCount);
517             ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Popped scope, Op=%p\n", Op));
518         }
519         else if (WalkState->PrevOp)
520         {
521             /* We were in the middle of an op */
522 
523             Op = WalkState->PrevOp;
524             WalkState->ArgTypes = WalkState->PrevArgTypes;
525         }
526     }
527 #endif
528 
529     /* Iterative parsing loop, while there is more AML to process: */
530 
531     while ((ParserState->Aml < ParserState->AmlEnd) || (Op))
532     {
533         ASL_CV_CAPTURE_COMMENTS (WalkState);
534 
535         AmlOpStart = ParserState->Aml;
536         if (!Op)
537         {
538             Status = AcpiPsCreateOp (WalkState, AmlOpStart, &Op);
539             if (ACPI_FAILURE (Status))
540             {
541                 /*
542                  * ACPI_PARSE_MODULE_LEVEL means that we are loading a table by
543                  * executing it as a control method. However, if we encounter
544                  * an error while loading the table, we need to keep trying to
545                  * load the table rather than aborting the table load. Set the
546                  * status to AE_OK to proceed with the table load.
547                  */
548                 if ((WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL) &&
549                     Status == AE_ALREADY_EXISTS)
550                 {
551                     Status = AE_OK;
552                 }
553                 if (Status == AE_CTRL_PARSE_CONTINUE)
554                 {
555                     continue;
556                 }
557 
558                 if (Status == AE_CTRL_PARSE_PENDING)
559                 {
560                     Status = AE_OK;
561                 }
562 
563                 if (Status == AE_CTRL_TERMINATE)
564                 {
565                     return_ACPI_STATUS (Status);
566                 }
567 
568                 Status = AcpiPsCompleteOp (WalkState, &Op, Status);
569                 if (ACPI_FAILURE (Status))
570                 {
571                     return_ACPI_STATUS (Status);
572                 }
573                 if (AcpiNsOpensScope (
574                     AcpiPsGetOpcodeInfo (WalkState->Opcode)->ObjectType))
575                 {
576                     /*
577                      * If the scope/device op fails to parse, skip the body of
578                      * the scope op because the parse failure indicates that
579                      * the device may not exist.
580                      */
581                     ACPI_ERROR ((AE_INFO, "Skip parsing opcode %s",
582                         AcpiPsGetOpcodeName (WalkState->Opcode)));
583                     WalkState->ParserState.Aml = WalkState->Aml + 1;
584                     WalkState->ParserState.Aml =
585                         AcpiPsGetNextPackageEnd(&WalkState->ParserState);
586                     WalkState->Aml = WalkState->ParserState.Aml;
587                 }
588 
589                 continue;
590             }
591 
592             AcpiExStartTraceOpcode (Op, WalkState);
593         }
594 
595         /*
596          * Start ArgCount at zero because we don't know if there are
597          * any args yet
598          */
599         WalkState->ArgCount = 0;
600 
601         switch (Op->Common.AmlOpcode)
602         {
603         case AML_BYTE_OP:
604         case AML_WORD_OP:
605         case AML_DWORD_OP:
606         case AML_QWORD_OP:
607 
608             break;
609 
610         default:
611 
612             ASL_CV_CAPTURE_COMMENTS (WalkState);
613             break;
614         }
615 
616         /* Are there any arguments that must be processed? */
617 
618         if (WalkState->ArgTypes)
619         {
620             /* Get arguments */
621 
622             Status = AcpiPsGetArguments (WalkState, AmlOpStart, Op);
623             if (ACPI_FAILURE (Status))
624             {
625                 Status = AcpiPsCompleteOp (WalkState, &Op, Status);
626                 if (ACPI_FAILURE (Status))
627                 {
628                     return_ACPI_STATUS (Status);
629                 }
630                 if ((WalkState->ControlState) &&
631                     ((WalkState->ControlState->Control.Opcode == AML_IF_OP) ||
632                     (WalkState->ControlState->Control.Opcode == AML_WHILE_OP)))
633                 {
634                     /*
635                      * If the if/while op fails to parse, we will skip parsing
636                      * the body of the op.
637                      */
638                     ParserState->Aml =
639                         WalkState->ControlState->Control.AmlPredicateStart + 1;
640                     ParserState->Aml =
641                         AcpiPsGetNextPackageEnd (ParserState);
642                     WalkState->Aml = ParserState->Aml;
643 
644                     ACPI_ERROR ((AE_INFO, "Skipping While/If block"));
645                     if (*WalkState->Aml == AML_ELSE_OP)
646                     {
647                         ACPI_ERROR ((AE_INFO, "Skipping Else block"));
648                         WalkState->ParserState.Aml = WalkState->Aml + 1;
649                         WalkState->ParserState.Aml =
650                             AcpiPsGetNextPackageEnd (ParserState);
651                         WalkState->Aml = ParserState->Aml;
652                     }
653                     ACPI_FREE(AcpiUtPopGenericState (&WalkState->ControlState));
654                 }
655                 Op = NULL;
656                 continue;
657             }
658         }
659 
660         /* Check for arguments that need to be processed */
661 
662         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
663             "Parseloop: argument count: %8.8X\n", WalkState->ArgCount));
664 
665         if (WalkState->ArgCount)
666         {
667             /*
668              * There are arguments (complex ones), push Op and
669              * prepare for argument
670              */
671             Status = AcpiPsPushScope (ParserState, Op,
672                 WalkState->ArgTypes, WalkState->ArgCount);
673             if (ACPI_FAILURE (Status))
674             {
675                 Status = AcpiPsCompleteOp (WalkState, &Op, Status);
676                 if (ACPI_FAILURE (Status))
677                 {
678                     return_ACPI_STATUS (Status);
679                 }
680 
681                 continue;
682             }
683 
684             Op = NULL;
685             continue;
686         }
687 
688         /*
689          * All arguments have been processed -- Op is complete,
690          * prepare for next
691          */
692         WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
693         if (WalkState->OpInfo->Flags & AML_NAMED)
694         {
695             if (Op->Common.AmlOpcode == AML_REGION_OP ||
696                 Op->Common.AmlOpcode == AML_DATA_REGION_OP)
697             {
698                 /*
699                  * Skip parsing of control method or opregion body,
700                  * because we don't have enough info in the first pass
701                  * to parse them correctly.
702                  *
703                  * Completed parsing an OpRegion declaration, we now
704                  * know the length.
705                  */
706                 Op->Named.Length = (UINT32) (ParserState->Aml - Op->Named.Data);
707             }
708         }
709 
710         if (WalkState->OpInfo->Flags & AML_CREATE)
711         {
712             /*
713              * Backup to beginning of CreateXXXfield declaration (1 for
714              * Opcode)
715              *
716              * BodyLength is unknown until we parse the body
717              */
718             Op->Named.Length = (UINT32) (ParserState->Aml - Op->Named.Data);
719         }
720 
721         if (Op->Common.AmlOpcode == AML_BANK_FIELD_OP)
722         {
723             /*
724              * Backup to beginning of BankField declaration
725              *
726              * BodyLength is unknown until we parse the body
727              */
728             Op->Named.Length = (UINT32) (ParserState->Aml - Op->Named.Data);
729         }
730 
731         /* This op complete, notify the dispatcher */
732 
733         if (WalkState->AscendingCallback != NULL)
734         {
735             WalkState->Op = Op;
736             WalkState->Opcode = Op->Common.AmlOpcode;
737 
738             Status = WalkState->AscendingCallback (WalkState);
739             Status = AcpiPsNextParseState (WalkState, Op, Status);
740             if (Status == AE_CTRL_PENDING)
741             {
742                 Status = AE_OK;
743             }
744             else if ((WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL) &&
745                 (ACPI_AML_EXCEPTION(Status) || Status == AE_ALREADY_EXISTS ||
746                 Status == AE_NOT_FOUND))
747             {
748                 /*
749                  * ACPI_PARSE_MODULE_LEVEL flag means that we are currently
750                  * loading a table by executing it as a control method.
751                  * However, if we encounter an error while loading the table,
752                  * we need to keep trying to load the table rather than
753                  * aborting the table load (setting the status to AE_OK
754                  * continues the table load). If we get a failure at this
755                  * point, it means that the dispatcher got an error while
756                  * trying to execute the Op.
757                  */
758                 Status = AE_OK;
759             }
760         }
761 
762         Status = AcpiPsCompleteOp (WalkState, &Op, Status);
763         if (ACPI_FAILURE (Status))
764         {
765             return_ACPI_STATUS (Status);
766         }
767 
768     } /* while ParserState->Aml */
769 
770     Status = AcpiPsCompleteFinalOp (WalkState, Op, Status);
771     return_ACPI_STATUS (Status);
772 }
773