Skip to contentSkip to conversation

option rom patches, next round

PATCH In review Gerd Hoffmann 2 participants 13 messages Dec 17, 2009 – Dec 18, 2009

lore
Share & tools
lore
#0 lore raw

cover option rom patches, next round

Hi,

All in one patch series for pci rom bar support and option rom loading via fw_cfg for the non-pci roms. This time the fw_cfg interface is actually tested with a little linux userspace app (attached below).

cheers,
Gerd

----- [ cut here ] -----
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <sys/io.h>
#include <arpa/inet.h>

#define FW_CFG_FILE_DIR 0x19

typedef struct FWCfgFile {
    uint32_t  size;        /* file size */
    uint16_t  select;      /* write this to 0x510 to read it */
    uint16_t  reserved;
    char      name[56];
} FWCfgFile;

void fw_read(void *ptr, int len)

{
    uint8_t *data = ptr;
    int i;

    for (i = 0; i < len; i++) {
        data[i] = inb(0x511);
    }
}

int main(int argc, char *argv[])

{
    uint8_t data[64];
    FWCfgFile *entry;
    uint32_t e, i, count;

    fprintf(stderr, "fwtest - qemu files\n");
    ioperm(0x510, 4, 1);

    outw(FW_CFG_FILE_DIR, 0x510);
    fw_read(&count, sizeof(count));
    fprintf(stderr, "%d files\n", ntohl(count));
    entry = malloc(sizeof(*entry) * ntohl(count));
    fw_read(entry, sizeof(*entry) * ntohl(count));

    for (e = 0; e < ntohl(count); e++) {
        fprintf(stderr, "   #%d: %s (%d bytes)\n", e,
                entry[e].name, ntohl(entry[e].size));
        outw(ntohs(entry[e].select), 0x510);
        fw_read(data, sizeof(data));

        for (i = 0; i < sizeof(data); i++) {
            if (i % 16 == 0)
                fprintf(stderr, "    ");
            if (i % 4 == 0)
                fprintf(stderr, " ");
            fprintf(stderr, " %02x", data[i]);
            if (i % 16 == 15)
                fprintf(stderr, "\n");
        }
    }
    return 0;
}
#1 lore raw

PATCH 1/6 patched seabios binary

---
 pc-bios/bios.bin |  Bin 131072 -> 131072 bytes
 1 files changed, 0 insertions(+), 0 deletions(-)
pc-bios/bios.bin binary +0 -0
index 29495801950660c19630444e410ff30d673e46af..4e7ae7efeb5964454d263a8b6482206c9d7bc358 100644
GIT binary patch
Signature · 1 line
1.6.5.2
#2 lore raw

PATCH 2/6 Support PCI based option rom loading

In reply to Gerd Hoffmann

From: Anthony Liguori <[email protected]>

Currently, we preload option roms into the option rom space in memory. This prevents DDIM from functioning correctly which severely limits the number of roms we can support.

This patch introduces a pci_add_option_rom() which registers the PCI_ROM_ADDRESS bar which points to our option rom. It also converts over the cirrus vga adapter, the rtl8139, virtio, and the e1000 to use this new mechanism.

The result is that PXE boot functions even with three unique types of cards.

---
 hw/cirrus_vga.c |    2 +-
 hw/e1000.c      |    2 +-
 hw/pci.c        |   35 +++++++++++++++++++++++++++++++++++
 hw/pci.h        |    5 +++++
 hw/rtl8139.c    |    2 +-
 hw/virtio-pci.c |    2 +-
 6 files changed, 44 insertions(+), 4 deletions(-)
hw/cirrus_vga.c +1 -1
index 24af81c..b08d2ae 100644
@@ -3211,7 +3211,7 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev)
      }
 
      /* ROM BIOS */
-     rom_add_vga(VGABIOS_CIRRUS_FILENAME);
+     pci_add_option_rom((PCIDevice *)d, VGABIOS_CIRRUS_FILENAME);
      return 0;
 }
 
hw/e1000.c +1 -1
index 8566fe3..f795601 100644
@@ -1125,7 +1125,7 @@ static int pci_e1000_init(PCIDevice *pci_dev)
     if (!pci_dev->qdev.hotplugged) {
         static int loaded = 0;
         if (!loaded) {
-            rom_add_option("pxe-e1000.bin");
+            pci_add_option_rom(&d->dev, "pxe-e1000.bin");
             loaded = 1;
         }
     }
hw/pci.c +35 -0
index 404eead..dbdfdbf 100644
@@ -26,6 +26,7 @@
 #include "monitor.h"
 #include "net.h"
 #include "sysemu.h"
+#include "loader.h"
 
 //#define DEBUG_PCI
 #ifdef DEBUG_PCI
@@ -1463,6 +1464,40 @@ static uint8_t pci_find_capability_list(PCIDevice *pdev, uint8_t cap_id,
     return next;
 }
 
