Update ACPI build wrappers to use new ACPICA(20050309) code.
[dragonfly.git] / sys / contrib / dev / acpica-unix-20050211 / namespace / nseval.c
blob5f40c07ab4c037d9510c6413a6bd6f7ff03a045e
1 /*******************************************************************************
3 * Module Name: nseval - Object evaluation interfaces -- includes control
4 * method lookup and execution.
5 * $Revision: 130 $
7 ******************************************************************************/
9 /******************************************************************************
11 * 1. Copyright Notice
13 * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
14 * All rights reserved.
16 * 2. License
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
21 * property rights.
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
40 * conditions are met:
42 * 3. Conditions
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
66 * make.
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
73 * distribution.
75 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * Intel Code.
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
91 * PARTICULAR PURPOSE.
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
100 * LIMITED REMEDY.
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 *****************************************************************************/
119 #define __NSEVAL_C__
121 #include "acpi.h"
122 #include "acparser.h"
123 #include "acinterp.h"
124 #include "acnamesp.h"
127 #define _COMPONENT ACPI_NAMESPACE
128 ACPI_MODULE_NAME ("nseval")
131 /*******************************************************************************
133 * FUNCTION: AcpiNsEvaluateRelative
135 * PARAMETERS: Pathname - Name of method to execute, If NULL, the
136 * handle is the object to execute
137 * Info - Method info block
139 * RETURN: Status
141 * DESCRIPTION: Find and execute the requested method using the handle as a
142 * scope
144 * MUTEX: Locks Namespace
146 ******************************************************************************/
148 ACPI_STATUS
149 AcpiNsEvaluateRelative (
150 char *Pathname,
151 ACPI_PARAMETER_INFO *Info)
153 ACPI_STATUS Status;
154 ACPI_NAMESPACE_NODE *Node = NULL;
155 ACPI_GENERIC_STATE *ScopeInfo;
156 char *InternalPath = NULL;
159 ACPI_FUNCTION_TRACE ("NsEvaluateRelative");
163 * Must have a valid object handle
165 if (!Info || !Info->Node)
167 return_ACPI_STATUS (AE_BAD_PARAMETER);
170 /* Build an internal name string for the method */
172 Status = AcpiNsInternalizeName (Pathname, &InternalPath);
173 if (ACPI_FAILURE (Status))
175 return_ACPI_STATUS (Status);
178 ScopeInfo = AcpiUtCreateGenericState ();
179 if (!ScopeInfo)
181 goto Cleanup1;
184 /* Get the prefix handle and Node */
186 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
187 if (ACPI_FAILURE (Status))
189 goto Cleanup;
192 Info->Node = AcpiNsMapHandleToNode (Info->Node);
193 if (!Info->Node)
195 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
196 Status = AE_BAD_PARAMETER;
197 goto Cleanup;
200 /* Lookup the name in the namespace */
202 ScopeInfo->Scope.Node = Info->Node;
203 Status = AcpiNsLookup (ScopeInfo, InternalPath, ACPI_TYPE_ANY,
204 ACPI_IMODE_EXECUTE, ACPI_NS_NO_UPSEARCH, NULL,
205 &Node);
207 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
209 if (ACPI_FAILURE (Status))
211 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Object [%s] not found [%s]\n",
212 Pathname, AcpiFormatException (Status)));
213 goto Cleanup;
217 * Now that we have a handle to the object, we can attempt to evaluate it.
219 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%s [%p] Value %p\n",
220 Pathname, Node, AcpiNsGetAttachedObject (Node)));
222 Info->Node = Node;
223 Status = AcpiNsEvaluateByHandle (Info);
225 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "*** Completed eval of object %s ***\n",
226 Pathname));
228 Cleanup:
229 AcpiUtDeleteGenericState (ScopeInfo);
231 Cleanup1:
232 ACPI_MEM_FREE (InternalPath);
233 return_ACPI_STATUS (Status);
237 /*******************************************************************************
239 * FUNCTION: AcpiNsEvaluateByName
241 * PARAMETERS: Pathname - Fully qualified pathname to the object
242 * Info - Contains:
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.
249 * RETURN: Status
251 * DESCRIPTION: Find and execute the requested method passing the given
252 * parameters
254 * MUTEX: Locks Namespace
256 ******************************************************************************/
258 ACPI_STATUS
259 AcpiNsEvaluateByName (
260 char *Pathname,
261 ACPI_PARAMETER_INFO *Info)
263 ACPI_STATUS Status;
264 char *InternalPath = NULL;
267 ACPI_FUNCTION_TRACE ("NsEvaluateByName");
270 /* Build an internal name string for the method */
272 Status = AcpiNsInternalizeName (Pathname, &InternalPath);
273 if (ACPI_FAILURE (Status))
275 return_ACPI_STATUS (Status);
278 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
279 if (ACPI_FAILURE (Status))
281 goto Cleanup;
284 /* Lookup the name in the namespace */
286 Status = AcpiNsLookup (NULL, InternalPath, ACPI_TYPE_ANY,
287 ACPI_IMODE_EXECUTE, ACPI_NS_NO_UPSEARCH, NULL,
288 &Info->Node);
290 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
292 if (ACPI_FAILURE (Status))
294 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
295 "Object at [%s] was not found, status=%.4X\n",
296 Pathname, Status));
297 goto Cleanup;
301 * Now that we have a handle to the object, we can attempt to evaluate it.
303 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%s [%p] Value %p\n",
304 Pathname, Info->Node, AcpiNsGetAttachedObject (Info->Node)));
306 Status = AcpiNsEvaluateByHandle (Info);
308 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "*** Completed eval of object %s ***\n",
309 Pathname));
312 Cleanup:
314 /* Cleanup */
316 if (InternalPath)
318 ACPI_MEM_FREE (InternalPath);
321 return_ACPI_STATUS (Status);
325 /*******************************************************************************
327 * FUNCTION: AcpiNsEvaluateByHandle
329 * PARAMETERS: Handle - Method Node to execute
330 * Params - List of parameters to pass to the method,
331 * terminated by NULL. Params itself may be
332 * NULL if no parameters are being passed.
333 * ParamType - Type of Parameter list
334 * ReturnObject - Where to put method's return value (if
335 * any). If NULL, no value is returned.
337 * RETURN: Status
339 * DESCRIPTION: Execute the requested method passing the given parameters
341 * MUTEX: Locks Namespace
343 ******************************************************************************/
345 ACPI_STATUS
346 AcpiNsEvaluateByHandle (
347 ACPI_PARAMETER_INFO *Info)
349 ACPI_STATUS Status;
352 ACPI_FUNCTION_TRACE ("NsEvaluateByHandle");
355 /* Check if namespace has been initialized */
357 if (!AcpiGbl_RootNode)
359 return_ACPI_STATUS (AE_NO_NAMESPACE);
362 /* Parameter Validation */
364 if (!Info)
366 return_ACPI_STATUS (AE_BAD_PARAMETER);
369 /* Initialize the return value to an invalid object */
371 Info->ReturnObject = NULL;
373 /* Get the prefix handle and Node */
375 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
376 if (ACPI_FAILURE (Status))
378 return_ACPI_STATUS (Status);
381 Info->Node = AcpiNsMapHandleToNode (Info->Node);
382 if (!Info->Node)
384 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
385 return_ACPI_STATUS (AE_BAD_PARAMETER);
389 * For a method alias, we must grab the actual method node so that proper
390 * scoping context will be established before execution.
392 if (AcpiNsGetType (Info->Node) == ACPI_TYPE_LOCAL_METHOD_ALIAS)
394 Info->Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Info->Node->Object);
398 * Two major cases here:
399 * 1) The object is an actual control method -- execute it.
400 * 2) The object is not a method -- just return it's current value
402 * In both cases, the namespace is unlocked by the AcpiNs* procedure
404 if (AcpiNsGetType (Info->Node) == ACPI_TYPE_METHOD)
407 * Case 1) We have an actual control method to execute
409 Status = AcpiNsExecuteControlMethod (Info);
411 else
414 * Case 2) Object is NOT a method, just return its current value
416 Status = AcpiNsGetObjectValue (Info);
420 * Check if there is a return value on the stack that must be dealt with
422 if (Status == AE_CTRL_RETURN_VALUE)
424 /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */
426 Status = AE_OK;
430 * Namespace was unlocked by the handling AcpiNs* function, so we
431 * just return
433 return_ACPI_STATUS (Status);
437 /*******************************************************************************
439 * FUNCTION: AcpiNsExecuteControlMethod
441 * PARAMETERS: Info - Method info block (w/params)
443 * RETURN: Status
445 * DESCRIPTION: Execute the requested method passing the given parameters
447 * MUTEX: Assumes namespace is locked
449 ******************************************************************************/
451 ACPI_STATUS
452 AcpiNsExecuteControlMethod (
453 ACPI_PARAMETER_INFO *Info)
455 ACPI_STATUS Status;
456 ACPI_OPERAND_OBJECT *ObjDesc;
459 ACPI_FUNCTION_TRACE ("NsExecuteControlMethod");
462 /* Verify that there is a method associated with this object */
464 ObjDesc = AcpiNsGetAttachedObject (Info->Node);
465 if (!ObjDesc)
467 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No attached method object\n"));
469 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
470 return_ACPI_STATUS (AE_NULL_OBJECT);
473 ACPI_DUMP_PATHNAME (Info->Node, "Execute Method:",
474 ACPI_LV_INFO, _COMPONENT);
476 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Method at AML address %p Length %X\n",
477 ObjDesc->Method.AmlStart + 1, ObjDesc->Method.AmlLength - 1));
480 * Unlock the namespace before execution. This allows namespace access
481 * via the external Acpi* interfaces while a method is being executed.
482 * However, any namespace deletion must acquire both the namespace and
483 * interpreter locks to ensure that no thread is using the portion of the
484 * namespace that is being deleted.
486 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
487 if (ACPI_FAILURE (Status))
489 return_ACPI_STATUS (Status);
493 * Execute the method via the interpreter. The interpreter is locked
494 * here before calling into the AML parser
496 Status = AcpiExEnterInterpreter ();
497 if (ACPI_FAILURE (Status))
499 return_ACPI_STATUS (Status);
502 Status = AcpiPsxExecute (Info);
503 AcpiExExitInterpreter ();
505 return_ACPI_STATUS (Status);
509 /*******************************************************************************
511 * FUNCTION: AcpiNsGetObjectValue
513 * PARAMETERS: Info - Method info block (w/params)
515 * RETURN: Status
517 * DESCRIPTION: Return the current value of the object
519 * MUTEX: Assumes namespace is locked, leaves namespace unlocked
521 ******************************************************************************/
523 ACPI_STATUS
524 AcpiNsGetObjectValue (
525 ACPI_PARAMETER_INFO *Info)
527 ACPI_STATUS Status = AE_OK;
528 ACPI_NAMESPACE_NODE *ResolvedNode = Info->Node;
531 ACPI_FUNCTION_TRACE ("NsGetObjectValue");
535 * Objects require additional resolution steps (e.g., the Node may be a
536 * field that must be read, etc.) -- we can't just grab the object out of
537 * the node.
541 * Use ResolveNodeToValue() to get the associated value. This call always
542 * deletes ObjDesc (allocated above).
544 * NOTE: we can get away with passing in NULL for a walk state because
545 * ObjDesc is guaranteed to not be a reference to either a method local or
546 * a method argument (because this interface can only be called from the
547 * AcpiEvaluate external interface, never called from a running method.)
549 * Even though we do not directly invoke the interpreter for this, we must
550 * enter it because we could access an opregion. The opregion access code
551 * assumes that the interpreter is locked.
553 * We must release the namespace lock before entering the intepreter.
555 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
556 if (ACPI_FAILURE (Status))
558 return_ACPI_STATUS (Status);
561 Status = AcpiExEnterInterpreter ();
562 if (ACPI_SUCCESS (Status))
564 Status = AcpiExResolveNodeToValue (&ResolvedNode, NULL);
566 * If AcpiExResolveNodeToValue() succeeded, the return value was placed
567 * in ResolvedNode.
569 AcpiExExitInterpreter ();
571 if (ACPI_SUCCESS (Status))
573 Status = AE_CTRL_RETURN_VALUE;
574 Info->ReturnObject = ACPI_CAST_PTR
575 (ACPI_OPERAND_OBJECT, ResolvedNode);
576 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Returning object %p [%s]\n",
577 Info->ReturnObject,
578 AcpiUtGetObjectTypeName (Info->ReturnObject)));
582 /* Namespace is unlocked */
584 return_ACPI_STATUS (Status);