dsutils.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  1. /*******************************************************************************
  2. *
  3. * Module Name: dsutils - Dispatcher utilities
  4. *
  5. ******************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2015, 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 "acdispat.h"
  47. #include "acinterp.h"
  48. #include "acnamesp.h"
  49. #include "acdebug.h"
  50. #define _COMPONENT ACPI_DISPATCHER
  51. ACPI_MODULE_NAME("dsutils")
  52. /*******************************************************************************
  53. *
  54. * FUNCTION: acpi_ds_clear_implicit_return
  55. *
  56. * PARAMETERS: walk_state - Current State
  57. *
  58. * RETURN: None.
  59. *
  60. * DESCRIPTION: Clear and remove a reference on an implicit return value. Used
  61. * to delete "stale" return values (if enabled, the return value
  62. * from every operator is saved at least momentarily, in case the
  63. * parent method exits.)
  64. *
  65. ******************************************************************************/
  66. void acpi_ds_clear_implicit_return(struct acpi_walk_state *walk_state)
  67. {
  68. ACPI_FUNCTION_NAME(ds_clear_implicit_return);
  69. /*
  70. * Slack must be enabled for this feature
  71. */
  72. if (!acpi_gbl_enable_interpreter_slack) {
  73. return;
  74. }
  75. if (walk_state->implicit_return_obj) {
  76. /*
  77. * Delete any "stale" implicit return. However, in
  78. * complex statements, the implicit return value can be
  79. * bubbled up several levels.
  80. */
  81. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  82. "Removing reference on stale implicit return obj %p\n",
  83. walk_state->implicit_return_obj));
  84. acpi_ut_remove_reference(walk_state->implicit_return_obj);
  85. walk_state->implicit_return_obj = NULL;
  86. }
  87. }
  88. #ifndef ACPI_NO_METHOD_EXECUTION
  89. /*******************************************************************************
  90. *
  91. * FUNCTION: acpi_ds_do_implicit_return
  92. *
  93. * PARAMETERS: return_desc - The return value
  94. * walk_state - Current State
  95. * add_reference - True if a reference should be added to the
  96. * return object
  97. *
  98. * RETURN: TRUE if implicit return enabled, FALSE otherwise
  99. *
  100. * DESCRIPTION: Implements the optional "implicit return". We save the result
  101. * of every ASL operator and control method invocation in case the
  102. * parent method exit. Before storing a new return value, we
  103. * delete the previous return value.
  104. *
  105. ******************************************************************************/
  106. u8
  107. acpi_ds_do_implicit_return(union acpi_operand_object *return_desc,
  108. struct acpi_walk_state *walk_state, u8 add_reference)
  109. {
  110. ACPI_FUNCTION_NAME(ds_do_implicit_return);
  111. /*
  112. * Slack must be enabled for this feature, and we must
  113. * have a valid return object
  114. */
  115. if ((!acpi_gbl_enable_interpreter_slack) || (!return_desc)) {
  116. return (FALSE);
  117. }
  118. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  119. "Result %p will be implicitly returned; Prev=%p\n",
  120. return_desc, walk_state->implicit_return_obj));
  121. /*
  122. * Delete any "stale" implicit return value first. However, in
  123. * complex statements, the implicit return value can be
  124. * bubbled up several levels, so we don't clear the value if it
  125. * is the same as the return_desc.
  126. */
  127. if (walk_state->implicit_return_obj) {
  128. if (walk_state->implicit_return_obj == return_desc) {
  129. return (TRUE);
  130. }
  131. acpi_ds_clear_implicit_return(walk_state);
  132. }
  133. /* Save the implicit return value, add a reference if requested */
  134. walk_state->implicit_return_obj = return_desc;
  135. if (add_reference) {
  136. acpi_ut_add_reference(return_desc);
  137. }
  138. return (TRUE);
  139. }
  140. /*******************************************************************************
  141. *
  142. * FUNCTION: acpi_ds_is_result_used
  143. *
  144. * PARAMETERS: op - Current Op
  145. * walk_state - Current State
  146. *
  147. * RETURN: TRUE if result is used, FALSE otherwise
  148. *
  149. * DESCRIPTION: Check if a result object will be used by the parent
  150. *
  151. ******************************************************************************/
  152. u8
  153. acpi_ds_is_result_used(union acpi_parse_object * op,
  154. struct acpi_walk_state * walk_state)
  155. {
  156. const struct acpi_opcode_info *parent_info;
  157. ACPI_FUNCTION_TRACE_PTR(ds_is_result_used, op);
  158. /* Must have both an Op and a Result Object */
  159. if (!op) {
  160. ACPI_ERROR((AE_INFO, "Null Op"));
  161. return_UINT8(TRUE);
  162. }
  163. /*
  164. * We know that this operator is not a
  165. * Return() operator (would not come here.) The following code is the
  166. * optional support for a so-called "implicit return". Some AML code
  167. * assumes that the last value of the method is "implicitly" returned
  168. * to the caller. Just save the last result as the return value.
  169. * NOTE: this is optional because the ASL language does not actually
  170. * support this behavior.
  171. */
  172. (void)acpi_ds_do_implicit_return(walk_state->result_obj, walk_state,
  173. TRUE);
  174. /*
  175. * Now determine if the parent will use the result
  176. *
  177. * If there is no parent, or the parent is a scope_op, we are executing
  178. * at the method level. An executing method typically has no parent,
  179. * since each method is parsed separately. A method invoked externally
  180. * via execute_control_method has a scope_op as the parent.
  181. */
  182. if ((!op->common.parent) ||
  183. (op->common.parent->common.aml_opcode == AML_SCOPE_OP)) {
  184. /* No parent, the return value cannot possibly be used */
  185. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  186. "At Method level, result of [%s] not used\n",
  187. acpi_ps_get_opcode_name(op->common.
  188. aml_opcode)));
  189. return_UINT8(FALSE);
  190. }
  191. /* Get info on the parent. The root_op is AML_SCOPE */
  192. parent_info =
  193. acpi_ps_get_opcode_info(op->common.parent->common.aml_opcode);
  194. if (parent_info->class == AML_CLASS_UNKNOWN) {
  195. ACPI_ERROR((AE_INFO, "Unknown parent opcode Op=%p", op));
  196. return_UINT8(FALSE);
  197. }
  198. /*
  199. * Decide what to do with the result based on the parent. If
  200. * the parent opcode will not use the result, delete the object.
  201. * Otherwise leave it as is, it will be deleted when it is used
  202. * as an operand later.
  203. */
  204. switch (parent_info->class) {
  205. case AML_CLASS_CONTROL:
  206. switch (op->common.parent->common.aml_opcode) {
  207. case AML_RETURN_OP:
  208. /* Never delete the return value associated with a return opcode */
  209. goto result_used;
  210. case AML_IF_OP:
  211. case AML_WHILE_OP:
  212. /*
  213. * If we are executing the predicate AND this is the predicate op,
  214. * we will use the return value
  215. */
  216. if ((walk_state->control_state->common.state ==
  217. ACPI_CONTROL_PREDICATE_EXECUTING)
  218. && (walk_state->control_state->control.
  219. predicate_op == op)) {
  220. goto result_used;
  221. }
  222. break;
  223. default:
  224. /* Ignore other control opcodes */
  225. break;
  226. }
  227. /* The general control opcode returns no result */
  228. goto result_not_used;
  229. case AML_CLASS_CREATE:
  230. /*
  231. * These opcodes allow term_arg(s) as operands and therefore
  232. * the operands can be method calls. The result is used.
  233. */
  234. goto result_used;
  235. case AML_CLASS_NAMED_OBJECT:
  236. if ((op->common.parent->common.aml_opcode == AML_REGION_OP) ||
  237. (op->common.parent->common.aml_opcode == AML_DATA_REGION_OP)
  238. || (op->common.parent->common.aml_opcode == AML_PACKAGE_OP)
  239. || (op->common.parent->common.aml_opcode ==
  240. AML_VAR_PACKAGE_OP)
  241. || (op->common.parent->common.aml_opcode == AML_BUFFER_OP)
  242. || (op->common.parent->common.aml_opcode ==
  243. AML_INT_EVAL_SUBTREE_OP)
  244. || (op->common.parent->common.aml_opcode ==
  245. AML_BANK_FIELD_OP)) {
  246. /*
  247. * These opcodes allow term_arg(s) as operands and therefore
  248. * the operands can be method calls. The result is used.
  249. */
  250. goto result_used;
  251. }
  252. goto result_not_used;
  253. default:
  254. /*
  255. * In all other cases. the parent will actually use the return
  256. * object, so keep it.
  257. */
  258. goto result_used;
  259. }
  260. result_used:
  261. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  262. "Result of [%s] used by Parent [%s] Op=%p\n",
  263. acpi_ps_get_opcode_name(op->common.aml_opcode),
  264. acpi_ps_get_opcode_name(op->common.parent->common.
  265. aml_opcode), op));
  266. return_UINT8(TRUE);
  267. result_not_used:
  268. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  269. "Result of [%s] not used by Parent [%s] Op=%p\n",
  270. acpi_ps_get_opcode_name(op->common.aml_opcode),
  271. acpi_ps_get_opcode_name(op->common.parent->common.
  272. aml_opcode), op));
  273. return_UINT8(FALSE);
  274. }
  275. /*******************************************************************************
  276. *
  277. * FUNCTION: acpi_ds_delete_result_if_not_used
  278. *
  279. * PARAMETERS: op - Current parse Op
  280. * result_obj - Result of the operation
  281. * walk_state - Current state
  282. *
  283. * RETURN: Status
  284. *
  285. * DESCRIPTION: Used after interpretation of an opcode. If there is an internal
  286. * result descriptor, check if the parent opcode will actually use
  287. * this result. If not, delete the result now so that it will
  288. * not become orphaned.
  289. *
  290. ******************************************************************************/
  291. void
  292. acpi_ds_delete_result_if_not_used(union acpi_parse_object *op,
  293. union acpi_operand_object *result_obj,
  294. struct acpi_walk_state *walk_state)
  295. {
  296. union acpi_operand_object *obj_desc;
  297. acpi_status status;
  298. ACPI_FUNCTION_TRACE_PTR(ds_delete_result_if_not_used, result_obj);
  299. if (!op) {
  300. ACPI_ERROR((AE_INFO, "Null Op"));
  301. return_VOID;
  302. }
  303. if (!result_obj) {
  304. return_VOID;
  305. }
  306. if (!acpi_ds_is_result_used(op, walk_state)) {
  307. /* Must pop the result stack (obj_desc should be equal to result_obj) */
  308. status = acpi_ds_result_pop(&obj_desc, walk_state);
  309. if (ACPI_SUCCESS(status)) {
  310. acpi_ut_remove_reference(result_obj);
  311. }
  312. }
  313. return_VOID;
  314. }
  315. /*******************************************************************************
  316. *
  317. * FUNCTION: acpi_ds_resolve_operands
  318. *
  319. * PARAMETERS: walk_state - Current walk state with operands on stack
  320. *
  321. * RETURN: Status
  322. *
  323. * DESCRIPTION: Resolve all operands to their values. Used to prepare
  324. * arguments to a control method invocation (a call from one
  325. * method to another.)
  326. *
  327. ******************************************************************************/
  328. acpi_status acpi_ds_resolve_operands(struct acpi_walk_state *walk_state)
  329. {
  330. u32 i;
  331. acpi_status status = AE_OK;
  332. ACPI_FUNCTION_TRACE_PTR(ds_resolve_operands, walk_state);
  333. /*
  334. * Attempt to resolve each of the valid operands
  335. * Method arguments are passed by reference, not by value. This means
  336. * that the actual objects are passed, not copies of the objects.
  337. */
  338. for (i = 0; i < walk_state->num_operands; i++) {
  339. status =
  340. acpi_ex_resolve_to_value(&walk_state->operands[i],
  341. walk_state);
  342. if (ACPI_FAILURE(status)) {
  343. break;
  344. }
  345. }
  346. return_ACPI_STATUS(status);
  347. }
  348. /*******************************************************************************
  349. *
  350. * FUNCTION: acpi_ds_clear_operands
  351. *
  352. * PARAMETERS: walk_state - Current walk state with operands on stack
  353. *
  354. * RETURN: None
  355. *
  356. * DESCRIPTION: Clear all operands on the current walk state operand stack.
  357. *
  358. ******************************************************************************/
  359. void acpi_ds_clear_operands(struct acpi_walk_state *walk_state)
  360. {
  361. u32 i;
  362. ACPI_FUNCTION_TRACE_PTR(ds_clear_operands, walk_state);
  363. /* Remove a reference on each operand on the stack */
  364. for (i = 0; i < walk_state->num_operands; i++) {
  365. /*
  366. * Remove a reference to all operands, including both
  367. * "Arguments" and "Targets".
  368. */
  369. acpi_ut_remove_reference(walk_state->operands[i]);
  370. walk_state->operands[i] = NULL;
  371. }
  372. walk_state->num_operands = 0;
  373. return_VOID;
  374. }
  375. #endif
  376. /*******************************************************************************
  377. *
  378. * FUNCTION: acpi_ds_create_operand
  379. *
  380. * PARAMETERS: walk_state - Current walk state
  381. * arg - Parse object for the argument
  382. * arg_index - Which argument (zero based)
  383. *
  384. * RETURN: Status
  385. *
  386. * DESCRIPTION: Translate a parse tree object that is an argument to an AML
  387. * opcode to the equivalent interpreter object. This may include
  388. * looking up a name or entering a new name into the internal
  389. * namespace.
  390. *
  391. ******************************************************************************/
  392. acpi_status
  393. acpi_ds_create_operand(struct acpi_walk_state *walk_state,
  394. union acpi_parse_object *arg, u32 arg_index)
  395. {
  396. acpi_status status = AE_OK;
  397. char *name_string;
  398. u32 name_length;
  399. union acpi_operand_object *obj_desc;
  400. union acpi_parse_object *parent_op;
  401. u16 opcode;
  402. acpi_interpreter_mode interpreter_mode;
  403. const struct acpi_opcode_info *op_info;
  404. ACPI_FUNCTION_TRACE_PTR(ds_create_operand, arg);
  405. /* A valid name must be looked up in the namespace */
  406. if ((arg->common.aml_opcode == AML_INT_NAMEPATH_OP) &&
  407. (arg->common.value.string) &&
  408. !(arg->common.flags & ACPI_PARSEOP_IN_STACK)) {
  409. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Getting a name: Arg=%p\n",
  410. arg));
  411. /* Get the entire name string from the AML stream */
  412. status =
  413. acpi_ex_get_name_string(ACPI_TYPE_ANY,
  414. arg->common.value.buffer,
  415. &name_string, &name_length);
  416. if (ACPI_FAILURE(status)) {
  417. return_ACPI_STATUS(status);
  418. }
  419. /* All prefixes have been handled, and the name is in name_string */
  420. /*
  421. * Special handling for buffer_field declarations. This is a deferred
  422. * opcode that unfortunately defines the field name as the last
  423. * parameter instead of the first. We get here when we are performing
  424. * the deferred execution, so the actual name of the field is already
  425. * in the namespace. We don't want to attempt to look it up again
  426. * because we may be executing in a different scope than where the
  427. * actual opcode exists.
  428. */
  429. if ((walk_state->deferred_node) &&
  430. (walk_state->deferred_node->type == ACPI_TYPE_BUFFER_FIELD)
  431. && (arg_index ==
  432. (u32) ((walk_state->opcode ==
  433. AML_CREATE_FIELD_OP) ? 3 : 2))) {
  434. obj_desc =
  435. ACPI_CAST_PTR(union acpi_operand_object,
  436. walk_state->deferred_node);
  437. status = AE_OK;
  438. } else { /* All other opcodes */
  439. /*
  440. * Differentiate between a namespace "create" operation
  441. * versus a "lookup" operation (IMODE_LOAD_PASS2 vs.
  442. * IMODE_EXECUTE) in order to support the creation of
  443. * namespace objects during the execution of control methods.
  444. */
  445. parent_op = arg->common.parent;
  446. op_info =
  447. acpi_ps_get_opcode_info(parent_op->common.
  448. aml_opcode);
  449. if ((op_info->flags & AML_NSNODE)
  450. && (parent_op->common.aml_opcode !=
  451. AML_INT_METHODCALL_OP)
  452. && (parent_op->common.aml_opcode != AML_REGION_OP)
  453. && (parent_op->common.aml_opcode !=
  454. AML_INT_NAMEPATH_OP)) {
  455. /* Enter name into namespace if not found */
  456. interpreter_mode = ACPI_IMODE_LOAD_PASS2;
  457. } else {
  458. /* Return a failure if name not found */
  459. interpreter_mode = ACPI_IMODE_EXECUTE;
  460. }
  461. status =
  462. acpi_ns_lookup(walk_state->scope_info, name_string,
  463. ACPI_TYPE_ANY, interpreter_mode,
  464. ACPI_NS_SEARCH_PARENT |
  465. ACPI_NS_DONT_OPEN_SCOPE, walk_state,
  466. ACPI_CAST_INDIRECT_PTR(struct
  467. acpi_namespace_node,
  468. &obj_desc));
  469. /*
  470. * The only case where we pass through (ignore) a NOT_FOUND
  471. * error is for the cond_ref_of opcode.
  472. */
  473. if (status == AE_NOT_FOUND) {
  474. if (parent_op->common.aml_opcode ==
  475. AML_COND_REF_OF_OP) {
  476. /*
  477. * For the Conditional Reference op, it's OK if
  478. * the name is not found; We just need a way to
  479. * indicate this to the interpreter, set the
  480. * object to the root
  481. */
  482. obj_desc =
  483. ACPI_CAST_PTR(union
  484. acpi_operand_object,
  485. acpi_gbl_root_node);
  486. status = AE_OK;
  487. } else if (parent_op->common.aml_opcode ==
  488. AML_EXTERNAL_OP) {
  489. /* TBD: May only be temporary */
  490. obj_desc =
  491. acpi_ut_create_string_object((acpi_size) name_length);
  492. strncpy(obj_desc->string.pointer,
  493. name_string, name_length);
  494. status = AE_OK;
  495. } else {
  496. /*
  497. * We just plain didn't find it -- which is a
  498. * very serious error at this point
  499. */
  500. status = AE_AML_NAME_NOT_FOUND;
  501. }
  502. }
  503. if (ACPI_FAILURE(status)) {
  504. ACPI_ERROR_NAMESPACE(name_string, status);
  505. }
  506. }
  507. /* Free the namestring created above */
  508. ACPI_FREE(name_string);
  509. /* Check status from the lookup */
  510. if (ACPI_FAILURE(status)) {
  511. return_ACPI_STATUS(status);
  512. }
  513. /* Put the resulting object onto the current object stack */
  514. status = acpi_ds_obj_stack_push(obj_desc, walk_state);
  515. if (ACPI_FAILURE(status)) {
  516. return_ACPI_STATUS(status);
  517. }
  518. ACPI_DEBUGGER_EXEC(acpi_db_display_argument_object
  519. (obj_desc, walk_state));
  520. } else {
  521. /* Check for null name case */
  522. if ((arg->common.aml_opcode == AML_INT_NAMEPATH_OP) &&
  523. !(arg->common.flags & ACPI_PARSEOP_IN_STACK)) {
  524. /*
  525. * If the name is null, this means that this is an
  526. * optional result parameter that was not specified
  527. * in the original ASL. Create a Zero Constant for a
  528. * placeholder. (Store to a constant is a Noop.)
  529. */
  530. opcode = AML_ZERO_OP; /* Has no arguments! */
  531. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  532. "Null namepath: Arg=%p\n", arg));
  533. } else {
  534. opcode = arg->common.aml_opcode;
  535. }
  536. /* Get the object type of the argument */
  537. op_info = acpi_ps_get_opcode_info(opcode);
  538. if (op_info->object_type == ACPI_TYPE_INVALID) {
  539. return_ACPI_STATUS(AE_NOT_IMPLEMENTED);
  540. }
  541. if ((op_info->flags & AML_HAS_RETVAL)
  542. || (arg->common.flags & ACPI_PARSEOP_IN_STACK)) {
  543. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  544. "Argument previously created, already stacked\n"));
  545. ACPI_DEBUGGER_EXEC(acpi_db_display_argument_object
  546. (walk_state->
  547. operands[walk_state->num_operands -
  548. 1], walk_state));
  549. /*
  550. * Use value that was already previously returned
  551. * by the evaluation of this argument
  552. */
  553. status = acpi_ds_result_pop(&obj_desc, walk_state);
  554. if (ACPI_FAILURE(status)) {
  555. /*
  556. * Only error is underflow, and this indicates
  557. * a missing or null operand!
  558. */
  559. ACPI_EXCEPTION((AE_INFO, status,
  560. "Missing or null operand"));
  561. return_ACPI_STATUS(status);
  562. }
  563. } else {
  564. /* Create an ACPI_INTERNAL_OBJECT for the argument */
  565. obj_desc =
  566. acpi_ut_create_internal_object(op_info->
  567. object_type);
  568. if (!obj_desc) {
  569. return_ACPI_STATUS(AE_NO_MEMORY);
  570. }
  571. /* Initialize the new object */
  572. status =
  573. acpi_ds_init_object_from_op(walk_state, arg, opcode,
  574. &obj_desc);
  575. if (ACPI_FAILURE(status)) {
  576. acpi_ut_delete_object_desc(obj_desc);
  577. return_ACPI_STATUS(status);
  578. }
  579. }
  580. /* Put the operand object on the object stack */
  581. status = acpi_ds_obj_stack_push(obj_desc, walk_state);
  582. if (ACPI_FAILURE(status)) {
  583. return_ACPI_STATUS(status);
  584. }
  585. ACPI_DEBUGGER_EXEC(acpi_db_display_argument_object
  586. (obj_desc, walk_state));
  587. }
  588. return_ACPI_STATUS(AE_OK);
  589. }
  590. /*******************************************************************************
  591. *
  592. * FUNCTION: acpi_ds_create_operands
  593. *
  594. * PARAMETERS: walk_state - Current state
  595. * first_arg - First argument of a parser argument tree
  596. *
  597. * RETURN: Status
  598. *
  599. * DESCRIPTION: Convert an operator's arguments from a parse tree format to
  600. * namespace objects and place those argument object on the object
  601. * stack in preparation for evaluation by the interpreter.
  602. *
  603. ******************************************************************************/
  604. acpi_status
  605. acpi_ds_create_operands(struct acpi_walk_state *walk_state,
  606. union acpi_parse_object *first_arg)
  607. {
  608. acpi_status status = AE_OK;
  609. union acpi_parse_object *arg;
  610. union acpi_parse_object *arguments[ACPI_OBJ_NUM_OPERANDS];
  611. u32 arg_count = 0;
  612. u32 index = walk_state->num_operands;
  613. u32 i;
  614. ACPI_FUNCTION_TRACE_PTR(ds_create_operands, first_arg);
  615. /* Get all arguments in the list */
  616. arg = first_arg;
  617. while (arg) {
  618. if (index >= ACPI_OBJ_NUM_OPERANDS) {
  619. return_ACPI_STATUS(AE_BAD_DATA);
  620. }
  621. arguments[index] = arg;
  622. walk_state->operands[index] = NULL;
  623. /* Move on to next argument, if any */
  624. arg = arg->common.next;
  625. arg_count++;
  626. index++;
  627. }
  628. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  629. "NumOperands %d, ArgCount %d, Index %d\n",
  630. walk_state->num_operands, arg_count, index));
  631. /* Create the interpreter arguments, in reverse order */
  632. index--;
  633. for (i = 0; i < arg_count; i++) {
  634. arg = arguments[index];
  635. walk_state->operand_index = (u8)index;
  636. status = acpi_ds_create_operand(walk_state, arg, index);
  637. if (ACPI_FAILURE(status)) {
  638. goto cleanup;
  639. }
  640. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  641. "Created Arg #%u (%p) %u args total\n",
  642. index, arg, arg_count));
  643. index--;
  644. }
  645. return_ACPI_STATUS(status);
  646. cleanup:
  647. /*
  648. * We must undo everything done above; meaning that we must
  649. * pop everything off of the operand stack and delete those
  650. * objects
  651. */
  652. acpi_ds_obj_stack_pop_and_delete(arg_count, walk_state);
  653. ACPI_EXCEPTION((AE_INFO, status, "While creating Arg %u", index));
  654. return_ACPI_STATUS(status);
  655. }
  656. /*****************************************************************************
  657. *
  658. * FUNCTION: acpi_ds_evaluate_name_path
  659. *
  660. * PARAMETERS: walk_state - Current state of the parse tree walk,
  661. * the opcode of current operation should be
  662. * AML_INT_NAMEPATH_OP
  663. *
  664. * RETURN: Status
  665. *
  666. * DESCRIPTION: Translate the -name_path- parse tree object to the equivalent
  667. * interpreter object, convert it to value, if needed, duplicate
  668. * it, if needed, and push it onto the current result stack.
  669. *
  670. ****************************************************************************/
  671. acpi_status acpi_ds_evaluate_name_path(struct acpi_walk_state *walk_state)
  672. {
  673. acpi_status status = AE_OK;
  674. union acpi_parse_object *op = walk_state->op;
  675. union acpi_operand_object **operand = &walk_state->operands[0];
  676. union acpi_operand_object *new_obj_desc;
  677. u8 type;
  678. ACPI_FUNCTION_TRACE_PTR(ds_evaluate_name_path, walk_state);
  679. if (!op->common.parent) {
  680. /* This happens after certain exception processing */
  681. goto exit;
  682. }
  683. if ((op->common.parent->common.aml_opcode == AML_PACKAGE_OP) ||
  684. (op->common.parent->common.aml_opcode == AML_VAR_PACKAGE_OP) ||
  685. (op->common.parent->common.aml_opcode == AML_REF_OF_OP)) {
  686. /* TBD: Should we specify this feature as a bit of op_info->Flags of these opcodes? */
  687. goto exit;
  688. }
  689. status = acpi_ds_create_operand(walk_state, op, 0);
  690. if (ACPI_FAILURE(status)) {
  691. goto exit;
  692. }
  693. if (op->common.flags & ACPI_PARSEOP_TARGET) {
  694. new_obj_desc = *operand;
  695. goto push_result;
  696. }
  697. type = (*operand)->common.type;
  698. status = acpi_ex_resolve_to_value(operand, walk_state);
  699. if (ACPI_FAILURE(status)) {
  700. goto exit;
  701. }
  702. if (type == ACPI_TYPE_INTEGER) {
  703. /* It was incremented by acpi_ex_resolve_to_value */
  704. acpi_ut_remove_reference(*operand);
  705. status =
  706. acpi_ut_copy_iobject_to_iobject(*operand, &new_obj_desc,
  707. walk_state);
  708. if (ACPI_FAILURE(status)) {
  709. goto exit;
  710. }
  711. } else {
  712. /*
  713. * The object either was anew created or is
  714. * a Namespace node - don't decrement it.
  715. */
  716. new_obj_desc = *operand;
  717. }
  718. /* Cleanup for name-path operand */
  719. status = acpi_ds_obj_stack_pop(1, walk_state);
  720. if (ACPI_FAILURE(status)) {
  721. walk_state->result_obj = new_obj_desc;
  722. goto exit;
  723. }
  724. push_result:
  725. walk_state->result_obj = new_obj_desc;
  726. status = acpi_ds_result_push(walk_state->result_obj, walk_state);
  727. if (ACPI_SUCCESS(status)) {
  728. /* Force to take it from stack */
  729. op->common.flags |= ACPI_PARSEOP_IN_STACK;
  730. }
  731. exit:
  732. return_ACPI_STATUS(status);
  733. }