xref: /minix3/minix/drivers/power/acpi/namespace/nsaccess.c (revision 29492bb71c7148a089a5afafa0c99409161218df)
1433d6423SLionel Sambuc /*******************************************************************************
2433d6423SLionel Sambuc  *
3433d6423SLionel Sambuc  * Module Name: nsaccess - Top-level functions for accessing ACPI namespace
4433d6423SLionel Sambuc  *
5433d6423SLionel Sambuc  ******************************************************************************/
6433d6423SLionel Sambuc 
7*29492bb7SDavid van Moolenbroek /*
8*29492bb7SDavid van Moolenbroek  * Copyright (C) 2000 - 2014, Intel Corp.
9433d6423SLionel Sambuc  * All rights reserved.
10433d6423SLionel Sambuc  *
11*29492bb7SDavid van Moolenbroek  * Redistribution and use in source and binary forms, with or without
12*29492bb7SDavid van Moolenbroek  * modification, are permitted provided that the following conditions
13*29492bb7SDavid van Moolenbroek  * are met:
14*29492bb7SDavid van Moolenbroek  * 1. Redistributions of source code must retain the above copyright
15*29492bb7SDavid van Moolenbroek  *    notice, this list of conditions, and the following disclaimer,
16*29492bb7SDavid van Moolenbroek  *    without modification.
17*29492bb7SDavid van Moolenbroek  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18*29492bb7SDavid van Moolenbroek  *    substantially similar to the "NO WARRANTY" disclaimer below
19*29492bb7SDavid van Moolenbroek  *    ("Disclaimer") and any redistribution must be conditioned upon
20*29492bb7SDavid van Moolenbroek  *    including a substantially similar Disclaimer requirement for further
21*29492bb7SDavid van Moolenbroek  *    binary redistribution.
22*29492bb7SDavid van Moolenbroek  * 3. Neither the names of the above-listed copyright holders nor the names
23*29492bb7SDavid van Moolenbroek  *    of any contributors may be used to endorse or promote products derived
24*29492bb7SDavid van Moolenbroek  *    from this software without specific prior written permission.
25433d6423SLionel Sambuc  *
26*29492bb7SDavid van Moolenbroek  * Alternatively, this software may be distributed under the terms of the
27*29492bb7SDavid van Moolenbroek  * GNU General Public License ("GPL") version 2 as published by the Free
28*29492bb7SDavid van Moolenbroek  * Software Foundation.
29433d6423SLionel Sambuc  *
30*29492bb7SDavid van Moolenbroek  * NO WARRANTY
31*29492bb7SDavid van Moolenbroek  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32*29492bb7SDavid van Moolenbroek  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33*29492bb7SDavid van Moolenbroek  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34*29492bb7SDavid van Moolenbroek  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35*29492bb7SDavid van Moolenbroek  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36*29492bb7SDavid van Moolenbroek  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37*29492bb7SDavid van Moolenbroek  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38*29492bb7SDavid van Moolenbroek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39*29492bb7SDavid van Moolenbroek  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40*29492bb7SDavid van Moolenbroek  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41*29492bb7SDavid van Moolenbroek  * POSSIBILITY OF SUCH DAMAGES.
42*29492bb7SDavid van Moolenbroek  */
43433d6423SLionel Sambuc 
44433d6423SLionel Sambuc #include "acpi.h"
45433d6423SLionel Sambuc #include "accommon.h"
46433d6423SLionel Sambuc #include "amlcode.h"
47433d6423SLionel Sambuc #include "acnamesp.h"
48433d6423SLionel Sambuc #include "acdispat.h"
49433d6423SLionel Sambuc 
50433d6423SLionel Sambuc 
51433d6423SLionel Sambuc #define _COMPONENT          ACPI_NAMESPACE
52433d6423SLionel Sambuc         ACPI_MODULE_NAME    ("nsaccess")
53433d6423SLionel Sambuc 
54433d6423SLionel Sambuc 
55433d6423SLionel Sambuc /*******************************************************************************
56433d6423SLionel Sambuc  *
57433d6423SLionel Sambuc  * FUNCTION:    AcpiNsRootInitialize
58433d6423SLionel Sambuc  *
59433d6423SLionel Sambuc  * PARAMETERS:  None
60433d6423SLionel Sambuc  *
61433d6423SLionel Sambuc  * RETURN:      Status
62433d6423SLionel Sambuc  *
63433d6423SLionel Sambuc  * DESCRIPTION: Allocate and initialize the default root named objects
64433d6423SLionel Sambuc  *
65433d6423SLionel Sambuc  * MUTEX:       Locks namespace for entire execution
66433d6423SLionel Sambuc  *
67433d6423SLionel Sambuc  ******************************************************************************/
68433d6423SLionel Sambuc 
69433d6423SLionel Sambuc ACPI_STATUS
AcpiNsRootInitialize(void)70433d6423SLionel Sambuc AcpiNsRootInitialize (
71433d6423SLionel Sambuc     void)
72433d6423SLionel Sambuc {
73433d6423SLionel Sambuc     ACPI_STATUS                 Status;
74433d6423SLionel Sambuc     const ACPI_PREDEFINED_NAMES *InitVal = NULL;
75433d6423SLionel Sambuc     ACPI_NAMESPACE_NODE         *NewNode;
76433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT         *ObjDesc;
77433d6423SLionel Sambuc     ACPI_STRING                 Val = NULL;
78433d6423SLionel Sambuc 
79433d6423SLionel Sambuc 
80433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (NsRootInitialize);
81433d6423SLionel Sambuc 
82433d6423SLionel Sambuc 
83433d6423SLionel Sambuc     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
84433d6423SLionel Sambuc     if (ACPI_FAILURE (Status))
85433d6423SLionel Sambuc     {
86433d6423SLionel Sambuc         return_ACPI_STATUS (Status);
87433d6423SLionel Sambuc     }
88433d6423SLionel Sambuc 
89433d6423SLionel Sambuc     /*
90433d6423SLionel Sambuc      * The global root ptr is initially NULL, so a non-NULL value indicates
91433d6423SLionel Sambuc      * that AcpiNsRootInitialize() has already been called; just return.
92433d6423SLionel Sambuc      */
93433d6423SLionel Sambuc     if (AcpiGbl_RootNode)
94433d6423SLionel Sambuc     {
95433d6423SLionel Sambuc         Status = AE_OK;
96433d6423SLionel Sambuc         goto UnlockAndExit;
97433d6423SLionel Sambuc     }
98433d6423SLionel Sambuc 
99433d6423SLionel Sambuc     /*
100433d6423SLionel Sambuc      * Tell the rest of the subsystem that the root is initialized
101433d6423SLionel Sambuc      * (This is OK because the namespace is locked)
102433d6423SLionel Sambuc      */
103433d6423SLionel Sambuc     AcpiGbl_RootNode = &AcpiGbl_RootNodeStruct;
104433d6423SLionel Sambuc 
105433d6423SLionel Sambuc     /* Enter the pre-defined names in the name table */
106433d6423SLionel Sambuc 
107433d6423SLionel Sambuc     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
108433d6423SLionel Sambuc         "Entering predefined entries into namespace\n"));
109433d6423SLionel Sambuc 
110433d6423SLionel Sambuc     for (InitVal = AcpiGbl_PreDefinedNames; InitVal->Name; InitVal++)
111433d6423SLionel Sambuc     {
112433d6423SLionel Sambuc         /* _OSI is optional for now, will be permanent later */
113433d6423SLionel Sambuc 
114433d6423SLionel Sambuc         if (!ACPI_STRCMP (InitVal->Name, "_OSI") && !AcpiGbl_CreateOsiMethod)
115433d6423SLionel Sambuc         {
116433d6423SLionel Sambuc             continue;
117433d6423SLionel Sambuc         }
118433d6423SLionel Sambuc 
119433d6423SLionel Sambuc         Status = AcpiNsLookup (NULL, InitVal->Name, InitVal->Type,
120433d6423SLionel Sambuc                         ACPI_IMODE_LOAD_PASS2, ACPI_NS_NO_UPSEARCH,
121433d6423SLionel Sambuc                         NULL, &NewNode);
122*29492bb7SDavid van Moolenbroek         if (ACPI_FAILURE (Status))
123433d6423SLionel Sambuc         {
124433d6423SLionel Sambuc             ACPI_EXCEPTION ((AE_INFO, Status,
125433d6423SLionel Sambuc                 "Could not create predefined name %s",
126433d6423SLionel Sambuc                 InitVal->Name));
127*29492bb7SDavid van Moolenbroek             continue;
128433d6423SLionel Sambuc         }
129433d6423SLionel Sambuc 
130433d6423SLionel Sambuc         /*
131433d6423SLionel Sambuc          * Name entered successfully. If entry in PreDefinedNames[] specifies
132433d6423SLionel Sambuc          * an initial value, create the initial value.
133433d6423SLionel Sambuc          */
134433d6423SLionel Sambuc         if (InitVal->Val)
135433d6423SLionel Sambuc         {
136433d6423SLionel Sambuc             Status = AcpiOsPredefinedOverride (InitVal, &Val);
137433d6423SLionel Sambuc             if (ACPI_FAILURE (Status))
138433d6423SLionel Sambuc             {
139433d6423SLionel Sambuc                 ACPI_ERROR ((AE_INFO,
140433d6423SLionel Sambuc                     "Could not override predefined %s",
141433d6423SLionel Sambuc                     InitVal->Name));
142433d6423SLionel Sambuc             }
143433d6423SLionel Sambuc 
144433d6423SLionel Sambuc             if (!Val)
145433d6423SLionel Sambuc             {
146433d6423SLionel Sambuc                 Val = InitVal->Val;
147433d6423SLionel Sambuc             }
148433d6423SLionel Sambuc 
149433d6423SLionel Sambuc             /*
150433d6423SLionel Sambuc              * Entry requests an initial value, allocate a
151433d6423SLionel Sambuc              * descriptor for it.
152433d6423SLionel Sambuc              */
153433d6423SLionel Sambuc             ObjDesc = AcpiUtCreateInternalObject (InitVal->Type);
154433d6423SLionel Sambuc             if (!ObjDesc)
155433d6423SLionel Sambuc             {
156433d6423SLionel Sambuc                 Status = AE_NO_MEMORY;
157433d6423SLionel Sambuc                 goto UnlockAndExit;
158433d6423SLionel Sambuc             }
159433d6423SLionel Sambuc 
160433d6423SLionel Sambuc             /*
161433d6423SLionel Sambuc              * Convert value string from table entry to
162433d6423SLionel Sambuc              * internal representation. Only types actually
163433d6423SLionel Sambuc              * used for initial values are implemented here.
164433d6423SLionel Sambuc              */
165433d6423SLionel Sambuc             switch (InitVal->Type)
166433d6423SLionel Sambuc             {
167433d6423SLionel Sambuc             case ACPI_TYPE_METHOD:
168*29492bb7SDavid van Moolenbroek 
169433d6423SLionel Sambuc                 ObjDesc->Method.ParamCount = (UINT8) ACPI_TO_INTEGER (Val);
170433d6423SLionel Sambuc                 ObjDesc->Common.Flags |= AOPOBJ_DATA_VALID;
171433d6423SLionel Sambuc 
172433d6423SLionel Sambuc #if defined (ACPI_ASL_COMPILER)
173433d6423SLionel Sambuc 
174433d6423SLionel Sambuc                 /* Save the parameter count for the iASL compiler */
175433d6423SLionel Sambuc 
176433d6423SLionel Sambuc                 NewNode->Value = ObjDesc->Method.ParamCount;
177433d6423SLionel Sambuc #else
178433d6423SLionel Sambuc                 /* Mark this as a very SPECIAL method */
179433d6423SLionel Sambuc 
180*29492bb7SDavid van Moolenbroek                 ObjDesc->Method.InfoFlags = ACPI_METHOD_INTERNAL_ONLY;
181*29492bb7SDavid van Moolenbroek                 ObjDesc->Method.Dispatch.Implementation = AcpiUtOsiImplementation;
182433d6423SLionel Sambuc #endif
183433d6423SLionel Sambuc                 break;
184433d6423SLionel Sambuc 
185433d6423SLionel Sambuc             case ACPI_TYPE_INTEGER:
186433d6423SLionel Sambuc 
187433d6423SLionel Sambuc                 ObjDesc->Integer.Value = ACPI_TO_INTEGER (Val);
188433d6423SLionel Sambuc                 break;
189433d6423SLionel Sambuc 
190433d6423SLionel Sambuc             case ACPI_TYPE_STRING:
191433d6423SLionel Sambuc 
192433d6423SLionel Sambuc                 /* Build an object around the static string */
193433d6423SLionel Sambuc 
194433d6423SLionel Sambuc                 ObjDesc->String.Length = (UINT32) ACPI_STRLEN (Val);
195433d6423SLionel Sambuc                 ObjDesc->String.Pointer = Val;
196433d6423SLionel Sambuc                 ObjDesc->Common.Flags |= AOPOBJ_STATIC_POINTER;
197433d6423SLionel Sambuc                 break;
198433d6423SLionel Sambuc 
199433d6423SLionel Sambuc             case ACPI_TYPE_MUTEX:
200433d6423SLionel Sambuc 
201433d6423SLionel Sambuc                 ObjDesc->Mutex.Node = NewNode;
202433d6423SLionel Sambuc                 ObjDesc->Mutex.SyncLevel = (UINT8) (ACPI_TO_INTEGER (Val) - 1);
203433d6423SLionel Sambuc 
204433d6423SLionel Sambuc                 /* Create a mutex */
205433d6423SLionel Sambuc 
206433d6423SLionel Sambuc                 Status = AcpiOsCreateMutex (&ObjDesc->Mutex.OsMutex);
207433d6423SLionel Sambuc                 if (ACPI_FAILURE (Status))
208433d6423SLionel Sambuc                 {
209433d6423SLionel Sambuc                     AcpiUtRemoveReference (ObjDesc);
210433d6423SLionel Sambuc                     goto UnlockAndExit;
211433d6423SLionel Sambuc                 }
212433d6423SLionel Sambuc 
213433d6423SLionel Sambuc                 /* Special case for ACPI Global Lock */
214433d6423SLionel Sambuc 
215433d6423SLionel Sambuc                 if (ACPI_STRCMP (InitVal->Name, "_GL_") == 0)
216433d6423SLionel Sambuc                 {
217433d6423SLionel Sambuc                     AcpiGbl_GlobalLockMutex = ObjDesc;
218433d6423SLionel Sambuc 
219433d6423SLionel Sambuc                     /* Create additional counting semaphore for global lock */
220433d6423SLionel Sambuc 
221433d6423SLionel Sambuc                     Status = AcpiOsCreateSemaphore (
222433d6423SLionel Sambuc                                 1, 0, &AcpiGbl_GlobalLockSemaphore);
223433d6423SLionel Sambuc                     if (ACPI_FAILURE (Status))
224433d6423SLionel Sambuc                     {
225433d6423SLionel Sambuc                         AcpiUtRemoveReference (ObjDesc);
226433d6423SLionel Sambuc                         goto UnlockAndExit;
227433d6423SLionel Sambuc                     }
228433d6423SLionel Sambuc                 }
229433d6423SLionel Sambuc                 break;
230433d6423SLionel Sambuc 
231433d6423SLionel Sambuc             default:
232433d6423SLionel Sambuc 
233433d6423SLionel Sambuc                 ACPI_ERROR ((AE_INFO, "Unsupported initial type value 0x%X",
234433d6423SLionel Sambuc                     InitVal->Type));
235433d6423SLionel Sambuc                 AcpiUtRemoveReference (ObjDesc);
236433d6423SLionel Sambuc                 ObjDesc = NULL;
237433d6423SLionel Sambuc                 continue;
238433d6423SLionel Sambuc             }
239433d6423SLionel Sambuc 
240433d6423SLionel Sambuc             /* Store pointer to value descriptor in the Node */
241433d6423SLionel Sambuc 
242433d6423SLionel Sambuc             Status = AcpiNsAttachObject (NewNode, ObjDesc,
243433d6423SLionel Sambuc                         ObjDesc->Common.Type);
244433d6423SLionel Sambuc 
245433d6423SLionel Sambuc             /* Remove local reference to the object */
246433d6423SLionel Sambuc 
247433d6423SLionel Sambuc             AcpiUtRemoveReference (ObjDesc);
248433d6423SLionel Sambuc         }
249433d6423SLionel Sambuc     }
250433d6423SLionel Sambuc 
251433d6423SLionel Sambuc 
252433d6423SLionel Sambuc UnlockAndExit:
253433d6423SLionel Sambuc     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
254433d6423SLionel Sambuc 
255433d6423SLionel Sambuc     /* Save a handle to "_GPE", it is always present */
256433d6423SLionel Sambuc 
257433d6423SLionel Sambuc     if (ACPI_SUCCESS (Status))
258433d6423SLionel Sambuc     {
259433d6423SLionel Sambuc         Status = AcpiNsGetNode (NULL, "\\_GPE", ACPI_NS_NO_UPSEARCH,
260433d6423SLionel Sambuc                     &AcpiGbl_FadtGpeDevice);
261433d6423SLionel Sambuc     }
262433d6423SLionel Sambuc 
263433d6423SLionel Sambuc     return_ACPI_STATUS (Status);
264433d6423SLionel Sambuc }
265433d6423SLionel Sambuc 
266433d6423SLionel Sambuc 
267433d6423SLionel Sambuc /*******************************************************************************
268433d6423SLionel Sambuc  *
269433d6423SLionel Sambuc  * FUNCTION:    AcpiNsLookup
270433d6423SLionel Sambuc  *
271433d6423SLionel Sambuc  * PARAMETERS:  ScopeInfo       - Current scope info block
272433d6423SLionel Sambuc  *              Pathname        - Search pathname, in internal format
273433d6423SLionel Sambuc  *                                (as represented in the AML stream)
274433d6423SLionel Sambuc  *              Type            - Type associated with name
275433d6423SLionel Sambuc  *              InterpreterMode - IMODE_LOAD_PASS2 => add name if not found
276433d6423SLionel Sambuc  *              Flags           - Flags describing the search restrictions
277433d6423SLionel Sambuc  *              WalkState       - Current state of the walk
278433d6423SLionel Sambuc  *              ReturnNode      - Where the Node is placed (if found
279433d6423SLionel Sambuc  *                                or created successfully)
280433d6423SLionel Sambuc  *
281433d6423SLionel Sambuc  * RETURN:      Status
282433d6423SLionel Sambuc  *
283433d6423SLionel Sambuc  * DESCRIPTION: Find or enter the passed name in the name space.
284433d6423SLionel Sambuc  *              Log an error if name not found in Exec mode.
285433d6423SLionel Sambuc  *
286433d6423SLionel Sambuc  * MUTEX:       Assumes namespace is locked.
287433d6423SLionel Sambuc  *
288433d6423SLionel Sambuc  ******************************************************************************/
289433d6423SLionel Sambuc 
290433d6423SLionel Sambuc ACPI_STATUS
AcpiNsLookup(ACPI_GENERIC_STATE * ScopeInfo,char * Pathname,ACPI_OBJECT_TYPE Type,ACPI_INTERPRETER_MODE InterpreterMode,UINT32 Flags,ACPI_WALK_STATE * WalkState,ACPI_NAMESPACE_NODE ** ReturnNode)291433d6423SLionel Sambuc AcpiNsLookup (
292433d6423SLionel Sambuc     ACPI_GENERIC_STATE      *ScopeInfo,
293433d6423SLionel Sambuc     char                    *Pathname,
294433d6423SLionel Sambuc     ACPI_OBJECT_TYPE        Type,
295433d6423SLionel Sambuc     ACPI_INTERPRETER_MODE   InterpreterMode,
296433d6423SLionel Sambuc     UINT32                  Flags,
297433d6423SLionel Sambuc     ACPI_WALK_STATE         *WalkState,
298433d6423SLionel Sambuc     ACPI_NAMESPACE_NODE     **ReturnNode)
299433d6423SLionel Sambuc {
300433d6423SLionel Sambuc     ACPI_STATUS             Status;
301433d6423SLionel Sambuc     char                    *Path = Pathname;
302433d6423SLionel Sambuc     ACPI_NAMESPACE_NODE     *PrefixNode;
303433d6423SLionel Sambuc     ACPI_NAMESPACE_NODE     *CurrentNode = NULL;
304433d6423SLionel Sambuc     ACPI_NAMESPACE_NODE     *ThisNode = NULL;
305433d6423SLionel Sambuc     UINT32                  NumSegments;
306433d6423SLionel Sambuc     UINT32                  NumCarats;
307433d6423SLionel Sambuc     ACPI_NAME               SimpleName;
308433d6423SLionel Sambuc     ACPI_OBJECT_TYPE        TypeToCheckFor;
309433d6423SLionel Sambuc     ACPI_OBJECT_TYPE        ThisSearchType;
310433d6423SLionel Sambuc     UINT32                  SearchParentFlag = ACPI_NS_SEARCH_PARENT;
311433d6423SLionel Sambuc     UINT32                  LocalFlags;
312433d6423SLionel Sambuc 
313433d6423SLionel Sambuc 
314433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (NsLookup);
315433d6423SLionel Sambuc 
316433d6423SLionel Sambuc 
317433d6423SLionel Sambuc     if (!ReturnNode)
318433d6423SLionel Sambuc     {
319433d6423SLionel Sambuc         return_ACPI_STATUS (AE_BAD_PARAMETER);
320433d6423SLionel Sambuc     }
321433d6423SLionel Sambuc 
322433d6423SLionel Sambuc     LocalFlags = Flags & ~(ACPI_NS_ERROR_IF_FOUND | ACPI_NS_SEARCH_PARENT);
323433d6423SLionel Sambuc     *ReturnNode = ACPI_ENTRY_NOT_FOUND;
324433d6423SLionel Sambuc     AcpiGbl_NsLookupCount++;
325433d6423SLionel Sambuc 
326433d6423SLionel Sambuc     if (!AcpiGbl_RootNode)
327433d6423SLionel Sambuc     {
328433d6423SLionel Sambuc         return_ACPI_STATUS (AE_NO_NAMESPACE);
329433d6423SLionel Sambuc     }
330433d6423SLionel Sambuc 
331433d6423SLionel Sambuc     /* Get the prefix scope. A null scope means use the root scope */
332433d6423SLionel Sambuc 
333433d6423SLionel Sambuc     if ((!ScopeInfo) ||
334433d6423SLionel Sambuc         (!ScopeInfo->Scope.Node))
335433d6423SLionel Sambuc     {
336433d6423SLionel Sambuc         ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
337433d6423SLionel Sambuc             "Null scope prefix, using root node (%p)\n",
338433d6423SLionel Sambuc             AcpiGbl_RootNode));
339433d6423SLionel Sambuc 
340433d6423SLionel Sambuc         PrefixNode = AcpiGbl_RootNode;
341433d6423SLionel Sambuc     }
342433d6423SLionel Sambuc     else
343433d6423SLionel Sambuc     {
344433d6423SLionel Sambuc         PrefixNode = ScopeInfo->Scope.Node;
345433d6423SLionel Sambuc         if (ACPI_GET_DESCRIPTOR_TYPE (PrefixNode) != ACPI_DESC_TYPE_NAMED)
346433d6423SLionel Sambuc         {
347433d6423SLionel Sambuc             ACPI_ERROR ((AE_INFO, "%p is not a namespace node [%s]",
348433d6423SLionel Sambuc                 PrefixNode, AcpiUtGetDescriptorName (PrefixNode)));
349433d6423SLionel Sambuc             return_ACPI_STATUS (AE_AML_INTERNAL);
350433d6423SLionel Sambuc         }
351433d6423SLionel Sambuc 
352433d6423SLionel Sambuc         if (!(Flags & ACPI_NS_PREFIX_IS_SCOPE))
353433d6423SLionel Sambuc         {
354433d6423SLionel Sambuc             /*
355433d6423SLionel Sambuc              * This node might not be a actual "scope" node (such as a
356433d6423SLionel Sambuc              * Device/Method, etc.)  It could be a Package or other object
357433d6423SLionel Sambuc              * node. Backup up the tree to find the containing scope node.
358433d6423SLionel Sambuc              */
359433d6423SLionel Sambuc             while (!AcpiNsOpensScope (PrefixNode->Type) &&
360433d6423SLionel Sambuc                     PrefixNode->Type != ACPI_TYPE_ANY)
361433d6423SLionel Sambuc             {
362433d6423SLionel Sambuc                 PrefixNode = PrefixNode->Parent;
363433d6423SLionel Sambuc             }
364433d6423SLionel Sambuc         }
365433d6423SLionel Sambuc     }
366433d6423SLionel Sambuc 
367433d6423SLionel Sambuc     /* Save type. TBD: may be no longer necessary */
368433d6423SLionel Sambuc 
369433d6423SLionel Sambuc     TypeToCheckFor = Type;
370433d6423SLionel Sambuc 
371433d6423SLionel Sambuc     /*
372433d6423SLionel Sambuc      * Begin examination of the actual pathname
373433d6423SLionel Sambuc      */
374433d6423SLionel Sambuc     if (!Pathname)
375433d6423SLionel Sambuc     {
376433d6423SLionel Sambuc         /* A Null NamePath is allowed and refers to the root */
377433d6423SLionel Sambuc 
378433d6423SLionel Sambuc         NumSegments = 0;
379433d6423SLionel Sambuc         ThisNode = AcpiGbl_RootNode;
380433d6423SLionel Sambuc         Path = "";
381433d6423SLionel Sambuc 
382433d6423SLionel Sambuc         ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
383433d6423SLionel Sambuc             "Null Pathname (Zero segments), Flags=%X\n", Flags));
384433d6423SLionel Sambuc     }
385433d6423SLionel Sambuc     else
386433d6423SLionel Sambuc     {
387433d6423SLionel Sambuc         /*
388433d6423SLionel Sambuc          * Name pointer is valid (and must be in internal name format)
389433d6423SLionel Sambuc          *
390433d6423SLionel Sambuc          * Check for scope prefixes:
391433d6423SLionel Sambuc          *
392433d6423SLionel Sambuc          * As represented in the AML stream, a namepath consists of an
393433d6423SLionel Sambuc          * optional scope prefix followed by a name segment part.
394433d6423SLionel Sambuc          *
395433d6423SLionel Sambuc          * If present, the scope prefix is either a Root Prefix (in
396433d6423SLionel Sambuc          * which case the name is fully qualified), or one or more
397433d6423SLionel Sambuc          * Parent Prefixes (in which case the name's scope is relative
398433d6423SLionel Sambuc          * to the current scope).
399433d6423SLionel Sambuc          */
400433d6423SLionel Sambuc         if (*Path == (UINT8) AML_ROOT_PREFIX)
401433d6423SLionel Sambuc         {
402433d6423SLionel Sambuc             /* Pathname is fully qualified, start from the root */
403433d6423SLionel Sambuc 
404433d6423SLionel Sambuc             ThisNode = AcpiGbl_RootNode;
405433d6423SLionel Sambuc             SearchParentFlag = ACPI_NS_NO_UPSEARCH;
406433d6423SLionel Sambuc 
407433d6423SLionel Sambuc             /* Point to name segment part */
408433d6423SLionel Sambuc 
409433d6423SLionel Sambuc             Path++;
410433d6423SLionel Sambuc 
411433d6423SLionel Sambuc             ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
412433d6423SLionel Sambuc                 "Path is absolute from root [%p]\n", ThisNode));
413433d6423SLionel Sambuc         }
414433d6423SLionel Sambuc         else
415433d6423SLionel Sambuc         {
416433d6423SLionel Sambuc             /* Pathname is relative to current scope, start there */
417433d6423SLionel Sambuc 
418433d6423SLionel Sambuc             ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
419433d6423SLionel Sambuc                 "Searching relative to prefix scope [%4.4s] (%p)\n",
420433d6423SLionel Sambuc                 AcpiUtGetNodeName (PrefixNode), PrefixNode));
421433d6423SLionel Sambuc 
422433d6423SLionel Sambuc             /*
423433d6423SLionel Sambuc              * Handle multiple Parent Prefixes (carat) by just getting
424433d6423SLionel Sambuc              * the parent node for each prefix instance.
425433d6423SLionel Sambuc              */
426433d6423SLionel Sambuc             ThisNode = PrefixNode;
427433d6423SLionel Sambuc             NumCarats = 0;
428433d6423SLionel Sambuc             while (*Path == (UINT8) AML_PARENT_PREFIX)
429433d6423SLionel Sambuc             {
430433d6423SLionel Sambuc                 /* Name is fully qualified, no search rules apply */
431433d6423SLionel Sambuc 
432433d6423SLionel Sambuc                 SearchParentFlag = ACPI_NS_NO_UPSEARCH;
433433d6423SLionel Sambuc 
434433d6423SLionel Sambuc                 /*
435433d6423SLionel Sambuc                  * Point past this prefix to the name segment
436433d6423SLionel Sambuc                  * part or the next Parent Prefix
437433d6423SLionel Sambuc                  */
438433d6423SLionel Sambuc                 Path++;
439433d6423SLionel Sambuc 
440433d6423SLionel Sambuc                 /* Backup to the parent node */
441433d6423SLionel Sambuc 
442433d6423SLionel Sambuc                 NumCarats++;
443433d6423SLionel Sambuc                 ThisNode = ThisNode->Parent;
444433d6423SLionel Sambuc                 if (!ThisNode)
445433d6423SLionel Sambuc                 {
446433d6423SLionel Sambuc                     /* Current scope has no parent scope */
447433d6423SLionel Sambuc 
448433d6423SLionel Sambuc                     ACPI_ERROR ((AE_INFO,
449*29492bb7SDavid van Moolenbroek                         "%s: Path has too many parent prefixes (^) "
450*29492bb7SDavid van Moolenbroek                         "- reached beyond root node", Pathname));
451433d6423SLionel Sambuc                     return_ACPI_STATUS (AE_NOT_FOUND);
452433d6423SLionel Sambuc                 }
453433d6423SLionel Sambuc             }
454433d6423SLionel Sambuc 
455433d6423SLionel Sambuc             if (SearchParentFlag == ACPI_NS_NO_UPSEARCH)
456433d6423SLionel Sambuc             {
457433d6423SLionel Sambuc                 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
458433d6423SLionel Sambuc                     "Search scope is [%4.4s], path has %u carat(s)\n",
459433d6423SLionel Sambuc                     AcpiUtGetNodeName (ThisNode), NumCarats));
460433d6423SLionel Sambuc             }
461433d6423SLionel Sambuc         }
462433d6423SLionel Sambuc 
463433d6423SLionel Sambuc         /*
464433d6423SLionel Sambuc          * Determine the number of ACPI name segments in this pathname.
465433d6423SLionel Sambuc          *
466433d6423SLionel Sambuc          * The segment part consists of either:
467433d6423SLionel Sambuc          *  - A Null name segment (0)
468433d6423SLionel Sambuc          *  - A DualNamePrefix followed by two 4-byte name segments
469433d6423SLionel Sambuc          *  - A MultiNamePrefix followed by a byte indicating the
470433d6423SLionel Sambuc          *      number of segments and the segments themselves.
471433d6423SLionel Sambuc          *  - A single 4-byte name segment
472433d6423SLionel Sambuc          *
473433d6423SLionel Sambuc          * Examine the name prefix opcode, if any, to determine the number of
474433d6423SLionel Sambuc          * segments.
475433d6423SLionel Sambuc          */
476433d6423SLionel Sambuc         switch (*Path)
477433d6423SLionel Sambuc         {
478433d6423SLionel Sambuc         case 0:
479433d6423SLionel Sambuc             /*
480433d6423SLionel Sambuc              * Null name after a root or parent prefixes. We already
481433d6423SLionel Sambuc              * have the correct target node and there are no name segments.
482433d6423SLionel Sambuc              */
483433d6423SLionel Sambuc             NumSegments  = 0;
484433d6423SLionel Sambuc             Type = ThisNode->Type;
485433d6423SLionel Sambuc 
486433d6423SLionel Sambuc             ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
487433d6423SLionel Sambuc                 "Prefix-only Pathname (Zero name segments), Flags=%X\n",
488433d6423SLionel Sambuc                 Flags));
489433d6423SLionel Sambuc             break;
490433d6423SLionel Sambuc 
491433d6423SLionel Sambuc         case AML_DUAL_NAME_PREFIX:
492433d6423SLionel Sambuc 
493433d6423SLionel Sambuc             /* More than one NameSeg, search rules do not apply */
494433d6423SLionel Sambuc 
495433d6423SLionel Sambuc             SearchParentFlag = ACPI_NS_NO_UPSEARCH;
496433d6423SLionel Sambuc 
497433d6423SLionel Sambuc             /* Two segments, point to first name segment */
498433d6423SLionel Sambuc 
499433d6423SLionel Sambuc             NumSegments = 2;
500433d6423SLionel Sambuc             Path++;
501433d6423SLionel Sambuc 
502433d6423SLionel Sambuc             ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
503433d6423SLionel Sambuc                 "Dual Pathname (2 segments, Flags=%X)\n", Flags));
504433d6423SLionel Sambuc             break;
505433d6423SLionel Sambuc 
506433d6423SLionel Sambuc         case AML_MULTI_NAME_PREFIX_OP:
507433d6423SLionel Sambuc 
508433d6423SLionel Sambuc             /* More than one NameSeg, search rules do not apply */
509433d6423SLionel Sambuc 
510433d6423SLionel Sambuc             SearchParentFlag = ACPI_NS_NO_UPSEARCH;
511433d6423SLionel Sambuc 
512433d6423SLionel Sambuc             /* Extract segment count, point to first name segment */
513433d6423SLionel Sambuc 
514433d6423SLionel Sambuc             Path++;
515433d6423SLionel Sambuc             NumSegments = (UINT32) (UINT8) *Path;
516433d6423SLionel Sambuc             Path++;
517433d6423SLionel Sambuc 
518433d6423SLionel Sambuc             ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
519433d6423SLionel Sambuc                 "Multi Pathname (%u Segments, Flags=%X)\n",
520433d6423SLionel Sambuc                 NumSegments, Flags));
521433d6423SLionel Sambuc             break;
522433d6423SLionel Sambuc 
523433d6423SLionel Sambuc         default:
524433d6423SLionel Sambuc             /*
525433d6423SLionel Sambuc              * Not a Null name, no Dual or Multi prefix, hence there is
526433d6423SLionel Sambuc              * only one name segment and Pathname is already pointing to it.
527433d6423SLionel Sambuc              */
528433d6423SLionel Sambuc             NumSegments = 1;
529433d6423SLionel Sambuc 
530433d6423SLionel Sambuc             ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
531433d6423SLionel Sambuc                 "Simple Pathname (1 segment, Flags=%X)\n", Flags));
532433d6423SLionel Sambuc             break;
533433d6423SLionel Sambuc         }
534433d6423SLionel Sambuc 
535433d6423SLionel Sambuc         ACPI_DEBUG_EXEC (AcpiNsPrintPathname (NumSegments, Path));
536433d6423SLionel Sambuc     }
537433d6423SLionel Sambuc 
538433d6423SLionel Sambuc 
539433d6423SLionel Sambuc     /*
540433d6423SLionel Sambuc      * Search namespace for each segment of the name. Loop through and
541433d6423SLionel Sambuc      * verify (or add to the namespace) each name segment.
542433d6423SLionel Sambuc      *
543433d6423SLionel Sambuc      * The object type is significant only at the last name
544433d6423SLionel Sambuc      * segment. (We don't care about the types along the path, only
545433d6423SLionel Sambuc      * the type of the final target object.)
546433d6423SLionel Sambuc      */
547433d6423SLionel Sambuc     ThisSearchType = ACPI_TYPE_ANY;
548433d6423SLionel Sambuc     CurrentNode = ThisNode;
549433d6423SLionel Sambuc     while (NumSegments && CurrentNode)
550433d6423SLionel Sambuc     {
551433d6423SLionel Sambuc         NumSegments--;
552433d6423SLionel Sambuc         if (!NumSegments)
553433d6423SLionel Sambuc         {
554433d6423SLionel Sambuc             /* This is the last segment, enable typechecking */
555433d6423SLionel Sambuc 
556433d6423SLionel Sambuc             ThisSearchType = Type;
557433d6423SLionel Sambuc 
558433d6423SLionel Sambuc             /*
559433d6423SLionel Sambuc              * Only allow automatic parent search (search rules) if the caller
560433d6423SLionel Sambuc              * requested it AND we have a single, non-fully-qualified NameSeg
561433d6423SLionel Sambuc              */
562433d6423SLionel Sambuc             if ((SearchParentFlag != ACPI_NS_NO_UPSEARCH) &&
563433d6423SLionel Sambuc                 (Flags & ACPI_NS_SEARCH_PARENT))
564433d6423SLionel Sambuc             {
565433d6423SLionel Sambuc                 LocalFlags |= ACPI_NS_SEARCH_PARENT;
566433d6423SLionel Sambuc             }
567433d6423SLionel Sambuc 
568433d6423SLionel Sambuc             /* Set error flag according to caller */
569433d6423SLionel Sambuc 
570433d6423SLionel Sambuc             if (Flags & ACPI_NS_ERROR_IF_FOUND)
571433d6423SLionel Sambuc             {
572433d6423SLionel Sambuc                 LocalFlags |= ACPI_NS_ERROR_IF_FOUND;
573433d6423SLionel Sambuc             }
574433d6423SLionel Sambuc         }
575433d6423SLionel Sambuc 
576433d6423SLionel Sambuc         /* Extract one ACPI name from the front of the pathname */
577433d6423SLionel Sambuc 
578433d6423SLionel Sambuc         ACPI_MOVE_32_TO_32 (&SimpleName, Path);
579433d6423SLionel Sambuc 
580433d6423SLionel Sambuc         /* Try to find the single (4 character) ACPI name */
581433d6423SLionel Sambuc 
582433d6423SLionel Sambuc         Status = AcpiNsSearchAndEnter (SimpleName, WalkState, CurrentNode,
583433d6423SLionel Sambuc                     InterpreterMode, ThisSearchType, LocalFlags, &ThisNode);
584433d6423SLionel Sambuc         if (ACPI_FAILURE (Status))
585433d6423SLionel Sambuc         {
586433d6423SLionel Sambuc             if (Status == AE_NOT_FOUND)
587433d6423SLionel Sambuc             {
588433d6423SLionel Sambuc                 /* Name not found in ACPI namespace */
589433d6423SLionel Sambuc 
590433d6423SLionel Sambuc                 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
591433d6423SLionel Sambuc                     "Name [%4.4s] not found in scope [%4.4s] %p\n",
592433d6423SLionel Sambuc                     (char *) &SimpleName, (char *) &CurrentNode->Name,
593433d6423SLionel Sambuc                     CurrentNode));
594433d6423SLionel Sambuc             }
595433d6423SLionel Sambuc 
596433d6423SLionel Sambuc             *ReturnNode = ThisNode;
597433d6423SLionel Sambuc             return_ACPI_STATUS (Status);
598433d6423SLionel Sambuc         }
599433d6423SLionel Sambuc 
600433d6423SLionel Sambuc         /* More segments to follow? */
601433d6423SLionel Sambuc 
602433d6423SLionel Sambuc         if (NumSegments > 0)
603433d6423SLionel Sambuc         {
604433d6423SLionel Sambuc             /*
605433d6423SLionel Sambuc              * If we have an alias to an object that opens a scope (such as a
606433d6423SLionel Sambuc              * device or processor), we need to dereference the alias here so
607433d6423SLionel Sambuc              * that we can access any children of the original node (via the
608433d6423SLionel Sambuc              * remaining segments).
609433d6423SLionel Sambuc              */
610433d6423SLionel Sambuc             if (ThisNode->Type == ACPI_TYPE_LOCAL_ALIAS)
611433d6423SLionel Sambuc             {
612433d6423SLionel Sambuc                 if (!ThisNode->Object)
613433d6423SLionel Sambuc                 {
614433d6423SLionel Sambuc                     return_ACPI_STATUS (AE_NOT_EXIST);
615433d6423SLionel Sambuc                 }
616433d6423SLionel Sambuc 
617433d6423SLionel Sambuc                 if (AcpiNsOpensScope (((ACPI_NAMESPACE_NODE *)
618433d6423SLionel Sambuc                         ThisNode->Object)->Type))
619433d6423SLionel Sambuc                 {
620433d6423SLionel Sambuc                     ThisNode = (ACPI_NAMESPACE_NODE *) ThisNode->Object;
621433d6423SLionel Sambuc                 }
622433d6423SLionel Sambuc             }
623433d6423SLionel Sambuc         }
624433d6423SLionel Sambuc 
625433d6423SLionel Sambuc         /* Special handling for the last segment (NumSegments == 0) */
626433d6423SLionel Sambuc 
627433d6423SLionel Sambuc         else
628433d6423SLionel Sambuc         {
629433d6423SLionel Sambuc             /*
630433d6423SLionel Sambuc              * Sanity typecheck of the target object:
631433d6423SLionel Sambuc              *
632433d6423SLionel Sambuc              * If 1) This is the last segment (NumSegments == 0)
633433d6423SLionel Sambuc              *    2) And we are looking for a specific type
634433d6423SLionel Sambuc              *       (Not checking for TYPE_ANY)
635433d6423SLionel Sambuc              *    3) Which is not an alias
636433d6423SLionel Sambuc              *    4) Which is not a local type (TYPE_SCOPE)
637433d6423SLionel Sambuc              *    5) And the type of target object is known (not TYPE_ANY)
638433d6423SLionel Sambuc              *    6) And target object does not match what we are looking for
639433d6423SLionel Sambuc              *
640433d6423SLionel Sambuc              * Then we have a type mismatch. Just warn and ignore it.
641433d6423SLionel Sambuc              */
642433d6423SLionel Sambuc             if ((TypeToCheckFor != ACPI_TYPE_ANY)                   &&
643433d6423SLionel Sambuc                 (TypeToCheckFor != ACPI_TYPE_LOCAL_ALIAS)           &&
644433d6423SLionel Sambuc                 (TypeToCheckFor != ACPI_TYPE_LOCAL_METHOD_ALIAS)    &&
645433d6423SLionel Sambuc                 (TypeToCheckFor != ACPI_TYPE_LOCAL_SCOPE)           &&
646433d6423SLionel Sambuc                 (ThisNode->Type != ACPI_TYPE_ANY)                   &&
647433d6423SLionel Sambuc                 (ThisNode->Type != TypeToCheckFor))
648433d6423SLionel Sambuc             {
649433d6423SLionel Sambuc                 /* Complain about a type mismatch */
650433d6423SLionel Sambuc 
651433d6423SLionel Sambuc                 ACPI_WARNING ((AE_INFO,
652433d6423SLionel Sambuc                     "NsLookup: Type mismatch on %4.4s (%s), searching for (%s)",
653433d6423SLionel Sambuc                     ACPI_CAST_PTR (char, &SimpleName),
654433d6423SLionel Sambuc                     AcpiUtGetTypeName (ThisNode->Type),
655433d6423SLionel Sambuc                     AcpiUtGetTypeName (TypeToCheckFor)));
656433d6423SLionel Sambuc             }
657433d6423SLionel Sambuc 
658433d6423SLionel Sambuc             /*
659433d6423SLionel Sambuc              * If this is the last name segment and we are not looking for a
660433d6423SLionel Sambuc              * specific type, but the type of found object is known, use that
661433d6423SLionel Sambuc              * type to (later) see if it opens a scope.
662433d6423SLionel Sambuc              */
663433d6423SLionel Sambuc             if (Type == ACPI_TYPE_ANY)
664433d6423SLionel Sambuc             {
665433d6423SLionel Sambuc                 Type = ThisNode->Type;
666433d6423SLionel Sambuc             }
667433d6423SLionel Sambuc         }
668433d6423SLionel Sambuc 
669433d6423SLionel Sambuc         /* Point to next name segment and make this node current */
670433d6423SLionel Sambuc 
671433d6423SLionel Sambuc         Path += ACPI_NAME_SIZE;
672433d6423SLionel Sambuc         CurrentNode = ThisNode;
673433d6423SLionel Sambuc     }
674433d6423SLionel Sambuc 
675433d6423SLionel Sambuc     /* Always check if we need to open a new scope */
676433d6423SLionel Sambuc 
677433d6423SLionel Sambuc     if (!(Flags & ACPI_NS_DONT_OPEN_SCOPE) && (WalkState))
678433d6423SLionel Sambuc     {
679433d6423SLionel Sambuc         /*
680433d6423SLionel Sambuc          * If entry is a type which opens a scope, push the new scope on the
681433d6423SLionel Sambuc          * scope stack.
682433d6423SLionel Sambuc          */
683433d6423SLionel Sambuc         if (AcpiNsOpensScope (Type))
684433d6423SLionel Sambuc         {
685433d6423SLionel Sambuc             Status = AcpiDsScopeStackPush (ThisNode, Type, WalkState);
686433d6423SLionel Sambuc             if (ACPI_FAILURE (Status))
687433d6423SLionel Sambuc             {
688433d6423SLionel Sambuc                 return_ACPI_STATUS (Status);
689433d6423SLionel Sambuc             }
690433d6423SLionel Sambuc         }
691433d6423SLionel Sambuc     }
692433d6423SLionel Sambuc 
693433d6423SLionel Sambuc     *ReturnNode = ThisNode;
694433d6423SLionel Sambuc     return_ACPI_STATUS (AE_OK);
695433d6423SLionel Sambuc }
696