Home | History | Annotate | Line # | Download | only in namespace
nsaccess.c revision 1.3.2.2
      1  1.3.2.2  bouyer /*******************************************************************************
      2  1.3.2.2  bouyer  *
      3  1.3.2.2  bouyer  * Module Name: nsaccess - Top-level functions for accessing ACPI namespace
      4  1.3.2.2  bouyer  *
      5  1.3.2.2  bouyer  ******************************************************************************/
      6  1.3.2.2  bouyer 
      7  1.3.2.2  bouyer /*
      8  1.3.2.2  bouyer  * Copyright (C) 2000 - 2011, Intel Corp.
      9  1.3.2.2  bouyer  * All rights reserved.
     10  1.3.2.2  bouyer  *
     11  1.3.2.2  bouyer  * Redistribution and use in source and binary forms, with or without
     12  1.3.2.2  bouyer  * modification, are permitted provided that the following conditions
     13  1.3.2.2  bouyer  * are met:
     14  1.3.2.2  bouyer  * 1. Redistributions of source code must retain the above copyright
     15  1.3.2.2  bouyer  *    notice, this list of conditions, and the following disclaimer,
     16  1.3.2.2  bouyer  *    without modification.
     17  1.3.2.2  bouyer  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  1.3.2.2  bouyer  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  1.3.2.2  bouyer  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  1.3.2.2  bouyer  *    including a substantially similar Disclaimer requirement for further
     21  1.3.2.2  bouyer  *    binary redistribution.
     22  1.3.2.2  bouyer  * 3. Neither the names of the above-listed copyright holders nor the names
     23  1.3.2.2  bouyer  *    of any contributors may be used to endorse or promote products derived
     24  1.3.2.2  bouyer  *    from this software without specific prior written permission.
     25  1.3.2.2  bouyer  *
     26  1.3.2.2  bouyer  * Alternatively, this software may be distributed under the terms of the
     27  1.3.2.2  bouyer  * GNU General Public License ("GPL") version 2 as published by the Free
     28  1.3.2.2  bouyer  * Software Foundation.
     29  1.3.2.2  bouyer  *
     30  1.3.2.2  bouyer  * NO WARRANTY
     31  1.3.2.2  bouyer  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  1.3.2.2  bouyer  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.3.2.2  bouyer  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  1.3.2.2  bouyer  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  1.3.2.2  bouyer  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  1.3.2.2  bouyer  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  1.3.2.2  bouyer  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  1.3.2.2  bouyer  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  1.3.2.2  bouyer  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  1.3.2.2  bouyer  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  1.3.2.2  bouyer  * POSSIBILITY OF SUCH DAMAGES.
     42  1.3.2.2  bouyer  */
     43  1.3.2.2  bouyer 
     44  1.3.2.2  bouyer #define __NSACCESS_C__
     45  1.3.2.2  bouyer 
     46  1.3.2.2  bouyer #include "acpi.h"
     47  1.3.2.2  bouyer #include "accommon.h"
     48  1.3.2.2  bouyer #include "amlcode.h"
     49  1.3.2.2  bouyer #include "acnamesp.h"
     50  1.3.2.2  bouyer #include "acdispat.h"
     51  1.3.2.2  bouyer 
     52  1.3.2.2  bouyer 
     53  1.3.2.2  bouyer #define _COMPONENT          ACPI_NAMESPACE
     54  1.3.2.2  bouyer         ACPI_MODULE_NAME    ("nsaccess")
     55  1.3.2.2  bouyer 
     56  1.3.2.2  bouyer 
     57  1.3.2.2  bouyer /*******************************************************************************
     58  1.3.2.2  bouyer  *
     59  1.3.2.2  bouyer  * FUNCTION:    AcpiNsRootInitialize
     60  1.3.2.2  bouyer  *
     61  1.3.2.2  bouyer  * PARAMETERS:  None
     62  1.3.2.2  bouyer  *
     63  1.3.2.2  bouyer  * RETURN:      Status
     64  1.3.2.2  bouyer  *
     65  1.3.2.2  bouyer  * DESCRIPTION: Allocate and initialize the default root named objects
     66  1.3.2.2  bouyer  *
     67  1.3.2.2  bouyer  * MUTEX:       Locks namespace for entire execution
     68  1.3.2.2  bouyer  *
     69  1.3.2.2  bouyer  ******************************************************************************/
     70  1.3.2.2  bouyer 
     71  1.3.2.2  bouyer ACPI_STATUS
     72  1.3.2.2  bouyer AcpiNsRootInitialize (
     73  1.3.2.2  bouyer     void)
     74  1.3.2.2  bouyer {
     75  1.3.2.2  bouyer     ACPI_STATUS                 Status;
     76  1.3.2.2  bouyer     const ACPI_PREDEFINED_NAMES *InitVal = NULL;
     77  1.3.2.2  bouyer     ACPI_NAMESPACE_NODE         *NewNode;
     78  1.3.2.2  bouyer     ACPI_OPERAND_OBJECT         *ObjDesc;
     79  1.3.2.2  bouyer     ACPI_STRING                 Val = NULL;
     80  1.3.2.2  bouyer 
     81  1.3.2.2  bouyer 
     82  1.3.2.2  bouyer     ACPI_FUNCTION_TRACE (NsRootInitialize);
     83  1.3.2.2  bouyer 
     84  1.3.2.2  bouyer 
     85  1.3.2.2  bouyer     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
     86  1.3.2.2  bouyer     if (ACPI_FAILURE (Status))
     87  1.3.2.2  bouyer     {
     88  1.3.2.2  bouyer         return_ACPI_STATUS (Status);
     89  1.3.2.2  bouyer     }
     90  1.3.2.2  bouyer 
     91  1.3.2.2  bouyer     /*
     92  1.3.2.2  bouyer      * The global root ptr is initially NULL, so a non-NULL value indicates
     93  1.3.2.2  bouyer      * that AcpiNsRootInitialize() has already been called; just return.
     94  1.3.2.2  bouyer      */
     95  1.3.2.2  bouyer     if (AcpiGbl_RootNode)
     96  1.3.2.2  bouyer     {
     97  1.3.2.2  bouyer         Status = AE_OK;
     98  1.3.2.2  bouyer         goto UnlockAndExit;
     99  1.3.2.2  bouyer     }
    100  1.3.2.2  bouyer 
    101  1.3.2.2  bouyer     /*
    102  1.3.2.2  bouyer      * Tell the rest of the subsystem that the root is initialized
    103  1.3.2.2  bouyer      * (This is OK because the namespace is locked)
    104  1.3.2.2  bouyer      */
    105  1.3.2.2  bouyer     AcpiGbl_RootNode = &AcpiGbl_RootNodeStruct;
    106  1.3.2.2  bouyer 
    107  1.3.2.2  bouyer     /* Enter the pre-defined names in the name table */
    108  1.3.2.2  bouyer 
    109  1.3.2.2  bouyer     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
    110  1.3.2.2  bouyer         "Entering predefined entries into namespace\n"));
    111  1.3.2.2  bouyer 
    112  1.3.2.2  bouyer     for (InitVal = AcpiGbl_PreDefinedNames; InitVal->Name; InitVal++)
    113  1.3.2.2  bouyer     {
    114  1.3.2.2  bouyer         /* _OSI is optional for now, will be permanent later */
    115  1.3.2.2  bouyer 
    116  1.3.2.2  bouyer         if (!ACPI_STRCMP (InitVal->Name, "_OSI") && !AcpiGbl_CreateOsiMethod)
    117  1.3.2.2  bouyer         {
    118  1.3.2.2  bouyer             continue;
    119  1.3.2.2  bouyer         }
    120  1.3.2.2  bouyer 
    121  1.3.2.2  bouyer         Status = AcpiNsLookup (NULL, __UNCONST(InitVal->Name), InitVal->Type,
    122  1.3.2.2  bouyer                         ACPI_IMODE_LOAD_PASS2, ACPI_NS_NO_UPSEARCH,
    123  1.3.2.2  bouyer                         NULL, &NewNode);
    124  1.3.2.2  bouyer 
    125  1.3.2.2  bouyer         if (ACPI_FAILURE (Status) || (!NewNode)) /* Must be on same line for code converter */
    126  1.3.2.2  bouyer         {
    127  1.3.2.2  bouyer             ACPI_EXCEPTION ((AE_INFO, Status,
    128  1.3.2.2  bouyer                 "Could not create predefined name %s",
    129  1.3.2.2  bouyer                 InitVal->Name));
    130  1.3.2.2  bouyer         }
    131  1.3.2.2  bouyer 
    132  1.3.2.2  bouyer         /*
    133  1.3.2.2  bouyer          * Name entered successfully. If entry in PreDefinedNames[] specifies
    134  1.3.2.2  bouyer          * an initial value, create the initial value.
    135  1.3.2.2  bouyer          */
    136  1.3.2.2  bouyer         if (InitVal->Val)
    137  1.3.2.2  bouyer         {
    138  1.3.2.2  bouyer             Status = AcpiOsPredefinedOverride (InitVal, &Val);
    139  1.3.2.2  bouyer             if (ACPI_FAILURE (Status))
    140  1.3.2.2  bouyer             {
    141  1.3.2.2  bouyer                 ACPI_ERROR ((AE_INFO,
    142  1.3.2.2  bouyer                     "Could not override predefined %s",
    143  1.3.2.2  bouyer                     InitVal->Name));
    144  1.3.2.2  bouyer             }
    145  1.3.2.2  bouyer 
    146  1.3.2.2  bouyer             if (!Val)
    147  1.3.2.2  bouyer             {
    148  1.3.2.2  bouyer                 Val = __UNCONST(InitVal->Val);
    149  1.3.2.2  bouyer             }
    150  1.3.2.2  bouyer 
    151  1.3.2.2  bouyer             /*
    152  1.3.2.2  bouyer              * Entry requests an initial value, allocate a
    153  1.3.2.2  bouyer              * descriptor for it.
    154  1.3.2.2  bouyer              */
    155  1.3.2.2  bouyer             ObjDesc = AcpiUtCreateInternalObject (InitVal->Type);
    156  1.3.2.2  bouyer             if (!ObjDesc)
    157  1.3.2.2  bouyer             {
    158  1.3.2.2  bouyer                 Status = AE_NO_MEMORY;
    159  1.3.2.2  bouyer                 goto UnlockAndExit;
    160  1.3.2.2  bouyer             }
    161  1.3.2.2  bouyer 
    162  1.3.2.2  bouyer             /*
    163  1.3.2.2  bouyer              * Convert value string from table entry to
    164  1.3.2.2  bouyer              * internal representation. Only types actually
    165  1.3.2.2  bouyer              * used for initial values are implemented here.
    166  1.3.2.2  bouyer              */
    167  1.3.2.2  bouyer             switch (InitVal->Type)
    168  1.3.2.2  bouyer             {
    169  1.3.2.2  bouyer             case ACPI_TYPE_METHOD:
    170  1.3.2.2  bouyer                 ObjDesc->Method.ParamCount = (UINT8) ACPI_TO_INTEGER (Val);
    171  1.3.2.2  bouyer                 ObjDesc->Common.Flags |= AOPOBJ_DATA_VALID;
    172  1.3.2.2  bouyer 
    173  1.3.2.2  bouyer #if defined (ACPI_ASL_COMPILER)
    174  1.3.2.2  bouyer 
    175  1.3.2.2  bouyer                 /* Save the parameter count for the iASL compiler */
    176  1.3.2.2  bouyer 
    177  1.3.2.2  bouyer                 NewNode->Value = ObjDesc->Method.ParamCount;
    178  1.3.2.2  bouyer #else
    179  1.3.2.2  bouyer                 /* Mark this as a very SPECIAL method */
    180  1.3.2.2  bouyer 
    181  1.3.2.2  bouyer                 ObjDesc->Method.InfoFlags = ACPI_METHOD_INTERNAL_ONLY;
    182  1.3.2.2  bouyer                 ObjDesc->Method.Dispatch.Implementation = AcpiUtOsiImplementation;
    183  1.3.2.2  bouyer #endif
    184  1.3.2.2  bouyer                 break;
    185  1.3.2.2  bouyer 
    186  1.3.2.2  bouyer             case ACPI_TYPE_INTEGER:
    187  1.3.2.2  bouyer 
    188  1.3.2.2  bouyer                 ObjDesc->Integer.Value = ACPI_TO_INTEGER (Val);
    189  1.3.2.2  bouyer                 break;
    190  1.3.2.2  bouyer 
    191  1.3.2.2  bouyer 
    192  1.3.2.2  bouyer             case ACPI_TYPE_STRING:
    193  1.3.2.2  bouyer 
    194  1.3.2.2  bouyer                 /* Build an object around the static string */
    195  1.3.2.2  bouyer 
    196  1.3.2.2  bouyer                 ObjDesc->String.Length = (UINT32) ACPI_STRLEN (Val);
    197  1.3.2.2  bouyer                 ObjDesc->String.Pointer = Val;
    198  1.3.2.2  bouyer                 ObjDesc->Common.Flags |= AOPOBJ_STATIC_POINTER;
    199  1.3.2.2  bouyer                 break;
    200  1.3.2.2  bouyer 
    201  1.3.2.2  bouyer 
    202  1.3.2.2  bouyer             case ACPI_TYPE_MUTEX:
    203  1.3.2.2  bouyer 
    204  1.3.2.2  bouyer                 ObjDesc->Mutex.Node = NewNode;
    205  1.3.2.2  bouyer                 ObjDesc->Mutex.SyncLevel = (UINT8) (ACPI_TO_INTEGER (Val) - 1);
    206  1.3.2.2  bouyer 
    207  1.3.2.2  bouyer                 /* Create a mutex */
    208  1.3.2.2  bouyer 
    209  1.3.2.2  bouyer                 Status = AcpiOsCreateMutex (&ObjDesc->Mutex.OsMutex);
    210  1.3.2.2  bouyer                 if (ACPI_FAILURE (Status))
    211  1.3.2.2  bouyer                 {
    212  1.3.2.2  bouyer                     AcpiUtRemoveReference (ObjDesc);
    213  1.3.2.2  bouyer                     goto UnlockAndExit;
    214  1.3.2.2  bouyer                 }
    215  1.3.2.2  bouyer 
    216  1.3.2.2  bouyer                 /* Special case for ACPI Global Lock */
    217  1.3.2.2  bouyer 
    218  1.3.2.2  bouyer                 if (ACPI_STRCMP (InitVal->Name, "_GL_") == 0)
    219  1.3.2.2  bouyer                 {
    220  1.3.2.2  bouyer                     AcpiGbl_GlobalLockMutex = ObjDesc;
    221  1.3.2.2  bouyer 
    222  1.3.2.2  bouyer                     /* Create additional counting semaphore for global lock */
    223  1.3.2.2  bouyer 
    224  1.3.2.2  bouyer                     Status = AcpiOsCreateSemaphore (
    225  1.3.2.2  bouyer                                 1, 0, &AcpiGbl_GlobalLockSemaphore);
    226  1.3.2.2  bouyer                     if (ACPI_FAILURE (Status))
    227  1.3.2.2  bouyer                     {
    228  1.3.2.2  bouyer                         AcpiUtRemoveReference (ObjDesc);
    229  1.3.2.2  bouyer                         goto UnlockAndExit;
    230  1.3.2.2  bouyer                     }
    231  1.3.2.2  bouyer                 }
    232  1.3.2.2  bouyer                 break;
    233  1.3.2.2  bouyer 
    234  1.3.2.2  bouyer 
    235  1.3.2.2  bouyer             default:
    236  1.3.2.2  bouyer 
    237  1.3.2.2  bouyer                 ACPI_ERROR ((AE_INFO, "Unsupported initial type value 0x%X",
    238  1.3.2.2  bouyer                     InitVal->Type));
    239  1.3.2.2  bouyer                 AcpiUtRemoveReference (ObjDesc);
    240  1.3.2.2  bouyer                 ObjDesc = NULL;
    241  1.3.2.2  bouyer                 continue;
    242  1.3.2.2  bouyer             }
    243  1.3.2.2  bouyer 
    244  1.3.2.2  bouyer             /* Store pointer to value descriptor in the Node */
    245  1.3.2.2  bouyer 
    246  1.3.2.2  bouyer             Status = AcpiNsAttachObject (NewNode, ObjDesc,
    247  1.3.2.2  bouyer                         ObjDesc->Common.Type);
    248  1.3.2.2  bouyer 
    249  1.3.2.2  bouyer             /* Remove local reference to the object */
    250  1.3.2.2  bouyer 
    251  1.3.2.2  bouyer             AcpiUtRemoveReference (ObjDesc);
    252  1.3.2.2  bouyer         }
    253  1.3.2.2  bouyer     }
    254  1.3.2.2  bouyer 
    255  1.3.2.2  bouyer 
    256  1.3.2.2  bouyer UnlockAndExit:
    257  1.3.2.2  bouyer     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    258  1.3.2.2  bouyer 
    259  1.3.2.2  bouyer     /* Save a handle to "_GPE", it is always present */
    260  1.3.2.2  bouyer 
    261  1.3.2.2  bouyer     if (ACPI_SUCCESS (Status))
    262  1.3.2.2  bouyer     {
    263  1.3.2.2  bouyer         Status = AcpiNsGetNode (NULL, "\\_GPE", ACPI_NS_NO_UPSEARCH,
    264  1.3.2.2  bouyer                     &AcpiGbl_FadtGpeDevice);
    265  1.3.2.2  bouyer     }
    266  1.3.2.2  bouyer 
    267  1.3.2.2  bouyer     return_ACPI_STATUS (Status);
    268  1.3.2.2  bouyer }
    269  1.3.2.2  bouyer 
    270  1.3.2.2  bouyer 
    271  1.3.2.2  bouyer /*******************************************************************************
    272  1.3.2.2  bouyer  *
    273  1.3.2.2  bouyer  * FUNCTION:    AcpiNsLookup
    274  1.3.2.2  bouyer  *
    275  1.3.2.2  bouyer  * PARAMETERS:  ScopeInfo       - Current scope info block
    276  1.3.2.2  bouyer  *              Pathname        - Search pathname, in internal format
    277  1.3.2.2  bouyer  *                                (as represented in the AML stream)
    278  1.3.2.2  bouyer  *              Type            - Type associated with name
    279  1.3.2.2  bouyer  *              InterpreterMode - IMODE_LOAD_PASS2 => add name if not found
    280  1.3.2.2  bouyer  *              Flags           - Flags describing the search restrictions
    281  1.3.2.2  bouyer  *              WalkState       - Current state of the walk
    282  1.3.2.2  bouyer  *              ReturnNode      - Where the Node is placed (if found
    283  1.3.2.2  bouyer  *                                or created successfully)
    284  1.3.2.2  bouyer  *
    285  1.3.2.2  bouyer  * RETURN:      Status
    286  1.3.2.2  bouyer  *
    287  1.3.2.2  bouyer  * DESCRIPTION: Find or enter the passed name in the name space.
    288  1.3.2.2  bouyer  *              Log an error if name not found in Exec mode.
    289  1.3.2.2  bouyer  *
    290  1.3.2.2  bouyer  * MUTEX:       Assumes namespace is locked.
    291  1.3.2.2  bouyer  *
    292  1.3.2.2  bouyer  ******************************************************************************/
    293  1.3.2.2  bouyer 
    294  1.3.2.2  bouyer ACPI_STATUS
    295  1.3.2.2  bouyer AcpiNsLookup (
    296  1.3.2.2  bouyer     ACPI_GENERIC_STATE      *ScopeInfo,
    297  1.3.2.2  bouyer     char                    *Pathname,
    298  1.3.2.2  bouyer     ACPI_OBJECT_TYPE        Type,
    299  1.3.2.2  bouyer     ACPI_INTERPRETER_MODE   InterpreterMode,
    300  1.3.2.2  bouyer     UINT32                  Flags,
    301  1.3.2.2  bouyer     ACPI_WALK_STATE         *WalkState,
    302  1.3.2.2  bouyer     ACPI_NAMESPACE_NODE     **ReturnNode)
    303  1.3.2.2  bouyer {
    304  1.3.2.2  bouyer     ACPI_STATUS             Status;
    305  1.3.2.2  bouyer     char                    *Path = Pathname;
    306  1.3.2.2  bouyer     ACPI_NAMESPACE_NODE     *PrefixNode;
    307  1.3.2.2  bouyer     ACPI_NAMESPACE_NODE     *CurrentNode = NULL;
    308  1.3.2.2  bouyer     ACPI_NAMESPACE_NODE     *ThisNode = NULL;
    309  1.3.2.2  bouyer     UINT32                  NumSegments;
    310  1.3.2.2  bouyer     UINT32                  NumCarats;
    311  1.3.2.2  bouyer     ACPI_NAME               SimpleName;
    312  1.3.2.2  bouyer     ACPI_OBJECT_TYPE        TypeToCheckFor;
    313  1.3.2.2  bouyer     ACPI_OBJECT_TYPE        ThisSearchType;
    314  1.3.2.2  bouyer     UINT32                  SearchParentFlag = ACPI_NS_SEARCH_PARENT;
    315  1.3.2.2  bouyer     UINT32                  LocalFlags;
    316  1.3.2.2  bouyer 
    317  1.3.2.2  bouyer 
    318  1.3.2.2  bouyer     ACPI_FUNCTION_TRACE (NsLookup);
    319  1.3.2.2  bouyer 
    320  1.3.2.2  bouyer 
    321  1.3.2.2  bouyer     if (!ReturnNode)
    322  1.3.2.2  bouyer     {
    323  1.3.2.2  bouyer         return_ACPI_STATUS (AE_BAD_PARAMETER);
    324  1.3.2.2  bouyer     }
    325  1.3.2.2  bouyer 
    326  1.3.2.2  bouyer     LocalFlags = Flags & ~(ACPI_NS_ERROR_IF_FOUND | ACPI_NS_SEARCH_PARENT);
    327  1.3.2.2  bouyer     *ReturnNode = ACPI_ENTRY_NOT_FOUND;
    328  1.3.2.2  bouyer     AcpiGbl_NsLookupCount++;
    329  1.3.2.2  bouyer 
    330  1.3.2.2  bouyer     if (!AcpiGbl_RootNode)
    331  1.3.2.2  bouyer     {
    332  1.3.2.2  bouyer         return_ACPI_STATUS (AE_NO_NAMESPACE);
    333  1.3.2.2  bouyer     }
    334  1.3.2.2  bouyer 
    335  1.3.2.2  bouyer     /* Get the prefix scope. A null scope means use the root scope */
    336  1.3.2.2  bouyer 
    337  1.3.2.2  bouyer     if ((!ScopeInfo) ||
    338  1.3.2.2  bouyer         (!ScopeInfo->Scope.Node))
    339  1.3.2.2  bouyer     {
    340  1.3.2.2  bouyer         ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
    341  1.3.2.2  bouyer             "Null scope prefix, using root node (%p)\n",
    342  1.3.2.2  bouyer             AcpiGbl_RootNode));
    343  1.3.2.2  bouyer 
    344  1.3.2.2  bouyer         PrefixNode = AcpiGbl_RootNode;
    345  1.3.2.2  bouyer     }
    346  1.3.2.2  bouyer     else
    347  1.3.2.2  bouyer     {
    348  1.3.2.2  bouyer         PrefixNode = ScopeInfo->Scope.Node;
    349  1.3.2.2  bouyer         if (ACPI_GET_DESCRIPTOR_TYPE (PrefixNode) != ACPI_DESC_TYPE_NAMED)
    350  1.3.2.2  bouyer         {
    351  1.3.2.2  bouyer             ACPI_ERROR ((AE_INFO, "%p is not a namespace node [%s]",
    352  1.3.2.2  bouyer                 PrefixNode, AcpiUtGetDescriptorName (PrefixNode)));
    353  1.3.2.2  bouyer             return_ACPI_STATUS (AE_AML_INTERNAL);
    354  1.3.2.2  bouyer         }
    355  1.3.2.2  bouyer 
    356  1.3.2.2  bouyer         if (!(Flags & ACPI_NS_PREFIX_IS_SCOPE))
    357  1.3.2.2  bouyer         {
    358  1.3.2.2  bouyer             /*
    359  1.3.2.2  bouyer              * This node might not be a actual "scope" node (such as a
    360  1.3.2.2  bouyer              * Device/Method, etc.)  It could be a Package or other object
    361  1.3.2.2  bouyer              * node. Backup up the tree to find the containing scope node.
    362  1.3.2.2  bouyer              */
    363  1.3.2.2  bouyer             while (!AcpiNsOpensScope (PrefixNode->Type) &&
    364  1.3.2.2  bouyer                     PrefixNode->Type != ACPI_TYPE_ANY)
    365  1.3.2.2  bouyer             {
    366  1.3.2.2  bouyer                 PrefixNode = PrefixNode->Parent;
    367  1.3.2.2  bouyer             }
    368  1.3.2.2  bouyer         }
    369  1.3.2.2  bouyer     }
    370  1.3.2.2  bouyer 
    371  1.3.2.2  bouyer     /* Save type. TBD: may be no longer necessary */
    372  1.3.2.2  bouyer 
    373  1.3.2.2  bouyer     TypeToCheckFor = Type;
    374  1.3.2.2  bouyer 
    375  1.3.2.2  bouyer     /*
    376  1.3.2.2  bouyer      * Begin examination of the actual pathname
    377  1.3.2.2  bouyer      */
    378  1.3.2.2  bouyer     if (!Pathname)
    379  1.3.2.2  bouyer     {
    380  1.3.2.2  bouyer         /* A Null NamePath is allowed and refers to the root */
    381  1.3.2.2  bouyer 
    382  1.3.2.2  bouyer         NumSegments = 0;
    383  1.3.2.2  bouyer         ThisNode = AcpiGbl_RootNode;
    384  1.3.2.2  bouyer         Path = __UNCONST("");
    385  1.3.2.2  bouyer 
    386  1.3.2.2  bouyer         ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
    387  1.3.2.2  bouyer             "Null Pathname (Zero segments), Flags=%X\n", Flags));
    388  1.3.2.2  bouyer     }
    389  1.3.2.2  bouyer     else
    390  1.3.2.2  bouyer     {
    391  1.3.2.2  bouyer         /*
    392  1.3.2.2  bouyer          * Name pointer is valid (and must be in internal name format)
    393  1.3.2.2  bouyer          *
    394  1.3.2.2  bouyer          * Check for scope prefixes:
    395  1.3.2.2  bouyer          *
    396  1.3.2.2  bouyer          * As represented in the AML stream, a namepath consists of an
    397  1.3.2.2  bouyer          * optional scope prefix followed by a name segment part.
    398  1.3.2.2  bouyer          *
    399  1.3.2.2  bouyer          * If present, the scope prefix is either a Root Prefix (in
    400  1.3.2.2  bouyer          * which case the name is fully qualified), or one or more
    401  1.3.2.2  bouyer          * Parent Prefixes (in which case the name's scope is relative
    402  1.3.2.2  bouyer          * to the current scope).
    403  1.3.2.2  bouyer          */
    404  1.3.2.2  bouyer         if (*Path == (UINT8) AML_ROOT_PREFIX)
    405  1.3.2.2  bouyer         {
    406  1.3.2.2  bouyer             /* Pathname is fully qualified, start from the root */
    407  1.3.2.2  bouyer 
    408  1.3.2.2  bouyer             ThisNode = AcpiGbl_RootNode;
    409  1.3.2.2  bouyer             SearchParentFlag = ACPI_NS_NO_UPSEARCH;
    410  1.3.2.2  bouyer 
    411  1.3.2.2  bouyer             /* Point to name segment part */
    412  1.3.2.2  bouyer 
    413  1.3.2.2  bouyer             Path++;
    414  1.3.2.2  bouyer 
    415  1.3.2.2  bouyer             ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
    416  1.3.2.2  bouyer                 "Path is absolute from root [%p]\n", ThisNode));
    417  1.3.2.2  bouyer         }
    418  1.3.2.2  bouyer         else
    419  1.3.2.2  bouyer         {
    420  1.3.2.2  bouyer             /* Pathname is relative to current scope, start there */
    421  1.3.2.2  bouyer 
    422  1.3.2.2  bouyer             ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
    423  1.3.2.2  bouyer                 "Searching relative to prefix scope [%4.4s] (%p)\n",
    424  1.3.2.2  bouyer                 AcpiUtGetNodeName (PrefixNode), PrefixNode));
    425  1.3.2.2  bouyer 
    426  1.3.2.2  bouyer             /*
    427  1.3.2.2  bouyer              * Handle multiple Parent Prefixes (carat) by just getting
    428  1.3.2.2  bouyer              * the parent node for each prefix instance.
    429  1.3.2.2  bouyer              */
    430  1.3.2.2  bouyer             ThisNode = PrefixNode;
    431  1.3.2.2  bouyer             NumCarats = 0;
    432  1.3.2.2  bouyer             while (*Path == (UINT8) AML_PARENT_PREFIX)
    433  1.3.2.2  bouyer             {
    434  1.3.2.2  bouyer                 /* Name is fully qualified, no search rules apply */
    435  1.3.2.2  bouyer 
    436  1.3.2.2  bouyer                 SearchParentFlag = ACPI_NS_NO_UPSEARCH;
    437  1.3.2.2  bouyer 
    438  1.3.2.2  bouyer                 /*
    439  1.3.2.2  bouyer                  * Point past this prefix to the name segment
    440  1.3.2.2  bouyer                  * part or the next Parent Prefix
    441  1.3.2.2  bouyer                  */
    442  1.3.2.2  bouyer                 Path++;
    443  1.3.2.2  bouyer 
    444  1.3.2.2  bouyer                 /* Backup to the parent node */
    445  1.3.2.2  bouyer 
    446  1.3.2.2  bouyer                 NumCarats++;
    447  1.3.2.2  bouyer                 ThisNode = ThisNode->Parent;
    448  1.3.2.2  bouyer                 if (!ThisNode)
    449  1.3.2.2  bouyer                 {
    450  1.3.2.2  bouyer                     /* Current scope has no parent scope */
    451  1.3.2.2  bouyer 
    452  1.3.2.2  bouyer                     ACPI_ERROR ((AE_INFO,
    453  1.3.2.2  bouyer                         "ACPI path has too many parent prefixes (^) "
    454  1.3.2.2  bouyer                         "- reached beyond root node"));
    455  1.3.2.2  bouyer                     return_ACPI_STATUS (AE_NOT_FOUND);
    456  1.3.2.2  bouyer                 }
    457  1.3.2.2  bouyer             }
    458  1.3.2.2  bouyer 
    459  1.3.2.2  bouyer             if (SearchParentFlag == ACPI_NS_NO_UPSEARCH)
    460  1.3.2.2  bouyer             {
    461  1.3.2.2  bouyer                 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
    462  1.3.2.2  bouyer                     "Search scope is [%4.4s], path has %u carat(s)\n",
    463  1.3.2.2  bouyer                     AcpiUtGetNodeName (ThisNode), NumCarats));
    464  1.3.2.2  bouyer             }
    465  1.3.2.2  bouyer         }
    466  1.3.2.2  bouyer 
    467  1.3.2.2  bouyer         /*
    468  1.3.2.2  bouyer          * Determine the number of ACPI name segments in this pathname.
    469  1.3.2.2  bouyer          *
    470  1.3.2.2  bouyer          * The segment part consists of either:
    471  1.3.2.2  bouyer          *  - A Null name segment (0)
    472  1.3.2.2  bouyer          *  - A DualNamePrefix followed by two 4-byte name segments
    473  1.3.2.2  bouyer          *  - A MultiNamePrefix followed by a byte indicating the
    474  1.3.2.2  bouyer          *      number of segments and the segments themselves.
    475  1.3.2.2  bouyer          *  - A single 4-byte name segment
    476  1.3.2.2  bouyer          *
    477  1.3.2.2  bouyer          * Examine the name prefix opcode, if any, to determine the number of
    478  1.3.2.2  bouyer          * segments.
    479  1.3.2.2  bouyer          */
    480  1.3.2.2  bouyer         switch (*Path)
    481  1.3.2.2  bouyer         {
    482  1.3.2.2  bouyer         case 0:
    483  1.3.2.2  bouyer             /*
    484  1.3.2.2  bouyer              * Null name after a root or parent prefixes. We already
    485  1.3.2.2  bouyer              * have the correct target node and there are no name segments.
    486  1.3.2.2  bouyer              */
    487  1.3.2.2  bouyer             NumSegments  = 0;
    488  1.3.2.2  bouyer             Type = ThisNode->Type;
    489  1.3.2.2  bouyer 
    490  1.3.2.2  bouyer             ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
    491  1.3.2.2  bouyer                 "Prefix-only Pathname (Zero name segments), Flags=%X\n",
    492  1.3.2.2  bouyer                 Flags));
    493  1.3.2.2  bouyer             break;
    494  1.3.2.2  bouyer 
    495  1.3.2.2  bouyer         case AML_DUAL_NAME_PREFIX:
    496  1.3.2.2  bouyer 
    497  1.3.2.2  bouyer             /* More than one NameSeg, search rules do not apply */
    498  1.3.2.2  bouyer 
    499  1.3.2.2  bouyer             SearchParentFlag = ACPI_NS_NO_UPSEARCH;
    500  1.3.2.2  bouyer 
    501  1.3.2.2  bouyer             /* Two segments, point to first name segment */
    502  1.3.2.2  bouyer 
    503  1.3.2.2  bouyer             NumSegments = 2;
    504  1.3.2.2  bouyer             Path++;
    505  1.3.2.2  bouyer 
    506  1.3.2.2  bouyer             ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
    507  1.3.2.2  bouyer                 "Dual Pathname (2 segments, Flags=%X)\n", Flags));
    508  1.3.2.2  bouyer             break;
    509  1.3.2.2  bouyer 
    510  1.3.2.2  bouyer         case AML_MULTI_NAME_PREFIX_OP:
    511  1.3.2.2  bouyer 
    512  1.3.2.2  bouyer             /* More than one NameSeg, search rules do not apply */
    513  1.3.2.2  bouyer 
    514  1.3.2.2  bouyer             SearchParentFlag = ACPI_NS_NO_UPSEARCH;
    515  1.3.2.2  bouyer 
    516  1.3.2.2  bouyer             /* Extract segment count, point to first name segment */
    517  1.3.2.2  bouyer 
    518  1.3.2.2  bouyer             Path++;
    519  1.3.2.2  bouyer             NumSegments = (UINT32) (UINT8) *Path;
    520  1.3.2.2  bouyer             Path++;
    521  1.3.2.2  bouyer 
    522  1.3.2.2  bouyer             ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
    523  1.3.2.2  bouyer                 "Multi Pathname (%u Segments, Flags=%X)\n",
    524  1.3.2.2  bouyer                 NumSegments, Flags));
    525  1.3.2.2  bouyer             break;
    526  1.3.2.2  bouyer 
    527  1.3.2.2  bouyer         default:
    528  1.3.2.2  bouyer             /*
    529  1.3.2.2  bouyer              * Not a Null name, no Dual or Multi prefix, hence there is
    530  1.3.2.2  bouyer              * only one name segment and Pathname is already pointing to it.
    531  1.3.2.2  bouyer              */
    532  1.3.2.2  bouyer             NumSegments = 1;
    533  1.3.2.2  bouyer 
    534  1.3.2.2  bouyer             ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
    535  1.3.2.2  bouyer                 "Simple Pathname (1 segment, Flags=%X)\n", Flags));
    536  1.3.2.2  bouyer             break;
    537  1.3.2.2  bouyer         }
    538  1.3.2.2  bouyer 
    539  1.3.2.2  bouyer         ACPI_DEBUG_EXEC (AcpiNsPrintPathname (NumSegments, Path));
    540  1.3.2.2  bouyer     }
    541  1.3.2.2  bouyer 
    542  1.3.2.2  bouyer 
    543  1.3.2.2  bouyer     /*
    544  1.3.2.2  bouyer      * Search namespace for each segment of the name. Loop through and
    545  1.3.2.2  bouyer      * verify (or add to the namespace) each name segment.
    546  1.3.2.2  bouyer      *
    547  1.3.2.2  bouyer      * The object type is significant only at the last name
    548  1.3.2.2  bouyer      * segment. (We don't care about the types along the path, only
    549  1.3.2.2  bouyer      * the type of the final target object.)
    550  1.3.2.2  bouyer      */
    551  1.3.2.2  bouyer     ThisSearchType = ACPI_TYPE_ANY;
    552  1.3.2.2  bouyer     CurrentNode = ThisNode;
    553  1.3.2.2  bouyer     while (NumSegments && CurrentNode)
    554  1.3.2.2  bouyer     {
    555  1.3.2.2  bouyer         NumSegments--;
    556  1.3.2.2  bouyer         if (!NumSegments)
    557  1.3.2.2  bouyer         {
    558  1.3.2.2  bouyer             /* This is the last segment, enable typechecking */
    559  1.3.2.2  bouyer 
    560  1.3.2.2  bouyer             ThisSearchType = Type;
    561  1.3.2.2  bouyer 
    562  1.3.2.2  bouyer             /*
    563  1.3.2.2  bouyer              * Only allow automatic parent search (search rules) if the caller
    564  1.3.2.2  bouyer              * requested it AND we have a single, non-fully-qualified NameSeg
    565  1.3.2.2  bouyer              */
    566  1.3.2.2  bouyer             if ((SearchParentFlag != ACPI_NS_NO_UPSEARCH) &&
    567  1.3.2.2  bouyer                 (Flags & ACPI_NS_SEARCH_PARENT))
    568  1.3.2.2  bouyer             {
    569  1.3.2.2  bouyer                 LocalFlags |= ACPI_NS_SEARCH_PARENT;
    570  1.3.2.2  bouyer             }
    571  1.3.2.2  bouyer 
    572  1.3.2.2  bouyer             /* Set error flag according to caller */
    573  1.3.2.2  bouyer 
    574  1.3.2.2  bouyer             if (Flags & ACPI_NS_ERROR_IF_FOUND)
    575  1.3.2.2  bouyer             {
    576  1.3.2.2  bouyer                 LocalFlags |= ACPI_NS_ERROR_IF_FOUND;
    577  1.3.2.2  bouyer             }
    578  1.3.2.2  bouyer         }
    579  1.3.2.2  bouyer 
    580  1.3.2.2  bouyer         /* Extract one ACPI name from the front of the pathname */
    581  1.3.2.2  bouyer 
    582  1.3.2.2  bouyer         ACPI_MOVE_32_TO_32 (&SimpleName, Path);
    583  1.3.2.2  bouyer 
    584  1.3.2.2  bouyer         /* Try to find the single (4 character) ACPI name */
    585  1.3.2.2  bouyer 
    586  1.3.2.2  bouyer         Status = AcpiNsSearchAndEnter (SimpleName, WalkState, CurrentNode,
    587  1.3.2.2  bouyer                     InterpreterMode, ThisSearchType, LocalFlags, &ThisNode);
    588  1.3.2.2  bouyer         if (ACPI_FAILURE (Status))
    589  1.3.2.2  bouyer         {
    590  1.3.2.2  bouyer             if (Status == AE_NOT_FOUND)
    591  1.3.2.2  bouyer             {
    592  1.3.2.2  bouyer                 /* Name not found in ACPI namespace */
    593  1.3.2.2  bouyer 
    594  1.3.2.2  bouyer                 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
    595  1.3.2.2  bouyer                     "Name [%4.4s] not found in scope [%4.4s] %p\n",
    596  1.3.2.2  bouyer                     (char *) &SimpleName, (char *) &CurrentNode->Name,
    597  1.3.2.2  bouyer                     CurrentNode));
    598  1.3.2.2  bouyer             }
    599  1.3.2.2  bouyer 
    600  1.3.2.2  bouyer             *ReturnNode = ThisNode;
    601  1.3.2.2  bouyer             return_ACPI_STATUS (Status);
    602  1.3.2.2  bouyer         }
    603  1.3.2.2  bouyer 
    604  1.3.2.2  bouyer         /* More segments to follow? */
    605  1.3.2.2  bouyer 
    606  1.3.2.2  bouyer         if (NumSegments > 0)
    607  1.3.2.2  bouyer         {
    608  1.3.2.2  bouyer             /*
    609  1.3.2.2  bouyer              * If we have an alias to an object that opens a scope (such as a
    610  1.3.2.2  bouyer              * device or processor), we need to dereference the alias here so
    611  1.3.2.2  bouyer              * that we can access any children of the original node (via the
    612  1.3.2.2  bouyer              * remaining segments).
    613  1.3.2.2  bouyer              */
    614  1.3.2.2  bouyer             if (ThisNode->Type == ACPI_TYPE_LOCAL_ALIAS)
    615  1.3.2.2  bouyer             {
    616  1.3.2.2  bouyer                 if (!ThisNode->Object)
    617  1.3.2.2  bouyer                 {
    618  1.3.2.2  bouyer                     return_ACPI_STATUS (AE_NOT_EXIST);
    619  1.3.2.2  bouyer                 }
    620  1.3.2.2  bouyer 
    621  1.3.2.2  bouyer                 if (AcpiNsOpensScope (((ACPI_NAMESPACE_NODE *)
    622  1.3.2.2  bouyer                         ThisNode->Object)->Type))
    623  1.3.2.2  bouyer                 {
    624  1.3.2.2  bouyer                     ThisNode = (ACPI_NAMESPACE_NODE *) ThisNode->Object;
    625  1.3.2.2  bouyer                 }
    626  1.3.2.2  bouyer             }
    627  1.3.2.2  bouyer         }
    628  1.3.2.2  bouyer 
    629  1.3.2.2  bouyer         /* Special handling for the last segment (NumSegments == 0) */
    630  1.3.2.2  bouyer 
    631  1.3.2.2  bouyer         else
    632  1.3.2.2  bouyer         {
    633  1.3.2.2  bouyer             /*
    634  1.3.2.2  bouyer              * Sanity typecheck of the target object:
    635  1.3.2.2  bouyer              *
    636  1.3.2.2  bouyer              * If 1) This is the last segment (NumSegments == 0)
    637  1.3.2.2  bouyer              *    2) And we are looking for a specific type
    638  1.3.2.2  bouyer              *       (Not checking for TYPE_ANY)
    639  1.3.2.2  bouyer              *    3) Which is not an alias
    640  1.3.2.2  bouyer              *    4) Which is not a local type (TYPE_SCOPE)
    641  1.3.2.2  bouyer              *    5) And the type of target object is known (not TYPE_ANY)
    642  1.3.2.2  bouyer              *    6) And target object does not match what we are looking for
    643  1.3.2.2  bouyer              *
    644  1.3.2.2  bouyer              * Then we have a type mismatch. Just warn and ignore it.
    645  1.3.2.2  bouyer              */
    646  1.3.2.2  bouyer             if ((TypeToCheckFor != ACPI_TYPE_ANY)                   &&
    647  1.3.2.2  bouyer                 (TypeToCheckFor != ACPI_TYPE_LOCAL_ALIAS)           &&
    648  1.3.2.2  bouyer                 (TypeToCheckFor != ACPI_TYPE_LOCAL_METHOD_ALIAS)    &&
    649  1.3.2.2  bouyer                 (TypeToCheckFor != ACPI_TYPE_LOCAL_SCOPE)           &&
    650  1.3.2.2  bouyer                 (ThisNode->Type != ACPI_TYPE_ANY)                   &&
    651  1.3.2.2  bouyer                 (ThisNode->Type != TypeToCheckFor))
    652  1.3.2.2  bouyer             {
    653  1.3.2.2  bouyer                 /* Complain about a type mismatch */
    654  1.3.2.2  bouyer 
    655  1.3.2.2  bouyer                 ACPI_WARNING ((AE_INFO,
    656  1.3.2.2  bouyer                     "NsLookup: Type mismatch on %4.4s (%s), searching for (%s)",
    657  1.3.2.2  bouyer                     ACPI_CAST_PTR (char, &SimpleName),
    658  1.3.2.2  bouyer                     AcpiUtGetTypeName (ThisNode->Type),
    659  1.3.2.2  bouyer                     AcpiUtGetTypeName (TypeToCheckFor)));
    660  1.3.2.2  bouyer             }
    661  1.3.2.2  bouyer 
    662  1.3.2.2  bouyer             /*
    663  1.3.2.2  bouyer              * If this is the last name segment and we are not looking for a
    664  1.3.2.2  bouyer              * specific type, but the type of found object is known, use that
    665  1.3.2.2  bouyer              * type to (later) see if it opens a scope.
    666  1.3.2.2  bouyer              */
    667  1.3.2.2  bouyer             if (Type == ACPI_TYPE_ANY)
    668  1.3.2.2  bouyer             {
    669  1.3.2.2  bouyer                 Type = ThisNode->Type;
    670  1.3.2.2  bouyer             }
    671  1.3.2.2  bouyer         }
    672  1.3.2.2  bouyer 
    673  1.3.2.2  bouyer         /* Point to next name segment and make this node current */
    674  1.3.2.2  bouyer 
    675  1.3.2.2  bouyer         Path += ACPI_NAME_SIZE;
    676  1.3.2.2  bouyer         CurrentNode = ThisNode;
    677  1.3.2.2  bouyer     }
    678  1.3.2.2  bouyer 
    679  1.3.2.2  bouyer     /* Always check if we need to open a new scope */
    680  1.3.2.2  bouyer 
    681  1.3.2.2  bouyer     if (!(Flags & ACPI_NS_DONT_OPEN_SCOPE) && (WalkState))
    682  1.3.2.2  bouyer     {
    683  1.3.2.2  bouyer         /*
    684  1.3.2.2  bouyer          * If entry is a type which opens a scope, push the new scope on the
    685  1.3.2.2  bouyer          * scope stack.
    686  1.3.2.2  bouyer          */
    687  1.3.2.2  bouyer         if (AcpiNsOpensScope (Type))
    688  1.3.2.2  bouyer         {
    689  1.3.2.2  bouyer             Status = AcpiDsScopeStackPush (ThisNode, Type, WalkState);
    690  1.3.2.2  bouyer             if (ACPI_FAILURE (Status))
    691  1.3.2.2  bouyer             {
    692  1.3.2.2  bouyer                 return_ACPI_STATUS (Status);
    693  1.3.2.2  bouyer             }
    694  1.3.2.2  bouyer         }
    695  1.3.2.2  bouyer     }
    696  1.3.2.2  bouyer 
    697  1.3.2.2  bouyer     *ReturnNode = ThisNode;
    698  1.3.2.2  bouyer     return_ACPI_STATUS (AE_OK);
    699  1.3.2.2  bouyer }
    700  1.3.2.2  bouyer 
    701