U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] acpi: simplify updating ACPI table header checksum
@ 2025-03-21 23:21 Heinrich Schuchardt
  2025-03-21 23:21 ` [PATCH 1/5] acpi: new function acpi_update_checksum() Heinrich Schuchardt
                   ` (5 more replies)
  0 siblings, 6 replies; 16+ messages in thread
From: Heinrich Schuchardt @ 2025-03-21 23:21 UTC (permalink / raw)
  To: Simon Glass
  Cc: Matthias Brugger, Peter Robinson, Tom Rini, Bin Meng,
	Patrick Rudolph, Maximilian Brune, Fiona Klute, Martin Stolpe,
	Rasmus Villemoes, Ilias Apalodimas, Moritz Fischer, u-boot,
	Heinrich Schuchardt

Introduce a new function to update ACPI table headers.
This allows to simplify the existing code.

Heinrich Schuchardt (5):
  acpi: new function acpi_update_checksum()
  acpi: simplify updating header checksum
  x86/acpi: simplify updating header checksum
  qemu-sbsa: simplify updating ACPI table header checksum
  arm: simplify updating ACPI table header checksum

 arch/arm/mach-bcm283x/bcm2711_acpi.c |  4 ++--
 arch/x86/cpu/apollolake/hostbridge.c |  2 +-
 arch/x86/lib/acpi_nhlt.c             |  2 +-
 arch/x86/lib/acpi_table.c            | 11 ++++-------
 board/emulation/qemu-sbsa/acpi.c     |  4 ++--
 board/raspberrypi/rpi/rpi.c          |  2 +-
 include/acpi/acpi_table.h            |  7 +++++++
 lib/acpi/acpi.c                      |  7 +++++++
 lib/acpi/acpi_table.c                | 18 +++++++-----------
 lib/acpi/base.c                      |  6 ++----
 lib/acpi/csrt.c                      |  2 +-
 lib/acpi/mcfg.c                      |  2 +-
 lib/acpi/ssdt.c                      |  2 +-
 13 files changed, 37 insertions(+), 32 deletions(-)

-- 
2.48.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 1/5] acpi: new function acpi_update_checksum()
  2025-03-21 23:21 [PATCH 0/5] acpi: simplify updating ACPI table header checksum Heinrich Schuchardt
@ 2025-03-21 23:21 ` Heinrich Schuchardt
  2025-03-25 14:49   ` Matthias Brugger
  2025-03-26  7:29   ` Ilias Apalodimas
  2025-03-21 23:21 ` [PATCH 2/5] acpi: simplify updating header checksum Heinrich Schuchardt
                   ` (4 subsequent siblings)
  5 siblings, 2 replies; 16+ messages in thread
From: Heinrich Schuchardt @ 2025-03-21 23:21 UTC (permalink / raw)
  To: Simon Glass
  Cc: Matthias Brugger, Peter Robinson, Tom Rini, Bin Meng,
	Patrick Rudolph, Maximilian Brune, Fiona Klute, Martin Stolpe,
	Rasmus Villemoes, Ilias Apalodimas, Moritz Fischer, u-boot,
	Heinrich Schuchardt

Introduce a new function to update ACPI table headers.
This allows to simplify the existing code.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
 include/acpi/acpi_table.h | 7 +++++++
 lib/acpi/acpi.c           | 7 +++++++
 2 files changed, 14 insertions(+)

diff --git a/include/acpi/acpi_table.h b/include/acpi/acpi_table.h
index b8b1f1338c6..f8e5f552ab1 100644
--- a/include/acpi/acpi_table.h
+++ b/include/acpi/acpi_table.h
@@ -1274,6 +1274,13 @@ ulong write_acpi_tables(ulong start);
  */
 struct acpi_table_header *acpi_find_table(const char *sig);
 
+/**
+ * acpi_update_checksum() - update ACPI table checksum
+ *
+ * @header - header of an ACPI table
+ */
+void acpi_update_checksum(struct acpi_table_header *header);
+
 #endif /* !__ACPI__*/
 
 #include <asm/acpi_table.h>
diff --git a/lib/acpi/acpi.c b/lib/acpi/acpi.c
index f4d5c1e25d0..596301a43fe 100644
--- a/lib/acpi/acpi.c
+++ b/lib/acpi/acpi.c
@@ -6,11 +6,18 @@
  */
 
 #include <mapmem.h>
+#include <tables_csum.h>
 #include <acpi/acpi_table.h>
 #include <asm/global_data.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
+void acpi_update_checksum(struct acpi_table_header *header)
+{
+	header->checksum = 0;
+	header->checksum = table_compute_checksum(header, header->length);
+}
+
 struct acpi_table_header *acpi_find_table(const char *sig)
 {
 	struct acpi_rsdp *rsdp;
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 2/5] acpi: simplify updating header checksum
  2025-03-21 23:21 [PATCH 0/5] acpi: simplify updating ACPI table header checksum Heinrich Schuchardt
  2025-03-21 23:21 ` [PATCH 1/5] acpi: new function acpi_update_checksum() Heinrich Schuchardt
