Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /****************************************************************************** |
| 3 | * |
| 4 | * Module Name: utinit - Common ACPI subsystem initialization |
| 5 | * |
Bob Moore | 800ba7c | 2020-01-10 11:31:49 -0800 | [diff] [blame] | 6 | * Copyright (C) 2000 - 2020, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 8 | *****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 11 | #include "accommon.h" |
| 12 | #include "acnamesp.h" |
| 13 | #include "acevents.h" |
| 14 | #include "actables.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
| 16 | #define _COMPONENT ACPI_UTILITIES |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 17 | ACPI_MODULE_NAME("utinit") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 19 | /* Local prototypes */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 20 | static void acpi_ut_terminate(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 22 | #if (!ACPI_REDUCED_HARDWARE) |
| 23 | |
| 24 | static void acpi_ut_free_gpe_lists(void); |
| 25 | |
| 26 | #else |
| 27 | |
| 28 | #define acpi_ut_free_gpe_lists() |
| 29 | #endif /* !ACPI_REDUCED_HARDWARE */ |
| 30 | |
| 31 | #if (!ACPI_REDUCED_HARDWARE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | /****************************************************************************** |
| 33 | * |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 34 | * FUNCTION: acpi_ut_free_gpe_lists |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | * |
| 36 | * PARAMETERS: none |
| 37 | * |
| 38 | * RETURN: none |
| 39 | * |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 40 | * DESCRIPTION: Free global GPE lists |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | * |
| 42 | ******************************************************************************/ |
| 43 | |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 44 | static void acpi_ut_free_gpe_lists(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 46 | struct acpi_gpe_block_info *gpe_block; |
| 47 | struct acpi_gpe_block_info *next_gpe_block; |
| 48 | struct acpi_gpe_xrupt_info *gpe_xrupt_info; |
| 49 | struct acpi_gpe_xrupt_info *next_gpe_xrupt_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | /* Free global GPE blocks and related info structures */ |
| 52 | |
| 53 | gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head; |
| 54 | while (gpe_xrupt_info) { |
| 55 | gpe_block = gpe_xrupt_info->gpe_block_list_head; |
| 56 | while (gpe_block) { |
| 57 | next_gpe_block = gpe_block->next; |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 58 | ACPI_FREE(gpe_block->event_info); |
| 59 | ACPI_FREE(gpe_block->register_info); |
| 60 | ACPI_FREE(gpe_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | gpe_block = next_gpe_block; |
| 63 | } |
| 64 | next_gpe_xrupt_info = gpe_xrupt_info->next; |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 65 | ACPI_FREE(gpe_xrupt_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | gpe_xrupt_info = next_gpe_xrupt_info; |
| 67 | } |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 68 | } |
| 69 | #endif /* !ACPI_REDUCED_HARDWARE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
Lv Zheng | e8c038a | 2014-07-08 10:06:39 +0800 | [diff] [blame] | 71 | /******************************************************************************* |
| 72 | * |
| 73 | * FUNCTION: acpi_ut_init_globals |
| 74 | * |
| 75 | * PARAMETERS: None |
| 76 | * |
| 77 | * RETURN: Status |
| 78 | * |
| 79 | * DESCRIPTION: Initialize ACPICA globals. All globals that require specific |
| 80 | * initialization should be initialized here. This allows for |
| 81 | * a warm restart. |
| 82 | * |
| 83 | ******************************************************************************/ |
| 84 | |
| 85 | acpi_status acpi_ut_init_globals(void) |
| 86 | { |
| 87 | acpi_status status; |
| 88 | u32 i; |
| 89 | |
| 90 | ACPI_FUNCTION_TRACE(ut_init_globals); |
| 91 | |
| 92 | /* Create all memory caches */ |
| 93 | |
| 94 | status = acpi_ut_create_caches(); |
| 95 | if (ACPI_FAILURE(status)) { |
| 96 | return_ACPI_STATUS(status); |
| 97 | } |
| 98 | |
| 99 | /* Address Range lists */ |
| 100 | |
| 101 | for (i = 0; i < ACPI_ADDRESS_RANGE_MAX; i++) { |
| 102 | acpi_gbl_address_range_list[i] = NULL; |
| 103 | } |
| 104 | |
| 105 | /* Mutex locked flags */ |
| 106 | |
| 107 | for (i = 0; i < ACPI_NUM_MUTEX; i++) { |
| 108 | acpi_gbl_mutex_info[i].mutex = NULL; |
| 109 | acpi_gbl_mutex_info[i].thread_id = ACPI_MUTEX_NOT_ACQUIRED; |
| 110 | acpi_gbl_mutex_info[i].use_count = 0; |
| 111 | } |
| 112 | |
| 113 | for (i = 0; i < ACPI_NUM_OWNERID_MASKS; i++) { |
| 114 | acpi_gbl_owner_id_mask[i] = 0; |
| 115 | } |
| 116 | |
| 117 | /* Last owner_ID is never valid */ |
| 118 | |
| 119 | acpi_gbl_owner_id_mask[ACPI_NUM_OWNERID_MASKS - 1] = 0x80000000; |
| 120 | |
| 121 | /* Event counters */ |
| 122 | |
| 123 | acpi_method_count = 0; |
| 124 | acpi_sci_count = 0; |
| 125 | acpi_gpe_count = 0; |
| 126 | |
| 127 | for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) { |
| 128 | acpi_fixed_event_count[i] = 0; |
| 129 | } |
| 130 | |
| 131 | #if (!ACPI_REDUCED_HARDWARE) |
| 132 | |
| 133 | /* GPE/SCI support */ |
| 134 | |
| 135 | acpi_gbl_all_gpes_initialized = FALSE; |
| 136 | acpi_gbl_gpe_xrupt_list_head = NULL; |
| 137 | acpi_gbl_gpe_fadt_blocks[0] = NULL; |
| 138 | acpi_gbl_gpe_fadt_blocks[1] = NULL; |
| 139 | acpi_current_gpe_count = 0; |
| 140 | |
| 141 | acpi_gbl_global_event_handler = NULL; |
| 142 | acpi_gbl_sci_handler_list = NULL; |
| 143 | |
| 144 | #endif /* !ACPI_REDUCED_HARDWARE */ |
| 145 | |
| 146 | /* Global handlers */ |
| 147 | |
| 148 | acpi_gbl_global_notify[0].handler = NULL; |
| 149 | acpi_gbl_global_notify[1].handler = NULL; |
| 150 | acpi_gbl_exception_handler = NULL; |
| 151 | acpi_gbl_init_handler = NULL; |
| 152 | acpi_gbl_table_handler = NULL; |
| 153 | acpi_gbl_interface_handler = NULL; |
| 154 | |
| 155 | /* Global Lock support */ |
| 156 | |
| 157 | acpi_gbl_global_lock_semaphore = NULL; |
| 158 | acpi_gbl_global_lock_mutex = NULL; |
| 159 | acpi_gbl_global_lock_acquired = FALSE; |
| 160 | acpi_gbl_global_lock_handle = 0; |
| 161 | acpi_gbl_global_lock_present = FALSE; |
| 162 | |
| 163 | /* Miscellaneous variables */ |
| 164 | |
| 165 | acpi_gbl_DSDT = NULL; |
| 166 | acpi_gbl_cm_single_step = FALSE; |
| 167 | acpi_gbl_shutdown = FALSE; |
| 168 | acpi_gbl_ns_lookup_count = 0; |
| 169 | acpi_gbl_ps_find_count = 0; |
| 170 | acpi_gbl_acpi_hardware_present = TRUE; |
| 171 | acpi_gbl_last_owner_id_index = 0; |
| 172 | acpi_gbl_next_owner_id_offset = 0; |
Lv Zheng | e8c038a | 2014-07-08 10:06:39 +0800 | [diff] [blame] | 173 | acpi_gbl_debugger_configuration = DEBUGGER_THREADING; |
Lv Zheng | e8c038a | 2014-07-08 10:06:39 +0800 | [diff] [blame] | 174 | acpi_gbl_osi_mutex = NULL; |
Lv Zheng | e8c038a | 2014-07-08 10:06:39 +0800 | [diff] [blame] | 175 | |
| 176 | /* Hardware oriented */ |
| 177 | |
| 178 | acpi_gbl_events_initialized = FALSE; |
| 179 | acpi_gbl_system_awake_and_running = TRUE; |
| 180 | |
| 181 | /* Namespace */ |
| 182 | |
Lv Zheng | e8c038a | 2014-07-08 10:06:39 +0800 | [diff] [blame] | 183 | acpi_gbl_root_node = NULL; |
| 184 | acpi_gbl_root_node_struct.name.integer = ACPI_ROOT_NAME; |
| 185 | acpi_gbl_root_node_struct.descriptor_type = ACPI_DESC_TYPE_NAMED; |
| 186 | acpi_gbl_root_node_struct.type = ACPI_TYPE_DEVICE; |
| 187 | acpi_gbl_root_node_struct.parent = NULL; |
| 188 | acpi_gbl_root_node_struct.child = NULL; |
| 189 | acpi_gbl_root_node_struct.peer = NULL; |
| 190 | acpi_gbl_root_node_struct.object = NULL; |
| 191 | |
| 192 | #ifdef ACPI_DISASSEMBLER |
| 193 | acpi_gbl_external_list = NULL; |
| 194 | acpi_gbl_num_external_methods = 0; |
| 195 | acpi_gbl_resolved_external_methods = 0; |
| 196 | #endif |
| 197 | |
| 198 | #ifdef ACPI_DEBUG_OUTPUT |
| 199 | acpi_gbl_lowest_stack_pointer = ACPI_CAST_PTR(acpi_size, ACPI_SIZE_MAX); |
| 200 | #endif |
| 201 | |
| 202 | #ifdef ACPI_DBG_TRACK_ALLOCATIONS |
| 203 | acpi_gbl_display_final_mem_stats = FALSE; |
| 204 | acpi_gbl_disable_mem_tracking = FALSE; |
| 205 | #endif |
| 206 | |
Lv Zheng | e8c038a | 2014-07-08 10:06:39 +0800 | [diff] [blame] | 207 | return_ACPI_STATUS(AE_OK); |
| 208 | } |
| 209 | |
Bob Moore | 33620c5 | 2012-02-14 18:14:27 +0800 | [diff] [blame] | 210 | /****************************************************************************** |
| 211 | * |
| 212 | * FUNCTION: acpi_ut_terminate |
| 213 | * |
| 214 | * PARAMETERS: none |
| 215 | * |
| 216 | * RETURN: none |
| 217 | * |
| 218 | * DESCRIPTION: Free global memory |
| 219 | * |
| 220 | ******************************************************************************/ |
| 221 | |
| 222 | static void acpi_ut_terminate(void) |
| 223 | { |
| 224 | ACPI_FUNCTION_TRACE(ut_terminate); |
| 225 | |
| 226 | acpi_ut_free_gpe_lists(); |
Lin Ming | f654c0f | 2012-01-12 13:10:32 +0800 | [diff] [blame] | 227 | acpi_ut_delete_address_lists(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | return_VOID; |
| 229 | } |
| 230 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | /******************************************************************************* |
| 232 | * |
| 233 | * FUNCTION: acpi_ut_subsystem_shutdown |
| 234 | * |
Bob Moore | 2f977b3 | 2009-07-24 11:25:16 +0800 | [diff] [blame] | 235 | * PARAMETERS: None |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | * |
Bob Moore | 2f977b3 | 2009-07-24 11:25:16 +0800 | [diff] [blame] | 237 | * RETURN: None |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | * |
Bob Moore | 2f977b3 | 2009-07-24 11:25:16 +0800 | [diff] [blame] | 239 | * DESCRIPTION: Shutdown the various components. Do not delete the mutex |
| 240 | * objects here, because the AML debugger may be still running. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | * |
| 242 | ******************************************************************************/ |
| 243 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 244 | void acpi_ut_subsystem_shutdown(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | { |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 246 | ACPI_FUNCTION_TRACE(ut_subsystem_shutdown); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
Lv Zheng | 086ab74 | 2015-10-19 10:25:42 +0800 | [diff] [blame] | 248 | /* Just exit if subsystem is already shutdown */ |
| 249 | |
| 250 | if (acpi_gbl_shutdown) { |
| 251 | ACPI_ERROR((AE_INFO, "ACPI Subsystem is already terminated")); |
| 252 | return_VOID; |
| 253 | } |
| 254 | |
| 255 | /* Subsystem appears active, go ahead and shut it down */ |
| 256 | |
| 257 | acpi_gbl_shutdown = TRUE; |
| 258 | acpi_gbl_startup_flags = 0; |
| 259 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Shutting down ACPI Subsystem\n")); |
| 260 | |
Bob Moore | e20a679 | 2008-04-10 19:06:38 +0400 | [diff] [blame] | 261 | #ifndef ACPI_ASL_COMPILER |
| 262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | /* Close the acpi_event Handling */ |
| 264 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 265 | acpi_ev_terminate(); |
Lin Ming | b0ed7a9 | 2010-08-06 09:35:51 +0800 | [diff] [blame] | 266 | |
| 267 | /* Delete any dynamic _OSI interfaces */ |
| 268 | |
| 269 | acpi_ut_interface_terminate(); |
Bob Moore | e20a679 | 2008-04-10 19:06:38 +0400 | [diff] [blame] | 270 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
| 272 | /* Close the Namespace */ |
| 273 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 274 | acpi_ns_terminate(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 276 | /* Delete the ACPI tables */ |
| 277 | |
| 278 | acpi_tb_terminate(); |
| 279 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | /* Close the globals */ |
| 281 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 282 | acpi_ut_terminate(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
| 284 | /* Purge the local caches */ |
| 285 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 286 | (void)acpi_ut_delete_caches(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | return_VOID; |
| 288 | } |