1 /****************************************************************************** 2 * 3 * Module Name: dmtbdump - Dump ACPI data tables that contain no AML code 4 * 5 *****************************************************************************/ 6 7 /****************************************************************************** 8 * 9 * 1. Copyright Notice 10 * 11 * Some or all of this work - Copyright (c) 1999 - 2022, 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 <contrib/dev/acpica/include/acpi.h> 153 #include <contrib/dev/acpica/include/accommon.h> 154 #include <contrib/dev/acpica/include/acdisasm.h> 155 #include <contrib/dev/acpica/include/actables.h> 156 157 /* This module used for application-level code only */ 158 159 #define _COMPONENT ACPI_CA_DISASSEMBLER 160 ACPI_MODULE_NAME ("dmtbdump") 161 162 163 /* Local prototypes */ 164 165 static void 166 AcpiDmValidateFadtLength ( 167 UINT32 Revision, 168 UINT32 Length); 169 170 171 /******************************************************************************* 172 * 173 * FUNCTION: AcpiDmDumpBuffer 174 * 175 * PARAMETERS: Table - ACPI Table or subtable 176 * BufferOffset - Offset of buffer from Table above 177 * Length - Length of the buffer 178 * AbsoluteOffset - Offset of buffer in the main ACPI table 179 * Header - Name of the buffer field (printed on the 180 * first line only.) 181 * 182 * RETURN: None 183 * 184 * DESCRIPTION: Format the contents of an arbitrary length data buffer (in the 185 * disassembler output format.) 186 * 187 ******************************************************************************/ 188 189 void 190 AcpiDmDumpBuffer ( 191 void *Table, 192 UINT32 BufferOffset, 193 UINT32 Length, 194 UINT32 AbsoluteOffset, 195 char *Header) 196 { 197 UINT8 *Buffer; 198 UINT8 BufChar; 199 UINT32 i; 200 UINT32 j; 201 202 203 if (!Length) 204 { 205 return; 206 } 207 208 Buffer = ACPI_CAST_PTR (UINT8, Table) + BufferOffset; 209 i = 0; 210 211 while (i < Length) 212 { 213 if ((Length > 16) && (i != 0)) 214 { 215 if ((Length - i) < 16) 216 AcpiOsPrintf ("\n/* %3.3Xh %4.4u %3u */ ", AbsoluteOffset, AbsoluteOffset, Length - i); 217 else 218 AcpiOsPrintf ("\n/* %3.3Xh %4.4u 16 */ ", AbsoluteOffset, AbsoluteOffset); 219 } 220 AbsoluteOffset += 16; 221 222 /* Emit the raw data bytes*/ 223 224 for (j = 0; j < 16; j++) 225 { 226 if (i + j >= Length) 227 { 228 /* Dump fill spaces */ 229 230 AcpiOsPrintf ("%*s", (48 - (3 * (Length -i))), " "); 231 break; 232 } 233 AcpiOsPrintf ("%.02X ", Buffer[(ACPI_SIZE) i + j]); 234 } 235 236 /* Emit the ASCII equivalent to the raw data bytes */ 237 238 for (j = 0; j < 16; j++) 239 { 240 if (i + j >= Length) 241 { 242 AcpiOsPrintf (" */\\\n"); 243 return; 244 } 245 246 /* 247 * Add comment characters so rest of line is ignored when 248 * compiled 249 */ 250 if (j == 0) 251 { 252 AcpiOsPrintf ("/* "); 253 } 254 255 BufChar = Buffer[(ACPI_SIZE) i + j]; 256 if (isprint (BufChar)) 257 { 258 AcpiOsPrintf ("%c", BufChar); 259 } 260 else 261 { 262 AcpiOsPrintf ("."); 263 } 264 } 265 266 /* Done with that line. */ 267 /* Close the comment and insert a backslash - line continuation character */ 268 269 if (Length > 16) 270 { 271 AcpiOsPrintf (" */\\"); 272 } 273 else 274 { 275 AcpiOsPrintf (" */\\"); 276 } 277 278 i += 16; /* Point to next line */ 279 } 280 281 AcpiOsPrintf ("\n"); 282 } 283 284 285 /******************************************************************************* 286 * 287 * FUNCTION: AcpiDmDumpUnicode 288 * 289 * PARAMETERS: Table - ACPI Table or subtable 290 * BufferOffset - Offset of buffer from Table above 291 * ByteLength - Length of the buffer 292 * 293 * RETURN: None 294 * 295 * DESCRIPTION: Validate and dump the contents of a buffer that contains 296 * unicode data. The output is a standard ASCII string. If it 297 * appears that the data is not unicode, the buffer is dumped 298 * as hex characters. 299 * 300 ******************************************************************************/ 301 302 void 303 AcpiDmDumpUnicode ( 304 void *Table, 305 UINT32 BufferOffset, 306 UINT32 ByteLength) 307 { 308 UINT8 *Buffer; 309 UINT32 Length; 310 UINT32 i; 311 312 313 Buffer = ((UINT8 *) Table) + BufferOffset; 314 Length = ByteLength - 2; /* Last two bytes are the null terminator */ 315 316 /* Ensure all low bytes are entirely printable ASCII */ 317 318 for (i = 0; i < Length; i += 2) 319 { 320 if (!isprint (Buffer[i])) 321 { 322 goto DumpRawBuffer; 323 } 324 } 325 326 /* Ensure all high bytes are zero */ 327 328 for (i = 1; i < Length; i += 2) 329 { 330 if (Buffer[i]) 331 { 332 goto DumpRawBuffer; 333 } 334 } 335 336 /* Dump the buffer as a normal string */ 337 338 AcpiOsPrintf ("\""); 339 for (i = 0; i < Length; i += 2) 340 { 341 AcpiOsPrintf ("%c", Buffer[i]); 342 } 343 344 AcpiOsPrintf ("\"\n"); 345 return; 346 347 DumpRawBuffer: 348 AcpiDmDumpBuffer (Table, BufferOffset, ByteLength, 349 BufferOffset, NULL); 350 AcpiOsPrintf ("\n"); 351 } 352 353 354 /******************************************************************************* 355 * 356 * FUNCTION: AcpiDmDumpRsdp 357 * 358 * PARAMETERS: Table - A RSDP 359 * 360 * RETURN: Length of the table (there is not always a length field, 361 * use revision or length if available (ACPI 2.0+)) 362 * 363 * DESCRIPTION: Format the contents of a RSDP 364 * 365 ******************************************************************************/ 366 367 UINT32 368 AcpiDmDumpRsdp ( 369 ACPI_TABLE_HEADER *Table) 370 { 371 ACPI_TABLE_RSDP *Rsdp = ACPI_CAST_PTR (ACPI_TABLE_RSDP, Table); 372 UINT32 Length = sizeof (ACPI_RSDP_COMMON); 373 UINT8 Checksum; 374 ACPI_STATUS Status; 375 376 377 /* Dump the common ACPI 1.0 portion */ 378 379 Status = AcpiDmDumpTable (Length, 0, Table, 0, AcpiDmTableInfoRsdp1); 380 if (ACPI_FAILURE (Status)) 381 { 382 return (Length); 383 } 384 385 /* Validate the first checksum */ 386 387 Checksum = AcpiDmGenerateChecksum (Rsdp, sizeof (ACPI_RSDP_COMMON), 388 Rsdp->Checksum); 389 if (Checksum != Rsdp->Checksum) 390 { 391 AcpiOsPrintf ("/* Incorrect Checksum above, should be 0x%2.2X */\n", 392 Checksum); 393 } 394 395 /* The RSDP for ACPI 2.0+ contains more data and has a Length field */ 396 397 if (Rsdp->Revision > 0) 398 { 399 Length = Rsdp->Length; 400 Status = AcpiDmDumpTable (Length, 0, Table, 0, AcpiDmTableInfoRsdp2); 401 if (ACPI_FAILURE (Status)) 402 { 403 return (Length); 404 } 405 406 /* Validate the extended checksum over entire RSDP */ 407 408 Checksum = AcpiDmGenerateChecksum (Rsdp, sizeof (ACPI_TABLE_RSDP), 409 Rsdp->ExtendedChecksum); 410 if (Checksum != Rsdp->ExtendedChecksum) 411 { 412 AcpiOsPrintf ( 413 "/* Incorrect Extended Checksum above, should be 0x%2.2X */\n", 414 Checksum); 415 } 416 } 417 418 return (Length); 419 } 420 421 422 /******************************************************************************* 423 * 424 * FUNCTION: AcpiDmDumpRsdt 425 * 426 * PARAMETERS: Table - A RSDT 427 * 428 * RETURN: None 429 * 430 * DESCRIPTION: Format the contents of a RSDT 431 * 432 ******************************************************************************/ 433 434 void 435 AcpiDmDumpRsdt ( 436 ACPI_TABLE_HEADER *Table) 437 { 438 UINT32 *Array; 439 UINT32 Entries; 440 UINT32 Offset; 441 UINT32 i; 442 443 444 /* Point to start of table pointer array */ 445 446 Array = ACPI_CAST_PTR (ACPI_TABLE_RSDT, Table)->TableOffsetEntry; 447 Offset = sizeof (ACPI_TABLE_HEADER); 448 449 /* RSDT uses 32-bit pointers */ 450 451 Entries = (Table->Length - sizeof (ACPI_TABLE_HEADER)) / sizeof (UINT32); 452 453 for (i = 0; i < Entries; i++) 454 { 455 AcpiDmLineHeader2 (Offset, sizeof (UINT32), "ACPI Table Address", i); 456 AcpiOsPrintf ("%8.8X\n", Array[i]); 457 Offset += sizeof (UINT32); 458 } 459 } 460 461 462 /******************************************************************************* 463 * 464 * FUNCTION: AcpiDmDumpXsdt 465 * 466 * PARAMETERS: Table - A XSDT 467 * 468 * RETURN: None 469 * 470 * DESCRIPTION: Format the contents of a XSDT 471 * 472 ******************************************************************************/ 473 474 void 475 AcpiDmDumpXsdt ( 476 ACPI_TABLE_HEADER *Table) 477 { 478 UINT64 *Array; 479 UINT32 Entries; 480 UINT32 Offset; 481 UINT32 i; 482 483 484 /* Point to start of table pointer array */ 485 486 Array = ACPI_CAST_PTR (ACPI_TABLE_XSDT, Table)->TableOffsetEntry; 487 Offset = sizeof (ACPI_TABLE_HEADER); 488 489 /* XSDT uses 64-bit pointers */ 490 491 Entries = (Table->Length - sizeof (ACPI_TABLE_HEADER)) / sizeof (UINT64); 492 493 for (i = 0; i < Entries; i++) 494 { 495 AcpiDmLineHeader2 (Offset, sizeof (UINT64), "ACPI Table Address", i); 496 AcpiOsPrintf ("%8.8X%8.8X\n", ACPI_FORMAT_UINT64 (Array[i])); 497 Offset += sizeof (UINT64); 498 } 499 } 500 501 502 /******************************************************************************* 503 * 504 * FUNCTION: AcpiDmDumpFadt 505 * 506 * PARAMETERS: Table - A FADT 507 * 508 * RETURN: None 509 * 510 * DESCRIPTION: Format the contents of a FADT 511 * 512 * NOTE: We cannot depend on the FADT version to indicate the actual 513 * contents of the FADT because of BIOS bugs. The table length 514 * is the only reliable indicator. 515 * 516 ******************************************************************************/ 517 518 void 519 AcpiDmDumpFadt ( 520 ACPI_TABLE_HEADER *Table) 521 { 522 ACPI_STATUS Status; 523 524 525 /* Always dump the minimum FADT revision 1 fields (ACPI 1.0) */ 526 527 Status = AcpiDmDumpTable (Table->Length, 0, Table, 0, 528 AcpiDmTableInfoFadt1); 529 if (ACPI_FAILURE (Status)) 530 { 531 return; 532 } 533 534 /* Check for FADT revision 2 fields (ACPI 1.0B MS extensions) */ 535 536 if ((Table->Length > ACPI_FADT_V1_SIZE) && 537 (Table->Length <= ACPI_FADT_V2_SIZE)) 538 { 539 Status = AcpiDmDumpTable (Table->Length, 0, Table, 0, 540 AcpiDmTableInfoFadt2); 541 if (ACPI_FAILURE (Status)) 542 { 543 return; 544 } 545 } 546 547 /* Check for FADT revision 3/4 fields and up (ACPI 2.0+ extended data) */ 548 549 else if (Table->Length > ACPI_FADT_V2_SIZE) 550 { 551 Status = AcpiDmDumpTable (Table->Length, 0, Table, 0, 552 AcpiDmTableInfoFadt3); 553 if (ACPI_FAILURE (Status)) 554 { 555 return; 556 } 557 558 /* Check for FADT revision 5 fields and up (ACPI 5.0+) */ 559 560 if (Table->Length > ACPI_FADT_V3_SIZE) 561 { 562 Status = AcpiDmDumpTable (Table->Length, 0, Table, 0, 563 AcpiDmTableInfoFadt5); 564 if (ACPI_FAILURE (Status)) 565 { 566 return; 567 } 568 } 569 570 /* Check for FADT revision 6 fields and up (ACPI 6.0+) */ 571 572 if (Table->Length > ACPI_FADT_V3_SIZE) 573 { 574 Status = AcpiDmDumpTable (Table->Length, 0, Table, 0, 575 AcpiDmTableInfoFadt6); 576 if (ACPI_FAILURE (Status)) 577 { 578 return; 579 } 580 } 581 } 582 583 /* Validate various fields in the FADT, including length */ 584 585 AcpiTbCreateLocalFadt (Table, Table->Length); 586 587 /* Validate FADT length against the revision */ 588 589 AcpiDmValidateFadtLength (Table->Revision, Table->Length); 590 } 591 592 593 /******************************************************************************* 594 * 595 * FUNCTION: AcpiDmValidateFadtLength 596 * 597 * PARAMETERS: Revision - FADT revision (Header->Revision) 598 * Length - FADT length (Header->Length 599 * 600 * RETURN: None 601 * 602 * DESCRIPTION: Check the FADT revision against the expected table length for 603 * that revision. Issue a warning if the length is not what was 604 * expected. This seems to be such a common BIOS bug that the 605 * FADT revision has been rendered virtually meaningless. 606 * 607 ******************************************************************************/ 608 609 static void 610 AcpiDmValidateFadtLength ( 611 UINT32 Revision, 612 UINT32 Length) 613 { 614 UINT32 ExpectedLength; 615 616 617 switch (Revision) 618 { 619 case 0: 620 621 AcpiOsPrintf ("// ACPI Warning: Invalid FADT revision: 0\n"); 622 return; 623 624 case 1: 625 626 ExpectedLength = ACPI_FADT_V1_SIZE; 627 break; 628 629 case 2: 630 631 ExpectedLength = ACPI_FADT_V2_SIZE; 632 break; 633 634 case 3: 635 case 4: 636 637 ExpectedLength = ACPI_FADT_V3_SIZE; 638 break; 639 640 case 5: 641 642 ExpectedLength = ACPI_FADT_V5_SIZE; 643 break; 644 645 default: 646 647 return; 648 } 649 650 if (Length == ExpectedLength) 651 { 652 return; 653 } 654 655 AcpiOsPrintf ( 656 "\n// ACPI Warning: FADT revision %X does not match length: " 657 "found %X expected %X\n", 658 Revision, Length, ExpectedLength); 659 } 660