blob: 8cbe361593769ae01b8df9a091c818e237518062 [file] [log] [blame]
Bob Moore42f8fb72013-01-11 13:08:51 +01001/******************************************************************************
2 *
3 * Module Name: psobject - Support for parse objects
4 *
5 *****************************************************************************/
6
7/*
Bob Moore7735ca02017-02-08 11:00:08 +08008 * Copyright (C) 2000 - 2017, Intel Corp.
Bob Moore42f8fb72013-01-11 13:08:51 +01009 * 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
44#include <acpi/acpi.h>
45#include "accommon.h"
46#include "acparser.h"
47#include "amlcode.h"
Bob Moore9cf7ade2017-04-28 08:53:22 +080048#include "acconvert.h"
Bob Moore42f8fb72013-01-11 13:08:51 +010049
50#define _COMPONENT ACPI_PARSER
51ACPI_MODULE_NAME("psobject")
52
53/* Local prototypes */
54static acpi_status acpi_ps_get_aml_opcode(struct acpi_walk_state *walk_state);
55
56/*******************************************************************************
57 *
58 * FUNCTION: acpi_ps_get_aml_opcode
59 *
60 * PARAMETERS: walk_state - Current state
61 *
62 * RETURN: Status
63 *
64 * DESCRIPTION: Extract the next AML opcode from the input stream.
65 *
66 ******************************************************************************/
67
68static acpi_status acpi_ps_get_aml_opcode(struct acpi_walk_state *walk_state)
69{
Lv Zheng83482f72015-07-23 12:52:11 +080070 u32 aml_offset;
Bob Moore42f8fb72013-01-11 13:08:51 +010071
72 ACPI_FUNCTION_TRACE_PTR(ps_get_aml_opcode, walk_state);
73
Lv Zheng83482f72015-07-23 12:52:11 +080074 walk_state->aml = walk_state->parser_state.aml;
Bob Moore42f8fb72013-01-11 13:08:51 +010075 walk_state->opcode = acpi_ps_peek_opcode(&(walk_state->parser_state));
76
77 /*
78 * First cut to determine what we have found:
79 * 1) A valid AML opcode
80 * 2) A name string
81 * 3) An unknown/invalid opcode
82 */
83 walk_state->op_info = acpi_ps_get_opcode_info(walk_state->opcode);
84
85 switch (walk_state->op_info->class) {
86 case AML_CLASS_ASCII:
87 case AML_CLASS_PREFIX:
88 /*
89 * Starts with a valid prefix or ASCII char, this is a name
90 * string. Convert the bare name string to a namepath.
91 */
92 walk_state->opcode = AML_INT_NAMEPATH_OP;
93 walk_state->arg_types = ARGP_NAMESTRING;
94 break;
95
96 case AML_CLASS_UNKNOWN:
97
98 /* The opcode is unrecognized. Complain and skip unknown opcodes */
99
100 if (walk_state->pass_number == 2) {
Lv Zheng83482f72015-07-23 12:52:11 +0800101 aml_offset = (u32)ACPI_PTR_DIFF(walk_state->aml,
102 walk_state->
103 parser_state.aml_start);
104
Bob Moore42f8fb72013-01-11 13:08:51 +0100105 ACPI_ERROR((AE_INFO,
106 "Unknown opcode 0x%.2X at table offset 0x%.4X, ignoring",
107 walk_state->opcode,
Lv Zheng83482f72015-07-23 12:52:11 +0800108 (u32)(aml_offset +
Bob Moore42f8fb72013-01-11 13:08:51 +0100109 sizeof(struct acpi_table_header))));
110
111 ACPI_DUMP_BUFFER((walk_state->parser_state.aml - 16),
112 48);
113
114#ifdef ACPI_ASL_COMPILER
115 /*
116 * This is executed for the disassembler only. Output goes
117 * to the disassembled ASL output file.
118 */
119 acpi_os_printf
120 ("/*\nError: Unknown opcode 0x%.2X at table offset 0x%.4X, context:\n",
121 walk_state->opcode,
Lv Zheng83482f72015-07-23 12:52:11 +0800122 (u32)(aml_offset +
Bob Moore42f8fb72013-01-11 13:08:51 +0100123 sizeof(struct acpi_table_header)));
124
Bob Moore6f0527b2017-06-05 16:40:34 +0800125 ACPI_ERROR((AE_INFO,
126 "Aborting disassembly, AML byte code is corrupt"));
127
Bob Moore42f8fb72013-01-11 13:08:51 +0100128 /* Dump the context surrounding the invalid opcode */
129
130 acpi_ut_dump_buffer(((u8 *)walk_state->parser_state.
131 aml - 16), 48, DB_BYTE_DISPLAY,
Lv Zheng83482f72015-07-23 12:52:11 +0800132 (aml_offset +
Bob Moore42f8fb72013-01-11 13:08:51 +0100133 sizeof(struct acpi_table_header) -
134 16));
135 acpi_os_printf(" */\n");
Bob Moore6f0527b2017-06-05 16:40:34 +0800136
137 /*
138 * Just abort the disassembly, cannot continue because the
139 * parser is essentially lost. The disassembler can then
140 * randomly fail because an ill-constructed parse tree
141 * can result.
142 */
143 return_ACPI_STATUS(AE_AML_BAD_OPCODE);
Bob Moore42f8fb72013-01-11 13:08:51 +0100144#endif
145 }
146
147 /* Increment past one-byte or two-byte opcode */
148
149 walk_state->parser_state.aml++;
150 if (walk_state->opcode > 0xFF) { /* Can only happen if first byte is 0x5B */
151 walk_state->parser_state.aml++;
152 }
153
154 return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE);
155
156 default:
157
158 /* Found opcode info, this is a normal opcode */
159
160 walk_state->parser_state.aml +=
161 acpi_ps_get_opcode_size(walk_state->opcode);
162 walk_state->arg_types = walk_state->op_info->parse_args;
163 break;
164 }
165
166 return_ACPI_STATUS(AE_OK);
167}
168
169/*******************************************************************************
170 *
171 * FUNCTION: acpi_ps_build_named_op
172 *
173 * PARAMETERS: walk_state - Current state
174 * aml_op_start - Begin of named Op in AML
175 * unnamed_op - Early Op (not a named Op)
176 * op - Returned Op
177 *
178 * RETURN: Status
179 *
180 * DESCRIPTION: Parse a named Op
181 *
182 ******************************************************************************/
183
184acpi_status
185acpi_ps_build_named_op(struct acpi_walk_state *walk_state,
186 u8 *aml_op_start,
187 union acpi_parse_object *unnamed_op,
188 union acpi_parse_object **op)
189{
190 acpi_status status = AE_OK;
191 union acpi_parse_object *arg = NULL;
192
193 ACPI_FUNCTION_TRACE_PTR(ps_build_named_op, walk_state);
194
195 unnamed_op->common.value.arg = NULL;
196 unnamed_op->common.arg_list_length = 0;
197 unnamed_op->common.aml_opcode = walk_state->opcode;
198
199 /*
200 * Get and append arguments until we find the node that contains
201 * the name (the type ARGP_NAME).
202 */
203 while (GET_CURRENT_ARG_TYPE(walk_state->arg_types) &&
204 (GET_CURRENT_ARG_TYPE(walk_state->arg_types) != ARGP_NAME)) {
Bob Moore9cf7ade2017-04-28 08:53:22 +0800205 ASL_CV_CAPTURE_COMMENTS(walk_state);
Bob Moore42f8fb72013-01-11 13:08:51 +0100206 status =
207 acpi_ps_get_next_arg(walk_state,
208 &(walk_state->parser_state),
209 GET_CURRENT_ARG_TYPE(walk_state->
210 arg_types), &arg);
211 if (ACPI_FAILURE(status)) {
212 return_ACPI_STATUS(status);
213 }
214
215 acpi_ps_append_arg(unnamed_op, arg);
216 INCREMENT_ARG_LIST(walk_state->arg_types);
217 }
218
Bob Moore9cf7ade2017-04-28 08:53:22 +0800219 /* are there any inline comments associated with the name_seg?? If so, save this. */
220
221 ASL_CV_CAPTURE_COMMENTS(walk_state);
222
223#ifdef ACPI_ASL_COMPILER
224 if (acpi_gbl_current_inline_comment != NULL) {
225 unnamed_op->common.name_comment =
226 acpi_gbl_current_inline_comment;
227 acpi_gbl_current_inline_comment = NULL;
228 }
229#endif
230
Bob Moore42f8fb72013-01-11 13:08:51 +0100231 /*
232 * Make sure that we found a NAME and didn't run out of arguments
233 */
234 if (!GET_CURRENT_ARG_TYPE(walk_state->arg_types)) {
235 return_ACPI_STATUS(AE_AML_NO_OPERAND);
236 }
237
238 /* We know that this arg is a name, move to next arg */
239
240 INCREMENT_ARG_LIST(walk_state->arg_types);
241
242 /*
243 * Find the object. This will either insert the object into
244 * the namespace or simply look it up
245 */
246 walk_state->op = NULL;
247
248 status = walk_state->descending_callback(walk_state, op);
249 if (ACPI_FAILURE(status)) {
Bob Moore22b5afc2014-03-24 14:49:00 +0800250 if (status != AE_CTRL_TERMINATE) {
251 ACPI_EXCEPTION((AE_INFO, status,
252 "During name lookup/catalog"));
253 }
Bob Moore42f8fb72013-01-11 13:08:51 +0100254 return_ACPI_STATUS(status);
255 }
256
257 if (!*op) {
258 return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE);
259 }
260
261 status = acpi_ps_next_parse_state(walk_state, *op, status);
262 if (ACPI_FAILURE(status)) {
263 if (status == AE_CTRL_PENDING) {
Bob Moore22b5afc2014-03-24 14:49:00 +0800264 status = AE_CTRL_PARSE_PENDING;
Bob Moore42f8fb72013-01-11 13:08:51 +0100265 }
266 return_ACPI_STATUS(status);
267 }
268
269 acpi_ps_append_arg(*op, unnamed_op->common.value.arg);
270
Bob Moore9cf7ade2017-04-28 08:53:22 +0800271#ifdef ACPI_ASL_COMPILER
272
273 /* save any comments that might be associated with unnamed_op. */
274
275 (*op)->common.inline_comment = unnamed_op->common.inline_comment;
276 (*op)->common.end_node_comment = unnamed_op->common.end_node_comment;
277 (*op)->common.close_brace_comment =
278 unnamed_op->common.close_brace_comment;
279 (*op)->common.name_comment = unnamed_op->common.name_comment;
280 (*op)->common.comment_list = unnamed_op->common.comment_list;
281 (*op)->common.end_blk_comment = unnamed_op->common.end_blk_comment;
282 (*op)->common.cv_filename = unnamed_op->common.cv_filename;
283 (*op)->common.cv_parent_filename =
284 unnamed_op->common.cv_parent_filename;
285 (*op)->named.aml = unnamed_op->common.aml;
286
287 unnamed_op->common.inline_comment = NULL;
288 unnamed_op->common.end_node_comment = NULL;
289 unnamed_op->common.close_brace_comment = NULL;
290 unnamed_op->common.name_comment = NULL;
291 unnamed_op->common.comment_list = NULL;
292 unnamed_op->common.end_blk_comment = NULL;
293#endif
294
Bob Moore42f8fb72013-01-11 13:08:51 +0100295 if ((*op)->common.aml_opcode == AML_REGION_OP ||
296 (*op)->common.aml_opcode == AML_DATA_REGION_OP) {
297 /*
298 * Defer final parsing of an operation_region body, because we don't
299 * have enough info in the first pass to parse it correctly (i.e.,
300 * there may be method calls within the term_arg elements of the body.)
301 *
302 * However, we must continue parsing because the opregion is not a
303 * standalone package -- we don't know where the end is at this point.
304 *
305 * (Length is unknown until parse of the body complete)
306 */
307 (*op)->named.data = aml_op_start;
308 (*op)->named.length = 0;
309 }
310
311 return_ACPI_STATUS(AE_OK);
312}
313
314/*******************************************************************************
315 *
316 * FUNCTION: acpi_ps_create_op
317 *
318 * PARAMETERS: walk_state - Current state
319 * aml_op_start - Op start in AML
320 * new_op - Returned Op
321 *
322 * RETURN: Status
323 *
324 * DESCRIPTION: Get Op from AML
325 *
326 ******************************************************************************/
327
328acpi_status
329acpi_ps_create_op(struct acpi_walk_state *walk_state,
330 u8 *aml_op_start, union acpi_parse_object **new_op)
331{
332 acpi_status status = AE_OK;
333 union acpi_parse_object *op;
334 union acpi_parse_object *named_op = NULL;
335 union acpi_parse_object *parent_scope;
336 u8 argument_count;
337 const struct acpi_opcode_info *op_info;
338
339 ACPI_FUNCTION_TRACE_PTR(ps_create_op, walk_state);
340
341 status = acpi_ps_get_aml_opcode(walk_state);
342 if (status == AE_CTRL_PARSE_CONTINUE) {
343 return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE);
344 }
Bob Moore6f0527b2017-06-05 16:40:34 +0800345 if (ACPI_FAILURE(status)) {
346 return_ACPI_STATUS(status);
347 }
Bob Moore42f8fb72013-01-11 13:08:51 +0100348
349 /* Create Op structure and append to parent's argument list */
350
351 walk_state->op_info = acpi_ps_get_opcode_info(walk_state->opcode);
Lv Zheng62eb9352015-07-23 12:52:24 +0800352 op = acpi_ps_alloc_op(walk_state->opcode, aml_op_start);
Bob Moore42f8fb72013-01-11 13:08:51 +0100353 if (!op) {
354 return_ACPI_STATUS(AE_NO_MEMORY);
355 }
356
357 if (walk_state->op_info->flags & AML_NAMED) {
358 status =
359 acpi_ps_build_named_op(walk_state, aml_op_start, op,
360 &named_op);
361 acpi_ps_free_op(op);
Erik Schmauss3f20ea12017-07-10 15:24:09 +0800362
363#ifdef ACPI_ASL_COMPILER
364 if (acpi_gbl_disasm_flag
365 && walk_state->opcode == AML_EXTERNAL_OP
366 && status == AE_NOT_FOUND) {
367 /*
368 * If parsing of AML_EXTERNAL_OP's name path fails, then skip
369 * past this opcode and keep parsing. This is a much better
370 * alternative than to abort the entire disassembler. At this
371 * point, the parser_state is at the end of the namepath of the
372 * external declaration opcode. Setting walk_state->Aml to
373 * walk_state->parser_state.Aml + 2 moves increments the
374 * walk_state->Aml past the object type and the paramcount of the
375 * external opcode. For the error message, only print the AML
376 * offset. We could attempt to print the name but this may cause
377 * a segmentation fault when printing the namepath because the
378 * AML may be incorrect.
379 */
380 acpi_os_printf
381 ("// Invalid external declaration at AML offset 0x%x.\n",
382 walk_state->aml -
383 walk_state->parser_state.aml_start);
384 walk_state->aml = walk_state->parser_state.aml + 2;
Erik Schmauss5c746632017-11-17 15:40:15 -0800385 walk_state->parser_state.aml = walk_state->aml;
Erik Schmauss3f20ea12017-07-10 15:24:09 +0800386 return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE);
387 }
388#endif
Bob Moore42f8fb72013-01-11 13:08:51 +0100389 if (ACPI_FAILURE(status)) {
390 return_ACPI_STATUS(status);
391 }
392
393 *new_op = named_op;
394 return_ACPI_STATUS(AE_OK);
395 }
396
397 /* Not a named opcode, just allocate Op and append to parent */
398
399 if (walk_state->op_info->flags & AML_CREATE) {
400 /*
401 * Backup to beginning of create_XXXfield declaration
402 * body_length is unknown until we parse the body
403 */
404 op->named.data = aml_op_start;
405 op->named.length = 0;
406 }
407
408 if (walk_state->opcode == AML_BANK_FIELD_OP) {
409 /*
410 * Backup to beginning of bank_field declaration
411 * body_length is unknown until we parse the body
412 */
413 op->named.data = aml_op_start;
414 op->named.length = 0;
415 }
416
417 parent_scope = acpi_ps_get_parent_scope(&(walk_state->parser_state));
418 acpi_ps_append_arg(parent_scope, op);
419
420 if (parent_scope) {
421 op_info =
422 acpi_ps_get_opcode_info(parent_scope->common.aml_opcode);
423 if (op_info->flags & AML_HAS_TARGET) {
424 argument_count =
425 acpi_ps_get_argument_count(op_info->type);
426 if (parent_scope->common.arg_list_length >
427 argument_count) {
428 op->common.flags |= ACPI_PARSEOP_TARGET;
429 }
Bob Moorece87e092016-12-28 15:29:43 +0800430 }
431
432 /*
433 * Special case for both Increment() and Decrement(), where
434 * the lone argument is both a source and a target.
435 */
436 else if ((parent_scope->common.aml_opcode == AML_INCREMENT_OP)
437 || (parent_scope->common.aml_opcode ==
438 AML_DECREMENT_OP)) {
Bob Moore42f8fb72013-01-11 13:08:51 +0100439 op->common.flags |= ACPI_PARSEOP_TARGET;
440 }
441 }
442
443 if (walk_state->descending_callback != NULL) {
444 /*
445 * Find the object. This will either insert the object into
446 * the namespace or simply look it up
447 */
448 walk_state->op = *new_op = op;
449
450 status = walk_state->descending_callback(walk_state, &op);
451 status = acpi_ps_next_parse_state(walk_state, op, status);
452 if (status == AE_CTRL_PENDING) {
453 status = AE_CTRL_PARSE_PENDING;
454 }
455 }
456
457 return_ACPI_STATUS(status);
458}
459
460/*******************************************************************************
461 *
462 * FUNCTION: acpi_ps_complete_op
463 *
464 * PARAMETERS: walk_state - Current state
465 * op - Returned Op
466 * status - Parse status before complete Op
467 *
468 * RETURN: Status
469 *
470 * DESCRIPTION: Complete Op
471 *
472 ******************************************************************************/
473
474acpi_status
475acpi_ps_complete_op(struct acpi_walk_state *walk_state,
476 union acpi_parse_object **op, acpi_status status)
477{
478 acpi_status status2;
479
480 ACPI_FUNCTION_TRACE_PTR(ps_complete_op, walk_state);
481
482 /*
483 * Finished one argument of the containing scope
484 */
485 walk_state->parser_state.scope->parse_scope.arg_count--;
486
487 /* Close this Op (will result in parse subtree deletion) */
488
489 status2 = acpi_ps_complete_this_op(walk_state, *op);
490 if (ACPI_FAILURE(status2)) {
491 return_ACPI_STATUS(status2);
492 }
493
494 *op = NULL;
495
496 switch (status) {
497 case AE_OK:
Chao Guan1d1ea1b72013-06-08 00:58:14 +0000498
Bob Moore42f8fb72013-01-11 13:08:51 +0100499 break;
500
501 case AE_CTRL_TRANSFER:
502
503 /* We are about to transfer to a called method */
504
505 walk_state->prev_op = NULL;
506 walk_state->prev_arg_types = walk_state->arg_types;
507 return_ACPI_STATUS(status);
508
509 case AE_CTRL_END:
510
511 acpi_ps_pop_scope(&(walk_state->parser_state), op,
512 &walk_state->arg_types,
513 &walk_state->arg_count);
514
515 if (*op) {
516 walk_state->op = *op;
517 walk_state->op_info =
518 acpi_ps_get_opcode_info((*op)->common.aml_opcode);
519 walk_state->opcode = (*op)->common.aml_opcode;
520
521 status = walk_state->ascending_callback(walk_state);
522 status =
523 acpi_ps_next_parse_state(walk_state, *op, status);
524
525 status2 = acpi_ps_complete_this_op(walk_state, *op);
526 if (ACPI_FAILURE(status2)) {
527 return_ACPI_STATUS(status2);
528 }
529 }
530
531 status = AE_OK;
532 break;
533
534 case AE_CTRL_BREAK:
535 case AE_CTRL_CONTINUE:
536
537 /* Pop off scopes until we find the While */
538
539 while (!(*op) || ((*op)->common.aml_opcode != AML_WHILE_OP)) {
540 acpi_ps_pop_scope(&(walk_state->parser_state), op,
541 &walk_state->arg_types,
542 &walk_state->arg_count);
543 }
544
545 /* Close this iteration of the While loop */
546
547 walk_state->op = *op;
548 walk_state->op_info =
549 acpi_ps_get_opcode_info((*op)->common.aml_opcode);
550 walk_state->opcode = (*op)->common.aml_opcode;
551
552 status = walk_state->ascending_callback(walk_state);
553 status = acpi_ps_next_parse_state(walk_state, *op, status);
554
555 status2 = acpi_ps_complete_this_op(walk_state, *op);
556 if (ACPI_FAILURE(status2)) {
557 return_ACPI_STATUS(status2);
558 }
559
560 status = AE_OK;
561 break;
562
563 case AE_CTRL_TERMINATE:
564
565 /* Clean up */
566 do {
567 if (*op) {
568 status2 =
569 acpi_ps_complete_this_op(walk_state, *op);
570 if (ACPI_FAILURE(status2)) {
571 return_ACPI_STATUS(status2);
572 }
573
574 acpi_ut_delete_generic_state
575 (acpi_ut_pop_generic_state
576 (&walk_state->control_state));
577 }
578
579 acpi_ps_pop_scope(&(walk_state->parser_state), op,
580 &walk_state->arg_types,
581 &walk_state->arg_count);
582
583 } while (*op);
584
585 return_ACPI_STATUS(AE_OK);
586
587 default: /* All other non-AE_OK status */
588
589 do {
590 if (*op) {
591 status2 =
592 acpi_ps_complete_this_op(walk_state, *op);
593 if (ACPI_FAILURE(status2)) {
594 return_ACPI_STATUS(status2);
595 }
596 }
597
598 acpi_ps_pop_scope(&(walk_state->parser_state), op,
599 &walk_state->arg_types,
600 &walk_state->arg_count);
601
602 } while (*op);
603
604#if 0
605 /*
606 * TBD: Cleanup parse ops on error
607 */
608 if (*op == NULL) {
609 acpi_ps_pop_scope(parser_state, op,
610 &walk_state->arg_types,
611 &walk_state->arg_count);
612 }
613#endif
614 walk_state->prev_op = NULL;
615 walk_state->prev_arg_types = walk_state->arg_types;
616 return_ACPI_STATUS(status);
617 }
618
619 /* This scope complete? */
620
621 if (acpi_ps_has_completed_scope(&(walk_state->parser_state))) {
622 acpi_ps_pop_scope(&(walk_state->parser_state), op,
623 &walk_state->arg_types,
624 &walk_state->arg_count);
625 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Popped scope, Op=%p\n", *op));
626 } else {
627 *op = NULL;
628 }
629
630 return_ACPI_STATUS(AE_OK);
631}
632
633/*******************************************************************************
634 *
635 * FUNCTION: acpi_ps_complete_final_op
636 *
637 * PARAMETERS: walk_state - Current state
638 * op - Current Op
639 * status - Current parse status before complete last
640 * Op
641 *
642 * RETURN: Status
643 *
644 * DESCRIPTION: Complete last Op.
645 *
646 ******************************************************************************/
647
648acpi_status
649acpi_ps_complete_final_op(struct acpi_walk_state *walk_state,
650 union acpi_parse_object *op, acpi_status status)
651{
652 acpi_status status2;
653
654 ACPI_FUNCTION_TRACE_PTR(ps_complete_final_op, walk_state);
655
656 /*
657 * Complete the last Op (if not completed), and clear the scope stack.
658 * It is easily possible to end an AML "package" with an unbounded number
659 * of open scopes (such as when several ASL blocks are closed with
660 * sequential closing braces). We want to terminate each one cleanly.
661 */
662 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "AML package complete at Op %p\n",
663 op));
664 do {
665 if (op) {
666 if (walk_state->ascending_callback != NULL) {
667 walk_state->op = op;
668 walk_state->op_info =
669 acpi_ps_get_opcode_info(op->common.
670 aml_opcode);
671 walk_state->opcode = op->common.aml_opcode;
672
673 status =
674 walk_state->ascending_callback(walk_state);
675 status =
676 acpi_ps_next_parse_state(walk_state, op,
677 status);
678 if (status == AE_CTRL_PENDING) {
679 status =
680 acpi_ps_complete_op(walk_state, &op,
681 AE_OK);
682 if (ACPI_FAILURE(status)) {
683 return_ACPI_STATUS(status);
684 }
685 }
686
687 if (status == AE_CTRL_TERMINATE) {
688 status = AE_OK;
689
690 /* Clean up */
691 do {
692 if (op) {
693 status2 =
694 acpi_ps_complete_this_op
695 (walk_state, op);
696 if (ACPI_FAILURE
697 (status2)) {
698 return_ACPI_STATUS
699 (status2);
700 }
701 }
702
703 acpi_ps_pop_scope(&
704 (walk_state->
705 parser_state),
706 &op,
707 &walk_state->
708 arg_types,
709 &walk_state->
710 arg_count);
711
712 } while (op);
713
714 return_ACPI_STATUS(status);
715 }
716
717 else if (ACPI_FAILURE(status)) {
718
719 /* First error is most important */
720
721 (void)
722 acpi_ps_complete_this_op(walk_state,
723 op);
724 return_ACPI_STATUS(status);
725 }
726 }
727
728 status2 = acpi_ps_complete_this_op(walk_state, op);
729 if (ACPI_FAILURE(status2)) {
730 return_ACPI_STATUS(status2);
731 }
732 }
733
734 acpi_ps_pop_scope(&(walk_state->parser_state), &op,
735 &walk_state->arg_types,
736 &walk_state->arg_count);
737
738 } while (op);
739
740 return_ACPI_STATUS(status);
741}