xref: /haiku/src/add-ons/kernel/bus_managers/acpi/acpica/components/namespace/nsaccess.c (revision fe2557b6eb55be3c2d36e1ee396e0f10e41bd214)
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 - 2016, 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 #include "acpi.h"
117 #include "accommon.h"
118 #include "amlcode.h"
119 #include "acnamesp.h"
120 #include "acdispat.h"
121 
122 
123 #define _COMPONENT          ACPI_NAMESPACE
124         ACPI_MODULE_NAME    ("nsaccess")
125 
126 
127 /*******************************************************************************
128  *
129  * FUNCTION:    AcpiNsRootInitialize
130  *
131  * PARAMETERS:  None
132  *
133  * RETURN:      Status
134  *
135  * DESCRIPTION: Allocate and initialize the default root named objects
136  *
137  * MUTEX:       Locks namespace for entire execution
138  *
139  ******************************************************************************/
140 
141 ACPI_STATUS
142 AcpiNsRootInitialize (
143     void)
144 {
145     ACPI_STATUS                 Status;
146     const ACPI_PREDEFINED_NAMES *InitVal = NULL;
147     ACPI_NAMESPACE_NODE         *NewNode;
148     ACPI_OPERAND_OBJECT         *ObjDesc;
149     ACPI_STRING                 Val = NULL;
150 
151 
152     ACPI_FUNCTION_TRACE (NsRootInitialize);
153 
154 
155     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
156     if (ACPI_FAILURE (Status))
157     {
158         return_ACPI_STATUS (Status);
159     }
160 
161     /*
162      * The global root ptr is initially NULL, so a non-NULL value indicates
163      * that AcpiNsRootInitialize() has already been called; just return.
164      */
165     if (AcpiGbl_RootNode)
166     {
167         Status = AE_OK;
168         goto UnlockAndExit;
169     }
170 
171     /*
172      * Tell the rest of the subsystem that the root is initialized
173      * (This is OK because the namespace is locked)
174      */
175     AcpiGbl_RootNode = &AcpiGbl_RootNodeStruct;
176 
177     /* Enter the pre-defined names in the name table */
178 
179     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
180         "Entering predefined entries into namespace\n"));
181 
182     for (InitVal = AcpiGbl_PreDefinedNames; InitVal->Name; InitVal++)
183     {
184         /* _OSI is optional for now, will be permanent later */
185 
186         if (!strcmp (InitVal->Name, "_OSI") && !AcpiGbl_CreateOsiMethod)
187         {
188             continue;
189         }
190 
191         Status = AcpiNsLookup (NULL, ACPI_CAST_PTR (char, InitVal->Name),
192             InitVal->Type, ACPI_IMODE_LOAD_PASS2, ACPI_NS_NO_UPSEARCH,
193             NULL, &NewNode);
194         if (ACPI_FAILURE (Status))
195         {
196             ACPI_EXCEPTION ((AE_INFO, Status,
197                 "Could not create predefined name %s",
198                 InitVal->Name));
199             continue;
200         }
201 
202         /*
203          * Name entered successfully. If entry in PreDefinedNames[] specifies
204          * an initial value, create the initial value.
205          */
206         if (InitVal->Val)
207         {
208             Status = AcpiOsPredefinedOverride (InitVal, &Val);
209             if (ACPI_FAILURE (Status))
210             {
211                 ACPI_ERROR ((AE_INFO,
212                     "Could not override predefined %s",
213                     InitVal->Name));
214             }
215 
216             if (!Val)
217             {
218                 Val = InitVal->Val;
219             }
220 
221             /*
222              * Entry requests an initial value, allocate a
223              * descriptor for it.
224              */
225             ObjDesc = AcpiUtCreateInternalObject (InitVal->Type);
226             if (!ObjDesc)
227             {
228                 Status = AE_NO_MEMORY;
229                 goto UnlockAndExit;
230             }
231 
232             /*
233              * Convert value string from table entry to
234              * internal representation. Only types actually
235              * used for initial values are implemented here.
236              */
237             switch (InitVal->Type)
238             {
239             case ACPI_TYPE_METHOD:
240 
241                 ObjDesc->Method.ParamCount = (UINT8) ACPI_TO_INTEGER (Val);
242                 ObjDesc->Common.Flags |= AOPOBJ_DATA_VALID;
243 
244 #if defined (ACPI_ASL_COMPILER)
245 
246                 /* Save the parameter count for the iASL compiler */
247 
248                 NewNode->Value = ObjDesc->Method.ParamCount;
249 #else
250                 /* Mark this as a very SPECIAL method */
251 
252                 ObjDesc->Method.InfoFlags = ACPI_METHOD_INTERNAL_ONLY;
253                 ObjDesc->Method.Dispatch.Implementation = AcpiUtOsiImplementation;
254 #endif
255                 break;
256 
257             case ACPI_TYPE_INTEGER:
258 
259                 ObjDesc->Integer.Value = ACPI_TO_INTEGER (Val);
260                 break;
261 
262             case ACPI_TYPE_STRING:
263 
264                 /* Build an object around the static string */
265 
266                 ObjDesc->String.Length = (UINT32) strlen (Val);
267                 ObjDesc->String.Pointer = Val;
268                 ObjDesc->Common.Flags |= AOPOBJ_STATIC_POINTER;
269                 break;
270 
271             case ACPI_TYPE_MUTEX:
272 
273                 ObjDesc->Mutex.Node = NewNode;
274                 ObjDesc->Mutex.SyncLevel = (UINT8) (ACPI_TO_INTEGER (Val) - 1);
275 
276                 /* Create a mutex */
277 
278                 Status = AcpiOsCreateMutex (&ObjDesc->Mutex.OsMutex);
279                 if (ACPI_FAILURE (Status))
280                 {
281                     AcpiUtRemoveReference (ObjDesc);
282                     goto UnlockAndExit;
283                 }
284 
285                 /* Special case for ACPI Global Lock */
286 
287                 if (strcmp (InitVal->Name, "_GL_") == 0)
288                 {
289                     AcpiGbl_GlobalLockMutex = ObjDesc;
290 
291                     /* Create additional counting semaphore for global lock */
292 
293                     Status = AcpiOsCreateSemaphore (
294                         1, 0, &AcpiGbl_GlobalLockSemaphore);
295                     if (ACPI_FAILURE (Status))
296                     {
297                         AcpiUtRemoveReference (ObjDesc);
298                         goto UnlockAndExit;
299                     }
300                 }
301                 break;
302 
303             default:
304 
305                 ACPI_ERROR ((AE_INFO, "Unsupported initial type value 0x%X",
306                     InitVal->Type));
307                 AcpiUtRemoveReference (ObjDesc);
308                 ObjDesc = NULL;
309                 continue;
310             }
311 
312             /* Store pointer to value descriptor in the Node */
313 
314             Status = AcpiNsAttachObject (NewNode, ObjDesc,
315                 ObjDesc->Common.Type);
316 
317             /* Remove local reference to the object */
318 
319             AcpiUtRemoveReference (ObjDesc);
320         }
321     }
322 
323 
324 UnlockAndExit:
325     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
326 
327     /* Save a handle to "_GPE", it is always present */
328 
329     if (ACPI_SUCCESS (Status))
330     {
331         Status = AcpiNsGetNode (NULL, "\\_GPE", ACPI_NS_NO_UPSEARCH,
332             &AcpiGbl_FadtGpeDevice);
333     }
334 
335     return_ACPI_STATUS (Status);
336 }
337 
338 
339 /*******************************************************************************
340  *
341  * FUNCTION:    AcpiNsLookup
342  *
343  * PARAMETERS:  ScopeInfo       - Current scope info block
344  *              Pathname        - Search pathname, in internal format
345  *                                (as represented in the AML stream)
346  *              Type            - Type associated with name
347  *              InterpreterMode - IMODE_LOAD_PASS2 => add name if not found
348  *              Flags           - Flags describing the search restrictions
349  *              WalkState       - Current state of the walk
350  *              ReturnNode      - Where the Node is placed (if found
351  *                                or created successfully)
352  *
353  * RETURN:      Status
354  *
355  * DESCRIPTION: Find or enter the passed name in the name space.
356  *              Log an error if name not found in Exec mode.
357  *
358  * MUTEX:       Assumes namespace is locked.
359  *
360  ******************************************************************************/
361 
362 ACPI_STATUS
363 AcpiNsLookup (
364     ACPI_GENERIC_STATE      *ScopeInfo,
365     char                    *Pathname,
366     ACPI_OBJECT_TYPE        Type,
367     ACPI_INTERPRETER_MODE   InterpreterMode,
368     UINT32                  Flags,
369     ACPI_WALK_STATE         *WalkState,
370     ACPI_NAMESPACE_NODE     **ReturnNode)
371 {
372     ACPI_STATUS             Status;
373     char                    *Path = Pathname;
374     ACPI_NAMESPACE_NODE     *PrefixNode;
375     ACPI_NAMESPACE_NODE     *CurrentNode = NULL;
376     ACPI_NAMESPACE_NODE     *ThisNode = NULL;
377     UINT32                  NumSegments;
378     UINT32                  NumCarats;
379     ACPI_NAME               SimpleName;
380     ACPI_OBJECT_TYPE        TypeToCheckFor;
381     ACPI_OBJECT_TYPE        ThisSearchType;
382     UINT32                  SearchParentFlag = ACPI_NS_SEARCH_PARENT;
383     UINT32                  LocalFlags;
384 
385 
386     ACPI_FUNCTION_TRACE (NsLookup);
387 
388 
389     if (!ReturnNode)
390     {
391         return_ACPI_STATUS (AE_BAD_PARAMETER);
392     }
393 
394     LocalFlags = Flags &
395         ~(ACPI_NS_ERROR_IF_FOUND | ACPI_NS_OVERRIDE_IF_FOUND |
396           ACPI_NS_SEARCH_PARENT);
397     *ReturnNode = ACPI_ENTRY_NOT_FOUND;
398     AcpiGbl_NsLookupCount++;
399 
400     if (!AcpiGbl_RootNode)
401     {
402         return_ACPI_STATUS (AE_NO_NAMESPACE);
403     }
404 
405     /* Get the prefix scope. A null scope means use the root scope */
406 
407     if ((!ScopeInfo) ||
408         (!ScopeInfo->Scope.Node))
409     {
410         ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
411             "Null scope prefix, using root node (%p)\n",
412             AcpiGbl_RootNode));
413 
414         PrefixNode = AcpiGbl_RootNode;
415     }
416     else
417     {
418         PrefixNode = ScopeInfo->Scope.Node;
419         if (ACPI_GET_DESCRIPTOR_TYPE (PrefixNode) != ACPI_DESC_TYPE_NAMED)
420         {
421             ACPI_ERROR ((AE_INFO, "%p is not a namespace node [%s]",
422                 PrefixNode, AcpiUtGetDescriptorName (PrefixNode)));
423             return_ACPI_STATUS (AE_AML_INTERNAL);
424         }
425 
426         if (!(Flags & ACPI_NS_PREFIX_IS_SCOPE))
427         {
428             /*
429              * This node might not be a actual "scope" node (such as a
430              * Device/Method, etc.)  It could be a Package or other object
431              * node. Backup up the tree to find the containing scope node.
432              */
433             while (!AcpiNsOpensScope (PrefixNode->Type) &&
434                     PrefixNode->Type != ACPI_TYPE_ANY)
435             {
436                 PrefixNode = PrefixNode->Parent;
437             }
438         }
439     }
440 
441     /* Save type. TBD: may be no longer necessary */
442 
443     TypeToCheckFor = Type;
444 
445     /*
446      * Begin examination of the actual pathname
447      */
448     if (!Pathname)
449     {
450         /* A Null NamePath is allowed and refers to the root */
451 
452         NumSegments = 0;
453         ThisNode = AcpiGbl_RootNode;
454         Path = "";
455 
456         ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
457             "Null Pathname (Zero segments), Flags=%X\n", Flags));
458     }
459     else
460     {
461         /*
462          * Name pointer is valid (and must be in internal name format)
463          *
464          * Check for scope prefixes:
465          *
466          * As represented in the AML stream, a namepath consists of an
467          * optional scope prefix followed by a name segment part.
468          *
469          * If present, the scope prefix is either a Root Prefix (in
470          * which case the name is fully qualified), or one or more
471          * Parent Prefixes (in which case the name's scope is relative
472          * to the current scope).
473          */
474         if (*Path == (UINT8) AML_ROOT_PREFIX)
475         {
476             /* Pathname is fully qualified, start from the root */
477 
478             ThisNode = AcpiGbl_RootNode;
479             SearchParentFlag = ACPI_NS_NO_UPSEARCH;
480 
481             /* Point to name segment part */
482 
483             Path++;
484 
485             ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
486                 "Path is absolute from root [%p]\n", ThisNode));
487         }
488         else
489         {
490             /* Pathname is relative to current scope, start there */
491 
492             ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
493                 "Searching relative to prefix scope [%4.4s] (%p)\n",
494                 AcpiUtGetNodeName (PrefixNode), PrefixNode));
495 
496             /*
497              * Handle multiple Parent Prefixes (carat) by just getting
498              * the parent node for each prefix instance.
499              */
500             ThisNode = PrefixNode;
501             NumCarats = 0;
502             while (*Path == (UINT8) AML_PARENT_PREFIX)
503             {
504                 /* Name is fully qualified, no search rules apply */
505 
506                 SearchParentFlag = ACPI_NS_NO_UPSEARCH;
507 
508                 /*
509                  * Point past this prefix to the name segment
510                  * part or the next Parent Prefix
511                  */
512                 Path++;
513 
514                 /* Backup to the parent node */
515 
516                 NumCarats++;
517                 ThisNode = ThisNode->Parent;
518                 if (!ThisNode)
519                 {
520                     /* Current scope has no parent scope */
521 
522                     ACPI_ERROR ((AE_INFO,
523                         "%s: Path has too many parent prefixes (^) "
524                         "- reached beyond root node", Pathname));
525                     return_ACPI_STATUS (AE_NOT_FOUND);
526                 }
527             }
528 
529             if (SearchParentFlag == ACPI_NS_NO_UPSEARCH)
530             {
531                 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
532                     "Search scope is [%4.4s], path has %u carat(s)\n",
533                     AcpiUtGetNodeName (ThisNode), NumCarats));
534             }
535         }
536 
537         /*
538          * Determine the number of ACPI name segments in this pathname.
539          *
540          * The segment part consists of either:
541          *  - A Null name segment (0)
542          *  - A DualNamePrefix followed by two 4-byte name segments
543          *  - A MultiNamePrefix followed by a byte indicating the
544          *      number of segments and the segments themselves.
545          *  - A single 4-byte name segment
546          *
547          * Examine the name prefix opcode, if any, to determine the number of
548          * segments.
549          */
550         switch (*Path)
551         {
552         case 0:
553             /*
554              * Null name after a root or parent prefixes. We already
555              * have the correct target node and there are no name segments.
556              */
557             NumSegments  = 0;
558             Type = ThisNode->Type;
559 
560             ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
561                 "Prefix-only Pathname (Zero name segments), Flags=%X\n",
562                 Flags));
563             break;
564 
565         case AML_DUAL_NAME_PREFIX:
566 
567             /* More than one NameSeg, search rules do not apply */
568 
569             SearchParentFlag = ACPI_NS_NO_UPSEARCH;
570 
571             /* Two segments, point to first name segment */
572 
573             NumSegments = 2;
574             Path++;
575 
576             ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
577                 "Dual Pathname (2 segments, Flags=%X)\n", Flags));
578             break;
579 
580         case AML_MULTI_NAME_PREFIX_OP:
581 
582             /* More than one NameSeg, search rules do not apply */
583 
584             SearchParentFlag = ACPI_NS_NO_UPSEARCH;
585 
586             /* Extract segment count, point to first name segment */
587 
588             Path++;
589             NumSegments = (UINT32) (UINT8) *Path;
590             Path++;
591 
592             ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
593                 "Multi Pathname (%u Segments, Flags=%X)\n",
594                 NumSegments, Flags));
595             break;
596 
597         default:
598             /*
599              * Not a Null name, no Dual or Multi prefix, hence there is
600              * only one name segment and Pathname is already pointing to it.
601              */
602             NumSegments = 1;
603 
604             ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
605                 "Simple Pathname (1 segment, Flags=%X)\n", Flags));
606             break;
607         }
608 
609         ACPI_DEBUG_EXEC (AcpiNsPrintPathname (NumSegments, Path));
610     }
611 
612 
613     /*
614      * Search namespace for each segment of the name. Loop through and
615      * verify (or add to the namespace) each name segment.
616      *
617      * The object type is significant only at the last name
618      * segment. (We don't care about the types along the path, only
619      * the type of the final target object.)
620      */
621     ThisSearchType = ACPI_TYPE_ANY;
622     CurrentNode = ThisNode;
623     while (NumSegments && CurrentNode)
624     {
625         NumSegments--;
626         if (!NumSegments)
627         {
628             /* This is the last segment, enable typechecking */
629 
630             ThisSearchType = Type;
631 
632             /*
633              * Only allow automatic parent search (search rules) if the caller
634              * requested it AND we have a single, non-fully-qualified NameSeg
635              */
636             if ((SearchParentFlag != ACPI_NS_NO_UPSEARCH) &&
637                 (Flags & ACPI_NS_SEARCH_PARENT))
638             {
639                 LocalFlags |= ACPI_NS_SEARCH_PARENT;
640             }
641 
642             /* Set error flag according to caller */
643 
644             if (Flags & ACPI_NS_ERROR_IF_FOUND)
645             {
646                 LocalFlags |= ACPI_NS_ERROR_IF_FOUND;
647             }
648 
649             /* Set override flag according to caller */
650 
651             if (Flags & ACPI_NS_OVERRIDE_IF_FOUND)
652             {
653                 LocalFlags |= ACPI_NS_OVERRIDE_IF_FOUND;
654             }
655         }
656 
657         /* Extract one ACPI name from the front of the pathname */
658 
659         ACPI_MOVE_32_TO_32 (&SimpleName, Path);
660 
661         /* Try to find the single (4 character) ACPI name */
662 
663         Status = AcpiNsSearchAndEnter (SimpleName, WalkState, CurrentNode,
664             InterpreterMode, ThisSearchType, LocalFlags, &ThisNode);
665         if (ACPI_FAILURE (Status))
666         {
667             if (Status == AE_NOT_FOUND)
668             {
669                 /* Name not found in ACPI namespace */
670 
671                 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
672                     "Name [%4.4s] not found in scope [%4.4s] %p\n",
673                     (char *) &SimpleName, (char *) &CurrentNode->Name,
674                     CurrentNode));
675             }
676 
677             *ReturnNode = ThisNode;
678             return_ACPI_STATUS (Status);
679         }
680 
681         /* More segments to follow? */
682 
683         if (NumSegments > 0)
684         {
685             /*
686              * If we have an alias to an object that opens a scope (such as a
687              * device or processor), we need to dereference the alias here so
688              * that we can access any children of the original node (via the
689              * remaining segments).
690              */
691             if (ThisNode->Type == ACPI_TYPE_LOCAL_ALIAS)
692             {
693                 if (!ThisNode->Object)
694                 {
695                     return_ACPI_STATUS (AE_NOT_EXIST);
696                 }
697 
698                 if (AcpiNsOpensScope (((ACPI_NAMESPACE_NODE *)
699                         ThisNode->Object)->Type))
700                 {
701                     ThisNode = (ACPI_NAMESPACE_NODE *) ThisNode->Object;
702                 }
703             }
704         }
705 
706         /* Special handling for the last segment (NumSegments == 0) */
707 
708         else
709         {
710             /*
711              * Sanity typecheck of the target object:
712              *
713              * If 1) This is the last segment (NumSegments == 0)
714              *    2) And we are looking for a specific type
715              *       (Not checking for TYPE_ANY)
716              *    3) Which is not an alias
717              *    4) Which is not a local type (TYPE_SCOPE)
718              *    5) And the type of target object is known (not TYPE_ANY)
719              *    6) And target object does not match what we are looking for
720              *
721              * Then we have a type mismatch. Just warn and ignore it.
722              */
723             if ((TypeToCheckFor != ACPI_TYPE_ANY)                   &&
724                 (TypeToCheckFor != ACPI_TYPE_LOCAL_ALIAS)           &&
725                 (TypeToCheckFor != ACPI_TYPE_LOCAL_METHOD_ALIAS)    &&
726                 (TypeToCheckFor != ACPI_TYPE_LOCAL_SCOPE)           &&
727                 (ThisNode->Type != ACPI_TYPE_ANY)                   &&
728                 (ThisNode->Type != TypeToCheckFor))
729             {
730                 /* Complain about a type mismatch */
731 
732                 ACPI_WARNING ((AE_INFO,
733                     "NsLookup: Type mismatch on %4.4s (%s), searching for (%s)",
734                     ACPI_CAST_PTR (char, &SimpleName),
735                     AcpiUtGetTypeName (ThisNode->Type),
736                     AcpiUtGetTypeName (TypeToCheckFor)));
737             }
738 
739             /*
740              * If this is the last name segment and we are not looking for a
741              * specific type, but the type of found object is known, use that
742              * type to (later) see if it opens a scope.
743              */
744             if (Type == ACPI_TYPE_ANY)
745             {
746                 Type = ThisNode->Type;
747             }
748         }
749 
750         /* Point to next name segment and make this node current */
751 
752         Path += ACPI_NAME_SIZE;
753         CurrentNode = ThisNode;
754     }
755 
756     /* Always check if we need to open a new scope */
757 
758     if (!(Flags & ACPI_NS_DONT_OPEN_SCOPE) && (WalkState))
759     {
760         /*
761          * If entry is a type which opens a scope, push the new scope on the
762          * scope stack.
763          */
764         if (AcpiNsOpensScope (Type))
765         {
766             Status = AcpiDsScopeStackPush (ThisNode, Type, WalkState);
767             if (ACPI_FAILURE (Status))
768             {
769                 return_ACPI_STATUS (Status);
770             }
771         }
772     }
773 
774     *ReturnNode = ThisNode;
775     return_ACPI_STATUS (AE_OK);
776 }
777