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