1 /*******************************************************************************
3 * Module Name: nseval - Object evaluation interfaces -- includes control
4 * method lookup and execution.
7 ******************************************************************************/
9 /******************************************************************************
13 * Some or all of this work - Copyright (c) 1999 - 2003, Intel Corp.
14 * All rights reserved.
18 * 2.1. This is your license from Intel Corp. under its intellectual property
19 * rights. You may have additional license terms from the party that provided
20 * you this software, covering your right to use that party's intellectual
23 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24 * copy of the source code appearing in this file ("Covered Code") an
25 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26 * base code distributed originally by Intel ("Original Intel Code") to copy,
27 * make derivatives, distribute, use and display any portion of the Covered
28 * Code in any form, with the right to sublicense such rights; and
30 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31 * license (with the right to sublicense), under only those claims of Intel
32 * patents that are infringed by the Original Intel Code, to make, use, sell,
33 * offer to sell, and import the Covered Code and derivative works thereof
34 * solely to the minimum extent necessary to exercise the above copyright
35 * license, and in no event shall the patent license extend to any additions
36 * to or modifications of the Original Intel Code. No other license or right
37 * is granted directly or by implication, estoppel or otherwise;
39 * The above copyright and patent license is granted only if the following
44 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45 * Redistribution of source code of any substantial portion of the Covered
46 * Code or modification with rights to further distribute source must include
47 * the above Copyright Notice, the above License, this list of Conditions,
48 * and the following Disclaimer and Export Compliance provision. In addition,
49 * Licensee must cause all Covered Code to which Licensee contributes to
50 * contain a file documenting the changes Licensee made to create that Covered
51 * Code and the date of any change. Licensee must include in that file the
52 * documentation of any changes made by any predecessor Licensee. Licensee
53 * must include a prominent statement that the modification is derived,
54 * directly or indirectly, from Original Intel Code.
56 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57 * Redistribution of source code of any substantial portion of the Covered
58 * Code or modification without rights to further distribute source must
59 * include the following Disclaimer and Export Compliance provision in the
60 * documentation and/or other materials provided with distribution. In
61 * addition, Licensee may not authorize further sublicense of source of any
62 * portion of the Covered Code, and must include terms to the effect that the
63 * license from Licensee to its licensee is limited to the intellectual
64 * property embodied in the software Licensee provides to its licensee, and
65 * not to intellectual property embodied in modifications its licensee may
69 * 3.3. Redistribution of Executable. Redistribution in executable form of any
70 * substantial portion of the Covered Code or modification must reproduce the
71 * above Copyright Notice, and the following Disclaimer and Export Compliance
72 * provision in the documentation and/or other materials provided with the
75 * 3.4. Intel retains all right, title, and interest in and to the Original
78 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
79 * Intel shall be used in advertising or otherwise to promote the sale, use or
80 * other dealings in products derived from or relating to the Covered Code
81 * without prior written authorization from Intel.
83 * 4. Disclaimer and Export Compliance
85 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
86 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
87 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
88 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
89 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
90 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
93 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
94 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
95 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
96 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
97 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
98 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
99 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
102 * 4.3. Licensee shall not export, either directly or indirectly, any of this
103 * software or system incorporating such software without first obtaining any
104 * required license or other approval from the U. S. Department of Commerce or
105 * any other agency or department of the United States Government. In the
106 * event Licensee exports any such software from the United States or
107 * re-exports any such software from a foreign destination, Licensee shall
108 * ensure that the distribution and export/re-export of the software is in
109 * compliance with all laws, regulations, orders, or other restrictions of the
110 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
111 * any of its subsidiaries will export/re-export any technical data, process,
112 * software, or service, directly or indirectly, to any country for which the
113 * United States government or any agency thereof requires an export license,
114 * other governmental approval, or letter of assurance, without first obtaining
115 * such license, approval or letter.
117 *****************************************************************************/
118 /* $DragonFly: src/sys/contrib/dev/acpica/Attic/nseval.c,v 1.1 2003/09/24 03:32:16 drhodus Exp $ */
123 #include "acparser.h"
124 #include "acinterp.h"
125 #include "acnamesp.h"
128 #define _COMPONENT ACPI_NAMESPACE
129 ACPI_MODULE_NAME ("nseval")
132 /*******************************************************************************
134 * FUNCTION: AcpiNsEvaluateRelative
136 * PARAMETERS: Handle - The relative containing object
137 * Pathname - Name of method to execute, If NULL, the
138 * handle is the object to execute
139 * Params - List of parameters to pass to the method,
140 * terminated by NULL. Params itself may be
141 * NULL if no parameters are being passed.
142 * ReturnObject - Where to put method's return value (if
143 * any). If NULL, no value is returned.
147 * DESCRIPTION: Find and execute the requested method using the handle as a
150 * MUTEX: Locks Namespace
152 ******************************************************************************/
155 AcpiNsEvaluateRelative (
156 ACPI_NAMESPACE_NODE *Handle,
158 ACPI_OPERAND_OBJECT **Params,
159 ACPI_OPERAND_OBJECT **ReturnObject)
161 ACPI_NAMESPACE_NODE *PrefixNode;
163 ACPI_NAMESPACE_NODE *Node = NULL;
164 char *InternalPath = NULL;
165 ACPI_GENERIC_STATE ScopeInfo;
168 ACPI_FUNCTION_TRACE ("NsEvaluateRelative");
172 * Must have a valid object handle
176 return_ACPI_STATUS (AE_BAD_PARAMETER);
179 /* Build an internal name string for the method */
181 Status = AcpiNsInternalizeName (Pathname, &InternalPath);
182 if (ACPI_FAILURE (Status))
184 return_ACPI_STATUS (Status);
187 /* Get the prefix handle and Node */
189 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
190 if (ACPI_FAILURE (Status))
192 return_ACPI_STATUS (Status);
195 PrefixNode = AcpiNsMapHandleToNode (Handle);
198 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
199 Status = AE_BAD_PARAMETER;
203 /* Lookup the name in the namespace */
205 ScopeInfo.Scope.Node = PrefixNode;
206 Status = AcpiNsLookup (&ScopeInfo, InternalPath, ACPI_TYPE_ANY,
207 ACPI_IMODE_EXECUTE, ACPI_NS_NO_UPSEARCH, NULL,
210 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
212 if (ACPI_FAILURE (Status))
214 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Object [%s] not found [%s]\n",
215 Pathname, AcpiFormatException (Status)));
220 * Now that we have a handle to the object, we can attempt
223 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%s [%p] Value %p\n",
224 Pathname, Node, AcpiNsGetAttachedObject (Node)));
226 Status = AcpiNsEvaluateByHandle (Node, Params, ReturnObject);
228 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "*** Completed eval of object %s ***\n",
233 ACPI_MEM_FREE (InternalPath);
234 return_ACPI_STATUS (Status);
238 /*******************************************************************************
240 * FUNCTION: AcpiNsEvaluateByName
242 * PARAMETERS: Pathname - Fully qualified pathname to the object
243 * ReturnObject - Where to put method's return value (if
244 * any). If NULL, no value is returned.
245 * Params - List of parameters to pass to the method,
246 * terminated by NULL. Params itself may be
247 * NULL if no parameters are being passed.
251 * DESCRIPTION: Find and execute the requested method passing the given
254 * MUTEX: Locks Namespace
256 ******************************************************************************/
259 AcpiNsEvaluateByName (
261 ACPI_OPERAND_OBJECT **Params,
262 ACPI_OPERAND_OBJECT **ReturnObject)
265 ACPI_NAMESPACE_NODE *Node = NULL;
266 char *InternalPath = NULL;
269 ACPI_FUNCTION_TRACE ("NsEvaluateByName");
272 /* Build an internal name string for the method */
274 Status = AcpiNsInternalizeName (Pathname, &InternalPath);
275 if (ACPI_FAILURE (Status))
277 return_ACPI_STATUS (Status);
280 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
281 if (ACPI_FAILURE (Status))
283 return_ACPI_STATUS (Status);
286 /* Lookup the name in the namespace */
288 Status = AcpiNsLookup (NULL, InternalPath, ACPI_TYPE_ANY,
289 ACPI_IMODE_EXECUTE, ACPI_NS_NO_UPSEARCH, NULL,
292 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
294 if (ACPI_FAILURE (Status))
296 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Object at [%s] was not found, status=%.4X\n",
302 * Now that we have a handle to the object, we can attempt
305 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%s [%p] Value %p\n",
306 Pathname, Node, AcpiNsGetAttachedObject (Node)));
308 Status = AcpiNsEvaluateByHandle (Node, Params, ReturnObject);
310 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "*** Completed eval of object %s ***\n",
320 ACPI_MEM_FREE (InternalPath);
323 return_ACPI_STATUS (Status);
327 /*******************************************************************************
329 * FUNCTION: AcpiNsEvaluateByHandle
331 * PARAMETERS: Handle - Method Node to execute
332 * Params - List of parameters to pass to the method,
333 * terminated by NULL. Params itself may be
334 * NULL if no parameters are being passed.
335 * ReturnObject - Where to put method's return value (if
336 * any). If NULL, no value is returned.
340 * DESCRIPTION: Execute the requested method passing the given parameters
342 * MUTEX: Locks Namespace
344 ******************************************************************************/
347 AcpiNsEvaluateByHandle (
348 ACPI_NAMESPACE_NODE *Handle,
349 ACPI_OPERAND_OBJECT **Params,
350 ACPI_OPERAND_OBJECT **ReturnObject)
352 ACPI_NAMESPACE_NODE *Node;
354 ACPI_OPERAND_OBJECT *LocalReturnObject;
357 ACPI_FUNCTION_TRACE ("NsEvaluateByHandle");
360 /* Check if namespace has been initialized */
362 if (!AcpiGbl_RootNode)
364 return_ACPI_STATUS (AE_NO_NAMESPACE);
367 /* Parameter Validation */
371 return_ACPI_STATUS (AE_BAD_PARAMETER);
376 /* Initialize the return value to an invalid object */
378 *ReturnObject = NULL;
381 /* Get the prefix handle and Node */
383 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
384 if (ACPI_FAILURE (Status))
386 return_ACPI_STATUS (Status);
389 Node = AcpiNsMapHandleToNode (Handle);
392 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
393 return_ACPI_STATUS (AE_BAD_PARAMETER);
397 * Two major cases here:
398 * 1) The object is an actual control method -- execute it.
399 * 2) The object is not a method -- just return it's current
402 * In both cases, the namespace is unlocked by the
405 if (AcpiNsGetType (Node) == ACPI_TYPE_METHOD)
408 * Case 1) We have an actual control method to execute
410 Status = AcpiNsExecuteControlMethod (Node, Params,
416 * Case 2) Object is NOT a method, just return its
419 Status = AcpiNsGetObjectValue (Node, &LocalReturnObject);
423 * Check if there is a return value on the stack that must
426 if (Status == AE_CTRL_RETURN_VALUE)
429 * If the Method returned a value and the caller
430 * provided a place to store a returned value, Copy
431 * the returned value to the object descriptor provided
437 * Valid return object, copy the pointer to
438 * the returned object
440 *ReturnObject = LocalReturnObject;
443 /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */
449 * Namespace was unlocked by the handling AcpiNs* function,
452 return_ACPI_STATUS (Status);
456 /*******************************************************************************
458 * FUNCTION: AcpiNsExecuteControlMethod
460 * PARAMETERS: MethodNode - The method to execute
461 * Params - List of parameters to pass to the method,
462 * terminated by NULL. Params itself may be
463 * NULL if no parameters are being passed.
464 * ReturnObjDesc - List of result objects to be returned
469 * DESCRIPTION: Execute the requested method passing the given parameters
471 * MUTEX: Assumes namespace is locked
473 ******************************************************************************/
476 AcpiNsExecuteControlMethod (
477 ACPI_NAMESPACE_NODE *MethodNode,
478 ACPI_OPERAND_OBJECT **Params,
479 ACPI_OPERAND_OBJECT **ReturnObjDesc)
482 ACPI_OPERAND_OBJECT *ObjDesc;
485 ACPI_FUNCTION_TRACE ("NsExecuteControlMethod");
488 /* Verify that there is a method associated with this object */
490 ObjDesc = AcpiNsGetAttachedObject (MethodNode);
493 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No attached method object\n"));
495 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
496 return_ACPI_STATUS (AE_NULL_OBJECT);
499 ACPI_DUMP_PATHNAME (MethodNode, "Execute Method:",
500 ACPI_LV_INFO, _COMPONENT);
502 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Method at AML address %p Length %X\n",
503 ObjDesc->Method.AmlStart + 1, ObjDesc->Method.AmlLength - 1));
506 * Unlock the namespace before execution. This allows namespace access
507 * via the external Acpi* interfaces while a method is being executed.
508 * However, any namespace deletion must acquire both the namespace and
509 * interpreter locks to ensure that no thread is using the portion of the
510 * namespace that is being deleted.
512 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
513 if (ACPI_FAILURE (Status))
515 return_ACPI_STATUS (Status);
519 * Execute the method via the interpreter. The interpreter is locked
520 * here before calling into the AML parser
522 Status = AcpiExEnterInterpreter ();
523 if (ACPI_FAILURE (Status))
525 return_ACPI_STATUS (Status);
528 Status = AcpiPsxExecute (MethodNode, Params, ReturnObjDesc);
529 AcpiExExitInterpreter ();
531 return_ACPI_STATUS (Status);
535 /*******************************************************************************
537 * FUNCTION: AcpiNsGetObjectValue
539 * PARAMETERS: Node - The object
540 * ReturnObjDesc - Where the objects value is returned
544 * DESCRIPTION: Return the current value of the object
546 * MUTEX: Assumes namespace is locked, leaves namespace unlocked
548 ******************************************************************************/
551 AcpiNsGetObjectValue (
552 ACPI_NAMESPACE_NODE *Node,
553 ACPI_OPERAND_OBJECT **ReturnObjDesc)
555 ACPI_STATUS Status = AE_OK;
556 ACPI_NAMESPACE_NODE *ResolvedNode = Node;
559 ACPI_FUNCTION_TRACE ("NsGetObjectValue");
563 * Objects require additional resolution steps (e.g., the
564 * Node may be a field that must be read, etc.) -- we can't just grab
565 * the object out of the node.
569 * Use ResolveNodeToValue() to get the associated value. This call
570 * always deletes ObjDesc (allocated above).
572 * NOTE: we can get away with passing in NULL for a walk state
573 * because ObjDesc is guaranteed to not be a reference to either
574 * a method local or a method argument (because this interface can only be
575 * called from the AcpiEvaluate external interface, never called from
576 * a running control method.)
578 * Even though we do not directly invoke the interpreter
579 * for this, we must enter it because we could access an opregion.
580 * The opregion access code assumes that the interpreter
583 * We must release the namespace lock before entering the
586 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
587 if (ACPI_FAILURE (Status))
589 return_ACPI_STATUS (Status);
592 Status = AcpiExEnterInterpreter ();
593 if (ACPI_SUCCESS (Status))
595 Status = AcpiExResolveNodeToValue (&ResolvedNode, NULL);
597 * If AcpiExResolveNodeToValue() succeeded, the return value was
598 * placed in ResolvedNode.
600 AcpiExExitInterpreter ();
602 if (ACPI_SUCCESS (Status))
604 Status = AE_CTRL_RETURN_VALUE;
605 *ReturnObjDesc = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, ResolvedNode);
606 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Returning object %p [%s]\n",
607 *ReturnObjDesc, AcpiUtGetObjectTypeName (*ReturnObjDesc)));
611 /* Namespace is unlocked */
613 return_ACPI_STATUS (Status);