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