FRV: Use generic show_interrupts()
[cris-mirror.git] / drivers / acpi / acpica / psloop.c
blob01dd70d1de514eb8e8a03dfbc94995e35a6f90e3
1 /******************************************************************************
3 * Module Name: psloop - Main AML parse loop
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2011, Intel Corp.
9 * All rights reserved.
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.
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.
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.
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>
53 #include "accommon.h"
54 #include "acparser.h"
55 #include "acdispat.h"
56 #include "amlcode.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);
67 static acpi_status
68 acpi_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);
73 static acpi_status
74 acpi_ps_create_op(struct acpi_walk_state *walk_state,
75 u8 * aml_op_start, union acpi_parse_object **new_op);
77 static acpi_status
78 acpi_ps_get_arguments(struct acpi_walk_state *walk_state,
79 u8 * aml_op_start, union acpi_parse_object *op);
81 static acpi_status
82 acpi_ps_complete_op(struct acpi_walk_state *walk_state,
83 union acpi_parse_object **op, acpi_status status);
85 static acpi_status
86 acpi_ps_complete_final_op(struct acpi_walk_state *walk_state,
87 union acpi_parse_object *op, acpi_status status);
89 static void
90 acpi_ps_link_module_code(union acpi_parse_object *parent_op,
91 u8 *aml_start, u32 aml_length, acpi_owner_id owner_id);
93 /*******************************************************************************
95 * FUNCTION: acpi_ps_get_aml_opcode
97 * PARAMETERS: walk_state - Current state
99 * RETURN: Status
101 * DESCRIPTION: Extract the next AML opcode from the input stream.
103 ******************************************************************************/
105 static acpi_status acpi_ps_get_aml_opcode(struct acpi_walk_state *walk_state)
108 ACPI_FUNCTION_TRACE_PTR(ps_get_aml_opcode, walk_state);
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));
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
121 walk_state->op_info = acpi_ps_get_opcode_info(walk_state->opcode);
123 switch (walk_state->op_info->class) {
124 case AML_CLASS_ASCII:
125 case AML_CLASS_PREFIX:
127 * Starts with a valid prefix or ASCII char, this is a name
128 * string. Convert the bare name string to a namepath.
130 walk_state->opcode = AML_INT_NAMEPATH_OP;
131 walk_state->arg_types = ARGP_NAMESTRING;
132 break;
134 case AML_CLASS_UNKNOWN:
136 /* The opcode is unrecognized. Just skip unknown opcodes */
138 ACPI_ERROR((AE_INFO,
139 "Found unknown opcode 0x%X at AML address %p offset 0x%X, ignoring",
140 walk_state->opcode, walk_state->parser_state.aml,
141 walk_state->aml_offset));
143 ACPI_DUMP_BUFFER(walk_state->parser_state.aml, 128);
145 /* Assume one-byte bad opcode */
147 walk_state->parser_state.aml++;
148 return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE);
150 default:
152 /* Found opcode info, this is a normal opcode */
154 walk_state->parser_state.aml +=
155 acpi_ps_get_opcode_size(walk_state->opcode);
156 walk_state->arg_types = walk_state->op_info->parse_args;
157 break;
160 return_ACPI_STATUS(AE_OK);
163 /*******************************************************************************
165 * FUNCTION: acpi_ps_build_named_op
167 * PARAMETERS: walk_state - Current state
168 * aml_op_start - Begin of named Op in AML
169 * unnamed_op - Early Op (not a named Op)
170 * Op - Returned Op
172 * RETURN: Status
174 * DESCRIPTION: Parse a named Op
176 ******************************************************************************/
178 static acpi_status
179 acpi_ps_build_named_op(struct acpi_walk_state *walk_state,
180 u8 * aml_op_start,
181 union acpi_parse_object *unnamed_op,
182 union acpi_parse_object **op)
184 acpi_status status = AE_OK;
185 union acpi_parse_object *arg = NULL;
187 ACPI_FUNCTION_TRACE_PTR(ps_build_named_op, walk_state);
189 unnamed_op->common.value.arg = NULL;
190 unnamed_op->common.arg_list_length = 0;
191 unnamed_op->common.aml_opcode = walk_state->opcode;
194 * Get and append arguments until we find the node that contains
195 * the name (the type ARGP_NAME).
197 while (GET_CURRENT_ARG_TYPE(walk_state->arg_types) &&
198 (GET_CURRENT_ARG_TYPE(walk_state->arg_types) != ARGP_NAME)) {
199 status =
200 acpi_ps_get_next_arg(walk_state,
201 &(walk_state->parser_state),
202 GET_CURRENT_ARG_TYPE(walk_state->
203 arg_types), &arg);
204 if (ACPI_FAILURE(status)) {
205 return_ACPI_STATUS(status);
208 acpi_ps_append_arg(unnamed_op, arg);
209 INCREMENT_ARG_LIST(walk_state->arg_types);
213 * Make sure that we found a NAME and didn't run out of arguments
215 if (!GET_CURRENT_ARG_TYPE(walk_state->arg_types)) {
216 return_ACPI_STATUS(AE_AML_NO_OPERAND);
219 /* We know that this arg is a name, move to next arg */
221 INCREMENT_ARG_LIST(walk_state->arg_types);
224 * Find the object. This will either insert the object into
225 * the namespace or simply look it up
227 walk_state->op = NULL;
229 status = walk_state->descending_callback(walk_state, op);
230 if (ACPI_FAILURE(status)) {
231 ACPI_EXCEPTION((AE_INFO, status, "During name lookup/catalog"));
232 return_ACPI_STATUS(status);
235 if (!*op) {
236 return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE);
239 status = acpi_ps_next_parse_state(walk_state, *op, status);
240 if (ACPI_FAILURE(status)) {
241 if (status == AE_CTRL_PENDING) {
242 return_ACPI_STATUS(AE_CTRL_PARSE_PENDING);
244 return_ACPI_STATUS(status);
247 acpi_ps_append_arg(*op, unnamed_op->common.value.arg);
248 acpi_gbl_depth++;
250 if ((*op)->common.aml_opcode == AML_REGION_OP ||
251 (*op)->common.aml_opcode == AML_DATA_REGION_OP) {
253 * Defer final parsing of an operation_region body, because we don't
254 * have enough info in the first pass to parse it correctly (i.e.,
255 * there may be method calls within the term_arg elements of the body.)
257 * However, we must continue parsing because the opregion is not a
258 * standalone package -- we don't know where the end is at this point.
260 * (Length is unknown until parse of the body complete)
262 (*op)->named.data = aml_op_start;
263 (*op)->named.length = 0;
266 return_ACPI_STATUS(AE_OK);
269 /*******************************************************************************
271 * FUNCTION: acpi_ps_create_op
273 * PARAMETERS: walk_state - Current state
274 * aml_op_start - Op start in AML
275 * new_op - Returned Op
277 * RETURN: Status
279 * DESCRIPTION: Get Op from AML
281 ******************************************************************************/
283 static acpi_status
284 acpi_ps_create_op(struct acpi_walk_state *walk_state,
285 u8 * aml_op_start, union acpi_parse_object **new_op)
287 acpi_status status = AE_OK;
288 union acpi_parse_object *op;
289 union acpi_parse_object *named_op = NULL;
290 union acpi_parse_object *parent_scope;
291 u8 argument_count;
292 const struct acpi_opcode_info *op_info;
294 ACPI_FUNCTION_TRACE_PTR(ps_create_op, walk_state);
296 status = acpi_ps_get_aml_opcode(walk_state);
297 if (status == AE_CTRL_PARSE_CONTINUE) {
298 return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE);
301 /* Create Op structure and append to parent's argument list */
303 walk_state->op_info = acpi_ps_get_opcode_info(walk_state->opcode);
304 op = acpi_ps_alloc_op(walk_state->opcode);
305 if (!op) {
306 return_ACPI_STATUS(AE_NO_MEMORY);
309 if (walk_state->op_info->flags & AML_NAMED) {
310 status =
311 acpi_ps_build_named_op(walk_state, aml_op_start, op,
312 &named_op);
313 acpi_ps_free_op(op);
314 if (ACPI_FAILURE(status)) {
315 return_ACPI_STATUS(status);
318 *new_op = named_op;
319 return_ACPI_STATUS(AE_OK);
322 /* Not a named opcode, just allocate Op and append to parent */
324 if (walk_state->op_info->flags & AML_CREATE) {
326 * Backup to beginning of create_xXXfield declaration
327 * body_length is unknown until we parse the body
329 op->named.data = aml_op_start;
330 op->named.length = 0;
333 if (walk_state->opcode == AML_BANK_FIELD_OP) {
335 * Backup to beginning of bank_field declaration
336 * body_length is unknown until we parse the body
338 op->named.data = aml_op_start;
339 op->named.length = 0;
342 parent_scope = acpi_ps_get_parent_scope(&(walk_state->parser_state));
343 acpi_ps_append_arg(parent_scope, op);
345 if (parent_scope) {
346 op_info =
347 acpi_ps_get_opcode_info(parent_scope->common.aml_opcode);
348 if (op_info->flags & AML_HAS_TARGET) {
349 argument_count =
350 acpi_ps_get_argument_count(op_info->type);
351 if (parent_scope->common.arg_list_length >
352 argument_count) {
353 op->common.flags |= ACPI_PARSEOP_TARGET;
355 } else if (parent_scope->common.aml_opcode == AML_INCREMENT_OP) {
356 op->common.flags |= ACPI_PARSEOP_TARGET;
360 if (walk_state->descending_callback != NULL) {
362 * Find the object. This will either insert the object into
363 * the namespace or simply look it up
365 walk_state->op = *new_op = op;
367 status = walk_state->descending_callback(walk_state, &op);
368 status = acpi_ps_next_parse_state(walk_state, op, status);
369 if (status == AE_CTRL_PENDING) {
370 status = AE_CTRL_PARSE_PENDING;
374 return_ACPI_STATUS(status);
377 /*******************************************************************************
379 * FUNCTION: acpi_ps_get_arguments
381 * PARAMETERS: walk_state - Current state
382 * aml_op_start - Op start in AML
383 * Op - Current Op
385 * RETURN: Status
387 * DESCRIPTION: Get arguments for passed Op.
389 ******************************************************************************/
391 static acpi_status
392 acpi_ps_get_arguments(struct acpi_walk_state *walk_state,
393 u8 * aml_op_start, union acpi_parse_object *op)
395 acpi_status status = AE_OK;
396 union acpi_parse_object *arg = NULL;
397 const struct acpi_opcode_info *op_info;
399 ACPI_FUNCTION_TRACE_PTR(ps_get_arguments, walk_state);
401 switch (op->common.aml_opcode) {
402 case AML_BYTE_OP: /* AML_BYTEDATA_ARG */
403 case AML_WORD_OP: /* AML_WORDDATA_ARG */
404 case AML_DWORD_OP: /* AML_DWORDATA_ARG */
405 case AML_QWORD_OP: /* AML_QWORDATA_ARG */
406 case AML_STRING_OP: /* AML_ASCIICHARLIST_ARG */
408 /* Fill in constant or string argument directly */
410 acpi_ps_get_next_simple_arg(&(walk_state->parser_state),
411 GET_CURRENT_ARG_TYPE(walk_state->
412 arg_types),
413 op);
414 break;
416 case AML_INT_NAMEPATH_OP: /* AML_NAMESTRING_ARG */
418 status =
419 acpi_ps_get_next_namepath(walk_state,
420 &(walk_state->parser_state), op,
422 if (ACPI_FAILURE(status)) {
423 return_ACPI_STATUS(status);
426 walk_state->arg_types = 0;
427 break;
429 default:
431 * Op is not a constant or string, append each argument to the Op
433 while (GET_CURRENT_ARG_TYPE(walk_state->arg_types)
434 && !walk_state->arg_count) {
435 walk_state->aml_offset =
436 (u32) ACPI_PTR_DIFF(walk_state->parser_state.aml,
437 walk_state->parser_state.
438 aml_start);
440 status =
441 acpi_ps_get_next_arg(walk_state,
442 &(walk_state->parser_state),
443 GET_CURRENT_ARG_TYPE
444 (walk_state->arg_types), &arg);
445 if (ACPI_FAILURE(status)) {
446 return_ACPI_STATUS(status);
449 if (arg) {
450 arg->common.aml_offset = walk_state->aml_offset;
451 acpi_ps_append_arg(op, arg);
454 INCREMENT_ARG_LIST(walk_state->arg_types);
458 * Handle executable code at "module-level". This refers to
459 * executable opcodes that appear outside of any control method.
461 if ((walk_state->pass_number <= ACPI_IMODE_LOAD_PASS2) &&
462 ((walk_state->parse_flags & ACPI_PARSE_DISASSEMBLE) == 0)) {
464 * We want to skip If/Else/While constructs during Pass1 because we
465 * want to actually conditionally execute the code during Pass2.
467 * Except for disassembly, where we always want to walk the
468 * If/Else/While packages
470 switch (op->common.aml_opcode) {
471 case AML_IF_OP:
472 case AML_ELSE_OP:
473 case AML_WHILE_OP:
476 * Currently supported module-level opcodes are:
477 * IF/ELSE/WHILE. These appear to be the most common,
478 * and easiest to support since they open an AML
479 * package.
481 if (walk_state->pass_number ==
482 ACPI_IMODE_LOAD_PASS1) {
483 acpi_ps_link_module_code(op->common.
484 parent,
485 aml_op_start,
486 (u32)
487 (walk_state->
488 parser_state.
489 pkg_end -
490 aml_op_start),
491 walk_state->
492 owner_id);
495 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
496 "Pass1: Skipping an If/Else/While body\n"));
498 /* Skip body of if/else/while in pass 1 */
500 walk_state->parser_state.aml =
501 walk_state->parser_state.pkg_end;
502 walk_state->arg_count = 0;
503 break;
505 default:
507 * Check for an unsupported executable opcode at module
508 * level. We must be in PASS1, the parent must be a SCOPE,
509 * The opcode class must be EXECUTE, and the opcode must
510 * not be an argument to another opcode.
512 if ((walk_state->pass_number ==
513 ACPI_IMODE_LOAD_PASS1)
514 && (op->common.parent->common.aml_opcode ==
515 AML_SCOPE_OP)) {
516 op_info =
517 acpi_ps_get_opcode_info(op->common.
518 aml_opcode);
519 if ((op_info->class ==
520 AML_CLASS_EXECUTE) && (!arg)) {
521 ACPI_WARNING((AE_INFO,
522 "Detected an unsupported executable opcode "
523 "at module-level: [0x%.4X] at table offset 0x%.4X",
524 op->common.aml_opcode,
525 (u32)((aml_op_start - walk_state->parser_state.aml_start)
526 + sizeof(struct acpi_table_header))));
529 break;
533 /* Special processing for certain opcodes */
535 switch (op->common.aml_opcode) {
536 case AML_METHOD_OP:
538 * Skip parsing of control method because we don't have enough
539 * info in the first pass to parse it correctly.
541 * Save the length and address of the body
543 op->named.data = walk_state->parser_state.aml;
544 op->named.length = (u32)
545 (walk_state->parser_state.pkg_end -
546 walk_state->parser_state.aml);
548 /* Skip body of method */
550 walk_state->parser_state.aml =
551 walk_state->parser_state.pkg_end;
552 walk_state->arg_count = 0;
553 break;
555 case AML_BUFFER_OP:
556 case AML_PACKAGE_OP:
557 case AML_VAR_PACKAGE_OP:
559 if ((op->common.parent) &&
560 (op->common.parent->common.aml_opcode ==
561 AML_NAME_OP)
562 && (walk_state->pass_number <=
563 ACPI_IMODE_LOAD_PASS2)) {
565 * Skip parsing of Buffers and Packages because we don't have
566 * enough info in the first pass to parse them correctly.
568 op->named.data = aml_op_start;
569 op->named.length = (u32)
570 (walk_state->parser_state.pkg_end -
571 aml_op_start);
573 /* Skip body */
575 walk_state->parser_state.aml =
576 walk_state->parser_state.pkg_end;
577 walk_state->arg_count = 0;
579 break;
581 case AML_WHILE_OP:
583 if (walk_state->control_state) {
584 walk_state->control_state->control.package_end =
585 walk_state->parser_state.pkg_end;
587 break;
589 default:
591 /* No action for all other opcodes */
592 break;
595 break;
598 return_ACPI_STATUS(AE_OK);
601 /*******************************************************************************
603 * FUNCTION: acpi_ps_link_module_code
605 * PARAMETERS: parent_op - Parent parser op
606 * aml_start - Pointer to the AML
607 * aml_length - Length of executable AML
608 * owner_id - owner_id of module level code
610 * RETURN: None.
612 * DESCRIPTION: Wrap the module-level code with a method object and link the
613 * object to the global list. Note, the mutex field of the method
614 * object is used to link multiple module-level code objects.
616 ******************************************************************************/
618 static void
619 acpi_ps_link_module_code(union acpi_parse_object *parent_op,
620 u8 *aml_start, u32 aml_length, acpi_owner_id owner_id)
622 union acpi_operand_object *prev;
623 union acpi_operand_object *next;
624 union acpi_operand_object *method_obj;
625 struct acpi_namespace_node *parent_node;
627 /* Get the tail of the list */
629 prev = next = acpi_gbl_module_code_list;
630 while (next) {
631 prev = next;
632 next = next->method.mutex;
636 * Insert the module level code into the list. Merge it if it is
637 * adjacent to the previous element.
639 if (!prev ||
640 ((prev->method.aml_start + prev->method.aml_length) != aml_start)) {
642 /* Create, initialize, and link a new temporary method object */
644 method_obj = acpi_ut_create_internal_object(ACPI_TYPE_METHOD);
645 if (!method_obj) {
646 return;
649 if (parent_op->common.node) {
650 parent_node = parent_op->common.node;
651 } else {
652 parent_node = acpi_gbl_root_node;
655 method_obj->method.aml_start = aml_start;
656 method_obj->method.aml_length = aml_length;
657 method_obj->method.owner_id = owner_id;
658 method_obj->method.info_flags |= ACPI_METHOD_MODULE_LEVEL;
661 * Save the parent node in next_object. This is cheating, but we
662 * don't want to expand the method object.
664 method_obj->method.next_object =
665 ACPI_CAST_PTR(union acpi_operand_object, parent_node);
667 if (!prev) {
668 acpi_gbl_module_code_list = method_obj;
669 } else {
670 prev->method.mutex = method_obj;
672 } else {
673 prev->method.aml_length += aml_length;
677 /*******************************************************************************
679 * FUNCTION: acpi_ps_complete_op
681 * PARAMETERS: walk_state - Current state
682 * Op - Returned Op
683 * Status - Parse status before complete Op
685 * RETURN: Status
687 * DESCRIPTION: Complete Op
689 ******************************************************************************/
691 static acpi_status
692 acpi_ps_complete_op(struct acpi_walk_state *walk_state,
693 union acpi_parse_object **op, acpi_status status)
695 acpi_status status2;
697 ACPI_FUNCTION_TRACE_PTR(ps_complete_op, walk_state);
700 * Finished one argument of the containing scope
702 walk_state->parser_state.scope->parse_scope.arg_count--;
704 /* Close this Op (will result in parse subtree deletion) */
706 status2 = acpi_ps_complete_this_op(walk_state, *op);
707 if (ACPI_FAILURE(status2)) {
708 return_ACPI_STATUS(status2);
711 *op = NULL;
713 switch (status) {
714 case AE_OK:
715 break;
717 case AE_CTRL_TRANSFER:
719 /* We are about to transfer to a called method */
721 walk_state->prev_op = NULL;
722 walk_state->prev_arg_types = walk_state->arg_types;
723 return_ACPI_STATUS(status);
725 case AE_CTRL_END:
727 acpi_ps_pop_scope(&(walk_state->parser_state), op,
728 &walk_state->arg_types,
729 &walk_state->arg_count);
731 if (*op) {
732 walk_state->op = *op;
733 walk_state->op_info =
734 acpi_ps_get_opcode_info((*op)->common.aml_opcode);
735 walk_state->opcode = (*op)->common.aml_opcode;
737 status = walk_state->ascending_callback(walk_state);
738 status =
739 acpi_ps_next_parse_state(walk_state, *op, status);
741 status2 = acpi_ps_complete_this_op(walk_state, *op);
742 if (ACPI_FAILURE(status2)) {
743 return_ACPI_STATUS(status2);
747 status = AE_OK;
748 break;
750 case AE_CTRL_BREAK:
751 case AE_CTRL_CONTINUE:
753 /* Pop off scopes until we find the While */
755 while (!(*op) || ((*op)->common.aml_opcode != AML_WHILE_OP)) {
756 acpi_ps_pop_scope(&(walk_state->parser_state), op,
757 &walk_state->arg_types,
758 &walk_state->arg_count);
761 /* Close this iteration of the While loop */
763 walk_state->op = *op;
764 walk_state->op_info =
765 acpi_ps_get_opcode_info((*op)->common.aml_opcode);
766 walk_state->opcode = (*op)->common.aml_opcode;
768 status = walk_state->ascending_callback(walk_state);
769 status = acpi_ps_next_parse_state(walk_state, *op, status);
771 status2 = acpi_ps_complete_this_op(walk_state, *op);
772 if (ACPI_FAILURE(status2)) {
773 return_ACPI_STATUS(status2);
776 status = AE_OK;
777 break;
779 case AE_CTRL_TERMINATE:
781 /* Clean up */
782 do {
783 if (*op) {
784 status2 =
785 acpi_ps_complete_this_op(walk_state, *op);
786 if (ACPI_FAILURE(status2)) {
787 return_ACPI_STATUS(status2);
790 acpi_ut_delete_generic_state
791 (acpi_ut_pop_generic_state
792 (&walk_state->control_state));
795 acpi_ps_pop_scope(&(walk_state->parser_state), op,
796 &walk_state->arg_types,
797 &walk_state->arg_count);
799 } while (*op);
801 return_ACPI_STATUS(AE_OK);
803 default: /* All other non-AE_OK status */
805 do {
806 if (*op) {
807 status2 =
808 acpi_ps_complete_this_op(walk_state, *op);
809 if (ACPI_FAILURE(status2)) {
810 return_ACPI_STATUS(status2);
814 acpi_ps_pop_scope(&(walk_state->parser_state), op,
815 &walk_state->arg_types,
816 &walk_state->arg_count);
818 } while (*op);
820 #if 0
822 * TBD: Cleanup parse ops on error
824 if (*op == NULL) {
825 acpi_ps_pop_scope(parser_state, op,
826 &walk_state->arg_types,
827 &walk_state->arg_count);
829 #endif
830 walk_state->prev_op = NULL;
831 walk_state->prev_arg_types = walk_state->arg_types;
832 return_ACPI_STATUS(status);
835 /* This scope complete? */
837 if (acpi_ps_has_completed_scope(&(walk_state->parser_state))) {
838 acpi_ps_pop_scope(&(walk_state->parser_state), op,
839 &walk_state->arg_types,
840 &walk_state->arg_count);
841 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Popped scope, Op=%p\n", *op));
842 } else {
843 *op = NULL;
846 ACPI_PREEMPTION_POINT();
848 return_ACPI_STATUS(AE_OK);
851 /*******************************************************************************
853 * FUNCTION: acpi_ps_complete_final_op
855 * PARAMETERS: walk_state - Current state
856 * Op - Current Op
857 * Status - Current parse status before complete last
858 * Op
860 * RETURN: Status
862 * DESCRIPTION: Complete last Op.
864 ******************************************************************************/
866 static acpi_status
867 acpi_ps_complete_final_op(struct acpi_walk_state *walk_state,
868 union acpi_parse_object *op, acpi_status status)
870 acpi_status status2;
872 ACPI_FUNCTION_TRACE_PTR(ps_complete_final_op, walk_state);
875 * Complete the last Op (if not completed), and clear the scope stack.
876 * It is easily possible to end an AML "package" with an unbounded number
877 * of open scopes (such as when several ASL blocks are closed with
878 * sequential closing braces). We want to terminate each one cleanly.
880 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "AML package complete at Op %p\n",
881 op));
882 do {
883 if (op) {
884 if (walk_state->ascending_callback != NULL) {
885 walk_state->op = op;
886 walk_state->op_info =
887 acpi_ps_get_opcode_info(op->common.
888 aml_opcode);
889 walk_state->opcode = op->common.aml_opcode;
891 status =
892 walk_state->ascending_callback(walk_state);
893 status =
894 acpi_ps_next_parse_state(walk_state, op,
895 status);
896 if (status == AE_CTRL_PENDING) {
897 status =
898 acpi_ps_complete_op(walk_state, &op,
899 AE_OK);
900 if (ACPI_FAILURE(status)) {
901 return_ACPI_STATUS(status);
905 if (status == AE_CTRL_TERMINATE) {
906 status = AE_OK;
908 /* Clean up */
909 do {
910 if (op) {
911 status2 =
912 acpi_ps_complete_this_op
913 (walk_state, op);
914 if (ACPI_FAILURE
915 (status2)) {
916 return_ACPI_STATUS
917 (status2);
921 acpi_ps_pop_scope(&
922 (walk_state->
923 parser_state),
924 &op,
925 &walk_state->
926 arg_types,
927 &walk_state->
928 arg_count);
930 } while (op);
932 return_ACPI_STATUS(status);
935 else if (ACPI_FAILURE(status)) {
937 /* First error is most important */
939 (void)
940 acpi_ps_complete_this_op(walk_state,
941 op);
942 return_ACPI_STATUS(status);
946 status2 = acpi_ps_complete_this_op(walk_state, op);
947 if (ACPI_FAILURE(status2)) {
948 return_ACPI_STATUS(status2);
952 acpi_ps_pop_scope(&(walk_state->parser_state), &op,
953 &walk_state->arg_types,
954 &walk_state->arg_count);
956 } while (op);
958 return_ACPI_STATUS(status);
961 /*******************************************************************************
963 * FUNCTION: acpi_ps_parse_loop
965 * PARAMETERS: walk_state - Current state
967 * RETURN: Status
969 * DESCRIPTION: Parse AML (pointed to by the current parser state) and return
970 * a tree of ops.
972 ******************************************************************************/
974 acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state)
976 acpi_status status = AE_OK;
977 union acpi_parse_object *op = NULL; /* current op */
978 struct acpi_parse_state *parser_state;
979 u8 *aml_op_start = NULL;
981 ACPI_FUNCTION_TRACE_PTR(ps_parse_loop, walk_state);
983 if (walk_state->descending_callback == NULL) {
984 return_ACPI_STATUS(AE_BAD_PARAMETER);
987 parser_state = &walk_state->parser_state;
988 walk_state->arg_types = 0;
990 #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
992 if (walk_state->walk_type & ACPI_WALK_METHOD_RESTART) {
994 /* We are restarting a preempted control method */
996 if (acpi_ps_has_completed_scope(parser_state)) {
998 * We must check if a predicate to an IF or WHILE statement
999 * was just completed
1001 if ((parser_state->scope->parse_scope.op) &&
1002 ((parser_state->scope->parse_scope.op->common.
1003 aml_opcode == AML_IF_OP)
1004 || (parser_state->scope->parse_scope.op->common.
1005 aml_opcode == AML_WHILE_OP))
1006 && (walk_state->control_state)
1007 && (walk_state->control_state->common.state ==
1008 ACPI_CONTROL_PREDICATE_EXECUTING)) {
1010 * A predicate was just completed, get the value of the
1011 * predicate and branch based on that value
1013 walk_state->op = NULL;
1014 status =
1015 acpi_ds_get_predicate_value(walk_state,
1016 ACPI_TO_POINTER
1017 (TRUE));
1018 if (ACPI_FAILURE(status)
1019 && ((status & AE_CODE_MASK) !=
1020 AE_CODE_CONTROL)) {
1021 if (status == AE_AML_NO_RETURN_VALUE) {
1022 ACPI_EXCEPTION((AE_INFO, status,
1023 "Invoked method did not return a value"));
1026 ACPI_EXCEPTION((AE_INFO, status,
1027 "GetPredicate Failed"));
1028 return_ACPI_STATUS(status);
1031 status =
1032 acpi_ps_next_parse_state(walk_state, op,
1033 status);
1036 acpi_ps_pop_scope(parser_state, &op,
1037 &walk_state->arg_types,
1038 &walk_state->arg_count);
1039 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
1040 "Popped scope, Op=%p\n", op));
1041 } else if (walk_state->prev_op) {
1043 /* We were in the middle of an op */
1045 op = walk_state->prev_op;
1046 walk_state->arg_types = walk_state->prev_arg_types;
1049 #endif
1051 /* Iterative parsing loop, while there is more AML to process: */
1053 while ((parser_state->aml < parser_state->aml_end) || (op)) {
1054 aml_op_start = parser_state->aml;
1055 if (!op) {
1056 status =
1057 acpi_ps_create_op(walk_state, aml_op_start, &op);
1058 if (ACPI_FAILURE(status)) {
1059 if (status == AE_CTRL_PARSE_CONTINUE) {
1060 continue;
1063 if (status == AE_CTRL_PARSE_PENDING) {
1064 status = AE_OK;
1067 status =
1068 acpi_ps_complete_op(walk_state, &op,
1069 status);
1070 if (ACPI_FAILURE(status)) {
1071 return_ACPI_STATUS(status);
1074 continue;
1077 op->common.aml_offset = walk_state->aml_offset;
1079 if (walk_state->op_info) {
1080 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
1081 "Opcode %4.4X [%s] Op %p Aml %p AmlOffset %5.5X\n",
1082 (u32) op->common.aml_opcode,
1083 walk_state->op_info->name, op,
1084 parser_state->aml,
1085 op->common.aml_offset));
1090 * Start arg_count at zero because we don't know if there are
1091 * any args yet
1093 walk_state->arg_count = 0;
1095 /* Are there any arguments that must be processed? */
1097 if (walk_state->arg_types) {
1099 /* Get arguments */
1101 status =
1102 acpi_ps_get_arguments(walk_state, aml_op_start, op);
1103 if (ACPI_FAILURE(status)) {
1104 status =
1105 acpi_ps_complete_op(walk_state, &op,
1106 status);
1107 if (ACPI_FAILURE(status)) {
1108 return_ACPI_STATUS(status);
1111 continue;
1115 /* Check for arguments that need to be processed */
1117 if (walk_state->arg_count) {
1119 * There are arguments (complex ones), push Op and
1120 * prepare for argument
1122 status = acpi_ps_push_scope(parser_state, op,
1123 walk_state->arg_types,
1124 walk_state->arg_count);
1125 if (ACPI_FAILURE(status)) {
1126 status =
1127 acpi_ps_complete_op(walk_state, &op,
1128 status);
1129 if (ACPI_FAILURE(status)) {
1130 return_ACPI_STATUS(status);
1133 continue;
1136 op = NULL;
1137 continue;
1141 * All arguments have been processed -- Op is complete,
1142 * prepare for next
1144 walk_state->op_info =
1145 acpi_ps_get_opcode_info(op->common.aml_opcode);
1146 if (walk_state->op_info->flags & AML_NAMED) {
1147 if (acpi_gbl_depth) {
1148 acpi_gbl_depth--;
1151 if (op->common.aml_opcode == AML_REGION_OP ||
1152 op->common.aml_opcode == AML_DATA_REGION_OP) {
1154 * Skip parsing of control method or opregion body,
1155 * because we don't have enough info in the first pass
1156 * to parse them correctly.
1158 * Completed parsing an op_region declaration, we now
1159 * know the length.
1161 op->named.length =
1162 (u32) (parser_state->aml - op->named.data);
1166 if (walk_state->op_info->flags & AML_CREATE) {
1168 * Backup to beginning of create_xXXfield declaration (1 for
1169 * Opcode)
1171 * body_length is unknown until we parse the body
1173 op->named.length =
1174 (u32) (parser_state->aml - op->named.data);
1177 if (op->common.aml_opcode == AML_BANK_FIELD_OP) {
1179 * Backup to beginning of bank_field declaration
1181 * body_length is unknown until we parse the body
1183 op->named.length =
1184 (u32) (parser_state->aml - op->named.data);
1187 /* This op complete, notify the dispatcher */
1189 if (walk_state->ascending_callback != NULL) {
1190 walk_state->op = op;
1191 walk_state->opcode = op->common.aml_opcode;
1193 status = walk_state->ascending_callback(walk_state);
1194 status =
1195 acpi_ps_next_parse_state(walk_state, op, status);
1196 if (status == AE_CTRL_PENDING) {
1197 status = AE_OK;
1201 status = acpi_ps_complete_op(walk_state, &op, status);
1202 if (ACPI_FAILURE(status)) {
1203 return_ACPI_STATUS(status);
1206 } /* while parser_state->Aml */
1208 status = acpi_ps_complete_final_op(walk_state, op, status);
1209 return_ACPI_STATUS(status);