+static void pci_map_option_rom(PCIDevice *pdev, int region_num, pcibus_t addr, pcibus_t size, int type)
+{
+    cpu_register_physical_memory(addr, size, pdev->rom_offset);
+}
+
+/* Add an option rom for the device */
+int pci_add_option_rom(PCIDevice *pdev, const char *name)
+{
+    int size;
+    char *path;
+    void *ptr;
+
+    path = qemu_find_file(QEMU_FILE_TYPE_BIOS, name);
+    if (path == NULL) {
+        path = qemu_strdup(name);
+    }
+
+    size = get_image_size(path);
+    if (size & (size - 1)) {
+        size = 1 << qemu_fls(size);
+    }
+
+    pdev->rom_offset = qemu_ram_alloc(size);
+
+    ptr = qemu_get_ram_ptr(pdev->rom_offset);
+    load_image(path, ptr);
+    qemu_free(path);
+
+    pci_register_bar(pdev, PCI_ROM_SLOT, size,
+                     0, pci_map_option_rom);
+
+    return 0;
+}
+
 /* Reserve space and add capability to the linked list in pci config space */
 int pci_add_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t size)
 {
hw/pci.h +5 -0
index d279e3f..89b3f55 100644
@@ -243,6 +243,9 @@ struct PCIDevice {
     uint32_t msix_bar_size;
     /* Version id needed for VMState */
     int32_t version_id;
+
+    /* Location of option rom */
+    ram_addr_t rom_offset;
 };
 
 PCIDevice *pci_register_device(PCIBus *bus, const char *name,
@@ -254,6 +257,8 @@ void pci_register_bar(PCIDevice *pci_dev, int region_num,
                             pcibus_t size, int type,
                             PCIMapIORegionFunc *map_func);
 
+int pci_add_option_rom(PCIDevice *pdev, const char *name);
+
 int pci_add_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
 
 void pci_del_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
hw/rtl8139.c +1 -1
index 9fd05a8..2cee97b 100644
@@ -3357,7 +3357,7 @@ static int pci_rtl8139_init(PCIDevice *dev)
     if (!dev->qdev.hotplugged) {
         static int loaded = 0;
         if (!loaded) {
-            rom_add_option("pxe-rtl8139.bin");
+            pci_add_option_rom(&s->dev, "pxe-rtl8139.bin");
             loaded = 1;
         }
     }
hw/virtio-pci.c +1 -1
index 4500130..85f14a2 100644
@@ -522,7 +522,7 @@ static int virtio_net_init_pci(PCIDevice *pci_dev)
     if (!pci_dev->qdev.hotplugged) {
         static int loaded = 0;
         if (!loaded) {
-            rom_add_option("pxe-virtio.bin");
+            pci_add_option_rom(pci_dev, "pxe-virtio.bin");
             loaded = 1;
         }
     }
Signature · 1 line
1.6.5.2
#3 lore raw

PATCH 3/6 pci romfiles: add property, add default to PCIDeviceInfo

In reply to Gerd Hoffmann

This patch adds a romfile property to the pci bus. It allows to specify a romfile to load into the rom bar of the pci device. The default value comes from a new field in PCIDeviceInfo. The property allows to change the file and also to disable the rom loading using an empty string.

---
 hw/cirrus_vga.c |    4 +---
 hw/e1000.c      |    9 +--------
 hw/pci.c        |   24 +++++++++++++++++++++---
 hw/pci.h        |    6 ++++--
 hw/rtl8139.c    |    9 +--------
 hw/virtio-pci.c |    9 +--------
 6 files changed, 29 insertions(+), 32 deletions(-)
hw/cirrus_vga.c +1 -3
index b08d2ae..6fe433d 100644
@@ -3209,9 +3209,6 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev)
          pci_register_bar((PCIDevice *)d, 1, CIRRUS_PNPMMIO_SIZE,
                           PCI_BASE_ADDRESS_SPACE_MEMORY, cirrus_pci_mmio_map);
      }
-
-     /* ROM BIOS */
-     pci_add_option_rom((PCIDevice *)d, VGABIOS_CIRRUS_FILENAME);
      return 0;
 }
 
@@ -3226,6 +3223,7 @@ static PCIDeviceInfo cirrus_vga_info = {
     .qdev.size    = sizeof(PCICirrusVGAState),
     .qdev.vmsd    = &vmstate_pci_cirrus_vga,
     .init         = pci_cirrus_vga_initfn,
+    .romfile      = VGABIOS_CIRRUS_FILENAME,
     .config_write = pci_cirrus_write_config,
 };
 
hw/e1000.c +1 -8
index f795601..33c4bc6 100644
@@ -1121,14 +1121,6 @@ static int pci_e1000_init(PCIDevice *pci_dev)
                           d->dev.qdev.info->name, d->dev.qdev.id, d);
 
     qemu_format_nic_info_str(&d->nic->nc, macaddr);
