psloop.c 22 KB

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