1433d6423SLionel Sambuc /******************************************************************************
2433d6423SLionel Sambuc *
3*29492bb7SDavid van Moolenbroek * Module Name: dswload - Dispatcher first pass namespace load callbacks
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 "acparser.h"
47433d6423SLionel Sambuc #include "amlcode.h"
48433d6423SLionel Sambuc #include "acdispat.h"
49433d6423SLionel Sambuc #include "acinterp.h"
50433d6423SLionel Sambuc #include "acnamesp.h"
51433d6423SLionel Sambuc
52433d6423SLionel Sambuc #ifdef ACPI_ASL_COMPILER
53433d6423SLionel Sambuc #include "acdisasm.h"
54433d6423SLionel Sambuc #endif
55433d6423SLionel Sambuc
56433d6423SLionel Sambuc #define _COMPONENT ACPI_DISPATCHER
57433d6423SLionel Sambuc ACPI_MODULE_NAME ("dswload")
58433d6423SLionel Sambuc
59433d6423SLionel Sambuc
60433d6423SLionel Sambuc /*******************************************************************************
61433d6423SLionel Sambuc *
62433d6423SLionel Sambuc * FUNCTION: AcpiDsInitCallbacks
63433d6423SLionel Sambuc *
64433d6423SLionel Sambuc * PARAMETERS: WalkState - Current state of the parse tree walk
65433d6423SLionel Sambuc * PassNumber - 1, 2, or 3
66433d6423SLionel Sambuc *
67433d6423SLionel Sambuc * RETURN: Status
68433d6423SLionel Sambuc *
69433d6423SLionel Sambuc * DESCRIPTION: Init walk state callbacks
70433d6423SLionel Sambuc *
71433d6423SLionel Sambuc ******************************************************************************/
72433d6423SLionel Sambuc
73433d6423SLionel Sambuc ACPI_STATUS
AcpiDsInitCallbacks(ACPI_WALK_STATE * WalkState,UINT32 PassNumber)74433d6423SLionel Sambuc AcpiDsInitCallbacks (
75433d6423SLionel Sambuc ACPI_WALK_STATE *WalkState,
76433d6423SLionel Sambuc UINT32 PassNumber)
77433d6423SLionel Sambuc {
78433d6423SLionel Sambuc
79433d6423SLionel Sambuc switch (PassNumber)
80433d6423SLionel Sambuc {
81*29492bb7SDavid van Moolenbroek case 0:
82*29492bb7SDavid van Moolenbroek
83*29492bb7SDavid van Moolenbroek /* Parse only - caller will setup callbacks */
84*29492bb7SDavid van Moolenbroek
85*29492bb7SDavid van Moolenbroek WalkState->ParseFlags = ACPI_PARSE_LOAD_PASS1 |
86*29492bb7SDavid van Moolenbroek ACPI_PARSE_DELETE_TREE |
87*29492bb7SDavid van Moolenbroek ACPI_PARSE_DISASSEMBLE;
88*29492bb7SDavid van Moolenbroek WalkState->DescendingCallback = NULL;
89*29492bb7SDavid van Moolenbroek WalkState->AscendingCallback = NULL;
90*29492bb7SDavid van Moolenbroek break;
91*29492bb7SDavid van Moolenbroek
92433d6423SLionel Sambuc case 1:
93*29492bb7SDavid van Moolenbroek
94*29492bb7SDavid van Moolenbroek /* Load pass 1 */
95*29492bb7SDavid van Moolenbroek
96433d6423SLionel Sambuc WalkState->ParseFlags = ACPI_PARSE_LOAD_PASS1 |
97433d6423SLionel Sambuc ACPI_PARSE_DELETE_TREE;
98433d6423SLionel Sambuc WalkState->DescendingCallback = AcpiDsLoad1BeginOp;
99433d6423SLionel Sambuc WalkState->AscendingCallback = AcpiDsLoad1EndOp;
100433d6423SLionel Sambuc break;
101433d6423SLionel Sambuc
102433d6423SLionel Sambuc case 2:
103*29492bb7SDavid van Moolenbroek
104*29492bb7SDavid van Moolenbroek /* Load pass 2 */
105*29492bb7SDavid van Moolenbroek
106433d6423SLionel Sambuc WalkState->ParseFlags = ACPI_PARSE_LOAD_PASS1 |
107433d6423SLionel Sambuc ACPI_PARSE_DELETE_TREE;
108433d6423SLionel Sambuc WalkState->DescendingCallback = AcpiDsLoad2BeginOp;
109433d6423SLionel Sambuc WalkState->AscendingCallback = AcpiDsLoad2EndOp;
110433d6423SLionel Sambuc break;
111433d6423SLionel Sambuc
112433d6423SLionel Sambuc case 3:
113*29492bb7SDavid van Moolenbroek
114*29492bb7SDavid van Moolenbroek /* Execution pass */
115*29492bb7SDavid van Moolenbroek
116433d6423SLionel Sambuc #ifndef ACPI_NO_METHOD_EXECUTION
117433d6423SLionel Sambuc WalkState->ParseFlags |= ACPI_PARSE_EXECUTE |
118433d6423SLionel Sambuc ACPI_PARSE_DELETE_TREE;
119433d6423SLionel Sambuc WalkState->DescendingCallback = AcpiDsExecBeginOp;
120433d6423SLionel Sambuc WalkState->AscendingCallback = AcpiDsExecEndOp;
121433d6423SLionel Sambuc #endif
122433d6423SLionel Sambuc break;
123433d6423SLionel Sambuc
124433d6423SLionel Sambuc default:
125*29492bb7SDavid van Moolenbroek
126433d6423SLionel Sambuc return (AE_BAD_PARAMETER);
127433d6423SLionel Sambuc }
128433d6423SLionel Sambuc
129433d6423SLionel Sambuc return (AE_OK);
130433d6423SLionel Sambuc }
131433d6423SLionel Sambuc
132433d6423SLionel Sambuc
133433d6423SLionel Sambuc /*******************************************************************************
134433d6423SLionel Sambuc *
135433d6423SLionel Sambuc * FUNCTION: AcpiDsLoad1BeginOp
136433d6423SLionel Sambuc *
137433d6423SLionel Sambuc * PARAMETERS: WalkState - Current state of the parse tree walk
138433d6423SLionel Sambuc * OutOp - Where to return op if a new one is created
139433d6423SLionel Sambuc *
140433d6423SLionel Sambuc * RETURN: Status
141433d6423SLionel Sambuc *
142433d6423SLionel Sambuc * DESCRIPTION: Descending callback used during the loading of ACPI tables.
143433d6423SLionel Sambuc *
144433d6423SLionel Sambuc ******************************************************************************/
145433d6423SLionel Sambuc
146433d6423SLionel Sambuc ACPI_STATUS
AcpiDsLoad1BeginOp(ACPI_WALK_STATE * WalkState,ACPI_PARSE_OBJECT ** OutOp)147433d6423SLionel Sambuc AcpiDsLoad1BeginOp (
148433d6423SLionel Sambuc ACPI_WALK_STATE *WalkState,
149433d6423SLionel Sambuc ACPI_PARSE_OBJECT **OutOp)
150433d6423SLionel Sambuc {
151433d6423SLionel Sambuc ACPI_PARSE_OBJECT *Op;
152433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *Node;
153433d6423SLionel Sambuc ACPI_STATUS Status;
154433d6423SLionel Sambuc ACPI_OBJECT_TYPE ObjectType;
155433d6423SLionel Sambuc char *Path;
156433d6423SLionel Sambuc UINT32 Flags;
157433d6423SLionel Sambuc
158433d6423SLionel Sambuc
159433d6423SLionel Sambuc ACPI_FUNCTION_TRACE (DsLoad1BeginOp);
160433d6423SLionel Sambuc
161433d6423SLionel Sambuc
162433d6423SLionel Sambuc Op = WalkState->Op;
163433d6423SLionel Sambuc ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
164433d6423SLionel Sambuc
165433d6423SLionel Sambuc /* We are only interested in opcodes that have an associated name */
166433d6423SLionel Sambuc
167433d6423SLionel Sambuc if (Op)
168433d6423SLionel Sambuc {
169433d6423SLionel Sambuc if (!(WalkState->OpInfo->Flags & AML_NAMED))
170433d6423SLionel Sambuc {
171433d6423SLionel Sambuc *OutOp = Op;
172433d6423SLionel Sambuc return_ACPI_STATUS (AE_OK);
173433d6423SLionel Sambuc }
174433d6423SLionel Sambuc
175433d6423SLionel Sambuc /* Check if this object has already been installed in the namespace */
176433d6423SLionel Sambuc
177433d6423SLionel Sambuc if (Op->Common.Node)
178433d6423SLionel Sambuc {
179433d6423SLionel Sambuc *OutOp = Op;
180433d6423SLionel Sambuc return_ACPI_STATUS (AE_OK);
181433d6423SLionel Sambuc }
182433d6423SLionel Sambuc }
183433d6423SLionel Sambuc
184433d6423SLionel Sambuc Path = AcpiPsGetNextNamestring (&WalkState->ParserState);
185433d6423SLionel Sambuc
186433d6423SLionel Sambuc /* Map the raw opcode into an internal object type */
187433d6423SLionel Sambuc
188433d6423SLionel Sambuc ObjectType = WalkState->OpInfo->ObjectType;
189433d6423SLionel Sambuc
190433d6423SLionel Sambuc ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
191433d6423SLionel Sambuc "State=%p Op=%p [%s]\n", WalkState, Op, AcpiUtGetTypeName (ObjectType)));
192433d6423SLionel Sambuc
193433d6423SLionel Sambuc switch (WalkState->Opcode)
194433d6423SLionel Sambuc {
195433d6423SLionel Sambuc case AML_SCOPE_OP:
196433d6423SLionel Sambuc /*
197433d6423SLionel Sambuc * The target name of the Scope() operator must exist at this point so
198433d6423SLionel Sambuc * that we can actually open the scope to enter new names underneath it.
199433d6423SLionel Sambuc * Allow search-to-root for single namesegs.
200433d6423SLionel Sambuc */
201433d6423SLionel Sambuc Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
202433d6423SLionel Sambuc ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &(Node));
203433d6423SLionel Sambuc #ifdef ACPI_ASL_COMPILER
204433d6423SLionel Sambuc if (Status == AE_NOT_FOUND)
205433d6423SLionel Sambuc {
206433d6423SLionel Sambuc /*
207433d6423SLionel Sambuc * Table disassembly:
208433d6423SLionel Sambuc * Target of Scope() not found. Generate an External for it, and
209433d6423SLionel Sambuc * insert the name into the namespace.
210433d6423SLionel Sambuc */
211*29492bb7SDavid van Moolenbroek AcpiDmAddOpToExternalList (Op, Path, ACPI_TYPE_DEVICE, 0, 0);
212433d6423SLionel Sambuc Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
213433d6423SLionel Sambuc ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT,
214433d6423SLionel Sambuc WalkState, &Node);
215433d6423SLionel Sambuc }
216433d6423SLionel Sambuc #endif
217433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
218433d6423SLionel Sambuc {
219433d6423SLionel Sambuc ACPI_ERROR_NAMESPACE (Path, Status);
220433d6423SLionel Sambuc return_ACPI_STATUS (Status);
221433d6423SLionel Sambuc }
222433d6423SLionel Sambuc
223433d6423SLionel Sambuc /*
224433d6423SLionel Sambuc * Check to make sure that the target is
225433d6423SLionel Sambuc * one of the opcodes that actually opens a scope
226433d6423SLionel Sambuc */
227433d6423SLionel Sambuc switch (Node->Type)
228433d6423SLionel Sambuc {
229433d6423SLionel Sambuc case ACPI_TYPE_ANY:
230433d6423SLionel Sambuc case ACPI_TYPE_LOCAL_SCOPE: /* Scope */
231433d6423SLionel Sambuc case ACPI_TYPE_DEVICE:
232433d6423SLionel Sambuc case ACPI_TYPE_POWER:
233433d6423SLionel Sambuc case ACPI_TYPE_PROCESSOR:
234433d6423SLionel Sambuc case ACPI_TYPE_THERMAL:
235433d6423SLionel Sambuc
236433d6423SLionel Sambuc /* These are acceptable types */
237433d6423SLionel Sambuc break;
238433d6423SLionel Sambuc
239433d6423SLionel Sambuc case ACPI_TYPE_INTEGER:
240433d6423SLionel Sambuc case ACPI_TYPE_STRING:
241433d6423SLionel Sambuc case ACPI_TYPE_BUFFER:
242433d6423SLionel Sambuc /*
243433d6423SLionel Sambuc * These types we will allow, but we will change the type.
244433d6423SLionel Sambuc * This enables some existing code of the form:
245433d6423SLionel Sambuc *
246433d6423SLionel Sambuc * Name (DEB, 0)
247433d6423SLionel Sambuc * Scope (DEB) { ... }
248433d6423SLionel Sambuc *
249433d6423SLionel Sambuc * Note: silently change the type here. On the second pass,
250433d6423SLionel Sambuc * we will report a warning
251433d6423SLionel Sambuc */
252433d6423SLionel Sambuc ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
253433d6423SLionel Sambuc "Type override - [%4.4s] had invalid type (%s) "
254433d6423SLionel Sambuc "for Scope operator, changed to type ANY\n",
255433d6423SLionel Sambuc AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type)));
256433d6423SLionel Sambuc
257433d6423SLionel Sambuc Node->Type = ACPI_TYPE_ANY;
258433d6423SLionel Sambuc WalkState->ScopeInfo->Common.Value = ACPI_TYPE_ANY;
259433d6423SLionel Sambuc break;
260433d6423SLionel Sambuc
261*29492bb7SDavid van Moolenbroek case ACPI_TYPE_METHOD:
262*29492bb7SDavid van Moolenbroek /*
263*29492bb7SDavid van Moolenbroek * Allow scope change to root during execution of module-level
264*29492bb7SDavid van Moolenbroek * code. Root is typed METHOD during this time.
265*29492bb7SDavid van Moolenbroek */
266*29492bb7SDavid van Moolenbroek if ((Node == AcpiGbl_RootNode) &&
267*29492bb7SDavid van Moolenbroek (WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
268*29492bb7SDavid van Moolenbroek {
269*29492bb7SDavid van Moolenbroek break;
270*29492bb7SDavid van Moolenbroek }
271*29492bb7SDavid van Moolenbroek
272*29492bb7SDavid van Moolenbroek /*lint -fallthrough */
273*29492bb7SDavid van Moolenbroek
274433d6423SLionel Sambuc default:
275433d6423SLionel Sambuc
276433d6423SLionel Sambuc /* All other types are an error */
277433d6423SLionel Sambuc
278433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO,
279433d6423SLionel Sambuc "Invalid type (%s) for target of "
280433d6423SLionel Sambuc "Scope operator [%4.4s] (Cannot override)",
281433d6423SLionel Sambuc AcpiUtGetTypeName (Node->Type), AcpiUtGetNodeName (Node)));
282433d6423SLionel Sambuc
283433d6423SLionel Sambuc return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
284433d6423SLionel Sambuc }
285433d6423SLionel Sambuc break;
286433d6423SLionel Sambuc
287433d6423SLionel Sambuc default:
288433d6423SLionel Sambuc /*
289433d6423SLionel Sambuc * For all other named opcodes, we will enter the name into
290433d6423SLionel Sambuc * the namespace.
291433d6423SLionel Sambuc *
292433d6423SLionel Sambuc * Setup the search flags.
293433d6423SLionel Sambuc * Since we are entering a name into the namespace, we do not want to
294433d6423SLionel Sambuc * enable the search-to-root upsearch.
295433d6423SLionel Sambuc *
296433d6423SLionel Sambuc * There are only two conditions where it is acceptable that the name
297433d6423SLionel Sambuc * already exists:
298433d6423SLionel Sambuc * 1) the Scope() operator can reopen a scoping object that was
299433d6423SLionel Sambuc * previously defined (Scope, Method, Device, etc.)
300433d6423SLionel Sambuc * 2) Whenever we are parsing a deferred opcode (OpRegion, Buffer,
301433d6423SLionel Sambuc * BufferField, or Package), the name of the object is already
302433d6423SLionel Sambuc * in the namespace.
303433d6423SLionel Sambuc */
304433d6423SLionel Sambuc if (WalkState->DeferredNode)
305433d6423SLionel Sambuc {
306433d6423SLionel Sambuc /* This name is already in the namespace, get the node */
307433d6423SLionel Sambuc
308433d6423SLionel Sambuc Node = WalkState->DeferredNode;
309433d6423SLionel Sambuc Status = AE_OK;
310433d6423SLionel Sambuc break;
311433d6423SLionel Sambuc }
312433d6423SLionel Sambuc
313433d6423SLionel Sambuc /*
314433d6423SLionel Sambuc * If we are executing a method, do not create any namespace objects
315433d6423SLionel Sambuc * during the load phase, only during execution.
316433d6423SLionel Sambuc */
317433d6423SLionel Sambuc if (WalkState->MethodNode)
318433d6423SLionel Sambuc {
319433d6423SLionel Sambuc Node = NULL;
320433d6423SLionel Sambuc Status = AE_OK;
321433d6423SLionel Sambuc break;
322433d6423SLionel Sambuc }
323433d6423SLionel Sambuc
324433d6423SLionel Sambuc Flags = ACPI_NS_NO_UPSEARCH;
325433d6423SLionel Sambuc if ((WalkState->Opcode != AML_SCOPE_OP) &&
326433d6423SLionel Sambuc (!(WalkState->ParseFlags & ACPI_PARSE_DEFERRED_OP)))
327433d6423SLionel Sambuc {
328433d6423SLionel Sambuc Flags |= ACPI_NS_ERROR_IF_FOUND;
329433d6423SLionel Sambuc ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Cannot already exist\n",
330433d6423SLionel Sambuc AcpiUtGetTypeName (ObjectType)));
331433d6423SLionel Sambuc }
332433d6423SLionel Sambuc else
333433d6423SLionel Sambuc {
334433d6423SLionel Sambuc ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
335433d6423SLionel Sambuc "[%s] Both Find or Create allowed\n",
336433d6423SLionel Sambuc AcpiUtGetTypeName (ObjectType)));
337433d6423SLionel Sambuc }
338433d6423SLionel Sambuc
339433d6423SLionel Sambuc /*
340433d6423SLionel Sambuc * Enter the named type into the internal namespace. We enter the name
341433d6423SLionel Sambuc * as we go downward in the parse tree. Any necessary subobjects that
342433d6423SLionel Sambuc * involve arguments to the opcode must be created as we go back up the
343433d6423SLionel Sambuc * parse tree later.
344433d6423SLionel Sambuc */
345433d6423SLionel Sambuc Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
346433d6423SLionel Sambuc ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
347433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
348433d6423SLionel Sambuc {
349433d6423SLionel Sambuc if (Status == AE_ALREADY_EXISTS)
350433d6423SLionel Sambuc {
351433d6423SLionel Sambuc /* The name already exists in this scope */
352433d6423SLionel Sambuc
353433d6423SLionel Sambuc if (Node->Flags & ANOBJ_IS_EXTERNAL)
354433d6423SLionel Sambuc {
355433d6423SLionel Sambuc /*
356433d6423SLionel Sambuc * Allow one create on an object or segment that was
357433d6423SLionel Sambuc * previously declared External
358433d6423SLionel Sambuc */
359433d6423SLionel Sambuc Node->Flags &= ~ANOBJ_IS_EXTERNAL;
360433d6423SLionel Sambuc Node->Type = (UINT8) ObjectType;
361433d6423SLionel Sambuc
362433d6423SLionel Sambuc /* Just retyped a node, probably will need to open a scope */
363433d6423SLionel Sambuc
364433d6423SLionel Sambuc if (AcpiNsOpensScope (ObjectType))
365433d6423SLionel Sambuc {
366433d6423SLionel Sambuc Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
367433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
368433d6423SLionel Sambuc {
369433d6423SLionel Sambuc return_ACPI_STATUS (Status);
370433d6423SLionel Sambuc }
371433d6423SLionel Sambuc }
372433d6423SLionel Sambuc
373433d6423SLionel Sambuc Status = AE_OK;
374433d6423SLionel Sambuc }
375433d6423SLionel Sambuc }
376433d6423SLionel Sambuc
377433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
378433d6423SLionel Sambuc {
379433d6423SLionel Sambuc ACPI_ERROR_NAMESPACE (Path, Status);
380433d6423SLionel Sambuc return_ACPI_STATUS (Status);
381433d6423SLionel Sambuc }
382433d6423SLionel Sambuc }
383433d6423SLionel Sambuc break;
384433d6423SLionel Sambuc }
385433d6423SLionel Sambuc
386433d6423SLionel Sambuc /* Common exit */
387433d6423SLionel Sambuc
388433d6423SLionel Sambuc if (!Op)
389433d6423SLionel Sambuc {
390433d6423SLionel Sambuc /* Create a new op */
391433d6423SLionel Sambuc
392433d6423SLionel Sambuc Op = AcpiPsAllocOp (WalkState->Opcode);
393433d6423SLionel Sambuc if (!Op)
394433d6423SLionel Sambuc {
395433d6423SLionel Sambuc return_ACPI_STATUS (AE_NO_MEMORY);
396433d6423SLionel Sambuc }
397433d6423SLionel Sambuc }
398433d6423SLionel Sambuc
399433d6423SLionel Sambuc /* Initialize the op */
400433d6423SLionel Sambuc
401433d6423SLionel Sambuc #if (defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY))
402433d6423SLionel Sambuc Op->Named.Path = ACPI_CAST_PTR (UINT8, Path);
403433d6423SLionel Sambuc #endif
404433d6423SLionel Sambuc
405433d6423SLionel Sambuc if (Node)
406433d6423SLionel Sambuc {
407433d6423SLionel Sambuc /*
408433d6423SLionel Sambuc * Put the Node in the "op" object that the parser uses, so we
409433d6423SLionel Sambuc * can get it again quickly when this scope is closed
410433d6423SLionel Sambuc */
411433d6423SLionel Sambuc Op->Common.Node = Node;
412433d6423SLionel Sambuc Op->Named.Name = Node->Name.Integer;
413433d6423SLionel Sambuc }
414433d6423SLionel Sambuc
415433d6423SLionel Sambuc AcpiPsAppendArg (AcpiPsGetParentScope (&WalkState->ParserState), Op);
416433d6423SLionel Sambuc *OutOp = Op;
417433d6423SLionel Sambuc return_ACPI_STATUS (Status);
418433d6423SLionel Sambuc }
419433d6423SLionel Sambuc
420433d6423SLionel Sambuc
421433d6423SLionel Sambuc /*******************************************************************************
422433d6423SLionel Sambuc *
423433d6423SLionel Sambuc * FUNCTION: AcpiDsLoad1EndOp
424433d6423SLionel Sambuc *
425433d6423SLionel Sambuc * PARAMETERS: WalkState - Current state of the parse tree walk
426433d6423SLionel Sambuc *
427433d6423SLionel Sambuc * RETURN: Status
428433d6423SLionel Sambuc *
429433d6423SLionel Sambuc * DESCRIPTION: Ascending callback used during the loading of the namespace,
430433d6423SLionel Sambuc * both control methods and everything else.
431433d6423SLionel Sambuc *
432433d6423SLionel Sambuc ******************************************************************************/
433433d6423SLionel Sambuc
434433d6423SLionel Sambuc ACPI_STATUS
AcpiDsLoad1EndOp(ACPI_WALK_STATE * WalkState)435433d6423SLionel Sambuc AcpiDsLoad1EndOp (
436433d6423SLionel Sambuc ACPI_WALK_STATE *WalkState)
437433d6423SLionel Sambuc {
438433d6423SLionel Sambuc ACPI_PARSE_OBJECT *Op;
439433d6423SLionel Sambuc ACPI_OBJECT_TYPE ObjectType;
440433d6423SLionel Sambuc ACPI_STATUS Status = AE_OK;
441433d6423SLionel Sambuc
442433d6423SLionel Sambuc
443433d6423SLionel Sambuc ACPI_FUNCTION_TRACE (DsLoad1EndOp);
444433d6423SLionel Sambuc
445433d6423SLionel Sambuc
446433d6423SLionel Sambuc Op = WalkState->Op;
447433d6423SLionel Sambuc ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
448433d6423SLionel Sambuc
449433d6423SLionel Sambuc /* We are only interested in opcodes that have an associated name */
450433d6423SLionel Sambuc
451433d6423SLionel Sambuc if (!(WalkState->OpInfo->Flags & (AML_NAMED | AML_FIELD)))
452433d6423SLionel Sambuc {
453433d6423SLionel Sambuc return_ACPI_STATUS (AE_OK);
454433d6423SLionel Sambuc }
455433d6423SLionel Sambuc
456433d6423SLionel Sambuc /* Get the object type to determine if we should pop the scope */
457433d6423SLionel Sambuc
458433d6423SLionel Sambuc ObjectType = WalkState->OpInfo->ObjectType;
459433d6423SLionel Sambuc
460433d6423SLionel Sambuc #ifndef ACPI_NO_METHOD_EXECUTION
461433d6423SLionel Sambuc if (WalkState->OpInfo->Flags & AML_FIELD)
462433d6423SLionel Sambuc {
463433d6423SLionel Sambuc /*
464433d6423SLionel Sambuc * If we are executing a method, do not create any namespace objects
465433d6423SLionel Sambuc * during the load phase, only during execution.
466433d6423SLionel Sambuc */
467433d6423SLionel Sambuc if (!WalkState->MethodNode)
468433d6423SLionel Sambuc {
469433d6423SLionel Sambuc if (WalkState->Opcode == AML_FIELD_OP ||
470433d6423SLionel Sambuc WalkState->Opcode == AML_BANK_FIELD_OP ||
471433d6423SLionel Sambuc WalkState->Opcode == AML_INDEX_FIELD_OP)
472433d6423SLionel Sambuc {
473433d6423SLionel Sambuc Status = AcpiDsInitFieldObjects (Op, WalkState);
474433d6423SLionel Sambuc }
475433d6423SLionel Sambuc }
476433d6423SLionel Sambuc return_ACPI_STATUS (Status);
477433d6423SLionel Sambuc }
478433d6423SLionel Sambuc
479433d6423SLionel Sambuc /*
480433d6423SLionel Sambuc * If we are executing a method, do not create any namespace objects
481433d6423SLionel Sambuc * during the load phase, only during execution.
482433d6423SLionel Sambuc */
483433d6423SLionel Sambuc if (!WalkState->MethodNode)
484433d6423SLionel Sambuc {
485433d6423SLionel Sambuc if (Op->Common.AmlOpcode == AML_REGION_OP)
486433d6423SLionel Sambuc {
487433d6423SLionel Sambuc Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
488433d6423SLionel Sambuc (ACPI_ADR_SPACE_TYPE) ((Op->Common.Value.Arg)->Common.Value.Integer),
489433d6423SLionel Sambuc WalkState);
490433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
491433d6423SLionel Sambuc {
492433d6423SLionel Sambuc return_ACPI_STATUS (Status);
493433d6423SLionel Sambuc }
494433d6423SLionel Sambuc }
495433d6423SLionel Sambuc else if (Op->Common.AmlOpcode == AML_DATA_REGION_OP)
496433d6423SLionel Sambuc {
497433d6423SLionel Sambuc Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
498*29492bb7SDavid van Moolenbroek ACPI_ADR_SPACE_DATA_TABLE, WalkState);
499433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
500433d6423SLionel Sambuc {
501433d6423SLionel Sambuc return_ACPI_STATUS (Status);
502433d6423SLionel Sambuc }
503433d6423SLionel Sambuc }
504433d6423SLionel Sambuc }
505433d6423SLionel Sambuc #endif
506433d6423SLionel Sambuc
507433d6423SLionel Sambuc if (Op->Common.AmlOpcode == AML_NAME_OP)
508433d6423SLionel Sambuc {
509433d6423SLionel Sambuc /* For Name opcode, get the object type from the argument */
510433d6423SLionel Sambuc
511433d6423SLionel Sambuc if (Op->Common.Value.Arg)
512433d6423SLionel Sambuc {
513433d6423SLionel Sambuc ObjectType = (AcpiPsGetOpcodeInfo (
514433d6423SLionel Sambuc (Op->Common.Value.Arg)->Common.AmlOpcode))->ObjectType;
515433d6423SLionel Sambuc
516433d6423SLionel Sambuc /* Set node type if we have a namespace node */
517433d6423SLionel Sambuc
518433d6423SLionel Sambuc if (Op->Common.Node)
519433d6423SLionel Sambuc {
520433d6423SLionel Sambuc Op->Common.Node->Type = (UINT8) ObjectType;
521433d6423SLionel Sambuc }
522433d6423SLionel Sambuc }
523433d6423SLionel Sambuc }
524433d6423SLionel Sambuc
525433d6423SLionel Sambuc /*
526433d6423SLionel Sambuc * If we are executing a method, do not create any namespace objects
527433d6423SLionel Sambuc * during the load phase, only during execution.
528433d6423SLionel Sambuc */
529433d6423SLionel Sambuc if (!WalkState->MethodNode)
530433d6423SLionel Sambuc {
531433d6423SLionel Sambuc if (Op->Common.AmlOpcode == AML_METHOD_OP)
532433d6423SLionel Sambuc {
533433d6423SLionel Sambuc /*
534433d6423SLionel Sambuc * MethodOp PkgLength NameString MethodFlags TermList
535433d6423SLionel Sambuc *
536433d6423SLionel Sambuc * Note: We must create the method node/object pair as soon as we
537433d6423SLionel Sambuc * see the method declaration. This allows later pass1 parsing
538433d6423SLionel Sambuc * of invocations of the method (need to know the number of
539433d6423SLionel Sambuc * arguments.)
540433d6423SLionel Sambuc */
541433d6423SLionel Sambuc ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
542433d6423SLionel Sambuc "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
543433d6423SLionel Sambuc WalkState, Op, Op->Named.Node));
544433d6423SLionel Sambuc
545433d6423SLionel Sambuc if (!AcpiNsGetAttachedObject (Op->Named.Node))
546433d6423SLionel Sambuc {
547433d6423SLionel Sambuc WalkState->Operands[0] = ACPI_CAST_PTR (void, Op->Named.Node);
548433d6423SLionel Sambuc WalkState->NumOperands = 1;
549433d6423SLionel Sambuc
550433d6423SLionel Sambuc Status = AcpiDsCreateOperands (WalkState, Op->Common.Value.Arg);
551433d6423SLionel Sambuc if (ACPI_SUCCESS (Status))
552433d6423SLionel Sambuc {
553433d6423SLionel Sambuc Status = AcpiExCreateMethod (Op->Named.Data,
554433d6423SLionel Sambuc Op->Named.Length, WalkState);
555433d6423SLionel Sambuc }
556433d6423SLionel Sambuc
557433d6423SLionel Sambuc WalkState->Operands[0] = NULL;
558433d6423SLionel Sambuc WalkState->NumOperands = 0;
559433d6423SLionel Sambuc
560433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
561433d6423SLionel Sambuc {
562433d6423SLionel Sambuc return_ACPI_STATUS (Status);
563433d6423SLionel Sambuc }
564433d6423SLionel Sambuc }
565433d6423SLionel Sambuc }
566433d6423SLionel Sambuc }
567433d6423SLionel Sambuc
568433d6423SLionel Sambuc /* Pop the scope stack (only if loading a table) */
569433d6423SLionel Sambuc
570433d6423SLionel Sambuc if (!WalkState->MethodNode &&
571433d6423SLionel Sambuc AcpiNsOpensScope (ObjectType))
572433d6423SLionel Sambuc {
573433d6423SLionel Sambuc ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s): Popping scope for Op %p\n",
574433d6423SLionel Sambuc AcpiUtGetTypeName (ObjectType), Op));
575433d6423SLionel Sambuc
576433d6423SLionel Sambuc Status = AcpiDsScopeStackPop (WalkState);
577433d6423SLionel Sambuc }
578433d6423SLionel Sambuc
579433d6423SLionel Sambuc return_ACPI_STATUS (Status);
580433d6423SLionel Sambuc }
581