xref: /freebsd/sys/contrib/dev/acpica/components/dispatcher/dswload.c (revision 313a0c13efa638cf248e35eed49f36ec0a1a7f26)
1a159c266SJung-uk Kim /******************************************************************************
2a159c266SJung-uk Kim  *
3a159c266SJung-uk Kim  * Module Name: dswload - Dispatcher first pass namespace load callbacks
4a159c266SJung-uk Kim  *
5a159c266SJung-uk Kim  *****************************************************************************/
6a159c266SJung-uk Kim 
7a159c266SJung-uk Kim /*
8*313a0c13SJung-uk Kim  * Copyright (C) 2000 - 2014, Intel Corp.
9a159c266SJung-uk Kim  * All rights reserved.
10a159c266SJung-uk Kim  *
11a159c266SJung-uk Kim  * Redistribution and use in source and binary forms, with or without
12a159c266SJung-uk Kim  * modification, are permitted provided that the following conditions
13a159c266SJung-uk Kim  * are met:
14a159c266SJung-uk Kim  * 1. Redistributions of source code must retain the above copyright
15a159c266SJung-uk Kim  *    notice, this list of conditions, and the following disclaimer,
16a159c266SJung-uk Kim  *    without modification.
17a159c266SJung-uk Kim  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18a159c266SJung-uk Kim  *    substantially similar to the "NO WARRANTY" disclaimer below
19a159c266SJung-uk Kim  *    ("Disclaimer") and any redistribution must be conditioned upon
20a159c266SJung-uk Kim  *    including a substantially similar Disclaimer requirement for further
21a159c266SJung-uk Kim  *    binary redistribution.
22a159c266SJung-uk Kim  * 3. Neither the names of the above-listed copyright holders nor the names
23a159c266SJung-uk Kim  *    of any contributors may be used to endorse or promote products derived
24a159c266SJung-uk Kim  *    from this software without specific prior written permission.
25a159c266SJung-uk Kim  *
26a159c266SJung-uk Kim  * Alternatively, this software may be distributed under the terms of the
27a159c266SJung-uk Kim  * GNU General Public License ("GPL") version 2 as published by the Free
28a159c266SJung-uk Kim  * Software Foundation.
29a159c266SJung-uk Kim  *
30a159c266SJung-uk Kim  * NO WARRANTY
31a159c266SJung-uk Kim  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32a159c266SJung-uk Kim  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33a159c266SJung-uk Kim  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34a159c266SJung-uk Kim  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35a159c266SJung-uk Kim  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36a159c266SJung-uk Kim  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37a159c266SJung-uk Kim  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38a159c266SJung-uk Kim  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39a159c266SJung-uk Kim  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40a159c266SJung-uk Kim  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41a159c266SJung-uk Kim  * POSSIBILITY OF SUCH DAMAGES.
42a159c266SJung-uk Kim  */
43a159c266SJung-uk Kim 
44a159c266SJung-uk Kim #define __DSWLOAD_C__
45a159c266SJung-uk Kim 
46a159c266SJung-uk Kim #include <contrib/dev/acpica/include/acpi.h>
47a159c266SJung-uk Kim #include <contrib/dev/acpica/include/accommon.h>
48a159c266SJung-uk Kim #include <contrib/dev/acpica/include/acparser.h>
49a159c266SJung-uk Kim #include <contrib/dev/acpica/include/amlcode.h>
50a159c266SJung-uk Kim #include <contrib/dev/acpica/include/acdispat.h>
51a159c266SJung-uk Kim #include <contrib/dev/acpica/include/acinterp.h>
52a159c266SJung-uk Kim #include <contrib/dev/acpica/include/acnamesp.h>
53a159c266SJung-uk Kim 
54a159c266SJung-uk Kim #ifdef ACPI_ASL_COMPILER
55a159c266SJung-uk Kim #include <contrib/dev/acpica/include/acdisasm.h>
56a159c266SJung-uk Kim #endif
57a159c266SJung-uk Kim 
58a159c266SJung-uk Kim #define _COMPONENT          ACPI_DISPATCHER
59a159c266SJung-uk Kim         ACPI_MODULE_NAME    ("dswload")
60a159c266SJung-uk Kim 
61a159c266SJung-uk Kim 
62a159c266SJung-uk Kim /*******************************************************************************
63a159c266SJung-uk Kim  *
64a159c266SJung-uk Kim  * FUNCTION:    AcpiDsInitCallbacks
65a159c266SJung-uk Kim  *
66a159c266SJung-uk Kim  * PARAMETERS:  WalkState       - Current state of the parse tree walk
67a159c266SJung-uk Kim  *              PassNumber      - 1, 2, or 3
68a159c266SJung-uk Kim  *
69a159c266SJung-uk Kim  * RETURN:      Status
70a159c266SJung-uk Kim  *
71a159c266SJung-uk Kim  * DESCRIPTION: Init walk state callbacks
72a159c266SJung-uk Kim  *
73a159c266SJung-uk Kim  ******************************************************************************/
74a159c266SJung-uk Kim 
75a159c266SJung-uk Kim ACPI_STATUS
76a159c266SJung-uk Kim AcpiDsInitCallbacks (
77a159c266SJung-uk Kim     ACPI_WALK_STATE         *WalkState,
78a159c266SJung-uk Kim     UINT32                  PassNumber)
79a159c266SJung-uk Kim {
80a159c266SJung-uk Kim 
81a159c266SJung-uk Kim     switch (PassNumber)
82a159c266SJung-uk Kim     {
83*313a0c13SJung-uk Kim     case 0:
84*313a0c13SJung-uk Kim 
85*313a0c13SJung-uk Kim         /* Parse only - caller will setup callbacks */
86*313a0c13SJung-uk Kim 
87*313a0c13SJung-uk Kim         WalkState->ParseFlags         = ACPI_PARSE_LOAD_PASS1 |
88*313a0c13SJung-uk Kim                                         ACPI_PARSE_DELETE_TREE |
89*313a0c13SJung-uk Kim                                         ACPI_PARSE_DISASSEMBLE;
90*313a0c13SJung-uk Kim         WalkState->DescendingCallback = NULL;
91*313a0c13SJung-uk Kim         WalkState->AscendingCallback  = NULL;
92*313a0c13SJung-uk Kim         break;
93*313a0c13SJung-uk Kim 
94a159c266SJung-uk Kim     case 1:
95a9d8d09cSJung-uk Kim 
96*313a0c13SJung-uk Kim         /* Load pass 1 */
97*313a0c13SJung-uk Kim 
98a159c266SJung-uk Kim         WalkState->ParseFlags         = ACPI_PARSE_LOAD_PASS1 |
99a159c266SJung-uk Kim                                         ACPI_PARSE_DELETE_TREE;
100a159c266SJung-uk Kim         WalkState->DescendingCallback = AcpiDsLoad1BeginOp;
101a159c266SJung-uk Kim         WalkState->AscendingCallback  = AcpiDsLoad1EndOp;
102a159c266SJung-uk Kim         break;
103a159c266SJung-uk Kim 
104a159c266SJung-uk Kim     case 2:
105a9d8d09cSJung-uk Kim 
106*313a0c13SJung-uk Kim         /* Load pass 2 */
107*313a0c13SJung-uk Kim 
108a159c266SJung-uk Kim         WalkState->ParseFlags         = ACPI_PARSE_LOAD_PASS1 |
109a159c266SJung-uk Kim                                         ACPI_PARSE_DELETE_TREE;
110a159c266SJung-uk Kim         WalkState->DescendingCallback = AcpiDsLoad2BeginOp;
111a159c266SJung-uk Kim         WalkState->AscendingCallback  = AcpiDsLoad2EndOp;
112a159c266SJung-uk Kim         break;
113a159c266SJung-uk Kim 
114a159c266SJung-uk Kim     case 3:
115a9d8d09cSJung-uk Kim 
116*313a0c13SJung-uk Kim         /* Execution pass */
117*313a0c13SJung-uk Kim 
118a159c266SJung-uk Kim #ifndef ACPI_NO_METHOD_EXECUTION
119a159c266SJung-uk Kim         WalkState->ParseFlags        |= ACPI_PARSE_EXECUTE  |
120a159c266SJung-uk Kim                                         ACPI_PARSE_DELETE_TREE;
121a159c266SJung-uk Kim         WalkState->DescendingCallback = AcpiDsExecBeginOp;
122a159c266SJung-uk Kim         WalkState->AscendingCallback  = AcpiDsExecEndOp;
123a159c266SJung-uk Kim #endif
124a159c266SJung-uk Kim         break;
125a159c266SJung-uk Kim 
126a159c266SJung-uk Kim     default:
127a9d8d09cSJung-uk Kim 
128a159c266SJung-uk Kim         return (AE_BAD_PARAMETER);
129a159c266SJung-uk Kim     }
130a159c266SJung-uk Kim 
131a159c266SJung-uk Kim     return (AE_OK);
132a159c266SJung-uk Kim }
133a159c266SJung-uk Kim 
134a159c266SJung-uk Kim 
135a159c266SJung-uk Kim /*******************************************************************************
136a159c266SJung-uk Kim  *
137a159c266SJung-uk Kim  * FUNCTION:    AcpiDsLoad1BeginOp
138a159c266SJung-uk Kim  *
139a159c266SJung-uk Kim  * PARAMETERS:  WalkState       - Current state of the parse tree walk
140a159c266SJung-uk Kim  *              OutOp           - Where to return op if a new one is created
141a159c266SJung-uk Kim  *
142a159c266SJung-uk Kim  * RETURN:      Status
143a159c266SJung-uk Kim  *
144a159c266SJung-uk Kim  * DESCRIPTION: Descending callback used during the loading of ACPI tables.
145a159c266SJung-uk Kim  *
146a159c266SJung-uk Kim  ******************************************************************************/
147a159c266SJung-uk Kim 
148a159c266SJung-uk Kim ACPI_STATUS
149a159c266SJung-uk Kim AcpiDsLoad1BeginOp (
150a159c266SJung-uk Kim     ACPI_WALK_STATE         *WalkState,
151a159c266SJung-uk Kim     ACPI_PARSE_OBJECT       **OutOp)
152a159c266SJung-uk Kim {
153a159c266SJung-uk Kim     ACPI_PARSE_OBJECT       *Op;
154a159c266SJung-uk Kim     ACPI_NAMESPACE_NODE     *Node;
155a159c266SJung-uk Kim     ACPI_STATUS             Status;
156a159c266SJung-uk Kim     ACPI_OBJECT_TYPE        ObjectType;
157a159c266SJung-uk Kim     char                    *Path;
158a159c266SJung-uk Kim     UINT32                  Flags;
159a159c266SJung-uk Kim 
160a159c266SJung-uk Kim 
161a159c266SJung-uk Kim     ACPI_FUNCTION_TRACE (DsLoad1BeginOp);
162a159c266SJung-uk Kim 
163a159c266SJung-uk Kim 
164a159c266SJung-uk Kim     Op = WalkState->Op;
165a159c266SJung-uk Kim     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
166a159c266SJung-uk Kim 
167a159c266SJung-uk Kim     /* We are only interested in opcodes that have an associated name */
168a159c266SJung-uk Kim 
169a159c266SJung-uk Kim     if (Op)
170a159c266SJung-uk Kim     {
171a159c266SJung-uk Kim         if (!(WalkState->OpInfo->Flags & AML_NAMED))
172a159c266SJung-uk Kim         {
173a159c266SJung-uk Kim             *OutOp = Op;
174a159c266SJung-uk Kim             return_ACPI_STATUS (AE_OK);
175a159c266SJung-uk Kim         }
176a159c266SJung-uk Kim 
177a159c266SJung-uk Kim         /* Check if this object has already been installed in the namespace */
178a159c266SJung-uk Kim 
179a159c266SJung-uk Kim         if (Op->Common.Node)
180a159c266SJung-uk Kim         {
181a159c266SJung-uk Kim             *OutOp = Op;
182a159c266SJung-uk Kim             return_ACPI_STATUS (AE_OK);
183a159c266SJung-uk Kim         }
184a159c266SJung-uk Kim     }
185a159c266SJung-uk Kim 
186a159c266SJung-uk Kim     Path = AcpiPsGetNextNamestring (&WalkState->ParserState);
187a159c266SJung-uk Kim 
188a159c266SJung-uk Kim     /* Map the raw opcode into an internal object type */
189a159c266SJung-uk Kim 
190a159c266SJung-uk Kim     ObjectType = WalkState->OpInfo->ObjectType;
191a159c266SJung-uk Kim 
192a159c266SJung-uk Kim     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
193a159c266SJung-uk Kim         "State=%p Op=%p [%s]\n", WalkState, Op, AcpiUtGetTypeName (ObjectType)));
194a159c266SJung-uk Kim 
195a159c266SJung-uk Kim     switch (WalkState->Opcode)
196a159c266SJung-uk Kim     {
197a159c266SJung-uk Kim     case AML_SCOPE_OP:
198a159c266SJung-uk Kim         /*
199a159c266SJung-uk Kim          * The target name of the Scope() operator must exist at this point so
200a159c266SJung-uk Kim          * that we can actually open the scope to enter new names underneath it.
201a159c266SJung-uk Kim          * Allow search-to-root for single namesegs.
202a159c266SJung-uk Kim          */
203a159c266SJung-uk Kim         Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
204a159c266SJung-uk Kim                         ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &(Node));
205a159c266SJung-uk Kim #ifdef ACPI_ASL_COMPILER
206a159c266SJung-uk Kim         if (Status == AE_NOT_FOUND)
207a159c266SJung-uk Kim         {
208a159c266SJung-uk Kim             /*
209a159c266SJung-uk Kim              * Table disassembly:
210a159c266SJung-uk Kim              * Target of Scope() not found. Generate an External for it, and
211a159c266SJung-uk Kim              * insert the name into the namespace.
212a159c266SJung-uk Kim              */
213*313a0c13SJung-uk Kim             AcpiDmAddOpToExternalList (Op, Path, ACPI_TYPE_DEVICE, 0, 0);
214a159c266SJung-uk Kim             Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
215a159c266SJung-uk Kim                        ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT,
216a159c266SJung-uk Kim                        WalkState, &Node);
217a159c266SJung-uk Kim         }
218a159c266SJung-uk Kim #endif
219a159c266SJung-uk Kim         if (ACPI_FAILURE (Status))
220a159c266SJung-uk Kim         {
221a159c266SJung-uk Kim             ACPI_ERROR_NAMESPACE (Path, Status);
222a159c266SJung-uk Kim             return_ACPI_STATUS (Status);
223a159c266SJung-uk Kim         }
224a159c266SJung-uk Kim 
225a159c266SJung-uk Kim         /*
226a159c266SJung-uk Kim          * Check to make sure that the target is
227a159c266SJung-uk Kim          * one of the opcodes that actually opens a scope
228a159c266SJung-uk Kim          */
229a159c266SJung-uk Kim         switch (Node->Type)
230a159c266SJung-uk Kim         {
231a159c266SJung-uk Kim         case ACPI_TYPE_ANY:
232a159c266SJung-uk Kim         case ACPI_TYPE_LOCAL_SCOPE:         /* Scope  */
233a159c266SJung-uk Kim         case ACPI_TYPE_DEVICE:
234a159c266SJung-uk Kim         case ACPI_TYPE_POWER:
235a159c266SJung-uk Kim         case ACPI_TYPE_PROCESSOR:
236a159c266SJung-uk Kim         case ACPI_TYPE_THERMAL:
237a159c266SJung-uk Kim 
238a159c266SJung-uk Kim             /* These are acceptable types */
239a159c266SJung-uk Kim             break;
240a159c266SJung-uk Kim 
241a159c266SJung-uk Kim         case ACPI_TYPE_INTEGER:
242a159c266SJung-uk Kim         case ACPI_TYPE_STRING:
243a159c266SJung-uk Kim         case ACPI_TYPE_BUFFER:
244a159c266SJung-uk Kim             /*
245a159c266SJung-uk Kim              * These types we will allow, but we will change the type.
246a159c266SJung-uk Kim              * This enables some existing code of the form:
247a159c266SJung-uk Kim              *
248a159c266SJung-uk Kim              *  Name (DEB, 0)
249a159c266SJung-uk Kim              *  Scope (DEB) { ... }
250a159c266SJung-uk Kim              *
251a159c266SJung-uk Kim              * Note: silently change the type here. On the second pass,
252a159c266SJung-uk Kim              * we will report a warning
253a159c266SJung-uk Kim              */
254a159c266SJung-uk Kim             ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
255a159c266SJung-uk Kim                 "Type override - [%4.4s] had invalid type (%s) "
256a159c266SJung-uk Kim                 "for Scope operator, changed to type ANY\n",
257a159c266SJung-uk Kim                 AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type)));
258a159c266SJung-uk Kim 
259a159c266SJung-uk Kim             Node->Type = ACPI_TYPE_ANY;
260a159c266SJung-uk Kim             WalkState->ScopeInfo->Common.Value = ACPI_TYPE_ANY;
261a159c266SJung-uk Kim             break;
262a159c266SJung-uk Kim 
2631df130f1SJung-uk Kim         case ACPI_TYPE_METHOD:
2641df130f1SJung-uk Kim             /*
2651df130f1SJung-uk Kim              * Allow scope change to root during execution of module-level
2661df130f1SJung-uk Kim              * code. Root is typed METHOD during this time.
2671df130f1SJung-uk Kim              */
2681df130f1SJung-uk Kim             if ((Node == AcpiGbl_RootNode) &&
2691df130f1SJung-uk Kim                 (WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
2701df130f1SJung-uk Kim             {
2711df130f1SJung-uk Kim                 break;
2721df130f1SJung-uk Kim             }
2731df130f1SJung-uk Kim 
2741df130f1SJung-uk Kim             /*lint -fallthrough */
2751df130f1SJung-uk Kim 
276a159c266SJung-uk Kim         default:
277a159c266SJung-uk Kim 
278a159c266SJung-uk Kim             /* All other types are an error */
279a159c266SJung-uk Kim 
280a159c266SJung-uk Kim             ACPI_ERROR ((AE_INFO,
281a159c266SJung-uk Kim                 "Invalid type (%s) for target of "
282a159c266SJung-uk Kim                 "Scope operator [%4.4s] (Cannot override)",
283a159c266SJung-uk Kim                 AcpiUtGetTypeName (Node->Type), AcpiUtGetNodeName (Node)));
284a159c266SJung-uk Kim 
285a159c266SJung-uk Kim             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
286a159c266SJung-uk Kim         }
287a159c266SJung-uk Kim         break;
288a159c266SJung-uk Kim 
289a159c266SJung-uk Kim     default:
290a159c266SJung-uk Kim         /*
291a159c266SJung-uk Kim          * For all other named opcodes, we will enter the name into
292a159c266SJung-uk Kim          * the namespace.
293a159c266SJung-uk Kim          *
294a159c266SJung-uk Kim          * Setup the search flags.
295a159c266SJung-uk Kim          * Since we are entering a name into the namespace, we do not want to
296a159c266SJung-uk Kim          * enable the search-to-root upsearch.
297a159c266SJung-uk Kim          *
298a159c266SJung-uk Kim          * There are only two conditions where it is acceptable that the name
299a159c266SJung-uk Kim          * already exists:
300a159c266SJung-uk Kim          *    1) the Scope() operator can reopen a scoping object that was
301a159c266SJung-uk Kim          *       previously defined (Scope, Method, Device, etc.)
302a159c266SJung-uk Kim          *    2) Whenever we are parsing a deferred opcode (OpRegion, Buffer,
303a159c266SJung-uk Kim          *       BufferField, or Package), the name of the object is already
304a159c266SJung-uk Kim          *       in the namespace.
305a159c266SJung-uk Kim          */
306a159c266SJung-uk Kim         if (WalkState->DeferredNode)
307a159c266SJung-uk Kim         {
308a159c266SJung-uk Kim             /* This name is already in the namespace, get the node */
309a159c266SJung-uk Kim 
310a159c266SJung-uk Kim             Node = WalkState->DeferredNode;
311a159c266SJung-uk Kim             Status = AE_OK;
312a159c266SJung-uk Kim             break;
313a159c266SJung-uk Kim         }
314a159c266SJung-uk Kim 
315a159c266SJung-uk Kim         /*
316a159c266SJung-uk Kim          * If we are executing a method, do not create any namespace objects
317a159c266SJung-uk Kim          * during the load phase, only during execution.
318a159c266SJung-uk Kim          */
319a159c266SJung-uk Kim         if (WalkState->MethodNode)
320a159c266SJung-uk Kim         {
321a159c266SJung-uk Kim             Node = NULL;
322a159c266SJung-uk Kim             Status = AE_OK;
323a159c266SJung-uk Kim             break;
324a159c266SJung-uk Kim         }
325a159c266SJung-uk Kim 
326a159c266SJung-uk Kim         Flags = ACPI_NS_NO_UPSEARCH;
327a159c266SJung-uk Kim         if ((WalkState->Opcode != AML_SCOPE_OP) &&
328a159c266SJung-uk Kim             (!(WalkState->ParseFlags & ACPI_PARSE_DEFERRED_OP)))
329a159c266SJung-uk Kim         {
330a159c266SJung-uk Kim             Flags |= ACPI_NS_ERROR_IF_FOUND;
331a159c266SJung-uk Kim             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Cannot already exist\n",
332a159c266SJung-uk Kim                     AcpiUtGetTypeName (ObjectType)));
333a159c266SJung-uk Kim         }
334a159c266SJung-uk Kim         else
335a159c266SJung-uk Kim         {
336a159c266SJung-uk Kim             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
337a159c266SJung-uk Kim                 "[%s] Both Find or Create allowed\n",
338a159c266SJung-uk Kim                     AcpiUtGetTypeName (ObjectType)));
339a159c266SJung-uk Kim         }
340a159c266SJung-uk Kim 
341a159c266SJung-uk Kim         /*
342a159c266SJung-uk Kim          * Enter the named type into the internal namespace. We enter the name
343a159c266SJung-uk Kim          * as we go downward in the parse tree. Any necessary subobjects that
344a159c266SJung-uk Kim          * involve arguments to the opcode must be created as we go back up the
345a159c266SJung-uk Kim          * parse tree later.
346a159c266SJung-uk Kim          */
347a159c266SJung-uk Kim         Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
348a159c266SJung-uk Kim                         ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
349a159c266SJung-uk Kim         if (ACPI_FAILURE (Status))
350a159c266SJung-uk Kim         {
351a159c266SJung-uk Kim             if (Status == AE_ALREADY_EXISTS)
352a159c266SJung-uk Kim             {
353a159c266SJung-uk Kim                 /* The name already exists in this scope */
354a159c266SJung-uk Kim 
355a159c266SJung-uk Kim                 if (Node->Flags & ANOBJ_IS_EXTERNAL)
356a159c266SJung-uk Kim                 {
357a159c266SJung-uk Kim                     /*
358a159c266SJung-uk Kim                      * Allow one create on an object or segment that was
359a159c266SJung-uk Kim                      * previously declared External
360a159c266SJung-uk Kim                      */
361a159c266SJung-uk Kim                     Node->Flags &= ~ANOBJ_IS_EXTERNAL;
362a159c266SJung-uk Kim                     Node->Type = (UINT8) ObjectType;
363a159c266SJung-uk Kim 
364a159c266SJung-uk Kim                     /* Just retyped a node, probably will need to open a scope */
365a159c266SJung-uk Kim 
366a159c266SJung-uk Kim                     if (AcpiNsOpensScope (ObjectType))
367a159c266SJung-uk Kim                     {
368a159c266SJung-uk Kim                         Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
369a159c266SJung-uk Kim                         if (ACPI_FAILURE (Status))
370a159c266SJung-uk Kim                         {
371a159c266SJung-uk Kim                             return_ACPI_STATUS (Status);
372a159c266SJung-uk Kim                         }
373a159c266SJung-uk Kim                     }
374a159c266SJung-uk Kim 
375a159c266SJung-uk Kim                     Status = AE_OK;
376a159c266SJung-uk Kim                 }
377a159c266SJung-uk Kim             }
378a159c266SJung-uk Kim 
379a159c266SJung-uk Kim             if (ACPI_FAILURE (Status))
380a159c266SJung-uk Kim             {
381a159c266SJung-uk Kim                 ACPI_ERROR_NAMESPACE (Path, Status);
382a159c266SJung-uk Kim                 return_ACPI_STATUS (Status);
383a159c266SJung-uk Kim             }
384a159c266SJung-uk Kim         }
385a159c266SJung-uk Kim         break;
386a159c266SJung-uk Kim     }
387a159c266SJung-uk Kim 
388a159c266SJung-uk Kim     /* Common exit */
389a159c266SJung-uk Kim 
390a159c266SJung-uk Kim     if (!Op)
391a159c266SJung-uk Kim     {
392a159c266SJung-uk Kim         /* Create a new op */
393a159c266SJung-uk Kim 
394a159c266SJung-uk Kim         Op = AcpiPsAllocOp (WalkState->Opcode);
395a159c266SJung-uk Kim         if (!Op)
396a159c266SJung-uk Kim         {
397a159c266SJung-uk Kim             return_ACPI_STATUS (AE_NO_MEMORY);
398a159c266SJung-uk Kim         }
399a159c266SJung-uk Kim     }
400a159c266SJung-uk Kim 
401a159c266SJung-uk Kim     /* Initialize the op */
402a159c266SJung-uk Kim 
403a159c266SJung-uk Kim #if (defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY))
404a159c266SJung-uk Kim     Op->Named.Path = ACPI_CAST_PTR (UINT8, Path);
405a159c266SJung-uk Kim #endif
406a159c266SJung-uk Kim 
407a159c266SJung-uk Kim     if (Node)
408a159c266SJung-uk Kim     {
409a159c266SJung-uk Kim         /*
410a159c266SJung-uk Kim          * Put the Node in the "op" object that the parser uses, so we
411a159c266SJung-uk Kim          * can get it again quickly when this scope is closed
412a159c266SJung-uk Kim          */
413a159c266SJung-uk Kim         Op->Common.Node = Node;
414a159c266SJung-uk Kim         Op->Named.Name = Node->Name.Integer;
415a159c266SJung-uk Kim     }
416a159c266SJung-uk Kim 
417a159c266SJung-uk Kim     AcpiPsAppendArg (AcpiPsGetParentScope (&WalkState->ParserState), Op);
418a159c266SJung-uk Kim     *OutOp = Op;
419a159c266SJung-uk Kim     return_ACPI_STATUS (Status);
420a159c266SJung-uk Kim }
421a159c266SJung-uk Kim 
422a159c266SJung-uk Kim 
423a159c266SJung-uk Kim /*******************************************************************************
424a159c266SJung-uk Kim  *
425a159c266SJung-uk Kim  * FUNCTION:    AcpiDsLoad1EndOp
426a159c266SJung-uk Kim  *
427a159c266SJung-uk Kim  * PARAMETERS:  WalkState       - Current state of the parse tree walk
428a159c266SJung-uk Kim  *
429a159c266SJung-uk Kim  * RETURN:      Status
430a159c266SJung-uk Kim  *
431a159c266SJung-uk Kim  * DESCRIPTION: Ascending callback used during the loading of the namespace,
432a159c266SJung-uk Kim  *              both control methods and everything else.
433a159c266SJung-uk Kim  *
434a159c266SJung-uk Kim  ******************************************************************************/
435a159c266SJung-uk Kim 
436a159c266SJung-uk Kim ACPI_STATUS
437a159c266SJung-uk Kim AcpiDsLoad1EndOp (
438a159c266SJung-uk Kim     ACPI_WALK_STATE         *WalkState)
439a159c266SJung-uk Kim {
440a159c266SJung-uk Kim     ACPI_PARSE_OBJECT       *Op;
441a159c266SJung-uk Kim     ACPI_OBJECT_TYPE        ObjectType;
442a159c266SJung-uk Kim     ACPI_STATUS             Status = AE_OK;
443a159c266SJung-uk Kim 
444a159c266SJung-uk Kim 
445a159c266SJung-uk Kim     ACPI_FUNCTION_TRACE (DsLoad1EndOp);
446a159c266SJung-uk Kim 
447a159c266SJung-uk Kim 
448a159c266SJung-uk Kim     Op = WalkState->Op;
449a159c266SJung-uk Kim     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
450a159c266SJung-uk Kim 
451a159c266SJung-uk Kim     /* We are only interested in opcodes that have an associated name */
452a159c266SJung-uk Kim 
453a159c266SJung-uk Kim     if (!(WalkState->OpInfo->Flags & (AML_NAMED | AML_FIELD)))
454a159c266SJung-uk Kim     {
455a159c266SJung-uk Kim         return_ACPI_STATUS (AE_OK);
456a159c266SJung-uk Kim     }
457a159c266SJung-uk Kim 
458a159c266SJung-uk Kim     /* Get the object type to determine if we should pop the scope */
459a159c266SJung-uk Kim 
460a159c266SJung-uk Kim     ObjectType = WalkState->OpInfo->ObjectType;
461a159c266SJung-uk Kim 
462a159c266SJung-uk Kim #ifndef ACPI_NO_METHOD_EXECUTION
463a159c266SJung-uk Kim     if (WalkState->OpInfo->Flags & AML_FIELD)
464a159c266SJung-uk Kim     {
465a159c266SJung-uk Kim         /*
466a159c266SJung-uk Kim          * If we are executing a method, do not create any namespace objects
467a159c266SJung-uk Kim          * during the load phase, only during execution.
468a159c266SJung-uk Kim          */
469a159c266SJung-uk Kim         if (!WalkState->MethodNode)
470a159c266SJung-uk Kim         {
471a159c266SJung-uk Kim             if (WalkState->Opcode == AML_FIELD_OP          ||
472a159c266SJung-uk Kim                 WalkState->Opcode == AML_BANK_FIELD_OP     ||
473a159c266SJung-uk Kim                 WalkState->Opcode == AML_INDEX_FIELD_OP)
474a159c266SJung-uk Kim             {
475a159c266SJung-uk Kim                 Status = AcpiDsInitFieldObjects (Op, WalkState);
476a159c266SJung-uk Kim             }
477a159c266SJung-uk Kim         }
478a159c266SJung-uk Kim         return_ACPI_STATUS (Status);
479a159c266SJung-uk Kim     }
480a159c266SJung-uk Kim 
481a159c266SJung-uk Kim     /*
482a159c266SJung-uk Kim      * If we are executing a method, do not create any namespace objects
483a159c266SJung-uk Kim      * during the load phase, only during execution.
484a159c266SJung-uk Kim      */
485a159c266SJung-uk Kim     if (!WalkState->MethodNode)
486a159c266SJung-uk Kim     {
487a159c266SJung-uk Kim         if (Op->Common.AmlOpcode == AML_REGION_OP)
488a159c266SJung-uk Kim         {
489a159c266SJung-uk Kim             Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
490a159c266SJung-uk Kim                         (ACPI_ADR_SPACE_TYPE) ((Op->Common.Value.Arg)->Common.Value.Integer),
491a159c266SJung-uk Kim                         WalkState);
492a159c266SJung-uk Kim             if (ACPI_FAILURE (Status))
493a159c266SJung-uk Kim             {
494a159c266SJung-uk Kim                 return_ACPI_STATUS (Status);
495a159c266SJung-uk Kim             }
496a159c266SJung-uk Kim         }
497a159c266SJung-uk Kim         else if (Op->Common.AmlOpcode == AML_DATA_REGION_OP)
498a159c266SJung-uk Kim         {
499a159c266SJung-uk Kim             Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
500a159c266SJung-uk Kim                         ACPI_ADR_SPACE_DATA_TABLE, WalkState);
501a159c266SJung-uk Kim             if (ACPI_FAILURE (Status))
502a159c266SJung-uk Kim             {
503a159c266SJung-uk Kim                 return_ACPI_STATUS (Status);
504a159c266SJung-uk Kim             }
505a159c266SJung-uk Kim         }
506a159c266SJung-uk Kim     }
507a159c266SJung-uk Kim #endif
508a159c266SJung-uk Kim 
509a159c266SJung-uk Kim     if (Op->Common.AmlOpcode == AML_NAME_OP)
510a159c266SJung-uk Kim     {
511a159c266SJung-uk Kim         /* For Name opcode, get the object type from the argument */
512a159c266SJung-uk Kim 
513a159c266SJung-uk Kim         if (Op->Common.Value.Arg)
514a159c266SJung-uk Kim         {
515a159c266SJung-uk Kim             ObjectType = (AcpiPsGetOpcodeInfo (
516a159c266SJung-uk Kim                 (Op->Common.Value.Arg)->Common.AmlOpcode))->ObjectType;
517a159c266SJung-uk Kim 
518a159c266SJung-uk Kim             /* Set node type if we have a namespace node */
519a159c266SJung-uk Kim 
520a159c266SJung-uk Kim             if (Op->Common.Node)
521a159c266SJung-uk Kim             {
522a159c266SJung-uk Kim                 Op->Common.Node->Type = (UINT8) ObjectType;
523a159c266SJung-uk Kim             }
524a159c266SJung-uk Kim         }
525a159c266SJung-uk Kim     }
526a159c266SJung-uk Kim 
527a159c266SJung-uk Kim     /*
528a159c266SJung-uk Kim      * If we are executing a method, do not create any namespace objects
529a159c266SJung-uk Kim      * during the load phase, only during execution.
530a159c266SJung-uk Kim      */
531a159c266SJung-uk Kim     if (!WalkState->MethodNode)
532a159c266SJung-uk Kim     {
533a159c266SJung-uk Kim         if (Op->Common.AmlOpcode == AML_METHOD_OP)
534a159c266SJung-uk Kim         {
535a159c266SJung-uk Kim             /*
536a159c266SJung-uk Kim              * MethodOp PkgLength NameString MethodFlags TermList
537a159c266SJung-uk Kim              *
538a159c266SJung-uk Kim              * Note: We must create the method node/object pair as soon as we
539a159c266SJung-uk Kim              * see the method declaration. This allows later pass1 parsing
540a159c266SJung-uk Kim              * of invocations of the method (need to know the number of
541a159c266SJung-uk Kim              * arguments.)
542a159c266SJung-uk Kim              */
543a159c266SJung-uk Kim             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
544a159c266SJung-uk Kim                 "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
545a159c266SJung-uk Kim                 WalkState, Op, Op->Named.Node));
546a159c266SJung-uk Kim 
547a159c266SJung-uk Kim             if (!AcpiNsGetAttachedObject (Op->Named.Node))
548a159c266SJung-uk Kim             {
549a159c266SJung-uk Kim                 WalkState->Operands[0] = ACPI_CAST_PTR (void, Op->Named.Node);
550a159c266SJung-uk Kim                 WalkState->NumOperands = 1;
551a159c266SJung-uk Kim 
552a159c266SJung-uk Kim                 Status = AcpiDsCreateOperands (WalkState, Op->Common.Value.Arg);
553a159c266SJung-uk Kim                 if (ACPI_SUCCESS (Status))
554a159c266SJung-uk Kim                 {
555a159c266SJung-uk Kim                     Status = AcpiExCreateMethod (Op->Named.Data,
556a159c266SJung-uk Kim                                         Op->Named.Length, WalkState);
557a159c266SJung-uk Kim                 }
558a159c266SJung-uk Kim 
559a159c266SJung-uk Kim                 WalkState->Operands[0] = NULL;
560a159c266SJung-uk Kim                 WalkState->NumOperands = 0;
561a159c266SJung-uk Kim 
562a159c266SJung-uk Kim                 if (ACPI_FAILURE (Status))
563a159c266SJung-uk Kim                 {
564a159c266SJung-uk Kim                     return_ACPI_STATUS (Status);
565a159c266SJung-uk Kim                 }
566a159c266SJung-uk Kim             }
567a159c266SJung-uk Kim         }
568a159c266SJung-uk Kim     }
569a159c266SJung-uk Kim 
570a159c266SJung-uk Kim     /* Pop the scope stack (only if loading a table) */
571a159c266SJung-uk Kim 
572a159c266SJung-uk Kim     if (!WalkState->MethodNode &&
573a159c266SJung-uk Kim         AcpiNsOpensScope (ObjectType))
574a159c266SJung-uk Kim     {
575a159c266SJung-uk Kim         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s): Popping scope for Op %p\n",
576a159c266SJung-uk Kim             AcpiUtGetTypeName (ObjectType), Op));
577a159c266SJung-uk Kim 
578a159c266SJung-uk Kim         Status = AcpiDsScopeStackPop (WalkState);
579a159c266SJung-uk Kim     }
580a159c266SJung-uk Kim 
581a159c266SJung-uk Kim     return_ACPI_STATUS (Status);
582a159c266SJung-uk Kim }
583