1 /******************************************************************************
3 * Module Name: psloop - Main AML parse loop
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2008, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
45 * 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[].
52 #include <acpi/acpi.h>
58 #define _COMPONENT ACPI_PARSER
59 ACPI_MODULE_NAME("psloop")
61 static u32 acpi_gbl_depth = 0;
63 /* Local prototypes */
65 static acpi_status acpi_ps_get_aml_opcode(struct acpi_walk_state *walk_state);
68 acpi_ps_build_named_op(struct acpi_walk_state *walk_state,
70 union acpi_parse_object *unnamed_op,
71 union acpi_parse_object **op);
74 acpi_ps_create_op(struct acpi_walk_state *walk_state,
75 u8 * aml_op_start, union acpi_parse_object **new_op);
78 acpi_ps_get_arguments(struct acpi_walk_state *walk_state,
79 u8 * aml_op_start, union acpi_parse_object *op);
82 acpi_ps_complete_op(struct acpi_walk_state *walk_state,
83 union acpi_parse_object **op, acpi_status status);
86 acpi_ps_complete_final_op(struct acpi_walk_state *walk_state,
87 union acpi_parse_object *op, acpi_status status);
89 /*******************************************************************************
91 * FUNCTION: acpi_ps_get_aml_opcode
93 * PARAMETERS: walk_state - Current state
97 * DESCRIPTION: Extract the next AML opcode from the input stream.
99 ******************************************************************************/
101 static acpi_status acpi_ps_get_aml_opcode(struct acpi_walk_state *walk_state)
104 ACPI_FUNCTION_TRACE_PTR(ps_get_aml_opcode, walk_state);
106 walk_state->aml_offset =
107 (u32) ACPI_PTR_DIFF(walk_state->parser_state.aml,
108 walk_state->parser_state.aml_start);
109 walk_state->opcode = acpi_ps_peek_opcode(&(walk_state->parser_state));
112 * First cut to determine what we have found:
113 * 1) A valid AML opcode
115 * 3) An unknown/invalid opcode
117 walk_state->op_info = acpi_ps_get_opcode_info(walk_state->opcode);
119 switch (walk_state->op_info->class) {
120 case AML_CLASS_ASCII:
121 case AML_CLASS_PREFIX:
123 * Starts with a valid prefix or ASCII char, this is a name
124 * string. Convert the bare name string to a namepath.
126 walk_state->opcode = AML_INT_NAMEPATH_OP;
127 walk_state->arg_types = ARGP_NAMESTRING;
130 case AML_CLASS_UNKNOWN:
132 /* The opcode is unrecognized. Just skip unknown opcodes */
135 "Found unknown opcode %X at AML address %p offset %X, ignoring",
136 walk_state->opcode, walk_state->parser_state.aml,
137 walk_state->aml_offset));
139 ACPI_DUMP_BUFFER(walk_state->parser_state.aml, 128);
141 /* Assume one-byte bad opcode */
143 walk_state->parser_state.aml++;
144 return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE);
148 /* Found opcode info, this is a normal opcode */
150 walk_state->parser_state.aml +=
151 acpi_ps_get_opcode_size(walk_state->opcode);
152 walk_state->arg_types = walk_state->op_info->parse_args;
156 return_ACPI_STATUS(AE_OK);
159 /*******************************************************************************
161 * FUNCTION: acpi_ps_build_named_op
163 * PARAMETERS: walk_state - Current state
164 * aml_op_start - Begin of named Op in AML
165 * unnamed_op - Early Op (not a named Op)
170 * DESCRIPTION: Parse a named Op
172 ******************************************************************************/
175 acpi_ps_build_named_op(struct acpi_walk_state *walk_state,
177 union acpi_parse_object *unnamed_op,
178 union acpi_parse_object **op)
180 acpi_status status = AE_OK;
181 union acpi_parse_object *arg = NULL;
183 ACPI_FUNCTION_TRACE_PTR(ps_build_named_op, walk_state);
185 unnamed_op->common.value.arg = NULL;
186 unnamed_op->common.arg_list_length = 0;
187 unnamed_op->common.aml_opcode = walk_state->opcode;
190 * Get and append arguments until we find the node that contains
191 * the name (the type ARGP_NAME).
193 while (GET_CURRENT_ARG_TYPE(walk_state->arg_types) &&
194 (GET_CURRENT_ARG_TYPE(walk_state->arg_types) != ARGP_NAME)) {
196 acpi_ps_get_next_arg(walk_state,
197 &(walk_state->parser_state),
198 GET_CURRENT_ARG_TYPE(walk_state->
200 if (ACPI_FAILURE(status)) {
201 return_ACPI_STATUS(status);
204 acpi_ps_append_arg(unnamed_op, arg);
205 INCREMENT_ARG_LIST(walk_state->arg_types);
209 * Make sure that we found a NAME and didn't run out of arguments
211 if (!GET_CURRENT_ARG_TYPE(walk_state->arg_types)) {
212 return_ACPI_STATUS(AE_AML_NO_OPERAND);
215 /* We know that this arg is a name, move to next arg */
217 INCREMENT_ARG_LIST(walk_state->arg_types);
220 * Find the object. This will either insert the object into
221 * the namespace or simply look it up
223 walk_state->op = NULL;
225 status = walk_state->descending_callback(walk_state, op);
226 if (ACPI_FAILURE(status)) {
227 ACPI_EXCEPTION((AE_INFO, status, "During name lookup/catalog"));
228 return_ACPI_STATUS(status);
232 return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE);
235 status = acpi_ps_next_parse_state(walk_state, *op, status);
236 if (ACPI_FAILURE(status)) {
237 if (status == AE_CTRL_PENDING) {
238 return_ACPI_STATUS(AE_CTRL_PARSE_PENDING);
240 return_ACPI_STATUS(status);
243 acpi_ps_append_arg(*op, unnamed_op->common.value.arg);
246 if ((*op)->common.aml_opcode == AML_REGION_OP ||
247 (*op)->common.aml_opcode == AML_DATA_REGION_OP) {
249 * Defer final parsing of an operation_region body, because we don't
250 * have enough info in the first pass to parse it correctly (i.e.,
251 * there may be method calls within the term_arg elements of the body.)
253 * However, we must continue parsing because the opregion is not a
254 * standalone package -- we don't know where the end is at this point.
256 * (Length is unknown until parse of the body complete)
258 (*op)->named.data = aml_op_start;
259 (*op)->named.length = 0;
262 return_ACPI_STATUS(AE_OK);
265 /*******************************************************************************
267 * FUNCTION: acpi_ps_create_op
269 * PARAMETERS: walk_state - Current state
270 * aml_op_start - Op start in AML
271 * new_op - Returned Op
275 * DESCRIPTION: Get Op from AML
277 ******************************************************************************/
280 acpi_ps_create_op(struct acpi_walk_state *walk_state,
281 u8 * aml_op_start, union acpi_parse_object **new_op)
283 acpi_status status = AE_OK;
284 union acpi_parse_object *op;
285 union acpi_parse_object *named_op = NULL;
286 union acpi_parse_object *parent_scope;
288 const struct acpi_opcode_info *op_info;
290 ACPI_FUNCTION_TRACE_PTR(ps_create_op, walk_state);
292 status = acpi_ps_get_aml_opcode(walk_state);
293 if (status == AE_CTRL_PARSE_CONTINUE) {
294 return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE);
297 /* Create Op structure and append to parent's argument list */
299 walk_state->op_info = acpi_ps_get_opcode_info(walk_state->opcode);
300 op = acpi_ps_alloc_op(walk_state->opcode);
302 return_ACPI_STATUS(AE_NO_MEMORY);
305 if (walk_state->op_info->flags & AML_NAMED) {
307 acpi_ps_build_named_op(walk_state, aml_op_start, op,
310 if (ACPI_FAILURE(status)) {
311 return_ACPI_STATUS(status);
315 return_ACPI_STATUS(AE_OK);
318 /* Not a named opcode, just allocate Op and append to parent */
320 if (walk_state->op_info->flags & AML_CREATE) {
322 * Backup to beginning of create_xXXfield declaration
323 * body_length is unknown until we parse the body
325 op->named.data = aml_op_start;
326 op->named.length = 0;
329 if (walk_state->opcode == AML_BANK_FIELD_OP) {
331 * Backup to beginning of bank_field declaration
332 * body_length is unknown until we parse the body
334 op->named.data = aml_op_start;
335 op->named.length = 0;
338 parent_scope = acpi_ps_get_parent_scope(&(walk_state->parser_state));
339 acpi_ps_append_arg(parent_scope, op);
343 acpi_ps_get_opcode_info(parent_scope->common.aml_opcode);
344 if (op_info->flags & AML_HAS_TARGET) {
346 acpi_ps_get_argument_count(op_info->type);
347 if (parent_scope->common.arg_list_length >
349 op->common.flags |= ACPI_PARSEOP_TARGET;
351 } else if (parent_scope->common.aml_opcode == AML_INCREMENT_OP) {
352 op->common.flags |= ACPI_PARSEOP_TARGET;
356 if (walk_state->descending_callback != NULL) {
358 * Find the object. This will either insert the object into
359 * the namespace or simply look it up
361 walk_state->op = *new_op = op;
363 status = walk_state->descending_callback(walk_state, &op);
364 status = acpi_ps_next_parse_state(walk_state, op, status);
365 if (status == AE_CTRL_PENDING) {
366 status = AE_CTRL_PARSE_PENDING;
370 return_ACPI_STATUS(status);
373 /*******************************************************************************
375 * FUNCTION: acpi_ps_get_arguments
377 * PARAMETERS: walk_state - Current state
378 * aml_op_start - Op start in AML
383 * DESCRIPTION: Get arguments for passed Op.
385 ******************************************************************************/
388 acpi_ps_get_arguments(struct acpi_walk_state *walk_state,
389 u8 * aml_op_start, union acpi_parse_object *op)
391 acpi_status status = AE_OK;
392 union acpi_parse_object *arg = NULL;
394 ACPI_FUNCTION_TRACE_PTR(ps_get_arguments, walk_state);
396 switch (op->common.aml_opcode) {
397 case AML_BYTE_OP: /* AML_BYTEDATA_ARG */
398 case AML_WORD_OP: /* AML_WORDDATA_ARG */
399 case AML_DWORD_OP: /* AML_DWORDATA_ARG */
400 case AML_QWORD_OP: /* AML_QWORDATA_ARG */
401 case AML_STRING_OP: /* AML_ASCIICHARLIST_ARG */
403 /* Fill in constant or string argument directly */
405 acpi_ps_get_next_simple_arg(&(walk_state->parser_state),
406 GET_CURRENT_ARG_TYPE(walk_state->
411 case AML_INT_NAMEPATH_OP: /* AML_NAMESTRING_ARG */
414 acpi_ps_get_next_namepath(walk_state,
415 &(walk_state->parser_state), op,
417 if (ACPI_FAILURE(status)) {
418 return_ACPI_STATUS(status);
421 walk_state->arg_types = 0;
426 * Op is not a constant or string, append each argument to the Op
428 while (GET_CURRENT_ARG_TYPE(walk_state->arg_types)
429 && !walk_state->arg_count) {
430 walk_state->aml_offset =
431 (u32) ACPI_PTR_DIFF(walk_state->parser_state.aml,
432 walk_state->parser_state.
436 acpi_ps_get_next_arg(walk_state,
437 &(walk_state->parser_state),
439 (walk_state->arg_types), &arg);
440 if (ACPI_FAILURE(status)) {
441 return_ACPI_STATUS(status);
445 arg->common.aml_offset = walk_state->aml_offset;
446 acpi_ps_append_arg(op, arg);
449 INCREMENT_ARG_LIST(walk_state->arg_types);
452 /* Special processing for certain opcodes */
454 /* TBD (remove): Temporary mechanism to disable this code if needed */
456 #ifdef ACPI_ENABLE_MODULE_LEVEL_CODE
458 if ((walk_state->pass_number <= ACPI_IMODE_LOAD_PASS1) &&
459 ((walk_state->parse_flags & ACPI_PARSE_DISASSEMBLE) == 0)) {
461 * We want to skip If/Else/While constructs during Pass1 because we
462 * want to actually conditionally execute the code during Pass2.
464 * Except for disassembly, where we always want to walk the
465 * If/Else/While packages
467 switch (op->common.aml_opcode) {
472 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
473 "Pass1: Skipping an If/Else/While body\n"));
475 /* Skip body of if/else/while in pass 1 */
477 walk_state->parser_state.aml =
478 walk_state->parser_state.pkg_end;
479 walk_state->arg_count = 0;
488 switch (op->common.aml_opcode) {
491 * Skip parsing of control method because we don't have enough
492 * info in the first pass to parse it correctly.
494 * Save the length and address of the body
496 op->named.data = walk_state->parser_state.aml;
497 op->named.length = (u32)
498 (walk_state->parser_state.pkg_end -
499 walk_state->parser_state.aml);
501 /* Skip body of method */
503 walk_state->parser_state.aml =
504 walk_state->parser_state.pkg_end;
505 walk_state->arg_count = 0;
510 case AML_VAR_PACKAGE_OP:
512 if ((op->common.parent) &&
513 (op->common.parent->common.aml_opcode ==
515 && (walk_state->pass_number <=
516 ACPI_IMODE_LOAD_PASS2)) {
518 * Skip parsing of Buffers and Packages because we don't have
519 * enough info in the first pass to parse them correctly.
521 op->named.data = aml_op_start;
522 op->named.length = (u32)
523 (walk_state->parser_state.pkg_end -
528 walk_state->parser_state.aml =
529 walk_state->parser_state.pkg_end;
530 walk_state->arg_count = 0;
536 if (walk_state->control_state) {
537 walk_state->control_state->control.package_end =
538 walk_state->parser_state.pkg_end;
544 /* No action for all other opcodes */
551 return_ACPI_STATUS(AE_OK);
554 /*******************************************************************************
556 * FUNCTION: acpi_ps_complete_op
558 * PARAMETERS: walk_state - Current state
560 * Status - Parse status before complete Op
564 * DESCRIPTION: Complete Op
566 ******************************************************************************/
569 acpi_ps_complete_op(struct acpi_walk_state *walk_state,
570 union acpi_parse_object **op, acpi_status status)
574 ACPI_FUNCTION_TRACE_PTR(ps_complete_op, walk_state);
577 * Finished one argument of the containing scope
579 walk_state->parser_state.scope->parse_scope.arg_count--;
581 /* Close this Op (will result in parse subtree deletion) */
583 status2 = acpi_ps_complete_this_op(walk_state, *op);
584 if (ACPI_FAILURE(status2)) {
585 return_ACPI_STATUS(status2);
594 case AE_CTRL_TRANSFER:
596 /* We are about to transfer to a called method */
598 walk_state->prev_op = NULL;
599 walk_state->prev_arg_types = walk_state->arg_types;
600 return_ACPI_STATUS(status);
604 acpi_ps_pop_scope(&(walk_state->parser_state), op,
605 &walk_state->arg_types,
606 &walk_state->arg_count);
609 walk_state->op = *op;
610 walk_state->op_info =
611 acpi_ps_get_opcode_info((*op)->common.aml_opcode);
612 walk_state->opcode = (*op)->common.aml_opcode;
614 status = walk_state->ascending_callback(walk_state);
616 acpi_ps_next_parse_state(walk_state, *op, status);
618 status2 = acpi_ps_complete_this_op(walk_state, *op);
619 if (ACPI_FAILURE(status2)) {
620 return_ACPI_STATUS(status2);
628 case AE_CTRL_CONTINUE:
630 /* Pop off scopes until we find the While */
632 while (!(*op) || ((*op)->common.aml_opcode != AML_WHILE_OP)) {
633 acpi_ps_pop_scope(&(walk_state->parser_state), op,
634 &walk_state->arg_types,
635 &walk_state->arg_count);
638 /* Close this iteration of the While loop */
640 walk_state->op = *op;
641 walk_state->op_info =
642 acpi_ps_get_opcode_info((*op)->common.aml_opcode);
643 walk_state->opcode = (*op)->common.aml_opcode;
645 status = walk_state->ascending_callback(walk_state);
646 status = acpi_ps_next_parse_state(walk_state, *op, status);
648 status2 = acpi_ps_complete_this_op(walk_state, *op);
649 if (ACPI_FAILURE(status2)) {
650 return_ACPI_STATUS(status2);
656 case AE_CTRL_TERMINATE:
662 acpi_ps_complete_this_op(walk_state, *op);
663 if (ACPI_FAILURE(status2)) {
664 return_ACPI_STATUS(status2);
667 acpi_ut_delete_generic_state
668 (acpi_ut_pop_generic_state
669 (&walk_state->control_state));
672 acpi_ps_pop_scope(&(walk_state->parser_state), op,
673 &walk_state->arg_types,
674 &walk_state->arg_count);
678 return_ACPI_STATUS(AE_OK);
680 default: /* All other non-AE_OK status */
685 acpi_ps_complete_this_op(walk_state, *op);
686 if (ACPI_FAILURE(status2)) {
687 return_ACPI_STATUS(status2);
691 acpi_ps_pop_scope(&(walk_state->parser_state), op,
692 &walk_state->arg_types,
693 &walk_state->arg_count);
699 * TBD: Cleanup parse ops on error
702 acpi_ps_pop_scope(parser_state, op,
703 &walk_state->arg_types,
704 &walk_state->arg_count);
707 walk_state->prev_op = NULL;
708 walk_state->prev_arg_types = walk_state->arg_types;
709 return_ACPI_STATUS(status);
712 /* This scope complete? */
714 if (acpi_ps_has_completed_scope(&(walk_state->parser_state))) {
715 acpi_ps_pop_scope(&(walk_state->parser_state), op,
716 &walk_state->arg_types,
717 &walk_state->arg_count);
718 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Popped scope, Op=%p\n", *op));
723 ACPI_PREEMPTION_POINT();
725 return_ACPI_STATUS(AE_OK);
728 /*******************************************************************************
730 * FUNCTION: acpi_ps_complete_final_op
732 * PARAMETERS: walk_state - Current state
734 * Status - Current parse status before complete last
739 * DESCRIPTION: Complete last Op.
741 ******************************************************************************/
744 acpi_ps_complete_final_op(struct acpi_walk_state *walk_state,
745 union acpi_parse_object *op, acpi_status status)
749 ACPI_FUNCTION_TRACE_PTR(ps_complete_final_op, walk_state);
752 * Complete the last Op (if not completed), and clear the scope stack.
753 * It is easily possible to end an AML "package" with an unbounded number
754 * of open scopes (such as when several ASL blocks are closed with
755 * sequential closing braces). We want to terminate each one cleanly.
757 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "AML package complete at Op %p\n",
761 if (walk_state->ascending_callback != NULL) {
763 walk_state->op_info =
764 acpi_ps_get_opcode_info(op->common.
766 walk_state->opcode = op->common.aml_opcode;
769 walk_state->ascending_callback(walk_state);
771 acpi_ps_next_parse_state(walk_state, op,
773 if (status == AE_CTRL_PENDING) {
775 acpi_ps_complete_op(walk_state, &op,
777 if (ACPI_FAILURE(status)) {
778 return_ACPI_STATUS(status);
782 if (status == AE_CTRL_TERMINATE) {
789 acpi_ps_complete_this_op
809 return_ACPI_STATUS(status);
812 else if (ACPI_FAILURE(status)) {
814 /* First error is most important */
817 acpi_ps_complete_this_op(walk_state,
819 return_ACPI_STATUS(status);
823 status2 = acpi_ps_complete_this_op(walk_state, op);
824 if (ACPI_FAILURE(status2)) {
825 return_ACPI_STATUS(status2);
829 acpi_ps_pop_scope(&(walk_state->parser_state), &op,
830 &walk_state->arg_types,
831 &walk_state->arg_count);
835 return_ACPI_STATUS(status);
838 /*******************************************************************************
840 * FUNCTION: acpi_ps_parse_loop
842 * PARAMETERS: walk_state - Current state
846 * DESCRIPTION: Parse AML (pointed to by the current parser state) and return
849 ******************************************************************************/
851 acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state)
853 acpi_status status = AE_OK;
854 union acpi_parse_object *op = NULL; /* current op */
855 struct acpi_parse_state *parser_state;
856 u8 *aml_op_start = NULL;
858 ACPI_FUNCTION_TRACE_PTR(ps_parse_loop, walk_state);
860 if (walk_state->descending_callback == NULL) {
861 return_ACPI_STATUS(AE_BAD_PARAMETER);
864 parser_state = &walk_state->parser_state;
865 walk_state->arg_types = 0;
867 #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
869 if (walk_state->walk_type & ACPI_WALK_METHOD_RESTART) {
871 /* We are restarting a preempted control method */
873 if (acpi_ps_has_completed_scope(parser_state)) {
875 * We must check if a predicate to an IF or WHILE statement
878 if ((parser_state->scope->parse_scope.op) &&
879 ((parser_state->scope->parse_scope.op->common.
880 aml_opcode == AML_IF_OP)
881 || (parser_state->scope->parse_scope.op->common.
882 aml_opcode == AML_WHILE_OP))
883 && (walk_state->control_state)
884 && (walk_state->control_state->common.state ==
885 ACPI_CONTROL_PREDICATE_EXECUTING)) {
887 * A predicate was just completed, get the value of the
888 * predicate and branch based on that value
890 walk_state->op = NULL;
892 acpi_ds_get_predicate_value(walk_state,
895 if (ACPI_FAILURE(status)
896 && ((status & AE_CODE_MASK) !=
898 if (status == AE_AML_NO_RETURN_VALUE) {
899 ACPI_EXCEPTION((AE_INFO, status,
900 "Invoked method did not return a value"));
904 ACPI_EXCEPTION((AE_INFO, status,
905 "GetPredicate Failed"));
906 return_ACPI_STATUS(status);
910 acpi_ps_next_parse_state(walk_state, op,
914 acpi_ps_pop_scope(parser_state, &op,
915 &walk_state->arg_types,
916 &walk_state->arg_count);
917 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
918 "Popped scope, Op=%p\n", op));
919 } else if (walk_state->prev_op) {
921 /* We were in the middle of an op */
923 op = walk_state->prev_op;
924 walk_state->arg_types = walk_state->prev_arg_types;
929 /* Iterative parsing loop, while there is more AML to process: */
931 while ((parser_state->aml < parser_state->aml_end) || (op)) {
932 aml_op_start = parser_state->aml;
935 acpi_ps_create_op(walk_state, aml_op_start, &op);
936 if (ACPI_FAILURE(status)) {
937 if (status == AE_CTRL_PARSE_CONTINUE) {
941 if (status == AE_CTRL_PARSE_PENDING) {
946 acpi_ps_complete_op(walk_state, &op,
948 if (ACPI_FAILURE(status)) {
949 return_ACPI_STATUS(status);
955 op->common.aml_offset = walk_state->aml_offset;
957 if (walk_state->op_info) {
958 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
959 "Opcode %4.4X [%s] Op %p Aml %p AmlOffset %5.5X\n",
960 (u32) op->common.aml_opcode,
961 walk_state->op_info->name, op,
963 op->common.aml_offset));
968 * Start arg_count at zero because we don't know if there are
971 walk_state->arg_count = 0;
973 /* Are there any arguments that must be processed? */
975 if (walk_state->arg_types) {
980 acpi_ps_get_arguments(walk_state, aml_op_start, op);
981 if (ACPI_FAILURE(status)) {
983 acpi_ps_complete_op(walk_state, &op,
985 if (ACPI_FAILURE(status)) {
986 return_ACPI_STATUS(status);
993 /* Check for arguments that need to be processed */
995 if (walk_state->arg_count) {
997 * There are arguments (complex ones), push Op and
998 * prepare for argument
1000 status = acpi_ps_push_scope(parser_state, op,
1001 walk_state->arg_types,
1002 walk_state->arg_count);
1003 if (ACPI_FAILURE(status)) {
1005 acpi_ps_complete_op(walk_state, &op,
1007 if (ACPI_FAILURE(status)) {
1008 return_ACPI_STATUS(status);
1019 * All arguments have been processed -- Op is complete,
1022 walk_state->op_info =
1023 acpi_ps_get_opcode_info(op->common.aml_opcode);
1024 if (walk_state->op_info->flags & AML_NAMED) {
1025 if (acpi_gbl_depth) {
1029 if (op->common.aml_opcode == AML_REGION_OP ||
1030 op->common.aml_opcode == AML_DATA_REGION_OP) {
1032 * Skip parsing of control method or opregion body,
1033 * because we don't have enough info in the first pass
1034 * to parse them correctly.
1036 * Completed parsing an op_region declaration, we now
1040 (u32) (parser_state->aml - op->named.data);
1044 if (walk_state->op_info->flags & AML_CREATE) {
1046 * Backup to beginning of create_xXXfield declaration (1 for
1049 * body_length is unknown until we parse the body
1052 (u32) (parser_state->aml - op->named.data);
1055 if (op->common.aml_opcode == AML_BANK_FIELD_OP) {
1057 * Backup to beginning of bank_field declaration
1059 * body_length is unknown until we parse the body
1062 (u32) (parser_state->aml - op->named.data);
1065 /* This op complete, notify the dispatcher */
1067 if (walk_state->ascending_callback != NULL) {
1068 walk_state->op = op;
1069 walk_state->opcode = op->common.aml_opcode;
1071 status = walk_state->ascending_callback(walk_state);
1073 acpi_ps_next_parse_state(walk_state, op, status);
1074 if (status == AE_CTRL_PENDING) {
1079 status = acpi_ps_complete_op(walk_state, &op, status);
1080 if (ACPI_FAILURE(status)) {
1081 return_ACPI_STATUS(status);
1084 } /* while parser_state->Aml */
1086 status = acpi_ps_complete_final_op(walk_state, op, status);
1087 return_ACPI_STATUS(status);