blob: a57f473bac83006b8cba99cbe86ac5ab390e3242 [file] [log] [blame]
Robert Moore73459f72005-06-24 00:00:00 -04001/******************************************************************************
2 *
3 * Module Name: psloop - Main AML parse loop
4 *
5 *****************************************************************************/
6
7/*
David E. Box82a80942015-02-05 15:20:45 +08008 * Copyright (C) 2000 - 2015, Intel Corp.
Robert Moore73459f72005-06-24 00:00:00 -04009 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
Robert Moore73459f72005-06-24 00:00:00 -040044/*
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +030045 * Parse the AML and build an operation tree as most interpreters, (such as
46 * Perl) do. Parsing is done by hand rather than with a YACC generated parser
47 * to tightly constrain stack and dynamic memory usage. Parsing is kept
48 * flexible and the code fairly compact by parsing based on a list of AML
49 * opcode templates in aml_op_info[].
Robert Moore73459f72005-06-24 00:00:00 -040050 */
51
52#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050053#include "accommon.h"
Lv Zhengab6c5732015-07-23 12:52:59 +080054#include "acinterp.h"
Len Browne2f7a772009-01-09 00:30:03 -050055#include "acparser.h"
56#include "acdispat.h"
57#include "amlcode.h"
Robert Moore73459f72005-06-24 00:00:00 -040058
59#define _COMPONENT ACPI_PARSER
Len Brown4be44fc2005-08-05 00:44:28 -040060ACPI_MODULE_NAME("psloop")
Robert Moore73459f72005-06-24 00:00:00 -040061
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +030062/* Local prototypes */
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +030063static acpi_status
64acpi_ps_get_arguments(struct acpi_walk_state *walk_state,
65 u8 * aml_op_start, union acpi_parse_object *op);
66
Lin Ming7f0c8262009-08-13 14:03:15 +080067static void
Lin Ming9a884ab2009-11-12 09:57:53 +080068acpi_ps_link_module_code(union acpi_parse_object *parent_op,
69 u8 *aml_start, u32 aml_length, acpi_owner_id owner_id);
Lin Ming7f0c8262009-08-13 14:03:15 +080070
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +030071/*******************************************************************************
72 *
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +030073 * FUNCTION: acpi_ps_get_arguments
74 *
75 * PARAMETERS: walk_state - Current state
76 * aml_op_start - Op start in AML
Bob Mooreba494be2012-07-12 09:40:10 +080077 * op - Current Op
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +030078 *
79 * RETURN: Status
80 *
81 * DESCRIPTION: Get arguments for passed Op.
82 *
83 ******************************************************************************/
84
85static acpi_status
86acpi_ps_get_arguments(struct acpi_walk_state *walk_state,
87 u8 * aml_op_start, union acpi_parse_object *op)
88{
89 acpi_status status = AE_OK;
90 union acpi_parse_object *arg = NULL;
Lin Ming7f0c8262009-08-13 14:03:15 +080091 const struct acpi_opcode_info *op_info;
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +030092
93 ACPI_FUNCTION_TRACE_PTR(ps_get_arguments, walk_state);
94
95 switch (op->common.aml_opcode) {
96 case AML_BYTE_OP: /* AML_BYTEDATA_ARG */
97 case AML_WORD_OP: /* AML_WORDDATA_ARG */
98 case AML_DWORD_OP: /* AML_DWORDATA_ARG */
99 case AML_QWORD_OP: /* AML_QWORDATA_ARG */
100 case AML_STRING_OP: /* AML_ASCIICHARLIST_ARG */
101
102 /* Fill in constant or string argument directly */
103
104 acpi_ps_get_next_simple_arg(&(walk_state->parser_state),
105 GET_CURRENT_ARG_TYPE(walk_state->
106 arg_types),
107 op);
108 break;
109
110 case AML_INT_NAMEPATH_OP: /* AML_NAMESTRING_ARG */
111
Bob Moore89438f92015-12-29 14:00:07 +0800112 status = acpi_ps_get_next_namepath(walk_state,
113 &(walk_state->parser_state),
114 op,
115 ACPI_POSSIBLE_METHOD_CALL);
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300116 if (ACPI_FAILURE(status)) {
117 return_ACPI_STATUS(status);
118 }
119
120 walk_state->arg_types = 0;
121 break;
122
123 default:
124 /*
125 * Op is not a constant or string, append each argument to the Op
126 */
Bob Moore1fad8732015-12-29 13:54:36 +0800127 while (GET_CURRENT_ARG_TYPE(walk_state->arg_types) &&
128 !walk_state->arg_count) {
Lv Zheng83482f72015-07-23 12:52:11 +0800129 walk_state->aml = walk_state->parser_state.aml;
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300130
131 status =
132 acpi_ps_get_next_arg(walk_state,
133 &(walk_state->parser_state),
134 GET_CURRENT_ARG_TYPE
135 (walk_state->arg_types), &arg);
136 if (ACPI_FAILURE(status)) {
137 return_ACPI_STATUS(status);
138 }
139
140 if (arg) {
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300141 acpi_ps_append_arg(op, arg);
142 }
143
144 INCREMENT_ARG_LIST(walk_state->arg_types);
145 }
146
Lin Ming7f0c8262009-08-13 14:03:15 +0800147 /*
148 * Handle executable code at "module-level". This refers to
149 * executable opcodes that appear outside of any control method.
150 */
151 if ((walk_state->pass_number <= ACPI_IMODE_LOAD_PASS2) &&
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300152 ((walk_state->parse_flags & ACPI_PARSE_DISASSEMBLE) == 0)) {
153 /*
154 * We want to skip If/Else/While constructs during Pass1 because we
155 * want to actually conditionally execute the code during Pass2.
156 *
157 * Except for disassembly, where we always want to walk the
158 * If/Else/While packages
159 */
160 switch (op->common.aml_opcode) {
161 case AML_IF_OP:
162 case AML_ELSE_OP:
163 case AML_WHILE_OP:
Lin Ming7f0c8262009-08-13 14:03:15 +0800164 /*
165 * Currently supported module-level opcodes are:
166 * IF/ELSE/WHILE. These appear to be the most common,
167 * and easiest to support since they open an AML
168 * package.
169 */
170 if (walk_state->pass_number ==
171 ACPI_IMODE_LOAD_PASS1) {
Lin Ming9a884ab2009-11-12 09:57:53 +0800172 acpi_ps_link_module_code(op->common.
173 parent,
174 aml_op_start,
175 (u32)
176 (walk_state->
Lin Ming7f0c8262009-08-13 14:03:15 +0800177 parser_state.
178 pkg_end -
Lin Ming9a884ab2009-11-12 09:57:53 +0800179 aml_op_start),
Lin Ming7f0c8262009-08-13 14:03:15 +0800180 walk_state->
181 owner_id);
182 }
183
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300184 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
185 "Pass1: Skipping an If/Else/While body\n"));
186
187 /* Skip body of if/else/while in pass 1 */
188
189 walk_state->parser_state.aml =
190 walk_state->parser_state.pkg_end;
191 walk_state->arg_count = 0;
192 break;
193
194 default:
Lin Ming7f0c8262009-08-13 14:03:15 +0800195 /*
196 * Check for an unsupported executable opcode at module
197 * level. We must be in PASS1, the parent must be a SCOPE,
198 * The opcode class must be EXECUTE, and the opcode must
199 * not be an argument to another opcode.
200 */
201 if ((walk_state->pass_number ==
202 ACPI_IMODE_LOAD_PASS1)
203 && (op->common.parent->common.aml_opcode ==
204 AML_SCOPE_OP)) {
205 op_info =
206 acpi_ps_get_opcode_info(op->common.
207 aml_opcode);
208 if ((op_info->class ==
209 AML_CLASS_EXECUTE) && (!arg)) {
210 ACPI_WARNING((AE_INFO,
Bob Moore00eb3252012-10-31 02:27:48 +0000211 "Unsupported module-level executable opcode "
212 "0x%.2X at table offset 0x%.4X",
213 op->common.
214 aml_opcode,
215 (u32)
216 (ACPI_PTR_DIFF
217 (aml_op_start,
218 walk_state->
219 parser_state.
220 aml_start) +
221 sizeof(struct
222 acpi_table_header))));
Lin Ming7f0c8262009-08-13 14:03:15 +0800223 }
224 }
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300225 break;
226 }
227 }
Lin Ming7f0c8262009-08-13 14:03:15 +0800228
229 /* Special processing for certain opcodes */
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300230
231 switch (op->common.aml_opcode) {
232 case AML_METHOD_OP:
233 /*
234 * Skip parsing of control method because we don't have enough
235 * info in the first pass to parse it correctly.
236 *
237 * Save the length and address of the body
238 */
239 op->named.data = walk_state->parser_state.aml;
240 op->named.length = (u32)
241 (walk_state->parser_state.pkg_end -
242 walk_state->parser_state.aml);
243
244 /* Skip body of method */
245
246 walk_state->parser_state.aml =
247 walk_state->parser_state.pkg_end;
248 walk_state->arg_count = 0;
249 break;
250
251 case AML_BUFFER_OP:
252 case AML_PACKAGE_OP:
253 case AML_VAR_PACKAGE_OP:
254
255 if ((op->common.parent) &&
256 (op->common.parent->common.aml_opcode ==
257 AML_NAME_OP)
258 && (walk_state->pass_number <=
259 ACPI_IMODE_LOAD_PASS2)) {
260 /*
261 * Skip parsing of Buffers and Packages because we don't have
262 * enough info in the first pass to parse them correctly.
263 */
264 op->named.data = aml_op_start;
265 op->named.length = (u32)
266 (walk_state->parser_state.pkg_end -
267 aml_op_start);
268
269 /* Skip body */
270
271 walk_state->parser_state.aml =
272 walk_state->parser_state.pkg_end;
273 walk_state->arg_count = 0;
274 }
275 break;
276
277 case AML_WHILE_OP:
278
279 if (walk_state->control_state) {
280 walk_state->control_state->control.package_end =
281 walk_state->parser_state.pkg_end;
282 }
283 break;
284
285 default:
286
287 /* No action for all other opcodes */
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000288
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300289 break;
290 }
291
292 break;
293 }
294
295 return_ACPI_STATUS(AE_OK);
296}
297
298/*******************************************************************************
299 *
Lin Ming7f0c8262009-08-13 14:03:15 +0800300 * FUNCTION: acpi_ps_link_module_code
301 *
Lin Ming9a884ab2009-11-12 09:57:53 +0800302 * PARAMETERS: parent_op - Parent parser op
303 * aml_start - Pointer to the AML
Lin Ming7f0c8262009-08-13 14:03:15 +0800304 * aml_length - Length of executable AML
305 * owner_id - owner_id of module level code
306 *
307 * RETURN: None.
308 *
309 * DESCRIPTION: Wrap the module-level code with a method object and link the
310 * object to the global list. Note, the mutex field of the method
311 * object is used to link multiple module-level code objects.
312 *
313 ******************************************************************************/
314
315static void
Lin Ming9a884ab2009-11-12 09:57:53 +0800316acpi_ps_link_module_code(union acpi_parse_object *parent_op,
317 u8 *aml_start, u32 aml_length, acpi_owner_id owner_id)
Lin Ming7f0c8262009-08-13 14:03:15 +0800318{
319 union acpi_operand_object *prev;
320 union acpi_operand_object *next;
321 union acpi_operand_object *method_obj;
Lin Ming9a884ab2009-11-12 09:57:53 +0800322 struct acpi_namespace_node *parent_node;
Lin Ming7f0c8262009-08-13 14:03:15 +0800323
Bob Moore25823e72015-08-25 10:29:45 +0800324 ACPI_FUNCTION_TRACE(ps_link_module_code);
325
Lin Ming7f0c8262009-08-13 14:03:15 +0800326 /* Get the tail of the list */
327
328 prev = next = acpi_gbl_module_code_list;
329 while (next) {
330 prev = next;
331 next = next->method.mutex;
332 }
333
334 /*
335 * Insert the module level code into the list. Merge it if it is
336 * adjacent to the previous element.
337 */
338 if (!prev ||
339 ((prev->method.aml_start + prev->method.aml_length) != aml_start)) {
340
341 /* Create, initialize, and link a new temporary method object */
342
343 method_obj = acpi_ut_create_internal_object(ACPI_TYPE_METHOD);
344 if (!method_obj) {
Bob Moore25823e72015-08-25 10:29:45 +0800345 return_VOID;
Lin Ming7f0c8262009-08-13 14:03:15 +0800346 }
347
Bob Moore25823e72015-08-25 10:29:45 +0800348 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
349 "Create/Link new code block: %p\n",
350 method_obj));
351
Lin Ming9a884ab2009-11-12 09:57:53 +0800352 if (parent_op->common.node) {
353 parent_node = parent_op->common.node;
354 } else {
355 parent_node = acpi_gbl_root_node;
356 }
357
Lin Ming7f0c8262009-08-13 14:03:15 +0800358 method_obj->method.aml_start = aml_start;
359 method_obj->method.aml_length = aml_length;
360 method_obj->method.owner_id = owner_id;
Lin Ming26294842011-01-12 09:19:43 +0800361 method_obj->method.info_flags |= ACPI_METHOD_MODULE_LEVEL;
Lin Ming7f0c8262009-08-13 14:03:15 +0800362
Lin Ming9a884ab2009-11-12 09:57:53 +0800363 /*
364 * Save the parent node in next_object. This is cheating, but we
365 * don't want to expand the method object.
366 */
367 method_obj->method.next_object =
368 ACPI_CAST_PTR(union acpi_operand_object, parent_node);
369
Lin Ming7f0c8262009-08-13 14:03:15 +0800370 if (!prev) {
371 acpi_gbl_module_code_list = method_obj;
372 } else {
373 prev->method.mutex = method_obj;
374 }
375 } else {
Bob Moore25823e72015-08-25 10:29:45 +0800376 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
377 "Appending to existing code block: %p\n",
378 prev));
379
Lin Ming7f0c8262009-08-13 14:03:15 +0800380 prev->method.aml_length += aml_length;
381 }
Bob Moore25823e72015-08-25 10:29:45 +0800382
383 return_VOID;
Lin Ming7f0c8262009-08-13 14:03:15 +0800384}
385
386/*******************************************************************************
387 *
Robert Moore73459f72005-06-24 00:00:00 -0400388 * FUNCTION: acpi_ps_parse_loop
389 *
390 * PARAMETERS: walk_state - Current state
391 *
392 * RETURN: Status
393 *
394 * DESCRIPTION: Parse AML (pointed to by the current parser state) and return
395 * a tree of ops.
396 *
397 ******************************************************************************/
398
Len Brown4be44fc2005-08-05 00:44:28 -0400399acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state)
Robert Moore73459f72005-06-24 00:00:00 -0400400{
Len Brown4be44fc2005-08-05 00:44:28 -0400401 acpi_status status = AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -0400402 union acpi_parse_object *op = NULL; /* current op */
Len Brown4be44fc2005-08-05 00:44:28 -0400403 struct acpi_parse_state *parser_state;
404 u8 *aml_op_start = NULL;
Robert Moore73459f72005-06-24 00:00:00 -0400405
Bob Mooreb229cf92006-04-21 17:15:00 -0400406 ACPI_FUNCTION_TRACE_PTR(ps_parse_loop, walk_state);
Robert Moore73459f72005-06-24 00:00:00 -0400407
408 if (walk_state->descending_callback == NULL) {
Len Brown4be44fc2005-08-05 00:44:28 -0400409 return_ACPI_STATUS(AE_BAD_PARAMETER);
Robert Moore73459f72005-06-24 00:00:00 -0400410 }
411
412 parser_state = &walk_state->parser_state;
413 walk_state->arg_types = 0;
414
415#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
416
417 if (walk_state->walk_type & ACPI_WALK_METHOD_RESTART) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400418
Robert Moore73459f72005-06-24 00:00:00 -0400419 /* We are restarting a preempted control method */
420
Len Brown4be44fc2005-08-05 00:44:28 -0400421 if (acpi_ps_has_completed_scope(parser_state)) {
Robert Moore73459f72005-06-24 00:00:00 -0400422 /*
423 * We must check if a predicate to an IF or WHILE statement
424 * was just completed
425 */
426 if ((parser_state->scope->parse_scope.op) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400427 ((parser_state->scope->parse_scope.op->common.
428 aml_opcode == AML_IF_OP)
429 || (parser_state->scope->parse_scope.op->common.
430 aml_opcode == AML_WHILE_OP))
431 && (walk_state->control_state)
432 && (walk_state->control_state->common.state ==
433 ACPI_CONTROL_PREDICATE_EXECUTING)) {
Robert Moore73459f72005-06-24 00:00:00 -0400434 /*
435 * A predicate was just completed, get the value of the
436 * predicate and branch based on that value
437 */
438 walk_state->op = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400439 status =
440 acpi_ds_get_predicate_value(walk_state,
441 ACPI_TO_POINTER
442 (TRUE));
443 if (ACPI_FAILURE(status)
444 && ((status & AE_CODE_MASK) !=
445 AE_CODE_CONTROL)) {
Robert Moore73459f72005-06-24 00:00:00 -0400446 if (status == AE_AML_NO_RETURN_VALUE) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500447 ACPI_EXCEPTION((AE_INFO, status,
448 "Invoked method did not return a value"));
Robert Moore73459f72005-06-24 00:00:00 -0400449 }
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300450
Bob Mooreb8e4d892006-01-27 16:43:00 -0500451 ACPI_EXCEPTION((AE_INFO, status,
Bob Mooreb229cf92006-04-21 17:15:00 -0400452 "GetPredicate Failed"));
Len Brown4be44fc2005-08-05 00:44:28 -0400453 return_ACPI_STATUS(status);
Robert Moore73459f72005-06-24 00:00:00 -0400454 }
455
Len Brown4be44fc2005-08-05 00:44:28 -0400456 status =
457 acpi_ps_next_parse_state(walk_state, op,
458 status);
Robert Moore73459f72005-06-24 00:00:00 -0400459 }
460
Len Brown4be44fc2005-08-05 00:44:28 -0400461 acpi_ps_pop_scope(parser_state, &op,
462 &walk_state->arg_types,
463 &walk_state->arg_count);
464 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
465 "Popped scope, Op=%p\n", op));
466 } else if (walk_state->prev_op) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400467
Robert Moore73459f72005-06-24 00:00:00 -0400468 /* We were in the middle of an op */
469
470 op = walk_state->prev_op;
471 walk_state->arg_types = walk_state->prev_arg_types;
472 }
473 }
474#endif
475
476 /* Iterative parsing loop, while there is more AML to process: */
477
478 while ((parser_state->aml < parser_state->aml_end) || (op)) {
479 aml_op_start = parser_state->aml;
480 if (!op) {
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300481 status =
482 acpi_ps_create_op(walk_state, aml_op_start, &op);
483 if (ACPI_FAILURE(status)) {
484 if (status == AE_CTRL_PARSE_CONTINUE) {
Robert Moore73459f72005-06-24 00:00:00 -0400485 continue;
486 }
487
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300488 if (status == AE_CTRL_PARSE_PENDING) {
Robert Moore73459f72005-06-24 00:00:00 -0400489 status = AE_OK;
Robert Moore73459f72005-06-24 00:00:00 -0400490 }
491
Bob Moore22b5afc2014-03-24 14:49:00 +0800492 if (status == AE_CTRL_TERMINATE) {
493 return_ACPI_STATUS(status);
494 }
495
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300496 status =
497 acpi_ps_complete_op(walk_state, &op,
498 status);
Len Brown4be44fc2005-08-05 00:44:28 -0400499 if (ACPI_FAILURE(status)) {
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300500 return_ACPI_STATUS(status);
Robert Moore73459f72005-06-24 00:00:00 -0400501 }
502
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300503 continue;
Robert Moore73459f72005-06-24 00:00:00 -0400504 }
505
Lv Zhengab6c5732015-07-23 12:52:59 +0800506 acpi_ex_start_trace_opcode(op, walk_state);
Robert Moore73459f72005-06-24 00:00:00 -0400507 }
508
Robert Moore73459f72005-06-24 00:00:00 -0400509 /*
510 * Start arg_count at zero because we don't know if there are
511 * any args yet
512 */
513 walk_state->arg_count = 0;
514
515 /* Are there any arguments that must be processed? */
516
517 if (walk_state->arg_types) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400518
Robert Moore73459f72005-06-24 00:00:00 -0400519 /* Get arguments */
520
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300521 status =
522 acpi_ps_get_arguments(walk_state, aml_op_start, op);
523 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400524 status =
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300525 acpi_ps_complete_op(walk_state, &op,
526 status);
Len Brown4be44fc2005-08-05 00:44:28 -0400527 if (ACPI_FAILURE(status)) {
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300528 return_ACPI_STATUS(status);
Robert Moore73459f72005-06-24 00:00:00 -0400529 }
530
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300531 continue;
Robert Moore73459f72005-06-24 00:00:00 -0400532 }
533 }
534
535 /* Check for arguments that need to be processed */
536
537 if (walk_state->arg_count) {
538 /*
539 * There are arguments (complex ones), push Op and
540 * prepare for argument
541 */
Len Brown4be44fc2005-08-05 00:44:28 -0400542 status = acpi_ps_push_scope(parser_state, op,
543 walk_state->arg_types,
544 walk_state->arg_count);
545 if (ACPI_FAILURE(status)) {
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300546 status =
547 acpi_ps_complete_op(walk_state, &op,
548 status);
549 if (ACPI_FAILURE(status)) {
550 return_ACPI_STATUS(status);
551 }
552
553 continue;
Robert Moore73459f72005-06-24 00:00:00 -0400554 }
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300555
Robert Moore73459f72005-06-24 00:00:00 -0400556 op = NULL;
557 continue;
558 }
559
560 /*
561 * All arguments have been processed -- Op is complete,
562 * prepare for next
563 */
Len Brown4be44fc2005-08-05 00:44:28 -0400564 walk_state->op_info =
565 acpi_ps_get_opcode_info(op->common.aml_opcode);
Robert Moore73459f72005-06-24 00:00:00 -0400566 if (walk_state->op_info->flags & AML_NAMED) {
Lin Ming941f48b2008-04-10 19:06:41 +0400567 if (op->common.aml_opcode == AML_REGION_OP ||
568 op->common.aml_opcode == AML_DATA_REGION_OP) {
Robert Moore73459f72005-06-24 00:00:00 -0400569 /*
570 * Skip parsing of control method or opregion body,
571 * because we don't have enough info in the first pass
572 * to parse them correctly.
573 *
574 * Completed parsing an op_region declaration, we now
575 * know the length.
576 */
Len Brown4be44fc2005-08-05 00:44:28 -0400577 op->named.length =
578 (u32) (parser_state->aml - op->named.data);
Robert Moore73459f72005-06-24 00:00:00 -0400579 }
580 }
581
582 if (walk_state->op_info->flags & AML_CREATE) {
583 /*
Bob Mooreba494be2012-07-12 09:40:10 +0800584 * Backup to beginning of create_XXXfield declaration (1 for
Robert Moore73459f72005-06-24 00:00:00 -0400585 * Opcode)
586 *
587 * body_length is unknown until we parse the body
588 */
Len Brown4be44fc2005-08-05 00:44:28 -0400589 op->named.length =
590 (u32) (parser_state->aml - op->named.data);
Robert Moore73459f72005-06-24 00:00:00 -0400591 }
592
Lin Mingef805d92008-04-10 19:06:41 +0400593 if (op->common.aml_opcode == AML_BANK_FIELD_OP) {
594 /*
595 * Backup to beginning of bank_field declaration
596 *
597 * body_length is unknown until we parse the body
598 */
599 op->named.length =
600 (u32) (parser_state->aml - op->named.data);
601 }
602
Robert Moore73459f72005-06-24 00:00:00 -0400603 /* This op complete, notify the dispatcher */
604
605 if (walk_state->ascending_callback != NULL) {
Len Brown4be44fc2005-08-05 00:44:28 -0400606 walk_state->op = op;
Robert Moore73459f72005-06-24 00:00:00 -0400607 walk_state->opcode = op->common.aml_opcode;
608
Len Brown4be44fc2005-08-05 00:44:28 -0400609 status = walk_state->ascending_callback(walk_state);
610 status =
611 acpi_ps_next_parse_state(walk_state, op, status);
Robert Moore73459f72005-06-24 00:00:00 -0400612 if (status == AE_CTRL_PENDING) {
613 status = AE_OK;
Robert Moore73459f72005-06-24 00:00:00 -0400614 }
615 }
616
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300617 status = acpi_ps_complete_op(walk_state, &op, status);
618 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400619 return_ACPI_STATUS(status);
Robert Moore73459f72005-06-24 00:00:00 -0400620 }
621
Len Brown4be44fc2005-08-05 00:44:28 -0400622 } /* while parser_state->Aml */
Robert Moore73459f72005-06-24 00:00:00 -0400623
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300624 status = acpi_ps_complete_final_op(walk_state, op, status);
Len Brown4be44fc2005-08-05 00:44:28 -0400625 return_ACPI_STATUS(status);
Robert Moore73459f72005-06-24 00:00:00 -0400626}