Path: blob/main/sys/contrib/dev/acpica/components/namespace/nsaccess.c
48524 views
/*******************************************************************************1*2* Module Name: nsaccess - Top-level functions for accessing ACPI namespace3*4******************************************************************************/56/******************************************************************************7*8* 1. Copyright Notice9*10* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.11* All rights reserved.12*13* 2. License14*15* 2.1. This is your license from Intel Corp. under its intellectual property16* rights. You may have additional license terms from the party that provided17* you this software, covering your right to use that party's intellectual18* property rights.19*20* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a21* copy of the source code appearing in this file ("Covered Code") an22* irrevocable, perpetual, worldwide license under Intel's copyrights in the23* base code distributed originally by Intel ("Original Intel Code") to copy,24* make derivatives, distribute, use and display any portion of the Covered25* Code in any form, with the right to sublicense such rights; and26*27* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent28* license (with the right to sublicense), under only those claims of Intel29* patents that are infringed by the Original Intel Code, to make, use, sell,30* offer to sell, and import the Covered Code and derivative works thereof31* solely to the minimum extent necessary to exercise the above copyright32* license, and in no event shall the patent license extend to any additions33* to or modifications of the Original Intel Code. No other license or right34* is granted directly or by implication, estoppel or otherwise;35*36* The above copyright and patent license is granted only if the following37* conditions are met:38*39* 3. Conditions40*41* 3.1. Redistribution of Source with Rights to Further Distribute Source.42* Redistribution of source code of any substantial portion of the Covered43* Code or modification with rights to further distribute source must include44* the above Copyright Notice, the above License, this list of Conditions,45* and the following Disclaimer and Export Compliance provision. In addition,46* Licensee must cause all Covered Code to which Licensee contributes to47* contain a file documenting the changes Licensee made to create that Covered48* Code and the date of any change. Licensee must include in that file the49* documentation of any changes made by any predecessor Licensee. Licensee50* must include a prominent statement that the modification is derived,51* directly or indirectly, from Original Intel Code.52*53* 3.2. Redistribution of Source with no Rights to Further Distribute Source.54* Redistribution of source code of any substantial portion of the Covered55* Code or modification without rights to further distribute source must56* include the following Disclaimer and Export Compliance provision in the57* documentation and/or other materials provided with distribution. In58* addition, Licensee may not authorize further sublicense of source of any59* portion of the Covered Code, and must include terms to the effect that the60* license from Licensee to its licensee is limited to the intellectual61* property embodied in the software Licensee provides to its licensee, and62* not to intellectual property embodied in modifications its licensee may63* make.64*65* 3.3. Redistribution of Executable. Redistribution in executable form of any66* substantial portion of the Covered Code or modification must reproduce the67* above Copyright Notice, and the following Disclaimer and Export Compliance68* provision in the documentation and/or other materials provided with the69* distribution.70*71* 3.4. Intel retains all right, title, and interest in and to the Original72* Intel Code.73*74* 3.5. Neither the name Intel nor any other trademark owned or controlled by75* Intel shall be used in advertising or otherwise to promote the sale, use or76* other dealings in products derived from or relating to the Covered Code77* without prior written authorization from Intel.78*79* 4. Disclaimer and Export Compliance80*81* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED82* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE83* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,84* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY85* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY86* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A87* PARTICULAR PURPOSE.88*89* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES90* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR91* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,92* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY93* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL94* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS95* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY96* LIMITED REMEDY.97*98* 4.3. Licensee shall not export, either directly or indirectly, any of this99* software or system incorporating such software without first obtaining any100* required license or other approval from the U. S. Department of Commerce or101* any other agency or department of the United States Government. In the102* event Licensee exports any such software from the United States or103* re-exports any such software from a foreign destination, Licensee shall104* ensure that the distribution and export/re-export of the software is in105* compliance with all laws, regulations, orders, or other restrictions of the106* U.S. Export Administration Regulations. Licensee agrees that neither it nor107* any of its subsidiaries will export/re-export any technical data, process,108* software, or service, directly or indirectly, to any country for which the109* United States government or any agency thereof requires an export license,110* other governmental approval, or letter of assurance, without first obtaining111* such license, approval or letter.112*113*****************************************************************************114*115* Alternatively, you may choose to be licensed under the terms of the116* following license:117*118* Redistribution and use in source and binary forms, with or without119* modification, are permitted provided that the following conditions120* are met:121* 1. Redistributions of source code must retain the above copyright122* notice, this list of conditions, and the following disclaimer,123* without modification.124* 2. Redistributions in binary form must reproduce at minimum a disclaimer125* substantially similar to the "NO WARRANTY" disclaimer below126* ("Disclaimer") and any redistribution must be conditioned upon127* including a substantially similar Disclaimer requirement for further128* binary redistribution.129* 3. Neither the names of the above-listed copyright holders nor the names130* of any contributors may be used to endorse or promote products derived131* from this software without specific prior written permission.132*133* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS134* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT135* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR136* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT137* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,138* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT139* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,140* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY141* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT142* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE143* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.144*145* Alternatively, you may choose to be licensed under the terms of the146* GNU General Public License ("GPL") version 2 as published by the Free147* Software Foundation.148*149*****************************************************************************/150151#include <contrib/dev/acpica/include/acpi.h>152#include <contrib/dev/acpica/include/accommon.h>153#include <contrib/dev/acpica/include/amlcode.h>154#include <contrib/dev/acpica/include/acnamesp.h>155#include <contrib/dev/acpica/include/acdispat.h>156157#ifdef ACPI_ASL_COMPILER158#include <contrib/dev/acpica/include/acdisasm.h>159#endif160161#define _COMPONENT ACPI_NAMESPACE162ACPI_MODULE_NAME ("nsaccess")163164165/*******************************************************************************166*167* FUNCTION: AcpiNsRootInitialize168*169* PARAMETERS: None170*171* RETURN: Status172*173* DESCRIPTION: Allocate and initialize the default root named objects174*175* MUTEX: Locks namespace for entire execution176*177******************************************************************************/178179ACPI_STATUS180AcpiNsRootInitialize (181void)182{183ACPI_STATUS Status;184const ACPI_PREDEFINED_NAMES *InitVal = NULL;185ACPI_NAMESPACE_NODE *NewNode;186ACPI_NAMESPACE_NODE *PrevNode = NULL;187ACPI_OPERAND_OBJECT *ObjDesc;188ACPI_STRING Val = NULL;189190191ACPI_FUNCTION_TRACE (NsRootInitialize);192193194Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);195if (ACPI_FAILURE (Status))196{197return_ACPI_STATUS (Status);198}199200/*201* The global root ptr is initially NULL, so a non-NULL value indicates202* that AcpiNsRootInitialize() has already been called; just return.203*/204if (AcpiGbl_RootNode)205{206Status = AE_OK;207goto UnlockAndExit;208}209210/*211* Tell the rest of the subsystem that the root is initialized212* (This is OK because the namespace is locked)213*/214AcpiGbl_RootNode = &AcpiGbl_RootNodeStruct;215216/* Enter the predefined names in the name table */217218ACPI_DEBUG_PRINT ((ACPI_DB_INFO,219"Entering predefined entries into namespace\n"));220221/*222* Create the initial (default) namespace.223* This namespace looks like something similar to this:224*225* ACPI Namespace (from Namespace Root):226* 0 _GPE Scope 00203160 00227* 0 _PR_ Scope 002031D0 00228* 0 _SB_ Device 00203240 00 Notify Object: 0020ADD8229* 0 _SI_ Scope 002032B0 00230* 0 _TZ_ Device 00203320 00231* 0 _REV Integer 00203390 00 = 0000000000000002232* 0 _OS_ String 00203488 00 Len 14 "Microsoft Windows NT"233* 0 _GL_ Mutex 00203580 00 Object 002035F0234* 0 _OSI Method 00203678 00 Args 1 Len 0000 Aml 00000000235*/236for (InitVal = AcpiGbl_PreDefinedNames; InitVal->Name; InitVal++)237{238Status = AE_OK;239240/* _OSI is optional for now, will be permanent later */241242if (!strcmp (InitVal->Name, "_OSI") && !AcpiGbl_CreateOsiMethod)243{244continue;245}246247/*248* Create, init, and link the new predefined name249* Note: No need to use AcpiNsLookup here because all the250* predefined names are at the root level. It is much easier to251* just create and link the new node(s) here.252*/253NewNode = AcpiNsCreateNode (*ACPI_CAST_PTR (UINT32, InitVal->Name));254if (!NewNode)255{256Status = AE_NO_MEMORY;257goto UnlockAndExit;258}259260NewNode->DescriptorType = ACPI_DESC_TYPE_NAMED;261NewNode->Type = InitVal->Type;262263if (!PrevNode)264{265AcpiGbl_RootNodeStruct.Child = NewNode;266}267else268{269PrevNode->Peer = NewNode;270}271272NewNode->Parent = &AcpiGbl_RootNodeStruct;273PrevNode = NewNode;274275/*276* Name entered successfully. If entry in PreDefinedNames[] specifies277* an initial value, create the initial value.278*/279if (InitVal->Val)280{281Status = AcpiOsPredefinedOverride (InitVal, &Val);282if (ACPI_FAILURE (Status))283{284ACPI_ERROR ((AE_INFO,285"Could not override predefined %s",286InitVal->Name));287}288289if (!Val)290{291Val = InitVal->Val;292}293294/*295* Entry requests an initial value, allocate a296* descriptor for it.297*/298ObjDesc = AcpiUtCreateInternalObject (InitVal->Type);299if (!ObjDesc)300{301Status = AE_NO_MEMORY;302goto UnlockAndExit;303}304305/*306* Convert value string from table entry to307* internal representation. Only types actually308* used for initial values are implemented here.309*/310switch (InitVal->Type)311{312case ACPI_TYPE_METHOD:313314ObjDesc->Method.ParamCount = (UINT8) ACPI_TO_INTEGER (Val);315ObjDesc->Common.Flags |= AOPOBJ_DATA_VALID;316317#if defined (ACPI_ASL_COMPILER)318319/* Save the parameter count for the iASL compiler */320321NewNode->Value = ObjDesc->Method.ParamCount;322#else323/* Mark this as a very SPECIAL method (_OSI) */324325ObjDesc->Method.InfoFlags = ACPI_METHOD_INTERNAL_ONLY;326ObjDesc->Method.Dispatch.Implementation = AcpiUtOsiImplementation;327#endif328break;329330case ACPI_TYPE_INTEGER:331332ObjDesc->Integer.Value = ACPI_TO_INTEGER (Val);333break;334335case ACPI_TYPE_STRING:336337/* Build an object around the static string */338339ObjDesc->String.Length = (UINT32) strlen (Val);340ObjDesc->String.Pointer = Val;341ObjDesc->Common.Flags |= AOPOBJ_STATIC_POINTER;342break;343344case ACPI_TYPE_MUTEX:345346ObjDesc->Mutex.Node = NewNode;347ObjDesc->Mutex.SyncLevel = (UINT8) (ACPI_TO_INTEGER (Val) - 1);348349/* Create a mutex */350351Status = AcpiOsCreateMutex (&ObjDesc->Mutex.OsMutex);352if (ACPI_FAILURE (Status))353{354AcpiUtRemoveReference (ObjDesc);355goto UnlockAndExit;356}357358/* Special case for ACPI Global Lock */359360if (strcmp (InitVal->Name, "_GL_") == 0)361{362AcpiGbl_GlobalLockMutex = ObjDesc;363364/* Create additional counting semaphore for global lock */365366Status = AcpiOsCreateSemaphore (3671, 0, &AcpiGbl_GlobalLockSemaphore);368if (ACPI_FAILURE (Status))369{370AcpiUtRemoveReference (ObjDesc);371goto UnlockAndExit;372}373}374break;375376default:377378ACPI_ERROR ((AE_INFO, "Unsupported initial type value 0x%X",379InitVal->Type));380AcpiUtRemoveReference (ObjDesc);381ObjDesc = NULL;382continue;383}384385/* Store pointer to value descriptor in the Node */386387Status = AcpiNsAttachObject (NewNode, ObjDesc,388ObjDesc->Common.Type);389390/* Remove local reference to the object */391392AcpiUtRemoveReference (ObjDesc);393}394}395396UnlockAndExit:397(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);398399/* Save a handle to "_GPE", it is always present */400401if (ACPI_SUCCESS (Status))402{403Status = AcpiNsGetNode (NULL, "\\_GPE", ACPI_NS_NO_UPSEARCH,404&AcpiGbl_FadtGpeDevice);405}406407return_ACPI_STATUS (Status);408}409410411/*******************************************************************************412*413* FUNCTION: AcpiNsLookup414*415* PARAMETERS: ScopeInfo - Current scope info block416* Pathname - Search pathname, in internal format417* (as represented in the AML stream)418* Type - Type associated with name419* InterpreterMode - IMODE_LOAD_PASS2 => add name if not found420* Flags - Flags describing the search restrictions421* WalkState - Current state of the walk422* ReturnNode - Where the Node is placed (if found423* or created successfully)424*425* RETURN: Status426*427* DESCRIPTION: Find or enter the passed name in the name space.428* Log an error if name not found in Exec mode.429*430* MUTEX: Assumes namespace is locked.431*432******************************************************************************/433434ACPI_STATUS435AcpiNsLookup (436ACPI_GENERIC_STATE *ScopeInfo,437char *Pathname,438ACPI_OBJECT_TYPE Type,439ACPI_INTERPRETER_MODE InterpreterMode,440UINT32 Flags,441ACPI_WALK_STATE *WalkState,442ACPI_NAMESPACE_NODE **ReturnNode)443{444ACPI_STATUS Status;445char *Path = Pathname;446char *ExternalPath;447ACPI_NAMESPACE_NODE *PrefixNode;448ACPI_NAMESPACE_NODE *CurrentNode = NULL;449ACPI_NAMESPACE_NODE *ThisNode = NULL;450UINT32 NumSegments;451#ifdef ACPI_DEBUG_OUTPUT452UINT32 NumCarats;453#endif454ACPI_NAME SimpleName;455ACPI_OBJECT_TYPE TypeToCheckFor;456ACPI_OBJECT_TYPE ThisSearchType;457UINT32 SearchParentFlag = ACPI_NS_SEARCH_PARENT;458UINT32 LocalFlags;459ACPI_INTERPRETER_MODE LocalInterpreterMode;460461462ACPI_FUNCTION_TRACE (NsLookup);463464465if (!ReturnNode)466{467return_ACPI_STATUS (AE_BAD_PARAMETER);468}469470LocalFlags = Flags &471~(ACPI_NS_ERROR_IF_FOUND | ACPI_NS_OVERRIDE_IF_FOUND |472ACPI_NS_SEARCH_PARENT);473*ReturnNode = ACPI_ENTRY_NOT_FOUND;474AcpiGbl_NsLookupCount++;475476if (!AcpiGbl_RootNode)477{478return_ACPI_STATUS (AE_NO_NAMESPACE);479}480481/* Get the prefix scope. A null scope means use the root scope */482483if ((!ScopeInfo) ||484(!ScopeInfo->Scope.Node))485{486ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,487"Null scope prefix, using root node (%p)\n",488AcpiGbl_RootNode));489490PrefixNode = AcpiGbl_RootNode;491}492else493{494PrefixNode = ScopeInfo->Scope.Node;495if (ACPI_GET_DESCRIPTOR_TYPE (PrefixNode) != ACPI_DESC_TYPE_NAMED)496{497ACPI_ERROR ((AE_INFO, "%p is not a namespace node [%s]",498PrefixNode, AcpiUtGetDescriptorName (PrefixNode)));499return_ACPI_STATUS (AE_AML_INTERNAL);500}501502if (!(Flags & ACPI_NS_PREFIX_IS_SCOPE))503{504/*505* This node might not be a actual "scope" node (such as a506* Device/Method, etc.) It could be a Package or other object507* node. Backup up the tree to find the containing scope node.508*/509while (!AcpiNsOpensScope (PrefixNode->Type) &&510PrefixNode->Type != ACPI_TYPE_ANY)511{512PrefixNode = PrefixNode->Parent;513}514}515}516517/* Save type. TBD: may be no longer necessary */518519TypeToCheckFor = Type;520521/*522* Begin examination of the actual pathname523*/524if (!Pathname)525{526/* A Null NamePath is allowed and refers to the root */527528NumSegments = 0;529ThisNode = AcpiGbl_RootNode;530Path = "";531532ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,533"Null Pathname (Zero segments), Flags=%X\n", Flags));534}535else536{537/*538* Name pointer is valid (and must be in internal name format)539*540* Check for scope prefixes:541*542* As represented in the AML stream, a namepath consists of an543* optional scope prefix followed by a name segment part.544*545* If present, the scope prefix is either a Root Prefix (in546* which case the name is fully qualified), or one or more547* Parent Prefixes (in which case the name's scope is relative548* to the current scope).549*/550if (*Path == (UINT8) AML_ROOT_PREFIX)551{552/* Pathname is fully qualified, start from the root */553554ThisNode = AcpiGbl_RootNode;555SearchParentFlag = ACPI_NS_NO_UPSEARCH;556557/* Point to name segment part */558559Path++;560561ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,562"Path is absolute from root [%p]\n", ThisNode));563}564else565{566/* Pathname is relative to current scope, start there */567568ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,569"Searching relative to prefix scope [%4.4s] (%p)\n",570AcpiUtGetNodeName (PrefixNode), PrefixNode));571572/*573* Handle multiple Parent Prefixes (carat) by just getting574* the parent node for each prefix instance.575*/576ThisNode = PrefixNode;577#ifdef ACPI_DEBUG_OUTPUT578NumCarats = 0;579#endif580while (*Path == (UINT8) AML_PARENT_PREFIX)581{582/* Name is fully qualified, no search rules apply */583584SearchParentFlag = ACPI_NS_NO_UPSEARCH;585586/*587* Point past this prefix to the name segment588* part or the next Parent Prefix589*/590Path++;591592/* Backup to the parent node */593594#ifdef ACPI_DEBUG_OUTPUT595NumCarats++;596#endif597ThisNode = ThisNode->Parent;598if (!ThisNode)599{600/*601* Current scope has no parent scope. Externalize602* the internal path for error message.603*/604Status = AcpiNsExternalizeName (ACPI_UINT32_MAX, Pathname,605NULL, &ExternalPath);606if (ACPI_SUCCESS (Status))607{608ACPI_ERROR ((AE_INFO,609"%s: Path has too many parent prefixes (^)",610ExternalPath));611612ACPI_FREE (ExternalPath);613}614615return_ACPI_STATUS (AE_NOT_FOUND);616}617}618619#ifdef ACPI_DEBUG_OUTPUT620if (SearchParentFlag == ACPI_NS_NO_UPSEARCH)621{622ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,623"Search scope is [%4.4s], path has %u carat(s)\n",624AcpiUtGetNodeName (ThisNode), NumCarats));625}626#endif627}628629/*630* Determine the number of ACPI name segments in this pathname.631*632* The segment part consists of either:633* - A Null name segment (0)634* - A DualNamePrefix followed by two 4-byte name segments635* - A MultiNamePrefix followed by a byte indicating the636* number of segments and the segments themselves.637* - A single 4-byte name segment638*639* Examine the name prefix opcode, if any, to determine the number of640* segments.641*/642switch (*Path)643{644case 0:645/*646* Null name after a root or parent prefixes. We already647* have the correct target node and there are no name segments.648*/649NumSegments = 0;650Type = ThisNode->Type;651652ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,653"Prefix-only Pathname (Zero name segments), Flags=%X\n",654Flags));655break;656657case AML_DUAL_NAME_PREFIX:658659/* More than one NameSeg, search rules do not apply */660661SearchParentFlag = ACPI_NS_NO_UPSEARCH;662663/* Two segments, point to first name segment */664665NumSegments = 2;666Path++;667668ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,669"Dual Pathname (2 segments, Flags=%X)\n", Flags));670break;671672case AML_MULTI_NAME_PREFIX:673674/* More than one NameSeg, search rules do not apply */675676SearchParentFlag = ACPI_NS_NO_UPSEARCH;677678/* Extract segment count, point to first name segment */679680Path++;681NumSegments = (UINT32) (UINT8) *Path;682Path++;683684ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,685"Multi Pathname (%u Segments, Flags=%X)\n",686NumSegments, Flags));687break;688689default:690/*691* Not a Null name, no Dual or Multi prefix, hence there is692* only one name segment and Pathname is already pointing to it.693*/694NumSegments = 1;695696ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,697"Simple Pathname (1 segment, Flags=%X)\n", Flags));698break;699}700701ACPI_DEBUG_EXEC (AcpiNsPrintPathname (NumSegments, Path));702}703704705/*706* Search namespace for each segment of the name. Loop through and707* verify (or add to the namespace) each name segment.708*709* The object type is significant only at the last name710* segment. (We don't care about the types along the path, only711* the type of the final target object.)712*/713ThisSearchType = ACPI_TYPE_ANY;714CurrentNode = ThisNode;715716while (NumSegments && CurrentNode)717{718NumSegments--;719if (!NumSegments)720{721/* This is the last segment, enable typechecking */722723ThisSearchType = Type;724725/*726* Only allow automatic parent search (search rules) if the caller727* requested it AND we have a single, non-fully-qualified NameSeg728*/729if ((SearchParentFlag != ACPI_NS_NO_UPSEARCH) &&730(Flags & ACPI_NS_SEARCH_PARENT))731{732LocalFlags |= ACPI_NS_SEARCH_PARENT;733}734735/* Set error flag according to caller */736737if (Flags & ACPI_NS_ERROR_IF_FOUND)738{739LocalFlags |= ACPI_NS_ERROR_IF_FOUND;740}741742/* Set override flag according to caller */743744if (Flags & ACPI_NS_OVERRIDE_IF_FOUND)745{746LocalFlags |= ACPI_NS_OVERRIDE_IF_FOUND;747}748}749750/* Handle opcodes that create a new NameSeg via a full NamePath */751752LocalInterpreterMode = InterpreterMode;753if ((Flags & ACPI_NS_PREFIX_MUST_EXIST) && (NumSegments > 0))754{755/* Every element of the path must exist (except for the final NameSeg) */756757LocalInterpreterMode = ACPI_IMODE_EXECUTE;758}759760/* Extract one ACPI name from the front of the pathname */761762ACPI_MOVE_32_TO_32 (&SimpleName, Path);763764/* Try to find the single (4 character) ACPI name */765766Status = AcpiNsSearchAndEnter (SimpleName, WalkState, CurrentNode,767LocalInterpreterMode, ThisSearchType, LocalFlags, &ThisNode);768if (ACPI_FAILURE (Status))769{770if (Status == AE_NOT_FOUND)771{772#if !defined ACPI_ASL_COMPILER /* Note: iASL reports this error by itself, not needed here */773if (Flags & ACPI_NS_PREFIX_MUST_EXIST)774{775AcpiOsPrintf (ACPI_MSG_BIOS_ERROR776"Object does not exist: %4.4s\n", (char *) &SimpleName);777}778#endif779/* Name not found in ACPI namespace */780781ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,782"Name [%4.4s] not found in scope [%4.4s] %p\n",783(char *) &SimpleName, (char *) &CurrentNode->Name,784CurrentNode));785}786787#ifdef ACPI_EXEC_APP788if ((Status == AE_ALREADY_EXISTS) &&789(ThisNode->Flags & ANOBJ_NODE_EARLY_INIT))790{791ThisNode->Flags &= ~ANOBJ_NODE_EARLY_INIT;792Status = AE_OK;793}794#endif795796#ifdef ACPI_ASL_COMPILER797/*798* If this ACPI name already exists within the namespace as an799* external declaration, then mark the external as a conflicting800* declaration and proceed to process the current node as if it did801* not exist in the namespace. If this node is not processed as802* normal, then it could cause improper namespace resolution803* by failing to open a new scope.804*/805if (AcpiGbl_DisasmFlag &&806(Status == AE_ALREADY_EXISTS) &&807((ThisNode->Flags & ANOBJ_IS_EXTERNAL) ||808(WalkState && WalkState->Opcode == AML_EXTERNAL_OP)))809{810ThisNode->Flags &= ~ANOBJ_IS_EXTERNAL;811ThisNode->Type = (UINT8)ThisSearchType;812if (WalkState->Opcode != AML_EXTERNAL_OP)813{814AcpiDmMarkExternalConflict (ThisNode);815}816break;817}818#endif819820*ReturnNode = ThisNode;821return_ACPI_STATUS (Status);822}823824/* More segments to follow? */825826if (NumSegments > 0)827{828/*829* If we have an alias to an object that opens a scope (such as a830* device or processor), we need to dereference the alias here so831* that we can access any children of the original node (via the832* remaining segments).833*/834if (ThisNode->Type == ACPI_TYPE_LOCAL_ALIAS)835{836if (!ThisNode->Object)837{838return_ACPI_STATUS (AE_NOT_EXIST);839}840841if (AcpiNsOpensScope (((ACPI_NAMESPACE_NODE *)842ThisNode->Object)->Type))843{844ThisNode = (ACPI_NAMESPACE_NODE *) ThisNode->Object;845}846}847}848849/* Special handling for the last segment (NumSegments == 0) */850851else852{853/*854* Sanity typecheck of the target object:855*856* If 1) This is the last segment (NumSegments == 0)857* 2) And we are looking for a specific type858* (Not checking for TYPE_ANY)859* 3) Which is not an alias860* 4) Which is not a local type (TYPE_SCOPE)861* 5) And the type of target object is known (not TYPE_ANY)862* 6) And target object does not match what we are looking for863*864* Then we have a type mismatch. Just warn and ignore it.865*/866if ((TypeToCheckFor != ACPI_TYPE_ANY) &&867(TypeToCheckFor != ACPI_TYPE_LOCAL_ALIAS) &&868(TypeToCheckFor != ACPI_TYPE_LOCAL_METHOD_ALIAS) &&869(TypeToCheckFor != ACPI_TYPE_LOCAL_SCOPE) &&870(ThisNode->Type != ACPI_TYPE_ANY) &&871(ThisNode->Type != TypeToCheckFor))872{873/* Complain about a type mismatch */874875ACPI_WARNING ((AE_INFO,876"NsLookup: Type mismatch on %4.4s (%s), searching for (%s)",877ACPI_CAST_PTR (char, &SimpleName),878AcpiUtGetTypeName (ThisNode->Type),879AcpiUtGetTypeName (TypeToCheckFor)));880}881882/*883* If this is the last name segment and we are not looking for a884* specific type, but the type of found object is known, use that885* type to (later) see if it opens a scope.886*/887if (Type == ACPI_TYPE_ANY)888{889Type = ThisNode->Type;890}891}892893/* Point to next name segment and make this node current */894895Path += ACPI_NAMESEG_SIZE;896CurrentNode = ThisNode;897}898899/* Always check if we need to open a new scope */900901if (!(Flags & ACPI_NS_DONT_OPEN_SCOPE) && (WalkState))902{903/*904* If entry is a type which opens a scope, push the new scope on the905* scope stack.906*/907if (AcpiNsOpensScope (Type))908{909Status = AcpiDsScopeStackPush (ThisNode, Type, WalkState);910if (ACPI_FAILURE (Status))911{912return_ACPI_STATUS (Status);913}914}915}916917#ifdef ACPI_EXEC_APP918if (Flags & ACPI_NS_EARLY_INIT)919{920ThisNode->Flags |= ANOBJ_NODE_EARLY_INIT;921}922#endif923924*ReturnNode = ThisNode;925return_ACPI_STATUS (AE_OK);926}927928929