1 /****************************************************************************** 2 * 3 * Module Name: utxfinit - External interfaces for ACPICA initialization 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2015, Intel Corp. 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 44 #define EXPORT_ACPI_INTERFACES 45 46 #include <contrib/dev/acpica/include/acpi.h> 47 #include <contrib/dev/acpica/include/accommon.h> 48 #include <contrib/dev/acpica/include/acevents.h> 49 #include <contrib/dev/acpica/include/acnamesp.h> 50 #include <contrib/dev/acpica/include/acdebug.h> 51 #include <contrib/dev/acpica/include/actables.h> 52 53 #define _COMPONENT ACPI_UTILITIES 54 ACPI_MODULE_NAME ("utxfinit") 55 56 /* For AcpiExec only */ 57 void 58 AeDoObjectOverrides ( 59 void); 60 61 62 /******************************************************************************* 63 * 64 * FUNCTION: AcpiInitializeSubsystem 65 * 66 * PARAMETERS: None 67 * 68 * RETURN: Status 69 * 70 * DESCRIPTION: Initializes all global variables. This is the first function 71 * called, so any early initialization belongs here. 72 * 73 ******************************************************************************/ 74 75 ACPI_STATUS 76 AcpiInitializeSubsystem ( 77 void) 78 { 79 ACPI_STATUS Status; 80 81 82 ACPI_FUNCTION_TRACE (AcpiInitializeSubsystem); 83 84 85 AcpiGbl_StartupFlags = ACPI_SUBSYSTEM_INITIALIZE; 86 ACPI_DEBUG_EXEC (AcpiUtInitStackPtrTrace ()); 87 88 /* Initialize the OS-Dependent layer */ 89 90 Status = AcpiOsInitialize (); 91 if (ACPI_FAILURE (Status)) 92 { 93 ACPI_EXCEPTION ((AE_INFO, Status, "During OSL initialization")); 94 return_ACPI_STATUS (Status); 95 } 96 97 /* Initialize all globals used by the subsystem */ 98 99 Status = AcpiUtInitGlobals (); 100 if (ACPI_FAILURE (Status)) 101 { 102 ACPI_EXCEPTION ((AE_INFO, Status, "During initialization of globals")); 103 return_ACPI_STATUS (Status); 104 } 105 106 /* Create the default mutex objects */ 107 108 Status = AcpiUtMutexInitialize (); 109 if (ACPI_FAILURE (Status)) 110 { 111 ACPI_EXCEPTION ((AE_INFO, Status, "During Global Mutex creation")); 112 return_ACPI_STATUS (Status); 113 } 114 115 /* 116 * Initialize the namespace manager and 117 * the root of the namespace tree 118 */ 119 Status = AcpiNsRootInitialize (); 120 if (ACPI_FAILURE (Status)) 121 { 122 ACPI_EXCEPTION ((AE_INFO, Status, "During Namespace initialization")); 123 return_ACPI_STATUS (Status); 124 } 125 126 /* Initialize the global OSI interfaces list with the static names */ 127 128 Status = AcpiUtInitializeInterfaces (); 129 if (ACPI_FAILURE (Status)) 130 { 131 ACPI_EXCEPTION ((AE_INFO, Status, "During OSI interfaces initialization")); 132 return_ACPI_STATUS (Status); 133 } 134 135 return_ACPI_STATUS (AE_OK); 136 } 137 138 ACPI_EXPORT_SYMBOL_INIT (AcpiInitializeSubsystem) 139 140 141 /******************************************************************************* 142 * 143 * FUNCTION: AcpiEnableSubsystem 144 * 145 * PARAMETERS: Flags - Init/enable Options 146 * 147 * RETURN: Status 148 * 149 * DESCRIPTION: Completes the subsystem initialization including hardware. 150 * Puts system into ACPI mode if it isn't already. 151 * 152 ******************************************************************************/ 153 154 ACPI_STATUS 155 AcpiEnableSubsystem ( 156 UINT32 Flags) 157 { 158 ACPI_STATUS Status = AE_OK; 159 160 161 ACPI_FUNCTION_TRACE (AcpiEnableSubsystem); 162 163 164 #if (!ACPI_REDUCED_HARDWARE) 165 166 /* Enable ACPI mode */ 167 168 if (!(Flags & ACPI_NO_ACPI_ENABLE)) 169 { 170 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Init] Going into ACPI mode\n")); 171 172 AcpiGbl_OriginalMode = AcpiHwGetMode(); 173 174 Status = AcpiEnable (); 175 if (ACPI_FAILURE (Status)) 176 { 177 ACPI_WARNING ((AE_INFO, "AcpiEnable failed")); 178 return_ACPI_STATUS (Status); 179 } 180 } 181 182 /* 183 * Obtain a permanent mapping for the FACS. This is required for the 184 * Global Lock and the Firmware Waking Vector 185 */ 186 if (!(Flags & ACPI_NO_FACS_INIT)) 187 { 188 Status = AcpiTbInitializeFacs (); 189 if (ACPI_FAILURE (Status)) 190 { 191 ACPI_WARNING ((AE_INFO, "Could not map the FACS table")); 192 return_ACPI_STATUS (Status); 193 } 194 } 195 196 #endif /* !ACPI_REDUCED_HARDWARE */ 197 198 /* 199 * Install the default OpRegion handlers. These are installed unless 200 * other handlers have already been installed via the 201 * InstallAddressSpaceHandler interface. 202 */ 203 if (!(Flags & ACPI_NO_ADDRESS_SPACE_INIT)) 204 { 205 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 206 "[Init] Installing default address space handlers\n")); 207 208 Status = AcpiEvInstallRegionHandlers (); 209 if (ACPI_FAILURE (Status)) 210 { 211 return_ACPI_STATUS (Status); 212 } 213 } 214 215 #if (!ACPI_REDUCED_HARDWARE) 216 /* 217 * Initialize ACPI Event handling (Fixed and General Purpose) 218 * 219 * Note1: We must have the hardware and events initialized before we can 220 * execute any control methods safely. Any control method can require 221 * ACPI hardware support, so the hardware must be fully initialized before 222 * any method execution! 223 * 224 * Note2: Fixed events are initialized and enabled here. GPEs are 225 * initialized, but cannot be enabled until after the hardware is 226 * completely initialized (SCI and GlobalLock activated) and the various 227 * initialization control methods are run (_REG, _STA, _INI) on the 228 * entire namespace. 229 */ 230 if (!(Flags & ACPI_NO_EVENT_INIT)) 231 { 232 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 233 "[Init] Initializing ACPI events\n")); 234 235 Status = AcpiEvInitializeEvents (); 236 if (ACPI_FAILURE (Status)) 237 { 238 return_ACPI_STATUS (Status); 239 } 240 } 241 242 /* 243 * Install the SCI handler and Global Lock handler. This completes the 244 * hardware initialization. 245 */ 246 if (!(Flags & ACPI_NO_HANDLER_INIT)) 247 { 248 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 249 "[Init] Installing SCI/GL handlers\n")); 250 251 Status = AcpiEvInstallXruptHandlers (); 252 if (ACPI_FAILURE (Status)) 253 { 254 return_ACPI_STATUS (Status); 255 } 256 } 257 258 #endif /* !ACPI_REDUCED_HARDWARE */ 259 260 return_ACPI_STATUS (Status); 261 } 262 263 ACPI_EXPORT_SYMBOL_INIT (AcpiEnableSubsystem) 264 265 266 /******************************************************************************* 267 * 268 * FUNCTION: AcpiInitializeObjects 269 * 270 * PARAMETERS: Flags - Init/enable Options 271 * 272 * RETURN: Status 273 * 274 * DESCRIPTION: Completes namespace initialization by initializing device 275 * objects and executing AML code for Regions, buffers, etc. 276 * 277 ******************************************************************************/ 278 279 ACPI_STATUS 280 AcpiInitializeObjects ( 281 UINT32 Flags) 282 { 283 ACPI_STATUS Status = AE_OK; 284 285 286 ACPI_FUNCTION_TRACE (AcpiInitializeObjects); 287 288 289 /* 290 * Run all _REG methods 291 * 292 * Note: Any objects accessed by the _REG methods will be automatically 293 * initialized, even if they contain executable AML (see the call to 294 * AcpiNsInitializeObjects below). 295 */ 296 if (!(Flags & ACPI_NO_ADDRESS_SPACE_INIT)) 297 { 298 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 299 "[Init] Executing _REG OpRegion methods\n")); 300 301 Status = AcpiEvInitializeOpRegions (); 302 if (ACPI_FAILURE (Status)) 303 { 304 return_ACPI_STATUS (Status); 305 } 306 } 307 308 #ifdef ACPI_EXEC_APP 309 /* 310 * This call implements the "initialization file" option for AcpiExec. 311 * This is the precise point that we want to perform the overrides. 312 */ 313 AeDoObjectOverrides (); 314 #endif 315 316 /* 317 * Execute any module-level code that was detected during the table load 318 * phase. Although illegal since ACPI 2.0, there are many machines that 319 * contain this type of code. Each block of detected executable AML code 320 * outside of any control method is wrapped with a temporary control 321 * method object and placed on a global list. The methods on this list 322 * are executed below. 323 */ 324 AcpiNsExecModuleCodeList (); 325 326 /* 327 * Initialize the objects that remain uninitialized. This runs the 328 * executable AML that may be part of the declaration of these objects: 329 * OperationRegions, BufferFields, Buffers, and Packages. 330 */ 331 if (!(Flags & ACPI_NO_OBJECT_INIT)) 332 { 333 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 334 "[Init] Completing Initialization of ACPI Objects\n")); 335 336 Status = AcpiNsInitializeObjects (); 337 if (ACPI_FAILURE (Status)) 338 { 339 return_ACPI_STATUS (Status); 340 } 341 } 342 343 /* 344 * Initialize all device objects in the namespace. This runs the device 345 * _STA and _INI methods. 346 */ 347 if (!(Flags & ACPI_NO_DEVICE_INIT)) 348 { 349 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 350 "[Init] Initializing ACPI Devices\n")); 351 352 Status = AcpiNsInitializeDevices (); 353 if (ACPI_FAILURE (Status)) 354 { 355 return_ACPI_STATUS (Status); 356 } 357 } 358 359 /* 360 * Empty the caches (delete the cached objects) on the assumption that 361 * the table load filled them up more than they will be at runtime -- 362 * thus wasting non-paged memory. 363 */ 364 Status = AcpiPurgeCachedObjects (); 365 366 AcpiGbl_StartupFlags |= ACPI_INITIALIZED_OK; 367 return_ACPI_STATUS (Status); 368 } 369 370 ACPI_EXPORT_SYMBOL_INIT (AcpiInitializeObjects) 371