psloop.c 21 KB

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