]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/dev/acpica/dsmethod.c
This commit was generated by cvs2svn to compensate for changes in r162911,
[FreeBSD/FreeBSD.git] / sys / contrib / dev / acpica / dsmethod.c
1 /******************************************************************************
2  *
3  * Module Name: dsmethod - Parser/Interpreter interface - control method parsing
4  *              $Revision: 1.110 $
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 #define __DSMETHOD_C__
118
119 #include <contrib/dev/acpica/acpi.h>
120 #include <contrib/dev/acpica/acparser.h>
121 #include <contrib/dev/acpica/amlcode.h>
122 #include <contrib/dev/acpica/acdispat.h>
123 #include <contrib/dev/acpica/acinterp.h>
124 #include <contrib/dev/acpica/acnamesp.h>
125
126
127 #define _COMPONENT          ACPI_DISPATCHER
128         ACPI_MODULE_NAME    ("dsmethod")
129
130
131 /*******************************************************************************
132  *
133  * FUNCTION:    AcpiDsParseMethod
134  *
135  * PARAMETERS:  Node        - Method node
136  *
137  * RETURN:      Status
138  *
139  * DESCRIPTION: Parse the AML that is associated with the method.
140  *
141  * MUTEX:       Assumes parser is locked
142  *
143  ******************************************************************************/
144
145 ACPI_STATUS
146 AcpiDsParseMethod (
147     ACPI_NAMESPACE_NODE     *Node)
148 {
149     ACPI_STATUS             Status;
150     ACPI_OPERAND_OBJECT     *ObjDesc;
151     ACPI_PARSE_OBJECT       *Op;
152     ACPI_WALK_STATE         *WalkState;
153
154
155     ACPI_FUNCTION_TRACE_PTR ("DsParseMethod", Node);
156
157
158     /* Parameter Validation */
159
160     if (!Node)
161     {
162         return_ACPI_STATUS (AE_NULL_ENTRY);
163     }
164
165     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Parsing [%4.4s] **** NamedObj=%p\n",
166         AcpiUtGetNodeName (Node), Node));
167
168     /* Extract the method object from the method Node */
169
170     ObjDesc = AcpiNsGetAttachedObject (Node);
171     if (!ObjDesc)
172     {
173         return_ACPI_STATUS (AE_NULL_OBJECT);
174     }
175
176     /* Create a mutex for the method if there is a concurrency limit */
177
178     if ((ObjDesc->Method.Concurrency != ACPI_INFINITE_CONCURRENCY) &&
179         (!ObjDesc->Method.Semaphore))
180     {
181         Status = AcpiOsCreateSemaphore (ObjDesc->Method.Concurrency,
182                                         ObjDesc->Method.Concurrency,
183                                         &ObjDesc->Method.Semaphore);
184         if (ACPI_FAILURE (Status))
185         {
186             return_ACPI_STATUS (Status);
187         }
188     }
189
190     /*
191      * Allocate a new parser op to be the root of the parsed
192      * method tree
193      */
194     Op = AcpiPsAllocOp (AML_METHOD_OP);
195     if (!Op)
196     {
197         return_ACPI_STATUS (AE_NO_MEMORY);
198     }
199
200     /* Init new op with the method name and pointer back to the Node */
201
202     AcpiPsSetName (Op, Node->Name.Integer);
203     Op->Common.Node = Node;
204
205     /*
206      * Get a new OwnerId for objects created by this method.  Namespace
207      * objects (such as Operation Regions) can be created during the
208      * first pass parse.
209      */
210     Status = AcpiUtAllocateOwnerId (&ObjDesc->Method.OwnerId);
211     if (ACPI_FAILURE (Status))
212     {
213         goto Cleanup;
214     }
215
216     /* Create and initialize a new walk state */
217
218     WalkState = AcpiDsCreateWalkState (
219                     ObjDesc->Method.OwnerId, NULL, NULL, NULL);
220     if (!WalkState)
221     {
222         Status = AE_NO_MEMORY;
223         goto Cleanup2;
224     }
225
226     Status = AcpiDsInitAmlWalk (WalkState, Op, Node,
227                     ObjDesc->Method.AmlStart,
228                     ObjDesc->Method.AmlLength, NULL, 1);
229     if (ACPI_FAILURE (Status))
230     {
231         AcpiDsDeleteWalkState (WalkState);
232         goto Cleanup2;
233     }
234
235     /*
236      * Parse the method, first pass
237      *
238      * The first pass load is where newly declared named objects are added into
239      * the namespace.  Actual evaluation of the named objects (what would be
240      * called a "second pass") happens during the actual execution of the
241      * method so that operands to the named objects can take on dynamic
242      * run-time values.
243      */
244     Status = AcpiPsParseAml (WalkState);
245     if (ACPI_FAILURE (Status))
246     {
247         goto Cleanup2;
248     }
249
250     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
251         "**** [%4.4s] Parsed **** NamedObj=%p Op=%p\n",
252         AcpiUtGetNodeName (Node), Node, Op));
253
254     /*
255      * Delete the parse tree. We simply re-parse the method for every
256      * execution since there isn't much overhead (compared to keeping lots
257      * of parse trees around)
258      */
259     AcpiNsDeleteNamespaceSubtree (Node);
260     AcpiNsDeleteNamespaceByOwner (ObjDesc->Method.OwnerId);
261
262 Cleanup2:
263     AcpiUtReleaseOwnerId (&ObjDesc->Method.OwnerId);
264
265 Cleanup:
266     AcpiPsDeleteParseTree (Op);
267     return_ACPI_STATUS (Status);
268 }
269
270
271 /*******************************************************************************
272  *
273  * FUNCTION:    AcpiDsBeginMethodExecution
274  *
275  * PARAMETERS:  MethodNode          - Node of the method
276  *              ObjDesc             - The method object
277  *              CallingMethodNode   - Caller of this method (if non-null)
278  *
279  * RETURN:      Status
280  *
281  * DESCRIPTION: Prepare a method for execution.  Parses the method if necessary,
282  *              increments the thread count, and waits at the method semaphore
283  *              for clearance to execute.
284  *
285  ******************************************************************************/
286
287 ACPI_STATUS
288 AcpiDsBeginMethodExecution (
289     ACPI_NAMESPACE_NODE     *MethodNode,
290     ACPI_OPERAND_OBJECT     *ObjDesc,
291     ACPI_NAMESPACE_NODE     *CallingMethodNode)
292 {
293     ACPI_STATUS             Status = AE_OK;
294
295
296     ACPI_FUNCTION_TRACE_PTR ("DsBeginMethodExecution", MethodNode);
297
298
299     if (!MethodNode)
300     {
301         return_ACPI_STATUS (AE_NULL_ENTRY);
302     }
303
304     /* Prevent wraparound of thread count */
305
306     if (ObjDesc->Method.ThreadCount == ACPI_UINT8_MAX)
307     {
308         ACPI_REPORT_ERROR ((
309             "Method reached maximum reentrancy limit (255)\n"));
310         return_ACPI_STATUS (AE_AML_METHOD_LIMIT);
311     }
312
313     /*
314      * If there is a concurrency limit on this method, we need to
315      * obtain a unit from the method semaphore.
316      */
317     if (ObjDesc->Method.Semaphore)
318     {
319         /*
320          * Allow recursive method calls, up to the reentrancy/concurrency
321          * limit imposed by the SERIALIZED rule and the SyncLevel method
322          * parameter.
323          *
324          * The point of this code is to avoid permanently blocking a
325          * thread that is making recursive method calls.
326          */
327         if (MethodNode == CallingMethodNode)
328         {
329             if (ObjDesc->Method.ThreadCount >= ObjDesc->Method.Concurrency)
330             {
331                 return_ACPI_STATUS (AE_AML_METHOD_LIMIT);
332             }
333         }
334
335         /*
336          * Get a unit from the method semaphore. This releases the
337          * interpreter if we block
338          */
339         Status = AcpiExSystemWaitSemaphore (ObjDesc->Method.Semaphore,
340                                             ACPI_WAIT_FOREVER);
341     }
342
343     /*
344      * Allocate an Owner ID for this method, only if this is the first thread
345      * to begin concurrent execution. We only need one OwnerId, even if the
346      * method is invoked recursively.
347      */
348      if (!ObjDesc->Method.OwnerId)
349      {
350          Status = AcpiUtAllocateOwnerId (&ObjDesc->Method.OwnerId);
351          if (ACPI_FAILURE (Status))
352          {
353              return_ACPI_STATUS (Status);
354          }
355      }
356
357     /*
358      * Increment the method parse tree thread count since it has been
359      * reentered one more time (even if it is the same thread)
360      */
361     ObjDesc->Method.ThreadCount++;
362     return_ACPI_STATUS (Status);
363 }
364
365
366 /*******************************************************************************
367  *
368  * FUNCTION:    AcpiDsCallControlMethod
369  *
370  * PARAMETERS:  Thread              - Info for this thread
371  *              ThisWalkState       - Current walk state
372  *              Op                  - Current Op to be walked
373  *
374  * RETURN:      Status
375  *
376  * DESCRIPTION: Transfer execution to a called control method
377  *
378  ******************************************************************************/
379
380 ACPI_STATUS
381 AcpiDsCallControlMethod (
382     ACPI_THREAD_STATE       *Thread,
383     ACPI_WALK_STATE         *ThisWalkState,
384     ACPI_PARSE_OBJECT       *Op)
385 {
386     ACPI_STATUS             Status;
387     ACPI_NAMESPACE_NODE     *MethodNode;
388     ACPI_WALK_STATE         *NextWalkState = NULL;
389     ACPI_OPERAND_OBJECT     *ObjDesc;
390     ACPI_PARAMETER_INFO     Info;
391     UINT32                  i;
392
393
394     ACPI_FUNCTION_TRACE_PTR ("DsCallControlMethod", ThisWalkState);
395
396     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Execute method %p, currentstate=%p\n",
397         ThisWalkState->PrevOp, ThisWalkState));
398
399     /*
400      * Get the namespace entry for the control method we are about to call
401      */
402     MethodNode = ThisWalkState->MethodCallNode;
403     if (!MethodNode)
404     {
405         return_ACPI_STATUS (AE_NULL_ENTRY);
406     }
407
408     ObjDesc = AcpiNsGetAttachedObject (MethodNode);
409     if (!ObjDesc)
410     {
411         return_ACPI_STATUS (AE_NULL_OBJECT);
412     }
413
414     /* Init for new method, wait on concurrency semaphore */
415
416     Status = AcpiDsBeginMethodExecution (MethodNode, ObjDesc,
417                     ThisWalkState->MethodNode);
418     if (ACPI_FAILURE (Status))
419     {
420         goto Cleanup;
421     }
422
423     if (!(ObjDesc->Method.MethodFlags & AML_METHOD_INTERNAL_ONLY))
424     {
425         /* 1) Parse: Create a new walk state for the preempting walk */
426
427         NextWalkState = AcpiDsCreateWalkState (ObjDesc->Method.OwnerId,
428                                                 Op, ObjDesc, NULL);
429         if (!NextWalkState)
430         {
431             return_ACPI_STATUS (AE_NO_MEMORY);
432         }
433
434         /* Create and init a Root Node */
435
436         Op = AcpiPsCreateScopeOp ();
437         if (!Op)
438         {
439             Status = AE_NO_MEMORY;
440             goto Cleanup;
441         }
442
443         Status = AcpiDsInitAmlWalk (NextWalkState, Op, MethodNode,
444                         ObjDesc->Method.AmlStart,  ObjDesc->Method.AmlLength,
445                         NULL, 1);
446         if (ACPI_FAILURE (Status))
447         {
448             AcpiDsDeleteWalkState (NextWalkState);
449             goto Cleanup;
450         }
451
452         /* Begin AML parse */
453
454         Status = AcpiPsParseAml (NextWalkState);
455         AcpiPsDeleteParseTree (Op);
456     }
457
458     /* 2) Execute: Create a new state for the preempting walk */
459
460     NextWalkState = AcpiDsCreateWalkState (ObjDesc->Method.OwnerId,
461                                             NULL, ObjDesc, Thread);
462     if (!NextWalkState)
463     {
464         Status = AE_NO_MEMORY;
465         goto Cleanup;
466     }
467     /*
468      * The resolved arguments were put on the previous walk state's operand
469      * stack. Operands on the previous walk state stack always
470      * start at index 0. Also, null terminate the list of arguments
471      */
472     ThisWalkState->Operands [ThisWalkState->NumOperands] = NULL;
473
474     Info.Parameters = &ThisWalkState->Operands[0];
475     Info.ParameterType = ACPI_PARAM_ARGS;
476
477     Status = AcpiDsInitAmlWalk (NextWalkState, NULL, MethodNode,
478                     ObjDesc->Method.AmlStart, ObjDesc->Method.AmlLength,
479                     &Info, 3);
480     if (ACPI_FAILURE (Status))
481     {
482         goto Cleanup;
483     }
484
485     /*
486      * Delete the operands on the previous walkstate operand stack
487      * (they were copied to new objects)
488      */
489     for (i = 0; i < ObjDesc->Method.ParamCount; i++)
490     {
491         AcpiUtRemoveReference (ThisWalkState->Operands [i]);
492         ThisWalkState->Operands [i] = NULL;
493     }
494
495     /* Clear the operand stack */
496
497     ThisWalkState->NumOperands = 0;
498
499     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
500         "Starting nested execution, newstate=%p\n", NextWalkState));
501
502     if (ObjDesc->Method.MethodFlags & AML_METHOD_INTERNAL_ONLY)
503     {
504         Status = ObjDesc->Method.Implementation (NextWalkState);
505     }
506
507     return_ACPI_STATUS (Status);
508
509
510 Cleanup:
511     /* Decrement the thread count on the method parse tree */
512
513     if (NextWalkState && (NextWalkState->MethodDesc))
514     {
515         NextWalkState->MethodDesc->Method.ThreadCount--;
516     }
517
518     /* On error, we must delete the new walk state */
519
520     AcpiDsTerminateControlMethod (NextWalkState);
521     AcpiDsDeleteWalkState (NextWalkState);
522     return_ACPI_STATUS (Status);
523 }
524
525
526 /*******************************************************************************
527  *
528  * FUNCTION:    AcpiDsRestartControlMethod
529  *
530  * PARAMETERS:  WalkState           - State for preempted method (caller)
531  *              ReturnDesc          - Return value from the called method
532  *
533  * RETURN:      Status
534  *
535  * DESCRIPTION: Restart a method that was preempted by another (nested) method
536  *              invocation.  Handle the return value (if any) from the callee.
537  *
538  ******************************************************************************/
539
540 ACPI_STATUS
541 AcpiDsRestartControlMethod (
542     ACPI_WALK_STATE         *WalkState,
543     ACPI_OPERAND_OBJECT     *ReturnDesc)
544 {
545     ACPI_STATUS             Status;
546
547
548     ACPI_FUNCTION_TRACE_PTR ("DsRestartControlMethod", WalkState);
549
550
551     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
552         "****Restart [%4.4s] Op %p ReturnValueFromCallee %p\n",
553         (char *) &WalkState->MethodNode->Name, WalkState->MethodCallOp,
554         ReturnDesc));
555
556     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
557         "    ReturnFromThisMethodUsed?=%X ResStack %p Walk %p\n",
558         WalkState->ReturnUsed,
559         WalkState->Results, WalkState));
560
561     /* Did the called method return a value? */
562
563     if (ReturnDesc)
564     {
565         /* Are we actually going to use the return value? */
566
567         if (WalkState->ReturnUsed)
568         {
569             /* Save the return value from the previous method */
570
571             Status = AcpiDsResultPush (ReturnDesc, WalkState);
572             if (ACPI_FAILURE (Status))
573             {
574                 AcpiUtRemoveReference (ReturnDesc);
575                 return_ACPI_STATUS (Status);
576             }
577
578             /*
579              * Save as THIS method's return value in case it is returned
580              * immediately to yet another method
581              */
582             WalkState->ReturnDesc = ReturnDesc;
583         }
584
585         /*
586          * The following code is the
587          * optional support for a so-called "implicit return". Some AML code
588          * assumes that the last value of the method is "implicitly" returned
589          * to the caller. Just save the last result as the return value.
590          * NOTE: this is optional because the ASL language does not actually
591          * support this behavior.
592          */
593         else if (!AcpiDsDoImplicitReturn (ReturnDesc, WalkState, FALSE))
594         {
595             /*
596              * Delete the return value if it will not be used by the
597              * calling method
598              */
599             AcpiUtRemoveReference (ReturnDesc);
600         }
601     }
602
603     return_ACPI_STATUS (AE_OK);
604 }
605
606
607 /*******************************************************************************
608  *
609  * FUNCTION:    AcpiDsTerminateControlMethod
610  *
611  * PARAMETERS:  WalkState           - State of the method
612  *
613  * RETURN:      None
614  *
615  * DESCRIPTION: Terminate a control method.  Delete everything that the method
616  *              created, delete all locals and arguments, and delete the parse
617  *              tree if requested.
618  *
619  ******************************************************************************/
620
621 void
622 AcpiDsTerminateControlMethod (
623     ACPI_WALK_STATE         *WalkState)
624 {
625     ACPI_OPERAND_OBJECT     *ObjDesc;
626     ACPI_NAMESPACE_NODE     *MethodNode;
627     ACPI_STATUS             Status;
628
629
630     ACPI_FUNCTION_TRACE_PTR ("DsTerminateControlMethod", WalkState);
631
632
633     if (!WalkState)
634     {
635         return_VOID;
636     }
637
638     /* The current method object was saved in the walk state */
639
640     ObjDesc = WalkState->MethodDesc;
641     if (!ObjDesc)
642     {
643         return_VOID;
644     }
645
646     /* Delete all arguments and locals */
647
648     AcpiDsMethodDataDeleteAll (WalkState);
649
650     /*
651      * Lock the parser while we terminate this method.
652      * If this is the last thread executing the method,
653      * we have additional cleanup to perform
654      */
655     Status = AcpiUtAcquireMutex (ACPI_MTX_PARSER);
656     if (ACPI_FAILURE (Status))
657     {
658         return_VOID;
659     }
660
661     /* Signal completion of the execution of this method if necessary */
662
663     if (WalkState->MethodDesc->Method.Semaphore)
664     {
665         Status = AcpiOsSignalSemaphore (
666                         WalkState->MethodDesc->Method.Semaphore, 1);
667         if (ACPI_FAILURE (Status))
668         {
669             ACPI_REPORT_ERROR (("Could not signal method semaphore\n"));
670
671             /* Ignore error and continue cleanup */
672         }
673     }
674
675     if (WalkState->MethodDesc->Method.ThreadCount)
676     {
677         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
678             "*** Not deleting method namespace, there are still %d threads\n",
679             WalkState->MethodDesc->Method.ThreadCount));
680     }
681     else /* This is the last executing thread */
682     {
683         /*
684          * Support to dynamically change a method from NotSerialized to
685          * Serialized if it appears that the method is written foolishly and
686          * does not support multiple thread execution.  The best example of this
687          * is if such a method creates namespace objects and blocks.  A second
688          * thread will fail with an AE_ALREADY_EXISTS exception
689          *
690          * This code is here because we must wait until the last thread exits
691          * before creating the synchronization semaphore.
692          */
693         if ((WalkState->MethodDesc->Method.Concurrency == 1) &&
694             (!WalkState->MethodDesc->Method.Semaphore))
695         {
696             Status = AcpiOsCreateSemaphore (1, 1,
697                         &WalkState->MethodDesc->Method.Semaphore);
698         }
699
700         /*
701          * There are no more threads executing this method.  Perform
702          * additional cleanup.
703          *
704          * The method Node is stored in the walk state
705          */
706         MethodNode = WalkState->MethodNode;
707
708         /*
709          * Delete any namespace entries created immediately underneath
710          * the method
711          */
712         Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
713         if (ACPI_FAILURE (Status))
714         {
715             goto Exit;
716         }
717
718         if (MethodNode->Child)
719         {
720             AcpiNsDeleteNamespaceSubtree (MethodNode);
721         }
722
723         /*
724          * Delete any namespace entries created anywhere else within
725          * the namespace
726          */
727         AcpiNsDeleteNamespaceByOwner (WalkState->MethodDesc->Method.OwnerId);
728         Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
729         AcpiUtReleaseOwnerId (&WalkState->MethodDesc->Method.OwnerId);
730     }
731
732 Exit:
733     (void) AcpiUtReleaseMutex (ACPI_MTX_PARSER);
734     return_VOID;
735 }
736
737