Sync usage with man page.
[netbsd-mini2440.git] / sys / external / intel-public / acpica / dist / namespace / nsxfeval.c
blobb1d18c64dc71af6f6ef1ad998561b4f213e23db1
1 /*******************************************************************************
3 * Module Name: nsxfeval - Public interfaces to the ACPI subsystem
4 * ACPI Object evaluation interfaces
6 ******************************************************************************/
8 /******************************************************************************
10 * 1. Copyright Notice
12 * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
13 * All rights reserved.
15 * 2. License
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
20 * property rights.
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
41 * 3. Conditions
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
65 * make.
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
71 * distribution.
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
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
89 * PARTICULAR PURPOSE.
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
98 * LIMITED REMEDY.
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 *****************************************************************************/
118 #define __NSXFEVAL_C__
120 #include "acpi.h"
121 #include "accommon.h"
122 #include "acnamesp.h"
123 #include "acinterp.h"
126 #define _COMPONENT ACPI_NAMESPACE
127 ACPI_MODULE_NAME ("nsxfeval")
129 /* Local prototypes */
131 static void
132 AcpiNsResolveReferences (
133 ACPI_EVALUATE_INFO *Info);
136 /*******************************************************************************
138 * FUNCTION: AcpiEvaluateObjectTyped
140 * PARAMETERS: Handle - Object handle (optional)
141 * Pathname - Object pathname (optional)
142 * ExternalParams - List of parameters to pass to method,
143 * terminated by NULL. May be NULL
144 * if no parameters are being passed.
145 * ReturnBuffer - Where to put method's return value (if
146 * any). If NULL, no value is returned.
147 * ReturnType - Expected type of return object
149 * RETURN: Status
151 * DESCRIPTION: Find and evaluate the given object, passing the given
152 * parameters if necessary. One of "Handle" or "Pathname" must
153 * be valid (non-null)
155 ******************************************************************************/
157 ACPI_STATUS
158 AcpiEvaluateObjectTyped (
159 ACPI_HANDLE Handle,
160 ACPI_CONST_STRING Pathname,
161 ACPI_OBJECT_LIST *ExternalParams,
162 ACPI_BUFFER *ReturnBuffer,
163 ACPI_OBJECT_TYPE ReturnType)
165 ACPI_STATUS Status;
166 BOOLEAN MustFree = FALSE;
168 ACPI_FUNCTION_TRACE (AcpiEvaluateObjectTyped);
171 /* Return buffer must be valid */
173 if (!ReturnBuffer)
175 return_ACPI_STATUS (AE_BAD_PARAMETER);
178 if (ReturnBuffer->Length == ACPI_ALLOCATE_BUFFER)
180 MustFree = TRUE;
183 /* Evaluate the object */
185 Status = AcpiEvaluateObject (Handle, Pathname, ExternalParams, ReturnBuffer);
186 if (ACPI_FAILURE (Status))
188 return_ACPI_STATUS (Status);
191 /* Type ANY means "don't care" */
193 if (ReturnType == ACPI_TYPE_ANY)
195 return_ACPI_STATUS (AE_OK);
198 if (ReturnBuffer->Length == 0)
200 /* Error because caller specifically asked for a return value */
202 ACPI_ERROR ((AE_INFO, "No return value"));
203 return_ACPI_STATUS (AE_NULL_OBJECT);
206 /* Examine the object type returned from EvaluateObject */
208 if (((ACPI_OBJECT *) ReturnBuffer->Pointer)->Type == ReturnType)
210 return_ACPI_STATUS (AE_OK);
213 /* Return object type does not match requested type */
215 ACPI_ERROR ((AE_INFO,
216 "Incorrect return type [%s] requested [%s]",
217 AcpiUtGetTypeName (((ACPI_OBJECT *) ReturnBuffer->Pointer)->Type),
218 AcpiUtGetTypeName (ReturnType)));
220 if (MustFree)
222 /* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */
224 AcpiOsFree (ReturnBuffer->Pointer);
225 ReturnBuffer->Pointer = NULL;
228 ReturnBuffer->Length = 0;
229 return_ACPI_STATUS (AE_TYPE);
232 ACPI_EXPORT_SYMBOL (AcpiEvaluateObjectTyped)
235 /*******************************************************************************
237 * FUNCTION: AcpiEvaluateObject
239 * PARAMETERS: Handle - Object handle (optional)
240 * Pathname - Object pathname (optional)
241 * ExternalParams - List of parameters to pass to method,
242 * terminated by NULL. May be NULL
243 * if no parameters are being passed.
244 * ReturnBuffer - Where to put method's return value (if
245 * any). If NULL, no value is returned.
247 * RETURN: Status
249 * DESCRIPTION: Find and evaluate the given object, passing the given
250 * parameters if necessary. One of "Handle" or "Pathname" must
251 * be valid (non-null)
253 ******************************************************************************/
255 ACPI_STATUS
256 AcpiEvaluateObject (
257 ACPI_HANDLE Handle,
258 ACPI_CONST_STRING Pathname,
259 ACPI_OBJECT_LIST *ExternalParams,
260 ACPI_BUFFER *ReturnBuffer)
262 ACPI_STATUS Status;
263 ACPI_EVALUATE_INFO *Info;
264 ACPI_SIZE BufferSpaceNeeded;
265 UINT32 i;
268 ACPI_FUNCTION_TRACE (AcpiEvaluateObject);
271 /* Allocate and initialize the evaluation information block */
273 Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
274 if (!Info)
276 return_ACPI_STATUS (AE_NO_MEMORY);
279 Info->Pathname = __UNCONST(Pathname);
281 /* Convert and validate the device handle */
283 Info->PrefixNode = AcpiNsMapHandleToNode (Handle);
284 if (!Info->PrefixNode)
286 Status = AE_BAD_PARAMETER;
287 goto Cleanup;
291 * If there are parameters to be passed to a control method, the external
292 * objects must all be converted to internal objects
294 if (ExternalParams && ExternalParams->Count)
297 * Allocate a new parameter block for the internal objects
298 * Add 1 to count to allow for null terminated internal list
300 Info->Parameters = ACPI_ALLOCATE_ZEROED (
301 ((ACPI_SIZE) ExternalParams->Count + 1) * sizeof (void *));
302 if (!Info->Parameters)
304 Status = AE_NO_MEMORY;
305 goto Cleanup;
308 /* Convert each external object in the list to an internal object */
310 for (i = 0; i < ExternalParams->Count; i++)
312 Status = AcpiUtCopyEobjectToIobject (
313 &ExternalParams->Pointer[i], &Info->Parameters[i]);
314 if (ACPI_FAILURE (Status))
316 goto Cleanup;
319 Info->Parameters[ExternalParams->Count] = NULL;
323 * Three major cases:
324 * 1) Fully qualified pathname
325 * 2) No handle, not fully qualified pathname (error)
326 * 3) Valid handle
328 if ((Pathname) &&
329 (AcpiNsValidRootPrefix (Pathname[0])))
331 /* The path is fully qualified, just evaluate by name */
333 Info->PrefixNode = NULL;
334 Status = AcpiNsEvaluate (Info);
336 else if (!Handle)
339 * A handle is optional iff a fully qualified pathname is specified.
340 * Since we've already handled fully qualified names above, this is
341 * an error
343 if (!Pathname)
345 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
346 "Both Handle and Pathname are NULL"));
348 else
350 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
351 "Null Handle with relative pathname [%s]", Pathname));
354 Status = AE_BAD_PARAMETER;
356 else
358 /* We have a namespace a node and a possible relative path */
360 Status = AcpiNsEvaluate (Info);
364 * If we are expecting a return value, and all went well above,
365 * copy the return value to an external object.
367 if (ReturnBuffer)
369 if (!Info->ReturnObject)
371 ReturnBuffer->Length = 0;
373 else
375 if (ACPI_GET_DESCRIPTOR_TYPE (Info->ReturnObject) ==
376 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.
386 Status = AE_TYPE;
387 Info->ReturnObject = NULL; /* No need to delete a NS Node */
388 ReturnBuffer->Length = 0;
391 if (ACPI_SUCCESS (Status))
393 /* Dereference Index and RefOf references */
395 AcpiNsResolveReferences (Info);
397 /* Get the size of the returned object */
399 Status = AcpiUtGetObjectSize (Info->ReturnObject,
400 &BufferSpaceNeeded);
401 if (ACPI_SUCCESS (Status))
403 /* Validate/Allocate/Clear caller buffer */
405 Status = AcpiUtInitializeBuffer (ReturnBuffer,
406 BufferSpaceNeeded);
407 if (ACPI_FAILURE (Status))
410 * Caller's buffer is too small or a new one can't
411 * be allocated
413 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
414 "Needed buffer size %X, %s\n",
415 (UINT32) BufferSpaceNeeded,
416 AcpiFormatException (Status)));
418 else
420 /* We have enough space for the object, build it */
422 Status = AcpiUtCopyIobjectToEobject (Info->ReturnObject,
423 ReturnBuffer);
430 if (Info->ReturnObject)
433 * Delete the internal return object. NOTE: Interpreter must be
434 * locked to avoid race condition.
436 AcpiExEnterInterpreter ();
438 /* Remove one reference on the return object (should delete it) */
440 AcpiUtRemoveReference (Info->ReturnObject);
441 AcpiExExitInterpreter ();
445 Cleanup:
447 /* Free the input parameter list (if we created one) */
449 if (Info->Parameters)
451 /* Free the allocated parameter block */
453 AcpiUtDeleteInternalObjectList (Info->Parameters);
456 ACPI_FREE (Info);
457 return_ACPI_STATUS (Status);
460 ACPI_EXPORT_SYMBOL (AcpiEvaluateObject)
463 /*******************************************************************************
465 * FUNCTION: AcpiNsResolveReferences
467 * PARAMETERS: Info - Evaluation info block
469 * RETURN: Info->ReturnObject is replaced with the dereferenced object
471 * DESCRIPTION: Dereference certain reference objects. Called before an
472 * internal return object is converted to an external ACPI_OBJECT.
474 * Performs an automatic dereference of Index and RefOf reference objects.
475 * These reference objects are not supported by the ACPI_OBJECT, so this is a
476 * last resort effort to return something useful. Also, provides compatibility
477 * with other ACPI implementations.
479 * NOTE: does not handle references within returned package objects or nested
480 * references, but this support could be added later if found to be necessary.
482 ******************************************************************************/
484 static void
485 AcpiNsResolveReferences (
486 ACPI_EVALUATE_INFO *Info)
488 ACPI_OPERAND_OBJECT *ObjDesc = NULL;
489 ACPI_NAMESPACE_NODE *Node;
492 /* We are interested in reference objects only */
494 if ((Info->ReturnObject)->Common.Type != ACPI_TYPE_LOCAL_REFERENCE)
496 return;
500 * Two types of references are supported - those created by Index and
501 * RefOf operators. A name reference (AML_NAMEPATH_OP) can be converted
502 * to an ACPI_OBJECT, so it is not dereferenced here. A DdbHandle
503 * (AML_LOAD_OP) cannot be dereferenced, nor can it be converted to
504 * an ACPI_OBJECT.
506 switch (Info->ReturnObject->Reference.Class)
508 case ACPI_REFCLASS_INDEX:
510 ObjDesc = *(Info->ReturnObject->Reference.Where);
511 break;
513 case ACPI_REFCLASS_REFOF:
515 Node = Info->ReturnObject->Reference.Object;
516 if (Node)
518 ObjDesc = Node->Object;
520 break;
522 default:
523 return;
526 /* Replace the existing reference object */
528 if (ObjDesc)
530 AcpiUtAddReference (ObjDesc);
531 AcpiUtRemoveReference (Info->ReturnObject);
532 Info->ReturnObject = ObjDesc;
535 return;
539 /*******************************************************************************
541 * FUNCTION: AcpiWalkNamespace
543 * PARAMETERS: Type - ACPI_OBJECT_TYPE to search for
544 * StartObject - Handle in namespace where search begins
545 * MaxDepth - Depth to which search is to reach
546 * UserFunction - Called when an object of "Type" is found
547 * Context - Passed to user function
548 * ReturnValue - Location where return value of
549 * UserFunction is put if terminated early
551 * RETURNS Return value from the UserFunction if terminated early.
552 * Otherwise, returns NULL.
554 * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
555 * starting (and ending) at the object specified by StartHandle.
556 * The UserFunction is called whenever an object that matches
557 * the type parameter is found. If the user function returns
558 * a non-zero value, the search is terminated immediately and this
559 * value is returned to the caller.
561 * The point of this procedure is to provide a generic namespace
562 * walk routine that can be called from multiple places to
563 * provide multiple services; the User Function can be tailored
564 * to each task, whether it is a print function, a compare
565 * function, etc.
567 ******************************************************************************/
569 ACPI_STATUS
570 AcpiWalkNamespace (
571 ACPI_OBJECT_TYPE Type,
572 ACPI_HANDLE StartObject,
573 UINT32 MaxDepth,
574 ACPI_WALK_CALLBACK UserFunction,
575 void *Context,
576 void **ReturnValue)
578 ACPI_STATUS Status;
581 ACPI_FUNCTION_TRACE (AcpiWalkNamespace);
584 /* Parameter validation */
586 if ((Type > ACPI_TYPE_LOCAL_MAX) ||
587 (!MaxDepth) ||
588 (!UserFunction))
590 return_ACPI_STATUS (AE_BAD_PARAMETER);
594 * Need to acquire the namespace reader lock to prevent interference
595 * with any concurrent table unloads (which causes the deletion of
596 * namespace objects). We cannot allow the deletion of a namespace node
597 * while the user function is using it. The exception to this are the
598 * nodes created and deleted during control method execution -- these
599 * nodes are marked as temporary nodes and are ignored by the namespace
600 * walk. Thus, control methods can be executed while holding the
601 * namespace deletion lock (and the user function can execute control
602 * methods.)
604 Status = AcpiUtAcquireReadLock (&AcpiGbl_NamespaceRwLock);
605 if (ACPI_FAILURE (Status))
607 return (Status);
611 * Lock the namespace around the walk. The namespace will be
612 * unlocked/locked around each call to the user function - since the user
613 * function must be allowed to make ACPICA calls itself (for example, it
614 * will typically execute control methods during device enumeration.)
616 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
617 if (ACPI_FAILURE (Status))
619 goto UnlockAndExit;
622 Status = AcpiNsWalkNamespace (Type, StartObject, MaxDepth,
623 ACPI_NS_WALK_UNLOCK, UserFunction, Context, ReturnValue);
625 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
627 UnlockAndExit:
628 (void) AcpiUtReleaseReadLock (&AcpiGbl_NamespaceRwLock);
629 return_ACPI_STATUS (Status);
632 ACPI_EXPORT_SYMBOL (AcpiWalkNamespace)
635 /*******************************************************************************
637 * FUNCTION: AcpiNsGetDeviceCallback
639 * PARAMETERS: Callback from AcpiGetDevice
641 * RETURN: Status
643 * DESCRIPTION: Takes callbacks from WalkNamespace and filters out all non-
644 * present devices, or if they specified a HID, it filters based
645 * on that.
647 ******************************************************************************/
649 static ACPI_STATUS
650 AcpiNsGetDeviceCallback (
651 ACPI_HANDLE ObjHandle,
652 UINT32 NestingLevel,
653 void *Context,
654 void **ReturnValue)
656 ACPI_GET_DEVICES_INFO *Info = Context;
657 ACPI_STATUS Status;
658 ACPI_NAMESPACE_NODE *Node;
659 UINT32 Flags;
660 ACPI_DEVICE_ID *Hid;
661 ACPI_DEVICE_ID_LIST *Cid;
662 UINT32 i;
663 BOOLEAN Found;
664 int NoMatch;
667 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
668 if (ACPI_FAILURE (Status))
670 return (Status);
673 Node = AcpiNsMapHandleToNode (ObjHandle);
674 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
675 if (ACPI_FAILURE (Status))
677 return (Status);
680 if (!Node)
682 return (AE_BAD_PARAMETER);
685 /* Run _STA to determine if device is present */
687 Status = AcpiUtExecute_STA (Node, &Flags);
688 if (ACPI_FAILURE (Status))
690 return (AE_CTRL_DEPTH);
693 if (!(Flags & ACPI_STA_DEVICE_PRESENT) &&
694 !(Flags & ACPI_STA_DEVICE_FUNCTIONING))
697 * Don't examine the children of the device only when the
698 * device is neither present nor functional. See ACPI spec,
699 * description of _STA for more information.
701 return (AE_CTRL_DEPTH);
704 /* Filter based on device HID & CID */
706 if (Info->Hid != NULL)
708 Status = AcpiUtExecute_HID (Node, &Hid);
709 if (Status == AE_NOT_FOUND)
711 return (AE_OK);
713 else if (ACPI_FAILURE (Status))
715 return (AE_CTRL_DEPTH);
718 NoMatch = ACPI_STRCMP (Hid->String, Info->Hid);
719 ACPI_FREE (Hid);
721 if (NoMatch)
724 * HID does not match, attempt match within the
725 * list of Compatible IDs (CIDs)
727 Status = AcpiUtExecute_CID (Node, &Cid);
728 if (Status == AE_NOT_FOUND)
730 return (AE_OK);
732 else if (ACPI_FAILURE (Status))
734 return (AE_CTRL_DEPTH);
737 /* Walk the CID list */
739 Found = FALSE;
740 for (i = 0; i < Cid->Count; i++)
742 if (ACPI_STRCMP (Cid->Ids[i].String, Info->Hid) == 0)
744 /* Found a matching CID */
746 Found = TRUE;
747 break;
751 ACPI_FREE (Cid);
752 if (!Found)
754 return (AE_OK);
759 /* We have a valid device, invoke the user function */
761 Status = Info->UserFunction (ObjHandle, NestingLevel, Info->Context,
762 ReturnValue);
763 return (Status);
767 /*******************************************************************************
769 * FUNCTION: AcpiGetDevices
771 * PARAMETERS: HID - HID to search for. Can be NULL.
772 * UserFunction - Called when a matching object is found
773 * Context - Passed to user function
774 * ReturnValue - Location where return value of
775 * UserFunction is put if terminated early
777 * RETURNS Return value from the UserFunction if terminated early.
778 * Otherwise, returns NULL.
780 * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
781 * starting (and ending) at the object specified by StartHandle.
782 * The UserFunction is called whenever an object of type
783 * Device is found. If the user function returns
784 * a non-zero value, the search is terminated immediately and this
785 * value is returned to the caller.
787 * This is a wrapper for WalkNamespace, but the callback performs
788 * additional filtering. Please see AcpiNsGetDeviceCallback.
790 ******************************************************************************/
792 ACPI_STATUS
793 AcpiGetDevices (
794 char *HID,
795 ACPI_WALK_CALLBACK UserFunction,
796 void *Context,
797 void **ReturnValue)
799 ACPI_STATUS Status;
800 ACPI_GET_DEVICES_INFO Info;
803 ACPI_FUNCTION_TRACE (AcpiGetDevices);
806 /* Parameter validation */
808 if (!UserFunction)
810 return_ACPI_STATUS (AE_BAD_PARAMETER);
814 * We're going to call their callback from OUR callback, so we need
815 * to know what it is, and their context parameter.
817 Info.Hid = HID;
818 Info.Context = Context;
819 Info.UserFunction = UserFunction;
822 * Lock the namespace around the walk.
823 * The namespace will be unlocked/locked around each call
824 * to the user function - since this function
825 * must be allowed to make Acpi calls itself.
827 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
828 if (ACPI_FAILURE (Status))
830 return_ACPI_STATUS (Status);
833 Status = AcpiNsWalkNamespace (ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
834 ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK,
835 AcpiNsGetDeviceCallback, &Info, ReturnValue);
837 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
838 return_ACPI_STATUS (Status);
841 ACPI_EXPORT_SYMBOL (AcpiGetDevices)
844 /*******************************************************************************
846 * FUNCTION: AcpiAttachData
848 * PARAMETERS: ObjHandle - Namespace node
849 * Handler - Handler for this attachment
850 * Data - Pointer to data to be attached
852 * RETURN: Status
854 * DESCRIPTION: Attach arbitrary data and handler to a namespace node.
856 ******************************************************************************/
858 ACPI_STATUS
859 AcpiAttachData (
860 ACPI_HANDLE ObjHandle,
861 ACPI_OBJECT_HANDLER Handler,
862 void *Data)
864 ACPI_NAMESPACE_NODE *Node;
865 ACPI_STATUS Status;
868 /* Parameter validation */
870 if (!ObjHandle ||
871 !Handler ||
872 !Data)
874 return (AE_BAD_PARAMETER);
877 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
878 if (ACPI_FAILURE (Status))
880 return (Status);
883 /* Convert and validate the handle */
885 Node = AcpiNsMapHandleToNode (ObjHandle);
886 if (!Node)
888 Status = AE_BAD_PARAMETER;
889 goto UnlockAndExit;
892 Status = AcpiNsAttachData (Node, Handler, Data);
894 UnlockAndExit:
895 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
896 return (Status);
899 ACPI_EXPORT_SYMBOL (AcpiAttachData)
902 /*******************************************************************************
904 * FUNCTION: AcpiDetachData
906 * PARAMETERS: ObjHandle - Namespace node handle
907 * Handler - Handler used in call to AcpiAttachData
909 * RETURN: Status
911 * DESCRIPTION: Remove data that was previously attached to a node.
913 ******************************************************************************/
915 ACPI_STATUS
916 AcpiDetachData (
917 ACPI_HANDLE ObjHandle,
918 ACPI_OBJECT_HANDLER Handler)
920 ACPI_NAMESPACE_NODE *Node;
921 ACPI_STATUS Status;
924 /* Parameter validation */
926 if (!ObjHandle ||
927 !Handler)
929 return (AE_BAD_PARAMETER);
932 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
933 if (ACPI_FAILURE (Status))
935 return (Status);
938 /* Convert and validate the handle */
940 Node = AcpiNsMapHandleToNode (ObjHandle);
941 if (!Node)
943 Status = AE_BAD_PARAMETER;
944 goto UnlockAndExit;
947 Status = AcpiNsDetachData (Node, Handler);
949 UnlockAndExit:
950 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
951 return (Status);
954 ACPI_EXPORT_SYMBOL (AcpiDetachData)
957 /*******************************************************************************
959 * FUNCTION: AcpiGetData
961 * PARAMETERS: ObjHandle - Namespace node
962 * Handler - Handler used in call to AttachData
963 * Data - Where the data is returned
965 * RETURN: Status
967 * DESCRIPTION: Retrieve data that was previously attached to a namespace node.
969 ******************************************************************************/
971 ACPI_STATUS
972 AcpiGetData (
973 ACPI_HANDLE ObjHandle,
974 ACPI_OBJECT_HANDLER Handler,
975 void **Data)
977 ACPI_NAMESPACE_NODE *Node;
978 ACPI_STATUS Status;
981 /* Parameter validation */
983 if (!ObjHandle ||
984 !Handler ||
985 !Data)
987 return (AE_BAD_PARAMETER);
990 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
991 if (ACPI_FAILURE (Status))
993 return (Status);
996 /* Convert and validate the handle */
998 Node = AcpiNsMapHandleToNode (ObjHandle);
999 if (!Node)
1001 Status = AE_BAD_PARAMETER;
1002 goto UnlockAndExit;
1005 Status = AcpiNsGetAttachedData (Node, Handler, Data);
1007 UnlockAndExit:
1008 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
1009 return (Status);
1012 ACPI_EXPORT_SYMBOL (AcpiGetData)