@ 2025-03-21 23:21 ` Heinrich Schuchardt
  2025-03-25 14:55   ` Matthias Brugger
  2025-03-26  7:30   ` Ilias Apalodimas
  2025-03-21 23:21 ` [PATCH 3/5] x86/acpi: " Heinrich Schuchardt
                   ` (3 subsequent siblings)
  5 siblings, 2 replies; 16+ messages in thread
From: Heinrich Schuchardt @ 2025-03-21 23:21 UTC (permalink / raw)
  To: Simon Glass
  Cc: Matthias Brugger, Peter Robinson, Tom Rini, Bin Meng,
	Patrick Rudolph, Maximilian Brune, Fiona Klute, Martin Stolpe,
	Rasmus Villemoes, Ilias Apalodimas, Moritz Fischer, u-boot,
	Heinrich Schuchardt

Use acpi_update_checksum() for updating ACPI table header checksum.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
 lib/acpi/acpi_table.c | 18 +++++++-----------
 lib/acpi/base.c       |  6 ++----
 lib/acpi/csrt.c       |  2 +-
 lib/acpi/mcfg.c       |  2 +-
 lib/acpi/ssdt.c       |  2 +-
 5 files changed, 12 insertions(+), 18 deletions(-)

diff --git a/lib/acpi/acpi_table.c b/lib/acpi/acpi_table.c
index c0ed24984af..b5495d48a46 100644
--- a/lib/acpi/acpi_table.c
+++ b/lib/acpi/acpi_table.c
@@ -195,9 +195,7 @@ int acpi_add_table(struct acpi_ctx *ctx, void *table)
 					(sizeof(u32) * (i + 1));
 
 		/* Re-calculate checksum */
-		rsdt->header.checksum = 0;
-		rsdt->header.checksum = table_compute_checksum((u8 *)rsdt,
-							       rsdt->header.length);
+		acpi_update_checksum(&rsdt->header);
 	}
 
 	if (ctx->xsdt) {
@@ -228,9 +226,7 @@ int acpi_add_table(struct acpi_ctx *ctx, void *table)
 					(sizeof(u64) * (i + 1));
 
 		/* Re-calculate checksum */
-		xsdt->header.checksum = 0;
-		xsdt->header.checksum = table_compute_checksum((u8 *)xsdt,
-							       xsdt->header.length);
+		acpi_update_checksum(&xsdt->header);
 	}
 
 	return 0;
@@ -268,7 +264,7 @@ int acpi_write_fadt(struct acpi_ctx *ctx, const struct acpi_writer *entry)
 
 	acpi_fill_fadt(fadt);
 
-	header->checksum = table_compute_checksum(fadt, header->length);
+	acpi_update_checksum(header);
 
 	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))
 		acpi_write_park(madt);
 
-	header->checksum = table_compute_checksum((void *)madt, header->length);
+	acpi_update_checksum(header);
 	acpi_add_table(ctx, madt);
 	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 */
 	device->length = current - (uintptr_t)device;
 	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,
@@ -549,7 +545,7 @@ static int acpi_write_spcr(struct acpi_ctx *ctx, const struct acpi_writer *entry
 		spcr->baud_rate = 0;
 
 	/* Fix checksum */
-	header->checksum = table_compute_checksum((void *)spcr, header->length);
+	acpi_update_checksum(header);
 
 	acpi_add_table(ctx, spcr);
 	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 */
 	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);
 
 	/* Drop the table if it is empty */
diff --git a/lib/acpi/base.c b/lib/acpi/base.c
index 8b6af2bc43a..5c755b14c16 100644
--- a/lib/acpi/base.c
+++ b/lib/acpi/base.c
@@ -50,8 +50,7 @@ static void acpi_write_rsdt(struct acpi_rsdt *rsdt)
 	/* Entries are filled in later, we come with an empty set */
 
 	/* Fix checksum */
-	header->checksum = table_compute_checksum(rsdt,
-						  sizeof(struct acpi_rsdt));
+	acpi_update_checksum(header);
 }
 
 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 */
 
 	/* Fix checksum */
-	header->checksum = table_compute_checksum(xsdt,
-						  sizeof(struct acpi_xsdt));
+	acpi_update_checksum(header);
 }
 
 static int acpi_write_base(struct acpi_ctx *ctx,
diff --git a/lib/acpi/csrt.c b/lib/acpi/csrt.c
index 00927e53406..b863c644c07 100644
--- a/lib/acpi/csrt.c
+++ b/lib/acpi/csrt.c
@@ -40,7 +40,7 @@ int acpi_write_csrt(struct acpi_ctx *ctx, const struct acpi_writer *entry)
 
 	/* (Re)calculate length and checksum */
 	header->length = (ulong)ctx->current - (ulong)csrt;
-	header->checksum = table_compute_checksum(csrt, header->length);
+	acpi_update_checksum(header);
 
 	acpi_add_table(ctx, csrt);
 
diff --git a/lib/acpi/mcfg.c b/lib/acpi/mcfg.c
index 8b8a5bfafae..e21fe7ce123 100644
--- a/lib/acpi/mcfg.c
+++ b/lib/acpi/mcfg.c
@@ -57,7 +57,7 @@ int acpi_write_mcfg(struct acpi_ctx *ctx, const struct acpi_writer *entry)
 
 	/* (Re)calculate length and checksum */
 	header->length = (ulong)ctx->current - (ulong)mcfg;
-	header->checksum = table_compute_checksum(mcfg, header->length);
+	acpi_update_checksum(header);
 
 	acpi_add_table(ctx, mcfg);
 
diff --git a/lib/acpi/ssdt.c b/lib/acpi/ssdt.c
index df1d739d117..41e2d3c2f6c 100644
--- a/lib/acpi/ssdt.c
+++ b/lib/acpi/ssdt.c
@@ -35,7 +35,7 @@ int acpi_write_ssdt(struct acpi_ctx *ctx, const struct acpi_writer *entry)
 
 	/* (Re)calculate length and checksum */
 	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);
 
 	/* Drop the table if it is empty */
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 3/5] x86/acpi: simplify updating header checksum
  2025-03-21 23:21 [PATCH 0/5] acpi: simplify updating ACPI table header checksum Heinrich Schuchardt
  2025-03-21 23:21 ` [PATCH 1/5] acpi: new function acpi_update_checksum() Heinrich Schuchardt
  2025-03-21 23:21 ` [PATCH 2/5] acpi: simplify updating header checksum Heinrich Schuchardt
@ 2025-03-21 23:21 ` Heinrich Schuchardt
  2025-03-25 14:58   ` Matthias Brugger
  2025-03-21 23:21 ` [PATCH 4/5] qemu-sbsa: simplify updating ACPI table " Heinrich Schuchardt
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 16+ messages in thread
From: Heinrich Schuchardt @ 2025-03-21 23:21 UTC (permalink / raw)
  To: Simon Glass
  Cc: Matthias Brugger, Peter Robinson, Tom Rini, Bin Meng,
	Patrick Rudolph, Maximilian Brune, Fiona Klute, Martin Stolpe,
	Rasmus Villemoes, Ilias Apalodimas, Moritz Fischer, u-boot,
	Heinrich Schuchardt

Use acpi_update_checksum() for updating ACPI table header checksum.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
 arch/x86/cpu/apollolake/hostbridge.c |  2 +-
 arch/x86/lib/acpi_nhlt.c             |  2 +-
 arch/x86/lib/acpi_table.c            | 11 ++++-------
 3 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/arch/x86/cpu/apollolake/hostbridge.c b/arch/x86/cpu/apollolake/hostbridge.c
index 039236df02d..284f16cfd91 100644
--- a/arch/x86/cpu/apollolake/hostbridge.c
+++ b/arch/x86/cpu/apollolake/hostbridge.c
@@ -298,7 +298,7 @@ static int apl_acpi_hb_write_tables(const struct udevice *dev,
 
 	/* (Re)calculate length and checksum */
 	header->length = ctx->current - (void *)dmar;
-	header->checksum = table_compute_checksum((void *)dmar, header->length);
+	acpi_update_checksum(header);
 
 	acpi_align(ctx);
 	acpi_add_table(ctx, dmar);
diff --git a/arch/x86/lib/acpi_nhlt.c b/arch/x86/lib/acpi_nhlt.c
index 880ef31df7d..8aae5fa5af7 100644
--- a/arch/x86/lib/acpi_nhlt.c
+++ b/arch/x86/lib/acpi_nhlt.c
@@ -414,7 +414,7 @@ int nhlt_serialise_oem_overrides(struct acpi_ctx *ctx, struct nhlt *nhlt,
 	cur.start = (void *)header;
 	nhlt_serialise_endpoints(nhlt, &cur);
 
-	header->checksum = table_compute_checksum(header, sz);
+	acpi_update_checksum(header);
 	nhlt_free_resources(nhlt);
 	assert(cur.buf - cur.start == sz);
 
diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c
index 3186e48d63b..b13292c4150 100644
--- a/arch/x86/lib/acpi_table.c
+++ b/arch/x86/lib/acpi_table.c
@@ -173,7 +173,7 @@ int acpi_write_tcpa(struct acpi_ctx *ctx, const struct acpi_writer *entry)
 	/* (Re)calculate length and checksum */
 	current = (u32)tcpa + sizeof(struct acpi_tcpa);
 	header->length = current - (u32)tcpa;
-	header->checksum = table_compute_checksum(tcpa, header->length);
+	acpi_update_checksum(header);
 
 	acpi_inc(ctx, tcpa->header.length);
 	acpi_add_table(ctx, tcpa);
@@ -242,7 +242,7 @@ static int acpi_write_tpm2(struct acpi_ctx *ctx,
 	tpm2->lasa = nomap_to_sysmem(lasa);
 
 	/* Calculate checksum. */
-	header->checksum = table_compute_checksum(tpm2, header->length);
+	acpi_update_checksum(header);
 
 	acpi_inc(ctx, tpm2->header.length);
 	acpi_add_table(ctx, tpm2);
@@ -279,9 +279,7 @@ int acpi_write_gnvs(struct acpi_ctx *ctx, const struct acpi_writer *entry)
 		 * patched the GNVS address. Set the checksum to zero since it
 		 * is part of the region being checksummed.
 		 */
-		ctx->dsdt->checksum = 0;
-		ctx->dsdt->checksum = table_compute_checksum((void *)ctx->dsdt,
-							     ctx->dsdt->length);
+		acpi_update_checksum(ctx->dsdt);
 	}
 
 	/* Fill in platform-specific global NVS variables */
@@ -330,8 +328,7 @@ static int acpi_create_hpet(struct acpi_hpet *hpet)
 	hpet->number = 0;
 	hpet->min_tick = 0; /* HPET_MIN_TICKS */
 
-	header->checksum = table_compute_checksum(hpet,
-						  sizeof(struct acpi_hpet));
+	acpi_update_checksum(header);
 
 	return 0;
 }
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 4/5] qemu-sbsa: simplify updating ACPI table header checksum
  2025-03-21 23:21 [PATCH 0/5] acpi: simplify updating ACPI table header checksum Heinrich Schuchardt
                   ` (2 preceding siblings ...)
  2025-03-21 23:21 ` [PATCH 3/5] x86/acpi: " Heinrich Schuchardt
