1 /******************************************************************************
3 * Module Name: dsmethod - Parser/Interpreter interface - control method parsing
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
13 * All rights reserved.
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
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
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;
38 * The above copyright and patent license is granted only if the following
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.
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
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
73 * 3.4. Intel retains all right, title, and interest in and to the Original
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.
81 * 4. Disclaimer and Export Compliance
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
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
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.
115 *****************************************************************************/
117 #define __DSMETHOD_C__
120 #include "acparser.h"
122 #include "acdispat.h"
123 #include "acinterp.h"
124 #include "acnamesp.h"
127 #define _COMPONENT ACPI_DISPATCHER
128 ACPI_MODULE_NAME ("dsmethod")
131 /*******************************************************************************
133 * FUNCTION: AcpiDsParseMethod
135 * PARAMETERS: ObjHandle - Method node
139 * DESCRIPTION: Call the parser and parse the AML that is associated with the
142 * MUTEX: Assumes parser is locked
144 ******************************************************************************/
148 ACPI_HANDLE ObjHandle
)
151 ACPI_OPERAND_OBJECT
*ObjDesc
;
152 ACPI_PARSE_OBJECT
*Op
;
153 ACPI_NAMESPACE_NODE
*Node
;
154 ACPI_OWNER_ID OwnerId
;
155 ACPI_WALK_STATE
*WalkState
;
158 ACPI_FUNCTION_TRACE_PTR ("DsParseMethod", ObjHandle
);
161 /* Parameter Validation */
165 return_ACPI_STATUS (AE_NULL_ENTRY
);
168 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE
, "**** Parsing [%4.4s] **** NamedObj=%p\n",
169 AcpiUtGetNodeName (ObjHandle
), ObjHandle
));
171 /* Extract the method object from the method Node */
173 Node
= (ACPI_NAMESPACE_NODE
*) ObjHandle
;
174 ObjDesc
= AcpiNsGetAttachedObject (Node
);
177 return_ACPI_STATUS (AE_NULL_OBJECT
);
180 /* Create a mutex for the method if there is a concurrency limit */
182 if ((ObjDesc
->Method
.Concurrency
!= ACPI_INFINITE_CONCURRENCY
) &&
183 (!ObjDesc
->Method
.Semaphore
))
185 Status
= AcpiOsCreateSemaphore (ObjDesc
->Method
.Concurrency
,
186 ObjDesc
->Method
.Concurrency
,
187 &ObjDesc
->Method
.Semaphore
);
188 if (ACPI_FAILURE (Status
))
190 return_ACPI_STATUS (Status
);
195 * Allocate a new parser op to be the root of the parsed
198 Op
= AcpiPsAllocOp (AML_METHOD_OP
);
201 return_ACPI_STATUS (AE_NO_MEMORY
);
204 /* Init new op with the method name and pointer back to the Node */
206 AcpiPsSetName (Op
, Node
->Name
.Integer
);
207 Op
->Common
.Node
= Node
;
210 * Get a new OwnerId for objects created by this method. Namespace
211 * objects (such as Operation Regions) can be created during the
214 OwnerId
= AcpiUtAllocateOwnerId (ACPI_OWNER_TYPE_METHOD
);
215 ObjDesc
->Method
.OwningId
= OwnerId
;
217 /* Create and initialize a new walk state */
219 WalkState
= AcpiDsCreateWalkState (OwnerId
, NULL
, NULL
, NULL
);
222 return_ACPI_STATUS (AE_NO_MEMORY
);
225 Status
= AcpiDsInitAmlWalk (WalkState
, Op
, Node
,
226 ObjDesc
->Method
.AmlStart
,
227 ObjDesc
->Method
.AmlLength
, NULL
, 1);
228 if (ACPI_FAILURE (Status
))
230 AcpiDsDeleteWalkState (WalkState
);
231 return_ACPI_STATUS (Status
);
235 * Parse the method, first pass
237 * The first pass load is where newly declared named objects are
238 * added into the namespace. Actual evaluation of
239 * the named objects (what would be called a "second
240 * pass") happens during the actual execution of the
241 * method so that operands to the named objects can
242 * take on dynamic run-time values.
244 Status
= AcpiPsParseAml (WalkState
);
245 if (ACPI_FAILURE (Status
))
247 return_ACPI_STATUS (Status
);
250 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE
,
251 "**** [%4.4s] Parsed **** NamedObj=%p Op=%p\n",
252 AcpiUtGetNodeName (ObjHandle
), ObjHandle
, Op
));
254 AcpiPsDeleteParseTree (Op
);
255 return_ACPI_STATUS (Status
);
259 /*******************************************************************************
261 * FUNCTION: AcpiDsBeginMethodExecution
263 * PARAMETERS: MethodNode - Node of the method
264 * ObjDesc - The method object
265 * CallingMethodNode - Caller of this method (if non-null)
269 * DESCRIPTION: Prepare a method for execution. Parses the method if necessary,
270 * increments the thread count, and waits at the method semaphore
271 * for clearance to execute.
273 ******************************************************************************/
276 AcpiDsBeginMethodExecution (
277 ACPI_NAMESPACE_NODE
*MethodNode
,
278 ACPI_OPERAND_OBJECT
*ObjDesc
,
279 ACPI_NAMESPACE_NODE
*CallingMethodNode
)
281 ACPI_STATUS Status
= AE_OK
;
284 ACPI_FUNCTION_TRACE_PTR ("DsBeginMethodExecution", MethodNode
);
289 return_ACPI_STATUS (AE_NULL_ENTRY
);
293 * If there is a concurrency limit on this method, we need to
294 * obtain a unit from the method semaphore.
296 if (ObjDesc
->Method
.Semaphore
)
299 * Allow recursive method calls, up to the reentrancy/concurrency
300 * limit imposed by the SERIALIZED rule and the SyncLevel method
303 * The point of this code is to avoid permanently blocking a
304 * thread that is making recursive method calls.
306 if (MethodNode
== CallingMethodNode
)
308 if (ObjDesc
->Method
.ThreadCount
>= ObjDesc
->Method
.Concurrency
)
310 return_ACPI_STATUS (AE_AML_METHOD_LIMIT
);
315 * Get a unit from the method semaphore. This releases the
316 * interpreter if we block
318 Status
= AcpiExSystemWaitSemaphore (ObjDesc
->Method
.Semaphore
,
323 * Increment the method parse tree thread count since it has been
324 * reentered one more time (even if it is the same thread)
326 ObjDesc
->Method
.ThreadCount
++;
327 return_ACPI_STATUS (Status
);
331 /*******************************************************************************
333 * FUNCTION: AcpiDsCallControlMethod
335 * PARAMETERS: Thread - Info for this thread
336 * ThisWalkState - Current walk state
337 * Op - Current Op to be walked
341 * DESCRIPTION: Transfer execution to a called control method
343 ******************************************************************************/
346 AcpiDsCallControlMethod (
347 ACPI_THREAD_STATE
*Thread
,
348 ACPI_WALK_STATE
*ThisWalkState
,
349 ACPI_PARSE_OBJECT
*Op
)
352 ACPI_NAMESPACE_NODE
*MethodNode
;
353 ACPI_WALK_STATE
*NextWalkState
;
354 ACPI_OPERAND_OBJECT
*ObjDesc
;
355 ACPI_PARAMETER_INFO Info
;
359 ACPI_FUNCTION_TRACE_PTR ("DsCallControlMethod", ThisWalkState
);
361 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
, "Execute method %p, currentstate=%p\n",
362 ThisWalkState
->PrevOp
, ThisWalkState
));
365 * Get the namespace entry for the control method we are about to call
367 MethodNode
= ThisWalkState
->MethodCallNode
;
370 return_ACPI_STATUS (AE_NULL_ENTRY
);
373 ObjDesc
= AcpiNsGetAttachedObject (MethodNode
);
376 return_ACPI_STATUS (AE_NULL_OBJECT
);
379 ObjDesc
->Method
.OwningId
= AcpiUtAllocateOwnerId (ACPI_OWNER_TYPE_METHOD
);
381 /* Init for new method, wait on concurrency semaphore */
383 Status
= AcpiDsBeginMethodExecution (MethodNode
, ObjDesc
,
384 ThisWalkState
->MethodNode
);
385 if (ACPI_FAILURE (Status
))
387 return_ACPI_STATUS (Status
);
390 if (!(ObjDesc
->Method
.MethodFlags
& AML_METHOD_INTERNAL_ONLY
))
392 /* 1) Parse: Create a new walk state for the preempting walk */
394 NextWalkState
= AcpiDsCreateWalkState (ObjDesc
->Method
.OwningId
,
398 return_ACPI_STATUS (AE_NO_MEMORY
);
401 /* Create and init a Root Node */
403 Op
= AcpiPsCreateScopeOp ();
406 Status
= AE_NO_MEMORY
;
410 Status
= AcpiDsInitAmlWalk (NextWalkState
, Op
, MethodNode
,
411 ObjDesc
->Method
.AmlStart
, ObjDesc
->Method
.AmlLength
,
413 if (ACPI_FAILURE (Status
))
415 AcpiDsDeleteWalkState (NextWalkState
);
419 /* Begin AML parse */
421 Status
= AcpiPsParseAml (NextWalkState
);
422 AcpiPsDeleteParseTree (Op
);
425 /* 2) Execute: Create a new state for the preempting walk */
427 NextWalkState
= AcpiDsCreateWalkState (ObjDesc
->Method
.OwningId
,
428 NULL
, ObjDesc
, Thread
);
431 Status
= AE_NO_MEMORY
;
435 * The resolved arguments were put on the previous walk state's operand
436 * stack. Operands on the previous walk state stack always
438 * Null terminate the list of arguments
440 ThisWalkState
->Operands
[ThisWalkState
->NumOperands
] = NULL
;
442 Info
.Parameters
= &ThisWalkState
->Operands
[0];
443 Info
.ParameterType
= ACPI_PARAM_ARGS
;
445 Status
= AcpiDsInitAmlWalk (NextWalkState
, NULL
, MethodNode
,
446 ObjDesc
->Method
.AmlStart
, ObjDesc
->Method
.AmlLength
,
448 if (ACPI_FAILURE (Status
))
454 * Delete the operands on the previous walkstate operand stack
455 * (they were copied to new objects)
457 for (i
= 0; i
< ObjDesc
->Method
.ParamCount
; i
++)
459 AcpiUtRemoveReference (ThisWalkState
->Operands
[i
]);
460 ThisWalkState
->Operands
[i
] = NULL
;
463 /* Clear the operand stack */
465 ThisWalkState
->NumOperands
= 0;
467 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
468 "Starting nested execution, newstate=%p\n", NextWalkState
));
470 if (ObjDesc
->Method
.MethodFlags
& AML_METHOD_INTERNAL_ONLY
)
472 Status
= ObjDesc
->Method
.Implementation (NextWalkState
);
473 return_ACPI_STATUS (Status
);
476 return_ACPI_STATUS (AE_OK
);
479 /* On error, we must delete the new walk state */
482 if (NextWalkState
&& (NextWalkState
->MethodDesc
))
484 /* Decrement the thread count on the method parse tree */
486 NextWalkState
->MethodDesc
->Method
.ThreadCount
--;
488 (void) AcpiDsTerminateControlMethod (NextWalkState
);
489 AcpiDsDeleteWalkState (NextWalkState
);
490 return_ACPI_STATUS (Status
);
494 /*******************************************************************************
496 * FUNCTION: AcpiDsRestartControlMethod
498 * PARAMETERS: WalkState - State for preempted method (caller)
499 * ReturnDesc - Return value from the called method
503 * DESCRIPTION: Restart a method that was preempted by another (nested) method
504 * invocation. Handle the return value (if any) from the callee.
506 ******************************************************************************/
509 AcpiDsRestartControlMethod (
510 ACPI_WALK_STATE
*WalkState
,
511 ACPI_OPERAND_OBJECT
*ReturnDesc
)
516 ACPI_FUNCTION_TRACE_PTR ("DsRestartControlMethod", WalkState
);
519 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
520 "****Restart [%4.4s] Op %p ReturnValueFromCallee %p\n",
521 (char *) &WalkState
->MethodNode
->Name
, WalkState
->MethodCallOp
,
524 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
525 " ReturnFromThisMethodUsed?=%X ResStack %p Walk %p\n",
526 WalkState
->ReturnUsed
,
527 WalkState
->Results
, WalkState
));
529 /* Did the called method return a value? */
533 /* Are we actually going to use the return value? */
535 if (WalkState
->ReturnUsed
)
537 /* Save the return value from the previous method */
539 Status
= AcpiDsResultPush (ReturnDesc
, WalkState
);
540 if (ACPI_FAILURE (Status
))
542 AcpiUtRemoveReference (ReturnDesc
);
543 return_ACPI_STATUS (Status
);
547 * Save as THIS method's return value in case it is returned
548 * immediately to yet another method
550 WalkState
->ReturnDesc
= ReturnDesc
;
555 * Delete the return value if it will not be used by the
558 AcpiUtRemoveReference (ReturnDesc
);
562 return_ACPI_STATUS (AE_OK
);
566 /*******************************************************************************
568 * FUNCTION: AcpiDsTerminateControlMethod
570 * PARAMETERS: WalkState - State of the method
574 * DESCRIPTION: Terminate a control method. Delete everything that the method
575 * created, delete all locals and arguments, and delete the parse
578 ******************************************************************************/
581 AcpiDsTerminateControlMethod (
582 ACPI_WALK_STATE
*WalkState
)
584 ACPI_OPERAND_OBJECT
*ObjDesc
;
585 ACPI_NAMESPACE_NODE
*MethodNode
;
589 ACPI_FUNCTION_TRACE_PTR ("DsTerminateControlMethod", WalkState
);
594 return (AE_BAD_PARAMETER
);
597 /* The current method object was saved in the walk state */
599 ObjDesc
= WalkState
->MethodDesc
;
602 return_ACPI_STATUS (AE_OK
);
605 /* Delete all arguments and locals */
607 AcpiDsMethodDataDeleteAll (WalkState
);
610 * Lock the parser while we terminate this method.
611 * If this is the last thread executing the method,
612 * we have additional cleanup to perform
614 Status
= AcpiUtAcquireMutex (ACPI_MTX_PARSER
);
615 if (ACPI_FAILURE (Status
))
617 return_ACPI_STATUS (Status
);
620 /* Signal completion of the execution of this method if necessary */
622 if (WalkState
->MethodDesc
->Method
.Semaphore
)
624 Status
= AcpiOsSignalSemaphore (
625 WalkState
->MethodDesc
->Method
.Semaphore
, 1);
626 if (ACPI_FAILURE (Status
))
628 ACPI_REPORT_ERROR (("Could not signal method semaphore\n"));
631 /* Ignore error and continue cleanup */
635 if (WalkState
->MethodDesc
->Method
.ThreadCount
)
637 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
638 "*** Not deleting method namespace, there are still %d threads\n",
639 WalkState
->MethodDesc
->Method
.ThreadCount
));
642 if (!WalkState
->MethodDesc
->Method
.ThreadCount
)
645 * Support to dynamically change a method from NotSerialized to
646 * Serialized if it appears that the method is written foolishly and
647 * does not support multiple thread execution. The best example of this
648 * is if such a method creates namespace objects and blocks. A second
649 * thread will fail with an AE_ALREADY_EXISTS exception
651 * This code is here because we must wait until the last thread exits
652 * before creating the synchronization semaphore.
654 if ((WalkState
->MethodDesc
->Method
.Concurrency
== 1) &&
655 (!WalkState
->MethodDesc
->Method
.Semaphore
))
657 Status
= AcpiOsCreateSemaphore (1,
659 &WalkState
->MethodDesc
->Method
.Semaphore
);
663 * There are no more threads executing this method. Perform
664 * additional cleanup.
666 * The method Node is stored in the walk state
668 MethodNode
= WalkState
->MethodNode
;
671 * Delete any namespace entries created immediately underneath
674 Status
= AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE
);
675 if (ACPI_FAILURE (Status
))
677 return_ACPI_STATUS (Status
);
680 if (MethodNode
->Child
)
682 AcpiNsDeleteNamespaceSubtree (MethodNode
);
686 * Delete any namespace entries created anywhere else within
689 AcpiNsDeleteNamespaceByOwner (WalkState
->MethodDesc
->Method
.OwningId
);
690 Status
= AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
691 if (ACPI_FAILURE (Status
))
693 return_ACPI_STATUS (Status
);
697 Status
= AcpiUtReleaseMutex (ACPI_MTX_PARSER
);
698 return_ACPI_STATUS (Status
);