GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / acpi / acpica / psloop.c
blob7f6ef45cef671534c52d646f39b61da7add31d24
1 /******************************************************************************
3 * Module Name: psloop - Main AML parse loop
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2010, 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.flags |= AOPOBJ_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 walk_state->prev_op = NULL;
821 walk_state->prev_arg_types = walk_state->arg_types;
822 return_ACPI_STATUS(status);
825 /* This scope complete? */
827 if (acpi_ps_has_completed_scope(&(walk_state->parser_state))) {
828 acpi_ps_pop_scope(&(walk_state->parser_state), op,
829 &walk_state->arg_types,
830 &walk_state->arg_count);
831 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Popped scope, Op=%p\n", *op));
832 } else {
833 *op = NULL;
836 ACPI_PREEMPTION_POINT();
838 return_ACPI_STATUS(AE_OK);
841 /*******************************************************************************
843 * FUNCTION: acpi_ps_complete_final_op
845 * PARAMETERS: walk_state - Current state
846 * Op - Current Op
847 * Status - Current parse status before complete last
848 * Op
850 * RETURN: Status
852 * DESCRIPTION: Complete last Op.
854 ******************************************************************************/
856 static acpi_status
857 acpi_ps_complete_final_op(struct acpi_walk_state *walk_state,
858 union acpi_parse_object *op, acpi_status status)
860 acpi_status status2;
862 ACPI_FUNCTION_TRACE_PTR(ps_complete_final_op, walk_state);
865 * Complete the last Op (if not completed), and clear the scope stack.
866 * It is easily possible to end an AML "package" with an unbounded number
867 * of open scopes (such as when several ASL blocks are closed with
868 * sequential closing braces). We want to terminate each one cleanly.
870 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "AML package complete at Op %p\n",
871 op));
872 do {
873 if (op) {
874 if (walk_state->ascending_callback != NULL) {
875 walk_state->op = op;
876 walk_state->op_info =
877 acpi_ps_get_opcode_info(op->common.
878 aml_opcode);
879 walk_state->opcode = op->common.aml_opcode;
881 status =
882 walk_state->ascending_callback(walk_state);
883 status =
884 acpi_ps_next_parse_state(walk_state, op,
885 status);
886 if (status == AE_CTRL_PENDING) {
887 status =
888 acpi_ps_complete_op(walk_state, &op,
889 AE_OK);
890 if (ACPI_FAILURE(status)) {
891 return_ACPI_STATUS(status);
895 if (status == AE_CTRL_TERMINATE) {
896 status = AE_OK;
898 /* Clean up */
899 do {
900 if (op) {
901 status2 =
902 acpi_ps_complete_this_op
903 (walk_state, op);
904 if (ACPI_FAILURE
905 (status2)) {
906 return_ACPI_STATUS
907 (status2);
911 acpi_ps_pop_scope(&
912 (walk_state->
913 parser_state),
914 &op,
915 &walk_state->
916 arg_types,
917 &walk_state->
918 arg_count);
920 } while (op);
922 return_ACPI_STATUS(status);
925 else if (ACPI_FAILURE(status)) {
927 /* First error is most important */
929 (void)
930 acpi_ps_complete_this_op(walk_state,
931 op);
932 return_ACPI_STATUS(status);
936 status2 = acpi_ps_complete_this_op(walk_state, op);
937 if (ACPI_FAILURE(status2)) {
938 return_ACPI_STATUS(status2);
942 acpi_ps_pop_scope(&(walk_state->parser_state), &op,
943 &walk_state->arg_types,
944 &walk_state->arg_count);
946 } while (op);
948 return_ACPI_STATUS(status);
951 /*******************************************************************************
953 * FUNCTION: acpi_ps_parse_loop
955 * PARAMETERS: walk_state - Current state
957 * RETURN: Status
959 * DESCRIPTION: Parse AML (pointed to by the current parser state) and return
960 * a tree of ops.
962 ******************************************************************************/
964 acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state)
966 acpi_status status = AE_OK;
967 union acpi_parse_object *op = NULL; /* current op */
968 struct acpi_parse_state *parser_state;
969 u8 *aml_op_start = NULL;
971 ACPI_FUNCTION_TRACE_PTR(ps_parse_loop, walk_state);
973 if (walk_state->descending_callback == NULL) {
974 return_ACPI_STATUS(AE_BAD_PARAMETER);
977 parser_state = &walk_state->parser_state;
978 walk_state->arg_types = 0;
980 #if (!defined(ACPI_NO_METHOD_EXECUTION) && !defined(ACPI_CONSTANT_EVAL_ONLY))
982 if (walk_state->walk_type & ACPI_WALK_METHOD_RESTART) {
984 /* We are restarting a preempted control method */
986 if (acpi_ps_has_completed_scope(parser_state)) {
988 * We must check if a predicate to an IF or WHILE statement
989 * was just completed
991 if ((parser_state->scope->parse_scope.op) &&
992 ((parser_state->scope->parse_scope.op->common.
993 aml_opcode == AML_IF_OP)
994 || (parser_state->scope->parse_scope.op->common.
995 aml_opcode == AML_WHILE_OP))
996 && (walk_state->control_state)
997 && (walk_state->control_state->common.state ==
998 ACPI_CONTROL_PREDICATE_EXECUTING)) {
1000 * A predicate was just completed, get the value of the
1001 * predicate and branch based on that value
1003 walk_state->op = NULL;
1004 status =
1005 acpi_ds_get_predicate_value(walk_state,
1006 ACPI_TO_POINTER
1007 (TRUE));
1008 if (ACPI_FAILURE(status)
1009 && ((status & AE_CODE_MASK) !=
1010 AE_CODE_CONTROL)) {
1011 if (status == AE_AML_NO_RETURN_VALUE) {
1012 ACPI_EXCEPTION((AE_INFO, status,
1013 "Invoked method did not return a value"));
1016 ACPI_EXCEPTION((AE_INFO, status,
1017 "GetPredicate Failed"));
1018 return_ACPI_STATUS(status);
1021 status =
1022 acpi_ps_next_parse_state(walk_state, op,
1023 status);
1026 acpi_ps_pop_scope(parser_state, &op,
1027 &walk_state->arg_types,
1028 &walk_state->arg_count);
1029 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
1030 "Popped scope, Op=%p\n", op));
1031 } else if (walk_state->prev_op) {
1033 /* We were in the middle of an op */
1035 op = walk_state->prev_op;
1036 walk_state->arg_types = walk_state->prev_arg_types;
1039 #endif
1041 /* Iterative parsing loop, while there is more AML to process: */
1043 while ((parser_state->aml < parser_state->aml_end) || (op)) {
1044 aml_op_start = parser_state->aml;
1045 if (!op) {
1046 status =
1047 acpi_ps_create_op(walk_state, aml_op_start, &op);
1048 if (ACPI_FAILURE(status)) {
1049 if (status == AE_CTRL_PARSE_CONTINUE) {
1050 continue;
1053 if (status == AE_CTRL_PARSE_PENDING) {
1054 status = AE_OK;
1057 status =
1058 acpi_ps_complete_op(walk_state, &op,
1059 status);
1060 if (ACPI_FAILURE(status)) {
1061 return_ACPI_STATUS(status);
1064 continue;
1067 op->common.aml_offset = walk_state->aml_offset;
1069 if (walk_state->op_info) {
1070 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
1071 "Opcode %4.4X [%s] Op %p Aml %p AmlOffset %5.5X\n",
1072 (u32) op->common.aml_opcode,
1073 walk_state->op_info->name, op,
1074 parser_state->aml,
1075 op->common.aml_offset));
1080 * Start arg_count at zero because we don't know if there are
1081 * any args yet
1083 walk_state->arg_count = 0;
1085 /* Are there any arguments that must be processed? */
1087 if (walk_state->arg_types) {
1089 /* Get arguments */
1091 status =
1092 acpi_ps_get_arguments(walk_state, aml_op_start, op);
1093 if (ACPI_FAILURE(status)) {
1094 status =
1095 acpi_ps_complete_op(walk_state, &op,
1096 status);
1097 if (ACPI_FAILURE(status)) {
1098 return_ACPI_STATUS(status);
1101 continue;
1105 /* Check for arguments that need to be processed */
1107 if (walk_state->arg_count) {
1109 * There are arguments (complex ones), push Op and
1110 * prepare for argument
1112 status = acpi_ps_push_scope(parser_state, op,
1113 walk_state->arg_types,
1114 walk_state->arg_count);
1115 if (ACPI_FAILURE(status)) {
1116 status =
1117 acpi_ps_complete_op(walk_state, &op,
1118 status);
1119 if (ACPI_FAILURE(status)) {
1120 return_ACPI_STATUS(status);
1123 continue;
1126 op = NULL;
1127 continue;
1131 * All arguments have been processed -- Op is complete,
1132 * prepare for next
1134 walk_state->op_info =
1135 acpi_ps_get_opcode_info(op->common.aml_opcode);
1136 if (walk_state->op_info->flags & AML_NAMED) {
1137 if (acpi_gbl_depth) {
1138 acpi_gbl_depth--;
1141 if (op->common.aml_opcode == AML_REGION_OP ||
1142 op->common.aml_opcode == AML_DATA_REGION_OP) {
1144 * Skip parsing of control method or opregion body,
1145 * because we don't have enough info in the first pass
1146 * to parse them correctly.
1148 * Completed parsing an op_region declaration, we now
1149 * know the length.
1151 op->named.length =
1152 (u32) (parser_state->aml - op->named.data);
1156 if (walk_state->op_info->flags & AML_CREATE) {
1158 * Backup to beginning of create_xXXfield declaration (1 for
1159 * Opcode)
1161 * body_length is unknown until we parse the body
1163 op->named.length =
1164 (u32) (parser_state->aml - op->named.data);
1167 if (op->common.aml_opcode == AML_BANK_FIELD_OP) {
1169 * Backup to beginning of bank_field declaration
1171 * body_length is unknown until we parse the body
1173 op->named.length =
1174 (u32) (parser_state->aml - op->named.data);
1177 /* This op complete, notify the dispatcher */
1179 if (walk_state->ascending_callback != NULL) {
1180 walk_state->op = op;
1181 walk_state->opcode = op->common.aml_opcode;
1183 status = walk_state->ascending_callback(walk_state);
1184 status =
1185 acpi_ps_next_parse_state(walk_state, op, status);
1186 if (status == AE_CTRL_PENDING) {
1187 status = AE_OK;
1191 status = acpi_ps_complete_op(walk_state, &op, status);
1192 if (ACPI_FAILURE(status)) {
1193 return_ACPI_STATUS(status);
1196 } /* while parser_state->Aml */
1198 status = acpi_ps_complete_final_op(walk_state, op, status);
1199 return_ACPI_STATUS(status);