@ 2025-03-21 23:21 ` Heinrich Schuchardt
  2025-03-25 15:01   ` Matthias Brugger
  2025-03-26  7:30   ` Ilias Apalodimas
  2025-03-21 23:21 ` [PATCH 5/5] arm: " Heinrich Schuchardt
  2025-04-10  1:46 ` [PATCH 0/5] acpi: " Tom Rini
  5 siblings, 2 replies; 16+ messages in thread
From: Heinrich Schuchardt @ 2025-03-21 23:21 UTC (permalink / raw)
  To: Simon Glass
  Cc: Matthias Brugger, Peter Robinson, Tom Rini, Bin Meng,
	Patrick Rudolph, Maximilian Brune, Fiona Klute, Martin Stolpe,
	Rasmus Villemoes, Ilias Apalodimas, Moritz Fischer, u-boot,
	Heinrich Schuchardt

Use acpi_update_checksum() to update table header.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
 board/emulation/qemu-sbsa/acpi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/board/emulation/qemu-sbsa/acpi.c b/board/emulation/qemu-sbsa/acpi.c
index ba85e08fc7d..7e4c55cc818 100644
--- a/board/emulation/qemu-sbsa/acpi.c
+++ b/board/emulation/qemu-sbsa/acpi.c
@@ -133,7 +133,7 @@ static int sbsa_write_gtdt(struct acpi_ctx *ctx, const struct acpi_writer *entry
 	gtdt->cnt_read_base = 0xffffffffffffffff;
 
 	// FIXME: VirtualPL2Timer
-	header->checksum = table_compute_checksum(header, header->length);
+	acpi_update_checksum(header);
 
 	acpi_add_table(ctx, gtdt);
 
@@ -181,7 +181,7 @@ static int acpi_write_pptt(struct acpi_ctx *ctx, const struct acpi_writer *entry
 	}
 
 	header->length = ctx->current - ctx->tab_start;
-	header->checksum = table_compute_checksum(header, header->length);
+	acpi_update_checksum(header);
 
 	acpi_inc(ctx, header->length);
 	acpi_add_table(ctx, header);
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 5/5] arm: simplify updating ACPI table header checksum
  2025-03-21 23:21 [PATCH 0/5] acpi: simplify updating ACPI table header checksum Heinrich Schuchardt
                   ` (3 preceding siblings ...)
  2025-03-21 23:21 ` [PATCH 4/5] qemu-sbsa: simplify updating ACPI table " Heinrich Schuchardt
@ 2025-03-21 23:21 ` Heinrich Schuchardt
  2025-03-25 15:03   ` Matthias Brugger
  2025-03-26  7:31   ` Ilias Apalodimas
  2025-04-10  1:46 ` [PATCH 0/5] acpi: " Tom Rini
  5 siblings, 2 replies; 16+ messages in thread
From: Heinrich Schuchardt @ 2025-03-21 23:21 UTC (permalink / raw)
  To: Simon Glass
  Cc: Matthias Brugger, Peter Robinson, Tom Rini, Bin Meng,
	Patrick Rudolph, Maximilian Brune, Fiona Klute, Martin Stolpe,
	Rasmus Villemoes, Ilias Apalodimas, Moritz Fischer, u-boot,
	Heinrich Schuchardt

Use acpi_update_checksum() to update table header.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
 arch/arm/mach-bcm283x/bcm2711_acpi.c | 4 ++--
 board/raspberrypi/rpi/rpi.c          | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-bcm283x/bcm2711_acpi.c b/arch/arm/mach-bcm283x/bcm2711_acpi.c
index 79b283353cf..58f8ee232b9 100644
--- a/arch/arm/mach-bcm283x/bcm2711_acpi.c
+++ b/arch/arm/mach-bcm283x/bcm2711_acpi.c
@@ -81,7 +81,7 @@ static int acpi_write_pptt(struct acpi_ctx *ctx, const struct acpi_writer *entry
 	}
 
 	header->length = ctx->current - ctx->tab_start;
-	header->checksum = table_compute_checksum(header, header->length);
+	acpi_update_checksum(header);
 
 	acpi_inc(ctx, header->length);
 	acpi_add_table(ctx, header);
@@ -116,7 +116,7 @@ static int rpi_write_gtdt(struct acpi_ctx *ctx, const struct acpi_writer *entry)
 	gtdt->el2_flags = GTDT_FLAG_INT_ACTIVE_LOW;
 	gtdt->cnt_read_base = 0xffffffffffffffff;
 
-	header->checksum = table_compute_checksum(header, header->length);
+	acpi_update_checksum(header);
 
 	acpi_add_table(ctx, gtdt);
 
diff --git a/board/raspberrypi/rpi/rpi.c b/board/raspberrypi/rpi/rpi.c
index 70d3c35499b..6ecd3eb120f 100644
--- a/board/raspberrypi/rpi/rpi.c
+++ b/board/raspberrypi/rpi/rpi.c
@@ -791,7 +791,7 @@ static int rpi_acpi_write_ssdt(struct acpi_ctx *ctx, const struct acpi_writer *e
 
 	/* (Re)calculate length and checksum */
 	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);
 
 	/* Drop the table if it is empty */
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/5] acpi: new function acpi_update_checksum()
  2025-03-21 23:21 ` [PATCH 1/5] acpi: new function acpi_update_checksum() Heinrich Schuchardt
@ 2025-03-25 14:49   ` Matthias Brugger
  2025-03-26  7:29   ` Ilias Apalodimas
  1 sibling, 0 replies; 16+ messages in thread
