Bob Moore | d978348 | 2012-08-17 10:51:47 +0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: utxfinit - External interfaces for ACPICA initialization |
| 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
Bob Moore | c8100dc | 2016-01-15 08:17:03 +0800 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2016, Intel Corp. |
Bob Moore | d978348 | 2012-08-17 10:51:47 +0800 | [diff] [blame] | 9 | * All rights reserved. |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or without |
| 12 | * modification, are permitted provided that the following conditions |
| 13 | * are met: |
| 14 | * 1. Redistributions of source code must retain the above copyright |
| 15 | * notice, this list of conditions, and the following disclaimer, |
| 16 | * without modification. |
| 17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 18 | * substantially similar to the "NO WARRANTY" disclaimer below |
| 19 | * ("Disclaimer") and any redistribution must be conditioned upon |
| 20 | * including a substantially similar Disclaimer requirement for further |
| 21 | * binary redistribution. |
| 22 | * 3. Neither the names of the above-listed copyright holders nor the names |
| 23 | * of any contributors may be used to endorse or promote products derived |
| 24 | * from this software without specific prior written permission. |
| 25 | * |
| 26 | * Alternatively, this software may be distributed under the terms of the |
| 27 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 28 | * Software Foundation. |
| 29 | * |
| 30 | * NO WARRANTY |
| 31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR |
| 34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 41 | * POSSIBILITY OF SUCH DAMAGES. |
| 42 | */ |
| 43 | |
Lv Zheng | 839e928 | 2013-10-29 09:29:51 +0800 | [diff] [blame] | 44 | #define EXPORT_ACPI_INTERFACES |
| 45 | |
Bob Moore | d978348 | 2012-08-17 10:51:47 +0800 | [diff] [blame] | 46 | #include <acpi/acpi.h> |
| 47 | #include "accommon.h" |
| 48 | #include "acevents.h" |
| 49 | #include "acnamesp.h" |
| 50 | #include "acdebug.h" |
| 51 | #include "actables.h" |
| 52 | |
| 53 | #define _COMPONENT ACPI_UTILITIES |
| 54 | ACPI_MODULE_NAME("utxfinit") |
| 55 | |
Bob Moore | b487867 | 2014-11-27 14:26:07 +0800 | [diff] [blame] | 56 | /* For acpi_exec only */ |
| 57 | void ae_do_object_overrides(void); |
| 58 | |
Bob Moore | d978348 | 2012-08-17 10:51:47 +0800 | [diff] [blame] | 59 | /******************************************************************************* |
| 60 | * |
| 61 | * FUNCTION: acpi_initialize_subsystem |
| 62 | * |
| 63 | * PARAMETERS: None |
| 64 | * |
| 65 | * RETURN: Status |
| 66 | * |
| 67 | * DESCRIPTION: Initializes all global variables. This is the first function |
| 68 | * called, so any early initialization belongs here. |
| 69 | * |
| 70 | ******************************************************************************/ |
Bob Moore | b487867 | 2014-11-27 14:26:07 +0800 | [diff] [blame] | 71 | |
Lv Zheng | 2368b1a | 2016-08-04 16:43:19 +0800 | [diff] [blame] | 72 | acpi_status ACPI_INIT_FUNCTION acpi_initialize_subsystem(void) |
Bob Moore | d978348 | 2012-08-17 10:51:47 +0800 | [diff] [blame] | 73 | { |
| 74 | acpi_status status; |
| 75 | |
| 76 | ACPI_FUNCTION_TRACE(acpi_initialize_subsystem); |
| 77 | |
| 78 | acpi_gbl_startup_flags = ACPI_SUBSYSTEM_INITIALIZE; |
| 79 | ACPI_DEBUG_EXEC(acpi_ut_init_stack_ptr_trace()); |
| 80 | |
| 81 | /* Initialize the OS-Dependent layer */ |
| 82 | |
| 83 | status = acpi_os_initialize(); |
| 84 | if (ACPI_FAILURE(status)) { |
| 85 | ACPI_EXCEPTION((AE_INFO, status, "During OSL initialization")); |
| 86 | return_ACPI_STATUS(status); |
| 87 | } |
| 88 | |
| 89 | /* Initialize all globals used by the subsystem */ |
| 90 | |
| 91 | status = acpi_ut_init_globals(); |
| 92 | if (ACPI_FAILURE(status)) { |
| 93 | ACPI_EXCEPTION((AE_INFO, status, |
| 94 | "During initialization of globals")); |
| 95 | return_ACPI_STATUS(status); |
| 96 | } |
| 97 | |
| 98 | /* Create the default mutex objects */ |
| 99 | |
| 100 | status = acpi_ut_mutex_initialize(); |
| 101 | if (ACPI_FAILURE(status)) { |
| 102 | ACPI_EXCEPTION((AE_INFO, status, |
| 103 | "During Global Mutex creation")); |
| 104 | return_ACPI_STATUS(status); |
| 105 | } |
| 106 | |
| 107 | /* |
| 108 | * Initialize the namespace manager and |
| 109 | * the root of the namespace tree |
| 110 | */ |
| 111 | status = acpi_ns_root_initialize(); |
| 112 | if (ACPI_FAILURE(status)) { |
| 113 | ACPI_EXCEPTION((AE_INFO, status, |
| 114 | "During Namespace initialization")); |
| 115 | return_ACPI_STATUS(status); |
| 116 | } |
| 117 | |
| 118 | /* Initialize the global OSI interfaces list with the static names */ |
| 119 | |
| 120 | status = acpi_ut_initialize_interfaces(); |
| 121 | if (ACPI_FAILURE(status)) { |
| 122 | ACPI_EXCEPTION((AE_INFO, status, |
| 123 | "During OSI interfaces initialization")); |
| 124 | return_ACPI_STATUS(status); |
| 125 | } |
| 126 | |
Bob Moore | 1a2c478 | 2014-01-08 13:44:38 +0800 | [diff] [blame] | 127 | return_ACPI_STATUS(AE_OK); |
Bob Moore | d978348 | 2012-08-17 10:51:47 +0800 | [diff] [blame] | 128 | } |
Lv Zheng | d21f600 | 2013-10-29 09:30:10 +0800 | [diff] [blame] | 129 | |
| 130 | ACPI_EXPORT_SYMBOL_INIT(acpi_initialize_subsystem) |
Bob Moore | d978348 | 2012-08-17 10:51:47 +0800 | [diff] [blame] | 131 | |
| 132 | /******************************************************************************* |
| 133 | * |
| 134 | * FUNCTION: acpi_enable_subsystem |
| 135 | * |
| 136 | * PARAMETERS: flags - Init/enable Options |
| 137 | * |
| 138 | * RETURN: Status |
| 139 | * |
| 140 | * DESCRIPTION: Completes the subsystem initialization including hardware. |
| 141 | * Puts system into ACPI mode if it isn't already. |
| 142 | * |
| 143 | ******************************************************************************/ |
Lv Zheng | 2368b1a | 2016-08-04 16:43:19 +0800 | [diff] [blame] | 144 | acpi_status ACPI_INIT_FUNCTION acpi_enable_subsystem(u32 flags) |
Bob Moore | d978348 | 2012-08-17 10:51:47 +0800 | [diff] [blame] | 145 | { |
| 146 | acpi_status status = AE_OK; |
| 147 | |
| 148 | ACPI_FUNCTION_TRACE(acpi_enable_subsystem); |
| 149 | |
Bob Moore | 7b73806 | 2015-12-29 14:01:53 +0800 | [diff] [blame] | 150 | /* |
| 151 | * The early initialization phase is complete. The namespace is loaded, |
| 152 | * and we can now support address spaces other than Memory, I/O, and |
| 153 | * PCI_Config. |
| 154 | */ |
| 155 | acpi_gbl_early_initialization = FALSE; |
| 156 | |
Bob Moore | d978348 | 2012-08-17 10:51:47 +0800 | [diff] [blame] | 157 | #if (!ACPI_REDUCED_HARDWARE) |
| 158 | |
| 159 | /* Enable ACPI mode */ |
| 160 | |
| 161 | if (!(flags & ACPI_NO_ACPI_ENABLE)) { |
| 162 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
| 163 | "[Init] Going into ACPI mode\n")); |
| 164 | |
| 165 | acpi_gbl_original_mode = acpi_hw_get_mode(); |
| 166 | |
| 167 | status = acpi_enable(); |
| 168 | if (ACPI_FAILURE(status)) { |
| 169 | ACPI_WARNING((AE_INFO, "AcpiEnable failed")); |
| 170 | return_ACPI_STATUS(status); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | /* |
| 175 | * Obtain a permanent mapping for the FACS. This is required for the |
| 176 | * Global Lock and the Firmware Waking Vector |
| 177 | */ |
Lv Zheng | c04be18 | 2015-07-01 14:43:26 +0800 | [diff] [blame] | 178 | if (!(flags & ACPI_NO_FACS_INIT)) { |
| 179 | status = acpi_tb_initialize_facs(); |
| 180 | if (ACPI_FAILURE(status)) { |
| 181 | ACPI_WARNING((AE_INFO, "Could not map the FACS table")); |
| 182 | return_ACPI_STATUS(status); |
| 183 | } |
Bob Moore | d978348 | 2012-08-17 10:51:47 +0800 | [diff] [blame] | 184 | } |
Bob Moore | d978348 | 2012-08-17 10:51:47 +0800 | [diff] [blame] | 185 | |
| 186 | /* |
Bob Moore | d978348 | 2012-08-17 10:51:47 +0800 | [diff] [blame] | 187 | * Initialize ACPI Event handling (Fixed and General Purpose) |
| 188 | * |
| 189 | * Note1: We must have the hardware and events initialized before we can |
| 190 | * execute any control methods safely. Any control method can require |
| 191 | * ACPI hardware support, so the hardware must be fully initialized before |
| 192 | * any method execution! |
| 193 | * |
| 194 | * Note2: Fixed events are initialized and enabled here. GPEs are |
| 195 | * initialized, but cannot be enabled until after the hardware is |
| 196 | * completely initialized (SCI and global_lock activated) and the various |
| 197 | * initialization control methods are run (_REG, _STA, _INI) on the |
| 198 | * entire namespace. |
| 199 | */ |
| 200 | if (!(flags & ACPI_NO_EVENT_INIT)) { |
| 201 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
| 202 | "[Init] Initializing ACPI events\n")); |
| 203 | |
| 204 | status = acpi_ev_initialize_events(); |
| 205 | if (ACPI_FAILURE(status)) { |
| 206 | return_ACPI_STATUS(status); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | /* |
| 211 | * Install the SCI handler and Global Lock handler. This completes the |
| 212 | * hardware initialization. |
| 213 | */ |
| 214 | if (!(flags & ACPI_NO_HANDLER_INIT)) { |
| 215 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
| 216 | "[Init] Installing SCI/GL handlers\n")); |
| 217 | |
| 218 | status = acpi_ev_install_xrupt_handlers(); |
| 219 | if (ACPI_FAILURE(status)) { |
| 220 | return_ACPI_STATUS(status); |
| 221 | } |
| 222 | } |
| 223 | #endif /* !ACPI_REDUCED_HARDWARE */ |
| 224 | |
| 225 | return_ACPI_STATUS(status); |
| 226 | } |
Lv Zheng | d21f600 | 2013-10-29 09:30:10 +0800 | [diff] [blame] | 227 | |
| 228 | ACPI_EXPORT_SYMBOL_INIT(acpi_enable_subsystem) |
Bob Moore | d978348 | 2012-08-17 10:51:47 +0800 | [diff] [blame] | 229 | |
| 230 | /******************************************************************************* |
| 231 | * |
| 232 | * FUNCTION: acpi_initialize_objects |
| 233 | * |
| 234 | * PARAMETERS: flags - Init/enable Options |
| 235 | * |
| 236 | * RETURN: Status |
| 237 | * |
| 238 | * DESCRIPTION: Completes namespace initialization by initializing device |
| 239 | * objects and executing AML code for Regions, buffers, etc. |
| 240 | * |
| 241 | ******************************************************************************/ |
Lv Zheng | 2368b1a | 2016-08-04 16:43:19 +0800 | [diff] [blame] | 242 | acpi_status ACPI_INIT_FUNCTION acpi_initialize_objects(u32 flags) |
Bob Moore | d978348 | 2012-08-17 10:51:47 +0800 | [diff] [blame] | 243 | { |
| 244 | acpi_status status = AE_OK; |
| 245 | |
| 246 | ACPI_FUNCTION_TRACE(acpi_initialize_objects); |
| 247 | |
Bob Moore | b487867 | 2014-11-27 14:26:07 +0800 | [diff] [blame] | 248 | #ifdef ACPI_EXEC_APP |
| 249 | /* |
| 250 | * This call implements the "initialization file" option for acpi_exec. |
| 251 | * This is the precise point that we want to perform the overrides. |
| 252 | */ |
| 253 | ae_do_object_overrides(); |
| 254 | #endif |
Bob Moore | d978348 | 2012-08-17 10:51:47 +0800 | [diff] [blame] | 255 | |
| 256 | /* |
| 257 | * Execute any module-level code that was detected during the table load |
| 258 | * phase. Although illegal since ACPI 2.0, there are many machines that |
| 259 | * contain this type of code. Each block of detected executable AML code |
| 260 | * outside of any control method is wrapped with a temporary control |
| 261 | * method object and placed on a global list. The methods on this list |
| 262 | * are executed below. |
Bob Moore | 2785ce8 | 2015-12-29 14:04:19 +0800 | [diff] [blame] | 263 | * |
| 264 | * This case executes the module-level code for all tables only after |
| 265 | * all of the tables have been loaded. It is a legacy option and is |
| 266 | * not compatible with other ACPI implementations. See acpi_ns_load_table. |
Bob Moore | d978348 | 2012-08-17 10:51:47 +0800 | [diff] [blame] | 267 | */ |
Lv Zheng | de56ba9 | 2016-09-07 14:06:54 +0800 | [diff] [blame] | 268 | if (!acpi_gbl_parse_table_as_term_list |
| 269 | && acpi_gbl_group_module_level_code) { |
Bob Moore | 2785ce8 | 2015-12-29 14:04:19 +0800 | [diff] [blame] | 270 | acpi_ns_exec_module_code_list(); |
Bob Moore | d978348 | 2012-08-17 10:51:47 +0800 | [diff] [blame] | 271 | |
Lv Zheng | 5508df8 | 2016-03-10 10:54:29 +0800 | [diff] [blame] | 272 | /* |
| 273 | * Initialize the objects that remain uninitialized. This |
| 274 | * runs the executable AML that may be part of the |
| 275 | * declaration of these objects: |
| 276 | * operation_regions, buffer_fields, Buffers, and Packages. |
| 277 | */ |
| 278 | if (!(flags & ACPI_NO_OBJECT_INIT)) { |
| 279 | status = acpi_ns_initialize_objects(); |
| 280 | if (ACPI_FAILURE(status)) { |
| 281 | return_ACPI_STATUS(status); |
| 282 | } |
Bob Moore | d978348 | 2012-08-17 10:51:47 +0800 | [diff] [blame] | 283 | } |
| 284 | } |
| 285 | |
Lv Zheng | 9559130 | 2016-02-19 14:17:05 +0800 | [diff] [blame] | 286 | /* |
Lv Zheng | ced0436 | 2016-02-19 14:17:15 +0800 | [diff] [blame] | 287 | * Initialize all device/region objects in the namespace. This runs |
| 288 | * the device _STA and _INI methods and region _REG methods. |
Bob Moore | d978348 | 2012-08-17 10:51:47 +0800 | [diff] [blame] | 289 | */ |
Lv Zheng | ced0436 | 2016-02-19 14:17:15 +0800 | [diff] [blame] | 290 | if (!(flags & (ACPI_NO_DEVICE_INIT | ACPI_NO_ADDRESS_SPACE_INIT))) { |
| 291 | status = acpi_ns_initialize_devices(flags); |
Bob Moore | d978348 | 2012-08-17 10:51:47 +0800 | [diff] [blame] | 292 | if (ACPI_FAILURE(status)) { |
| 293 | return_ACPI_STATUS(status); |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | /* |
| 298 | * Empty the caches (delete the cached objects) on the assumption that |
| 299 | * the table load filled them up more than they will be at runtime -- |
| 300 | * thus wasting non-paged memory. |
| 301 | */ |
| 302 | status = acpi_purge_cached_objects(); |
| 303 | |
| 304 | acpi_gbl_startup_flags |= ACPI_INITIALIZED_OK; |
| 305 | return_ACPI_STATUS(status); |
| 306 | } |
Lv Zheng | d21f600 | 2013-10-29 09:30:10 +0800 | [diff] [blame] | 307 | |
| 308 | ACPI_EXPORT_SYMBOL_INIT(acpi_initialize_objects) |