psloop.c revision 1.1.1.2.2.2 1 1.1.1.2.2.2 bouyer /******************************************************************************
2 1.1.1.2.2.2 bouyer *
3 1.1.1.2.2.2 bouyer * Module Name: psloop - Main AML parse loop
4 1.1.1.2.2.2 bouyer *
5 1.1.1.2.2.2 bouyer *****************************************************************************/
6 1.1.1.2.2.2 bouyer
7 1.1.1.2.2.2 bouyer /*
8 1.1.1.2.2.2 bouyer * Copyright (C) 2000 - 2011, Intel Corp.
9 1.1.1.2.2.2 bouyer * All rights reserved.
10 1.1.1.2.2.2 bouyer *
11 1.1.1.2.2.2 bouyer * Redistribution and use in source and binary forms, with or without
12 1.1.1.2.2.2 bouyer * modification, are permitted provided that the following conditions
13 1.1.1.2.2.2 bouyer * are met:
14 1.1.1.2.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
15 1.1.1.2.2.2 bouyer * notice, this list of conditions, and the following disclaimer,
16 1.1.1.2.2.2 bouyer * without modification.
17 1.1.1.2.2.2 bouyer * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.2.2.2 bouyer * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.2.2.2 bouyer * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.2.2.2 bouyer * including a substantially similar Disclaimer requirement for further
21 1.1.1.2.2.2 bouyer * binary redistribution.
22 1.1.1.2.2.2 bouyer * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.2.2.2 bouyer * of any contributors may be used to endorse or promote products derived
24 1.1.1.2.2.2 bouyer * from this software without specific prior written permission.
25 1.1.1.2.2.2 bouyer *
26 1.1.1.2.2.2 bouyer * Alternatively, this software may be distributed under the terms of the
27 1.1.1.2.2.2 bouyer * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.2.2.2 bouyer * Software Foundation.
29 1.1.1.2.2.2 bouyer *
30 1.1.1.2.2.2 bouyer * NO WARRANTY
31 1.1.1.2.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.2.2.2 bouyer * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.2.2.2 bouyer * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.2.2.2 bouyer * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.2.2.2 bouyer * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.2.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.2.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.2.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.2.2.2 bouyer * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.2.2.2 bouyer * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.2.2.2 bouyer * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.2.2.2 bouyer */
43 1.1.1.2.2.2 bouyer
44 1.1.1.2.2.2 bouyer
45 1.1.1.2.2.2 bouyer /*
46 1.1.1.2.2.2 bouyer * Parse the AML and build an operation tree as most interpreters, (such as
47 1.1.1.2.2.2 bouyer * Perl) do. Parsing is done by hand rather than with a YACC generated parser
48 1.1.1.2.2.2 bouyer * to tightly constrain stack and dynamic memory usage. Parsing is kept
49 1.1.1.2.2.2 bouyer * flexible and the code fairly compact by parsing based on a list of AML
50 1.1.1.2.2.2 bouyer * opcode templates in AmlOpInfo[].
51 1.1.1.2.2.2 bouyer */
52 1.1.1.2.2.2 bouyer
53 1.1.1.2.2.2 bouyer #include "acpi.h"
54 1.1.1.2.2.2 bouyer #include "accommon.h"
55 1.1.1.2.2.2 bouyer #include "acparser.h"
56 1.1.1.2.2.2 bouyer #include "acdispat.h"
57 1.1.1.2.2.2 bouyer #include "amlcode.h"
58 1.1.1.2.2.2 bouyer
59 1.1.1.2.2.2 bouyer #define _COMPONENT ACPI_PARSER
60 1.1.1.2.2.2 bouyer ACPI_MODULE_NAME ("psloop")
61 1.1.1.2.2.2 bouyer
62 1.1.1.2.2.2 bouyer static UINT32 AcpiGbl_Depth = 0;
63 1.1.1.2.2.2 bouyer
64 1.1.1.2.2.2 bouyer
65 1.1.1.2.2.2 bouyer /* Local prototypes */
66 1.1.1.2.2.2 bouyer
67 1.1.1.2.2.2 bouyer static ACPI_STATUS
68 1.1.1.2.2.2 bouyer AcpiPsGetAmlOpcode (
69 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState);
70 1.1.1.2.2.2 bouyer
71 1.1.1.2.2.2 bouyer static ACPI_STATUS
72 1.1.1.2.2.2 bouyer AcpiPsBuildNamedOp (
73 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState,
74 1.1.1.2.2.2 bouyer UINT8 *AmlOpStart,
75 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *UnnamedOp,
76 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT **Op);
77 1.1.1.2.2.2 bouyer
78 1.1.1.2.2.2 bouyer static ACPI_STATUS
79 1.1.1.2.2.2 bouyer AcpiPsCreateOp (
80 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState,
81 1.1.1.2.2.2 bouyer UINT8 *AmlOpStart,
82 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT **NewOp);
83 1.1.1.2.2.2 bouyer
84 1.1.1.2.2.2 bouyer static ACPI_STATUS
85 1.1.1.2.2.2 bouyer AcpiPsGetArguments (
86 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState,
87 1.1.1.2.2.2 bouyer UINT8 *AmlOpStart,
88 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *Op);
89 1.1.1.2.2.2 bouyer
90 1.1.1.2.2.2 bouyer static ACPI_STATUS
91 1.1.1.2.2.2 bouyer AcpiPsCompleteOp (
92 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState,
93 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT **Op,
94 1.1.1.2.2.2 bouyer ACPI_STATUS Status);
95 1.1.1.2.2.2 bouyer
96 1.1.1.2.2.2 bouyer static ACPI_STATUS
97 1.1.1.2.2.2 bouyer AcpiPsCompleteFinalOp (
98 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState,
99 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *Op,
100 1.1.1.2.2.2 bouyer ACPI_STATUS Status);
101 1.1.1.2.2.2 bouyer
102 1.1.1.2.2.2 bouyer static void
103 1.1.1.2.2.2 bouyer AcpiPsLinkModuleCode (
104 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *ParentOp,
105 1.1.1.2.2.2 bouyer UINT8 *AmlStart,
106 1.1.1.2.2.2 bouyer UINT32 AmlLength,
107 1.1.1.2.2.2 bouyer ACPI_OWNER_ID OwnerId);
108 1.1.1.2.2.2 bouyer
109 1.1.1.2.2.2 bouyer
110 1.1.1.2.2.2 bouyer /*******************************************************************************
111 1.1.1.2.2.2 bouyer *
112 1.1.1.2.2.2 bouyer * FUNCTION: AcpiPsGetAmlOpcode
113 1.1.1.2.2.2 bouyer *
114 1.1.1.2.2.2 bouyer * PARAMETERS: WalkState - Current state
115 1.1.1.2.2.2 bouyer *
116 1.1.1.2.2.2 bouyer * RETURN: Status
117 1.1.1.2.2.2 bouyer *
118 1.1.1.2.2.2 bouyer * DESCRIPTION: Extract the next AML opcode from the input stream.
119 1.1.1.2.2.2 bouyer *
120 1.1.1.2.2.2 bouyer ******************************************************************************/
121 1.1.1.2.2.2 bouyer
122 1.1.1.2.2.2 bouyer static ACPI_STATUS
123 1.1.1.2.2.2 bouyer AcpiPsGetAmlOpcode (
124 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState)
125 1.1.1.2.2.2 bouyer {
126 1.1.1.2.2.2 bouyer
127 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE_PTR (PsGetAmlOpcode, WalkState);
128 1.1.1.2.2.2 bouyer
129 1.1.1.2.2.2 bouyer
130 1.1.1.2.2.2 bouyer WalkState->AmlOffset = (UINT32) ACPI_PTR_DIFF (WalkState->ParserState.Aml,
131 1.1.1.2.2.2 bouyer WalkState->ParserState.AmlStart);
132 1.1.1.2.2.2 bouyer WalkState->Opcode = AcpiPsPeekOpcode (&(WalkState->ParserState));
133 1.1.1.2.2.2 bouyer
134 1.1.1.2.2.2 bouyer /*
135 1.1.1.2.2.2 bouyer * First cut to determine what we have found:
136 1.1.1.2.2.2 bouyer * 1) A valid AML opcode
137 1.1.1.2.2.2 bouyer * 2) A name string
138 1.1.1.2.2.2 bouyer * 3) An unknown/invalid opcode
139 1.1.1.2.2.2 bouyer */
140 1.1.1.2.2.2 bouyer WalkState->OpInfo = AcpiPsGetOpcodeInfo (WalkState->Opcode);
141 1.1.1.2.2.2 bouyer
142 1.1.1.2.2.2 bouyer switch (WalkState->OpInfo->Class)
143 1.1.1.2.2.2 bouyer {
144 1.1.1.2.2.2 bouyer case AML_CLASS_ASCII:
145 1.1.1.2.2.2 bouyer case AML_CLASS_PREFIX:
146 1.1.1.2.2.2 bouyer /*
147 1.1.1.2.2.2 bouyer * Starts with a valid prefix or ASCII char, this is a name
148 1.1.1.2.2.2 bouyer * string. Convert the bare name string to a namepath.
149 1.1.1.2.2.2 bouyer */
150 1.1.1.2.2.2 bouyer WalkState->Opcode = AML_INT_NAMEPATH_OP;
151 1.1.1.2.2.2 bouyer WalkState->ArgTypes = ARGP_NAMESTRING;
152 1.1.1.2.2.2 bouyer break;
153 1.1.1.2.2.2 bouyer
154 1.1.1.2.2.2 bouyer case AML_CLASS_UNKNOWN:
155 1.1.1.2.2.2 bouyer
156 1.1.1.2.2.2 bouyer /* The opcode is unrecognized. Just skip unknown opcodes */
157 1.1.1.2.2.2 bouyer
158 1.1.1.2.2.2 bouyer ACPI_ERROR ((AE_INFO,
159 1.1.1.2.2.2 bouyer "Found unknown opcode 0x%X at AML address %p offset 0x%X, ignoring",
160 1.1.1.2.2.2 bouyer WalkState->Opcode, WalkState->ParserState.Aml, WalkState->AmlOffset));
161 1.1.1.2.2.2 bouyer
162 1.1.1.2.2.2 bouyer ACPI_DUMP_BUFFER (WalkState->ParserState.Aml, 128);
163 1.1.1.2.2.2 bouyer
164 1.1.1.2.2.2 bouyer /* Assume one-byte bad opcode */
165 1.1.1.2.2.2 bouyer
166 1.1.1.2.2.2 bouyer WalkState->ParserState.Aml++;
167 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE);
168 1.1.1.2.2.2 bouyer
169 1.1.1.2.2.2 bouyer default:
170 1.1.1.2.2.2 bouyer
171 1.1.1.2.2.2 bouyer /* Found opcode info, this is a normal opcode */
172 1.1.1.2.2.2 bouyer
173 1.1.1.2.2.2 bouyer WalkState->ParserState.Aml += AcpiPsGetOpcodeSize (WalkState->Opcode);
174 1.1.1.2.2.2 bouyer WalkState->ArgTypes = WalkState->OpInfo->ParseArgs;
175 1.1.1.2.2.2 bouyer break;
176 1.1.1.2.2.2 bouyer }
177 1.1.1.2.2.2 bouyer
178 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_OK);
179 1.1.1.2.2.2 bouyer }
180 1.1.1.2.2.2 bouyer
181 1.1.1.2.2.2 bouyer
182 1.1.1.2.2.2 bouyer /*******************************************************************************
183 1.1.1.2.2.2 bouyer *
184 1.1.1.2.2.2 bouyer * FUNCTION: AcpiPsBuildNamedOp
185 1.1.1.2.2.2 bouyer *
186 1.1.1.2.2.2 bouyer * PARAMETERS: WalkState - Current state
187 1.1.1.2.2.2 bouyer * AmlOpStart - Begin of named Op in AML
188 1.1.1.2.2.2 bouyer * UnnamedOp - Early Op (not a named Op)
189 1.1.1.2.2.2 bouyer * Op - Returned Op
190 1.1.1.2.2.2 bouyer *
191 1.1.1.2.2.2 bouyer * RETURN: Status
192 1.1.1.2.2.2 bouyer *
193 1.1.1.2.2.2 bouyer * DESCRIPTION: Parse a named Op
194 1.1.1.2.2.2 bouyer *
195 1.1.1.2.2.2 bouyer ******************************************************************************/
196 1.1.1.2.2.2 bouyer
197 1.1.1.2.2.2 bouyer static ACPI_STATUS
198 1.1.1.2.2.2 bouyer AcpiPsBuildNamedOp (
199 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState,
200 1.1.1.2.2.2 bouyer UINT8 *AmlOpStart,
201 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *UnnamedOp,
202 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT **Op)
203 1.1.1.2.2.2 bouyer {
204 1.1.1.2.2.2 bouyer ACPI_STATUS Status = AE_OK;
205 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *Arg = NULL;
206 1.1.1.2.2.2 bouyer
207 1.1.1.2.2.2 bouyer
208 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE_PTR (PsBuildNamedOp, WalkState);
209 1.1.1.2.2.2 bouyer
210 1.1.1.2.2.2 bouyer
211 1.1.1.2.2.2 bouyer UnnamedOp->Common.Value.Arg = NULL;
212 1.1.1.2.2.2 bouyer UnnamedOp->Common.ArgListLength = 0;
213 1.1.1.2.2.2 bouyer UnnamedOp->Common.AmlOpcode = WalkState->Opcode;
214 1.1.1.2.2.2 bouyer
215 1.1.1.2.2.2 bouyer /*
216 1.1.1.2.2.2 bouyer * Get and append arguments until we find the node that contains
217 1.1.1.2.2.2 bouyer * the name (the type ARGP_NAME).
218 1.1.1.2.2.2 bouyer */
219 1.1.1.2.2.2 bouyer while (GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) &&
220 1.1.1.2.2.2 bouyer (GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) != ARGP_NAME))
221 1.1.1.2.2.2 bouyer {
222 1.1.1.2.2.2 bouyer Status = AcpiPsGetNextArg (WalkState, &(WalkState->ParserState),
223 1.1.1.2.2.2 bouyer GET_CURRENT_ARG_TYPE (WalkState->ArgTypes), &Arg);
224 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
225 1.1.1.2.2.2 bouyer {
226 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
227 1.1.1.2.2.2 bouyer }
228 1.1.1.2.2.2 bouyer
229 1.1.1.2.2.2 bouyer AcpiPsAppendArg (UnnamedOp, Arg);
230 1.1.1.2.2.2 bouyer INCREMENT_ARG_LIST (WalkState->ArgTypes);
231 1.1.1.2.2.2 bouyer }
232 1.1.1.2.2.2 bouyer
233 1.1.1.2.2.2 bouyer /*
234 1.1.1.2.2.2 bouyer * Make sure that we found a NAME and didn't run out of arguments
235 1.1.1.2.2.2 bouyer */
236 1.1.1.2.2.2 bouyer if (!GET_CURRENT_ARG_TYPE (WalkState->ArgTypes))
237 1.1.1.2.2.2 bouyer {
238 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_AML_NO_OPERAND);
239 1.1.1.2.2.2 bouyer }
240 1.1.1.2.2.2 bouyer
241 1.1.1.2.2.2 bouyer /* We know that this arg is a name, move to next arg */
242 1.1.1.2.2.2 bouyer
243 1.1.1.2.2.2 bouyer INCREMENT_ARG_LIST (WalkState->ArgTypes);
244 1.1.1.2.2.2 bouyer
245 1.1.1.2.2.2 bouyer /*
246 1.1.1.2.2.2 bouyer * Find the object. This will either insert the object into
247 1.1.1.2.2.2 bouyer * the namespace or simply look it up
248 1.1.1.2.2.2 bouyer */
249 1.1.1.2.2.2 bouyer WalkState->Op = NULL;
250 1.1.1.2.2.2 bouyer
251 1.1.1.2.2.2 bouyer Status = WalkState->DescendingCallback (WalkState, Op);
252 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
253 1.1.1.2.2.2 bouyer {
254 1.1.1.2.2.2 bouyer ACPI_EXCEPTION ((AE_INFO, Status, "During name lookup/catalog"));
255 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
256 1.1.1.2.2.2 bouyer }
257 1.1.1.2.2.2 bouyer
258 1.1.1.2.2.2 bouyer if (!*Op)
259 1.1.1.2.2.2 bouyer {
260 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE);
261 1.1.1.2.2.2 bouyer }
262 1.1.1.2.2.2 bouyer
263 1.1.1.2.2.2 bouyer Status = AcpiPsNextParseState (WalkState, *Op, Status);
264 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
265 1.1.1.2.2.2 bouyer {
266 1.1.1.2.2.2 bouyer if (Status == AE_CTRL_PENDING)
267 1.1.1.2.2.2 bouyer {
268 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_CTRL_PARSE_PENDING);
269 1.1.1.2.2.2 bouyer }
270 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
271 1.1.1.2.2.2 bouyer }
272 1.1.1.2.2.2 bouyer
273 1.1.1.2.2.2 bouyer AcpiPsAppendArg (*Op, UnnamedOp->Common.Value.Arg);
274 1.1.1.2.2.2 bouyer AcpiGbl_Depth++;
275 1.1.1.2.2.2 bouyer
276 1.1.1.2.2.2 bouyer if ((*Op)->Common.AmlOpcode == AML_REGION_OP ||
277 1.1.1.2.2.2 bouyer (*Op)->Common.AmlOpcode == AML_DATA_REGION_OP)
278 1.1.1.2.2.2 bouyer {
279 1.1.1.2.2.2 bouyer /*
280 1.1.1.2.2.2 bouyer * Defer final parsing of an OperationRegion body, because we don't
281 1.1.1.2.2.2 bouyer * have enough info in the first pass to parse it correctly (i.e.,
282 1.1.1.2.2.2 bouyer * there may be method calls within the TermArg elements of the body.)
283 1.1.1.2.2.2 bouyer *
284 1.1.1.2.2.2 bouyer * However, we must continue parsing because the opregion is not a
285 1.1.1.2.2.2 bouyer * standalone package -- we don't know where the end is at this point.
286 1.1.1.2.2.2 bouyer *
287 1.1.1.2.2.2 bouyer * (Length is unknown until parse of the body complete)
288 1.1.1.2.2.2 bouyer */
289 1.1.1.2.2.2 bouyer (*Op)->Named.Data = AmlOpStart;
290 1.1.1.2.2.2 bouyer (*Op)->Named.Length = 0;
291 1.1.1.2.2.2 bouyer }
292 1.1.1.2.2.2 bouyer
293 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_OK);
294 1.1.1.2.2.2 bouyer }
295 1.1.1.2.2.2 bouyer
296 1.1.1.2.2.2 bouyer
297 1.1.1.2.2.2 bouyer /*******************************************************************************
298 1.1.1.2.2.2 bouyer *
299 1.1.1.2.2.2 bouyer * FUNCTION: AcpiPsCreateOp
300 1.1.1.2.2.2 bouyer *
301 1.1.1.2.2.2 bouyer * PARAMETERS: WalkState - Current state
302 1.1.1.2.2.2 bouyer * AmlOpStart - Op start in AML
303 1.1.1.2.2.2 bouyer * NewOp - Returned Op
304 1.1.1.2.2.2 bouyer *
305 1.1.1.2.2.2 bouyer * RETURN: Status
306 1.1.1.2.2.2 bouyer *
307 1.1.1.2.2.2 bouyer * DESCRIPTION: Get Op from AML
308 1.1.1.2.2.2 bouyer *
309 1.1.1.2.2.2 bouyer ******************************************************************************/
310 1.1.1.2.2.2 bouyer
311 1.1.1.2.2.2 bouyer static ACPI_STATUS
312 1.1.1.2.2.2 bouyer AcpiPsCreateOp (
313 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState,
314 1.1.1.2.2.2 bouyer UINT8 *AmlOpStart,
315 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT **NewOp)
316 1.1.1.2.2.2 bouyer {
317 1.1.1.2.2.2 bouyer ACPI_STATUS Status = AE_OK;
318 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *Op;
319 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *NamedOp = NULL;
320 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *ParentScope;
321 1.1.1.2.2.2 bouyer UINT8 ArgumentCount;
322 1.1.1.2.2.2 bouyer const ACPI_OPCODE_INFO *OpInfo;
323 1.1.1.2.2.2 bouyer
324 1.1.1.2.2.2 bouyer
325 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE_PTR (PsCreateOp, WalkState);
326 1.1.1.2.2.2 bouyer
327 1.1.1.2.2.2 bouyer
328 1.1.1.2.2.2 bouyer Status = AcpiPsGetAmlOpcode (WalkState);
329 1.1.1.2.2.2 bouyer if (Status == AE_CTRL_PARSE_CONTINUE)
330 1.1.1.2.2.2 bouyer {
331 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE);
332 1.1.1.2.2.2 bouyer }
333 1.1.1.2.2.2 bouyer
334 1.1.1.2.2.2 bouyer /* Create Op structure and append to parent's argument list */
335 1.1.1.2.2.2 bouyer
336 1.1.1.2.2.2 bouyer WalkState->OpInfo = AcpiPsGetOpcodeInfo (WalkState->Opcode);
337 1.1.1.2.2.2 bouyer Op = AcpiPsAllocOp (WalkState->Opcode);
338 1.1.1.2.2.2 bouyer if (!Op)
339 1.1.1.2.2.2 bouyer {
340 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_NO_MEMORY);
341 1.1.1.2.2.2 bouyer }
342 1.1.1.2.2.2 bouyer
343 1.1.1.2.2.2 bouyer if (WalkState->OpInfo->Flags & AML_NAMED)
344 1.1.1.2.2.2 bouyer {
345 1.1.1.2.2.2 bouyer Status = AcpiPsBuildNamedOp (WalkState, AmlOpStart, Op, &NamedOp);
346 1.1.1.2.2.2 bouyer AcpiPsFreeOp (Op);
347 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
348 1.1.1.2.2.2 bouyer {
349 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
350 1.1.1.2.2.2 bouyer }
351 1.1.1.2.2.2 bouyer
352 1.1.1.2.2.2 bouyer *NewOp = NamedOp;
353 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_OK);
354 1.1.1.2.2.2 bouyer }
355 1.1.1.2.2.2 bouyer
356 1.1.1.2.2.2 bouyer /* Not a named opcode, just allocate Op and append to parent */
357 1.1.1.2.2.2 bouyer
358 1.1.1.2.2.2 bouyer if (WalkState->OpInfo->Flags & AML_CREATE)
359 1.1.1.2.2.2 bouyer {
360 1.1.1.2.2.2 bouyer /*
361 1.1.1.2.2.2 bouyer * Backup to beginning of CreateXXXfield declaration
362 1.1.1.2.2.2 bouyer * BodyLength is unknown until we parse the body
363 1.1.1.2.2.2 bouyer */
364 1.1.1.2.2.2 bouyer Op->Named.Data = AmlOpStart;
365 1.1.1.2.2.2 bouyer Op->Named.Length = 0;
366 1.1.1.2.2.2 bouyer }
367 1.1.1.2.2.2 bouyer
368 1.1.1.2.2.2 bouyer if (WalkState->Opcode == AML_BANK_FIELD_OP)
369 1.1.1.2.2.2 bouyer {
370 1.1.1.2.2.2 bouyer /*
371 1.1.1.2.2.2 bouyer * Backup to beginning of BankField declaration
372 1.1.1.2.2.2 bouyer * BodyLength is unknown until we parse the body
373 1.1.1.2.2.2 bouyer */
374 1.1.1.2.2.2 bouyer Op->Named.Data = AmlOpStart;
375 1.1.1.2.2.2 bouyer Op->Named.Length = 0;
376 1.1.1.2.2.2 bouyer }
377 1.1.1.2.2.2 bouyer
378 1.1.1.2.2.2 bouyer ParentScope = AcpiPsGetParentScope (&(WalkState->ParserState));
379 1.1.1.2.2.2 bouyer AcpiPsAppendArg (ParentScope, Op);
380 1.1.1.2.2.2 bouyer
381 1.1.1.2.2.2 bouyer if (ParentScope)
382 1.1.1.2.2.2 bouyer {
383 1.1.1.2.2.2 bouyer OpInfo = AcpiPsGetOpcodeInfo (ParentScope->Common.AmlOpcode);
384 1.1.1.2.2.2 bouyer if (OpInfo->Flags & AML_HAS_TARGET)
385 1.1.1.2.2.2 bouyer {
386 1.1.1.2.2.2 bouyer ArgumentCount = AcpiPsGetArgumentCount (OpInfo->Type);
387 1.1.1.2.2.2 bouyer if (ParentScope->Common.ArgListLength > ArgumentCount)
388 1.1.1.2.2.2 bouyer {
389 1.1.1.2.2.2 bouyer Op->Common.Flags |= ACPI_PARSEOP_TARGET;
390 1.1.1.2.2.2 bouyer }
391 1.1.1.2.2.2 bouyer }
392 1.1.1.2.2.2 bouyer else if (ParentScope->Common.AmlOpcode == AML_INCREMENT_OP)
393 1.1.1.2.2.2 bouyer {
394 1.1.1.2.2.2 bouyer Op->Common.Flags |= ACPI_PARSEOP_TARGET;
395 1.1.1.2.2.2 bouyer }
396 1.1.1.2.2.2 bouyer }
397 1.1.1.2.2.2 bouyer
398 1.1.1.2.2.2 bouyer if (WalkState->DescendingCallback != NULL)
399 1.1.1.2.2.2 bouyer {
400 1.1.1.2.2.2 bouyer /*
401 1.1.1.2.2.2 bouyer * Find the object. This will either insert the object into
402 1.1.1.2.2.2 bouyer * the namespace or simply look it up
403 1.1.1.2.2.2 bouyer */
404 1.1.1.2.2.2 bouyer WalkState->Op = *NewOp = Op;
405 1.1.1.2.2.2 bouyer
406 1.1.1.2.2.2 bouyer Status = WalkState->DescendingCallback (WalkState, &Op);
407 1.1.1.2.2.2 bouyer Status = AcpiPsNextParseState (WalkState, Op, Status);
408 1.1.1.2.2.2 bouyer if (Status == AE_CTRL_PENDING)
409 1.1.1.2.2.2 bouyer {
410 1.1.1.2.2.2 bouyer Status = AE_CTRL_PARSE_PENDING;
411 1.1.1.2.2.2 bouyer }
412 1.1.1.2.2.2 bouyer }
413 1.1.1.2.2.2 bouyer
414 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
415 1.1.1.2.2.2 bouyer }
416 1.1.1.2.2.2 bouyer
417 1.1.1.2.2.2 bouyer
418 1.1.1.2.2.2 bouyer /*******************************************************************************
419 1.1.1.2.2.2 bouyer *
420 1.1.1.2.2.2 bouyer * FUNCTION: AcpiPsGetArguments
421 1.1.1.2.2.2 bouyer *
422 1.1.1.2.2.2 bouyer * PARAMETERS: WalkState - Current state
423 1.1.1.2.2.2 bouyer * AmlOpStart - Op start in AML
424 1.1.1.2.2.2 bouyer * Op - Current Op
425 1.1.1.2.2.2 bouyer *
426 1.1.1.2.2.2 bouyer * RETURN: Status
427 1.1.1.2.2.2 bouyer *
428 1.1.1.2.2.2 bouyer * DESCRIPTION: Get arguments for passed Op.
429 1.1.1.2.2.2 bouyer *
430 1.1.1.2.2.2 bouyer ******************************************************************************/
431 1.1.1.2.2.2 bouyer
432 1.1.1.2.2.2 bouyer static ACPI_STATUS
433 1.1.1.2.2.2 bouyer AcpiPsGetArguments (
434 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState,
435 1.1.1.2.2.2 bouyer UINT8 *AmlOpStart,
436 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *Op)
437 1.1.1.2.2.2 bouyer {
438 1.1.1.2.2.2 bouyer ACPI_STATUS Status = AE_OK;
439 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *Arg = NULL;
440 1.1.1.2.2.2 bouyer const ACPI_OPCODE_INFO *OpInfo;
441 1.1.1.2.2.2 bouyer
442 1.1.1.2.2.2 bouyer
443 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE_PTR (PsGetArguments, WalkState);
444 1.1.1.2.2.2 bouyer
445 1.1.1.2.2.2 bouyer
446 1.1.1.2.2.2 bouyer switch (Op->Common.AmlOpcode)
447 1.1.1.2.2.2 bouyer {
448 1.1.1.2.2.2 bouyer case AML_BYTE_OP: /* AML_BYTEDATA_ARG */
449 1.1.1.2.2.2 bouyer case AML_WORD_OP: /* AML_WORDDATA_ARG */
450 1.1.1.2.2.2 bouyer case AML_DWORD_OP: /* AML_DWORDATA_ARG */
451 1.1.1.2.2.2 bouyer case AML_QWORD_OP: /* AML_QWORDATA_ARG */
452 1.1.1.2.2.2 bouyer case AML_STRING_OP: /* AML_ASCIICHARLIST_ARG */
453 1.1.1.2.2.2 bouyer
454 1.1.1.2.2.2 bouyer /* Fill in constant or string argument directly */
455 1.1.1.2.2.2 bouyer
456 1.1.1.2.2.2 bouyer AcpiPsGetNextSimpleArg (&(WalkState->ParserState),
457 1.1.1.2.2.2 bouyer GET_CURRENT_ARG_TYPE (WalkState->ArgTypes), Op);
458 1.1.1.2.2.2 bouyer break;
459 1.1.1.2.2.2 bouyer
460 1.1.1.2.2.2 bouyer case AML_INT_NAMEPATH_OP: /* AML_NAMESTRING_ARG */
461 1.1.1.2.2.2 bouyer
462 1.1.1.2.2.2 bouyer Status = AcpiPsGetNextNamepath (WalkState, &(WalkState->ParserState), Op, 1);
463 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
464 1.1.1.2.2.2 bouyer {
465 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
466 1.1.1.2.2.2 bouyer }
467 1.1.1.2.2.2 bouyer
468 1.1.1.2.2.2 bouyer WalkState->ArgTypes = 0;
469 1.1.1.2.2.2 bouyer break;
470 1.1.1.2.2.2 bouyer
471 1.1.1.2.2.2 bouyer default:
472 1.1.1.2.2.2 bouyer /*
473 1.1.1.2.2.2 bouyer * Op is not a constant or string, append each argument to the Op
474 1.1.1.2.2.2 bouyer */
475 1.1.1.2.2.2 bouyer while (GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) && !WalkState->ArgCount)
476 1.1.1.2.2.2 bouyer {
477 1.1.1.2.2.2 bouyer WalkState->AmlOffset = (UINT32) ACPI_PTR_DIFF (WalkState->ParserState.Aml,
478 1.1.1.2.2.2 bouyer WalkState->ParserState.AmlStart);
479 1.1.1.2.2.2 bouyer
480 1.1.1.2.2.2 bouyer Status = AcpiPsGetNextArg (WalkState, &(WalkState->ParserState),
481 1.1.1.2.2.2 bouyer GET_CURRENT_ARG_TYPE (WalkState->ArgTypes), &Arg);
482 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
483 1.1.1.2.2.2 bouyer {
484 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
485 1.1.1.2.2.2 bouyer }
486 1.1.1.2.2.2 bouyer
487 1.1.1.2.2.2 bouyer if (Arg)
488 1.1.1.2.2.2 bouyer {
489 1.1.1.2.2.2 bouyer Arg->Common.AmlOffset = WalkState->AmlOffset;
490 1.1.1.2.2.2 bouyer AcpiPsAppendArg (Op, Arg);
491 1.1.1.2.2.2 bouyer }
492 1.1.1.2.2.2 bouyer
493 1.1.1.2.2.2 bouyer INCREMENT_ARG_LIST (WalkState->ArgTypes);
494 1.1.1.2.2.2 bouyer }
495 1.1.1.2.2.2 bouyer
496 1.1.1.2.2.2 bouyer
497 1.1.1.2.2.2 bouyer /*
498 1.1.1.2.2.2 bouyer * Handle executable code at "module-level". This refers to
499 1.1.1.2.2.2 bouyer * executable opcodes that appear outside of any control method.
500 1.1.1.2.2.2 bouyer */
501 1.1.1.2.2.2 bouyer if ((WalkState->PassNumber <= ACPI_IMODE_LOAD_PASS2) &&
502 1.1.1.2.2.2 bouyer ((WalkState->ParseFlags & ACPI_PARSE_DISASSEMBLE) == 0))
503 1.1.1.2.2.2 bouyer {
504 1.1.1.2.2.2 bouyer /*
505 1.1.1.2.2.2 bouyer * We want to skip If/Else/While constructs during Pass1 because we
506 1.1.1.2.2.2 bouyer * want to actually conditionally execute the code during Pass2.
507 1.1.1.2.2.2 bouyer *
508 1.1.1.2.2.2 bouyer * Except for disassembly, where we always want to walk the
509 1.1.1.2.2.2 bouyer * If/Else/While packages
510 1.1.1.2.2.2 bouyer */
511 1.1.1.2.2.2 bouyer switch (Op->Common.AmlOpcode)
512 1.1.1.2.2.2 bouyer {
513 1.1.1.2.2.2 bouyer case AML_IF_OP:
514 1.1.1.2.2.2 bouyer case AML_ELSE_OP:
515 1.1.1.2.2.2 bouyer case AML_WHILE_OP:
516 1.1.1.2.2.2 bouyer
517 1.1.1.2.2.2 bouyer /*
518 1.1.1.2.2.2 bouyer * Currently supported module-level opcodes are:
519 1.1.1.2.2.2 bouyer * IF/ELSE/WHILE. These appear to be the most common,
520 1.1.1.2.2.2 bouyer * and easiest to support since they open an AML
521 1.1.1.2.2.2 bouyer * package.
522 1.1.1.2.2.2 bouyer */
523 1.1.1.2.2.2 bouyer if (WalkState->PassNumber == ACPI_IMODE_LOAD_PASS1)
524 1.1.1.2.2.2 bouyer {
525 1.1.1.2.2.2 bouyer AcpiPsLinkModuleCode (Op->Common.Parent, AmlOpStart,
526 1.1.1.2.2.2 bouyer (UINT32) (WalkState->ParserState.PkgEnd - AmlOpStart),
527 1.1.1.2.2.2 bouyer WalkState->OwnerId);
528 1.1.1.2.2.2 bouyer }
529 1.1.1.2.2.2 bouyer
530 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
531 1.1.1.2.2.2 bouyer "Pass1: Skipping an If/Else/While body\n"));
532 1.1.1.2.2.2 bouyer
533 1.1.1.2.2.2 bouyer /* Skip body of if/else/while in pass 1 */
534 1.1.1.2.2.2 bouyer
535 1.1.1.2.2.2 bouyer WalkState->ParserState.Aml = WalkState->ParserState.PkgEnd;
536 1.1.1.2.2.2 bouyer WalkState->ArgCount = 0;
537 1.1.1.2.2.2 bouyer break;
538 1.1.1.2.2.2 bouyer
539 1.1.1.2.2.2 bouyer default:
540 1.1.1.2.2.2 bouyer /*
541 1.1.1.2.2.2 bouyer * Check for an unsupported executable opcode at module
542 1.1.1.2.2.2 bouyer * level. We must be in PASS1, the parent must be a SCOPE,
543 1.1.1.2.2.2 bouyer * The opcode class must be EXECUTE, and the opcode must
544 1.1.1.2.2.2 bouyer * not be an argument to another opcode.
545 1.1.1.2.2.2 bouyer */
546 1.1.1.2.2.2 bouyer if ((WalkState->PassNumber == ACPI_IMODE_LOAD_PASS1) &&
547 1.1.1.2.2.2 bouyer (Op->Common.Parent->Common.AmlOpcode == AML_SCOPE_OP))
548 1.1.1.2.2.2 bouyer {
549 1.1.1.2.2.2 bouyer OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
550 1.1.1.2.2.2 bouyer if ((OpInfo->Class == AML_CLASS_EXECUTE) &&
551 1.1.1.2.2.2 bouyer (!Arg))
552 1.1.1.2.2.2 bouyer {
553 1.1.1.2.2.2 bouyer ACPI_WARNING ((AE_INFO,
554 1.1.1.2.2.2 bouyer "Detected an unsupported executable opcode "
555 1.1.1.2.2.2 bouyer "at module-level: [0x%.4X] at table offset 0x%.4X",
556 1.1.1.2.2.2 bouyer Op->Common.AmlOpcode,
557 1.1.1.2.2.2 bouyer (UINT32) (ACPI_PTR_DIFF (AmlOpStart,
558 1.1.1.2.2.2 bouyer WalkState->ParserState.AmlStart) +
559 1.1.1.2.2.2 bouyer sizeof (ACPI_TABLE_HEADER))));
560 1.1.1.2.2.2 bouyer }
561 1.1.1.2.2.2 bouyer }
562 1.1.1.2.2.2 bouyer break;
563 1.1.1.2.2.2 bouyer }
564 1.1.1.2.2.2 bouyer }
565 1.1.1.2.2.2 bouyer
566 1.1.1.2.2.2 bouyer /* Special processing for certain opcodes */
567 1.1.1.2.2.2 bouyer
568 1.1.1.2.2.2 bouyer switch (Op->Common.AmlOpcode)
569 1.1.1.2.2.2 bouyer {
570 1.1.1.2.2.2 bouyer case AML_METHOD_OP:
571 1.1.1.2.2.2 bouyer /*
572 1.1.1.2.2.2 bouyer * Skip parsing of control method because we don't have enough
573 1.1.1.2.2.2 bouyer * info in the first pass to parse it correctly.
574 1.1.1.2.2.2 bouyer *
575 1.1.1.2.2.2 bouyer * Save the length and address of the body
576 1.1.1.2.2.2 bouyer */
577 1.1.1.2.2.2 bouyer Op->Named.Data = WalkState->ParserState.Aml;
578 1.1.1.2.2.2 bouyer Op->Named.Length = (UINT32)
579 1.1.1.2.2.2 bouyer (WalkState->ParserState.PkgEnd - WalkState->ParserState.Aml);
580 1.1.1.2.2.2 bouyer
581 1.1.1.2.2.2 bouyer /* Skip body of method */
582 1.1.1.2.2.2 bouyer
583 1.1.1.2.2.2 bouyer WalkState->ParserState.Aml = WalkState->ParserState.PkgEnd;
584 1.1.1.2.2.2 bouyer WalkState->ArgCount = 0;
585 1.1.1.2.2.2 bouyer break;
586 1.1.1.2.2.2 bouyer
587 1.1.1.2.2.2 bouyer case AML_BUFFER_OP:
588 1.1.1.2.2.2 bouyer case AML_PACKAGE_OP:
589 1.1.1.2.2.2 bouyer case AML_VAR_PACKAGE_OP:
590 1.1.1.2.2.2 bouyer
591 1.1.1.2.2.2 bouyer if ((Op->Common.Parent) &&
592 1.1.1.2.2.2 bouyer (Op->Common.Parent->Common.AmlOpcode == AML_NAME_OP) &&
593 1.1.1.2.2.2 bouyer (WalkState->PassNumber <= ACPI_IMODE_LOAD_PASS2))
594 1.1.1.2.2.2 bouyer {
595 1.1.1.2.2.2 bouyer /*
596 1.1.1.2.2.2 bouyer * Skip parsing of Buffers and Packages because we don't have
597 1.1.1.2.2.2 bouyer * enough info in the first pass to parse them correctly.
598 1.1.1.2.2.2 bouyer */
599 1.1.1.2.2.2 bouyer Op->Named.Data = AmlOpStart;
600 1.1.1.2.2.2 bouyer Op->Named.Length = (UINT32)
601 1.1.1.2.2.2 bouyer (WalkState->ParserState.PkgEnd - AmlOpStart);
602 1.1.1.2.2.2 bouyer
603 1.1.1.2.2.2 bouyer /* Skip body */
604 1.1.1.2.2.2 bouyer
605 1.1.1.2.2.2 bouyer WalkState->ParserState.Aml = WalkState->ParserState.PkgEnd;
606 1.1.1.2.2.2 bouyer WalkState->ArgCount = 0;
607 1.1.1.2.2.2 bouyer }
608 1.1.1.2.2.2 bouyer break;
609 1.1.1.2.2.2 bouyer
610 1.1.1.2.2.2 bouyer case AML_WHILE_OP:
611 1.1.1.2.2.2 bouyer
612 1.1.1.2.2.2 bouyer if (WalkState->ControlState)
613 1.1.1.2.2.2 bouyer {
614 1.1.1.2.2.2 bouyer WalkState->ControlState->Control.PackageEnd =
615 1.1.1.2.2.2 bouyer WalkState->ParserState.PkgEnd;
616 1.1.1.2.2.2 bouyer }
617 1.1.1.2.2.2 bouyer break;
618 1.1.1.2.2.2 bouyer
619 1.1.1.2.2.2 bouyer default:
620 1.1.1.2.2.2 bouyer
621 1.1.1.2.2.2 bouyer /* No action for all other opcodes */
622 1.1.1.2.2.2 bouyer break;
623 1.1.1.2.2.2 bouyer }
624 1.1.1.2.2.2 bouyer
625 1.1.1.2.2.2 bouyer break;
626 1.1.1.2.2.2 bouyer }
627 1.1.1.2.2.2 bouyer
628 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_OK);
629 1.1.1.2.2.2 bouyer }
630 1.1.1.2.2.2 bouyer
631 1.1.1.2.2.2 bouyer
632 1.1.1.2.2.2 bouyer /*******************************************************************************
633 1.1.1.2.2.2 bouyer *
634 1.1.1.2.2.2 bouyer * FUNCTION: AcpiPsLinkModuleCode
635 1.1.1.2.2.2 bouyer *
636 1.1.1.2.2.2 bouyer * PARAMETERS: ParentOp - Parent parser op
637 1.1.1.2.2.2 bouyer * AmlStart - Pointer to the AML
638 1.1.1.2.2.2 bouyer * AmlLength - Length of executable AML
639 1.1.1.2.2.2 bouyer * OwnerId - OwnerId of module level code
640 1.1.1.2.2.2 bouyer *
641 1.1.1.2.2.2 bouyer * RETURN: None.
642 1.1.1.2.2.2 bouyer *
643 1.1.1.2.2.2 bouyer * DESCRIPTION: Wrap the module-level code with a method object and link the
644 1.1.1.2.2.2 bouyer * object to the global list. Note, the mutex field of the method
645 1.1.1.2.2.2 bouyer * object is used to link multiple module-level code objects.
646 1.1.1.2.2.2 bouyer *
647 1.1.1.2.2.2 bouyer ******************************************************************************/
648 1.1.1.2.2.2 bouyer
649 1.1.1.2.2.2 bouyer static void
650 1.1.1.2.2.2 bouyer AcpiPsLinkModuleCode (
651 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *ParentOp,
652 1.1.1.2.2.2 bouyer UINT8 *AmlStart,
653 1.1.1.2.2.2 bouyer UINT32 AmlLength,
654 1.1.1.2.2.2 bouyer ACPI_OWNER_ID OwnerId)
655 1.1.1.2.2.2 bouyer {
656 1.1.1.2.2.2 bouyer ACPI_OPERAND_OBJECT *Prev;
657 1.1.1.2.2.2 bouyer ACPI_OPERAND_OBJECT *Next;
658 1.1.1.2.2.2 bouyer ACPI_OPERAND_OBJECT *MethodObj;
659 1.1.1.2.2.2 bouyer ACPI_NAMESPACE_NODE *ParentNode;
660 1.1.1.2.2.2 bouyer
661 1.1.1.2.2.2 bouyer
662 1.1.1.2.2.2 bouyer /* Get the tail of the list */
663 1.1.1.2.2.2 bouyer
664 1.1.1.2.2.2 bouyer Prev = Next = AcpiGbl_ModuleCodeList;
665 1.1.1.2.2.2 bouyer while (Next)
666 1.1.1.2.2.2 bouyer {
667 1.1.1.2.2.2 bouyer Prev = Next;
668 1.1.1.2.2.2 bouyer Next = Next->Method.Mutex;
669 1.1.1.2.2.2 bouyer }
670 1.1.1.2.2.2 bouyer
671 1.1.1.2.2.2 bouyer /*
672 1.1.1.2.2.2 bouyer * Insert the module level code into the list. Merge it if it is
673 1.1.1.2.2.2 bouyer * adjacent to the previous element.
674 1.1.1.2.2.2 bouyer */
675 1.1.1.2.2.2 bouyer if (!Prev ||
676 1.1.1.2.2.2 bouyer ((Prev->Method.AmlStart + Prev->Method.AmlLength) != AmlStart))
677 1.1.1.2.2.2 bouyer {
678 1.1.1.2.2.2 bouyer /* Create, initialize, and link a new temporary method object */
679 1.1.1.2.2.2 bouyer
680 1.1.1.2.2.2 bouyer MethodObj = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);
681 1.1.1.2.2.2 bouyer if (!MethodObj)
682 1.1.1.2.2.2 bouyer {
683 1.1.1.2.2.2 bouyer return;
684 1.1.1.2.2.2 bouyer }
685 1.1.1.2.2.2 bouyer
686 1.1.1.2.2.2 bouyer if (ParentOp->Common.Node)
687 1.1.1.2.2.2 bouyer {
688 1.1.1.2.2.2 bouyer ParentNode = ParentOp->Common.Node;
689 1.1.1.2.2.2 bouyer }
690 1.1.1.2.2.2 bouyer else
691 1.1.1.2.2.2 bouyer {
692 1.1.1.2.2.2 bouyer ParentNode = AcpiGbl_RootNode;
693 1.1.1.2.2.2 bouyer }
694 1.1.1.2.2.2 bouyer
695 1.1.1.2.2.2 bouyer MethodObj->Method.AmlStart = AmlStart;
696 1.1.1.2.2.2 bouyer MethodObj->Method.AmlLength = AmlLength;
697 1.1.1.2.2.2 bouyer MethodObj->Method.OwnerId = OwnerId;
698 1.1.1.2.2.2 bouyer MethodObj->Method.InfoFlags |= ACPI_METHOD_MODULE_LEVEL;
699 1.1.1.2.2.2 bouyer
700 1.1.1.2.2.2 bouyer /*
701 1.1.1.2.2.2 bouyer * Save the parent node in NextObject. This is cheating, but we
702 1.1.1.2.2.2 bouyer * don't want to expand the method object.
703 1.1.1.2.2.2 bouyer */
704 1.1.1.2.2.2 bouyer MethodObj->Method.NextObject =
705 1.1.1.2.2.2 bouyer ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, ParentNode);
706 1.1.1.2.2.2 bouyer
707 1.1.1.2.2.2 bouyer if (!Prev)
708 1.1.1.2.2.2 bouyer {
709 1.1.1.2.2.2 bouyer AcpiGbl_ModuleCodeList = MethodObj;
710 1.1.1.2.2.2 bouyer }
711 1.1.1.2.2.2 bouyer else
712 1.1.1.2.2.2 bouyer {
713 1.1.1.2.2.2 bouyer Prev->Method.Mutex = MethodObj;
714 1.1.1.2.2.2 bouyer }
715 1.1.1.2.2.2 bouyer }
716 1.1.1.2.2.2 bouyer else
717 1.1.1.2.2.2 bouyer {
718 1.1.1.2.2.2 bouyer Prev->Method.AmlLength += AmlLength;
719 1.1.1.2.2.2 bouyer }
720 1.1.1.2.2.2 bouyer }
721 1.1.1.2.2.2 bouyer
722 1.1.1.2.2.2 bouyer
723 1.1.1.2.2.2 bouyer /*******************************************************************************
724 1.1.1.2.2.2 bouyer *
725 1.1.1.2.2.2 bouyer * FUNCTION: AcpiPsCompleteOp
726 1.1.1.2.2.2 bouyer *
727 1.1.1.2.2.2 bouyer * PARAMETERS: WalkState - Current state
728 1.1.1.2.2.2 bouyer * Op - Returned Op
729 1.1.1.2.2.2 bouyer * Status - Parse status before complete Op
730 1.1.1.2.2.2 bouyer *
731 1.1.1.2.2.2 bouyer * RETURN: Status
732 1.1.1.2.2.2 bouyer *
733 1.1.1.2.2.2 bouyer * DESCRIPTION: Complete Op
734 1.1.1.2.2.2 bouyer *
735 1.1.1.2.2.2 bouyer ******************************************************************************/
736 1.1.1.2.2.2 bouyer
737 1.1.1.2.2.2 bouyer static ACPI_STATUS
738 1.1.1.2.2.2 bouyer AcpiPsCompleteOp (
739 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState,
740 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT **Op,
741 1.1.1.2.2.2 bouyer ACPI_STATUS Status)
742 1.1.1.2.2.2 bouyer {
743 1.1.1.2.2.2 bouyer ACPI_STATUS Status2;
744 1.1.1.2.2.2 bouyer
745 1.1.1.2.2.2 bouyer
746 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE_PTR (PsCompleteOp, WalkState);
747 1.1.1.2.2.2 bouyer
748 1.1.1.2.2.2 bouyer
749 1.1.1.2.2.2 bouyer /*
750 1.1.1.2.2.2 bouyer * Finished one argument of the containing scope
751 1.1.1.2.2.2 bouyer */
752 1.1.1.2.2.2 bouyer WalkState->ParserState.Scope->ParseScope.ArgCount--;
753 1.1.1.2.2.2 bouyer
754 1.1.1.2.2.2 bouyer /* Close this Op (will result in parse subtree deletion) */
755 1.1.1.2.2.2 bouyer
756 1.1.1.2.2.2 bouyer Status2 = AcpiPsCompleteThisOp (WalkState, *Op);
757 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status2))
758 1.1.1.2.2.2 bouyer {
759 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status2);
760 1.1.1.2.2.2 bouyer }
761 1.1.1.2.2.2 bouyer
762 1.1.1.2.2.2 bouyer *Op = NULL;
763 1.1.1.2.2.2 bouyer
764 1.1.1.2.2.2 bouyer switch (Status)
765 1.1.1.2.2.2 bouyer {
766 1.1.1.2.2.2 bouyer case AE_OK:
767 1.1.1.2.2.2 bouyer break;
768 1.1.1.2.2.2 bouyer
769 1.1.1.2.2.2 bouyer
770 1.1.1.2.2.2 bouyer case AE_CTRL_TRANSFER:
771 1.1.1.2.2.2 bouyer
772 1.1.1.2.2.2 bouyer /* We are about to transfer to a called method */
773 1.1.1.2.2.2 bouyer
774 1.1.1.2.2.2 bouyer WalkState->PrevOp = NULL;
775 1.1.1.2.2.2 bouyer WalkState->PrevArgTypes = WalkState->ArgTypes;
776 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
777 1.1.1.2.2.2 bouyer
778 1.1.1.2.2.2 bouyer
779 1.1.1.2.2.2 bouyer case AE_CTRL_END:
780 1.1.1.2.2.2 bouyer
781 1.1.1.2.2.2 bouyer AcpiPsPopScope (&(WalkState->ParserState), Op,
782 1.1.1.2.2.2 bouyer &WalkState->ArgTypes, &WalkState->ArgCount);
783 1.1.1.2.2.2 bouyer
784 1.1.1.2.2.2 bouyer if (*Op)
785 1.1.1.2.2.2 bouyer {
786 1.1.1.2.2.2 bouyer WalkState->Op = *Op;
787 1.1.1.2.2.2 bouyer WalkState->OpInfo = AcpiPsGetOpcodeInfo ((*Op)->Common.AmlOpcode);
788 1.1.1.2.2.2 bouyer WalkState->Opcode = (*Op)->Common.AmlOpcode;
789 1.1.1.2.2.2 bouyer
790 1.1.1.2.2.2 bouyer Status = WalkState->AscendingCallback (WalkState);
791 1.1.1.2.2.2 bouyer Status = AcpiPsNextParseState (WalkState, *Op, Status);
792 1.1.1.2.2.2 bouyer
793 1.1.1.2.2.2 bouyer Status2 = AcpiPsCompleteThisOp (WalkState, *Op);
794 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status2))
795 1.1.1.2.2.2 bouyer {
796 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status2);
797 1.1.1.2.2.2 bouyer }
798 1.1.1.2.2.2 bouyer }
799 1.1.1.2.2.2 bouyer
800 1.1.1.2.2.2 bouyer Status = AE_OK;
801 1.1.1.2.2.2 bouyer break;
802 1.1.1.2.2.2 bouyer
803 1.1.1.2.2.2 bouyer
804 1.1.1.2.2.2 bouyer case AE_CTRL_BREAK:
805 1.1.1.2.2.2 bouyer case AE_CTRL_CONTINUE:
806 1.1.1.2.2.2 bouyer
807 1.1.1.2.2.2 bouyer /* Pop off scopes until we find the While */
808 1.1.1.2.2.2 bouyer
809 1.1.1.2.2.2 bouyer while (!(*Op) || ((*Op)->Common.AmlOpcode != AML_WHILE_OP))
810 1.1.1.2.2.2 bouyer {
811 1.1.1.2.2.2 bouyer AcpiPsPopScope (&(WalkState->ParserState), Op,
812 1.1.1.2.2.2 bouyer &WalkState->ArgTypes, &WalkState->ArgCount);
813 1.1.1.2.2.2 bouyer }
814 1.1.1.2.2.2 bouyer
815 1.1.1.2.2.2 bouyer /* Close this iteration of the While loop */
816 1.1.1.2.2.2 bouyer
817 1.1.1.2.2.2 bouyer WalkState->Op = *Op;
818 1.1.1.2.2.2 bouyer WalkState->OpInfo = AcpiPsGetOpcodeInfo ((*Op)->Common.AmlOpcode);
819 1.1.1.2.2.2 bouyer WalkState->Opcode = (*Op)->Common.AmlOpcode;
820 1.1.1.2.2.2 bouyer
821 1.1.1.2.2.2 bouyer Status = WalkState->AscendingCallback (WalkState);
822 1.1.1.2.2.2 bouyer Status = AcpiPsNextParseState (WalkState, *Op, Status);
823 1.1.1.2.2.2 bouyer
824 1.1.1.2.2.2 bouyer Status2 = AcpiPsCompleteThisOp (WalkState, *Op);
825 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status2))
826 1.1.1.2.2.2 bouyer {
827 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status2);
828 1.1.1.2.2.2 bouyer }
829 1.1.1.2.2.2 bouyer
830 1.1.1.2.2.2 bouyer Status = AE_OK;
831 1.1.1.2.2.2 bouyer break;
832 1.1.1.2.2.2 bouyer
833 1.1.1.2.2.2 bouyer
834 1.1.1.2.2.2 bouyer case AE_CTRL_TERMINATE:
835 1.1.1.2.2.2 bouyer
836 1.1.1.2.2.2 bouyer /* Clean up */
837 1.1.1.2.2.2 bouyer do
838 1.1.1.2.2.2 bouyer {
839 1.1.1.2.2.2 bouyer if (*Op)
840 1.1.1.2.2.2 bouyer {
841 1.1.1.2.2.2 bouyer Status2 = AcpiPsCompleteThisOp (WalkState, *Op);
842 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status2))
843 1.1.1.2.2.2 bouyer {
844 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status2);
845 1.1.1.2.2.2 bouyer }
846 1.1.1.2.2.2 bouyer
847 1.1.1.2.2.2 bouyer AcpiUtDeleteGenericState (
848 1.1.1.2.2.2 bouyer AcpiUtPopGenericState (&WalkState->ControlState));
849 1.1.1.2.2.2 bouyer }
850 1.1.1.2.2.2 bouyer
851 1.1.1.2.2.2 bouyer AcpiPsPopScope (&(WalkState->ParserState), Op,
852 1.1.1.2.2.2 bouyer &WalkState->ArgTypes, &WalkState->ArgCount);
853 1.1.1.2.2.2 bouyer
854 1.1.1.2.2.2 bouyer } while (*Op);
855 1.1.1.2.2.2 bouyer
856 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_OK);
857 1.1.1.2.2.2 bouyer
858 1.1.1.2.2.2 bouyer
859 1.1.1.2.2.2 bouyer default: /* All other non-AE_OK status */
860 1.1.1.2.2.2 bouyer
861 1.1.1.2.2.2 bouyer do
862 1.1.1.2.2.2 bouyer {
863 1.1.1.2.2.2 bouyer if (*Op)
864 1.1.1.2.2.2 bouyer {
865 1.1.1.2.2.2 bouyer Status2 = AcpiPsCompleteThisOp (WalkState, *Op);
866 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status2))
867 1.1.1.2.2.2 bouyer {
868 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status2);
869 1.1.1.2.2.2 bouyer }
870 1.1.1.2.2.2 bouyer }
871 1.1.1.2.2.2 bouyer
872 1.1.1.2.2.2 bouyer AcpiPsPopScope (&(WalkState->ParserState), Op,
873 1.1.1.2.2.2 bouyer &WalkState->ArgTypes, &WalkState->ArgCount);
874 1.1.1.2.2.2 bouyer
875 1.1.1.2.2.2 bouyer } while (*Op);
876 1.1.1.2.2.2 bouyer
877 1.1.1.2.2.2 bouyer
878 1.1.1.2.2.2 bouyer #if 0
879 1.1.1.2.2.2 bouyer /*
880 1.1.1.2.2.2 bouyer * TBD: Cleanup parse ops on error
881 1.1.1.2.2.2 bouyer */
882 1.1.1.2.2.2 bouyer if (*Op == NULL)
883 1.1.1.2.2.2 bouyer {
884 1.1.1.2.2.2 bouyer AcpiPsPopScope (ParserState, Op,
885 1.1.1.2.2.2 bouyer &WalkState->ArgTypes, &WalkState->ArgCount);
886 1.1.1.2.2.2 bouyer }
887 1.1.1.2.2.2 bouyer #endif
888 1.1.1.2.2.2 bouyer WalkState->PrevOp = NULL;
889 1.1.1.2.2.2 bouyer WalkState->PrevArgTypes = WalkState->ArgTypes;
890 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
891 1.1.1.2.2.2 bouyer }
892 1.1.1.2.2.2 bouyer
893 1.1.1.2.2.2 bouyer /* This scope complete? */
894 1.1.1.2.2.2 bouyer
895 1.1.1.2.2.2 bouyer if (AcpiPsHasCompletedScope (&(WalkState->ParserState)))
896 1.1.1.2.2.2 bouyer {
897 1.1.1.2.2.2 bouyer AcpiPsPopScope (&(WalkState->ParserState), Op,
898 1.1.1.2.2.2 bouyer &WalkState->ArgTypes, &WalkState->ArgCount);
899 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Popped scope, Op=%p\n", *Op));
900 1.1.1.2.2.2 bouyer }
901 1.1.1.2.2.2 bouyer else
902 1.1.1.2.2.2 bouyer {
903 1.1.1.2.2.2 bouyer *Op = NULL;
904 1.1.1.2.2.2 bouyer }
905 1.1.1.2.2.2 bouyer
906 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_OK);
907 1.1.1.2.2.2 bouyer }
908 1.1.1.2.2.2 bouyer
909 1.1.1.2.2.2 bouyer
910 1.1.1.2.2.2 bouyer /*******************************************************************************
911 1.1.1.2.2.2 bouyer *
912 1.1.1.2.2.2 bouyer * FUNCTION: AcpiPsCompleteFinalOp
913 1.1.1.2.2.2 bouyer *
914 1.1.1.2.2.2 bouyer * PARAMETERS: WalkState - Current state
915 1.1.1.2.2.2 bouyer * Op - Current Op
916 1.1.1.2.2.2 bouyer * Status - Current parse status before complete last
917 1.1.1.2.2.2 bouyer * Op
918 1.1.1.2.2.2 bouyer *
919 1.1.1.2.2.2 bouyer * RETURN: Status
920 1.1.1.2.2.2 bouyer *
921 1.1.1.2.2.2 bouyer * DESCRIPTION: Complete last Op.
922 1.1.1.2.2.2 bouyer *
923 1.1.1.2.2.2 bouyer ******************************************************************************/
924 1.1.1.2.2.2 bouyer
925 1.1.1.2.2.2 bouyer static ACPI_STATUS
926 1.1.1.2.2.2 bouyer AcpiPsCompleteFinalOp (
927 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState,
928 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *Op,
929 1.1.1.2.2.2 bouyer ACPI_STATUS Status)
930 1.1.1.2.2.2 bouyer {
931 1.1.1.2.2.2 bouyer ACPI_STATUS Status2;
932 1.1.1.2.2.2 bouyer
933 1.1.1.2.2.2 bouyer
934 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE_PTR (PsCompleteFinalOp, WalkState);
935 1.1.1.2.2.2 bouyer
936 1.1.1.2.2.2 bouyer
937 1.1.1.2.2.2 bouyer /*
938 1.1.1.2.2.2 bouyer * Complete the last Op (if not completed), and clear the scope stack.
939 1.1.1.2.2.2 bouyer * It is easily possible to end an AML "package" with an unbounded number
940 1.1.1.2.2.2 bouyer * of open scopes (such as when several ASL blocks are closed with
941 1.1.1.2.2.2 bouyer * sequential closing braces). We want to terminate each one cleanly.
942 1.1.1.2.2.2 bouyer */
943 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "AML package complete at Op %p\n", Op));
944 1.1.1.2.2.2 bouyer do
945 1.1.1.2.2.2 bouyer {
946 1.1.1.2.2.2 bouyer if (Op)
947 1.1.1.2.2.2 bouyer {
948 1.1.1.2.2.2 bouyer if (WalkState->AscendingCallback != NULL)
949 1.1.1.2.2.2 bouyer {
950 1.1.1.2.2.2 bouyer WalkState->Op = Op;
951 1.1.1.2.2.2 bouyer WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
952 1.1.1.2.2.2 bouyer WalkState->Opcode = Op->Common.AmlOpcode;
953 1.1.1.2.2.2 bouyer
954 1.1.1.2.2.2 bouyer Status = WalkState->AscendingCallback (WalkState);
955 1.1.1.2.2.2 bouyer Status = AcpiPsNextParseState (WalkState, Op, Status);
956 1.1.1.2.2.2 bouyer if (Status == AE_CTRL_PENDING)
957 1.1.1.2.2.2 bouyer {
958 1.1.1.2.2.2 bouyer Status = AcpiPsCompleteOp (WalkState, &Op, AE_OK);
959 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
960 1.1.1.2.2.2 bouyer {
961 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
962 1.1.1.2.2.2 bouyer }
963 1.1.1.2.2.2 bouyer }
964 1.1.1.2.2.2 bouyer
965 1.1.1.2.2.2 bouyer if (Status == AE_CTRL_TERMINATE)
966 1.1.1.2.2.2 bouyer {
967 1.1.1.2.2.2 bouyer Status = AE_OK;
968 1.1.1.2.2.2 bouyer
969 1.1.1.2.2.2 bouyer /* Clean up */
970 1.1.1.2.2.2 bouyer do
971 1.1.1.2.2.2 bouyer {
972 1.1.1.2.2.2 bouyer if (Op)
973 1.1.1.2.2.2 bouyer {
974 1.1.1.2.2.2 bouyer Status2 = AcpiPsCompleteThisOp (WalkState, Op);
975 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status2))
976 1.1.1.2.2.2 bouyer {
977 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status2);
978 1.1.1.2.2.2 bouyer }
979 1.1.1.2.2.2 bouyer }
980 1.1.1.2.2.2 bouyer
981 1.1.1.2.2.2 bouyer AcpiPsPopScope (&(WalkState->ParserState), &Op,
982 1.1.1.2.2.2 bouyer &WalkState->ArgTypes, &WalkState->ArgCount);
983 1.1.1.2.2.2 bouyer
984 1.1.1.2.2.2 bouyer } while (Op);
985 1.1.1.2.2.2 bouyer
986 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
987 1.1.1.2.2.2 bouyer }
988 1.1.1.2.2.2 bouyer
989 1.1.1.2.2.2 bouyer else if (ACPI_FAILURE (Status))
990 1.1.1.2.2.2 bouyer {
991 1.1.1.2.2.2 bouyer /* First error is most important */
992 1.1.1.2.2.2 bouyer
993 1.1.1.2.2.2 bouyer (void) AcpiPsCompleteThisOp (WalkState, Op);
994 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
995 1.1.1.2.2.2 bouyer }
996 1.1.1.2.2.2 bouyer }
997 1.1.1.2.2.2 bouyer
998 1.1.1.2.2.2 bouyer Status2 = AcpiPsCompleteThisOp (WalkState, Op);
999 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status2))
1000 1.1.1.2.2.2 bouyer {
1001 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status2);
1002 1.1.1.2.2.2 bouyer }
1003 1.1.1.2.2.2 bouyer }
1004 1.1.1.2.2.2 bouyer
1005 1.1.1.2.2.2 bouyer AcpiPsPopScope (&(WalkState->ParserState), &Op, &WalkState->ArgTypes,
1006 1.1.1.2.2.2 bouyer &WalkState->ArgCount);
1007 1.1.1.2.2.2 bouyer
1008 1.1.1.2.2.2 bouyer } while (Op);
1009 1.1.1.2.2.2 bouyer
1010 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
1011 1.1.1.2.2.2 bouyer }
1012 1.1.1.2.2.2 bouyer
1013 1.1.1.2.2.2 bouyer
1014 1.1.1.2.2.2 bouyer /*******************************************************************************
1015 1.1.1.2.2.2 bouyer *
1016 1.1.1.2.2.2 bouyer * FUNCTION: AcpiPsParseLoop
1017 1.1.1.2.2.2 bouyer *
1018 1.1.1.2.2.2 bouyer * PARAMETERS: WalkState - Current state
1019 1.1.1.2.2.2 bouyer *
1020 1.1.1.2.2.2 bouyer * RETURN: Status
1021 1.1.1.2.2.2 bouyer *
1022 1.1.1.2.2.2 bouyer * DESCRIPTION: Parse AML (pointed to by the current parser state) and return
1023 1.1.1.2.2.2 bouyer * a tree of ops.
1024 1.1.1.2.2.2 bouyer *
1025 1.1.1.2.2.2 bouyer ******************************************************************************/
1026 1.1.1.2.2.2 bouyer
1027 1.1.1.2.2.2 bouyer ACPI_STATUS
1028 1.1.1.2.2.2 bouyer AcpiPsParseLoop (
1029 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState)
1030 1.1.1.2.2.2 bouyer {
1031 1.1.1.2.2.2 bouyer ACPI_STATUS Status = AE_OK;
1032 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *Op = NULL; /* current op */
1033 1.1.1.2.2.2 bouyer ACPI_PARSE_STATE *ParserState;
1034 1.1.1.2.2.2 bouyer UINT8 *AmlOpStart = NULL;
1035 1.1.1.2.2.2 bouyer
1036 1.1.1.2.2.2 bouyer
1037 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE_PTR (PsParseLoop, WalkState);
1038 1.1.1.2.2.2 bouyer
1039 1.1.1.2.2.2 bouyer
1040 1.1.1.2.2.2 bouyer if (WalkState->DescendingCallback == NULL)
1041 1.1.1.2.2.2 bouyer {
1042 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_BAD_PARAMETER);
1043 1.1.1.2.2.2 bouyer }
1044 1.1.1.2.2.2 bouyer
1045 1.1.1.2.2.2 bouyer ParserState = &WalkState->ParserState;
1046 1.1.1.2.2.2 bouyer WalkState->ArgTypes = 0;
1047 1.1.1.2.2.2 bouyer
1048 1.1.1.2.2.2 bouyer #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
1049 1.1.1.2.2.2 bouyer
1050 1.1.1.2.2.2 bouyer if (WalkState->WalkType & ACPI_WALK_METHOD_RESTART)
1051 1.1.1.2.2.2 bouyer {
1052 1.1.1.2.2.2 bouyer /* We are restarting a preempted control method */
1053 1.1.1.2.2.2 bouyer
1054 1.1.1.2.2.2 bouyer if (AcpiPsHasCompletedScope (ParserState))
1055 1.1.1.2.2.2 bouyer {
1056 1.1.1.2.2.2 bouyer /*
1057 1.1.1.2.2.2 bouyer * We must check if a predicate to an IF or WHILE statement
1058 1.1.1.2.2.2 bouyer * was just completed
1059 1.1.1.2.2.2 bouyer */
1060 1.1.1.2.2.2 bouyer if ((ParserState->Scope->ParseScope.Op) &&
1061 1.1.1.2.2.2 bouyer ((ParserState->Scope->ParseScope.Op->Common.AmlOpcode == AML_IF_OP) ||
1062 1.1.1.2.2.2 bouyer (ParserState->Scope->ParseScope.Op->Common.AmlOpcode == AML_WHILE_OP)) &&
1063 1.1.1.2.2.2 bouyer (WalkState->ControlState) &&
1064 1.1.1.2.2.2 bouyer (WalkState->ControlState->Common.State ==
1065 1.1.1.2.2.2 bouyer ACPI_CONTROL_PREDICATE_EXECUTING))
1066 1.1.1.2.2.2 bouyer {
1067 1.1.1.2.2.2 bouyer /*
1068 1.1.1.2.2.2 bouyer * A predicate was just completed, get the value of the
1069 1.1.1.2.2.2 bouyer * predicate and branch based on that value
1070 1.1.1.2.2.2 bouyer */
1071 1.1.1.2.2.2 bouyer WalkState->Op = NULL;
1072 1.1.1.2.2.2 bouyer Status = AcpiDsGetPredicateValue (WalkState, ACPI_TO_POINTER (TRUE));
1073 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status) &&
1074 1.1.1.2.2.2 bouyer ((Status & AE_CODE_MASK) != AE_CODE_CONTROL))
1075 1.1.1.2.2.2 bouyer {
1076 1.1.1.2.2.2 bouyer if (Status == AE_AML_NO_RETURN_VALUE)
1077 1.1.1.2.2.2 bouyer {
1078 1.1.1.2.2.2 bouyer ACPI_EXCEPTION ((AE_INFO, Status,
1079 1.1.1.2.2.2 bouyer "Invoked method did not return a value"));
1080 1.1.1.2.2.2 bouyer }
1081 1.1.1.2.2.2 bouyer
1082 1.1.1.2.2.2 bouyer ACPI_EXCEPTION ((AE_INFO, Status, "GetPredicate Failed"));
1083 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
1084 1.1.1.2.2.2 bouyer }
1085 1.1.1.2.2.2 bouyer
1086 1.1.1.2.2.2 bouyer Status = AcpiPsNextParseState (WalkState, Op, Status);
1087 1.1.1.2.2.2 bouyer }
1088 1.1.1.2.2.2 bouyer
1089 1.1.1.2.2.2 bouyer AcpiPsPopScope (ParserState, &Op,
1090 1.1.1.2.2.2 bouyer &WalkState->ArgTypes, &WalkState->ArgCount);
1091 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Popped scope, Op=%p\n", Op));
1092 1.1.1.2.2.2 bouyer }
1093 1.1.1.2.2.2 bouyer else if (WalkState->PrevOp)
1094 1.1.1.2.2.2 bouyer {
1095 1.1.1.2.2.2 bouyer /* We were in the middle of an op */
1096 1.1.1.2.2.2 bouyer
1097 1.1.1.2.2.2 bouyer Op = WalkState->PrevOp;
1098 1.1.1.2.2.2 bouyer WalkState->ArgTypes = WalkState->PrevArgTypes;
1099 1.1.1.2.2.2 bouyer }
1100 1.1.1.2.2.2 bouyer }
1101 1.1.1.2.2.2 bouyer #endif
1102 1.1.1.2.2.2 bouyer
1103 1.1.1.2.2.2 bouyer /* Iterative parsing loop, while there is more AML to process: */
1104 1.1.1.2.2.2 bouyer
1105 1.1.1.2.2.2 bouyer while ((ParserState->Aml < ParserState->AmlEnd) || (Op))
1106 1.1.1.2.2.2 bouyer {
1107 1.1.1.2.2.2 bouyer AmlOpStart = ParserState->Aml;
1108 1.1.1.2.2.2 bouyer if (!Op)
1109 1.1.1.2.2.2 bouyer {
1110 1.1.1.2.2.2 bouyer Status = AcpiPsCreateOp (WalkState, AmlOpStart, &Op);
1111 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
1112 1.1.1.2.2.2 bouyer {
1113 1.1.1.2.2.2 bouyer if (Status == AE_CTRL_PARSE_CONTINUE)
1114 1.1.1.2.2.2 bouyer {
1115 1.1.1.2.2.2 bouyer continue;
1116 1.1.1.2.2.2 bouyer }
1117 1.1.1.2.2.2 bouyer
1118 1.1.1.2.2.2 bouyer if (Status == AE_CTRL_PARSE_PENDING)
1119 1.1.1.2.2.2 bouyer {
1120 1.1.1.2.2.2 bouyer Status = AE_OK;
1121 1.1.1.2.2.2 bouyer }
1122 1.1.1.2.2.2 bouyer
1123 1.1.1.2.2.2 bouyer Status = AcpiPsCompleteOp (WalkState, &Op, Status);
1124 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
1125 1.1.1.2.2.2 bouyer {
1126 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
1127 1.1.1.2.2.2 bouyer }
1128 1.1.1.2.2.2 bouyer
1129 1.1.1.2.2.2 bouyer continue;
1130 1.1.1.2.2.2 bouyer }
1131 1.1.1.2.2.2 bouyer
1132 1.1.1.2.2.2 bouyer Op->Common.AmlOffset = WalkState->AmlOffset;
1133 1.1.1.2.2.2 bouyer
1134 1.1.1.2.2.2 bouyer if (WalkState->OpInfo)
1135 1.1.1.2.2.2 bouyer {
1136 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
1137 1.1.1.2.2.2 bouyer "Opcode %4.4X [%s] Op %p Aml %p AmlOffset %5.5X\n",
1138 1.1.1.2.2.2 bouyer (UINT32) Op->Common.AmlOpcode, WalkState->OpInfo->Name,
1139 1.1.1.2.2.2 bouyer Op, ParserState->Aml, Op->Common.AmlOffset));
1140 1.1.1.2.2.2 bouyer }
1141 1.1.1.2.2.2 bouyer }
1142 1.1.1.2.2.2 bouyer
1143 1.1.1.2.2.2 bouyer
1144 1.1.1.2.2.2 bouyer /*
1145 1.1.1.2.2.2 bouyer * Start ArgCount at zero because we don't know if there are
1146 1.1.1.2.2.2 bouyer * any args yet
1147 1.1.1.2.2.2 bouyer */
1148 1.1.1.2.2.2 bouyer WalkState->ArgCount = 0;
1149 1.1.1.2.2.2 bouyer
1150 1.1.1.2.2.2 bouyer /* Are there any arguments that must be processed? */
1151 1.1.1.2.2.2 bouyer
1152 1.1.1.2.2.2 bouyer if (WalkState->ArgTypes)
1153 1.1.1.2.2.2 bouyer {
1154 1.1.1.2.2.2 bouyer /* Get arguments */
1155 1.1.1.2.2.2 bouyer
1156 1.1.1.2.2.2 bouyer Status = AcpiPsGetArguments (WalkState, AmlOpStart, Op);
1157 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
1158 1.1.1.2.2.2 bouyer {
1159 1.1.1.2.2.2 bouyer Status = AcpiPsCompleteOp (WalkState, &Op, Status);
1160 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
1161 1.1.1.2.2.2 bouyer {
1162 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
1163 1.1.1.2.2.2 bouyer }
1164 1.1.1.2.2.2 bouyer
1165 1.1.1.2.2.2 bouyer continue;
1166 1.1.1.2.2.2 bouyer }
1167 1.1.1.2.2.2 bouyer }
1168 1.1.1.2.2.2 bouyer
1169 1.1.1.2.2.2 bouyer /* Check for arguments that need to be processed */
1170 1.1.1.2.2.2 bouyer
1171 1.1.1.2.2.2 bouyer if (WalkState->ArgCount)
1172 1.1.1.2.2.2 bouyer {
1173 1.1.1.2.2.2 bouyer /*
1174 1.1.1.2.2.2 bouyer * There are arguments (complex ones), push Op and
1175 1.1.1.2.2.2 bouyer * prepare for argument
1176 1.1.1.2.2.2 bouyer */
1177 1.1.1.2.2.2 bouyer Status = AcpiPsPushScope (ParserState, Op,
1178 1.1.1.2.2.2 bouyer WalkState->ArgTypes, WalkState->ArgCount);
1179 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
1180 1.1.1.2.2.2 bouyer {
1181 1.1.1.2.2.2 bouyer Status = AcpiPsCompleteOp (WalkState, &Op, Status);
1182 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
1183 1.1.1.2.2.2 bouyer {
1184 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
1185 1.1.1.2.2.2 bouyer }
1186 1.1.1.2.2.2 bouyer
1187 1.1.1.2.2.2 bouyer continue;
1188 1.1.1.2.2.2 bouyer }
1189 1.1.1.2.2.2 bouyer
1190 1.1.1.2.2.2 bouyer Op = NULL;
1191 1.1.1.2.2.2 bouyer continue;
1192 1.1.1.2.2.2 bouyer }
1193 1.1.1.2.2.2 bouyer
1194 1.1.1.2.2.2 bouyer /*
1195 1.1.1.2.2.2 bouyer * All arguments have been processed -- Op is complete,
1196 1.1.1.2.2.2 bouyer * prepare for next
1197 1.1.1.2.2.2 bouyer */
1198 1.1.1.2.2.2 bouyer WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
1199 1.1.1.2.2.2 bouyer if (WalkState->OpInfo->Flags & AML_NAMED)
1200 1.1.1.2.2.2 bouyer {
1201 1.1.1.2.2.2 bouyer if (AcpiGbl_Depth)
1202 1.1.1.2.2.2 bouyer {
1203 1.1.1.2.2.2 bouyer AcpiGbl_Depth--;
1204 1.1.1.2.2.2 bouyer }
1205 1.1.1.2.2.2 bouyer
1206 1.1.1.2.2.2 bouyer if (Op->Common.AmlOpcode == AML_REGION_OP ||
1207 1.1.1.2.2.2 bouyer Op->Common.AmlOpcode == AML_DATA_REGION_OP)
1208 1.1.1.2.2.2 bouyer {
1209 1.1.1.2.2.2 bouyer /*
1210 1.1.1.2.2.2 bouyer * Skip parsing of control method or opregion body,
1211 1.1.1.2.2.2 bouyer * because we don't have enough info in the first pass
1212 1.1.1.2.2.2 bouyer * to parse them correctly.
1213 1.1.1.2.2.2 bouyer *
1214 1.1.1.2.2.2 bouyer * Completed parsing an OpRegion declaration, we now
1215 1.1.1.2.2.2 bouyer * know the length.
1216 1.1.1.2.2.2 bouyer */
1217 1.1.1.2.2.2 bouyer Op->Named.Length = (UINT32) (ParserState->Aml - Op->Named.Data);
1218 1.1.1.2.2.2 bouyer }
1219 1.1.1.2.2.2 bouyer }
1220 1.1.1.2.2.2 bouyer
1221 1.1.1.2.2.2 bouyer if (WalkState->OpInfo->Flags & AML_CREATE)
1222 1.1.1.2.2.2 bouyer {
1223 1.1.1.2.2.2 bouyer /*
1224 1.1.1.2.2.2 bouyer * Backup to beginning of CreateXXXfield declaration (1 for
1225 1.1.1.2.2.2 bouyer * Opcode)
1226 1.1.1.2.2.2 bouyer *
1227 1.1.1.2.2.2 bouyer * BodyLength is unknown until we parse the body
1228 1.1.1.2.2.2 bouyer */
1229 1.1.1.2.2.2 bouyer Op->Named.Length = (UINT32) (ParserState->Aml - Op->Named.Data);
1230 1.1.1.2.2.2 bouyer }
1231 1.1.1.2.2.2 bouyer
1232 1.1.1.2.2.2 bouyer if (Op->Common.AmlOpcode == AML_BANK_FIELD_OP)
1233 1.1.1.2.2.2 bouyer {
1234 1.1.1.2.2.2 bouyer /*
1235 1.1.1.2.2.2 bouyer * Backup to beginning of BankField declaration
1236 1.1.1.2.2.2 bouyer *
1237 1.1.1.2.2.2 bouyer * BodyLength is unknown until we parse the body
1238 1.1.1.2.2.2 bouyer */
1239 1.1.1.2.2.2 bouyer Op->Named.Length = (UINT32) (ParserState->Aml - Op->Named.Data);
1240 1.1.1.2.2.2 bouyer }
1241 1.1.1.2.2.2 bouyer
1242 1.1.1.2.2.2 bouyer /* This op complete, notify the dispatcher */
1243 1.1.1.2.2.2 bouyer
1244 1.1.1.2.2.2 bouyer if (WalkState->AscendingCallback != NULL)
1245 1.1.1.2.2.2 bouyer {
1246 1.1.1.2.2.2 bouyer WalkState->Op = Op;
1247 1.1.1.2.2.2 bouyer WalkState->Opcode = Op->Common.AmlOpcode;
1248 1.1.1.2.2.2 bouyer
1249 1.1.1.2.2.2 bouyer Status = WalkState->AscendingCallback (WalkState);
1250 1.1.1.2.2.2 bouyer Status = AcpiPsNextParseState (WalkState, Op, Status);
1251 1.1.1.2.2.2 bouyer if (Status == AE_CTRL_PENDING)
1252 1.1.1.2.2.2 bouyer {
1253 1.1.1.2.2.2 bouyer Status = AE_OK;
1254 1.1.1.2.2.2 bouyer }
1255 1.1.1.2.2.2 bouyer }
1256 1.1.1.2.2.2 bouyer
1257 1.1.1.2.2.2 bouyer Status = AcpiPsCompleteOp (WalkState, &Op, Status);
1258 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
1259 1.1.1.2.2.2 bouyer {
1260 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
1261 1.1.1.2.2.2 bouyer }
1262 1.1.1.2.2.2 bouyer
1263 1.1.1.2.2.2 bouyer } /* while ParserState->Aml */
1264 1.1.1.2.2.2 bouyer
1265 1.1.1.2.2.2 bouyer Status = AcpiPsCompleteFinalOp (WalkState, Op, Status);
1266 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
1267 1.1.1.2.2.2 bouyer }
1268 1.1.1.2.2.2 bouyer
1269