utinit.c 8.7 KB

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