-
-    if (!pci_dev->qdev.hotplugged) {
-        static int loaded = 0;
-        if (!loaded) {
-            pci_add_option_rom(&d->dev, "pxe-e1000.bin");
-            loaded = 1;
-        }
-    }
     return 0;
 }
 
@@ -1146,6 +1138,7 @@ static PCIDeviceInfo e1000_info = {
     .qdev.vmsd  = &vmstate_e1000,
     .init       = pci_e1000_init,
     .exit       = pci_e1000_uninit,
+    .romfile    = "pxe-e1000.bin",
     .qdev.props = (Property[]) {
         DEFINE_NIC_PROPERTIES(E1000State, conf),
         DEFINE_PROP_END_OF_LIST(),
hw/pci.c +21 -3
index dbdfdbf..d54f05e 100644
@@ -63,12 +63,14 @@ static struct BusInfo pci_bus_info = {
     .print_dev  = pcibus_dev_print,
     .props      = (Property[]) {
         DEFINE_PROP_PCI_DEVFN("addr", PCIDevice, devfn, -1),
+        DEFINE_PROP_STRING("romfile", PCIDevice, romfile),
         DEFINE_PROP_END_OF_LIST()
     }
 };
 
 static void pci_update_mappings(PCIDevice *d);
 static void pci_set_irq(void *opaque, int irq_num, int level);
+static int pci_add_option_rom(PCIDevice *pdev);
 
 target_phys_addr_t pci_mem_base;
 static uint16_t pci_default_sub_vendor_id = PCI_SUBVENDOR_ID_REDHAT_QUMRANET;
@@ -1387,6 +1389,12 @@ static int pci_qdev_init(DeviceState *qdev, DeviceInfo *base)
     rc = info->init(pci_dev);
     if (rc != 0)
         return rc;
+
+    /* rom loading */
+    if (pci_dev->romfile == NULL && info->romfile != NULL)
+        pci_dev->romfile = qemu_strdup(info->romfile);
+    pci_add_option_rom(pci_dev);
+
     if (qdev->hotplugged)
         bus->hotplug(pci_dev, 1);
     return 0;
@@ -1470,18 +1478,28 @@ static void pci_map_option_rom(PCIDevice *pdev, int region_num, pcibus_t addr, p
 }
 
 /* Add an option rom for the device */
-int pci_add_option_rom(PCIDevice *pdev, const char *name)
+static int pci_add_option_rom(PCIDevice *pdev)
 {
     int size;
     char *path;
     void *ptr;
 
-    path = qemu_find_file(QEMU_FILE_TYPE_BIOS, name);
+    if (!pdev->romfile)
+        return 0;
+    if (strlen(pdev->romfile) == 0)
+        return 0;
+
+    path = qemu_find_file(QEMU_FILE_TYPE_BIOS, pdev->romfile);
     if (path == NULL) {
-        path = qemu_strdup(name);
+        path = qemu_strdup(pdev->romfile);
     }
 
     size = get_image_size(path);
+    if (size < 0) {
+        qemu_error("%s: failed to find romfile \"%s\"\n", __FUNCTION__,
+                   pdev->romfile);
+        return -1;
+    }
     if (size & (size - 1)) {
         size = 1 << qemu_fls(size);
     }
hw/pci.h +4 -2
index 89b3f55..39da7df 100644
@@ -245,6 +245,7 @@ struct PCIDevice {
     int32_t version_id;
 
     /* Location of option rom */
+    char *romfile;
     ram_addr_t rom_offset;
 };
 
@@ -257,8 +258,6 @@ void pci_register_bar(PCIDevice *pci_dev, int region_num,
                             pcibus_t size, int type,
                             PCIMapIORegionFunc *map_func);
 
-int pci_add_option_rom(PCIDevice *pdev, const char *name);
-
 int pci_add_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
 
 void pci_del_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
@@ -386,6 +385,9 @@ typedef struct {
 
     /* pcie stuff */
     int is_express;   /* is this device pci express? */
+
+    /* rom bar */
+    const char *romfile;
 } PCIDeviceInfo;
 
 void pci_qdev_register(PCIDeviceInfo *info);
hw/rtl8139.c +1 -8
index 2cee97b..fcdcd1d 100644
@@ -3353,14 +3353,6 @@ static int pci_rtl8139_init(PCIDevice *dev)
     qemu_mod_timer(s->timer,
         rtl8139_get_next_tctr_time(s,qemu_get_clock(vm_clock)));
 #endif /* RTL8139_ONBOARD_TIMER */
-
-    if (!dev->qdev.hotplugged) {
-        static int loaded = 0;
-        if (!loaded) {
-            pci_add_option_rom(&s->dev, "pxe-rtl8139.bin");
-            loaded = 1;
-        }
-    }
     return 0;
 }
 
@@ -3371,6 +3363,7 @@ static PCIDeviceInfo rtl8139_info = {
     .qdev.vmsd  = &vmstate_rtl8139,
     .init       = pci_rtl8139_init,
     .exit       = pci_rtl8139_uninit,
+    .romfile    = "pxe-rtl8139.bin",
     .qdev.props = (Property[]) {
         DEFINE_NIC_PROPERTIES(RTL8139State, conf),
         DEFINE_PROP_END_OF_LIST(),
hw/virtio-pci.c +1 -8
index 85f14a2..62b46bd 100644
@@ -518,14 +518,6 @@ static int virtio_net_init_pci(PCIDevice *pci_dev)
 
     /* make the actual value visible */
     proxy->nvectors = vdev->nvectors;
-
-    if (!pci_dev->qdev.hotplugged) {
-        static int loaded = 0;
-        if (!loaded) {
-            pci_add_option_rom(pci_dev, "pxe-virtio.bin");
-            loaded = 1;
-        }
-    }
     return 0;
 }
 
@@ -569,6 +561,7 @@ static PCIDeviceInfo virtio_info[] = {
         .qdev.size  = sizeof(VirtIOPCIProxy),
         .init       = virtio_net_init_pci,
         .exit       = virtio_net_exit_pci,
+        .romfile    = "pxe-virtio.bin",
         .qdev.props = (Property[]) {
             DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
             DEFINE_NIC_PROPERTIES(VirtIOPCIProxy, nic),
Signature · 1 line
1.6.5.2
#4 lore raw

Re: [Qemu-devel] [PATCH 3/6] pci romfiles: add property, add default to PCIDeviceInfo

Quoted 30 lines · Gerd Hoffmann

This patch adds a romfile property to the pci bus. It allows to specify a romfile to load into the rom bar of the pci device. The default value comes from a new field in PCIDeviceInfo. The property allows to change the file and also to disable the rom loading using an empty string.

---
 hw/cirrus_vga.c |    4 +---
 hw/e1000.c      |    9 +--------
 hw/pci.c        |   24 +++++++++++++++++++++---
 hw/pci.h        |    6 ++++--
 hw/rtl8139.c    |    9 +--------
 hw/virtio-pci.c |    9 +--------
 6 files changed, 29 insertions(+), 32 deletions(-)
hw/cirrus_vga.c +0 -3
index b08d2ae..6fe433d 100644
@@ -3209,9 +3209,6 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev)
          pci_register_bar((PCIDevice *)d, 1, CIRRUS_PNPMMIO_SIZE,
                           PCI_BASE_ADDRESS_SPACE_MEMORY, cirrus_pci_mmio_map);
      }
-
-     /* ROM BIOS */
-     pci_add_option_rom((PCIDevice *)d, VGABIOS_CIRRUS_FILENAME);
      return 0;
 }
 

hw/cirrus_vga.c static PCIDeviceInfo cirrus_vga_info = { · line 3229

Quoted 7 lines
hw/cirrus_vga.c +1 -0
@@ -3226,6 +3223,7 @@ static PCIDeviceInfo cirrus_vga_info = {
     .qdev.size    = sizeof(PCICirrusVGAState),
     .qdev.vmsd    = &vmstate_pci_cirrus_vga,
     .init         = pci_cirrus_vga_initfn,
+    .romfile      = VGABIOS_CIRRUS_FILENAME,
     .config_write = pci_cirrus_write_config,
 };
 

Really nice example of qdev in action. Very nice cleanup!

Regards,

Anthony Liguori

#5 lore raw

PATCH 4/6 fw_cfg: make calls typesafe

In reply to Gerd Hoffmann
---
 hw/fw_cfg.c |   26 ++++++++++++--------------
 hw/fw_cfg.h |   16 +++++++++-------
 2 files changed, 21 insertions(+), 21 deletions(-)
hw/fw_cfg.c +12 -14
index b25afff..2e3662d 100644
@@ -45,11 +45,11 @@ typedef struct _FWCfgEntry {
     FWCfgCallback callback;
 } FWCfgEntry;
 
-typedef struct _FWCfgState {
+struct _FWCfgState {
     FWCfgEntry entries[2][FW_CFG_MAX_ENTRY];
     uint16_t cur_entry;
     uint32_t cur_offset;
-} FWCfgState;
+};
 
 static void fw_cfg_write(FWCfgState *s, uint8_t value)
 {
@@ -210,9 +210,8 @@ static const VMStateDescription vmstate_fw_cfg = {
     }
 };
 
-int fw_cfg_add_bytes(void *opaque, uint16_t key, uint8_t *data, uint32_t len)
+int fw_cfg_add_bytes(FWCfgState *s, uint16_t key, uint8_t *data, uint32_t len)
 {
-    FWCfgState *s = opaque;
     int arch = !!(key & FW_CFG_ARCH_LOCAL);
 
     key &= FW_CFG_ENTRY_MASK;
@@ -226,37 +225,36 @@ int fw_cfg_add_bytes(void *opaque, uint16_t key, uint8_t *data, uint32_t len)
     return 1;
 }
 
-int fw_cfg_add_i16(void *opaque, uint16_t key, uint16_t value)
+int fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value)
 {
     uint16_t *copy;
 
     copy = qemu_malloc(sizeof(value));
     *copy = cpu_to_le16(value);
-    return fw_cfg_add_bytes(opaque, key, (uint8_t *)copy, sizeof(value));
+    return fw_cfg_add_bytes(s, key, (uint8_t *)copy, sizeof(value));
 }
 
-int fw_cfg_add_i32(void *opaque, uint16_t key, uint32_t value)
+int fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value)
 {
     uint32_t *copy;
 
     copy = qemu_malloc(sizeof(value));
     *copy = cpu_to_le32(value);
-    return fw_cfg_add_bytes(opaque, key, (uint8_t *)copy, sizeof(value));
+    return fw_cfg_add_bytes(s, key, (uint8_t *)copy, sizeof(value));
 }
 
-int fw_cfg_add_i64(void *opaque, uint16_t key, uint64_t value)
+int fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value)
 {
     uint64_t *copy;
 
     copy = qemu_malloc(sizeof(value));
     *copy = cpu_to_le64(value);
-    return fw_cfg_add_bytes(opaque, key, (uint8_t *)copy, sizeof(value));
+    return fw_cfg_add_bytes(s, key, (uint8_t *)copy, sizeof(value));
 }
 
