blob: bc5f05906bd1c871403896c3a2bce9122f3a67df [file] [log] [blame]
Erik Schmauss95857632018-03-14 16:13:07 -07001// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
Robert Moore73459f72005-06-24 00:00:00 -04002/******************************************************************************
3 *
4 * Module Name: psloop - Main AML parse loop
5 *
Bob Mooreda6f8322018-01-04 10:06:38 -08006 * Copyright (C) 2000 - 2018, Intel Corp.
Robert Moore73459f72005-06-24 00:00:00 -04007 *
Erik Schmauss95857632018-03-14 16:13:07 -07008 *****************************************************************************/
Robert Moore73459f72005-06-24 00:00:00 -04009
Robert Moore73459f72005-06-24 00:00:00 -040010/*
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +030011 * Parse the AML and build an operation tree as most interpreters, (such as
12 * Perl) do. Parsing is done by hand rather than with a YACC generated parser
13 * to tightly constrain stack and dynamic memory usage. Parsing is kept
14 * flexible and the code fairly compact by parsing based on a list of AML
15 * opcode templates in aml_op_info[].
Robert Moore73459f72005-06-24 00:00:00 -040016 */
17
18#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050019#include "accommon.h"
Lv Zhengab6c5732015-07-23 12:52:59 +080020#include "acinterp.h"
Len Browne2f7a772009-01-09 00:30:03 -050021#include "acparser.h"
22#include "acdispat.h"
23#include "amlcode.h"
Bob Moore9cf7ade2017-04-28 08:53:22 +080024#include "acconvert.h"
Robert Moore73459f72005-06-24 00:00:00 -040025
26#define _COMPONENT ACPI_PARSER
Len Brown4be44fc2005-08-05 00:44:28 -040027ACPI_MODULE_NAME("psloop")
Robert Moore73459f72005-06-24 00:00:00 -040028
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +030029/* Local prototypes */
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +030030static acpi_status
31acpi_ps_get_arguments(struct acpi_walk_state *walk_state,
32 u8 * aml_op_start, union acpi_parse_object *op);
33
Lin Ming7f0c8262009-08-13 14:03:15 +080034static void
Lin Ming9a884ab2009-11-12 09:57:53 +080035acpi_ps_link_module_code(union acpi_parse_object *parent_op,
36 u8 *aml_start, u32 aml_length, acpi_owner_id owner_id);
Lin Ming7f0c8262009-08-13 14:03:15 +080037
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +030038/*******************************************************************************
39 *
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +030040 * FUNCTION: acpi_ps_get_arguments
41 *
42 * PARAMETERS: walk_state - Current state
43 * aml_op_start - Op start in AML
Bob Mooreba494be2012-07-12 09:40:10 +080044 * op - Current Op
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +030045 *
46 * RETURN: Status
47 *
48 * DESCRIPTION: Get arguments for passed Op.
49 *
50 ******************************************************************************/
51
52static acpi_status
53acpi_ps_get_arguments(struct acpi_walk_state *walk_state,
54 u8 * aml_op_start, union acpi_parse_object *op)
55{
56 acpi_status status = AE_OK;
57 union acpi_parse_object *arg = NULL;
Lin Ming7f0c8262009-08-13 14:03:15 +080058 const struct acpi_opcode_info *op_info;
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +030059
60 ACPI_FUNCTION_TRACE_PTR(ps_get_arguments, walk_state);
61
Bob Moorece87e092016-12-28 15:29:43 +080062 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
63 "Get arguments for opcode [%s]\n",
64 op->common.aml_op_name));
65
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +030066 switch (op->common.aml_opcode) {
67 case AML_BYTE_OP: /* AML_BYTEDATA_ARG */
68 case AML_WORD_OP: /* AML_WORDDATA_ARG */
69 case AML_DWORD_OP: /* AML_DWORDATA_ARG */
70 case AML_QWORD_OP: /* AML_QWORDATA_ARG */
71 case AML_STRING_OP: /* AML_ASCIICHARLIST_ARG */
72
73 /* Fill in constant or string argument directly */
74
75 acpi_ps_get_next_simple_arg(&(walk_state->parser_state),
76 GET_CURRENT_ARG_TYPE(walk_state->
77 arg_types),
78 op);
79 break;
80
81 case AML_INT_NAMEPATH_OP: /* AML_NAMESTRING_ARG */
82
Bob Moore89438f92015-12-29 14:00:07 +080083 status = acpi_ps_get_next_namepath(walk_state,
84 &(walk_state->parser_state),
85 op,
86 ACPI_POSSIBLE_METHOD_CALL);
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +030087 if (ACPI_FAILURE(status)) {
88 return_ACPI_STATUS(status);
89 }
90
91 walk_state->arg_types = 0;
92 break;
93
94 default:
95 /*
96 * Op is not a constant or string, append each argument to the Op
97 */
Bob Moore1fad8732015-12-29 13:54:36 +080098 while (GET_CURRENT_ARG_TYPE(walk_state->arg_types) &&
99 !walk_state->arg_count) {
Lv Zheng83482f72015-07-23 12:52:11 +0800100 walk_state->aml = walk_state->parser_state.aml;
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300101
Bob Moore9cf7ade2017-04-28 08:53:22 +0800102 switch (op->common.aml_opcode) {
103 case AML_METHOD_OP:
104 case AML_BUFFER_OP:
105 case AML_PACKAGE_OP:
106 case AML_VARIABLE_PACKAGE_OP:
107 case AML_WHILE_OP:
108
109 break;
110
111 default:
112
113 ASL_CV_CAPTURE_COMMENTS(walk_state);
114 break;
115 }
116
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300117 status =
118 acpi_ps_get_next_arg(walk_state,
119 &(walk_state->parser_state),
120 GET_CURRENT_ARG_TYPE
121 (walk_state->arg_types), &arg);
122 if (ACPI_FAILURE(status)) {
123 return_ACPI_STATUS(status);
124 }
125
126 if (arg) {
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300127 acpi_ps_append_arg(op, arg);
128 }
129
130 INCREMENT_ARG_LIST(walk_state->arg_types);
131 }
132
Bob Moorea62a7112017-08-03 14:27:22 +0800133 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
Bob Moore1ef63232018-02-15 13:09:28 -0800134 "Final argument count: %8.8X pass %u\n",
Bob Moorea62a7112017-08-03 14:27:22 +0800135 walk_state->arg_count,
136 walk_state->pass_number));
137
Lin Ming7f0c8262009-08-13 14:03:15 +0800138 /*
Bob Moorea406dea2018-03-14 16:13:09 -0700139 * This case handles the legacy option that groups all module-level
140 * code blocks together and defers execution until all of the tables
141 * are loaded. Execute all of these blocks at this time.
142 * Execute any module-level code that was detected during the table
143 * load phase.
144 *
145 * Note: this option is deprecated and will be eliminated in the
146 * future. Use of this option can cause problems with AML code that
147 * depends upon in-order immediate execution of module-level code.
Lin Ming7f0c8262009-08-13 14:03:15 +0800148 */
Bob Moorea406dea2018-03-14 16:13:09 -0700149 if (acpi_gbl_group_module_level_code &&
150 (walk_state->pass_number <= ACPI_IMODE_LOAD_PASS2) &&
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300151 ((walk_state->parse_flags & ACPI_PARSE_DISASSEMBLE) == 0)) {
152 /*
153 * We want to skip If/Else/While constructs during Pass1 because we
154 * want to actually conditionally execute the code during Pass2.
155 *
156 * Except for disassembly, where we always want to walk the
157 * If/Else/While packages
158 */
159 switch (op->common.aml_opcode) {
160 case AML_IF_OP:
161 case AML_ELSE_OP:
162 case AML_WHILE_OP:
Lin Ming7f0c8262009-08-13 14:03:15 +0800163 /*
164 * Currently supported module-level opcodes are:
165 * IF/ELSE/WHILE. These appear to be the most common,
166 * and easiest to support since they open an AML
167 * package.
168 */
169 if (walk_state->pass_number ==
170 ACPI_IMODE_LOAD_PASS1) {
Lin Ming9a884ab2009-11-12 09:57:53 +0800171 acpi_ps_link_module_code(op->common.
172 parent,
173 aml_op_start,
174 (u32)
175 (walk_state->
Lin Ming7f0c8262009-08-13 14:03:15 +0800176 parser_state.
177 pkg_end -
Lin Ming9a884ab2009-11-12 09:57:53 +0800178 aml_op_start),
Lin Ming7f0c8262009-08-13 14:03:15 +0800179 walk_state->
180 owner_id);
181 }
182
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300183 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
184 "Pass1: Skipping an If/Else/While body\n"));
185
186 /* Skip body of if/else/while in pass 1 */
187
188 walk_state->parser_state.aml =
189 walk_state->parser_state.pkg_end;
190 walk_state->arg_count = 0;
191 break;
192
193 default:
Lin Ming7f0c8262009-08-13 14:03:15 +0800194 /*
195 * Check for an unsupported executable opcode at module
196 * level. We must be in PASS1, the parent must be a SCOPE,
197 * The opcode class must be EXECUTE, and the opcode must
198 * not be an argument to another opcode.
199 */
200 if ((walk_state->pass_number ==
201 ACPI_IMODE_LOAD_PASS1)
202 && (op->common.parent->common.aml_opcode ==
203 AML_SCOPE_OP)) {
204 op_info =
205 acpi_ps_get_opcode_info(op->common.
206 aml_opcode);
207 if ((op_info->class ==
208 AML_CLASS_EXECUTE) && (!arg)) {
209 ACPI_WARNING((AE_INFO,
Bob Moore00eb3252012-10-31 02:27:48 +0000210 "Unsupported module-level executable opcode "
211 "0x%.2X at table offset 0x%.4X",
212 op->common.
213 aml_opcode,
214 (u32)
215 (ACPI_PTR_DIFF
216 (aml_op_start,
217 walk_state->
218 parser_state.
219 aml_start) +
220 sizeof(struct
221 acpi_table_header))));
Lin Ming7f0c8262009-08-13 14:03:15 +0800222 }
223 }
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300224 break;
225 }
226 }
Lin Ming7f0c8262009-08-13 14:03:15 +0800227
228 /* Special processing for certain opcodes */
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300229
230 switch (op->common.aml_opcode) {
231 case AML_METHOD_OP:
232 /*
233 * Skip parsing of control method because we don't have enough
234 * info in the first pass to parse it correctly.
235 *
236 * Save the length and address of the body
237 */
238 op->named.data = walk_state->parser_state.aml;
239 op->named.length = (u32)
240 (walk_state->parser_state.pkg_end -
241 walk_state->parser_state.aml);
242
243 /* Skip body of method */
244
245 walk_state->parser_state.aml =
246 walk_state->parser_state.pkg_end;
247 walk_state->arg_count = 0;
248 break;
249
250 case AML_BUFFER_OP:
251 case AML_PACKAGE_OP:
Bob Moore9ff5a21a2017-04-26 16:18:40 +0800252 case AML_VARIABLE_PACKAGE_OP:
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300253
254 if ((op->common.parent) &&
255 (op->common.parent->common.aml_opcode ==
256 AML_NAME_OP)
257 && (walk_state->pass_number <=
258 ACPI_IMODE_LOAD_PASS2)) {
Bob Moorea62a7112017-08-03 14:27:22 +0800259 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
260 "Setup Package/Buffer: Pass %u, AML Ptr: %p\n",
261 walk_state->pass_number,
262 aml_op_start));
263
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300264 /*
265 * Skip parsing of Buffers and Packages because we don't have
266 * enough info in the first pass to parse them correctly.
267 */
268 op->named.data = aml_op_start;
269 op->named.length = (u32)
270 (walk_state->parser_state.pkg_end -
271 aml_op_start);
272
273 /* Skip body */
274
275 walk_state->parser_state.aml =
276 walk_state->parser_state.pkg_end;
277 walk_state->arg_count = 0;
278 }
279 break;
280
281 case AML_WHILE_OP:
282
283 if (walk_state->control_state) {
284 walk_state->control_state->control.package_end =
285 walk_state->parser_state.pkg_end;
286 }
287 break;
288
289 default:
290
291 /* No action for all other opcodes */
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000292
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300293 break;
294 }
295
296 break;
297 }
298
299 return_ACPI_STATUS(AE_OK);
300}
301
302/*******************************************************************************
303 *
Lin Ming7f0c8262009-08-13 14:03:15 +0800304 * FUNCTION: acpi_ps_link_module_code
305 *
Lin Ming9a884ab2009-11-12 09:57:53 +0800306 * PARAMETERS: parent_op - Parent parser op
307 * aml_start - Pointer to the AML
Lin Ming7f0c8262009-08-13 14:03:15 +0800308 * aml_length - Length of executable AML
309 * owner_id - owner_id of module level code
310 *
311 * RETURN: None.
312 *
313 * DESCRIPTION: Wrap the module-level code with a method object and link the
314 * object to the global list. Note, the mutex field of the method
315 * object is used to link multiple module-level code objects.
316 *
Bob Moorea406dea2018-03-14 16:13:09 -0700317 * NOTE: In this legacy option, each block of detected executable AML
318 * code that is outside of any control method is wrapped with a temporary
319 * control method object and placed on a global list below.
320 *
321 * This function executes the module-level code for all tables only after
322 * all of the tables have been loaded. It is a legacy option and is
323 * not compatible with other ACPI implementations. See acpi_ns_load_table.
324 *
325 * This function will be removed when the legacy option is removed.
326 *
Lin Ming7f0c8262009-08-13 14:03:15 +0800327 ******************************************************************************/
328
329static void
Lin Ming9a884ab2009-11-12 09:57:53 +0800330acpi_ps_link_module_code(union acpi_parse_object *parent_op,
331 u8 *aml_start, u32 aml_length, acpi_owner_id owner_id)
Lin Ming7f0c8262009-08-13 14:03:15 +0800332{
333 union acpi_operand_object *prev;
334 union acpi_operand_object *next;
335 union acpi_operand_object *method_obj;
Lin Ming9a884ab2009-11-12 09:57:53 +0800336 struct acpi_namespace_node *parent_node;
Lin Ming7f0c8262009-08-13 14:03:15 +0800337
Bob Moore25823e72015-08-25 10:29:45 +0800338 ACPI_FUNCTION_TRACE(ps_link_module_code);
339
Lin Ming7f0c8262009-08-13 14:03:15 +0800340 /* Get the tail of the list */
341
342 prev = next = acpi_gbl_module_code_list;
343 while (next) {
344 prev = next;
345 next = next->method.mutex;
346 }
347
348 /*
349 * Insert the module level code into the list. Merge it if it is
350 * adjacent to the previous element.
351 */
352 if (!prev ||
353 ((prev->method.aml_start + prev->method.aml_length) != aml_start)) {
354
355 /* Create, initialize, and link a new temporary method object */
356
357 method_obj = acpi_ut_create_internal_object(ACPI_TYPE_METHOD);
358 if (!method_obj) {
Bob Moore25823e72015-08-25 10:29:45 +0800359 return_VOID;
Lin Ming7f0c8262009-08-13 14:03:15 +0800360 }
361
Bob Moore25823e72015-08-25 10:29:45 +0800362 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
363 "Create/Link new code block: %p\n",
364 method_obj));
365
Lin Ming9a884ab2009-11-12 09:57:53 +0800366 if (parent_op->common.node) {
367 parent_node = parent_op->common.node;
368 } else {
369 parent_node = acpi_gbl_root_node;
370 }
371
Lin Ming7f0c8262009-08-13 14:03:15 +0800372 method_obj->method.aml_start = aml_start;
373 method_obj->method.aml_length = aml_length;
374 method_obj->method.owner_id = owner_id;
Lin Ming26294842011-01-12 09:19:43 +0800375 method_obj->method.info_flags |= ACPI_METHOD_MODULE_LEVEL;
Lin Ming7f0c8262009-08-13 14:03:15 +0800376
Lin Ming9a884ab2009-11-12 09:57:53 +0800377 /*
378 * Save the parent node in next_object. This is cheating, but we
379 * don't want to expand the method object.
380 */
381 method_obj->method.next_object =
382 ACPI_CAST_PTR(union acpi_operand_object, parent_node);
383
Lin Ming7f0c8262009-08-13 14:03:15 +0800384 if (!prev) {
385 acpi_gbl_module_code_list = method_obj;
386 } else {
387 prev->method.mutex = method_obj;
388 }
389 } else {
Bob Moore25823e72015-08-25 10:29:45 +0800390 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
391 "Appending to existing code block: %p\n",
392 prev));
393
Lin Ming7f0c8262009-08-13 14:03:15 +0800394 prev->method.aml_length += aml_length;
395 }
Bob Moore25823e72015-08-25 10:29:45 +0800396
397 return_VOID;
Lin Ming7f0c8262009-08-13 14:03:15 +0800398}
399
400/*******************************************************************************
401 *
Robert Moore73459f72005-06-24 00:00:00 -0400402 * FUNCTION: acpi_ps_parse_loop
403 *
404 * PARAMETERS: walk_state - Current state
405 *
406 * RETURN: Status
407 *
408 * DESCRIPTION: Parse AML (pointed to by the current parser state) and return
409 * a tree of ops.
410 *
411 ******************************************************************************/
412
Len Brown4be44fc2005-08-05 00:44:28 -0400413acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state)
Robert Moore73459f72005-06-24 00:00:00 -0400414{
Len Brown4be44fc2005-08-05 00:44:28 -0400415 acpi_status status = AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -0400416 union acpi_parse_object *op = NULL; /* current op */
Len Brown4be44fc2005-08-05 00:44:28 -0400417 struct acpi_parse_state *parser_state;
418 u8 *aml_op_start = NULL;
Robert Moore73459f72005-06-24 00:00:00 -0400419
Bob Mooreb229cf92006-04-21 17:15:00 -0400420 ACPI_FUNCTION_TRACE_PTR(ps_parse_loop, walk_state);
Robert Moore73459f72005-06-24 00:00:00 -0400421
422 if (walk_state->descending_callback == NULL) {
Len Brown4be44fc2005-08-05 00:44:28 -0400423 return_ACPI_STATUS(AE_BAD_PARAMETER);
Robert Moore73459f72005-06-24 00:00:00 -0400424 }
425
426 parser_state = &walk_state->parser_state;
427 walk_state->arg_types = 0;
428
429#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
430
431 if (walk_state->walk_type & ACPI_WALK_METHOD_RESTART) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400432
Robert Moore73459f72005-06-24 00:00:00 -0400433 /* We are restarting a preempted control method */
434
Len Brown4be44fc2005-08-05 00:44:28 -0400435 if (acpi_ps_has_completed_scope(parser_state)) {
Robert Moore73459f72005-06-24 00:00:00 -0400436 /*
437 * We must check if a predicate to an IF or WHILE statement
438 * was just completed
439 */
440 if ((parser_state->scope->parse_scope.op) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400441 ((parser_state->scope->parse_scope.op->common.
442 aml_opcode == AML_IF_OP)
443 || (parser_state->scope->parse_scope.op->common.
444 aml_opcode == AML_WHILE_OP))
445 && (walk_state->control_state)
446 && (walk_state->control_state->common.state ==
447 ACPI_CONTROL_PREDICATE_EXECUTING)) {
Robert Moore73459f72005-06-24 00:00:00 -0400448 /*
449 * A predicate was just completed, get the value of the
450 * predicate and branch based on that value
451 */
452 walk_state->op = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400453 status =
454 acpi_ds_get_predicate_value(walk_state,
455 ACPI_TO_POINTER
456 (TRUE));
457 if (ACPI_FAILURE(status)
458 && ((status & AE_CODE_MASK) !=
459 AE_CODE_CONTROL)) {
Robert Moore73459f72005-06-24 00:00:00 -0400460 if (status == AE_AML_NO_RETURN_VALUE) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500461 ACPI_EXCEPTION((AE_INFO, status,
462 "Invoked method did not return a value"));
Robert Moore73459f72005-06-24 00:00:00 -0400463 }
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300464
Bob Mooreb8e4d892006-01-27 16:43:00 -0500465 ACPI_EXCEPTION((AE_INFO, status,
Bob Mooreb229cf92006-04-21 17:15:00 -0400466 "GetPredicate Failed"));
Len Brown4be44fc2005-08-05 00:44:28 -0400467 return_ACPI_STATUS(status);
Robert Moore73459f72005-06-24 00:00:00 -0400468 }
469
Len Brown4be44fc2005-08-05 00:44:28 -0400470 status =
471 acpi_ps_next_parse_state(walk_state, op,
472 status);
Robert Moore73459f72005-06-24 00:00:00 -0400473 }
474
Len Brown4be44fc2005-08-05 00:44:28 -0400475 acpi_ps_pop_scope(parser_state, &op,
476 &walk_state->arg_types,
477 &walk_state->arg_count);
478 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
479 "Popped scope, Op=%p\n", op));
480 } else if (walk_state->prev_op) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400481
Robert Moore73459f72005-06-24 00:00:00 -0400482 /* We were in the middle of an op */
483
484 op = walk_state->prev_op;
485 walk_state->arg_types = walk_state->prev_arg_types;
486 }
487 }
488#endif
489
490 /* Iterative parsing loop, while there is more AML to process: */
491
492 while ((parser_state->aml < parser_state->aml_end) || (op)) {
Bob Moore9cf7ade2017-04-28 08:53:22 +0800493 ASL_CV_CAPTURE_COMMENTS(walk_state);
494
Robert Moore73459f72005-06-24 00:00:00 -0400495 aml_op_start = parser_state->aml;
496 if (!op) {
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300497 status =
498 acpi_ps_create_op(walk_state, aml_op_start, &op);
499 if (ACPI_FAILURE(status)) {
500 if (status == AE_CTRL_PARSE_CONTINUE) {
Robert Moore73459f72005-06-24 00:00:00 -0400501 continue;
502 }
503
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300504 if (status == AE_CTRL_PARSE_PENDING) {
Robert Moore73459f72005-06-24 00:00:00 -0400505 status = AE_OK;
Robert Moore73459f72005-06-24 00:00:00 -0400506 }
507
Bob Moore22b5afc2014-03-24 14:49:00 +0800508 if (status == AE_CTRL_TERMINATE) {
509 return_ACPI_STATUS(status);
510 }
511
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300512 status =
513 acpi_ps_complete_op(walk_state, &op,
514 status);
Len Brown4be44fc2005-08-05 00:44:28 -0400515 if (ACPI_FAILURE(status)) {
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300516 return_ACPI_STATUS(status);
Robert Moore73459f72005-06-24 00:00:00 -0400517 }
Erik Schmauss50888142018-06-01 12:06:43 -0700518 if (walk_state->opcode == AML_SCOPE_OP) {
519 /*
520 * If the scope op fails to parse, skip the body of the
521 * scope op because the parse failure indicates that the
522 * device may not exist.
523 */
524 walk_state->parser_state.aml =
525 walk_state->aml + 1;
526 walk_state->parser_state.aml =
527 acpi_ps_get_next_package_end
528 (&walk_state->parser_state);
529 walk_state->aml =
530 walk_state->parser_state.aml;
531 ACPI_ERROR((AE_INFO,
532 "Skipping Scope block"));
533 }
Robert Moore73459f72005-06-24 00:00:00 -0400534
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300535 continue;
Robert Moore73459f72005-06-24 00:00:00 -0400536 }
537
Lv Zhengab6c5732015-07-23 12:52:59 +0800538 acpi_ex_start_trace_opcode(op, walk_state);
Robert Moore73459f72005-06-24 00:00:00 -0400539 }
540
Robert Moore73459f72005-06-24 00:00:00 -0400541 /*
542 * Start arg_count at zero because we don't know if there are
543 * any args yet
544 */
545 walk_state->arg_count = 0;
546
Bob Moore9cf7ade2017-04-28 08:53:22 +0800547 switch (op->common.aml_opcode) {
548 case AML_BYTE_OP:
549 case AML_WORD_OP:
550 case AML_DWORD_OP:
551 case AML_QWORD_OP:
552
553 break;
554
555 default:
556
557 ASL_CV_CAPTURE_COMMENTS(walk_state);
558 break;
559 }
560
Robert Moore73459f72005-06-24 00:00:00 -0400561 /* Are there any arguments that must be processed? */
562
563 if (walk_state->arg_types) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400564
Robert Moore73459f72005-06-24 00:00:00 -0400565 /* Get arguments */
566
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300567 status =
568 acpi_ps_get_arguments(walk_state, aml_op_start, op);
569 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400570 status =
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300571 acpi_ps_complete_op(walk_state, &op,
572 status);
Len Brown4be44fc2005-08-05 00:44:28 -0400573 if (ACPI_FAILURE(status)) {
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300574 return_ACPI_STATUS(status);
Robert Moore73459f72005-06-24 00:00:00 -0400575 }
Erik Schmauss50888142018-06-01 12:06:43 -0700576 if ((walk_state->control_state) &&
577 ((walk_state->control_state->control.
578 opcode == AML_IF_OP)
579 || (walk_state->control_state->control.
580 opcode == AML_WHILE_OP))) {
581 /*
582 * If the if/while op fails to parse, we will skip parsing
583 * the body of the op.
584 */
585 parser_state->aml =
586 walk_state->control_state->control.
587 aml_predicate_start + 1;
588 parser_state->aml =
589 acpi_ps_get_next_package_end
590 (parser_state);
591 walk_state->aml = parser_state->aml;
Robert Moore73459f72005-06-24 00:00:00 -0400592
Erik Schmauss50888142018-06-01 12:06:43 -0700593 ACPI_ERROR((AE_INFO,
594 "Skipping While/If block"));
595 if (*walk_state->aml == AML_ELSE_OP) {
596 ACPI_ERROR((AE_INFO,
597 "Skipping Else block"));
598 walk_state->parser_state.aml =
599 walk_state->aml + 1;
600 walk_state->parser_state.aml =
601 acpi_ps_get_next_package_end
602 (parser_state);
603 walk_state->aml =
604 parser_state->aml;
605 }
606 ACPI_FREE(acpi_ut_pop_generic_state
607 (&walk_state->control_state));
608 }
609 op = NULL;
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300610 continue;
Robert Moore73459f72005-06-24 00:00:00 -0400611 }
612 }
613
614 /* Check for arguments that need to be processed */
615
Bob Moorea62a7112017-08-03 14:27:22 +0800616 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
Bob Moore1ef63232018-02-15 13:09:28 -0800617 "Parseloop: argument count: %8.8X\n",
Bob Moorea62a7112017-08-03 14:27:22 +0800618 walk_state->arg_count));
619
Robert Moore73459f72005-06-24 00:00:00 -0400620 if (walk_state->arg_count) {
621 /*
622 * There are arguments (complex ones), push Op and
623 * prepare for argument
624 */
Len Brown4be44fc2005-08-05 00:44:28 -0400625 status = acpi_ps_push_scope(parser_state, op,
626 walk_state->arg_types,
627 walk_state->arg_count);
628 if (ACPI_FAILURE(status)) {
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300629 status =
630 acpi_ps_complete_op(walk_state, &op,
631 status);
632 if (ACPI_FAILURE(status)) {
633 return_ACPI_STATUS(status);
634 }
635
636 continue;
Robert Moore73459f72005-06-24 00:00:00 -0400637 }
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300638
Robert Moore73459f72005-06-24 00:00:00 -0400639 op = NULL;
640 continue;
641 }
642
643 /*
644 * All arguments have been processed -- Op is complete,
645 * prepare for next
646 */
Len Brown4be44fc2005-08-05 00:44:28 -0400647 walk_state->op_info =
648 acpi_ps_get_opcode_info(op->common.aml_opcode);
Robert Moore73459f72005-06-24 00:00:00 -0400649 if (walk_state->op_info->flags & AML_NAMED) {
Lin Ming941f48b2008-04-10 19:06:41 +0400650 if (op->common.aml_opcode == AML_REGION_OP ||
651 op->common.aml_opcode == AML_DATA_REGION_OP) {
Robert Moore73459f72005-06-24 00:00:00 -0400652 /*
653 * Skip parsing of control method or opregion body,
654 * because we don't have enough info in the first pass
655 * to parse them correctly.
656 *
657 * Completed parsing an op_region declaration, we now
658 * know the length.
659 */
Len Brown4be44fc2005-08-05 00:44:28 -0400660 op->named.length =
661 (u32) (parser_state->aml - op->named.data);
Robert Moore73459f72005-06-24 00:00:00 -0400662 }
663 }
664
665 if (walk_state->op_info->flags & AML_CREATE) {
666 /*
Bob Mooreba494be2012-07-12 09:40:10 +0800667 * Backup to beginning of create_XXXfield declaration (1 for
Robert Moore73459f72005-06-24 00:00:00 -0400668 * Opcode)
669 *
670 * body_length is unknown until we parse the body
671 */
Len Brown4be44fc2005-08-05 00:44:28 -0400672 op->named.length =
673 (u32) (parser_state->aml - op->named.data);
Robert Moore73459f72005-06-24 00:00:00 -0400674 }
675
Lin Mingef805d92008-04-10 19:06:41 +0400676 if (op->common.aml_opcode == AML_BANK_FIELD_OP) {
677 /*
678 * Backup to beginning of bank_field declaration
679 *
680 * body_length is unknown until we parse the body
681 */
682 op->named.length =
683 (u32) (parser_state->aml - op->named.data);
684 }
685
Robert Moore73459f72005-06-24 00:00:00 -0400686 /* This op complete, notify the dispatcher */
687
688 if (walk_state->ascending_callback != NULL) {
Len Brown4be44fc2005-08-05 00:44:28 -0400689 walk_state->op = op;
Robert Moore73459f72005-06-24 00:00:00 -0400690 walk_state->opcode = op->common.aml_opcode;
691
Len Brown4be44fc2005-08-05 00:44:28 -0400692 status = walk_state->ascending_callback(walk_state);
693 status =
694 acpi_ps_next_parse_state(walk_state, op, status);
Robert Moore73459f72005-06-24 00:00:00 -0400695 if (status == AE_CTRL_PENDING) {
696 status = AE_OK;
Robert Moore73459f72005-06-24 00:00:00 -0400697 }
698 }
699
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300700 status = acpi_ps_complete_op(walk_state, &op, status);
701 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400702 return_ACPI_STATUS(status);
Robert Moore73459f72005-06-24 00:00:00 -0400703 }
704
Len Brown4be44fc2005-08-05 00:44:28 -0400705 } /* while parser_state->Aml */
Robert Moore73459f72005-06-24 00:00:00 -0400706
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300707 status = acpi_ps_complete_final_op(walk_state, op, status);
Len Brown4be44fc2005-08-05 00:44:28 -0400708 return_ACPI_STATUS(status);
Robert Moore73459f72005-06-24 00:00:00 -0400709}