qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org, seabios@seabios.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 2/8] pci romfiles: add property, add default to PCIDeviceInfo
Date: Fri, 18 Dec 2009 12:01:08 +0100	[thread overview]
Message-ID: <1261134074-11795-3-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1261134074-11795-1-git-send-email-kraxel@redhat.com>

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.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 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(-)

diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
index b08d2ae..6fe433d 100644
--- a/hw/cirrus_vga.c
+++ b/hw/cirrus_vga.c
@@ -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,
 };
 
diff --git a/hw/e1000.c b/hw/e1000.c
index f795601..33c4bc6 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -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(),
diff --git a/hw/pci.c b/hw/pci.c
index dbdfdbf..d54f05e 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -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);
     }
diff --git a/hw/pci.h b/hw/pci.h
index 89b3f55..39da7df 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -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);
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index 2cee97b..fcdcd1d 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -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(),
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 85f14a2..62b46bd 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -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),
-- 
1.6.5.2

  parent reply	other threads:[~2009-12-18 11:01 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-18 11:01 [Qemu-devel] [PATCH 0/8] option rom loading overhaul Gerd Hoffmann
2009-12-18 11:01 ` [Qemu-devel] [PATCH 1/8] Support PCI based option rom loading Gerd Hoffmann
2009-12-19 10:57   ` Blue Swirl
2009-12-20 15:34     ` Anthony Liguori
2009-12-20 17:02       ` Blue Swirl
2009-12-20 17:18         ` Alexander Graf
2009-12-20 17:55           ` Anthony Liguori
2009-12-20 18:01             ` Alexander Graf
2009-12-20 18:24               ` Andreas Färber
2009-12-20 18:53                 ` Blue Swirl
2009-12-20 21:24                   ` Benjamin Herrenschmidt
2009-12-20 21:23               ` Benjamin Herrenschmidt
2009-12-18 11:01 ` Gerd Hoffmann [this message]
2010-01-11 21:18   ` [Qemu-devel] [RFC] New naming rules for GPXE romfiles Stefan Weil
2010-01-11 21:34     ` Anthony Liguori
2010-01-12 10:23     ` Kevin Wolf
2009-12-18 11:01 ` [Qemu-devel] [PATCH 3/8] fw_cfg: make calls typesafe Gerd Hoffmann
2009-12-18 11:01 ` [Qemu-devel] [PATCH 4/8] fw_cfg: add API for file transfer Gerd Hoffmann
2009-12-19 12:06   ` Blue Swirl
2009-12-20  8:42   ` [Qemu-devel] Re: [SeaBIOS] " Gleb Natapov
2009-12-18 11:01 ` [Qemu-devel] [PATCH 5/8] roms: use new fw_cfg file xfer support Gerd Hoffmann
2009-12-20  8:45   ` [Qemu-devel] Re: [SeaBIOS] " Gleb Natapov
2009-12-18 11:01 ` [Qemu-devel] [PATCH 6/8] roms: remove option rom packing logic Gerd Hoffmann
2009-12-18 11:01 ` [Qemu-devel] [PATCH 7/8] updated seabios binary for testing convinience Gerd Hoffmann
2009-12-18 11:01 ` [Qemu-devel] [PATCH 8/8] debug: enable bios messages Gerd Hoffmann
2009-12-18 14:35 ` [Qemu-devel] Re: [SeaBIOS] [PATCH 0/8] option rom loading overhaul Anthony Liguori
2009-12-18 16:34   ` Gerd Hoffmann
2009-12-18 16:42     ` Anthony Liguori
2009-12-18 17:03       ` Gerd Hoffmann
2009-12-18 17:12         ` Anthony Liguori
2009-12-19  1:48           ` Kevin O'Connor
2009-12-19  3:07             ` Anthony Liguori
2009-12-18 17:14         ` Anthony Liguori
2009-12-18 18:04           ` Gerd Hoffmann
2009-12-18 19:41         ` Sebastian Herbszt
2009-12-18 19:53           ` Anthony Liguori
2009-12-18 20:10             ` Sebastian Herbszt
2009-12-20  8:38 ` Gleb Natapov
2009-12-20 14:43   ` Anthony Liguori
2009-12-20 14:52     ` Gleb Natapov
2009-12-20 14:58       ` Anthony Liguori
2009-12-20 15:07         ` Gleb Natapov
2009-12-20 15:11           ` Anthony Liguori
2009-12-20 15:20             ` Avi Kivity
2009-12-20 15:31               ` Anthony Liguori
2009-12-20 15:35                 ` Avi Kivity
2009-12-22 13:04               ` Paul Brook
2009-12-22 13:09                 ` Avi Kivity
2009-12-22 15:11                 ` Anthony Liguori
2009-12-22 15:54                   ` Paul Brook
2009-12-22 16:16                     ` Anthony Liguori
2009-12-20 15:23             ` Gleb Natapov
2009-12-20 15:28               ` Anthony Liguori
2009-12-20 15:33                 ` Gleb Natapov
2009-12-20 15:39                   ` Anthony Liguori
2009-12-20 15:52                     ` Gleb Natapov
2009-12-20 16:08                       ` Blue Swirl
2009-12-20 16:15                         ` Gleb Natapov
2009-12-20 16:23                           ` Blue Swirl
2009-12-20 17:48                       ` Anthony Liguori
2009-12-21  1:59                         ` Kevin O'Connor
2009-12-21  7:32                           ` Gleb Natapov
2009-12-21 16:40                             ` Anthony Liguori
2009-12-21 16:43                               ` Gleb Natapov
2009-12-21 17:26                                 ` Anthony Liguori
2009-12-21 17:43                                   ` Gleb Natapov
2009-12-21 18:24                                     ` [Qemu-devel] Re: Re: [SeaBIOS] [PATCH 0/8] option rom loadingoverhaul Sebastian Herbszt
2009-12-21 18:36                                       ` Gleb Natapov
2009-12-21 19:28                                         ` Sebastian Herbszt
2009-12-21 19:57                                           ` Gleb Natapov
2009-12-21 19:17                                       ` [Qemu-devel] " Anthony Liguori
2009-12-21 19:39                                         ` Sebastian Herbszt
2009-12-21 19:53                                           ` Gleb Natapov
2009-12-21 20:16                                             ` Sebastian Herbszt
2009-12-22  7:58                                               ` Gleb Natapov
2009-12-22 14:57                                                 ` Anthony Liguori
2009-12-21 19:48                                         ` Gleb Natapov
2009-12-21 19:13                                     ` [Qemu-devel] Re: [SeaBIOS] [PATCH 0/8] option rom loading overhaul Anthony Liguori
2009-12-21 19:43                                       ` Gleb Natapov
2009-12-21 23:54                                         ` Anthony Liguori
2009-12-22 20:50                                           ` [Qemu-devel] Re: Re: [SeaBIOS] [PATCH 0/8] option rom loadingoverhaul Sebastian Herbszt
2009-12-21  7:40                         ` [Qemu-devel] Re: [SeaBIOS] [PATCH 0/8] option rom loading overhaul Gleb Natapov
2009-12-21 17:27                           ` Michael S. Tsirkin
2010-01-12  4:48                   ` Jamie Lokier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1261134074-11795-3-git-send-email-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=seabios@seabios.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).