[SeaBIOS] [PATCH 4/5] Use biostables.c for copying bios tables even when generating them.

Kevin O'Connor kevin at koconnor.net
Mon Apr 7 22:49:07 CEST 2014


Use the biostables.c copy_pir(), copy_smbios(), copy_acpi_rsdp(), and
copy_mptable() code even when using the legacy bios table generation
code.  This unifies the final bios table deployment code between qemu,
coreboot, and csm.

Signed-off-by: Kevin O'Connor <kevin at koconnor.net>
---
 src/fw/acpi.c       | 19 +++++++------------
 src/fw/biostables.c |  9 ++++++---
 src/fw/mptable.c    | 33 +++++++++------------------------
 src/fw/pirtable.c   |  7 ++-----
 src/fw/smbios.c     | 37 ++++++++++++++++---------------------
 src/util.h          |  3 +++
 6 files changed, 43 insertions(+), 65 deletions(-)

diff --git a/src/fw/acpi.c b/src/fw/acpi.c
index 340ea9d..70284ab 100644
--- a/src/fw/acpi.c
+++ b/src/fw/acpi.c
@@ -676,16 +676,11 @@ acpi_setup(void)
     build_header((void*)rsdt, RSDT_SIGNATURE, rsdt_len, 1);
 
     // Build rsdp pointer table
-    struct rsdp_descriptor *rsdp = malloc_fseg(sizeof(*rsdp));
-    if (!rsdp) {
-        warn_noalloc();
-        return;
-    }
-    memset(rsdp, 0, sizeof(*rsdp));
-    rsdp->signature = cpu_to_le64(RSDP_SIGNATURE);
-    memcpy(rsdp->oem_id, BUILD_APPNAME6, 6);
-    rsdp->rsdt_physical_address = cpu_to_le32((u32)rsdt);
-    rsdp->checksum -= checksum(rsdp, 20);
-    RsdpAddr = rsdp;
-    dprintf(1, "ACPI tables: RSDP=%p RSDT=%p\n", rsdp, rsdt);
+    struct rsdp_descriptor rsdp;
+    memset(&rsdp, 0, sizeof(rsdp));
+    rsdp.signature = cpu_to_le64(RSDP_SIGNATURE);
+    memcpy(rsdp.oem_id, BUILD_APPNAME6, 6);
+    rsdp.rsdt_physical_address = cpu_to_le32((u32)rsdt);
+    rsdp.checksum -= checksum(&rsdp, 20);
+    copy_acpi_rsdp(&rsdp);
 }
diff --git a/src/fw/biostables.c b/src/fw/biostables.c
index b132734..19fcbf9 100644
--- a/src/fw/biostables.c
+++ b/src/fw/biostables.c
@@ -19,7 +19,7 @@
 
 struct pir_header *PirAddr VARFSEG;
 
-static void
+void
 copy_pir(void *pos)
 {
     struct pir_header *p = pos;
@@ -41,7 +41,7 @@ copy_pir(void *pos)
     PirAddr = newpos;
 }
 
