1 /*******************************************************************************
3 * Module Name: nsxfeval - Public interfaces to the ACPI subsystem
4 * ACPI Object evaluation interfaces
7 ******************************************************************************/
9 /******************************************************************************
13 * Some or all of this work - Copyright (c) 1999 - 2005, 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
68 * 3.3. Redistribution of Executable. Redistribution in executable form of any
69 * substantial portion of the Covered Code or modification must reproduce the
70 * above Copyright Notice, and the following Disclaimer and Export Compliance
71 * provision in the documentation and/or other materials provided with the
74 * 3.4. Intel retains all right, title, and interest in and to the Original
77 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78 * Intel shall be used in advertising or otherwise to promote the sale, use or
79 * other dealings in products derived from or relating to the Covered Code
80 * without prior written authorization from Intel.
82 * 4. Disclaimer and Export Compliance
84 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
87 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
88 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
89 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
92 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
98 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
101 * 4.3. Licensee shall not export, either directly or indirectly, any of this
102 * software or system incorporating such software without first obtaining any
103 * required license or other approval from the U. S. Department of Commerce or
104 * any other agency or department of the United States Government. In the
105 * event Licensee exports any such software from the United States or
106 * re-exports any such software from a foreign destination, Licensee shall
107 * ensure that the distribution and export/re-export of the software is in
108 * compliance with all laws, regulations, orders, or other restrictions of the
109 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110 * any of its subsidiaries will export/re-export any technical data, process,
111 * software, or service, directly or indirectly, to any country for which the
112 * United States government or any agency thereof requires an export license,
113 * other governmental approval, or letter of assurance, without first obtaining
114 * such license, approval or letter.
116 *****************************************************************************/
119 #define __NSXFEVAL_C__
122 #include "acnamesp.h"
123 #include "acinterp.h"
126 #define _COMPONENT ACPI_NAMESPACE
127 ACPI_MODULE_NAME ("nsxfeval")
130 /*******************************************************************************
132 * FUNCTION: AcpiEvaluateObjectTyped
134 * PARAMETERS: Handle - Object handle (optional)
135 * *Pathname - Object pathname (optional)
136 * **ExternalParams - List of parameters to pass to method,
137 * terminated by NULL. May be NULL
138 * if no parameters are being passed.
139 * *ReturnBuffer - Where to put method's return value (if
140 * any). If NULL, no value is returned.
141 * ReturnType - Expected type of return object
145 * DESCRIPTION: Find and evaluate the given object, passing the given
146 * parameters if necessary. One of "Handle" or "Pathname" must
147 * be valid (non-null)
149 ******************************************************************************/
152 AcpiEvaluateObjectTyped (
154 ACPI_STRING Pathname,
155 ACPI_OBJECT_LIST *ExternalParams,
156 ACPI_BUFFER *ReturnBuffer,
157 ACPI_OBJECT_TYPE ReturnType)
160 BOOLEAN MustFree = FALSE;
163 ACPI_FUNCTION_TRACE ("AcpiEvaluateObjectTyped");
166 /* Return buffer must be valid */
170 return_ACPI_STATUS (AE_BAD_PARAMETER);
173 if (ReturnBuffer->Length == ACPI_ALLOCATE_BUFFER)
178 /* Evaluate the object */
180 Status = AcpiEvaluateObject (Handle, Pathname, ExternalParams, ReturnBuffer);
181 if (ACPI_FAILURE (Status))
183 return_ACPI_STATUS (Status);
186 /* Type ANY means "don't care" */
188 if (ReturnType == ACPI_TYPE_ANY)
190 return_ACPI_STATUS (AE_OK);
193 if (ReturnBuffer->Length == 0)
195 /* Error because caller specifically asked for a return value */
197 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
198 "No return value\n"));
200 return_ACPI_STATUS (AE_NULL_OBJECT);
203 /* Examine the object type returned from EvaluateObject */
205 if (((ACPI_OBJECT *) ReturnBuffer->Pointer)->Type == ReturnType)
207 return_ACPI_STATUS (AE_OK);
210 /* Return object type does not match requested type */
212 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
213 "Incorrect return type [%s] requested [%s]\n",
214 AcpiUtGetTypeName (((ACPI_OBJECT *) ReturnBuffer->Pointer)->Type),
215 AcpiUtGetTypeName (ReturnType)));
219 /* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */
221 AcpiOsFree (ReturnBuffer->Pointer);
222 ReturnBuffer->Pointer = NULL;
225 ReturnBuffer->Length = 0;
226 return_ACPI_STATUS (AE_TYPE);
230 /*******************************************************************************
232 * FUNCTION: AcpiEvaluateObject
234 * PARAMETERS: Handle - Object handle (optional)
235 * Pathname - Object pathname (optional)
236 * ExternalParams - List of parameters to pass to method,
237 * terminated by NULL. May be NULL
238 * if no parameters are being passed.
239 * ReturnBuffer - Where to put method's return value (if
240 * any). If NULL, no value is returned.
244 * DESCRIPTION: Find and evaluate the given object, passing the given
245 * parameters if necessary. One of "Handle" or "Pathname" must
246 * be valid (non-null)
248 ******************************************************************************/
253 ACPI_STRING Pathname,
254 ACPI_OBJECT_LIST *ExternalParams,
255 ACPI_BUFFER *ReturnBuffer)
259 ACPI_PARAMETER_INFO Info;
260 ACPI_SIZE BufferSpaceNeeded;
264 ACPI_FUNCTION_TRACE ("AcpiEvaluateObject");
268 Info.Parameters = NULL;
269 Info.ReturnObject = NULL;
270 Info.ParameterType = ACPI_PARAM_ARGS;
273 * If there are parameters to be passed to the object
274 * (which must be a control method), the external objects
275 * must be converted to internal objects
277 if (ExternalParams && ExternalParams->Count)
280 * Allocate a new parameter block for the internal objects
281 * Add 1 to count to allow for null terminated internal list
283 Info.Parameters = ACPI_MEM_CALLOCATE (
284 ((ACPI_SIZE) ExternalParams->Count + 1) *
286 if (!Info.Parameters)
288 return_ACPI_STATUS (AE_NO_MEMORY);
292 * Convert each external object in the list to an
295 for (i = 0; i < ExternalParams->Count; i++)
297 Status = AcpiUtCopyEobjectToIobject (&ExternalParams->Pointer[i],
298 &Info.Parameters[i]);
299 if (ACPI_FAILURE (Status))
301 AcpiUtDeleteInternalObjectList (Info.Parameters);
302 return_ACPI_STATUS (Status);
305 Info.Parameters[ExternalParams->Count] = NULL;
311 * 1) Fully qualified pathname
312 * 2) No handle, not fully qualified pathname (error)
316 (AcpiNsValidRootPrefix (Pathname[0])))
319 * The path is fully qualified, just evaluate by name
321 Status = AcpiNsEvaluateByName (Pathname, &Info);
326 * A handle is optional iff a fully qualified pathname
327 * is specified. Since we've already handled fully
328 * qualified names above, this is an error
332 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
333 "Both Handle and Pathname are NULL\n"));
337 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
338 "Handle is NULL and Pathname is relative\n"));
341 Status = AE_BAD_PARAMETER;
346 * We get here if we have a handle -- and if we have a
347 * pathname it is relative. The handle will be validated
348 * in the lower procedures
353 * The null pathname case means the handle is for
354 * the actual object to be evaluated
356 Status = AcpiNsEvaluateByHandle (&Info);
361 * Both a Handle and a relative Pathname
363 Status = AcpiNsEvaluateRelative (Pathname, &Info);
369 * If we are expecting a return value, and all went well above,
370 * copy the return value to an external object.
374 if (!Info.ReturnObject)
376 ReturnBuffer->Length = 0;
380 if (ACPI_GET_DESCRIPTOR_TYPE (Info.ReturnObject) == ACPI_DESC_TYPE_NAMED)
383 * If we received a NS Node as a return object, this means that
384 * the object we are evaluating has nothing interesting to
385 * return (such as a mutex, etc.) We return an error because
386 * these types are essentially unsupported by this interface.
387 * We don't check up front because this makes it easier to add
388 * support for various types at a later date if necessary.
391 Info.ReturnObject = NULL; /* No need to delete a NS Node */
392 ReturnBuffer->Length = 0;
395 if (ACPI_SUCCESS (Status))
398 * Find out how large a buffer is needed
399 * to contain the returned object
401 Status = AcpiUtGetObjectSize (Info.ReturnObject,
403 if (ACPI_SUCCESS (Status))
405 /* Validate/Allocate/Clear caller buffer */
407 Status = AcpiUtInitializeBuffer (ReturnBuffer, BufferSpaceNeeded);
408 if (ACPI_FAILURE (Status))
411 * Caller's buffer is too small or a new one can't be allocated
413 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
414 "Needed buffer size %X, %s\n",
415 (UINT32) BufferSpaceNeeded,
416 AcpiFormatException (Status)));
421 * We have enough space for the object, build it
423 Status = AcpiUtCopyIobjectToEobject (Info.ReturnObject,
431 if (Info.ReturnObject)
434 * Delete the internal return object. NOTE: Interpreter
435 * must be locked to avoid race condition.
437 Status2 = AcpiExEnterInterpreter ();
438 if (ACPI_SUCCESS (Status2))
441 * Delete the internal return object. (Or at least
442 * decrement the reference count by one)
444 AcpiUtRemoveReference (Info.ReturnObject);
445 AcpiExExitInterpreter ();
450 * Free the input parameter list (if we created one),
454 /* Free the allocated parameter block */
456 AcpiUtDeleteInternalObjectList (Info.Parameters);
459 return_ACPI_STATUS (Status);
463 /*******************************************************************************
465 * FUNCTION: AcpiWalkNamespace
467 * PARAMETERS: Type - ACPI_OBJECT_TYPE to search for
468 * StartObject - Handle in namespace where search begins
469 * MaxDepth - Depth to which search is to reach
470 * UserFunction - Called when an object of "Type" is found
471 * Context - Passed to user function
472 * ReturnValue - Location where return value of
473 * UserFunction is put if terminated early
475 * RETURNS Return value from the UserFunction if terminated early.
476 * Otherwise, returns NULL.
478 * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
479 * starting (and ending) at the object specified by StartHandle.
480 * The UserFunction is called whenever an object that matches
481 * the type parameter is found. If the user function returns
482 * a non-zero value, the search is terminated immediately and this
483 * value is returned to the caller.
485 * The point of this procedure is to provide a generic namespace
486 * walk routine that can be called from multiple places to
487 * provide multiple services; the User Function can be tailored
488 * to each task, whether it is a print function, a compare
491 ******************************************************************************/
495 ACPI_OBJECT_TYPE Type,
496 ACPI_HANDLE StartObject,
498 ACPI_WALK_CALLBACK UserFunction,
505 ACPI_FUNCTION_TRACE ("AcpiWalkNamespace");
508 /* Parameter validation */
510 if ((Type > ACPI_TYPE_EXTERNAL_MAX) ||
514 return_ACPI_STATUS (AE_BAD_PARAMETER);
518 * Lock the namespace around the walk.
519 * The namespace will be unlocked/locked around each call
520 * to the user function - since this function
521 * must be allowed to make Acpi calls itself.
523 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
524 if (ACPI_FAILURE (Status))
526 return_ACPI_STATUS (Status);
529 Status = AcpiNsWalkNamespace (Type, StartObject, MaxDepth, ACPI_NS_WALK_UNLOCK,
530 UserFunction, Context, ReturnValue);
532 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
533 return_ACPI_STATUS (Status);
537 /*******************************************************************************
539 * FUNCTION: AcpiNsGetDeviceCallback
541 * PARAMETERS: Callback from AcpiGetDevice
545 * DESCRIPTION: Takes callbacks from WalkNamespace and filters out all non-
546 * present devices, or if they specified a HID, it filters based
549 ******************************************************************************/
552 AcpiNsGetDeviceCallback (
553 ACPI_HANDLE ObjHandle,
558 ACPI_GET_DEVICES_INFO *Info = Context;
560 ACPI_NAMESPACE_NODE *Node;
563 ACPI_COMPATIBLE_ID_LIST *Cid;
567 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
568 if (ACPI_FAILURE (Status))
573 Node = AcpiNsMapHandleToNode (ObjHandle);
574 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
575 if (ACPI_FAILURE (Status))
582 return (AE_BAD_PARAMETER);
585 /* Run _STA to determine if device is present */
587 Status = AcpiUtExecute_STA (Node, &Flags);
588 if (ACPI_FAILURE (Status))
590 return (AE_CTRL_DEPTH);
595 /* Don't return at the device or children of the device if not there */
597 return (AE_CTRL_DEPTH);
600 /* Filter based on device HID & CID */
602 if (Info->Hid != NULL)
604 Status = AcpiUtExecute_HID (Node, &Hid);
605 if (Status == AE_NOT_FOUND)
609 else if (ACPI_FAILURE (Status))
611 return (AE_CTRL_DEPTH);
614 if (ACPI_STRNCMP (Hid.Value, Info->Hid, sizeof (Hid.Value)) != 0)
616 /* Get the list of Compatible IDs */
618 Status = AcpiUtExecute_CID (Node, &Cid);
619 if (Status == AE_NOT_FOUND)
623 else if (ACPI_FAILURE (Status))
625 return (AE_CTRL_DEPTH);
628 /* Walk the CID list */
630 for (i = 0; i < Cid->Count; i++)
632 if (ACPI_STRNCMP (Cid->Id[i].Value, Info->Hid,
633 sizeof (ACPI_COMPATIBLE_ID)) != 0)
643 Status = Info->UserFunction (ObjHandle, NestingLevel, Info->Context, ReturnValue);
648 /*******************************************************************************
650 * FUNCTION: AcpiGetDevices
652 * PARAMETERS: HID - HID to search for. Can be NULL.
653 * UserFunction - Called when a matching object is found
654 * Context - Passed to user function
655 * ReturnValue - Location where return value of
656 * UserFunction is put if terminated early
658 * RETURNS Return value from the UserFunction if terminated early.
659 * Otherwise, returns NULL.
661 * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
662 * starting (and ending) at the object specified by StartHandle.
663 * The UserFunction is called whenever an object of type
664 * Device is found. If the user function returns
665 * a non-zero value, the search is terminated immediately and this
666 * value is returned to the caller.
668 * This is a wrapper for WalkNamespace, but the callback performs
669 * additional filtering. Please see AcpiGetDeviceCallback.
671 ******************************************************************************/
676 ACPI_WALK_CALLBACK UserFunction,
681 ACPI_GET_DEVICES_INFO Info;
684 ACPI_FUNCTION_TRACE ("AcpiGetDevices");
687 /* Parameter validation */
691 return_ACPI_STATUS (AE_BAD_PARAMETER);
695 * We're going to call their callback from OUR callback, so we need
696 * to know what it is, and their context parameter.
698 Info.Context = Context;
699 Info.UserFunction = UserFunction;
703 * Lock the namespace around the walk.
704 * The namespace will be unlocked/locked around each call
705 * to the user function - since this function
706 * must be allowed to make Acpi calls itself.
708 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
709 if (ACPI_FAILURE (Status))
711 return_ACPI_STATUS (Status);
714 Status = AcpiNsWalkNamespace (ACPI_TYPE_DEVICE,
715 ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
717 AcpiNsGetDeviceCallback, &Info,
720 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
721 return_ACPI_STATUS (Status);
725 /*******************************************************************************
727 * FUNCTION: AcpiAttachData
729 * PARAMETERS: ObjHandle - Namespace node
730 * Handler - Handler for this attachment
731 * Data - Pointer to data to be attached
735 * DESCRIPTION: Attach arbitrary data and handler to a namespace node.
737 ******************************************************************************/
741 ACPI_HANDLE ObjHandle,
742 ACPI_OBJECT_HANDLER Handler,
745 ACPI_NAMESPACE_NODE *Node;
749 /* Parameter validation */
755 return (AE_BAD_PARAMETER);
758 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
759 if (ACPI_FAILURE (Status))
764 /* Convert and validate the handle */
766 Node = AcpiNsMapHandleToNode (ObjHandle);
769 Status = AE_BAD_PARAMETER;
773 Status = AcpiNsAttachData (Node, Handler, Data);
776 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
781 /*******************************************************************************
783 * FUNCTION: AcpiDetachData
785 * PARAMETERS: ObjHandle - Namespace node handle
786 * Handler - Handler used in call to AcpiAttachData
790 * DESCRIPTION: Remove data that was previously attached to a node.
792 ******************************************************************************/
796 ACPI_HANDLE ObjHandle,
797 ACPI_OBJECT_HANDLER Handler)
799 ACPI_NAMESPACE_NODE *Node;
803 /* Parameter validation */
808 return (AE_BAD_PARAMETER);
811 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
812 if (ACPI_FAILURE (Status))
817 /* Convert and validate the handle */
819 Node = AcpiNsMapHandleToNode (ObjHandle);
822 Status = AE_BAD_PARAMETER;
826 Status = AcpiNsDetachData (Node, Handler);
829 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
834 /*******************************************************************************
836 * FUNCTION: AcpiGetData
838 * PARAMETERS: ObjHandle - Namespace node
839 * Handler - Handler used in call to AttachData
840 * Data - Where the data is returned
844 * DESCRIPTION: Retrieve data that was previously attached to a namespace node.
846 ******************************************************************************/
850 ACPI_HANDLE ObjHandle,
851 ACPI_OBJECT_HANDLER Handler,
854 ACPI_NAMESPACE_NODE *Node;
858 /* Parameter validation */
864 return (AE_BAD_PARAMETER);
867 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
868 if (ACPI_FAILURE (Status))
873 /* Convert and validate the handle */
875 Node = AcpiNsMapHandleToNode (ObjHandle);
878 Status = AE_BAD_PARAMETER;
882 Status = AcpiNsGetAttachedData (Node, Handler, Data);
885 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);