1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: utinit - Common ACPI subsystem initialization
6 * Copyright (C) 2000 - 2018, Intel Corp.
8 *****************************************************************************/
10 #include <acpi/acpi.h>
16 #define _COMPONENT ACPI_UTILITIES
17 ACPI_MODULE_NAME("utinit")
19 /* Local prototypes */
20 static void acpi_ut_terminate(void);
22 #if (!ACPI_REDUCED_HARDWARE)
24 static void acpi_ut_free_gpe_lists(void);
28 #define acpi_ut_free_gpe_lists()
29 #endif /* !ACPI_REDUCED_HARDWARE */
31 #if (!ACPI_REDUCED_HARDWARE)
32 /******************************************************************************
34 * FUNCTION: acpi_ut_free_gpe_lists
40 * DESCRIPTION: Free global GPE lists
42 ******************************************************************************/
44 static void acpi_ut_free_gpe_lists(void)
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
;
51 /* Free global GPE blocks and related info structures */
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
;
57 next_gpe_block
= gpe_block
->next
;
58 ACPI_FREE(gpe_block
->event_info
);
59 ACPI_FREE(gpe_block
->register_info
);
62 gpe_block
= next_gpe_block
;
64 next_gpe_xrupt_info
= gpe_xrupt_info
->next
;
65 ACPI_FREE(gpe_xrupt_info
);
66 gpe_xrupt_info
= next_gpe_xrupt_info
;
69 #endif /* !ACPI_REDUCED_HARDWARE */
71 /*******************************************************************************
73 * FUNCTION: acpi_ut_init_globals
79 * DESCRIPTION: Initialize ACPICA globals. All globals that require specific
80 * initialization should be initialized here. This allows for
83 ******************************************************************************/
85 acpi_status
acpi_ut_init_globals(void)
90 ACPI_FUNCTION_TRACE(ut_init_globals
);
92 /* Create all memory caches */
94 status
= acpi_ut_create_caches();
95 if (ACPI_FAILURE(status
)) {
96 return_ACPI_STATUS(status
);
99 /* Address Range lists */
101 for (i
= 0; i
< ACPI_ADDRESS_RANGE_MAX
; i
++) {
102 acpi_gbl_address_range_list
[i
] = NULL
;
105 /* Mutex locked flags */
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;
113 for (i
= 0; i
< ACPI_NUM_OWNERID_MASKS
; i
++) {
114 acpi_gbl_owner_id_mask
[i
] = 0;
117 /* Last owner_ID is never valid */
119 acpi_gbl_owner_id_mask
[ACPI_NUM_OWNERID_MASKS
- 1] = 0x80000000;
123 acpi_method_count
= 0;
127 for (i
= 0; i
< ACPI_NUM_FIXED_EVENTS
; i
++) {
128 acpi_fixed_event_count
[i
] = 0;
131 #if (!ACPI_REDUCED_HARDWARE)
133 /* GPE/SCI support */
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;
141 acpi_gbl_global_event_handler
= NULL
;
142 acpi_gbl_sci_handler_list
= NULL
;
144 #endif /* !ACPI_REDUCED_HARDWARE */
146 /* Global handlers */
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
;
155 /* Global Lock support */
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
;
163 /* Miscellaneous variables */
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;
173 acpi_gbl_debugger_configuration
= DEBUGGER_THREADING
;
174 acpi_gbl_osi_mutex
= NULL
;
176 /* Hardware oriented */
178 acpi_gbl_events_initialized
= FALSE
;
179 acpi_gbl_system_awake_and_running
= TRUE
;
183 acpi_gbl_module_code_list
= NULL
;
184 acpi_gbl_root_node
= NULL
;
185 acpi_gbl_root_node_struct
.name
.integer
= ACPI_ROOT_NAME
;
186 acpi_gbl_root_node_struct
.descriptor_type
= ACPI_DESC_TYPE_NAMED
;
187 acpi_gbl_root_node_struct
.type
= ACPI_TYPE_DEVICE
;
188 acpi_gbl_root_node_struct
.parent
= NULL
;
189 acpi_gbl_root_node_struct
.child
= NULL
;
190 acpi_gbl_root_node_struct
.peer
= NULL
;
191 acpi_gbl_root_node_struct
.object
= NULL
;
193 #ifdef ACPI_DISASSEMBLER
194 acpi_gbl_external_list
= NULL
;
195 acpi_gbl_num_external_methods
= 0;
196 acpi_gbl_resolved_external_methods
= 0;
199 #ifdef ACPI_DEBUG_OUTPUT
200 acpi_gbl_lowest_stack_pointer
= ACPI_CAST_PTR(acpi_size
, ACPI_SIZE_MAX
);
203 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
204 acpi_gbl_display_final_mem_stats
= FALSE
;
205 acpi_gbl_disable_mem_tracking
= FALSE
;
208 return_ACPI_STATUS(AE_OK
);
211 /******************************************************************************
213 * FUNCTION: acpi_ut_terminate
219 * DESCRIPTION: Free global memory
221 ******************************************************************************/
223 static void acpi_ut_terminate(void)
225 ACPI_FUNCTION_TRACE(ut_terminate
);
227 acpi_ut_free_gpe_lists();
228 acpi_ut_delete_address_lists();
232 /*******************************************************************************
234 * FUNCTION: acpi_ut_subsystem_shutdown
240 * DESCRIPTION: Shutdown the various components. Do not delete the mutex
241 * objects here, because the AML debugger may be still running.
243 ******************************************************************************/
245 void acpi_ut_subsystem_shutdown(void)
247 ACPI_FUNCTION_TRACE(ut_subsystem_shutdown
);
249 /* Just exit if subsystem is already shutdown */
251 if (acpi_gbl_shutdown
) {
252 ACPI_ERROR((AE_INFO
, "ACPI Subsystem is already terminated"));
256 /* Subsystem appears active, go ahead and shut it down */
258 acpi_gbl_shutdown
= TRUE
;
259 acpi_gbl_startup_flags
= 0;
260 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Shutting down ACPI Subsystem\n"));
262 #ifndef ACPI_ASL_COMPILER
264 /* Close the acpi_event Handling */
268 /* Delete any dynamic _OSI interfaces */
270 acpi_ut_interface_terminate();
273 /* Close the Namespace */
277 /* Delete the ACPI tables */
281 /* Close the globals */
285 /* Purge the local caches */
287 (void)acpi_ut_delete_caches();