nsxfeval.c revision 128212
1/*******************************************************************************
2 *
3 * Module Name: nsxfeval - Public interfaces to the ACPI subsystem
4 *                         ACPI Object evaluation interfaces
5 *              $Revision: 12 $
6 *
7 ******************************************************************************/
8
9/******************************************************************************
10 *
11 * 1. Copyright Notice
12 *
13 * Some or all of this work - Copyright (c) 1999 - 2004, Intel Corp.
14 * All rights reserved.
15 *
16 * 2. License
17 *
18 * 2.1. This is your license from Intel Corp. under its intellectual property
19 * rights.  You may have additional license terms from the party that provided
20 * you this software, covering your right to use that party's intellectual
21 * property rights.
22 *
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
29 *
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;
38 *
39 * The above copyright and patent license is granted only if the following
40 * conditions are met:
41 *
42 * 3. Conditions
43 *
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.
55 *
56 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57 * Redistribution of source code of any substantial portion of the Covered
58 * Code or modification without rights to further distribute source must
59 * include the following Disclaimer and Export Compliance provision in the
60 * documentation and/or other materials provided with distribution.  In
61 * addition, Licensee may not authorize further sublicense of source of any
62 * portion of the Covered Code, and must include terms to the effect that the
63 * license from Licensee to its licensee is limited to the intellectual
64 * property embodied in the software Licensee provides to its licensee, and
65 * not to intellectual property embodied in modifications its licensee may
66 * make.
67 *
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
72 * distribution.
73 *
74 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * Intel Code.
76 *
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.
81 *
82 * 4. Disclaimer and Export Compliance
83 *
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
90 * PARTICULAR PURPOSE.
91 *
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
99 * LIMITED REMEDY.
100 *
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.
115 *
116 *****************************************************************************/
117
118
119#define __NSXFEVAL_C__
120
121#include "acpi.h"
122#include "acnamesp.h"
123#include "acinterp.h"
124
125
126#define _COMPONENT          ACPI_NAMESPACE
127        ACPI_MODULE_NAME    ("nsxfeval")
128
129
130/*******************************************************************************
131 *
132 * FUNCTION:    AcpiEvaluateObjectTyped
133 *
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
142 *
143 * RETURN:      Status
144 *
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)
148 *
149 ******************************************************************************/
150
151ACPI_STATUS
152AcpiEvaluateObjectTyped (
153    ACPI_HANDLE             Handle,
154    ACPI_STRING             Pathname,
155    ACPI_OBJECT_LIST        *ExternalParams,
156    ACPI_BUFFER             *ReturnBuffer,
157    ACPI_OBJECT_TYPE        ReturnType)
158{
159    ACPI_STATUS             Status;
160    BOOLEAN                 MustFree = FALSE;
161
162
163    ACPI_FUNCTION_TRACE ("AcpiEvaluateObjectTyped");
164
165
166    /* Return buffer must be valid */
167
168    if (!ReturnBuffer)
169    {
170        return_ACPI_STATUS (AE_BAD_PARAMETER);
171    }
172
173    if (ReturnBuffer->Length == ACPI_ALLOCATE_BUFFER)
174    {
175        MustFree = TRUE;
176    }
177
178    /* Evaluate the object */
179
180    Status = AcpiEvaluateObject (Handle, Pathname, ExternalParams, ReturnBuffer);
181    if (ACPI_FAILURE (Status))
182    {
183        return_ACPI_STATUS (Status);
184    }
185
186    /* Type ANY means "don't care" */
187
188    if (ReturnType == ACPI_TYPE_ANY)
189    {
190        return_ACPI_STATUS (AE_OK);
191    }
192
193    if (ReturnBuffer->Length == 0)
194    {
195        /* Error because caller specifically asked for a return value */
196
197        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
198            "No return value\n"));
199
200        return_ACPI_STATUS (AE_NULL_OBJECT);
201    }
202
203    /* Examine the object type returned from EvaluateObject */
204
205    if (((ACPI_OBJECT *) ReturnBuffer->Pointer)->Type == ReturnType)
206    {
207        return_ACPI_STATUS (AE_OK);
208    }
209
210    /* Return object type does not match requested type */
211
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)));
216
217    if (MustFree)
218    {
219        /* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */
220
221        AcpiOsFree (ReturnBuffer->Pointer);
222        ReturnBuffer->Pointer = NULL;
223    }
224
225    ReturnBuffer->Length = 0;
226    return_ACPI_STATUS (AE_TYPE);
227}
228
229
230/*******************************************************************************
231 *
232 * FUNCTION:    AcpiEvaluateObject
233 *
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.
241 *
242 * RETURN:      Status
243 *
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)
247 *
248 ******************************************************************************/
249
250ACPI_STATUS
251AcpiEvaluateObject (
252    ACPI_HANDLE             Handle,
253    ACPI_STRING             Pathname,
254    ACPI_OBJECT_LIST        *ExternalParams,
255    ACPI_BUFFER             *ReturnBuffer)
256{
257    ACPI_STATUS             Status;
258    ACPI_STATUS             Status2;
259    ACPI_OPERAND_OBJECT     **InternalParams = NULL;
260    ACPI_OPERAND_OBJECT     *InternalReturnObj = NULL;
261    ACPI_SIZE               BufferSpaceNeeded;
262    UINT32                  i;
263
264
265    ACPI_FUNCTION_TRACE ("AcpiEvaluateObject");
266
267
268    /*
269     * If there are parameters to be passed to the object
270     * (which must be a control method), the external objects
271     * must be converted to internal objects
272     */
273    if (ExternalParams && ExternalParams->Count)
274    {
275        /*
276         * Allocate a new parameter block for the internal objects
277         * Add 1 to count to allow for null terminated internal list
278         */
279        InternalParams = ACPI_MEM_CALLOCATE (((ACPI_SIZE) ExternalParams->Count + 1) *
280                                                sizeof (void *));
281        if (!InternalParams)
282        {
283            return_ACPI_STATUS (AE_NO_MEMORY);
284        }
285
286        /*
287         * Convert each external object in the list to an
288         * internal object
289         */
290        for (i = 0; i < ExternalParams->Count; i++)
291        {
292            Status = AcpiUtCopyEobjectToIobject (&ExternalParams->Pointer[i],
293                                                 &InternalParams[i]);
294            if (ACPI_FAILURE (Status))
295            {
296                AcpiUtDeleteInternalObjectList (InternalParams);
297                return_ACPI_STATUS (Status);
298            }
299        }
300        InternalParams[ExternalParams->Count] = NULL;
301    }
302
303    /*
304     * Three major cases:
305     * 1) Fully qualified pathname
306     * 2) No handle, not fully qualified pathname (error)
307     * 3) Valid handle
308     */
309    if ((Pathname) &&
310        (AcpiNsValidRootPrefix (Pathname[0])))
311    {
312        /*
313         *  The path is fully qualified, just evaluate by name
314         */
315        Status = AcpiNsEvaluateByName (Pathname, InternalParams,
316                    &InternalReturnObj);
317    }
318    else if (!Handle)
319    {
320        /*
321         * A handle is optional iff a fully qualified pathname
322         * is specified.  Since we've already handled fully
323         * qualified names above, this is an error
324         */
325        if (!Pathname)
326        {
327            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
328                "Both Handle and Pathname are NULL\n"));
329        }
330        else
331        {
332            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
333                "Handle is NULL and Pathname is relative\n"));
334        }
335
336        Status = AE_BAD_PARAMETER;
337    }
338    else
339    {
340        /*
341         * We get here if we have a handle -- and if we have a
342         * pathname it is relative.  The handle will be validated
343         * in the lower procedures
344         */
345        if (!Pathname)
346        {
347            /*
348             * The null pathname case means the handle is for
349             * the actual object to be evaluated
350             */
351            Status = AcpiNsEvaluateByHandle (Handle, InternalParams,
352                            &InternalReturnObj);
353        }
354        else
355        {
356           /*
357            * Both a Handle and a relative Pathname
358            */
359            Status = AcpiNsEvaluateRelative (Handle, Pathname, InternalParams,
360                            &InternalReturnObj);
361        }
362    }
363
364
365    /*
366     * If we are expecting a return value, and all went well above,
367     * copy the return value to an external object.
368     */
369    if (ReturnBuffer)
370    {
371        if (!InternalReturnObj)
372        {
373            ReturnBuffer->Length = 0;
374        }
375        else
376        {
377            if (ACPI_GET_DESCRIPTOR_TYPE (InternalReturnObj) == ACPI_DESC_TYPE_NAMED)
378            {
379                /*
380                 * If we received a NS Node as a return object, this means that
381                 * the object we are evaluating has nothing interesting to
382                 * return (such as a mutex, etc.)  We return an error because
383                 * these types are essentially unsupported by this interface.
384                 * We don't check up front because this makes it easier to add
385                 * support for various types at a later date if necessary.
386                 */
387                Status = AE_TYPE;
388                InternalReturnObj = NULL;   /* No need to delete a NS Node */
389                ReturnBuffer->Length = 0;
390            }
391
392            if (ACPI_SUCCESS (Status))
393            {
394                /*
395                 * Find out how large a buffer is needed
396                 * to contain the returned object
397                 */
398                Status = AcpiUtGetObjectSize (InternalReturnObj,
399                                                &BufferSpaceNeeded);
400                if (ACPI_SUCCESS (Status))
401                {
402                    /* Validate/Allocate/Clear caller buffer */
403
404                    Status = AcpiUtInitializeBuffer (ReturnBuffer, BufferSpaceNeeded);
405                    if (ACPI_FAILURE (Status))
406                    {
407                        /*
408                         * Caller's buffer is too small or a new one can't be allocated
409                         */
410                        ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
411                            "Needed buffer size %X, %s\n",
412                            (UINT32) BufferSpaceNeeded, AcpiFormatException (Status)));
413                    }
414                    else
415                    {
416                        /*
417                         *  We have enough space for the object, build it
418                         */
419                        Status = AcpiUtCopyIobjectToEobject (InternalReturnObj,
420                                        ReturnBuffer);
421                    }
422                }
423            }
424        }
425    }
426
427    if (InternalReturnObj)
428    {
429        /*
430         * Delete the internal return object.  NOTE: Interpreter
431         * must be locked to avoid race condition.
432         */
433        Status2 = AcpiExEnterInterpreter ();
434        if (ACPI_SUCCESS (Status2))
435        {
436            /*
437             * Delete the internal return object. (Or at least
438             * decrement the reference count by one)
439             */
440            AcpiUtRemoveReference (InternalReturnObj);
441            AcpiExExitInterpreter ();
442        }
443    }
444
445    /*
446     * Free the input parameter list (if we created one),
447     */
448    if (InternalParams)
449    {
450        /* Free the allocated parameter block */
451
452        AcpiUtDeleteInternalObjectList (InternalParams);
453    }
454
455    return_ACPI_STATUS (Status);
456}
457
458
459/*******************************************************************************
460 *
461 * FUNCTION:    AcpiWalkNamespace
462 *
463 * PARAMETERS:  Type                - ACPI_OBJECT_TYPE to search for
464 *              StartObject         - Handle in namespace where search begins
465 *              MaxDepth            - Depth to which search is to reach
466 *              UserFunction        - Called when an object of "Type" is found
467 *              Context             - Passed to user function
468 *              ReturnValue         - Location where return value of
469 *                                    UserFunction is put if terminated early
470 *
471 * RETURNS      Return value from the UserFunction if terminated early.
472 *              Otherwise, returns NULL.
473 *
474 * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
475 *              starting (and ending) at the object specified by StartHandle.
476 *              The UserFunction is called whenever an object that matches
477 *              the type parameter is found.  If the user function returns
478 *              a non-zero value, the search is terminated immediately and this
479 *              value is returned to the caller.
480 *
481 *              The point of this procedure is to provide a generic namespace
482 *              walk routine that can be called from multiple places to
483 *              provide multiple services;  the User Function can be tailored
484 *              to each task, whether it is a print function, a compare
485 *              function, etc.
486 *
487 ******************************************************************************/
488
489ACPI_STATUS
490AcpiWalkNamespace (
491    ACPI_OBJECT_TYPE        Type,
492    ACPI_HANDLE             StartObject,
493    UINT32                  MaxDepth,
494    ACPI_WALK_CALLBACK      UserFunction,
495    void                    *Context,
496    void                    **ReturnValue)
497{
498    ACPI_STATUS             Status;
499
500
501    ACPI_FUNCTION_TRACE ("AcpiWalkNamespace");
502
503
504    /* Parameter validation */
505
506    if ((Type > ACPI_TYPE_EXTERNAL_MAX) ||
507        (!MaxDepth)                     ||
508        (!UserFunction))
509    {
510        return_ACPI_STATUS (AE_BAD_PARAMETER);
511    }
512
513    /*
514     * Lock the namespace around the walk.
515     * The namespace will be unlocked/locked around each call
516     * to the user function - since this function
517     * must be allowed to make Acpi calls itself.
518     */
519    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
520    if (ACPI_FAILURE (Status))
521    {
522        return_ACPI_STATUS (Status);
523    }
524
525    Status = AcpiNsWalkNamespace (Type, StartObject, MaxDepth, ACPI_NS_WALK_UNLOCK,
526                    UserFunction, Context, ReturnValue);
527
528    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
529    return_ACPI_STATUS (Status);
530}
531
532
533/*******************************************************************************
534 *
535 * FUNCTION:    AcpiNsGetDeviceCallback
536 *
537 * PARAMETERS:  Callback from AcpiGetDevice
538 *
539 * RETURN:      Status
540 *
541 * DESCRIPTION: Takes callbacks from WalkNamespace and filters out all non-
542 *              present devices, or if they specified a HID, it filters based
543 *              on that.
544 *
545 ******************************************************************************/
546
547static ACPI_STATUS
548AcpiNsGetDeviceCallback (
549    ACPI_HANDLE             ObjHandle,
550    UINT32                  NestingLevel,
551    void                    *Context,
552    void                    **ReturnValue)
553{
554    ACPI_GET_DEVICES_INFO   *Info = Context;
555    ACPI_STATUS             Status;
556    ACPI_NAMESPACE_NODE     *Node;
557    UINT32                  Flags;
558    ACPI_DEVICE_ID          Hid;
559    ACPI_COMPATIBLE_ID_LIST *Cid;
560    ACPI_NATIVE_UINT        i;
561
562
563    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
564    if (ACPI_FAILURE (Status))
565    {
566        return (Status);
567    }
568
569    Node = AcpiNsMapHandleToNode (ObjHandle);
570    Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
571    if (ACPI_FAILURE (Status))
572    {
573        return (Status);
574    }
575
576    if (!Node)
577    {
578        return (AE_BAD_PARAMETER);
579    }
580
581    /* Run _STA to determine if device is present */
582
583    Status = AcpiUtExecute_STA (Node, &Flags);
584    if (ACPI_FAILURE (Status))
585    {
586        return (AE_CTRL_DEPTH);
587    }
588
589    if (!(Flags & 0x01))
590    {
591        /* Don't return at the device or children of the device if not there */
592
593        return (AE_CTRL_DEPTH);
594    }
595
596    /* Filter based on device HID & CID */
597
598    if (Info->Hid != NULL)
599    {
600        Status = AcpiUtExecute_HID (Node, &Hid);
601        if (Status == AE_NOT_FOUND)
602        {
603            return (AE_OK);
604        }
605        else if (ACPI_FAILURE (Status))
606        {
607            return (AE_CTRL_DEPTH);
608        }
609
610        if (ACPI_STRNCMP (Hid.Value, Info->Hid, sizeof (Hid.Value)) != 0)
611        {
612            /* Get the list of Compatible IDs */
613
614            Status = AcpiUtExecute_CID (Node, &Cid);
615            if (Status == AE_NOT_FOUND)
616            {
617                return (AE_OK);
618            }
619            else if (ACPI_FAILURE (Status))
620            {
621                return (AE_CTRL_DEPTH);
622            }
623
624            /* Walk the CID list */
625
626            for (i = 0; i < Cid->Count; i++)
627            {
628                if (ACPI_STRNCMP (Cid->Id[i].Value, Info->Hid,
629                                        sizeof (ACPI_COMPATIBLE_ID)) != 0)
630                {
631                    ACPI_MEM_FREE (Cid);
632                    return (AE_OK);
633                }
634            }
635            ACPI_MEM_FREE (Cid);
636        }
637    }
638
639    Status = Info->UserFunction (ObjHandle, NestingLevel, Info->Context, ReturnValue);
640    return (Status);
641}
642
643
644/*******************************************************************************
645 *
646 * FUNCTION:    AcpiGetDevices
647 *
648 * PARAMETERS:  HID                 - HID to search for. Can be NULL.
649 *              UserFunction        - Called when a matching object is found
650 *              Context             - Passed to user function
651 *              ReturnValue         - Location where return value of
652 *                                    UserFunction is put if terminated early
653 *
654 * RETURNS      Return value from the UserFunction if terminated early.
655 *              Otherwise, returns NULL.
656 *
657 * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
658 *              starting (and ending) at the object specified by StartHandle.
659 *              The UserFunction is called whenever an object of type
660 *              Device is found.  If the user function returns
661 *              a non-zero value, the search is terminated immediately and this
662 *              value is returned to the caller.
663 *
664 *              This is a wrapper for WalkNamespace, but the callback performs
665 *              additional filtering. Please see AcpiGetDeviceCallback.
666 *
667 ******************************************************************************/
668
669ACPI_STATUS
670AcpiGetDevices (
671    char                    *HID,
672    ACPI_WALK_CALLBACK      UserFunction,
673    void                    *Context,
674    void                    **ReturnValue)
675{
676    ACPI_STATUS             Status;
677    ACPI_GET_DEVICES_INFO   Info;
678
679
680    ACPI_FUNCTION_TRACE ("AcpiGetDevices");
681
682
683    /* Parameter validation */
684
685    if (!UserFunction)
686    {
687        return_ACPI_STATUS (AE_BAD_PARAMETER);
688    }
689
690    /*
691     * We're going to call their callback from OUR callback, so we need
692     * to know what it is, and their context parameter.
693     */
694    Info.Context      = Context;
695    Info.UserFunction = UserFunction;
696    Info.Hid          = HID;
697
698    /*
699     * Lock the namespace around the walk.
700     * The namespace will be unlocked/locked around each call
701     * to the user function - since this function
702     * must be allowed to make Acpi calls itself.
703     */
704    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
705    if (ACPI_FAILURE (Status))
706    {
707        return_ACPI_STATUS (Status);
708    }
709
710    Status = AcpiNsWalkNamespace (ACPI_TYPE_DEVICE,
711                                    ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
712                                    ACPI_NS_WALK_UNLOCK,
713                                    AcpiNsGetDeviceCallback, &Info,
714                                    ReturnValue);
715
716    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
717    return_ACPI_STATUS (Status);
718}
719
720
721/*******************************************************************************
722 *
723 * FUNCTION:    AcpiAttachData
724 *
725 * PARAMETERS:  ObjHandle           - Namespace node
726 *              Handler             - Handler for this attachment
727 *              Data                - Pointer to data to be attached
728 *
729 * RETURN:      Status
730 *
731 * DESCRIPTION: Attach arbitrary data and handler to a namespace node.
732 *
733 ******************************************************************************/
734
735ACPI_STATUS
736AcpiAttachData (
737    ACPI_HANDLE             ObjHandle,
738    ACPI_OBJECT_HANDLER     Handler,
739    void                    *Data)
740{
741    ACPI_NAMESPACE_NODE     *Node;
742    ACPI_STATUS             Status;
743
744
745    /* Parameter validation */
746
747    if (!ObjHandle  ||
748        !Handler    ||
749        !Data)
750    {
751        return (AE_BAD_PARAMETER);
752    }
753
754    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
755    if (ACPI_FAILURE (Status))
756    {
757        return (Status);
758    }
759
760    /* Convert and validate the handle */
761
762    Node = AcpiNsMapHandleToNode (ObjHandle);
763    if (!Node)
764    {
765        Status = AE_BAD_PARAMETER;
766        goto UnlockAndExit;
767    }
768
769    Status = AcpiNsAttachData (Node, Handler, Data);
770
771UnlockAndExit:
772    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
773    return (Status);
774}
775
776
777/*******************************************************************************
778 *
779 * FUNCTION:    AcpiDetachData
780 *
781 * PARAMETERS:  ObjHandle           - Namespace node handle
782 *              Handler             - Handler used in call to AcpiAttachData
783 *
784 * RETURN:      Status
785 *
786 * DESCRIPTION: Remove data that was previously attached to a node.
787 *
788 ******************************************************************************/
789
790ACPI_STATUS
791AcpiDetachData (
792    ACPI_HANDLE             ObjHandle,
793    ACPI_OBJECT_HANDLER     Handler)
794{
795    ACPI_NAMESPACE_NODE     *Node;
796    ACPI_STATUS             Status;
797
798
799    /* Parameter validation */
800
801    if (!ObjHandle  ||
802        !Handler)
803    {
804        return (AE_BAD_PARAMETER);
805    }
806
807    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
808    if (ACPI_FAILURE (Status))
809    {
810        return (Status);
811    }
812
813    /* Convert and validate the handle */
814
815    Node = AcpiNsMapHandleToNode (ObjHandle);
816    if (!Node)
817    {
818        Status = AE_BAD_PARAMETER;
819        goto UnlockAndExit;
820    }
821
822    Status = AcpiNsDetachData (Node, Handler);
823
824UnlockAndExit:
825    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
826    return (Status);
827}
828
829
830/*******************************************************************************
831 *
832 * FUNCTION:    AcpiGetData
833 *
834 * PARAMETERS:  ObjHandle           - Namespace node
835 *              Handler             - Handler used in call to AttachData
836 *              Data                - Where the data is returned
837 *
838 * RETURN:      Status
839 *
840 * DESCRIPTION: Retrieve data that was previously attached to a namespace node.
841 *
842 ******************************************************************************/
843
844ACPI_STATUS
845AcpiGetData (
846    ACPI_HANDLE             ObjHandle,
847    ACPI_OBJECT_HANDLER     Handler,
848    void                    **Data)
849{
850    ACPI_NAMESPACE_NODE     *Node;
851    ACPI_STATUS             Status;
852
853
854    /* Parameter validation */
855
856    if (!ObjHandle  ||
857        !Handler    ||
858        !Data)
859    {
860        return (AE_BAD_PARAMETER);
861    }
862
863    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
864    if (ACPI_FAILURE (Status))
865    {
866        return (Status);
867    }
868
869    /* Convert and validate the handle */
870
871    Node = AcpiNsMapHandleToNode (ObjHandle);
872    if (!Node)
873    {
874        Status = AE_BAD_PARAMETER;
875        goto UnlockAndExit;
876    }
877
878    Status = AcpiNsGetAttachedData (Node, Handler, Data);
879
880UnlockAndExit:
881    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
882    return (Status);
883}
884
885
886