From: Matthias Brugger @ 2025-03-25 14:49 UTC (permalink / raw)
  To: Heinrich Schuchardt, Simon Glass
  Cc: Peter Robinson, Tom Rini, Bin Meng, Patrick Rudolph,
	Maximilian Brune, Fiona Klute, Martin Stolpe, Rasmus Villemoes,
	Ilias Apalodimas, Moritz Fischer, u-boot



On 22/03/2025 00:21, Heinrich Schuchardt wrote:
> Introduce a new function to update ACPI table headers.
> This allows to simplify the existing code.
> 
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

Reviewed-by: Matthias Brugger <mbrugger@suse.com>

> ---
>   include/acpi/acpi_table.h | 7 +++++++
>   lib/acpi/acpi.c           | 7 +++++++
>   2 files changed, 14 insertions(+)
> 
> diff --git a/include/acpi/acpi_table.h b/include/acpi/acpi_table.h
> index b8b1f1338c6..f8e5f552ab1 100644
> --- a/include/acpi/acpi_table.h
> +++ b/include/acpi/acpi_table.h
> @@ -1274,6 +1274,13 @@ ulong write_acpi_tables(ulong start);
>    */
>   struct acpi_table_header *acpi_find_table(const char *sig);
>   
> +/**
> + * acpi_update_checksum() - update ACPI table checksum
> + *
> + * @header - header of an ACPI table
> + */
> +void acpi_update_checksum(struct acpi_table_header *header);
> +
>   #endif /* !__ACPI__*/
>   
>   #include <asm/acpi_table.h>
> diff --git a/lib/acpi/acpi.c b/lib/acpi/acpi.c
> index f4d5c1e25d0..596301a43fe 100644
> --- a/lib/acpi/acpi.c
> +++ b/lib/acpi/acpi.c
> @@ -6,11 +6,18 @@
>    */
>   
>   #include <mapmem.h>
> +#include <tables_csum.h>
>   #include <acpi/acpi_table.h>
>   #include <asm/global_data.h>
>   
>   DECLARE_GLOBAL_DATA_PTR;
>   
> +void acpi_update_checksum(struct acpi_table_header *header)
> +{
> +	header->checksum = 0;
> +	header->checksum = table_compute_checksum(header, header->length);
> +}
> +
>   struct acpi_table_header *acpi_find_table(const char *sig)
>   {
>   	struct acpi_rsdp *rsdp;


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 2/5] acpi: simplify updating header checksum
  2025-03-21 23:21 ` [PATCH 2/5] acpi: simplify updating header checksum Heinrich Schuchardt
@ 2025-03-25 14:55   ` Matthias Brugger
  2025-03-26  7:30   ` Ilias Apalodimas
  1 sibling, 0 replies; 16+ messages in thread
From: Matthias Brugger @ 2025-03-25 14:55 UTC (permalink / raw)
  To: Heinrich Schuchardt, Simon Glass
  Cc: Peter Robinson, Tom Rini, Bin Meng, Patrick Rudolph,
	Maximilian Brune, Fiona Klute, Martin Stolpe, Rasmus Villemoes,
	Ilias Apalodimas, Moritz Fischer, u-boot



On 22/03/2025 00:21, Heinrich Schuchardt wrote:
> Use acpi_update_checksum() for updating ACPI table header checksum.
> 
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

Reviewed-by: Matthias Brugger <mbrugger@suse.com>

> ---
>   lib/acpi/acpi_table.c | 18 +++++++-----------
>   lib/acpi/base.c       |  6 ++----
>   lib/acpi/csrt.c       |  2 +-
>   lib/acpi/mcfg.c       |  2 +-
>   lib/acpi/ssdt.c       |  2 +-
>   5 files changed, 12 insertions(+), 18 deletions(-)
> 
> diff --git a/lib/acpi/acpi_table.c b/lib/acpi/acpi_table.c
> index c0ed24984af..b5495d48a46 100644
> --- a/lib/acpi/acpi_table.c
> +++ b/lib/acpi/acpi_table.c
> @@ -195,9 +195,7 @@ int acpi_add_table(struct acpi_ctx *ctx, void *table)
>   					(sizeof(u32) * (i + 1));
>   
>   		/* Re-calculate checksum */
> -		rsdt->header.checksum = 0;
> -		rsdt->header.checksum = table_compute_checksum((u8 *)rsdt,
> -							       rsdt->header.length);
> +		acpi_update_checksum(&rsdt->header);
>   	}
>   
>   	if (ctx->xsdt) {
> @@ -228,9 +226,7 @@ int acpi_add_table(struct acpi_ctx *ctx, void *table)
>   					(sizeof(u64) * (i + 1));
>   
>   		/* Re-calculate checksum */
> -		xsdt->header.checksum = 0;
> -		xsdt->header.checksum = table_compute_checksum((u8 *)xsdt,
> -							       xsdt->header.length);
> +		acpi_update_checksum(&xsdt->header);
>   	}
>   
>   	return 0;
> @@ -268,7 +264,7 @@ int acpi_write_fadt(struct acpi_ctx *ctx, const struct acpi_writer *entry)
>   
>   	acpi_fill_fadt(fadt);
>   
> -	header->checksum = table_compute_checksum(fadt, header->length);
> +	acpi_update_checksum(header);
>   
>   	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))
>   		acpi_write_park(madt);
>   
> -	header->checksum = table_compute_checksum((void *)madt, header->length);
> +	acpi_update_checksum(header);
>   	acpi_add_table(ctx, madt);
>   	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 */
>   	device->length = current - (uintptr_t)device;
>   	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,
> @@ -549,7 +545,7 @@ static int acpi_write_spcr(struct acpi_ctx *ctx, const struct acpi_writer *entry
>   		spcr->baud_rate = 0;
>   
>   	/* Fix checksum */
> -	header->checksum = table_compute_checksum((void *)spcr, header->length);
> +	acpi_update_checksum(header);
>   
>   	acpi_add_table(ctx, spcr);
>   	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 */
>   	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);
>   
>   	/* Drop the table if it is empty */
> diff --git a/lib/acpi/base.c b/lib/acpi/base.c
> index 8b6af2bc43a..5c755b14c16 100644
> --- a/lib/acpi/base.c
> +++ b/lib/acpi/base.c
> @@ -50,8 +50,7 @@ static void acpi_write_rsdt(struct acpi_rsdt *rsdt)
>   	/* Entries are filled in later, we come with an empty set */
>   
>   	/* Fix checksum */
> -	header->checksum = table_compute_checksum(rsdt,
> -						  sizeof(struct acpi_rsdt));
> +	acpi_update_checksum(header);
>   }
>   
>   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 */
>   
>   	/* Fix checksum */
> -	header->checksum = table_compute_checksum(xsdt,
> -						  sizeof(struct acpi_xsdt));
> +	acpi_update_checksum(header);
>   }
>   
>   static int acpi_write_base(struct acpi_ctx *ctx,
> diff --git a/lib/acpi/csrt.c b/lib/acpi/csrt.c
> index 00927e53406..b863c644c07 100644
> --- a/lib/acpi/csrt.c
> +++ b/lib/acpi/csrt.c
> @@ -40,7 +40,7 @@ int acpi_write_csrt(struct acpi_ctx *ctx, const struct acpi_writer *entry)
>   
>   	/* (Re)calculate length and checksum */
>   	header->length = (ulong)ctx->current - (ulong)csrt;
> -	header->checksum = table_compute_checksum(csrt, header->length);
> +	acpi_update_checksum(header);
>   
>   	acpi_add_table(ctx, csrt);
>   
> diff --git a/lib/acpi/mcfg.c b/lib/acpi/mcfg.c
> index 8b8a5bfafae..e21fe7ce123 100644
> --- a/lib/acpi/mcfg.c
> +++ b/lib/acpi/mcfg.c
> @@ -57,7 +57,7 @@ int acpi_write_mcfg(struct acpi_ctx *ctx, const struct acpi_writer *entry)
>   
>   	/* (Re)calculate length and checksum */
>   	header->length = (ulong)ctx->current - (ulong)mcfg;
> -	header->checksum = table_compute_checksum(mcfg, header->length);
> +	acpi_update_checksum(header);
>   
>   	acpi_add_table(ctx, mcfg);
>   
> diff --git a/lib/acpi/ssdt.c b/lib/acpi/ssdt.c
> index df1d739d117..41e2d3c2f6c 100644
> --- a/lib/acpi/ssdt.c
> +++ b/lib/acpi/ssdt.c
> @@ -35,7 +35,7 @@ int acpi_write_ssdt(struct acpi_ctx *ctx, const struct acpi_writer *entry)
>   
>   	/* (Re)calculate length and checksum */
>   	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);
>   
>   	/* Drop the table if it is empty */


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/5] x86/acpi: simplify updating header checksum
  2025-03-21 23:21 ` [PATCH 3/5] x86/acpi: " Heinrich Schuchardt
