[ACPI] ACPICA 20051216
[linux-2.6-block.git] / drivers / acpi / parser / psloop.c
CommitLineData
73459f73
RM
1/******************************************************************************
2 *
3 * Module Name: psloop - Main AML parse loop
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2005, R. Byron Moore
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
73459f73
RM
44/*
45 * Parse the AML and build an operation tree as most interpreters,
46 * like Perl, do. Parsing is done by hand rather than with a YACC
47 * generated parser to tightly constrain stack and dynamic memory
48 * usage. At the same time, parsing is kept flexible and the code
49 * fairly compact by parsing based on a list of AML opcode
50 * templates in aml_op_info[]
51 */
52
53#include <acpi/acpi.h>
54#include <acpi/acparser.h>
55#include <acpi/acdispat.h>
56#include <acpi/amlcode.h>
73459f73
RM
57
58#define _COMPONENT ACPI_PARSER
4be44fcd 59ACPI_MODULE_NAME("psloop")
73459f73 60
4be44fcd 61static u32 acpi_gbl_depth = 0;
73459f73
RM
62
63/*******************************************************************************
64 *
65 * FUNCTION: acpi_ps_parse_loop
66 *
67 * PARAMETERS: walk_state - Current state
68 *
69 * RETURN: Status
70 *
71 * DESCRIPTION: Parse AML (pointed to by the current parser state) and return
72 * a tree of ops.
73 *
74 ******************************************************************************/
75
4be44fcd 76acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state)
73459f73 77{
4be44fcd
LB
78 acpi_status status = AE_OK;
79 acpi_status status2;
80 union acpi_parse_object *op = NULL; /* current op */
81 union acpi_parse_object *arg = NULL;
82 union acpi_parse_object *pre_op = NULL;
83 struct acpi_parse_state *parser_state;
84 u8 *aml_op_start = NULL;
73459f73 85
4be44fcd 86 ACPI_FUNCTION_TRACE_PTR("ps_parse_loop", walk_state);
73459f73
RM
87
88 if (walk_state->descending_callback == NULL) {
4be44fcd 89 return_ACPI_STATUS(AE_BAD_PARAMETER);
73459f73
RM
90 }
91
92 parser_state = &walk_state->parser_state;
93 walk_state->arg_types = 0;
94
95#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
96
97 if (walk_state->walk_type & ACPI_WALK_METHOD_RESTART) {
98 /* We are restarting a preempted control method */
99
4be44fcd 100 if (acpi_ps_has_completed_scope(parser_state)) {
73459f73
RM
101 /*
102 * We must check if a predicate to an IF or WHILE statement
103 * was just completed
104 */
105 if ((parser_state->scope->parse_scope.op) &&
4be44fcd
LB
106 ((parser_state->scope->parse_scope.op->common.
107 aml_opcode == AML_IF_OP)
108 || (parser_state->scope->parse_scope.op->common.
109 aml_opcode == AML_WHILE_OP))
110 && (walk_state->control_state)
111 && (walk_state->control_state->common.state ==
112 ACPI_CONTROL_PREDICATE_EXECUTING)) {
73459f73
RM
113 /*
114 * A predicate was just completed, get the value of the
115 * predicate and branch based on that value
116 */
117 walk_state->op = NULL;
4be44fcd
LB
118 status =
119 acpi_ds_get_predicate_value(walk_state,
120 ACPI_TO_POINTER
121 (TRUE));
122 if (ACPI_FAILURE(status)
123 && ((status & AE_CODE_MASK) !=
124 AE_CODE_CONTROL)) {
73459f73 125 if (status == AE_AML_NO_RETURN_VALUE) {
4be44fcd
LB
126 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
127 "Invoked method did not return a value, %s\n",
128 acpi_format_exception
129 (status)));
73459f73
RM
130
131 }
4be44fcd
LB
132 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
133 "get_predicate Failed, %s\n",
134 acpi_format_exception
135 (status)));
136 return_ACPI_STATUS(status);
73459f73
RM
137 }
138
4be44fcd
LB
139 status =
140 acpi_ps_next_parse_state(walk_state, op,
141 status);
73459f73
RM
142 }
143
4be44fcd
LB
144 acpi_ps_pop_scope(parser_state, &op,
145 &walk_state->arg_types,
146 &walk_state->arg_count);
147 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
148 "Popped scope, Op=%p\n", op));
149 } else if (walk_state->prev_op) {
73459f73
RM
150 /* We were in the middle of an op */
151
152 op = walk_state->prev_op;
153 walk_state->arg_types = walk_state->prev_arg_types;
154 }
155 }
156#endif
157
158 /* Iterative parsing loop, while there is more AML to process: */
159
160 while ((parser_state->aml < parser_state->aml_end) || (op)) {
161 aml_op_start = parser_state->aml;
162 if (!op) {
163 /* Get the next opcode from the AML stream */
164
4be44fcd
LB
165 walk_state->aml_offset =
166 (u32) ACPI_PTR_DIFF(parser_state->aml,
167 parser_state->aml_start);
168 walk_state->opcode = acpi_ps_peek_opcode(parser_state);
73459f73
RM
169
170 /*
171 * First cut to determine what we have found:
172 * 1) A valid AML opcode
173 * 2) A name string
174 * 3) An unknown/invalid opcode
175 */
4be44fcd
LB
176 walk_state->op_info =
177 acpi_ps_get_opcode_info(walk_state->opcode);
73459f73
RM
178 switch (walk_state->op_info->class) {
179 case AML_CLASS_ASCII:
180 case AML_CLASS_PREFIX:
181 /*
182 * Starts with a valid prefix or ASCII char, this is a name
183 * string. Convert the bare name string to a namepath.
184 */
185 walk_state->opcode = AML_INT_NAMEPATH_OP;
186 walk_state->arg_types = ARGP_NAMESTRING;
187 break;
188
189 case AML_CLASS_UNKNOWN:
190
191 /* The opcode is unrecognized. Just skip unknown opcodes */
192
4be44fcd
LB
193 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
194 "Found unknown opcode %X at AML address %p offset %X, ignoring\n",
195 walk_state->opcode,
196 parser_state->aml,
197 walk_state->aml_offset));
73459f73 198
4be44fcd 199 ACPI_DUMP_BUFFER(parser_state->aml, 128);
73459f73
RM
200
201 /* Assume one-byte bad opcode */
202
203 parser_state->aml++;
204 continue;
205
206 default:
207
208 /* Found opcode info, this is a normal opcode */
209
4be44fcd
LB
210 parser_state->aml +=
211 acpi_ps_get_opcode_size(walk_state->opcode);
212 walk_state->arg_types =
213 walk_state->op_info->parse_args;
73459f73
RM
214 break;
215 }
216
217 /* Create Op structure and append to parent's argument list */
218
219 if (walk_state->op_info->flags & AML_NAMED) {
220 /* Allocate a new pre_op if necessary */
221
222 if (!pre_op) {
4be44fcd
LB
223 pre_op =
224 acpi_ps_alloc_op(walk_state->
225 opcode);
73459f73
RM
226 if (!pre_op) {
227 status = AE_NO_MEMORY;
228 goto close_this_op;
229 }
230 }
231
232 pre_op->common.value.arg = NULL;
233 pre_op->common.aml_opcode = walk_state->opcode;
234
235 /*
236 * Get and append arguments until we find the node that contains
237 * the name (the type ARGP_NAME).
238 */
4be44fcd
LB
239 while (GET_CURRENT_ARG_TYPE
240 (walk_state->arg_types)
241 &&
242 (GET_CURRENT_ARG_TYPE
243 (walk_state->arg_types) != ARGP_NAME)) {
244 status =
245 acpi_ps_get_next_arg(walk_state,
246 parser_state,
247 GET_CURRENT_ARG_TYPE
248 (walk_state->
249 arg_types),
250 &arg);
251 if (ACPI_FAILURE(status)) {
73459f73
RM
252 goto close_this_op;
253 }
254
4be44fcd
LB
255 acpi_ps_append_arg(pre_op, arg);
256 INCREMENT_ARG_LIST(walk_state->
257 arg_types);
73459f73
RM
258 }
259
260 /*
261 * Make sure that we found a NAME and didn't run out of
262 * arguments
263 */
4be44fcd
LB
264 if (!GET_CURRENT_ARG_TYPE
265 (walk_state->arg_types)) {
73459f73
RM
266 status = AE_AML_NO_OPERAND;
267 goto close_this_op;
268 }
269
270 /* We know that this arg is a name, move to next arg */
271
4be44fcd 272 INCREMENT_ARG_LIST(walk_state->arg_types);
73459f73
RM
273
274 /*
275 * Find the object. This will either insert the object into
276 * the namespace or simply look it up
277 */
278 walk_state->op = NULL;
279
4be44fcd
LB
280 status =
281 walk_state->descending_callback(walk_state,
282 &op);
283 if (ACPI_FAILURE(status)) {
284 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
285 "During name lookup/catalog, %s\n",
286 acpi_format_exception
287 (status)));
73459f73
RM
288 goto close_this_op;
289 }
290
291 if (!op) {
292 continue;
293 }
294
4be44fcd
LB
295 status =
296 acpi_ps_next_parse_state(walk_state, op,
297 status);
73459f73
RM
298 if (status == AE_CTRL_PENDING) {
299 status = AE_OK;
300 goto close_this_op;
301 }
302
4be44fcd 303 if (ACPI_FAILURE(status)) {
73459f73
RM
304 goto close_this_op;
305 }
306
4be44fcd
LB
307 acpi_ps_append_arg(op,
308 pre_op->common.value.arg);
73459f73
RM
309 acpi_gbl_depth++;
310
311 if (op->common.aml_opcode == AML_REGION_OP) {
312 /*
313 * Defer final parsing of an operation_region body,
314 * because we don't have enough info in the first pass
315 * to parse it correctly (i.e., there may be method
316 * calls within the term_arg elements of the body.)
317 *
318 * However, we must continue parsing because
319 * the opregion is not a standalone package --
320 * we don't know where the end is at this point.
321 *
322 * (Length is unknown until parse of the body complete)
323 */
4be44fcd
LB
324 op->named.data = aml_op_start;
325 op->named.length = 0;
73459f73 326 }
4be44fcd 327 } else {
73459f73
RM
328 /* Not a named opcode, just allocate Op and append to parent */
329
4be44fcd
LB
330 walk_state->op_info =
331 acpi_ps_get_opcode_info(walk_state->opcode);
332 op = acpi_ps_alloc_op(walk_state->opcode);
73459f73
RM
333 if (!op) {
334 status = AE_NO_MEMORY;
335 goto close_this_op;
336 }
337
338 if (walk_state->op_info->flags & AML_CREATE) {
339 /*
340 * Backup to beginning of create_xXXfield declaration
341 * body_length is unknown until we parse the body
342 */
4be44fcd
LB
343 op->named.data = aml_op_start;
344 op->named.length = 0;
73459f73
RM
345 }
346
4be44fcd
LB
347 acpi_ps_append_arg(acpi_ps_get_parent_scope
348 (parser_state), op);
73459f73
RM
349
350 if ((walk_state->descending_callback != NULL)) {
351 /*
352 * Find the object. This will either insert the object into
353 * the namespace or simply look it up
354 */
355 walk_state->op = op;
356
4be44fcd
LB
357 status =
358 walk_state->
359 descending_callback(walk_state,
360 &op);
361 status =
362 acpi_ps_next_parse_state(walk_state,
363 op,
364 status);
73459f73
RM
365 if (status == AE_CTRL_PENDING) {
366 status = AE_OK;
367 goto close_this_op;
368 }
369
4be44fcd 370 if (ACPI_FAILURE(status)) {
73459f73
RM
371 goto close_this_op;
372 }
373 }
374 }
375
376 op->common.aml_offset = walk_state->aml_offset;
377
378 if (walk_state->op_info) {
4be44fcd
LB
379 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
380 "Opcode %4.4X [%s] Op %p Aml %p aml_offset %5.5X\n",
381 (u32) op->common.aml_opcode,
382 walk_state->op_info->name, op,
383 parser_state->aml,
384 op->common.aml_offset));
73459f73
RM
385 }
386 }
387
73459f73
RM
388 /*
389 * Start arg_count at zero because we don't know if there are
390 * any args yet
391 */
392 walk_state->arg_count = 0;
393
394 /* Are there any arguments that must be processed? */
395
396 if (walk_state->arg_types) {
397 /* Get arguments */
398
399 switch (op->common.aml_opcode) {
4be44fcd
LB
400 case AML_BYTE_OP: /* AML_BYTEDATA_ARG */
401 case AML_WORD_OP: /* AML_WORDDATA_ARG */
402 case AML_DWORD_OP: /* AML_DWORDATA_ARG */
403 case AML_QWORD_OP: /* AML_QWORDATA_ARG */
404 case AML_STRING_OP: /* AML_ASCIICHARLIST_ARG */
73459f73
RM
405
406 /* Fill in constant or string argument directly */
407
4be44fcd
LB
408 acpi_ps_get_next_simple_arg(parser_state,
409 GET_CURRENT_ARG_TYPE
410 (walk_state->
411 arg_types), op);
73459f73
RM
412 break;
413
4be44fcd 414 case AML_INT_NAMEPATH_OP: /* AML_NAMESTRING_ARG */
73459f73 415
4be44fcd
LB
416 status =
417 acpi_ps_get_next_namepath(walk_state,
418 parser_state, op,
419 1);
420 if (ACPI_FAILURE(status)) {
73459f73
RM
421 goto close_this_op;
422 }
423
424 walk_state->arg_types = 0;
425 break;
426
427 default:
428 /*
429 * Op is not a constant or string, append each argument
430 * to the Op
431 */
4be44fcd
LB
432 while (GET_CURRENT_ARG_TYPE
433 (walk_state->arg_types)
434 && !walk_state->arg_count) {
73459f73 435 walk_state->aml_offset = (u32)
4be44fcd
LB
436 ACPI_PTR_DIFF(parser_state->aml,
437 parser_state->
438 aml_start);
439
440 status =
441 acpi_ps_get_next_arg(walk_state,
442 parser_state,
443 GET_CURRENT_ARG_TYPE
444 (walk_state->
445 arg_types),
446 &arg);
447 if (ACPI_FAILURE(status)) {
73459f73
RM
448 goto close_this_op;
449 }
450
451 if (arg) {
4be44fcd
LB
452 arg->common.aml_offset =
453 walk_state->aml_offset;
454 acpi_ps_append_arg(op, arg);
73459f73 455 }
4be44fcd
LB
456 INCREMENT_ARG_LIST(walk_state->
457 arg_types);
73459f73
RM
458 }
459
460 /* Special processing for certain opcodes */
461
4be44fcd 462 /* TBD (remove): Temporary mechanism to disable this code if needed */
f9f4601f 463
0c9938cc 464#ifdef ACPI_ENABLE_MODULE_LEVEL_CODE
f9f4601f 465
4be44fcd
LB
466 if ((walk_state->pass_number <=
467 ACPI_IMODE_LOAD_PASS1)
468 &&
469 ((walk_state->
470 parse_flags & ACPI_PARSE_DISASSEMBLE) ==
471 0)) {
73459f73
RM
472 /*
473 * We want to skip If/Else/While constructs during Pass1
474 * because we want to actually conditionally execute the
475 * code during Pass2.
476 *
477 * Except for disassembly, where we always want to
478 * walk the If/Else/While packages
479 */
480 switch (op->common.aml_opcode) {
481 case AML_IF_OP:
482 case AML_ELSE_OP:
483 case AML_WHILE_OP:
484
4be44fcd
LB
485 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
486 "Pass1: Skipping an If/Else/While body\n"));
0c9938cc 487
73459f73
RM
488 /* Skip body of if/else/while in pass 1 */
489
4be44fcd
LB
490 parser_state->aml =
491 parser_state->pkg_end;
73459f73
RM
492 walk_state->arg_count = 0;
493 break;
494
495 default:
496 break;
497 }
498 }
f9f4601f 499#endif
73459f73
RM
500 switch (op->common.aml_opcode) {
501 case AML_METHOD_OP:
502
503 /*
504 * Skip parsing of control method
505 * because we don't have enough info in the first pass
506 * to parse it correctly.
507 *
508 * Save the length and address of the body
509 */
4be44fcd
LB
510 op->named.data = parser_state->aml;
511 op->named.length =
512 (u32) (parser_state->pkg_end -
513 parser_state->aml);
73459f73
RM
514
515 /* Skip body of method */
516
4be44fcd
LB
517 parser_state->aml =
518 parser_state->pkg_end;
73459f73
RM
519 walk_state->arg_count = 0;
520 break;
521
522 case AML_BUFFER_OP:
523 case AML_PACKAGE_OP:
524 case AML_VAR_PACKAGE_OP:
525
526 if ((op->common.parent) &&
4be44fcd
LB
527 (op->common.parent->common.
528 aml_opcode == AML_NAME_OP)
529 && (walk_state->pass_number <=
530 ACPI_IMODE_LOAD_PASS2)) {
73459f73
RM
531 /*
532 * Skip parsing of Buffers and Packages
533 * because we don't have enough info in the first pass
534 * to parse them correctly.
535 */
4be44fcd
LB
536 op->named.data = aml_op_start;
537 op->named.length =
538 (u32) (parser_state->
539 pkg_end -
540 aml_op_start);
73459f73
RM
541
542 /* Skip body */
543
4be44fcd
LB
544 parser_state->aml =
545 parser_state->pkg_end;
73459f73
RM
546 walk_state->arg_count = 0;
547 }
548 break;
549
550 case AML_WHILE_OP:
551
552 if (walk_state->control_state) {
4be44fcd
LB
553 walk_state->control_state->
554 control.package_end =
555 parser_state->pkg_end;
73459f73
RM
556 }
557 break;
558
559 default:
560
561 /* No action for all other opcodes */
562 break;
563 }
564 break;
565 }
566 }
567
568 /* Check for arguments that need to be processed */
569
570 if (walk_state->arg_count) {
571 /*
572 * There are arguments (complex ones), push Op and
573 * prepare for argument
574 */
4be44fcd
LB
575 status = acpi_ps_push_scope(parser_state, op,
576 walk_state->arg_types,
577 walk_state->arg_count);
578 if (ACPI_FAILURE(status)) {
73459f73
RM
579 goto close_this_op;
580 }
581 op = NULL;
582 continue;
583 }
584
585 /*
586 * All arguments have been processed -- Op is complete,
587 * prepare for next
588 */
4be44fcd
LB
589 walk_state->op_info =
590 acpi_ps_get_opcode_info(op->common.aml_opcode);
73459f73
RM
591 if (walk_state->op_info->flags & AML_NAMED) {
592 if (acpi_gbl_depth) {
593 acpi_gbl_depth--;
594 }
595
596 if (op->common.aml_opcode == AML_REGION_OP) {
597 /*
598 * Skip parsing of control method or opregion body,
599 * because we don't have enough info in the first pass
600 * to parse them correctly.
601 *
602 * Completed parsing an op_region declaration, we now
603 * know the length.
604 */
4be44fcd
LB
605 op->named.length =
606 (u32) (parser_state->aml - op->named.data);
73459f73
RM
607 }
608 }
609
610 if (walk_state->op_info->flags & AML_CREATE) {
611 /*
612 * Backup to beginning of create_xXXfield declaration (1 for
613 * Opcode)
614 *
615 * body_length is unknown until we parse the body
616 */
4be44fcd
LB
617 op->named.length =
618 (u32) (parser_state->aml - op->named.data);
73459f73
RM
619 }
620
621 /* This op complete, notify the dispatcher */
622
623 if (walk_state->ascending_callback != NULL) {
4be44fcd 624 walk_state->op = op;
73459f73
RM
625 walk_state->opcode = op->common.aml_opcode;
626
4be44fcd
LB
627 status = walk_state->ascending_callback(walk_state);
628 status =
629 acpi_ps_next_parse_state(walk_state, op, status);
73459f73
RM
630 if (status == AE_CTRL_PENDING) {
631 status = AE_OK;
632 goto close_this_op;
633 }
634 }
635
4be44fcd 636 close_this_op:
73459f73
RM
637 /*
638 * Finished one argument of the containing scope
639 */
640 parser_state->scope->parse_scope.arg_count--;
641
642 /* Finished with pre_op */
643
644 if (pre_op) {
4be44fcd 645 acpi_ps_free_op(pre_op);
73459f73
RM
646 pre_op = NULL;
647 }
648
649 /* Close this Op (will result in parse subtree deletion) */
650
4be44fcd
LB
651 status2 = acpi_ps_complete_this_op(walk_state, op);
652 if (ACPI_FAILURE(status2)) {
653 return_ACPI_STATUS(status2);
73459f73
RM
654 }
655 op = NULL;
656
657 switch (status) {
658 case AE_OK:
659 break;
660
73459f73
RM
661 case AE_CTRL_TRANSFER:
662
663 /* We are about to transfer to a called method. */
664
665 walk_state->prev_op = op;
666 walk_state->prev_arg_types = walk_state->arg_types;
4be44fcd 667 return_ACPI_STATUS(status);
73459f73
RM
668
669 case AE_CTRL_END:
670
4be44fcd
LB
671 acpi_ps_pop_scope(parser_state, &op,
672 &walk_state->arg_types,
673 &walk_state->arg_count);
73459f73
RM
674
675 if (op) {
4be44fcd
LB
676 walk_state->op = op;
677 walk_state->op_info =
678 acpi_ps_get_opcode_info(op->common.
679 aml_opcode);
73459f73
RM
680 walk_state->opcode = op->common.aml_opcode;
681
4be44fcd
LB
682 status =
683 walk_state->ascending_callback(walk_state);
684 status =
685 acpi_ps_next_parse_state(walk_state, op,
686 status);
73459f73 687
4be44fcd
LB
688 status2 =
689 acpi_ps_complete_this_op(walk_state, op);
690 if (ACPI_FAILURE(status2)) {
691 return_ACPI_STATUS(status2);
73459f73
RM
692 }
693 op = NULL;
694 }
695 status = AE_OK;
696 break;
697
73459f73
RM
698 case AE_CTRL_BREAK:
699 case AE_CTRL_CONTINUE:
700
701 /* Pop off scopes until we find the While */
702
703 while (!op || (op->common.aml_opcode != AML_WHILE_OP)) {
4be44fcd
LB
704 acpi_ps_pop_scope(parser_state, &op,
705 &walk_state->arg_types,
706 &walk_state->arg_count);
defba1d8
BM
707
708 if (op->common.aml_opcode != AML_WHILE_OP) {
709 status2 =
710 acpi_ds_result_stack_pop
711 (walk_state);
712 if (ACPI_FAILURE(status2)) {
713 return_ACPI_STATUS(status2);
714 }
715 }
73459f73
RM
716 }
717
718 /* Close this iteration of the While loop */
719
4be44fcd
LB
720 walk_state->op = op;
721 walk_state->op_info =
722 acpi_ps_get_opcode_info(op->common.aml_opcode);
73459f73
RM
723 walk_state->opcode = op->common.aml_opcode;
724
4be44fcd
LB
725 status = walk_state->ascending_callback(walk_state);
726 status =
727 acpi_ps_next_parse_state(walk_state, op, status);
73459f73 728
4be44fcd
LB
729 status2 = acpi_ps_complete_this_op(walk_state, op);
730 if (ACPI_FAILURE(status2)) {
731 return_ACPI_STATUS(status2);
73459f73
RM
732 }
733 op = NULL;
734
735 status = AE_OK;
736 break;
737
73459f73
RM
738 case AE_CTRL_TERMINATE:
739
740 status = AE_OK;
741
742 /* Clean up */
743 do {
744 if (op) {
4be44fcd
LB
745 status2 =
746 acpi_ps_complete_this_op(walk_state,
747 op);
748 if (ACPI_FAILURE(status2)) {
749 return_ACPI_STATUS(status2);
73459f73
RM
750 }
751 }
4be44fcd
LB
752 acpi_ps_pop_scope(parser_state, &op,
753 &walk_state->arg_types,
754 &walk_state->arg_count);
73459f73
RM
755
756 } while (op);
757
4be44fcd 758 return_ACPI_STATUS(status);
73459f73 759
4be44fcd 760 default: /* All other non-AE_OK status */
73459f73
RM
761
762 do {
763 if (op) {
4be44fcd
LB
764 status2 =
765 acpi_ps_complete_this_op(walk_state,
766 op);
767 if (ACPI_FAILURE(status2)) {
768 return_ACPI_STATUS(status2);
73459f73
RM
769 }
770 }
4be44fcd
LB
771 acpi_ps_pop_scope(parser_state, &op,
772 &walk_state->arg_types,
773 &walk_state->arg_count);
73459f73
RM
774
775 } while (op);
776
73459f73
RM
777 /*
778 * TBD: Cleanup parse ops on error
779 */
780#if 0
781 if (op == NULL) {
4be44fcd
LB
782 acpi_ps_pop_scope(parser_state, &op,
783 &walk_state->arg_types,
784 &walk_state->arg_count);
73459f73
RM
785 }
786#endif
787 walk_state->prev_op = op;
788 walk_state->prev_arg_types = walk_state->arg_types;
4be44fcd 789 return_ACPI_STATUS(status);
73459f73
RM
790 }
791
792 /* This scope complete? */
793
4be44fcd
LB
794 if (acpi_ps_has_completed_scope(parser_state)) {
795 acpi_ps_pop_scope(parser_state, &op,
796 &walk_state->arg_types,
797 &walk_state->arg_count);
798 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
799 "Popped scope, Op=%p\n", op));
800 } else {
73459f73
RM
801 op = NULL;
802 }
803
4be44fcd 804 } /* while parser_state->Aml */
73459f73
RM
805
806 /*
807 * Complete the last Op (if not completed), and clear the scope stack.
808 * It is easily possible to end an AML "package" with an unbounded number
809 * of open scopes (such as when several ASL blocks are closed with
810 * sequential closing braces). We want to terminate each one cleanly.
811 */
4be44fcd
LB
812 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "AML package complete at Op %p\n",
813 op));
73459f73
RM
814 do {
815 if (op) {
816 if (walk_state->ascending_callback != NULL) {
4be44fcd
LB
817 walk_state->op = op;
818 walk_state->op_info =
819 acpi_ps_get_opcode_info(op->common.
820 aml_opcode);
73459f73
RM
821 walk_state->opcode = op->common.aml_opcode;
822
4be44fcd
LB
823 status =
824 walk_state->ascending_callback(walk_state);
825 status =
826 acpi_ps_next_parse_state(walk_state, op,
827 status);
73459f73
RM
828 if (status == AE_CTRL_PENDING) {
829 status = AE_OK;
830 goto close_this_op;
831 }
832
833 if (status == AE_CTRL_TERMINATE) {
834 status = AE_OK;
835
836 /* Clean up */
837 do {
838 if (op) {
4be44fcd
LB
839 status2 =
840 acpi_ps_complete_this_op
841 (walk_state, op);
842 if (ACPI_FAILURE
843 (status2)) {
844 return_ACPI_STATUS
845 (status2);
73459f73
RM
846 }
847 }
848
4be44fcd
LB
849 acpi_ps_pop_scope(parser_state,
850 &op,
851 &walk_state->
852 arg_types,
853 &walk_state->
854 arg_count);
73459f73
RM
855
856 } while (op);
857
4be44fcd 858 return_ACPI_STATUS(status);
73459f73
RM
859 }
860
4be44fcd 861 else if (ACPI_FAILURE(status)) {
73459f73
RM
862 /* First error is most important */
863
4be44fcd
LB
864 (void)
865 acpi_ps_complete_this_op(walk_state,
866 op);
867 return_ACPI_STATUS(status);
73459f73
RM
868 }
869 }
870
4be44fcd
LB
871 status2 = acpi_ps_complete_this_op(walk_state, op);
872 if (ACPI_FAILURE(status2)) {
873 return_ACPI_STATUS(status2);
73459f73
RM
874 }
875 }
876
4be44fcd
LB
877 acpi_ps_pop_scope(parser_state, &op, &walk_state->arg_types,
878 &walk_state->arg_count);
73459f73
RM
879
880 } while (op);
881
4be44fcd 882 return_ACPI_STATUS(status);
73459f73 883}