exresnte.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2. /******************************************************************************
  3. *
  4. * Module Name: exresnte - AML Interpreter object resolution
  5. *
  6. * Copyright (C) 2000 - 2022, Intel Corp.
  7. *
  8. *****************************************************************************/
  9. #include <acpi/acpi.h>
  10. #include "accommon.h"
  11. #include "acdispat.h"
  12. #include "acinterp.h"
  13. #include "acnamesp.h"
  14. #define _COMPONENT ACPI_EXECUTER
  15. ACPI_MODULE_NAME("exresnte")
  16. /*******************************************************************************
  17. *
  18. * FUNCTION: acpi_ex_resolve_node_to_value
  19. *
  20. * PARAMETERS: object_ptr - Pointer to a location that contains
  21. * a pointer to a NS node, and will receive a
  22. * pointer to the resolved object.
  23. * walk_state - Current state. Valid only if executing AML
  24. * code. NULL if simply resolving an object
  25. *
  26. * RETURN: Status
  27. *
  28. * DESCRIPTION: Resolve a Namespace node to a valued object
  29. *
  30. * Note: for some of the data types, the pointer attached to the Node
  31. * can be either a pointer to an actual internal object or a pointer into the
  32. * AML stream itself. These types are currently:
  33. *
  34. * ACPI_TYPE_INTEGER
  35. * ACPI_TYPE_STRING
  36. * ACPI_TYPE_BUFFER
  37. * ACPI_TYPE_MUTEX
  38. * ACPI_TYPE_PACKAGE
  39. *
  40. ******************************************************************************/
  41. acpi_status
  42. acpi_ex_resolve_node_to_value(struct acpi_namespace_node **object_ptr,
  43. struct acpi_walk_state *walk_state)
  44. {
  45. acpi_status status = AE_OK;
  46. union acpi_operand_object *source_desc;
  47. union acpi_operand_object *obj_desc = NULL;
  48. struct acpi_namespace_node *node;
  49. acpi_object_type entry_type;
  50. ACPI_FUNCTION_TRACE(ex_resolve_node_to_value);
  51. /*
  52. * The stack pointer points to a struct acpi_namespace_node (Node). Get the
  53. * object that is attached to the Node.
  54. */
  55. node = *object_ptr;
  56. source_desc = acpi_ns_get_attached_object(node);
  57. entry_type = acpi_ns_get_type((acpi_handle)node);
  58. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Entry=%p SourceDesc=%p [%s]\n",
  59. node, source_desc,
  60. acpi_ut_get_type_name(entry_type)));
  61. if ((entry_type == ACPI_TYPE_LOCAL_ALIAS) ||
  62. (entry_type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) {
  63. /* There is always exactly one level of indirection */
  64. node = ACPI_CAST_PTR(struct acpi_namespace_node, node->object);
  65. source_desc = acpi_ns_get_attached_object(node);
  66. entry_type = acpi_ns_get_type((acpi_handle)node);
  67. *object_ptr = node;
  68. }
  69. /*
  70. * Several object types require no further processing:
  71. * 1) Device/Thermal objects don't have a "real" subobject, return Node
  72. * 2) Method locals and arguments have a pseudo-Node
  73. * 3) 10/2007: Added method type to assist with Package construction.
  74. */
  75. if ((entry_type == ACPI_TYPE_DEVICE) ||
  76. (entry_type == ACPI_TYPE_THERMAL) ||
  77. (entry_type == ACPI_TYPE_METHOD) ||
  78. (node->flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL))) {
  79. return_ACPI_STATUS(AE_OK);
  80. }
  81. if (!source_desc) {
  82. ACPI_ERROR((AE_INFO, "No object attached to node [%4.4s] %p",
  83. node->name.ascii, node));
  84. return_ACPI_STATUS(AE_AML_UNINITIALIZED_NODE);
  85. }
  86. /*
  87. * Action is based on the type of the Node, which indicates the type
  88. * of the attached object or pointer
  89. */
  90. switch (entry_type) {
  91. case ACPI_TYPE_PACKAGE:
  92. if (source_desc->common.type != ACPI_TYPE_PACKAGE) {
  93. ACPI_ERROR((AE_INFO, "Object not a Package, type %s",
  94. acpi_ut_get_object_type_name(source_desc)));
  95. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  96. }
  97. status = acpi_ds_get_package_arguments(source_desc);
  98. if (ACPI_SUCCESS(status)) {
  99. /* Return an additional reference to the object */
  100. obj_desc = source_desc;
  101. acpi_ut_add_reference(obj_desc);
  102. }
  103. break;
  104. case ACPI_TYPE_BUFFER:
  105. if (source_desc->common.type != ACPI_TYPE_BUFFER) {
  106. ACPI_ERROR((AE_INFO, "Object not a Buffer, type %s",
  107. acpi_ut_get_object_type_name(source_desc)));
  108. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  109. }
  110. status = acpi_ds_get_buffer_arguments(source_desc);
  111. if (ACPI_SUCCESS(status)) {
  112. /* Return an additional reference to the object */
  113. obj_desc = source_desc;
  114. acpi_ut_add_reference(obj_desc);
  115. }
  116. break;
  117. case ACPI_TYPE_STRING:
  118. if (source_desc->common.type != ACPI_TYPE_STRING) {
  119. ACPI_ERROR((AE_INFO, "Object not a String, type %s",
  120. acpi_ut_get_object_type_name(source_desc)));
  121. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  122. }
  123. /* Return an additional reference to the object */
  124. obj_desc = source_desc;
  125. acpi_ut_add_reference(obj_desc);
  126. break;
  127. case ACPI_TYPE_INTEGER:
  128. if (source_desc->common.type != ACPI_TYPE_INTEGER) {
  129. ACPI_ERROR((AE_INFO, "Object not a Integer, type %s",
  130. acpi_ut_get_object_type_name(source_desc)));
  131. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  132. }
  133. /* Return an additional reference to the object */
  134. obj_desc = source_desc;
  135. acpi_ut_add_reference(obj_desc);
  136. break;
  137. case ACPI_TYPE_BUFFER_FIELD:
  138. case ACPI_TYPE_LOCAL_REGION_FIELD:
  139. case ACPI_TYPE_LOCAL_BANK_FIELD:
  140. case ACPI_TYPE_LOCAL_INDEX_FIELD:
  141. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  142. "FieldRead Node=%p SourceDesc=%p Type=%X\n",
  143. node, source_desc, entry_type));
  144. status =
  145. acpi_ex_read_data_from_field(walk_state, source_desc,
  146. &obj_desc);
  147. break;
  148. /* For these objects, just return the object attached to the Node */
  149. case ACPI_TYPE_MUTEX:
  150. case ACPI_TYPE_POWER:
  151. case ACPI_TYPE_PROCESSOR:
  152. case ACPI_TYPE_EVENT:
  153. case ACPI_TYPE_REGION:
  154. /* Return an additional reference to the object */
  155. obj_desc = source_desc;
  156. acpi_ut_add_reference(obj_desc);
  157. break;
  158. /* TYPE_ANY is untyped, and thus there is no object associated with it */
  159. case ACPI_TYPE_ANY:
  160. ACPI_ERROR((AE_INFO,
  161. "Untyped entry %p, no attached object!", node));
  162. return_ACPI_STATUS(AE_AML_OPERAND_TYPE); /* Cannot be AE_TYPE */
  163. case ACPI_TYPE_LOCAL_REFERENCE:
  164. switch (source_desc->reference.class) {
  165. case ACPI_REFCLASS_TABLE: /* This is a ddb_handle */
  166. case ACPI_REFCLASS_REFOF:
  167. case ACPI_REFCLASS_INDEX:
  168. /* Return an additional reference to the object */
  169. obj_desc = source_desc;
  170. acpi_ut_add_reference(obj_desc);
  171. break;
  172. default:
  173. /* No named references are allowed here */
  174. ACPI_ERROR((AE_INFO,
  175. "Unsupported Reference type 0x%X",
  176. source_desc->reference.class));
  177. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  178. }
  179. break;
  180. default:
  181. /* Default case is for unknown types */
  182. ACPI_ERROR((AE_INFO,
  183. "Node %p - Unknown object type 0x%X",
  184. node, entry_type));
  185. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  186. } /* switch (entry_type) */
  187. /* Return the object descriptor */
  188. *object_ptr = (void *)obj_desc;
  189. return_ACPI_STATUS(status);
  190. }