@ 2025-03-25 14:58   ` Matthias Brugger
  0 siblings, 0 replies; 16+ messages in thread
From: Matthias Brugger @ 2025-03-25 14:58 UTC (permalink / raw)
  To: Heinrich Schuchardt, Simon Glass
  Cc: Peter Robinson, Tom Rini, Bin Meng, Patrick Rudolph,
	Maximilian Brune, Fiona Klute, Martin Stolpe, Rasmus Villemoes,
	Ilias Apalodimas, Moritz Fischer, u-boot



On 22/03/2025 00:21, Heinrich Schuchardt wrote:
> Use acpi_update_checksum() for updating ACPI table header checksum.
> 
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

Reviewed-by: Matthias Brugger <mbrugger@suse.com>

> ---
>   arch/x86/cpu/apollolake/hostbridge.c |  2 +-
>   arch/x86/lib/acpi_nhlt.c             |  2 +-
>   arch/x86/lib/acpi_table.c            | 11 ++++-------
>   3 files changed, 6 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/x86/cpu/apollolake/hostbridge.c b/arch/x86/cpu/apollolake/hostbridge.c
> index 039236df02d..284f16cfd91 100644
> --- a/arch/x86/cpu/apollolake/hostbridge.c
> +++ b/arch/x86/cpu/apollolake/hostbridge.c
> @@ -298,7 +298,7 @@ static int apl_acpi_hb_write_tables(const struct udevice *dev,
>   
>   	/* (Re)calculate length and checksum */
>   	header->length = ctx->current - (void *)dmar;
> -	header->checksum = table_compute_checksum((void *)dmar, header->length);
> +	acpi_update_checksum(header);
>   
>   	acpi_align(ctx);
>   	acpi_add_table(ctx, dmar);
> diff --git a/arch/x86/lib/acpi_nhlt.c b/arch/x86/lib/acpi_nhlt.c
> index 880ef31df7d..8aae5fa5af7 100644
> --- a/arch/x86/lib/acpi_nhlt.c
> +++ b/arch/x86/lib/acpi_nhlt.c
> @@ -414,7 +414,7 @@ int nhlt_serialise_oem_overrides(struct acpi_ctx *ctx, struct nhlt *nhlt,
>   	cur.start = (void *)header;
>   	nhlt_serialise_endpoints(nhlt, &cur);
>   
> -	header->checksum = table_compute_checksum(header, sz);
> +	acpi_update_checksum(header);
>   	nhlt_free_resources(nhlt);
>   	assert(cur.buf - cur.start == sz);
>   
> diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c
> index 3186e48d63b..b13292c4150 100644
> --- a/arch/x86/lib/acpi_table.c
> +++ b/arch/x86/lib/acpi_table.c
> @@ -173,7 +173,7 @@ int acpi_write_tcpa(struct acpi_ctx *ctx, const struct acpi_writer *entry)
>   	/* (Re)calculate length and checksum */
>   	current = (u32)tcpa + sizeof(struct acpi_tcpa);
>   	header->length = current - (u32)tcpa;
> -	header->checksum = table_compute_checksum(tcpa, header->length);
> +	acpi_update_checksum(header);
>   
>   	acpi_inc(ctx, tcpa->header.length);
>   	acpi_add_table(ctx, tcpa);
> @@ -242,7 +242,7 @@ static int acpi_write_tpm2(struct acpi_ctx *ctx,
>   	tpm2->lasa = nomap_to_sysmem(lasa);
>   
>   	/* Calculate checksum. */
> -	header->checksum = table_compute_checksum(tpm2, header->length);
> +	acpi_update_checksum(header);
>   
>   	acpi_inc(ctx, tpm2->header.length);
>   	acpi_add_table(ctx, tpm2);
> @@ -279,9 +279,7 @@ int acpi_write_gnvs(struct acpi_ctx *ctx, const struct acpi_writer *entry)
>   		 * patched the GNVS address. Set the checksum to zero since it
>   		 * is part of the region being checksummed.
>   		 */
> -		ctx->dsdt->checksum = 0;
> -		ctx->dsdt->checksum = table_compute_checksum((void *)ctx->dsdt,
> -							     ctx->dsdt->length);
> +		acpi_update_checksum(ctx->dsdt);
>   	}
>   
>   	/* Fill in platform-specific global NVS variables */
> @@ -330,8 +328,7 @@ static int acpi_create_hpet(struct acpi_hpet *hpet)
>   	hpet->number = 0;
>   	hpet->min_tick = 0; /* HPET_MIN_TICKS */
>   
> -	header->checksum = table_compute_checksum(hpet,
> -						  sizeof(struct acpi_hpet));
> +	acpi_update_checksum(header);
>   
>   	return 0;
>   }


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 4/5] qemu-sbsa: simplify updating ACPI table header checksum
  2025-03-21 23:21 ` [PATCH 4/5] qemu-sbsa: simplify updating ACPI table " Heinrich Schuchardt
@ 2025-03-25 15:01   ` Matthias Brugger
  2025-03-26  7:30   ` Ilias Apalodimas
  1 sibling, 0 replies; 16+ messages in thread
From: Matthias Brugger @ 2025-03-25 15:01 UTC (permalink / raw)
  To: Heinrich Schuchardt, Simon Glass
  Cc: Peter Robinson, Tom Rini, Bin Meng, Patrick Rudolph,
	Maximilian Brune, Fiona Klute, Martin Stolpe, Rasmus Villemoes,
	Ilias Apalodimas, Moritz Fischer, u-boot



On 22/03/2025 00:21, Heinrich Schuchardt wrote:
> Use acpi_update_checksum() to update table header.
> 
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

