[PATCH 1/4] acpi: add index parameter to acpi_find_table

Heinrich Schuchardt heinrich.schuchardt at canonical.com
Tue Apr 21 00:08:01 CEST 2026


ACPI tables like SSDT may have multiple indexs.

Add an index parameter to acpi_find_table() to allow finding the n-th
instance of an ACPI table with the same signature.

Update all callers to pass index 1.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
---
 cmd/acpi.c                       |  2 +-
 drivers/serial/serial_coreboot.c |  2 +-
 include/acpi/acpi_table.h        |  3 ++-
 lib/acpi/acpi.c                  | 21 ++++++++++++++++-----
 test/dm/acpi.c                   | 18 +++++++++---------
 5 files changed, 29 insertions(+), 17 deletions(-)

diff --git a/cmd/acpi.c b/cmd/acpi.c
index bb243202009..a88cd995460 100644
--- a/cmd/acpi.c
+++ b/cmd/acpi.c
@@ -55,7 +55,7 @@ static int dump_table_name(const char *sig)
 {
 	struct acpi_table_header *hdr;
 
-	hdr = acpi_find_table(sig);
+	hdr = acpi_find_table(sig, 0);
 	if (!hdr)
 		return -ENOENT;
 	printf("%.*s @ %16lx\n", ACPI_NAME_LEN, hdr->signature,
diff --git a/drivers/serial/serial_coreboot.c b/drivers/serial/serial_coreboot.c
index b1f69f6998c..e41430a8cd7 100644
--- a/drivers/serial/serial_coreboot.c
+++ b/drivers/serial/serial_coreboot.c
@@ -30,7 +30,7 @@ static int read_dbg2(struct ns16550_plat *plat)
 		return -ENOENT;
 	}
 
-	tab = acpi_find_table("DBG2");
+	tab = acpi_find_table("DBG2", 0);
 	if (!tab) {
 		log_debug("No DBG2 table\n");
 		return -ENOENT;
diff --git a/include/acpi/acpi_table.h b/include/acpi/acpi_table.h
index 4895366a618..1c5aba9c54d 100644
--- a/include/acpi/acpi_table.h
+++ b/include/acpi/acpi_table.h
@@ -1284,9 +1284,10 @@ ulong write_acpi_tables(ulong start);
  * acpi_find_table() - Look up an ACPI table
  *
  * @sig: Signature of table (4 characters, upper case)
+ * @index: 1-based index number to find
  * Return: pointer to table header, or NULL if not found
  */
-struct acpi_table_header *acpi_find_table(const char *sig);
+struct acpi_table_header *acpi_find_table(const char *sig, ulong index);
 
 /**
  * acpi_update_checksum() - update ACPI table checksum
diff --git a/lib/acpi/acpi.c b/lib/acpi/acpi.c
index 596301a43fe..0cc492b1569 100644
--- a/lib/acpi/acpi.c
+++ b/lib/acpi/acpi.c
@@ -18,7 +18,7 @@ void acpi_update_checksum(struct acpi_table_header *header)
 	header->checksum = table_compute_checksum(header, header->length);
 }
 
-struct acpi_table_header *acpi_find_table(const char *sig)
+struct acpi_table_header *acpi_find_table(const char *sig, ulong index)
 {
 	struct acpi_rsdp *rsdp;
 	struct acpi_rsdt *rsdt;
@@ -46,8 +46,11 @@ struct acpi_table_header *acpi_find_table(const char *sig)
 			hdr = nomap_sysmem(xsdt->entry[i], 0);
 		else
 			hdr = nomap_sysmem(rsdt->entry[i], 0);
-		if (!memcmp(hdr->signature, sig, ACPI_NAME_LEN))
-			return hdr;
+		if (!memcmp(hdr->signature, sig, ACPI_NAME_LEN)) {
+			if (!index)
+				return hdr;
+			--index;
+		}
 		if (!memcmp(hdr->signature, "FACP", ACPI_NAME_LEN)) {
 			struct acpi_fadt *fadt = (struct acpi_fadt *)hdr;
 
@@ -60,7 +63,11 @@ struct acpi_table_header *acpi_find_table(const char *sig)
 					dsdt = nomap_sysmem(fadt->dsdt, 0);
 				else
 					dsdt = NULL;
-				return dsdt;
+				if (dsdt) {
+					if (!index)
+						return dsdt;
+					--index;
+				}
 			}
 
 			if (!memcmp(sig, "FACS", ACPI_NAME_LEN)) {
@@ -73,7 +80,11 @@ struct acpi_table_header *acpi_find_table(const char *sig)
 					facs = nomap_sysmem(fadt->firmware_ctrl, 0);
 				else
 					facs = NULL;
-				return facs;
+				if (facs) {
+					if (!index)
+						return facs;
+					--index;
+				}
 			}
 		}
 	}
diff --git a/test/dm/acpi.c b/test/dm/acpi.c
index 559ea269de2..8bec09f4e44 100644
--- a/test/dm/acpi.c
+++ b/test/dm/acpi.c
@@ -809,33 +809,33 @@ static int dm_test_acpi_find_table(struct unit_test_state *uts)
 	ut_assert(xsdt);
 
 	/* Find with both RSDT and XSDT */
-	table = acpi_find_table("TST1");
+	table = acpi_find_table("TST1", 0);
 	ut_asserteq_ptr(table1, table);
 	ut_asserteq_strn("TST1", table->signature);
-	table = acpi_find_table("TST2");
+	table = acpi_find_table("TST2", 0);
 	ut_asserteq_ptr(table2, table);
 	ut_asserteq_strn("TST2", table->signature);
-	table = acpi_find_table("TST3");
+	table = acpi_find_table("TST3", 0);
 	ut_asserteq_ptr(table3, table);
 	ut_asserteq_strn("TST3", table->signature);
 
 	/* Find with XSDT only */
 	rsdp->rsdt_address = 0;
-	table = acpi_find_table("TST1");
+	table = acpi_find_table("TST1", 0);
 	ut_asserteq_ptr(table1, table);
-	table = acpi_find_table("TST2");
+	table = acpi_find_table("TST2", 0);
 	ut_asserteq_ptr(table2, table);
-	table = acpi_find_table("TST3");
+	table = acpi_find_table("TST3", 0);
 	ut_asserteq_ptr(table3, table);
 	rsdp->rsdt_address = rsdt;
 
 	/* Find with RSDT only */
 	rsdp->xsdt_address = 0;
-	table = acpi_find_table("TST1");
+	table = acpi_find_table("TST1", 0);
 	ut_asserteq_ptr(table1, table);
-	table = acpi_find_table("TST2");
+	table = acpi_find_table("TST2", 0);
 	ut_asserteq_ptr(table2, table);
-	table = acpi_find_table("TST3");
+	table = acpi_find_table("TST3", 0);
 	ut_asserteq_ptr(table3, table);
 	rsdp->xsdt_address = xsdt;
 
-- 
2.53.0



More information about the U-Boot mailing list