| 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: tbprint - Table output utilities |
| 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
| 8 | * Copyright (C) 2000 - 2026, 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 | #include "acdisasm.h" |
| 48 | #include "acutils.h" |
| 49 | |
| 50 | #define _COMPONENT ACPI_TABLES |
| 51 | ACPI_MODULE_NAME ("tbprint") |
| 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 | |
| 67 | /******************************************************************************* |
| 68 | * |
| 69 | * FUNCTION: AcpiTbFixString |
| 70 | * |
| 71 | * PARAMETERS: String - String to be repaired |
| 72 | * Length - Maximum length |
| 73 | * |
| 74 | * RETURN: None |
| 75 | * |
| 76 | * DESCRIPTION: Replace every non-printable or non-ascii byte in the string |
| 77 | * with a question mark '?'. |
| 78 | * |
| 79 | ******************************************************************************/ |
| 80 | |
| 81 | static void |
| 82 | AcpiTbFixString ( |
| 83 | char *String, |
| 84 | ACPI_SIZE Length) |
| 85 | { |
| 86 | |
| 87 | while (Length && *String) |
| 88 | { |
| 89 | if (!isprint ((int) (UINT8) *String)) |
| 90 | { |
| 91 | *String = '?'; |
| 92 | } |
| 93 | |
| 94 | String++; |
| 95 | Length--; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | |
| 100 | /******************************************************************************* |
| 101 | * |
| 102 | * FUNCTION: AcpiTbCleanupTableHeader |
| 103 | * |
| 104 | * PARAMETERS: OutHeader - Where the cleaned header is returned |
| 105 | * Header - Input ACPI table header |
| 106 | * |
| 107 | * RETURN: Returns the cleaned header in OutHeader |
| 108 | * |
| 109 | * DESCRIPTION: Copy the table header and ensure that all "string" fields in |
| 110 | * the header consist of printable characters. |
| 111 | * |
| 112 | ******************************************************************************/ |
| 113 | |
| 114 | static void |
| 115 | AcpiTbCleanupTableHeader ( |
| 116 | ACPI_TABLE_HEADER *OutHeader, |
| 117 | ACPI_TABLE_HEADER *Header) |
| 118 | { |
| 119 | |
| 120 | memcpy (OutHeader, Header, sizeof (ACPI_TABLE_HEADER)); |
| 121 | |
| 122 | AcpiTbFixString (OutHeader->Signature, ACPI_NAMESEG_SIZE); |
| 123 | AcpiTbFixString (OutHeader->OemId, ACPI_OEM_ID_SIZE); |
| 124 | AcpiTbFixString (OutHeader->OemTableId, ACPI_OEM_TABLE_ID_SIZE); |
| 125 | AcpiTbFixString (OutHeader->AslCompilerId, ACPI_NAMESEG_SIZE); |
| 126 | } |
| 127 | |
| 128 | |
| 129 | /******************************************************************************* |
| 130 | * |
| 131 | * FUNCTION: AcpiTbPrintTableHeader |
| 132 | * |
| 133 | * PARAMETERS: Address - Table physical address |
| 134 | * Header - Table header |
| 135 | * |
| 136 | * RETURN: None |
| 137 | * |
| 138 | * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP. |
| 139 | * |
| 140 | ******************************************************************************/ |
| 141 | |
| 142 | void |
| 143 | AcpiTbPrintTableHeader ( |
| 144 | ACPI_PHYSICAL_ADDRESS Address, |
| 145 | ACPI_TABLE_HEADER *Header) |
| 146 | { |
| 147 | ACPI_TABLE_HEADER LocalHeader; |
| 148 | |
| 149 | #pragma GCC diagnostic push |
| 150 | #if defined(__GNUC__) && __GNUC__ >= 11 |
| 151 | #pragma GCC diagnostic ignored "-Wstringop-overread" |
| 152 | #endif |
| 153 | |
| 154 | if (ACPI_COMPARE_NAMESEG (Header->Signature, ACPI_SIG_FACS)) |
| 155 | { |
| 156 | /* FACS only has signature and length fields */ |
| 157 | |
| 158 | ACPI_INFO (("%-4.4s 0x%8.8X%8.8X %06X", |
| 159 | Header->Signature, ACPI_FORMAT_UINT64 (Address), |
| 160 | Header->Length)); |
| 161 | } |
| 162 | else if (ACPI_VALIDATE_RSDP_SIG (ACPI_CAST_PTR (ACPI_TABLE_RSDP, |
| 163 | Header)->Signature)) |
| 164 | { |
| 165 | /* RSDP has no common fields */ |
| 166 | |
| 167 | memcpy (LocalHeader.OemId, ACPI_CAST_PTR (ACPI_TABLE_RSDP, |
| 168 | Header)->OemId, ACPI_OEM_ID_SIZE); |
| 169 | AcpiTbFixString (LocalHeader.OemId, ACPI_OEM_ID_SIZE); |
| 170 | |
| 171 | ACPI_INFO (("RSDP 0x%8.8X%8.8X %06X (v%.2d %-6.6s)", |
| 172 | ACPI_FORMAT_UINT64 (Address), |
| 173 | (ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->Revision > 0) ? |
| 174 | ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->Length : 20, |
| 175 | ACPI_CAST_PTR (ACPI_TABLE_RSDP, Header)->Revision, |
| 176 | LocalHeader.OemId)); |
| 177 | } |
| 178 | else if (AcpiGbl_CDAT && !AcpiUtValidNameseg (Header->Signature)) |
| 179 | { |
| 180 | /* CDAT does not use the common ACPI table header */ |
| 181 | |
| 182 | ACPI_INFO (("%-4.4s 0x%8.8X%8.8X %06X", |
| 183 | ACPI_SIG_CDAT, ACPI_FORMAT_UINT64 (Address), |
| 184 | ACPI_CAST_PTR (ACPI_TABLE_CDAT, Header)->Length)); |
| 185 | } |
| 186 | else |
| 187 | { |
| 188 | /* Standard ACPI table with full common header */ |
| 189 | |
| 190 | AcpiTbCleanupTableHeader (&LocalHeader, Header); |
| 191 | |
| 192 | ACPI_INFO (( |
| 193 | "%-4.4s 0x%8.8X%8.8X" |
| 194 | " %06X (v%.2d %-6.6s %-8.8s %08X %-4.4s %08X)", |
| 195 | LocalHeader.Signature, ACPI_FORMAT_UINT64 (Address), |
| 196 | LocalHeader.Length, LocalHeader.Revision, LocalHeader.OemId, |
| 197 | LocalHeader.OemTableId, LocalHeader.OemRevision, |
| 198 | LocalHeader.AslCompilerId, LocalHeader.AslCompilerRevision)); |
| 199 | } |
| 200 | #pragma GCC diagnostic pop |
| 201 | } |