-int fw_cfg_add_callback(void *opaque, uint16_t key, FWCfgCallback callback,
+int fw_cfg_add_callback(FWCfgState *s, uint16_t key, FWCfgCallback callback,
                         void *callback_opaque, uint8_t *data, size_t len)
 {
-    FWCfgState *s = opaque;
     int arch = !!(key & FW_CFG_ARCH_LOCAL);
 
     if (!(key & FW_CFG_WRITE_CHANNEL))
@@ -275,8 +273,8 @@ int fw_cfg_add_callback(void *opaque, uint16_t key, FWCfgCallback callback,
     return 1;
 }
 
-void *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
-		target_phys_addr_t ctl_addr, target_phys_addr_t data_addr)
+FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
+                        target_phys_addr_t ctl_addr, target_phys_addr_t data_addr)
 {
     FWCfgState *s;
     int io_ctl_memory, io_data_memory;
hw/fw_cfg.h +9 -7
index 7070c94..b06665e 100644
@@ -37,14 +37,16 @@
 #ifndef NO_QEMU_PROTOS
 typedef void (*FWCfgCallback)(void *opaque, uint8_t *data);
 
-int fw_cfg_add_bytes(void *opaque, uint16_t key, uint8_t *data, uint32_t len);
-int fw_cfg_add_i16(void *opaque, uint16_t key, uint16_t value);
-int fw_cfg_add_i32(void *opaque, uint16_t key, uint32_t value);
-int fw_cfg_add_i64(void *opaque, uint16_t key, uint64_t value);
-int fw_cfg_add_callback(void *opaque, uint16_t key, FWCfgCallback callback,
+typedef struct _FWCfgState FWCfgState;
+int fw_cfg_add_bytes(FWCfgState *s, uint16_t key, uint8_t *data, uint32_t len);
+int fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value);
+int fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value);
+int fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value);
+int fw_cfg_add_callback(FWCfgState *s, uint16_t key, FWCfgCallback callback,
                         void *callback_opaque, uint8_t *data, size_t len);
