Be sure to add "void" to all function prototypes that take no args.
[seabios.git] / src / coreboot.c
index 1b93f480a85aacb36353f28f039652d88442299c..7ad46cedbd3b310898b3536695572332edd19ad6 100644 (file)
@@ -11,6 +11,7 @@
 #include "mptable.h" // MPTABLE_SIGNATURE
 #include "biosvar.h" // GET_EBDA
 #include "lzmadecode.h" // LzmaDecode
+#include "smbios.h" // smbios_init
 
 
 /****************************************************************
@@ -121,7 +122,7 @@ static struct cb_memory *CBMemTable;
 
 // Populate max ram and e820 map info by scanning for a coreboot table.
 static void
-coreboot_fill_map()
+coreboot_fill_map(void)
 {
     dprintf(3, "Attempting to find coreboot table\n");
 
@@ -281,7 +282,7 @@ scan_tables(u32 start, u32 size)
 }
 
 void
-coreboot_copy_biostable()
+coreboot_copy_biostable(void)
 {
     struct cb_memory *cbm = CBMemTable;
     if (! CONFIG_COREBOOT || !cbm)
@@ -350,11 +351,6 @@ ulzma(u8 *dst, u32 maxlen, const u8 *src, u32 srclen)
  * Coreboot flash format
  ****************************************************************/
 
-// XXX - optimize
-#define ntohl(x) ((((x)&0xff)<<24) | (((x)&0xff00)<<8) | \
-                  (((x)&0xff0000) >> 8) | (((x)&0xff000000) >> 24))
-#define htonl(x) ntohl(x)
-
 #define CBFS_HEADER_MAGIC 0x4F524243
 #define CBFS_HEADPTR_ADDR 0xFFFFFFFc
 #define CBFS_VERSION1 0x31313131
@@ -372,7 +368,7 @@ struct cbfs_header {
 static struct cbfs_header *CBHDR;
 
 static void
-cbfs_setup()
+cbfs_setup(void)
 {
     if (! CONFIG_COREBOOT_FLASH)
         return;
@@ -415,7 +411,7 @@ cbfs_verify(struct cbfs_file *file)
 
 // Return the first file in the CBFS archive
 static struct cbfs_file *
-cbfs_getfirst()
+cbfs_getfirst(void)
 {
     if (! CBHDR)
         return NULL;
@@ -512,9 +508,18 @@ cbfs_copyfile(struct cbfs_file *file, void *dst, u32 maxlen)
 
     u32 size = ntohl(file->len);
     void *src = (void*)file + ntohl(file->offset);
-    if (cbfs_iscomp(file))
-        // Compressed.
-        return ulzma(dst, maxlen, src, size);
+    if (cbfs_iscomp(file)) {
+        // Compressed - copy to temp ram and uncompress it.
+        u32 asize = ALIGN(size, 4);
+        void *temp = malloc_tmphigh(asize);
+        if (!temp)
+            return -1;
+        iomemcpy(temp, src, asize);
+        int ret = ulzma(dst, maxlen, temp, size);
+        yield();
+        free(temp);
+        return ret;
+    }
 
     // Not compressed.
     dprintf(3, "Copying data %d@%p to %d@%p\n", size, src, maxlen, dst);
@@ -522,27 +527,10 @@ cbfs_copyfile(struct cbfs_file *file, void *dst, u32 maxlen)
         dprintf(1, "File too big to copy\n");
         return -1;
     }
-    memcpy(dst, src, size);
+    iomemcpy(dst, src, size);
     return size;
 }
 
-static char
-getHex(u8 x)
-{
-    if (x <= 9)
-        return '0' + x;
-    return 'a' + x - 10;
-}
-
-static u32
-hexify4(u16 x)
-{
-    return ((getHex(x&0xf) << 24)
-            | (getHex((x>>4)&0xf) << 16)
-            | (getHex((x>>8)&0xf) << 8)
-            | (getHex(x>>12)));
-}
-
 // Find and copy the optionrom for the given vendor/device id.
 int
 cbfs_copy_optionrom(void *dst, u32 maxlen, u32 vendev)
@@ -551,14 +539,8 @@ cbfs_copy_optionrom(void *dst, u32 maxlen, u32 vendev)
         return -1;
 
     char fname[17];
-    // Ughh - poor man's sprintf of "pci%04x,%04x.rom"
-    *(u32*)fname = 0x20696370; // "pci "
-    *(u32*)&fname[3] = hexify4(vendev);
-    fname[7] = ',';
-    *(u32*)&fname[8] = hexify4(vendev >> 16);
-    *(u32*)&fname[12] = 0x6d6f722e; // ".rom"
-    fname[16] = '\0';
-
+    snprintf(fname, sizeof(fname), "pci%04x,%04x.rom"
+             , (u16)vendev, vendev >> 16);
     return cbfs_copyfile(cbfs_finddatafile(fname), dst, maxlen);
 }