Reviewed-by: Matthias Brugger <mbrugger@suse.com>

> ---
>   board/emulation/qemu-sbsa/acpi.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/board/emulation/qemu-sbsa/acpi.c b/board/emulation/qemu-sbsa/acpi.c
> index ba85e08fc7d..7e4c55cc818 100644
> --- a/board/emulation/qemu-sbsa/acpi.c
> +++ b/board/emulation/qemu-sbsa/acpi.c
> @@ -133,7 +133,7 @@ static int sbsa_write_gtdt(struct acpi_ctx *ctx, const struct acpi_writer *entry
>   	gtdt->cnt_read_base = 0xffffffffffffffff;
>   
>   	// FIXME: VirtualPL2Timer
> -	header->checksum = table_compute_checksum(header, header->length);
> +	acpi_update_checksum(header);
>   
>   	acpi_add_table(ctx, gtdt);
>   
> @@ -181,7 +181,7 @@ static int acpi_write_pptt(struct acpi_ctx *ctx, const struct acpi_writer *entry
>   	}
>   
>   	header->length = ctx->current - ctx->tab_start;
> -	header->checksum = table_compute_checksum(header, header->length);
> +	acpi_update_checksum(header);
>   
>   	acpi_inc(ctx, header->length);
>   	acpi_add_table(ctx, header);


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 5/5] arm: simplify updating ACPI table header checksum
  2025-03-21 23:21 ` [PATCH 5/5] arm: " Heinrich Schuchardt
@ 2025-03-25 15:03   ` Matthias Brugger
  2025-03-26  7:31   ` Ilias Apalodimas
  1 sibling, 0 replies; 16+ messages in thread
From: Matthias Brugger @ 2025-03-25 15:03 UTC (permalink / raw)
  To: Heinrich Schuchardt, Simon Glass
  Cc: Peter Robinson, Tom Rini, Bin Meng, Patrick Rudolph,
	Maximilian Brune, Fiona Klute, Martin Stolpe, Rasmus Villemoes,
	Ilias Apalodimas, Moritz Fischer, u-boot



On 22/03/2025 00:21, Heinrich Schuchardt wrote:
> Use acpi_update_checksum() to update table header.
> 
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

Reviewed-by: Matthias Brugger <mbrugger@suse.com>

> ---
>   arch/arm/mach-bcm283x/bcm2711_acpi.c | 4 ++--
>   board/raspberrypi/rpi/rpi.c          | 2 +-
>   2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/arm/mach-bcm283x/bcm2711_acpi.c b/arch/arm/mach-bcm283x/bcm2711_acpi.c
> index 79b283353cf..58f8ee232b9 100644
> --- a/arch/arm/mach-bcm283x/bcm2711_acpi.c
> +++ b/arch/arm/mach-bcm283x/bcm2711_acpi.c
> @@ -81,7 +81,7 @@ static int acpi_write_pptt(struct acpi_ctx *ctx, const struct acpi_writer *entry
>   	}
>   
>   	header->length = ctx->current - ctx->tab_start;
> -	header->checksum = table_compute_checksum(header, header->length);
> +	acpi_update_checksum(header);
>   
>   	acpi_inc(ctx, header->length);
>   	acpi_add_table(ctx, header);
> @@ -116,7 +116,7 @@ static int rpi_write_gtdt(struct acpi_ctx *ctx, const struct acpi_writer *entry)
>   	gtdt->el2_flags = GTDT_FLAG_INT_ACTIVE_LOW;
>   	gtdt->cnt_read_base = 0xffffffffffffffff;
>   
> -	header->checksum = table_compute_checksum(header, header->length);
> +	acpi_update_checksum(header);
>   
>   	acpi_add_table(ctx, gtdt);
>   
> diff --git a/board/raspberrypi/rpi/rpi.c b/board/raspberrypi/rpi/rpi.c
> index 70d3c35499b..6ecd3eb120f 100644
> --- a/board/raspberrypi/rpi/rpi.c
> +++ b/board/raspberrypi/rpi/rpi.c
> @@ -791,7 +791,7 @@ static int rpi_acpi_write_ssdt(struct acpi_ctx *ctx, const struct acpi_writer *e
>   
>   	/* (Re)calculate length and checksum */
>   	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);
>   
>   	/* Drop the table if it is empty */


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/5] acpi: new function acpi_update_checksum()
  2025-03-21 23:21 ` [PATCH 1/5] acpi: new function acpi_update_checksum() Heinrich Schuchardt
  2025-03-25 14:49   ` Matthias Brugger
@ 2025-03-26  7:29   ` Ilias Apalodimas
  1 sibling, 0 replies; 16+ messages in thread
From: Ilias Apalodimas @ 2025-03-26  7:29 UTC (permalink / raw)
  To: Heinrich Schuchardt
  Cc: Simon Glass, Matthias Brugger, Peter Robinson, Tom Rini, Bin Meng,
	Patrick Rudolph, Maximilian Brune, Fiona Klute, Martin Stolpe,
	Rasmus Villemoes, Moritz Fischer, u-boot

On Sat, 22 Mar 2025 at 01:21, Heinrich Schuchardt
<heinrich.schuchardt@canonical.com> wrote:
>
> Introduce a new function to update ACPI table headers.
> This allows to simplify the existing code.
>
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

> ---
>  include/acpi/acpi_table.h | 7 +++++++
>  lib/acpi/acpi.c           | 7 +++++++
>  2 files changed, 14 insertions(+)
>
> diff --git a/include/acpi/acpi_table.h b/include/acpi/acpi_table.h
> index b8b1f1338c6..f8e5f552ab1 100644
> --- a/include/acpi/acpi_table.h
> +++ b/include/acpi/acpi_table.h
> @@ -1274,6 +1274,13 @@ ulong write_acpi_tables(ulong start);
>   */
>  struct acpi_table_header *acpi_find_table(const char *sig);
>
> +/**
> + * acpi_update_checksum() - update ACPI table checksum
> + *
> + * @header - header of an ACPI table
> + */
> +void acpi_update_checksum(struct acpi_table_header *header);
> +
>  #endif /* !__ACPI__*/
>
>  #include <asm/acpi_table.h>
> diff --git a/lib/acpi/acpi.c b/lib/acpi/acpi.c
> index f4d5c1e25d0..596301a43fe 100644
> --- a/lib/acpi/acpi.c
> +++ b/lib/acpi/acpi.c
> @@ -6,11 +6,18 @@
>   */
>
>  #include <mapmem.h>
> +#include <tables_csum.h>
>  #include <acpi/acpi_table.h>
>  #include <asm/global_data.h>
>
>  DECLARE_GLOBAL_DATA_PTR;
>
> +void acpi_update_checksum(struct acpi_table_header *header)
> +{
> +       header->checksum = 0;
> +       header->checksum = table_compute_checksum(header, header->length);
> +}
> +
>  struct acpi_table_header *acpi_find_table(const char *sig)
>  {
>         struct acpi_rsdp *rsdp;
> --
> 2.48.1
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 2/5] acpi: simplify updating header checksum
  2025-03-21 23:21 ` [PATCH 2/5] acpi: simplify updating header checksum Heinrich Schuchardt
  2025-03-25 14:55   ` Matthias Brugger
