1 /*******************************************************************************
3 * Module Name: nseval - Object evaluation, includes control method execution
5 ******************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2009, 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 *****************************************************************************/
119 #include <contrib/dev/acpica/include/acpi.h>
120 #include <contrib/dev/acpica/include/accommon.h>
121 #include <contrib/dev/acpica/include/acparser.h>
122 #include <contrib/dev/acpica/include/acinterp.h>
123 #include <contrib/dev/acpica/include/acnamesp.h>
126 #define _COMPONENT ACPI_NAMESPACE
127 ACPI_MODULE_NAME ("nseval")
130 /*******************************************************************************
132 * FUNCTION: AcpiNsEvaluate
134 * PARAMETERS: Info - Evaluation info block, contains:
135 * PrefixNode - Prefix or Method/Object Node to execute
136 * Pathname - Name of method to execute, If NULL, the
137 * Node is the object to execute
138 * Parameters - List of parameters to pass to the method,
139 * terminated by NULL. Params itself may be
140 * NULL if no parameters are being passed.
141 * ReturnObject - Where to put method's return value (if
142 * any). If NULL, no value is returned.
143 * ParameterType - Type of Parameter list
144 * ReturnObject - Where to put method's return value (if
145 * any). If NULL, no value is returned.
146 * Flags - ACPI_IGNORE_RETURN_VALUE to delete return
150 * DESCRIPTION: Execute a control method or return the current value of an
151 * ACPI namespace object.
153 * MUTEX: Locks interpreter
155 ******************************************************************************/
159 ACPI_EVALUATE_INFO *Info)
162 ACPI_NAMESPACE_NODE *Node;
165 ACPI_FUNCTION_TRACE (NsEvaluate);
170 return_ACPI_STATUS (AE_BAD_PARAMETER);
173 /* Initialize the return value to an invalid object */
175 Info->ReturnObject = NULL;
176 Info->ParamCount = 0;
179 * Get the actual namespace node for the target object. Handles these cases:
181 * 1) Null node, Pathname (absolute path)
182 * 2) Node, Pathname (path relative to Node)
183 * 3) Node, Null Pathname
185 Status = AcpiNsGetNode (Info->PrefixNode, Info->Pathname,
186 ACPI_NS_NO_UPSEARCH, &Info->ResolvedNode);
187 if (ACPI_FAILURE (Status))
189 return_ACPI_STATUS (Status);
193 * For a method alias, we must grab the actual method node so that proper
194 * scoping context will be established before execution.
196 if (AcpiNsGetType (Info->ResolvedNode) == ACPI_TYPE_LOCAL_METHOD_ALIAS)
199 ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Info->ResolvedNode->Object);
202 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%s [%p] Value %p\n", Info->Pathname,
203 Info->ResolvedNode, AcpiNsGetAttachedObject (Info->ResolvedNode)));
205 Node = Info->ResolvedNode;
208 * Two major cases here:
210 * 1) The object is a control method -- execute it
211 * 2) The object is not a method -- just return it's current value
213 if (AcpiNsGetType (Info->ResolvedNode) == ACPI_TYPE_METHOD)
216 * 1) Object is a control method - execute it
219 /* Verify that there is a method object associated with this node */
221 Info->ObjDesc = AcpiNsGetAttachedObject (Info->ResolvedNode);
224 ACPI_ERROR ((AE_INFO, "Control method has no attached sub-object"));
225 return_ACPI_STATUS (AE_NULL_OBJECT);
228 /* Count the number of arguments being passed to the method */
230 if (Info->Parameters)
232 while (Info->Parameters[Info->ParamCount])
234 if (Info->ParamCount > ACPI_METHOD_MAX_ARG)
236 return_ACPI_STATUS (AE_LIMIT);
242 ACPI_DUMP_PATHNAME (Info->ResolvedNode, "ACPI: Execute Method",
243 ACPI_LV_INFO, _COMPONENT);
245 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
246 "Method at AML address %p Length %X\n",
247 Info->ObjDesc->Method.AmlStart + 1,
248 Info->ObjDesc->Method.AmlLength - 1));
251 * Any namespace deletion must acquire both the namespace and
252 * interpreter locks to ensure that no thread is using the portion of
253 * the namespace that is being deleted.
255 * Execute the method via the interpreter. The interpreter is locked
256 * here before calling into the AML parser
258 AcpiExEnterInterpreter ();
259 Status = AcpiPsExecuteMethod (Info);
260 AcpiExExitInterpreter ();
265 * 2) Object is not a method, return its current value
267 * Disallow certain object types. For these, "evaluation" is undefined.
269 switch (Info->ResolvedNode->Type)
271 case ACPI_TYPE_DEVICE:
272 case ACPI_TYPE_EVENT:
273 case ACPI_TYPE_MUTEX:
274 case ACPI_TYPE_REGION:
275 case ACPI_TYPE_THERMAL:
276 case ACPI_TYPE_LOCAL_SCOPE:
278 ACPI_ERROR ((AE_INFO,
279 "[%4.4s] Evaluation of object type [%s] is not supported",
280 Info->ResolvedNode->Name.Ascii,
281 AcpiUtGetTypeName (Info->ResolvedNode->Type)));
283 return_ACPI_STATUS (AE_TYPE);
290 * Objects require additional resolution steps (e.g., the Node may be
291 * a field that must be read, etc.) -- we can't just grab the object
294 * Use ResolveNodeToValue() to get the associated value.
296 * NOTE: we can get away with passing in NULL for a walk state because
297 * ResolvedNode is guaranteed to not be a reference to either a method
298 * local or a method argument (because this interface is never called
299 * from a running method.)
301 * Even though we do not directly invoke the interpreter for object
302 * resolution, we must lock it because we could access an opregion.
303 * The opregion access code assumes that the interpreter is locked.
305 AcpiExEnterInterpreter ();
307 /* Function has a strange interface */
309 Status = AcpiExResolveNodeToValue (&Info->ResolvedNode, NULL);
310 AcpiExExitInterpreter ();
313 * If AcpiExResolveNodeToValue() succeeded, the return value was placed
316 if (ACPI_SUCCESS (Status))
318 Status = AE_CTRL_RETURN_VALUE;
320 ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Info->ResolvedNode);
322 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Returning object %p [%s]\n",
324 AcpiUtGetObjectTypeName (Info->ReturnObject)));
329 * Check input argument count against the ASL-defined count for a method.
330 * Also check predefined names: argument count and return value against
331 * the ACPI specification. Some incorrect return value types are repaired.
333 (void) AcpiNsCheckPredefinedNames (Node, Info->ParamCount,
334 Status, &Info->ReturnObject);
336 /* Check if there is a return value that must be dealt with */
338 if (Status == AE_CTRL_RETURN_VALUE)
340 /* If caller does not want the return value, delete it */
342 if (Info->Flags & ACPI_IGNORE_RETURN_VALUE)
344 AcpiUtRemoveReference (Info->ReturnObject);
345 Info->ReturnObject = NULL;
348 /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */
353 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
354 "*** Completed evaluation of object %s ***\n", Info->Pathname));
357 * Namespace was unlocked by the handling AcpiNs* function, so we
360 return_ACPI_STATUS (Status);