Home | History | Annotate | Line # | Download | only in common
dmtbdump.c revision 1.1.1.18
      1 /******************************************************************************
      2  *
      3  * Module Name: dmtbdump - Dump ACPI data tables that contain no AML code
      4  *
      5  *****************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2021, 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 MERCHANTABILITY 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 #include "acpi.h"
     45 #include "accommon.h"
     46 #include "acdisasm.h"
     47 #include "actables.h"
     48 
     49 /* This module used for application-level code only */
     50 
     51 #define _COMPONENT          ACPI_CA_DISASSEMBLER
     52         ACPI_MODULE_NAME    ("dmtbdump")
     53 
     54 
     55 /* Local prototypes */
     56 
     57 static void
     58 AcpiDmValidateFadtLength (
     59     UINT32                  Revision,
     60     UINT32                  Length);
     61 
     62 
     63 /*******************************************************************************
     64  *
     65  * FUNCTION:    AcpiDmDumpBuffer
     66  *
     67  * PARAMETERS:  Table               - ACPI Table or subtable
     68  *              BufferOffset        - Offset of buffer from Table above
     69  *              Length              - Length of the buffer
     70  *              AbsoluteOffset      - Offset of buffer in the main ACPI table
     71  *              Header              - Name of the buffer field (printed on the
     72  *                                    first line only.)
     73  *
     74  * RETURN:      None
     75  *
     76  * DESCRIPTION: Format the contents of an arbitrary length data buffer (in the
     77  *              disassembler output format.)
     78  *
     79  ******************************************************************************/
     80 
     81 void
     82 AcpiDmDumpBuffer (
     83     void                    *Table,
     84     UINT32                  BufferOffset,
     85     UINT32                  Length,
     86     UINT32                  AbsoluteOffset,
     87     char                    *Header)
     88 {
     89     UINT8                   *Buffer;
     90     UINT8                   BufChar;
     91     UINT32                  i;
     92     UINT32                  j;
     93 
     94 
     95     if (!Length)
     96     {
     97         return;
     98     }
     99 
    100     Buffer = ACPI_CAST_PTR (UINT8, Table) + BufferOffset;
    101     i = 0;
    102 
    103     while (i < Length)
    104     {
    105         if ((Length > 16) && (i != 0))
    106         {
    107         if ((Length - i) < 16)
    108             AcpiOsPrintf ("\n/* %3.3Xh %4.4u %3u */                            ", AbsoluteOffset, AbsoluteOffset, Length - i);
    109         else
    110             AcpiOsPrintf ("\n/* %3.3Xh %4.4u  16 */                            ", AbsoluteOffset, AbsoluteOffset);
    111         }
    112         AbsoluteOffset += 16;
    113 
    114         /* Emit the raw data bytes*/
    115 
    116         for (j = 0; j < 16; j++)
    117         {
    118             if (i + j >= Length)
    119             {
    120                 /* Dump fill spaces */
    121 
    122                 AcpiOsPrintf ("%*s", (48 - (3 * (Length -i))), " ");
    123                 break;
    124             }
    125             AcpiOsPrintf ("%.02X ", Buffer[(ACPI_SIZE) i + j]);
    126         }
    127 
    128         /* Emit the ASCII equivalent to the raw data bytes */
    129 
    130         for (j = 0; j < 16; j++)
    131         {
    132             if (i + j >= Length)
    133             {
    134                 AcpiOsPrintf (" */\\\n");
    135                 return;
    136             }
    137 
    138             /*
    139              * Add comment characters so rest of line is ignored when
    140              * compiled
    141              */
    142             if (j == 0)
    143             {
    144                 AcpiOsPrintf ("/* ");
    145             }
    146 
    147             BufChar = Buffer[(ACPI_SIZE) i + j];
    148             if (isprint (BufChar))
    149             {
    150                 AcpiOsPrintf ("%c", BufChar);
    151             }
    152             else
    153             {
    154                 AcpiOsPrintf (".");
    155             }
    156         }
    157 
    158         /* Done with that line. */
    159         /* Close the comment and insert a backslash - line continuation character */
    160 
    161         if (Length > 16)
    162         {
    163             AcpiOsPrintf (" */\\");
    164         }
    165         else
    166         {
    167             AcpiOsPrintf (" */\\");
    168         }
    169 
    170         i += 16; /* Point to next line */
    171     }
    172 
    173     AcpiOsPrintf ("\n");
    174 }
    175 
    176 
    177 /*******************************************************************************
    178  *
    179  * FUNCTION:    AcpiDmDumpUnicode
    180  *
    181  * PARAMETERS:  Table               - ACPI Table or subtable
    182  *              BufferOffset        - Offset of buffer from Table above
    183  *              ByteLength          - Length of the buffer
    184  *
    185  * RETURN:      None
    186  *
    187  * DESCRIPTION: Validate and dump the contents of a buffer that contains
    188  *              unicode data. The output is a standard ASCII string. If it
    189  *              appears that the data is not unicode, the buffer is dumped
    190  *              as hex characters.
    191  *
    192  ******************************************************************************/
    193 
    194 void
    195 AcpiDmDumpUnicode (
    196     void                    *Table,
    197     UINT32                  BufferOffset,
    198     UINT32                  ByteLength)
    199 {
    200     UINT8                   *Buffer;
    201     UINT32                  Length;
    202     UINT32                  i;
    203 
    204 
    205     Buffer = ((UINT8 *) Table) + BufferOffset;
    206     Length = ByteLength - 2; /* Last two bytes are the null terminator */
    207 
    208     /* Ensure all low bytes are entirely printable ASCII */
    209 
    210     for (i = 0; i < Length; i += 2)
    211     {
    212         if (!isprint (Buffer[i]))
    213         {
    214             goto DumpRawBuffer;
    215         }
    216     }
    217 
    218     /* Ensure all high bytes are zero */
    219 
    220     for (i = 1; i < Length; i += 2)
    221     {
    222         if (Buffer[i])
    223         {
    224             goto DumpRawBuffer;
    225         }
    226     }
    227 
    228     /* Dump the buffer as a normal string */
    229 
    230     AcpiOsPrintf ("\"");
    231     for (i = 0; i < Length; i += 2)
    232     {
    233         AcpiOsPrintf ("%c", Buffer[i]);
    234     }
    235 
    236     AcpiOsPrintf ("\"\n");
    237     return;
    238 
    239 DumpRawBuffer:
    240     AcpiDmDumpBuffer (Table, BufferOffset, ByteLength,
    241         BufferOffset, NULL);
    242     AcpiOsPrintf ("\n");
    243 }
    244 
    245 
    246 /*******************************************************************************
    247  *
    248  * FUNCTION:    AcpiDmDumpRsdp
    249  *
    250  * PARAMETERS:  Table               - A RSDP
    251  *
    252  * RETURN:      Length of the table (there is not always a length field,
    253  *              use revision or length if available (ACPI 2.0+))
    254  *
    255  * DESCRIPTION: Format the contents of a RSDP
    256  *
    257  ******************************************************************************/
    258 
    259 UINT32
    260 AcpiDmDumpRsdp (
    261     ACPI_TABLE_HEADER       *Table)
    262 {
    263     ACPI_TABLE_RSDP         *Rsdp = ACPI_CAST_PTR (ACPI_TABLE_RSDP, Table);
    264     UINT32                  Length = sizeof (ACPI_RSDP_COMMON);
    265     UINT8                   Checksum;
    266     ACPI_STATUS             Status;
    267 
    268 
    269     /* Dump the common ACPI 1.0 portion */
    270 
    271     Status = AcpiDmDumpTable (Length, 0, Table, 0, AcpiDmTableInfoRsdp1);
    272     if (ACPI_FAILURE (Status))
    273     {
    274         return (Length);
    275     }
    276 
    277     /* Validate the first checksum */
    278 
    279     Checksum = AcpiDmGenerateChecksum (Rsdp, sizeof (ACPI_RSDP_COMMON),
    280         Rsdp->Checksum);
    281     if (Checksum != Rsdp->Checksum)
    282     {
    283         AcpiOsPrintf ("/* Incorrect Checksum above, should be 0x%2.2X */\n",
    284             Checksum);
    285     }
    286 
    287     /* The RSDP for ACPI 2.0+ contains more data and has a Length field */
    288 
    289     if (Rsdp->Revision > 0)
    290     {
    291         Length = Rsdp->Length;
    292         Status = AcpiDmDumpTable (Length, 0, Table, 0, AcpiDmTableInfoRsdp2);
    293         if (ACPI_FAILURE (Status))
    294         {
    295             return (Length);
    296         }
    297 
    298         /* Validate the extended checksum over entire RSDP */
    299 
    300         Checksum = AcpiDmGenerateChecksum (Rsdp, sizeof (ACPI_TABLE_RSDP),
    301             Rsdp->ExtendedChecksum);
    302         if (Checksum != Rsdp->ExtendedChecksum)
    303         {
    304             AcpiOsPrintf (
    305                 "/* Incorrect Extended Checksum above, should be 0x%2.2X */\n",
    306                 Checksum);
    307         }
    308     }
    309 
    310     return (Length);
    311 }
    312 
    313 
    314 /*******************************************************************************
    315  *
    316  * FUNCTION:    AcpiDmDumpRsdt
    317  *
    318  * PARAMETERS:  Table               - A RSDT
    319  *
    320  * RETURN:      None
    321  *
    322  * DESCRIPTION: Format the contents of a RSDT
    323  *
    324  ******************************************************************************/
    325 
    326 void
    327 AcpiDmDumpRsdt (
    328     ACPI_TABLE_HEADER       *Table)
    329 {
    330     UINT32                  *Array;
    331     UINT32                  Entries;
    332     UINT32                  Offset;
    333     UINT32                  i;
    334 
    335 
    336     /* Point to start of table pointer array */
    337 
    338     Array = ACPI_CAST_PTR (ACPI_TABLE_RSDT, Table)->TableOffsetEntry;
    339     Offset = sizeof (ACPI_TABLE_HEADER);
    340 
    341     /* RSDT uses 32-bit pointers */
    342 
    343     Entries = (Table->Length - sizeof (ACPI_TABLE_HEADER)) / sizeof (UINT32);
    344 
    345     for (i = 0; i < Entries; i++)
    346     {
    347         AcpiDmLineHeader2 (Offset, sizeof (UINT32), "ACPI Table Address", i);
    348         AcpiOsPrintf ("%8.8X\n", Array[i]);
    349         Offset += sizeof (UINT32);
    350     }
    351 }
    352 
    353 
    354 /*******************************************************************************
    355  *
    356  * FUNCTION:    AcpiDmDumpXsdt
    357  *
    358  * PARAMETERS:  Table               - A XSDT
    359  *
    360  * RETURN:      None
    361  *
    362  * DESCRIPTION: Format the contents of a XSDT
    363  *
    364  ******************************************************************************/
    365 
    366 void
    367 AcpiDmDumpXsdt (
    368     ACPI_TABLE_HEADER       *Table)
    369 {
    370     UINT64                  *Array;
    371     UINT32                  Entries;
    372     UINT32                  Offset;
    373     UINT32                  i;
    374 
    375 
    376     /* Point to start of table pointer array */
    377 
    378     Array = ACPI_CAST_PTR (ACPI_TABLE_XSDT, Table)->TableOffsetEntry;
    379     Offset = sizeof (ACPI_TABLE_HEADER);
    380 
    381     /* XSDT uses 64-bit pointers */
    382 
    383     Entries = (Table->Length - sizeof (ACPI_TABLE_HEADER)) / sizeof (UINT64);
    384 
    385     for (i = 0; i < Entries; i++)
    386     {
    387         AcpiDmLineHeader2 (Offset, sizeof (UINT64), "ACPI Table Address", i);
    388         AcpiOsPrintf ("%8.8X%8.8X\n", ACPI_FORMAT_UINT64 (Array[i]));
    389         Offset += sizeof (UINT64);
    390     }
    391 }
    392 
    393 
    394 /*******************************************************************************
    395  *
    396  * FUNCTION:    AcpiDmDumpFadt
    397  *
    398  * PARAMETERS:  Table               - A FADT
    399  *
    400  * RETURN:      None
    401  *
    402  * DESCRIPTION: Format the contents of a FADT
    403  *
    404  * NOTE:        We cannot depend on the FADT version to indicate the actual
    405  *              contents of the FADT because of BIOS bugs. The table length
    406  *              is the only reliable indicator.
    407  *
    408  ******************************************************************************/
    409 
    410 void
    411 AcpiDmDumpFadt (
    412     ACPI_TABLE_HEADER       *Table)
    413 {
    414     ACPI_STATUS             Status;
    415 
    416 
    417     /* Always dump the minimum FADT revision 1 fields (ACPI 1.0) */
    418 
    419     Status = AcpiDmDumpTable (Table->Length, 0, Table, 0,
    420         AcpiDmTableInfoFadt1);
    421     if (ACPI_FAILURE (Status))
    422     {
    423         return;
    424     }
    425 
    426     /* Check for FADT revision 2 fields (ACPI 1.0B MS extensions) */
    427 
    428     if ((Table->Length > ACPI_FADT_V1_SIZE) &&
    429         (Table->Length <= ACPI_FADT_V2_SIZE))
    430     {
    431         Status = AcpiDmDumpTable (Table->Length, 0, Table, 0,
    432             AcpiDmTableInfoFadt2);
    433         if (ACPI_FAILURE (Status))
    434         {
    435             return;
    436         }
    437     }
    438 
    439     /* Check for FADT revision 3/4 fields and up (ACPI 2.0+ extended data) */
    440 
    441     else if (Table->Length > ACPI_FADT_V2_SIZE)
    442     {
    443         Status = AcpiDmDumpTable (Table->Length, 0, Table, 0,
    444             AcpiDmTableInfoFadt3);
    445         if (ACPI_FAILURE (Status))
    446         {
    447             return;
    448         }
    449 
    450         /* Check for FADT revision 5 fields and up (ACPI 5.0+) */
    451 
    452         if (Table->Length > ACPI_FADT_V3_SIZE)
    453         {
    454             Status = AcpiDmDumpTable (Table->Length, 0, Table, 0,
    455                 AcpiDmTableInfoFadt5);
    456             if (ACPI_FAILURE (Status))
    457             {
    458                 return;
    459             }
    460         }
    461 
    462         /* Check for FADT revision 6 fields and up (ACPI 6.0+) */
    463 
    464         if (Table->Length > ACPI_FADT_V3_SIZE)
    465         {
    466             Status = AcpiDmDumpTable (Table->Length, 0, Table, 0,
    467                 AcpiDmTableInfoFadt6);
    468             if (ACPI_FAILURE (Status))
    469             {
    470                 return;
    471             }
    472         }
    473     }
    474 
    475     /* Validate various fields in the FADT, including length */
    476 
    477     AcpiTbCreateLocalFadt (Table, Table->Length);
    478 
    479     /* Validate FADT length against the revision */
    480 
    481     AcpiDmValidateFadtLength (Table->Revision, Table->Length);
    482 }
    483 
    484 
    485 /*******************************************************************************
    486  *
    487  * FUNCTION:    AcpiDmValidateFadtLength
    488  *
    489  * PARAMETERS:  Revision            - FADT revision (Header->Revision)
    490  *              Length              - FADT length (Header->Length
    491  *
    492  * RETURN:      None
    493  *
    494  * DESCRIPTION: Check the FADT revision against the expected table length for
    495  *              that revision. Issue a warning if the length is not what was
    496  *              expected. This seems to be such a common BIOS bug that the
    497  *              FADT revision has been rendered virtually meaningless.
    498  *
    499  ******************************************************************************/
    500 
    501 static void
    502 AcpiDmValidateFadtLength (
    503     UINT32                  Revision,
    504     UINT32                  Length)
    505 {
    506     UINT32                  ExpectedLength;
    507 
    508 
    509     switch (Revision)
    510     {
    511     case 0:
    512 
    513         AcpiOsPrintf ("// ACPI Warning: Invalid FADT revision: 0\n");
    514         return;
    515 
    516     case 1:
    517 
    518         ExpectedLength = ACPI_FADT_V1_SIZE;
    519         break;
    520 
    521     case 2:
    522 
    523         ExpectedLength = ACPI_FADT_V2_SIZE;
    524         break;
    525 
    526     case 3:
    527     case 4:
    528 
    529         ExpectedLength = ACPI_FADT_V3_SIZE;
    530         break;
    531 
    532     case 5:
    533 
    534         ExpectedLength = ACPI_FADT_V5_SIZE;
    535         break;
    536 
    537     default:
    538 
    539         return;
    540     }
    541 
    542     if (Length == ExpectedLength)
    543     {
    544         return;
    545     }
    546 
    547     AcpiOsPrintf (
    548         "\n// ACPI Warning: FADT revision %X does not match length: "
    549         "found %X expected %X\n",
    550         Revision, Length, ExpectedLength);
    551 }
    552