]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/dev/acpica/psparse.c
This commit was generated by cvs2svn to compensate for changes in r159952,
[FreeBSD/FreeBSD.git] / sys / contrib / dev / acpica / psparse.c
1 /******************************************************************************
2  *
3  * Module Name: psparse - Parser top level AML parse routines
4  *              $Revision: 146 $
5  *
6  *****************************************************************************/
7
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
13  * All rights reserved.
14  *
15  * 2. License
16  *
17  * 2.1. This is your license from Intel Corp. under its intellectual property
18  * rights.  You may have additional license terms from the party that provided
19  * you this software, covering your right to use that party's intellectual
20  * property rights.
21  *
22  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23  * copy of the source code appearing in this file ("Covered Code") an
24  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25  * base code distributed originally by Intel ("Original Intel Code") to copy,
26  * make derivatives, distribute, use and display any portion of the Covered
27  * Code in any form, with the right to sublicense such rights; and
28  *
29  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30  * license (with the right to sublicense), under only those claims of Intel
31  * patents that are infringed by the Original Intel Code, to make, use, sell,
32  * offer to sell, and import the Covered Code and derivative works thereof
33  * solely to the minimum extent necessary to exercise the above copyright
34  * license, and in no event shall the patent license extend to any additions
35  * to or modifications of the Original Intel Code.  No other license or right
36  * is granted directly or by implication, estoppel or otherwise;
37  *
38  * The above copyright and patent license is granted only if the following
39  * conditions are met:
40  *
41  * 3. Conditions
42  *
43  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44  * Redistribution of source code of any substantial portion of the Covered
45  * Code or modification with rights to further distribute source must include
46  * the above Copyright Notice, the above License, this list of Conditions,
47  * and the following Disclaimer and Export Compliance provision.  In addition,
48  * Licensee must cause all Covered Code to which Licensee contributes to
49  * contain a file documenting the changes Licensee made to create that Covered
50  * Code and the date of any change.  Licensee must include in that file the
51  * documentation of any changes made by any predecessor Licensee.  Licensee
52  * must include a prominent statement that the modification is derived,
53  * directly or indirectly, from Original Intel Code.
54  *
55  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56  * Redistribution of source code of any substantial portion of the Covered
57  * Code or modification without rights to further distribute source must
58  * include the following Disclaimer and Export Compliance provision in the
59  * documentation and/or other materials provided with distribution.  In
60  * addition, Licensee may not authorize further sublicense of source of any
61  * portion of the Covered Code, and must include terms to the effect that the
62  * license from Licensee to its licensee is limited to the intellectual
63  * property embodied in the software Licensee provides to its licensee, and
64  * not to intellectual property embodied in modifications its licensee may
65  * make.
66  *
67  * 3.3. Redistribution of Executable. Redistribution in executable form of any
68  * substantial portion of the Covered Code or modification must reproduce the
69  * above Copyright Notice, and the following Disclaimer and Export Compliance
70  * provision in the documentation and/or other materials provided with the
71  * distribution.
72  *
73  * 3.4. Intel retains all right, title, and interest in and to the Original
74  * Intel Code.
75  *
76  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77  * Intel shall be used in advertising or otherwise to promote the sale, use or
78  * other dealings in products derived from or relating to the Covered Code
79  * without prior written authorization from Intel.
80  *
81  * 4. Disclaimer and Export Compliance
82  *
83  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89  * PARTICULAR PURPOSE.
90  *
91  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98  * LIMITED REMEDY.
99  *
100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
101  * software or system incorporating such software without first obtaining any
102  * required license or other approval from the U. S. Department of Commerce or
103  * any other agency or department of the United States Government.  In the
104  * event Licensee exports any such software from the United States or
105  * re-exports any such software from a foreign destination, Licensee shall
106  * ensure that the distribution and export/re-export of the software is in
107  * compliance with all laws, regulations, orders, or other restrictions of the
108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109  * any of its subsidiaries will export/re-export any technical data, process,
110  * software, or service, directly or indirectly, to any country for which the
111  * United States government or any agency thereof requires an export license,
112  * other governmental approval, or letter of assurance, without first obtaining
113  * such license, approval or letter.
114  *
115  *****************************************************************************/
116
117
118 /*
119  * Parse the AML and build an operation tree as most interpreters,
120  * like Perl, do.  Parsing is done by hand rather than with a YACC
121  * generated parser to tightly constrain stack and dynamic memory
122  * usage.  At the same time, parsing is kept flexible and the code
123  * fairly compact by parsing based on a list of AML opcode
124  * templates in AmlOpInfo[]
125  */
126
127 #include <contrib/dev/acpica/acpi.h>
128 #include <contrib/dev/acpica/acparser.h>
129 #include <contrib/dev/acpica/acdispat.h>
130 #include <contrib/dev/acpica/amlcode.h>
131 #include <contrib/dev/acpica/acnamesp.h>
132 #include <contrib/dev/acpica/acinterp.h>
133
134 #define _COMPONENT          ACPI_PARSER
135         ACPI_MODULE_NAME    ("psparse")
136
137
138 /*******************************************************************************
139  *
140  * FUNCTION:    AcpiPsGetOpcodeSize
141  *
142  * PARAMETERS:  Opcode          - An AML opcode
143  *
144  * RETURN:      Size of the opcode, in bytes (1 or 2)
145  *
146  * DESCRIPTION: Get the size of the current opcode.
147  *
148  ******************************************************************************/
149
150 UINT32
151 AcpiPsGetOpcodeSize (
152     UINT32                  Opcode)
153 {
154
155     /* Extended (2-byte) opcode if > 255 */
156
157     if (Opcode > 0x00FF)
158     {
159         return (2);
160     }
161
162     /* Otherwise, just a single byte opcode */
163
164     return (1);
165 }
166
167
168 /*******************************************************************************
169  *
170  * FUNCTION:    AcpiPsPeekOpcode
171  *
172  * PARAMETERS:  ParserState         - A parser state object
173  *
174  * RETURN:      Next AML opcode
175  *
176  * DESCRIPTION: Get next AML opcode (without incrementing AML pointer)
177  *
178  ******************************************************************************/
179
180 UINT16
181 AcpiPsPeekOpcode (
182     ACPI_PARSE_STATE        *ParserState)
183 {
184     UINT8                   *Aml;
185     UINT16                  Opcode;
186
187
188     Aml = ParserState->Aml;
189     Opcode = (UINT16) ACPI_GET8 (Aml);
190
191     if (Opcode == AML_EXTENDED_OP_PREFIX)
192     {
193         /* Extended opcode, get the second opcode byte */
194
195         Aml++;
196         Opcode = (UINT16) ((Opcode << 8) | ACPI_GET8 (Aml));
197     }
198
199     return (Opcode);
200 }
201
202
203 /*******************************************************************************
204  *
205  * FUNCTION:    AcpiPsCompleteThisOp
206  *
207  * PARAMETERS:  WalkState       - Current State
208  *              Op              - Op to complete
209  *
210  * RETURN:      Status
211  *
212  * DESCRIPTION: Perform any cleanup at the completion of an Op.
213  *
214  ******************************************************************************/
215
216 ACPI_STATUS
217 AcpiPsCompleteThisOp (
218     ACPI_WALK_STATE         *WalkState,
219     ACPI_PARSE_OBJECT       *Op)
220 {
221     ACPI_PARSE_OBJECT       *Prev;
222     ACPI_PARSE_OBJECT       *Next;
223     const ACPI_OPCODE_INFO  *ParentInfo;
224     ACPI_PARSE_OBJECT       *ReplacementOp = NULL;
225
226
227     ACPI_FUNCTION_TRACE_PTR ("PsCompleteThisOp", Op);
228
229
230     /* Check for null Op, can happen if AML code is corrupt */
231
232     if (!Op)
233     {
234         return_ACPI_STATUS (AE_OK);  /* OK for now */
235     }
236
237     /* Delete this op and the subtree below it if asked to */
238
239     if (((WalkState->ParseFlags & ACPI_PARSE_TREE_MASK) != ACPI_PARSE_DELETE_TREE) ||
240          (WalkState->OpInfo->Class == AML_CLASS_ARGUMENT))
241     {
242         return_ACPI_STATUS (AE_OK);
243     }
244
245     /* Make sure that we only delete this subtree */
246
247     if (Op->Common.Parent)
248     {
249         Prev = Op->Common.Parent->Common.Value.Arg;
250         if (!Prev)
251         {
252             /* Nothing more to do */
253
254             goto Cleanup;
255         }
256
257         /*
258          * Check if we need to replace the operator and its subtree
259          * with a return value op (placeholder op)
260          */
261         ParentInfo = AcpiPsGetOpcodeInfo (Op->Common.Parent->Common.AmlOpcode);
262
263         switch (ParentInfo->Class)
264         {
265         case AML_CLASS_CONTROL:
266             break;
267
268         case AML_CLASS_CREATE:
269
270             /*
271              * These opcodes contain TermArg operands.  The current
272              * op must be replaced by a placeholder return op
273              */
274             ReplacementOp = AcpiPsAllocOp (AML_INT_RETURN_VALUE_OP);
275             if (!ReplacementOp)
276             {
277                 goto AllocateError;
278             }
279             break;
280
281         case AML_CLASS_NAMED_OBJECT:
282
283             /*
284              * These opcodes contain TermArg operands.  The current
285              * op must be replaced by a placeholder return op
286              */
287             if ((Op->Common.Parent->Common.AmlOpcode == AML_REGION_OP)       ||
288                 (Op->Common.Parent->Common.AmlOpcode == AML_DATA_REGION_OP)  ||
289                 (Op->Common.Parent->Common.AmlOpcode == AML_BUFFER_OP)       ||
290                 (Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP)      ||
291                 (Op->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP))
292             {
293                 ReplacementOp = AcpiPsAllocOp (AML_INT_RETURN_VALUE_OP);
294                 if (!ReplacementOp)
295                 {
296                     goto AllocateError;
297                 }
298             }
299             else if ((Op->Common.Parent->Common.AmlOpcode == AML_NAME_OP) &&
300                      (WalkState->PassNumber <= ACPI_IMODE_LOAD_PASS2))
301             {
302                 if ((Op->Common.AmlOpcode == AML_BUFFER_OP) ||
303                     (Op->Common.AmlOpcode == AML_PACKAGE_OP) ||
304                     (Op->Common.AmlOpcode == AML_VAR_PACKAGE_OP))
305                 {
306                     ReplacementOp = AcpiPsAllocOp (Op->Common.AmlOpcode);
307                     if (!ReplacementOp)
308                     {
309                         goto AllocateError;
310                     }
311
312                     ReplacementOp->Named.Data = Op->Named.Data;
313                     ReplacementOp->Named.Length = Op->Named.Length;
314                 }
315             }
316             break;
317
318         default:
319
320             ReplacementOp = AcpiPsAllocOp (AML_INT_RETURN_VALUE_OP);
321             if (!ReplacementOp)
322             {
323                 goto AllocateError;
324             }
325         }
326
327         /* We must unlink this op from the parent tree */
328
329         if (Prev == Op)
330         {
331             /* This op is the first in the list */
332
333             if (ReplacementOp)
334             {
335                 ReplacementOp->Common.Parent        = Op->Common.Parent;
336                 ReplacementOp->Common.Value.Arg     = NULL;
337                 ReplacementOp->Common.Node          = Op->Common.Node;
338                 Op->Common.Parent->Common.Value.Arg = ReplacementOp;
339                 ReplacementOp->Common.Next          = Op->Common.Next;
340             }
341             else
342             {
343                 Op->Common.Parent->Common.Value.Arg = Op->Common.Next;
344             }
345         }
346
347         /* Search the parent list */
348
349         else while (Prev)
350         {
351             /* Traverse all siblings in the parent's argument list */
352
353             Next = Prev->Common.Next;
354             if (Next == Op)
355             {
356                 if (ReplacementOp)
357                 {
358                     ReplacementOp->Common.Parent    = Op->Common.Parent;
359                     ReplacementOp->Common.Value.Arg = NULL;
360                     ReplacementOp->Common.Node      = Op->Common.Node;
361                     Prev->Common.Next               = ReplacementOp;
362                     ReplacementOp->Common.Next      = Op->Common.Next;
363                     Next = NULL;
364                 }
365                 else
366                 {
367                     Prev->Common.Next = Op->Common.Next;
368                     Next = NULL;
369                 }
370             }
371             Prev = Next;
372         }
373     }
374
375
376 Cleanup:
377
378     /* Now we can actually delete the subtree rooted at Op */
379
380     AcpiPsDeleteParseTree (Op);
381     return_ACPI_STATUS (AE_OK);
382
383
384 AllocateError:
385
386     /* Always delete the subtree, even on error */
387
388     AcpiPsDeleteParseTree (Op);
389     return_ACPI_STATUS (AE_NO_MEMORY);
390 }
391
392
393 /*******************************************************************************
394  *
395  * FUNCTION:    AcpiPsNextParseState
396  *
397  * PARAMETERS:  WalkState           - Current state
398  *              Op                  - Current parse op
399  *              CallbackStatus      - Status from previous operation
400  *
401  * RETURN:      Status
402  *
403  * DESCRIPTION: Update the parser state based upon the return exception from
404  *              the parser callback.
405  *
406  ******************************************************************************/
407
408 ACPI_STATUS
409 AcpiPsNextParseState (
410     ACPI_WALK_STATE         *WalkState,
411     ACPI_PARSE_OBJECT       *Op,
412     ACPI_STATUS             CallbackStatus)
413 {
414     ACPI_PARSE_STATE        *ParserState = &WalkState->ParserState;
415     ACPI_STATUS             Status = AE_CTRL_PENDING;
416
417
418     ACPI_FUNCTION_TRACE_PTR ("PsNextParseState", Op);
419
420
421     switch (CallbackStatus)
422     {
423     case AE_CTRL_TERMINATE:
424
425         /*
426          * A control method was terminated via a RETURN statement.
427          * The walk of this method is complete.
428          */
429         ParserState->Aml = ParserState->AmlEnd;
430         Status = AE_CTRL_TERMINATE;
431         break;
432
433
434     case AE_CTRL_BREAK:
435
436         ParserState->Aml = WalkState->AmlLastWhile;
437         WalkState->ControlState->Common.Value = FALSE;
438         Status = AE_CTRL_BREAK;
439         break;
440
441     case AE_CTRL_CONTINUE:
442
443
444         ParserState->Aml = WalkState->AmlLastWhile;
445         Status = AE_CTRL_CONTINUE;
446         break;
447
448     case AE_CTRL_PENDING:
449
450         ParserState->Aml = WalkState->AmlLastWhile;
451         break;
452
453 #if 0
454     case AE_CTRL_SKIP:
455
456         ParserState->Aml = ParserState->Scope->ParseScope.PkgEnd;
457         Status = AE_OK;
458         break;
459 #endif
460
461     case AE_CTRL_TRUE:
462
463         /*
464          * Predicate of an IF was true, and we are at the matching ELSE.
465          * Just close out this package
466          */
467         ParserState->Aml = AcpiPsGetNextPackageEnd (ParserState);
468         break;
469
470
471     case AE_CTRL_FALSE:
472
473         /*
474          * Either an IF/WHILE Predicate was false or we encountered a BREAK
475          * opcode.  In both cases, we do not execute the rest of the
476          * package;  We simply close out the parent (finishing the walk of
477          * this branch of the tree) and continue execution at the parent
478          * level.
479          */
480         ParserState->Aml = ParserState->Scope->ParseScope.PkgEnd;
481
482         /* In the case of a BREAK, just force a predicate (if any) to FALSE */
483
484         WalkState->ControlState->Common.Value = FALSE;
485         Status = AE_CTRL_END;
486         break;
487
488
489     case AE_CTRL_TRANSFER:
490
491         /* A method call (invocation) -- transfer control */
492
493         Status = AE_CTRL_TRANSFER;
494         WalkState->PrevOp = Op;
495         WalkState->MethodCallOp = Op;
496         WalkState->MethodCallNode = (Op->Common.Value.Arg)->Common.Node;
497
498         /* Will return value (if any) be used by the caller? */
499
500         WalkState->ReturnUsed = AcpiDsIsResultUsed (Op, WalkState);
501         break;
502
503
504     default:
505
506         Status = CallbackStatus;
507         if ((CallbackStatus & AE_CODE_MASK) == AE_CODE_CONTROL)
508         {
509             Status = AE_OK;
510         }
511         break;
512     }
513
514     return_ACPI_STATUS (Status);
515 }
516
517
518 /*******************************************************************************
519  *
520  * FUNCTION:    AcpiPsParseAml
521  *
522  * PARAMETERS:  WalkState       - Current state
523  *
524  *
525  * RETURN:      Status
526  *
527  * DESCRIPTION: Parse raw AML and return a tree of ops
528  *
529  ******************************************************************************/
530
531 ACPI_STATUS
532 AcpiPsParseAml (
533     ACPI_WALK_STATE         *WalkState)
534 {
535     ACPI_STATUS             Status;
536     ACPI_THREAD_STATE       *Thread;
537     ACPI_THREAD_STATE       *PrevWalkList = AcpiGbl_CurrentWalkList;
538     ACPI_WALK_STATE         *PreviousWalkState;
539
540
541     ACPI_FUNCTION_TRACE ("PsParseAml");
542
543     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
544         "Entered with WalkState=%p Aml=%p size=%X\n",
545         WalkState, WalkState->ParserState.Aml,
546         WalkState->ParserState.AmlSize));
547
548
549     /* Create and initialize a new thread state */
550
551     Thread = AcpiUtCreateThreadState ();
552     if (!Thread)
553     {
554         return_ACPI_STATUS (AE_NO_MEMORY);
555     }
556
557     WalkState->Thread = Thread;
558     AcpiDsPushWalkState (WalkState, Thread);
559
560     /*
561      * This global allows the AML debugger to get a handle to the currently
562      * executing control method.
563      */
564     AcpiGbl_CurrentWalkList = Thread;
565
566     /*
567      * Execute the walk loop as long as there is a valid Walk State.  This
568      * handles nested control method invocations without recursion.
569      */
570     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "State=%p\n", WalkState));
571
572     Status = AE_OK;
573     while (WalkState)
574     {
575         if (ACPI_SUCCESS (Status))
576         {
577             /*
578              * The ParseLoop executes AML until the method terminates
579              * or calls another method.
580              */
581             Status = AcpiPsParseLoop (WalkState);
582         }
583
584         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
585             "Completed one call to walk loop, %s State=%p\n",
586             AcpiFormatException (Status), WalkState));
587
588         if (Status == AE_CTRL_TRANSFER)
589         {
590             /*
591              * A method call was detected.
592              * Transfer control to the called control method
593              */
594             Status = AcpiDsCallControlMethod (Thread, WalkState, NULL);
595
596             /*
597              * If the transfer to the new method method call worked, a new walk
598              * state was created -- get it
599              */
600             WalkState = AcpiDsGetCurrentWalkState (Thread);
601             continue;
602         }
603         else if (Status == AE_CTRL_TERMINATE)
604         {
605             Status = AE_OK;
606         }
607         else if ((Status != AE_OK) && (WalkState->MethodDesc))
608         {
609             ACPI_REPORT_METHOD_ERROR ("Method execution failed",
610                 WalkState->MethodNode, NULL, Status);
611
612             /* Ensure proper cleanup */
613
614             WalkState->ParseFlags |= ACPI_PARSE_EXECUTE;
615
616             /* Check for possible multi-thread reentrancy problem */
617
618             if ((Status == AE_ALREADY_EXISTS) &&
619                 (!WalkState->MethodDesc->Method.Semaphore))
620             {
621                 /*
622                  * This method is marked NotSerialized, but it tried to create
623                  * a named object, causing the second thread entrance to fail.
624                  * We will workaround this by marking the method permanently
625                  * as Serialized.
626                  */
627                 WalkState->MethodDesc->Method.MethodFlags |= AML_METHOD_SERIALIZED;
628                 WalkState->MethodDesc->Method.Concurrency = 1;
629             }
630         }
631
632         /* We are done with this walk, move on to the parent if any */
633
634         WalkState = AcpiDsPopWalkState (Thread);
635
636         /* Reset the current scope to the beginning of scope stack */
637
638         AcpiDsScopeStackClear (WalkState);
639
640         /*
641          * If we just returned from the execution of a control method,
642          * there's lots of cleanup to do
643          */
644         if ((WalkState->ParseFlags & ACPI_PARSE_MODE_MASK) == ACPI_PARSE_EXECUTE)
645         {
646             if (WalkState->MethodDesc)
647             {
648                 /* Decrement the thread count on the method parse tree */
649
650                 WalkState->MethodDesc->Method.ThreadCount--;
651             }
652
653             AcpiDsTerminateControlMethod (WalkState);
654         }
655
656         /* Delete this walk state and all linked control states */
657
658         AcpiPsCleanupScope (&WalkState->ParserState);
659
660         PreviousWalkState = WalkState;
661
662         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
663             "ReturnValue=%p, ImplicitValue=%p State=%p\n",
664             WalkState->ReturnDesc, WalkState->ImplicitReturnObj, WalkState));
665
666         /* Check if we have restarted a preempted walk */
667
668         WalkState = AcpiDsGetCurrentWalkState (Thread);
669         if (WalkState)
670         {
671             if (ACPI_SUCCESS (Status))
672             {
673                 /*
674                  * There is another walk state, restart it.
675                  * If the method return value is not used by the parent,
676                  * The object is deleted
677                  */
678                 if (!PreviousWalkState->ReturnDesc)
679                 {
680                     Status = AcpiDsRestartControlMethod (WalkState,
681                                 PreviousWalkState->ImplicitReturnObj);
682                 }
683                 else
684                 {
685                     /*
686                      * We have a valid return value, delete any implicit
687                      * return value.
688                      */
689                     AcpiDsClearImplicitReturn (PreviousWalkState);
690
691                     Status = AcpiDsRestartControlMethod (WalkState,
692                                 PreviousWalkState->ReturnDesc);
693                 }
694                 if (ACPI_SUCCESS (Status))
695                 {
696                     WalkState->WalkType |= ACPI_WALK_METHOD_RESTART;
697                 }
698             }
699             else
700             {
701                 /* On error, delete any return object */
702
703                 AcpiUtRemoveReference (PreviousWalkState->ReturnDesc);
704             }
705         }
706
707         /*
708          * Just completed a 1st-level method, save the final internal return
709          * value (if any)
710          */
711         else if (PreviousWalkState->CallerReturnDesc)
712         {
713             if (PreviousWalkState->ImplicitReturnObj)
714             {
715                 *(PreviousWalkState->CallerReturnDesc) =
716                     PreviousWalkState->ImplicitReturnObj;
717             }
718             else
719             {
720                  /* NULL if no return value */
721
722                 *(PreviousWalkState->CallerReturnDesc) =
723                     PreviousWalkState->ReturnDesc;
724             }
725         }
726         else
727         {
728             if (PreviousWalkState->ReturnDesc)
729             {
730                 /* Caller doesn't want it, must delete it */
731
732                 AcpiUtRemoveReference (PreviousWalkState->ReturnDesc);
733             }
734             if (PreviousWalkState->ImplicitReturnObj)
735             {
736                 /* Caller doesn't want it, must delete it */
737
738                 AcpiUtRemoveReference (PreviousWalkState->ImplicitReturnObj);
739             }
740         }
741
742         AcpiDsDeleteWalkState (PreviousWalkState);
743     }
744
745     /* Normal exit */
746
747     AcpiExReleaseAllMutexes (Thread);
748     AcpiUtDeleteGenericState (ACPI_CAST_PTR (ACPI_GENERIC_STATE, Thread));
749     AcpiGbl_CurrentWalkList = PrevWalkList;
750     return_ACPI_STATUS (Status);
751 }
752
753