1 /****************************************************************************** 2 * 3 * Module Name: tbdata - Table manager data structure functions 4 * 5 *****************************************************************************/ 6 7 /****************************************************************************** 8 * 9 * 1. Copyright Notice 10 * 11 * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp. 12 * All rights reserved. 13 * 14 * 2. License 15 * 16 * 2.1. This is your license from Intel Corp. under its intellectual property 17 * rights. You may have additional license terms from the party that provided 18 * you this software, covering your right to use that party's intellectual 19 * property rights. 20 * 21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22 * copy of the source code appearing in this file ("Covered Code") an 23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24 * base code distributed originally by Intel ("Original Intel Code") to copy, 25 * make derivatives, distribute, use and display any portion of the Covered 26 * Code in any form, with the right to sublicense such rights; and 27 * 28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29 * license (with the right to sublicense), under only those claims of Intel 30 * patents that are infringed by the Original Intel Code, to make, use, sell, 31 * offer to sell, and import the Covered Code and derivative works thereof 32 * solely to the minimum extent necessary to exercise the above copyright 33 * license, and in no event shall the patent license extend to any additions 34 * to or modifications of the Original Intel Code. No other license or right 35 * is granted directly or by implication, estoppel or otherwise; 36 * 37 * The above copyright and patent license is granted only if the following 38 * conditions are met: 39 * 40 * 3. Conditions 41 * 42 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43 * Redistribution of source code of any substantial portion of the Covered 44 * Code or modification with rights to further distribute source must include 45 * the above Copyright Notice, the above License, this list of Conditions, 46 * and the following Disclaimer and Export Compliance provision. In addition, 47 * Licensee must cause all Covered Code to which Licensee contributes to 48 * contain a file documenting the changes Licensee made to create that Covered 49 * Code and the date of any change. Licensee must include in that file the 50 * documentation of any changes made by any predecessor Licensee. Licensee 51 * must include a prominent statement that the modification is derived, 52 * directly or indirectly, from Original Intel Code. 53 * 54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55 * Redistribution of source code of any substantial portion of the Covered 56 * Code or modification without rights to further distribute source must 57 * include the following Disclaimer and Export Compliance provision in the 58 * documentation and/or other materials provided with distribution. In 59 * addition, Licensee may not authorize further sublicense of source of any 60 * portion of the Covered Code, and must include terms to the effect that the 61 * license from Licensee to its licensee is limited to the intellectual 62 * property embodied in the software Licensee provides to its licensee, and 63 * not to intellectual property embodied in modifications its licensee may 64 * make. 65 * 66 * 3.3. Redistribution of Executable. Redistribution in executable form of any 67 * substantial portion of the Covered Code or modification must reproduce the 68 * above Copyright Notice, and the following Disclaimer and Export Compliance 69 * provision in the documentation and/or other materials provided with the 70 * distribution. 71 * 72 * 3.4. Intel retains all right, title, and interest in and to the Original 73 * Intel Code. 74 * 75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76 * Intel shall be used in advertising or otherwise to promote the sale, use or 77 * other dealings in products derived from or relating to the Covered Code 78 * without prior written authorization from Intel. 79 * 80 * 4. Disclaimer and Export Compliance 81 * 82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88 * PARTICULAR PURPOSE. 89 * 90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97 * LIMITED REMEDY. 98 * 99 * 4.3. Licensee shall not export, either directly or indirectly, any of this 100 * software or system incorporating such software without first obtaining any 101 * required license or other approval from the U. S. Department of Commerce or 102 * any other agency or department of the United States Government. In the 103 * event Licensee exports any such software from the United States or 104 * re-exports any such software from a foreign destination, Licensee shall 105 * ensure that the distribution and export/re-export of the software is in 106 * compliance with all laws, regulations, orders, or other restrictions of the 107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108 * any of its subsidiaries will export/re-export any technical data, process, 109 * software, or service, directly or indirectly, to any country for which the 110 * United States government or any agency thereof requires an export license, 111 * other governmental approval, or letter of assurance, without first obtaining 112 * such license, approval or letter. 113 * 114 ***************************************************************************** 115 * 116 * Alternatively, you may choose to be licensed under the terms of the 117 * following license: 118 * 119 * Redistribution and use in source and binary forms, with or without 120 * modification, are permitted provided that the following conditions 121 * are met: 122 * 1. Redistributions of source code must retain the above copyright 123 * notice, this list of conditions, and the following disclaimer, 124 * without modification. 125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126 * substantially similar to the "NO WARRANTY" disclaimer below 127 * ("Disclaimer") and any redistribution must be conditioned upon 128 * including a substantially similar Disclaimer requirement for further 129 * binary redistribution. 130 * 3. Neither the names of the above-listed copyright holders nor the names 131 * of any contributors may be used to endorse or promote products derived 132 * from this software without specific prior written permission. 133 * 134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145 * 146 * Alternatively, you may choose to be licensed under the terms of the 147 * GNU General Public License ("GPL") version 2 as published by the Free 148 * Software Foundation. 149 * 150 *****************************************************************************/ 151 152 #include "acpi.h" 153 #include "accommon.h" 154 #include "acnamesp.h" 155 #include "actables.h" 156 #include "acevents.h" 157 158 #define _COMPONENT ACPI_TABLES 159 ACPI_MODULE_NAME ("tbdata") 160 161 /* Local prototypes */ 162 163 static ACPI_STATUS 164 AcpiTbCheckDuplication ( 165 ACPI_TABLE_DESC *TableDesc, 166 UINT32 *TableIndex); 167 168 static BOOLEAN 169 AcpiTbCompareTables ( 170 ACPI_TABLE_DESC *TableDesc, 171 UINT32 TableIndex); 172 173 174 /******************************************************************************* 175 * 176 * FUNCTION: AcpiTbCompareTables 177 * 178 * PARAMETERS: TableDesc - Table 1 descriptor to be compared 179 * TableIndex - Index of table 2 to be compared 180 * 181 * RETURN: TRUE if both tables are identical. 182 * 183 * DESCRIPTION: This function compares a table with another table that has 184 * already been installed in the root table list. 185 * 186 ******************************************************************************/ 187 188 static BOOLEAN 189 AcpiTbCompareTables ( 190 ACPI_TABLE_DESC *TableDesc, 191 UINT32 TableIndex) 192 { 193 ACPI_STATUS Status = AE_OK; 194 BOOLEAN IsIdentical; 195 ACPI_TABLE_HEADER *Table; 196 UINT32 TableLength; 197 UINT8 TableFlags; 198 199 200 Status = AcpiTbAcquireTable (&AcpiGbl_RootTableList.Tables[TableIndex], 201 &Table, &TableLength, &TableFlags); 202 if (ACPI_FAILURE (Status)) 203 { 204 return (FALSE); 205 } 206 207 /* 208 * Check for a table match on the entire table length, 209 * not just the header. 210 */ 211 IsIdentical = (BOOLEAN)((TableDesc->Length != TableLength || 212 memcmp (TableDesc->Pointer, Table, TableLength)) ? 213 FALSE : TRUE); 214 215 /* Release the acquired table */ 216 217 AcpiTbReleaseTable (Table, TableLength, TableFlags); 218 return (IsIdentical); 219 } 220 221 222 /******************************************************************************* 223 * 224 * FUNCTION: AcpiTbInitTableDescriptor 225 * 226 * PARAMETERS: TableDesc - Table descriptor 227 * Address - Physical address of the table 228 * Flags - Allocation flags of the table 229 * Table - Pointer to the table 230 * 231 * RETURN: None 232 * 233 * DESCRIPTION: Initialize a new table descriptor 234 * 235 ******************************************************************************/ 236 237 void 238 AcpiTbInitTableDescriptor ( 239 ACPI_TABLE_DESC *TableDesc, 240 ACPI_PHYSICAL_ADDRESS Address, 241 UINT8 Flags, 242 ACPI_TABLE_HEADER *Table) 243 { 244 245 /* 246 * Initialize the table descriptor. Set the pointer to NULL, since the 247 * table is not fully mapped at this time. 248 */ 249 memset (TableDesc, 0, sizeof (ACPI_TABLE_DESC)); 250 TableDesc->Address = Address; 251 TableDesc->Length = Table->Length; 252 TableDesc->Flags = Flags; 253 ACPI_MOVE_32_TO_32 (TableDesc->Signature.Ascii, Table->Signature); 254 } 255 256 257 /******************************************************************************* 258 * 259 * FUNCTION: AcpiTbAcquireTable 260 * 261 * PARAMETERS: TableDesc - Table descriptor 262 * TablePtr - Where table is returned 263 * TableLength - Where table length is returned 264 * TableFlags - Where table allocation flags are returned 265 * 266 * RETURN: Status 267 * 268 * DESCRIPTION: Acquire an ACPI table. It can be used for tables not 269 * maintained in the AcpiGbl_RootTableList. 270 * 271 ******************************************************************************/ 272 273 ACPI_STATUS 274 AcpiTbAcquireTable ( 275 ACPI_TABLE_DESC *TableDesc, 276 ACPI_TABLE_HEADER **TablePtr, 277 UINT32 *TableLength, 278 UINT8 *TableFlags) 279 { 280 ACPI_TABLE_HEADER *Table = NULL; 281 282 283 switch (TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK) 284 { 285 case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL: 286 287 Table = AcpiOsMapMemory (TableDesc->Address, TableDesc->Length); 288 break; 289 290 case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL: 291 case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL: 292 293 Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER, 294 ACPI_PHYSADDR_TO_PTR (TableDesc->Address)); 295 break; 296 297 default: 298 299 break; 300 } 301 302 /* Table is not valid yet */ 303 304 if (!Table) 305 { 306 return (AE_NO_MEMORY); 307 } 308 309 /* Fill the return values */ 310 311 *TablePtr = Table; 312 *TableLength = TableDesc->Length; 313 *TableFlags = TableDesc->Flags; 314 return (AE_OK); 315 } 316 317 318 /******************************************************************************* 319 * 320 * FUNCTION: AcpiTbReleaseTable 321 * 322 * PARAMETERS: Table - Pointer for the table 323 * TableLength - Length for the table 324 * TableFlags - Allocation flags for the table 325 * 326 * RETURN: None 327 * 328 * DESCRIPTION: Release a table. The inverse of AcpiTbAcquireTable(). 329 * 330 ******************************************************************************/ 331 332 void 333 AcpiTbReleaseTable ( 334 ACPI_TABLE_HEADER *Table, 335 UINT32 TableLength, 336 UINT8 TableFlags) 337 { 338 339 switch (TableFlags & ACPI_TABLE_ORIGIN_MASK) 340 { 341 case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL: 342 343 AcpiOsUnmapMemory (Table, TableLength); 344 break; 345 346 case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL: 347 case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL: 348 default: 349 350 break; 351 } 352 } 353 354 355 /******************************************************************************* 356 * 357 * FUNCTION: AcpiTbAcquireTempTable 358 * 359 * PARAMETERS: TableDesc - Table descriptor to be acquired 360 * Address - Address of the table 361 * Flags - Allocation flags of the table 362 * 363 * RETURN: Status 364 * 365 * DESCRIPTION: This function validates the table header to obtain the length 366 * of a table and fills the table descriptor to make its state as 367 * "INSTALLED". Such a table descriptor is only used for verified 368 * installation. 369 * 370 ******************************************************************************/ 371 372 ACPI_STATUS 373 AcpiTbAcquireTempTable ( 374 ACPI_TABLE_DESC *TableDesc, 375 ACPI_PHYSICAL_ADDRESS Address, 376 UINT8 Flags) 377 { 378 ACPI_TABLE_HEADER *TableHeader; 379 380 381 switch (Flags & ACPI_TABLE_ORIGIN_MASK) 382 { 383 case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL: 384 385 /* Get the length of the full table from the header */ 386 387 TableHeader = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER)); 388 if (!TableHeader) 389 { 390 return (AE_NO_MEMORY); 391 } 392 393 AcpiTbInitTableDescriptor (TableDesc, Address, Flags, TableHeader); 394 AcpiOsUnmapMemory (TableHeader, sizeof (ACPI_TABLE_HEADER)); 395 return (AE_OK); 396 397 case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL: 398 case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL: 399 400 TableHeader = ACPI_CAST_PTR (ACPI_TABLE_HEADER, 401 ACPI_PHYSADDR_TO_PTR (Address)); 402 if (!TableHeader) 403 { 404 return (AE_NO_MEMORY); 405 } 406 407 AcpiTbInitTableDescriptor (TableDesc, Address, Flags, TableHeader); 408 return (AE_OK); 409 410 default: 411 412 break; 413 } 414 415 /* Table is not valid yet */ 416 417 return (AE_NO_MEMORY); 418 } 419 420 421 /******************************************************************************* 422 * 423 * FUNCTION: AcpiTbReleaseTempTable 424 * 425 * PARAMETERS: TableDesc - Table descriptor to be released 426 * 427 * RETURN: Status 428 * 429 * DESCRIPTION: The inverse of AcpiTbAcquireTempTable(). 430 * 431 *****************************************************************************/ 432 433 void 434 AcpiTbReleaseTempTable ( 435 ACPI_TABLE_DESC *TableDesc) 436 { 437 438 /* 439 * Note that the .Address is maintained by the callers of 440 * AcpiTbAcquireTempTable(), thus do not invoke AcpiTbUninstallTable() 441 * where .Address will be freed. 442 */ 443 AcpiTbInvalidateTable (TableDesc); 444 } 445 446 447 /****************************************************************************** 448 * 449 * FUNCTION: AcpiTbValidateTable 450 * 451 * PARAMETERS: TableDesc - Table descriptor 452 * 453 * RETURN: Status 454 * 455 * DESCRIPTION: This function is called to validate the table, the returned 456 * table descriptor is in "VALIDATED" state. 457 * 458 *****************************************************************************/ 459 460 ACPI_STATUS 461 AcpiTbValidateTable ( 462 ACPI_TABLE_DESC *TableDesc) 463 { 464 ACPI_STATUS Status = AE_OK; 465 466 467 ACPI_FUNCTION_TRACE (TbValidateTable); 468 469 470 /* Validate the table if necessary */ 471 472 if (!TableDesc->Pointer) 473 { 474 Status = AcpiTbAcquireTable (TableDesc, &TableDesc->Pointer, 475 &TableDesc->Length, &TableDesc->Flags); 476 if (!TableDesc->Pointer) 477 { 478 Status = AE_NO_MEMORY; 479 } 480 } 481 482 return_ACPI_STATUS (Status); 483 } 484 485 486 /******************************************************************************* 487 * 488 * FUNCTION: AcpiTbInvalidateTable 489 * 490 * PARAMETERS: TableDesc - Table descriptor 491 * 492 * RETURN: None 493 * 494 * DESCRIPTION: Invalidate one internal ACPI table, this is the inverse of 495 * AcpiTbValidateTable(). 496 * 497 ******************************************************************************/ 498 499 void 500 AcpiTbInvalidateTable ( 501 ACPI_TABLE_DESC *TableDesc) 502 { 503 504 ACPI_FUNCTION_TRACE (TbInvalidateTable); 505 506 507 /* Table must be validated */ 508 509 if (!TableDesc->Pointer) 510 { 511 return_VOID; 512 } 513 514 AcpiTbReleaseTable (TableDesc->Pointer, TableDesc->Length, 515 TableDesc->Flags); 516 TableDesc->Pointer = NULL; 517 518 return_VOID; 519 } 520 521 522 /****************************************************************************** 523 * 524 * FUNCTION: AcpiTbValidateTempTable 525 * 526 * PARAMETERS: TableDesc - Table descriptor 527 * 528 * RETURN: Status 529 * 530 * DESCRIPTION: This function is called to validate the table, the returned 531 * table descriptor is in "VALIDATED" state. 532 * 533 *****************************************************************************/ 534 535 ACPI_STATUS 536 AcpiTbValidateTempTable ( 537 ACPI_TABLE_DESC *TableDesc) 538 { 539 540 if (!TableDesc->Pointer && !AcpiGbl_EnableTableValidation) 541 { 542 /* 543 * Only validates the header of the table. 544 * Note that Length contains the size of the mapping after invoking 545 * this work around, this value is required by 546 * AcpiTbReleaseTempTable(). 547 * We can do this because in AcpiInitTableDescriptor(), the Length 548 * field of the installed descriptor is filled with the actual 549 * table length obtaining from the table header. 550 */ 551 TableDesc->Length = sizeof (ACPI_TABLE_HEADER); 552 } 553 554 return (AcpiTbValidateTable (TableDesc)); 555 } 556 557 558 /******************************************************************************* 559 * 560 * FUNCTION: AcpiTbCheckDuplication 561 * 562 * PARAMETERS: TableDesc - Table descriptor 563 * TableIndex - Where the table index is returned 564 * 565 * RETURN: Status 566 * 567 * DESCRIPTION: Avoid installing duplicated tables. However table override and 568 * user aided dynamic table load is allowed, thus comparing the 569 * address of the table is not sufficient, and checking the entire 570 * table content is required. 571 * 572 ******************************************************************************/ 573 574 static ACPI_STATUS 575 AcpiTbCheckDuplication ( 576 ACPI_TABLE_DESC *TableDesc, 577 UINT32 *TableIndex) 578 { 579 UINT32 i; 580 581 582 ACPI_FUNCTION_TRACE (TbCheckDuplication); 583 584 585 /* Check if table is already registered */ 586 587 for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i) 588 { 589 /* Do not compare with unverified tables */ 590 591 if (!(AcpiGbl_RootTableList.Tables[i].Flags & ACPI_TABLE_IS_VERIFIED)) 592 { 593 continue; 594 } 595 596 /* 597 * Check for a table match on the entire table length, 598 * not just the header. 599 */ 600 if (!AcpiTbCompareTables (TableDesc, i)) 601 { 602 continue; 603 } 604 605 /* 606 * Note: the current mechanism does not unregister a table if it is 607 * dynamically unloaded. The related namespace entries are deleted, 608 * but the table remains in the root table list. 609 * 610 * The assumption here is that the number of different tables that 611 * will be loaded is actually small, and there is minimal overhead 612 * in just keeping the table in case it is needed again. 613 * 614 * If this assumption changes in the future (perhaps on large 615 * machines with many table load/unload operations), tables will 616 * need to be unregistered when they are unloaded, and slots in the 617 * root table list should be reused when empty. 618 */ 619 if (AcpiGbl_RootTableList.Tables[i].Flags & 620 ACPI_TABLE_IS_LOADED) 621 { 622 /* Table is still loaded, this is an error */ 623 624 return_ACPI_STATUS (AE_ALREADY_EXISTS); 625 } 626 else 627 { 628 *TableIndex = i; 629 return_ACPI_STATUS (AE_CTRL_TERMINATE); 630 } 631 } 632 633 /* Indicate no duplication to the caller */ 634 635 return_ACPI_STATUS (AE_OK); 636 } 637 638 639 /****************************************************************************** 640 * 641 * FUNCTION: AcpiTbVerifyTempTable 642 * 643 * PARAMETERS: TableDesc - Table descriptor 644 * Signature - Table signature to verify 645 * TableIndex - Where the table index is returned 646 * 647 * RETURN: Status 648 * 649 * DESCRIPTION: This function is called to validate and verify the table, the 650 * returned table descriptor is in "VALIDATED" state. 651 * 652 *****************************************************************************/ 653 654 ACPI_STATUS 655 AcpiTbVerifyTempTable ( 656 ACPI_TABLE_DESC *TableDesc, 657 char *Signature, 658 UINT32 *TableIndex) 659 { 660 ACPI_STATUS Status = AE_OK; 661 662 663 ACPI_FUNCTION_TRACE (TbVerifyTempTable); 664 665 666 /* Validate the table */ 667 668 Status = AcpiTbValidateTempTable (TableDesc); 669 if (ACPI_FAILURE (Status)) 670 { 671 return_ACPI_STATUS (AE_NO_MEMORY); 672 } 673 674 /* If a particular signature is expected (DSDT/FACS), it must match */ 675 676 if (Signature && 677 !ACPI_COMPARE_NAME (&TableDesc->Signature, Signature)) 678 { 679 ACPI_BIOS_ERROR ((AE_INFO, 680 "Invalid signature 0x%X for ACPI table, expected [%s]", 681 TableDesc->Signature.Integer, Signature)); 682 Status = AE_BAD_SIGNATURE; 683 goto InvalidateAndExit; 684 } 685 686 if (AcpiGbl_EnableTableValidation) 687 { 688 /* Verify the checksum */ 689 690 Status = AcpiTbVerifyChecksum (TableDesc->Pointer, TableDesc->Length); 691 if (ACPI_FAILURE (Status)) 692 { 693 ACPI_EXCEPTION ((AE_INFO, AE_NO_MEMORY, 694 "%4.4s 0x%8.8X%8.8X" 695 " Attempted table install failed", 696 AcpiUtValidNameseg (TableDesc->Signature.Ascii) ? 697 TableDesc->Signature.Ascii : "????", 698 ACPI_FORMAT_UINT64 (TableDesc->Address))); 699 700 goto InvalidateAndExit; 701 } 702 703 /* Avoid duplications */ 704 705 if (TableIndex) 706 { 707 Status = AcpiTbCheckDuplication (TableDesc, TableIndex); 708 if (ACPI_FAILURE (Status)) 709 { 710 if (Status != AE_CTRL_TERMINATE) 711 { 712 ACPI_EXCEPTION ((AE_INFO, AE_NO_MEMORY, 713 "%4.4s 0x%8.8X%8.8X" 714 " Table is duplicated", 715 AcpiUtValidNameseg (TableDesc->Signature.Ascii) ? 716 TableDesc->Signature.Ascii : "????", 717 ACPI_FORMAT_UINT64 (TableDesc->Address))); 718 } 719 720 goto InvalidateAndExit; 721 } 722 } 723 724 TableDesc->Flags |= ACPI_TABLE_IS_VERIFIED; 725 } 726 727 return_ACPI_STATUS (Status); 728 729 InvalidateAndExit: 730 AcpiTbInvalidateTable (TableDesc); 731 return_ACPI_STATUS (Status); 732 } 733 734 735 /******************************************************************************* 736 * 737 * FUNCTION: AcpiTbResizeRootTableList 738 * 739 * PARAMETERS: None 740 * 741 * RETURN: Status 742 * 743 * DESCRIPTION: Expand the size of global table array 744 * 745 ******************************************************************************/ 746 747 ACPI_STATUS 748 AcpiTbResizeRootTableList ( 749 void) 750 { 751 ACPI_TABLE_DESC *Tables; 752 UINT32 TableCount; 753 UINT32 CurrentTableCount, MaxTableCount; 754 UINT32 i; 755 756 757 ACPI_FUNCTION_TRACE (TbResizeRootTableList); 758 759 760 /* AllowResize flag is a parameter to AcpiInitializeTables */ 761 762 if (!(AcpiGbl_RootTableList.Flags & ACPI_ROOT_ALLOW_RESIZE)) 763 { 764 ACPI_ERROR ((AE_INFO, "Resize of Root Table Array is not allowed")); 765 return_ACPI_STATUS (AE_SUPPORT); 766 } 767 768 /* Increase the Table Array size */ 769 770 if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED) 771 { 772 TableCount = AcpiGbl_RootTableList.MaxTableCount; 773 } 774 else 775 { 776 TableCount = AcpiGbl_RootTableList.CurrentTableCount; 777 } 778 779 MaxTableCount = TableCount + ACPI_ROOT_TABLE_SIZE_INCREMENT; 780 Tables = ACPI_ALLOCATE_ZEROED ( 781 ((ACPI_SIZE) MaxTableCount) * sizeof (ACPI_TABLE_DESC)); 782 if (!Tables) 783 { 784 ACPI_ERROR ((AE_INFO, "Could not allocate new root table array")); 785 return_ACPI_STATUS (AE_NO_MEMORY); 786 } 787 788 /* Copy and free the previous table array */ 789 790 CurrentTableCount = 0; 791 if (AcpiGbl_RootTableList.Tables) 792 { 793 for (i = 0; i < TableCount; i++) 794 { 795 if (AcpiGbl_RootTableList.Tables[i].Address) 796 { 797 memcpy (Tables + CurrentTableCount, 798 AcpiGbl_RootTableList.Tables + i, 799 sizeof (ACPI_TABLE_DESC)); 800 CurrentTableCount++; 801 } 802 } 803 804 if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED) 805 { 806 ACPI_FREE (AcpiGbl_RootTableList.Tables); 807 } 808 } 809 810 AcpiGbl_RootTableList.Tables = Tables; 811 AcpiGbl_RootTableList.MaxTableCount = MaxTableCount; 812 AcpiGbl_RootTableList.CurrentTableCount = CurrentTableCount; 813 AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ORIGIN_ALLOCATED; 814 815 return_ACPI_STATUS (AE_OK); 816 } 817 818 819 /******************************************************************************* 820 * 821 * FUNCTION: AcpiTbGetNextTableDescriptor 822 * 823 * PARAMETERS: TableIndex - Where table index is returned 824 * TableDesc - Where table descriptor is returned 825 * 826 * RETURN: Status and table index/descriptor. 827 * 828 * DESCRIPTION: Allocate a new ACPI table entry to the global table list 829 * 830 ******************************************************************************/ 831 832 ACPI_STATUS 833 AcpiTbGetNextTableDescriptor ( 834 UINT32 *TableIndex, 835 ACPI_TABLE_DESC **TableDesc) 836 { 837 ACPI_STATUS Status; 838 UINT32 i; 839 840 841 /* Ensure that there is room for the table in the Root Table List */ 842 843 if (AcpiGbl_RootTableList.CurrentTableCount >= 844 AcpiGbl_RootTableList.MaxTableCount) 845 { 846 Status = AcpiTbResizeRootTableList(); 847 if (ACPI_FAILURE (Status)) 848 { 849 return (Status); 850 } 851 } 852 853 i = AcpiGbl_RootTableList.CurrentTableCount; 854 AcpiGbl_RootTableList.CurrentTableCount++; 855 856 if (TableIndex) 857 { 858 *TableIndex = i; 859 } 860 if (TableDesc) 861 { 862 *TableDesc = &AcpiGbl_RootTableList.Tables[i]; 863 } 864 865 return (AE_OK); 866 } 867 868 869 /******************************************************************************* 870 * 871 * FUNCTION: AcpiTbTerminate 872 * 873 * PARAMETERS: None 874 * 875 * RETURN: None 876 * 877 * DESCRIPTION: Delete all internal ACPI tables 878 * 879 ******************************************************************************/ 880 881 void 882 AcpiTbTerminate ( 883 void) 884 { 885 UINT32 i; 886 887 888 ACPI_FUNCTION_TRACE (TbTerminate); 889 890 891 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES); 892 893 /* Delete the individual tables */ 894 895 for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++) 896 { 897 AcpiTbUninstallTable (&AcpiGbl_RootTableList.Tables[i]); 898 } 899 900 /* 901 * Delete the root table array if allocated locally. Array cannot be 902 * mapped, so we don't need to check for that flag. 903 */ 904 if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED) 905 { 906 ACPI_FREE (AcpiGbl_RootTableList.Tables); 907 } 908 909 AcpiGbl_RootTableList.Tables = NULL; 910 AcpiGbl_RootTableList.Flags = 0; 911 AcpiGbl_RootTableList.CurrentTableCount = 0; 912 913 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ACPI Tables freed\n")); 914 915 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 916 return_VOID; 917 } 918 919 920 /******************************************************************************* 921 * 922 * FUNCTION: AcpiTbDeleteNamespaceByOwner 923 * 924 * PARAMETERS: TableIndex - Table index 925 * 926 * RETURN: Status 927 * 928 * DESCRIPTION: Delete all namespace objects created when this table was loaded. 929 * 930 ******************************************************************************/ 931 932 ACPI_STATUS 933 AcpiTbDeleteNamespaceByOwner ( 934 UINT32 TableIndex) 935 { 936 ACPI_OWNER_ID OwnerId; 937 ACPI_STATUS Status; 938 939 940 ACPI_FUNCTION_TRACE (TbDeleteNamespaceByOwner); 941 942 943 Status = AcpiUtAcquireMutex (ACPI_MTX_TABLES); 944 if (ACPI_FAILURE (Status)) 945 { 946 return_ACPI_STATUS (Status); 947 } 948 949 if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount) 950 { 951 /* The table index does not exist */ 952 953 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 954 return_ACPI_STATUS (AE_NOT_EXIST); 955 } 956 957 /* Get the owner ID for this table, used to delete namespace nodes */ 958 959 OwnerId = AcpiGbl_RootTableList.Tables[TableIndex].OwnerId; 960 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 961 962 /* 963 * Need to acquire the namespace writer lock to prevent interference 964 * with any concurrent namespace walks. The interpreter must be 965 * released during the deletion since the acquisition of the deletion 966 * lock may block, and also since the execution of a namespace walk 967 * must be allowed to use the interpreter. 968 */ 969 Status = AcpiUtAcquireWriteLock (&AcpiGbl_NamespaceRwLock); 970 if (ACPI_FAILURE (Status)) 971 { 972 return_ACPI_STATUS (Status); 973 } 974 AcpiNsDeleteNamespaceByOwner (OwnerId); 975 AcpiUtReleaseWriteLock (&AcpiGbl_NamespaceRwLock); 976 return_ACPI_STATUS (Status); 977 } 978 979 980 /******************************************************************************* 981 * 982 * FUNCTION: AcpiTbAllocateOwnerId 983 * 984 * PARAMETERS: TableIndex - Table index 985 * 986 * RETURN: Status 987 * 988 * DESCRIPTION: Allocates OwnerId in TableDesc 989 * 990 ******************************************************************************/ 991 992 ACPI_STATUS 993 AcpiTbAllocateOwnerId ( 994 UINT32 TableIndex) 995 { 996 ACPI_STATUS Status = AE_BAD_PARAMETER; 997 998 999 ACPI_FUNCTION_TRACE (TbAllocateOwnerId); 1000 1001 1002 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES); 1003 if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount) 1004 { 1005 Status = AcpiUtAllocateOwnerId ( 1006 &(AcpiGbl_RootTableList.Tables[TableIndex].OwnerId)); 1007 } 1008 1009 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 1010 return_ACPI_STATUS (Status); 1011 } 1012 1013 1014 /******************************************************************************* 1015 * 1016 * FUNCTION: AcpiTbReleaseOwnerId 1017 * 1018 * PARAMETERS: TableIndex - Table index 1019 * 1020 * RETURN: Status 1021 * 1022 * DESCRIPTION: Releases OwnerId in TableDesc 1023 * 1024 ******************************************************************************/ 1025 1026 ACPI_STATUS 1027 AcpiTbReleaseOwnerId ( 1028 UINT32 TableIndex) 1029 { 1030 ACPI_STATUS Status = AE_BAD_PARAMETER; 1031 1032 1033 ACPI_FUNCTION_TRACE (TbReleaseOwnerId); 1034 1035 1036 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES); 1037 if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount) 1038 { 1039 AcpiUtReleaseOwnerId ( 1040 &(AcpiGbl_RootTableList.Tables[TableIndex].OwnerId)); 1041 Status = AE_OK; 1042 } 1043 1044 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 1045 return_ACPI_STATUS (Status); 1046 } 1047 1048 1049 /******************************************************************************* 1050 * 1051 * FUNCTION: AcpiTbGetOwnerId 1052 * 1053 * PARAMETERS: TableIndex - Table index 1054 * OwnerId - Where the table OwnerId is returned 1055 * 1056 * RETURN: Status 1057 * 1058 * DESCRIPTION: returns OwnerId for the ACPI table 1059 * 1060 ******************************************************************************/ 1061 1062 ACPI_STATUS 1063 AcpiTbGetOwnerId ( 1064 UINT32 TableIndex, 1065 ACPI_OWNER_ID *OwnerId) 1066 { 1067 ACPI_STATUS Status = AE_BAD_PARAMETER; 1068 1069 1070 ACPI_FUNCTION_TRACE (TbGetOwnerId); 1071 1072 1073 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES); 1074 if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount) 1075 { 1076 *OwnerId = AcpiGbl_RootTableList.Tables[TableIndex].OwnerId; 1077 Status = AE_OK; 1078 } 1079 1080 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 1081 return_ACPI_STATUS (Status); 1082 } 1083 1084 1085 /******************************************************************************* 1086 * 1087 * FUNCTION: AcpiTbIsTableLoaded 1088 * 1089 * PARAMETERS: TableIndex - Index into the root table 1090 * 1091 * RETURN: Table Loaded Flag 1092 * 1093 ******************************************************************************/ 1094 1095 BOOLEAN 1096 AcpiTbIsTableLoaded ( 1097 UINT32 TableIndex) 1098 { 1099 BOOLEAN IsLoaded = FALSE; 1100 1101 1102 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES); 1103 if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount) 1104 { 1105 IsLoaded = (BOOLEAN) 1106 (AcpiGbl_RootTableList.Tables[TableIndex].Flags & 1107 ACPI_TABLE_IS_LOADED); 1108 } 1109 1110 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 1111 return (IsLoaded); 1112 } 1113 1114 1115 /******************************************************************************* 1116 * 1117 * FUNCTION: AcpiTbSetTableLoadedFlag 1118 * 1119 * PARAMETERS: TableIndex - Table index 1120 * IsLoaded - TRUE if table is loaded, FALSE otherwise 1121 * 1122 * RETURN: None 1123 * 1124 * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE. 1125 * 1126 ******************************************************************************/ 1127 1128 void 1129 AcpiTbSetTableLoadedFlag ( 1130 UINT32 TableIndex, 1131 BOOLEAN IsLoaded) 1132 { 1133 1134 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES); 1135 if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount) 1136 { 1137 if (IsLoaded) 1138 { 1139 AcpiGbl_RootTableList.Tables[TableIndex].Flags |= 1140 ACPI_TABLE_IS_LOADED; 1141 } 1142 else 1143 { 1144 AcpiGbl_RootTableList.Tables[TableIndex].Flags &= 1145 ~ACPI_TABLE_IS_LOADED; 1146 } 1147 } 1148 1149 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 1150 } 1151 1152 1153 /******************************************************************************* 1154 * 1155 * FUNCTION: AcpiTbLoadTable 1156 * 1157 * PARAMETERS: TableIndex - Table index 1158 * ParentNode - Where table index is returned 1159 * 1160 * RETURN: Status 1161 * 1162 * DESCRIPTION: Load an ACPI table 1163 * 1164 ******************************************************************************/ 1165 1166 ACPI_STATUS 1167 AcpiTbLoadTable ( 1168 UINT32 TableIndex, 1169 ACPI_NAMESPACE_NODE *ParentNode) 1170 { 1171 ACPI_TABLE_HEADER *Table; 1172 ACPI_STATUS Status; 1173 ACPI_OWNER_ID OwnerId; 1174 1175 1176 ACPI_FUNCTION_TRACE (TbLoadTable); 1177 1178 1179 /* 1180 * Note: Now table is "INSTALLED", it must be validated before 1181 * using. 1182 */ 1183 Status = AcpiGetTableByIndex (TableIndex, &Table); 1184 if (ACPI_FAILURE (Status)) 1185 { 1186 return_ACPI_STATUS (Status); 1187 } 1188 1189 Status = AcpiNsLoadTable (TableIndex, ParentNode); 1190 1191 /* Execute any module-level code that was found in the table */ 1192 1193 if (!AcpiGbl_ParseTableAsTermList && AcpiGbl_GroupModuleLevelCode) 1194 { 1195 AcpiNsExecModuleCodeList (); 1196 } 1197 1198 /* 1199 * Update GPEs for any new _Lxx/_Exx methods. Ignore errors. The host is 1200 * responsible for discovering any new wake GPEs by running _PRW methods 1201 * that may have been loaded by this table. 1202 */ 1203 Status = AcpiTbGetOwnerId (TableIndex, &OwnerId); 1204 if (ACPI_SUCCESS (Status)) 1205 { 1206 AcpiEvUpdateGpes (OwnerId); 1207 } 1208 1209 /* Invoke table handler */ 1210 1211 AcpiTbNotifyTable (ACPI_TABLE_EVENT_LOAD, Table); 1212 return_ACPI_STATUS (Status); 1213 } 1214 1215 1216 /******************************************************************************* 1217 * 1218 * FUNCTION: AcpiTbInstallAndLoadTable 1219 * 1220 * PARAMETERS: Address - Physical address of the table 1221 * Flags - Allocation flags of the table 1222 * Override - Whether override should be performed 1223 * TableIndex - Where table index is returned 1224 * 1225 * RETURN: Status 1226 * 1227 * DESCRIPTION: Install and load an ACPI table 1228 * 1229 ******************************************************************************/ 1230 1231 ACPI_STATUS 1232 AcpiTbInstallAndLoadTable ( 1233 ACPI_PHYSICAL_ADDRESS Address, 1234 UINT8 Flags, 1235 BOOLEAN Override, 1236 UINT32 *TableIndex) 1237 { 1238 ACPI_STATUS Status; 1239 UINT32 i; 1240 1241 1242 ACPI_FUNCTION_TRACE (TbInstallAndLoadTable); 1243 1244 1245 /* Install the table and load it into the namespace */ 1246 1247 Status = AcpiTbInstallStandardTable (Address, Flags, TRUE, 1248 Override, &i); 1249 if (ACPI_FAILURE (Status)) 1250 { 1251 goto Exit; 1252 } 1253 1254 Status = AcpiTbLoadTable (i, AcpiGbl_RootNode); 1255 1256 Exit: 1257 *TableIndex = i; 1258 return_ACPI_STATUS (Status); 1259 } 1260 1261 1262 /******************************************************************************* 1263 * 1264 * FUNCTION: AcpiTbUnloadTable 1265 * 1266 * PARAMETERS: TableIndex - Table index 1267 * 1268 * RETURN: Status 1269 * 1270 * DESCRIPTION: Unload an ACPI table 1271 * 1272 ******************************************************************************/ 1273 1274 ACPI_STATUS 1275 AcpiTbUnloadTable ( 1276 UINT32 TableIndex) 1277 { 1278 ACPI_STATUS Status = AE_OK; 1279 ACPI_TABLE_HEADER *Table; 1280 1281 1282 ACPI_FUNCTION_TRACE (TbUnloadTable); 1283 1284 1285 /* Ensure the table is still loaded */ 1286 1287 if (!AcpiTbIsTableLoaded (TableIndex)) 1288 { 1289 return_ACPI_STATUS (AE_NOT_EXIST); 1290 } 1291 1292 /* Invoke table handler */ 1293 1294 Status = AcpiGetTableByIndex (TableIndex, &Table); 1295 if (ACPI_SUCCESS (Status)) 1296 { 1297 AcpiTbNotifyTable (ACPI_TABLE_EVENT_UNLOAD, Table); 1298 } 1299 1300 /* Delete the portion of the namespace owned by this table */ 1301 1302 Status = AcpiTbDeleteNamespaceByOwner (TableIndex); 1303 if (ACPI_FAILURE (Status)) 1304 { 1305 return_ACPI_STATUS (Status); 1306 } 1307 1308 (void) AcpiTbReleaseOwnerId (TableIndex); 1309 AcpiTbSetTableLoadedFlag (TableIndex, FALSE); 1310 return_ACPI_STATUS (Status); 1311 } 1312 1313 1314 /******************************************************************************* 1315 * 1316 * FUNCTION: AcpiTbNotifyTable 1317 * 1318 * PARAMETERS: Event - Table event 1319 * Table - Validated table pointer 1320 * 1321 * RETURN: None 1322 * 1323 * DESCRIPTION: Notify a table event to the users. 1324 * 1325 ******************************************************************************/ 1326 1327 void 1328 AcpiTbNotifyTable ( 1329 UINT32 Event, 1330 void *Table) 1331 { 1332 /* Invoke table handler if present */ 1333 1334 if (AcpiGbl_TableHandler) 1335 { 1336 (void) AcpiGbl_TableHandler (Event, Table, 1337 AcpiGbl_TableHandlerContext); 1338 } 1339 } 1340