1 /******************************************************************************
3 * Module Name: dsmethod - Parser/Interpreter interface - control method parsing
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2018, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
54 #define _COMPONENT ACPI_DISPATCHER
55 ACPI_MODULE_NAME ("dsmethod")
57 /* Local prototypes */
60 AcpiDsDetectNamedOpcodes (
61 ACPI_WALK_STATE
*WalkState
,
62 ACPI_PARSE_OBJECT
**OutOp
);
65 AcpiDsCreateMethodMutex (
66 ACPI_OPERAND_OBJECT
*MethodDesc
);
69 /*******************************************************************************
71 * FUNCTION: AcpiDsAutoSerializeMethod
73 * PARAMETERS: Node - Namespace Node of the method
74 * ObjDesc - Method object attached to node
78 * DESCRIPTION: Parse a control method AML to scan for control methods that
79 * need serialization due to the creation of named objects.
81 * NOTE: It is a bit of overkill to mark all such methods serialized, since
82 * there is only a problem if the method actually blocks during execution.
83 * A blocking operation is, for example, a Sleep() operation, or any access
84 * to an operation region. However, it is probably not possible to easily
85 * detect whether a method will block or not, so we simply mark all suspicious
86 * methods as serialized.
88 * NOTE2: This code is essentially a generic routine for parsing a single
91 ******************************************************************************/
94 AcpiDsAutoSerializeMethod (
95 ACPI_NAMESPACE_NODE
*Node
,
96 ACPI_OPERAND_OBJECT
*ObjDesc
)
99 ACPI_PARSE_OBJECT
*Op
= NULL
;
100 ACPI_WALK_STATE
*WalkState
;
103 ACPI_FUNCTION_TRACE_PTR (DsAutoSerializeMethod
, Node
);
106 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE
,
107 "Method auto-serialization parse [%4.4s] %p\n",
108 AcpiUtGetNodeName (Node
), Node
));
110 /* Create/Init a root op for the method parse tree */
112 Op
= AcpiPsAllocOp (AML_METHOD_OP
, ObjDesc
->Method
.AmlStart
);
115 return_ACPI_STATUS (AE_NO_MEMORY
);
118 AcpiPsSetName (Op
, Node
->Name
.Integer
);
119 Op
->Common
.Node
= Node
;
121 /* Create and initialize a new walk state */
123 WalkState
= AcpiDsCreateWalkState (Node
->OwnerId
, NULL
, NULL
, NULL
);
127 return_ACPI_STATUS (AE_NO_MEMORY
);
130 Status
= AcpiDsInitAmlWalk (WalkState
, Op
, Node
,
131 ObjDesc
->Method
.AmlStart
, ObjDesc
->Method
.AmlLength
, NULL
, 0);
132 if (ACPI_FAILURE (Status
))
134 AcpiDsDeleteWalkState (WalkState
);
136 return_ACPI_STATUS (Status
);
139 WalkState
->DescendingCallback
= AcpiDsDetectNamedOpcodes
;
141 /* Parse the method, scan for creation of named objects */
143 Status
= AcpiPsParseAml (WalkState
);
145 AcpiPsDeleteParseTree (Op
);
146 return_ACPI_STATUS (Status
);
150 /*******************************************************************************
152 * FUNCTION: AcpiDsDetectNamedOpcodes
154 * PARAMETERS: WalkState - Current state of the parse tree walk
155 * OutOp - Unused, required for parser interface
159 * DESCRIPTION: Descending callback used during the loading of ACPI tables.
160 * Currently used to detect methods that must be marked serialized
161 * in order to avoid problems with the creation of named objects.
163 ******************************************************************************/
166 AcpiDsDetectNamedOpcodes (
167 ACPI_WALK_STATE
*WalkState
,
168 ACPI_PARSE_OBJECT
**OutOp
)
171 ACPI_FUNCTION_NAME (AcpiDsDetectNamedOpcodes
);
174 /* We are only interested in opcodes that create a new name */
176 if (!(WalkState
->OpInfo
->Flags
& (AML_NAMED
| AML_CREATE
| AML_FIELD
)))
182 * At this point, we know we have a Named object opcode.
183 * Mark the method as serialized. Later code will create a mutex for
184 * this method to enforce serialization.
186 * Note, ACPI_METHOD_IGNORE_SYNC_LEVEL flag means that we will ignore the
187 * Sync Level mechanism for this method, even though it is now serialized.
188 * Otherwise, there can be conflicts with existing ASL code that actually
191 WalkState
->MethodDesc
->Method
.SyncLevel
= 0;
192 WalkState
->MethodDesc
->Method
.InfoFlags
|=
193 (ACPI_METHOD_SERIALIZED
| ACPI_METHOD_IGNORE_SYNC_LEVEL
);
195 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
196 "Method serialized [%4.4s] %p - [%s] (%4.4X)\n",
197 WalkState
->MethodNode
->Name
.Ascii
, WalkState
->MethodNode
,
198 WalkState
->OpInfo
->Name
, WalkState
->Opcode
));
200 /* Abort the parse, no need to examine this method any further */
202 return (AE_CTRL_TERMINATE
);
206 /*******************************************************************************
208 * FUNCTION: AcpiDsMethodError
210 * PARAMETERS: Status - Execution status
211 * WalkState - Current state
215 * DESCRIPTION: Called on method error. Invoke the global exception handler if
216 * present, dump the method data if the debugger is configured
218 * Note: Allows the exception handler to change the status code
220 ******************************************************************************/
225 ACPI_WALK_STATE
*WalkState
)
231 ACPI_FUNCTION_ENTRY ();
234 /* Ignore AE_OK and control exception codes */
236 if (ACPI_SUCCESS (Status
) ||
237 (Status
& AE_CODE_CONTROL
))
242 /* Invoke the global exception handler */
244 if (AcpiGbl_ExceptionHandler
)
246 /* Exit the interpreter, allow handler to execute methods */
248 AcpiExExitInterpreter ();
251 * Handler can map the exception code to anything it wants, including
252 * AE_OK, in which case the executing method will not be aborted.
254 AmlOffset
= (UINT32
) ACPI_PTR_DIFF (WalkState
->Aml
,
255 WalkState
->ParserState
.AmlStart
);
257 if (WalkState
->MethodNode
)
259 Name
= WalkState
->MethodNode
->Name
.Integer
;
261 else if (WalkState
->DeferredNode
)
263 Name
= WalkState
->DeferredNode
->Name
.Integer
;
266 Status
= AcpiGbl_ExceptionHandler (Status
, Name
,
267 WalkState
->Opcode
, AmlOffset
, NULL
);
268 AcpiExEnterInterpreter ();
271 AcpiDsClearImplicitReturn (WalkState
);
273 if (ACPI_FAILURE (Status
))
275 AcpiDsDumpMethodStack (Status
, WalkState
, WalkState
->Op
);
277 /* Display method locals/args if debugger is present */
280 AcpiDbDumpMethodInfo (Status
, WalkState
);
288 /*******************************************************************************
290 * FUNCTION: AcpiDsCreateMethodMutex
292 * PARAMETERS: ObjDesc - The method object
296 * DESCRIPTION: Create a mutex object for a serialized control method
298 ******************************************************************************/
301 AcpiDsCreateMethodMutex (
302 ACPI_OPERAND_OBJECT
*MethodDesc
)
304 ACPI_OPERAND_OBJECT
*MutexDesc
;
308 ACPI_FUNCTION_TRACE (DsCreateMethodMutex
);
311 /* Create the new mutex object */
313 MutexDesc
= AcpiUtCreateInternalObject (ACPI_TYPE_MUTEX
);
316 return_ACPI_STATUS (AE_NO_MEMORY
);
319 /* Create the actual OS Mutex */
321 Status
= AcpiOsCreateMutex (&MutexDesc
->Mutex
.OsMutex
);
322 if (ACPI_FAILURE (Status
))
324 AcpiUtDeleteObjectDesc (MutexDesc
);
325 return_ACPI_STATUS (Status
);
328 MutexDesc
->Mutex
.SyncLevel
= MethodDesc
->Method
.SyncLevel
;
329 MethodDesc
->Method
.Mutex
= MutexDesc
;
330 return_ACPI_STATUS (AE_OK
);
334 /*******************************************************************************
336 * FUNCTION: AcpiDsBeginMethodExecution
338 * PARAMETERS: MethodNode - Node of the method
339 * ObjDesc - The method object
340 * WalkState - current state, NULL if not yet executing
345 * DESCRIPTION: Prepare a method for execution. Parses the method if necessary,
346 * increments the thread count, and waits at the method semaphore
347 * for clearance to execute.
349 ******************************************************************************/
352 AcpiDsBeginMethodExecution (
353 ACPI_NAMESPACE_NODE
*MethodNode
,
354 ACPI_OPERAND_OBJECT
*ObjDesc
,
355 ACPI_WALK_STATE
*WalkState
)
357 ACPI_STATUS Status
= AE_OK
;
360 ACPI_FUNCTION_TRACE_PTR (DsBeginMethodExecution
, MethodNode
);
365 return_ACPI_STATUS (AE_NULL_ENTRY
);
368 AcpiExStartTraceMethod (MethodNode
, ObjDesc
, WalkState
);
370 /* Prevent wraparound of thread count */
372 if (ObjDesc
->Method
.ThreadCount
== ACPI_UINT8_MAX
)
374 ACPI_ERROR ((AE_INFO
,
375 "Method reached maximum reentrancy limit (255)"));
376 return_ACPI_STATUS (AE_AML_METHOD_LIMIT
);
380 * If this method is serialized, we need to acquire the method mutex.
382 if (ObjDesc
->Method
.InfoFlags
& ACPI_METHOD_SERIALIZED
)
385 * Create a mutex for the method if it is defined to be Serialized
386 * and a mutex has not already been created. We defer the mutex creation
387 * until a method is actually executed, to minimize the object count
389 if (!ObjDesc
->Method
.Mutex
)
391 Status
= AcpiDsCreateMethodMutex (ObjDesc
);
392 if (ACPI_FAILURE (Status
))
394 return_ACPI_STATUS (Status
);
399 * The CurrentSyncLevel (per-thread) must be less than or equal to
400 * the sync level of the method. This mechanism provides some
401 * deadlock prevention.
403 * If the method was auto-serialized, we just ignore the sync level
404 * mechanism, because auto-serialization of methods can interfere
405 * with ASL code that actually uses sync levels.
407 * Top-level method invocation has no walk state at this point
410 (!(ObjDesc
->Method
.InfoFlags
& ACPI_METHOD_IGNORE_SYNC_LEVEL
)) &&
411 (WalkState
->Thread
->CurrentSyncLevel
>
412 ObjDesc
->Method
.Mutex
->Mutex
.SyncLevel
))
414 ACPI_ERROR ((AE_INFO
,
415 "Cannot acquire Mutex for method [%4.4s]"
416 ", current SyncLevel is too large (%u)",
417 AcpiUtGetNodeName (MethodNode
),
418 WalkState
->Thread
->CurrentSyncLevel
));
420 return_ACPI_STATUS (AE_AML_MUTEX_ORDER
);
424 * Obtain the method mutex if necessary. Do not acquire mutex for a
428 !ObjDesc
->Method
.Mutex
->Mutex
.ThreadId
||
429 (WalkState
->Thread
->ThreadId
!=
430 ObjDesc
->Method
.Mutex
->Mutex
.ThreadId
))
433 * Acquire the method mutex. This releases the interpreter if we
434 * block (and reacquires it before it returns)
436 Status
= AcpiExSystemWaitMutex (
437 ObjDesc
->Method
.Mutex
->Mutex
.OsMutex
, ACPI_WAIT_FOREVER
);
438 if (ACPI_FAILURE (Status
))
440 return_ACPI_STATUS (Status
);
443 /* Update the mutex and walk info and save the original SyncLevel */
447 ObjDesc
->Method
.Mutex
->Mutex
.OriginalSyncLevel
=
448 WalkState
->Thread
->CurrentSyncLevel
;
450 ObjDesc
->Method
.Mutex
->Mutex
.ThreadId
=
451 WalkState
->Thread
->ThreadId
;
454 * Update the current SyncLevel only if this is not an auto-
455 * serialized method. In the auto case, we have to ignore
456 * the sync level for the method mutex (created for the
457 * auto-serialization) because we have no idea of what the
458 * sync level should be. Therefore, just ignore it.
460 if (!(ObjDesc
->Method
.InfoFlags
&
461 ACPI_METHOD_IGNORE_SYNC_LEVEL
))
463 WalkState
->Thread
->CurrentSyncLevel
=
464 ObjDesc
->Method
.SyncLevel
;
469 ObjDesc
->Method
.Mutex
->Mutex
.OriginalSyncLevel
=
470 ObjDesc
->Method
.Mutex
->Mutex
.SyncLevel
;
472 ObjDesc
->Method
.Mutex
->Mutex
.ThreadId
=
473 AcpiOsGetThreadId ();
477 /* Always increase acquisition depth */
479 ObjDesc
->Method
.Mutex
->Mutex
.AcquisitionDepth
++;
483 * Allocate an Owner ID for this method, only if this is the first thread
484 * to begin concurrent execution. We only need one OwnerId, even if the
485 * method is invoked recursively.
487 if (!ObjDesc
->Method
.OwnerId
)
489 Status
= AcpiUtAllocateOwnerId (&ObjDesc
->Method
.OwnerId
);
490 if (ACPI_FAILURE (Status
))
497 * Increment the method parse tree thread count since it has been
498 * reentered one more time (even if it is the same thread)
500 ObjDesc
->Method
.ThreadCount
++;
502 return_ACPI_STATUS (Status
);
506 /* On error, must release the method mutex (if present) */
508 if (ObjDesc
->Method
.Mutex
)
510 AcpiOsReleaseMutex (ObjDesc
->Method
.Mutex
->Mutex
.OsMutex
);
512 return_ACPI_STATUS (Status
);
516 /*******************************************************************************
518 * FUNCTION: AcpiDsCallControlMethod
520 * PARAMETERS: Thread - Info for this thread
521 * ThisWalkState - Current walk state
522 * Op - Current Op to be walked
526 * DESCRIPTION: Transfer execution to a called control method
528 ******************************************************************************/
531 AcpiDsCallControlMethod (
532 ACPI_THREAD_STATE
*Thread
,
533 ACPI_WALK_STATE
*ThisWalkState
,
534 ACPI_PARSE_OBJECT
*Op
)
537 ACPI_NAMESPACE_NODE
*MethodNode
;
538 ACPI_WALK_STATE
*NextWalkState
= NULL
;
539 ACPI_OPERAND_OBJECT
*ObjDesc
;
540 ACPI_EVALUATE_INFO
*Info
;
544 ACPI_FUNCTION_TRACE_PTR (DsCallControlMethod
, ThisWalkState
);
546 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
547 "Calling method %p, currentstate=%p\n",
548 ThisWalkState
->PrevOp
, ThisWalkState
));
551 * Get the namespace entry for the control method we are about to call
553 MethodNode
= ThisWalkState
->MethodCallNode
;
556 return_ACPI_STATUS (AE_NULL_ENTRY
);
559 ObjDesc
= AcpiNsGetAttachedObject (MethodNode
);
562 return_ACPI_STATUS (AE_NULL_OBJECT
);
565 /* Init for new method, possibly wait on method mutex */
567 Status
= AcpiDsBeginMethodExecution (
568 MethodNode
, ObjDesc
, ThisWalkState
);
569 if (ACPI_FAILURE (Status
))
571 return_ACPI_STATUS (Status
);
574 /* Begin method parse/execution. Create a new walk state */
576 NextWalkState
= AcpiDsCreateWalkState (
577 ObjDesc
->Method
.OwnerId
, NULL
, ObjDesc
, Thread
);
580 Status
= AE_NO_MEMORY
;
585 * The resolved arguments were put on the previous walk state's operand
586 * stack. Operands on the previous walk state stack always
587 * start at index 0. Also, null terminate the list of arguments
589 ThisWalkState
->Operands
[ThisWalkState
->NumOperands
] = NULL
;
592 * Allocate and initialize the evaluation information block
593 * TBD: this is somewhat inefficient, should change interface to
594 * DsInitAmlWalk. For now, keeps this struct off the CPU stack
596 Info
= ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO
));
599 Status
= AE_NO_MEMORY
;
603 Info
->Parameters
= &ThisWalkState
->Operands
[0];
605 Status
= AcpiDsInitAmlWalk (NextWalkState
, NULL
, MethodNode
,
606 ObjDesc
->Method
.AmlStart
, ObjDesc
->Method
.AmlLength
,
607 Info
, ACPI_IMODE_EXECUTE
);
610 if (ACPI_FAILURE (Status
))
616 * Delete the operands on the previous walkstate operand stack
617 * (they were copied to new objects)
619 for (i
= 0; i
< ObjDesc
->Method
.ParamCount
; i
++)
621 AcpiUtRemoveReference (ThisWalkState
->Operands
[i
]);
622 ThisWalkState
->Operands
[i
] = NULL
;
625 /* Clear the operand stack */
627 ThisWalkState
->NumOperands
= 0;
629 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
630 "**** Begin nested execution of [%4.4s] **** WalkState=%p\n",
631 MethodNode
->Name
.Ascii
, NextWalkState
));
633 /* Invoke an internal method if necessary */
635 if (ObjDesc
->Method
.InfoFlags
& ACPI_METHOD_INTERNAL_ONLY
)
637 Status
= ObjDesc
->Method
.Dispatch
.Implementation (NextWalkState
);
640 Status
= AE_CTRL_TERMINATE
;
644 return_ACPI_STATUS (Status
);
649 /* On error, we must terminate the method properly */
651 AcpiDsTerminateControlMethod (ObjDesc
, NextWalkState
);
652 AcpiDsDeleteWalkState (NextWalkState
);
654 return_ACPI_STATUS (Status
);
658 /*******************************************************************************
660 * FUNCTION: AcpiDsRestartControlMethod
662 * PARAMETERS: WalkState - State for preempted method (caller)
663 * ReturnDesc - Return value from the called method
667 * DESCRIPTION: Restart a method that was preempted by another (nested) method
668 * invocation. Handle the return value (if any) from the callee.
670 ******************************************************************************/
673 AcpiDsRestartControlMethod (
674 ACPI_WALK_STATE
*WalkState
,
675 ACPI_OPERAND_OBJECT
*ReturnDesc
)
678 int SameAsImplicitReturn
;
681 ACPI_FUNCTION_TRACE_PTR (DsRestartControlMethod
, WalkState
);
684 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
685 "****Restart [%4.4s] Op %p ReturnValueFromCallee %p\n",
686 AcpiUtGetNodeName (WalkState
->MethodNode
),
687 WalkState
->MethodCallOp
, ReturnDesc
));
689 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
690 " ReturnFromThisMethodUsed?=%X ResStack %p Walk %p\n",
691 WalkState
->ReturnUsed
,
692 WalkState
->Results
, WalkState
));
694 /* Did the called method return a value? */
698 /* Is the implicit return object the same as the return desc? */
700 SameAsImplicitReturn
= (WalkState
->ImplicitReturnObj
== ReturnDesc
);
702 /* Are we actually going to use the return value? */
704 if (WalkState
->ReturnUsed
)
706 /* Save the return value from the previous method */
708 Status
= AcpiDsResultPush (ReturnDesc
, WalkState
);
709 if (ACPI_FAILURE (Status
))
711 AcpiUtRemoveReference (ReturnDesc
);
712 return_ACPI_STATUS (Status
);
716 * Save as THIS method's return value in case it is returned
717 * immediately to yet another method
719 WalkState
->ReturnDesc
= ReturnDesc
;
723 * The following code is the optional support for the so-called
724 * "implicit return". Some AML code assumes that the last value of the
725 * method is "implicitly" returned to the caller, in the absence of an
726 * explicit return value.
728 * Just save the last result of the method as the return value.
730 * NOTE: this is optional because the ASL language does not actually
731 * support this behavior.
733 else if (!AcpiDsDoImplicitReturn (ReturnDesc
, WalkState
, FALSE
) ||
734 SameAsImplicitReturn
)
737 * Delete the return value if it will not be used by the
738 * calling method or remove one reference if the explicit return
739 * is the same as the implicit return value.
741 AcpiUtRemoveReference (ReturnDesc
);
745 return_ACPI_STATUS (AE_OK
);
749 /*******************************************************************************
751 * FUNCTION: AcpiDsTerminateControlMethod
753 * PARAMETERS: MethodDesc - Method object
754 * WalkState - State associated with the method
758 * DESCRIPTION: Terminate a control method. Delete everything that the method
759 * created, delete all locals and arguments, and delete the parse
762 * MUTEX: Interpreter is locked
764 ******************************************************************************/
767 AcpiDsTerminateControlMethod (
768 ACPI_OPERAND_OBJECT
*MethodDesc
,
769 ACPI_WALK_STATE
*WalkState
)
772 ACPI_FUNCTION_TRACE_PTR (DsTerminateControlMethod
, WalkState
);
775 /* MethodDesc is required, WalkState is optional */
784 /* Delete all arguments and locals */
786 AcpiDsMethodDataDeleteAll (WalkState
);
789 * Delete any namespace objects created anywhere within the
790 * namespace by the execution of this method. Unless:
791 * 1) This method is a module-level executable code method, in which
792 * case we want make the objects permanent.
793 * 2) There are other threads executing the method, in which case we
794 * will wait until the last thread has completed.
796 if (!(MethodDesc
->Method
.InfoFlags
& ACPI_METHOD_MODULE_LEVEL
) &&
797 (MethodDesc
->Method
.ThreadCount
== 1))
799 /* Delete any direct children of (created by) this method */
801 (void) AcpiExExitInterpreter ();
802 AcpiNsDeleteNamespaceSubtree (WalkState
->MethodNode
);
803 (void) AcpiExEnterInterpreter ();
806 * Delete any objects that were created by this method
807 * elsewhere in the namespace (if any were created).
808 * Use of the ACPI_METHOD_MODIFIED_NAMESPACE optimizes the
809 * deletion such that we don't have to perform an entire
810 * namespace walk for every control method execution.
812 if (MethodDesc
->Method
.InfoFlags
& ACPI_METHOD_MODIFIED_NAMESPACE
)
814 (void) AcpiExExitInterpreter ();
815 AcpiNsDeleteNamespaceByOwner (MethodDesc
->Method
.OwnerId
);
816 (void) AcpiExEnterInterpreter ();
817 MethodDesc
->Method
.InfoFlags
&=
818 ~ACPI_METHOD_MODIFIED_NAMESPACE
;
823 * If method is serialized, release the mutex and restore the
824 * current sync level for this thread
826 if (MethodDesc
->Method
.Mutex
)
828 /* Acquisition Depth handles recursive calls */
830 MethodDesc
->Method
.Mutex
->Mutex
.AcquisitionDepth
--;
831 if (!MethodDesc
->Method
.Mutex
->Mutex
.AcquisitionDepth
)
833 WalkState
->Thread
->CurrentSyncLevel
=
834 MethodDesc
->Method
.Mutex
->Mutex
.OriginalSyncLevel
;
837 MethodDesc
->Method
.Mutex
->Mutex
.OsMutex
);
838 MethodDesc
->Method
.Mutex
->Mutex
.ThreadId
= 0;
843 /* Decrement the thread count on the method */
845 if (MethodDesc
->Method
.ThreadCount
)
847 MethodDesc
->Method
.ThreadCount
--;
851 ACPI_ERROR ((AE_INFO
,
852 "Invalid zero thread count in method"));
855 /* Are there any other threads currently executing this method? */
857 if (MethodDesc
->Method
.ThreadCount
)
860 * Additional threads. Do not release the OwnerId in this case,
861 * we immediately reuse it for the next thread executing this method
863 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
864 "*** Completed execution of one thread, %u threads remaining\n",
865 MethodDesc
->Method
.ThreadCount
));
869 /* This is the only executing thread for this method */
872 * Support to dynamically change a method from NotSerialized to
873 * Serialized if it appears that the method is incorrectly written and
874 * does not support multiple thread execution. The best example of this
875 * is if such a method creates namespace objects and blocks. A second
876 * thread will fail with an AE_ALREADY_EXISTS exception.
878 * This code is here because we must wait until the last thread exits
879 * before marking the method as serialized.
881 if (MethodDesc
->Method
.InfoFlags
& ACPI_METHOD_SERIALIZED_PENDING
)
886 "Marking method %4.4s as Serialized "
887 "because of AE_ALREADY_EXISTS error",
888 WalkState
->MethodNode
->Name
.Ascii
));
892 * Method tried to create an object twice and was marked as
893 * "pending serialized". The probable cause is that the method
894 * cannot handle reentrancy.
896 * The method was created as NotSerialized, but it tried to create
897 * a named object and then blocked, causing the second thread
898 * entrance to begin and then fail. Workaround this problem by
899 * marking the method permanently as Serialized when the last
902 MethodDesc
->Method
.InfoFlags
&=
903 ~ACPI_METHOD_SERIALIZED_PENDING
;
905 MethodDesc
->Method
.InfoFlags
|=
906 (ACPI_METHOD_SERIALIZED
| ACPI_METHOD_IGNORE_SYNC_LEVEL
);
907 MethodDesc
->Method
.SyncLevel
= 0;
910 /* No more threads, we can free the OwnerId */
912 if (!(MethodDesc
->Method
.InfoFlags
& ACPI_METHOD_MODULE_LEVEL
))
914 AcpiUtReleaseOwnerId (&MethodDesc
->Method
.OwnerId
);
918 AcpiExStopTraceMethod ((ACPI_NAMESPACE_NODE
*) MethodDesc
->Method
.Node
,
919 MethodDesc
, WalkState
);