Home | History | Annotate | Line # | Download | only in tables
tbprint.c revision 1.1.1.12
      1 /******************************************************************************
      2  *
      3  * Module Name: tbprint - Table output utilities
      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 "actables.h"
     47 
     48 #define _COMPONENT          ACPI_TABLES
     49         ACPI_MODULE_NAME    ("tbprint")
     50 
     51 
     52 /* Local prototypes */
     53 
     54 static void
     55 AcpiTbFixString (
     56     char                    *String,
     57     ACPI_SIZE               Length);
     58 
     59 static void
     60 AcpiTbCleanupTableHeader (
     61     ACPI_TABLE_HEADER       *OutHeader,
     62     ACPI_TABLE_HEADER       *Header);
     63 
     64 
     65 /*******************************************************************************
     66  *
     67  * FUNCTION:    AcpiTbFixString
     68  *
     69  * PARAMETERS:  String              - String to be repaired
     70  *              Length              - Maximum length
     71  *
     72  * RETURN:      None
     73  *
     74  * DESCRIPTION: Replace every non-printable or non-ascii byte in the string
     75  *              with a question mark '?'.
     76  *
     77  ******************************************************************************/
     78 
     79 static void
     80 AcpiTbFixString (
     81     char                    *String,
     82     ACPI_SIZE               Length)
     83 {
     84 
     85     while (Length && *String)
     86     {
     87         if (!isprint ((int) *String))
     88         {
     89             *String = '?';
     90         }
     91 
     92         String++;
     93         Length--;
     94     }
     95 }
     96 
     97 
     98 /*******************************************************************************
     99  *
    100  * FUNCTION:    AcpiTbCleanupTableHeader
    101  *
    102  * PARAMETERS:  OutHeader           - Where the cleaned header is returned
    103  *              Header              - Input ACPI table header
    104  *
    105  * RETURN:      Returns the cleaned header in OutHeader
    106  *
    107  * DESCRIPTION: Copy the table header and ensure that all "string" fields in
    108  *              the header consist of printable characters.
    109  *
    110  ******************************************************************************/
    111 
    112 static void
    113 AcpiTbCleanupTableHeader (
    114     ACPI_TABLE_HEADER       *OutHeader,
    115     ACPI_TABLE_HEADER       *Header)
    116 {
    117 
    118     memcpy (OutHeader, Header, sizeof (ACPI_TABLE_HEADER));
    119 
    120     AcpiTbFixString (OutHeader->Signature, ACPI_NAMESEG_SIZE);
    121     AcpiTbFixString (OutHeader->OemId, ACPI_OEM_ID_SIZE);
    122     AcpiTbFixString (OutHeader->OemTableId, ACPI_OEM_TABLE_ID_SIZE);
    123     AcpiTbFixString (OutHeader->AslCompilerId, ACPI_NAMESEG_SIZE);
    124 }
    125 
    126 
    127 /*******************************************************************************
    128  *
    129  * FUNCTION:    AcpiTbPrintTableHeader
    130  *
    131  * PARAMETERS:  Address             - Table physical address
    132  *              Header              - Table header
    133  *
    134  * RETURN:      None
    135  *
    136  * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP.
    137  *
    138  ******************************************************************************/
    139 
    140 void
    141 AcpiTbPrintTableHeader (
    142     ACPI_PHYSICAL_ADDRESS   Address,
    143     ACPI_TABLE_HEADER       *Header)
    144 {
    145     ACPI_TABLE_HEADER       LocalHeader;
    146 
    147 
    148     if (ACPI_COMPARE_NAMESEG (Header->Signature, ACPI_SIG_FACS))
    149     {
    150         /* FACS only has signature and length fields */
    151 
    152         ACPI_INFO (("%-4.4s 0x%8.8X%8.8X %06X",
    153             Header->Signature, ACPI_FORMAT_UINT64 (Address),
    154             Header->Length));
    155     }
    156     else if (ACPI_VALIDATE_RSDP_SIG (ACPI_CAST_PTR (ACPI_TABLE_RSDP,
    157         Header)->Signature))
    158     {
    159         /* RSDP has no common fields */
    160 
    161         memcpy (LocalHeader.OemId, ACPI_CAST_PTR (ACPI_TABLE_RSDP,
    162             Header)->OemId, ACPI_OEM_ID_SIZE);
    163         AcpiTbFixString (LocalHeader.OemId, ACPI_OEM_ID_SIZE);
    164 
    165         ACPI_INFO (("RSDP 0x%8.8X%8.8X %06X (v%.2d %-6.6s)",
    166             ACPI_FORMAT_UINT64 (Address),
    167             (ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->Revision > 0) ?
    168                 ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->Length : 20,
    169             ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->Revision,
    170             LocalHeader.OemId));
    171     }
    172     else
    173     {
    174         /* Standard ACPI table with full common header */
    175 
    176         AcpiTbCleanupTableHeader (&LocalHeader, Header);
    177 
    178         ACPI_INFO ((
    179             "%-4.4s 0x%8.8X%8.8X"
    180             " %06X (v%.2d %-6.6s %-8.8s %08X %-4.4s %08X)",
    181             LocalHeader.Signature, ACPI_FORMAT_UINT64 (Address),
    182             LocalHeader.Length, LocalHeader.Revision, LocalHeader.OemId,
    183             LocalHeader.OemTableId, LocalHeader.OemRevision,
    184             LocalHeader.AslCompilerId, LocalHeader.AslCompilerRevision));
    185     }
    186 }
    187 
    188 
    189 /*******************************************************************************
    190  *
    191  * FUNCTION:    AcpiTbValidateChecksum
    192  *
    193  * PARAMETERS:  Table               - ACPI table to verify
    194  *              Length              - Length of entire table
    195  *
    196  * RETURN:      Status
    197  *
    198  * DESCRIPTION: Verifies that the table checksums to zero. Optionally returns
    199  *              exception on bad checksum.
    200  *
    201  ******************************************************************************/
    202 
    203 ACPI_STATUS
    204 AcpiTbVerifyChecksum (
    205     ACPI_TABLE_HEADER       *Table,
    206     UINT32                  Length)
    207 {
    208     UINT8                   Checksum;
    209 
    210 
    211     /*
    212      * FACS/S3PT:
    213      * They are the odd tables, have no standard ACPI header and no checksum
    214      */
    215 
    216     if (ACPI_COMPARE_NAMESEG (Table->Signature, ACPI_SIG_S3PT) ||
    217         ACPI_COMPARE_NAMESEG (Table->Signature, ACPI_SIG_FACS))
    218     {
    219         return (AE_OK);
    220     }
    221 
    222     /* Compute the checksum on the table */
    223 
    224     Checksum = AcpiTbChecksum (ACPI_CAST_PTR (UINT8, Table), Length);
    225 
    226     /* Checksum ok? (should be zero) */
    227 
    228     if (Checksum)
    229     {
    230         ACPI_BIOS_WARNING ((AE_INFO,
    231             "Incorrect checksum in table [%4.4s] - 0x%2.2X, "
    232             "should be 0x%2.2X",
    233             Table->Signature, Table->Checksum,
    234             (UINT8) (Table->Checksum - Checksum)));
    235 
    236 #if (ACPI_CHECKSUM_ABORT)
    237         return (AE_BAD_CHECKSUM);
    238 #endif
    239     }
    240 
    241     return (AE_OK);
    242 }
    243 
    244 
    245 /*******************************************************************************
    246  *
    247  * FUNCTION:    AcpiTbChecksum
    248  *
    249  * PARAMETERS:  Buffer          - Pointer to memory region to be checked
    250  *              Length          - Length of this memory region
    251  *
    252  * RETURN:      Checksum (UINT8)
    253  *
    254  * DESCRIPTION: Calculates circular checksum of memory region.
    255  *
    256  ******************************************************************************/
    257 
    258 UINT8
    259 AcpiTbChecksum (
    260     UINT8                   *Buffer,
    261     UINT32                  Length)
    262 {
    263     UINT8                   Sum = 0;
    264     UINT8                   *End = Buffer + Length;
    265 
    266 
    267     while (Buffer < End)
    268     {
    269         Sum = (UINT8) (Sum + *(Buffer++));
    270     }
    271 
    272     return (Sum);
    273 }
    274