psobject.c 20 KB

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