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