exresolv.c 14 KB

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