1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: utcksum - Support generating table checksums
6 * Copyright (C) 2000 - 2023, Intel Corp.
8 *****************************************************************************/
10 #include <acpi/acpi.h>
14 /* This module used for application-level code only */
16 #define _COMPONENT ACPI_CA_DISASSEMBLER
17 ACPI_MODULE_NAME("utcksum")
19 /*******************************************************************************
21 * FUNCTION: acpi_ut_verify_checksum
23 * PARAMETERS: table - ACPI table to verify
24 * length - Length of entire table
28 * DESCRIPTION: Verifies that the table checksums to zero. Optionally returns
29 * exception on bad checksum.
30 * Note: We don't have to check for a CDAT here, since CDAT is
31 * not in the RSDT/XSDT, and the CDAT table is never installed
34 ******************************************************************************/
35 acpi_status acpi_ut_verify_checksum(struct acpi_table_header *table, u32 length)
41 * They are the odd tables, have no standard ACPI header and no checksum
43 if (ACPI_COMPARE_NAMESEG(table->signature, ACPI_SIG_S3PT) ||
44 ACPI_COMPARE_NAMESEG(table->signature, ACPI_SIG_FACS)) {
48 /* Compute the checksum on the table */
50 length = table->length;
52 acpi_ut_generate_checksum(ACPI_CAST_PTR(u8, table), length,
55 /* Computed checksum matches table? */
57 if (checksum != table->checksum) {
58 ACPI_BIOS_WARNING((AE_INFO,
59 "Incorrect checksum in table [%4.4s] - 0x%2.2X, "
61 table->signature, table->checksum,
62 table->checksum - checksum));
64 #if (ACPI_CHECKSUM_ABORT)
65 return (AE_BAD_CHECKSUM);
72 /*******************************************************************************
74 * FUNCTION: acpi_ut_verify_cdat_checksum
76 * PARAMETERS: table - CDAT ACPI table to verify
77 * length - Length of entire table
81 * DESCRIPTION: Verifies that the CDAT table checksums to zero. Optionally
82 * returns an exception on bad checksum.
84 ******************************************************************************/
87 acpi_ut_verify_cdat_checksum(struct acpi_table_cdat *cdat_table, u32 length)
91 /* Compute the checksum on the table */
93 checksum = acpi_ut_generate_checksum(ACPI_CAST_PTR(u8, cdat_table),
95 cdat_table->checksum);
97 /* Computed checksum matches table? */
99 if (checksum != cdat_table->checksum) {
100 ACPI_BIOS_WARNING((AE_INFO,
101 "Incorrect checksum in table [%4.4s] - 0x%2.2X, "
103 acpi_gbl_CDAT, cdat_table->checksum,
106 #if (ACPI_CHECKSUM_ABORT)
107 return (AE_BAD_CHECKSUM);
111 cdat_table->checksum = checksum;
115 /*******************************************************************************
117 * FUNCTION: acpi_ut_generate_checksum
119 * PARAMETERS: table - Pointer to table to be checksummed
120 * length - Length of the table
121 * original_checksum - Value of the checksum field
123 * RETURN: 8 bit checksum of buffer
125 * DESCRIPTION: Computes an 8 bit checksum of the table.
127 ******************************************************************************/
129 u8 acpi_ut_generate_checksum(void *table, u32 length, u8 original_checksum)
133 /* Sum the entire table as-is */
135 checksum = acpi_ut_checksum((u8 *)table, length);
137 /* Subtract off the existing checksum value in the table */
139 checksum = (u8)(checksum - original_checksum);
141 /* Compute and return the final checksum */
143 checksum = (u8)(0 - checksum);
147 /*******************************************************************************
149 * FUNCTION: acpi_ut_checksum
151 * PARAMETERS: buffer - Pointer to memory region to be checked
152 * length - Length of this memory region
154 * RETURN: Checksum (u8)
156 * DESCRIPTION: Calculates circular checksum of memory region.
158 ******************************************************************************/
160 u8 acpi_ut_checksum(u8 *buffer, u32 length)
163 u8 *end = buffer + length;
165 while (buffer < end) {
166 sum = (u8)(sum + *(buffer++));