1 /****************************************************************************** 2 * 3 * Module Name: tbutils - table utilities 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2012, 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 __TBUTILS_C__ 45 46 #include <contrib/dev/acpica/include/acpi.h> 47 #include <contrib/dev/acpica/include/accommon.h> 48 #include <contrib/dev/acpica/include/actables.h> 49 50 #define _COMPONENT ACPI_TABLES 51 ACPI_MODULE_NAME ("tbutils") 52 53 54 /* Local prototypes */ 55 56 static void 57 AcpiTbFixString ( 58 char *String, 59 ACPI_SIZE Length); 60 61 static void 62 AcpiTbCleanupTableHeader ( 63 ACPI_TABLE_HEADER *OutHeader, 64 ACPI_TABLE_HEADER *Header); 65 66 static ACPI_PHYSICAL_ADDRESS 67 AcpiTbGetRootTableEntry ( 68 UINT8 *TableEntry, 69 UINT32 TableEntrySize); 70 71 72 #if (!ACPI_REDUCED_HARDWARE) 73 /******************************************************************************* 74 * 75 * FUNCTION: AcpiTbInitializeFacs 76 * 77 * PARAMETERS: None 78 * 79 * RETURN: Status 80 * 81 * DESCRIPTION: Create a permanent mapping for the FADT and save it in a global 82 * for accessing the Global Lock and Firmware Waking Vector 83 * 84 ******************************************************************************/ 85 86 ACPI_STATUS 87 AcpiTbInitializeFacs ( 88 void) 89 { 90 ACPI_STATUS Status; 91 92 93 /* If Hardware Reduced flag is set, there is no FACS */ 94 95 if (AcpiGbl_ReducedHardware) 96 { 97 AcpiGbl_FACS = NULL; 98 return (AE_OK); 99 } 100 101 Status = AcpiGetTableByIndex (ACPI_TABLE_INDEX_FACS, 102 ACPI_CAST_INDIRECT_PTR (ACPI_TABLE_HEADER, &AcpiGbl_FACS)); 103 return (Status); 104 } 105 #endif /* !ACPI_REDUCED_HARDWARE */ 106 107 108 /******************************************************************************* 109 * 110 * FUNCTION: AcpiTbTablesLoaded 111 * 112 * PARAMETERS: None 113 * 114 * RETURN: TRUE if required ACPI tables are loaded 115 * 116 * DESCRIPTION: Determine if the minimum required ACPI tables are present 117 * (FADT, FACS, DSDT) 118 * 119 ******************************************************************************/ 120 121 BOOLEAN 122 AcpiTbTablesLoaded ( 123 void) 124 { 125 126 if (AcpiGbl_RootTableList.CurrentTableCount >= 3) 127 { 128 return (TRUE); 129 } 130 131 return (FALSE); 132 } 133 134 135 /******************************************************************************* 136 * 137 * FUNCTION: AcpiTbFixString 138 * 139 * PARAMETERS: String - String to be repaired 140 * Length - Maximum length 141 * 142 * RETURN: None 143 * 144 * DESCRIPTION: Replace every non-printable or non-ascii byte in the string 145 * with a question mark '?'. 146 * 147 ******************************************************************************/ 148 149 static void 150 AcpiTbFixString ( 151 char *String, 152 ACPI_SIZE Length) 153 { 154 155 while (Length && *String) 156 { 157 if (!ACPI_IS_PRINT (*String)) 158 { 159 *String = '?'; 160 } 161 String++; 162 Length--; 163 } 164 } 165 166 167 /******************************************************************************* 168 * 169 * FUNCTION: AcpiTbCleanupTableHeader 170 * 171 * PARAMETERS: OutHeader - Where the cleaned header is returned 172 * Header - Input ACPI table header 173 * 174 * RETURN: Returns the cleaned header in OutHeader 175 * 176 * DESCRIPTION: Copy the table header and ensure that all "string" fields in 177 * the header consist of printable characters. 178 * 179 ******************************************************************************/ 180 181 static void 182 AcpiTbCleanupTableHeader ( 183 ACPI_TABLE_HEADER *OutHeader, 184 ACPI_TABLE_HEADER *Header) 185 { 186 187 ACPI_MEMCPY (OutHeader, Header, sizeof (ACPI_TABLE_HEADER)); 188 189 AcpiTbFixString (OutHeader->Signature, ACPI_NAME_SIZE); 190 AcpiTbFixString (OutHeader->OemId, ACPI_OEM_ID_SIZE); 191 AcpiTbFixString (OutHeader->OemTableId, ACPI_OEM_TABLE_ID_SIZE); 192 AcpiTbFixString (OutHeader->AslCompilerId, ACPI_NAME_SIZE); 193 } 194 195 196 /******************************************************************************* 197 * 198 * FUNCTION: AcpiTbPrintTableHeader 199 * 200 * PARAMETERS: Address - Table physical address 201 * Header - Table header 202 * 203 * RETURN: None 204 * 205 * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP. 206 * 207 ******************************************************************************/ 208 209 void 210 AcpiTbPrintTableHeader ( 211 ACPI_PHYSICAL_ADDRESS Address, 212 ACPI_TABLE_HEADER *Header) 213 { 214 ACPI_TABLE_HEADER LocalHeader; 215 216 217 /* 218 * The reason that the Address is cast to a void pointer is so that we 219 * can use %p which will work properly on both 32-bit and 64-bit hosts. 220 */ 221 if (ACPI_COMPARE_NAME (Header->Signature, ACPI_SIG_FACS)) 222 { 223 /* FACS only has signature and length fields */ 224 225 ACPI_INFO ((AE_INFO, "%4.4s %p %05X", 226 Header->Signature, ACPI_CAST_PTR (void, Address), 227 Header->Length)); 228 } 229 else if (ACPI_COMPARE_NAME (Header->Signature, ACPI_SIG_RSDP)) 230 { 231 /* RSDP has no common fields */ 232 233 ACPI_MEMCPY (LocalHeader.OemId, 234 ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->OemId, ACPI_OEM_ID_SIZE); 235 AcpiTbFixString (LocalHeader.OemId, ACPI_OEM_ID_SIZE); 236 237 ACPI_INFO ((AE_INFO, "RSDP %p %05X (v%.2d %6.6s)", 238 ACPI_CAST_PTR (void, Address), 239 (ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->Revision > 0) ? 240 ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->Length : 20, 241 ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->Revision, 242 LocalHeader.OemId)); 243 } 244 else 245 { 246 /* Standard ACPI table with full common header */ 247 248 AcpiTbCleanupTableHeader (&LocalHeader, Header); 249 250 ACPI_INFO ((AE_INFO, 251 "%4.4s %p %05X (v%.2d %6.6s %8.8s %08X %4.4s %08X)", 252 LocalHeader.Signature, ACPI_CAST_PTR (void, Address), 253 LocalHeader.Length, LocalHeader.Revision, LocalHeader.OemId, 254 LocalHeader.OemTableId, LocalHeader.OemRevision, 255 LocalHeader.AslCompilerId, LocalHeader.AslCompilerRevision)); 256 } 257 } 258 259 260 /******************************************************************************* 261 * 262 * FUNCTION: AcpiTbValidateChecksum 263 * 264 * PARAMETERS: Table - ACPI table to verify 265 * Length - Length of entire table 266 * 267 * RETURN: Status 268 * 269 * DESCRIPTION: Verifies that the table checksums to zero. Optionally returns 270 * exception on bad checksum. 271 * 272 ******************************************************************************/ 273 274 ACPI_STATUS 275 AcpiTbVerifyChecksum ( 276 ACPI_TABLE_HEADER *Table, 277 UINT32 Length) 278 { 279 UINT8 Checksum; 280 281 282 /* Compute the checksum on the table */ 283 284 Checksum = AcpiTbChecksum (ACPI_CAST_PTR (UINT8, Table), Length); 285 286 /* Checksum ok? (should be zero) */ 287 288 if (Checksum) 289 { 290 ACPI_WARNING ((AE_INFO, 291 "Incorrect checksum in table [%4.4s] - 0x%2.2X, should be 0x%2.2X", 292 Table->Signature, Table->Checksum, 293 (UINT8) (Table->Checksum - Checksum))); 294 295 #if (ACPI_CHECKSUM_ABORT) 296 return (AE_BAD_CHECKSUM); 297 #endif 298 } 299 300 return (AE_OK); 301 } 302 303 304 /******************************************************************************* 305 * 306 * FUNCTION: AcpiTbChecksum 307 * 308 * PARAMETERS: Buffer - Pointer to memory region to be checked 309 * Length - Length of this memory region 310 * 311 * RETURN: Checksum (UINT8) 312 * 313 * DESCRIPTION: Calculates circular checksum of memory region. 314 * 315 ******************************************************************************/ 316 317 UINT8 318 AcpiTbChecksum ( 319 UINT8 *Buffer, 320 UINT32 Length) 321 { 322 UINT8 Sum = 0; 323 UINT8 *End = Buffer + Length; 324 325 326 while (Buffer < End) 327 { 328 Sum = (UINT8) (Sum + *(Buffer++)); 329 } 330 331 return Sum; 332 } 333 334 335 /******************************************************************************* 336 * 337 * FUNCTION: AcpiTbCheckDsdtHeader 338 * 339 * PARAMETERS: None 340 * 341 * RETURN: None 342 * 343 * DESCRIPTION: Quick compare to check validity of the DSDT. This will detect 344 * if the DSDT has been replaced from outside the OS and/or if 345 * the DSDT header has been corrupted. 346 * 347 ******************************************************************************/ 348 349 void 350 AcpiTbCheckDsdtHeader ( 351 void) 352 { 353 354 /* Compare original length and checksum to current values */ 355 356 if (AcpiGbl_OriginalDsdtHeader.Length != AcpiGbl_DSDT->Length || 357 AcpiGbl_OriginalDsdtHeader.Checksum != AcpiGbl_DSDT->Checksum) 358 { 359 ACPI_ERROR ((AE_INFO, 360 "The DSDT has been corrupted or replaced - old, new headers below")); 361 AcpiTbPrintTableHeader (0, &AcpiGbl_OriginalDsdtHeader); 362 AcpiTbPrintTableHeader (0, AcpiGbl_DSDT); 363 364 /* Disable further error messages */ 365 366 AcpiGbl_OriginalDsdtHeader.Length = AcpiGbl_DSDT->Length; 367 AcpiGbl_OriginalDsdtHeader.Checksum = AcpiGbl_DSDT->Checksum; 368 } 369 } 370 371 372 /******************************************************************************* 373 * 374 * FUNCTION: AcpiTbCopyDsdt 375 * 376 * PARAMETERS: TableDesc - Installed table to copy 377 * 378 * RETURN: None 379 * 380 * DESCRIPTION: Implements a subsystem option to copy the DSDT to local memory. 381 * Some very bad BIOSs are known to either corrupt the DSDT or 382 * install a new, bad DSDT. This copy works around the problem. 383 * 384 ******************************************************************************/ 385 386 ACPI_TABLE_HEADER * 387 AcpiTbCopyDsdt ( 388 UINT32 TableIndex) 389 { 390 ACPI_TABLE_HEADER *NewTable; 391 ACPI_TABLE_DESC *TableDesc; 392 393 394 TableDesc = &AcpiGbl_RootTableList.Tables[TableIndex]; 395 396 NewTable = ACPI_ALLOCATE (TableDesc->Length); 397 if (!NewTable) 398 { 399 ACPI_ERROR ((AE_INFO, "Could not copy DSDT of length 0x%X", 400 TableDesc->Length)); 401 return (NULL); 402 } 403 404 ACPI_MEMCPY (NewTable, TableDesc->Pointer, TableDesc->Length); 405 AcpiTbDeleteTable (TableDesc); 406 TableDesc->Pointer = NewTable; 407 TableDesc->Flags = ACPI_TABLE_ORIGIN_ALLOCATED; 408 409 ACPI_INFO ((AE_INFO, 410 "Forced DSDT copy: length 0x%05X copied locally, original unmapped", 411 NewTable->Length)); 412 413 return (NewTable); 414 } 415 416 417 /******************************************************************************* 418 * 419 * FUNCTION: AcpiTbInstallTable 420 * 421 * PARAMETERS: Address - Physical address of DSDT or FACS 422 * Signature - Table signature, NULL if no need to 423 * match 424 * TableIndex - Index into root table array 425 * 426 * RETURN: None 427 * 428 * DESCRIPTION: Install an ACPI table into the global data structure. The 429 * table override mechanism is called to allow the host 430 * OS to replace any table before it is installed in the root 431 * table array. 432 * 433 ******************************************************************************/ 434 435 void 436 AcpiTbInstallTable ( 437 ACPI_PHYSICAL_ADDRESS Address, 438 char *Signature, 439 UINT32 TableIndex) 440 { 441 ACPI_TABLE_HEADER *Table; 442 ACPI_TABLE_HEADER *FinalTable; 443 ACPI_TABLE_DESC *TableDesc; 444 445 446 if (!Address) 447 { 448 ACPI_ERROR ((AE_INFO, "Null physical address for ACPI table [%s]", 449 Signature)); 450 return; 451 } 452 453 /* Map just the table header */ 454 455 Table = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER)); 456 if (!Table) 457 { 458 ACPI_ERROR ((AE_INFO, "Could not map memory for table [%s] at %p", 459 Signature, ACPI_CAST_PTR (void, Address))); 460 return; 461 } 462 463 /* Skip SSDT when DSDT is overriden */ 464 465 if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_SSDT) && 466 (AcpiGbl_RootTableList.Tables[ACPI_TABLE_INDEX_DSDT].Flags & 467 ACPI_TABLE_ORIGIN_OVERRIDE)) 468 { 469 ACPI_INFO ((AE_INFO, 470 "%4.4s @ 0x%p Table override, replaced with:", ACPI_SIG_SSDT, 471 ACPI_CAST_PTR (void, Address))); 472 AcpiTbPrintTableHeader ( 473 AcpiGbl_RootTableList.Tables[ACPI_TABLE_INDEX_DSDT].Address, 474 AcpiGbl_RootTableList.Tables[ACPI_TABLE_INDEX_DSDT].Pointer); 475 goto UnmapAndExit; 476 } 477 478 /* If a particular signature is expected (DSDT/FACS), it must match */ 479 480 if (Signature && 481 !ACPI_COMPARE_NAME (Table->Signature, Signature)) 482 { 483 ACPI_ERROR ((AE_INFO, 484 "Invalid signature 0x%X for ACPI table, expected [%s]", 485 *ACPI_CAST_PTR (UINT32, Table->Signature), Signature)); 486 goto UnmapAndExit; 487 } 488 489 /* 490 * Initialize the table entry. Set the pointer to NULL, since the 491 * table is not fully mapped at this time. 492 */ 493 TableDesc = &AcpiGbl_RootTableList.Tables[TableIndex]; 494 495 TableDesc->Address = Address; 496 TableDesc->Pointer = NULL; 497 TableDesc->Length = Table->Length; 498 TableDesc->Flags = ACPI_TABLE_ORIGIN_MAPPED; 499 ACPI_MOVE_32_TO_32 (TableDesc->Signature.Ascii, Table->Signature); 500 501 /* 502 * ACPI Table Override: 503 * 504 * Before we install the table, let the host OS override it with a new 505 * one if desired. Any table within the RSDT/XSDT can be replaced, 506 * including the DSDT which is pointed to by the FADT. 507 * 508 * NOTE: If the table is overridden, then FinalTable will contain a 509 * mapped pointer to the full new table. If the table is not overridden, 510 * then the table will be fully mapped elsewhere (in verify table). 511 * In any case, we must unmap the header that was mapped above. 512 */ 513 FinalTable = AcpiTbTableOverride (Table, TableDesc); 514 if (!FinalTable) 515 { 516 FinalTable = Table; /* There was no override */ 517 } 518 519 AcpiTbPrintTableHeader (TableDesc->Address, FinalTable); 520 521 /* Set the global integer width (based upon revision of the DSDT) */ 522 523 if (TableIndex == ACPI_TABLE_INDEX_DSDT) 524 { 525 AcpiUtSetIntegerWidth (FinalTable->Revision); 526 } 527 528 UnmapAndExit: 529 530 /* Always unmap the table header that we mapped above */ 531 532 AcpiOsUnmapMemory (Table, sizeof (ACPI_TABLE_HEADER)); 533 } 534 535 536 /******************************************************************************* 537 * 538 * FUNCTION: AcpiTbGetRootTableEntry 539 * 540 * PARAMETERS: TableEntry - Pointer to the RSDT/XSDT table entry 541 * TableEntrySize - sizeof 32 or 64 (RSDT or XSDT) 542 * 543 * RETURN: Physical address extracted from the root table 544 * 545 * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on 546 * both 32-bit and 64-bit platforms 547 * 548 * NOTE: ACPI_PHYSICAL_ADDRESS is 32-bit on 32-bit platforms, 64-bit on 549 * 64-bit platforms. 550 * 551 ******************************************************************************/ 552 553 static ACPI_PHYSICAL_ADDRESS 554 AcpiTbGetRootTableEntry ( 555 UINT8 *TableEntry, 556 UINT32 TableEntrySize) 557 { 558 UINT64 Address64; 559 560 561 /* 562 * Get the table physical address (32-bit for RSDT, 64-bit for XSDT): 563 * Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT 564 */ 565 if (TableEntrySize == sizeof (UINT32)) 566 { 567 /* 568 * 32-bit platform, RSDT: Return 32-bit table entry 569 * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return 570 */ 571 return ((ACPI_PHYSICAL_ADDRESS) (*ACPI_CAST_PTR (UINT32, TableEntry))); 572 } 573 else 574 { 575 /* 576 * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return 577 * 64-bit platform, XSDT: Move (unaligned) 64-bit to local, 578 * return 64-bit 579 */ 580 ACPI_MOVE_64_TO_64 (&Address64, TableEntry); 581 582 #if ACPI_MACHINE_WIDTH == 32 583 if (Address64 > ACPI_UINT32_MAX) 584 { 585 /* Will truncate 64-bit address to 32 bits, issue warning */ 586 587 ACPI_WARNING ((AE_INFO, 588 "64-bit Physical Address in XSDT is too large (0x%8.8X%8.8X)," 589 " truncating", 590 ACPI_FORMAT_UINT64 (Address64))); 591 } 592 #endif 593 return ((ACPI_PHYSICAL_ADDRESS) (Address64)); 594 } 595 } 596 597 598 /******************************************************************************* 599 * 600 * FUNCTION: AcpiTbParseRootTable 601 * 602 * PARAMETERS: Rsdp - Pointer to the RSDP 603 * 604 * RETURN: Status 605 * 606 * DESCRIPTION: This function is called to parse the Root System Description 607 * Table (RSDT or XSDT) 608 * 609 * NOTE: Tables are mapped (not copied) for efficiency. The FACS must 610 * be mapped and cannot be copied because it contains the actual 611 * memory location of the ACPI Global Lock. 612 * 613 ******************************************************************************/ 614 615 ACPI_STATUS 616 AcpiTbParseRootTable ( 617 ACPI_PHYSICAL_ADDRESS RsdpAddress) 618 { 619 ACPI_TABLE_RSDP *Rsdp; 620 UINT32 TableEntrySize; 621 UINT32 i; 622 UINT32 TableCount; 623 ACPI_TABLE_HEADER *Table; 624 ACPI_PHYSICAL_ADDRESS Address; 625 UINT32 Length; 626 UINT8 *TableEntry; 627 ACPI_STATUS Status; 628 629 630 ACPI_FUNCTION_TRACE (TbParseRootTable); 631 632 633 /* 634 * Map the entire RSDP and extract the address of the RSDT or XSDT 635 */ 636 Rsdp = AcpiOsMapMemory (RsdpAddress, sizeof (ACPI_TABLE_RSDP)); 637 if (!Rsdp) 638 { 639 return_ACPI_STATUS (AE_NO_MEMORY); 640 } 641 642 AcpiTbPrintTableHeader (RsdpAddress, 643 ACPI_CAST_PTR (ACPI_TABLE_HEADER, Rsdp)); 644 645 /* Differentiate between RSDT and XSDT root tables */ 646 647 if (Rsdp->Revision > 1 && Rsdp->XsdtPhysicalAddress) 648 { 649 /* 650 * Root table is an XSDT (64-bit physical addresses). We must use the 651 * XSDT if the revision is > 1 and the XSDT pointer is present, as per 652 * the ACPI specification. 653 */ 654 Address = (ACPI_PHYSICAL_ADDRESS) Rsdp->XsdtPhysicalAddress; 655 TableEntrySize = sizeof (UINT64); 656 } 657 else 658 { 659 /* Root table is an RSDT (32-bit physical addresses) */ 660 661 Address = (ACPI_PHYSICAL_ADDRESS) Rsdp->RsdtPhysicalAddress; 662 TableEntrySize = sizeof (UINT32); 663 } 664 665 /* 666 * It is not possible to map more than one entry in some environments, 667 * so unmap the RSDP here before mapping other tables 668 */ 669 AcpiOsUnmapMemory (Rsdp, sizeof (ACPI_TABLE_RSDP)); 670 671 672 /* Map the RSDT/XSDT table header to get the full table length */ 673 674 Table = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER)); 675 if (!Table) 676 { 677 return_ACPI_STATUS (AE_NO_MEMORY); 678 } 679 680 AcpiTbPrintTableHeader (Address, Table); 681 682 /* Get the length of the full table, verify length and map entire table */ 683 684 Length = Table->Length; 685 AcpiOsUnmapMemory (Table, sizeof (ACPI_TABLE_HEADER)); 686 687 if (Length < sizeof (ACPI_TABLE_HEADER)) 688 { 689 ACPI_ERROR ((AE_INFO, "Invalid length 0x%X in RSDT/XSDT", Length)); 690 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH); 691 } 692 693 Table = AcpiOsMapMemory (Address, Length); 694 if (!Table) 695 { 696 return_ACPI_STATUS (AE_NO_MEMORY); 697 } 698 699 /* Validate the root table checksum */ 700 701 Status = AcpiTbVerifyChecksum (Table, Length); 702 if (ACPI_FAILURE (Status)) 703 { 704 AcpiOsUnmapMemory (Table, Length); 705 return_ACPI_STATUS (Status); 706 } 707 708 /* Calculate the number of tables described in the root table */ 709 710 TableCount = (UINT32) ((Table->Length - sizeof (ACPI_TABLE_HEADER)) / 711 TableEntrySize); 712 713 /* 714 * First two entries in the table array are reserved for the DSDT 715 * and FACS, which are not actually present in the RSDT/XSDT - they 716 * come from the FADT 717 */ 718 TableEntry = ACPI_CAST_PTR (UINT8, Table) + sizeof (ACPI_TABLE_HEADER); 719 AcpiGbl_RootTableList.CurrentTableCount = 2; 720 721 /* 722 * Initialize the root table array from the RSDT/XSDT 723 */ 724 for (i = 0; i < TableCount; i++) 725 { 726 if (AcpiGbl_RootTableList.CurrentTableCount >= 727 AcpiGbl_RootTableList.MaxTableCount) 728 { 729 /* There is no more room in the root table array, attempt resize */ 730 731 Status = AcpiTbResizeRootTableList (); 732 if (ACPI_FAILURE (Status)) 733 { 734 ACPI_WARNING ((AE_INFO, "Truncating %u table entries!", 735 (unsigned) (TableCount - 736 (AcpiGbl_RootTableList.CurrentTableCount - 2)))); 737 break; 738 } 739 } 740 741 /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */ 742 743 AcpiGbl_RootTableList.Tables[AcpiGbl_RootTableList.CurrentTableCount].Address = 744 AcpiTbGetRootTableEntry (TableEntry, TableEntrySize); 745 746 TableEntry += TableEntrySize; 747 AcpiGbl_RootTableList.CurrentTableCount++; 748 } 749 750 /* 751 * It is not possible to map more than one entry in some environments, 752 * so unmap the root table here before mapping other tables 753 */ 754 AcpiOsUnmapMemory (Table, Length); 755 756 /* 757 * Complete the initialization of the root table array by examining 758 * the header of each table 759 */ 760 for (i = 2; i < AcpiGbl_RootTableList.CurrentTableCount; i++) 761 { 762 AcpiTbInstallTable (AcpiGbl_RootTableList.Tables[i].Address, 763 NULL, i); 764 765 /* Special case for FADT - get the DSDT and FACS */ 766 767 if (ACPI_COMPARE_NAME ( 768 &AcpiGbl_RootTableList.Tables[i].Signature, ACPI_SIG_FADT)) 769 { 770 AcpiTbParseFadt (i); 771 } 772 } 773 774 return_ACPI_STATUS (AE_OK); 775 } 776