drm/panel: panel-himax-hx83102: support for csot-pna957qt1-1 MIPI-DSI panel
[drm/drm-misc.git] / drivers / acpi / acpica / utcksum.c
blobb483894c3629068c5ef558df83fe783b8c676f25
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>
11 #include "accommon.h"
12 #include "acutils.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
26 * RETURN: Status
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
32 * via ACPICA.
34 ******************************************************************************/
35 acpi_status acpi_ut_verify_checksum(struct acpi_table_header *table, u32 length)
37 u8 checksum;
40 * FACS/S3PT:
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)) {
45 return (AE_OK);
48 /* Compute the checksum on the table */
50 length = table->length;
51 checksum =
52 acpi_ut_generate_checksum(ACPI_CAST_PTR(u8, table), length,
53 table->checksum);
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, "
60 "should be 0x%2.2X",
61 table->signature, table->checksum,
62 table->checksum - checksum));
64 #if (ACPI_CHECKSUM_ABORT)
65 return (AE_BAD_CHECKSUM);
66 #endif
69 return (AE_OK);
72 /*******************************************************************************
74 * FUNCTION: acpi_ut_verify_cdat_checksum
76 * PARAMETERS: table - CDAT ACPI table to verify
77 * length - Length of entire table
79 * RETURN: Status
81 * DESCRIPTION: Verifies that the CDAT table checksums to zero. Optionally
82 * returns an exception on bad checksum.
84 ******************************************************************************/
86 acpi_status
87 acpi_ut_verify_cdat_checksum(struct acpi_table_cdat *cdat_table, u32 length)
89 u8 checksum;
91 /* Compute the checksum on the table */
93 checksum = acpi_ut_generate_checksum(ACPI_CAST_PTR(u8, cdat_table),
94 cdat_table->length,
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, "
102 "should be 0x%2.2X",
103 acpi_gbl_CDAT, cdat_table->checksum,
104 checksum));
106 #if (ACPI_CHECKSUM_ABORT)
107 return (AE_BAD_CHECKSUM);
108 #endif
111 cdat_table->checksum = checksum;
112 return (AE_OK);
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)
131 u8 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);
144 return (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)
162 u8 sum = 0;
163 u8 *end = buffer + length;
165 while (buffer < end) {
166 sum = (u8)(sum + *(buffer++));
169 return (sum);