exresolv.c 14 KB

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