]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/contrib/dev/acpica/psparse.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / contrib / dev / acpica / psparse.c
1 /******************************************************************************
2  *
3  * Module Name: psparse - Parser top level AML parse routines
4  *              $Revision: 1.171 $
5  *
6  *****************************************************************************/
7
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2007, 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          * A control method was terminated via a RETURN statement.
426          * The walk of this method is complete.
427          */
428         ParserState->Aml = ParserState->AmlEnd;
429         Status = AE_CTRL_TERMINATE;
430         break;
431
432
433     case AE_CTRL_BREAK:
434
435         ParserState->Aml = WalkState->AmlLastWhile;
436         WalkState->ControlState->Common.Value = FALSE;
437         Status = AE_CTRL_BREAK;
438         break;
439
440
441     case AE_CTRL_CONTINUE:
442
443         ParserState->Aml = WalkState->AmlLastWhile;
444         Status = AE_CTRL_CONTINUE;
445         break;
446
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          * Predicate of an IF was true, and we are at the matching ELSE.
464          * Just close out this package
465          */
466         ParserState->Aml = AcpiPsGetNextPackageEnd (ParserState);
467         Status = AE_CTRL_PENDING;
468         break;
469
470
471     case AE_CTRL_FALSE:
472         /*
473          * Either an IF/WHILE Predicate was false or we encountered a BREAK
474          * opcode.  In both cases, we do not execute the rest of the
475          * package;  We simply close out the parent (finishing the walk of
476          * this branch of the tree) and continue execution at the parent
477          * level.
478          */
479         ParserState->Aml = ParserState->Scope->ParseScope.PkgEnd;
480
481         /* In the case of a BREAK, just force a predicate (if any) to FALSE */
482
483         WalkState->ControlState->Common.Value = FALSE;
484         Status = AE_CTRL_END;
485         break;
486
487
488     case AE_CTRL_TRANSFER:
489
490         /* A method call (invocation) -- transfer control */
491
492         Status = AE_CTRL_TRANSFER;
493         WalkState->PrevOp = Op;
494         WalkState->MethodCallOp = Op;
495         WalkState->MethodCallNode = (Op->Common.Value.Arg)->Common.Node;
496
497         /* Will return value (if any) be used by the caller? */
498
499         WalkState->ReturnUsed = AcpiDsIsResultUsed (Op, WalkState);
500         break;
501
502
503     default:
504
505         Status = CallbackStatus;
506         if ((CallbackStatus & AE_CODE_MASK) == AE_CODE_CONTROL)
507         {
508             Status = AE_OK;
509         }
510         break;
511     }
512
513     return_ACPI_STATUS (Status);
514 }
515
516
517 /*******************************************************************************
518  *
519  * FUNCTION:    AcpiPsParseAml
520  *
521  * PARAMETERS:  WalkState       - Current state
522  *
523  *
524  * RETURN:      Status
525  *
526  * DESCRIPTION: Parse raw AML and return a tree of ops
527  *
528  ******************************************************************************/
529
530 ACPI_STATUS
531 AcpiPsParseAml (
532     ACPI_WALK_STATE         *WalkState)
533 {
534     ACPI_STATUS             Status;
535     ACPI_THREAD_STATE       *Thread;
536     ACPI_THREAD_STATE       *PrevWalkList = AcpiGbl_CurrentWalkList;
537     ACPI_WALK_STATE         *PreviousWalkState;
538
539
540     ACPI_FUNCTION_TRACE (PsParseAml);
541
542     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
543         "Entered with WalkState=%p Aml=%p size=%X\n",
544         WalkState, WalkState->ParserState.Aml,
545         WalkState->ParserState.AmlSize));
546
547
548     /* Create and initialize a new thread state */
549
550     Thread = AcpiUtCreateThreadState ();
551     if (!Thread)
552     {
553         AcpiDsDeleteWalkState (WalkState);
554         return_ACPI_STATUS (AE_NO_MEMORY);
555     }
556
557     WalkState->Thread = Thread;
558
559     /*
560      * If executing a method, the starting SyncLevel is this method's
561      * SyncLevel
562      */
563     if (WalkState->MethodDesc)
564     {
565         WalkState->Thread->CurrentSyncLevel = WalkState->MethodDesc->Method.SyncLevel;
566     }
567
568     AcpiDsPushWalkState (WalkState, Thread);
569
570     /*
571      * This global allows the AML debugger to get a handle to the currently
572      * executing control method.
573      */
574     AcpiGbl_CurrentWalkList = Thread;
575
576     /*
577      * Execute the walk loop as long as there is a valid Walk State.  This
578      * handles nested control method invocations without recursion.
579      */
580     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "State=%p\n", WalkState));
581
582     Status = AE_OK;
583     while (WalkState)
584     {
585         if (ACPI_SUCCESS (Status))
586         {
587             /*
588              * The ParseLoop executes AML until the method terminates
589              * or calls another method.
590              */
591             Status = AcpiPsParseLoop (WalkState);
592         }
593
594         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
595             "Completed one call to walk loop, %s State=%p\n",
596             AcpiFormatException (Status), WalkState));
597
598         if (Status == AE_CTRL_TRANSFER)
599         {
600             /*
601              * A method call was detected.
602              * Transfer control to the called control method
603              */
604             Status = AcpiDsCallControlMethod (Thread, WalkState, NULL);
605             if (ACPI_FAILURE (Status))
606             {
607                 Status = AcpiDsMethodError (Status, WalkState);
608             }
609
610             /*
611              * If the transfer to the new method method call worked, a new walk
612              * state was created -- get it
613              */
614             WalkState = AcpiDsGetCurrentWalkState (Thread);
615             continue;
616         }
617         else if (Status == AE_CTRL_TERMINATE)
618         {
619             Status = AE_OK;
620         }
621         else if ((Status != AE_OK) && (WalkState->MethodDesc))
622         {
623             /* Either the method parse or actual execution failed */
624
625             ACPI_ERROR_METHOD ("Method parse/execution failed",
626                 WalkState->MethodNode, NULL, Status);
627
628             /* Check for possible multi-thread reentrancy problem */
629
630             if ((Status == AE_ALREADY_EXISTS) &&
631                 (!WalkState->MethodDesc->Method.Mutex))
632             {
633                 ACPI_INFO ((AE_INFO, "Marking method %4.4s as Serialized",
634                     WalkState->MethodNode->Name.Ascii));
635
636                 /*
637                  * Method tried to create an object twice. The probable cause is
638                  * that the method cannot handle reentrancy.
639                  *
640                  * The method is marked NotSerialized, but it tried to create
641                  * a named object, causing the second thread entrance to fail.
642                  * Workaround this problem by marking the method permanently
643                  * as Serialized.
644                  */
645                 WalkState->MethodDesc->Method.MethodFlags |= AML_METHOD_SERIALIZED;
646                 WalkState->MethodDesc->Method.SyncLevel = 0;
647             }
648         }
649
650         /* We are done with this walk, move on to the parent if any */
651
652         WalkState = AcpiDsPopWalkState (Thread);
653
654         /* Reset the current scope to the beginning of scope stack */
655
656         AcpiDsScopeStackClear (WalkState);
657
658         /*
659          * If we just returned from the execution of a control method or if we
660          * encountered an error during the method parse phase, there's lots of
661          * cleanup to do
662          */
663         if (((WalkState->ParseFlags & ACPI_PARSE_MODE_MASK) == ACPI_PARSE_EXECUTE) ||
664             (ACPI_FAILURE (Status)))
665         {
666             AcpiDsTerminateControlMethod (WalkState->MethodDesc, WalkState);
667         }
668
669         /* Delete this walk state and all linked control states */
670
671         AcpiPsCleanupScope (&WalkState->ParserState);
672         PreviousWalkState = WalkState;
673
674         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
675             "ReturnValue=%p, ImplicitValue=%p State=%p\n",
676             WalkState->ReturnDesc, WalkState->ImplicitReturnObj, WalkState));
677
678         /* Check if we have restarted a preempted walk */
679
680         WalkState = AcpiDsGetCurrentWalkState (Thread);
681         if (WalkState)
682         {
683             if (ACPI_SUCCESS (Status))
684             {
685                 /*
686                  * There is another walk state, restart it.
687                  * If the method return value is not used by the parent,
688                  * The object is deleted
689                  */
690                 if (!PreviousWalkState->ReturnDesc)
691                 {
692                     Status = AcpiDsRestartControlMethod (WalkState,
693                                 PreviousWalkState->ImplicitReturnObj);
694                 }
695                 else
696                 {
697                     /*
698                      * We have a valid return value, delete any implicit
699                      * return value.
700                      */
701                     AcpiDsClearImplicitReturn (PreviousWalkState);
702
703                     Status = AcpiDsRestartControlMethod (WalkState,
704                                 PreviousWalkState->ReturnDesc);
705                 }
706                 if (ACPI_SUCCESS (Status))
707                 {
708                     WalkState->WalkType |= ACPI_WALK_METHOD_RESTART;
709                 }
710             }
711             else
712             {
713                 /* On error, delete any return object */
714
715                 AcpiUtRemoveReference (PreviousWalkState->ReturnDesc);
716             }
717         }
718
719         /*
720          * Just completed a 1st-level method, save the final internal return
721          * value (if any)
722          */
723         else if (PreviousWalkState->CallerReturnDesc)
724         {
725             if (PreviousWalkState->ImplicitReturnObj)
726             {
727                 *(PreviousWalkState->CallerReturnDesc) =
728                     PreviousWalkState->ImplicitReturnObj;
729             }
730             else
731             {
732                  /* NULL if no return value */
733
734                 *(PreviousWalkState->CallerReturnDesc) =
735                     PreviousWalkState->ReturnDesc;
736             }
737         }
738         else
739         {
740             if (PreviousWalkState->ReturnDesc)
741             {
742                 /* Caller doesn't want it, must delete it */
743
744                 AcpiUtRemoveReference (PreviousWalkState->ReturnDesc);
745             }
746             if (PreviousWalkState->ImplicitReturnObj)
747             {
748                 /* Caller doesn't want it, must delete it */
749
750                 AcpiUtRemoveReference (PreviousWalkState->ImplicitReturnObj);
751             }
752         }
753
754         AcpiDsDeleteWalkState (PreviousWalkState);
755     }
756
757     /* Normal exit */
758
759     AcpiExReleaseAllMutexes (Thread);
760     AcpiUtDeleteGenericState (ACPI_CAST_PTR (ACPI_GENERIC_STATE, Thread));
761     AcpiGbl_CurrentWalkList = PrevWalkList;
762     return_ACPI_STATUS (Status);
763 }
764
765