Home | History | Annotate | Line # | Download | only in namespace
nsxfeval.c revision 1.3.4.2
      1  1.3.4.2  rmind /*******************************************************************************
      2  1.3.4.2  rmind  *
      3  1.3.4.2  rmind  * Module Name: nsxfeval - Public interfaces to the ACPI subsystem
      4  1.3.4.2  rmind  *                         ACPI Object evaluation interfaces
      5  1.3.4.2  rmind  *
      6  1.3.4.2  rmind  ******************************************************************************/
      7  1.3.4.2  rmind 
      8  1.3.4.2  rmind /*
      9  1.3.4.2  rmind  * Copyright (C) 2000 - 2011, Intel Corp.
     10  1.3.4.2  rmind  * All rights reserved.
     11  1.3.4.2  rmind  *
     12  1.3.4.2  rmind  * Redistribution and use in source and binary forms, with or without
     13  1.3.4.2  rmind  * modification, are permitted provided that the following conditions
     14  1.3.4.2  rmind  * are met:
     15  1.3.4.2  rmind  * 1. Redistributions of source code must retain the above copyright
     16  1.3.4.2  rmind  *    notice, this list of conditions, and the following disclaimer,
     17  1.3.4.2  rmind  *    without modification.
     18  1.3.4.2  rmind  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     19  1.3.4.2  rmind  *    substantially similar to the "NO WARRANTY" disclaimer below
     20  1.3.4.2  rmind  *    ("Disclaimer") and any redistribution must be conditioned upon
     21  1.3.4.2  rmind  *    including a substantially similar Disclaimer requirement for further
     22  1.3.4.2  rmind  *    binary redistribution.
     23  1.3.4.2  rmind  * 3. Neither the names of the above-listed copyright holders nor the names
     24  1.3.4.2  rmind  *    of any contributors may be used to endorse or promote products derived
     25  1.3.4.2  rmind  *    from this software without specific prior written permission.
     26  1.3.4.2  rmind  *
     27  1.3.4.2  rmind  * Alternatively, this software may be distributed under the terms of the
     28  1.3.4.2  rmind  * GNU General Public License ("GPL") version 2 as published by the Free
     29  1.3.4.2  rmind  * Software Foundation.
     30  1.3.4.2  rmind  *
     31  1.3.4.2  rmind  * NO WARRANTY
     32  1.3.4.2  rmind  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     33  1.3.4.2  rmind  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     34  1.3.4.2  rmind  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     35  1.3.4.2  rmind  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     36  1.3.4.2  rmind  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37  1.3.4.2  rmind  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38  1.3.4.2  rmind  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39  1.3.4.2  rmind  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     40  1.3.4.2  rmind  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     41  1.3.4.2  rmind  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     42  1.3.4.2  rmind  * POSSIBILITY OF SUCH DAMAGES.
     43  1.3.4.2  rmind  */
     44  1.3.4.2  rmind 
     45  1.3.4.2  rmind 
     46  1.3.4.2  rmind #define __NSXFEVAL_C__
     47  1.3.4.2  rmind 
     48  1.3.4.2  rmind #include "acpi.h"
     49  1.3.4.2  rmind #include "accommon.h"
     50  1.3.4.2  rmind #include "acnamesp.h"
     51  1.3.4.2  rmind #include "acinterp.h"
     52  1.3.4.2  rmind 
     53  1.3.4.2  rmind 
     54  1.3.4.2  rmind #define _COMPONENT          ACPI_NAMESPACE
     55  1.3.4.2  rmind         ACPI_MODULE_NAME    ("nsxfeval")
     56  1.3.4.2  rmind 
     57  1.3.4.2  rmind /* Local prototypes */
     58  1.3.4.2  rmind 
     59  1.3.4.2  rmind static void
     60  1.3.4.2  rmind AcpiNsResolveReferences (
     61  1.3.4.2  rmind     ACPI_EVALUATE_INFO      *Info);
     62  1.3.4.2  rmind 
     63  1.3.4.2  rmind 
     64  1.3.4.2  rmind /*******************************************************************************
     65  1.3.4.2  rmind  *
     66  1.3.4.2  rmind  * FUNCTION:    AcpiEvaluateObjectTyped
     67  1.3.4.2  rmind  *
     68  1.3.4.2  rmind  * PARAMETERS:  Handle              - Object handle (optional)
     69  1.3.4.2  rmind  *              Pathname            - Object pathname (optional)
     70  1.3.4.2  rmind  *              ExternalParams      - List of parameters to pass to method,
     71  1.3.4.2  rmind  *                                    terminated by NULL.  May be NULL
     72  1.3.4.2  rmind  *                                    if no parameters are being passed.
     73  1.3.4.2  rmind  *              ReturnBuffer        - Where to put method's return value (if
     74  1.3.4.2  rmind  *                                    any).  If NULL, no value is returned.
     75  1.3.4.2  rmind  *              ReturnType          - Expected type of return object
     76  1.3.4.2  rmind  *
     77  1.3.4.2  rmind  * RETURN:      Status
     78  1.3.4.2  rmind  *
     79  1.3.4.2  rmind  * DESCRIPTION: Find and evaluate the given object, passing the given
     80  1.3.4.2  rmind  *              parameters if necessary.  One of "Handle" or "Pathname" must
     81  1.3.4.2  rmind  *              be valid (non-null)
     82  1.3.4.2  rmind  *
     83  1.3.4.2  rmind  ******************************************************************************/
     84  1.3.4.2  rmind 
     85  1.3.4.2  rmind ACPI_STATUS
     86  1.3.4.2  rmind AcpiEvaluateObjectTyped (
     87  1.3.4.2  rmind     ACPI_HANDLE             Handle,
     88  1.3.4.2  rmind     ACPI_CONST_STRING       Pathname,
     89  1.3.4.2  rmind     ACPI_OBJECT_LIST        *ExternalParams,
     90  1.3.4.2  rmind     ACPI_BUFFER             *ReturnBuffer,
     91  1.3.4.2  rmind     ACPI_OBJECT_TYPE        ReturnType)
     92  1.3.4.2  rmind {
     93  1.3.4.2  rmind     ACPI_STATUS             Status;
     94  1.3.4.2  rmind     BOOLEAN                 MustFree = FALSE;
     95  1.3.4.2  rmind 
     96  1.3.4.2  rmind     ACPI_FUNCTION_TRACE (AcpiEvaluateObjectTyped);
     97  1.3.4.2  rmind 
     98  1.3.4.2  rmind 
     99  1.3.4.2  rmind     /* Return buffer must be valid */
    100  1.3.4.2  rmind 
    101  1.3.4.2  rmind     if (!ReturnBuffer)
    102  1.3.4.2  rmind     {
    103  1.3.4.2  rmind         return_ACPI_STATUS (AE_BAD_PARAMETER);
    104  1.3.4.2  rmind     }
    105  1.3.4.2  rmind 
    106  1.3.4.2  rmind     if (ReturnBuffer->Length == ACPI_ALLOCATE_BUFFER)
    107  1.3.4.2  rmind     {
    108  1.3.4.2  rmind         MustFree = TRUE;
    109  1.3.4.2  rmind     }
    110  1.3.4.2  rmind 
    111  1.3.4.2  rmind     /* Evaluate the object */
    112  1.3.4.2  rmind 
    113  1.3.4.2  rmind     Status = AcpiEvaluateObject (Handle, Pathname, ExternalParams, ReturnBuffer);
    114  1.3.4.2  rmind     if (ACPI_FAILURE (Status))
    115  1.3.4.2  rmind     {
    116  1.3.4.2  rmind         return_ACPI_STATUS (Status);
    117  1.3.4.2  rmind     }
    118  1.3.4.2  rmind 
    119  1.3.4.2  rmind     /* Type ANY means "don't care" */
    120  1.3.4.2  rmind 
    121  1.3.4.2  rmind     if (ReturnType == ACPI_TYPE_ANY)
    122  1.3.4.2  rmind     {
    123  1.3.4.2  rmind         return_ACPI_STATUS (AE_OK);
    124  1.3.4.2  rmind     }
    125  1.3.4.2  rmind 
    126  1.3.4.2  rmind     if (ReturnBuffer->Length == 0)
    127  1.3.4.2  rmind     {
    128  1.3.4.2  rmind         /* Error because caller specifically asked for a return value */
    129  1.3.4.2  rmind 
    130  1.3.4.2  rmind         ACPI_ERROR ((AE_INFO, "No return value"));
    131  1.3.4.2  rmind         return_ACPI_STATUS (AE_NULL_OBJECT);
    132  1.3.4.2  rmind     }
    133  1.3.4.2  rmind 
    134  1.3.4.2  rmind     /* Examine the object type returned from EvaluateObject */
    135  1.3.4.2  rmind 
    136  1.3.4.2  rmind     if (((ACPI_OBJECT *) ReturnBuffer->Pointer)->Type == ReturnType)
    137  1.3.4.2  rmind     {
    138  1.3.4.2  rmind         return_ACPI_STATUS (AE_OK);
    139  1.3.4.2  rmind     }
    140  1.3.4.2  rmind 
    141  1.3.4.2  rmind     /* Return object type does not match requested type */
    142  1.3.4.2  rmind 
    143  1.3.4.2  rmind     ACPI_ERROR ((AE_INFO,
    144  1.3.4.2  rmind         "Incorrect return type [%s] requested [%s]",
    145  1.3.4.2  rmind         AcpiUtGetTypeName (((ACPI_OBJECT *) ReturnBuffer->Pointer)->Type),
    146  1.3.4.2  rmind         AcpiUtGetTypeName (ReturnType)));
    147  1.3.4.2  rmind 
    148  1.3.4.2  rmind     if (MustFree)
    149  1.3.4.2  rmind     {
    150  1.3.4.2  rmind         /* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */
    151  1.3.4.2  rmind 
    152  1.3.4.2  rmind         AcpiOsFree (ReturnBuffer->Pointer);
    153  1.3.4.2  rmind         ReturnBuffer->Pointer = NULL;
    154  1.3.4.2  rmind     }
    155  1.3.4.2  rmind 
    156  1.3.4.2  rmind     ReturnBuffer->Length = 0;
    157  1.3.4.2  rmind     return_ACPI_STATUS (AE_TYPE);
    158  1.3.4.2  rmind }
    159  1.3.4.2  rmind 
    160  1.3.4.2  rmind ACPI_EXPORT_SYMBOL (AcpiEvaluateObjectTyped)
    161  1.3.4.2  rmind 
    162  1.3.4.2  rmind 
    163  1.3.4.2  rmind /*******************************************************************************
    164  1.3.4.2  rmind  *
    165  1.3.4.2  rmind  * FUNCTION:    AcpiEvaluateObject
    166  1.3.4.2  rmind  *
    167  1.3.4.2  rmind  * PARAMETERS:  Handle              - Object handle (optional)
    168  1.3.4.2  rmind  *              Pathname            - Object pathname (optional)
    169  1.3.4.2  rmind  *              ExternalParams      - List of parameters to pass to method,
    170  1.3.4.2  rmind  *                                    terminated by NULL.  May be NULL
    171  1.3.4.2  rmind  *                                    if no parameters are being passed.
    172  1.3.4.2  rmind  *              ReturnBuffer        - Where to put method's return value (if
    173  1.3.4.2  rmind  *                                    any).  If NULL, no value is returned.
    174  1.3.4.2  rmind  *
    175  1.3.4.2  rmind  * RETURN:      Status
    176  1.3.4.2  rmind  *
    177  1.3.4.2  rmind  * DESCRIPTION: Find and evaluate the given object, passing the given
    178  1.3.4.2  rmind  *              parameters if necessary.  One of "Handle" or "Pathname" must
    179  1.3.4.2  rmind  *              be valid (non-null)
    180  1.3.4.2  rmind  *
    181  1.3.4.2  rmind  ******************************************************************************/
    182  1.3.4.2  rmind 
    183  1.3.4.2  rmind ACPI_STATUS
    184  1.3.4.2  rmind AcpiEvaluateObject (
    185  1.3.4.2  rmind     ACPI_HANDLE             Handle,
    186  1.3.4.2  rmind     ACPI_CONST_STRING       Pathname,
    187  1.3.4.2  rmind     ACPI_OBJECT_LIST        *ExternalParams,
    188  1.3.4.2  rmind     ACPI_BUFFER             *ReturnBuffer)
    189  1.3.4.2  rmind {
    190  1.3.4.2  rmind     ACPI_STATUS             Status;
    191  1.3.4.2  rmind     ACPI_EVALUATE_INFO      *Info;
    192  1.3.4.2  rmind     ACPI_SIZE               BufferSpaceNeeded;
    193  1.3.4.2  rmind     UINT32                  i;
    194  1.3.4.2  rmind 
    195  1.3.4.2  rmind 
    196  1.3.4.2  rmind     ACPI_FUNCTION_TRACE (AcpiEvaluateObject);
    197  1.3.4.2  rmind 
    198  1.3.4.2  rmind 
    199  1.3.4.2  rmind     /* Allocate and initialize the evaluation information block */
    200  1.3.4.2  rmind 
    201  1.3.4.2  rmind     Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
    202  1.3.4.2  rmind     if (!Info)
    203  1.3.4.2  rmind     {
    204  1.3.4.2  rmind         return_ACPI_STATUS (AE_NO_MEMORY);
    205  1.3.4.2  rmind     }
    206  1.3.4.2  rmind 
    207  1.3.4.2  rmind     Info->Pathname = __UNCONST(Pathname);
    208  1.3.4.2  rmind 
    209  1.3.4.2  rmind     /* Convert and validate the device handle */
    210  1.3.4.2  rmind 
    211  1.3.4.2  rmind     Info->PrefixNode = AcpiNsValidateHandle (Handle);
    212  1.3.4.2  rmind     if (!Info->PrefixNode)
    213  1.3.4.2  rmind     {
    214  1.3.4.2  rmind         Status = AE_BAD_PARAMETER;
    215  1.3.4.2  rmind         goto Cleanup;
    216  1.3.4.2  rmind     }
    217  1.3.4.2  rmind 
    218  1.3.4.2  rmind     /*
    219  1.3.4.2  rmind      * If there are parameters to be passed to a control method, the external
    220  1.3.4.2  rmind      * objects must all be converted to internal objects
    221  1.3.4.2  rmind      */
    222  1.3.4.2  rmind     if (ExternalParams && ExternalParams->Count)
    223  1.3.4.2  rmind     {
    224  1.3.4.2  rmind         /*
    225  1.3.4.2  rmind          * Allocate a new parameter block for the internal objects
    226  1.3.4.2  rmind          * Add 1 to count to allow for null terminated internal list
    227  1.3.4.2  rmind          */
    228  1.3.4.2  rmind         Info->Parameters = ACPI_ALLOCATE_ZEROED (
    229  1.3.4.2  rmind             ((ACPI_SIZE) ExternalParams->Count + 1) * sizeof (void *));
    230  1.3.4.2  rmind         if (!Info->Parameters)
    231  1.3.4.2  rmind         {
    232  1.3.4.2  rmind             Status = AE_NO_MEMORY;
    233  1.3.4.2  rmind             goto Cleanup;
    234  1.3.4.2  rmind         }
    235  1.3.4.2  rmind 
    236  1.3.4.2  rmind         /* Convert each external object in the list to an internal object */
    237  1.3.4.2  rmind 
    238  1.3.4.2  rmind         for (i = 0; i < ExternalParams->Count; i++)
    239  1.3.4.2  rmind         {
    240  1.3.4.2  rmind             Status = AcpiUtCopyEobjectToIobject (
    241  1.3.4.2  rmind                         &ExternalParams->Pointer[i], &Info->Parameters[i]);
    242  1.3.4.2  rmind             if (ACPI_FAILURE (Status))
    243  1.3.4.2  rmind             {
    244  1.3.4.2  rmind                 goto Cleanup;
    245  1.3.4.2  rmind             }
    246  1.3.4.2  rmind         }
    247  1.3.4.2  rmind         Info->Parameters[ExternalParams->Count] = NULL;
    248  1.3.4.2  rmind     }
    249  1.3.4.2  rmind 
    250  1.3.4.2  rmind     /*
    251  1.3.4.2  rmind      * Three major cases:
    252  1.3.4.2  rmind      * 1) Fully qualified pathname
    253  1.3.4.2  rmind      * 2) No handle, not fully qualified pathname (error)
    254  1.3.4.2  rmind      * 3) Valid handle
    255  1.3.4.2  rmind      */
    256  1.3.4.2  rmind     if ((Pathname) &&
    257  1.3.4.2  rmind         (AcpiNsValidRootPrefix (Pathname[0])))
    258  1.3.4.2  rmind     {
    259  1.3.4.2  rmind         /* The path is fully qualified, just evaluate by name */
    260  1.3.4.2  rmind 
    261  1.3.4.2  rmind         Info->PrefixNode = NULL;
    262  1.3.4.2  rmind         Status = AcpiNsEvaluate (Info);
    263  1.3.4.2  rmind     }
    264  1.3.4.2  rmind     else if (!Handle)
    265  1.3.4.2  rmind     {
    266  1.3.4.2  rmind         /*
    267  1.3.4.2  rmind          * A handle is optional iff a fully qualified pathname is specified.
    268  1.3.4.2  rmind          * Since we've already handled fully qualified names above, this is
    269  1.3.4.2  rmind          * an error
    270  1.3.4.2  rmind          */
    271  1.3.4.2  rmind         if (!Pathname)
    272  1.3.4.2  rmind         {
    273  1.3.4.2  rmind             ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
    274  1.3.4.2  rmind                 "Both Handle and Pathname are NULL"));
    275  1.3.4.2  rmind         }
    276  1.3.4.2  rmind         else
    277  1.3.4.2  rmind         {
    278  1.3.4.2  rmind             ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
    279  1.3.4.2  rmind                 "Null Handle with relative pathname [%s]", Pathname));
    280  1.3.4.2  rmind         }
    281  1.3.4.2  rmind 
    282  1.3.4.2  rmind         Status = AE_BAD_PARAMETER;
    283  1.3.4.2  rmind     }
    284  1.3.4.2  rmind     else
    285  1.3.4.2  rmind     {
    286  1.3.4.2  rmind         /* We have a namespace a node and a possible relative path */
    287  1.3.4.2  rmind 
    288  1.3.4.2  rmind         Status = AcpiNsEvaluate (Info);
    289  1.3.4.2  rmind     }
    290  1.3.4.2  rmind 
    291  1.3.4.2  rmind     /*
    292  1.3.4.2  rmind      * If we are expecting a return value, and all went well above,
    293  1.3.4.2  rmind      * copy the return value to an external object.
    294  1.3.4.2  rmind      */
    295  1.3.4.2  rmind     if (ReturnBuffer)
    296  1.3.4.2  rmind     {
    297  1.3.4.2  rmind         if (!Info->ReturnObject)
    298  1.3.4.2  rmind         {
    299  1.3.4.2  rmind             ReturnBuffer->Length = 0;
    300  1.3.4.2  rmind         }
    301  1.3.4.2  rmind         else
    302  1.3.4.2  rmind         {
    303  1.3.4.2  rmind             if (ACPI_GET_DESCRIPTOR_TYPE (Info->ReturnObject) ==
    304  1.3.4.2  rmind                 ACPI_DESC_TYPE_NAMED)
    305  1.3.4.2  rmind             {
    306  1.3.4.2  rmind                 /*
    307  1.3.4.2  rmind                  * If we received a NS Node as a return object, this means that
    308  1.3.4.2  rmind                  * the object we are evaluating has nothing interesting to
    309  1.3.4.2  rmind                  * return (such as a mutex, etc.)  We return an error because
    310  1.3.4.2  rmind                  * these types are essentially unsupported by this interface.
    311  1.3.4.2  rmind                  * We don't check up front because this makes it easier to add
    312  1.3.4.2  rmind                  * support for various types at a later date if necessary.
    313  1.3.4.2  rmind                  */
    314  1.3.4.2  rmind                 Status = AE_TYPE;
    315  1.3.4.2  rmind                 Info->ReturnObject = NULL;   /* No need to delete a NS Node */
    316  1.3.4.2  rmind                 ReturnBuffer->Length = 0;
    317  1.3.4.2  rmind             }
    318  1.3.4.2  rmind 
    319  1.3.4.2  rmind             if (ACPI_SUCCESS (Status))
    320  1.3.4.2  rmind             {
    321  1.3.4.2  rmind                 /* Dereference Index and RefOf references */
    322  1.3.4.2  rmind 
    323  1.3.4.2  rmind                 AcpiNsResolveReferences (Info);
    324  1.3.4.2  rmind 
    325  1.3.4.2  rmind                 /* Get the size of the returned object */
    326  1.3.4.2  rmind 
    327  1.3.4.2  rmind                 Status = AcpiUtGetObjectSize (Info->ReturnObject,
    328  1.3.4.2  rmind                             &BufferSpaceNeeded);
    329  1.3.4.2  rmind                 if (ACPI_SUCCESS (Status))
    330  1.3.4.2  rmind                 {
    331  1.3.4.2  rmind                     /* Validate/Allocate/Clear caller buffer */
    332  1.3.4.2  rmind 
    333  1.3.4.2  rmind                     Status = AcpiUtInitializeBuffer (ReturnBuffer,
    334  1.3.4.2  rmind                                 BufferSpaceNeeded);
    335  1.3.4.2  rmind                     if (ACPI_FAILURE (Status))
    336  1.3.4.2  rmind                     {
    337  1.3.4.2  rmind                         /*
    338  1.3.4.2  rmind                          * Caller's buffer is too small or a new one can't
    339  1.3.4.2  rmind                          * be allocated
    340  1.3.4.2  rmind                          */
    341  1.3.4.2  rmind                         ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
    342  1.3.4.2  rmind                             "Needed buffer size %X, %s\n",
    343  1.3.4.2  rmind                             (UINT32) BufferSpaceNeeded,
    344  1.3.4.2  rmind                             AcpiFormatException (Status)));
    345  1.3.4.2  rmind                     }
    346  1.3.4.2  rmind                     else
    347  1.3.4.2  rmind                     {
    348  1.3.4.2  rmind                         /* We have enough space for the object, build it */
    349  1.3.4.2  rmind 
    350  1.3.4.2  rmind                         Status = AcpiUtCopyIobjectToEobject (Info->ReturnObject,
    351  1.3.4.2  rmind                                     ReturnBuffer);
    352  1.3.4.2  rmind                     }
    353  1.3.4.2  rmind                 }
    354  1.3.4.2  rmind             }
    355  1.3.4.2  rmind         }
    356  1.3.4.2  rmind     }
    357  1.3.4.2  rmind 
    358  1.3.4.2  rmind     if (Info->ReturnObject)
    359  1.3.4.2  rmind     {
    360  1.3.4.2  rmind         /*
    361  1.3.4.2  rmind          * Delete the internal return object. NOTE: Interpreter must be
    362  1.3.4.2  rmind          * locked to avoid race condition.
    363  1.3.4.2  rmind          */
    364  1.3.4.2  rmind         AcpiExEnterInterpreter ();
    365  1.3.4.2  rmind 
    366  1.3.4.2  rmind         /* Remove one reference on the return object (should delete it) */
    367  1.3.4.2  rmind 
    368  1.3.4.2  rmind         AcpiUtRemoveReference (Info->ReturnObject);
    369  1.3.4.2  rmind         AcpiExExitInterpreter ();
    370  1.3.4.2  rmind     }
    371  1.3.4.2  rmind 
    372  1.3.4.2  rmind 
    373  1.3.4.2  rmind Cleanup:
    374  1.3.4.2  rmind 
    375  1.3.4.2  rmind     /* Free the input parameter list (if we created one) */
    376  1.3.4.2  rmind 
    377  1.3.4.2  rmind     if (Info->Parameters)
    378  1.3.4.2  rmind     {
    379  1.3.4.2  rmind         /* Free the allocated parameter block */
    380  1.3.4.2  rmind 
    381  1.3.4.2  rmind         AcpiUtDeleteInternalObjectList (Info->Parameters);
    382  1.3.4.2  rmind     }
    383  1.3.4.2  rmind 
    384  1.3.4.2  rmind     ACPI_FREE (Info);
    385  1.3.4.2  rmind     return_ACPI_STATUS (Status);
    386  1.3.4.2  rmind }
    387  1.3.4.2  rmind 
    388  1.3.4.2  rmind ACPI_EXPORT_SYMBOL (AcpiEvaluateObject)
    389  1.3.4.2  rmind 
    390  1.3.4.2  rmind 
    391  1.3.4.2  rmind /*******************************************************************************
    392  1.3.4.2  rmind  *
    393  1.3.4.2  rmind  * FUNCTION:    AcpiNsResolveReferences
    394  1.3.4.2  rmind  *
    395  1.3.4.2  rmind  * PARAMETERS:  Info                    - Evaluation info block
    396  1.3.4.2  rmind  *
    397  1.3.4.2  rmind  * RETURN:      Info->ReturnObject is replaced with the dereferenced object
    398  1.3.4.2  rmind  *
    399  1.3.4.2  rmind  * DESCRIPTION: Dereference certain reference objects. Called before an
    400  1.3.4.2  rmind  *              internal return object is converted to an external ACPI_OBJECT.
    401  1.3.4.2  rmind  *
    402  1.3.4.2  rmind  * Performs an automatic dereference of Index and RefOf reference objects.
    403  1.3.4.2  rmind  * These reference objects are not supported by the ACPI_OBJECT, so this is a
    404  1.3.4.2  rmind  * last resort effort to return something useful. Also, provides compatibility
    405  1.3.4.2  rmind  * with other ACPI implementations.
    406  1.3.4.2  rmind  *
    407  1.3.4.2  rmind  * NOTE: does not handle references within returned package objects or nested
    408  1.3.4.2  rmind  * references, but this support could be added later if found to be necessary.
    409  1.3.4.2  rmind  *
    410  1.3.4.2  rmind  ******************************************************************************/
    411  1.3.4.2  rmind 
    412  1.3.4.2  rmind static void
    413  1.3.4.2  rmind AcpiNsResolveReferences (
    414  1.3.4.2  rmind     ACPI_EVALUATE_INFO      *Info)
    415  1.3.4.2  rmind {
    416  1.3.4.2  rmind     ACPI_OPERAND_OBJECT     *ObjDesc = NULL;
    417  1.3.4.2  rmind     ACPI_NAMESPACE_NODE     *Node;
    418  1.3.4.2  rmind 
    419  1.3.4.2  rmind 
    420  1.3.4.2  rmind     /* We are interested in reference objects only */
    421  1.3.4.2  rmind 
    422  1.3.4.2  rmind     if ((Info->ReturnObject)->Common.Type != ACPI_TYPE_LOCAL_REFERENCE)
    423  1.3.4.2  rmind     {
    424  1.3.4.2  rmind         return;
    425  1.3.4.2  rmind     }
    426  1.3.4.2  rmind 
    427  1.3.4.2  rmind     /*
    428  1.3.4.2  rmind      * Two types of references are supported - those created by Index and
    429  1.3.4.2  rmind      * RefOf operators. A name reference (AML_NAMEPATH_OP) can be converted
    430  1.3.4.2  rmind      * to an ACPI_OBJECT, so it is not dereferenced here. A DdbHandle
    431  1.3.4.2  rmind      * (AML_LOAD_OP) cannot be dereferenced, nor can it be converted to
    432  1.3.4.2  rmind      * an ACPI_OBJECT.
    433  1.3.4.2  rmind      */
    434  1.3.4.2  rmind     switch (Info->ReturnObject->Reference.Class)
    435  1.3.4.2  rmind     {
    436  1.3.4.2  rmind     case ACPI_REFCLASS_INDEX:
    437  1.3.4.2  rmind 
    438  1.3.4.2  rmind         ObjDesc = *(Info->ReturnObject->Reference.Where);
    439  1.3.4.2  rmind         break;
    440  1.3.4.2  rmind 
    441  1.3.4.2  rmind     case ACPI_REFCLASS_REFOF:
    442  1.3.4.2  rmind 
    443  1.3.4.2  rmind         Node = Info->ReturnObject->Reference.Object;
    444  1.3.4.2  rmind         if (Node)
    445  1.3.4.2  rmind         {
    446  1.3.4.2  rmind             ObjDesc = Node->Object;
    447  1.3.4.2  rmind         }
    448  1.3.4.2  rmind         break;
    449  1.3.4.2  rmind 
    450  1.3.4.2  rmind     default:
    451  1.3.4.2  rmind         return;
    452  1.3.4.2  rmind     }
    453  1.3.4.2  rmind 
    454  1.3.4.2  rmind     /* Replace the existing reference object */
    455  1.3.4.2  rmind 
    456  1.3.4.2  rmind     if (ObjDesc)
    457  1.3.4.2  rmind     {
    458  1.3.4.2  rmind         AcpiUtAddReference (ObjDesc);
    459  1.3.4.2  rmind         AcpiUtRemoveReference (Info->ReturnObject);
    460  1.3.4.2  rmind         Info->ReturnObject = ObjDesc;
    461  1.3.4.2  rmind     }
    462  1.3.4.2  rmind 
    463  1.3.4.2  rmind     return;
    464  1.3.4.2  rmind }
    465  1.3.4.2  rmind 
    466  1.3.4.2  rmind 
    467  1.3.4.2  rmind /*******************************************************************************
    468  1.3.4.2  rmind  *
    469  1.3.4.2  rmind  * FUNCTION:    AcpiWalkNamespace
    470  1.3.4.2  rmind  *
    471  1.3.4.2  rmind  * PARAMETERS:  Type                - ACPI_OBJECT_TYPE to search for
    472  1.3.4.2  rmind  *              StartObject         - Handle in namespace where search begins
    473  1.3.4.2  rmind  *              MaxDepth            - Depth to which search is to reach
    474  1.3.4.2  rmind  *              PreOrderVisit       - Called during tree pre-order visit
    475  1.3.4.2  rmind  *                                    when an object of "Type" is found
    476  1.3.4.2  rmind  *              PostOrderVisit      - Called during tree post-order visit
    477  1.3.4.2  rmind  *                                    when an object of "Type" is found
    478  1.3.4.2  rmind  *              Context             - Passed to user function(s) above
    479  1.3.4.2  rmind  *              ReturnValue         - Location where return value of
    480  1.3.4.2  rmind  *                                    UserFunction is put if terminated early
    481  1.3.4.2  rmind  *
    482  1.3.4.2  rmind  * RETURNS      Return value from the UserFunction if terminated early.
    483  1.3.4.2  rmind  *              Otherwise, returns NULL.
    484  1.3.4.2  rmind  *
    485  1.3.4.2  rmind  * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
    486  1.3.4.2  rmind  *              starting (and ending) at the object specified by StartHandle.
    487  1.3.4.2  rmind  *              The callback function is called whenever an object that matches
    488  1.3.4.2  rmind  *              the type parameter is found. If the callback function returns
    489  1.3.4.2  rmind  *              a non-zero value, the search is terminated immediately and this
    490  1.3.4.2  rmind  *              value is returned to the caller.
    491  1.3.4.2  rmind  *
    492  1.3.4.2  rmind  *              The point of this procedure is to provide a generic namespace
    493  1.3.4.2  rmind  *              walk routine that can be called from multiple places to
    494  1.3.4.2  rmind  *              provide multiple services; the callback function(s) can be
    495  1.3.4.2  rmind  *              tailored to each task, whether it is a print function,
    496  1.3.4.2  rmind  *              a compare function, etc.
    497  1.3.4.2  rmind  *
    498  1.3.4.2  rmind  ******************************************************************************/
    499  1.3.4.2  rmind 
    500  1.3.4.2  rmind ACPI_STATUS
    501  1.3.4.2  rmind AcpiWalkNamespace (
    502  1.3.4.2  rmind     ACPI_OBJECT_TYPE        Type,
    503  1.3.4.2  rmind     ACPI_HANDLE             StartObject,
    504  1.3.4.2  rmind     UINT32                  MaxDepth,
    505  1.3.4.2  rmind     ACPI_WALK_CALLBACK      PreOrderVisit,
    506  1.3.4.2  rmind     ACPI_WALK_CALLBACK      PostOrderVisit,
    507  1.3.4.2  rmind     void                    *Context,
    508  1.3.4.2  rmind     void                    **ReturnValue)
    509  1.3.4.2  rmind {
    510  1.3.4.2  rmind     ACPI_STATUS             Status;
    511  1.3.4.2  rmind 
    512  1.3.4.2  rmind 
    513  1.3.4.2  rmind     ACPI_FUNCTION_TRACE (AcpiWalkNamespace);
    514  1.3.4.2  rmind 
    515  1.3.4.2  rmind 
    516  1.3.4.2  rmind     /* Parameter validation */
    517  1.3.4.2  rmind 
    518  1.3.4.2  rmind     if ((Type > ACPI_TYPE_LOCAL_MAX) ||
    519  1.3.4.2  rmind         (!MaxDepth)                  ||
    520  1.3.4.2  rmind         (!PreOrderVisit && !PostOrderVisit))
    521  1.3.4.2  rmind     {
    522  1.3.4.2  rmind         return_ACPI_STATUS (AE_BAD_PARAMETER);
    523  1.3.4.2  rmind     }
    524  1.3.4.2  rmind 
    525  1.3.4.2  rmind     /*
    526  1.3.4.2  rmind      * Need to acquire the namespace reader lock to prevent interference
    527  1.3.4.2  rmind      * with any concurrent table unloads (which causes the deletion of
    528  1.3.4.2  rmind      * namespace objects). We cannot allow the deletion of a namespace node
    529  1.3.4.2  rmind      * while the user function is using it. The exception to this are the
    530  1.3.4.2  rmind      * nodes created and deleted during control method execution -- these
    531  1.3.4.2  rmind      * nodes are marked as temporary nodes and are ignored by the namespace
    532  1.3.4.2  rmind      * walk. Thus, control methods can be executed while holding the
    533  1.3.4.2  rmind      * namespace deletion lock (and the user function can execute control
    534  1.3.4.2  rmind      * methods.)
    535  1.3.4.2  rmind      */
    536  1.3.4.2  rmind     Status = AcpiUtAcquireReadLock (&AcpiGbl_NamespaceRwLock);
    537  1.3.4.2  rmind     if (ACPI_FAILURE (Status))
    538  1.3.4.2  rmind     {
    539  1.3.4.2  rmind         return (Status);
    540  1.3.4.2  rmind     }
    541  1.3.4.2  rmind 
    542  1.3.4.2  rmind     /*
    543  1.3.4.2  rmind      * Lock the namespace around the walk. The namespace will be
    544  1.3.4.2  rmind      * unlocked/locked around each call to the user function - since the user
    545  1.3.4.2  rmind      * function must be allowed to make ACPICA calls itself (for example, it
    546  1.3.4.2  rmind      * will typically execute control methods during device enumeration.)
    547  1.3.4.2  rmind      */
    548  1.3.4.2  rmind     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
    549  1.3.4.2  rmind     if (ACPI_FAILURE (Status))
    550  1.3.4.2  rmind     {
    551  1.3.4.2  rmind         goto UnlockAndExit;
    552  1.3.4.2  rmind     }
    553  1.3.4.2  rmind 
    554  1.3.4.2  rmind     Status = AcpiNsWalkNamespace (Type, StartObject, MaxDepth,
    555  1.3.4.2  rmind                 ACPI_NS_WALK_UNLOCK, PreOrderVisit,
    556  1.3.4.2  rmind                 PostOrderVisit, Context, ReturnValue);
    557  1.3.4.2  rmind 
    558  1.3.4.2  rmind     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    559  1.3.4.2  rmind 
    560  1.3.4.2  rmind UnlockAndExit:
    561  1.3.4.2  rmind     (void) AcpiUtReleaseReadLock (&AcpiGbl_NamespaceRwLock);
    562  1.3.4.2  rmind     return_ACPI_STATUS (Status);
    563  1.3.4.2  rmind }
    564  1.3.4.2  rmind 
    565  1.3.4.2  rmind ACPI_EXPORT_SYMBOL (AcpiWalkNamespace)
    566  1.3.4.2  rmind 
    567  1.3.4.2  rmind 
    568  1.3.4.2  rmind /*******************************************************************************
    569  1.3.4.2  rmind  *
    570  1.3.4.2  rmind  * FUNCTION:    AcpiNsGetDeviceCallback
    571  1.3.4.2  rmind  *
    572  1.3.4.2  rmind  * PARAMETERS:  Callback from AcpiGetDevice
    573  1.3.4.2  rmind  *
    574  1.3.4.2  rmind  * RETURN:      Status
    575  1.3.4.2  rmind  *
    576  1.3.4.2  rmind  * DESCRIPTION: Takes callbacks from WalkNamespace and filters out all non-
    577  1.3.4.2  rmind  *              present devices, or if they specified a HID, it filters based
    578  1.3.4.2  rmind  *              on that.
    579  1.3.4.2  rmind  *
    580  1.3.4.2  rmind  ******************************************************************************/
    581  1.3.4.2  rmind 
    582  1.3.4.2  rmind static ACPI_STATUS
    583  1.3.4.2  rmind AcpiNsGetDeviceCallback (
    584  1.3.4.2  rmind     ACPI_HANDLE             ObjHandle,
    585  1.3.4.2  rmind     UINT32                  NestingLevel,
    586  1.3.4.2  rmind     void                    *Context,
    587  1.3.4.2  rmind     void                    **ReturnValue)
    588  1.3.4.2  rmind {
    589  1.3.4.2  rmind     ACPI_GET_DEVICES_INFO   *Info = Context;
    590  1.3.4.2  rmind     ACPI_STATUS             Status;
    591  1.3.4.2  rmind     ACPI_NAMESPACE_NODE     *Node;
    592  1.3.4.2  rmind     UINT32                  Flags;
    593  1.3.4.2  rmind     ACPI_DEVICE_ID          *Hid;
    594  1.3.4.2  rmind     ACPI_DEVICE_ID_LIST     *Cid;
    595  1.3.4.2  rmind     UINT32                  i;
    596  1.3.4.2  rmind     BOOLEAN                 Found;
    597  1.3.4.2  rmind     int                     NoMatch;
    598  1.3.4.2  rmind 
    599  1.3.4.2  rmind 
    600  1.3.4.2  rmind     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
    601  1.3.4.2  rmind     if (ACPI_FAILURE (Status))
    602  1.3.4.2  rmind     {
    603  1.3.4.2  rmind         return (Status);
    604  1.3.4.2  rmind     }
    605  1.3.4.2  rmind 
    606  1.3.4.2  rmind     Node = AcpiNsValidateHandle (ObjHandle);
    607  1.3.4.2  rmind     Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    608  1.3.4.2  rmind     if (ACPI_FAILURE (Status))
    609  1.3.4.2  rmind     {
    610  1.3.4.2  rmind         return (Status);
    611  1.3.4.2  rmind     }
    612  1.3.4.2  rmind 
    613  1.3.4.2  rmind     if (!Node)
    614  1.3.4.2  rmind     {
    615  1.3.4.2  rmind         return (AE_BAD_PARAMETER);
    616  1.3.4.2  rmind     }
    617  1.3.4.2  rmind 
    618  1.3.4.2  rmind     /*
    619  1.3.4.2  rmind      * First, filter based on the device HID and CID.
    620  1.3.4.2  rmind      *
    621  1.3.4.2  rmind      * 01/2010: For this case where a specific HID is requested, we don't
    622  1.3.4.2  rmind      * want to run _STA until we have an actual HID match. Thus, we will
    623  1.3.4.2  rmind      * not unnecessarily execute _STA on devices for which the caller
    624  1.3.4.2  rmind      * doesn't care about. Previously, _STA was executed unconditionally
    625  1.3.4.2  rmind      * on all devices found here.
    626  1.3.4.2  rmind      *
    627  1.3.4.2  rmind      * A side-effect of this change is that now we will continue to search
    628  1.3.4.2  rmind      * for a matching HID even under device trees where the parent device
    629  1.3.4.2  rmind      * would have returned a _STA that indicates it is not present or
    630  1.3.4.2  rmind      * not functioning (thus aborting the search on that branch).
    631  1.3.4.2  rmind      */
    632  1.3.4.2  rmind     if (Info->Hid != NULL)
    633  1.3.4.2  rmind     {
    634  1.3.4.2  rmind         Status = AcpiUtExecute_HID (Node, &Hid);
    635  1.3.4.2  rmind         if (Status == AE_NOT_FOUND)
    636  1.3.4.2  rmind         {
    637  1.3.4.2  rmind             return (AE_OK);
    638  1.3.4.2  rmind         }
    639  1.3.4.2  rmind         else if (ACPI_FAILURE (Status))
    640  1.3.4.2  rmind         {
    641  1.3.4.2  rmind             return (AE_CTRL_DEPTH);
    642  1.3.4.2  rmind         }
    643  1.3.4.2  rmind 
    644  1.3.4.2  rmind         NoMatch = ACPI_STRCMP (Hid->String, Info->Hid);
    645  1.3.4.2  rmind         ACPI_FREE (Hid);
    646  1.3.4.2  rmind 
    647  1.3.4.2  rmind         if (NoMatch)
    648  1.3.4.2  rmind         {
    649  1.3.4.2  rmind             /*
    650  1.3.4.2  rmind              * HID does not match, attempt match within the
    651  1.3.4.2  rmind              * list of Compatible IDs (CIDs)
    652  1.3.4.2  rmind              */
    653  1.3.4.2  rmind             Status = AcpiUtExecute_CID (Node, &Cid);
    654  1.3.4.2  rmind             if (Status == AE_NOT_FOUND)
    655  1.3.4.2  rmind             {
    656  1.3.4.2  rmind                 return (AE_OK);
    657  1.3.4.2  rmind             }
    658  1.3.4.2  rmind             else if (ACPI_FAILURE (Status))
    659  1.3.4.2  rmind             {
    660  1.3.4.2  rmind                 return (AE_CTRL_DEPTH);
    661  1.3.4.2  rmind             }
    662  1.3.4.2  rmind 
    663  1.3.4.2  rmind             /* Walk the CID list */
    664  1.3.4.2  rmind 
    665  1.3.4.2  rmind             Found = FALSE;
    666  1.3.4.2  rmind             for (i = 0; i < Cid->Count; i++)
    667  1.3.4.2  rmind             {
    668  1.3.4.2  rmind                 if (ACPI_STRCMP (Cid->Ids[i].String, Info->Hid) == 0)
    669  1.3.4.2  rmind                 {
    670  1.3.4.2  rmind                     /* Found a matching CID */
    671  1.3.4.2  rmind 
    672  1.3.4.2  rmind                     Found = TRUE;
    673  1.3.4.2  rmind                     break;
    674  1.3.4.2  rmind                 }
    675  1.3.4.2  rmind             }
    676  1.3.4.2  rmind 
    677  1.3.4.2  rmind             ACPI_FREE (Cid);
    678  1.3.4.2  rmind             if (!Found)
    679  1.3.4.2  rmind             {
    680  1.3.4.2  rmind                 return (AE_OK);
    681  1.3.4.2  rmind             }
    682  1.3.4.2  rmind         }
    683  1.3.4.2  rmind     }
    684  1.3.4.2  rmind 
    685  1.3.4.2  rmind     /* Run _STA to determine if device is present */
    686  1.3.4.2  rmind 
    687  1.3.4.2  rmind     Status = AcpiUtExecute_STA (Node, &Flags);
    688  1.3.4.2  rmind     if (ACPI_FAILURE (Status))
    689  1.3.4.2  rmind     {
    690  1.3.4.2  rmind         return (AE_CTRL_DEPTH);
    691  1.3.4.2  rmind     }
    692  1.3.4.2  rmind 
    693  1.3.4.2  rmind     if (!(Flags & ACPI_STA_DEVICE_PRESENT) &&
    694  1.3.4.2  rmind         !(Flags & ACPI_STA_DEVICE_FUNCTIONING))
    695  1.3.4.2  rmind     {
    696  1.3.4.2  rmind         /*
    697  1.3.4.2  rmind          * Don't examine the children of the device only when the
    698  1.3.4.2  rmind          * device is neither present nor functional. See ACPI spec,
    699  1.3.4.2  rmind          * description of _STA for more information.
    700  1.3.4.2  rmind          */
    701  1.3.4.2  rmind         return (AE_CTRL_DEPTH);
    702  1.3.4.2  rmind     }
    703  1.3.4.2  rmind 
    704  1.3.4.2  rmind     /* We have a valid device, invoke the user function */
    705  1.3.4.2  rmind 
    706  1.3.4.2  rmind     Status = Info->UserFunction (ObjHandle, NestingLevel, Info->Context,
    707  1.3.4.2  rmind                 ReturnValue);
    708  1.3.4.2  rmind     return (Status);
    709  1.3.4.2  rmind }
    710  1.3.4.2  rmind 
    711  1.3.4.2  rmind 
    712  1.3.4.2  rmind /*******************************************************************************
    713  1.3.4.2  rmind  *
    714  1.3.4.2  rmind  * FUNCTION:    AcpiGetDevices
    715  1.3.4.2  rmind  *
    716  1.3.4.2  rmind  * PARAMETERS:  HID                 - HID to search for. Can be NULL.
    717  1.3.4.2  rmind  *              UserFunction        - Called when a matching object is found
    718  1.3.4.2  rmind  *              Context             - Passed to user function
    719  1.3.4.2  rmind  *              ReturnValue         - Location where return value of
    720  1.3.4.2  rmind  *                                    UserFunction is put if terminated early
    721  1.3.4.2  rmind  *
    722  1.3.4.2  rmind  * RETURNS      Return value from the UserFunction if terminated early.
    723  1.3.4.2  rmind  *              Otherwise, returns NULL.
    724  1.3.4.2  rmind  *
    725  1.3.4.2  rmind  * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
    726  1.3.4.2  rmind  *              starting (and ending) at the object specified by StartHandle.
    727  1.3.4.2  rmind  *              The UserFunction is called whenever an object of type
    728  1.3.4.2  rmind  *              Device is found.  If the user function returns
    729  1.3.4.2  rmind  *              a non-zero value, the search is terminated immediately and this
    730  1.3.4.2  rmind  *              value is returned to the caller.
    731  1.3.4.2  rmind  *
    732  1.3.4.2  rmind  *              This is a wrapper for WalkNamespace, but the callback performs
    733  1.3.4.2  rmind  *              additional filtering. Please see AcpiNsGetDeviceCallback.
    734  1.3.4.2  rmind  *
    735  1.3.4.2  rmind  ******************************************************************************/
    736  1.3.4.2  rmind 
    737  1.3.4.2  rmind ACPI_STATUS
    738  1.3.4.2  rmind AcpiGetDevices (
    739  1.3.4.2  rmind     char                    *HID,
    740  1.3.4.2  rmind     ACPI_WALK_CALLBACK      UserFunction,
    741  1.3.4.2  rmind     void                    *Context,
    742  1.3.4.2  rmind     void                    **ReturnValue)
    743  1.3.4.2  rmind {
    744  1.3.4.2  rmind     ACPI_STATUS             Status;
    745  1.3.4.2  rmind     ACPI_GET_DEVICES_INFO   Info;
    746  1.3.4.2  rmind 
    747  1.3.4.2  rmind 
    748  1.3.4.2  rmind     ACPI_FUNCTION_TRACE (AcpiGetDevices);
    749  1.3.4.2  rmind 
    750  1.3.4.2  rmind 
    751  1.3.4.2  rmind     /* Parameter validation */
    752  1.3.4.2  rmind 
    753  1.3.4.2  rmind     if (!UserFunction)
    754  1.3.4.2  rmind     {
    755  1.3.4.2  rmind         return_ACPI_STATUS (AE_BAD_PARAMETER);
    756  1.3.4.2  rmind     }
    757  1.3.4.2  rmind 
    758  1.3.4.2  rmind     /*
    759  1.3.4.2  rmind      * We're going to call their callback from OUR callback, so we need
    760  1.3.4.2  rmind      * to know what it is, and their context parameter.
    761  1.3.4.2  rmind      */
    762  1.3.4.2  rmind     Info.Hid          = HID;
    763  1.3.4.2  rmind     Info.Context      = Context;
    764  1.3.4.2  rmind     Info.UserFunction = UserFunction;
    765  1.3.4.2  rmind 
    766  1.3.4.2  rmind     /*
    767  1.3.4.2  rmind      * Lock the namespace around the walk.
    768  1.3.4.2  rmind      * The namespace will be unlocked/locked around each call
    769  1.3.4.2  rmind      * to the user function - since this function
    770  1.3.4.2  rmind      * must be allowed to make Acpi calls itself.
    771  1.3.4.2  rmind      */
    772  1.3.4.2  rmind     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
    773  1.3.4.2  rmind     if (ACPI_FAILURE (Status))
    774  1.3.4.2  rmind     {
    775  1.3.4.2  rmind         return_ACPI_STATUS (Status);
    776  1.3.4.2  rmind     }
    777  1.3.4.2  rmind 
    778  1.3.4.2  rmind     Status = AcpiNsWalkNamespace (ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
    779  1.3.4.2  rmind                 ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK,
    780  1.3.4.2  rmind                 AcpiNsGetDeviceCallback, NULL, &Info, ReturnValue);
    781  1.3.4.2  rmind 
    782  1.3.4.2  rmind     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    783  1.3.4.2  rmind     return_ACPI_STATUS (Status);
    784  1.3.4.2  rmind }
    785  1.3.4.2  rmind 
    786  1.3.4.2  rmind ACPI_EXPORT_SYMBOL (AcpiGetDevices)
    787  1.3.4.2  rmind 
    788  1.3.4.2  rmind 
    789  1.3.4.2  rmind /*******************************************************************************
    790  1.3.4.2  rmind  *
    791  1.3.4.2  rmind  * FUNCTION:    AcpiAttachData
    792  1.3.4.2  rmind  *
    793  1.3.4.2  rmind  * PARAMETERS:  ObjHandle           - Namespace node
    794  1.3.4.2  rmind  *              Handler             - Handler for this attachment
    795  1.3.4.2  rmind  *              Data                - Pointer to data to be attached
    796  1.3.4.2  rmind  *
    797  1.3.4.2  rmind  * RETURN:      Status
    798  1.3.4.2  rmind  *
    799  1.3.4.2  rmind  * DESCRIPTION: Attach arbitrary data and handler to a namespace node.
    800  1.3.4.2  rmind  *
    801  1.3.4.2  rmind  ******************************************************************************/
    802  1.3.4.2  rmind 
    803  1.3.4.2  rmind ACPI_STATUS
    804  1.3.4.2  rmind AcpiAttachData (
    805  1.3.4.2  rmind     ACPI_HANDLE             ObjHandle,
    806  1.3.4.2  rmind     ACPI_OBJECT_HANDLER     Handler,
    807  1.3.4.2  rmind     void                    *Data)
    808  1.3.4.2  rmind {
    809  1.3.4.2  rmind     ACPI_NAMESPACE_NODE     *Node;
    810  1.3.4.2  rmind     ACPI_STATUS             Status;
    811  1.3.4.2  rmind 
    812  1.3.4.2  rmind 
    813  1.3.4.2  rmind     /* Parameter validation */
    814  1.3.4.2  rmind 
    815  1.3.4.2  rmind     if (!ObjHandle  ||
    816  1.3.4.2  rmind         !Handler    ||
    817  1.3.4.2  rmind         !Data)
    818  1.3.4.2  rmind     {
    819  1.3.4.2  rmind         return (AE_BAD_PARAMETER);
    820  1.3.4.2  rmind     }
    821  1.3.4.2  rmind 
    822  1.3.4.2  rmind     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
    823  1.3.4.2  rmind     if (ACPI_FAILURE (Status))
    824  1.3.4.2  rmind     {
    825  1.3.4.2  rmind         return (Status);
    826  1.3.4.2  rmind     }
    827  1.3.4.2  rmind 
    828  1.3.4.2  rmind     /* Convert and validate the handle */
    829  1.3.4.2  rmind 
    830  1.3.4.2  rmind     Node = AcpiNsValidateHandle (ObjHandle);
    831  1.3.4.2  rmind     if (!Node)
    832  1.3.4.2  rmind     {
    833  1.3.4.2  rmind         Status = AE_BAD_PARAMETER;
    834  1.3.4.2  rmind         goto UnlockAndExit;
    835  1.3.4.2  rmind     }
    836  1.3.4.2  rmind 
    837  1.3.4.2  rmind     Status = AcpiNsAttachData (Node, Handler, Data);
    838  1.3.4.2  rmind 
    839  1.3.4.2  rmind UnlockAndExit:
    840  1.3.4.2  rmind     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    841  1.3.4.2  rmind     return (Status);
    842  1.3.4.2  rmind }
    843  1.3.4.2  rmind 
    844  1.3.4.2  rmind ACPI_EXPORT_SYMBOL (AcpiAttachData)
    845  1.3.4.2  rmind 
    846  1.3.4.2  rmind 
    847  1.3.4.2  rmind /*******************************************************************************
    848  1.3.4.2  rmind  *
    849  1.3.4.2  rmind  * FUNCTION:    AcpiDetachData
    850  1.3.4.2  rmind  *
    851  1.3.4.2  rmind  * PARAMETERS:  ObjHandle           - Namespace node handle
    852  1.3.4.2  rmind  *              Handler             - Handler used in call to AcpiAttachData
    853  1.3.4.2  rmind  *
    854  1.3.4.2  rmind  * RETURN:      Status
    855  1.3.4.2  rmind  *
    856  1.3.4.2  rmind  * DESCRIPTION: Remove data that was previously attached to a node.
    857  1.3.4.2  rmind  *
    858  1.3.4.2  rmind  ******************************************************************************/
    859  1.3.4.2  rmind 
    860  1.3.4.2  rmind ACPI_STATUS
    861  1.3.4.2  rmind AcpiDetachData (
    862  1.3.4.2  rmind     ACPI_HANDLE             ObjHandle,
    863  1.3.4.2  rmind     ACPI_OBJECT_HANDLER     Handler)
    864  1.3.4.2  rmind {
    865  1.3.4.2  rmind     ACPI_NAMESPACE_NODE     *Node;
    866  1.3.4.2  rmind     ACPI_STATUS             Status;
    867  1.3.4.2  rmind 
    868  1.3.4.2  rmind 
    869  1.3.4.2  rmind     /* Parameter validation */
    870  1.3.4.2  rmind 
    871  1.3.4.2  rmind     if (!ObjHandle  ||
    872  1.3.4.2  rmind         !Handler)
    873  1.3.4.2  rmind     {
    874  1.3.4.2  rmind         return (AE_BAD_PARAMETER);
    875  1.3.4.2  rmind     }
    876  1.3.4.2  rmind 
    877  1.3.4.2  rmind     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
    878  1.3.4.2  rmind     if (ACPI_FAILURE (Status))
    879  1.3.4.2  rmind     {
    880  1.3.4.2  rmind         return (Status);
    881  1.3.4.2  rmind     }
    882  1.3.4.2  rmind 
    883  1.3.4.2  rmind     /* Convert and validate the handle */
    884  1.3.4.2  rmind 
    885  1.3.4.2  rmind     Node = AcpiNsValidateHandle (ObjHandle);
    886  1.3.4.2  rmind     if (!Node)
    887  1.3.4.2  rmind     {
    888  1.3.4.2  rmind         Status = AE_BAD_PARAMETER;
    889  1.3.4.2  rmind         goto UnlockAndExit;
    890  1.3.4.2  rmind     }
    891  1.3.4.2  rmind 
    892  1.3.4.2  rmind     Status = AcpiNsDetachData (Node, Handler);
    893  1.3.4.2  rmind 
    894  1.3.4.2  rmind UnlockAndExit:
    895  1.3.4.2  rmind     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    896  1.3.4.2  rmind     return (Status);
    897  1.3.4.2  rmind }
    898  1.3.4.2  rmind 
    899  1.3.4.2  rmind ACPI_EXPORT_SYMBOL (AcpiDetachData)
    900  1.3.4.2  rmind 
    901  1.3.4.2  rmind 
    902  1.3.4.2  rmind /*******************************************************************************
    903  1.3.4.2  rmind  *
    904  1.3.4.2  rmind  * FUNCTION:    AcpiGetData
    905  1.3.4.2  rmind  *
    906  1.3.4.2  rmind  * PARAMETERS:  ObjHandle           - Namespace node
    907  1.3.4.2  rmind  *              Handler             - Handler used in call to AttachData
    908  1.3.4.2  rmind  *              Data                - Where the data is returned
    909  1.3.4.2  rmind  *
    910  1.3.4.2  rmind  * RETURN:      Status
    911  1.3.4.2  rmind  *
    912  1.3.4.2  rmind  * DESCRIPTION: Retrieve data that was previously attached to a namespace node.
    913  1.3.4.2  rmind  *
    914  1.3.4.2  rmind  ******************************************************************************/
    915  1.3.4.2  rmind 
    916  1.3.4.2  rmind ACPI_STATUS
    917  1.3.4.2  rmind AcpiGetData (
    918  1.3.4.2  rmind     ACPI_HANDLE             ObjHandle,
    919  1.3.4.2  rmind     ACPI_OBJECT_HANDLER     Handler,
    920  1.3.4.2  rmind     void                    **Data)
    921  1.3.4.2  rmind {
    922  1.3.4.2  rmind     ACPI_NAMESPACE_NODE     *Node;
    923  1.3.4.2  rmind     ACPI_STATUS             Status;
    924  1.3.4.2  rmind 
    925  1.3.4.2  rmind 
    926  1.3.4.2  rmind     /* Parameter validation */
    927  1.3.4.2  rmind 
    928  1.3.4.2  rmind     if (!ObjHandle  ||
    929  1.3.4.2  rmind         !Handler    ||
    930  1.3.4.2  rmind         !Data)
    931  1.3.4.2  rmind     {
    932  1.3.4.2  rmind         return (AE_BAD_PARAMETER);
    933  1.3.4.2  rmind     }
    934  1.3.4.2  rmind 
    935  1.3.4.2  rmind     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
    936  1.3.4.2  rmind     if (ACPI_FAILURE (Status))
    937  1.3.4.2  rmind     {
    938  1.3.4.2  rmind         return (Status);
    939  1.3.4.2  rmind     }
    940  1.3.4.2  rmind 
    941  1.3.4.2  rmind     /* Convert and validate the handle */
    942  1.3.4.2  rmind 
    943  1.3.4.2  rmind     Node = AcpiNsValidateHandle (ObjHandle);
    944  1.3.4.2  rmind     if (!Node)
    945  1.3.4.2  rmind     {
    946  1.3.4.2  rmind         Status = AE_BAD_PARAMETER;
    947  1.3.4.2  rmind         goto UnlockAndExit;
    948  1.3.4.2  rmind     }
    949  1.3.4.2  rmind 
    950  1.3.4.2  rmind     Status = AcpiNsGetAttachedData (Node, Handler, Data);
    951  1.3.4.2  rmind 
    952  1.3.4.2  rmind UnlockAndExit:
    953  1.3.4.2  rmind     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    954  1.3.4.2  rmind     return (Status);
    955  1.3.4.2  rmind }
    956  1.3.4.2  rmind 
    957  1.3.4.2  rmind ACPI_EXPORT_SYMBOL (AcpiGetData)
    958  1.3.4.2  rmind 
    959  1.3.4.2  rmind 
    960