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