Fixed compatibility of output.
[AROS.git] / arch / all-pc / acpica / source / components / namespace / nsxfeval.c
bloba1af583a600136a88e3fb55ea59e7b01b882e28d
1 /*******************************************************************************
3 * Module Name: nsxfeval - Public interfaces to the ACPI subsystem
4 * ACPI Object evaluation interfaces
6 ******************************************************************************/
8 /*
9 * Copyright (C) 2000 - 2013, Intel Corp.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
46 #define __NSXFEVAL_C__
47 #define EXPORT_ACPI_INTERFACES
49 #include "acpi.h"
50 #include "accommon.h"
51 #include "acnamesp.h"
52 #include "acinterp.h"
55 #define _COMPONENT ACPI_NAMESPACE
56 ACPI_MODULE_NAME ("nsxfeval")
58 /* Local prototypes */
60 static void
61 AcpiNsResolveReferences (
62 ACPI_EVALUATE_INFO *Info);
65 /*******************************************************************************
67 * FUNCTION: AcpiEvaluateObjectTyped
69 * PARAMETERS: Handle - Object handle (optional)
70 * Pathname - Object pathname (optional)
71 * ExternalParams - List of parameters to pass to method,
72 * terminated by NULL. May be NULL
73 * if no parameters are being passed.
74 * ReturnBuffer - Where to put method's return value (if
75 * any). If NULL, no value is returned.
76 * ReturnType - Expected type of return object
78 * RETURN: Status
80 * DESCRIPTION: Find and evaluate the given object, passing the given
81 * parameters if necessary. One of "Handle" or "Pathname" must
82 * be valid (non-null)
84 ******************************************************************************/
86 ACPI_STATUS
87 AcpiEvaluateObjectTyped (
88 ACPI_HANDLE Handle,
89 ACPI_STRING Pathname,
90 ACPI_OBJECT_LIST *ExternalParams,
91 ACPI_BUFFER *ReturnBuffer,
92 ACPI_OBJECT_TYPE ReturnType)
94 ACPI_STATUS Status;
95 BOOLEAN MustFree = FALSE;
98 ACPI_FUNCTION_TRACE (AcpiEvaluateObjectTyped);
101 /* Return buffer must be valid */
103 if (!ReturnBuffer)
105 return_ACPI_STATUS (AE_BAD_PARAMETER);
108 if (ReturnBuffer->Length == ACPI_ALLOCATE_BUFFER)
110 MustFree = TRUE;
113 /* Evaluate the object */
115 Status = AcpiEvaluateObject (Handle, Pathname, ExternalParams, ReturnBuffer);
116 if (ACPI_FAILURE (Status))
118 return_ACPI_STATUS (Status);
121 /* Type ANY means "don't care" */
123 if (ReturnType == ACPI_TYPE_ANY)
125 return_ACPI_STATUS (AE_OK);
128 if (ReturnBuffer->Length == 0)
130 /* Error because caller specifically asked for a return value */
132 ACPI_ERROR ((AE_INFO, "No return value"));
133 return_ACPI_STATUS (AE_NULL_OBJECT);
136 /* Examine the object type returned from EvaluateObject */
138 if (((ACPI_OBJECT *) ReturnBuffer->Pointer)->Type == ReturnType)
140 return_ACPI_STATUS (AE_OK);
143 /* Return object type does not match requested type */
145 ACPI_ERROR ((AE_INFO,
146 "Incorrect return type [%s] requested [%s]",
147 AcpiUtGetTypeName (((ACPI_OBJECT *) ReturnBuffer->Pointer)->Type),
148 AcpiUtGetTypeName (ReturnType)));
150 if (MustFree)
153 * Caller used ACPI_ALLOCATE_BUFFER, free the return buffer.
154 * Note: We use AcpiOsFree here because AcpiOsAllocate was used
155 * to allocate the buffer. This purposefully bypasses the internal
156 * allocation tracking mechanism (if it is enabled).
158 AcpiOsFree (ReturnBuffer->Pointer);
159 ReturnBuffer->Pointer = NULL;
162 ReturnBuffer->Length = 0;
163 return_ACPI_STATUS (AE_TYPE);
166 ACPI_EXPORT_SYMBOL (AcpiEvaluateObjectTyped)
169 /*******************************************************************************
171 * FUNCTION: AcpiEvaluateObject
173 * PARAMETERS: Handle - Object handle (optional)
174 * Pathname - Object pathname (optional)
175 * ExternalParams - List of parameters to pass to method,
176 * terminated by NULL. May be NULL
177 * if no parameters are being passed.
178 * ReturnBuffer - Where to put method's return value (if
179 * any). If NULL, no value is returned.
181 * RETURN: Status
183 * DESCRIPTION: Find and evaluate the given object, passing the given
184 * parameters if necessary. One of "Handle" or "Pathname" must
185 * be valid (non-null)
187 ******************************************************************************/
189 ACPI_STATUS
190 AcpiEvaluateObject (
191 ACPI_HANDLE Handle,
192 ACPI_STRING Pathname,
193 ACPI_OBJECT_LIST *ExternalParams,
194 ACPI_BUFFER *ReturnBuffer)
196 ACPI_STATUS Status;
197 ACPI_EVALUATE_INFO *Info;
198 ACPI_SIZE BufferSpaceNeeded;
199 UINT32 i;
202 ACPI_FUNCTION_TRACE (AcpiEvaluateObject);
205 /* Allocate and initialize the evaluation information block */
207 Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
208 if (!Info)
210 return_ACPI_STATUS (AE_NO_MEMORY);
213 /* Convert and validate the device handle */
215 Info->PrefixNode = AcpiNsValidateHandle (Handle);
216 if (!Info->PrefixNode)
218 Status = AE_BAD_PARAMETER;
219 goto Cleanup;
223 * Get the actual namespace node for the target object.
224 * Handles these cases:
226 * 1) Null node, valid pathname from root (absolute path)
227 * 2) Node and valid pathname (path relative to Node)
228 * 3) Node, Null pathname
230 if ((Pathname) &&
231 (ACPI_IS_ROOT_PREFIX (Pathname[0])))
233 /* The path is fully qualified, just evaluate by name */
235 Info->PrefixNode = NULL;
237 else if (!Handle)
240 * A handle is optional iff a fully qualified pathname is specified.
241 * Since we've already handled fully qualified names above, this is
242 * an error.
244 if (!Pathname)
246 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
247 "Both Handle and Pathname are NULL"));
249 else
251 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
252 "Null Handle with relative pathname [%s]", Pathname));
255 Status = AE_BAD_PARAMETER;
256 goto Cleanup;
259 Info->RelativePathname = Pathname;
262 * Convert all external objects passed as arguments to the
263 * internal version(s).
265 if (ExternalParams && ExternalParams->Count)
267 Info->ParamCount = (UINT16) ExternalParams->Count;
269 /* Warn on impossible argument count */
271 if (Info->ParamCount > ACPI_METHOD_NUM_ARGS)
273 ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
274 "Excess arguments (%u) - using only %u",
275 Info->ParamCount, ACPI_METHOD_NUM_ARGS));
277 Info->ParamCount = ACPI_METHOD_NUM_ARGS;
281 * Allocate a new parameter block for the internal objects
282 * Add 1 to count to allow for null terminated internal list
284 Info->Parameters = ACPI_ALLOCATE_ZEROED (
285 ((ACPI_SIZE) Info->ParamCount + 1) * sizeof (void *));
286 if (!Info->Parameters)
288 Status = AE_NO_MEMORY;
289 goto Cleanup;
292 /* Convert each external object in the list to an internal object */
294 for (i = 0; i < Info->ParamCount; i++)
296 Status = AcpiUtCopyEobjectToIobject (
297 &ExternalParams->Pointer[i], &Info->Parameters[i]);
298 if (ACPI_FAILURE (Status))
300 goto Cleanup;
304 Info->Parameters[Info->ParamCount] = NULL;
308 #if 0
311 * Begin incoming argument count analysis. Check for too few args
312 * and too many args.
315 switch (AcpiNsGetType (Info->Node))
317 case ACPI_TYPE_METHOD:
319 /* Check incoming argument count against the method definition */
321 if (Info->ObjDesc->Method.ParamCount > Info->ParamCount)
323 ACPI_ERROR ((AE_INFO,
324 "Insufficient arguments (%u) - %u are required",
325 Info->ParamCount,
326 Info->ObjDesc->Method.ParamCount));
328 Status = AE_MISSING_ARGUMENTS;
329 goto Cleanup;
332 else if (Info->ObjDesc->Method.ParamCount < Info->ParamCount)
334 ACPI_WARNING ((AE_INFO,
335 "Excess arguments (%u) - only %u are required",
336 Info->ParamCount,
337 Info->ObjDesc->Method.ParamCount));
339 /* Just pass the required number of arguments */
341 Info->ParamCount = Info->ObjDesc->Method.ParamCount;
345 * Any incoming external objects to be passed as arguments to the
346 * method must be converted to internal objects
348 if (Info->ParamCount)
351 * Allocate a new parameter block for the internal objects
352 * Add 1 to count to allow for null terminated internal list
354 Info->Parameters = ACPI_ALLOCATE_ZEROED (
355 ((ACPI_SIZE) Info->ParamCount + 1) * sizeof (void *));
356 if (!Info->Parameters)
358 Status = AE_NO_MEMORY;
359 goto Cleanup;
362 /* Convert each external object in the list to an internal object */
364 for (i = 0; i < Info->ParamCount; i++)
366 Status = AcpiUtCopyEobjectToIobject (
367 &ExternalParams->Pointer[i], &Info->Parameters[i]);
368 if (ACPI_FAILURE (Status))
370 goto Cleanup;
374 Info->Parameters[Info->ParamCount] = NULL;
376 break;
378 default:
380 /* Warn if arguments passed to an object that is not a method */
382 if (Info->ParamCount)
384 ACPI_WARNING ((AE_INFO,
385 "%u arguments were passed to a non-method ACPI object",
386 Info->ParamCount));
388 break;
391 #endif
394 /* Now we can evaluate the object */
396 Status = AcpiNsEvaluate (Info);
399 * If we are expecting a return value, and all went well above,
400 * copy the return value to an external object.
402 if (ReturnBuffer)
404 if (!Info->ReturnObject)
406 ReturnBuffer->Length = 0;
408 else
410 if (ACPI_GET_DESCRIPTOR_TYPE (Info->ReturnObject) ==
411 ACPI_DESC_TYPE_NAMED)
414 * If we received a NS Node as a return object, this means that
415 * the object we are evaluating has nothing interesting to
416 * return (such as a mutex, etc.) We return an error because
417 * these types are essentially unsupported by this interface.
418 * We don't check up front because this makes it easier to add
419 * support for various types at a later date if necessary.
421 Status = AE_TYPE;
422 Info->ReturnObject = NULL; /* No need to delete a NS Node */
423 ReturnBuffer->Length = 0;
426 if (ACPI_SUCCESS (Status))
428 /* Dereference Index and RefOf references */
430 AcpiNsResolveReferences (Info);
432 /* Get the size of the returned object */
434 Status = AcpiUtGetObjectSize (Info->ReturnObject,
435 &BufferSpaceNeeded);
436 if (ACPI_SUCCESS (Status))
438 /* Validate/Allocate/Clear caller buffer */
440 Status = AcpiUtInitializeBuffer (ReturnBuffer,
441 BufferSpaceNeeded);
442 if (ACPI_FAILURE (Status))
445 * Caller's buffer is too small or a new one can't
446 * be allocated
448 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
449 "Needed buffer size %X, %s\n",
450 (UINT32) BufferSpaceNeeded,
451 AcpiFormatException (Status)));
453 else
455 /* We have enough space for the object, build it */
457 Status = AcpiUtCopyIobjectToEobject (Info->ReturnObject,
458 ReturnBuffer);
465 if (Info->ReturnObject)
468 * Delete the internal return object. NOTE: Interpreter must be
469 * locked to avoid race condition.
471 AcpiExEnterInterpreter ();
473 /* Remove one reference on the return object (should delete it) */
475 AcpiUtRemoveReference (Info->ReturnObject);
476 AcpiExExitInterpreter ();
480 Cleanup:
482 /* Free the input parameter list (if we created one) */
484 if (Info->Parameters)
486 /* Free the allocated parameter block */
488 AcpiUtDeleteInternalObjectList (Info->Parameters);
491 ACPI_FREE (Info);
492 return_ACPI_STATUS (Status);
495 ACPI_EXPORT_SYMBOL (AcpiEvaluateObject)
498 /*******************************************************************************
500 * FUNCTION: AcpiNsResolveReferences
502 * PARAMETERS: Info - Evaluation info block
504 * RETURN: Info->ReturnObject is replaced with the dereferenced object
506 * DESCRIPTION: Dereference certain reference objects. Called before an
507 * internal return object is converted to an external ACPI_OBJECT.
509 * Performs an automatic dereference of Index and RefOf reference objects.
510 * These reference objects are not supported by the ACPI_OBJECT, so this is a
511 * last resort effort to return something useful. Also, provides compatibility
512 * with other ACPI implementations.
514 * NOTE: does not handle references within returned package objects or nested
515 * references, but this support could be added later if found to be necessary.
517 ******************************************************************************/
519 static void
520 AcpiNsResolveReferences (
521 ACPI_EVALUATE_INFO *Info)
523 ACPI_OPERAND_OBJECT *ObjDesc = NULL;
524 ACPI_NAMESPACE_NODE *Node;
527 /* We are interested in reference objects only */
529 if ((Info->ReturnObject)->Common.Type != ACPI_TYPE_LOCAL_REFERENCE)
531 return;
535 * Two types of references are supported - those created by Index and
536 * RefOf operators. A name reference (AML_NAMEPATH_OP) can be converted
537 * to an ACPI_OBJECT, so it is not dereferenced here. A DdbHandle
538 * (AML_LOAD_OP) cannot be dereferenced, nor can it be converted to
539 * an ACPI_OBJECT.
541 switch (Info->ReturnObject->Reference.Class)
543 case ACPI_REFCLASS_INDEX:
545 ObjDesc = *(Info->ReturnObject->Reference.Where);
546 break;
548 case ACPI_REFCLASS_REFOF:
550 Node = Info->ReturnObject->Reference.Object;
551 if (Node)
553 ObjDesc = Node->Object;
555 break;
557 default:
559 return;
562 /* Replace the existing reference object */
564 if (ObjDesc)
566 AcpiUtAddReference (ObjDesc);
567 AcpiUtRemoveReference (Info->ReturnObject);
568 Info->ReturnObject = ObjDesc;
571 return;
575 /*******************************************************************************
577 * FUNCTION: AcpiWalkNamespace
579 * PARAMETERS: Type - ACPI_OBJECT_TYPE to search for
580 * StartObject - Handle in namespace where search begins
581 * MaxDepth - Depth to which search is to reach
582 * DescendingCallback - Called during tree descent
583 * when an object of "Type" is found
584 * AscendingCallback - Called during tree ascent
585 * when an object of "Type" is found
586 * Context - Passed to user function(s) above
587 * ReturnValue - Location where return value of
588 * UserFunction is put if terminated early
590 * RETURNS Return value from the UserFunction if terminated early.
591 * Otherwise, returns NULL.
593 * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
594 * starting (and ending) at the object specified by StartHandle.
595 * The callback function is called whenever an object that matches
596 * the type parameter is found. If the callback function returns
597 * a non-zero value, the search is terminated immediately and this
598 * value is returned to the caller.
600 * The point of this procedure is to provide a generic namespace
601 * walk routine that can be called from multiple places to
602 * provide multiple services; the callback function(s) can be
603 * tailored to each task, whether it is a print function,
604 * a compare function, etc.
606 ******************************************************************************/
608 ACPI_STATUS
609 AcpiWalkNamespace (
610 ACPI_OBJECT_TYPE Type,
611 ACPI_HANDLE StartObject,
612 UINT32 MaxDepth,
613 ACPI_WALK_CALLBACK DescendingCallback,
614 ACPI_WALK_CALLBACK AscendingCallback,
615 void *Context,
616 void **ReturnValue)
618 ACPI_STATUS Status;
621 ACPI_FUNCTION_TRACE (AcpiWalkNamespace);
624 /* Parameter validation */
626 if ((Type > ACPI_TYPE_LOCAL_MAX) ||
627 (!MaxDepth) ||
628 (!DescendingCallback && !AscendingCallback))
630 return_ACPI_STATUS (AE_BAD_PARAMETER);
634 * Need to acquire the namespace reader lock to prevent interference
635 * with any concurrent table unloads (which causes the deletion of
636 * namespace objects). We cannot allow the deletion of a namespace node
637 * while the user function is using it. The exception to this are the
638 * nodes created and deleted during control method execution -- these
639 * nodes are marked as temporary nodes and are ignored by the namespace
640 * walk. Thus, control methods can be executed while holding the
641 * namespace deletion lock (and the user function can execute control
642 * methods.)
644 Status = AcpiUtAcquireReadLock (&AcpiGbl_NamespaceRwLock);
645 if (ACPI_FAILURE (Status))
647 return_ACPI_STATUS (Status);
651 * Lock the namespace around the walk. The namespace will be
652 * unlocked/locked around each call to the user function - since the user
653 * function must be allowed to make ACPICA calls itself (for example, it
654 * will typically execute control methods during device enumeration.)
656 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
657 if (ACPI_FAILURE (Status))
659 goto UnlockAndExit;
662 /* Now we can validate the starting node */
664 if (!AcpiNsValidateHandle (StartObject))
666 Status = AE_BAD_PARAMETER;
667 goto UnlockAndExit2;
670 Status = AcpiNsWalkNamespace (Type, StartObject, MaxDepth,
671 ACPI_NS_WALK_UNLOCK, DescendingCallback,
672 AscendingCallback, Context, ReturnValue);
674 UnlockAndExit2:
675 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
677 UnlockAndExit:
678 (void) AcpiUtReleaseReadLock (&AcpiGbl_NamespaceRwLock);
679 return_ACPI_STATUS (Status);
682 ACPI_EXPORT_SYMBOL (AcpiWalkNamespace)
685 /*******************************************************************************
687 * FUNCTION: AcpiNsGetDeviceCallback
689 * PARAMETERS: Callback from AcpiGetDevice
691 * RETURN: Status
693 * DESCRIPTION: Takes callbacks from WalkNamespace and filters out all non-
694 * present devices, or if they specified a HID, it filters based
695 * on that.
697 ******************************************************************************/
699 static ACPI_STATUS
700 AcpiNsGetDeviceCallback (
701 ACPI_HANDLE ObjHandle,
702 UINT32 NestingLevel,
703 void *Context,
704 void **ReturnValue)
706 ACPI_GET_DEVICES_INFO *Info = Context;
707 ACPI_STATUS Status;
708 ACPI_NAMESPACE_NODE *Node;
709 UINT32 Flags;
710 ACPI_PNP_DEVICE_ID *Hid;
711 ACPI_PNP_DEVICE_ID_LIST *Cid;
712 UINT32 i;
713 BOOLEAN Found;
714 int NoMatch;
717 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
718 if (ACPI_FAILURE (Status))
720 return (Status);
723 Node = AcpiNsValidateHandle (ObjHandle);
724 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
725 if (ACPI_FAILURE (Status))
727 return (Status);
730 if (!Node)
732 return (AE_BAD_PARAMETER);
736 * First, filter based on the device HID and CID.
738 * 01/2010: For this case where a specific HID is requested, we don't
739 * want to run _STA until we have an actual HID match. Thus, we will
740 * not unnecessarily execute _STA on devices for which the caller
741 * doesn't care about. Previously, _STA was executed unconditionally
742 * on all devices found here.
744 * A side-effect of this change is that now we will continue to search
745 * for a matching HID even under device trees where the parent device
746 * would have returned a _STA that indicates it is not present or
747 * not functioning (thus aborting the search on that branch).
749 if (Info->Hid != NULL)
751 Status = AcpiUtExecute_HID (Node, &Hid);
752 if (Status == AE_NOT_FOUND)
754 return (AE_OK);
756 else if (ACPI_FAILURE (Status))
758 return (AE_CTRL_DEPTH);
761 NoMatch = ACPI_STRCMP (Hid->String, Info->Hid);
762 ACPI_FREE (Hid);
764 if (NoMatch)
767 * HID does not match, attempt match within the
768 * list of Compatible IDs (CIDs)
770 Status = AcpiUtExecute_CID (Node, &Cid);
771 if (Status == AE_NOT_FOUND)
773 return (AE_OK);
775 else if (ACPI_FAILURE (Status))
777 return (AE_CTRL_DEPTH);
780 /* Walk the CID list */
782 Found = FALSE;
783 for (i = 0; i < Cid->Count; i++)
785 if (ACPI_STRCMP (Cid->Ids[i].String, Info->Hid) == 0)
787 /* Found a matching CID */
789 Found = TRUE;
790 break;
794 ACPI_FREE (Cid);
795 if (!Found)
797 return (AE_OK);
802 /* Run _STA to determine if device is present */
804 Status = AcpiUtExecute_STA (Node, &Flags);
805 if (ACPI_FAILURE (Status))
807 return (AE_CTRL_DEPTH);
810 if (!(Flags & ACPI_STA_DEVICE_PRESENT) &&
811 !(Flags & ACPI_STA_DEVICE_FUNCTIONING))
814 * Don't examine the children of the device only when the
815 * device is neither present nor functional. See ACPI spec,
816 * description of _STA for more information.
818 return (AE_CTRL_DEPTH);
821 /* We have a valid device, invoke the user function */
823 Status = Info->UserFunction (ObjHandle, NestingLevel, Info->Context,
824 ReturnValue);
825 return (Status);
829 /*******************************************************************************
831 * FUNCTION: AcpiGetDevices
833 * PARAMETERS: HID - HID to search for. Can be NULL.
834 * UserFunction - Called when a matching object is found
835 * Context - Passed to user function
836 * ReturnValue - Location where return value of
837 * UserFunction is put if terminated early
839 * RETURNS Return value from the UserFunction if terminated early.
840 * Otherwise, returns NULL.
842 * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
843 * starting (and ending) at the object specified by StartHandle.
844 * The UserFunction is called whenever an object of type
845 * Device is found. If the user function returns
846 * a non-zero value, the search is terminated immediately and this
847 * value is returned to the caller.
849 * This is a wrapper for WalkNamespace, but the callback performs
850 * additional filtering. Please see AcpiNsGetDeviceCallback.
852 ******************************************************************************/
854 ACPI_STATUS
855 AcpiGetDevices (
856 char *HID,
857 ACPI_WALK_CALLBACK UserFunction,
858 void *Context,
859 void **ReturnValue)
861 ACPI_STATUS Status;
862 ACPI_GET_DEVICES_INFO Info;
865 ACPI_FUNCTION_TRACE (AcpiGetDevices);
868 /* Parameter validation */
870 if (!UserFunction)
872 return_ACPI_STATUS (AE_BAD_PARAMETER);
876 * We're going to call their callback from OUR callback, so we need
877 * to know what it is, and their context parameter.
879 Info.Hid = HID;
880 Info.Context = Context;
881 Info.UserFunction = UserFunction;
884 * Lock the namespace around the walk.
885 * The namespace will be unlocked/locked around each call
886 * to the user function - since this function
887 * must be allowed to make Acpi calls itself.
889 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
890 if (ACPI_FAILURE (Status))
892 return_ACPI_STATUS (Status);
895 Status = AcpiNsWalkNamespace (ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
896 ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK,
897 AcpiNsGetDeviceCallback, NULL, &Info, ReturnValue);
899 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
900 return_ACPI_STATUS (Status);
903 ACPI_EXPORT_SYMBOL (AcpiGetDevices)
906 /*******************************************************************************
908 * FUNCTION: AcpiAttachData
910 * PARAMETERS: ObjHandle - Namespace node
911 * Handler - Handler for this attachment
912 * Data - Pointer to data to be attached
914 * RETURN: Status
916 * DESCRIPTION: Attach arbitrary data and handler to a namespace node.
918 ******************************************************************************/
920 ACPI_STATUS
921 AcpiAttachData (
922 ACPI_HANDLE ObjHandle,
923 ACPI_OBJECT_HANDLER Handler,
924 void *Data)
926 ACPI_NAMESPACE_NODE *Node;
927 ACPI_STATUS Status;
930 /* Parameter validation */
932 if (!ObjHandle ||
933 !Handler ||
934 !Data)
936 return (AE_BAD_PARAMETER);
939 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
940 if (ACPI_FAILURE (Status))
942 return (Status);
945 /* Convert and validate the handle */
947 Node = AcpiNsValidateHandle (ObjHandle);
948 if (!Node)
950 Status = AE_BAD_PARAMETER;
951 goto UnlockAndExit;
954 Status = AcpiNsAttachData (Node, Handler, Data);
956 UnlockAndExit:
957 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
958 return (Status);
961 ACPI_EXPORT_SYMBOL (AcpiAttachData)
964 /*******************************************************************************
966 * FUNCTION: AcpiDetachData
968 * PARAMETERS: ObjHandle - Namespace node handle
969 * Handler - Handler used in call to AcpiAttachData
971 * RETURN: Status
973 * DESCRIPTION: Remove data that was previously attached to a node.
975 ******************************************************************************/
977 ACPI_STATUS
978 AcpiDetachData (
979 ACPI_HANDLE ObjHandle,
980 ACPI_OBJECT_HANDLER Handler)
982 ACPI_NAMESPACE_NODE *Node;
983 ACPI_STATUS Status;
986 /* Parameter validation */
988 if (!ObjHandle ||
989 !Handler)
991 return (AE_BAD_PARAMETER);
994 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
995 if (ACPI_FAILURE (Status))
997 return (Status);
1000 /* Convert and validate the handle */
1002 Node = AcpiNsValidateHandle (ObjHandle);
1003 if (!Node)
1005 Status = AE_BAD_PARAMETER;
1006 goto UnlockAndExit;
1009 Status = AcpiNsDetachData (Node, Handler);
1011 UnlockAndExit:
1012 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
1013 return (Status);
1016 ACPI_EXPORT_SYMBOL (AcpiDetachData)
1019 /*******************************************************************************
1021 * FUNCTION: AcpiGetData
1023 * PARAMETERS: ObjHandle - Namespace node
1024 * Handler - Handler used in call to AttachData
1025 * Data - Where the data is returned
1027 * RETURN: Status
1029 * DESCRIPTION: Retrieve data that was previously attached to a namespace node.
1031 ******************************************************************************/
1033 ACPI_STATUS
1034 AcpiGetData (
1035 ACPI_HANDLE ObjHandle,
1036 ACPI_OBJECT_HANDLER Handler,
1037 void **Data)
1039 ACPI_NAMESPACE_NODE *Node;
1040 ACPI_STATUS Status;
1043 /* Parameter validation */
1045 if (!ObjHandle ||
1046 !Handler ||
1047 !Data)
1049 return (AE_BAD_PARAMETER);
1052 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
1053 if (ACPI_FAILURE (Status))
1055 return (Status);
1058 /* Convert and validate the handle */
1060 Node = AcpiNsValidateHandle (ObjHandle);
1061 if (!Node)
1063 Status = AE_BAD_PARAMETER;
1064 goto UnlockAndExit;
1067 Status = AcpiNsGetAttachedData (Node, Handler, Data);
1069 UnlockAndExit:
1070 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
1071 return (Status);
1074 ACPI_EXPORT_SYMBOL (AcpiGetData)