dsutils.c 23 KB

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