1*3446Smrj /******************************************************************************* 2*3446Smrj * 3*3446Smrj * Module Name: nsaccess - Top-level functions for accessing ACPI namespace 4*3446Smrj * $Revision: 1.203 $ 5*3446Smrj * 6*3446Smrj ******************************************************************************/ 7*3446Smrj 8*3446Smrj /****************************************************************************** 9*3446Smrj * 10*3446Smrj * 1. Copyright Notice 11*3446Smrj * 12*3446Smrj * Some or all of this work - Copyright (c) 1999 - 2006, Intel Corp. 13*3446Smrj * All rights reserved. 14*3446Smrj * 15*3446Smrj * 2. License 16*3446Smrj * 17*3446Smrj * 2.1. This is your license from Intel Corp. under its intellectual property 18*3446Smrj * rights. You may have additional license terms from the party that provided 19*3446Smrj * you this software, covering your right to use that party's intellectual 20*3446Smrj * property rights. 21*3446Smrj * 22*3446Smrj * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 23*3446Smrj * copy of the source code appearing in this file ("Covered Code") an 24*3446Smrj * irrevocable, perpetual, worldwide license under Intel's copyrights in the 25*3446Smrj * base code distributed originally by Intel ("Original Intel Code") to copy, 26*3446Smrj * make derivatives, distribute, use and display any portion of the Covered 27*3446Smrj * Code in any form, with the right to sublicense such rights; and 28*3446Smrj * 29*3446Smrj * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 30*3446Smrj * license (with the right to sublicense), under only those claims of Intel 31*3446Smrj * patents that are infringed by the Original Intel Code, to make, use, sell, 32*3446Smrj * offer to sell, and import the Covered Code and derivative works thereof 33*3446Smrj * solely to the minimum extent necessary to exercise the above copyright 34*3446Smrj * license, and in no event shall the patent license extend to any additions 35*3446Smrj * to or modifications of the Original Intel Code. No other license or right 36*3446Smrj * is granted directly or by implication, estoppel or otherwise; 37*3446Smrj * 38*3446Smrj * The above copyright and patent license is granted only if the following 39*3446Smrj * conditions are met: 40*3446Smrj * 41*3446Smrj * 3. Conditions 42*3446Smrj * 43*3446Smrj * 3.1. Redistribution of Source with Rights to Further Distribute Source. 44*3446Smrj * Redistribution of source code of any substantial portion of the Covered 45*3446Smrj * Code or modification with rights to further distribute source must include 46*3446Smrj * the above Copyright Notice, the above License, this list of Conditions, 47*3446Smrj * and the following Disclaimer and Export Compliance provision. In addition, 48*3446Smrj * Licensee must cause all Covered Code to which Licensee contributes to 49*3446Smrj * contain a file documenting the changes Licensee made to create that Covered 50*3446Smrj * Code and the date of any change. Licensee must include in that file the 51*3446Smrj * documentation of any changes made by any predecessor Licensee. Licensee 52*3446Smrj * must include a prominent statement that the modification is derived, 53*3446Smrj * directly or indirectly, from Original Intel Code. 54*3446Smrj * 55*3446Smrj * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 56*3446Smrj * Redistribution of source code of any substantial portion of the Covered 57*3446Smrj * Code or modification without rights to further distribute source must 58*3446Smrj * include the following Disclaimer and Export Compliance provision in the 59*3446Smrj * documentation and/or other materials provided with distribution. In 60*3446Smrj * addition, Licensee may not authorize further sublicense of source of any 61*3446Smrj * portion of the Covered Code, and must include terms to the effect that the 62*3446Smrj * license from Licensee to its licensee is limited to the intellectual 63*3446Smrj * property embodied in the software Licensee provides to its licensee, and 64*3446Smrj * not to intellectual property embodied in modifications its licensee may 65*3446Smrj * make. 66*3446Smrj * 67*3446Smrj * 3.3. Redistribution of Executable. Redistribution in executable form of any 68*3446Smrj * substantial portion of the Covered Code or modification must reproduce the 69*3446Smrj * above Copyright Notice, and the following Disclaimer and Export Compliance 70*3446Smrj * provision in the documentation and/or other materials provided with the 71*3446Smrj * distribution. 72*3446Smrj * 73*3446Smrj * 3.4. Intel retains all right, title, and interest in and to the Original 74*3446Smrj * Intel Code. 75*3446Smrj * 76*3446Smrj * 3.5. Neither the name Intel nor any other trademark owned or controlled by 77*3446Smrj * Intel shall be used in advertising or otherwise to promote the sale, use or 78*3446Smrj * other dealings in products derived from or relating to the Covered Code 79*3446Smrj * without prior written authorization from Intel. 80*3446Smrj * 81*3446Smrj * 4. Disclaimer and Export Compliance 82*3446Smrj * 83*3446Smrj * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 84*3446Smrj * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 85*3446Smrj * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 86*3446Smrj * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 87*3446Smrj * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 88*3446Smrj * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 89*3446Smrj * PARTICULAR PURPOSE. 90*3446Smrj * 91*3446Smrj * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 92*3446Smrj * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 93*3446Smrj * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 94*3446Smrj * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 95*3446Smrj * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 96*3446Smrj * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 97*3446Smrj * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 98*3446Smrj * LIMITED REMEDY. 99*3446Smrj * 100*3446Smrj * 4.3. Licensee shall not export, either directly or indirectly, any of this 101*3446Smrj * software or system incorporating such software without first obtaining any 102*3446Smrj * required license or other approval from the U. S. Department of Commerce or 103*3446Smrj * any other agency or department of the United States Government. In the 104*3446Smrj * event Licensee exports any such software from the United States or 105*3446Smrj * re-exports any such software from a foreign destination, Licensee shall 106*3446Smrj * ensure that the distribution and export/re-export of the software is in 107*3446Smrj * compliance with all laws, regulations, orders, or other restrictions of the 108*3446Smrj * U.S. Export Administration Regulations. Licensee agrees that neither it nor 109*3446Smrj * any of its subsidiaries will export/re-export any technical data, process, 110*3446Smrj * software, or service, directly or indirectly, to any country for which the 111*3446Smrj * United States government or any agency thereof requires an export license, 112*3446Smrj * other governmental approval, or letter of assurance, without first obtaining 113*3446Smrj * such license, approval or letter. 114*3446Smrj * 115*3446Smrj *****************************************************************************/ 116*3446Smrj 117*3446Smrj #define __NSACCESS_C__ 118*3446Smrj 119*3446Smrj #include "acpi.h" 120*3446Smrj #include "amlcode.h" 121*3446Smrj #include "acnamesp.h" 122*3446Smrj #include "acdispat.h" 123*3446Smrj 124*3446Smrj 125*3446Smrj #define _COMPONENT ACPI_NAMESPACE 126*3446Smrj ACPI_MODULE_NAME ("nsaccess") 127*3446Smrj 128*3446Smrj 129*3446Smrj /******************************************************************************* 130*3446Smrj * 131*3446Smrj * FUNCTION: AcpiNsRootInitialize 132*3446Smrj * 133*3446Smrj * PARAMETERS: None 134*3446Smrj * 135*3446Smrj * RETURN: Status 136*3446Smrj * 137*3446Smrj * DESCRIPTION: Allocate and initialize the default root named objects 138*3446Smrj * 139*3446Smrj * MUTEX: Locks namespace for entire execution 140*3446Smrj * 141*3446Smrj ******************************************************************************/ 142*3446Smrj 143*3446Smrj ACPI_STATUS 144*3446Smrj AcpiNsRootInitialize ( 145*3446Smrj void) 146*3446Smrj { 147*3446Smrj ACPI_STATUS Status; 148*3446Smrj const ACPI_PREDEFINED_NAMES *InitVal = NULL; 149*3446Smrj ACPI_NAMESPACE_NODE *NewNode; 150*3446Smrj ACPI_OPERAND_OBJECT *ObjDesc; 151*3446Smrj ACPI_STRING Val = NULL; 152*3446Smrj 153*3446Smrj 154*3446Smrj ACPI_FUNCTION_TRACE (NsRootInitialize); 155*3446Smrj 156*3446Smrj 157*3446Smrj Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 158*3446Smrj if (ACPI_FAILURE (Status)) 159*3446Smrj { 160*3446Smrj return_ACPI_STATUS (Status); 161*3446Smrj } 162*3446Smrj 163*3446Smrj /* 164*3446Smrj * The global root ptr is initially NULL, so a non-NULL value indicates 165*3446Smrj * that AcpiNsRootInitialize() has already been called; just return. 166*3446Smrj */ 167*3446Smrj if (AcpiGbl_RootNode) 168*3446Smrj { 169*3446Smrj Status = AE_OK; 170*3446Smrj goto UnlockAndExit; 171*3446Smrj } 172*3446Smrj 173*3446Smrj /* 174*3446Smrj * Tell the rest of the subsystem that the root is initialized 175*3446Smrj * (This is OK because the namespace is locked) 176*3446Smrj */ 177*3446Smrj AcpiGbl_RootNode = &AcpiGbl_RootNodeStruct; 178*3446Smrj 179*3446Smrj /* Enter the pre-defined names in the name table */ 180*3446Smrj 181*3446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 182*3446Smrj "Entering predefined entries into namespace\n")); 183*3446Smrj 184*3446Smrj for (InitVal = AcpiGbl_PreDefinedNames; InitVal->Name; InitVal++) 185*3446Smrj { 186*3446Smrj /* _OSI is optional for now, will be permanent later */ 187*3446Smrj 188*3446Smrj if (!ACPI_STRCMP (InitVal->Name, "_OSI") && !AcpiGbl_CreateOsiMethod) 189*3446Smrj { 190*3446Smrj continue; 191*3446Smrj } 192*3446Smrj 193*3446Smrj Status = AcpiNsLookup (NULL, InitVal->Name, InitVal->Type, 194*3446Smrj ACPI_IMODE_LOAD_PASS2, ACPI_NS_NO_UPSEARCH, 195*3446Smrj NULL, &NewNode); 196*3446Smrj 197*3446Smrj if (ACPI_FAILURE (Status) || (!NewNode)) /* Must be on same line for code converter */ 198*3446Smrj { 199*3446Smrj ACPI_EXCEPTION ((AE_INFO, Status, 200*3446Smrj "Could not create predefined name %s", 201*3446Smrj InitVal->Name)); 202*3446Smrj } 203*3446Smrj 204*3446Smrj /* 205*3446Smrj * Name entered successfully. 206*3446Smrj * If entry in PreDefinedNames[] specifies an 207*3446Smrj * initial value, create the initial value. 208*3446Smrj */ 209*3446Smrj if (InitVal->Val) 210*3446Smrj { 211*3446Smrj Status = AcpiOsPredefinedOverride (InitVal, &Val); 212*3446Smrj if (ACPI_FAILURE (Status)) 213*3446Smrj { 214*3446Smrj ACPI_ERROR ((AE_INFO, 215*3446Smrj "Could not override predefined %s", 216*3446Smrj InitVal->Name)); 217*3446Smrj } 218*3446Smrj 219*3446Smrj if (!Val) 220*3446Smrj { 221*3446Smrj Val = InitVal->Val; 222*3446Smrj } 223*3446Smrj 224*3446Smrj /* 225*3446Smrj * Entry requests an initial value, allocate a 226*3446Smrj * descriptor for it. 227*3446Smrj */ 228*3446Smrj ObjDesc = AcpiUtCreateInternalObject (InitVal->Type); 229*3446Smrj if (!ObjDesc) 230*3446Smrj { 231*3446Smrj Status = AE_NO_MEMORY; 232*3446Smrj goto UnlockAndExit; 233*3446Smrj } 234*3446Smrj 235*3446Smrj /* 236*3446Smrj * Convert value string from table entry to 237*3446Smrj * internal representation. Only types actually 238*3446Smrj * used for initial values are implemented here. 239*3446Smrj */ 240*3446Smrj switch (InitVal->Type) 241*3446Smrj { 242*3446Smrj case ACPI_TYPE_METHOD: 243*3446Smrj ObjDesc->Method.ParamCount = (UINT8) ACPI_TO_INTEGER (Val); 244*3446Smrj ObjDesc->Common.Flags |= AOPOBJ_DATA_VALID; 245*3446Smrj 246*3446Smrj #if defined (ACPI_ASL_COMPILER) 247*3446Smrj 248*3446Smrj /* Save the parameter count for the iASL compiler */ 249*3446Smrj 250*3446Smrj NewNode->Value = ObjDesc->Method.ParamCount; 251*3446Smrj #else 252*3446Smrj /* Mark this as a very SPECIAL method */ 253*3446Smrj 254*3446Smrj ObjDesc->Method.MethodFlags = AML_METHOD_INTERNAL_ONLY; 255*3446Smrj 256*3446Smrj #ifndef ACPI_DUMP_APP 257*3446Smrj ObjDesc->Method.Implementation = AcpiUtOsiImplementation; 258*3446Smrj #endif 259*3446Smrj #endif 260*3446Smrj break; 261*3446Smrj 262*3446Smrj case ACPI_TYPE_INTEGER: 263*3446Smrj 264*3446Smrj ObjDesc->Integer.Value = ACPI_TO_INTEGER (Val); 265*3446Smrj break; 266*3446Smrj 267*3446Smrj 268*3446Smrj case ACPI_TYPE_STRING: 269*3446Smrj 270*3446Smrj /* 271*3446Smrj * Build an object around the static string 272*3446Smrj */ 273*3446Smrj ObjDesc->String.Length = (UINT32) ACPI_STRLEN (Val); 274*3446Smrj ObjDesc->String.Pointer = Val; 275*3446Smrj ObjDesc->Common.Flags |= AOPOBJ_STATIC_POINTER; 276*3446Smrj break; 277*3446Smrj 278*3446Smrj 279*3446Smrj case ACPI_TYPE_MUTEX: 280*3446Smrj 281*3446Smrj ObjDesc->Mutex.Node = NewNode; 282*3446Smrj ObjDesc->Mutex.SyncLevel = (UINT8) (ACPI_TO_INTEGER (Val) - 1); 283*3446Smrj 284*3446Smrj /* Create a mutex */ 285*3446Smrj 286*3446Smrj Status = AcpiOsCreateMutex (&ObjDesc->Mutex.OsMutex); 287*3446Smrj if (ACPI_FAILURE (Status)) 288*3446Smrj { 289*3446Smrj AcpiUtRemoveReference (ObjDesc); 290*3446Smrj goto UnlockAndExit; 291*3446Smrj } 292*3446Smrj 293*3446Smrj /* Special case for ACPI Global Lock */ 294*3446Smrj 295*3446Smrj if (ACPI_STRCMP (InitVal->Name, "_GL_") == 0) 296*3446Smrj { 297*3446Smrj AcpiGbl_GlobalLockMutex = ObjDesc->Mutex.OsMutex; 298*3446Smrj 299*3446Smrj /* Create additional counting semaphore for global lock */ 300*3446Smrj 301*3446Smrj Status = AcpiOsCreateSemaphore ( 302*3446Smrj 1, 1, &AcpiGbl_GlobalLockSemaphore); 303*3446Smrj if (ACPI_FAILURE (Status)) 304*3446Smrj { 305*3446Smrj AcpiUtRemoveReference (ObjDesc); 306*3446Smrj goto UnlockAndExit; 307*3446Smrj } 308*3446Smrj } 309*3446Smrj break; 310*3446Smrj 311*3446Smrj 312*3446Smrj default: 313*3446Smrj 314*3446Smrj ACPI_ERROR ((AE_INFO, "Unsupported initial type value %X", 315*3446Smrj InitVal->Type)); 316*3446Smrj AcpiUtRemoveReference (ObjDesc); 317*3446Smrj ObjDesc = NULL; 318*3446Smrj continue; 319*3446Smrj } 320*3446Smrj 321*3446Smrj /* Store pointer to value descriptor in the Node */ 322*3446Smrj 323*3446Smrj Status = AcpiNsAttachObject (NewNode, ObjDesc, 324*3446Smrj ACPI_GET_OBJECT_TYPE (ObjDesc)); 325*3446Smrj 326*3446Smrj /* Remove local reference to the object */ 327*3446Smrj 328*3446Smrj AcpiUtRemoveReference (ObjDesc); 329*3446Smrj } 330*3446Smrj } 331*3446Smrj 332*3446Smrj 333*3446Smrj UnlockAndExit: 334*3446Smrj (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 335*3446Smrj 336*3446Smrj /* Save a handle to "_GPE", it is always present */ 337*3446Smrj 338*3446Smrj if (ACPI_SUCCESS (Status)) 339*3446Smrj { 340*3446Smrj Status = AcpiNsGetNode (NULL, "\\_GPE", ACPI_NS_NO_UPSEARCH, 341*3446Smrj &AcpiGbl_FadtGpeDevice); 342*3446Smrj } 343*3446Smrj 344*3446Smrj return_ACPI_STATUS (Status); 345*3446Smrj } 346*3446Smrj 347*3446Smrj 348*3446Smrj /******************************************************************************* 349*3446Smrj * 350*3446Smrj * FUNCTION: AcpiNsLookup 351*3446Smrj * 352*3446Smrj * PARAMETERS: ScopeInfo - Current scope info block 353*3446Smrj * Pathname - Search pathname, in internal format 354*3446Smrj * (as represented in the AML stream) 355*3446Smrj * Type - Type associated with name 356*3446Smrj * InterpreterMode - IMODE_LOAD_PASS2 => add name if not found 357*3446Smrj * Flags - Flags describing the search restrictions 358*3446Smrj * WalkState - Current state of the walk 359*3446Smrj * ReturnNode - Where the Node is placed (if found 360*3446Smrj * or created successfully) 361*3446Smrj * 362*3446Smrj * RETURN: Status 363*3446Smrj * 364*3446Smrj * DESCRIPTION: Find or enter the passed name in the name space. 365*3446Smrj * Log an error if name not found in Exec mode. 366*3446Smrj * 367*3446Smrj * MUTEX: Assumes namespace is locked. 368*3446Smrj * 369*3446Smrj ******************************************************************************/ 370*3446Smrj 371*3446Smrj ACPI_STATUS 372*3446Smrj AcpiNsLookup ( 373*3446Smrj ACPI_GENERIC_STATE *ScopeInfo, 374*3446Smrj char *Pathname, 375*3446Smrj ACPI_OBJECT_TYPE Type, 376*3446Smrj ACPI_INTERPRETER_MODE InterpreterMode, 377*3446Smrj UINT32 Flags, 378*3446Smrj ACPI_WALK_STATE *WalkState, 379*3446Smrj ACPI_NAMESPACE_NODE **ReturnNode) 380*3446Smrj { 381*3446Smrj ACPI_STATUS Status; 382*3446Smrj char *Path = Pathname; 383*3446Smrj ACPI_NAMESPACE_NODE *PrefixNode; 384*3446Smrj ACPI_NAMESPACE_NODE *CurrentNode = NULL; 385*3446Smrj ACPI_NAMESPACE_NODE *ThisNode = NULL; 386*3446Smrj UINT32 NumSegments; 387*3446Smrj UINT32 NumCarats; 388*3446Smrj ACPI_NAME SimpleName; 389*3446Smrj ACPI_OBJECT_TYPE TypeToCheckFor; 390*3446Smrj ACPI_OBJECT_TYPE ThisSearchType; 391*3446Smrj UINT32 SearchParentFlag = ACPI_NS_SEARCH_PARENT; 392*3446Smrj UINT32 LocalFlags; 393*3446Smrj 394*3446Smrj 395*3446Smrj ACPI_FUNCTION_TRACE (NsLookup); 396*3446Smrj 397*3446Smrj 398*3446Smrj if (!ReturnNode) 399*3446Smrj { 400*3446Smrj return_ACPI_STATUS (AE_BAD_PARAMETER); 401*3446Smrj } 402*3446Smrj 403*3446Smrj LocalFlags = Flags & ~(ACPI_NS_ERROR_IF_FOUND | ACPI_NS_SEARCH_PARENT); 404*3446Smrj *ReturnNode = ACPI_ENTRY_NOT_FOUND; 405*3446Smrj AcpiGbl_NsLookupCount++; 406*3446Smrj 407*3446Smrj if (!AcpiGbl_RootNode) 408*3446Smrj { 409*3446Smrj return_ACPI_STATUS (AE_NO_NAMESPACE); 410*3446Smrj } 411*3446Smrj 412*3446Smrj /* 413*3446Smrj * Get the prefix scope. 414*3446Smrj * A null scope means use the root scope 415*3446Smrj */ 416*3446Smrj if ((!ScopeInfo) || 417*3446Smrj (!ScopeInfo->Scope.Node)) 418*3446Smrj { 419*3446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, 420*3446Smrj "Null scope prefix, using root node (%p)\n", 421*3446Smrj AcpiGbl_RootNode)); 422*3446Smrj 423*3446Smrj PrefixNode = AcpiGbl_RootNode; 424*3446Smrj } 425*3446Smrj else 426*3446Smrj { 427*3446Smrj PrefixNode = ScopeInfo->Scope.Node; 428*3446Smrj if (ACPI_GET_DESCRIPTOR_TYPE (PrefixNode) != ACPI_DESC_TYPE_NAMED) 429*3446Smrj { 430*3446Smrj ACPI_ERROR ((AE_INFO, "%p is not a namespace node [%s]", 431*3446Smrj PrefixNode, AcpiUtGetDescriptorName (PrefixNode))); 432*3446Smrj return_ACPI_STATUS (AE_AML_INTERNAL); 433*3446Smrj } 434*3446Smrj 435*3446Smrj if (!(Flags & ACPI_NS_PREFIX_IS_SCOPE)) 436*3446Smrj { 437*3446Smrj /* 438*3446Smrj * This node might not be a actual "scope" node (such as a 439*3446Smrj * Device/Method, etc.) It could be a Package or other object node. 440*3446Smrj * Backup up the tree to find the containing scope node. 441*3446Smrj */ 442*3446Smrj while (!AcpiNsOpensScope (PrefixNode->Type) && 443*3446Smrj PrefixNode->Type != ACPI_TYPE_ANY) 444*3446Smrj { 445*3446Smrj PrefixNode = AcpiNsGetParentNode (PrefixNode); 446*3446Smrj } 447*3446Smrj } 448*3446Smrj } 449*3446Smrj 450*3446Smrj /* Save type TBD: may be no longer necessary */ 451*3446Smrj 452*3446Smrj TypeToCheckFor = Type; 453*3446Smrj 454*3446Smrj /* 455*3446Smrj * Begin examination of the actual pathname 456*3446Smrj */ 457*3446Smrj if (!Pathname) 458*3446Smrj { 459*3446Smrj /* A Null NamePath is allowed and refers to the root */ 460*3446Smrj 461*3446Smrj NumSegments = 0; 462*3446Smrj ThisNode = AcpiGbl_RootNode; 463*3446Smrj Path = ""; 464*3446Smrj 465*3446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, 466*3446Smrj "Null Pathname (Zero segments), Flags=%X\n", Flags)); 467*3446Smrj } 468*3446Smrj else 469*3446Smrj { 470*3446Smrj /* 471*3446Smrj * Name pointer is valid (and must be in internal name format) 472*3446Smrj * 473*3446Smrj * Check for scope prefixes: 474*3446Smrj * 475*3446Smrj * As represented in the AML stream, a namepath consists of an 476*3446Smrj * optional scope prefix followed by a name segment part. 477*3446Smrj * 478*3446Smrj * If present, the scope prefix is either a Root Prefix (in 479*3446Smrj * which case the name is fully qualified), or one or more 480*3446Smrj * Parent Prefixes (in which case the name's scope is relative 481*3446Smrj * to the current scope). 482*3446Smrj */ 483*3446Smrj if (*Path == (UINT8) AML_ROOT_PREFIX) 484*3446Smrj { 485*3446Smrj /* Pathname is fully qualified, start from the root */ 486*3446Smrj 487*3446Smrj ThisNode = AcpiGbl_RootNode; 488*3446Smrj SearchParentFlag = ACPI_NS_NO_UPSEARCH; 489*3446Smrj 490*3446Smrj /* Point to name segment part */ 491*3446Smrj 492*3446Smrj Path++; 493*3446Smrj 494*3446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, 495*3446Smrj "Path is absolute from root [%p]\n", ThisNode)); 496*3446Smrj } 497*3446Smrj else 498*3446Smrj { 499*3446Smrj /* Pathname is relative to current scope, start there */ 500*3446Smrj 501*3446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, 502*3446Smrj "Searching relative to prefix scope [%4.4s] (%p)\n", 503*3446Smrj AcpiUtGetNodeName (PrefixNode), PrefixNode)); 504*3446Smrj 505*3446Smrj /* 506*3446Smrj * Handle multiple Parent Prefixes (carat) by just getting 507*3446Smrj * the parent node for each prefix instance. 508*3446Smrj */ 509*3446Smrj ThisNode = PrefixNode; 510*3446Smrj NumCarats = 0; 511*3446Smrj while (*Path == (UINT8) AML_PARENT_PREFIX) 512*3446Smrj { 513*3446Smrj /* Name is fully qualified, no search rules apply */ 514*3446Smrj 515*3446Smrj SearchParentFlag = ACPI_NS_NO_UPSEARCH; 516*3446Smrj /* 517*3446Smrj * Point past this prefix to the name segment 518*3446Smrj * part or the next Parent Prefix 519*3446Smrj */ 520*3446Smrj Path++; 521*3446Smrj 522*3446Smrj /* Backup to the parent node */ 523*3446Smrj 524*3446Smrj NumCarats++; 525*3446Smrj ThisNode = AcpiNsGetParentNode (ThisNode); 526*3446Smrj if (!ThisNode) 527*3446Smrj { 528*3446Smrj /* Current scope has no parent scope */ 529*3446Smrj 530*3446Smrj ACPI_ERROR ((AE_INFO, 531*3446Smrj "ACPI path has too many parent prefixes (^) - reached beyond root node")); 532*3446Smrj return_ACPI_STATUS (AE_NOT_FOUND); 533*3446Smrj } 534*3446Smrj } 535*3446Smrj 536*3446Smrj if (SearchParentFlag == ACPI_NS_NO_UPSEARCH) 537*3446Smrj { 538*3446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, 539*3446Smrj "Search scope is [%4.4s], path has %d carat(s)\n", 540*3446Smrj AcpiUtGetNodeName (ThisNode), NumCarats)); 541*3446Smrj } 542*3446Smrj } 543*3446Smrj 544*3446Smrj /* 545*3446Smrj * Determine the number of ACPI name segments in this pathname. 546*3446Smrj * 547*3446Smrj * The segment part consists of either: 548*3446Smrj * - A Null name segment (0) 549*3446Smrj * - A DualNamePrefix followed by two 4-byte name segments 550*3446Smrj * - A MultiNamePrefix followed by a byte indicating the 551*3446Smrj * number of segments and the segments themselves. 552*3446Smrj * - A single 4-byte name segment 553*3446Smrj * 554*3446Smrj * Examine the name prefix opcode, if any, to determine the number of 555*3446Smrj * segments. 556*3446Smrj */ 557*3446Smrj switch (*Path) 558*3446Smrj { 559*3446Smrj case 0: 560*3446Smrj /* 561*3446Smrj * Null name after a root or parent prefixes. We already 562*3446Smrj * have the correct target node and there are no name segments. 563*3446Smrj */ 564*3446Smrj NumSegments = 0; 565*3446Smrj Type = ThisNode->Type; 566*3446Smrj 567*3446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, 568*3446Smrj "Prefix-only Pathname (Zero name segments), Flags=%X\n", 569*3446Smrj Flags)); 570*3446Smrj break; 571*3446Smrj 572*3446Smrj case AML_DUAL_NAME_PREFIX: 573*3446Smrj 574*3446Smrj /* More than one NameSeg, search rules do not apply */ 575*3446Smrj 576*3446Smrj SearchParentFlag = ACPI_NS_NO_UPSEARCH; 577*3446Smrj 578*3446Smrj /* Two segments, point to first name segment */ 579*3446Smrj 580*3446Smrj NumSegments = 2; 581*3446Smrj Path++; 582*3446Smrj 583*3446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, 584*3446Smrj "Dual Pathname (2 segments, Flags=%X)\n", Flags)); 585*3446Smrj break; 586*3446Smrj 587*3446Smrj case AML_MULTI_NAME_PREFIX_OP: 588*3446Smrj 589*3446Smrj /* More than one NameSeg, search rules do not apply */ 590*3446Smrj 591*3446Smrj SearchParentFlag = ACPI_NS_NO_UPSEARCH; 592*3446Smrj 593*3446Smrj /* Extract segment count, point to first name segment */ 594*3446Smrj 595*3446Smrj Path++; 596*3446Smrj NumSegments = (UINT32) (UINT8) *Path; 597*3446Smrj Path++; 598*3446Smrj 599*3446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, 600*3446Smrj "Multi Pathname (%d Segments, Flags=%X)\n", 601*3446Smrj NumSegments, Flags)); 602*3446Smrj break; 603*3446Smrj 604*3446Smrj default: 605*3446Smrj /* 606*3446Smrj * Not a Null name, no Dual or Multi prefix, hence there is 607*3446Smrj * only one name segment and Pathname is already pointing to it. 608*3446Smrj */ 609*3446Smrj NumSegments = 1; 610*3446Smrj 611*3446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, 612*3446Smrj "Simple Pathname (1 segment, Flags=%X)\n", Flags)); 613*3446Smrj break; 614*3446Smrj } 615*3446Smrj 616*3446Smrj ACPI_DEBUG_EXEC (AcpiNsPrintPathname (NumSegments, Path)); 617*3446Smrj } 618*3446Smrj 619*3446Smrj 620*3446Smrj /* 621*3446Smrj * Search namespace for each segment of the name. Loop through and 622*3446Smrj * verify (or add to the namespace) each name segment. 623*3446Smrj * 624*3446Smrj * The object type is significant only at the last name 625*3446Smrj * segment. (We don't care about the types along the path, only 626*3446Smrj * the type of the final target object.) 627*3446Smrj */ 628*3446Smrj ThisSearchType = ACPI_TYPE_ANY; 629*3446Smrj CurrentNode = ThisNode; 630*3446Smrj while (NumSegments && CurrentNode) 631*3446Smrj { 632*3446Smrj NumSegments--; 633*3446Smrj if (!NumSegments) 634*3446Smrj { 635*3446Smrj /* 636*3446Smrj * This is the last segment, enable typechecking 637*3446Smrj */ 638*3446Smrj ThisSearchType = Type; 639*3446Smrj 640*3446Smrj /* 641*3446Smrj * Only allow automatic parent search (search rules) if the caller 642*3446Smrj * requested it AND we have a single, non-fully-qualified NameSeg 643*3446Smrj */ 644*3446Smrj if ((SearchParentFlag != ACPI_NS_NO_UPSEARCH) && 645*3446Smrj (Flags & ACPI_NS_SEARCH_PARENT)) 646*3446Smrj { 647*3446Smrj LocalFlags |= ACPI_NS_SEARCH_PARENT; 648*3446Smrj } 649*3446Smrj 650*3446Smrj /* Set error flag according to caller */ 651*3446Smrj 652*3446Smrj if (Flags & ACPI_NS_ERROR_IF_FOUND) 653*3446Smrj { 654*3446Smrj LocalFlags |= ACPI_NS_ERROR_IF_FOUND; 655*3446Smrj } 656*3446Smrj } 657*3446Smrj 658*3446Smrj /* Extract one ACPI name from the front of the pathname */ 659*3446Smrj 660*3446Smrj ACPI_MOVE_32_TO_32 (&SimpleName, Path); 661*3446Smrj 662*3446Smrj /* Try to find the single (4 character) ACPI name */ 663*3446Smrj 664*3446Smrj Status = AcpiNsSearchAndEnter (SimpleName, WalkState, CurrentNode, 665*3446Smrj InterpreterMode, ThisSearchType, LocalFlags, &ThisNode); 666*3446Smrj if (ACPI_FAILURE (Status)) 667*3446Smrj { 668*3446Smrj if (Status == AE_NOT_FOUND) 669*3446Smrj { 670*3446Smrj /* Name not found in ACPI namespace */ 671*3446Smrj 672*3446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, 673*3446Smrj "Name [%4.4s] not found in scope [%4.4s] %p\n", 674*3446Smrj (char *) &SimpleName, (char *) &CurrentNode->Name, 675*3446Smrj CurrentNode)); 676*3446Smrj } 677*3446Smrj 678*3446Smrj *ReturnNode = ThisNode; 679*3446Smrj return_ACPI_STATUS (Status); 680*3446Smrj } 681*3446Smrj 682*3446Smrj /* 683*3446Smrj * Sanity typecheck of the target object: 684*3446Smrj * 685*3446Smrj * If 1) This is the last segment (NumSegments == 0) 686*3446Smrj * 2) And we are looking for a specific type 687*3446Smrj * (Not checking for TYPE_ANY) 688*3446Smrj * 3) Which is not an alias 689*3446Smrj * 4) Which is not a local type (TYPE_SCOPE) 690*3446Smrj * 5) And the type of target object is known (not TYPE_ANY) 691*3446Smrj * 6) And target object does not match what we are looking for 692*3446Smrj * 693*3446Smrj * Then we have a type mismatch. Just warn and ignore it. 694*3446Smrj */ 695*3446Smrj if ((NumSegments == 0) && 696*3446Smrj (TypeToCheckFor != ACPI_TYPE_ANY) && 697*3446Smrj (TypeToCheckFor != ACPI_TYPE_LOCAL_ALIAS) && 698*3446Smrj (TypeToCheckFor != ACPI_TYPE_LOCAL_METHOD_ALIAS) && 699*3446Smrj (TypeToCheckFor != ACPI_TYPE_LOCAL_SCOPE) && 700*3446Smrj (ThisNode->Type != ACPI_TYPE_ANY) && 701*3446Smrj (ThisNode->Type != TypeToCheckFor)) 702*3446Smrj { 703*3446Smrj /* Complain about a type mismatch */ 704*3446Smrj 705*3446Smrj ACPI_WARNING ((AE_INFO, 706*3446Smrj "NsLookup: Type mismatch on %4.4s (%s), searching for (%s)", 707*3446Smrj ACPI_CAST_PTR (char, &SimpleName), 708*3446Smrj AcpiUtGetTypeName (ThisNode->Type), 709*3446Smrj AcpiUtGetTypeName (TypeToCheckFor))); 710*3446Smrj } 711*3446Smrj 712*3446Smrj /* 713*3446Smrj * If this is the last name segment and we are not looking for a 714*3446Smrj * specific type, but the type of found object is known, use that type 715*3446Smrj * to see if it opens a scope. 716*3446Smrj */ 717*3446Smrj if ((NumSegments == 0) && (Type == ACPI_TYPE_ANY)) 718*3446Smrj { 719*3446Smrj Type = ThisNode->Type; 720*3446Smrj } 721*3446Smrj 722*3446Smrj /* Point to next name segment and make this node current */ 723*3446Smrj 724*3446Smrj Path += ACPI_NAME_SIZE; 725*3446Smrj CurrentNode = ThisNode; 726*3446Smrj } 727*3446Smrj 728*3446Smrj /* 729*3446Smrj * Always check if we need to open a new scope 730*3446Smrj */ 731*3446Smrj if (!(Flags & ACPI_NS_DONT_OPEN_SCOPE) && (WalkState)) 732*3446Smrj { 733*3446Smrj /* 734*3446Smrj * If entry is a type which opens a scope, push the new scope on the 735*3446Smrj * scope stack. 736*3446Smrj */ 737*3446Smrj if (AcpiNsOpensScope (Type)) 738*3446Smrj { 739*3446Smrj Status = AcpiDsScopeStackPush (ThisNode, Type, WalkState); 740*3446Smrj if (ACPI_FAILURE (Status)) 741*3446Smrj { 742*3446Smrj return_ACPI_STATUS (Status); 743*3446Smrj } 744*3446Smrj } 745*3446Smrj } 746*3446Smrj 747*3446Smrj *ReturnNode = ThisNode; 748*3446Smrj return_ACPI_STATUS (AE_OK); 749*3446Smrj } 750*3446Smrj 751