qemu: add rom loading via fw_cfg
authorGerd Hoffmann <kraxel@redhat.com>
Fri, 18 Dec 2009 11:16:04 +0000 (12:16 +0100)
committerAnthony Liguori <aliguori@us.ibm.com>
Fri, 18 Dec 2009 15:42:15 +0000 (09:42 -0600)
Add support for loading roms using the qemu fw_cfg interface,
modeled after the existing cbfs support.  Use it to look for
vgabios (vgaroms/*) and option roms (genroms/*).

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
src/optionroms.c
src/paravirt.c
src/paravirt.h

index 27465adc6778c8202ec475aabce91b14261a9dfd..0be68524d290ac87f11b85ebbadc0e3f23ca2027 100644 (file)
@@ -13,6 +13,7 @@
 #include "pci_regs.h" // PCI_ROM_ADDRESS
 #include "pci_ids.h" // PCI_CLASS_DISPLAY_VGA
 #include "boot.h" // IPL
+#include "paravirt.h" // qemu_cfg_*
 
 
 /****************************************************************
@@ -247,6 +248,26 @@ run_cbfs_roms(const char *prefix, int isvga)
     }
 }
 
+static void
+run_qemu_roms(const char *prefix, int isvga)
+{
+    struct QemuCfgFile entry;
+    int plen = strlen(prefix);
+    int rc, dlen;
+
+    rc = qemu_cfg_first_file(&entry);
+    while (rc > 0) {
+        if (memcmp(prefix, entry.name, plen) == 0) {
+            dlen = qemu_cfg_read_file(&entry, (void*)RomEnd, max_rom() - RomEnd);
+            if (dlen > 0) {
+                dprintf(1, "init qemu rom: %s\n", entry.name);
+                init_optionrom((void*)RomEnd, 0, isvga);
+            }
+        }
+        rc = qemu_cfg_next_file(&entry);
+    }
+}
+
 
 /****************************************************************
  * PCI roms
@@ -375,6 +396,7 @@ optionrom_setup()
 
         // Find and deploy CBFS roms not associated with a device.
         run_cbfs_roms("genroms/", 0);
+        run_qemu_roms("genroms/", 0);
     }
 
     // All option roms found and deployed - now build BEV/BCV vectors.
@@ -434,6 +456,7 @@ vga_setup()
 
         // Find and deploy CBFS vga-style roms not associated with a device.
         run_cbfs_roms("vgaroms/", 1);
+        run_qemu_roms("vgaroms/", 1);
     }
 
     if (RomEnd == BUILD_ROM_START) {
index 6f48d2e0ff48a924df586604fb472c5296676897..7171bac2bfe99beec790720e45488b49d52c054a 100644 (file)
@@ -8,6 +8,7 @@
 // This file may be distributed under the terms of the GNU LGPLv3 license.
 
 #include "config.h" // CONFIG_COREBOOT
+#include "util.h" // ntoh[ls]
 #include "ioport.h" // outw
 #include "paravirt.h" // qemu_cfg_port_probe
 #include "smbios.h" // struct smbios_structure_header
@@ -287,3 +288,39 @@ u16 qemu_cfg_get_max_cpus(void)
 
     return cnt;
 }
+
+u16 qemu_cfg_first_file(QemuCfgFile *entry)
+{
+    memset(entry, 0, sizeof(*entry));
+    return qemu_cfg_next_file(entry);
+}
+
+u16 qemu_cfg_next_file(QemuCfgFile *entry)
+{
+    u16 last = ntohs(entry->select);
+    u32 e,count;
+
+    if (!qemu_cfg_present)
+        return 0;
+
+    qemu_cfg_read_entry(&count, QEMU_CFG_FILE_DIR, sizeof(count));
+    for (e = 0; e < ntohl(count); e++) {
+        qemu_cfg_read((void*)entry, sizeof(*entry));
+        if (ntohs(entry->select) > last) {
+            return 1;
+        }
+    }
+    return 0;
+}
+
+u32 qemu_cfg_read_file(QemuCfgFile *entry, void *dst, u32 maxlen)
+{
+    int len = ntohl(entry->size);
+
+    if (!qemu_cfg_present)
+        return 0;
+    if (len > maxlen)
+        return 0;
+    qemu_cfg_read_entry(dst, ntohs(entry->select), len);
+    return len;
+}
index 29a2c04af2b780baf9e2d71120e7cb232f573ab6..4cef48e16e51c6f00e357ba9a759eab92aa98f96 100644 (file)
@@ -31,6 +31,7 @@ static inline int kvm_para_available(void)
 #define QEMU_CFG_NUMA                  0x0d
 #define QEMU_CFG_BOOT_MENU             0x0e
 #define QEMU_CFG_MAX_CPUS              0x0f
+#define QEMU_CFG_FILE_DIR               0x19
 #define QEMU_CFG_ARCH_LOCAL            0x8000
 #define QEMU_CFG_ACPI_TABLES           (QEMU_CFG_ARCH_LOCAL + 0)
 #define QEMU_CFG_SMBIOS_ENTRIES                (QEMU_CFG_ARCH_LOCAL + 1)
@@ -53,4 +54,15 @@ int qemu_cfg_get_numa_nodes(void);
 void qemu_cfg_get_numa_data(u64 *data, int n);
 u16 qemu_cfg_get_max_cpus(void);
 
+typedef struct QemuCfgFile {
+    u32  size;        /* file size */
+    u16  select;      /* write this to 0x510 to read it */
+    u16  reserved;
+    char name[56];
+} QemuCfgFile;
+
+u16 qemu_cfg_first_file(QemuCfgFile *entry);
+u16 qemu_cfg_next_file(QemuCfgFile *entry);
+u32 qemu_cfg_read_file(QemuCfgFile *entry, void *dst, u32 maxlen);
+
 #endif