-void *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
-		target_phys_addr_t crl_addr, target_phys_addr_t data_addr);
+int fw_cfg_add_file(FWCfgState *s, uint8_t type, uint8_t *data, uint32_t len);
+FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
+                        target_phys_addr_t crl_addr, target_phys_addr_t data_addr);
 
 #endif /* NO_QEMU_PROTOS */
 
Signature · 1 line
1.6.5.2
#6 lore raw

PATCH 5/6 fw_cfg: add API for file transfer.

In reply to Gerd Hoffmann

This patch adds a file transfer interface to fw_cfg. Intended to be used for passing non-pci option roms and vgabios to seabios. Namespace is modeled after the existing cbfs filesystem support in seabios.

Reading the new FW_CFG_FILE_DIR entry returns a file list. Fields there are in network byte order (aka bigendian).

---
 hw/fw_cfg.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 hw/fw_cfg.h |   21 +++++++++++++++++++--
 2 files changed, 62 insertions(+), 2 deletions(-)
hw/fw_cfg.c +43 -0
index 2e3662d..0492f5f 100644
@@ -47,6 +47,7 @@ typedef struct _FWCfgEntry {
 
 struct _FWCfgState {
     FWCfgEntry entries[2][FW_CFG_MAX_ENTRY];
+    FWCfgFiles *files;
     uint16_t cur_entry;
     uint32_t cur_offset;
 };
@@ -273,6 +274,48 @@ int fw_cfg_add_callback(FWCfgState *s, uint16_t key, FWCfgCallback callback,
     return 1;
 }
 
+int fw_cfg_add_file(FWCfgState *s,  const char *dir, const char *filename,
+                    uint8_t *data, uint32_t len)
+{
+    const char *basename;
+    int index;
+
+    if (!s->files) {
+        int dsize = sizeof(uint32_t) + sizeof(FWCfgFile) * FW_CFG_FILE_SLOTS;
+        s->files = qemu_mallocz(dsize);
+        fw_cfg_add_bytes(s, FW_CFG_FILE_DIR, (uint8_t*)s->files, dsize);
+    }
+
+    index = be32_to_cpu(s->files->count);
+    if (index == FW_CFG_FILE_SLOTS) {
+        fprintf(stderr, "fw_cfg: out of file slots\n");
+        return 0;
+    }
+
+    fw_cfg_add_bytes(s, FW_CFG_FILE_FIRST + index, data, len);
+
+    basename = strrchr(filename, '/');
+    if (basename) {
+        basename++;
+    } else {
+        basename = filename;
+    }
+    if (dir) {
+        snprintf(s->files->f[index].name, sizeof(s->files->f[index].name),
+                 "%s/%s", dir, basename);
+    } else {
+        snprintf(s->files->f[index].name, sizeof(s->files->f[index].name),
+                 "%s", basename);
+    }
+    s->files->f[index].size   = cpu_to_be32(len);
+    s->files->f[index].select = cpu_to_be16(FW_CFG_FILE_FIRST + index);
+    fprintf(stderr, "%s: #%d: %s (%d bytes)\n", __FUNCTION__,
+            index, s->files->f[index].name, len);
+
+    s->files->count = cpu_to_be32(index+1);
+    return 1;
+}
+
 FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
                         target_phys_addr_t ctl_addr, target_phys_addr_t data_addr)
 {
hw/fw_cfg.h +19 -2
index b06665e..a63f54f 100644
@@ -26,7 +26,11 @@
 #define FW_CFG_SETUP_ADDR       0x16
 #define FW_CFG_SETUP_SIZE       0x17
 #define FW_CFG_SETUP_DATA       0x18
-#define FW_CFG_MAX_ENTRY        0x19
+#define FW_CFG_FILE_DIR         0x19
+
+#define FW_CFG_FILE_FIRST       0x20
+#define FW_CFG_FILE_SLOTS       0x10
+#define FW_CFG_MAX_ENTRY        (FW_CFG_FILE_FIRST+FW_CFG_FILE_SLOTS)
 
 #define FW_CFG_WRITE_CHANNEL    0x4000
 #define FW_CFG_ARCH_LOCAL       0x8000
@@ -34,6 +38,18 @@
 
 #define FW_CFG_INVALID          0xffff
 
+typedef struct FWCfgFile {
+    uint32_t  size;        /* file size */
+    uint16_t  select;      /* write this to 0x510 to read it */
+    uint16_t  reserved;
+    char      name[56];
+} FWCfgFile;
+
+typedef struct FWCfgFiles {
+    uint32_t  count;
+    FWCfgFile f[];
+} FWCfgFiles;
+
 #ifndef NO_QEMU_PROTOS
 typedef void (*FWCfgCallback)(void *opaque, uint8_t *data);
 
@@ -44,7 +60,8 @@ int fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value);
 int fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value);
 int fw_cfg_add_callback(FWCfgState *s, uint16_t key, FWCfgCallback callback,
                         void *callback_opaque, uint8_t *data, size_t len);
