exresnte.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /******************************************************************************
  2. *
  3. * Module Name: exresnte - 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/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 SourceDesc=%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) Device/Thermal objects don't have a "real" subobject, return the Node
  106. * 2) Method locals and arguments have a pseudo-Node
  107. * 3) 10/2007: Added method type to assist with Package construction.
  108. */
  109. if ((entry_type == ACPI_TYPE_DEVICE) ||
  110. (entry_type == ACPI_TYPE_THERMAL) ||
  111. (entry_type == ACPI_TYPE_METHOD) ||
  112. (node->flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL))) {
  113. return_ACPI_STATUS(AE_OK);
  114. }
  115. if (!source_desc) {
  116. ACPI_ERROR((AE_INFO, "No object attached to node %p", node));
  117. return_ACPI_STATUS(AE_AML_NO_OPERAND);
  118. }
  119. /*
  120. * Action is based on the type of the Node, which indicates the type
  121. * of the attached object or pointer
  122. */
  123. switch (entry_type) {
  124. case ACPI_TYPE_PACKAGE:
  125. if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_PACKAGE) {
  126. ACPI_ERROR((AE_INFO, "Object not a Package, type %s",
  127. acpi_ut_get_object_type_name(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_ERROR((AE_INFO, "Object not a Buffer, type %s",
  140. acpi_ut_get_object_type_name(source_desc)));
  141. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  142. }
  143. status = acpi_ds_get_buffer_arguments(source_desc);
  144. if (ACPI_SUCCESS(status)) {
  145. /* Return an additional reference to the object */
  146. obj_desc = source_desc;
  147. acpi_ut_add_reference(obj_desc);
  148. }
  149. break;
  150. case ACPI_TYPE_STRING:
  151. if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_STRING) {
  152. ACPI_ERROR((AE_INFO, "Object not a String, type %s",
  153. acpi_ut_get_object_type_name(source_desc)));
  154. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  155. }
  156. /* Return an additional reference to the object */
  157. obj_desc = source_desc;
  158. acpi_ut_add_reference(obj_desc);
  159. break;
  160. case ACPI_TYPE_INTEGER:
  161. if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_INTEGER) {
  162. ACPI_ERROR((AE_INFO, "Object not a Integer, type %s",
  163. acpi_ut_get_object_type_name(source_desc)));
  164. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  165. }
  166. /* Return an additional reference to the object */
  167. obj_desc = source_desc;
  168. acpi_ut_add_reference(obj_desc);
  169. break;
  170. case ACPI_TYPE_BUFFER_FIELD:
  171. case ACPI_TYPE_LOCAL_REGION_FIELD:
  172. case ACPI_TYPE_LOCAL_BANK_FIELD:
  173. case ACPI_TYPE_LOCAL_INDEX_FIELD:
  174. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  175. "FieldRead Node=%p SourceDesc=%p Type=%X\n",
  176. node, source_desc, entry_type));
  177. status =
  178. acpi_ex_read_data_from_field(walk_state, source_desc,
  179. &obj_desc);
  180. break;
  181. /* For these objects, just return the object attached to the Node */
  182. case ACPI_TYPE_MUTEX:
  183. case ACPI_TYPE_POWER:
  184. case ACPI_TYPE_PROCESSOR:
  185. case ACPI_TYPE_EVENT:
  186. case ACPI_TYPE_REGION:
  187. /* Return an additional reference to the object */
  188. obj_desc = source_desc;
  189. acpi_ut_add_reference(obj_desc);
  190. break;
  191. /* TYPE_ANY is untyped, and thus there is no object associated with it */
  192. case ACPI_TYPE_ANY:
  193. ACPI_ERROR((AE_INFO,
  194. "Untyped entry %p, no attached object!", node));
  195. return_ACPI_STATUS(AE_AML_OPERAND_TYPE); /* Cannot be AE_TYPE */
  196. case ACPI_TYPE_LOCAL_REFERENCE:
  197. switch (source_desc->reference.opcode) {
  198. case AML_LOAD_OP: /* This is a ddb_handle */
  199. case AML_REF_OF_OP:
  200. case AML_INDEX_OP:
  201. /* Return an additional reference to the object */
  202. obj_desc = source_desc;
  203. acpi_ut_add_reference(obj_desc);
  204. break;
  205. default:
  206. /* No named references are allowed here */
  207. ACPI_ERROR((AE_INFO,
  208. "Unsupported Reference opcode %X (%s)",
  209. source_desc->reference.opcode,
  210. acpi_ps_get_opcode_name(source_desc->
  211. reference.opcode)));
  212. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  213. }
  214. break;
  215. default:
  216. /* Default case is for unknown types */
  217. ACPI_ERROR((AE_INFO,
  218. "Node %p - Unknown object type %X",
  219. node, entry_type));
  220. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  221. } /* switch (entry_type) */
  222. /* Return the object descriptor */
  223. *object_ptr = (void *)obj_desc;
  224. return_ACPI_STATUS(status);
  225. }