exresolv.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. /******************************************************************************
  2. *
  3. * Module Name: exresolv - AML Interpreter object resolution
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2005, R. Byron Moore
  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/amlcode.h>
  44. #include <acpi/acdispat.h>
  45. #include <acpi/acinterp.h>
  46. #include <acpi/acnamesp.h>
  47. #include <acpi/acparser.h>
  48. #define _COMPONENT ACPI_EXECUTER
  49. ACPI_MODULE_NAME ("exresolv")
  50. /* Local prototypes */
  51. static acpi_status
  52. acpi_ex_resolve_object_to_value (
  53. union acpi_operand_object **stack_ptr,
  54. struct acpi_walk_state *walk_state);
  55. /*******************************************************************************
  56. *
  57. * FUNCTION: acpi_ex_resolve_to_value
  58. *
  59. * PARAMETERS: **stack_ptr - Points to entry on obj_stack, which can
  60. * be either an (union acpi_operand_object *)
  61. * or an acpi_handle.
  62. * walk_state - Current method state
  63. *
  64. * RETURN: Status
  65. *
  66. * DESCRIPTION: Convert Reference objects to values
  67. *
  68. ******************************************************************************/
  69. acpi_status
  70. acpi_ex_resolve_to_value (
  71. union acpi_operand_object **stack_ptr,
  72. struct acpi_walk_state *walk_state)
  73. {
  74. acpi_status status;
  75. ACPI_FUNCTION_TRACE_PTR ("ex_resolve_to_value", stack_ptr);
  76. if (!stack_ptr || !*stack_ptr) {
  77. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Internal - null pointer\n"));
  78. return_ACPI_STATUS (AE_AML_NO_OPERAND);
  79. }
  80. /*
  81. * The entity pointed to by the stack_ptr can be either
  82. * 1) A valid union acpi_operand_object, or
  83. * 2) A struct acpi_namespace_node (named_obj)
  84. */
  85. if (ACPI_GET_DESCRIPTOR_TYPE (*stack_ptr) == ACPI_DESC_TYPE_OPERAND) {
  86. status = acpi_ex_resolve_object_to_value (stack_ptr, walk_state);
  87. if (ACPI_FAILURE (status)) {
  88. return_ACPI_STATUS (status);
  89. }
  90. if (!*stack_ptr) {
  91. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Internal - null pointer\n"));
  92. return_ACPI_STATUS (AE_AML_NO_OPERAND);
  93. }
  94. }
  95. /*
  96. * Object on the stack may have changed if acpi_ex_resolve_object_to_value()
  97. * was called (i.e., we can't use an _else_ here.)
  98. */
  99. if (ACPI_GET_DESCRIPTOR_TYPE (*stack_ptr) == ACPI_DESC_TYPE_NAMED) {
  100. status = acpi_ex_resolve_node_to_value (
  101. ACPI_CAST_INDIRECT_PTR (struct acpi_namespace_node, stack_ptr),
  102. walk_state);
  103. if (ACPI_FAILURE (status)) {
  104. return_ACPI_STATUS (status);
  105. }
  106. }
  107. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Resolved object %p\n", *stack_ptr));
  108. return_ACPI_STATUS (AE_OK);
  109. }
  110. /*******************************************************************************
  111. *
  112. * FUNCTION: acpi_ex_resolve_object_to_value
  113. *
  114. * PARAMETERS: stack_ptr - Pointer to an internal object
  115. * walk_state - Current method state
  116. *
  117. * RETURN: Status
  118. *
  119. * DESCRIPTION: Retrieve the value from an internal object. The Reference type
  120. * uses the associated AML opcode to determine the value.
  121. *
  122. ******************************************************************************/
  123. static acpi_status
  124. acpi_ex_resolve_object_to_value (
  125. union acpi_operand_object **stack_ptr,
  126. struct acpi_walk_state *walk_state)
  127. {
  128. acpi_status status = AE_OK;
  129. union acpi_operand_object *stack_desc;
  130. void *temp_node;
  131. union acpi_operand_object *obj_desc;
  132. u16 opcode;
  133. ACPI_FUNCTION_TRACE ("ex_resolve_object_to_value");
  134. stack_desc = *stack_ptr;
  135. /* This is an union acpi_operand_object */
  136. switch (ACPI_GET_OBJECT_TYPE (stack_desc)) {
  137. case ACPI_TYPE_LOCAL_REFERENCE:
  138. opcode = stack_desc->reference.opcode;
  139. switch (opcode) {
  140. case AML_NAME_OP:
  141. /*
  142. * Convert name reference to a namespace node
  143. * Then, acpi_ex_resolve_node_to_value can be used to get the value
  144. */
  145. temp_node = stack_desc->reference.object;
  146. /* Delete the Reference Object */
  147. acpi_ut_remove_reference (stack_desc);
  148. /* Return the namespace node */
  149. (*stack_ptr) = temp_node;
  150. break;
  151. case AML_LOCAL_OP:
  152. case AML_ARG_OP:
  153. /*
  154. * Get the local from the method's state info
  155. * Note: this increments the local's object reference count
  156. */
  157. status = acpi_ds_method_data_get_value (opcode,
  158. stack_desc->reference.offset, walk_state, &obj_desc);
  159. if (ACPI_FAILURE (status)) {
  160. return_ACPI_STATUS (status);
  161. }
  162. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Arg/Local %X] value_obj is %p\n",
  163. stack_desc->reference.offset, obj_desc));
  164. /*
  165. * Now we can delete the original Reference Object and
  166. * replace it with the resolved value
  167. */
  168. acpi_ut_remove_reference (stack_desc);
  169. *stack_ptr = obj_desc;
  170. break;
  171. case AML_INDEX_OP:
  172. switch (stack_desc->reference.target_type) {
  173. case ACPI_TYPE_BUFFER_FIELD:
  174. /* Just return - leave the Reference on the stack */
  175. break;
  176. case ACPI_TYPE_PACKAGE:
  177. obj_desc = *stack_desc->reference.where;
  178. if (obj_desc) {
  179. /*
  180. * Valid obj descriptor, copy pointer to return value
  181. * (i.e., dereference the package index)
  182. * Delete the ref object, increment the returned object
  183. */
  184. acpi_ut_remove_reference (stack_desc);
  185. acpi_ut_add_reference (obj_desc);
  186. *stack_ptr = obj_desc;
  187. }
  188. else {
  189. /*
  190. * A NULL object descriptor means an unitialized element of
  191. * the package, can't dereference it
  192. */
  193. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
  194. "Attempt to deref an Index to NULL pkg element Idx=%p\n",
  195. stack_desc));
  196. status = AE_AML_UNINITIALIZED_ELEMENT;
  197. }
  198. break;
  199. default:
  200. /* Invalid reference object */
  201. ACPI_REPORT_ERROR ((
  202. "During resolve, Unknown target_type %X in Index/Reference obj %p\n",
  203. stack_desc->reference.target_type, stack_desc));
  204. status = AE_AML_INTERNAL;
  205. break;
  206. }
  207. break;
  208. case AML_REF_OF_OP:
  209. case AML_DEBUG_OP:
  210. case AML_LOAD_OP:
  211. /* Just leave the object as-is */
  212. break;
  213. case AML_INT_NAMEPATH_OP: /* Reference to a named object */
  214. /* Get the object pointed to by the namespace node */
  215. *stack_ptr = (stack_desc->reference.node)->object;
  216. acpi_ut_add_reference (*stack_ptr);
  217. acpi_ut_remove_reference (stack_desc);
  218. break;
  219. default:
  220. ACPI_REPORT_ERROR ((
  221. "During resolve, Unknown Reference opcode %X (%s) in %p\n",
  222. opcode, acpi_ps_get_opcode_name (opcode), stack_desc));
  223. status = AE_AML_INTERNAL;
  224. break;
  225. }
  226. break;
  227. case ACPI_TYPE_BUFFER:
  228. status = acpi_ds_get_buffer_arguments (stack_desc);
  229. break;
  230. case ACPI_TYPE_PACKAGE:
  231. status = acpi_ds_get_package_arguments (stack_desc);
  232. break;
  233. /* These cases may never happen here, but just in case.. */
  234. case ACPI_TYPE_BUFFER_FIELD:
  235. case ACPI_TYPE_LOCAL_REGION_FIELD:
  236. case ACPI_TYPE_LOCAL_BANK_FIELD:
  237. case ACPI_TYPE_LOCAL_INDEX_FIELD:
  238. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "field_read source_desc=%p Type=%X\n",
  239. stack_desc, ACPI_GET_OBJECT_TYPE (stack_desc)));
  240. status = acpi_ex_read_data_from_field (walk_state, stack_desc, &obj_desc);
  241. *stack_ptr = (void *) obj_desc;
  242. break;
  243. default:
  244. break;
  245. }
  246. return_ACPI_STATUS (status);
  247. }
  248. /*******************************************************************************
  249. *
  250. * FUNCTION: acpi_ex_resolve_multiple
  251. *
  252. * PARAMETERS: walk_state - Current state (contains AML opcode)
  253. * Operand - Starting point for resolution
  254. * return_type - Where the object type is returned
  255. * return_desc - Where the resolved object is returned
  256. *
  257. * RETURN: Status
  258. *
  259. * DESCRIPTION: Return the base object and type. Traverse a reference list if
  260. * necessary to get to the base object.
  261. *
  262. ******************************************************************************/
  263. acpi_status
  264. acpi_ex_resolve_multiple (
  265. struct acpi_walk_state *walk_state,
  266. union acpi_operand_object *operand,
  267. acpi_object_type *return_type,
  268. union acpi_operand_object **return_desc)
  269. {
  270. union acpi_operand_object *obj_desc = (void *) operand;
  271. struct acpi_namespace_node *node;
  272. acpi_object_type type;
  273. acpi_status status;
  274. ACPI_FUNCTION_TRACE ("acpi_ex_resolve_multiple");
  275. /* Operand can be either a namespace node or an operand descriptor */
  276. switch (ACPI_GET_DESCRIPTOR_TYPE (obj_desc)) {
  277. case ACPI_DESC_TYPE_OPERAND:
  278. type = obj_desc->common.type;
  279. break;
  280. case ACPI_DESC_TYPE_NAMED:
  281. type = ((struct acpi_namespace_node *) obj_desc)->type;
  282. obj_desc = acpi_ns_get_attached_object ((struct acpi_namespace_node *) obj_desc);
  283. /* If we had an Alias node, use the attached object for type info */
  284. if (type == ACPI_TYPE_LOCAL_ALIAS) {
  285. type = ((struct acpi_namespace_node *) obj_desc)->type;
  286. obj_desc = acpi_ns_get_attached_object ((struct acpi_namespace_node *) obj_desc);
  287. }
  288. break;
  289. default:
  290. return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
  291. }
  292. /* If type is anything other than a reference, we are done */
  293. if (type != ACPI_TYPE_LOCAL_REFERENCE) {
  294. goto exit;
  295. }
  296. /*
  297. * For reference objects created via the ref_of or Index operators,
  298. * we need to get to the base object (as per the ACPI specification
  299. * of the object_type and size_of operators). This means traversing
  300. * the list of possibly many nested references.
  301. */
  302. while (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_LOCAL_REFERENCE) {
  303. switch (obj_desc->reference.opcode) {
  304. case AML_REF_OF_OP:
  305. /* Dereference the reference pointer */
  306. node = obj_desc->reference.object;
  307. /* All "References" point to a NS node */
  308. if (ACPI_GET_DESCRIPTOR_TYPE (node) != ACPI_DESC_TYPE_NAMED) {
  309. ACPI_REPORT_ERROR ((
  310. "acpi_ex_resolve_multiple: Not a NS node %p [%s]\n",
  311. node, acpi_ut_get_descriptor_name (node)));
  312. return_ACPI_STATUS (AE_AML_INTERNAL);
  313. }
  314. /* Get the attached object */
  315. obj_desc = acpi_ns_get_attached_object (node);
  316. if (!obj_desc) {
  317. /* No object, use the NS node type */
  318. type = acpi_ns_get_type (node);
  319. goto exit;
  320. }
  321. /* Check for circular references */
  322. if (obj_desc == operand) {
  323. return_ACPI_STATUS (AE_AML_CIRCULAR_REFERENCE);
  324. }
  325. break;
  326. case AML_INDEX_OP:
  327. /* Get the type of this reference (index into another object) */
  328. type = obj_desc->reference.target_type;
  329. if (type != ACPI_TYPE_PACKAGE) {
  330. goto exit;
  331. }
  332. /*
  333. * The main object is a package, we want to get the type
  334. * of the individual package element that is referenced by
  335. * the index.
  336. *
  337. * This could of course in turn be another reference object.
  338. */
  339. obj_desc = *(obj_desc->reference.where);
  340. if (!obj_desc) {
  341. /* NULL package elements are allowed */
  342. type = 0; /* Uninitialized */
  343. goto exit;
  344. }
  345. break;
  346. case AML_INT_NAMEPATH_OP:
  347. /* Dereference the reference pointer */
  348. node = obj_desc->reference.node;
  349. /* All "References" point to a NS node */
  350. if (ACPI_GET_DESCRIPTOR_TYPE (node) != ACPI_DESC_TYPE_NAMED) {
  351. ACPI_REPORT_ERROR ((
  352. "acpi_ex_resolve_multiple: Not a NS node %p [%s]\n",
  353. node, acpi_ut_get_descriptor_name (node)));
  354. return_ACPI_STATUS (AE_AML_INTERNAL);
  355. }
  356. /* Get the attached object */
  357. obj_desc = acpi_ns_get_attached_object (node);
  358. if (!obj_desc) {
  359. /* No object, use the NS node type */
  360. type = acpi_ns_get_type (node);
  361. goto exit;
  362. }
  363. /* Check for circular references */
  364. if (obj_desc == operand) {
  365. return_ACPI_STATUS (AE_AML_CIRCULAR_REFERENCE);
  366. }
  367. break;
  368. case AML_LOCAL_OP:
  369. case AML_ARG_OP:
  370. if (return_desc) {
  371. status = acpi_ds_method_data_get_value (obj_desc->reference.opcode,
  372. obj_desc->reference.offset, walk_state, &obj_desc);
  373. if (ACPI_FAILURE (status)) {
  374. return_ACPI_STATUS (status);
  375. }
  376. acpi_ut_remove_reference (obj_desc);
  377. }
  378. else {
  379. status = acpi_ds_method_data_get_node (obj_desc->reference.opcode,
  380. obj_desc->reference.offset, walk_state, &node);
  381. if (ACPI_FAILURE (status)) {
  382. return_ACPI_STATUS (status);
  383. }
  384. obj_desc = acpi_ns_get_attached_object (node);
  385. if (!obj_desc) {
  386. type = ACPI_TYPE_ANY;
  387. goto exit;
  388. }
  389. }
  390. break;
  391. case AML_DEBUG_OP:
  392. /* The Debug Object is of type "debug_object" */
  393. type = ACPI_TYPE_DEBUG_OBJECT;
  394. goto exit;
  395. default:
  396. ACPI_REPORT_ERROR ((
  397. "acpi_ex_resolve_multiple: Unknown Reference subtype %X\n",
  398. obj_desc->reference.opcode));
  399. return_ACPI_STATUS (AE_AML_INTERNAL);
  400. }
  401. }
  402. /*
  403. * Now we are guaranteed to have an object that has not been created
  404. * via the ref_of or Index operators.
  405. */
  406. type = ACPI_GET_OBJECT_TYPE (obj_desc);
  407. exit:
  408. /* Convert internal types to external types */
  409. switch (type) {
  410. case ACPI_TYPE_LOCAL_REGION_FIELD:
  411. case ACPI_TYPE_LOCAL_BANK_FIELD:
  412. case ACPI_TYPE_LOCAL_INDEX_FIELD:
  413. type = ACPI_TYPE_FIELD_UNIT;
  414. break;
  415. case ACPI_TYPE_LOCAL_SCOPE:
  416. /* Per ACPI Specification, Scope is untyped */
  417. type = ACPI_TYPE_ANY;
  418. break;
  419. default:
  420. /* No change to Type required */
  421. break;
  422. }
  423. *return_type = type;
  424. if (return_desc) {
  425. *return_desc = obj_desc;
  426. }
  427. return_ACPI_STATUS (AE_OK);
  428. }