-int fw_cfg_add_file(FWCfgState *s, uint8_t type, uint8_t *data, uint32_t len);
+int fw_cfg_add_file(FWCfgState *s, const char *dir, const char *filename,
+                    uint8_t *data, uint32_t len);
 FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
                         target_phys_addr_t crl_addr, target_phys_addr_t data_addr);
 
Signature · 1 line
1.6.5.2
#7 lore raw

PATCH 6/6 roms: use fw_cfg file.

In reply to Gerd Hoffmann
---
 hw/loader.c |   25 ++++++++++++++++++++++---
 hw/loader.h |    5 +++--
 hw/pc.c     |    2 ++
 3 files changed, 27 insertions(+), 5 deletions(-)
hw/loader.c +22 -3
index 2d7a2c4..451ee54 100644
@@ -48,6 +48,7 @@
 #include "sysemu.h"
 #include "uboot_image.h"
 #include "loader.h"
+#include "fw_cfg.h"
 
 #include <zlib.h>
 
@@ -528,6 +529,8 @@ struct Rom {
     uint8_t *data;
     int align;
     int isrom;
+    char *fw_dir;
+    char *fw_file;
 
     target_phys_addr_t min;
     target_phys_addr_t max;
@@ -556,7 +559,7 @@ static void rom_insert(Rom *rom)
     QTAILQ_INSERT_TAIL(&roms, rom, next);
 }
 
