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 - 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
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 *****************************************************************************/
117 /* $DragonFly: src/sys/contrib/dev/acpica/Attic/nsxfeval.c,v 1.1 2003/09/24 03:32:16 drhodus Exp $ */
120 #define __NSXFEVAL_C__
123 #include "acnamesp.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)
258 ACPI_OPERAND_OBJECT **InternalParams = NULL;
259 ACPI_OPERAND_OBJECT *InternalReturnObj = NULL;
260 ACPI_SIZE BufferSpaceNeeded;
264 ACPI_FUNCTION_TRACE ("AcpiEvaluateObject");
268 * If there are parameters to be passed to the object
269 * (which must be a control method), the external objects
270 * must be converted to internal objects
272 if (ExternalParams && ExternalParams->Count)
275 * Allocate a new parameter block for the internal objects
276 * Add 1 to count to allow for null terminated internal list
278 InternalParams = ACPI_MEM_CALLOCATE (((ACPI_SIZE) ExternalParams->Count + 1) *
282 return_ACPI_STATUS (AE_NO_MEMORY);
286 * Convert each external object in the list to an
289 for (i = 0; i < ExternalParams->Count; i++)
291 Status = AcpiUtCopyEobjectToIobject (&ExternalParams->Pointer[i],
293 if (ACPI_FAILURE (Status))
295 AcpiUtDeleteInternalObjectList (InternalParams);
296 return_ACPI_STATUS (Status);
299 InternalParams[ExternalParams->Count] = NULL;
304 * 1) Fully qualified pathname
305 * 2) No handle, not fully qualified pathname (error)
309 (AcpiNsValidRootPrefix (Pathname[0])))
312 * The path is fully qualified, just evaluate by name
314 Status = AcpiNsEvaluateByName (Pathname, InternalParams,
320 * A handle is optional iff a fully qualified pathname
321 * is specified. Since we've already handled fully
322 * qualified names above, this is an error
326 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
327 "Both Handle and Pathname are NULL\n"));
331 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
332 "Handle is NULL and Pathname is relative\n"));
335 Status = AE_BAD_PARAMETER;
340 * We get here if we have a handle -- and if we have a
341 * pathname it is relative. The handle will be validated
342 * in the lower procedures
347 * The null pathname case means the handle is for
348 * the actual object to be evaluated
350 Status = AcpiNsEvaluateByHandle (Handle, InternalParams,
356 * Both a Handle and a relative Pathname
358 Status = AcpiNsEvaluateRelative (Handle, Pathname, InternalParams,
365 * If we are expecting a return value, and all went well above,
366 * copy the return value to an external object.
370 if (!InternalReturnObj)
372 ReturnBuffer->Length = 0;
376 if (ACPI_GET_DESCRIPTOR_TYPE (InternalReturnObj) == ACPI_DESC_TYPE_NAMED)
379 * If we received a NS Node as a return object, this means that
380 * the object we are evaluating has nothing interesting to
381 * return (such as a mutex, etc.) We return an error because
382 * these types are essentially unsupported by this interface.
383 * We don't check up front because this makes it easier to add
384 * support for various types at a later date if necessary.
387 InternalReturnObj = NULL; /* No need to delete a NS Node */
388 ReturnBuffer->Length = 0;
391 if (ACPI_SUCCESS (Status))
394 * Find out how large a buffer is needed
395 * to contain the returned object
397 Status = AcpiUtGetObjectSize (InternalReturnObj,
399 if (ACPI_SUCCESS (Status))
401 /* Validate/Allocate/Clear caller buffer */
403 Status = AcpiUtInitializeBuffer (ReturnBuffer, BufferSpaceNeeded);
404 if (ACPI_FAILURE (Status))
407 * Caller's buffer is too small or a new one can't be allocated
409 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
410 "Needed buffer size %X, %s\n",
411 (UINT32) BufferSpaceNeeded, AcpiFormatException (Status)));
416 * We have enough space for the object, build it
418 Status = AcpiUtCopyIobjectToEobject (InternalReturnObj,
426 /* Delete the return and parameter objects */
428 if (InternalReturnObj)
431 * Delete the internal return object. (Or at least
432 * decrement the reference count by one)
434 AcpiUtRemoveReference (InternalReturnObj);
438 * Free the input parameter list (if we created one),
442 /* Free the allocated parameter block */
444 AcpiUtDeleteInternalObjectList (InternalParams);
447 return_ACPI_STATUS (Status);
451 /*******************************************************************************
453 * FUNCTION: AcpiWalkNamespace
455 * PARAMETERS: Type - ACPI_OBJECT_TYPE to search for
456 * StartObject - Handle in namespace where search begins
457 * MaxDepth - Depth to which search is to reach
458 * UserFunction - Called when an object of "Type" is found
459 * Context - Passed to user function
460 * ReturnValue - Location where return value of
461 * UserFunction is put if terminated early
463 * RETURNS Return value from the UserFunction if terminated early.
464 * Otherwise, returns NULL.
466 * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
467 * starting (and ending) at the object specified by StartHandle.
468 * The UserFunction is called whenever an object that matches
469 * the type parameter is found. If the user function returns
470 * a non-zero value, the search is terminated immediately and this
471 * value is returned to the caller.
473 * The point of this procedure is to provide a generic namespace
474 * walk routine that can be called from multiple places to
475 * provide multiple services; the User Function can be tailored
476 * to each task, whether it is a print function, a compare
479 ******************************************************************************/
483 ACPI_OBJECT_TYPE Type,
484 ACPI_HANDLE StartObject,
486 ACPI_WALK_CALLBACK UserFunction,
493 ACPI_FUNCTION_TRACE ("AcpiWalkNamespace");
496 /* Parameter validation */
498 if ((Type > ACPI_TYPE_EXTERNAL_MAX) ||
502 return_ACPI_STATUS (AE_BAD_PARAMETER);
506 * Lock the namespace around the walk.
507 * The namespace will be unlocked/locked around each call
508 * to the user function - since this function
509 * must be allowed to make Acpi calls itself.
511 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
512 if (ACPI_FAILURE (Status))
514 return_ACPI_STATUS (Status);
517 Status = AcpiNsWalkNamespace (Type, StartObject, MaxDepth, ACPI_NS_WALK_UNLOCK,
518 UserFunction, Context, ReturnValue);
520 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
521 return_ACPI_STATUS (Status);
525 /*******************************************************************************
527 * FUNCTION: AcpiNsGetDeviceCallback
529 * PARAMETERS: Callback from AcpiGetDevice
533 * DESCRIPTION: Takes callbacks from WalkNamespace and filters out all non-
534 * present devices, or if they specified a HID, it filters based
537 ******************************************************************************/
540 AcpiNsGetDeviceCallback (
541 ACPI_HANDLE ObjHandle,
547 ACPI_NAMESPACE_NODE *Node;
551 ACPI_GET_DEVICES_INFO *Info;
556 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
557 if (ACPI_FAILURE (Status))
562 Node = AcpiNsMapHandleToNode (ObjHandle);
563 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
564 if (ACPI_FAILURE (Status))
571 return (AE_BAD_PARAMETER);
575 * Run _STA to determine if device is present
577 Status = AcpiUtExecute_STA (Node, &Flags);
578 if (ACPI_FAILURE (Status))
580 return (AE_CTRL_DEPTH);
585 /* Don't return at the device or children of the device if not there */
586 return (AE_CTRL_DEPTH);
590 * Filter based on device HID & CID
592 if (Info->Hid != NULL)
594 Status = AcpiUtExecute_HID (Node, &Hid);
595 if (Status == AE_NOT_FOUND)
599 else if (ACPI_FAILURE (Status))
601 return (AE_CTRL_DEPTH);
604 if (ACPI_STRNCMP (Hid.Buffer, Info->Hid, sizeof (Hid.Buffer)) != 0)
606 Status = AcpiUtExecute_CID (Node, &Cid);
607 if (Status == AE_NOT_FOUND)
611 else if (ACPI_FAILURE (Status))
613 return (AE_CTRL_DEPTH);
616 /* TBD: Handle CID packages */
618 if (ACPI_STRNCMP (Cid.Buffer, Info->Hid, sizeof (Cid.Buffer)) != 0)
625 Status = Info->UserFunction (ObjHandle, NestingLevel, Info->Context, ReturnValue);
630 /*******************************************************************************
632 * FUNCTION: AcpiGetDevices
634 * PARAMETERS: HID - HID to search for. Can be NULL.
635 * UserFunction - Called when a matching object is found
636 * Context - Passed to user function
637 * ReturnValue - Location where return value of
638 * UserFunction is put if terminated early
640 * RETURNS Return value from the UserFunction if terminated early.
641 * Otherwise, returns NULL.
643 * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
644 * starting (and ending) at the object specified by StartHandle.
645 * The UserFunction is called whenever an object that matches
646 * the type parameter is found. If the user function returns
647 * a non-zero value, the search is terminated immediately and this
648 * value is returned to the caller.
650 * This is a wrapper for WalkNamespace, but the callback performs
651 * additional filtering. Please see AcpiGetDeviceCallback.
653 ******************************************************************************/
658 ACPI_WALK_CALLBACK UserFunction,
663 ACPI_GET_DEVICES_INFO Info;
666 ACPI_FUNCTION_TRACE ("AcpiGetDevices");
669 /* Parameter validation */
673 return_ACPI_STATUS (AE_BAD_PARAMETER);
677 * We're going to call their callback from OUR callback, so we need
678 * to know what it is, and their context parameter.
680 Info.Context = Context;
681 Info.UserFunction = UserFunction;
685 * Lock the namespace around the walk.
686 * The namespace will be unlocked/locked around each call
687 * to the user function - since this function
688 * must be allowed to make Acpi calls itself.
690 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
691 if (ACPI_FAILURE (Status))
693 return_ACPI_STATUS (Status);
696 Status = AcpiNsWalkNamespace (ACPI_TYPE_DEVICE,
697 ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
699 AcpiNsGetDeviceCallback, &Info,
702 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
703 return_ACPI_STATUS (Status);
707 /*******************************************************************************
709 * FUNCTION: AcpiAttachData
711 * PARAMETERS: ObjHandle - Namespace node
712 * Handler - Handler for this attachment
713 * Data - Pointer to data to be attached
717 * DESCRIPTION: Attach arbitrary data and handler to a namespace node.
719 ******************************************************************************/
723 ACPI_HANDLE ObjHandle,
724 ACPI_OBJECT_HANDLER Handler,
727 ACPI_NAMESPACE_NODE *Node;
731 /* Parameter validation */
737 return (AE_BAD_PARAMETER);
740 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
741 if (ACPI_FAILURE (Status))
746 /* Convert and validate the handle */
748 Node = AcpiNsMapHandleToNode (ObjHandle);
751 Status = AE_BAD_PARAMETER;
755 Status = AcpiNsAttachData (Node, Handler, Data);
758 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
763 /*******************************************************************************
765 * FUNCTION: AcpiDetachData
767 * PARAMETERS: ObjHandle - Namespace node handle
768 * Handler - Handler used in call to AcpiAttachData
772 * DESCRIPTION: Remove data that was previously attached to a node.
774 ******************************************************************************/
778 ACPI_HANDLE ObjHandle,
779 ACPI_OBJECT_HANDLER Handler)
781 ACPI_NAMESPACE_NODE *Node;
785 /* Parameter validation */
790 return (AE_BAD_PARAMETER);
793 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
794 if (ACPI_FAILURE (Status))
799 /* Convert and validate the handle */
801 Node = AcpiNsMapHandleToNode (ObjHandle);
804 Status = AE_BAD_PARAMETER;
808 Status = AcpiNsDetachData (Node, Handler);
811 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
816 /*******************************************************************************
818 * FUNCTION: AcpiGetData
820 * PARAMETERS: ObjHandle - Namespace node
821 * Handler - Handler used in call to AttachData
822 * Data - Where the data is returned
826 * DESCRIPTION: Retrieve data that was previously attached to a namespace node.
828 ******************************************************************************/
832 ACPI_HANDLE ObjHandle,
833 ACPI_OBJECT_HANDLER Handler,
836 ACPI_NAMESPACE_NODE *Node;
840 /* Parameter validation */
846 return (AE_BAD_PARAMETER);
849 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
850 if (ACPI_FAILURE (Status))
855 /* Convert and validate the handle */
857 Node = AcpiNsMapHandleToNode (ObjHandle);
860 Status = AE_BAD_PARAMETER;
864 Status = AcpiNsGetAttachedData (Node, Handler, Data);
867 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);