summaryrefslogtreecommitdiff
path: root/src/soc
diff options
context:
space:
mode:
authorJulius Werner <jwerner@chromium.org>2024-01-30 16:51:05 -0800
committerJulius Werner <jwerner@chromium.org>2024-02-02 22:48:27 +0000
commitde37109767b6b415778f34cbac196c8418f7e371 (patch)
tree44ede1025fd6058c09cc99c8e7d7122a64203641 /src/soc
parent416cc665929e4e66bcab3e395daa031401a61fe8 (diff)
lib: Move IP checksum to commonlib
This patch moves the IP checksum algorithm into commonlib to prepare for it being shared with libpayload. The current implementation is ancient and pretty hard to read (and does some unnecessary questionable things like the type-punning stuff which leads to suboptimal code generation), so this reimplements it from scratch (that also helps with the licensing). This algorithm is prepared to take in a pre-calculated "wide" checksum in a machine-register-sized data type which is then narrowed down to 16 bits (see RFC 1071 for why that's valid). This isn't used yet (and the code will get optimized out), but will be used later in this patch series for architecture-specific optimization. Change-Id: Ic04c714c00439a17fc04a8a6e730cc2aa19b8e68 Signed-off-by: Julius Werner <jwerner@chromium.org> Reviewed-on: https://review.coreboot.org/c/coreboot/+/80251 Reviewed-by: Yidi Lin <yidilin@google.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Jakub Czapiga <czapiga@google.com>
Diffstat (limited to 'src/soc')
-rw-r--r--src/soc/intel/common/basecode/ramtop/ramtop.c7
-rw-r--r--src/soc/intel/common/block/cse/cse_lite_cmos.c7
-rw-r--r--src/soc/mediatek/common/memory.c1
-rw-r--r--src/soc/mediatek/mt8183/memory.c5
4 files changed, 8 insertions, 12 deletions
diff --git a/src/soc/intel/common/basecode/ramtop/ramtop.c b/src/soc/intel/common/basecode/ramtop/ramtop.c
index 90717e0025..ec326bb1c0 100644
--- a/src/soc/intel/common/basecode/ramtop/ramtop.c
+++ b/src/soc/intel/common/basecode/ramtop/ramtop.c
@@ -1,8 +1,8 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include <commonlib/bsd/ipchksum.h>
#include <console/console.h>
#include <cpu/x86/mtrr.h>
-#include <ip_checksum.h>
#include <intelbasecode/ramtop.h>
#include <pc80/mc146818rtc.h>
#include <stdint.h>
@@ -57,7 +57,7 @@ static int ramtop_cmos_read(struct ramtop_table *ramtop)
}
/* Verify checksum over signature and counter only */
- csum = compute_ip_checksum(ramtop, offsetof(struct ramtop_table, checksum));
+ csum = ipchksum(ramtop, offsetof(struct ramtop_table, checksum));
if (csum != ramtop->checksum) {
printk(BIOS_DEBUG, "ramtop_table checksum mismatch\n");
@@ -73,8 +73,7 @@ static void ramtop_cmos_write(struct ramtop_table *ramtop)
u8 i, *p;
/* Checksum over signature and counter only */
- ramtop->checksum = compute_ip_checksum(
- ramtop, offsetof(struct ramtop_table, checksum));
+ ramtop->checksum = ipchksum(ramtop, offsetof(struct ramtop_table, checksum));
for (p = (u8 *)ramtop, i = 0; i < sizeof(*ramtop); i++, p++)
cmos_write(*p, (CMOS_VSTART_ramtop / 8) + i);
diff --git a/src/soc/intel/common/block/cse/cse_lite_cmos.c b/src/soc/intel/common/block/cse/cse_lite_cmos.c
index 02d0232376..5c26c01360 100644
--- a/src/soc/intel/common/block/cse/cse_lite_cmos.c
+++ b/src/soc/intel/common/block/cse/cse_lite_cmos.c
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-only */
+#include <commonlib/bsd/ipchksum.h>
#include <console/console.h>
-#include <ip_checksum.h>
#include <pc80/mc146818rtc.h>
#include "cse_lite_cmos.h"
@@ -66,7 +66,7 @@ static int psr_backup_status_cmos_read(struct psr_backup_status *psr)
}
/* Verify checksum over signature and backup_status only */
- uint16_t csum = compute_ip_checksum(psr, offsetof(struct psr_backup_status, checksum));
+ uint16_t csum = ipchksum(psr, offsetof(struct psr_backup_status, checksum));
if (csum != psr->checksum) {
printk(BIOS_ERR, "PSR backup status checksum mismatch\n");
@@ -80,8 +80,7 @@ static int psr_backup_status_cmos_read(struct psr_backup_status *psr)
static void psr_backup_status_cmos_write(struct psr_backup_status *psr)
{
/* Checksum over signature and backup_status only */
- psr->checksum = compute_ip_checksum(
- psr, offsetof(struct psr_backup_status, checksum));
+ psr->checksum = ipchksum(psr, offsetof(struct psr_backup_status, checksum));
for (uint8_t *p = (uint8_t *)psr, i = 0; i < sizeof(*psr); i++, p++)
cmos_write(*p, PARTITION_FW_CMOS_OFFSET + sizeof(struct cse_specific_info) + i);
diff --git a/src/soc/mediatek/common/memory.c b/src/soc/mediatek/common/memory.c
index 1a627ddd35..be72023dac 100644
--- a/src/soc/mediatek/common/memory.c
+++ b/src/soc/mediatek/common/memory.c
@@ -6,7 +6,6 @@
#include <commonlib/bsd/mem_chip_info.h>
#include <console/console.h>
#include <soc/dramc_common.h>
-#include <ip_checksum.h>
#include <mrc_cache.h>
#include <soc/dramc_param.h>
#include <soc/emi.h>
diff --git a/src/soc/mediatek/mt8183/memory.c b/src/soc/mediatek/mt8183/memory.c
index a43cdea102..ca6f7a1850 100644
--- a/src/soc/mediatek/mt8183/memory.c
+++ b/src/soc/mediatek/mt8183/memory.c
@@ -3,8 +3,8 @@
#include <assert.h>
#include <bootmode.h>
#include <cbfs.h>
+#include <commonlib/bsd/ipchksum.h>
#include <console/console.h>
-#include <ip_checksum.h>
#include <security/vboot/vboot_common.h>
#include <soc/dramc_param.h>
#include <soc/dramc_pi_api.h>
@@ -63,8 +63,7 @@ static void dump_param_header(const struct dramc_param *dparam)
static u32 compute_checksum(const struct dramc_param *dparam)
{
- return (u32)compute_ip_checksum(dparam->freq_params,
- sizeof(dparam->freq_params));
+ return (u32)ipchksum(dparam->freq_params, sizeof(dparam->freq_params));
}
static int dram_run_fast_calibration(const struct dramc_param *dparam,