psloop.c 22 KB

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