tbinstal.c revision 91116
1/****************************************************************************** 2 * 3 * Module Name: tbinstal - ACPI table installation and removal 4 * $Revision: 55 $ 5 * 6 *****************************************************************************/ 7 8/****************************************************************************** 9 * 10 * 1. Copyright Notice 11 * 12 * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp. 13 * All rights reserved. 14 * 15 * 2. License 16 * 17 * 2.1. This is your license from Intel Corp. under its intellectual property 18 * rights. You may have additional license terms from the party that provided 19 * you this software, covering your right to use that party's intellectual 20 * property rights. 21 * 22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 23 * copy of the source code appearing in this file ("Covered Code") an 24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 25 * base code distributed originally by Intel ("Original Intel Code") to copy, 26 * make derivatives, distribute, use and display any portion of the Covered 27 * Code in any form, with the right to sublicense such rights; and 28 * 29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 30 * license (with the right to sublicense), under only those claims of Intel 31 * patents that are infringed by the Original Intel Code, to make, use, sell, 32 * offer to sell, and import the Covered Code and derivative works thereof 33 * solely to the minimum extent necessary to exercise the above copyright 34 * license, and in no event shall the patent license extend to any additions 35 * to or modifications of the Original Intel Code. No other license or right 36 * is granted directly or by implication, estoppel or otherwise; 37 * 38 * The above copyright and patent license is granted only if the following 39 * conditions are met: 40 * 41 * 3. Conditions 42 * 43 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 44 * Redistribution of source code of any substantial portion of the Covered 45 * Code or modification with rights to further distribute source must include 46 * the above Copyright Notice, the above License, this list of Conditions, 47 * and the following Disclaimer and Export Compliance provision. In addition, 48 * Licensee must cause all Covered Code to which Licensee contributes to 49 * contain a file documenting the changes Licensee made to create that Covered 50 * Code and the date of any change. Licensee must include in that file the 51 * documentation of any changes made by any predecessor Licensee. Licensee 52 * must include a prominent statement that the modification is derived, 53 * directly or indirectly, from Original Intel Code. 54 * 55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 56 * Redistribution of source code of any substantial portion of the Covered 57 * Code or modification without rights to further distribute source must 58 * include the following Disclaimer and Export Compliance provision in the 59 * documentation and/or other materials provided with distribution. In 60 * addition, Licensee may not authorize further sublicense of source of any 61 * portion of the Covered Code, and must include terms to the effect that the 62 * license from Licensee to its licensee is limited to the intellectual 63 * property embodied in the software Licensee provides to its licensee, and 64 * not to intellectual property embodied in modifications its licensee may 65 * make. 66 * 67 * 3.3. Redistribution of Executable. Redistribution in executable form of any 68 * substantial portion of the Covered Code or modification must reproduce the 69 * above Copyright Notice, and the following Disclaimer and Export Compliance 70 * provision in the documentation and/or other materials provided with the 71 * distribution. 72 * 73 * 3.4. Intel retains all right, title, and interest in and to the Original 74 * Intel Code. 75 * 76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 77 * Intel shall be used in advertising or otherwise to promote the sale, use or 78 * other dealings in products derived from or relating to the Covered Code 79 * without prior written authorization from Intel. 80 * 81 * 4. Disclaimer and Export Compliance 82 * 83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 89 * PARTICULAR PURPOSE. 90 * 91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 98 * LIMITED REMEDY. 99 * 100 * 4.3. Licensee shall not export, either directly or indirectly, any of this 101 * software or system incorporating such software without first obtaining any 102 * required license or other approval from the U. S. Department of Commerce or 103 * any other agency or department of the United States Government. In the 104 * event Licensee exports any such software from the United States or 105 * re-exports any such software from a foreign destination, Licensee shall 106 * ensure that the distribution and export/re-export of the software is in 107 * compliance with all laws, regulations, orders, or other restrictions of the 108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 109 * any of its subsidiaries will export/re-export any technical data, process, 110 * software, or service, directly or indirectly, to any country for which the 111 * United States government or any agency thereof requires an export license, 112 * other governmental approval, or letter of assurance, without first obtaining 113 * such license, approval or letter. 114 * 115 *****************************************************************************/ 116 117 118#define __TBINSTAL_C__ 119 120#include "acpi.h" 121#include "actables.h" 122 123 124#define _COMPONENT ACPI_TABLES 125 ACPI_MODULE_NAME ("tbinstal") 126 127 128/******************************************************************************* 129 * 130 * FUNCTION: AcpiTbMatchSignature 131 * 132 * PARAMETERS: Signature - Table signature to match 133 * TableInfo - Return data 134 * 135 * RETURN: Status 136 * 137 * DESCRIPTION: Compare signature against the list of "ACPI-subsystem-owned" 138 * tables (DSDT/FADT/SSDT, etc.) Returns the TableTypeID on match. 139 * 140 ******************************************************************************/ 141 142ACPI_STATUS 143AcpiTbMatchSignature ( 144 NATIVE_CHAR *Signature, 145 ACPI_TABLE_DESC *TableInfo) 146{ 147 NATIVE_UINT i; 148 149 150 ACPI_FUNCTION_TRACE ("TbMatchSignature"); 151 152 153 /* 154 * Search for a signature match among the known table types 155 */ 156 for (i = 0; i < NUM_ACPI_TABLES; i++) 157 { 158 if (!ACPI_STRNCMP (Signature, AcpiGbl_AcpiTableData[i].Signature, 159 AcpiGbl_AcpiTableData[i].SigLength)) 160 { 161 /* Found a signature match, return index if requested */ 162 163 if (TableInfo) 164 { 165 TableInfo->Type = (UINT8) i; 166 } 167 168 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ACPI Signature match %4.4s\n", 169 (char *) AcpiGbl_AcpiTableData[i].Signature)); 170 171 return_ACPI_STATUS (AE_OK); 172 } 173 } 174 175 return_ACPI_STATUS (AE_TABLE_NOT_SUPPORTED); 176} 177 178 179/******************************************************************************* 180 * 181 * FUNCTION: AcpiTbInstallTable 182 * 183 * PARAMETERS: TablePtr - Input buffer pointer, optional 184 * TableInfo - Return value from AcpiTbGetTable 185 * 186 * RETURN: Status 187 * 188 * DESCRIPTION: Load and validate all tables other than the RSDT. The RSDT must 189 * already be loaded and validated. 190 * Install the table into the global data structs. 191 * 192 ******************************************************************************/ 193 194ACPI_STATUS 195AcpiTbInstallTable ( 196 ACPI_TABLE_HEADER *TablePtr, 197 ACPI_TABLE_DESC *TableInfo) 198{ 199 ACPI_STATUS Status; 200 201 ACPI_FUNCTION_TRACE ("TbInstallTable"); 202 203 204 /* 205 * Check the table signature and make sure it is recognized 206 * Also checks the header checksum 207 */ 208 Status = AcpiTbRecognizeTable (TablePtr, TableInfo); 209 if (ACPI_FAILURE (Status)) 210 { 211 return_ACPI_STATUS (Status); 212 } 213 214 /* Lock tables while installing */ 215 216 Status = AcpiUtAcquireMutex (ACPI_MTX_TABLES); 217 if (ACPI_FAILURE (Status)) 218 { 219 return_ACPI_STATUS (Status); 220 } 221 222 /* Install the table into the global data structure */ 223 224 Status = AcpiTbInitTableDescriptor (TableInfo->Type, TableInfo); 225 226 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "%s located at %p\n", 227 AcpiGbl_AcpiTableData[TableInfo->Type].Name, TableInfo->Pointer)); 228 229 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 230 return_ACPI_STATUS (Status); 231} 232 233 234/******************************************************************************* 235 * 236 * FUNCTION: AcpiTbRecognizeTable 237 * 238 * PARAMETERS: TablePtr - Input buffer pointer, optional 239 * TableInfo - Return value from AcpiTbGetTable 240 * 241 * RETURN: Status 242 * 243 * DESCRIPTION: Check a table signature for a match against known table types 244 * 245 * NOTE: All table pointers are validated as follows: 246 * 1) Table pointer must point to valid physical memory 247 * 2) Signature must be 4 ASCII chars, even if we don't recognize the 248 * name 249 * 3) Table must be readable for length specified in the header 250 * 4) Table checksum must be valid (with the exception of the FACS 251 * which has no checksum for some odd reason) 252 * 253 ******************************************************************************/ 254 255ACPI_STATUS 256AcpiTbRecognizeTable ( 257 ACPI_TABLE_HEADER *TablePtr, 258 ACPI_TABLE_DESC *TableInfo) 259{ 260 ACPI_TABLE_HEADER *TableHeader; 261 ACPI_STATUS Status; 262 263 264 ACPI_FUNCTION_TRACE ("TbRecognizeTable"); 265 266 267 /* Ensure that we have a valid table pointer */ 268 269 TableHeader = (ACPI_TABLE_HEADER *) TableInfo->Pointer; 270 if (!TableHeader) 271 { 272 return_ACPI_STATUS (AE_BAD_PARAMETER); 273 } 274 275 /* 276 * We only "recognize" a limited number of ACPI tables -- namely, the 277 * ones that are used by the subsystem (DSDT, FADT, etc.) 278 * 279 * An AE_NOT_FOUND means that the table was not recognized. 280 * This can be any one of many valid ACPI tables, it just isn't one of 281 * the tables that is consumed by the core subsystem 282 */ 283 Status = AcpiTbMatchSignature (TableHeader->Signature, TableInfo); 284 if (ACPI_SUCCESS (Status)) 285 { 286 /* Return the table type and length via the info struct */ 287 288 TableInfo->Length = TableHeader->Length; 289 290 /* 291 * Validate checksum for _most_ tables, 292 * even the ones whose signature we don't recognize 293 */ 294 if (TableInfo->Type != ACPI_TABLE_FACS) 295 { 296 Status = AcpiTbVerifyTableChecksum (TableHeader); 297 if (ACPI_FAILURE (Status) && 298 (!ACPI_CHECKSUM_ABORT)) 299 { 300 /* Ignore the error if configuration says so */ 301 302 Status = AE_OK; 303 } 304 } 305 } 306 307 return_ACPI_STATUS (Status); 308} 309 310 311/******************************************************************************* 312 * 313 * FUNCTION: AcpiTbInitTableDescriptor 314 * 315 * PARAMETERS: TableType - The type of the table 316 * TableInfo - A table info struct 317 * 318 * RETURN: None. 319 * 320 * DESCRIPTION: Install a table into the global data structs. 321 * 322 ******************************************************************************/ 323 324ACPI_STATUS 325AcpiTbInitTableDescriptor ( 326 ACPI_TABLE_TYPE TableType, 327 ACPI_TABLE_DESC *TableInfo) 328{ 329 ACPI_TABLE_DESC *ListHead; 330 ACPI_TABLE_DESC *TableDesc; 331 332 333 ACPI_FUNCTION_TRACE_U32 ("TbInitTableDescriptor", TableType); 334 335 /* 336 * Install the table into the global data structure 337 */ 338 ListHead = &AcpiGbl_AcpiTables[TableType]; 339 TableDesc = ListHead; 340 341 /* 342 * Two major types of tables: 1) Only one instance is allowed. This 343 * includes most ACPI tables such as the DSDT. 2) Multiple instances of 344 * the table are allowed. This includes SSDT and PSDTs. 345 */ 346 if (ACPI_IS_SINGLE_TABLE (AcpiGbl_AcpiTableData[TableType].Flags)) 347 { 348 /* 349 * Only one table allowed, and a table has alread been installed 350 * at this location, so return an error. 351 */ 352 if (ListHead->Pointer) 353 { 354 return_ACPI_STATUS (AE_ALREADY_EXISTS); 355 } 356 357 TableDesc->Count = 1; 358 TableDesc->Prev = NULL; 359 TableDesc->Next = NULL; 360 } 361 else 362 { 363 /* 364 * Multiple tables allowed for this table type, we must link 365 * the new table in to the list of tables of this type. 366 */ 367 if (ListHead->Pointer) 368 { 369 TableDesc = ACPI_MEM_CALLOCATE (sizeof (ACPI_TABLE_DESC)); 370 if (!TableDesc) 371 { 372 return_ACPI_STATUS (AE_NO_MEMORY); 373 } 374 375 ListHead->Count++; 376 377 /* Update the original previous */ 378 379 ListHead->Prev->Next = TableDesc; 380 381 /* Update new entry */ 382 383 TableDesc->Prev = ListHead->Prev; 384 TableDesc->Next = ListHead; 385 386 /* Update list head */ 387 388 ListHead->Prev = TableDesc; 389 } 390 else 391 { 392 TableDesc->Count = 1; 393 } 394 } 395 396 /* Common initialization of the table descriptor */ 397 398 TableDesc->Type = TableInfo->Type; 399 TableDesc->Pointer = TableInfo->Pointer; 400 TableDesc->BasePointer = TableInfo->BasePointer; 401 TableDesc->Length = TableInfo->Length; 402 TableDesc->Allocation = TableInfo->Allocation; 403 TableDesc->AmlStart = (UINT8 *) (TableDesc->Pointer + 1), 404 TableDesc->AmlLength = (UINT32) (TableDesc->Length - 405 (UINT32) sizeof (ACPI_TABLE_HEADER)); 406 TableDesc->TableId = AcpiUtAllocateOwnerId (ACPI_OWNER_TYPE_TABLE); 407 TableDesc->LoadedIntoNamespace = FALSE; 408 409 /* 410 * Set the appropriate global pointer (if there is one) to point to the 411 * newly installed table 412 */ 413 if (AcpiGbl_AcpiTableData[TableType].GlobalPtr) 414 { 415 *(AcpiGbl_AcpiTableData[TableType].GlobalPtr) = TableInfo->Pointer; 416 } 417 418 /* Return Data */ 419 420 TableInfo->TableId = TableDesc->TableId; 421 TableInfo->InstalledDesc = TableDesc; 422 423 return_ACPI_STATUS (AE_OK); 424} 425 426 427/******************************************************************************* 428 * 429 * FUNCTION: AcpiTbDeleteAcpiTables 430 * 431 * PARAMETERS: None. 432 * 433 * RETURN: None. 434 * 435 * DESCRIPTION: Delete all internal ACPI tables 436 * 437 ******************************************************************************/ 438 439void 440AcpiTbDeleteAcpiTables (void) 441{ 442 ACPI_TABLE_TYPE Type; 443 444 445 /* 446 * Free memory allocated for ACPI tables 447 * Memory can either be mapped or allocated 448 */ 449 for (Type = 0; Type < NUM_ACPI_TABLES; Type++) 450 { 451 AcpiTbDeleteAcpiTable (Type); 452 } 453} 454 455 456/******************************************************************************* 457 * 458 * FUNCTION: AcpiTbDeleteAcpiTable 459 * 460 * PARAMETERS: Type - The table type to be deleted 461 * 462 * RETURN: None. 463 * 464 * DESCRIPTION: Delete an internal ACPI table 465 * Locks the ACPI table mutex 466 * 467 ******************************************************************************/ 468 469void 470AcpiTbDeleteAcpiTable ( 471 ACPI_TABLE_TYPE Type) 472{ 473 474 ACPI_FUNCTION_TRACE_U32 ("TbDeleteAcpiTable", Type); 475 476 477 if (Type > ACPI_TABLE_MAX) 478 { 479 return_VOID; 480 } 481 482 if (ACPI_FAILURE (AcpiUtAcquireMutex (ACPI_MTX_TABLES))) 483 { 484 return; 485 } 486 487 /* Free the table */ 488 489 AcpiTbFreeAcpiTablesOfType (&AcpiGbl_AcpiTables[Type]); 490 491 /* Clear the appropriate "typed" global table pointer */ 492 493 switch (Type) 494 { 495 case ACPI_TABLE_RSDP: 496 AcpiGbl_RSDP = NULL; 497 break; 498 499 case ACPI_TABLE_DSDT: 500 AcpiGbl_DSDT = NULL; 501 break; 502 503 case ACPI_TABLE_FADT: 504 AcpiGbl_FADT = NULL; 505 break; 506 507 case ACPI_TABLE_FACS: 508 AcpiGbl_FACS = NULL; 509 break; 510 511 case ACPI_TABLE_XSDT: 512 AcpiGbl_XSDT = NULL; 513 break; 514 515 case ACPI_TABLE_SSDT: 516 case ACPI_TABLE_PSDT: 517 default: 518 break; 519 } 520 521 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 522 return_VOID; 523} 524 525 526/******************************************************************************* 527 * 528 * FUNCTION: AcpiTbFreeAcpiTablesOfType 529 * 530 * PARAMETERS: TableInfo - A table info struct 531 * 532 * RETURN: None. 533 * 534 * DESCRIPTION: Free the memory associated with an internal ACPI table 535 * Table mutex should be locked. 536 * 537 ******************************************************************************/ 538 539void 540AcpiTbFreeAcpiTablesOfType ( 541 ACPI_TABLE_DESC *ListHead) 542{ 543 ACPI_TABLE_DESC *TableDesc; 544 UINT32 Count; 545 UINT32 i; 546 547 548 ACPI_FUNCTION_TRACE_PTR ("TbFreeAcpiTablesOfType", ListHead); 549 550 551 /* Get the head of the list */ 552 553 TableDesc = ListHead; 554 Count = ListHead->Count; 555 556 /* 557 * Walk the entire list, deleting both the allocated tables 558 * and the table descriptors 559 */ 560 for (i = 0; i < Count; i++) 561 { 562 TableDesc = AcpiTbUninstallTable (TableDesc); 563 } 564 565 return_VOID; 566} 567 568 569/******************************************************************************* 570 * 571 * FUNCTION: AcpiTbDeleteSingleTable 572 * 573 * PARAMETERS: TableInfo - A table info struct 574 * 575 * RETURN: None. 576 * 577 * DESCRIPTION: Low-level free for a single ACPI table. Handles cases where 578 * the table was allocated a buffer or was mapped. 579 * 580 ******************************************************************************/ 581 582void 583AcpiTbDeleteSingleTable ( 584 ACPI_TABLE_DESC *TableDesc) 585{ 586 587 if (!TableDesc) 588 { 589 return; 590 } 591 592 if (TableDesc->Pointer) 593 { 594 /* Valid table, determine type of memory allocation */ 595 596 switch (TableDesc->Allocation) 597 { 598 case ACPI_MEM_NOT_ALLOCATED: 599 break; 600 601 case ACPI_MEM_ALLOCATED: 602 603 ACPI_MEM_FREE (TableDesc->BasePointer); 604 break; 605 606 case ACPI_MEM_MAPPED: 607 608 AcpiOsUnmapMemory (TableDesc->BasePointer, TableDesc->Length); 609 break; 610 } 611 } 612} 613 614 615/******************************************************************************* 616 * 617 * FUNCTION: AcpiTbUninstallTable 618 * 619 * PARAMETERS: TableInfo - A table info struct 620 * 621 * RETURN: None. 622 * 623 * DESCRIPTION: Free the memory associated with an internal ACPI table that 624 * is either installed or has never been installed. 625 * Table mutex should be locked. 626 * 627 ******************************************************************************/ 628 629ACPI_TABLE_DESC * 630AcpiTbUninstallTable ( 631 ACPI_TABLE_DESC *TableDesc) 632{ 633 ACPI_TABLE_DESC *NextDesc; 634 635 636 ACPI_FUNCTION_TRACE_PTR ("TbDeleteSingleTable", TableDesc); 637 638 639 if (!TableDesc) 640 { 641 return_PTR (NULL); 642 } 643 644 /* Unlink the descriptor */ 645 646 if (TableDesc->Prev) 647 { 648 TableDesc->Prev->Next = TableDesc->Next; 649 } 650 651 if (TableDesc->Next) 652 { 653 TableDesc->Next->Prev = TableDesc->Prev; 654 } 655 656 /* Free the memory allocated for the table itself */ 657 658 AcpiTbDeleteSingleTable (TableDesc); 659 660 /* Free the table descriptor (Don't delete the list head, tho) */ 661 662 if ((TableDesc->Prev) == (TableDesc->Next)) 663 { 664 NextDesc = NULL; 665 666 /* Clear the list head */ 667 668 TableDesc->Pointer = NULL; 669 TableDesc->Length = 0; 670 TableDesc->Count = 0; 671 } 672 else 673 { 674 /* Free the table descriptor */ 675 676 NextDesc = TableDesc->Next; 677 ACPI_MEM_FREE (TableDesc); 678 } 679 680 return_PTR (NextDesc); 681} 682 683 684