Skip to contentSkip to conversation

rom loading patches

PATCH New Gerd Hoffmann 1 participant 5 messages Dec 16, 2009

lore
Share & tools
lore
#0 lore raw

cover rom loading patches

Hi,

Current state of the rom loading patches for testing and discussions.

What is in here:
#1 new seabios binary for testing convinience, git head as of yesterday
plus anthonys patches
#2 anthonys initial patch, unmodified.
#3 romfile property patch, was already on the list but deep in a
thread.
#4 specify romfile in PCIDeviceInfo, which allows to have *no*
pci rom loading code outside pci.c

We eventually want squash 2-4 together in the final version.

Todo list:
#1 Figure a sane way to load non-pci option roms (fw_cfg?). #2 Anything needed for '-M pc-0.11' ?

A few things are broken (todo #1 will fix them), among them are '-vga std' and -kernel.

Let the fl^Wdiscussions begin.

cheers,
Gerd

#1 lore raw

PATCH 1/4 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/4 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/4 pci: add romfile property

In reply to Gerd Hoffmann
---
 hw/cirrus_vga.c |    4 +++-
 hw/e1000.c      |    8 ++------
 hw/pci.c        |   19 ++++++++++++++++---
 hw/pci.h        |    3 +--
 hw/rtl8139.c    |    8 ++------
 hw/virtio-pci.c |    8 ++------
 6 files changed, 26 insertions(+), 24 deletions(-)
hw/cirrus_vga.c +3 -1
index b08d2ae..b2886c4 100644
@@ -3211,7 +3211,9 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev)
      }
 
      /* ROM BIOS */
-     pci_add_option_rom((PCIDevice *)d, VGABIOS_CIRRUS_FILENAME);
+     if (dev->rom_filename == NULL) {
+         dev->rom_filename = qemu_strdup(VGABIOS_CIRRUS_FILENAME);
+     }
      return 0;
 }
 
hw/e1000.c +2 -6
index f795601..021f666 100644
@@ -1122,12 +1122,8 @@ static int pci_e1000_init(PCIDevice *pci_dev)
 
     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;
-        }
+    if (pci_dev->rom_filename == NULL) {
+        pci_dev->rom_filename = qemu_strdup("pxe-e1000.bin");
     }
     return 0;
 }
hw/pci.c +16 -3
index dbdfdbf..3ff7d0c 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, rom_filename),
         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,7 @@ static int pci_qdev_init(DeviceState *qdev, DeviceInfo *base)
     rc = info->init(pci_dev);
     if (rc != 0)
         return rc;
+    pci_add_option_rom(pci_dev);
     if (qdev->hotplugged)
         bus->hotplug(pci_dev, 1);
     return 0;
@@ -1470,18 +1473,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->rom_filename)
+        return 0;
+    if (strlen(pdev->rom_filename) == 0)
+        return 0;
+
+    path = qemu_find_file(QEMU_FILE_TYPE_BIOS, pdev->rom_filename);
     if (path == NULL) {
-        path = qemu_strdup(name);
+        path = qemu_strdup(pdev->rom_filename);
     }
 
     size = get_image_size(path);
+    if (size < 0) {
+        qemu_error("%s: failed to find romfile \"%s\"\n", __FUNCTION__,
+                   pdev->rom_filename);
+        return -1;
+    }
     if (size & (size - 1)) {
         size = 1 << qemu_fls(size);
     }
hw/pci.h +1 -2
index 89b3f55..c27e800 100644
@@ -245,6 +245,7 @@ struct PCIDevice {
     int32_t version_id;
 
     /* Location of option rom */
+    char *rom_filename;
     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);
hw/rtl8139.c +2 -6
index 2cee97b..d096711 100644
@@ -3354,12 +3354,8 @@ static int pci_rtl8139_init(PCIDevice *dev)
         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;
