nssearch.c revision 102550
1204431Sraj/******************************************************************************* 2204431Sraj * 3204431Sraj * Module Name: nssearch - Namespace search 4204431Sraj * $Revision: 89 $ 5204431Sraj * 6204431Sraj ******************************************************************************/ 7204431Sraj 8204431Sraj/****************************************************************************** 9204431Sraj * 10204431Sraj * 1. Copyright Notice 11204431Sraj * 12204431Sraj * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp. 13204431Sraj * All rights reserved. 14204431Sraj * 15204431Sraj * 2. License 16204431Sraj * 17204431Sraj * 2.1. This is your license from Intel Corp. under its intellectual property 18204431Sraj * rights. You may have additional license terms from the party that provided 19204431Sraj * you this software, covering your right to use that party's intellectual 20204431Sraj * property rights. 21204431Sraj * 22204431Sraj * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 23204431Sraj * copy of the source code appearing in this file ("Covered Code") an 24204431Sraj * irrevocable, perpetual, worldwide license under Intel's copyrights in the 25204431Sraj * base code distributed originally by Intel ("Original Intel Code") to copy, 26204431Sraj * make derivatives, distribute, use and display any portion of the Covered 27204431Sraj * Code in any form, with the right to sublicense such rights; and 28204431Sraj * 29204431Sraj * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 30204431Sraj * license (with the right to sublicense), under only those claims of Intel 31204431Sraj * patents that are infringed by the Original Intel Code, to make, use, sell, 32204431Sraj * offer to sell, and import the Covered Code and derivative works thereof 33204431Sraj * solely to the minimum extent necessary to exercise the above copyright 34204431Sraj * license, and in no event shall the patent license extend to any additions 35204431Sraj * to or modifications of the Original Intel Code. No other license or right 36204431Sraj * is granted directly or by implication, estoppel or otherwise; 37204431Sraj * 38204431Sraj * The above copyright and patent license is granted only if the following 39204431Sraj * conditions are met: 40204431Sraj * 41204431Sraj * 3. Conditions 42204431Sraj * 43204431Sraj * 3.1. Redistribution of Source with Rights to Further Distribute Source. 44204431Sraj * Redistribution of source code of any substantial portion of the Covered 45204431Sraj * Code or modification with rights to further distribute source must include 46204431Sraj * the above Copyright Notice, the above License, this list of Conditions, 47204431Sraj * and the following Disclaimer and Export Compliance provision. In addition, 48204431Sraj * Licensee must cause all Covered Code to which Licensee contributes to 49204431Sraj * contain a file documenting the changes Licensee made to create that Covered 50204431Sraj * Code and the date of any change. Licensee must include in that file the 51204431Sraj * documentation of any changes made by any predecessor Licensee. Licensee 52204431Sraj * must include a prominent statement that the modification is derived, 53204431Sraj * directly or indirectly, from Original Intel Code. 54238742Simp * 55204431Sraj * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 56266130Sian * Redistribution of source code of any substantial portion of the Covered 57204431Sraj * Code or modification without rights to further distribute source must 58204431Sraj * include the following Disclaimer and Export Compliance provision in the 59204431Sraj * documentation and/or other materials provided with distribution. In 60204431Sraj * addition, Licensee may not authorize further sublicense of source of any 61238742Simp * portion of the Covered Code, and must include terms to the effect that the 62204431Sraj * license from Licensee to its licensee is limited to the intellectual 63204431Sraj * property embodied in the software Licensee provides to its licensee, and 64204431Sraj * not to intellectual property embodied in modifications its licensee may 65204431Sraj * make. 66204431Sraj * 67204431Sraj * 3.3. Redistribution of Executable. Redistribution in executable form of any 68204431Sraj * substantial portion of the Covered Code or modification must reproduce the 69238742Simp * above Copyright Notice, and the following Disclaimer and Export Compliance 70238742Simp * provision in the documentation and/or other materials provided with the 71204431Sraj * distribution. 72204431Sraj * 73204431Sraj * 3.4. Intel retains all right, title, and interest in and to the Original 74204431Sraj * Intel Code. 75238742Simp * 76238742Simp * 3.5. Neither the name Intel nor any other trademark owned or controlled by 77238742Simp * Intel shall be used in advertising or otherwise to promote the sale, use or 78238742Simp * other dealings in products derived from or relating to the Covered Code 79238742Simp * without prior written authorization from Intel. 80238742Simp * 81204431Sraj * 4. Disclaimer and Export Compliance 82238742Simp * 83238742Simp * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 84238742Simp * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 85238742Simp * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 86238742Simp * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 87238742Simp * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 88238742Simp * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 89238742Simp * PARTICULAR PURPOSE. 90238742Simp * 91238742Simp * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 92238742Simp * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 93238742Simp * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 94238742Simp * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 95238742Simp * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 96238742Simp * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 97238742Simp * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 98238742Simp * LIMITED REMEDY. 99238742Simp * 100204431Sraj * 4.3. Licensee shall not export, either directly or indirectly, any of this 101204431Sraj * software or system incorporating such software without first obtaining any 102204431Sraj * required license or other approval from the U. S. Department of Commerce or 103204431Sraj * any other agency or department of the United States Government. In the 104204431Sraj * event Licensee exports any such software from the United States or 105204431Sraj * re-exports any such software from a foreign destination, Licensee shall 106204431Sraj * ensure that the distribution and export/re-export of the software is in 107204431Sraj * compliance with all laws, regulations, orders, or other restrictions of the 108204431Sraj * U.S. Export Administration Regulations. Licensee agrees that neither it nor 109238742Simp * any of its subsidiaries will export/re-export any technical data, process, 110238742Simp * software, or service, directly or indirectly, to any country for which the 111238742Simp * United States government or any agency thereof requires an export license, 112238742Simp * other governmental approval, or letter of assurance, without first obtaining 113238742Simp * such license, approval or letter. 114238742Simp * 115238742Simp *****************************************************************************/ 116204431Sraj 117204431Sraj#define __NSSEARCH_C__ 118204431Sraj 119204431Sraj#include "acpi.h" 120204431Sraj#include "acnamesp.h" 121204431Sraj 122204431Sraj 123204431Sraj#define _COMPONENT ACPI_NAMESPACE 124204431Sraj ACPI_MODULE_NAME ("nssearch") 125204431Sraj 126204431Sraj 127204431Sraj/******************************************************************************* 128204431Sraj * 129204431Sraj * FUNCTION: AcpiNsSearchNode 130204431Sraj * 131204431Sraj * PARAMETERS: *TargetName - Ascii ACPI name to search for 132204431Sraj * *Node - Starting table where search will begin 133204431Sraj * Type - Object type to match 134204431Sraj * **ReturnNode - Where the matched Named obj is returned 135204431Sraj * 136204431Sraj * RETURN: Status 137204431Sraj * 138204431Sraj * DESCRIPTION: Search a single namespace table. Performs a simple search, 139204431Sraj * does not add entries or search parents. 140204431Sraj * 141204431Sraj * 142204431Sraj * Named object lists are built (and subsequently dumped) in the 143204431Sraj * order in which the names are encountered during the namespace load; 144266130Sian * 145204431Sraj * All namespace searching is linear in this implementation, but 146266130Sian * could be easily modified to support any improved search 147204431Sraj * algorithm. However, the linear search was chosen for simplicity 148204431Sraj * and because the trees are small and the other interpreter 149204431Sraj * execution overhead is relatively high. 150204431Sraj * 151204431Sraj ******************************************************************************/ 152204431Sraj 153204431SrajACPI_STATUS 154266130SianAcpiNsSearchNode ( 155204431Sraj UINT32 TargetName, 156204431Sraj ACPI_NAMESPACE_NODE *Node, 157204431Sraj ACPI_OBJECT_TYPE Type, 158266130Sian ACPI_NAMESPACE_NODE **ReturnNode) 159204431Sraj{ 160204431Sraj ACPI_NAMESPACE_NODE *NextNode; 161204431Sraj 162204431Sraj 163204431Sraj ACPI_FUNCTION_TRACE ("NsSearchNode"); 164204431Sraj 165204431Sraj 166204431Sraj#ifdef ACPI_DEBUG_OUTPUT 167204431Sraj if (ACPI_LV_NAMES & AcpiDbgLevel) 168204431Sraj { 169204431Sraj NATIVE_CHAR *ScopeName; 170204431Sraj 171204431Sraj ScopeName = AcpiNsGetExternalPathname (Node); 172204431Sraj if (ScopeName) 173204431Sraj { 174204431Sraj ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Searching %s [%p] For %4.4s (type %s)\n", 175204431Sraj ScopeName, Node, (char *) &TargetName, AcpiUtGetTypeName (Type))); 176204431Sraj 177204431Sraj ACPI_MEM_FREE (ScopeName); 178204431Sraj } 179204431Sraj } 180266130Sian#endif 181238742Simp 182266130Sian /* 183204431Sraj * Search for name in this table, which is to say that we must search 184204431Sraj * for the name among the children of this object 185204431Sraj */ 186204431Sraj NextNode = Node->Child; 187204431Sraj while (NextNode) 188204431Sraj { 189204431Sraj /* Check for match against the name */ 190238742Simp 191238742Simp if (NextNode->Name.Integer == TargetName) 192238742Simp { 193238742Simp /* 194238742Simp * Found matching entry. Capture the type if appropriate, before 195238742Simp * returning the entry. 196238742Simp * 197204431Sraj * The DefFieldDefn and BankFieldDefn cases are actually looking up 198204431Sraj * the Region in which the field will be defined 199204431Sraj */ 200204431Sraj if ((INTERNAL_TYPE_FIELD_DEFN == Type) || 201204431Sraj (INTERNAL_TYPE_BANK_FIELD_DEFN == Type)) 202204431Sraj { 203204431Sraj Type = ACPI_TYPE_REGION; 204204431Sraj } 205204431Sraj 206204431Sraj /* 207204431Sraj * Scope, DefAny, and IndexFieldDefn are bogus "types" which do not 208204431Sraj * actually have anything to do with the type of the name being 209204431Sraj * looked up. For any other value of Type, if the type stored in 210204431Sraj * the entry is Any (i.e. unknown), save the actual type. 211238742Simp */ 212238742Simp if (Type != INTERNAL_TYPE_SCOPE && 213238742Simp Type != INTERNAL_TYPE_DEF_ANY && 214238742Simp Type != INTERNAL_TYPE_INDEX_FIELD_DEFN && 215204431Sraj NextNode->Type == ACPI_TYPE_ANY) 216204431Sraj { 217204431Sraj NextNode->Type = (UINT8) Type; 218204431Sraj } 219204431Sraj 220204431Sraj ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, 221204431Sraj "Name %4.4s Type [%s] found at %p\n", 222204431Sraj (char *) &TargetName, AcpiUtGetTypeName (NextNode->Type), NextNode)); 223204431Sraj 224204431Sraj *ReturnNode = NextNode; 225204431Sraj return_ACPI_STATUS (AE_OK); 226204431Sraj } 227204431Sraj 228204431Sraj /* 229204431Sraj * The last entry in the list points back to the parent, 230238742Simp * so a flag is used to indicate the end-of-list 231238742Simp */ 232238742Simp if (NextNode->Flags & ANOBJ_END_OF_PEER_LIST) 233238742Simp { 234204431Sraj /* Searched entire list, we are done */ 235204431Sraj 236204431Sraj break; 237204431Sraj } 238204431Sraj 239204431Sraj /* Didn't match name, move on to the next peer object */ 240204431Sraj 241204431Sraj NextNode = NextNode->Peer; 242204431Sraj } 243204431Sraj 244204431Sraj /* Searched entire table, not found */ 245204431Sraj 246204431Sraj ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Name %4.4s Type [%s] not found at %p\n", 247204431Sraj (char *) &TargetName, AcpiUtGetTypeName (Type), NextNode)); 248204431Sraj 249204431Sraj return_ACPI_STATUS (AE_NOT_FOUND); 250204431Sraj} 251204431Sraj 252238742Simp 253204431Sraj/******************************************************************************* 254204431Sraj * 255204431Sraj * FUNCTION: AcpiNsSearchParentTree 256204431Sraj * 257204431Sraj * PARAMETERS: *TargetName - Ascii ACPI name to search for 258204431Sraj * *Node - Starting table where search will begin 259266130Sian * Type - Object type to match 260266130Sian * **ReturnNode - Where the matched Named Obj is returned 261266130Sian * 262266130Sian * RETURN: Status 263204431Sraj * 264204431Sraj * DESCRIPTION: Called when a name has not been found in the current namespace 265204431Sraj * table. Before adding it or giving up, ACPI scope rules require 266266130Sian * searching enclosing scopes in cases identified by AcpiNsLocal(). 267266130Sian * 268204431Sraj * "A name is located by finding the matching name in the current 269238742Simp * name space, and then in the parent name space. If the parent 270204431Sraj * name space does not contain the name, the search continues 271204431Sraj * recursively until either the name is found or the name space 272204431Sraj * does not have a parent (the root of the name space). This 273204431Sraj * indicates that the name is not found" (From ACPI Specification, 274204431Sraj * section 5.3) 275204431Sraj * 276204431Sraj ******************************************************************************/ 277204431Sraj 278204431Srajstatic ACPI_STATUS 279204431SrajAcpiNsSearchParentTree ( 280204431Sraj UINT32 TargetName, 281204431Sraj ACPI_NAMESPACE_NODE *Node, 282204431Sraj ACPI_OBJECT_TYPE Type, 283204431Sraj ACPI_NAMESPACE_NODE **ReturnNode) 284204431Sraj{ 285238742Simp ACPI_STATUS Status; 286204431Sraj ACPI_NAMESPACE_NODE *ParentNode; 287204431Sraj 288204431Sraj 289204431Sraj ACPI_FUNCTION_TRACE ("NsSearchParentTree"); 290204431Sraj 291204431Sraj 292204431Sraj ParentNode = AcpiNsGetParentNode (Node); 293204431Sraj 294238742Simp /* 295204431Sraj * If there is no parent (at the root) or type is "local", we won't be 296204431Sraj * searching the parent tree. 297204431Sraj */ 298204431Sraj if ((AcpiNsLocal (Type)) || 299204431Sraj (!ParentNode)) 300204431Sraj { 301204431Sraj if (!ParentNode) 302204431Sraj { 303204431Sraj ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "[%4.4s] has no parent\n", 304204431Sraj (char *) &TargetName)); 305238742Simp } 306204431Sraj 307238742Simp if (AcpiNsLocal (Type)) 308238742Simp { 309238742Simp ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, 310238742Simp "[%4.4s] type [%s] must be local to this scope (no parent search)\n", 311238742Simp (char *) &TargetName, AcpiUtGetTypeName (Type))); 312238742Simp } 313238742Simp 314238742Simp return_ACPI_STATUS (AE_NOT_FOUND); 315238742Simp } 316238742Simp 317238742Simp /* Search the parent tree */ 318238742Simp 319238742Simp ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Searching parent for %4.4s\n", (char *) &TargetName)); 320238742Simp 321238742Simp /* 322238742Simp * Search parents until found the target or we have backed up to 323238742Simp * the root 324238742Simp */ 325238742Simp while (ParentNode) 326238742Simp { 327238742Simp /* 328238742Simp * Search parent scope. Use TYPE_ANY because we don't care about the 329238742Simp * object type at this point, we only care about the existence of 330238742Simp * the actual name we are searching for. Typechecking comes later. 331238742Simp */ 332238742Simp Status = AcpiNsSearchNode (TargetName, ParentNode, 333238742Simp ACPI_TYPE_ANY, ReturnNode); 334238742Simp if (ACPI_SUCCESS (Status)) 335238742Simp { 336238742Simp return_ACPI_STATUS (Status); 337238742Simp } 338238742Simp 339238742Simp /* 340238742Simp * Not found here, go up another level 341238742Simp * (until we reach the root) 342238742Simp */ 343238742Simp ParentNode = AcpiNsGetParentNode (ParentNode); 344238742Simp } 345238742Simp 346238742Simp /* Not found in parent tree */ 347238742Simp 348238742Simp return_ACPI_STATUS (AE_NOT_FOUND); 349238742Simp} 350238742Simp 351238742Simp 352238742Simp/******************************************************************************* 353238742Simp * 354238742Simp * FUNCTION: AcpiNsSearchAndEnter 355238742Simp * 356238742Simp * PARAMETERS: TargetName - Ascii ACPI name to search for (4 chars) 357238742Simp * WalkState - Current state of the walk 358238742Simp * *Node - Starting table where search will begin 359238742Simp * InterpreterMode - Add names only in MODE_LoadPassX. 360238742Simp * Otherwise,search only. 361238742Simp * Type - Object type to match 362238742Simp * Flags - Flags describing the search restrictions 363204431Sraj * **ReturnNode - Where the Node is returned 364204433Sraj * 365204431Sraj * RETURN: Status 366204433Sraj * 367204431Sraj * DESCRIPTION: Search for a name segment in a single name table, 368204431Sraj * optionally adding it if it is not found. If the passed 369204431Sraj * Type is not Any and the type previously stored in the 370204433Sraj * entry was Any (i.e. unknown), update the stored type. 371204433Sraj * 372204433Sraj * In IMODE_EXECUTE, search only. 373204431Sraj * In other modes, search and add if not found. 374204431Sraj * 375204433Sraj ******************************************************************************/ 376204433Sraj 377204431SrajACPI_STATUS 378204431SrajAcpiNsSearchAndEnter ( 379204431Sraj UINT32 TargetName, 380204433Sraj ACPI_WALK_STATE *WalkState, 381204433Sraj ACPI_NAMESPACE_NODE *Node, 382204433Sraj ACPI_INTERPRETER_MODE InterpreterMode, 383204433Sraj ACPI_OBJECT_TYPE Type, 384204433Sraj UINT32 Flags, 385204433Sraj ACPI_NAMESPACE_NODE **ReturnNode) 386204433Sraj{ 387204433Sraj ACPI_STATUS Status; 388204433Sraj ACPI_NAMESPACE_NODE *NewNode; 389204433Sraj 390204433Sraj 391204433Sraj ACPI_FUNCTION_TRACE ("NsSearchAndEnter"); 392204433Sraj 393204433Sraj 394204433Sraj /* Parameter validation */ 395204433Sraj 396204433Sraj if (!Node || !TargetName || !ReturnNode) 397204433Sraj { 398204433Sraj ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null param: Node %p Name %X ReturnNode %p\n", 399204431Sraj Node, TargetName, ReturnNode)); 400204433Sraj 401204431Sraj ACPI_REPORT_ERROR (("NsSearchAndEnter: Null parameter\n")); 402204433Sraj return_ACPI_STATUS (AE_BAD_PARAMETER); 403204433Sraj } 404204431Sraj 405204431Sraj /* Name must consist of printable characters */ 406204431Sraj 407204433Sraj if (!AcpiUtValidAcpiName (TargetName)) 408204433Sraj { 409204433Sraj ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "*** Bad character in name: %08x *** \n", 410204433Sraj TargetName)); 411204431Sraj 412204433Sraj ACPI_REPORT_ERROR (("NsSearchAndEnter: Bad character in ACPI Name\n")); 413204431Sraj return_ACPI_STATUS (AE_BAD_CHARACTER); 414204431Sraj } 415204431Sraj 416204431Sraj /* Try to find the name in the table specified by the caller */ 417204431Sraj 418204431Sraj *ReturnNode = ACPI_ENTRY_NOT_FOUND; 419204431Sraj Status = AcpiNsSearchNode (TargetName, Node, Type, ReturnNode); 420238742Simp if (Status != AE_NOT_FOUND) 421204431Sraj { 422204431Sraj /* 423204431Sraj * If we found it AND the request specifies that a find is an error, 424204431Sraj * return the error 425204431Sraj */ 426204431Sraj if ((Status == AE_OK) && 427204431Sraj (Flags & ACPI_NS_ERROR_IF_FOUND)) 428204431Sraj { 429204431Sraj Status = AE_ALREADY_EXISTS; 430204431Sraj } 431204431Sraj 432204431Sraj /* 433204431Sraj * Either found it or there was an error 434204431Sraj * -- finished either way 435204431Sraj */ 436204431Sraj return_ACPI_STATUS (Status); 437204431Sraj } 438204431Sraj 439204431Sraj /* 440204431Sraj * The name was not found. If we are NOT performing the 441204431Sraj * first pass (name entry) of loading the namespace, search 442204431Sraj * the parent tree (all the way to the root if necessary.) 443204431Sraj * We don't want to perform the parent search when the 444204431Sraj * namespace is actually being loaded. We want to perform 445204431Sraj * the search when namespace references are being resolved 446204431Sraj * (load pass 2) and during the execution phase. 447204431Sraj */ 448204431Sraj if ((InterpreterMode != ACPI_IMODE_LOAD_PASS1) && 449238742Simp (Flags & ACPI_NS_SEARCH_PARENT)) 450238742Simp { 451204431Sraj /* 452204431Sraj * Not found in table - search parent tree according 453204431Sraj * to ACPI specification 454204431Sraj */ 455204431Sraj Status = AcpiNsSearchParentTree (TargetName, Node, 456204431Sraj Type, ReturnNode); 457204431Sraj if (ACPI_SUCCESS (Status)) 458204431Sraj { 459204431Sraj return_ACPI_STATUS (Status); 460204431Sraj } 461204431Sraj } 462204431Sraj 463204431Sraj /* 464204431Sraj * In execute mode, just search, never add names. Exit now. 465204431Sraj */ 466204431Sraj if (InterpreterMode == ACPI_IMODE_EXECUTE) 467204431Sraj { 468204431Sraj ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%4.4s Not found in %p [Not adding]\n", 469204431Sraj (char *) &TargetName, Node)); 470204431Sraj 471204431Sraj return_ACPI_STATUS (AE_NOT_FOUND); 472204431Sraj } 473204431Sraj 474204431Sraj /* Create the new named object */ 475204431Sraj 476204431Sraj NewNode = AcpiNsCreateNode (TargetName); 477238742Simp if (!NewNode) 478204431Sraj { 479204431Sraj return_ACPI_STATUS (AE_NO_MEMORY); 480204431Sraj } 481204431Sraj 482204431Sraj /* Install the new object into the parent's list of children */ 483204431Sraj 484204431Sraj AcpiNsInstallNode (WalkState, Node, NewNode, Type); 485204431Sraj *ReturnNode = NewNode; 486204431Sraj 487204431Sraj return_ACPI_STATUS (AE_OK); 488204431Sraj} 489204431Sraj 490204431Sraj