1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: tbprint - Table output utilities
6 * Copyright (C) 2000 - 2021, Intel Corp.
8 *****************************************************************************/
10 #include <acpi/acpi.h>
14 #define _COMPONENT ACPI_TABLES
15 ACPI_MODULE_NAME("tbprint")
17 /* Local prototypes */
18 static void acpi_tb_fix_string(char *string, acpi_size length);
21 acpi_tb_cleanup_table_header(struct acpi_table_header *out_header,
22 struct acpi_table_header *header);
24 /*******************************************************************************
26 * FUNCTION: acpi_tb_fix_string
28 * PARAMETERS: string - String to be repaired
29 * length - Maximum length
33 * DESCRIPTION: Replace every non-printable or non-ascii byte in the string
34 * with a question mark '?'.
36 ******************************************************************************/
38 static void acpi_tb_fix_string(char *string, acpi_size length)
41 while (length && *string) {
42 if (!isprint((int)*string)) {
51 /*******************************************************************************
53 * FUNCTION: acpi_tb_cleanup_table_header
55 * PARAMETERS: out_header - Where the cleaned header is returned
56 * header - Input ACPI table header
58 * RETURN: Returns the cleaned header in out_header
60 * DESCRIPTION: Copy the table header and ensure that all "string" fields in
61 * the header consist of printable characters.
63 ******************************************************************************/
66 acpi_tb_cleanup_table_header(struct acpi_table_header *out_header,
67 struct acpi_table_header *header)
70 memcpy(out_header, header, sizeof(struct acpi_table_header));
72 acpi_tb_fix_string(out_header->signature, ACPI_NAMESEG_SIZE);
73 acpi_tb_fix_string(out_header->oem_id, ACPI_OEM_ID_SIZE);
74 acpi_tb_fix_string(out_header->oem_table_id, ACPI_OEM_TABLE_ID_SIZE);
75 acpi_tb_fix_string(out_header->asl_compiler_id, ACPI_NAMESEG_SIZE);
78 /*******************************************************************************
80 * FUNCTION: acpi_tb_print_table_header
82 * PARAMETERS: address - Table physical address
83 * header - Table header
87 * DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP.
89 ******************************************************************************/
92 acpi_tb_print_table_header(acpi_physical_address address,
93 struct acpi_table_header *header)
95 struct acpi_table_header local_header;
97 if (ACPI_COMPARE_NAMESEG(header->signature, ACPI_SIG_FACS)) {
99 /* FACS only has signature and length fields */
101 ACPI_INFO(("%-4.4s 0x%8.8X%8.8X %06X",
102 header->signature, ACPI_FORMAT_UINT64(address),
104 } else if (ACPI_VALIDATE_RSDP_SIG(ACPI_CAST_PTR(struct acpi_table_rsdp,
105 header)->signature)) {
107 /* RSDP has no common fields */
109 memcpy(local_header.oem_id,
110 ACPI_CAST_PTR(struct acpi_table_rsdp, header)->oem_id,
112 acpi_tb_fix_string(local_header.oem_id, ACPI_OEM_ID_SIZE);
114 ACPI_INFO(("RSDP 0x%8.8X%8.8X %06X (v%.2d %-6.6s)",
115 ACPI_FORMAT_UINT64(address),
116 (ACPI_CAST_PTR(struct acpi_table_rsdp, header)->
118 0) ? ACPI_CAST_PTR(struct acpi_table_rsdp,
119 header)->length : 20,
120 ACPI_CAST_PTR(struct acpi_table_rsdp,
122 local_header.oem_id));
124 /* Standard ACPI table with full common header */
126 acpi_tb_cleanup_table_header(&local_header, header);
128 ACPI_INFO(("%-4.4s 0x%8.8X%8.8X"
129 " %06X (v%.2d %-6.6s %-8.8s %08X %-4.4s %08X)",
130 local_header.signature, ACPI_FORMAT_UINT64(address),
131 local_header.length, local_header.revision,
132 local_header.oem_id, local_header.oem_table_id,
133 local_header.oem_revision,
134 local_header.asl_compiler_id,
135 local_header.asl_compiler_revision));
139 /*******************************************************************************
141 * FUNCTION: acpi_tb_validate_checksum
143 * PARAMETERS: table - ACPI table to verify
144 * length - Length of entire table
148 * DESCRIPTION: Verifies that the table checksums to zero. Optionally returns
149 * exception on bad checksum.
151 ******************************************************************************/
153 acpi_status acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length)
159 * They are the odd tables, have no standard ACPI header and no checksum
162 if (ACPI_COMPARE_NAMESEG(table->signature, ACPI_SIG_S3PT) ||
163 ACPI_COMPARE_NAMESEG(table->signature, ACPI_SIG_FACS)) {
167 /* Compute the checksum on the table */
169 checksum = acpi_tb_checksum(ACPI_CAST_PTR(u8, table), length);
171 /* Checksum ok? (should be zero) */
174 ACPI_BIOS_WARNING((AE_INFO,
175 "Incorrect checksum in table [%4.4s] - 0x%2.2X, "
177 table->signature, table->checksum,
178 (u8)(table->checksum - checksum)));
180 #if (ACPI_CHECKSUM_ABORT)
181 return (AE_BAD_CHECKSUM);
188 /*******************************************************************************
190 * FUNCTION: acpi_tb_checksum
192 * PARAMETERS: buffer - Pointer to memory region to be checked
193 * length - Length of this memory region
195 * RETURN: Checksum (u8)
197 * DESCRIPTION: Calculates circular checksum of memory region.
199 ******************************************************************************/
201 u8 acpi_tb_checksum(u8 *buffer, u32 length)
204 u8 *end = buffer + length;
206 while (buffer < end) {
207 sum = (u8)(sum + *(buffer++));