1 /****************************************************************************** 2 * 3 * Module Name: utinit - Common ACPI subsystem initialization 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2014, 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 45 #define __UTINIT_C__ 46 47 #include "acpi.h" 48 #include "accommon.h" 49 #include "acnamesp.h" 50 #include "acevents.h" 51 #include "actables.h" 52 53 #define _COMPONENT ACPI_UTILITIES 54 ACPI_MODULE_NAME ("utinit") 55 56 /* Local prototypes */ 57 58 static void AcpiUtTerminate ( 59 void); 60 61 #if (!ACPI_REDUCED_HARDWARE) 62 63 static void 64 AcpiUtFreeGpeLists ( 65 void); 66 67 #else 68 69 #define AcpiUtFreeGpeLists() 70 #endif /* !ACPI_REDUCED_HARDWARE */ 71 72 73 #if (!ACPI_REDUCED_HARDWARE) 74 /****************************************************************************** 75 * 76 * FUNCTION: AcpiUtFreeGpeLists 77 * 78 * PARAMETERS: none 79 * 80 * RETURN: none 81 * 82 * DESCRIPTION: Free global GPE lists 83 * 84 ******************************************************************************/ 85 86 static void 87 AcpiUtFreeGpeLists ( 88 void) 89 { 90 ACPI_GPE_BLOCK_INFO *GpeBlock; 91 ACPI_GPE_BLOCK_INFO *NextGpeBlock; 92 ACPI_GPE_XRUPT_INFO *GpeXruptInfo; 93 ACPI_GPE_XRUPT_INFO *NextGpeXruptInfo; 94 95 96 /* Free global GPE blocks and related info structures */ 97 98 GpeXruptInfo = AcpiGbl_GpeXruptListHead; 99 while (GpeXruptInfo) 100 { 101 GpeBlock = GpeXruptInfo->GpeBlockListHead; 102 while (GpeBlock) 103 { 104 NextGpeBlock = GpeBlock->Next; 105 ACPI_FREE (GpeBlock->EventInfo); 106 ACPI_FREE (GpeBlock->RegisterInfo); 107 ACPI_FREE (GpeBlock); 108 109 GpeBlock = NextGpeBlock; 110 } 111 NextGpeXruptInfo = GpeXruptInfo->Next; 112 ACPI_FREE (GpeXruptInfo); 113 GpeXruptInfo = NextGpeXruptInfo; 114 } 115 } 116 #endif /* !ACPI_REDUCED_HARDWARE */ 117 118 119 /******************************************************************************* 120 * 121 * FUNCTION: AcpiUtInitGlobals 122 * 123 * PARAMETERS: None 124 * 125 * RETURN: Status 126 * 127 * DESCRIPTION: Initialize ACPICA globals. All globals that require specific 128 * initialization should be initialized here. This allows for 129 * a warm restart. 130 * 131 ******************************************************************************/ 132 133 ACPI_STATUS 134 AcpiUtInitGlobals ( 135 void) 136 { 137 ACPI_STATUS Status; 138 UINT32 i; 139 140 141 ACPI_FUNCTION_TRACE (UtInitGlobals); 142 143 144 /* Create all memory caches */ 145 146 Status = AcpiUtCreateCaches (); 147 if (ACPI_FAILURE (Status)) 148 { 149 return_ACPI_STATUS (Status); 150 } 151 152 /* Address Range lists */ 153 154 for (i = 0; i < ACPI_ADDRESS_RANGE_MAX; i++) 155 { 156 AcpiGbl_AddressRangeList[i] = NULL; 157 } 158 159 /* Mutex locked flags */ 160 161 for (i = 0; i < ACPI_NUM_MUTEX; i++) 162 { 163 AcpiGbl_MutexInfo[i].Mutex = NULL; 164 AcpiGbl_MutexInfo[i].ThreadId = ACPI_MUTEX_NOT_ACQUIRED; 165 AcpiGbl_MutexInfo[i].UseCount = 0; 166 } 167 168 for (i = 0; i < ACPI_NUM_OWNERID_MASKS; i++) 169 { 170 AcpiGbl_OwnerIdMask[i] = 0; 171 } 172 173 /* Last OwnerID is never valid */ 174 175 AcpiGbl_OwnerIdMask[ACPI_NUM_OWNERID_MASKS - 1] = 0x80000000; 176 177 /* Event counters */ 178 179 AcpiMethodCount = 0; 180 AcpiSciCount = 0; 181 AcpiGpeCount = 0; 182 183 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) 184 { 185 AcpiFixedEventCount[i] = 0; 186 } 187 188 #if (!ACPI_REDUCED_HARDWARE) 189 190 /* GPE/SCI support */ 191 192 AcpiGbl_AllGpesInitialized = FALSE; 193 AcpiGbl_GpeXruptListHead = NULL; 194 AcpiGbl_GpeFadtBlocks[0] = NULL; 195 AcpiGbl_GpeFadtBlocks[1] = NULL; 196 AcpiCurrentGpeCount = 0; 197 198 AcpiGbl_GlobalEventHandler = NULL; 199 AcpiGbl_SciHandlerList = NULL; 200 201 #endif /* !ACPI_REDUCED_HARDWARE */ 202 203 /* Global handlers */ 204 205 AcpiGbl_GlobalNotify[0].Handler = NULL; 206 AcpiGbl_GlobalNotify[1].Handler = NULL; 207 AcpiGbl_ExceptionHandler = NULL; 208 AcpiGbl_InitHandler = NULL; 209 AcpiGbl_TableHandler = NULL; 210 AcpiGbl_InterfaceHandler = NULL; 211 212 /* Global Lock support */ 213 214 AcpiGbl_GlobalLockSemaphore = NULL; 215 AcpiGbl_GlobalLockMutex = NULL; 216 AcpiGbl_GlobalLockAcquired = FALSE; 217 AcpiGbl_GlobalLockHandle = 0; 218 AcpiGbl_GlobalLockPresent = FALSE; 219 220 /* Miscellaneous variables */ 221 222 AcpiGbl_DSDT = NULL; 223 AcpiGbl_CmSingleStep = FALSE; 224 AcpiGbl_Shutdown = FALSE; 225 AcpiGbl_NsLookupCount = 0; 226 AcpiGbl_PsFindCount = 0; 227 AcpiGbl_AcpiHardwarePresent = TRUE; 228 AcpiGbl_LastOwnerIdIndex = 0; 229 AcpiGbl_NextOwnerIdOffset = 0; 230 AcpiGbl_TraceDbgLevel = 0; 231 AcpiGbl_TraceDbgLayer = 0; 232 AcpiGbl_DebuggerConfiguration = DEBUGGER_THREADING; 233 AcpiGbl_OsiMutex = NULL; 234 AcpiGbl_RegMethodsExecuted = FALSE; 235 236 /* Hardware oriented */ 237 238 AcpiGbl_EventsInitialized = FALSE; 239 AcpiGbl_SystemAwakeAndRunning = TRUE; 240 241 /* Namespace */ 242 243 AcpiGbl_ModuleCodeList = NULL; 244 AcpiGbl_RootNode = NULL; 245 AcpiGbl_RootNodeStruct.Name.Integer = ACPI_ROOT_NAME; 246 AcpiGbl_RootNodeStruct.DescriptorType = ACPI_DESC_TYPE_NAMED; 247 AcpiGbl_RootNodeStruct.Type = ACPI_TYPE_DEVICE; 248 AcpiGbl_RootNodeStruct.Parent = NULL; 249 AcpiGbl_RootNodeStruct.Child = NULL; 250 AcpiGbl_RootNodeStruct.Peer = NULL; 251 AcpiGbl_RootNodeStruct.Object = NULL; 252 253 254 #ifdef ACPI_DISASSEMBLER 255 AcpiGbl_ExternalList = NULL; 256 AcpiGbl_NumExternalMethods = 0; 257 AcpiGbl_ResolvedExternalMethods = 0; 258 #endif 259 260 #ifdef ACPI_DEBUG_OUTPUT 261 AcpiGbl_LowestStackPointer = ACPI_CAST_PTR (ACPI_SIZE, ACPI_SIZE_MAX); 262 #endif 263 264 #ifdef ACPI_DBG_TRACK_ALLOCATIONS 265 AcpiGbl_DisplayFinalMemStats = FALSE; 266 AcpiGbl_DisableMemTracking = FALSE; 267 #endif 268 269 ACPI_DEBUGGER_EXEC (AcpiGbl_DbTerminateThreads = FALSE); 270 271 return_ACPI_STATUS (AE_OK); 272 } 273 274 275 /****************************************************************************** 276 * 277 * FUNCTION: AcpiUtTerminate 278 * 279 * PARAMETERS: none 280 * 281 * RETURN: none 282 * 283 * DESCRIPTION: Free global memory 284 * 285 ******************************************************************************/ 286 287 static void 288 AcpiUtTerminate ( 289 void) 290 { 291 ACPI_FUNCTION_TRACE (UtTerminate); 292 293 AcpiUtFreeGpeLists (); 294 AcpiUtDeleteAddressLists (); 295 return_VOID; 296 } 297 298 299 /******************************************************************************* 300 * 301 * FUNCTION: AcpiUtSubsystemShutdown 302 * 303 * PARAMETERS: None 304 * 305 * RETURN: None 306 * 307 * DESCRIPTION: Shutdown the various components. Do not delete the mutex 308 * objects here, because the AML debugger may be still running. 309 * 310 ******************************************************************************/ 311 312 void 313 AcpiUtSubsystemShutdown ( 314 void) 315 { 316 ACPI_FUNCTION_TRACE (UtSubsystemShutdown); 317 318 319 #ifndef ACPI_ASL_COMPILER 320 321 /* Close the AcpiEvent Handling */ 322 323 AcpiEvTerminate (); 324 325 /* Delete any dynamic _OSI interfaces */ 326 327 AcpiUtInterfaceTerminate (); 328 #endif 329 330 /* Close the Namespace */ 331 332 AcpiNsTerminate (); 333 334 /* Delete the ACPI tables */ 335 336 AcpiTbTerminate (); 337 338 /* Close the globals */ 339 340 AcpiUtTerminate (); 341 342 /* Purge the local caches */ 343 344 (void) AcpiUtDeleteCaches (); 345 return_VOID; 346 } 347