utinit.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2. /******************************************************************************
  3. *
  4. * Module Name: utinit - Common ACPI subsystem initialization
  5. *
  6. * Copyright (C) 2000 - 2018, Intel Corp.
  7. *
  8. *****************************************************************************/
  9. #include <acpi/acpi.h>
  10. #include "accommon.h"
  11. #include "acnamesp.h"
  12. #include "acevents.h"
  13. #include "actables.h"
  14. #define _COMPONENT ACPI_UTILITIES
  15. ACPI_MODULE_NAME("utinit")
  16. /* Local prototypes */
  17. static void acpi_ut_terminate(void);
  18. #if (!ACPI_REDUCED_HARDWARE)
  19. static void acpi_ut_free_gpe_lists(void);
  20. #else
  21. #define acpi_ut_free_gpe_lists()
  22. #endif /* !ACPI_REDUCED_HARDWARE */
  23. #if (!ACPI_REDUCED_HARDWARE)
  24. /******************************************************************************
  25. *
  26. * FUNCTION: acpi_ut_free_gpe_lists
  27. *
  28. * PARAMETERS: none
  29. *
  30. * RETURN: none
  31. *
  32. * DESCRIPTION: Free global GPE lists
  33. *
  34. ******************************************************************************/
  35. static void acpi_ut_free_gpe_lists(void)
  36. {
  37. struct acpi_gpe_block_info *gpe_block;
  38. struct acpi_gpe_block_info *next_gpe_block;
  39. struct acpi_gpe_xrupt_info *gpe_xrupt_info;
  40. struct acpi_gpe_xrupt_info *next_gpe_xrupt_info;
  41. /* Free global GPE blocks and related info structures */
  42. gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head;
  43. while (gpe_xrupt_info) {
  44. gpe_block = gpe_xrupt_info->gpe_block_list_head;
  45. while (gpe_block) {
  46. next_gpe_block = gpe_block->next;
  47. ACPI_FREE(gpe_block->event_info);
  48. ACPI_FREE(gpe_block->register_info);
  49. ACPI_FREE(gpe_block);
  50. gpe_block = next_gpe_block;
  51. }
  52. next_gpe_xrupt_info = gpe_xrupt_info->next;
  53. ACPI_FREE(gpe_xrupt_info);
  54. gpe_xrupt_info = next_gpe_xrupt_info;
  55. }
  56. }
  57. #endif /* !ACPI_REDUCED_HARDWARE */
  58. /*******************************************************************************
  59. *
  60. * FUNCTION: acpi_ut_init_globals
  61. *
  62. * PARAMETERS: None
  63. *
  64. * RETURN: Status
  65. *
  66. * DESCRIPTION: Initialize ACPICA globals. All globals that require specific
  67. * initialization should be initialized here. This allows for
  68. * a warm restart.
  69. *
  70. ******************************************************************************/
  71. acpi_status acpi_ut_init_globals(void)
  72. {
  73. acpi_status status;
  74. u32 i;
  75. ACPI_FUNCTION_TRACE(ut_init_globals);
  76. /* Create all memory caches */
  77. status = acpi_ut_create_caches();
  78. if (ACPI_FAILURE(status)) {
  79. return_ACPI_STATUS(status);
  80. }
  81. /* Address Range lists */
  82. for (i = 0; i < ACPI_ADDRESS_RANGE_MAX; i++) {
  83. acpi_gbl_address_range_list[i] = NULL;
  84. }
  85. /* Mutex locked flags */
  86. for (i = 0; i < ACPI_NUM_MUTEX; i++) {
  87. acpi_gbl_mutex_info[i].mutex = NULL;
  88. acpi_gbl_mutex_info[i].thread_id = ACPI_MUTEX_NOT_ACQUIRED;
  89. acpi_gbl_mutex_info[i].use_count = 0;
  90. }
  91. for (i = 0; i < ACPI_NUM_OWNERID_MASKS; i++) {
  92. acpi_gbl_owner_id_mask[i] = 0;
  93. }
  94. /* Last owner_ID is never valid */
  95. acpi_gbl_owner_id_mask[ACPI_NUM_OWNERID_MASKS - 1] = 0x80000000;
  96. /* Event counters */
  97. acpi_method_count = 0;
  98. acpi_sci_count = 0;
  99. acpi_gpe_count = 0;
  100. for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) {
  101. acpi_fixed_event_count[i] = 0;
  102. }
  103. #if (!ACPI_REDUCED_HARDWARE)
  104. /* GPE/SCI support */
  105. acpi_gbl_all_gpes_initialized = FALSE;
  106. acpi_gbl_gpe_xrupt_list_head = NULL;
  107. acpi_gbl_gpe_fadt_blocks[0] = NULL;
  108. acpi_gbl_gpe_fadt_blocks[1] = NULL;
  109. acpi_current_gpe_count = 0;
  110. acpi_gbl_global_event_handler = NULL;
  111. acpi_gbl_sci_handler_list = NULL;
  112. #endif /* !ACPI_REDUCED_HARDWARE */
  113. /* Global handlers */
  114. acpi_gbl_global_notify[0].handler = NULL;
  115. acpi_gbl_global_notify[1].handler = NULL;
  116. acpi_gbl_exception_handler = NULL;
  117. acpi_gbl_init_handler = NULL;
  118. acpi_gbl_table_handler = NULL;
  119. acpi_gbl_interface_handler = NULL;
  120. /* Global Lock support */
  121. acpi_gbl_global_lock_semaphore = NULL;
  122. acpi_gbl_global_lock_mutex = NULL;
  123. acpi_gbl_global_lock_acquired = FALSE;
  124. acpi_gbl_global_lock_handle = 0;
  125. acpi_gbl_global_lock_present = FALSE;
  126. /* Miscellaneous variables */
  127. acpi_gbl_DSDT = NULL;
  128. acpi_gbl_cm_single_step = FALSE;
  129. acpi_gbl_shutdown = FALSE;
  130. acpi_gbl_ns_lookup_count = 0;
  131. acpi_gbl_ps_find_count = 0;
  132. acpi_gbl_acpi_hardware_present = TRUE;
  133. acpi_gbl_last_owner_id_index = 0;
  134. acpi_gbl_next_owner_id_offset = 0;
  135. acpi_gbl_debugger_configuration = DEBUGGER_THREADING;
  136. acpi_gbl_osi_mutex = NULL;
  137. /* Hardware oriented */
  138. acpi_gbl_events_initialized = FALSE;
  139. acpi_gbl_system_awake_and_running = TRUE;
  140. /* Namespace */
  141. acpi_gbl_module_code_list = NULL;
  142. acpi_gbl_root_node = NULL;
  143. acpi_gbl_root_node_struct.name.integer = ACPI_ROOT_NAME;
  144. acpi_gbl_root_node_struct.descriptor_type = ACPI_DESC_TYPE_NAMED;
  145. acpi_gbl_root_node_struct.type = ACPI_TYPE_DEVICE;
  146. acpi_gbl_root_node_struct.parent = NULL;
  147. acpi_gbl_root_node_struct.child = NULL;
  148. acpi_gbl_root_node_struct.peer = NULL;
  149. acpi_gbl_root_node_struct.object = NULL;
  150. #ifdef ACPI_DISASSEMBLER
  151. acpi_gbl_external_list = NULL;
  152. acpi_gbl_num_external_methods = 0;
  153. acpi_gbl_resolved_external_methods = 0;
  154. #endif
  155. #ifdef ACPI_DEBUG_OUTPUT
  156. acpi_gbl_lowest_stack_pointer = ACPI_CAST_PTR(acpi_size, ACPI_SIZE_MAX);
  157. #endif
  158. #ifdef ACPI_DBG_TRACK_ALLOCATIONS
  159. acpi_gbl_display_final_mem_stats = FALSE;
  160. acpi_gbl_disable_mem_tracking = FALSE;
  161. #endif
  162. return_ACPI_STATUS(AE_OK);
  163. }
  164. /******************************************************************************
  165. *
  166. * FUNCTION: acpi_ut_terminate
  167. *
  168. * PARAMETERS: none
  169. *
  170. * RETURN: none
  171. *
  172. * DESCRIPTION: Free global memory
  173. *
  174. ******************************************************************************/
  175. static void acpi_ut_terminate(void)
  176. {
  177. ACPI_FUNCTION_TRACE(ut_terminate);
  178. acpi_ut_free_gpe_lists();
  179. acpi_ut_delete_address_lists();
  180. return_VOID;
  181. }
  182. /*******************************************************************************
  183. *
  184. * FUNCTION: acpi_ut_subsystem_shutdown
  185. *
  186. * PARAMETERS: None
  187. *
  188. * RETURN: None
  189. *
  190. * DESCRIPTION: Shutdown the various components. Do not delete the mutex
  191. * objects here, because the AML debugger may be still running.
  192. *
  193. ******************************************************************************/
  194. void acpi_ut_subsystem_shutdown(void)
  195. {
  196. ACPI_FUNCTION_TRACE(ut_subsystem_shutdown);
  197. /* Just exit if subsystem is already shutdown */
  198. if (acpi_gbl_shutdown) {
  199. ACPI_ERROR((AE_INFO, "ACPI Subsystem is already terminated"));
  200. return_VOID;
  201. }
  202. /* Subsystem appears active, go ahead and shut it down */
  203. acpi_gbl_shutdown = TRUE;
  204. acpi_gbl_startup_flags = 0;
  205. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Shutting down ACPI Subsystem\n"));
  206. #ifndef ACPI_ASL_COMPILER
  207. /* Close the acpi_event Handling */
  208. acpi_ev_terminate();
  209. /* Delete any dynamic _OSI interfaces */
  210. acpi_ut_interface_terminate();
  211. #endif
  212. /* Close the Namespace */
  213. acpi_ns_terminate();
  214. /* Delete the ACPI tables */
  215. acpi_tb_terminate();
  216. /* Close the globals */
  217. acpi_ut_terminate();
  218. /* Purge the local caches */
  219. (void)acpi_ut_delete_caches();
  220. return_VOID;
  221. }