exresnte.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /******************************************************************************
  2. *
  3. * Module Name: exresnte - AML Interpreter object resolution
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2015, 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 "accommon.h"
  44. #include "acdispat.h"
  45. #include "acinterp.h"
  46. #include "acnamesp.h"
  47. #define _COMPONENT ACPI_EXECUTER
  48. ACPI_MODULE_NAME("exresnte")
  49. /*******************************************************************************
  50. *
  51. * FUNCTION: acpi_ex_resolve_node_to_value
  52. *
  53. * PARAMETERS: object_ptr - Pointer to a location that contains
  54. * a pointer to a NS node, and will receive a
  55. * pointer to the resolved object.
  56. * walk_state - Current state. Valid only if executing AML
  57. * code. NULL if simply resolving an object
  58. *
  59. * RETURN: Status
  60. *
  61. * DESCRIPTION: Resolve a Namespace node to a valued object
  62. *
  63. * Note: for some of the data types, the pointer attached to the Node
  64. * can be either a pointer to an actual internal object or a pointer into the
  65. * AML stream itself. These types are currently:
  66. *
  67. * ACPI_TYPE_INTEGER
  68. * ACPI_TYPE_STRING
  69. * ACPI_TYPE_BUFFER
  70. * ACPI_TYPE_MUTEX
  71. * ACPI_TYPE_PACKAGE
  72. *
  73. ******************************************************************************/
  74. acpi_status
  75. acpi_ex_resolve_node_to_value(struct acpi_namespace_node **object_ptr,
  76. struct acpi_walk_state *walk_state)
  77. {
  78. acpi_status status = AE_OK;
  79. union acpi_operand_object *source_desc;
  80. union acpi_operand_object *obj_desc = NULL;
  81. struct acpi_namespace_node *node;
  82. acpi_object_type entry_type;
  83. ACPI_FUNCTION_TRACE(ex_resolve_node_to_value);
  84. /*
  85. * The stack pointer points to a struct acpi_namespace_node (Node). Get the
  86. * object that is attached to the Node.
  87. */
  88. node = *object_ptr;
  89. source_desc = acpi_ns_get_attached_object(node);
  90. entry_type = acpi_ns_get_type((acpi_handle) node);
  91. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Entry=%p SourceDesc=%p [%s]\n",
  92. node, source_desc,
  93. acpi_ut_get_type_name(entry_type)));
  94. if ((entry_type == ACPI_TYPE_LOCAL_ALIAS) ||
  95. (entry_type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) {
  96. /* There is always exactly one level of indirection */
  97. node = ACPI_CAST_PTR(struct acpi_namespace_node, node->object);
  98. source_desc = acpi_ns_get_attached_object(node);
  99. entry_type = acpi_ns_get_type((acpi_handle) node);
  100. *object_ptr = node;
  101. }
  102. /*
  103. * Several object types require no further processing:
  104. * 1) Device/Thermal objects don't have a "real" subobject, return the Node
  105. * 2) Method locals and arguments have a pseudo-Node
  106. * 3) 10/2007: Added method type to assist with Package construction.
  107. */
  108. if ((entry_type == ACPI_TYPE_DEVICE) ||
  109. (entry_type == ACPI_TYPE_THERMAL) ||
  110. (entry_type == ACPI_TYPE_METHOD) ||
  111. (node->flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL))) {
  112. return_ACPI_STATUS(AE_OK);
  113. }
  114. if (!source_desc) {
  115. ACPI_ERROR((AE_INFO, "No object attached to node [%4.4s] %p",
  116. node->name.ascii, node));
  117. return_ACPI_STATUS(AE_AML_UNINITIALIZED_NODE);
  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 (source_desc->common.type != 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 (source_desc->common.type != 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 (source_desc->common.type != 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 (source_desc->common.type != 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.class) {
  198. case ACPI_REFCLASS_TABLE: /* This is a ddb_handle */
  199. case ACPI_REFCLASS_REFOF:
  200. case ACPI_REFCLASS_INDEX:
  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 type 0x%X",
  209. source_desc->reference.class));
  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 0x%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. }