1 /****************************************************************************** 2 * 3 * Module Name: tbutils - ACPI Table utilities 4 * 5 *****************************************************************************/ 6 7 /****************************************************************************** 8 * 9 * 1. Copyright Notice 10 * 11 * Some or all of this work - Copyright (c) 1999 - 2013, 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 #define __TBUTILS_C__ 117 118 #include "acpi.h" 119 #include "accommon.h" 120 #include "actables.h" 121 122 #define _COMPONENT ACPI_TABLES 123 ACPI_MODULE_NAME ("tbutils") 124 125 126 /* Local prototypes */ 127 128 static ACPI_PHYSICAL_ADDRESS 129 AcpiTbGetRootTableEntry ( 130 UINT8 *TableEntry, 131 UINT32 TableEntrySize); 132 133 134 #if (!ACPI_REDUCED_HARDWARE) 135 /******************************************************************************* 136 * 137 * FUNCTION: AcpiTbInitializeFacs 138 * 139 * PARAMETERS: None 140 * 141 * RETURN: Status 142 * 143 * DESCRIPTION: Create a permanent mapping for the FADT and save it in a global 144 * for accessing the Global Lock and Firmware Waking Vector 145 * 146 ******************************************************************************/ 147 148 ACPI_STATUS 149 AcpiTbInitializeFacs ( 150 void) 151 { 152 ACPI_STATUS Status; 153 154 155 /* If Hardware Reduced flag is set, there is no FACS */ 156 157 if (AcpiGbl_ReducedHardware) 158 { 159 AcpiGbl_FACS = NULL; 160 return (AE_OK); 161 } 162 163 Status = AcpiGetTableByIndex (ACPI_TABLE_INDEX_FACS, 164 ACPI_CAST_INDIRECT_PTR (ACPI_TABLE_HEADER, &AcpiGbl_FACS)); 165 return (Status); 166 } 167 #endif /* !ACPI_REDUCED_HARDWARE */ 168 169 170 /******************************************************************************* 171 * 172 * FUNCTION: AcpiTbTablesLoaded 173 * 174 * PARAMETERS: None 175 * 176 * RETURN: TRUE if required ACPI tables are loaded 177 * 178 * DESCRIPTION: Determine if the minimum required ACPI tables are present 179 * (FADT, FACS, DSDT) 180 * 181 ******************************************************************************/ 182 183 BOOLEAN 184 AcpiTbTablesLoaded ( 185 void) 186 { 187 188 if (AcpiGbl_RootTableList.CurrentTableCount >= 3) 189 { 190 return (TRUE); 191 } 192 193 return (FALSE); 194 } 195 196 197 /******************************************************************************* 198 * 199 * FUNCTION: AcpiTbCheckDsdtHeader 200 * 201 * PARAMETERS: None 202 * 203 * RETURN: None 204 * 205 * DESCRIPTION: Quick compare to check validity of the DSDT. This will detect 206 * if the DSDT has been replaced from outside the OS and/or if 207 * the DSDT header has been corrupted. 208 * 209 ******************************************************************************/ 210 211 void 212 AcpiTbCheckDsdtHeader ( 213 void) 214 { 215 216 /* Compare original length and checksum to current values */ 217 218 if (AcpiGbl_OriginalDsdtHeader.Length != AcpiGbl_DSDT->Length || 219 AcpiGbl_OriginalDsdtHeader.Checksum != AcpiGbl_DSDT->Checksum) 220 { 221 ACPI_BIOS_ERROR ((AE_INFO, 222 "The DSDT has been corrupted or replaced - " 223 "old, new headers below")); 224 AcpiTbPrintTableHeader (0, &AcpiGbl_OriginalDsdtHeader); 225 AcpiTbPrintTableHeader (0, AcpiGbl_DSDT); 226 227 /* Disable further error messages */ 228 229 AcpiGbl_OriginalDsdtHeader.Length = AcpiGbl_DSDT->Length; 230 AcpiGbl_OriginalDsdtHeader.Checksum = AcpiGbl_DSDT->Checksum; 231 } 232 } 233 234 235 /******************************************************************************* 236 * 237 * FUNCTION: AcpiTbCopyDsdt 238 * 239 * PARAMETERS: TableDesc - Installed table to copy 240 * 241 * RETURN: None 242 * 243 * DESCRIPTION: Implements a subsystem option to copy the DSDT to local memory. 244 * Some very bad BIOSs are known to either corrupt the DSDT or 245 * install a new, bad DSDT. This copy works around the problem. 246 * 247 ******************************************************************************/ 248 249 ACPI_TABLE_HEADER * 250 AcpiTbCopyDsdt ( 251 UINT32 TableIndex) 252 { 253 ACPI_TABLE_HEADER *NewTable; 254 ACPI_TABLE_DESC *TableDesc; 255 256 257 TableDesc = &AcpiGbl_RootTableList.Tables[TableIndex]; 258 259 NewTable = ACPI_ALLOCATE (TableDesc->Length); 260 if (!NewTable) 261 { 262 ACPI_ERROR ((AE_INFO, "Could not copy DSDT of length 0x%X", 263 TableDesc->Length)); 264 return (NULL); 265 } 266 267 ACPI_MEMCPY (NewTable, TableDesc->Pointer, TableDesc->Length); 268 AcpiTbDeleteTable (TableDesc); 269 TableDesc->Pointer = NewTable; 270 TableDesc->Flags = ACPI_TABLE_ORIGIN_ALLOCATED; 271 272 ACPI_INFO ((AE_INFO, 273 "Forced DSDT copy: length 0x%05X copied locally, original unmapped", 274 NewTable->Length)); 275 276 return (NewTable); 277 } 278 279 280 /******************************************************************************* 281 * 282 * FUNCTION: AcpiTbInstallTable 283 * 284 * PARAMETERS: Address - Physical address of DSDT or FACS 285 * Signature - Table signature, NULL if no need to 286 * match 287 * TableIndex - Index into root table array 288 * 289 * RETURN: None 290 * 291 * DESCRIPTION: Install an ACPI table into the global data structure. The 292 * table override mechanism is called to allow the host 293 * OS to replace any table before it is installed in the root 294 * table array. 295 * 296 ******************************************************************************/ 297 298 void 299 AcpiTbInstallTable ( 300 ACPI_PHYSICAL_ADDRESS Address, 301 char *Signature, 302 UINT32 TableIndex) 303 { 304 ACPI_TABLE_HEADER *Table; 305 ACPI_TABLE_HEADER *FinalTable; 306 ACPI_TABLE_DESC *TableDesc; 307 308 309 if (!Address) 310 { 311 ACPI_ERROR ((AE_INFO, "Null physical address for ACPI table [%s]", 312 Signature)); 313 return; 314 } 315 316 /* Map just the table header */ 317 318 Table = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER)); 319 if (!Table) 320 { 321 ACPI_ERROR ((AE_INFO, "Could not map memory for table [%s] at %p", 322 Signature, ACPI_CAST_PTR (void, Address))); 323 return; 324 } 325 326 /* If a particular signature is expected (DSDT/FACS), it must match */ 327 328 if (Signature && 329 !ACPI_COMPARE_NAME (Table->Signature, Signature)) 330 { 331 ACPI_BIOS_ERROR ((AE_INFO, 332 "Invalid signature 0x%X for ACPI table, expected [%s]", 333 *ACPI_CAST_PTR (UINT32, Table->Signature), Signature)); 334 goto UnmapAndExit; 335 } 336 337 /* 338 * Initialize the table entry. Set the pointer to NULL, since the 339 * table is not fully mapped at this time. 340 */ 341 TableDesc = &AcpiGbl_RootTableList.Tables[TableIndex]; 342 343 TableDesc->Address = Address; 344 TableDesc->Pointer = NULL; 345 TableDesc->Length = Table->Length; 346 TableDesc->Flags = ACPI_TABLE_ORIGIN_MAPPED; 347 ACPI_MOVE_32_TO_32 (TableDesc->Signature.Ascii, Table->Signature); 348 349 /* 350 * ACPI Table Override: 351 * 352 * Before we install the table, let the host OS override it with a new 353 * one if desired. Any table within the RSDT/XSDT can be replaced, 354 * including the DSDT which is pointed to by the FADT. 355 * 356 * NOTE: If the table is overridden, then FinalTable will contain a 357 * mapped pointer to the full new table. If the table is not overridden, 358 * or if there has been a physical override, then the table will be 359 * fully mapped later (in verify table). In any case, we must 360 * unmap the header that was mapped above. 361 */ 362 FinalTable = AcpiTbTableOverride (Table, TableDesc); 363 if (!FinalTable) 364 { 365 FinalTable = Table; /* There was no override */ 366 } 367 368 AcpiTbPrintTableHeader (TableDesc->Address, FinalTable); 369 370 /* Set the global integer width (based upon revision of the DSDT) */ 371 372 if (TableIndex == ACPI_TABLE_INDEX_DSDT) 373 { 374 AcpiUtSetIntegerWidth (FinalTable->Revision); 375 } 376 377 /* 378 * If we have a physical override during this early loading of the ACPI 379 * tables, unmap the table for now. It will be mapped again later when 380 * it is actually used. This supports very early loading of ACPI tables, 381 * before virtual memory is fully initialized and running within the 382 * host OS. Note: A logical override has the ACPI_TABLE_ORIGIN_OVERRIDE 383 * flag set and will not be deleted below. 384 */ 385 if (FinalTable != Table) 386 { 387 AcpiTbDeleteTable (TableDesc); 388 } 389 390 391 UnmapAndExit: 392 393 /* Always unmap the table header that we mapped above */ 394 395 AcpiOsUnmapMemory (Table, sizeof (ACPI_TABLE_HEADER)); 396 } 397 398 399 /******************************************************************************* 400 * 401 * FUNCTION: AcpiTbGetRootTableEntry 402 * 403 * PARAMETERS: TableEntry - Pointer to the RSDT/XSDT table entry 404 * TableEntrySize - sizeof 32 or 64 (RSDT or XSDT) 405 * 406 * RETURN: Physical address extracted from the root table 407 * 408 * DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on 409 * both 32-bit and 64-bit platforms 410 * 411 * NOTE: ACPI_PHYSICAL_ADDRESS is 32-bit on 32-bit platforms, 64-bit on 412 * 64-bit platforms. 413 * 414 ******************************************************************************/ 415 416 static ACPI_PHYSICAL_ADDRESS 417 AcpiTbGetRootTableEntry ( 418 UINT8 *TableEntry, 419 UINT32 TableEntrySize) 420 { 421 UINT64 Address64; 422 423 424 /* 425 * Get the table physical address (32-bit for RSDT, 64-bit for XSDT): 426 * Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT 427 */ 428 if (TableEntrySize == sizeof (UINT32)) 429 { 430 /* 431 * 32-bit platform, RSDT: Return 32-bit table entry 432 * 64-bit platform, RSDT: Expand 32-bit to 64-bit and return 433 */ 434 return ((ACPI_PHYSICAL_ADDRESS) (*ACPI_CAST_PTR (UINT32, TableEntry))); 435 } 436 else 437 { 438 /* 439 * 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return 440 * 64-bit platform, XSDT: Move (unaligned) 64-bit to local, 441 * return 64-bit 442 */ 443 ACPI_MOVE_64_TO_64 (&Address64, TableEntry); 444 445 #if ACPI_MACHINE_WIDTH == 32 446 if (Address64 > ACPI_UINT32_MAX) 447 { 448 /* Will truncate 64-bit address to 32 bits, issue warning */ 449 450 ACPI_BIOS_WARNING ((AE_INFO, 451 "64-bit Physical Address in XSDT is too large (0x%8.8X%8.8X)," 452 " truncating", 453 ACPI_FORMAT_UINT64 (Address64))); 454 } 455 #endif 456 return ((ACPI_PHYSICAL_ADDRESS) (Address64)); 457 } 458 } 459 460 461 /******************************************************************************* 462 * 463 * FUNCTION: AcpiTbParseRootTable 464 * 465 * PARAMETERS: Rsdp - Pointer to the RSDP 466 * 467 * RETURN: Status 468 * 469 * DESCRIPTION: This function is called to parse the Root System Description 470 * Table (RSDT or XSDT) 471 * 472 * NOTE: Tables are mapped (not copied) for efficiency. The FACS must 473 * be mapped and cannot be copied because it contains the actual 474 * memory location of the ACPI Global Lock. 475 * 476 ******************************************************************************/ 477 478 ACPI_STATUS 479 AcpiTbParseRootTable ( 480 ACPI_PHYSICAL_ADDRESS RsdpAddress) 481 { 482 ACPI_TABLE_RSDP *Rsdp; 483 UINT32 TableEntrySize; 484 UINT32 i; 485 UINT32 TableCount; 486 ACPI_TABLE_HEADER *Table; 487 ACPI_PHYSICAL_ADDRESS Address; 488 UINT32 Length; 489 UINT8 *TableEntry; 490 ACPI_STATUS Status; 491 492 493 ACPI_FUNCTION_TRACE (TbParseRootTable); 494 495 496 /* 497 * Map the entire RSDP and extract the address of the RSDT or XSDT 498 */ 499 Rsdp = AcpiOsMapMemory (RsdpAddress, sizeof (ACPI_TABLE_RSDP)); 500 if (!Rsdp) 501 { 502 return_ACPI_STATUS (AE_NO_MEMORY); 503 } 504 505 AcpiTbPrintTableHeader (RsdpAddress, 506 ACPI_CAST_PTR (ACPI_TABLE_HEADER, Rsdp)); 507 508 /* Differentiate between RSDT and XSDT root tables */ 509 510 if (Rsdp->Revision > 1 && Rsdp->XsdtPhysicalAddress) 511 { 512 /* 513 * Root table is an XSDT (64-bit physical addresses). We must use the 514 * XSDT if the revision is > 1 and the XSDT pointer is present, as per 515 * the ACPI specification. 516 */ 517 Address = (ACPI_PHYSICAL_ADDRESS) Rsdp->XsdtPhysicalAddress; 518 TableEntrySize = sizeof (UINT64); 519 } 520 else 521 { 522 /* Root table is an RSDT (32-bit physical addresses) */ 523 524 Address = (ACPI_PHYSICAL_ADDRESS) Rsdp->RsdtPhysicalAddress; 525 TableEntrySize = sizeof (UINT32); 526 } 527 528 /* 529 * It is not possible to map more than one entry in some environments, 530 * so unmap the RSDP here before mapping other tables 531 */ 532 AcpiOsUnmapMemory (Rsdp, sizeof (ACPI_TABLE_RSDP)); 533 534 535 /* Map the RSDT/XSDT table header to get the full table length */ 536 537 Table = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER)); 538 if (!Table) 539 { 540 return_ACPI_STATUS (AE_NO_MEMORY); 541 } 542 543 AcpiTbPrintTableHeader (Address, Table); 544 545 /* Get the length of the full table, verify length and map entire table */ 546 547 Length = Table->Length; 548 AcpiOsUnmapMemory (Table, sizeof (ACPI_TABLE_HEADER)); 549 550 if (Length < sizeof (ACPI_TABLE_HEADER)) 551 { 552 ACPI_BIOS_ERROR ((AE_INFO, 553 "Invalid table length 0x%X in RSDT/XSDT", Length)); 554 return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH); 555 } 556 557 Table = AcpiOsMapMemory (Address, Length); 558 if (!Table) 559 { 560 return_ACPI_STATUS (AE_NO_MEMORY); 561 } 562 563 /* Validate the root table checksum */ 564 565 Status = AcpiTbVerifyChecksum (Table, Length); 566 if (ACPI_FAILURE (Status)) 567 { 568 AcpiOsUnmapMemory (Table, Length); 569 return_ACPI_STATUS (Status); 570 } 571 572 /* Calculate the number of tables described in the root table */ 573 574 TableCount = (UINT32) ((Table->Length - sizeof (ACPI_TABLE_HEADER)) / 575 TableEntrySize); 576 577 /* 578 * First two entries in the table array are reserved for the DSDT 579 * and FACS, which are not actually present in the RSDT/XSDT - they 580 * come from the FADT 581 */ 582 TableEntry = ACPI_CAST_PTR (UINT8, Table) + sizeof (ACPI_TABLE_HEADER); 583 AcpiGbl_RootTableList.CurrentTableCount = 2; 584 585 /* 586 * Initialize the root table array from the RSDT/XSDT 587 */ 588 for (i = 0; i < TableCount; i++) 589 { 590 if (AcpiGbl_RootTableList.CurrentTableCount >= 591 AcpiGbl_RootTableList.MaxTableCount) 592 { 593 /* There is no more room in the root table array, attempt resize */ 594 595 Status = AcpiTbResizeRootTableList (); 596 if (ACPI_FAILURE (Status)) 597 { 598 ACPI_WARNING ((AE_INFO, "Truncating %u table entries!", 599 (unsigned) (TableCount - 600 (AcpiGbl_RootTableList.CurrentTableCount - 2)))); 601 break; 602 } 603 } 604 605 /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */ 606 607 AcpiGbl_RootTableList.Tables[AcpiGbl_RootTableList.CurrentTableCount].Address = 608 AcpiTbGetRootTableEntry (TableEntry, TableEntrySize); 609 610 TableEntry += TableEntrySize; 611 AcpiGbl_RootTableList.CurrentTableCount++; 612 } 613 614 /* 615 * It is not possible to map more than one entry in some environments, 616 * so unmap the root table here before mapping other tables 617 */ 618 AcpiOsUnmapMemory (Table, Length); 619 620 /* 621 * Complete the initialization of the root table array by examining 622 * the header of each table 623 */ 624 for (i = 2; i < AcpiGbl_RootTableList.CurrentTableCount; i++) 625 { 626 AcpiTbInstallTable (AcpiGbl_RootTableList.Tables[i].Address, 627 NULL, i); 628 629 /* Special case for FADT - get the DSDT and FACS */ 630 631 if (ACPI_COMPARE_NAME ( 632 &AcpiGbl_RootTableList.Tables[i].Signature, ACPI_SIG_FADT)) 633 { 634 AcpiTbParseFadt (i); 635 } 636 } 637 638 return_ACPI_STATUS (AE_OK); 639 } 640