dsutils.c 25 KB

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