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