exresnte.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /******************************************************************************
  2. *
  3. * Module Name: exresnte - AML Interpreter object resolution
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2006, 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_ERROR((AE_INFO, "No object attached to node %p", node));
  114. return_ACPI_STATUS(AE_AML_NO_OPERAND);
  115. }
  116. /*
  117. * Action is based on the type of the Node, which indicates the type
  118. * of the attached object or pointer
  119. */
  120. switch (entry_type) {
  121. case ACPI_TYPE_PACKAGE:
  122. if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_PACKAGE) {
  123. ACPI_ERROR((AE_INFO, "Object not a Package, type %s",
  124. acpi_ut_get_object_type_name(source_desc)));
  125. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  126. }
  127. status = acpi_ds_get_package_arguments(source_desc);
  128. if (ACPI_SUCCESS(status)) {
  129. /* Return an additional reference to the object */
  130. obj_desc = source_desc;
  131. acpi_ut_add_reference(obj_desc);
  132. }
  133. break;
  134. case ACPI_TYPE_BUFFER:
  135. if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_BUFFER) {
  136. ACPI_ERROR((AE_INFO, "Object not a Buffer, type %s",
  137. acpi_ut_get_object_type_name(source_desc)));
  138. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  139. }
  140. status = acpi_ds_get_buffer_arguments(source_desc);
  141. if (ACPI_SUCCESS(status)) {
  142. /* Return an additional reference to the object */
  143. obj_desc = source_desc;
  144. acpi_ut_add_reference(obj_desc);
  145. }
  146. break;
  147. case ACPI_TYPE_STRING:
  148. if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_STRING) {
  149. ACPI_ERROR((AE_INFO, "Object not a String, type %s",
  150. acpi_ut_get_object_type_name(source_desc)));
  151. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  152. }
  153. /* Return an additional reference to the object */
  154. obj_desc = source_desc;
  155. acpi_ut_add_reference(obj_desc);
  156. break;
  157. case ACPI_TYPE_INTEGER:
  158. if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_INTEGER) {
  159. ACPI_ERROR((AE_INFO, "Object not a Integer, type %s",
  160. acpi_ut_get_object_type_name(source_desc)));
  161. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  162. }
  163. /* Return an additional reference to the object */
  164. obj_desc = source_desc;
  165. acpi_ut_add_reference(obj_desc);
  166. break;
  167. case ACPI_TYPE_BUFFER_FIELD:
  168. case ACPI_TYPE_LOCAL_REGION_FIELD:
  169. case ACPI_TYPE_LOCAL_BANK_FIELD:
  170. case ACPI_TYPE_LOCAL_INDEX_FIELD:
  171. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  172. "field_read Node=%p source_desc=%p Type=%X\n",
  173. node, source_desc, entry_type));
  174. status =
  175. acpi_ex_read_data_from_field(walk_state, source_desc,
  176. &obj_desc);
  177. break;
  178. /* For these objects, just return the object attached to the Node */
  179. case ACPI_TYPE_MUTEX:
  180. case ACPI_TYPE_METHOD:
  181. case ACPI_TYPE_POWER:
  182. case ACPI_TYPE_PROCESSOR:
  183. case ACPI_TYPE_THERMAL:
  184. case ACPI_TYPE_EVENT:
  185. case ACPI_TYPE_REGION:
  186. /* Return an additional reference to the object */
  187. obj_desc = source_desc;
  188. acpi_ut_add_reference(obj_desc);
  189. break;
  190. /* TYPE_ANY is untyped, and thus there is no object associated with it */
  191. case ACPI_TYPE_ANY:
  192. ACPI_ERROR((AE_INFO,
  193. "Untyped entry %p, no attached object!", node));
  194. return_ACPI_STATUS(AE_AML_OPERAND_TYPE); /* Cannot be AE_TYPE */
  195. case ACPI_TYPE_LOCAL_REFERENCE:
  196. switch (source_desc->reference.opcode) {
  197. case AML_LOAD_OP:
  198. /* This is a ddb_handle */
  199. /* Return an additional reference to the object */
  200. obj_desc = source_desc;
  201. acpi_ut_add_reference(obj_desc);
  202. break;
  203. default:
  204. /* No named references are allowed here */
  205. ACPI_ERROR((AE_INFO,
  206. "Unsupported Reference opcode %X (%s)",
  207. source_desc->reference.opcode,
  208. acpi_ps_get_opcode_name(source_desc->
  209. reference.opcode)));
  210. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  211. }
  212. break;
  213. default:
  214. /* Default case is for unknown types */
  215. ACPI_ERROR((AE_INFO,
  216. "Node %p - Unknown object type %X",
  217. node, entry_type));
  218. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  219. } /* switch (entry_type) */
  220. /* Return the object descriptor */
  221. *object_ptr = (void *)obj_desc;
  222. return_ACPI_STATUS(status);
  223. }