1 /****************************************************************************** 2 * 3 * Module Name: tbxfload - Table load/unload external interfaces 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2022, 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 MERCHANTABILITY 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 /* 115 * Initialize the objects in the namespace that remain uninitialized. 116 * This runs the executable AML that may be part of the declaration of 117 * these name objects: 118 * OperationRegions, BufferFields, Buffers, and Packages. 119 * 120 */ 121 Status = AcpiNsInitializeObjects (); 122 if (ACPI_SUCCESS (Status)) 123 { 124 AcpiGbl_NamespaceInitialized = TRUE; 125 } 126 127 return_ACPI_STATUS (Status); 128 } 129 130 ACPI_EXPORT_SYMBOL_INIT (AcpiLoadTables) 131 132 133 /******************************************************************************* 134 * 135 * FUNCTION: AcpiTbLoadNamespace 136 * 137 * PARAMETERS: None 138 * 139 * RETURN: Status 140 * 141 * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in 142 * the RSDT/XSDT. 143 * 144 ******************************************************************************/ 145 146 ACPI_STATUS 147 AcpiTbLoadNamespace ( 148 void) 149 { 150 ACPI_STATUS Status; 151 UINT32 i; 152 ACPI_TABLE_HEADER *NewDsdt; 153 ACPI_TABLE_DESC *Table; 154 UINT32 TablesLoaded = 0; 155 UINT32 TablesFailed = 0; 156 157 158 ACPI_FUNCTION_TRACE (TbLoadNamespace); 159 160 161 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES); 162 163 /* 164 * Load the namespace. The DSDT is required, but any SSDT and 165 * PSDT tables are optional. Verify the DSDT. 166 */ 167 Table = &AcpiGbl_RootTableList.Tables[AcpiGbl_DsdtIndex]; 168 169 if (!AcpiGbl_RootTableList.CurrentTableCount || 170 !ACPI_COMPARE_NAMESEG (Table->Signature.Ascii, ACPI_SIG_DSDT) || 171 ACPI_FAILURE (AcpiTbValidateTable (Table))) 172 { 173 Status = AE_NO_ACPI_TABLES; 174 goto UnlockAndExit; 175 } 176 177 /* 178 * Save the DSDT pointer for simple access. This is the mapped memory 179 * address. We must take care here because the address of the .Tables 180 * array can change dynamically as tables are loaded at run-time. Note: 181 * .Pointer field is not validated until after call to AcpiTbValidateTable. 182 */ 183 AcpiGbl_DSDT = Table->Pointer; 184 185 /* 186 * Optionally copy the entire DSDT to local memory (instead of simply 187 * mapping it.) There are some BIOSs that corrupt or replace the original 188 * DSDT, creating the need for this option. Default is FALSE, do not copy 189 * the DSDT. 190 */ 191 if (AcpiGbl_CopyDsdtLocally) 192 { 193 NewDsdt = AcpiTbCopyDsdt (AcpiGbl_DsdtIndex); 194 if (NewDsdt) 195 { 196 AcpiGbl_DSDT = NewDsdt; 197 } 198 } 199 200 /* 201 * Save the original DSDT header for detection of table corruption 202 * and/or replacement of the DSDT from outside the OS. 203 */ 204 memcpy (&AcpiGbl_OriginalDsdtHeader, AcpiGbl_DSDT, 205 sizeof (ACPI_TABLE_HEADER)); 206 207 /* Load and parse tables */ 208 209 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 210 Status = AcpiNsLoadTable (AcpiGbl_DsdtIndex, AcpiGbl_RootNode); 211 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES); 212 if (ACPI_FAILURE (Status)) 213 { 214 ACPI_EXCEPTION ((AE_INFO, Status, "[DSDT] table load failed")); 215 TablesFailed++; 216 } 217 else 218 { 219 TablesLoaded++; 220 } 221 222 /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */ 223 224 for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i) 225 { 226 Table = &AcpiGbl_RootTableList.Tables[i]; 227 228 if (!Table->Address || 229 (!ACPI_COMPARE_NAMESEG (Table->Signature.Ascii, ACPI_SIG_SSDT) && 230 !ACPI_COMPARE_NAMESEG (Table->Signature.Ascii, ACPI_SIG_PSDT) && 231 !ACPI_COMPARE_NAMESEG (Table->Signature.Ascii, ACPI_SIG_OSDT)) || 232 ACPI_FAILURE (AcpiTbValidateTable (Table))) 233 { 234 continue; 235 } 236 237 /* Ignore errors while loading tables, get as many as possible */ 238 239 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 240 Status = AcpiNsLoadTable (i, AcpiGbl_RootNode); 241 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES); 242 if (ACPI_FAILURE (Status)) 243 { 244 ACPI_EXCEPTION ((AE_INFO, Status, "(%4.4s:%8.8s) while loading table", 245 Table->Signature.Ascii, Table->Pointer->OemTableId)); 246 247 TablesFailed++; 248 249 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, 250 "Table [%4.4s:%8.8s] (id FF) - Table namespace load failed\n\n", 251 Table->Signature.Ascii, Table->Pointer->OemTableId)); 252 } 253 else 254 { 255 TablesLoaded++; 256 } 257 } 258 259 if (!TablesFailed) 260 { 261 ACPI_INFO (( 262 "%u ACPI AML tables successfully acquired and loaded", 263 TablesLoaded)); 264 } 265 else 266 { 267 ACPI_ERROR ((AE_INFO, 268 "%u table load failures, %u successful", 269 TablesFailed, TablesLoaded)); 270 271 /* Indicate at least one failure */ 272 273 Status = AE_CTRL_TERMINATE; 274 } 275 276 #ifdef ACPI_APPLICATION 277 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, "\n")); 278 #endif 279 280 281 UnlockAndExit: 282 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 283 return_ACPI_STATUS (Status); 284 } 285 286 287 /******************************************************************************* 288 * 289 * FUNCTION: AcpiInstallTable 290 * 291 * PARAMETERS: Table - Pointer to the ACPI table to be installed. 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_TABLE_HEADER *Table) 304 { 305 ACPI_STATUS Status; 306 UINT32 TableIndex; 307 308 309 ACPI_FUNCTION_TRACE (AcpiInstallTable); 310 311 312 Status = AcpiTbInstallStandardTable (ACPI_PTR_TO_PHYSADDR (Table), 313 ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL, Table, FALSE, FALSE, &TableIndex); 314 315 return_ACPI_STATUS (Status); 316 } 317 318 ACPI_EXPORT_SYMBOL_INIT (AcpiInstallTable) 319 320 321 /******************************************************************************* 322 * 323 * FUNCTION: AcpiInstallPhysicalTable 324 * 325 * PARAMETERS: Address - Address of the ACPI table to be installed. 326 * 327 * RETURN: Status 328 * 329 * DESCRIPTION: Dynamically install an ACPI table. 330 * Note: This function should only be invoked after 331 * AcpiInitializeTables() and before AcpiLoadTables(). 332 * 333 ******************************************************************************/ 334 335 ACPI_STATUS ACPI_INIT_FUNCTION 336 AcpiInstallPhysicalTable ( 337 ACPI_PHYSICAL_ADDRESS Address) 338 { 339 ACPI_STATUS Status; 340 UINT32 TableIndex; 341 342 343 ACPI_FUNCTION_TRACE (AcpiInstallPhysicalTable); 344 345 346 Status = AcpiTbInstallStandardTable (Address, 347 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL, NULL, FALSE, FALSE, &TableIndex); 348 349 return_ACPI_STATUS (Status); 350 } 351 352 ACPI_EXPORT_SYMBOL_INIT (AcpiInstallPhysicalTable) 353 354 355 /******************************************************************************* 356 * 357 * FUNCTION: AcpiLoadTable 358 * 359 * PARAMETERS: Table - Pointer to a buffer containing the ACPI 360 * table to be loaded. 361 * TableIdx - Pointer to a UINT32 for storing the table 362 * index, might be NULL 363 * 364 * RETURN: Status 365 * 366 * DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must 367 * be a valid ACPI table with a valid ACPI table header. 368 * Note1: Mainly intended to support hotplug addition of SSDTs. 369 * Note2: Does not copy the incoming table. User is responsible 370 * to ensure that the table is not deleted or unmapped. 371 * 372 ******************************************************************************/ 373 374 ACPI_STATUS 375 AcpiLoadTable ( 376 ACPI_TABLE_HEADER *Table, 377 UINT32 *TableIdx) 378 { 379 ACPI_STATUS Status; 380 UINT32 TableIndex; 381 382 383 ACPI_FUNCTION_TRACE (AcpiLoadTable); 384 385 386 /* Parameter validation */ 387 388 if (!Table) 389 { 390 return_ACPI_STATUS (AE_BAD_PARAMETER); 391 } 392 393 /* Install the table and load it into the namespace */ 394 395 ACPI_INFO (("Host-directed Dynamic ACPI Table Load:")); 396 Status = AcpiTbInstallAndLoadTable (ACPI_PTR_TO_PHYSADDR (Table), 397 ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL, Table, FALSE, &TableIndex); 398 if (TableIdx) 399 { 400 *TableIdx = TableIndex; 401 } 402 403 if (ACPI_SUCCESS (Status)) 404 { 405 /* Complete the initialization/resolution of new objects */ 406 407 AcpiNsInitializeObjects (); 408 } 409 410 return_ACPI_STATUS (Status); 411 } 412 413 ACPI_EXPORT_SYMBOL (AcpiLoadTable) 414 415 416 /******************************************************************************* 417 * 418 * FUNCTION: AcpiUnloadParentTable 419 * 420 * PARAMETERS: Object - Handle to any namespace object owned by 421 * the table to be unloaded 422 * 423 * RETURN: Status 424 * 425 * DESCRIPTION: Via any namespace object within an SSDT or OEMx table, unloads 426 * the table and deletes all namespace objects associated with 427 * that table. Unloading of the DSDT is not allowed. 428 * Note: Mainly intended to support hotplug removal of SSDTs. 429 * 430 ******************************************************************************/ 431 432 ACPI_STATUS 433 AcpiUnloadParentTable ( 434 ACPI_HANDLE Object) 435 { 436 ACPI_NAMESPACE_NODE *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Object); 437 ACPI_STATUS Status = AE_NOT_EXIST; 438 ACPI_OWNER_ID OwnerId; 439 UINT32 i; 440 441 442 ACPI_FUNCTION_TRACE (AcpiUnloadParentTable); 443 444 445 /* Parameter validation */ 446 447 if (!Object) 448 { 449 return_ACPI_STATUS (AE_BAD_PARAMETER); 450 } 451 452 /* 453 * The node OwnerId is currently the same as the parent table ID. 454 * However, this could change in the future. 455 */ 456 OwnerId = Node->OwnerId; 457 if (!OwnerId) 458 { 459 /* OwnerId==0 means DSDT is the owner. DSDT cannot be unloaded */ 460 461 return_ACPI_STATUS (AE_TYPE); 462 } 463 464 /* Must acquire the table lock during this operation */ 465 466 Status = AcpiUtAcquireMutex (ACPI_MTX_TABLES); 467 if (ACPI_FAILURE (Status)) 468 { 469 return_ACPI_STATUS (Status); 470 } 471 472 /* Find the table in the global table list */ 473 474 for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++) 475 { 476 if (OwnerId != AcpiGbl_RootTableList.Tables[i].OwnerId) 477 { 478 continue; 479 } 480 481 /* 482 * Allow unload of SSDT and OEMx tables only. Do not allow unload 483 * of the DSDT. No other types of tables should get here, since 484 * only these types can contain AML and thus are the only types 485 * that can create namespace objects. 486 */ 487 if (ACPI_COMPARE_NAMESEG ( 488 AcpiGbl_RootTableList.Tables[i].Signature.Ascii, 489 ACPI_SIG_DSDT)) 490 { 491 Status = AE_TYPE; 492 break; 493 } 494 495 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 496 Status = AcpiTbUnloadTable (i); 497 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES); 498 break; 499 } 500 501 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 502 return_ACPI_STATUS (Status); 503 } 504 505 ACPI_EXPORT_SYMBOL (AcpiUnloadParentTable) 506 507 508 /******************************************************************************* 509 * 510 * FUNCTION: AcpiUnloadTable 511 * 512 * PARAMETERS: TableIndex - Index as returned by AcpiLoadTable 513 * 514 * RETURN: Status 515 * 516 * DESCRIPTION: Via the TableIndex representing an SSDT or OEMx table, unloads 517 * the table and deletes all namespace objects associated with 518 * that table. Unloading of the DSDT is not allowed. 519 * Note: Mainly intended to support hotplug removal of SSDTs. 520 * 521 ******************************************************************************/ 522 523 ACPI_STATUS 524 AcpiUnloadTable ( 525 UINT32 TableIndex) 526 { 527 ACPI_STATUS Status; 528 529 530 ACPI_FUNCTION_TRACE (AcpiUnloadTable); 531 532 533 if (TableIndex == 1) 534 { 535 /* TableIndex==1 means DSDT is the owner. DSDT cannot be unloaded */ 536 537 return_ACPI_STATUS (AE_TYPE); 538 } 539 540 Status = AcpiTbUnloadTable (TableIndex); 541 return_ACPI_STATUS (Status); 542 } 543 544 ACPI_EXPORT_SYMBOL (AcpiUnloadTable) 545