exresnte.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /******************************************************************************
  2. *
  3. * Module Name: exresnte - 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/acdispat.h>
  44. #include <acpi/acinterp.h>
  45. #include <acpi/acnamesp.h>
  46. #include <acpi/acparser.h>
  47. #include <acpi/amlcode.h>
  48. #define _COMPONENT ACPI_EXECUTER
  49. ACPI_MODULE_NAME("exresnte")
  50. /*******************************************************************************
  51. *
  52. * FUNCTION: acpi_ex_resolve_node_to_value
  53. *
  54. * PARAMETERS: object_ptr - Pointer to a location that contains
  55. * a pointer to a NS node, and will receive a
  56. * pointer to the resolved object.
  57. * walk_state - Current state. Valid only if executing AML
  58. * code. NULL if simply resolving an object
  59. *
  60. * RETURN: Status
  61. *
  62. * DESCRIPTION: Resolve a Namespace node to a valued object
  63. *
  64. * Note: for some of the data types, the pointer attached to the Node
  65. * can be either a pointer to an actual internal object or a pointer into the
  66. * AML stream itself. These types are currently:
  67. *
  68. * ACPI_TYPE_INTEGER
  69. * ACPI_TYPE_STRING
  70. * ACPI_TYPE_BUFFER
  71. * ACPI_TYPE_MUTEX
  72. * ACPI_TYPE_PACKAGE
  73. *
  74. ******************************************************************************/
  75. acpi_status
  76. acpi_ex_resolve_node_to_value(struct acpi_namespace_node **object_ptr,
  77. struct acpi_walk_state *walk_state)
  78. {
  79. acpi_status status = AE_OK;
  80. union acpi_operand_object *source_desc;
  81. union acpi_operand_object *obj_desc = NULL;
  82. struct acpi_namespace_node *node;
  83. acpi_object_type entry_type;
  84. ACPI_FUNCTION_TRACE("ex_resolve_node_to_value");
  85. /*
  86. * The stack pointer points to a struct acpi_namespace_node (Node). Get the
  87. * object that is attached to the Node.
  88. */
  89. node = *object_ptr;
  90. source_desc = acpi_ns_get_attached_object(node);
  91. entry_type = acpi_ns_get_type((acpi_handle) node);
  92. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Entry=%p source_desc=%p [%s]\n",
  93. node, source_desc,
  94. acpi_ut_get_type_name(entry_type)));
  95. if ((entry_type == ACPI_TYPE_LOCAL_ALIAS) ||
  96. (entry_type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) {
  97. /* There is always exactly one level of indirection */
  98. node = ACPI_CAST_PTR(struct acpi_namespace_node, node->object);
  99. source_desc = acpi_ns_get_attached_object(node);
  100. entry_type = acpi_ns_get_type((acpi_handle) node);
  101. *object_ptr = node;
  102. }
  103. /*
  104. * Several object types require no further processing:
  105. * 1) Devices rarely have an attached object, return the Node
  106. * 2) Method locals and arguments have a pseudo-Node
  107. */
  108. if (entry_type == ACPI_TYPE_DEVICE ||
  109. (node->flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL))) {
  110. return_ACPI_STATUS(AE_OK);
  111. }
  112. if (!source_desc) {
  113. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  114. "No object attached to node %p\n", node));
  115. return_ACPI_STATUS(AE_AML_NO_OPERAND);
  116. }
  117. /*
  118. * Action is based on the type of the Node, which indicates the type
  119. * of the attached object or pointer
  120. */
  121. switch (entry_type) {
  122. case ACPI_TYPE_PACKAGE:
  123. if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_PACKAGE) {
  124. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  125. "Object not a Package, type %s\n",
  126. acpi_ut_get_object_type_name
  127. (source_desc)));
  128. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  129. }
  130. status = acpi_ds_get_package_arguments(source_desc);
  131. if (ACPI_SUCCESS(status)) {
  132. /* Return an additional reference to the object */
  133. obj_desc = source_desc;
  134. acpi_ut_add_reference(obj_desc);
  135. }
  136. break;
  137. case ACPI_TYPE_BUFFER:
  138. if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_BUFFER) {
  139. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  140. "Object not a Buffer, type %s\n",
  141. acpi_ut_get_object_type_name
  142. (source_desc)));
  143. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  144. }
  145. status = acpi_ds_get_buffer_arguments(source_desc);
  146. if (ACPI_SUCCESS(status)) {
  147. /* Return an additional reference to the object */
  148. obj_desc = source_desc;
  149. acpi_ut_add_reference(obj_desc);
  150. }
  151. break;
  152. case ACPI_TYPE_STRING:
  153. if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_STRING) {
  154. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  155. "Object not a String, type %s\n",
  156. acpi_ut_get_object_type_name
  157. (source_desc)));
  158. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  159. }
  160. /* Return an additional reference to the object */
  161. obj_desc = source_desc;
  162. acpi_ut_add_reference(obj_desc);
  163. break;
  164. case ACPI_TYPE_INTEGER:
  165. if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_INTEGER) {
  166. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  167. "Object not a Integer, type %s\n",
  168. acpi_ut_get_object_type_name
  169. (source_desc)));
  170. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  171. }
  172. /* Return an additional reference to the object */
  173. obj_desc = source_desc;
  174. acpi_ut_add_reference(obj_desc);
  175. break;
  176. case ACPI_TYPE_BUFFER_FIELD:
  177. case ACPI_TYPE_LOCAL_REGION_FIELD:
  178. case ACPI_TYPE_LOCAL_BANK_FIELD:
  179. case ACPI_TYPE_LOCAL_INDEX_FIELD:
  180. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  181. "field_read Node=%p source_desc=%p Type=%X\n",
  182. node, source_desc, entry_type));
  183. status =
  184. acpi_ex_read_data_from_field(walk_state, source_desc,
  185. &obj_desc);
  186. break;
  187. /* For these objects, just return the object attached to the Node */
  188. case ACPI_TYPE_MUTEX:
  189. case ACPI_TYPE_METHOD:
  190. case ACPI_TYPE_POWER:
  191. case ACPI_TYPE_PROCESSOR:
  192. case ACPI_TYPE_THERMAL:
  193. case ACPI_TYPE_EVENT:
  194. case ACPI_TYPE_REGION:
  195. /* Return an additional reference to the object */
  196. obj_desc = source_desc;
  197. acpi_ut_add_reference(obj_desc);
  198. break;
  199. /* TYPE_ANY is untyped, and thus there is no object associated with it */
  200. case ACPI_TYPE_ANY:
  201. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  202. "Untyped entry %p, no attached object!\n",
  203. node));
  204. return_ACPI_STATUS(AE_AML_OPERAND_TYPE); /* Cannot be AE_TYPE */
  205. case ACPI_TYPE_LOCAL_REFERENCE:
  206. switch (source_desc->reference.opcode) {
  207. case AML_LOAD_OP:
  208. /* This is a ddb_handle */
  209. /* Return an additional reference to the object */
  210. obj_desc = source_desc;
  211. acpi_ut_add_reference(obj_desc);
  212. break;
  213. default:
  214. /* No named references are allowed here */
  215. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  216. "Unsupported Reference opcode %X (%s)\n",
  217. source_desc->reference.opcode,
  218. acpi_ps_get_opcode_name(source_desc->
  219. reference.
  220. opcode)));
  221. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  222. }
  223. break;
  224. default:
  225. /* Default case is for unknown types */
  226. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  227. "Node %p - Unknown object type %X\n",
  228. node, entry_type));
  229. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  230. } /* switch (entry_type) */
  231. /* Return the object descriptor */
  232. *object_ptr = (void *)obj_desc;
  233. return_ACPI_STATUS(status);
  234. }