1 /*******************************************************************************
3 * Module Name: nseval - Object evaluation, includes control method execution
5 ******************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * 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 *****************************************************************************/
120 #include "accommon.h"
121 #include "acparser.h"
122 #include "acinterp.h"
123 #include "acnamesp.h"
126 #define _COMPONENT ACPI_NAMESPACE
127 ACPI_MODULE_NAME ("nseval")
129 /* Local prototypes */
132 AcpiNsExecModuleCode (
133 ACPI_OPERAND_OBJECT
*MethodObj
,
134 ACPI_EVALUATE_INFO
*Info
);
137 /*******************************************************************************
139 * FUNCTION: AcpiNsEvaluate
141 * PARAMETERS: Info - Evaluation info block, contains:
142 * PrefixNode - Prefix or Method/Object Node to execute
143 * Pathname - Name of method to execute, If NULL, the
144 * Node is the object to execute
145 * Parameters - List of parameters to pass to the method,
146 * terminated by NULL. Params itself may be
147 * NULL if no parameters are being passed.
148 * ReturnObject - Where to put method's return value (if
149 * any). If NULL, no value is returned.
150 * ParameterType - Type of Parameter list
151 * ReturnObject - Where to put method's return value (if
152 * any). If NULL, no value is returned.
153 * Flags - ACPI_IGNORE_RETURN_VALUE to delete return
157 * DESCRIPTION: Execute a control method or return the current value of an
158 * ACPI namespace object.
160 * MUTEX: Locks interpreter
162 ******************************************************************************/
166 ACPI_EVALUATE_INFO
*Info
)
169 ACPI_NAMESPACE_NODE
*Node
;
172 ACPI_FUNCTION_TRACE (NsEvaluate
);
177 return_ACPI_STATUS (AE_BAD_PARAMETER
);
180 /* Initialize the return value to an invalid object */
182 Info
->ReturnObject
= NULL
;
183 Info
->ParamCount
= 0;
186 * Get the actual namespace node for the target object. Handles these cases:
188 * 1) Null node, Pathname (absolute path)
189 * 2) Node, Pathname (path relative to Node)
190 * 3) Node, Null Pathname
192 Status
= AcpiNsGetNode (Info
->PrefixNode
, Info
->Pathname
,
193 ACPI_NS_NO_UPSEARCH
, &Info
->ResolvedNode
);
194 if (ACPI_FAILURE (Status
))
196 return_ACPI_STATUS (Status
);
200 * For a method alias, we must grab the actual method node so that proper
201 * scoping context will be established before execution.
203 if (AcpiNsGetType (Info
->ResolvedNode
) == ACPI_TYPE_LOCAL_METHOD_ALIAS
)
206 ACPI_CAST_PTR (ACPI_NAMESPACE_NODE
, Info
->ResolvedNode
->Object
);
209 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES
, "%s [%p] Value %p\n", Info
->Pathname
,
210 Info
->ResolvedNode
, AcpiNsGetAttachedObject (Info
->ResolvedNode
)));
212 Node
= Info
->ResolvedNode
;
215 * Two major cases here:
217 * 1) The object is a control method -- execute it
218 * 2) The object is not a method -- just return it's current value
220 if (AcpiNsGetType (Info
->ResolvedNode
) == ACPI_TYPE_METHOD
)
223 * 1) Object is a control method - execute it
226 /* Verify that there is a method object associated with this node */
228 Info
->ObjDesc
= AcpiNsGetAttachedObject (Info
->ResolvedNode
);
231 ACPI_ERROR ((AE_INFO
, "Control method has no attached sub-object"));
232 return_ACPI_STATUS (AE_NULL_OBJECT
);
235 /* Count the number of arguments being passed to the method */
237 if (Info
->Parameters
)
239 while (Info
->Parameters
[Info
->ParamCount
])
241 if (Info
->ParamCount
> ACPI_METHOD_MAX_ARG
)
243 return_ACPI_STATUS (AE_LIMIT
);
249 ACPI_DUMP_PATHNAME (Info
->ResolvedNode
, "ACPI: Execute Method",
250 ACPI_LV_INFO
, _COMPONENT
);
252 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
253 "Method at AML address %p Length %X\n",
254 Info
->ObjDesc
->Method
.AmlStart
+ 1,
255 Info
->ObjDesc
->Method
.AmlLength
- 1));
258 * Any namespace deletion must acquire both the namespace and
259 * interpreter locks to ensure that no thread is using the portion of
260 * the namespace that is being deleted.
262 * Execute the method via the interpreter. The interpreter is locked
263 * here before calling into the AML parser
265 AcpiExEnterInterpreter ();
266 Status
= AcpiPsExecuteMethod (Info
);
267 AcpiExExitInterpreter ();
272 * 2) Object is not a method, return its current value
274 * Disallow certain object types. For these, "evaluation" is undefined.
276 switch (Info
->ResolvedNode
->Type
)
278 case ACPI_TYPE_DEVICE
:
279 case ACPI_TYPE_EVENT
:
280 case ACPI_TYPE_MUTEX
:
281 case ACPI_TYPE_REGION
:
282 case ACPI_TYPE_THERMAL
:
283 case ACPI_TYPE_LOCAL_SCOPE
:
285 ACPI_ERROR ((AE_INFO
,
286 "[%4.4s] Evaluation of object type [%s] is not supported",
287 Info
->ResolvedNode
->Name
.Ascii
,
288 AcpiUtGetTypeName (Info
->ResolvedNode
->Type
)));
290 return_ACPI_STATUS (AE_TYPE
);
297 * Objects require additional resolution steps (e.g., the Node may be
298 * a field that must be read, etc.) -- we can't just grab the object
301 * Use ResolveNodeToValue() to get the associated value.
303 * NOTE: we can get away with passing in NULL for a walk state because
304 * ResolvedNode is guaranteed to not be a reference to either a method
305 * local or a method argument (because this interface is never called
306 * from a running method.)
308 * Even though we do not directly invoke the interpreter for object
309 * resolution, we must lock it because we could access an opregion.
310 * The opregion access code assumes that the interpreter is locked.
312 AcpiExEnterInterpreter ();
314 /* Function has a strange interface */
316 Status
= AcpiExResolveNodeToValue (&Info
->ResolvedNode
, NULL
);
317 AcpiExExitInterpreter ();
320 * If AcpiExResolveNodeToValue() succeeded, the return value was placed
323 if (ACPI_SUCCESS (Status
))
325 Status
= AE_CTRL_RETURN_VALUE
;
327 ACPI_CAST_PTR (ACPI_OPERAND_OBJECT
, Info
->ResolvedNode
);
329 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES
, "Returning object %p [%s]\n",
331 AcpiUtGetObjectTypeName (Info
->ReturnObject
)));
336 * Check input argument count against the ASL-defined count for a method.
337 * Also check predefined names: argument count and return value against
338 * the ACPI specification. Some incorrect return value types are repaired.
340 (void) AcpiNsCheckPredefinedNames (Node
, Info
->ParamCount
,
341 Status
, &Info
->ReturnObject
);
343 /* Check if there is a return value that must be dealt with */
345 if (Status
== AE_CTRL_RETURN_VALUE
)
347 /* If caller does not want the return value, delete it */
349 if (Info
->Flags
& ACPI_IGNORE_RETURN_VALUE
)
351 AcpiUtRemoveReference (Info
->ReturnObject
);
352 Info
->ReturnObject
= NULL
;
355 /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */
360 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES
,
361 "*** Completed evaluation of object %s ***\n", Info
->Pathname
));
364 * Namespace was unlocked by the handling AcpiNs* function, so we
367 return_ACPI_STATUS (Status
);
371 /*******************************************************************************
373 * FUNCTION: AcpiNsExecModuleCodeList
377 * RETURN: None. Exceptions during method execution are ignored, since
378 * we cannot abort a table load.
380 * DESCRIPTION: Execute all elements of the global module-level code list.
381 * Each element is executed as a single control method.
383 ******************************************************************************/
386 AcpiNsExecModuleCodeList (
389 ACPI_OPERAND_OBJECT
*Prev
;
390 ACPI_OPERAND_OBJECT
*Next
;
391 ACPI_EVALUATE_INFO
*Info
;
392 UINT32 MethodCount
= 0;
395 ACPI_FUNCTION_TRACE (NsExecModuleCodeList
);
398 /* Exit now if the list is empty */
400 Next
= AcpiGbl_ModuleCodeList
;
406 /* Allocate the evaluation information block */
408 Info
= ACPI_ALLOCATE (sizeof (ACPI_EVALUATE_INFO
));
414 /* Walk the list, executing each "method" */
419 Next
= Next
->Method
.Mutex
;
421 /* Clear the link field and execute the method */
423 Prev
->Method
.Mutex
= NULL
;
424 AcpiNsExecModuleCode (Prev
, Info
);
427 /* Delete the (temporary) method object */
429 AcpiUtRemoveReference (Prev
);
433 "Executed %u blocks of module-level executable AML code",
437 AcpiGbl_ModuleCodeList
= NULL
;
442 /*******************************************************************************
444 * FUNCTION: AcpiNsExecModuleCode
446 * PARAMETERS: MethodObj - Object container for the module-level code
447 * Info - Info block for method evaluation
449 * RETURN: None. Exceptions during method execution are ignored, since
450 * we cannot abort a table load.
452 * DESCRIPTION: Execute a control method containing a block of module-level
453 * executable AML code. The control method is temporarily
454 * installed to the root node, then evaluated.
456 ******************************************************************************/
459 AcpiNsExecModuleCode (
460 ACPI_OPERAND_OBJECT
*MethodObj
,
461 ACPI_EVALUATE_INFO
*Info
)
463 ACPI_OPERAND_OBJECT
*ParentObj
;
464 ACPI_NAMESPACE_NODE
*ParentNode
;
465 ACPI_OBJECT_TYPE Type
;
469 ACPI_FUNCTION_TRACE (NsExecModuleCode
);
473 * Get the parent node. We cheat by using the NextObject field
474 * of the method object descriptor.
476 ParentNode
= ACPI_CAST_PTR (ACPI_NAMESPACE_NODE
,
477 MethodObj
->Method
.NextObject
);
478 Type
= AcpiNsGetType (ParentNode
);
481 * Get the region handler and save it in the method object. We may need
482 * this if an operation region declaration causes a _REG method to be run.
484 * We can't do this in AcpiPsLinkModuleCode because
485 * AcpiGbl_RootNode->Object is NULL at PASS1.
487 if ((Type
== ACPI_TYPE_DEVICE
) && ParentNode
->Object
)
489 MethodObj
->Method
.Extra
.Handler
=
490 ParentNode
->Object
->Device
.Handler
;
493 /* Must clear NextObject (AcpiNsAttachObject needs the field) */
495 MethodObj
->Method
.NextObject
= NULL
;
497 /* Initialize the evaluation information block */
499 ACPI_MEMSET (Info
, 0, sizeof (ACPI_EVALUATE_INFO
));
500 Info
->PrefixNode
= ParentNode
;
503 * Get the currently attached parent object. Add a reference, because the
504 * ref count will be decreased when the method object is installed to
507 ParentObj
= AcpiNsGetAttachedObject (ParentNode
);
510 AcpiUtAddReference (ParentObj
);
513 /* Install the method (module-level code) in the parent node */
515 Status
= AcpiNsAttachObject (ParentNode
, MethodObj
,
517 if (ACPI_FAILURE (Status
))
522 /* Execute the parent node as a control method */
524 Status
= AcpiNsEvaluate (Info
);
526 ACPI_DEBUG_PRINT ((ACPI_DB_INIT
, "Executed module-level code at %p\n",
527 MethodObj
->Method
.AmlStart
));
529 /* Delete a possible implicit return value (in slack mode) */
531 if (Info
->ReturnObject
)
533 AcpiUtRemoveReference (Info
->ReturnObject
);
536 /* Detach the temporary method object */
538 AcpiNsDetachObject (ParentNode
);
540 /* Restore the original parent object */
544 Status
= AcpiNsAttachObject (ParentNode
, ParentObj
, Type
);
548 ParentNode
->Type
= (UINT8
) Type
;
554 AcpiUtRemoveReference (ParentObj
);