-int rom_add_file(const char *file,
+int rom_add_file(const char *file, const char *fw_dir, const char *fw_file,
                  target_phys_addr_t min, target_phys_addr_t max, int align)
 {
     Rom *rom;
@@ -576,6 +579,8 @@ int rom_add_file(const char *file,
         goto err;
     }
 
+    rom->fw_dir  = fw_dir  ? qemu_strdup(fw_dir)  : NULL;
+    rom->fw_file = fw_file ? qemu_strdup(fw_file) : NULL;
     rom->align   = align;
     rom->min     = min;
     rom->max     = max;
@@ -623,14 +628,16 @@ int rom_add_vga(const char *file)
 {
     if (!rom_enable_driver_roms)
         return 0;
-    return rom_add_file(file, PC_ROM_MIN_VGA, PC_ROM_MAX, PC_ROM_ALIGN);
+    return rom_add_file(file, "vgabios", file,
+                        PC_ROM_MIN_VGA, PC_ROM_MAX, PC_ROM_ALIGN);
 }
 
 int rom_add_option(const char *file)
 {
     if (!rom_enable_driver_roms)
         return 0;
-    return rom_add_file(file, PC_ROM_MIN_OPTION, PC_ROM_MAX, PC_ROM_ALIGN);
+    return rom_add_file(file, "genrom", file,
+                        PC_ROM_MIN_OPTION, PC_ROM_MAX, PC_ROM_ALIGN);
 }
 
 static void rom_reset(void *unused)
@@ -692,6 +699,18 @@ int rom_load_all(void)
     return 0;
 }
 
+int rom_load_fw(void *fw_cfg)
+{
+    Rom *rom;
+
+    QTAILQ_FOREACH(rom, &roms, next) {
+        if (!rom->fw_file)
+            continue;
+        fw_cfg_add_file(fw_cfg, rom->fw_dir, rom->fw_file, rom->data, rom->romsize);
+    }
+    return 0;
+}
+
 static Rom *find_rom(target_phys_addr_t addr)
 {
     Rom *rom;
hw/loader.h +3 -2
index b3311a3..634f7d5 100644
@@ -19,17 +19,18 @@ void pstrcpy_targphys(const char *name,
                       target_phys_addr_t dest, int buf_size,
                       const char *source);
 
-int rom_add_file(const char *file,
+int rom_add_file(const char *file, const char *fw_dir, const char *fw_file,
                  target_phys_addr_t min, target_phys_addr_t max, int align);
 int rom_add_blob(const char *name, const void *blob, size_t len,
                  target_phys_addr_t min, target_phys_addr_t max, int align);
 int rom_load_all(void);
+int rom_load_fw(void *fw_cfg);
 int rom_copy(uint8_t *dest, target_phys_addr_t addr, size_t size);
 void *rom_ptr(target_phys_addr_t addr);
 void do_info_roms(Monitor *mon);
 
 #define rom_add_file_fixed(_f, _a)              \
-    rom_add_file(_f, _a, 0, 0)
+    rom_add_file(_f, NULL, NULL, _a, 0, 0)
 #define rom_add_blob_fixed(_f, _b, _l, _a)      \
     rom_add_blob(_f, _b, _l, _a, 0, 0)
 
hw/pc.c +2 -0
index 147a9a7..be70f50 100644
@@ -1248,6 +1248,8 @@ static void pc_init1(ram_addr_t ram_size,
             }
         }
     }
+
+    rom_load_fw(fw_cfg);
 }
 
 static void pc_init_pci(ram_addr_t ram_size,
Signature · 1 line
1.6.5.2
#8 lore raw
In reply to Gerd Hoffmann
Quoted 5 lines · Gerd Hoffmann
   Hi,

All in one patch series for pci rom bar support and option rom loading via fw_cfg for the non-pci roms. This time the fw_cfg interface is actually tested with a little linux userspace app (attached below).

Now some seabios bits.

I got the naming of *both* vga and optionrom directories wrong, so there is first an incremental fix for this patch series.

Also attached are two seabios patches (go on top of the two ones from anthony) which implement the seabios side of the file interface.

'-kernel' and '-vga std' are working again ;)

cheers,
Gerd

Quoted 1 line

From 517fd48fdddfe93b5ef4081c11e87b250892cd49 Mon Sep 17 00:00:00 2001

From: Gerd Hoffmann <[email protected]>
Date: Thu, 17 Dec 2009 15:32:03 +0100
Subject: [PATCH] loader: fix dirname tyops

---
 hw/loader.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