-        }
+    if (dev->rom_filename == NULL) {
+        dev->rom_filename = qemu_strdup("pxe-rtl8139.bin");
     }
     return 0;
 }
hw/virtio-pci.c +2 -6
index 85f14a2..e38fe70 100644
@@ -519,12 +519,8 @@ 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;
-        }
+    if (pci_dev->rom_filename == NULL) {
+        pci_dev->rom_filename = qemu_strdup("pxe-virtio.bin");
     }
     return 0;
 }
Signature · 1 line
1.6.5.2
#4 lore raw

PATCH 4/4 pci: specify default romfile in PCIDeviceInfo.

In reply to Gerd Hoffmann
---
 hw/cirrus_vga.c |    6 +-----
 hw/e1000.c      |    5 +----
 hw/pci.c        |   17 +++++++++++------
 hw/pci.h        |    5 ++++-
 hw/rtl8139.c    |    5 +----
 hw/virtio-pci.c |    5 +----
 6 files changed, 19 insertions(+), 24 deletions(-)
hw/cirrus_vga.c +1 -5
index b2886c4..6fe433d 100644
@@ -3209,11 +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 */
-     if (dev->rom_filename == NULL) {
-         dev->rom_filename = qemu_strdup(VGABIOS_CIRRUS_FILENAME);
-     }
      return 0;
 }
 
@@ -3228,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 -4
index 021f666..33c4bc6 100644
@@ -1121,10 +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->rom_filename == NULL) {
-        pci_dev->rom_filename = qemu_strdup("pxe-e1000.bin");
-    }
     return 0;
 }
 
@@ -1142,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 +11 -6
index 3ff7d0c..d54f05e 100644
@@ -63,7 +63,7 @@ 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, rom_filename),
+        DEFINE_PROP_STRING("romfile", PCIDevice, romfile),
         DEFINE_PROP_END_OF_LIST()
     }
 };
@@ -1389,7 +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;
@@ -1479,20 +1484,20 @@ static int pci_add_option_rom(PCIDevice *pdev)
     char *path;
     void *ptr;
 
-    if (!pdev->rom_filename)
+    if (!pdev->romfile)
         return 0;
-    if (strlen(pdev->rom_filename) == 0)
+    if (strlen(pdev->romfile) == 0)
         return 0;
 
-    path = qemu_find_file(QEMU_FILE_TYPE_BIOS, pdev->rom_filename);
+    path = qemu_find_file(QEMU_FILE_TYPE_BIOS, pdev->romfile);
     if (path == NULL) {
-        path = qemu_strdup(pdev->rom_filename);
+        path = qemu_strdup(pdev->romfile);
     }
 
     size = get_image_size(path);
     if (size < 0) {
         qemu_error("%s: failed to find romfile \"%s\"\n", __FUNCTION__,
-                   pdev->rom_filename);
+                   pdev->romfile);
         return -1;
     }
     if (size & (size - 1)) {
hw/pci.h +4 -1
index c27e800..39da7df 100644
@@ -245,7 +245,7 @@ struct PCIDevice {
     int32_t version_id;
 
     /* Location of option rom */
-    char *rom_filename;
+    char *romfile;
     ram_addr_t rom_offset;
 };
 
@@ -385,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 -4
index d096711..fcdcd1d 100644
@@ -3353,10 +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->rom_filename == NULL) {
-        dev->rom_filename = qemu_strdup("pxe-rtl8139.bin");
-    }
     return 0;
 }
 
@@ -3367,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 -4
index e38fe70..62b46bd 100644
@@ -518,10 +518,6 @@ static int virtio_net_init_pci(PCIDevice *pci_dev)
 
     /* make the actual value visible */
     proxy->nvectors = vdev->nvectors;
-
-    if (pci_dev->rom_filename == NULL) {
-        pci_dev->rom_filename = qemu_strdup("pxe-virtio.bin");
-    }
     return 0;
 }
 
@@ -565,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