nsaccess.c revision 107325
1189251Ssam/*******************************************************************************
2189251Ssam *
3189251Ssam * Module Name: nsaccess - Top-level functions for accessing ACPI namespace
4189251Ssam *              $Revision: 165 $
5252726Srpaulo *
6252726Srpaulo ******************************************************************************/
7189251Ssam
8189251Ssam/******************************************************************************
9189251Ssam *
10189251Ssam * 1. Copyright Notice
11189251Ssam *
12214734Srpaulo * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp.
13214734Srpaulo * All rights reserved.
14252726Srpaulo *
15189251Ssam * 2. License
16189251Ssam *
17189251Ssam * 2.1. This is your license from Intel Corp. under its intellectual property
18189251Ssam * rights.  You may have additional license terms from the party that provided
19189251Ssam * you this software, covering your right to use that party's intellectual
20189251Ssam * property rights.
21189251Ssam *
22189251Ssam * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23189251Ssam * copy of the source code appearing in this file ("Covered Code") an
24189251Ssam * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25189251Ssam * base code distributed originally by Intel ("Original Intel Code") to copy,
26189251Ssam * make derivatives, distribute, use and display any portion of the Covered
27189251Ssam * Code in any form, with the right to sublicense such rights; and
28189251Ssam *
29189251Ssam * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30189251Ssam * license (with the right to sublicense), under only those claims of Intel
31189251Ssam * patents that are infringed by the Original Intel Code, to make, use, sell,
32189251Ssam * offer to sell, and import the Covered Code and derivative works thereof
33189251Ssam * solely to the minimum extent necessary to exercise the above copyright
34189251Ssam * license, and in no event shall the patent license extend to any additions
35189251Ssam * to or modifications of the Original Intel Code.  No other license or right
36189251Ssam * is granted directly or by implication, estoppel or otherwise;
37189251Ssam *
38189251Ssam * The above copyright and patent license is granted only if the following
39189251Ssam * conditions are met:
40189251Ssam *
41189251Ssam * 3. Conditions
42189251Ssam *
43189251Ssam * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44189251Ssam * Redistribution of source code of any substantial portion of the Covered
45189251Ssam * Code or modification with rights to further distribute source must include
46189251Ssam * the above Copyright Notice, the above License, this list of Conditions,
47189251Ssam * and the following Disclaimer and Export Compliance provision.  In addition,
48189251Ssam * Licensee must cause all Covered Code to which Licensee contributes to
49189251Ssam * contain a file documenting the changes Licensee made to create that Covered
50189251Ssam * Code and the date of any change.  Licensee must include in that file the
51189251Ssam * documentation of any changes made by any predecessor Licensee.  Licensee
52189251Ssam * must include a prominent statement that the modification is derived,
53189251Ssam * directly or indirectly, from Original Intel Code.
54189251Ssam *
55189251Ssam * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56189251Ssam * Redistribution of source code of any substantial portion of the Covered
57189251Ssam * Code or modification without rights to further distribute source must
58189251Ssam * include the following Disclaimer and Export Compliance provision in the
59189251Ssam * documentation and/or other materials provided with distribution.  In
60189251Ssam * addition, Licensee may not authorize further sublicense of source of any
61189251Ssam * portion of the Covered Code, and must include terms to the effect that the
62189251Ssam * license from Licensee to its licensee is limited to the intellectual
63189251Ssam * property embodied in the software Licensee provides to its licensee, and
64189251Ssam * not to intellectual property embodied in modifications its licensee may
65189251Ssam * make.
66189251Ssam *
67189251Ssam * 3.3. Redistribution of Executable. Redistribution in executable form of any
68189251Ssam * substantial portion of the Covered Code or modification must reproduce the
69189251Ssam * above Copyright Notice, and the following Disclaimer and Export Compliance
70189251Ssam * provision in the documentation and/or other materials provided with the
71189251Ssam * distribution.
72189251Ssam *
73189251Ssam * 3.4. Intel retains all right, title, and interest in and to the Original
74189251Ssam * Intel Code.
75189251Ssam *
76189251Ssam * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77189251Ssam * Intel shall be used in advertising or otherwise to promote the sale, use or
78189251Ssam * other dealings in products derived from or relating to the Covered Code
79189251Ssam * without prior written authorization from Intel.
80189251Ssam *
81189251Ssam * 4. Disclaimer and Export Compliance
82189251Ssam *
83189251Ssam * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84189251Ssam * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85189251Ssam * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86189251Ssam * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87189251Ssam * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88189251Ssam * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89189251Ssam * PARTICULAR PURPOSE.
90189251Ssam *
91189251Ssam * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92189251Ssam * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93189251Ssam * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94189251Ssam * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95189251Ssam * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96189251Ssam * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97189251Ssam * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98189251Ssam * LIMITED REMEDY.
99189251Ssam *
100189251Ssam * 4.3. Licensee shall not export, either directly or indirectly, any of this
101189251Ssam * software or system incorporating such software without first obtaining any
102189251Ssam * required license or other approval from the U. S. Department of Commerce or
103189251Ssam * any other agency or department of the United States Government.  In the
104189251Ssam * event Licensee exports any such software from the United States or
105189251Ssam * re-exports any such software from a foreign destination, Licensee shall
106189251Ssam * ensure that the distribution and export/re-export of the software is in
107189251Ssam * compliance with all laws, regulations, orders, or other restrictions of the
108189251Ssam * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109189251Ssam * any of its subsidiaries will export/re-export any technical data, process,
110189251Ssam * software, or service, directly or indirectly, to any country for which the
111189251Ssam * United States government or any agency thereof requires an export license,
112189251Ssam * other governmental approval, or letter of assurance, without first obtaining
113189251Ssam * such license, approval or letter.
114189251Ssam *
115189251Ssam *****************************************************************************/
116189251Ssam
117189251Ssam#define __NSACCESS_C__
118346981Scy
119346981Scy#include "acpi.h"
120346981Scy#include "amlcode.h"
121346981Scy#include "acnamesp.h"
122346981Scy#include "acdispat.h"
123346981Scy
124346981Scy
125346981Scy#define _COMPONENT          ACPI_NAMESPACE
126189251Ssam        ACPI_MODULE_NAME    ("nsaccess")
127189251Ssam
128189251Ssam
129189251Ssam/*******************************************************************************
130189251Ssam *
131189251Ssam * FUNCTION:    AcpiNsRootInitialize
132189251Ssam *
133189251Ssam * PARAMETERS:  None
134189251Ssam *
135189251Ssam * RETURN:      Status
136189251Ssam *
137189251Ssam * DESCRIPTION: Allocate and initialize the default root named objects
138189251Ssam *
139189251Ssam * MUTEX:       Locks namespace for entire execution
140189251Ssam *
141189251Ssam ******************************************************************************/
142189251Ssam
143189251SsamACPI_STATUS
144189251SsamAcpiNsRootInitialize (void)
145189251Ssam{
146189251Ssam    ACPI_STATUS                 Status;
147189251Ssam    const ACPI_PREDEFINED_NAMES *InitVal = NULL;
148189251Ssam    ACPI_NAMESPACE_NODE         *NewNode;
149189251Ssam    ACPI_OPERAND_OBJECT         *ObjDesc;
150189251Ssam
151189251Ssam
152189251Ssam    ACPI_FUNCTION_TRACE ("NsRootInitialize");
153189251Ssam
154189251Ssam
155189251Ssam    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
156189251Ssam    if (ACPI_FAILURE (Status))
157189251Ssam    {
158189251Ssam        return_ACPI_STATUS (Status);
159189251Ssam    }
160189251Ssam
161189251Ssam    /*
162189251Ssam     * The global root ptr is initially NULL, so a non-NULL value indicates
163189251Ssam     * that AcpiNsRootInitialize() has already been called; just return.
164189251Ssam     */
165189251Ssam    if (AcpiGbl_RootNode)
166189251Ssam    {
167189251Ssam        Status = AE_OK;
168189251Ssam        goto UnlockAndExit;
169252726Srpaulo    }
170189251Ssam
171189251Ssam    /*
172189251Ssam     * Tell the rest of the subsystem that the root is initialized
173189251Ssam     * (This is OK because the namespace is locked)
174189251Ssam     */
175189251Ssam    AcpiGbl_RootNode = &AcpiGbl_RootNodeStruct;
176189251Ssam
177189251Ssam    /* Enter the pre-defined names in the name table */
178189251Ssam
179189251Ssam    ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
180189251Ssam        "Entering predefined entries into namespace\n"));
181189251Ssam
182189251Ssam    for (InitVal = AcpiGbl_PreDefinedNames; InitVal->Name; InitVal++)
183189251Ssam    {
184189251Ssam        Status = AcpiNsLookup (NULL, InitVal->Name, InitVal->Type,
185189251Ssam                        ACPI_IMODE_LOAD_PASS2, ACPI_NS_NO_UPSEARCH, NULL, &NewNode);
186189251Ssam
187189251Ssam        if (ACPI_FAILURE (Status) || (!NewNode)) /* Must be on same line for code converter */
188189251Ssam        {
189189251Ssam            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
190189251Ssam                "Could not create predefined name %s, %s\n",
191189251Ssam                InitVal->Name, AcpiFormatException (Status)));
192189251Ssam        }
193189251Ssam
194189251Ssam        /*
195189251Ssam         * Name entered successfully.
196189251Ssam         * If entry in PreDefinedNames[] specifies an
197189251Ssam         * initial value, create the initial value.
198189251Ssam         */
199189251Ssam        if (InitVal->Val)
200189251Ssam        {
201189251Ssam            /*
202189251Ssam             * Entry requests an initial value, allocate a
203189251Ssam             * descriptor for it.
204189251Ssam             */
205189251Ssam            ObjDesc = AcpiUtCreateInternalObject (InitVal->Type);
206189251Ssam            if (!ObjDesc)
207189251Ssam            {
208189251Ssam                Status = AE_NO_MEMORY;
209189251Ssam                goto UnlockAndExit;
210189251Ssam            }
211189251Ssam
212189251Ssam            /*
213189251Ssam             * Convert value string from table entry to
214189251Ssam             * internal representation. Only types actually
215189251Ssam             * used for initial values are implemented here.
216189251Ssam             */
217189251Ssam            switch (InitVal->Type)
218189251Ssam            {
219189251Ssam            case ACPI_TYPE_METHOD:
220189251Ssam                ObjDesc->Method.ParamCount =
221189251Ssam                        (UINT8) ACPI_STRTOUL (InitVal->Val, NULL, 10);
222189251Ssam                ObjDesc->Common.Flags |= AOPOBJ_DATA_VALID;
223189251Ssam
224189251Ssam#if defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY)
225189251Ssam
226189251Ssam                /* Compiler cheats by putting parameter count in the OwnerID */
227189251Ssam
228189251Ssam                NewNode->OwnerId = ObjDesc->Method.ParamCount;
229189251Ssam#endif
230189251Ssam                break;
231189251Ssam
232189251Ssam            case ACPI_TYPE_INTEGER:
233189251Ssam
234189251Ssam                ObjDesc->Integer.Value =
235214734Srpaulo                        (ACPI_INTEGER) ACPI_STRTOUL (InitVal->Val, NULL, 10);
236214734Srpaulo                break;
237214734Srpaulo
238214734Srpaulo
239189251Ssam            case ACPI_TYPE_STRING:
240214734Srpaulo
241214734Srpaulo                /*
242214734Srpaulo                 * Build an object around the static string
243214734Srpaulo                 */
244214734Srpaulo                ObjDesc->String.Length = (UINT32) ACPI_STRLEN (InitVal->Val);
245189251Ssam                ObjDesc->String.Pointer = InitVal->Val;
246346981Scy                ObjDesc->Common.Flags |= AOPOBJ_STATIC_POINTER;
247346981Scy                break;
248346981Scy
249346981Scy
250189251Ssam            case ACPI_TYPE_MUTEX:
251189251Ssam
252189251Ssam                ObjDesc->Mutex.Node = NewNode;
253189251Ssam                ObjDesc->Mutex.SyncLevel =
254281806Srpaulo                            (UINT16) ACPI_STRTOUL (InitVal->Val, NULL, 10);
255189251Ssam
256189251Ssam                if (ACPI_STRCMP (InitVal->Name, "_GL_") == 0)
257189251Ssam                {
258189251Ssam                    /*
259189251Ssam                     * Create a counting semaphore for the
260189251Ssam                     * global lock
261189251Ssam                     */
262189251Ssam                    Status = AcpiOsCreateSemaphore (ACPI_NO_UNIT_LIMIT,
263189251Ssam                                            1, &ObjDesc->Mutex.Semaphore);
264189251Ssam                    if (ACPI_FAILURE (Status))
265189251Ssam                    {
266189251Ssam                        goto UnlockAndExit;
267189251Ssam                    }
268189251Ssam
269189251Ssam                    /*
270189251Ssam                     * We just created the mutex for the
271189251Ssam                     * global lock, save it
272189251Ssam                     */
273189251Ssam                    AcpiGbl_GlobalLockSemaphore = ObjDesc->Mutex.Semaphore;
274189251Ssam                }
275189251Ssam                else
276189251Ssam                {
277189251Ssam                    /* Create a mutex */
278189251Ssam
279189251Ssam                    Status = AcpiOsCreateSemaphore (1, 1,
280189251Ssam                                        &ObjDesc->Mutex.Semaphore);
281189251Ssam                    if (ACPI_FAILURE (Status))
282189251Ssam                    {
283189251Ssam                        goto UnlockAndExit;
284189251Ssam                    }
285189251Ssam                }
286189251Ssam                break;
287189251Ssam
288189251Ssam
289189251Ssam            default:
290189251Ssam                ACPI_REPORT_ERROR (("Unsupported initial type value %X\n",
291189251Ssam                    InitVal->Type));
292189251Ssam                AcpiUtRemoveReference (ObjDesc);
293189251Ssam                ObjDesc = NULL;
294189251Ssam                continue;
295189251Ssam            }
296189251Ssam
297189251Ssam            /* Store pointer to value descriptor in the Node */
298189251Ssam
299189251Ssam            Status = AcpiNsAttachObject (NewNode, ObjDesc, ACPI_GET_OBJECT_TYPE (ObjDesc));
300189251Ssam
301189251Ssam            /* Remove local reference to the object */
302189251Ssam
303189251Ssam            AcpiUtRemoveReference (ObjDesc);
304189251Ssam        }
305189251Ssam    }
306189251Ssam
307189251Ssam
308189251SsamUnlockAndExit:
309189251Ssam    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
310189251Ssam    return_ACPI_STATUS (Status);
311189251Ssam}
312189251Ssam
313189251Ssam
314189251Ssam/*******************************************************************************
315189251Ssam *
316189251Ssam * FUNCTION:    AcpiNsLookup
317189251Ssam *
318189251Ssam * PARAMETERS:  PrefixNode      - Search scope if name is not fully qualified
319189251Ssam *              Pathname        - Search pathname, in internal format
320189251Ssam *                                (as represented in the AML stream)
321189251Ssam *              Type            - Type associated with name
322189251Ssam *              InterpreterMode - IMODE_LOAD_PASS2 => add name if not found
323189251Ssam *              Flags           - Flags describing the search restrictions
324189251Ssam *              WalkState       - Current state of the walk
325189251Ssam *              ReturnNode      - Where the Node is placed (if found
326189251Ssam *                                or created successfully)
327189251Ssam *
328189251Ssam * RETURN:      Status
329189251Ssam *
330189251Ssam * DESCRIPTION: Find or enter the passed name in the name space.
331189251Ssam *              Log an error if name not found in Exec mode.
332189251Ssam *
333189251Ssam * MUTEX:       Assumes namespace is locked.
334189251Ssam *
335189251Ssam ******************************************************************************/
336189251Ssam
337189251SsamACPI_STATUS
338189251SsamAcpiNsLookup (
339189251Ssam    ACPI_GENERIC_STATE      *ScopeInfo,
340189251Ssam    NATIVE_CHAR             *Pathname,
341189251Ssam    ACPI_OBJECT_TYPE        Type,
342189251Ssam    ACPI_INTERPRETER_MODE   InterpreterMode,
343189251Ssam    UINT32                  Flags,
344189251Ssam    ACPI_WALK_STATE         *WalkState,
345189251Ssam    ACPI_NAMESPACE_NODE     **ReturnNode)
346189251Ssam{
347189251Ssam    ACPI_STATUS             Status;
348189251Ssam    NATIVE_CHAR             *Path = Pathname;
349189251Ssam    ACPI_NAMESPACE_NODE     *PrefixNode;
350189251Ssam    ACPI_NAMESPACE_NODE     *CurrentNode = NULL;
351189251Ssam    ACPI_NAMESPACE_NODE     *ThisNode = NULL;
352189251Ssam    UINT32                  NumSegments;
353189251Ssam    UINT32                  NumCarats;
354189251Ssam    ACPI_NAME               SimpleName;
355189251Ssam    ACPI_OBJECT_TYPE        TypeToCheckFor;
356214734Srpaulo    ACPI_OBJECT_TYPE        ThisSearchType;
357214734Srpaulo    UINT32                  SearchParentFlag = ACPI_NS_SEARCH_PARENT;
358214734Srpaulo    UINT32                  LocalFlags = Flags & ~(ACPI_NS_ERROR_IF_FOUND |
359214734Srpaulo                                                   ACPI_NS_SEARCH_PARENT);
360214734Srpaulo
361214734Srpaulo
362214734Srpaulo    ACPI_FUNCTION_TRACE ("NsLookup");
363214734Srpaulo
364214734Srpaulo
365214734Srpaulo    if (!ReturnNode)
366214734Srpaulo    {
367189251Ssam        return_ACPI_STATUS (AE_BAD_PARAMETER);
368189251Ssam    }
369189251Ssam
370189251Ssam    AcpiGbl_NsLookupCount++;
371189251Ssam    *ReturnNode = ACPI_ENTRY_NOT_FOUND;
372189251Ssam
373189251Ssam    if (!AcpiGbl_RootNode)
374189251Ssam    {
375189251Ssam        return_ACPI_STATUS (AE_NO_NAMESPACE);
376189251Ssam    }
377189251Ssam
378189251Ssam    /*
379189251Ssam     * Get the prefix scope.
380189251Ssam     * A null scope means use the root scope
381189251Ssam     */
382189251Ssam    if ((!ScopeInfo) ||
383189251Ssam        (!ScopeInfo->Scope.Node))
384189251Ssam    {
385189251Ssam        ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
386189251Ssam            "Null scope prefix, using root node (%p)\n",
387189251Ssam            AcpiGbl_RootNode));
388189251Ssam
389189251Ssam        PrefixNode = AcpiGbl_RootNode;
390189251Ssam    }
391189251Ssam    else
392189251Ssam    {
393351611Scy        PrefixNode = ScopeInfo->Scope.Node;
394351611Scy        if (ACPI_GET_DESCRIPTOR_TYPE (PrefixNode) != ACPI_DESC_TYPE_NAMED)
395281806Srpaulo        {
396189251Ssam            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "[%p] Not a namespace node\n",
397189251Ssam                PrefixNode));
398189251Ssam            return_ACPI_STATUS (AE_AML_INTERNAL);
399189251Ssam        }
400189251Ssam
401189251Ssam        /*
402189251Ssam         * This node might not be a actual "scope" node (such as a
403189251Ssam         * Device/Method, etc.)  It could be a Package or other object node.
404189251Ssam         * Backup up the tree to find the containing scope node.
405189251Ssam         */
406189251Ssam        while (!AcpiNsOpensScope (PrefixNode->Type) &&
407189251Ssam                PrefixNode->Type != ACPI_TYPE_ANY)
408189251Ssam        {
409189251Ssam            PrefixNode = AcpiNsGetParentNode (PrefixNode);
410189251Ssam        }
411189251Ssam    }
412189251Ssam
413189251Ssam    /* Save type   TBD: may be no longer necessary */
414189251Ssam
415337817Scy    TypeToCheckFor = Type;
416189251Ssam
417    /*
418     * Begin examination of the actual pathname
419     */
420    if (!Pathname)
421    {
422        /* A Null NamePath is allowed and refers to the root */
423
424        NumSegments  = 0;
425        ThisNode     = AcpiGbl_RootNode;
426        Path     = "";
427
428        ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
429            "Null Pathname (Zero segments), Flags=%X\n", Flags));
430    }
431    else
432    {
433        /*
434         * Name pointer is valid (and must be in internal name format)
435         *
436         * Check for scope prefixes:
437         *
438         * As represented in the AML stream, a namepath consists of an
439         * optional scope prefix followed by a name segment part.
440         *
441         * If present, the scope prefix is either a Root Prefix (in
442         * which case the name is fully qualified), or one or more
443         * Parent Prefixes (in which case the name's scope is relative
444         * to the current scope).
445         */
446        if (*Path == (UINT8) AML_ROOT_PREFIX)
447        {
448            /* Pathname is fully qualified, start from the root */
449
450            ThisNode = AcpiGbl_RootNode;
451            SearchParentFlag = ACPI_NS_NO_UPSEARCH;
452
453            /* Point to name segment part */
454
455            Path++;
456
457            ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
458                "Path is absolute from root [%p]\n", ThisNode));
459        }
460        else
461        {
462            /* Pathname is relative to current scope, start there */
463
464            ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
465                "Searching relative to prefix scope [%4.4s] (%p)\n",
466                PrefixNode->Name.Ascii, PrefixNode));
467
468            /*
469             * Handle multiple Parent Prefixes (carat) by just getting
470             * the parent node for each prefix instance.
471             */
472            ThisNode = PrefixNode;
473            NumCarats = 0;
474            while (*Path == (UINT8) AML_PARENT_PREFIX)
475            {
476                /* Name is fully qualified, no search rules apply */
477
478                SearchParentFlag = ACPI_NS_NO_UPSEARCH;
479                /*
480                 * Point past this prefix to the name segment
481                 * part or the next Parent Prefix
482                 */
483                Path++;
484
485                /* Backup to the parent node */
486
487                NumCarats++;
488                ThisNode = AcpiNsGetParentNode (ThisNode);
489                if (!ThisNode)
490                {
491                    /* Current scope has no parent scope */
492
493                    ACPI_REPORT_ERROR (
494                        ("ACPI path has too many parent prefixes (^) - reached beyond root node\n"));
495                    return_ACPI_STATUS (AE_NOT_FOUND);
496                }
497            }
498
499            if (SearchParentFlag == ACPI_NS_NO_UPSEARCH)
500            {
501                ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
502                    "Search scope is [%4.4s], path has %d carat(s)\n",
503                    ThisNode->Name.Ascii, NumCarats));
504            }
505        }
506
507        /*
508         * Determine the number of ACPI name segments in this pathname.
509         *
510         * The segment part consists of either:
511         *  - A Null name segment (0)
512         *  - A DualNamePrefix followed by two 4-byte name segments
513         *  - A MultiNamePrefix followed by a byte indicating the
514         *      number of segments and the segments themselves.
515         *  - A single 4-byte name segment
516         *
517         * Examine the name prefix opcode, if any, to determine the number of
518         * segments.
519         */
520        switch (*Path)
521        {
522        case 0:
523            /*
524             * Null name after a root or parent prefixes. We already
525             * have the correct target node and there are no name segments.
526             */
527            NumSegments  = 0;
528            Type = ThisNode->Type;
529
530            ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
531                "Prefix-only Pathname (Zero name segments), Flags=%X\n", Flags));
532            break;
533
534        case AML_DUAL_NAME_PREFIX:
535
536            /* More than one NameSeg, search rules do not apply */
537
538            SearchParentFlag = ACPI_NS_NO_UPSEARCH;
539
540            /* Two segments, point to first name segment */
541
542            NumSegments = 2;
543            Path++;
544
545            ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
546                "Dual Pathname (2 segments, Flags=%X)\n", Flags));
547            break;
548
549        case AML_MULTI_NAME_PREFIX_OP:
550
551            /* More than one NameSeg, search rules do not apply */
552
553            SearchParentFlag = ACPI_NS_NO_UPSEARCH;
554
555            /* Extract segment count, point to first name segment */
556
557            Path++;
558            NumSegments = (UINT32) (UINT8) *Path;
559            Path++;
560
561            ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
562                "Multi Pathname (%d Segments, Flags=%X) \n",
563                NumSegments, Flags));
564            break;
565
566        default:
567            /*
568             * Not a Null name, no Dual or Multi prefix, hence there is
569             * only one name segment and Pathname is already pointing to it.
570             */
571            NumSegments = 1;
572
573            ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
574                "Simple Pathname (1 segment, Flags=%X)\n", Flags));
575            break;
576        }
577
578        ACPI_DEBUG_EXEC (AcpiNsPrintPathname (NumSegments, Path));
579    }
580
581
582    /*
583     * Search namespace for each segment of the name.  Loop through and
584     * verify (or add to the namespace) each name segment.
585     *
586     * The object type is significant only at the last name
587     * segment.  (We don't care about the types along the path, only
588     * the type of the final target object.)
589     */
590    ThisSearchType = ACPI_TYPE_ANY;
591    CurrentNode = ThisNode;
592    while (NumSegments && CurrentNode)
593    {
594        NumSegments--;
595        if (!NumSegments)
596        {
597            /*
598             * This is the last segment, enable typechecking
599             */
600            ThisSearchType = Type;
601
602            /*
603             * Only allow automatic parent search (search rules) if the caller
604             * requested it AND we have a single, non-fully-qualified NameSeg
605             */
606            if ((SearchParentFlag != ACPI_NS_NO_UPSEARCH) &&
607                (Flags & ACPI_NS_SEARCH_PARENT))
608            {
609                LocalFlags |= ACPI_NS_SEARCH_PARENT;
610            }
611
612            /* Set error flag according to caller */
613
614            if (Flags & ACPI_NS_ERROR_IF_FOUND)
615            {
616                LocalFlags |= ACPI_NS_ERROR_IF_FOUND;
617            }
618        }
619
620        /* Extract one ACPI name from the front of the pathname */
621
622        ACPI_MOVE_UNALIGNED32_TO_32 (&SimpleName, Path);
623
624        /* Try to find the single (4 character) ACPI name */
625
626        Status = AcpiNsSearchAndEnter (SimpleName, WalkState, CurrentNode,
627                        InterpreterMode, ThisSearchType, LocalFlags, &ThisNode);
628        if (ACPI_FAILURE (Status))
629        {
630            if (Status == AE_NOT_FOUND)
631            {
632                /* Name not found in ACPI namespace */
633
634                ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
635                    "Name [%4.4s] not found in scope [%4.4s] %p\n",
636                    (char *) &SimpleName, (char *) &CurrentNode->Name,
637                    CurrentNode));
638            }
639
640            *ReturnNode = ThisNode;
641            return_ACPI_STATUS (Status);
642        }
643
644        /*
645         * Sanity typecheck of the target object:
646         *
647         * If 1) This is the last segment (NumSegments == 0)
648         *    2) And we are looking for a specific type
649         *       (Not checking for TYPE_ANY)
650         *    3) Which is not an alias
651         *    4) Which is not a local type (TYPE_SCOPE)
652         *    5) And the type of target object is known (not TYPE_ANY)
653         *    6) And target object does not match what we are looking for
654         *
655         * Then we have a type mismatch.  Just warn and ignore it.
656         */
657        if ((NumSegments        == 0)                               &&
658            (TypeToCheckFor     != ACPI_TYPE_ANY)                   &&
659            (TypeToCheckFor     != ACPI_TYPE_LOCAL_ALIAS)           &&
660            (TypeToCheckFor     != ACPI_TYPE_LOCAL_SCOPE)           &&
661            (ThisNode->Type     != ACPI_TYPE_ANY)                   &&
662            (ThisNode->Type     != TypeToCheckFor))
663        {
664            /* Complain about a type mismatch */
665
666            ACPI_REPORT_WARNING (
667                ("NsLookup: Type mismatch on %4.4s (%s), searching for (%s)\n",
668                (char *) &SimpleName, AcpiUtGetTypeName (ThisNode->Type),
669                AcpiUtGetTypeName (TypeToCheckFor)));
670        }
671
672        /*
673         * If this is the last name segment and we are not looking for a
674         * specific type, but the type of found object is known, use that type
675         * to see if it opens a scope.
676         */
677        if ((NumSegments == 0) && (Type == ACPI_TYPE_ANY))
678        {
679            Type = ThisNode->Type;
680        }
681
682        /* Point to next name segment and make this node current */
683
684        Path += ACPI_NAME_SIZE;
685        CurrentNode = ThisNode;
686    }
687
688    /*
689     * Always check if we need to open a new scope
690     */
691    if (!(Flags & ACPI_NS_DONT_OPEN_SCOPE) && (WalkState))
692    {
693        /*
694         * If entry is a type which opens a scope, push the new scope on the
695         * scope stack.
696         */
697        if (AcpiNsOpensScope (Type))
698        {
699            Status = AcpiDsScopeStackPush (ThisNode, Type, WalkState);
700            if (ACPI_FAILURE (Status))
701            {
702                return_ACPI_STATUS (Status);
703            }
704        }
705    }
706
707    *ReturnNode = ThisNode;
708    return_ACPI_STATUS (AE_OK);
709}
710
711