[SeaBIOS] [PATCH 4/6] acpi: Generalize find_fadt() and find_tcpa_by_rsdp() into find_acpi_table()

Kevin O'Connor kevin at koconnor.net
Thu Aug 11 17:18:01 CEST 2016


The find_fadt() and find_tcpa_by_rsdp() functions are very similar.
Create a new find_acpi_table() function and replace the two functions
with this new function.

Signed-off-by: Kevin O'Connor <kevin at koconnor.net>
---
 src/fw/biostables.c | 18 +++++++++---------
 src/std/acpi.h      |  7 -------
 src/tcgbios.c       | 34 +---------------------------------
 src/util.h          |  1 +
 4 files changed, 11 insertions(+), 49 deletions(-)

diff --git a/src/fw/biostables.c b/src/fw/biostables.c
index 9fb9ff9..fe8626e 100644
--- a/src/fw/biostables.c
+++ b/src/fw/biostables.c
@@ -134,8 +134,8 @@ void *find_acpi_rsdp(void)
     return NULL;
 }
 
-static struct fadt_descriptor_rev1 *
-find_fadt(void)
+void *
+find_acpi_table(u32 signature)
 {
     dprintf(4, "rsdp=%p\n", RsdpAddr);
     if (!RsdpAddr || RsdpAddr->signature != RSDP_SIGNATURE)
@@ -147,20 +147,20 @@ find_fadt(void)
     void *end = (void*)rsdt + rsdt->length;
     int i;
     for (i=0; (void*)&rsdt->table_offset_entry[i] < end; i++) {
-        struct fadt_descriptor_rev1 *fadt = (void*)rsdt->table_offset_entry[i];
-        if (!fadt || fadt->signature != FACP_SIGNATURE)
+        struct acpi_table_header *tbl = (void*)rsdt->table_offset_entry[i];
+        if (!tbl || tbl->signature != signature)
             continue;
-        dprintf(4, "fadt=%p\n", fadt);
-        return fadt;
+        dprintf(4, "table(%x)=%p\n", signature, tbl);
+        return tbl;
     }
-    dprintf(4, "no fadt found\n");
+    dprintf(4, "no table %x found\n", signature);
     return NULL;
 }
 
 u32
 find_resume_vector(void)
 {
-    struct fadt_descriptor_rev1 *fadt = find_fadt();
+    struct fadt_descriptor_rev1 *fadt = find_acpi_table(FACP_SIGNATURE);
     if (!fadt)
         return 0;
     struct facs_descriptor_rev1 *facs = (void*)fadt->firmware_ctrl;
@@ -218,7 +218,7 @@ acpi_set_reset_reg(struct acpi_20_generic_address *reg, u8 val)
 void
 find_acpi_features(void)
 {
-    struct fadt_descriptor_rev1 *fadt = find_fadt();
+    struct fadt_descriptor_rev1 *fadt = find_acpi_table(FACP_SIGNATURE);
     if (!fadt)
         return;
     u32 pm_tmr = le32_to_cpu(fadt->pm_tmr_blk);
diff --git a/src/std/acpi.h b/src/std/acpi.h
index b672bbe..c2ea707 100644
--- a/src/std/acpi.h
+++ b/src/std/acpi.h
@@ -294,12 +294,6 @@ struct acpi_table_mcfg {
     struct acpi_mcfg_allocation allocation[0];
 } PACKED;
 
-
-struct rsdt_descriptor {
-    ACPI_TABLE_HEADER_DEF
-    u32 entry[1];
-} PACKED;
-
 #define TCPA_SIGNATURE 0x41504354
 struct tcpa_descriptor_rev2
 {
@@ -313,5 +307,4 @@ struct tcpa_descriptor_rev2
 #define TCPA_ACPI_CLASS_CLIENT          0
 #define TCPA_ACPI_CLASS_SERVER          1
 
-
 #endif // acpi.h
diff --git a/src/tcgbios.c b/src/tcgbios.c
index 5c40d62..5475535 100644
--- a/src/tcgbios.c
+++ b/src/tcgbios.c
@@ -71,42 +71,10 @@ struct {
     u8 *          log_area_last_entry;
 } tpm_state VARLOW;
 
-static struct tcpa_descriptor_rev2 *
-find_tcpa_by_rsdp(struct rsdp_descriptor *rsdp)
-{
-    if (!rsdp) {
-        dprintf(DEBUG_tcg,
-                "TCGBIOS: RSDP was NOT found! -- Disabling interface.\n");
-        return NULL;
-    }
-    struct rsdt_descriptor *rsdt = (void*)rsdp->rsdt_physical_address;
-    if (!rsdt)
-        return NULL;
-
-    u32 length = rsdt->length;
-    u16 off = offsetof(struct rsdt_descriptor, entry);
-    u32 ctr = 0;
-    while ((off + sizeof(rsdt->entry[0])) <= length) {
-        /* try all pointers to structures */
-        struct tcpa_descriptor_rev2 *tcpa = (void*)rsdt->entry[ctr];
-
-        /* valid TCPA ACPI table ? */
-        if (tcpa->signature == TCPA_SIGNATURE
-            && checksum(tcpa, tcpa->length) == 0)
-            return tcpa;
-
-        off += sizeof(rsdt->entry[0]);
-        ctr++;
-    }
-
-    dprintf(DEBUG_tcg, "TCGBIOS: TCPA ACPI was NOT found!\n");
-    return NULL;
-}
-
 static int
 tpm_tcpa_probe(void)
 {
-    struct tcpa_descriptor_rev2 *tcpa = find_tcpa_by_rsdp(RsdpAddr);
+    struct tcpa_descriptor_rev2 *tcpa = find_acpi_table(TCPA_SIGNATURE);
     if (!tcpa)
         return -1;
 
diff --git a/src/util.h b/src/util.h
index 557eb8b..336eaaf 100644
--- a/src/util.h
+++ b/src/util.h
@@ -72,6 +72,7 @@ extern struct rsdp_descriptor *RsdpAddr;
 extern u32 acpi_pm1a_cnt;
 extern u16 acpi_pm_base;
 void *find_acpi_rsdp(void);
+void *find_acpi_table(u32 signature);
 u32 find_resume_vector(void);
 void acpi_reboot(void);
 void find_acpi_features(void);
-- 
2.5.5




More information about the SeaBIOS mailing list