dsutils.c 23 KB

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