dsinit.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2. /******************************************************************************
  3. *
  4. * Module Name: dsinit - Object initialization namespace walk
  5. *
  6. * Copyright (C) 2000 - 2018, Intel Corp.
  7. *
  8. *****************************************************************************/
  9. #include <acpi/acpi.h>
  10. #include "accommon.h"
  11. #include "acdispat.h"
  12. #include "acnamesp.h"
  13. #include "actables.h"
  14. #include "acinterp.h"
  15. #define _COMPONENT ACPI_DISPATCHER
  16. ACPI_MODULE_NAME("dsinit")
  17. /* Local prototypes */
  18. static acpi_status
  19. acpi_ds_init_one_object(acpi_handle obj_handle,
  20. u32 level, void *context, void **return_value);
  21. /*******************************************************************************
  22. *
  23. * FUNCTION: acpi_ds_init_one_object
  24. *
  25. * PARAMETERS: obj_handle - Node for the object
  26. * level - Current nesting level
  27. * context - Points to a init info struct
  28. * return_value - Not used
  29. *
  30. * RETURN: Status
  31. *
  32. * DESCRIPTION: Callback from acpi_walk_namespace. Invoked for every object
  33. * within the namespace.
  34. *
  35. * Currently, the only objects that require initialization are:
  36. * 1) Methods
  37. * 2) Operation Regions
  38. *
  39. ******************************************************************************/
  40. static acpi_status
  41. acpi_ds_init_one_object(acpi_handle obj_handle,
  42. u32 level, void *context, void **return_value)
  43. {
  44. struct acpi_init_walk_info *info =
  45. (struct acpi_init_walk_info *)context;
  46. struct acpi_namespace_node *node =
  47. (struct acpi_namespace_node *)obj_handle;
  48. acpi_status status;
  49. union acpi_operand_object *obj_desc;
  50. ACPI_FUNCTION_ENTRY();
  51. /*
  52. * We are only interested in NS nodes owned by the table that
  53. * was just loaded
  54. */
  55. if (node->owner_id != info->owner_id) {
  56. return (AE_OK);
  57. }
  58. info->object_count++;
  59. /* And even then, we are only interested in a few object types */
  60. switch (acpi_ns_get_type(obj_handle)) {
  61. case ACPI_TYPE_REGION:
  62. status = acpi_ds_initialize_region(obj_handle);
  63. if (ACPI_FAILURE(status)) {
  64. ACPI_EXCEPTION((AE_INFO, status,
  65. "During Region initialization %p [%4.4s]",
  66. obj_handle,
  67. acpi_ut_get_node_name(obj_handle)));
  68. }
  69. info->op_region_count++;
  70. break;
  71. case ACPI_TYPE_METHOD:
  72. /*
  73. * Auto-serialization support. We will examine each method that is
  74. * not_serialized to determine if it creates any Named objects. If
  75. * it does, it will be marked serialized to prevent problems if
  76. * the method is entered by two or more threads and an attempt is
  77. * made to create the same named object twice -- which results in
  78. * an AE_ALREADY_EXISTS exception and method abort.
  79. */
  80. info->method_count++;
  81. obj_desc = acpi_ns_get_attached_object(node);
  82. if (!obj_desc) {
  83. break;
  84. }
  85. /* Ignore if already serialized */
  86. if (obj_desc->method.info_flags & ACPI_METHOD_SERIALIZED) {
  87. info->serial_method_count++;
  88. break;
  89. }
  90. if (acpi_gbl_auto_serialize_methods) {
  91. /* Parse/scan method and serialize it if necessary */
  92. acpi_ds_auto_serialize_method(node, obj_desc);
  93. if (obj_desc->method.
  94. info_flags & ACPI_METHOD_SERIALIZED) {
  95. /* Method was just converted to Serialized */
  96. info->serial_method_count++;
  97. info->serialized_method_count++;
  98. break;
  99. }
  100. }
  101. info->non_serial_method_count++;
  102. break;
  103. case ACPI_TYPE_DEVICE:
  104. info->device_count++;
  105. break;
  106. default:
  107. break;
  108. }
  109. /*
  110. * We ignore errors from above, and always return OK, since
  111. * we don't want to abort the walk on a single error.
  112. */
  113. return (AE_OK);
  114. }
  115. /*******************************************************************************
  116. *
  117. * FUNCTION: acpi_ds_initialize_objects
  118. *
  119. * PARAMETERS: table_desc - Descriptor for parent ACPI table
  120. * start_node - Root of subtree to be initialized.
  121. *
  122. * RETURN: Status
  123. *
  124. * DESCRIPTION: Walk the namespace starting at "StartNode" and perform any
  125. * necessary initialization on the objects found therein
  126. *
  127. ******************************************************************************/
  128. acpi_status
  129. acpi_ds_initialize_objects(u32 table_index,
  130. struct acpi_namespace_node *start_node)
  131. {
  132. acpi_status status;
  133. struct acpi_init_walk_info info;
  134. struct acpi_table_header *table;
  135. acpi_owner_id owner_id;
  136. ACPI_FUNCTION_TRACE(ds_initialize_objects);
  137. status = acpi_tb_get_owner_id(table_index, &owner_id);
  138. if (ACPI_FAILURE(status)) {
  139. return_ACPI_STATUS(status);
  140. }
  141. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  142. "**** Starting initialization of namespace objects ****\n"));
  143. /* Set all init info to zero */
  144. memset(&info, 0, sizeof(struct acpi_init_walk_info));
  145. info.owner_id = owner_id;
  146. info.table_index = table_index;
  147. /* Walk entire namespace from the supplied root */
  148. /*
  149. * We don't use acpi_walk_namespace since we do not want to acquire
  150. * the namespace reader lock.
  151. */
  152. status =
  153. acpi_ns_walk_namespace(ACPI_TYPE_ANY, start_node, ACPI_UINT32_MAX,
  154. ACPI_NS_WALK_NO_UNLOCK,
  155. acpi_ds_init_one_object, NULL, &info, NULL);
  156. if (ACPI_FAILURE(status)) {
  157. ACPI_EXCEPTION((AE_INFO, status, "During WalkNamespace"));
  158. }
  159. status = acpi_get_table_by_index(table_index, &table);
  160. if (ACPI_FAILURE(status)) {
  161. return_ACPI_STATUS(status);
  162. }
  163. /* DSDT is always the first AML table */
  164. if (ACPI_COMPARE_NAME(table->signature, ACPI_SIG_DSDT)) {
  165. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
  166. "\nInitializing Namespace objects:\n"));
  167. }
  168. /* Summary of objects initialized */
  169. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
  170. "Table [%4.4s: %-8.8s] (id %.2X) - %4u Objects with %3u Devices, "
  171. "%3u Regions, %4u Methods (%u/%u/%u Serial/Non/Cvt)\n",
  172. table->signature, table->oem_table_id, owner_id,
  173. info.object_count, info.device_count,
  174. info.op_region_count, info.method_count,
  175. info.serial_method_count,
  176. info.non_serial_method_count,
  177. info.serialized_method_count));
  178. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "%u Methods, %u Regions\n",
  179. info.method_count, info.op_region_count));
  180. return_ACPI_STATUS(AE_OK);
  181. }