1 /******************************************************************************
3 * Module Name: psparse - Parser top level AML parse routines
6 *****************************************************************************/
9 * Copyright (C) 2000, 2001 R. Byron Moore
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 * Parse the AML and build an operation tree as most interpreters,
29 * like Perl, do. Parsing is done by hand rather than with a YACC
30 * generated parser to tightly constrain stack and dynamic memory
31 * usage. At the same time, parsing is kept flexible and the code
32 * fairly compact by parsing based on a list of AML opcode
33 * templates in Aml_op_info[]
44 #define _COMPONENT ACPI_PARSER
45 MODULE_NAME ("psparse")
48 u32 acpi_gbl_depth
= 0;
49 extern u32 acpi_gbl_scope_depth
;
52 /*******************************************************************************
54 * FUNCTION: Acpi_ps_peek_opcode
60 * DESCRIPTION: Get next AML opcode (without incrementing AML pointer)
62 ******************************************************************************/
65 acpi_ps_get_opcode_size (
69 /* Extended (2-byte) opcode if > 255 */
71 if (opcode
> 0x00FF) {
75 /* Otherwise, just a single byte opcode */
81 /*******************************************************************************
83 * FUNCTION: Acpi_ps_peek_opcode
85 * PARAMETERS: Parser_state - A parser state object
89 * DESCRIPTION: Get next AML opcode (without incrementing AML pointer)
91 ******************************************************************************/
95 ACPI_PARSE_STATE
*parser_state
)
101 aml
= parser_state
->aml
;
102 opcode
= (u16
) GET8 (aml
);
108 * Original code special cased LNOTEQUAL, LLESSEQUAL, LGREATEREQUAL.
109 * These opcodes are no longer recognized. Instead, they are broken into
113 * if (Opcode == AML_EXTOP
114 * || (Opcode == AML_LNOT
115 * && (GET8 (Acpi_aml) == AML_LEQUAL
116 * || GET8 (Acpi_aml) == AML_LGREATER
117 * || GET8 (Acpi_aml) == AML_LLESS)))
119 * extended Opcode, !=, <=, or >=
122 if (opcode
== AML_EXTOP
) {
123 /* Extended opcode */
125 opcode
= (u16
) ((opcode
<< 8) | GET8 (aml
));
129 /* don't convert bare name to a namepath */
135 /*******************************************************************************
137 * FUNCTION: Acpi_ps_create_state
139 * PARAMETERS: Acpi_aml - Acpi_aml code pointer
140 * Acpi_aml_size - Length of AML code
142 * RETURN: A new parser state object
144 * DESCRIPTION: Create and initialize a new parser state object
146 ******************************************************************************/
149 acpi_ps_create_state (
153 ACPI_PARSE_STATE
*parser_state
;
156 parser_state
= acpi_cm_callocate (sizeof (ACPI_PARSE_STATE
));
161 parser_state
->aml
= aml
;
162 parser_state
->aml_end
= aml
+ aml_size
;
163 parser_state
->pkg_end
= parser_state
->aml_end
;
164 parser_state
->aml_start
= aml
;
167 return (parser_state
);
171 /*******************************************************************************
173 * FUNCTION: Acpi_ps_find_object
175 * PARAMETERS: Opcode - Current opcode
176 * Parser_state - Current state
177 * Walk_state - Current state
178 * *Op - Where found/new op is returned
182 * DESCRIPTION: Find a named object. Two versions - one to search the parse
183 * tree (for parser-only applications such as acpidump), another
184 * to search the ACPI internal namespace (the parse tree may no
187 ******************************************************************************/
192 acpi_ps_find_object (
194 ACPI_PARSE_OBJECT
*op
,
195 ACPI_WALK_STATE
*walk_state
,
196 ACPI_PARSE_OBJECT
**out_op
)
201 /* We are only interested in opcodes that have an associated name */
203 if (!acpi_ps_is_named_op (opcode
)) {
208 /* Find the name in the parse tree */
210 path
= acpi_ps_get_next_namestring (walk_state
->parser_state
);
212 *out_op
= acpi_ps_find (acpi_ps_get_parent_scope (walk_state
->parser_state
),
216 return (AE_NOT_FOUND
);
225 /*******************************************************************************
227 * FUNCTION: Acpi_ps_complete_this_op
229 * PARAMETERS: Walk_state - Current State
230 * Op - Op to complete
232 * RETURN: TRUE if Op and subtree was deleted
234 * DESCRIPTION: Perform any cleanup at the completion of an Op.
236 ******************************************************************************/
239 acpi_ps_complete_this_op (
240 ACPI_WALK_STATE
*walk_state
,
241 ACPI_PARSE_OBJECT
*op
)
244 ACPI_PARSE_OBJECT
*prev
;
245 ACPI_PARSE_OBJECT
*next
;
246 ACPI_OPCODE_INFO
*op_info
;
247 ACPI_OPCODE_INFO
*parent_info
;
249 ACPI_PARSE_OBJECT
*replacement_op
= NULL
;
252 op_info
= acpi_ps_get_opcode_info (op
->opcode
);
253 opcode_class
= ACPI_GET_OP_CLASS (op_info
);
256 /* Delete this op and the subtree below it if asked to */
258 if (((walk_state
->parse_flags
& ACPI_PARSE_TREE_MASK
) == ACPI_PARSE_DELETE_TREE
) &&
259 (opcode_class
!= OPTYPE_CONSTANT
) &&
260 (opcode_class
!= OPTYPE_LITERAL
) &&
261 (opcode_class
!= OPTYPE_LOCAL_VARIABLE
) &&
262 (opcode_class
!= OPTYPE_METHOD_ARGUMENT
) &&
263 (opcode_class
!= OPTYPE_DATA_TERM
) &&
264 (op
->opcode
!= AML_NAMEPATH_OP
)) {
265 /* Make sure that we only delete this subtree */
269 * Check if we need to replace the operator and its subtree
270 * with a return value op (placeholder op)
273 parent_info
= acpi_ps_get_opcode_info (op
->parent
->opcode
);
275 switch (ACPI_GET_OP_CLASS (parent_info
)) {
276 case OPTYPE_CONTROL
: /* IF, ELSE, WHILE only */
279 case OPTYPE_NAMED_OBJECT
: /* Scope, method, etc. */
282 * These opcodes contain Term_arg operands. The current
283 * op must be replace by a placeholder return op
286 if ((op
->parent
->opcode
== AML_REGION_OP
) ||
287 (op
->parent
->opcode
== AML_CREATE_FIELD_OP
) ||
288 (op
->parent
->opcode
== AML_BIT_FIELD_OP
) ||
289 (op
->parent
->opcode
== AML_BYTE_FIELD_OP
) ||
290 (op
->parent
->opcode
== AML_WORD_FIELD_OP
) ||
291 (op
->parent
->opcode
== AML_DWORD_FIELD_OP
) ||
292 (op
->parent
->opcode
== AML_QWORD_FIELD_OP
)) {
293 replacement_op
= acpi_ps_alloc_op (AML_RETURN_VALUE_OP
);
294 if (!replacement_op
) {
302 replacement_op
= acpi_ps_alloc_op (AML_RETURN_VALUE_OP
);
303 if (!replacement_op
) {
308 /* We must unlink this op from the parent tree */
310 prev
= op
->parent
->value
.arg
;
312 /* This op is the first in the list */
314 if (replacement_op
) {
315 replacement_op
->parent
= op
->parent
;
316 replacement_op
->value
.arg
= NULL
;
317 op
->parent
->value
.arg
= replacement_op
;
318 replacement_op
->next
= op
->next
;
321 op
->parent
->value
.arg
= op
->next
;
325 /* Search the parent list */
328 /* Traverse all siblings in the parent's argument list */
332 if (replacement_op
) {
333 replacement_op
->parent
= op
->parent
;
334 replacement_op
->value
.arg
= NULL
;
335 prev
->next
= replacement_op
;
336 replacement_op
->next
= op
->next
;
340 prev
->next
= op
->next
;
350 /* Now we can actually delete the subtree rooted at op */
352 acpi_ps_delete_parse_tree (op
);
365 /*******************************************************************************
367 * FUNCTION: Acpi_ps_next_parse_state
369 * PARAMETERS: Parser_state - Current parser state object
375 ******************************************************************************/
378 acpi_ps_next_parse_state (
379 ACPI_WALK_STATE
*walk_state
,
380 ACPI_PARSE_OBJECT
*op
,
381 ACPI_STATUS callback_status
)
383 ACPI_PARSE_STATE
*parser_state
= walk_state
->parser_state
;
384 ACPI_STATUS status
= AE_CTRL_PENDING
;
389 switch (callback_status
) {
390 case AE_CTRL_TERMINATE
:
393 * A control method was terminated via a RETURN statement.
394 * The walk of this method is complete.
397 parser_state
->aml
= parser_state
->aml_end
;
398 status
= AE_CTRL_TERMINATE
;
402 case AE_CTRL_PENDING
:
405 * Predicate of a WHILE was true and the loop just completed an
406 * execution. Go back to the start of the loop and reevaluate the
409 /* Walk_state->Control_state->Common.State =
410 CONTROL_PREDICATE_EXECUTING;*/
412 /* TBD: How to handle a break within a while. */
413 /* This code attempts it */
415 parser_state
->aml
= walk_state
->aml_last_while
;
421 * Predicate of an IF was true, and we are at the matching ELSE.
422 * Just close out this package
424 * Note: Parser_state->Aml is modified by the package length procedure
425 * TBD: [Investigate] perhaps it shouldn't, too much trouble
427 start
= parser_state
->aml
;
428 package_length
= acpi_ps_get_next_package_length (parser_state
);
429 parser_state
->aml
= start
+ package_length
;
436 * Either an IF/WHILE Predicate was false or we encountered a BREAK
437 * opcode. In both cases, we do not execute the rest of the
438 * package; We simply close out the parent (finishing the walk of
439 * this branch of the tree) and continue execution at the parent
443 parser_state
->aml
= parser_state
->scope
->parse_scope
.pkg_end
;
445 /* In the case of a BREAK, just force a predicate (if any) to FALSE */
447 walk_state
->control_state
->common
.value
= FALSE
;
448 status
= AE_CTRL_END
;
452 case AE_CTRL_TRANSFER
:
455 * A method call (invocation) -- transfer control
457 status
= AE_CTRL_TRANSFER
;
458 walk_state
->prev_op
= op
;
459 walk_state
->method_call_op
= op
;
460 walk_state
->method_call_node
= (op
->value
.arg
)->node
;
462 /* Will return value (if any) be used by the caller? */
464 walk_state
->return_used
= acpi_ds_is_result_used (op
, walk_state
);
469 status
= callback_status
;
470 if ((callback_status
& AE_CODE_MASK
) == AE_CODE_CONTROL
) {
481 /*******************************************************************************
483 * FUNCTION: Acpi_ps_parse_loop
485 * PARAMETERS: Parser_state - Current parser state object
489 * DESCRIPTION: Parse AML (pointed to by the current parser state) and return
492 ******************************************************************************/
496 ACPI_WALK_STATE
*walk_state
)
498 ACPI_STATUS status
= AE_OK
;
499 ACPI_PARSE_OBJECT
*op
= NULL
; /* current op */
500 ACPI_OPCODE_INFO
*op_info
;
501 ACPI_PARSE_OBJECT
*arg
= NULL
;
502 ACPI_PARSE2_OBJECT
*deferred_op
;
503 u32 arg_count
; /* push for fixed or var args */
505 ACPI_PTRDIFF aml_offset
;
507 ACPI_PARSE_OBJECT pre_op
;
508 ACPI_PARSE_STATE
*parser_state
;
512 parser_state
= walk_state
->parser_state
;
515 if (walk_state
->walk_type
& WALK_METHOD_RESTART
) {
516 /* We are restarting a preempted control method */
518 if (acpi_ps_has_completed_scope (parser_state
)) {
520 * We must check if a predicate to an IF or WHILE statement
523 if ((parser_state
->scope
->parse_scope
.op
) &&
524 ((parser_state
->scope
->parse_scope
.op
->opcode
== AML_IF_OP
) ||
525 (parser_state
->scope
->parse_scope
.op
->opcode
== AML_WHILE_OP
)) &&
526 (walk_state
->control_state
) &&
527 (walk_state
->control_state
->common
.state
==
528 CONTROL_PREDICATE_EXECUTING
)) {
531 * A predicate was just completed, get the value of the
532 * predicate and branch based on that value
535 status
= acpi_ds_get_predicate_value (walk_state
, NULL
, TRUE
);
536 if (ACPI_FAILURE (status
) &&
537 ((status
& AE_CODE_MASK
) != AE_CODE_CONTROL
)) {
541 status
= acpi_ps_next_parse_state (walk_state
, op
, status
);
544 acpi_ps_pop_scope (parser_state
, &op
, &arg_types
, &arg_count
);
547 else if (walk_state
->prev_op
) {
548 /* We were in the middle of an op */
550 op
= walk_state
->prev_op
;
551 arg_types
= walk_state
->prev_arg_types
;
557 * Iterative parsing loop, while there is more aml to process:
559 while ((parser_state
->aml
< parser_state
->aml_end
) || (op
)) {
561 /* Get the next opcode from the AML stream */
563 aml_op_start
= parser_state
->aml
;
564 aml_offset
= parser_state
->aml
- parser_state
->aml_start
;
565 opcode
= acpi_ps_peek_opcode (parser_state
);
568 * First cut to determine what we have found:
569 * 1) A valid AML opcode
571 * 3) An unknown/invalid opcode
574 op_info
= acpi_ps_get_opcode_info (opcode
);
575 switch (ACPI_GET_OP_TYPE (op_info
)) {
576 case ACPI_OP_TYPE_OPCODE
:
578 /* Found opcode info, this is a normal opcode */
580 parser_state
->aml
+= acpi_ps_get_opcode_size (opcode
);
581 arg_types
= op_info
->parse_args
;
584 case ACPI_OP_TYPE_ASCII
:
585 case ACPI_OP_TYPE_PREFIX
:
587 * Starts with a valid prefix or ASCII char, this is a name
588 * string. Convert the bare name string to a namepath.
591 opcode
= AML_NAMEPATH_OP
;
592 arg_types
= ARGP_NAMESTRING
;
595 case ACPI_OP_TYPE_UNKNOWN
:
597 /* The opcode is unrecognized. Just skip unknown opcodes */
599 /* Assume one-byte bad opcode */
606 /* Create Op structure and append to parent's argument list */
608 if (acpi_ps_is_named_op (opcode
)) {
609 pre_op
.value
.arg
= NULL
;
610 pre_op
.opcode
= opcode
;
612 while (GET_CURRENT_ARG_TYPE (arg_types
) != ARGP_NAME
) {
613 arg
= acpi_ps_get_next_arg (parser_state
,
614 GET_CURRENT_ARG_TYPE (arg_types
),
616 acpi_ps_append_arg (&pre_op
, arg
);
617 INCREMENT_ARG_LIST (arg_types
);
621 /* We know that this arg is a name, move to next arg */
623 INCREMENT_ARG_LIST (arg_types
);
625 if (walk_state
->descending_callback
!= NULL
) {
627 * Find the object. This will either insert the object into
628 * the namespace or simply look it up
630 status
= walk_state
->descending_callback (opcode
, NULL
, walk_state
, &op
);
634 status
= acpi_ps_next_parse_state (walk_state
, op
, status
);
635 if (status
== AE_CTRL_PENDING
) {
640 if (ACPI_FAILURE (status
)) {
645 acpi_ps_append_arg (op
, pre_op
.value
.arg
);
649 if (op
->opcode
== AML_REGION_OP
) {
650 deferred_op
= acpi_ps_to_extended_op (op
);
653 * Defer final parsing of an Operation_region body,
654 * because we don't have enough info in the first pass
655 * to parse it correctly (i.e., there may be method
656 * calls within the Term_arg elements of the body.
658 * However, we must continue parsing because
659 * the opregion is not a standalone package --
660 * we don't know where the end is at this point.
662 * (Length is unknown until parse of the body complete)
665 deferred_op
->data
= aml_op_start
;
666 deferred_op
->length
= 0;
673 /* Not a named opcode, just allocate Op and append to parent */
675 op
= acpi_ps_alloc_op (opcode
);
677 return (AE_NO_MEMORY
);
681 if ((op
->opcode
== AML_CREATE_FIELD_OP
) ||
682 (op
->opcode
== AML_BIT_FIELD_OP
) ||
683 (op
->opcode
== AML_BYTE_FIELD_OP
) ||
684 (op
->opcode
== AML_WORD_FIELD_OP
) ||
685 (op
->opcode
== AML_DWORD_FIELD_OP
)) {
687 * Backup to beginning of Create_xXXfield declaration
688 * Body_length is unknown until we parse the body
690 deferred_op
= (ACPI_PARSE2_OBJECT
*) op
;
692 deferred_op
->data
= aml_op_start
;
693 deferred_op
->length
= 0;
696 acpi_ps_append_arg (acpi_ps_get_parent_scope (parser_state
), op
);
698 if ((walk_state
->descending_callback
!= NULL
)) {
700 * Find the object. This will either insert the object into
701 * the namespace or simply look it up
703 status
= walk_state
->descending_callback (opcode
, op
, walk_state
, &op
);
704 status
= acpi_ps_next_parse_state (walk_state
, op
, status
);
705 if (status
== AE_CTRL_PENDING
) {
710 if (ACPI_FAILURE (status
)) {
716 op
->aml_offset
= aml_offset
;
721 /* Start Arg_count at zero because we don't know if there are any args yet */
726 if (arg_types
) /* Are there any arguments that must be processed? */ {
729 switch (op
->opcode
) {
730 case AML_BYTE_OP
: /* AML_BYTEDATA_ARG */
731 case AML_WORD_OP
: /* AML_WORDDATA_ARG */
732 case AML_DWORD_OP
: /* AML_DWORDATA_ARG */
733 case AML_STRING_OP
: /* AML_ASCIICHARLIST_ARG */
735 /* fill in constant or string argument directly */
737 acpi_ps_get_next_simple_arg (parser_state
,
738 GET_CURRENT_ARG_TYPE (arg_types
), op
);
741 case AML_NAMEPATH_OP
: /* AML_NAMESTRING_ARG */
743 acpi_ps_get_next_namepath (parser_state
, op
, &arg_count
, 1);
750 /* Op is not a constant or string, append each argument */
752 while (GET_CURRENT_ARG_TYPE (arg_types
) && !arg_count
) {
753 aml_offset
= parser_state
->aml
- parser_state
->aml_start
;
754 arg
= acpi_ps_get_next_arg (parser_state
,
755 GET_CURRENT_ARG_TYPE (arg_types
),
758 arg
->aml_offset
= aml_offset
;
759 acpi_ps_append_arg (op
, arg
);
762 INCREMENT_ARG_LIST (arg_types
);
766 /* For a method, save the length and address of the body */
768 if (op
->opcode
== AML_METHOD_OP
) {
769 deferred_op
= acpi_ps_to_extended_op (op
);
772 * Skip parsing of control method or opregion body,
773 * because we don't have enough info in the first pass
774 * to parse them correctly.
777 deferred_op
->data
= parser_state
->aml
;
778 deferred_op
->length
= parser_state
->pkg_end
-
782 * Skip body of method. For Op_regions, we must continue
783 * parsing because the opregion is not a standalone
784 * package (We don't know where the end is).
786 parser_state
->aml
= parser_state
->pkg_end
;
797 * Zero Arg_count means that all arguments for this op have been processed
800 /* completed Op, prepare for next */
802 if (acpi_ps_is_named_op (op
->opcode
)) {
803 if (acpi_gbl_depth
) {
807 if (op
->opcode
== AML_REGION_OP
) {
808 deferred_op
= acpi_ps_to_extended_op (op
);
811 * Skip parsing of control method or opregion body,
812 * because we don't have enough info in the first pass
813 * to parse them correctly.
815 * Completed parsing an Op_region declaration, we now
819 deferred_op
->length
= parser_state
->aml
-
825 if ((op
->opcode
== AML_CREATE_FIELD_OP
) ||
826 (op
->opcode
== AML_BIT_FIELD_OP
) ||
827 (op
->opcode
== AML_BYTE_FIELD_OP
) ||
828 (op
->opcode
== AML_WORD_FIELD_OP
) ||
829 (op
->opcode
== AML_DWORD_FIELD_OP
) ||
830 (op
->opcode
== AML_QWORD_FIELD_OP
)) {
832 * Backup to beginning of Create_xXXfield declaration (1 for
835 * Body_length is unknown until we parse the body
837 deferred_op
= (ACPI_PARSE2_OBJECT
*) op
;
838 deferred_op
->length
= parser_state
->aml
- deferred_op
->data
;
841 /* This op complete, notify the dispatcher */
843 if (walk_state
->ascending_callback
!= NULL
) {
844 status
= walk_state
->ascending_callback (walk_state
, op
);
845 status
= acpi_ps_next_parse_state (walk_state
, op
, status
);
846 if (status
== AE_CTRL_PENDING
) {
856 * Finished one argument of the containing scope
858 parser_state
->scope
->parse_scope
.arg_count
--;
860 /* Close this Op (may result in parse subtree deletion) */
862 if (acpi_ps_complete_this_op (walk_state
, op
)) {
872 case AE_CTRL_TRANSFER
:
875 * We are about to transfer to a called method.
877 walk_state
->prev_op
= op
;
878 walk_state
->prev_arg_types
= arg_types
;
885 acpi_ps_pop_scope (parser_state
, &op
, &arg_types
, &arg_count
);
887 status
= walk_state
->ascending_callback (walk_state
, op
);
888 status
= acpi_ps_next_parse_state (walk_state
, op
, status
);
890 acpi_ps_complete_this_op (walk_state
, op
);
896 case AE_CTRL_TERMINATE
:
903 acpi_ps_complete_this_op (walk_state
, op
);
906 acpi_ps_pop_scope (parser_state
, &op
, &arg_types
, &arg_count
);
913 default: /* All other non-AE_OK status */
916 acpi_ps_pop_scope (parser_state
, &op
, &arg_types
, &arg_count
);
918 walk_state
->prev_op
= op
;
919 walk_state
->prev_arg_types
= arg_types
;
930 /* This scope complete? */
932 if (acpi_ps_has_completed_scope (parser_state
)) {
933 acpi_ps_pop_scope (parser_state
, &op
, &arg_types
, &arg_count
);
943 /* Arg_count is non-zero */
946 /* complex argument, push Op and prepare for argument */
948 acpi_ps_push_scope (parser_state
, op
, arg_types
, arg_count
);
952 } /* while Parser_state->Aml */
956 * Complete the last Op (if not completed), and clear the scope stack.
957 * It is easily possible to end an AML "package" with an unbounded number
958 * of open scopes (such as when several AML blocks are closed with
959 * sequential closing braces). We want to terminate each one cleanly.
964 if (walk_state
->ascending_callback
!= NULL
) {
965 status
= walk_state
->ascending_callback (walk_state
, op
);
966 status
= acpi_ps_next_parse_state (walk_state
, op
, status
);
967 if (status
== AE_CTRL_PENDING
) {
972 if (status
== AE_CTRL_TERMINATE
) {
978 acpi_ps_complete_this_op (walk_state
, op
);
981 acpi_ps_pop_scope (parser_state
, &op
, &arg_types
, &arg_count
);
988 else if (ACPI_FAILURE (status
)) {
989 acpi_ps_complete_this_op (walk_state
, op
);
994 acpi_ps_complete_this_op (walk_state
, op
);
997 acpi_ps_pop_scope (parser_state
, &op
, &arg_types
, &arg_count
);
1005 /*******************************************************************************
1007 * FUNCTION: Acpi_ps_parse_aml
1009 * PARAMETERS: Start_scope - The starting point of the parse. Becomes the
1010 * root of the parsed op tree.
1011 * Aml - Pointer to the raw AML code to parse
1012 * Aml_size - Length of the AML to parse
1016 * DESCRIPTION: Parse raw AML and return a tree of ops
1018 ******************************************************************************/
1022 ACPI_PARSE_OBJECT
*start_scope
,
1026 ACPI_NAMESPACE_NODE
*method_node
,
1027 ACPI_OPERAND_OBJECT
**params
,
1028 ACPI_OPERAND_OBJECT
**caller_return_desc
,
1029 ACPI_PARSE_DOWNWARDS descending_callback
,
1030 ACPI_PARSE_UPWARDS ascending_callback
)
1033 ACPI_PARSE_STATE
*parser_state
;
1034 ACPI_WALK_STATE
*walk_state
;
1035 ACPI_WALK_LIST walk_list
;
1036 ACPI_NAMESPACE_NODE
*node
= NULL
;
1037 ACPI_WALK_LIST
*prev_walk_list
= acpi_gbl_current_walk_list
;
1038 ACPI_OPERAND_OBJECT
*return_desc
;
1039 ACPI_OPERAND_OBJECT
*mth_desc
= NULL
;
1042 /* Create and initialize a new parser state */
1044 parser_state
= acpi_ps_create_state (aml
, aml_size
);
1045 if (!parser_state
) {
1046 return (AE_NO_MEMORY
);
1049 acpi_ps_init_scope (parser_state
, start_scope
);
1052 mth_desc
= acpi_ns_get_attached_object (method_node
);
1055 /* Create and initialize a new walk list */
1057 walk_list
.walk_state
= NULL
;
1058 walk_list
.acquired_mutex_list
.prev
= NULL
;
1059 walk_list
.acquired_mutex_list
.next
= NULL
;
1061 walk_state
= acpi_ds_create_walk_state (TABLE_ID_DSDT
, parser_state
->start_op
, mth_desc
, &walk_list
);
1063 status
= AE_NO_MEMORY
;
1067 walk_state
->method_node
= method_node
;
1068 walk_state
->parser_state
= parser_state
;
1069 walk_state
->parse_flags
= parse_flags
;
1070 walk_state
->descending_callback
= descending_callback
;
1071 walk_state
->ascending_callback
= ascending_callback
;
1073 /* TBD: [Restructure] TEMP until we pass Walk_state to the interpreter
1075 acpi_gbl_current_walk_list
= &walk_list
;
1079 parser_state
->start_node
= method_node
;
1080 walk_state
->walk_type
= WALK_METHOD
;
1082 /* Push start scope on scope stack and make it current */
1084 status
= acpi_ds_scope_stack_push (method_node
, ACPI_TYPE_METHOD
, walk_state
);
1085 if (ACPI_FAILURE (status
)) {
1089 /* Init arguments if this is a control method */
1090 /* TBD: [Restructure] add walkstate as a param */
1092 acpi_ds_method_data_init_args (params
, MTH_NUM_ARGS
, walk_state
);
1096 /* Setup the current scope */
1098 node
= parser_state
->start_op
->node
;
1099 parser_state
->start_node
= node
;
1102 /* Push start scope on scope stack and make it current */
1104 status
= acpi_ds_scope_stack_push (node
, node
->type
,
1106 if (ACPI_FAILURE (status
)) {
1117 * Execute the walk loop as long as there is a valid Walk State. This
1118 * handles nested control method invocations without recursion.
1121 while (walk_state
) {
1122 if (ACPI_SUCCESS (status
)) {
1123 status
= acpi_ps_parse_loop (walk_state
);
1126 if (status
== AE_CTRL_TRANSFER
) {
1128 * A method call was detected.
1129 * Transfer control to the called control method
1132 status
= acpi_ds_call_control_method (&walk_list
, walk_state
, NULL
);
1135 * If the transfer to the new method method call worked, a new walk
1136 * state was created -- get it
1139 walk_state
= acpi_ds_get_current_walk_state (&walk_list
);
1143 else if (status
== AE_CTRL_TERMINATE
) {
1147 /* We are done with this walk, move on to the parent if any */
1150 walk_state
= acpi_ds_pop_walk_state (&walk_list
);
1152 /* Extract return value before we delete Walk_state */
1154 return_desc
= walk_state
->return_desc
;
1156 /* Reset the current scope to the beginning of scope stack */
1158 acpi_ds_scope_stack_clear (walk_state
);
1161 * If we just returned from the execution of a control method,
1162 * there's lots of cleanup to do
1165 if ((walk_state
->parse_flags
& ACPI_PARSE_MODE_MASK
) == ACPI_PARSE_EXECUTE
) {
1166 acpi_ds_terminate_control_method (walk_state
);
1169 /* Delete this walk state and all linked control states */
1171 acpi_ps_cleanup_scope (walk_state
->parser_state
);
1172 acpi_cm_free (walk_state
->parser_state
);
1173 acpi_ds_delete_walk_state (walk_state
);
1175 /* Check if we have restarted a preempted walk */
1177 walk_state
= acpi_ds_get_current_walk_state (&walk_list
);
1179 ACPI_SUCCESS (status
)) {
1180 /* There is another walk state, restart it */
1183 * If the method returned value is not used by the parent,
1184 * The object is deleted
1187 acpi_ds_restart_control_method (walk_state
, return_desc
);
1188 walk_state
->walk_type
|= WALK_METHOD_RESTART
;
1192 * Just completed a 1st-level method, save the final internal return
1196 else if (caller_return_desc
) {
1197 *caller_return_desc
= return_desc
; /* NULL if no return value */
1200 else if (return_desc
) {
1201 /* Caller doesn't want it, must delete it */
1203 acpi_cm_remove_reference (return_desc
);
1210 acpi_aml_release_all_mutexes ((ACPI_OPERAND_OBJECT
*) &walk_list
.acquired_mutex_list
);
1211 acpi_gbl_current_walk_list
= prev_walk_list
;
1219 acpi_ds_delete_walk_state (walk_state
);
1220 acpi_ps_cleanup_scope (parser_state
);
1221 acpi_cm_free (parser_state
);
1223 acpi_aml_release_all_mutexes ((ACPI_OPERAND_OBJECT
*)&walk_list
.acquired_mutex_list
);
1224 acpi_gbl_current_walk_list
= prev_walk_list
;