hw/loader.c +2 -2
index 451ee54..ccc0ccc 100644
@@ -628,7 +628,7 @@ int rom_add_vga(const char *file)
 {
     if (!rom_enable_driver_roms)
         return 0;
-    return rom_add_file(file, "vgabios", file,
+    return rom_add_file(file, "vgaroms", file,
                         PC_ROM_MIN_VGA, PC_ROM_MAX, PC_ROM_ALIGN);
 }
 
@@ -636,7 +636,7 @@ int rom_add_option(const char *file)
 {
     if (!rom_enable_driver_roms)
         return 0;
-    return rom_add_file(file, "genrom", file,
+    return rom_add_file(file, "genroms", file,
                         PC_ROM_MIN_OPTION, PC_ROM_MAX, PC_ROM_ALIGN);
 }
 
Signature · 1 line
1.6.5.2
Quoted 1 line

From 9ec26264036ae620cccc9e69cfc75b1284a7f06b Mon Sep 17 00:00:00 2001

From: Gerd Hoffmann <[email protected]>
Date: Thu, 17 Dec 2009 15:33:21 +0100
Subject: [PATCH 1/2] move htonl() + friends to util.h

---
 src/coreboot.c |    5 -----
 src/util.h     |    7 +++++++
 2 files changed, 7 insertions(+), 5 deletions(-)
src/coreboot.c +0 -5
index 7fa18e4..3dc6a7f 100644
@@ -351,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
src/util.h +7 -0
index 1eafce0..24e39d1 100644
@@ -367,4 +367,11 @@ extern u8 BiosChecksum;
 // version (auto generated file out/version.c)
 extern const char VERSION[];
 
+// XXX - optimize
+#define ntohl(x) ((((x)&0xff)<<24) | (((x)&0xff00)<<8) | \
+                  (((x)&0xff0000) >> 8) | (((x)&0xff000000) >> 24))
+#define htonl(x) ntohl(x)
+#define ntohs(x) ((((x)&0xff)<<8) | (((x)&0xff00)>>8))
+#define htons(x) ntohs(x)
+
 #endif // util.h
Signature · 1 line
1.6.5.2
Quoted 1 line

From 02e660e21d6db37d3ba6033215d2ddae6a8e1eb2 Mon Sep 17 00:00:00 2001

From: Gerd Hoffmann <[email protected]>
Date: Thu, 17 Dec 2009 15:34:02 +0100
Subject: [PATCH 2/2] qemu: add rom loading via fw_cfg

---
 src/optionroms.c |   22 ++++++++++++++++++++++
 src/paravirt.c   |   37 +++++++++++++++++++++++++++++++++++++
 src/paravirt.h   |   11 +++++++++++
 3 files changed, 70 insertions(+), 0 deletions(-)
src/optionroms.c +22 -0
index 27465ad..c5de1ad 100644
@@ -247,6 +247,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 +395,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 +455,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) {
src/paravirt.c +37 -0
index 6f48d2e..7171bac 100644
@@ -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;
+}
src/paravirt.h +11 -0
index 29a2c04..d33e10d 100644
@@ -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,14 @@ 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);
+
 #endif
Signature · 1 line
1.6.5.2
#9 lore raw
Quoted 7 lines · Gerd Hoffmann
Quoted 5 lines · Gerd Hoffmann
   Hi,

All in one patch series for pci rom bar support and option rom loading via fw_cfg for the non-pci roms. This time the fw_cfg interface is actually tested with a little linux userspace app (attached below).

Quoted 7 lines

Now some seabios bits.

I got the naming of *both* vga and optionrom directories wrong, so there is first an incremental fix for this patch series.

Also attached are two seabios patches (go on top of the two ones from anthony) which implement the seabios side of the file interface.

'-kernel' and '-vga std' are working again ;)

Very nice! No reason not to convert std vga and vmware vga to use the pci based rom loading interface.

Care to fold everything into one series that we can bring into the tree?

Quoted 2 lines

cheers,
Gerd

#10 lore raw
Quoted 2 lines · Anthony Liguori

Very nice! No reason not to convert std vga and vmware vga to use the pci based rom loading interface.

seabios thinks about vgabios.bin:

Scan for VGA option rom
Attempting to init PCI bdf 00:02.0 (dev/ven 11111234) Attempting to map option rom on dev 00:02.0 Option rom sizing returned f0800000 ffff0000 Inspecting possible rom at 0xf0800000 (dv=11111234 bdf=10) No valid pci signature found ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Adding a pci rom header (with vendor and product id which seabios will check) doesn't look that useful for a generic vga bios though. If we go down that route we'll need at least two roms then (one for std, one for vmware-svga) where the only difference is the pci header ...

cheers,
Gerd

#11 lore raw
In reply to Gerd Hoffmann
Quoted 6 lines · Gerd Hoffmann

Hi,

All in one patch series for pci rom bar support and option rom loading via fw_cfg for the non-pci roms. This time the fw_cfg interface is actually tested with a little linux userspace app (attached below).

Does this mean that -kernel works with this series?

Regards,

Anthony Liguori

#12 lore raw
Quoted 8 lines · Anthony Liguori
Quoted 5 lines · Gerd Hoffmann

Hi,

All in one patch series for pci rom bar support and option rom loading via fw_cfg for the non-pci roms. This time the fw_cfg interface is actually tested with a little linux userspace app (attached below).

Does this mean that -kernel works with this series?

Almost. See the followup with a little qemu fix and seabios patches, this is needed additionally.

cheers,
Gerd