/drivers/acpi/acpica/utinit.c

http://github.com/mirrors/linux · C · 288 lines · 144 code · 68 blank · 76 comment · 8 complexity · 8d6ae8623545020e8f64a881b702b937 MD5 · raw file

  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 - 2020, 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_root_node = NULL;
  142. acpi_gbl_root_node_struct.name.integer = ACPI_ROOT_NAME;
  143. acpi_gbl_root_node_struct.descriptor_type = ACPI_DESC_TYPE_NAMED;
  144. acpi_gbl_root_node_struct.type = ACPI_TYPE_DEVICE;
  145. acpi_gbl_root_node_struct.parent = NULL;
  146. acpi_gbl_root_node_struct.child = NULL;
  147. acpi_gbl_root_node_struct.peer = NULL;
  148. acpi_gbl_root_node_struct.object = NULL;
  149. #ifdef ACPI_DISASSEMBLER
  150. acpi_gbl_external_list = NULL;
  151. acpi_gbl_num_external_methods = 0;
  152. acpi_gbl_resolved_external_methods = 0;
  153. #endif
  154. #ifdef ACPI_DEBUG_OUTPUT
  155. acpi_gbl_lowest_stack_pointer = ACPI_CAST_PTR(acpi_size, ACPI_SIZE_MAX);
  156. #endif
  157. #ifdef ACPI_DBG_TRACK_ALLOCATIONS
  158. acpi_gbl_display_final_mem_stats = FALSE;
  159. acpi_gbl_disable_mem_tracking = FALSE;
  160. #endif
  161. return_ACPI_STATUS(AE_OK);
  162. }
  163. /******************************************************************************
  164. *
  165. * FUNCTION: acpi_ut_terminate
  166. *
  167. * PARAMETERS: none
  168. *
  169. * RETURN: none
  170. *
  171. * DESCRIPTION: Free global memory
  172. *
  173. ******************************************************************************/
  174. static void acpi_ut_terminate(void)
  175. {
  176. ACPI_FUNCTION_TRACE(ut_terminate);
  177. acpi_ut_free_gpe_lists();
  178. acpi_ut_delete_address_lists();
  179. return_VOID;
  180. }
  181. /*******************************************************************************
  182. *
  183. * FUNCTION: acpi_ut_subsystem_shutdown
  184. *
  185. * PARAMETERS: None
  186. *
  187. * RETURN: None
  188. *
  189. * DESCRIPTION: Shutdown the various components. Do not delete the mutex
  190. * objects here, because the AML debugger may be still running.
  191. *
  192. ******************************************************************************/
  193. void acpi_ut_subsystem_shutdown(void)
  194. {
  195. ACPI_FUNCTION_TRACE(ut_subsystem_shutdown);
  196. /* Just exit if subsystem is already shutdown */
  197. if (acpi_gbl_shutdown) {
  198. ACPI_ERROR((AE_INFO, "ACPI Subsystem is already terminated"));
  199. return_VOID;
  200. }
  201. /* Subsystem appears active, go ahead and shut it down */
  202. acpi_gbl_shutdown = TRUE;
  203. acpi_gbl_startup_flags = 0;
  204. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Shutting down ACPI Subsystem\n"));
  205. #ifndef ACPI_ASL_COMPILER
  206. /* Close the acpi_event Handling */
  207. acpi_ev_terminate();
  208. /* Delete any dynamic _OSI interfaces */
  209. acpi_ut_interface_terminate();
  210. #endif
  211. /* Close the Namespace */
  212. acpi_ns_terminate();
  213. /* Delete the ACPI tables */
  214. acpi_tb_terminate();
  215. /* Close the globals */
  216. acpi_ut_terminate();
  217. /* Purge the local caches */
  218. (void)acpi_ut_delete_caches();
  219. return_VOID;
  220. }