xref: /titanic_53/usr/src/uts/intel/io/acpica/namespace/nssearch.c (revision 385cc6b4ad1792caef3f84eb61eed3f27085801f)
1ae115bc7Smrj /*******************************************************************************
2ae115bc7Smrj  *
3ae115bc7Smrj  * Module Name: nssearch - Namespace search
4ae115bc7Smrj  *
5ae115bc7Smrj  ******************************************************************************/
6ae115bc7Smrj 
726f3cdf0SGordon Ross /*
8*385cc6b4SJerry Jelinek  * Copyright (C) 2000 - 2016, Intel Corp.
9ae115bc7Smrj  * All rights reserved.
10ae115bc7Smrj  *
1126f3cdf0SGordon Ross  * Redistribution and use in source and binary forms, with or without
1226f3cdf0SGordon Ross  * modification, are permitted provided that the following conditions
1326f3cdf0SGordon Ross  * are met:
1426f3cdf0SGordon Ross  * 1. Redistributions of source code must retain the above copyright
1526f3cdf0SGordon Ross  *    notice, this list of conditions, and the following disclaimer,
1626f3cdf0SGordon Ross  *    without modification.
1726f3cdf0SGordon Ross  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1826f3cdf0SGordon Ross  *    substantially similar to the "NO WARRANTY" disclaimer below
1926f3cdf0SGordon Ross  *    ("Disclaimer") and any redistribution must be conditioned upon
2026f3cdf0SGordon Ross  *    including a substantially similar Disclaimer requirement for further
2126f3cdf0SGordon Ross  *    binary redistribution.
2226f3cdf0SGordon Ross  * 3. Neither the names of the above-listed copyright holders nor the names
2326f3cdf0SGordon Ross  *    of any contributors may be used to endorse or promote products derived
2426f3cdf0SGordon Ross  *    from this software without specific prior written permission.
25ae115bc7Smrj  *
2626f3cdf0SGordon Ross  * Alternatively, this software may be distributed under the terms of the
2726f3cdf0SGordon Ross  * GNU General Public License ("GPL") version 2 as published by the Free
2826f3cdf0SGordon Ross  * Software Foundation.
29ae115bc7Smrj  *
3026f3cdf0SGordon Ross  * NO WARRANTY
3126f3cdf0SGordon Ross  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3226f3cdf0SGordon Ross  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3326f3cdf0SGordon Ross  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
3426f3cdf0SGordon Ross  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3526f3cdf0SGordon Ross  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3626f3cdf0SGordon Ross  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3726f3cdf0SGordon Ross  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3826f3cdf0SGordon Ross  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3926f3cdf0SGordon Ross  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
4026f3cdf0SGordon Ross  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4126f3cdf0SGordon Ross  * POSSIBILITY OF SUCH DAMAGES.
4226f3cdf0SGordon Ross  */
43ae115bc7Smrj 
44ae115bc7Smrj #include "acpi.h"
45aa2aa9a6SDana Myers #include "accommon.h"
46ae115bc7Smrj #include "acnamesp.h"
47ae115bc7Smrj 
48aa2aa9a6SDana Myers #ifdef ACPI_ASL_COMPILER
49aa2aa9a6SDana Myers #include "amlcode.h"
50aa2aa9a6SDana Myers #endif
51ae115bc7Smrj 
52ae115bc7Smrj #define _COMPONENT          ACPI_NAMESPACE
53ae115bc7Smrj         ACPI_MODULE_NAME    ("nssearch")
54ae115bc7Smrj 
55ae115bc7Smrj /* Local prototypes */
56ae115bc7Smrj 
57ae115bc7Smrj static ACPI_STATUS
58ae115bc7Smrj AcpiNsSearchParentTree (
59ae115bc7Smrj     UINT32                  TargetName,
60ae115bc7Smrj     ACPI_NAMESPACE_NODE     *Node,
61ae115bc7Smrj     ACPI_OBJECT_TYPE        Type,
62ae115bc7Smrj     ACPI_NAMESPACE_NODE     **ReturnNode);
63ae115bc7Smrj 
64ae115bc7Smrj 
65ae115bc7Smrj /*******************************************************************************
66ae115bc7Smrj  *
67ae115bc7Smrj  * FUNCTION:    AcpiNsSearchOneScope
68ae115bc7Smrj  *
69ae115bc7Smrj  * PARAMETERS:  TargetName      - Ascii ACPI name to search for
70ae115bc7Smrj  *              ParentNode      - Starting node where search will begin
71ae115bc7Smrj  *              Type            - Object type to match
72ae115bc7Smrj  *              ReturnNode      - Where the matched Named obj is returned
73ae115bc7Smrj  *
74ae115bc7Smrj  * RETURN:      Status
75ae115bc7Smrj  *
76ae115bc7Smrj  * DESCRIPTION: Search a single level of the namespace. Performs a
77ae115bc7Smrj  *              simple search of the specified level, and does not add
78ae115bc7Smrj  *              entries or search parents.
79ae115bc7Smrj  *
80ae115bc7Smrj  *
81ae115bc7Smrj  *      Named object lists are built (and subsequently dumped) in the
82ae115bc7Smrj  *      order in which the names are encountered during the namespace load;
83ae115bc7Smrj  *
84ae115bc7Smrj  *      All namespace searching is linear in this implementation, but
85ae115bc7Smrj  *      could be easily modified to support any improved search
86ae115bc7Smrj  *      algorithm. However, the linear search was chosen for simplicity
87ae115bc7Smrj  *      and because the trees are small and the other interpreter
88ae115bc7Smrj  *      execution overhead is relatively high.
89ae115bc7Smrj  *
90ae115bc7Smrj  *      Note: CPU execution analysis has shown that the AML interpreter spends
91ae115bc7Smrj  *      a very small percentage of its time searching the namespace. Therefore,
92ae115bc7Smrj  *      the linear search seems to be sufficient, as there would seem to be
93ae115bc7Smrj  *      little value in improving the search.
94ae115bc7Smrj  *
95ae115bc7Smrj  ******************************************************************************/
96ae115bc7Smrj 
97ae115bc7Smrj ACPI_STATUS
AcpiNsSearchOneScope(UINT32 TargetName,ACPI_NAMESPACE_NODE * ParentNode,ACPI_OBJECT_TYPE Type,ACPI_NAMESPACE_NODE ** ReturnNode)98ae115bc7Smrj AcpiNsSearchOneScope (
99ae115bc7Smrj     UINT32                  TargetName,
100ae115bc7Smrj     ACPI_NAMESPACE_NODE     *ParentNode,
101ae115bc7Smrj     ACPI_OBJECT_TYPE        Type,
102ae115bc7Smrj     ACPI_NAMESPACE_NODE     **ReturnNode)
103ae115bc7Smrj {
104ae115bc7Smrj     ACPI_NAMESPACE_NODE     *Node;
105ae115bc7Smrj 
106ae115bc7Smrj 
107ae115bc7Smrj     ACPI_FUNCTION_TRACE (NsSearchOneScope);
108ae115bc7Smrj 
109ae115bc7Smrj 
110ae115bc7Smrj #ifdef ACPI_DEBUG_OUTPUT
111ae115bc7Smrj     if (ACPI_LV_NAMES & AcpiDbgLevel)
112ae115bc7Smrj     {
113ae115bc7Smrj         char                *ScopeName;
114ae115bc7Smrj 
115*385cc6b4SJerry Jelinek         ScopeName = AcpiNsGetNormalizedPathname (ParentNode, TRUE);
116ae115bc7Smrj         if (ScopeName)
117ae115bc7Smrj         {
118ae115bc7Smrj             ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
119ae115bc7Smrj                 "Searching %s (%p) For [%4.4s] (%s)\n",
120ae115bc7Smrj                 ScopeName, ParentNode, ACPI_CAST_PTR (char, &TargetName),
121ae115bc7Smrj                 AcpiUtGetTypeName (Type)));
122ae115bc7Smrj 
123ae115bc7Smrj             ACPI_FREE (ScopeName);
124ae115bc7Smrj         }
125ae115bc7Smrj     }
126ae115bc7Smrj #endif
127ae115bc7Smrj 
128ae115bc7Smrj     /*
129ae115bc7Smrj      * Search for name at this namespace level, which is to say that we
130ae115bc7Smrj      * must search for the name among the children of this object
131ae115bc7Smrj      */
132ae115bc7Smrj     Node = ParentNode->Child;
133ae115bc7Smrj     while (Node)
134ae115bc7Smrj     {
135ae115bc7Smrj         /* Check for match against the name */
136ae115bc7Smrj 
137ae115bc7Smrj         if (Node->Name.Integer == TargetName)
138ae115bc7Smrj         {
139ae115bc7Smrj             /* Resolve a control method alias if any */
140ae115bc7Smrj 
141ae115bc7Smrj             if (AcpiNsGetType (Node) == ACPI_TYPE_LOCAL_METHOD_ALIAS)
142ae115bc7Smrj             {
143ae115bc7Smrj                 Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Node->Object);
144ae115bc7Smrj             }
145ae115bc7Smrj 
146ae115bc7Smrj             /* Found matching entry */
147ae115bc7Smrj 
148ae115bc7Smrj             ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
149ae115bc7Smrj                 "Name [%4.4s] (%s) %p found in scope [%4.4s] %p\n",
150ae115bc7Smrj                 ACPI_CAST_PTR (char, &TargetName),
151ae115bc7Smrj                 AcpiUtGetTypeName (Node->Type),
152ae115bc7Smrj                 Node, AcpiUtGetNodeName (ParentNode), ParentNode));
153ae115bc7Smrj 
154ae115bc7Smrj             *ReturnNode = Node;
155ae115bc7Smrj             return_ACPI_STATUS (AE_OK);
156ae115bc7Smrj         }
157ae115bc7Smrj 
158ae115bc7Smrj         /* Didn't match name, move on to the next peer object */
159ae115bc7Smrj 
160ae115bc7Smrj         Node = Node->Peer;
161ae115bc7Smrj     }
162ae115bc7Smrj 
163ae115bc7Smrj     /* Searched entire namespace level, not found */
164ae115bc7Smrj 
165ae115bc7Smrj     ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
166aa2aa9a6SDana Myers         "Name [%4.4s] (%s) not found in search in scope [%4.4s] "
167aa2aa9a6SDana Myers         "%p first child %p\n",
168ae115bc7Smrj         ACPI_CAST_PTR (char, &TargetName), AcpiUtGetTypeName (Type),
169ae115bc7Smrj         AcpiUtGetNodeName (ParentNode), ParentNode, ParentNode->Child));
170ae115bc7Smrj 
171ae115bc7Smrj     return_ACPI_STATUS (AE_NOT_FOUND);
172ae115bc7Smrj }
173ae115bc7Smrj 
174ae115bc7Smrj 
175ae115bc7Smrj /*******************************************************************************
176ae115bc7Smrj  *
177ae115bc7Smrj  * FUNCTION:    AcpiNsSearchParentTree
178ae115bc7Smrj  *
179ae115bc7Smrj  * PARAMETERS:  TargetName      - Ascii ACPI name to search for
180ae115bc7Smrj  *              Node            - Starting node where search will begin
181ae115bc7Smrj  *              Type            - Object type to match
182ae115bc7Smrj  *              ReturnNode      - Where the matched Node is returned
183ae115bc7Smrj  *
184ae115bc7Smrj  * RETURN:      Status
185ae115bc7Smrj  *
186ae115bc7Smrj  * DESCRIPTION: Called when a name has not been found in the current namespace
187ae115bc7Smrj  *              level. Before adding it or giving up, ACPI scope rules require
188ae115bc7Smrj  *              searching enclosing scopes in cases identified by AcpiNsLocal().
189ae115bc7Smrj  *
190ae115bc7Smrj  *              "A name is located by finding the matching name in the current
191ae115bc7Smrj  *              name space, and then in the parent name space. If the parent
192ae115bc7Smrj  *              name space does not contain the name, the search continues
193ae115bc7Smrj  *              recursively until either the name is found or the name space
194ae115bc7Smrj  *              does not have a parent (the root of the name space). This
195ae115bc7Smrj  *              indicates that the name is not found" (From ACPI Specification,
196ae115bc7Smrj  *              section 5.3)
197ae115bc7Smrj  *
198ae115bc7Smrj  ******************************************************************************/
199ae115bc7Smrj 
200ae115bc7Smrj static ACPI_STATUS
AcpiNsSearchParentTree(UINT32 TargetName,ACPI_NAMESPACE_NODE * Node,ACPI_OBJECT_TYPE Type,ACPI_NAMESPACE_NODE ** ReturnNode)201ae115bc7Smrj AcpiNsSearchParentTree (
202ae115bc7Smrj     UINT32                  TargetName,
203ae115bc7Smrj     ACPI_NAMESPACE_NODE     *Node,
204ae115bc7Smrj     ACPI_OBJECT_TYPE        Type,
205ae115bc7Smrj     ACPI_NAMESPACE_NODE     **ReturnNode)
206ae115bc7Smrj {
207ae115bc7Smrj     ACPI_STATUS             Status;
208ae115bc7Smrj     ACPI_NAMESPACE_NODE     *ParentNode;
209ae115bc7Smrj 
210ae115bc7Smrj 
211ae115bc7Smrj     ACPI_FUNCTION_TRACE (NsSearchParentTree);
212ae115bc7Smrj 
213ae115bc7Smrj 
21426f3cdf0SGordon Ross     ParentNode = Node->Parent;
215ae115bc7Smrj 
216ae115bc7Smrj     /*
217ae115bc7Smrj      * If there is no parent (i.e., we are at the root) or type is "local",
218ae115bc7Smrj      * we won't be searching the parent tree.
219ae115bc7Smrj      */
220ae115bc7Smrj     if (!ParentNode)
221ae115bc7Smrj     {
222ae115bc7Smrj         ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "[%4.4s] has no parent\n",
223ae115bc7Smrj             ACPI_CAST_PTR (char, &TargetName)));
224ae115bc7Smrj         return_ACPI_STATUS (AE_NOT_FOUND);
225ae115bc7Smrj     }
226ae115bc7Smrj 
227ae115bc7Smrj     if (AcpiNsLocal (Type))
228ae115bc7Smrj     {
229ae115bc7Smrj         ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
230ae115bc7Smrj             "[%4.4s] type [%s] must be local to this scope (no parent search)\n",
231ae115bc7Smrj             ACPI_CAST_PTR (char, &TargetName), AcpiUtGetTypeName (Type)));
232ae115bc7Smrj         return_ACPI_STATUS (AE_NOT_FOUND);
233ae115bc7Smrj     }
234ae115bc7Smrj 
235ae115bc7Smrj     /* Search the parent tree */
236ae115bc7Smrj 
237ae115bc7Smrj     ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
238ae115bc7Smrj         "Searching parent [%4.4s] for [%4.4s]\n",
239ae115bc7Smrj         AcpiUtGetNodeName (ParentNode), ACPI_CAST_PTR (char, &TargetName)));
240ae115bc7Smrj 
241aa2aa9a6SDana Myers     /* Search parents until target is found or we have backed up to the root */
242aa2aa9a6SDana Myers 
243ae115bc7Smrj     while (ParentNode)
244ae115bc7Smrj     {
245ae115bc7Smrj         /*
246ae115bc7Smrj          * Search parent scope. Use TYPE_ANY because we don't care about the
247ae115bc7Smrj          * object type at this point, we only care about the existence of
248ae115bc7Smrj          * the actual name we are searching for. Typechecking comes later.
249ae115bc7Smrj          */
250ae115bc7Smrj         Status = AcpiNsSearchOneScope (
251ae115bc7Smrj             TargetName, ParentNode, ACPI_TYPE_ANY, ReturnNode);
252ae115bc7Smrj         if (ACPI_SUCCESS (Status))
253ae115bc7Smrj         {
254ae115bc7Smrj             return_ACPI_STATUS (Status);
255ae115bc7Smrj         }
256ae115bc7Smrj 
257ae115bc7Smrj         /* Not found here, go up another level (until we reach the root) */
258ae115bc7Smrj 
25926f3cdf0SGordon Ross         ParentNode = ParentNode->Parent;
260ae115bc7Smrj     }
261ae115bc7Smrj 
262ae115bc7Smrj     /* Not found in parent tree */
263ae115bc7Smrj 
264ae115bc7Smrj     return_ACPI_STATUS (AE_NOT_FOUND);
265ae115bc7Smrj }
266ae115bc7Smrj 
267ae115bc7Smrj 
268ae115bc7Smrj /*******************************************************************************
269ae115bc7Smrj  *
270ae115bc7Smrj  * FUNCTION:    AcpiNsSearchAndEnter
271ae115bc7Smrj  *
272ae115bc7Smrj  * PARAMETERS:  TargetName          - Ascii ACPI name to search for (4 chars)
273ae115bc7Smrj  *              WalkState           - Current state of the walk
274ae115bc7Smrj  *              Node                - Starting node where search will begin
275ae115bc7Smrj  *              InterpreterMode     - Add names only in ACPI_MODE_LOAD_PASS_x.
276ae115bc7Smrj  *                                    Otherwise,search only.
277ae115bc7Smrj  *              Type                - Object type to match
278ae115bc7Smrj  *              Flags               - Flags describing the search restrictions
279ae115bc7Smrj  *              ReturnNode          - Where the Node is returned
280ae115bc7Smrj  *
281ae115bc7Smrj  * RETURN:      Status
282ae115bc7Smrj  *
283ae115bc7Smrj  * DESCRIPTION: Search for a name segment in a single namespace level,
284ae115bc7Smrj  *              optionally adding it if it is not found. If the passed
285ae115bc7Smrj  *              Type is not Any and the type previously stored in the
286ae115bc7Smrj  *              entry was Any (i.e. unknown), update the stored type.
287ae115bc7Smrj  *
288ae115bc7Smrj  *              In ACPI_IMODE_EXECUTE, search only.
289ae115bc7Smrj  *              In other modes, search and add if not found.
290ae115bc7Smrj  *
291ae115bc7Smrj  ******************************************************************************/
292ae115bc7Smrj 
293ae115bc7Smrj 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)294ae115bc7Smrj AcpiNsSearchAndEnter (
295ae115bc7Smrj     UINT32                  TargetName,
296ae115bc7Smrj     ACPI_WALK_STATE         *WalkState,
297ae115bc7Smrj     ACPI_NAMESPACE_NODE     *Node,
298ae115bc7Smrj     ACPI_INTERPRETER_MODE   InterpreterMode,
299ae115bc7Smrj     ACPI_OBJECT_TYPE        Type,
300ae115bc7Smrj     UINT32                  Flags,
301ae115bc7Smrj     ACPI_NAMESPACE_NODE     **ReturnNode)
302ae115bc7Smrj {
303ae115bc7Smrj     ACPI_STATUS             Status;
304ae115bc7Smrj     ACPI_NAMESPACE_NODE     *NewNode;
305ae115bc7Smrj 
306ae115bc7Smrj 
307ae115bc7Smrj     ACPI_FUNCTION_TRACE (NsSearchAndEnter);
308ae115bc7Smrj 
309ae115bc7Smrj 
310ae115bc7Smrj     /* Parameter validation */
311ae115bc7Smrj 
312ae115bc7Smrj     if (!Node || !TargetName || !ReturnNode)
313ae115bc7Smrj     {
314ae115bc7Smrj         ACPI_ERROR ((AE_INFO,
31526f3cdf0SGordon Ross             "Null parameter: Node %p Name 0x%X ReturnNode %p",
316ae115bc7Smrj             Node, TargetName, ReturnNode));
317ae115bc7Smrj         return_ACPI_STATUS (AE_BAD_PARAMETER);
318ae115bc7Smrj     }
319ae115bc7Smrj 
320ae115bc7Smrj     /*
321ae115bc7Smrj      * Name must consist of valid ACPI characters. We will repair the name if
322ae115bc7Smrj      * necessary because we don't want to abort because of this, but we want
323ae115bc7Smrj      * all namespace names to be printable. A warning message is appropriate.
324ae115bc7Smrj      *
325ae115bc7Smrj      * This issue came up because there are in fact machines that exhibit
326ae115bc7Smrj      * this problem, and we want to be able to enable ACPI support for them,
327ae115bc7Smrj      * even though there are a few bad names.
328ae115bc7Smrj      */
329db2bae30SDana Myers     AcpiUtRepairName (ACPI_CAST_PTR (char, &TargetName));
330ae115bc7Smrj 
331ae115bc7Smrj     /* Try to find the name in the namespace level specified by the caller */
332ae115bc7Smrj 
333ae115bc7Smrj     *ReturnNode = ACPI_ENTRY_NOT_FOUND;
334ae115bc7Smrj     Status = AcpiNsSearchOneScope (TargetName, Node, Type, ReturnNode);
335ae115bc7Smrj     if (Status != AE_NOT_FOUND)
336ae115bc7Smrj     {
337ae115bc7Smrj         /*
338ae115bc7Smrj          * If we found it AND the request specifies that a find is an error,
339ae115bc7Smrj          * return the error
340ae115bc7Smrj          */
341*385cc6b4SJerry Jelinek         if (Status == AE_OK)
342*385cc6b4SJerry Jelinek         {
343*385cc6b4SJerry Jelinek             /* The node was found in the namespace */
344*385cc6b4SJerry Jelinek 
345*385cc6b4SJerry Jelinek             /*
346*385cc6b4SJerry Jelinek              * If the namespace override feature is enabled for this node,
347*385cc6b4SJerry Jelinek              * delete any existing attached sub-object and make the node
348*385cc6b4SJerry Jelinek              * look like a new node that is owned by the override table.
349*385cc6b4SJerry Jelinek              */
350*385cc6b4SJerry Jelinek             if (Flags & ACPI_NS_OVERRIDE_IF_FOUND)
351*385cc6b4SJerry Jelinek             {
352*385cc6b4SJerry Jelinek                 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
353*385cc6b4SJerry Jelinek                     "Namespace override: %4.4s pass %u type %X Owner %X\n",
354*385cc6b4SJerry Jelinek                     ACPI_CAST_PTR(char, &TargetName), InterpreterMode,
355*385cc6b4SJerry Jelinek                     (*ReturnNode)->Type, WalkState->OwnerId));
356*385cc6b4SJerry Jelinek 
357*385cc6b4SJerry Jelinek                 AcpiNsDeleteChildren (*ReturnNode);
358*385cc6b4SJerry Jelinek                 if (AcpiGbl_RuntimeNamespaceOverride)
359*385cc6b4SJerry Jelinek                 {
360*385cc6b4SJerry Jelinek                     AcpiUtRemoveReference ((*ReturnNode)->Object);
361*385cc6b4SJerry Jelinek                     (*ReturnNode)->Object = NULL;
362*385cc6b4SJerry Jelinek                     (*ReturnNode)->OwnerId = WalkState->OwnerId;
363*385cc6b4SJerry Jelinek                 }
364*385cc6b4SJerry Jelinek                 else
365*385cc6b4SJerry Jelinek                 {
366*385cc6b4SJerry Jelinek                     AcpiNsRemoveNode (*ReturnNode);
367*385cc6b4SJerry Jelinek                     *ReturnNode = ACPI_ENTRY_NOT_FOUND;
368*385cc6b4SJerry Jelinek                 }
369*385cc6b4SJerry Jelinek             }
370*385cc6b4SJerry Jelinek 
371*385cc6b4SJerry Jelinek             /* Return an error if we don't expect to find the object */
372*385cc6b4SJerry Jelinek 
373*385cc6b4SJerry Jelinek             else if (Flags & ACPI_NS_ERROR_IF_FOUND)
374ae115bc7Smrj             {
375ae115bc7Smrj                 Status = AE_ALREADY_EXISTS;
376ae115bc7Smrj             }
377*385cc6b4SJerry Jelinek         }
378ae115bc7Smrj 
379aa2aa9a6SDana Myers #ifdef ACPI_ASL_COMPILER
380aa2aa9a6SDana Myers         if (*ReturnNode && (*ReturnNode)->Type == ACPI_TYPE_ANY)
381aa2aa9a6SDana Myers         {
382aa2aa9a6SDana Myers             (*ReturnNode)->Flags |= ANOBJ_IS_EXTERNAL;
383aa2aa9a6SDana Myers         }
384aa2aa9a6SDana Myers #endif
385aa2aa9a6SDana Myers 
386ae115bc7Smrj         /* Either found it or there was an error: finished either way */
387ae115bc7Smrj 
388ae115bc7Smrj         return_ACPI_STATUS (Status);
389ae115bc7Smrj     }
390ae115bc7Smrj 
391ae115bc7Smrj     /*
392ae115bc7Smrj      * The name was not found. If we are NOT performing the first pass
393ae115bc7Smrj      * (name entry) of loading the namespace, search the parent tree (all the
394ae115bc7Smrj      * way to the root if necessary.) We don't want to perform the parent
395ae115bc7Smrj      * search when the namespace is actually being loaded. We want to perform
396ae115bc7Smrj      * the search when namespace references are being resolved (load pass 2)
397ae115bc7Smrj      * and during the execution phase.
398ae115bc7Smrj      */
399ae115bc7Smrj     if ((InterpreterMode != ACPI_IMODE_LOAD_PASS1) &&
400ae115bc7Smrj         (Flags & ACPI_NS_SEARCH_PARENT))
401ae115bc7Smrj     {
402ae115bc7Smrj         /*
403ae115bc7Smrj          * Not found at this level - search parent tree according to the
404ae115bc7Smrj          * ACPI specification
405ae115bc7Smrj          */
406ae115bc7Smrj         Status = AcpiNsSearchParentTree (TargetName, Node, Type, ReturnNode);
407ae115bc7Smrj         if (ACPI_SUCCESS (Status))
408ae115bc7Smrj         {
409ae115bc7Smrj             return_ACPI_STATUS (Status);
410ae115bc7Smrj         }
411ae115bc7Smrj     }
412ae115bc7Smrj 
413ae115bc7Smrj     /* In execute mode, just search, never add names. Exit now */
414ae115bc7Smrj 
415ae115bc7Smrj     if (InterpreterMode == ACPI_IMODE_EXECUTE)
416ae115bc7Smrj     {
417ae115bc7Smrj         ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
418ae115bc7Smrj             "%4.4s Not found in %p [Not adding]\n",
419ae115bc7Smrj             ACPI_CAST_PTR (char, &TargetName), Node));
420ae115bc7Smrj 
421ae115bc7Smrj         return_ACPI_STATUS (AE_NOT_FOUND);
422ae115bc7Smrj     }
423ae115bc7Smrj 
424ae115bc7Smrj     /* Create the new named object */
425ae115bc7Smrj 
426ae115bc7Smrj     NewNode = AcpiNsCreateNode (TargetName);
427ae115bc7Smrj     if (!NewNode)
428ae115bc7Smrj     {
429ae115bc7Smrj         return_ACPI_STATUS (AE_NO_MEMORY);
430ae115bc7Smrj     }
431ae115bc7Smrj 
432ae115bc7Smrj #ifdef ACPI_ASL_COMPILER
433aa2aa9a6SDana Myers 
434aa2aa9a6SDana Myers     /* Node is an object defined by an External() statement */
435aa2aa9a6SDana Myers 
436aa2aa9a6SDana Myers     if (Flags & ACPI_NS_EXTERNAL ||
437aa2aa9a6SDana Myers         (WalkState && WalkState->Opcode == AML_SCOPE_OP))
438ae115bc7Smrj     {
439ae115bc7Smrj         NewNode->Flags |= ANOBJ_IS_EXTERNAL;
440ae115bc7Smrj     }
441ae115bc7Smrj #endif
442ae115bc7Smrj 
443db2bae30SDana Myers     if (Flags & ACPI_NS_TEMPORARY)
444db2bae30SDana Myers     {
445db2bae30SDana Myers         NewNode->Flags |= ANOBJ_TEMPORARY;
446db2bae30SDana Myers     }
447db2bae30SDana Myers 
448ae115bc7Smrj     /* Install the new object into the parent's list of children */
449ae115bc7Smrj 
450ae115bc7Smrj     AcpiNsInstallNode (WalkState, Node, NewNode, Type);
451ae115bc7Smrj     *ReturnNode = NewNode;
452ae115bc7Smrj     return_ACPI_STATUS (AE_OK);
453ae115bc7Smrj }
454