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