@ 2025-03-26  7:30   ` Ilias Apalodimas
  1 sibling, 0 replies; 16+ messages in thread
From: Ilias Apalodimas @ 2025-03-26  7:30 UTC (permalink / raw)
  To: Heinrich Schuchardt
  Cc: Simon Glass, Matthias Brugger, Peter Robinson, Tom Rini, Bin Meng,
	Patrick Rudolph, Maximilian Brune, Fiona Klute, Martin Stolpe,
	Rasmus Villemoes, Moritz Fischer, u-boot

On Sat, 22 Mar 2025 at 01:21, Heinrich Schuchardt
<heinrich.schuchardt@canonical.com> wrote:
>
> 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>

> ---
>  lib/acpi/acpi_table.c | 18 +++++++-----------
>  lib/acpi/base.c       |  6 ++----
>  lib/acpi/csrt.c       |  2 +-
>  lib/acpi/mcfg.c       |  2 +-
>  lib/acpi/ssdt.c       |  2 +-
>  5 files changed, 12 insertions(+), 18 deletions(-)
>
> diff --git a/lib/acpi/acpi_table.c b/lib/acpi/acpi_table.c
> index c0ed24984af..b5495d48a46 100644
> --- a/lib/acpi/acpi_table.c
> +++ b/lib/acpi/acpi_table.c
> @@ -195,9 +195,7 @@ int acpi_add_table(struct acpi_ctx *ctx, void *table)
>                                         (sizeof(u32) * (i + 1));
>
>                 /* Re-calculate checksum */
> -               rsdt->header.checksum = 0;
> -               rsdt->header.checksum = table_compute_checksum((u8 *)rsdt,
> -                                                              rsdt->header.length);
> +               acpi_update_checksum(&rsdt->header);
>         }
>
>         if (ctx->xsdt) {
> @@ -228,9 +226,7 @@ int acpi_add_table(struct acpi_ctx *ctx, void *table)
>                                         (sizeof(u64) * (i + 1));
>
>                 /* Re-calculate checksum */
> -               xsdt->header.checksum = 0;
> -               xsdt->header.checksum = table_compute_checksum((u8 *)xsdt,
> -                                                              xsdt->header.length);
> +               acpi_update_checksum(&xsdt->header);
>         }
>
>         return 0;
> @@ -268,7 +264,7 @@ int acpi_write_fadt(struct acpi_ctx *ctx, const struct acpi_writer *entry)
>
>         acpi_fill_fadt(fadt);
>
> -       header->checksum = table_compute_checksum(fadt, header->length);
> +       acpi_update_checksum(header);
>
>         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))
>                 acpi_write_park(madt);
>
> -       header->checksum = table_compute_checksum((void *)madt, header->length);
> +       acpi_update_checksum(header);
>         acpi_add_table(ctx, madt);
>         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 */
>         device->length = current - (uintptr_t)device;
>         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,
> @@ -549,7 +545,7 @@ static int acpi_write_spcr(struct acpi_ctx *ctx, const struct acpi_writer *entry
>                 spcr->baud_rate = 0;
>
>         /* Fix checksum */
> -       header->checksum = table_compute_checksum((void *)spcr, header->length);
> +       acpi_update_checksum(header);
>
>         acpi_add_table(ctx, spcr);
>         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 */
>         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);
>
>         /* Drop the table if it is empty */
> diff --git a/lib/acpi/base.c b/lib/acpi/base.c
> index 8b6af2bc43a..5c755b14c16 100644
> --- a/lib/acpi/base.c
> +++ b/lib/acpi/base.c
> @@ -50,8 +50,7 @@ static void acpi_write_rsdt(struct acpi_rsdt *rsdt)
>         /* Entries are filled in later, we come with an empty set */
>
>         /* Fix checksum */
> -       header->checksum = table_compute_checksum(rsdt,
> -                                                 sizeof(struct acpi_rsdt));
> +       acpi_update_checksum(header);
>  }
>
>  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 */
>
>         /* Fix checksum */
> -       header->checksum = table_compute_checksum(xsdt,
> -                                                 sizeof(struct acpi_xsdt));
> +       acpi_update_checksum(header);
>  }
>
>  static int acpi_write_base(struct acpi_ctx *ctx,
> diff --git a/lib/acpi/csrt.c b/lib/acpi/csrt.c
> index 00927e53406..b863c644c07 100644
> --- a/lib/acpi/csrt.c
> +++ b/lib/acpi/csrt.c
> @@ -40,7 +40,7 @@ int acpi_write_csrt(struct acpi_ctx *ctx, const struct acpi_writer *entry)
>
>         /* (Re)calculate length and checksum */
>         header->length = (ulong)ctx->current - (ulong)csrt;
> -       header->checksum = table_compute_checksum(csrt, header->length);
> +       acpi_update_checksum(header);
>
>         acpi_add_table(ctx, csrt);
>
> diff --git a/lib/acpi/mcfg.c b/lib/acpi/mcfg.c
> index 8b8a5bfafae..e21fe7ce123 100644
> --- a/lib/acpi/mcfg.c
> +++ b/lib/acpi/mcfg.c
> @@ -57,7 +57,7 @@ int acpi_write_mcfg(struct acpi_ctx *ctx, const struct acpi_writer *entry)
>
>         /* (Re)calculate length and checksum */
>         header->length = (ulong)ctx->current - (ulong)mcfg;
> -       header->checksum = table_compute_checksum(mcfg, header->length);
> +       acpi_update_checksum(header);
>
>         acpi_add_table(ctx, mcfg);
>
> diff --git a/lib/acpi/ssdt.c b/lib/acpi/ssdt.c
> index df1d739d117..41e2d3c2f6c 100644
> --- a/lib/acpi/ssdt.c
> +++ b/lib/acpi/ssdt.c
> @@ -35,7 +35,7 @@ int acpi_write_ssdt(struct acpi_ctx *ctx, const struct acpi_writer *entry)
>
>         /* (Re)calculate length and checksum */
>         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);
>
>         /* Drop the table if it is empty */
> --
> 2.48.1
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 4/5] qemu-sbsa: simplify updating ACPI table header checksum
  2025-03-21 23:21 ` [PATCH 4/5] qemu-sbsa: simplify updating ACPI table " Heinrich Schuchardt
  2025-03-25 15:01   ` Matthias Brugger
@ 2025-03-26  7:30   ` Ilias Apalodimas
  1 sibling, 0 replies; 16+ messages in thread
From: Ilias Apalodimas @ 2025-03-26  7:30 UTC (permalink / raw)
  To: Heinrich Schuchardt
  Cc: Simon Glass, Matthias Brugger, Peter Robinson, Tom Rini, Bin Meng,
	Patrick Rudolph, Maximilian Brune, Fiona Klute, Martin Stolpe,
	Rasmus Villemoes, Moritz Fischer, u-boot

On Sat, 22 Mar 2025 at 01:21, Heinrich Schuchardt
<heinrich.schuchardt@canonical.com> wrote:
>
> Use acpi_update_checksum() to update table header.
>
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

