[PATCH 2/2] ACPI: LoongArch: Add checksum support with IOVT table

From: Bibo Mao

Date: Tue Nov 10 2026 - 04:22:05 EST


Checksum information is put in acpi_table_header, here add
checksum support with IOVT table.

Signed-off-by: Bibo Mao <maobibo@xxxxxxxxxxx>
---
drivers/acpi/loongarch/iovt.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)

diff --git a/drivers/acpi/loongarch/iovt.c b/drivers/acpi/loongarch/iovt.c
index 6c5bcb4df7d8..c9830ba46729 100644
--- a/drivers/acpi/loongarch/iovt.c
+++ b/drivers/acpi/loongarch/iovt.c
@@ -20,6 +20,7 @@ struct iovt_fwnode {

static LIST_HEAD(iovt_fwnode_list);
static DEFINE_SPINLOCK(iovt_fwnode_lock);
+static bool checksum_valid;

#ifdef CONFIG_PCI
static void __init iovt_enable_acs(struct acpi_iovt_iommu *iommu)
@@ -168,6 +169,17 @@ static void __init iovt_init_devices(struct acpi_table_header *header)
}
}

+/* Come from acpi_ut_checksum */
+static unsigned char acpi_iovt_checksum(unsigned char *buffer, unsigned int len)
+{
+ unsigned char sum = 0, *end = buffer + len;
+
+ while (buffer < end)
+ sum += *buffer++;
+
+ return sum;
+}
+
void __init acpi_iovt_init(void)
{
int i;
@@ -184,6 +196,13 @@ void __init acpi_iovt_init(void)
return;
}

+ if (acpi_iovt_checksum((unsigned char *)hdr, hdr->length)) {
+ pr_err("IOVT invalid checksum\n");
+ acpi_put_table(hdr);
+ return;
+ }
+
+ checksum_valid = true;
iovt = (struct acpi_table_iovt *)hdr;
iommu = ACPI_ADD_PTR(struct acpi_iovt_iommu, iovt, iovt->iommu_offset);
for (i = 0; i < iovt->iommu_count; i++) {
@@ -199,6 +218,9 @@ void __init acpi_iovt_late_init(void)
acpi_status status;
struct acpi_table_header *hdr;

+ if (!checksum_valid)
+ return;
+
status = acpi_get_table(ACPI_SIG_IOVT, 0, &hdr);
if (ACPI_FAILURE(status)) {
if (status != AE_NOT_FOUND)
--
2.39.3