blob: a6f8592c9ae5cbb337235ac9532e175207f55fd4 [file] [log] [blame]
Robert Moore73459f72005-06-24 00:00:00 -04001/******************************************************************************
2 *
3 * Module Name: psloop - Main AML parse loop
4 *
5 *****************************************************************************/
6
7/*
Bob Moore77848132012-01-12 13:27:23 +08008 * Copyright (C) 2000 - 2012, 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"
54#include "acparser.h"
55#include "acdispat.h"
56#include "amlcode.h"
Robert Moore73459f72005-06-24 00:00:00 -040057
58#define _COMPONENT ACPI_PARSER
Len Brown4be44fc2005-08-05 00:44:28 -040059ACPI_MODULE_NAME("psloop")
Robert Moore73459f72005-06-24 00:00:00 -040060
Len Brown4be44fc2005-08-05 00:44:28 -040061static u32 acpi_gbl_depth = 0;
Robert Moore73459f72005-06-24 00:00:00 -040062
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +030063/* Local prototypes */
64
65static acpi_status acpi_ps_get_aml_opcode(struct acpi_walk_state *walk_state);
66
67static acpi_status
68acpi_ps_build_named_op(struct acpi_walk_state *walk_state,
69 u8 * aml_op_start,
70 union acpi_parse_object *unnamed_op,
71 union acpi_parse_object **op);
72
73static acpi_status
74acpi_ps_create_op(struct acpi_walk_state *walk_state,
75 u8 * aml_op_start, union acpi_parse_object **new_op);
76
77static acpi_status
78acpi_ps_get_arguments(struct acpi_walk_state *walk_state,
79 u8 * aml_op_start, union acpi_parse_object *op);
80
81static acpi_status
82acpi_ps_complete_op(struct acpi_walk_state *walk_state,
83 union acpi_parse_object **op, acpi_status status);
84
85static acpi_status
86acpi_ps_complete_final_op(struct acpi_walk_state *walk_state,
87 union acpi_parse_object *op, acpi_status status);
88
Lin Ming7f0c8262009-08-13 14:03:15 +080089static void
Lin Ming9a884ab2009-11-12 09:57:53 +080090acpi_ps_link_module_code(union acpi_parse_object *parent_op,
91 u8 *aml_start, u32 aml_length, acpi_owner_id owner_id);
Lin Ming7f0c8262009-08-13 14:03:15 +080092
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +030093/*******************************************************************************
94 *
95 * FUNCTION: acpi_ps_get_aml_opcode
96 *
97 * PARAMETERS: walk_state - Current state
98 *
99 * RETURN: Status
100 *
101 * DESCRIPTION: Extract the next AML opcode from the input stream.
102 *
103 ******************************************************************************/
104
105static acpi_status acpi_ps_get_aml_opcode(struct acpi_walk_state *walk_state)
106{
107
108 ACPI_FUNCTION_TRACE_PTR(ps_get_aml_opcode, walk_state);
109
110 walk_state->aml_offset =
111 (u32) ACPI_PTR_DIFF(walk_state->parser_state.aml,
112 walk_state->parser_state.aml_start);
113 walk_state->opcode = acpi_ps_peek_opcode(&(walk_state->parser_state));
114
115 /*
116 * First cut to determine what we have found:
117 * 1) A valid AML opcode
118 * 2) A name string
119 * 3) An unknown/invalid opcode
120 */
121 walk_state->op_info = acpi_ps_get_opcode_info(walk_state->opcode);
122
123 switch (walk_state->op_info->class) {
124 case AML_CLASS_ASCII:
125 case AML_CLASS_PREFIX:
126 /*
127 * Starts with a valid prefix or ASCII char, this is a name
128 * string. Convert the bare name string to a namepath.
129 */
130 walk_state->opcode = AML_INT_NAMEPATH_OP;
131 walk_state->arg_types = ARGP_NAMESTRING;
132 break;
133
134 case AML_CLASS_UNKNOWN:
135
Bob Moore97171c62012-10-31 02:28:11 +0000136 /* The opcode is unrecognized. Complain and skip unknown opcodes */
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300137
Bob Moore00eb3252012-10-31 02:27:48 +0000138 if (walk_state->pass_number == 2) {
139 ACPI_ERROR((AE_INFO,
140 "Unknown opcode 0x%.2X at table offset 0x%.4X, ignoring",
141 walk_state->opcode,
Bob Moore17b1f452012-10-31 02:28:27 +0000142 (u32)(walk_state->aml_offset +
143 sizeof(struct acpi_table_header))));
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300144
Bob Moorec8d586f2012-12-31 00:05:39 +0000145 ACPI_DUMP_BUFFER((walk_state->parser_state.aml - 16),
146 48);
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300147
Bob Moore00eb3252012-10-31 02:27:48 +0000148#ifdef ACPI_ASL_COMPILER
Bob Moore97171c62012-10-31 02:28:11 +0000149 /*
150 * This is executed for the disassembler only. Output goes
151 * to the disassembled ASL output file.
152 */
Bob Moore00eb3252012-10-31 02:27:48 +0000153 acpi_os_printf
154 ("/*\nError: Unknown opcode 0x%.2X at table offset 0x%.4X, context:\n",
155 walk_state->opcode,
Bob Moore17b1f452012-10-31 02:28:27 +0000156 (u32)(walk_state->aml_offset +
157 sizeof(struct acpi_table_header)));
Bob Moore00eb3252012-10-31 02:27:48 +0000158
Bob Moore97171c62012-10-31 02:28:11 +0000159 /* Dump the context surrounding the invalid opcode */
Bob Moore00eb3252012-10-31 02:27:48 +0000160
Bob Moore97171c62012-10-31 02:28:11 +0000161 acpi_ut_dump_buffer(((u8 *)walk_state->parser_state.
162 aml - 16), 48, DB_BYTE_DISPLAY,
Bob Moorec8d586f2012-12-31 00:05:39 +0000163 (walk_state->aml_offset +
164 sizeof(struct acpi_table_header) -
165 16));
Bob Moore00eb3252012-10-31 02:27:48 +0000166 acpi_os_printf(" */\n");
167#endif
168 }
169
Bob Moore97171c62012-10-31 02:28:11 +0000170 /* Increment past one-byte or two-byte opcode */
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300171
172 walk_state->parser_state.aml++;
Bob Moore97171c62012-10-31 02:28:11 +0000173 if (walk_state->opcode > 0xFF) { /* Can only happen if first byte is 0x5B */
Bob Moore00eb3252012-10-31 02:27:48 +0000174 walk_state->parser_state.aml++;
175 }
176
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300177 return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE);
178
179 default:
180
181 /* Found opcode info, this is a normal opcode */
182
183 walk_state->parser_state.aml +=
184 acpi_ps_get_opcode_size(walk_state->opcode);
185 walk_state->arg_types = walk_state->op_info->parse_args;
186 break;
187 }
188
189 return_ACPI_STATUS(AE_OK);
190}
191
192/*******************************************************************************
193 *
194 * FUNCTION: acpi_ps_build_named_op
195 *
196 * PARAMETERS: walk_state - Current state
197 * aml_op_start - Begin of named Op in AML
198 * unnamed_op - Early Op (not a named Op)
Bob Mooreba494be2012-07-12 09:40:10 +0800199 * op - Returned Op
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300200 *
201 * RETURN: Status
202 *
203 * DESCRIPTION: Parse a named Op
204 *
205 ******************************************************************************/
206
207static acpi_status
208acpi_ps_build_named_op(struct acpi_walk_state *walk_state,
209 u8 * aml_op_start,
210 union acpi_parse_object *unnamed_op,
211 union acpi_parse_object **op)
212{
213 acpi_status status = AE_OK;
214 union acpi_parse_object *arg = NULL;
215
216 ACPI_FUNCTION_TRACE_PTR(ps_build_named_op, walk_state);
217
218 unnamed_op->common.value.arg = NULL;
Bob Moore4e3156b2008-04-10 19:06:37 +0400219 unnamed_op->common.arg_list_length = 0;
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300220 unnamed_op->common.aml_opcode = walk_state->opcode;
221
222 /*
223 * Get and append arguments until we find the node that contains
224 * the name (the type ARGP_NAME).
225 */
226 while (GET_CURRENT_ARG_TYPE(walk_state->arg_types) &&
227 (GET_CURRENT_ARG_TYPE(walk_state->arg_types) != ARGP_NAME)) {
228 status =
229 acpi_ps_get_next_arg(walk_state,
230 &(walk_state->parser_state),
231 GET_CURRENT_ARG_TYPE(walk_state->
232 arg_types), &arg);
233 if (ACPI_FAILURE(status)) {
234 return_ACPI_STATUS(status);
235 }
236
237 acpi_ps_append_arg(unnamed_op, arg);
238 INCREMENT_ARG_LIST(walk_state->arg_types);
239 }
240
241 /*
242 * Make sure that we found a NAME and didn't run out of arguments
243 */
244 if (!GET_CURRENT_ARG_TYPE(walk_state->arg_types)) {
245 return_ACPI_STATUS(AE_AML_NO_OPERAND);
246 }
247
248 /* We know that this arg is a name, move to next arg */
249
250 INCREMENT_ARG_LIST(walk_state->arg_types);
251
252 /*
253 * Find the object. This will either insert the object into
254 * the namespace or simply look it up
255 */
256 walk_state->op = NULL;
257
258 status = walk_state->descending_callback(walk_state, op);
259 if (ACPI_FAILURE(status)) {
260 ACPI_EXCEPTION((AE_INFO, status, "During name lookup/catalog"));
261 return_ACPI_STATUS(status);
262 }
263
Valery Podrezov9bc75cf2007-02-02 19:48:21 +0300264 if (!*op) {
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300265 return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE);
266 }
267
268 status = acpi_ps_next_parse_state(walk_state, *op, status);
269 if (ACPI_FAILURE(status)) {
270 if (status == AE_CTRL_PENDING) {
271 return_ACPI_STATUS(AE_CTRL_PARSE_PENDING);
272 }
273 return_ACPI_STATUS(status);
274 }
275
276 acpi_ps_append_arg(*op, unnamed_op->common.value.arg);
277 acpi_gbl_depth++;
278
Lin Ming941f48b2008-04-10 19:06:41 +0400279 if ((*op)->common.aml_opcode == AML_REGION_OP ||
280 (*op)->common.aml_opcode == AML_DATA_REGION_OP) {
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300281 /*
282 * Defer final parsing of an operation_region body, because we don't
283 * have enough info in the first pass to parse it correctly (i.e.,
284 * there may be method calls within the term_arg elements of the body.)
285 *
286 * However, we must continue parsing because the opregion is not a
287 * standalone package -- we don't know where the end is at this point.
288 *
289 * (Length is unknown until parse of the body complete)
290 */
291 (*op)->named.data = aml_op_start;
292 (*op)->named.length = 0;
293 }
294
295 return_ACPI_STATUS(AE_OK);
296}
297
298/*******************************************************************************
299 *
300 * FUNCTION: acpi_ps_create_op
301 *
302 * PARAMETERS: walk_state - Current state
303 * aml_op_start - Op start in AML
304 * new_op - Returned Op
305 *
306 * RETURN: Status
307 *
308 * DESCRIPTION: Get Op from AML
309 *
310 ******************************************************************************/
311
312static acpi_status
313acpi_ps_create_op(struct acpi_walk_state *walk_state,
314 u8 * aml_op_start, union acpi_parse_object **new_op)
315{
316 acpi_status status = AE_OK;
317 union acpi_parse_object *op;
318 union acpi_parse_object *named_op = NULL;
Bob Moore4e3156b2008-04-10 19:06:37 +0400319 union acpi_parse_object *parent_scope;
320 u8 argument_count;
321 const struct acpi_opcode_info *op_info;
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300322
323 ACPI_FUNCTION_TRACE_PTR(ps_create_op, walk_state);
324
325 status = acpi_ps_get_aml_opcode(walk_state);
326 if (status == AE_CTRL_PARSE_CONTINUE) {
327 return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE);
328 }
329
330 /* Create Op structure and append to parent's argument list */
331
332 walk_state->op_info = acpi_ps_get_opcode_info(walk_state->opcode);
333 op = acpi_ps_alloc_op(walk_state->opcode);
334 if (!op) {
335 return_ACPI_STATUS(AE_NO_MEMORY);
336 }
337
338 if (walk_state->op_info->flags & AML_NAMED) {
339 status =
340 acpi_ps_build_named_op(walk_state, aml_op_start, op,
341 &named_op);
342 acpi_ps_free_op(op);
343 if (ACPI_FAILURE(status)) {
344 return_ACPI_STATUS(status);
345 }
346
347 *new_op = named_op;
348 return_ACPI_STATUS(AE_OK);
349 }
350
351 /* Not a named opcode, just allocate Op and append to parent */
352
353 if (walk_state->op_info->flags & AML_CREATE) {
354 /*
Bob Mooreba494be2012-07-12 09:40:10 +0800355 * Backup to beginning of create_XXXfield declaration
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300356 * body_length is unknown until we parse the body
357 */
358 op->named.data = aml_op_start;
359 op->named.length = 0;
360 }
361
Lin Mingef805d92008-04-10 19:06:41 +0400362 if (walk_state->opcode == AML_BANK_FIELD_OP) {
363 /*
364 * Backup to beginning of bank_field declaration
365 * body_length is unknown until we parse the body
366 */
367 op->named.data = aml_op_start;
368 op->named.length = 0;
369 }
370
Bob Moore4e3156b2008-04-10 19:06:37 +0400371 parent_scope = acpi_ps_get_parent_scope(&(walk_state->parser_state));
372 acpi_ps_append_arg(parent_scope, op);
373
374 if (parent_scope) {
375 op_info =
376 acpi_ps_get_opcode_info(parent_scope->common.aml_opcode);
377 if (op_info->flags & AML_HAS_TARGET) {
378 argument_count =
379 acpi_ps_get_argument_count(op_info->type);
380 if (parent_scope->common.arg_list_length >
381 argument_count) {
382 op->common.flags |= ACPI_PARSEOP_TARGET;
383 }
384 } else if (parent_scope->common.aml_opcode == AML_INCREMENT_OP) {
385 op->common.flags |= ACPI_PARSEOP_TARGET;
386 }
387 }
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300388
389 if (walk_state->descending_callback != NULL) {
390 /*
391 * Find the object. This will either insert the object into
392 * the namespace or simply look it up
393 */
394 walk_state->op = *new_op = op;
395
396 status = walk_state->descending_callback(walk_state, &op);
397 status = acpi_ps_next_parse_state(walk_state, op, status);
398 if (status == AE_CTRL_PENDING) {
399 status = AE_CTRL_PARSE_PENDING;
400 }
401 }
402
403 return_ACPI_STATUS(status);
404}
405
406/*******************************************************************************
407 *
408 * FUNCTION: acpi_ps_get_arguments
409 *
410 * PARAMETERS: walk_state - Current state
411 * aml_op_start - Op start in AML
Bob Mooreba494be2012-07-12 09:40:10 +0800412 * op - Current Op
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300413 *
414 * RETURN: Status
415 *
416 * DESCRIPTION: Get arguments for passed Op.
417 *
418 ******************************************************************************/
419
420static acpi_status
421acpi_ps_get_arguments(struct acpi_walk_state *walk_state,
422 u8 * aml_op_start, union acpi_parse_object *op)
423{
424 acpi_status status = AE_OK;
425 union acpi_parse_object *arg = NULL;
Lin Ming7f0c8262009-08-13 14:03:15 +0800426 const struct acpi_opcode_info *op_info;
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300427
428 ACPI_FUNCTION_TRACE_PTR(ps_get_arguments, walk_state);
429
430 switch (op->common.aml_opcode) {
431 case AML_BYTE_OP: /* AML_BYTEDATA_ARG */
432 case AML_WORD_OP: /* AML_WORDDATA_ARG */
433 case AML_DWORD_OP: /* AML_DWORDATA_ARG */
434 case AML_QWORD_OP: /* AML_QWORDATA_ARG */
435 case AML_STRING_OP: /* AML_ASCIICHARLIST_ARG */
436
437 /* Fill in constant or string argument directly */
438
439 acpi_ps_get_next_simple_arg(&(walk_state->parser_state),
440 GET_CURRENT_ARG_TYPE(walk_state->
441 arg_types),
442 op);
443 break;
444
445 case AML_INT_NAMEPATH_OP: /* AML_NAMESTRING_ARG */
446
447 status =
448 acpi_ps_get_next_namepath(walk_state,
449 &(walk_state->parser_state), op,
450 1);
451 if (ACPI_FAILURE(status)) {
452 return_ACPI_STATUS(status);
453 }
454
455 walk_state->arg_types = 0;
456 break;
457
458 default:
459 /*
460 * Op is not a constant or string, append each argument to the Op
461 */
462 while (GET_CURRENT_ARG_TYPE(walk_state->arg_types)
463 && !walk_state->arg_count) {
464 walk_state->aml_offset =
465 (u32) ACPI_PTR_DIFF(walk_state->parser_state.aml,
466 walk_state->parser_state.
467 aml_start);
468
469 status =
470 acpi_ps_get_next_arg(walk_state,
471 &(walk_state->parser_state),
472 GET_CURRENT_ARG_TYPE
473 (walk_state->arg_types), &arg);
474 if (ACPI_FAILURE(status)) {
475 return_ACPI_STATUS(status);
476 }
477
478 if (arg) {
479 arg->common.aml_offset = walk_state->aml_offset;
480 acpi_ps_append_arg(op, arg);
481 }
482
483 INCREMENT_ARG_LIST(walk_state->arg_types);
484 }
485
Lin Ming7f0c8262009-08-13 14:03:15 +0800486 /*
487 * Handle executable code at "module-level". This refers to
488 * executable opcodes that appear outside of any control method.
489 */
490 if ((walk_state->pass_number <= ACPI_IMODE_LOAD_PASS2) &&
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300491 ((walk_state->parse_flags & ACPI_PARSE_DISASSEMBLE) == 0)) {
492 /*
493 * We want to skip If/Else/While constructs during Pass1 because we
494 * want to actually conditionally execute the code during Pass2.
495 *
496 * Except for disassembly, where we always want to walk the
497 * If/Else/While packages
498 */
499 switch (op->common.aml_opcode) {
500 case AML_IF_OP:
501 case AML_ELSE_OP:
502 case AML_WHILE_OP:
503
Lin Ming7f0c8262009-08-13 14:03:15 +0800504 /*
505 * Currently supported module-level opcodes are:
506 * IF/ELSE/WHILE. These appear to be the most common,
507 * and easiest to support since they open an AML
508 * package.
509 */
510 if (walk_state->pass_number ==
511 ACPI_IMODE_LOAD_PASS1) {
Lin Ming9a884ab2009-11-12 09:57:53 +0800512 acpi_ps_link_module_code(op->common.
513 parent,
514 aml_op_start,
515 (u32)
516 (walk_state->
Lin Ming7f0c8262009-08-13 14:03:15 +0800517 parser_state.
518 pkg_end -
Lin Ming9a884ab2009-11-12 09:57:53 +0800519 aml_op_start),
Lin Ming7f0c8262009-08-13 14:03:15 +0800520 walk_state->
521 owner_id);
522 }
523
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300524 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
525 "Pass1: Skipping an If/Else/While body\n"));
526
527 /* Skip body of if/else/while in pass 1 */
528
529 walk_state->parser_state.aml =
530 walk_state->parser_state.pkg_end;
531 walk_state->arg_count = 0;
532 break;
533
534 default:
Lin Ming7f0c8262009-08-13 14:03:15 +0800535 /*
536 * Check for an unsupported executable opcode at module
537 * level. We must be in PASS1, the parent must be a SCOPE,
538 * The opcode class must be EXECUTE, and the opcode must
539 * not be an argument to another opcode.
540 */
541 if ((walk_state->pass_number ==
542 ACPI_IMODE_LOAD_PASS1)
543 && (op->common.parent->common.aml_opcode ==
544 AML_SCOPE_OP)) {
545 op_info =
546 acpi_ps_get_opcode_info(op->common.
547 aml_opcode);
548 if ((op_info->class ==
549 AML_CLASS_EXECUTE) && (!arg)) {
550 ACPI_WARNING((AE_INFO,
Bob Moore00eb3252012-10-31 02:27:48 +0000551 "Unsupported module-level executable opcode "
552 "0x%.2X at table offset 0x%.4X",
553 op->common.
554 aml_opcode,
555 (u32)
556 (ACPI_PTR_DIFF
557 (aml_op_start,
558 walk_state->
559 parser_state.
560 aml_start) +
561 sizeof(struct
562 acpi_table_header))));
Lin Ming7f0c8262009-08-13 14:03:15 +0800563 }
564 }
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300565 break;
566 }
567 }
Lin Ming7f0c8262009-08-13 14:03:15 +0800568
569 /* Special processing for certain opcodes */
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300570
571 switch (op->common.aml_opcode) {
572 case AML_METHOD_OP:
573 /*
574 * Skip parsing of control method because we don't have enough
575 * info in the first pass to parse it correctly.
576 *
577 * Save the length and address of the body
578 */
579 op->named.data = walk_state->parser_state.aml;
580 op->named.length = (u32)
581 (walk_state->parser_state.pkg_end -
582 walk_state->parser_state.aml);
583
584 /* Skip body of method */
585
586 walk_state->parser_state.aml =
587 walk_state->parser_state.pkg_end;
588 walk_state->arg_count = 0;
589 break;
590
591 case AML_BUFFER_OP:
592 case AML_PACKAGE_OP:
593 case AML_VAR_PACKAGE_OP:
594
595 if ((op->common.parent) &&
596 (op->common.parent->common.aml_opcode ==
597 AML_NAME_OP)
598 && (walk_state->pass_number <=
599 ACPI_IMODE_LOAD_PASS2)) {
600 /*
601 * Skip parsing of Buffers and Packages because we don't have
602 * enough info in the first pass to parse them correctly.
603 */
604 op->named.data = aml_op_start;
605 op->named.length = (u32)
606 (walk_state->parser_state.pkg_end -
607 aml_op_start);
608
609 /* Skip body */
610
611 walk_state->parser_state.aml =
612 walk_state->parser_state.pkg_end;
613 walk_state->arg_count = 0;
614 }
615 break;
616
617 case AML_WHILE_OP:
618
619 if (walk_state->control_state) {
620 walk_state->control_state->control.package_end =
621 walk_state->parser_state.pkg_end;
622 }
623 break;
624
625 default:
626
627 /* No action for all other opcodes */
628 break;
629 }
630
631 break;
632 }
633
634 return_ACPI_STATUS(AE_OK);
635}
636
637/*******************************************************************************
638 *
Lin Ming7f0c8262009-08-13 14:03:15 +0800639 * FUNCTION: acpi_ps_link_module_code
640 *
Lin Ming9a884ab2009-11-12 09:57:53 +0800641 * PARAMETERS: parent_op - Parent parser op
642 * aml_start - Pointer to the AML
Lin Ming7f0c8262009-08-13 14:03:15 +0800643 * aml_length - Length of executable AML
644 * owner_id - owner_id of module level code
645 *
646 * RETURN: None.
647 *
648 * DESCRIPTION: Wrap the module-level code with a method object and link the
649 * object to the global list. Note, the mutex field of the method
650 * object is used to link multiple module-level code objects.
651 *
652 ******************************************************************************/
653
654static void
Lin Ming9a884ab2009-11-12 09:57:53 +0800655acpi_ps_link_module_code(union acpi_parse_object *parent_op,
656 u8 *aml_start, u32 aml_length, acpi_owner_id owner_id)
Lin Ming7f0c8262009-08-13 14:03:15 +0800657{
658 union acpi_operand_object *prev;
659 union acpi_operand_object *next;
660 union acpi_operand_object *method_obj;
Lin Ming9a884ab2009-11-12 09:57:53 +0800661 struct acpi_namespace_node *parent_node;
Lin Ming7f0c8262009-08-13 14:03:15 +0800662
663 /* Get the tail of the list */
664
665 prev = next = acpi_gbl_module_code_list;
666 while (next) {
667 prev = next;
668 next = next->method.mutex;
669 }
670
671 /*
672 * Insert the module level code into the list. Merge it if it is
673 * adjacent to the previous element.
674 */
675 if (!prev ||
676 ((prev->method.aml_start + prev->method.aml_length) != aml_start)) {
677
678 /* Create, initialize, and link a new temporary method object */
679
680 method_obj = acpi_ut_create_internal_object(ACPI_TYPE_METHOD);
681 if (!method_obj) {
682 return;
683 }
684
Lin Ming9a884ab2009-11-12 09:57:53 +0800685 if (parent_op->common.node) {
686 parent_node = parent_op->common.node;
687 } else {
688 parent_node = acpi_gbl_root_node;
689 }
690
Lin Ming7f0c8262009-08-13 14:03:15 +0800691 method_obj->method.aml_start = aml_start;
692 method_obj->method.aml_length = aml_length;
693 method_obj->method.owner_id = owner_id;
Lin Ming26294842011-01-12 09:19:43 +0800694 method_obj->method.info_flags |= ACPI_METHOD_MODULE_LEVEL;
Lin Ming7f0c8262009-08-13 14:03:15 +0800695
Lin Ming9a884ab2009-11-12 09:57:53 +0800696 /*
697 * Save the parent node in next_object. This is cheating, but we
698 * don't want to expand the method object.
699 */
700 method_obj->method.next_object =
701 ACPI_CAST_PTR(union acpi_operand_object, parent_node);
702
Lin Ming7f0c8262009-08-13 14:03:15 +0800703 if (!prev) {
704 acpi_gbl_module_code_list = method_obj;
705 } else {
706 prev->method.mutex = method_obj;
707 }
708 } else {
709 prev->method.aml_length += aml_length;
710 }
711}
712
713/*******************************************************************************
714 *
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300715 * FUNCTION: acpi_ps_complete_op
716 *
717 * PARAMETERS: walk_state - Current state
Bob Mooreba494be2012-07-12 09:40:10 +0800718 * op - Returned Op
719 * status - Parse status before complete Op
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300720 *
721 * RETURN: Status
722 *
723 * DESCRIPTION: Complete Op
724 *
725 ******************************************************************************/
726
727static acpi_status
728acpi_ps_complete_op(struct acpi_walk_state *walk_state,
729 union acpi_parse_object **op, acpi_status status)
730{
731 acpi_status status2;
732
733 ACPI_FUNCTION_TRACE_PTR(ps_complete_op, walk_state);
734
735 /*
736 * Finished one argument of the containing scope
737 */
738 walk_state->parser_state.scope->parse_scope.arg_count--;
739
740 /* Close this Op (will result in parse subtree deletion) */
741
742 status2 = acpi_ps_complete_this_op(walk_state, *op);
743 if (ACPI_FAILURE(status2)) {
744 return_ACPI_STATUS(status2);
745 }
746
747 *op = NULL;
748
749 switch (status) {
750 case AE_OK:
751 break;
752
753 case AE_CTRL_TRANSFER:
754
755 /* We are about to transfer to a called method */
756
757 walk_state->prev_op = NULL;
758 walk_state->prev_arg_types = walk_state->arg_types;
759 return_ACPI_STATUS(status);
760
761 case AE_CTRL_END:
762
763 acpi_ps_pop_scope(&(walk_state->parser_state), op,
764 &walk_state->arg_types,
765 &walk_state->arg_count);
766
767 if (*op) {
768 walk_state->op = *op;
769 walk_state->op_info =
770 acpi_ps_get_opcode_info((*op)->common.aml_opcode);
771 walk_state->opcode = (*op)->common.aml_opcode;
772
773 status = walk_state->ascending_callback(walk_state);
774 status =
775 acpi_ps_next_parse_state(walk_state, *op, status);
776
777 status2 = acpi_ps_complete_this_op(walk_state, *op);
778 if (ACPI_FAILURE(status2)) {
779 return_ACPI_STATUS(status2);
780 }
781 }
782
783 status = AE_OK;
784 break;
785
786 case AE_CTRL_BREAK:
787 case AE_CTRL_CONTINUE:
788
789 /* Pop off scopes until we find the While */
790
791 while (!(*op) || ((*op)->common.aml_opcode != AML_WHILE_OP)) {
792 acpi_ps_pop_scope(&(walk_state->parser_state), op,
793 &walk_state->arg_types,
794 &walk_state->arg_count);
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300795 }
796
797 /* Close this iteration of the While loop */
798
799 walk_state->op = *op;
800 walk_state->op_info =
801 acpi_ps_get_opcode_info((*op)->common.aml_opcode);
802 walk_state->opcode = (*op)->common.aml_opcode;
803
804 status = walk_state->ascending_callback(walk_state);
805 status = acpi_ps_next_parse_state(walk_state, *op, status);
806
807 status2 = acpi_ps_complete_this_op(walk_state, *op);
808 if (ACPI_FAILURE(status2)) {
809 return_ACPI_STATUS(status2);
810 }
811
812 status = AE_OK;
813 break;
814
815 case AE_CTRL_TERMINATE:
816
817 /* Clean up */
818 do {
819 if (*op) {
820 status2 =
821 acpi_ps_complete_this_op(walk_state, *op);
822 if (ACPI_FAILURE(status2)) {
823 return_ACPI_STATUS(status2);
824 }
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300825
826 acpi_ut_delete_generic_state
827 (acpi_ut_pop_generic_state
828 (&walk_state->control_state));
829 }
830
831 acpi_ps_pop_scope(&(walk_state->parser_state), op,
832 &walk_state->arg_types,
833 &walk_state->arg_count);
834
835 } while (*op);
836
837 return_ACPI_STATUS(AE_OK);
838
839 default: /* All other non-AE_OK status */
840
841 do {
842 if (*op) {
843 status2 =
844 acpi_ps_complete_this_op(walk_state, *op);
845 if (ACPI_FAILURE(status2)) {
846 return_ACPI_STATUS(status2);
847 }
848 }
849
850 acpi_ps_pop_scope(&(walk_state->parser_state), op,
851 &walk_state->arg_types,
852 &walk_state->arg_count);
853
854 } while (*op);
855
856#if 0
857 /*
858 * TBD: Cleanup parse ops on error
859 */
860 if (*op == NULL) {
861 acpi_ps_pop_scope(parser_state, op,
862 &walk_state->arg_types,
863 &walk_state->arg_count);
864 }
865#endif
866 walk_state->prev_op = NULL;
867 walk_state->prev_arg_types = walk_state->arg_types;
868 return_ACPI_STATUS(status);
869 }
870
871 /* This scope complete? */
872
873 if (acpi_ps_has_completed_scope(&(walk_state->parser_state))) {
874 acpi_ps_pop_scope(&(walk_state->parser_state), op,
875 &walk_state->arg_types,
876 &walk_state->arg_count);
877 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Popped scope, Op=%p\n", *op));
878 } else {
879 *op = NULL;
880 }
881
882 return_ACPI_STATUS(AE_OK);
883}
884
885/*******************************************************************************
886 *
887 * FUNCTION: acpi_ps_complete_final_op
888 *
889 * PARAMETERS: walk_state - Current state
Bob Mooreba494be2012-07-12 09:40:10 +0800890 * op - Current Op
891 * status - Current parse status before complete last
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +0300892 * Op
893 *
894 * RETURN: Status
895 *
896 * DESCRIPTION: Complete last Op.
897 *
898 ******************************************************************************/
899
900static acpi_status
901acpi_ps_complete_final_op(struct acpi_walk_state *walk_state,
902 union acpi_parse_object *op, acpi_status status)
903{
904 acpi_status status2;
905
906 ACPI_FUNCTION_TRACE_PTR(ps_complete_final_op, walk_state);
907
908 /*
909 * Complete the last Op (if not completed), and clear the scope stack.
910 * It is easily possible to end an AML "package" with an unbounded number
911 * of open scopes (such as when several ASL blocks are closed with
912 * sequential closing braces). We want to terminate each one cleanly.
913 */
914 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "AML package complete at Op %p\n",
915 op));
916 do {
917 if (op) {
918 if (walk_state->ascending_callback != NULL) {
919 walk_state->op = op;
920 walk_state->op_info =
921 acpi_ps_get_opcode_info(op->common.
922 aml_opcode);
923 walk_state->opcode = op->common.aml_opcode;
924
925 status =
926 walk_state->ascending_callback(walk_state);
927 status =
928 acpi_ps_next_parse_state(walk_state, op,
929 status);
930 if (status == AE_CTRL_PENDING) {
931 status =
932 acpi_ps_complete_op(walk_state, &op,
933 AE_OK);
934 if (ACPI_FAILURE(status)) {
935 return_ACPI_STATUS(status);
936 }
937 }
938
939 if (status == AE_CTRL_TERMINATE) {
940 status = AE_OK;
941
942 /* Clean up */
943 do {
944 if (op) {
945 status2 =
946 acpi_ps_complete_this_op
947 (walk_state, op);
948 if (ACPI_FAILURE
949 (status2)) {
950 return_ACPI_STATUS
951 (status2);
952 }
953 }
954
955 acpi_ps_pop_scope(&
956 (walk_state->
957 parser_state),
958 &op,
959 &walk_state->
960 arg_types,
961 &walk_state->
962 arg_count);
963
964 } while (op);
965
966 return_ACPI_STATUS(status);
967 }
968
969 else if (ACPI_FAILURE(status)) {
970
971 /* First error is most important */
972
973 (void)
974 acpi_ps_complete_this_op(walk_state,
975 op);
976 return_ACPI_STATUS(status);
977 }
978 }
979
980 status2 = acpi_ps_complete_this_op(walk_state, op);
981 if (ACPI_FAILURE(status2)) {
982 return_ACPI_STATUS(status2);
983 }
984 }
985
986 acpi_ps_pop_scope(&(walk_state->parser_state), &op,
987 &walk_state->arg_types,
988 &walk_state->arg_count);
989
990 } while (op);
991
992 return_ACPI_STATUS(status);
993}
994
Robert Moore73459f72005-06-24 00:00:00 -0400995/*******************************************************************************
996 *
997 * FUNCTION: acpi_ps_parse_loop
998 *
999 * PARAMETERS: walk_state - Current state
1000 *
1001 * RETURN: Status
1002 *
1003 * DESCRIPTION: Parse AML (pointed to by the current parser state) and return
1004 * a tree of ops.
1005 *
1006 ******************************************************************************/
1007
Len Brown4be44fc2005-08-05 00:44:28 -04001008acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state)
Robert Moore73459f72005-06-24 00:00:00 -04001009{
Len Brown4be44fc2005-08-05 00:44:28 -04001010 acpi_status status = AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -04001011 union acpi_parse_object *op = NULL; /* current op */
Len Brown4be44fc2005-08-05 00:44:28 -04001012 struct acpi_parse_state *parser_state;
1013 u8 *aml_op_start = NULL;
Robert Moore73459f72005-06-24 00:00:00 -04001014
Bob Mooreb229cf92006-04-21 17:15:00 -04001015 ACPI_FUNCTION_TRACE_PTR(ps_parse_loop, walk_state);
Robert Moore73459f72005-06-24 00:00:00 -04001016
1017 if (walk_state->descending_callback == NULL) {
Len Brown4be44fc2005-08-05 00:44:28 -04001018 return_ACPI_STATUS(AE_BAD_PARAMETER);
Robert Moore73459f72005-06-24 00:00:00 -04001019 }
1020
1021 parser_state = &walk_state->parser_state;
1022 walk_state->arg_types = 0;
1023
1024#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
1025
1026 if (walk_state->walk_type & ACPI_WALK_METHOD_RESTART) {
Bob Moore52fc0b02006-10-02 00:00:00 -04001027
Robert Moore73459f72005-06-24 00:00:00 -04001028 /* We are restarting a preempted control method */
1029
Len Brown4be44fc2005-08-05 00:44:28 -04001030 if (acpi_ps_has_completed_scope(parser_state)) {
Robert Moore73459f72005-06-24 00:00:00 -04001031 /*
1032 * We must check if a predicate to an IF or WHILE statement
1033 * was just completed
1034 */
1035 if ((parser_state->scope->parse_scope.op) &&
Len Brown4be44fc2005-08-05 00:44:28 -04001036 ((parser_state->scope->parse_scope.op->common.
1037 aml_opcode == AML_IF_OP)
1038 || (parser_state->scope->parse_scope.op->common.
1039 aml_opcode == AML_WHILE_OP))
1040 && (walk_state->control_state)
1041 && (walk_state->control_state->common.state ==
1042 ACPI_CONTROL_PREDICATE_EXECUTING)) {
Robert Moore73459f72005-06-24 00:00:00 -04001043 /*
1044 * A predicate was just completed, get the value of the
1045 * predicate and branch based on that value
1046 */
1047 walk_state->op = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001048 status =
1049 acpi_ds_get_predicate_value(walk_state,
1050 ACPI_TO_POINTER
1051 (TRUE));
1052 if (ACPI_FAILURE(status)
1053 && ((status & AE_CODE_MASK) !=
1054 AE_CODE_CONTROL)) {
Robert Moore73459f72005-06-24 00:00:00 -04001055 if (status == AE_AML_NO_RETURN_VALUE) {
Bob Mooreb8e4d892006-01-27 16:43:00 -05001056 ACPI_EXCEPTION((AE_INFO, status,
1057 "Invoked method did not return a value"));
Robert Moore73459f72005-06-24 00:00:00 -04001058 }
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +03001059
Bob Mooreb8e4d892006-01-27 16:43:00 -05001060 ACPI_EXCEPTION((AE_INFO, status,
Bob Mooreb229cf92006-04-21 17:15:00 -04001061 "GetPredicate Failed"));
Len Brown4be44fc2005-08-05 00:44:28 -04001062 return_ACPI_STATUS(status);
Robert Moore73459f72005-06-24 00:00:00 -04001063 }
1064
Len Brown4be44fc2005-08-05 00:44:28 -04001065 status =
1066 acpi_ps_next_parse_state(walk_state, op,
1067 status);
Robert Moore73459f72005-06-24 00:00:00 -04001068 }
1069
Len Brown4be44fc2005-08-05 00:44:28 -04001070 acpi_ps_pop_scope(parser_state, &op,
1071 &walk_state->arg_types,
1072 &walk_state->arg_count);
1073 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
1074 "Popped scope, Op=%p\n", op));
1075 } else if (walk_state->prev_op) {
Bob Moore52fc0b02006-10-02 00:00:00 -04001076
Robert Moore73459f72005-06-24 00:00:00 -04001077 /* We were in the middle of an op */
1078
1079 op = walk_state->prev_op;
1080 walk_state->arg_types = walk_state->prev_arg_types;
1081 }
1082 }
1083#endif
1084
1085 /* Iterative parsing loop, while there is more AML to process: */
1086
1087 while ((parser_state->aml < parser_state->aml_end) || (op)) {
1088 aml_op_start = parser_state->aml;
1089 if (!op) {
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +03001090 status =
1091 acpi_ps_create_op(walk_state, aml_op_start, &op);
1092 if (ACPI_FAILURE(status)) {
1093 if (status == AE_CTRL_PARSE_CONTINUE) {
Robert Moore73459f72005-06-24 00:00:00 -04001094 continue;
1095 }
1096
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +03001097 if (status == AE_CTRL_PARSE_PENDING) {
Robert Moore73459f72005-06-24 00:00:00 -04001098 status = AE_OK;
Robert Moore73459f72005-06-24 00:00:00 -04001099 }
1100
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +03001101 status =
1102 acpi_ps_complete_op(walk_state, &op,
1103 status);
Len Brown4be44fc2005-08-05 00:44:28 -04001104 if (ACPI_FAILURE(status)) {
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +03001105 return_ACPI_STATUS(status);
Robert Moore73459f72005-06-24 00:00:00 -04001106 }
1107
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +03001108 continue;
Robert Moore73459f72005-06-24 00:00:00 -04001109 }
1110
1111 op->common.aml_offset = walk_state->aml_offset;
1112
1113 if (walk_state->op_info) {
Len Brown4be44fc2005-08-05 00:44:28 -04001114 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
Bob Mooreb229cf92006-04-21 17:15:00 -04001115 "Opcode %4.4X [%s] Op %p Aml %p AmlOffset %5.5X\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001116 (u32) op->common.aml_opcode,
1117 walk_state->op_info->name, op,
1118 parser_state->aml,
1119 op->common.aml_offset));
Robert Moore73459f72005-06-24 00:00:00 -04001120 }
1121 }
1122
Robert Moore73459f72005-06-24 00:00:00 -04001123 /*
1124 * Start arg_count at zero because we don't know if there are
1125 * any args yet
1126 */
1127 walk_state->arg_count = 0;
1128
1129 /* Are there any arguments that must be processed? */
1130
1131 if (walk_state->arg_types) {
Bob Moore52fc0b02006-10-02 00:00:00 -04001132
Robert Moore73459f72005-06-24 00:00:00 -04001133 /* Get arguments */
1134
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +03001135 status =
1136 acpi_ps_get_arguments(walk_state, aml_op_start, op);
1137 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001138 status =
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +03001139 acpi_ps_complete_op(walk_state, &op,
1140 status);
Len Brown4be44fc2005-08-05 00:44:28 -04001141 if (ACPI_FAILURE(status)) {
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +03001142 return_ACPI_STATUS(status);
Robert Moore73459f72005-06-24 00:00:00 -04001143 }
1144
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +03001145 continue;
Robert Moore73459f72005-06-24 00:00:00 -04001146 }
1147 }
1148
1149 /* Check for arguments that need to be processed */
1150
1151 if (walk_state->arg_count) {
1152 /*
1153 * There are arguments (complex ones), push Op and
1154 * prepare for argument
1155 */
Len Brown4be44fc2005-08-05 00:44:28 -04001156 status = acpi_ps_push_scope(parser_state, op,
1157 walk_state->arg_types,
1158 walk_state->arg_count);
1159 if (ACPI_FAILURE(status)) {
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +03001160 status =
1161 acpi_ps_complete_op(walk_state, &op,
1162 status);
1163 if (ACPI_FAILURE(status)) {
1164 return_ACPI_STATUS(status);
1165 }
1166
1167 continue;
Robert Moore73459f72005-06-24 00:00:00 -04001168 }
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +03001169
Robert Moore73459f72005-06-24 00:00:00 -04001170 op = NULL;
1171 continue;
1172 }
1173
1174 /*
1175 * All arguments have been processed -- Op is complete,
1176 * prepare for next
1177 */
Len Brown4be44fc2005-08-05 00:44:28 -04001178 walk_state->op_info =
1179 acpi_ps_get_opcode_info(op->common.aml_opcode);
Robert Moore73459f72005-06-24 00:00:00 -04001180 if (walk_state->op_info->flags & AML_NAMED) {
1181 if (acpi_gbl_depth) {
1182 acpi_gbl_depth--;
1183 }
1184
Lin Ming941f48b2008-04-10 19:06:41 +04001185 if (op->common.aml_opcode == AML_REGION_OP ||
1186 op->common.aml_opcode == AML_DATA_REGION_OP) {
Robert Moore73459f72005-06-24 00:00:00 -04001187 /*
1188 * Skip parsing of control method or opregion body,
1189 * because we don't have enough info in the first pass
1190 * to parse them correctly.
1191 *
1192 * Completed parsing an op_region declaration, we now
1193 * know the length.
1194 */
Len Brown4be44fc2005-08-05 00:44:28 -04001195 op->named.length =
1196 (u32) (parser_state->aml - op->named.data);
Robert Moore73459f72005-06-24 00:00:00 -04001197 }
1198 }
1199
1200 if (walk_state->op_info->flags & AML_CREATE) {
1201 /*
Bob Mooreba494be2012-07-12 09:40:10 +08001202 * Backup to beginning of create_XXXfield declaration (1 for
Robert Moore73459f72005-06-24 00:00:00 -04001203 * Opcode)
1204 *
1205 * body_length is unknown until we parse the body
1206 */
Len Brown4be44fc2005-08-05 00:44:28 -04001207 op->named.length =
1208 (u32) (parser_state->aml - op->named.data);
Robert Moore73459f72005-06-24 00:00:00 -04001209 }
1210
Lin Mingef805d92008-04-10 19:06:41 +04001211 if (op->common.aml_opcode == AML_BANK_FIELD_OP) {
1212 /*
1213 * Backup to beginning of bank_field declaration
1214 *
1215 * body_length is unknown until we parse the body
1216 */
1217 op->named.length =
1218 (u32) (parser_state->aml - op->named.data);
1219 }
1220
Robert Moore73459f72005-06-24 00:00:00 -04001221 /* This op complete, notify the dispatcher */
1222
1223 if (walk_state->ascending_callback != NULL) {
Len Brown4be44fc2005-08-05 00:44:28 -04001224 walk_state->op = op;
Robert Moore73459f72005-06-24 00:00:00 -04001225 walk_state->opcode = op->common.aml_opcode;
1226
Len Brown4be44fc2005-08-05 00:44:28 -04001227 status = walk_state->ascending_callback(walk_state);
1228 status =
1229 acpi_ps_next_parse_state(walk_state, op, status);
Robert Moore73459f72005-06-24 00:00:00 -04001230 if (status == AE_CTRL_PENDING) {
1231 status = AE_OK;
Robert Moore73459f72005-06-24 00:00:00 -04001232 }
1233 }
1234
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +03001235 status = acpi_ps_complete_op(walk_state, &op, status);
1236 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001237 return_ACPI_STATUS(status);
Robert Moore73459f72005-06-24 00:00:00 -04001238 }
1239
Len Brown4be44fc2005-08-05 00:44:28 -04001240 } /* while parser_state->Aml */
Robert Moore73459f72005-06-24 00:00:00 -04001241
Mikhail Kouzmich4d0b4af2007-02-02 19:48:21 +03001242 status = acpi_ps_complete_final_op(walk_state, op, status);
Len Brown4be44fc2005-08-05 00:44:28 -04001243 return_ACPI_STATUS(status);
Robert Moore73459f72005-06-24 00:00:00 -04001244}