> ---
>  board/emulation/qemu-sbsa/acpi.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/board/emulation/qemu-sbsa/acpi.c b/board/emulation/qemu-sbsa/acpi.c
> index ba85e08fc7d..7e4c55cc818 100644
> --- a/board/emulation/qemu-sbsa/acpi.c
> +++ b/board/emulation/qemu-sbsa/acpi.c
> @@ -133,7 +133,7 @@ static int sbsa_write_gtdt(struct acpi_ctx *ctx, const struct acpi_writer *entry
>         gtdt->cnt_read_base = 0xffffffffffffffff;
>
>         // FIXME: VirtualPL2Timer
> -       header->checksum = table_compute_checksum(header, header->length);
> +       acpi_update_checksum(header);
>
>         acpi_add_table(ctx, gtdt);
>
> @@ -181,7 +181,7 @@ static int acpi_write_pptt(struct acpi_ctx *ctx, const struct acpi_writer *entry
>         }
>
>         header->length = ctx->current - ctx->tab_start;
> -       header->checksum = table_compute_checksum(header, header->length);
> +       acpi_update_checksum(header);
>
>         acpi_inc(ctx, header->length);
>         acpi_add_table(ctx, header);
> --
> 2.48.1
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 5/5] arm: simplify updating ACPI table header checksum
  2025-03-21 23:21 ` [PATCH 5/5] arm: " Heinrich Schuchardt
  2025-03-25 15:03   ` Matthias Brugger
@ 2025-03-26  7:31   ` Ilias Apalodimas
  1 sibling, 0 replies; 16+ messages in thread
From: Ilias Apalodimas @ 2025-03-26  7:31 UTC (permalink / raw)
  To: Heinrich Schuchardt
  Cc: Simon Glass, Matthias Brugger, Peter Robinson, Tom Rini, Bin Meng,
	Patrick Rudolph, Maximilian Brune, Fiona Klute, Martin Stolpe,
	Rasmus Villemoes, Moritz Fischer, u-boot

On Sat, 22 Mar 2025 at 01:21, Heinrich Schuchardt
<heinrich.schuchardt@canonical.com> wrote:
>
> Use acpi_update_checksum() to update table header.
>
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

> ---
>  arch/arm/mach-bcm283x/bcm2711_acpi.c | 4 ++--
>  board/raspberrypi/rpi/rpi.c          | 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/arch/arm/mach-bcm283x/bcm2711_acpi.c b/arch/arm/mach-bcm283x/bcm2711_acpi.c
> index 79b283353cf..58f8ee232b9 100644
> --- a/arch/arm/mach-bcm283x/bcm2711_acpi.c
> +++ b/arch/arm/mach-bcm283x/bcm2711_acpi.c
> @@ -81,7 +81,7 @@ static int acpi_write_pptt(struct acpi_ctx *ctx, const struct acpi_writer *entry
>         }
>
>         header->length = ctx->current - ctx->tab_start;
> -       header->checksum = table_compute_checksum(header, header->length);
> +       acpi_update_checksum(header);
>
>         acpi_inc(ctx, header->length);
>         acpi_add_table(ctx, header);
> @@ -116,7 +116,7 @@ static int rpi_write_gtdt(struct acpi_ctx *ctx, const struct acpi_writer *entry)
>         gtdt->el2_flags = GTDT_FLAG_INT_ACTIVE_LOW;
>         gtdt->cnt_read_base = 0xffffffffffffffff;
>
> -       header->checksum = table_compute_checksum(header, header->length);
> +       acpi_update_checksum(header);
>
>         acpi_add_table(ctx, gtdt);
>
> diff --git a/board/raspberrypi/rpi/rpi.c b/board/raspberrypi/rpi/rpi.c
> index 70d3c35499b..6ecd3eb120f 100644
> --- a/board/raspberrypi/rpi/rpi.c
> +++ b/board/raspberrypi/rpi/rpi.c
> @@ -791,7 +791,7 @@ static int rpi_acpi_write_ssdt(struct acpi_ctx *ctx, const struct acpi_writer *e
>
>         /* (Re)calculate length and checksum */
>         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);
>
>         /* Drop the table if it is empty */
> --
> 2.48.1
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 0/5] acpi: simplify updating ACPI table header checksum
  2025-03-21 23:21 [PATCH 0/5] acpi: simplify updating ACPI table header checksum Heinrich Schuchardt
                   ` (4 preceding siblings ...)
  2025-03-21 23:21 ` [PATCH 5/5] arm: " Heinrich Schuchardt
@ 2025-04-10  1:46 ` Tom Rini
  5 siblings, 0 replies; 16+ messages in thread
From: Tom Rini @ 2025-04-10  1:46 UTC (permalink / raw)
  To: Simon Glass, Heinrich Schuchardt
  Cc: Matthias Brugger, Peter Robinson, Bin Meng, Patrick Rudolph,
	Maximilian Brune, Fiona Klute, Martin Stolpe, Rasmus Villemoes,
	Ilias Apalodimas, Moritz Fischer, u-boot

On Sat, 22 Mar 2025 00:21:15 +0100, Heinrich Schuchardt wrote:

> Introduce a new function to update ACPI table headers.
> This allows to simplify the existing code.
> 
> Heinrich Schuchardt (5):
>   acpi: new function acpi_update_checksum()
>   acpi: simplify updating header checksum
>   x86/acpi: simplify updating header checksum
>   qemu-sbsa: simplify updating ACPI table header checksum
>   arm: simplify updating ACPI table header checksum
> 
> [...]

Applied to u-boot/master, thanks!

[1/5] acpi: new function acpi_update_checksum()
      commit: 69e61d46d2dcdcf84a3a7aed7cf74ac3b3b850fd
[2/5] acpi: simplify updating header checksum
      commit: bbc78592b16d164fbb252455d6a60afb3ee52709
[3/5] x86/acpi: simplify updating header checksum
      commit: e0055ac9bbd3059c961b1d7f98dcff276502c847
[4/5] qemu-sbsa: simplify updating ACPI table header checksum
      commit: 5eca1696d25f61ad58582820f8477360c81b8b7b
[5/5] arm: simplify updating ACPI table header checksum
      commit: fecc50b0517d362b4db173b08a769f7b975d8255
-- 
Tom



^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2025-04-10  1:46 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-21 23:21 [PATCH 0/5] acpi: simplify updating ACPI table header checksum Heinrich Schuchardt
2025-03-21 23:21 ` [PATCH 1/5] acpi: new function acpi_update_checksum() Heinrich Schuchardt
2025-03-25 14:49   ` Matthias Brugger
2025-03-26  7:29   ` Ilias Apalodimas
2025-03-21 23:21 ` [PATCH 2/5] acpi: simplify updating header checksum Heinrich Schuchardt
2025-03-25 14:55   ` Matthias Brugger
2025-03-26  7:30   ` Ilias Apalodimas
2025-03-21 23:21 ` [PATCH 3/5] x86/acpi: " Heinrich Schuchardt
2025-03-25 14:58   ` Matthias Brugger
2025-03-21 23:21 ` [PATCH 4/5] qemu-sbsa: simplify updating ACPI table " Heinrich Schuchardt
2025-03-25 15:01   ` Matthias Brugger
2025-03-26  7:30   ` Ilias Apalodimas
2025-03-21 23:21 ` [PATCH 5/5] arm: " Heinrich Schuchardt
2025-03-25 15:03   ` Matthias Brugger
2025-03-26  7:31   ` Ilias Apalodimas
2025-04-10  1:46 ` [PATCH 0/5] acpi: " Tom Rini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox