psloop.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  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_EXCEPTION((AE_INFO, status,
  114. "Invoked method did not return a value"));
  115. }
  116. ACPI_EXCEPTION((AE_INFO, status,
  117. "get_predicate Failed"));
  118. return_ACPI_STATUS(status);
  119. }
  120. status =
  121. acpi_ps_next_parse_state(walk_state, op,
  122. status);
  123. }
  124. acpi_ps_pop_scope(parser_state, &op,
  125. &walk_state->arg_types,
  126. &walk_state->arg_count);
  127. ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
  128. "Popped scope, Op=%p\n", op));
  129. } else if (walk_state->prev_op) {
  130. /* We were in the middle of an op */
  131. op = walk_state->prev_op;
  132. walk_state->arg_types = walk_state->prev_arg_types;
  133. }
  134. }
  135. #endif
  136. /* Iterative parsing loop, while there is more AML to process: */
  137. while ((parser_state->aml < parser_state->aml_end) || (op)) {
  138. aml_op_start = parser_state->aml;
  139. if (!op) {
  140. /* Get the next opcode from the AML stream */
  141. walk_state->aml_offset =
  142. (u32) ACPI_PTR_DIFF(parser_state->aml,
  143. parser_state->aml_start);
  144. walk_state->opcode = acpi_ps_peek_opcode(parser_state);
  145. /*
  146. * First cut to determine what we have found:
  147. * 1) A valid AML opcode
  148. * 2) A name string
  149. * 3) An unknown/invalid opcode
  150. */
  151. walk_state->op_info =
  152. acpi_ps_get_opcode_info(walk_state->opcode);
  153. switch (walk_state->op_info->class) {
  154. case AML_CLASS_ASCII:
  155. case AML_CLASS_PREFIX:
  156. /*
  157. * Starts with a valid prefix or ASCII char, this is a name
  158. * string. Convert the bare name string to a namepath.
  159. */
  160. walk_state->opcode = AML_INT_NAMEPATH_OP;
  161. walk_state->arg_types = ARGP_NAMESTRING;
  162. break;
  163. case AML_CLASS_UNKNOWN:
  164. /* The opcode is unrecognized. Just skip unknown opcodes */
  165. ACPI_ERROR((AE_INFO,
  166. "Found unknown opcode %X at AML address %p offset %X, ignoring",
  167. walk_state->opcode,
  168. parser_state->aml,
  169. walk_state->aml_offset));
  170. ACPI_DUMP_BUFFER(parser_state->aml, 128);
  171. /* Assume one-byte bad opcode */
  172. parser_state->aml++;
  173. continue;
  174. default:
  175. /* Found opcode info, this is a normal opcode */
  176. parser_state->aml +=
  177. acpi_ps_get_opcode_size(walk_state->opcode);
  178. walk_state->arg_types =
  179. walk_state->op_info->parse_args;
  180. break;
  181. }
  182. /* Create Op structure and append to parent's argument list */
  183. if (walk_state->op_info->flags & AML_NAMED) {
  184. /* Allocate a new pre_op if necessary */
  185. if (!pre_op) {
  186. pre_op =
  187. acpi_ps_alloc_op(walk_state->
  188. opcode);
  189. if (!pre_op) {
  190. status = AE_NO_MEMORY;
  191. goto close_this_op;
  192. }
  193. }
  194. pre_op->common.value.arg = NULL;
  195. pre_op->common.aml_opcode = walk_state->opcode;
  196. /*
  197. * Get and append arguments until we find the node that contains
  198. * the name (the type ARGP_NAME).
  199. */
  200. while (GET_CURRENT_ARG_TYPE
  201. (walk_state->arg_types)
  202. &&
  203. (GET_CURRENT_ARG_TYPE
  204. (walk_state->arg_types) != ARGP_NAME)) {
  205. status =
  206. acpi_ps_get_next_arg(walk_state,
  207. parser_state,
  208. GET_CURRENT_ARG_TYPE
  209. (walk_state->
  210. arg_types),
  211. &arg);
  212. if (ACPI_FAILURE(status)) {
  213. goto close_this_op;
  214. }
  215. acpi_ps_append_arg(pre_op, arg);
  216. INCREMENT_ARG_LIST(walk_state->
  217. arg_types);
  218. }
  219. /*
  220. * Make sure that we found a NAME and didn't run out of
  221. * arguments
  222. */
  223. if (!GET_CURRENT_ARG_TYPE
  224. (walk_state->arg_types)) {
  225. status = AE_AML_NO_OPERAND;
  226. goto close_this_op;
  227. }
  228. /* We know that this arg is a name, move to next arg */
  229. INCREMENT_ARG_LIST(walk_state->arg_types);
  230. /*
  231. * Find the object. This will either insert the object into
  232. * the namespace or simply look it up
  233. */
  234. walk_state->op = NULL;
  235. status =
  236. walk_state->descending_callback(walk_state,
  237. &op);
  238. if (ACPI_FAILURE(status)) {
  239. ACPI_EXCEPTION((AE_INFO, status,
  240. "During name lookup/catalog"));
  241. goto close_this_op;
  242. }
  243. if (!op) {
  244. continue;
  245. }
  246. status =
  247. acpi_ps_next_parse_state(walk_state, op,
  248. status);
  249. if (status == AE_CTRL_PENDING) {
  250. status = AE_OK;
  251. goto close_this_op;
  252. }
  253. if (ACPI_FAILURE(status)) {
  254. goto close_this_op;
  255. }
  256. acpi_ps_append_arg(op,
  257. pre_op->common.value.arg);
  258. acpi_gbl_depth++;
  259. if (op->common.aml_opcode == AML_REGION_OP) {
  260. /*
  261. * Defer final parsing of an operation_region body,
  262. * because we don't have enough info in the first pass
  263. * to parse it correctly (i.e., there may be method
  264. * calls within the term_arg elements of the body.)
  265. *
  266. * However, we must continue parsing because
  267. * the opregion is not a standalone package --
  268. * we don't know where the end is at this point.
  269. *
  270. * (Length is unknown until parse of the body complete)
  271. */
  272. op->named.data = aml_op_start;
  273. op->named.length = 0;
  274. }
  275. } else {
  276. /* Not a named opcode, just allocate Op and append to parent */
  277. walk_state->op_info =
  278. acpi_ps_get_opcode_info(walk_state->opcode);
  279. op = acpi_ps_alloc_op(walk_state->opcode);
  280. if (!op) {
  281. status = AE_NO_MEMORY;
  282. goto close_this_op;
  283. }
  284. if (walk_state->op_info->flags & AML_CREATE) {
  285. /*
  286. * Backup to beginning of create_xXXfield declaration
  287. * body_length is unknown until we parse the body
  288. */
  289. op->named.data = aml_op_start;
  290. op->named.length = 0;
  291. }
  292. acpi_ps_append_arg(acpi_ps_get_parent_scope
  293. (parser_state), op);
  294. if ((walk_state->descending_callback != NULL)) {
  295. /*
  296. * Find the object. This will either insert the object into
  297. * the namespace or simply look it up
  298. */
  299. walk_state->op = op;
  300. status =
  301. walk_state->
  302. descending_callback(walk_state,
  303. &op);
  304. status =
  305. acpi_ps_next_parse_state(walk_state,
  306. op,
  307. status);
  308. if (status == AE_CTRL_PENDING) {
  309. status = AE_OK;
  310. goto close_this_op;
  311. }
  312. if (ACPI_FAILURE(status)) {
  313. goto close_this_op;
  314. }
  315. }
  316. }
  317. op->common.aml_offset = walk_state->aml_offset;
  318. if (walk_state->op_info) {
  319. ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
  320. "Opcode %4.4X [%s] Op %p Aml %p aml_offset %5.5X\n",
  321. (u32) op->common.aml_opcode,
  322. walk_state->op_info->name, op,
  323. parser_state->aml,
  324. op->common.aml_offset));
  325. }
  326. }
  327. /*
  328. * Start arg_count at zero because we don't know if there are
  329. * any args yet
  330. */
  331. walk_state->arg_count = 0;
  332. /* Are there any arguments that must be processed? */
  333. if (walk_state->arg_types) {
  334. /* Get arguments */
  335. switch (op->common.aml_opcode) {
  336. case AML_BYTE_OP: /* AML_BYTEDATA_ARG */
  337. case AML_WORD_OP: /* AML_WORDDATA_ARG */
  338. case AML_DWORD_OP: /* AML_DWORDATA_ARG */
  339. case AML_QWORD_OP: /* AML_QWORDATA_ARG */
  340. case AML_STRING_OP: /* AML_ASCIICHARLIST_ARG */
  341. /* Fill in constant or string argument directly */
  342. acpi_ps_get_next_simple_arg(parser_state,
  343. GET_CURRENT_ARG_TYPE
  344. (walk_state->
  345. arg_types), op);
  346. break;
  347. case AML_INT_NAMEPATH_OP: /* AML_NAMESTRING_ARG */
  348. status =
  349. acpi_ps_get_next_namepath(walk_state,
  350. parser_state, op,
  351. 1);
  352. if (ACPI_FAILURE(status)) {
  353. goto close_this_op;
  354. }
  355. walk_state->arg_types = 0;
  356. break;
  357. default:
  358. /*
  359. * Op is not a constant or string, append each argument
  360. * to the Op
  361. */
  362. while (GET_CURRENT_ARG_TYPE
  363. (walk_state->arg_types)
  364. && !walk_state->arg_count) {
  365. walk_state->aml_offset = (u32)
  366. ACPI_PTR_DIFF(parser_state->aml,
  367. parser_state->
  368. aml_start);
  369. status =
  370. acpi_ps_get_next_arg(walk_state,
  371. parser_state,
  372. GET_CURRENT_ARG_TYPE
  373. (walk_state->
  374. arg_types),
  375. &arg);
  376. if (ACPI_FAILURE(status)) {
  377. goto close_this_op;
  378. }
  379. if (arg) {
  380. arg->common.aml_offset =
  381. walk_state->aml_offset;
  382. acpi_ps_append_arg(op, arg);
  383. }
  384. INCREMENT_ARG_LIST(walk_state->
  385. arg_types);
  386. }
  387. /* Special processing for certain opcodes */
  388. /* TBD (remove): Temporary mechanism to disable this code if needed */
  389. #ifdef ACPI_ENABLE_MODULE_LEVEL_CODE
  390. if ((walk_state->pass_number <=
  391. ACPI_IMODE_LOAD_PASS1)
  392. &&
  393. ((walk_state->
  394. parse_flags & ACPI_PARSE_DISASSEMBLE) ==
  395. 0)) {
  396. /*
  397. * We want to skip If/Else/While constructs during Pass1
  398. * because we want to actually conditionally execute the
  399. * code during Pass2.
  400. *
  401. * Except for disassembly, where we always want to
  402. * walk the If/Else/While packages
  403. */
  404. switch (op->common.aml_opcode) {
  405. case AML_IF_OP:
  406. case AML_ELSE_OP:
  407. case AML_WHILE_OP:
  408. ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
  409. "Pass1: Skipping an If/Else/While body\n"));
  410. /* Skip body of if/else/while in pass 1 */
  411. parser_state->aml =
  412. parser_state->pkg_end;
  413. walk_state->arg_count = 0;
  414. break;
  415. default:
  416. break;
  417. }
  418. }
  419. #endif
  420. switch (op->common.aml_opcode) {
  421. case AML_METHOD_OP:
  422. /*
  423. * Skip parsing of control method
  424. * because we don't have enough info in the first pass
  425. * to parse it correctly.
  426. *
  427. * Save the length and address of the body
  428. */
  429. op->named.data = parser_state->aml;
  430. op->named.length =
  431. (u32) (parser_state->pkg_end -
  432. parser_state->aml);
  433. /* Skip body of method */
  434. parser_state->aml =
  435. parser_state->pkg_end;
  436. walk_state->arg_count = 0;
  437. break;
  438. case AML_BUFFER_OP:
  439. case AML_PACKAGE_OP:
  440. case AML_VAR_PACKAGE_OP:
  441. if ((op->common.parent) &&
  442. (op->common.parent->common.
  443. aml_opcode == AML_NAME_OP)
  444. && (walk_state->pass_number <=
  445. ACPI_IMODE_LOAD_PASS2)) {
  446. /*
  447. * Skip parsing of Buffers and Packages
  448. * because we don't have enough info in the first pass
  449. * to parse them correctly.
  450. */
  451. op->named.data = aml_op_start;
  452. op->named.length =
  453. (u32) (parser_state->
  454. pkg_end -
  455. aml_op_start);
  456. /* Skip body */
  457. parser_state->aml =
  458. parser_state->pkg_end;
  459. walk_state->arg_count = 0;
  460. }
  461. break;
  462. case AML_WHILE_OP:
  463. if (walk_state->control_state) {
  464. walk_state->control_state->
  465. control.package_end =
  466. parser_state->pkg_end;
  467. }
  468. break;
  469. default:
  470. /* No action for all other opcodes */
  471. break;
  472. }
  473. break;
  474. }
  475. }
  476. /* Check for arguments that need to be processed */
  477. if (walk_state->arg_count) {
  478. /*
  479. * There are arguments (complex ones), push Op and
  480. * prepare for argument
  481. */
  482. status = acpi_ps_push_scope(parser_state, op,
  483. walk_state->arg_types,
  484. walk_state->arg_count);
  485. if (ACPI_FAILURE(status)) {
  486. goto close_this_op;
  487. }
  488. op = NULL;
  489. continue;
  490. }
  491. /*
  492. * All arguments have been processed -- Op is complete,
  493. * prepare for next
  494. */
  495. walk_state->op_info =
  496. acpi_ps_get_opcode_info(op->common.aml_opcode);
  497. if (walk_state->op_info->flags & AML_NAMED) {
  498. if (acpi_gbl_depth) {
  499. acpi_gbl_depth--;
  500. }
  501. if (op->common.aml_opcode == AML_REGION_OP) {
  502. /*
  503. * Skip parsing of control method or opregion body,
  504. * because we don't have enough info in the first pass
  505. * to parse them correctly.
  506. *
  507. * Completed parsing an op_region declaration, we now
  508. * know the length.
  509. */
  510. op->named.length =
  511. (u32) (parser_state->aml - op->named.data);
  512. }
  513. }
  514. if (walk_state->op_info->flags & AML_CREATE) {
  515. /*
  516. * Backup to beginning of create_xXXfield declaration (1 for
  517. * Opcode)
  518. *
  519. * body_length is unknown until we parse the body
  520. */
  521. op->named.length =
  522. (u32) (parser_state->aml - op->named.data);
  523. }
  524. /* This op complete, notify the dispatcher */
  525. if (walk_state->ascending_callback != NULL) {
  526. walk_state->op = op;
  527. walk_state->opcode = op->common.aml_opcode;
  528. status = walk_state->ascending_callback(walk_state);
  529. status =
  530. acpi_ps_next_parse_state(walk_state, op, status);
  531. if (status == AE_CTRL_PENDING) {
  532. status = AE_OK;
  533. goto close_this_op;
  534. }
  535. }
  536. close_this_op:
  537. /*
  538. * Finished one argument of the containing scope
  539. */
  540. parser_state->scope->parse_scope.arg_count--;
  541. /* Finished with pre_op */
  542. if (pre_op) {
  543. acpi_ps_free_op(pre_op);
  544. pre_op = NULL;
  545. }
  546. /* Close this Op (will result in parse subtree deletion) */
  547. status2 = acpi_ps_complete_this_op(walk_state, op);
  548. if (ACPI_FAILURE(status2)) {
  549. return_ACPI_STATUS(status2);
  550. }
  551. op = NULL;
  552. switch (status) {
  553. case AE_OK:
  554. break;
  555. case AE_CTRL_TRANSFER:
  556. /* We are about to transfer to a called method. */
  557. walk_state->prev_op = op;
  558. walk_state->prev_arg_types = walk_state->arg_types;
  559. return_ACPI_STATUS(status);
  560. case AE_CTRL_END:
  561. acpi_ps_pop_scope(parser_state, &op,
  562. &walk_state->arg_types,
  563. &walk_state->arg_count);
  564. if (op) {
  565. walk_state->op = op;
  566. walk_state->op_info =
  567. acpi_ps_get_opcode_info(op->common.
  568. aml_opcode);
  569. walk_state->opcode = op->common.aml_opcode;
  570. status =
  571. walk_state->ascending_callback(walk_state);
  572. status =
  573. acpi_ps_next_parse_state(walk_state, op,
  574. status);
  575. status2 =
  576. acpi_ps_complete_this_op(walk_state, op);
  577. if (ACPI_FAILURE(status2)) {
  578. return_ACPI_STATUS(status2);
  579. }
  580. op = NULL;
  581. }
  582. status = AE_OK;
  583. break;
  584. case AE_CTRL_BREAK:
  585. case AE_CTRL_CONTINUE:
  586. /* Pop off scopes until we find the While */
  587. while (!op || (op->common.aml_opcode != AML_WHILE_OP)) {
  588. acpi_ps_pop_scope(parser_state, &op,
  589. &walk_state->arg_types,
  590. &walk_state->arg_count);
  591. if (op->common.aml_opcode != AML_WHILE_OP) {
  592. status2 =
  593. acpi_ds_result_stack_pop
  594. (walk_state);
  595. if (ACPI_FAILURE(status2)) {
  596. return_ACPI_STATUS(status2);
  597. }
  598. }
  599. }
  600. /* Close this iteration of the While loop */
  601. walk_state->op = op;
  602. walk_state->op_info =
  603. acpi_ps_get_opcode_info(op->common.aml_opcode);
  604. walk_state->opcode = op->common.aml_opcode;
  605. status = walk_state->ascending_callback(walk_state);
  606. status =
  607. acpi_ps_next_parse_state(walk_state, op, status);
  608. status2 = acpi_ps_complete_this_op(walk_state, op);
  609. if (ACPI_FAILURE(status2)) {
  610. return_ACPI_STATUS(status2);
  611. }
  612. op = NULL;
  613. status = AE_OK;
  614. break;
  615. case AE_CTRL_TERMINATE:
  616. status = AE_OK;
  617. /* Clean up */
  618. do {
  619. if (op) {
  620. status2 =
  621. acpi_ps_complete_this_op(walk_state,
  622. op);
  623. if (ACPI_FAILURE(status2)) {
  624. return_ACPI_STATUS(status2);
  625. }
  626. }
  627. acpi_ps_pop_scope(parser_state, &op,
  628. &walk_state->arg_types,
  629. &walk_state->arg_count);
  630. } while (op);
  631. return_ACPI_STATUS(status);
  632. default: /* All other non-AE_OK status */
  633. do {
  634. if (op) {
  635. status2 =
  636. acpi_ps_complete_this_op(walk_state,
  637. op);
  638. if (ACPI_FAILURE(status2)) {
  639. return_ACPI_STATUS(status2);
  640. }
  641. }
  642. acpi_ps_pop_scope(parser_state, &op,
  643. &walk_state->arg_types,
  644. &walk_state->arg_count);
  645. } while (op);
  646. /*
  647. * TBD: Cleanup parse ops on error
  648. */
  649. #if 0
  650. if (op == NULL) {
  651. acpi_ps_pop_scope(parser_state, &op,
  652. &walk_state->arg_types,
  653. &walk_state->arg_count);
  654. }
  655. #endif
  656. walk_state->prev_op = op;
  657. walk_state->prev_arg_types = walk_state->arg_types;
  658. return_ACPI_STATUS(status);
  659. }
  660. /* This scope complete? */
  661. if (acpi_ps_has_completed_scope(parser_state)) {
  662. acpi_ps_pop_scope(parser_state, &op,
  663. &walk_state->arg_types,
  664. &walk_state->arg_count);
  665. ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
  666. "Popped scope, Op=%p\n", op));
  667. } else {
  668. op = NULL;
  669. }
  670. } /* while parser_state->Aml */
  671. /*
  672. * Complete the last Op (if not completed), and clear the scope stack.
  673. * It is easily possible to end an AML "package" with an unbounded number
  674. * of open scopes (such as when several ASL blocks are closed with
  675. * sequential closing braces). We want to terminate each one cleanly.
  676. */
  677. ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "AML package complete at Op %p\n",
  678. op));
  679. do {
  680. if (op) {
  681. if (walk_state->ascending_callback != NULL) {
  682. walk_state->op = op;
  683. walk_state->op_info =
  684. acpi_ps_get_opcode_info(op->common.
  685. aml_opcode);
  686. walk_state->opcode = op->common.aml_opcode;
  687. status =
  688. walk_state->ascending_callback(walk_state);
  689. status =
  690. acpi_ps_next_parse_state(walk_state, op,
  691. status);
  692. if (status == AE_CTRL_PENDING) {
  693. status = AE_OK;
  694. goto close_this_op;
  695. }
  696. if (status == AE_CTRL_TERMINATE) {
  697. status = AE_OK;
  698. /* Clean up */
  699. do {
  700. if (op) {
  701. status2 =
  702. acpi_ps_complete_this_op
  703. (walk_state, op);
  704. if (ACPI_FAILURE
  705. (status2)) {
  706. return_ACPI_STATUS
  707. (status2);
  708. }
  709. }
  710. acpi_ps_pop_scope(parser_state,
  711. &op,
  712. &walk_state->
  713. arg_types,
  714. &walk_state->
  715. arg_count);
  716. } while (op);
  717. return_ACPI_STATUS(status);
  718. }
  719. else if (ACPI_FAILURE(status)) {
  720. /* First error is most important */
  721. (void)
  722. acpi_ps_complete_this_op(walk_state,
  723. op);
  724. return_ACPI_STATUS(status);
  725. }
  726. }
  727. status2 = acpi_ps_complete_this_op(walk_state, op);
  728. if (ACPI_FAILURE(status2)) {
  729. return_ACPI_STATUS(status2);
  730. }
  731. }
  732. acpi_ps_pop_scope(parser_state, &op, &walk_state->arg_types,
  733. &walk_state->arg_count);
  734. } while (op);
  735. return_ACPI_STATUS(status);
  736. }