xref: /minix3/minix/drivers/power/acpi/namespace/nssearch.c (revision 29492bb71c7148a089a5afafa0c99409161218df)
1433d6423SLionel Sambuc /*******************************************************************************
2433d6423SLionel Sambuc  *
3433d6423SLionel Sambuc  * Module Name: nssearch - Namespace search
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 "acnamesp.h"
47433d6423SLionel Sambuc 
48433d6423SLionel Sambuc #ifdef ACPI_ASL_COMPILER
49433d6423SLionel Sambuc #include "amlcode.h"
50433d6423SLionel Sambuc #endif
51433d6423SLionel Sambuc 
52433d6423SLionel Sambuc #define _COMPONENT          ACPI_NAMESPACE
53433d6423SLionel Sambuc         ACPI_MODULE_NAME    ("nssearch")
54433d6423SLionel Sambuc 
55433d6423SLionel Sambuc /* Local prototypes */
56433d6423SLionel Sambuc 
57433d6423SLionel Sambuc static ACPI_STATUS
58433d6423SLionel Sambuc AcpiNsSearchParentTree (
59433d6423SLionel Sambuc     UINT32                  TargetName,
60433d6423SLionel Sambuc     ACPI_NAMESPACE_NODE     *Node,
61433d6423SLionel Sambuc     ACPI_OBJECT_TYPE        Type,
62433d6423SLionel Sambuc     ACPI_NAMESPACE_NODE     **ReturnNode);
63433d6423SLionel Sambuc 
64433d6423SLionel Sambuc 
65433d6423SLionel Sambuc /*******************************************************************************
66433d6423SLionel Sambuc  *
67433d6423SLionel Sambuc  * FUNCTION:    AcpiNsSearchOneScope
68433d6423SLionel Sambuc  *
69433d6423SLionel Sambuc  * PARAMETERS:  TargetName      - Ascii ACPI name to search for
70433d6423SLionel Sambuc  *              ParentNode      - Starting node where search will begin
71433d6423SLionel Sambuc  *              Type            - Object type to match
72433d6423SLionel Sambuc  *              ReturnNode      - Where the matched Named obj is returned
73433d6423SLionel Sambuc  *
74433d6423SLionel Sambuc  * RETURN:      Status
75433d6423SLionel Sambuc  *
76433d6423SLionel Sambuc  * DESCRIPTION: Search a single level of the namespace. Performs a
77433d6423SLionel Sambuc  *              simple search of the specified level, and does not add
78433d6423SLionel Sambuc  *              entries or search parents.
79433d6423SLionel Sambuc  *
80433d6423SLionel Sambuc  *
81433d6423SLionel Sambuc  *      Named object lists are built (and subsequently dumped) in the
82433d6423SLionel Sambuc  *      order in which the names are encountered during the namespace load;
83433d6423SLionel Sambuc  *
84433d6423SLionel Sambuc  *      All namespace searching is linear in this implementation, but
85433d6423SLionel Sambuc  *      could be easily modified to support any improved search
86433d6423SLionel Sambuc  *      algorithm. However, the linear search was chosen for simplicity
87433d6423SLionel Sambuc  *      and because the trees are small and the other interpreter
88433d6423SLionel Sambuc  *      execution overhead is relatively high.
89433d6423SLionel Sambuc  *
90433d6423SLionel Sambuc  *      Note: CPU execution analysis has shown that the AML interpreter spends
91433d6423SLionel Sambuc  *      a very small percentage of its time searching the namespace. Therefore,
92433d6423SLionel Sambuc  *      the linear search seems to be sufficient, as there would seem to be
93433d6423SLionel Sambuc  *      little value in improving the search.
94433d6423SLionel Sambuc  *
95433d6423SLionel Sambuc  ******************************************************************************/
96433d6423SLionel Sambuc 
97433d6423SLionel Sambuc ACPI_STATUS
AcpiNsSearchOneScope(UINT32 TargetName,ACPI_NAMESPACE_NODE * ParentNode,ACPI_OBJECT_TYPE Type,ACPI_NAMESPACE_NODE ** ReturnNode)98433d6423SLionel Sambuc AcpiNsSearchOneScope (
99433d6423SLionel Sambuc     UINT32                  TargetName,
100433d6423SLionel Sambuc     ACPI_NAMESPACE_NODE     *ParentNode,
101433d6423SLionel Sambuc     ACPI_OBJECT_TYPE        Type,
102433d6423SLionel Sambuc     ACPI_NAMESPACE_NODE     **ReturnNode)
103433d6423SLionel Sambuc {
104433d6423SLionel Sambuc     ACPI_NAMESPACE_NODE     *Node;
105433d6423SLionel Sambuc 
106433d6423SLionel Sambuc 
107433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (NsSearchOneScope);
108433d6423SLionel Sambuc 
109433d6423SLionel Sambuc 
110433d6423SLionel Sambuc #ifdef ACPI_DEBUG_OUTPUT
111433d6423SLionel Sambuc     if (ACPI_LV_NAMES & AcpiDbgLevel)
112433d6423SLionel Sambuc     {
113433d6423SLionel Sambuc         char                *ScopeName;
114433d6423SLionel Sambuc 
115433d6423SLionel Sambuc         ScopeName = AcpiNsGetExternalPathname (ParentNode);
116433d6423SLionel Sambuc         if (ScopeName)
117433d6423SLionel Sambuc         {
118433d6423SLionel Sambuc             ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
119433d6423SLionel Sambuc                 "Searching %s (%p) For [%4.4s] (%s)\n",
120433d6423SLionel Sambuc                 ScopeName, ParentNode, ACPI_CAST_PTR (char, &TargetName),
121433d6423SLionel Sambuc                 AcpiUtGetTypeName (Type)));
122433d6423SLionel Sambuc 
123433d6423SLionel Sambuc             ACPI_FREE (ScopeName);
124433d6423SLionel Sambuc         }
125433d6423SLionel Sambuc     }
126433d6423SLionel Sambuc #endif
127433d6423SLionel Sambuc 
128433d6423SLionel Sambuc     /*
129433d6423SLionel Sambuc      * Search for name at this namespace level, which is to say that we
130433d6423SLionel Sambuc      * must search for the name among the children of this object
131433d6423SLionel Sambuc      */
132433d6423SLionel Sambuc     Node = ParentNode->Child;
133433d6423SLionel Sambuc     while (Node)
134433d6423SLionel Sambuc     {
135433d6423SLionel Sambuc         /* Check for match against the name */
136433d6423SLionel Sambuc 
137433d6423SLionel Sambuc         if (Node->Name.Integer == TargetName)
138433d6423SLionel Sambuc         {
139433d6423SLionel Sambuc             /* Resolve a control method alias if any */
140433d6423SLionel Sambuc 
141433d6423SLionel Sambuc             if (AcpiNsGetType (Node) == ACPI_TYPE_LOCAL_METHOD_ALIAS)
142433d6423SLionel Sambuc             {
143433d6423SLionel Sambuc                 Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Node->Object);
144433d6423SLionel Sambuc             }
145433d6423SLionel Sambuc 
146433d6423SLionel Sambuc             /* Found matching entry */
147433d6423SLionel Sambuc 
148433d6423SLionel Sambuc             ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
149433d6423SLionel Sambuc                 "Name [%4.4s] (%s) %p found in scope [%4.4s] %p\n",
150433d6423SLionel Sambuc                 ACPI_CAST_PTR (char, &TargetName),
151433d6423SLionel Sambuc                 AcpiUtGetTypeName (Node->Type),
152433d6423SLionel Sambuc                 Node, AcpiUtGetNodeName (ParentNode), ParentNode));
153433d6423SLionel Sambuc 
154433d6423SLionel Sambuc             *ReturnNode = Node;
155433d6423SLionel Sambuc             return_ACPI_STATUS (AE_OK);
156433d6423SLionel Sambuc         }
157433d6423SLionel Sambuc 
158433d6423SLionel Sambuc         /* Didn't match name, move on to the next peer object */
159433d6423SLionel Sambuc 
160433d6423SLionel Sambuc         Node = Node->Peer;
161433d6423SLionel Sambuc     }
162433d6423SLionel Sambuc 
163433d6423SLionel Sambuc     /* Searched entire namespace level, not found */
164433d6423SLionel Sambuc 
165433d6423SLionel Sambuc     ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
166433d6423SLionel Sambuc         "Name [%4.4s] (%s) not found in search in scope [%4.4s] "
167433d6423SLionel Sambuc         "%p first child %p\n",
168433d6423SLionel Sambuc         ACPI_CAST_PTR (char, &TargetName), AcpiUtGetTypeName (Type),
169433d6423SLionel Sambuc         AcpiUtGetNodeName (ParentNode), ParentNode, ParentNode->Child));
170433d6423SLionel Sambuc 
171433d6423SLionel Sambuc     return_ACPI_STATUS (AE_NOT_FOUND);
172433d6423SLionel Sambuc }
173433d6423SLionel Sambuc 
174433d6423SLionel Sambuc 
175433d6423SLionel Sambuc /*******************************************************************************
176433d6423SLionel Sambuc  *
177433d6423SLionel Sambuc  * FUNCTION:    AcpiNsSearchParentTree
178433d6423SLionel Sambuc  *
179433d6423SLionel Sambuc  * PARAMETERS:  TargetName      - Ascii ACPI name to search for
180433d6423SLionel Sambuc  *              Node            - Starting node where search will begin
181433d6423SLionel Sambuc  *              Type            - Object type to match
182433d6423SLionel Sambuc  *              ReturnNode      - Where the matched Node is returned
183433d6423SLionel Sambuc  *
184433d6423SLionel Sambuc  * RETURN:      Status
185433d6423SLionel Sambuc  *
186433d6423SLionel Sambuc  * DESCRIPTION: Called when a name has not been found in the current namespace
187433d6423SLionel Sambuc  *              level. Before adding it or giving up, ACPI scope rules require
188433d6423SLionel Sambuc  *              searching enclosing scopes in cases identified by AcpiNsLocal().
189433d6423SLionel Sambuc  *
190433d6423SLionel Sambuc  *              "A name is located by finding the matching name in the current
191433d6423SLionel Sambuc  *              name space, and then in the parent name space. If the parent
192433d6423SLionel Sambuc  *              name space does not contain the name, the search continues
193433d6423SLionel Sambuc  *              recursively until either the name is found or the name space
194433d6423SLionel Sambuc  *              does not have a parent (the root of the name space). This
195433d6423SLionel Sambuc  *              indicates that the name is not found" (From ACPI Specification,
196433d6423SLionel Sambuc  *              section 5.3)
197433d6423SLionel Sambuc  *
198433d6423SLionel Sambuc  ******************************************************************************/
199433d6423SLionel Sambuc 
200433d6423SLionel Sambuc static ACPI_STATUS
AcpiNsSearchParentTree(UINT32 TargetName,ACPI_NAMESPACE_NODE * Node,ACPI_OBJECT_TYPE Type,ACPI_NAMESPACE_NODE ** ReturnNode)201433d6423SLionel Sambuc AcpiNsSearchParentTree (
202433d6423SLionel Sambuc     UINT32                  TargetName,
203433d6423SLionel Sambuc     ACPI_NAMESPACE_NODE     *Node,
204433d6423SLionel Sambuc     ACPI_OBJECT_TYPE        Type,
205433d6423SLionel Sambuc     ACPI_NAMESPACE_NODE     **ReturnNode)
206433d6423SLionel Sambuc {
207433d6423SLionel Sambuc     ACPI_STATUS             Status;
208433d6423SLionel Sambuc     ACPI_NAMESPACE_NODE     *ParentNode;
209433d6423SLionel Sambuc 
210433d6423SLionel Sambuc 
211433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (NsSearchParentTree);
212433d6423SLionel Sambuc 
213433d6423SLionel Sambuc 
214433d6423SLionel Sambuc     ParentNode = Node->Parent;
215433d6423SLionel Sambuc 
216433d6423SLionel Sambuc     /*
217433d6423SLionel Sambuc      * If there is no parent (i.e., we are at the root) or type is "local",
218433d6423SLionel Sambuc      * we won't be searching the parent tree.
219433d6423SLionel Sambuc      */
220433d6423SLionel Sambuc     if (!ParentNode)
221433d6423SLionel Sambuc     {
222433d6423SLionel Sambuc         ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "[%4.4s] has no parent\n",
223433d6423SLionel Sambuc             ACPI_CAST_PTR (char, &TargetName)));
224433d6423SLionel Sambuc         return_ACPI_STATUS (AE_NOT_FOUND);
225433d6423SLionel Sambuc     }
226433d6423SLionel Sambuc 
227433d6423SLionel Sambuc     if (AcpiNsLocal (Type))
228433d6423SLionel Sambuc     {
229433d6423SLionel Sambuc         ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
230433d6423SLionel Sambuc             "[%4.4s] type [%s] must be local to this scope (no parent search)\n",
231433d6423SLionel Sambuc             ACPI_CAST_PTR (char, &TargetName), AcpiUtGetTypeName (Type)));
232433d6423SLionel Sambuc         return_ACPI_STATUS (AE_NOT_FOUND);
233433d6423SLionel Sambuc     }
234433d6423SLionel Sambuc 
235433d6423SLionel Sambuc     /* Search the parent tree */
236433d6423SLionel Sambuc 
237433d6423SLionel Sambuc     ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
238433d6423SLionel Sambuc         "Searching parent [%4.4s] for [%4.4s]\n",
239433d6423SLionel Sambuc         AcpiUtGetNodeName (ParentNode), ACPI_CAST_PTR (char, &TargetName)));
240433d6423SLionel Sambuc 
241433d6423SLionel Sambuc     /* Search parents until target is found or we have backed up to the root */
242433d6423SLionel Sambuc 
243433d6423SLionel Sambuc     while (ParentNode)
244433d6423SLionel Sambuc     {
245433d6423SLionel Sambuc         /*
246433d6423SLionel Sambuc          * Search parent scope. Use TYPE_ANY because we don't care about the
247433d6423SLionel Sambuc          * object type at this point, we only care about the existence of
248433d6423SLionel Sambuc          * the actual name we are searching for. Typechecking comes later.
249433d6423SLionel Sambuc          */
250433d6423SLionel Sambuc         Status = AcpiNsSearchOneScope (
251433d6423SLionel Sambuc                     TargetName, ParentNode, ACPI_TYPE_ANY, ReturnNode);
252433d6423SLionel Sambuc         if (ACPI_SUCCESS (Status))
253433d6423SLionel Sambuc         {
254433d6423SLionel Sambuc             return_ACPI_STATUS (Status);
255433d6423SLionel Sambuc         }
256433d6423SLionel Sambuc 
257433d6423SLionel Sambuc         /* Not found here, go up another level (until we reach the root) */
258433d6423SLionel Sambuc 
259433d6423SLionel Sambuc         ParentNode = ParentNode->Parent;
260433d6423SLionel Sambuc     }
261433d6423SLionel Sambuc 
262433d6423SLionel Sambuc     /* Not found in parent tree */
263433d6423SLionel Sambuc 
264433d6423SLionel Sambuc     return_ACPI_STATUS (AE_NOT_FOUND);
265433d6423SLionel Sambuc }
266433d6423SLionel Sambuc 
267433d6423SLionel Sambuc 
268433d6423SLionel Sambuc /*******************************************************************************
269433d6423SLionel Sambuc  *
270433d6423SLionel Sambuc  * FUNCTION:    AcpiNsSearchAndEnter
271433d6423SLionel Sambuc  *
272433d6423SLionel Sambuc  * PARAMETERS:  TargetName          - Ascii ACPI name to search for (4 chars)
273433d6423SLionel Sambuc  *              WalkState           - Current state of the walk
274433d6423SLionel Sambuc  *              Node                - Starting node where search will begin
275433d6423SLionel Sambuc  *              InterpreterMode     - Add names only in ACPI_MODE_LOAD_PASS_x.
276433d6423SLionel Sambuc  *                                    Otherwise,search only.
277433d6423SLionel Sambuc  *              Type                - Object type to match
278433d6423SLionel Sambuc  *              Flags               - Flags describing the search restrictions
279433d6423SLionel Sambuc  *              ReturnNode          - Where the Node is returned
280433d6423SLionel Sambuc  *
281433d6423SLionel Sambuc  * RETURN:      Status
282433d6423SLionel Sambuc  *
283433d6423SLionel Sambuc  * DESCRIPTION: Search for a name segment in a single namespace level,
284433d6423SLionel Sambuc  *              optionally adding it if it is not found. If the passed
285433d6423SLionel Sambuc  *              Type is not Any and the type previously stored in the
286433d6423SLionel Sambuc  *              entry was Any (i.e. unknown), update the stored type.
287433d6423SLionel Sambuc  *
288433d6423SLionel Sambuc  *              In ACPI_IMODE_EXECUTE, search only.
289433d6423SLionel Sambuc  *              In other modes, search and add if not found.
290433d6423SLionel Sambuc  *
291433d6423SLionel Sambuc  ******************************************************************************/
292433d6423SLionel Sambuc 
293433d6423SLionel Sambuc ACPI_STATUS
AcpiNsSearchAndEnter(UINT32 TargetName,ACPI_WALK_STATE * WalkState,ACPI_NAMESPACE_NODE * Node,ACPI_INTERPRETER_MODE InterpreterMode,ACPI_OBJECT_TYPE Type,UINT32 Flags,ACPI_NAMESPACE_NODE ** ReturnNode)294433d6423SLionel Sambuc AcpiNsSearchAndEnter (
295433d6423SLionel Sambuc     UINT32                  TargetName,
296433d6423SLionel Sambuc     ACPI_WALK_STATE         *WalkState,
297433d6423SLionel Sambuc     ACPI_NAMESPACE_NODE     *Node,
298433d6423SLionel Sambuc     ACPI_INTERPRETER_MODE   InterpreterMode,
299433d6423SLionel Sambuc     ACPI_OBJECT_TYPE        Type,
300433d6423SLionel Sambuc     UINT32                  Flags,
301433d6423SLionel Sambuc     ACPI_NAMESPACE_NODE     **ReturnNode)
302433d6423SLionel Sambuc {
303433d6423SLionel Sambuc     ACPI_STATUS             Status;
304433d6423SLionel Sambuc     ACPI_NAMESPACE_NODE     *NewNode;
305433d6423SLionel Sambuc 
306433d6423SLionel Sambuc 
307433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (NsSearchAndEnter);
308433d6423SLionel Sambuc 
309433d6423SLionel Sambuc 
310433d6423SLionel Sambuc     /* Parameter validation */
311433d6423SLionel Sambuc 
312433d6423SLionel Sambuc     if (!Node || !TargetName || !ReturnNode)
313433d6423SLionel Sambuc     {
314433d6423SLionel Sambuc         ACPI_ERROR ((AE_INFO,
315433d6423SLionel Sambuc             "Null parameter: Node %p Name 0x%X ReturnNode %p",
316433d6423SLionel Sambuc             Node, TargetName, ReturnNode));
317433d6423SLionel Sambuc         return_ACPI_STATUS (AE_BAD_PARAMETER);
318433d6423SLionel Sambuc     }
319433d6423SLionel Sambuc 
320433d6423SLionel Sambuc     /*
321433d6423SLionel Sambuc      * Name must consist of valid ACPI characters. We will repair the name if
322433d6423SLionel Sambuc      * necessary because we don't want to abort because of this, but we want
323433d6423SLionel Sambuc      * all namespace names to be printable. A warning message is appropriate.
324433d6423SLionel Sambuc      *
325433d6423SLionel Sambuc      * This issue came up because there are in fact machines that exhibit
326433d6423SLionel Sambuc      * this problem, and we want to be able to enable ACPI support for them,
327433d6423SLionel Sambuc      * even though there are a few bad names.
328433d6423SLionel Sambuc      */
329433d6423SLionel Sambuc     AcpiUtRepairName (ACPI_CAST_PTR (char, &TargetName));
330433d6423SLionel Sambuc 
331433d6423SLionel Sambuc     /* Try to find the name in the namespace level specified by the caller */
332433d6423SLionel Sambuc 
333433d6423SLionel Sambuc     *ReturnNode = ACPI_ENTRY_NOT_FOUND;
334433d6423SLionel Sambuc     Status = AcpiNsSearchOneScope (TargetName, Node, Type, ReturnNode);
335433d6423SLionel Sambuc     if (Status != AE_NOT_FOUND)
336433d6423SLionel Sambuc     {
337433d6423SLionel Sambuc         /*
338433d6423SLionel Sambuc          * If we found it AND the request specifies that a find is an error,
339433d6423SLionel Sambuc          * return the error
340433d6423SLionel Sambuc          */
341433d6423SLionel Sambuc         if ((Status == AE_OK) &&
342433d6423SLionel Sambuc             (Flags & ACPI_NS_ERROR_IF_FOUND))
343433d6423SLionel Sambuc         {
344433d6423SLionel Sambuc             Status = AE_ALREADY_EXISTS;
345433d6423SLionel Sambuc         }
346433d6423SLionel Sambuc 
347433d6423SLionel Sambuc #ifdef ACPI_ASL_COMPILER
348433d6423SLionel Sambuc         if (*ReturnNode && (*ReturnNode)->Type == ACPI_TYPE_ANY)
349433d6423SLionel Sambuc         {
350433d6423SLionel Sambuc             (*ReturnNode)->Flags |= ANOBJ_IS_EXTERNAL;
351433d6423SLionel Sambuc         }
352433d6423SLionel Sambuc #endif
353433d6423SLionel Sambuc 
354433d6423SLionel Sambuc         /* Either found it or there was an error: finished either way */
355433d6423SLionel Sambuc 
356433d6423SLionel Sambuc         return_ACPI_STATUS (Status);
357433d6423SLionel Sambuc     }
358433d6423SLionel Sambuc 
359433d6423SLionel Sambuc     /*
360433d6423SLionel Sambuc      * The name was not found. If we are NOT performing the first pass
361433d6423SLionel Sambuc      * (name entry) of loading the namespace, search the parent tree (all the
362433d6423SLionel Sambuc      * way to the root if necessary.) We don't want to perform the parent
363433d6423SLionel Sambuc      * search when the namespace is actually being loaded. We want to perform
364433d6423SLionel Sambuc      * the search when namespace references are being resolved (load pass 2)
365433d6423SLionel Sambuc      * and during the execution phase.
366433d6423SLionel Sambuc      */
367433d6423SLionel Sambuc     if ((InterpreterMode != ACPI_IMODE_LOAD_PASS1) &&
368433d6423SLionel Sambuc         (Flags & ACPI_NS_SEARCH_PARENT))
369433d6423SLionel Sambuc     {
370433d6423SLionel Sambuc         /*
371433d6423SLionel Sambuc          * Not found at this level - search parent tree according to the
372433d6423SLionel Sambuc          * ACPI specification
373433d6423SLionel Sambuc          */
374433d6423SLionel Sambuc         Status = AcpiNsSearchParentTree (TargetName, Node, Type, ReturnNode);
375433d6423SLionel Sambuc         if (ACPI_SUCCESS (Status))
376433d6423SLionel Sambuc         {
377433d6423SLionel Sambuc             return_ACPI_STATUS (Status);
378433d6423SLionel Sambuc         }
379433d6423SLionel Sambuc     }
380433d6423SLionel Sambuc 
381433d6423SLionel Sambuc     /* In execute mode, just search, never add names. Exit now */
382433d6423SLionel Sambuc 
383433d6423SLionel Sambuc     if (InterpreterMode == ACPI_IMODE_EXECUTE)
384433d6423SLionel Sambuc     {
385433d6423SLionel Sambuc         ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
386433d6423SLionel Sambuc             "%4.4s Not found in %p [Not adding]\n",
387433d6423SLionel Sambuc             ACPI_CAST_PTR (char, &TargetName), Node));
388433d6423SLionel Sambuc 
389433d6423SLionel Sambuc         return_ACPI_STATUS (AE_NOT_FOUND);
390433d6423SLionel Sambuc     }
391433d6423SLionel Sambuc 
392433d6423SLionel Sambuc     /* Create the new named object */
393433d6423SLionel Sambuc 
394433d6423SLionel Sambuc     NewNode = AcpiNsCreateNode (TargetName);
395433d6423SLionel Sambuc     if (!NewNode)
396433d6423SLionel Sambuc     {
397433d6423SLionel Sambuc         return_ACPI_STATUS (AE_NO_MEMORY);
398433d6423SLionel Sambuc     }
399433d6423SLionel Sambuc 
400433d6423SLionel Sambuc #ifdef ACPI_ASL_COMPILER
401433d6423SLionel Sambuc 
402433d6423SLionel Sambuc     /* Node is an object defined by an External() statement */
403433d6423SLionel Sambuc 
404433d6423SLionel Sambuc     if (Flags & ACPI_NS_EXTERNAL ||
405433d6423SLionel Sambuc         (WalkState && WalkState->Opcode == AML_SCOPE_OP))
406433d6423SLionel Sambuc     {
407433d6423SLionel Sambuc         NewNode->Flags |= ANOBJ_IS_EXTERNAL;
408433d6423SLionel Sambuc     }
409433d6423SLionel Sambuc #endif
410433d6423SLionel Sambuc 
411433d6423SLionel Sambuc     if (Flags & ACPI_NS_TEMPORARY)
412433d6423SLionel Sambuc     {
413433d6423SLionel Sambuc         NewNode->Flags |= ANOBJ_TEMPORARY;
414433d6423SLionel Sambuc     }
415433d6423SLionel Sambuc 
416433d6423SLionel Sambuc     /* Install the new object into the parent's list of children */
417433d6423SLionel Sambuc 
418433d6423SLionel Sambuc     AcpiNsInstallNode (WalkState, Node, NewNode, Type);
419433d6423SLionel Sambuc     *ReturnNode = NewNode;
420433d6423SLionel Sambuc     return_ACPI_STATUS (AE_OK);
421433d6423SLionel Sambuc }
422