-static void
+void
 copy_mptable(void *pos)
 {
     struct mptable_floating_s *p = pos;
@@ -53,6 +53,9 @@ copy_mptable(void *pos)
         return;
     u32 length = p->length * 16;
     u16 mpclength = ((struct mptable_config_s *)p->physaddr)->length;
+    // Allocate final memory location.  (In theory the config
+    // structure can go in high memory, but Linux kernels before
+    // v2.6.30 crash with that.)
     struct mptable_floating_s *newpos = malloc_fseg(length + mpclength);
     if (!newpos) {
         warn_noalloc();
@@ -93,7 +96,7 @@ get_acpi_rsdp_length(void *pos, unsigned size)
 
 struct rsdp_descriptor *RsdpAddr;
 
-static void
+void
 copy_acpi_rsdp(void *pos)
 {
     if (RsdpAddr)
diff --git a/src/fw/mptable.c b/src/fw/mptable.c
index b453469..59c2a3e 100644
--- a/src/fw/mptable.c
+++ b/src/fw/mptable.c
@@ -182,29 +182,14 @@ mptable_setup(void)
     config->length = length;
     config->checksum -= checksum(config, length);
 
-    // Allocate final memory locations.  (In theory the config
-    // structure can go in high memory, but Linux kernels before
-    // v2.6.30 crash with that.)
-    struct mptable_config_s *finalconfig = malloc_fseg(length);
-    struct mptable_floating_s *floating = malloc_fseg(sizeof(*floating));
-    if (!finalconfig || !floating) {
-        warn_noalloc();
-        free(config);
-        free(finalconfig);
-        free(floating);
-        return;
-    }
-    memcpy(finalconfig, config, length);
+    // floating pointer structure
+    struct mptable_floating_s floating;
+    memset(&floating, 0, sizeof(floating));
+    floating.signature = MPTABLE_SIGNATURE;
+    floating.physaddr = (u32)config;
+    floating.length = 1;
+    floating.spec_rev = 4;
+    floating.checksum -= checksum(&floating, sizeof(floating));
+    copy_mptable(&floating);
     free(config);
-
-    /* floating pointer structure */
-    memset(floating, 0, sizeof(*floating));
-    floating->signature = MPTABLE_SIGNATURE;
-    floating->physaddr = (u32)finalconfig;
-    floating->length = 1;
-    floating->spec_rev = 4;
-    floating->checksum -= checksum(floating, sizeof(*floating));
-
-    dprintf(1, "MP table addr=%p MPC table addr=%p size=%d\n",
-            floating, finalconfig, length);
 }
diff --git a/src/fw/pirtable.c b/src/fw/pirtable.c
index ded9143..44fc71b 100644
--- a/src/fw/pirtable.c
+++ b/src/fw/pirtable.c
@@ -16,9 +16,7 @@ struct pir_table {
     struct pir_slot slots[6];
 } PACKED;
 
-extern struct pir_table PIR_TABLE;
-#if CONFIG_PIRTABLE
-struct pir_table PIR_TABLE __aligned(16) VARFSEG = {
+static struct pir_table PIR_TABLE = {
     .pir = {
         .version = 0x0100,
         .size = sizeof(struct pir_table),
@@ -89,7 +87,6 @@ struct pir_table PIR_TABLE __aligned(16) VARFSEG = {
         },
     }
 };
-#endif // CONFIG_PIRTABLE
 
 void
 pirtable_setup(void)
@@ -101,5 +98,5 @@ pirtable_setup(void)
 
     PIR_TABLE.pir.signature = PIR_SIGNATURE;
     PIR_TABLE.pir.checksum -= checksum(&PIR_TABLE, sizeof(PIR_TABLE));
-    PirAddr = &PIR_TABLE.pir;
+    copy_pir(&PIR_TABLE);
 }
diff --git a/src/fw/smbios.c b/src/fw/smbios.c
index 902e8ab..6d580c2 100644
--- a/src/fw/smbios.c
+++ b/src/fw/smbios.c
@@ -21,7 +21,6 @@ smbios_entry_point_setup(u16 max_structure_size,
                          void *structure_table_address,
                          u16 number_of_structures)
 {
-    struct smbios_entry_point *ep = malloc_fseg(sizeof(*ep));
     void *finaltable;
     if (structure_table_length <= BUILD_MAX_SMBIOS_FSEG)
         // Table is small enough for f-seg - allocate there.  This
@@ -29,35 +28,31 @@ smbios_entry_point_setup(u16 max_structure_size,
         finaltable = malloc_fseg(structure_table_length);
     else
         finaltable = malloc_high(structure_table_length);
-    if (!ep || !finaltable) {
+    if (!finaltable) {
         warn_noalloc();
-        free(ep);
-        free(finaltable);
         return;
     }
     memcpy(finaltable, structure_table_address, structure_table_length);
 
-    memcpy(ep->anchor_string, "_SM_", 4);
-    ep->length = 0x1f;
-    ep->smbios_major_version = 2;
-    ep->smbios_minor_version = 4;
-    ep->max_structure_size = max_structure_size;
-    ep->entry_point_revision = 0;
-    memset(ep->formatted_area, 0, 5);
-    memcpy(ep->intermediate_anchor_string, "_DMI_", 5);
+    struct smbios_entry_point ep;
+    memset(&ep, 0, sizeof(ep));
+    memcpy(ep.anchor_string, "_SM_", 4);
+    ep.length = 0x1f;
+    ep.smbios_major_version = 2;
+    ep.smbios_minor_version = 4;
+    ep.max_structure_size = max_structure_size;
+    memcpy(ep.intermediate_anchor_string, "_DMI_", 5);
 
-    ep->structure_table_length = structure_table_length;
-    ep->structure_table_address = (u32)finaltable;
-    ep->number_of_structures = number_of_structures;
-    ep->smbios_bcd_revision = 0x24;
+    ep.structure_table_length = structure_table_length;
+    ep.structure_table_address = (u32)finaltable;
+    ep.number_of_structures = number_of_structures;
+    ep.smbios_bcd_revision = 0x24;
 
-    ep->checksum -= checksum(ep, 0x10);
+    ep.checksum -= checksum(&ep, 0x10);
 
-    ep->intermediate_checksum -= checksum((void*)ep + 0x10, ep->length - 0x10);
+    ep.intermediate_checksum -= checksum((void*)&ep + 0x10, ep.length - 0x10);
 
-    SMBiosAddr = ep;
-    dprintf(1, "SMBIOS ptr=%p table=%p size=%d\n"
-            , ep, finaltable, structure_table_length);
+    copy_smbios(&ep);
 }
 
 static int
diff --git a/src/util.h b/src/util.h
index 223d5c0..dd0ec6a 100644
--- a/src/util.h
+++ b/src/util.h
@@ -64,7 +64,10 @@ void handle_1586(struct bregs *regs);
 void acpi_setup(void);
 
 // fw/biostable.c
+void copy_pir(void *pos);
+void copy_mptable(void *pos);
 extern struct pir_header *PirAddr;
+void copy_acpi_rsdp(void *pos);
 extern struct rsdp_descriptor *RsdpAddr;
 extern u32 acpi_pm1a_cnt;
 void *find_acpi_rsdp(void);
-- 
1.9.0




More information about the SeaBIOS mailing list