acpi: simplify updating header checksum

Use acpi_update_checksum() for updating ACPI table header checksum.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Matthias Brugger <mbrugger@suse.com>
This commit is contained in:
Heinrich Schuchardt 2025-03-22 00:21:17 +01:00 committed by Tom Rini
parent 69e61d46d2
commit bbc78592b1
5 changed files with 12 additions and 18 deletions

View file

@ -195,9 +195,7 @@ int acpi_add_table(struct acpi_ctx *ctx, void *table)
(sizeof(u32) * (i + 1)); (sizeof(u32) * (i + 1));
/* Re-calculate checksum */ /* Re-calculate checksum */
rsdt->header.checksum = 0; acpi_update_checksum(&rsdt->header);
rsdt->header.checksum = table_compute_checksum((u8 *)rsdt,
rsdt->header.length);
} }
if (ctx->xsdt) { if (ctx->xsdt) {
@ -228,9 +226,7 @@ int acpi_add_table(struct acpi_ctx *ctx, void *table)
(sizeof(u64) * (i + 1)); (sizeof(u64) * (i + 1));
/* Re-calculate checksum */ /* Re-calculate checksum */
xsdt->header.checksum = 0; acpi_update_checksum(&xsdt->header);
xsdt->header.checksum = table_compute_checksum((u8 *)xsdt,
xsdt->header.length);
} }
return 0; return 0;
@ -268,7 +264,7 @@ int acpi_write_fadt(struct acpi_ctx *ctx, const struct acpi_writer *entry)
acpi_fill_fadt(fadt); acpi_fill_fadt(fadt);
header->checksum = table_compute_checksum(fadt, header->length); acpi_update_checksum(header);
return acpi_add_fadt(ctx, fadt); return acpi_add_fadt(ctx, fadt);
} }
@ -303,7 +299,7 @@ int acpi_write_madt(struct acpi_ctx *ctx, const struct acpi_writer *entry)
if (IS_ENABLED(CONFIG_ACPI_PARKING_PROTOCOL)) if (IS_ENABLED(CONFIG_ACPI_PARKING_PROTOCOL))
acpi_write_park(madt); acpi_write_park(madt);
header->checksum = table_compute_checksum((void *)madt, header->length); acpi_update_checksum(header);
acpi_add_table(ctx, madt); acpi_add_table(ctx, madt);
ctx->current = (void *)madt + madt->header.length; ctx->current = (void *)madt + madt->header.length;
@ -374,7 +370,7 @@ void acpi_create_dbg2(struct acpi_dbg2_header *dbg2,
/* Update structure lengths and checksum */ /* Update structure lengths and checksum */
device->length = current - (uintptr_t)device; device->length = current - (uintptr_t)device;
header->length = current - (uintptr_t)dbg2; header->length = current - (uintptr_t)dbg2;
header->checksum = table_compute_checksum(dbg2, header->length); acpi_update_checksum(header);
} }
int acpi_write_dbg2_pci_uart(struct acpi_ctx *ctx, struct udevice *dev, int acpi_write_dbg2_pci_uart(struct acpi_ctx *ctx, struct udevice *dev,
@ -549,7 +545,7 @@ static int acpi_write_spcr(struct acpi_ctx *ctx, const struct acpi_writer *entry
spcr->baud_rate = 0; spcr->baud_rate = 0;
/* Fix checksum */ /* Fix checksum */
header->checksum = table_compute_checksum((void *)spcr, header->length); acpi_update_checksum(header);
acpi_add_table(ctx, spcr); acpi_add_table(ctx, spcr);
acpi_inc(ctx, spcr->header.length); acpi_inc(ctx, spcr->header.length);
@ -759,7 +755,7 @@ static int acpi_write_iort(struct acpi_ctx *ctx, const struct acpi_writer *entry
/* (Re)calculate length and checksum */ /* (Re)calculate length and checksum */
iort->header.length = ctx->current - (void *)iort; iort->header.length = ctx->current - (void *)iort;
iort->header.checksum = table_compute_checksum((void *)iort, iort->header.length); acpi_update_checksum(&iort->header);
log_debug("IORT at %p, length %x\n", iort, iort->header.length); log_debug("IORT at %p, length %x\n", iort, iort->header.length);
/* Drop the table if it is empty */ /* Drop the table if it is empty */

View file

@ -50,8 +50,7 @@ static void acpi_write_rsdt(struct acpi_rsdt *rsdt)
/* Entries are filled in later, we come with an empty set */ /* Entries are filled in later, we come with an empty set */
/* Fix checksum */ /* Fix checksum */
header->checksum = table_compute_checksum(rsdt, acpi_update_checksum(header);
sizeof(struct acpi_rsdt));
} }
static void acpi_write_xsdt(struct acpi_xsdt *xsdt) static void acpi_write_xsdt(struct acpi_xsdt *xsdt)
@ -66,8 +65,7 @@ static void acpi_write_xsdt(struct acpi_xsdt *xsdt)
/* Entries are filled in later, we come with an empty set */ /* Entries are filled in later, we come with an empty set */
/* Fix checksum */ /* Fix checksum */
header->checksum = table_compute_checksum(xsdt, acpi_update_checksum(header);
sizeof(struct acpi_xsdt));
} }
static int acpi_write_base(struct acpi_ctx *ctx, static int acpi_write_base(struct acpi_ctx *ctx,

View file

@ -40,7 +40,7 @@ int acpi_write_csrt(struct acpi_ctx *ctx, const struct acpi_writer *entry)
/* (Re)calculate length and checksum */ /* (Re)calculate length and checksum */
header->length = (ulong)ctx->current - (ulong)csrt; header->length = (ulong)ctx->current - (ulong)csrt;
header->checksum = table_compute_checksum(csrt, header->length); acpi_update_checksum(header);
acpi_add_table(ctx, csrt); acpi_add_table(ctx, csrt);

View file

@ -57,7 +57,7 @@ int acpi_write_mcfg(struct acpi_ctx *ctx, const struct acpi_writer *entry)
/* (Re)calculate length and checksum */ /* (Re)calculate length and checksum */
header->length = (ulong)ctx->current - (ulong)mcfg; header->length = (ulong)ctx->current - (ulong)mcfg;
header->checksum = table_compute_checksum(mcfg, header->length); acpi_update_checksum(header);
acpi_add_table(ctx, mcfg); acpi_add_table(ctx, mcfg);

View file

@ -35,7 +35,7 @@ int acpi_write_ssdt(struct acpi_ctx *ctx, const struct acpi_writer *entry)
/* (Re)calculate length and checksum */ /* (Re)calculate length and checksum */
ssdt->length = ctx->current - (void *)ssdt; ssdt->length = ctx->current - (void *)ssdt;
ssdt->checksum = table_compute_checksum((void *)ssdt, ssdt->length); acpi_update_checksum(ssdt);
log_debug("SSDT at %p, length %x\n", ssdt, ssdt->length); log_debug("SSDT at %p, length %x\n", ssdt, ssdt->length);
/* Drop the table if it is empty */ /* Drop the table if it is empty */