1 /****************************************************************************** 2 * 3 * Module Name: tbxfload - Table load/unload external interfaces 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2016, 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 "acpi.h" 47 #include "accommon.h" 48 #include "acnamesp.h" 49 #include "actables.h" 50 #include "acevents.h" 51 52 #define _COMPONENT ACPI_TABLES 53 ACPI_MODULE_NAME ("tbxfload") 54 55 56 /******************************************************************************* 57 * 58 * FUNCTION: AcpiLoadTables 59 * 60 * PARAMETERS: None 61 * 62 * RETURN: Status 63 * 64 * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT 65 * 66 ******************************************************************************/ 67 68 ACPI_STATUS ACPI_INIT_FUNCTION 69 AcpiLoadTables ( 70 void) 71 { 72 ACPI_STATUS Status; 73 74 75 ACPI_FUNCTION_TRACE (AcpiLoadTables); 76 77 78 /* 79 * Install the default operation region handlers. These are the 80 * handlers that are defined by the ACPI specification to be 81 * "always accessible" -- namely, SystemMemory, SystemIO, and 82 * PCI_Config. This also means that no _REG methods need to be 83 * run for these address spaces. We need to have these handlers 84 * installed before any AML code can be executed, especially any 85 * module-level code (11/2015). 86 * Note that we allow OSPMs to install their own region handlers 87 * between AcpiInitializeSubsystem() and AcpiLoadTables() to use 88 * their customized default region handlers. 89 */ 90 Status = AcpiEvInstallRegionHandlers (); 91 if (ACPI_FAILURE (Status)) 92 { 93 ACPI_EXCEPTION ((AE_INFO, Status, "During Region initialization")); 94 return_ACPI_STATUS (Status); 95 } 96 97 /* Load the namespace from the tables */ 98 99 Status = AcpiTbLoadNamespace (); 100 101 /* Don't let single failures abort the load */ 102 103 if (Status == AE_CTRL_TERMINATE) 104 { 105 Status = AE_OK; 106 } 107 108 if (ACPI_FAILURE (Status)) 109 { 110 ACPI_EXCEPTION ((AE_INFO, Status, 111 "While loading namespace from ACPI tables")); 112 } 113 114 if (AcpiGbl_ParseTableAsTermList || !AcpiGbl_GroupModuleLevelCode) 115 { 116 /* 117 * Initialize the objects that remain uninitialized. This 118 * runs the executable AML that may be part of the 119 * declaration of these objects: 120 * OperationRegions, BufferFields, Buffers, and Packages. 121 */ 122 Status = AcpiNsInitializeObjects (); 123 if (ACPI_FAILURE (Status)) 124 { 125 return_ACPI_STATUS (Status); 126 } 127 } 128 129 AcpiGbl_NamespaceInitialized = TRUE; 130 return_ACPI_STATUS (Status); 131 } 132 133 ACPI_EXPORT_SYMBOL_INIT (AcpiLoadTables) 134 135 136 /******************************************************************************* 137 * 138 * FUNCTION: AcpiTbLoadNamespace 139 * 140 * PARAMETERS: None 141 * 142 * RETURN: Status 143 * 144 * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in 145 * the RSDT/XSDT. 146 * 147 ******************************************************************************/ 148 149 ACPI_STATUS 150 AcpiTbLoadNamespace ( 151 void) 152 { 153 ACPI_STATUS Status; 154 UINT32 i; 155 ACPI_TABLE_HEADER *NewDsdt; 156 ACPI_TABLE_DESC *Table; 157 UINT32 TablesLoaded = 0; 158 UINT32 TablesFailed = 0; 159 160 161 ACPI_FUNCTION_TRACE (TbLoadNamespace); 162 163 164 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES); 165 166 /* 167 * Load the namespace. The DSDT is required, but any SSDT and 168 * PSDT tables are optional. Verify the DSDT. 169 */ 170 Table = &AcpiGbl_RootTableList.Tables[AcpiGbl_DsdtIndex]; 171 172 if (!AcpiGbl_RootTableList.CurrentTableCount || 173 !ACPI_COMPARE_NAME (Table->Signature.Ascii, ACPI_SIG_DSDT) || 174 ACPI_FAILURE (AcpiTbValidateTable (Table))) 175 { 176 Status = AE_NO_ACPI_TABLES; 177 goto UnlockAndExit; 178 } 179 180 /* 181 * Save the DSDT pointer for simple access. This is the mapped memory 182 * address. We must take care here because the address of the .Tables 183 * array can change dynamically as tables are loaded at run-time. Note: 184 * .Pointer field is not validated until after call to AcpiTbValidateTable. 185 */ 186 AcpiGbl_DSDT = Table->Pointer; 187 188 /* 189 * Optionally copy the entire DSDT to local memory (instead of simply 190 * mapping it.) There are some BIOSs that corrupt or replace the original 191 * DSDT, creating the need for this option. Default is FALSE, do not copy 192 * the DSDT. 193 */ 194 if (AcpiGbl_CopyDsdtLocally) 195 { 196 NewDsdt = AcpiTbCopyDsdt (AcpiGbl_DsdtIndex); 197 if (NewDsdt) 198 { 199 AcpiGbl_DSDT = NewDsdt; 200 } 201 } 202 203 /* 204 * Save the original DSDT header for detection of table corruption 205 * and/or replacement of the DSDT from outside the OS. 206 */ 207 memcpy (&AcpiGbl_OriginalDsdtHeader, AcpiGbl_DSDT, 208 sizeof (ACPI_TABLE_HEADER)); 209 210 /* Load and parse tables */ 211 212 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 213 Status = AcpiNsLoadTable (AcpiGbl_DsdtIndex, AcpiGbl_RootNode); 214 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES); 215 if (ACPI_FAILURE (Status)) 216 { 217 ACPI_EXCEPTION ((AE_INFO, Status, "[DSDT] table load failed")); 218 TablesFailed++; 219 } 220 else 221 { 222 TablesLoaded++; 223 } 224 225 /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */ 226 227 for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i) 228 { 229 Table = &AcpiGbl_RootTableList.Tables[i]; 230 231 if (!AcpiGbl_RootTableList.Tables[i].Address || 232 (!ACPI_COMPARE_NAME (Table->Signature.Ascii, ACPI_SIG_SSDT) && 233 !ACPI_COMPARE_NAME (Table->Signature.Ascii, ACPI_SIG_PSDT) && 234 !ACPI_COMPARE_NAME (Table->Signature.Ascii, ACPI_SIG_OSDT)) || 235 ACPI_FAILURE (AcpiTbValidateTable (Table))) 236 { 237 continue; 238 } 239 240 /* Ignore errors while loading tables, get as many as possible */ 241 242 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 243 Status = AcpiNsLoadTable (i, AcpiGbl_RootNode); 244 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES); 245 if (ACPI_FAILURE (Status)) 246 { 247 ACPI_EXCEPTION ((AE_INFO, Status, "(%4.4s:%8.8s) while loading table", 248 Table->Signature.Ascii, Table->Pointer->OemTableId)); 249 250 TablesFailed++; 251 252 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, 253 "Table [%4.4s:%8.8s] (id FF) - Table namespace load failed\n\n", 254 Table->Signature.Ascii, Table->Pointer->OemTableId)); 255 } 256 else 257 { 258 TablesLoaded++; 259 } 260 } 261 262 if (!TablesFailed) 263 { 264 ACPI_INFO (( 265 "%u ACPI AML tables successfully acquired and loaded", 266 TablesLoaded)); 267 } 268 else 269 { 270 ACPI_ERROR ((AE_INFO, 271 "%u table load failures, %u successful", 272 TablesFailed, TablesLoaded)); 273 274 /* Indicate at least one failure */ 275 276 Status = AE_CTRL_TERMINATE; 277 } 278 279 UnlockAndExit: 280 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 281 return_ACPI_STATUS (Status); 282 } 283 284 285 /******************************************************************************* 286 * 287 * FUNCTION: AcpiInstallTable 288 * 289 * PARAMETERS: Address - Address of the ACPI table to be installed. 290 * Physical - Whether the address is a physical table 291 * address or not 292 * 293 * RETURN: Status 294 * 295 * DESCRIPTION: Dynamically install an ACPI table. 296 * Note: This function should only be invoked after 297 * AcpiInitializeTables() and before AcpiLoadTables(). 298 * 299 ******************************************************************************/ 300 301 ACPI_STATUS ACPI_INIT_FUNCTION 302 AcpiInstallTable ( 303 ACPI_PHYSICAL_ADDRESS Address, 304 BOOLEAN Physical) 305 { 306 ACPI_STATUS Status; 307 UINT8 Flags; 308 UINT32 TableIndex; 309 310 311 ACPI_FUNCTION_TRACE (AcpiInstallTable); 312 313 314 if (Physical) 315 { 316 Flags = ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL; 317 } 318 else 319 { 320 Flags = ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL; 321 } 322 323 Status = AcpiTbInstallStandardTable (Address, Flags, 324 FALSE, FALSE, &TableIndex); 325 326 return_ACPI_STATUS (Status); 327 } 328 329 ACPI_EXPORT_SYMBOL_INIT (AcpiInstallTable) 330 331 332 /******************************************************************************* 333 * 334 * FUNCTION: AcpiLoadTable 335 * 336 * PARAMETERS: Table - Pointer to a buffer containing the ACPI 337 * table to be loaded. 338 * 339 * RETURN: Status 340 * 341 * DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must 342 * be a valid ACPI table with a valid ACPI table header. 343 * Note1: Mainly intended to support hotplug addition of SSDTs. 344 * Note2: Does not copy the incoming table. User is responsible 345 * to ensure that the table is not deleted or unmapped. 346 * 347 ******************************************************************************/ 348 349 ACPI_STATUS 350 AcpiLoadTable ( 351 ACPI_TABLE_HEADER *Table) 352 { 353 ACPI_STATUS Status; 354 UINT32 TableIndex; 355 356 357 ACPI_FUNCTION_TRACE (AcpiLoadTable); 358 359 360 /* Parameter validation */ 361 362 if (!Table) 363 { 364 return_ACPI_STATUS (AE_BAD_PARAMETER); 365 } 366 367 /* Install the table and load it into the namespace */ 368 369 ACPI_INFO (("Host-directed Dynamic ACPI Table Load:")); 370 Status = AcpiTbInstallAndLoadTable (Table, ACPI_PTR_TO_PHYSADDR (Table), 371 ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL, FALSE, &TableIndex); 372 return_ACPI_STATUS (Status); 373 } 374 375 ACPI_EXPORT_SYMBOL (AcpiLoadTable) 376 377 378 /******************************************************************************* 379 * 380 * FUNCTION: AcpiUnloadParentTable 381 * 382 * PARAMETERS: Object - Handle to any namespace object owned by 383 * the table to be unloaded 384 * 385 * RETURN: Status 386 * 387 * DESCRIPTION: Via any namespace object within an SSDT or OEMx table, unloads 388 * the table and deletes all namespace objects associated with 389 * that table. Unloading of the DSDT is not allowed. 390 * Note: Mainly intended to support hotplug removal of SSDTs. 391 * 392 ******************************************************************************/ 393 394 ACPI_STATUS 395 AcpiUnloadParentTable ( 396 ACPI_HANDLE Object) 397 { 398 ACPI_NAMESPACE_NODE *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Object); 399 ACPI_STATUS Status = AE_NOT_EXIST; 400 ACPI_OWNER_ID OwnerId; 401 UINT32 i; 402 403 404 ACPI_FUNCTION_TRACE (AcpiUnloadParentTable); 405 406 407 /* Parameter validation */ 408 409 if (!Object) 410 { 411 return_ACPI_STATUS (AE_BAD_PARAMETER); 412 } 413 414 /* 415 * The node OwnerId is currently the same as the parent table ID. 416 * However, this could change in the future. 417 */ 418 OwnerId = Node->OwnerId; 419 if (!OwnerId) 420 { 421 /* OwnerId==0 means DSDT is the owner. DSDT cannot be unloaded */ 422 423 return_ACPI_STATUS (AE_TYPE); 424 } 425 426 /* Must acquire the interpreter lock during this operation */ 427 428 Status = AcpiUtAcquireMutex (ACPI_MTX_INTERPRETER); 429 if (ACPI_FAILURE (Status)) 430 { 431 return_ACPI_STATUS (Status); 432 } 433 434 /* Find the table in the global table list */ 435 436 for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++) 437 { 438 if (OwnerId != AcpiGbl_RootTableList.Tables[i].OwnerId) 439 { 440 continue; 441 } 442 443 /* 444 * Allow unload of SSDT and OEMx tables only. Do not allow unload 445 * of the DSDT. No other types of tables should get here, since 446 * only these types can contain AML and thus are the only types 447 * that can create namespace objects. 448 */ 449 if (ACPI_COMPARE_NAME ( 450 AcpiGbl_RootTableList.Tables[i].Signature.Ascii, 451 ACPI_SIG_DSDT)) 452 { 453 Status = AE_TYPE; 454 break; 455 } 456 457 /* Ensure the table is actually loaded */ 458 459 if (!AcpiTbIsTableLoaded (i)) 460 { 461 Status = AE_NOT_EXIST; 462 break; 463 } 464 465 /* Invoke table handler if present */ 466 467 if (AcpiGbl_TableHandler) 468 { 469 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_UNLOAD, 470 AcpiGbl_RootTableList.Tables[i].Pointer, 471 AcpiGbl_TableHandlerContext); 472 } 473 474 /* 475 * Delete all namespace objects owned by this table. Note that 476 * these objects can appear anywhere in the namespace by virtue 477 * of the AML "Scope" operator. Thus, we need to track ownership 478 * by an ID, not simply a position within the hierarchy. 479 */ 480 Status = AcpiTbDeleteNamespaceByOwner (i); 481 if (ACPI_FAILURE (Status)) 482 { 483 break; 484 } 485 486 Status = AcpiTbReleaseOwnerId (i); 487 AcpiTbSetTableLoadedFlag (i, FALSE); 488 break; 489 } 490 491 (void) AcpiUtReleaseMutex (ACPI_MTX_INTERPRETER); 492 return_ACPI_STATUS (Status); 493 } 494 495 ACPI_EXPORT_SYMBOL (AcpiUnloadParentTable) 496