dsinit.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /******************************************************************************
  2. *
  3. * Module Name: dsinit - Object initialization namespace walk
  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 "acnamesp.h"
  46. #include "actables.h"
  47. #define _COMPONENT ACPI_DISPATCHER
  48. ACPI_MODULE_NAME("dsinit")
  49. /* Local prototypes */
  50. static acpi_status
  51. acpi_ds_init_one_object(acpi_handle obj_handle,
  52. u32 level, void *context, void **return_value);
  53. /*******************************************************************************
  54. *
  55. * FUNCTION: acpi_ds_init_one_object
  56. *
  57. * PARAMETERS: obj_handle - Node for the object
  58. * level - Current nesting level
  59. * context - Points to a init info struct
  60. * return_value - Not used
  61. *
  62. * RETURN: Status
  63. *
  64. * DESCRIPTION: Callback from acpi_walk_namespace. Invoked for every object
  65. * within the namespace.
  66. *
  67. * Currently, the only objects that require initialization are:
  68. * 1) Methods
  69. * 2) Operation Regions
  70. *
  71. ******************************************************************************/
  72. static acpi_status
  73. acpi_ds_init_one_object(acpi_handle obj_handle,
  74. u32 level, void *context, void **return_value)
  75. {
  76. struct acpi_init_walk_info *info =
  77. (struct acpi_init_walk_info *)context;
  78. struct acpi_namespace_node *node =
  79. (struct acpi_namespace_node *)obj_handle;
  80. acpi_status status;
  81. union acpi_operand_object *obj_desc;
  82. ACPI_FUNCTION_ENTRY();
  83. /*
  84. * We are only interested in NS nodes owned by the table that
  85. * was just loaded
  86. */
  87. if (node->owner_id != info->owner_id) {
  88. return (AE_OK);
  89. }
  90. info->object_count++;
  91. /* And even then, we are only interested in a few object types */
  92. switch (acpi_ns_get_type(obj_handle)) {
  93. case ACPI_TYPE_REGION:
  94. status = acpi_ds_initialize_region(obj_handle);
  95. if (ACPI_FAILURE(status)) {
  96. ACPI_EXCEPTION((AE_INFO, status,
  97. "During Region initialization %p [%4.4s]",
  98. obj_handle,
  99. acpi_ut_get_node_name(obj_handle)));
  100. }
  101. info->op_region_count++;
  102. break;
  103. case ACPI_TYPE_METHOD:
  104. /*
  105. * Auto-serialization support. We will examine each method that is
  106. * not_serialized to determine if it creates any Named objects. If
  107. * it does, it will be marked serialized to prevent problems if
  108. * the method is entered by two or more threads and an attempt is
  109. * made to create the same named object twice -- which results in
  110. * an AE_ALREADY_EXISTS exception and method abort.
  111. */
  112. info->method_count++;
  113. obj_desc = acpi_ns_get_attached_object(node);
  114. if (!obj_desc) {
  115. break;
  116. }
  117. /* Ignore if already serialized */
  118. if (obj_desc->method.info_flags & ACPI_METHOD_SERIALIZED) {
  119. info->serial_method_count++;
  120. break;
  121. }
  122. if (acpi_gbl_auto_serialize_methods) {
  123. /* Parse/scan method and serialize it if necessary */
  124. acpi_ds_auto_serialize_method(node, obj_desc);
  125. if (obj_desc->method.
  126. info_flags & ACPI_METHOD_SERIALIZED) {
  127. /* Method was just converted to Serialized */
  128. info->serial_method_count++;
  129. info->serialized_method_count++;
  130. break;
  131. }
  132. }
  133. info->non_serial_method_count++;
  134. break;
  135. case ACPI_TYPE_DEVICE:
  136. info->device_count++;
  137. break;
  138. default:
  139. break;
  140. }
  141. /*
  142. * We ignore errors from above, and always return OK, since
  143. * we don't want to abort the walk on a single error.
  144. */
  145. return (AE_OK);
  146. }
  147. /*******************************************************************************
  148. *
  149. * FUNCTION: acpi_ds_initialize_objects
  150. *
  151. * PARAMETERS: table_desc - Descriptor for parent ACPI table
  152. * start_node - Root of subtree to be initialized.
  153. *
  154. * RETURN: Status
  155. *
  156. * DESCRIPTION: Walk the namespace starting at "StartNode" and perform any
  157. * necessary initialization on the objects found therein
  158. *
  159. ******************************************************************************/
  160. acpi_status
  161. acpi_ds_initialize_objects(u32 table_index,
  162. struct acpi_namespace_node * start_node)
  163. {
  164. acpi_status status;
  165. struct acpi_init_walk_info info;
  166. struct acpi_table_header *table;
  167. acpi_owner_id owner_id;
  168. ACPI_FUNCTION_TRACE(ds_initialize_objects);
  169. status = acpi_tb_get_owner_id(table_index, &owner_id);
  170. if (ACPI_FAILURE(status)) {
  171. return_ACPI_STATUS(status);
  172. }
  173. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
  174. "**** Starting initialization of namespace objects ****\n"));
  175. /* Set all init info to zero */
  176. memset(&info, 0, sizeof(struct acpi_init_walk_info));
  177. info.owner_id = owner_id;
  178. info.table_index = table_index;
  179. /* Walk entire namespace from the supplied root */
  180. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  181. if (ACPI_FAILURE(status)) {
  182. return_ACPI_STATUS(status);
  183. }
  184. /*
  185. * We don't use acpi_walk_namespace since we do not want to acquire
  186. * the namespace reader lock.
  187. */
  188. status =
  189. acpi_ns_walk_namespace(ACPI_TYPE_ANY, start_node, ACPI_UINT32_MAX,
  190. ACPI_NS_WALK_UNLOCK, acpi_ds_init_one_object,
  191. NULL, &info, NULL);
  192. if (ACPI_FAILURE(status)) {
  193. ACPI_EXCEPTION((AE_INFO, status, "During WalkNamespace"));
  194. }
  195. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  196. status = acpi_get_table_by_index(table_index, &table);
  197. if (ACPI_FAILURE(status)) {
  198. return_ACPI_STATUS(status);
  199. }
  200. /* DSDT is always the first AML table */
  201. if (ACPI_COMPARE_NAME(table->signature, ACPI_SIG_DSDT)) {
  202. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
  203. "\nInitializing Namespace objects:\n"));
  204. }
  205. /* Summary of objects initialized */
  206. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
  207. "Table [%4.4s:%8.8s] (id %.2X) - %4u Objects with %3u Devices, "
  208. "%3u Regions, %4u Methods (%u/%u/%u Serial/Non/Cvt)\n",
  209. table->signature, table->oem_table_id, owner_id,
  210. info.object_count, info.device_count,
  211. info.op_region_count, info.method_count,
  212. info.serial_method_count,
  213. info.non_serial_method_count,
  214. info.serialized_method_count));
  215. ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "%u Methods, %u Regions\n",
  216. info.method_count, info.op_region_count));
  217. return_ACPI_STATUS(AE_OK);
  218. }