All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gleb Natapov <gleb@redhat.com>
To: qemu-devel@nongnu.org
Cc: kvm@vger.kernel.org, blauwirbel@gmail.com, armbru@redhat.com,
	alex.williamson@redhat.com, mst@redhat.com, kevin@koconnor.net
Subject: [PATCHv6 12/16] Add bootindex parameter to net/block/fd device
Date: Wed, 17 Nov 2010 18:43:59 +0200	[thread overview]
Message-ID: <1290012243-6087-13-git-send-email-gleb@redhat.com> (raw)
In-Reply-To: <1290012243-6087-1-git-send-email-gleb@redhat.com>

If bootindex is specified on command line a string that describes device
in firmware readable way is added into sorted list. Later this list will
be passed into firmware to control boot order.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
---
 block_int.h     |    4 +++-
 hw/e1000.c      |    4 ++++
 hw/eepro100.c   |    3 +++
 hw/fdc.c        |    8 ++++++++
 hw/ide/qdev.c   |    5 +++++
 hw/ne2000.c     |    3 +++
 hw/pcnet.c      |    4 ++++
 hw/qdev.c       |   32 ++++++++++++++++++++++++++++++++
 hw/qdev.h       |    1 +
 hw/rtl8139.c    |    4 ++++
 hw/scsi-disk.c  |    1 +
 hw/usb-net.c    |    2 ++
 hw/virtio-blk.c |    2 ++
 hw/virtio-net.c |    2 ++
 net.h           |    4 +++-
 sysemu.h        |    2 ++
 vl.c            |   40 ++++++++++++++++++++++++++++++++++++++++
 17 files changed, 119 insertions(+), 2 deletions(-)

diff --git a/block_int.h b/block_int.h
index 3c3adb5..0a0e47d 100644
--- a/block_int.h
+++ b/block_int.h
@@ -227,6 +227,7 @@ typedef struct BlockConf {
     uint16_t logical_block_size;
     uint16_t min_io_size;
     uint32_t opt_io_size;
+    int32_t bootindex;
 } BlockConf;
 
 static inline unsigned int get_physical_block_exp(BlockConf *conf)
@@ -249,6 +250,7 @@ static inline unsigned int get_physical_block_exp(BlockConf *conf)
     DEFINE_PROP_UINT16("physical_block_size", _state,                   \
                        _conf.physical_block_size, 512),                 \
     DEFINE_PROP_UINT16("min_io_size", _state, _conf.min_io_size, 0),  \
-    DEFINE_PROP_UINT32("opt_io_size", _state, _conf.opt_io_size, 0)
+    DEFINE_PROP_UINT32("opt_io_size", _state, _conf.opt_io_size, 0),    \
+    DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1)         \
 
 #endif /* BLOCK_INT_H */
diff --git a/hw/e1000.c b/hw/e1000.c
index 7811699..34ad136 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -30,6 +30,7 @@
 #include "net.h"
 #include "net/checksum.h"
 #include "loader.h"
+#include "sysemu.h"
 
 #include "e1000_hw.h"
 
@@ -1154,6 +1155,9 @@ 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);
+
+    add_boot_device_path(d->conf.bootindex, &pci_dev->qdev, "/ethernet-phy@0");
+
     return 0;
 }
 
diff --git a/hw/eepro100.c b/hw/eepro100.c
index 41d792a..ae96204 100644
--- a/hw/eepro100.c
+++ b/hw/eepro100.c
@@ -46,6 +46,7 @@
 #include "pci.h"
 #include "net.h"
 #include "eeprom93xx.h"
+#include "sysemu.h"
 
 #define KiB 1024
 
@@ -1907,6 +1908,8 @@ static int e100_nic_init(PCIDevice *pci_dev)
     s->vmstate->name = s->nic->nc.model;
     vmstate_register(&pci_dev->qdev, -1, s->vmstate, s);
 
+    add_boot_device_path(s->conf.bootindex, &pci_dev->qdev, "/ethernet-phy@0");
+
     return 0;
 }
 
diff --git a/hw/fdc.c b/hw/fdc.c
index 5ab754b..543aa68 100644
--- a/hw/fdc.c
+++ b/hw/fdc.c
@@ -35,6 +35,7 @@
 #include "sysbus.h"
 #include "qdev-addr.h"
 #include "blockdev.h"
+#include "sysemu.h"
 
 /********************************************************/
 /* debug Floppy devices */
@@ -523,6 +524,8 @@ typedef struct FDCtrlSysBus {
 typedef struct FDCtrlISABus {
     ISADevice busdev;
     struct FDCtrl state;
+    int32_t bootindexA;
+    int32_t bootindexB;
 } FDCtrlISABus;
 
 static uint32_t fdctrl_read (void *opaque, uint32_t reg)
@@ -1992,6 +1995,9 @@ static int isabus_fdc_init1(ISADevice *dev)
     qdev_set_legacy_instance_id(&dev->qdev, iobase, 2);
     ret = fdctrl_init_common(fdctrl);
 
+    add_boot_device_path(isa->bootindexA, &dev->qdev, "/floppy@0");
+    add_boot_device_path(isa->bootindexB, &dev->qdev, "/floppy@1");
+
     return ret;
 }
 
@@ -2051,6 +2057,8 @@ static ISADeviceInfo isa_fdc_info = {
     .qdev.props = (Property[]) {
         DEFINE_PROP_DRIVE("driveA", FDCtrlISABus, state.drives[0].bs),
         DEFINE_PROP_DRIVE("driveB", FDCtrlISABus, state.drives[1].bs),
+        DEFINE_PROP_INT32("bootindexA", FDCtrlISABus, bootindexA, -1),
+        DEFINE_PROP_INT32("bootindexB", FDCtrlISABus, bootindexB, -1),
         DEFINE_PROP_END_OF_LIST(),
     },
 };
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index 01a181b..69a00e2 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -21,6 +21,7 @@
 #include "qemu-error.h"
 #include <hw/ide/internal.h>
 #include "blockdev.h"
+#include "sysemu.h"
 
 /* --------------------------------- */
 
@@ -143,6 +144,10 @@ static int ide_drive_initfn(IDEDevice *dev)
     if (!dev->serial) {
         dev->serial = qemu_strdup(s->drive_serial_str);
     }
+
+    add_boot_device_path(dev->conf.bootindex, &dev->qdev,
+                         dev->unit ? "disk@1" : "disk@0");
+
     return 0;
 }
 
diff --git a/hw/ne2000.c b/hw/ne2000.c
index 126e7cf..a030106 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -26,6 +26,7 @@
 #include "net.h"
 #include "ne2000.h"
 #include "loader.h"
+#include "sysemu.h"
 
 /* debug NE2000 card */
 //#define DEBUG_NE2000
@@ -746,6 +747,8 @@ static int pci_ne2000_init(PCIDevice *pci_dev)
         }
     }
 
+    add_boot_device_path(s->c.bootindex, &pci_dev->qdev, "/ethernet-phy@0");
+
     return 0;
 }
 
diff --git a/hw/pcnet.c b/hw/pcnet.c
index b52935a..f100945 100644
--- a/hw/pcnet.c
+++ b/hw/pcnet.c
@@ -40,6 +40,7 @@
 #include "loader.h"
 #include "qemu-timer.h"
 #include "qemu_socket.h"
+#include "sysemu.h"
 
 #include "pcnet.h"
 
@@ -1898,6 +1899,9 @@ int pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info)
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
     s->nic = qemu_new_nic(info, &s->conf, dev->info->name, dev->id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
+
+    add_boot_device_path(s->conf.bootindex, dev, "/ethernet-phy@0");
+
     return 0;
 }
 
diff --git a/hw/qdev.c b/hw/qdev.c
index 35858cb..cc9bf43 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -820,3 +820,35 @@ int do_device_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
     }
     return qdev_unplug(dev);
 }
+
+static int qdev_get_fw_dev_path_helper(DeviceState *dev, char *p, int size)
+{
+    int l = 0;
+
+    if (dev && dev->parent_bus) {
+        char *d;
+        l = qdev_get_fw_dev_path_helper(dev->parent_bus->parent, p, size);
+        if (dev->parent_bus->info->get_fw_dev_path) {
+            d = dev->parent_bus->info->get_fw_dev_path(dev);
+            l += snprintf(p + l, size - l, "%s", d);
+            qemu_free(d);
+        } else {
+            l += snprintf(p + l, size - l, "%s", dev->info->name);
+        }
+    }
+    l += snprintf(p + l , size - l, "/");
+
+    return l;
+}
+
+char* qdev_get_fw_dev_path(DeviceState *dev)
+{
+    char path[128];
+    int l;
+
+    l = qdev_get_fw_dev_path_helper(dev, path, 128);
+
+    path[l-1] = '\0';
+
+    return strdup(path);
+}
diff --git a/hw/qdev.h b/hw/qdev.h
index dc669b3..13f3597 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -296,6 +296,7 @@ static inline const char *qdev_fw_name(DeviceState *dev)
     return dev->info->fw_name ? : dev->info->alias ? : dev->info->name;
 }
 
+char *qdev_get_fw_dev_path(DeviceState *dev);
 /* This is a nasty hack to allow passing a NULL bus to qdev_create.  */
 extern struct BusInfo system_bus_info;
 
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index d92981d..80a2813 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -52,6 +52,7 @@
 #include "qemu-timer.h"
 #include "net.h"
 #include "loader.h"
+#include "sysemu.h"
 
 /* debug RTL8139 card */
 //#define DEBUG_RTL8139 1
@@ -3387,6 +3388,9 @@ static int pci_rtl8139_init(PCIDevice *dev)
     s->TimerExpire = 0;
     s->timer = qemu_new_timer(vm_clock, rtl8139_timer, s);
     rtl8139_set_next_tctr_time(s, qemu_get_clock(vm_clock));
+
+    add_boot_device_path(s->conf.bootindex, &dev->qdev, "/ethernet-phy@0");
+
     return 0;
 }
 
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 2b22777..705ebf8 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1230,6 +1230,7 @@ static int scsi_disk_initfn(SCSIDevice *dev)
     s->qdev.type = TYPE_DISK;
     qemu_add_vm_change_state_handler(scsi_dma_restart_cb, s);
     bdrv_set_removable(s->bs, is_cd);
+    add_boot_device_path(s->qdev.conf.bootindex, &dev->qdev, ",0");
     return 0;
 }
 
diff --git a/hw/usb-net.c b/hw/usb-net.c
index f6bed21..8492455 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -27,6 +27,7 @@
 #include "usb.h"
 #include "net.h"
 #include "qemu-queue.h"
+#include "sysemu.h"
 
 /*#define TRAFFIC_DEBUG*/
 /* Thanks to NetChip Technologies for donating this product ID.
@@ -1463,6 +1464,7 @@ static int usb_net_initfn(USBDevice *dev)
              s->conf.macaddr.a[4],
              s->conf.macaddr.a[5]);
 
+    add_boot_device_path(s->conf.bootindex, &dev->qdev, "/ethernet@0");
     return 0;
 }
 
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 49528a9..c48dda5 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -548,6 +548,8 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf)
     bdrv_set_removable(s->bs, 0);
     s->bs->buffer_alignment = conf->logical_block_size;
 
+    add_boot_device_path(conf->bootindex, dev, "/disk@0,0");
+
     return &s->vdev;
 }
 
diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 7e1688c..b67c9ee 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -1018,6 +1018,8 @@ VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf,
                     virtio_net_save, virtio_net_load, n);
     n->vmstate = qemu_add_vm_change_state_handler(virtio_net_vmstate_change, n);
 
+    add_boot_device_path(conf->bootindex, dev, "/ethernet-phy@0");
+
     return &n->vdev;
 }
 
diff --git a/net.h b/net.h
index 44c31a9..6ceca50 100644
--- a/net.h
+++ b/net.h
@@ -17,12 +17,14 @@ typedef struct NICConf {
     MACAddr macaddr;
     VLANState *vlan;
     VLANClientState *peer;
+    int32_t bootindex;
 } NICConf;
 
 #define DEFINE_NIC_PROPERTIES(_state, _conf)                            \
     DEFINE_PROP_MACADDR("mac",   _state, _conf.macaddr),                \
     DEFINE_PROP_VLAN("vlan",     _state, _conf.vlan),                   \
-    DEFINE_PROP_NETDEV("netdev", _state, _conf.peer)
+    DEFINE_PROP_NETDEV("netdev", _state, _conf.peer),                   \
+    DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1)
 
 /* VLANs support */
 
diff --git a/sysemu.h b/sysemu.h
index b81a70e..fe9a582 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -188,4 +188,6 @@ void rtc_change_mon_event(struct tm *tm);
 
 void register_devices(void);
 
+void add_boot_device_path(int32_t bootindex, DeviceState *dev,
+                          const char *suffix);
 #endif
diff --git a/vl.c b/vl.c
index 9ee6479..4e5d146 100644
--- a/vl.c
+++ b/vl.c
@@ -228,6 +228,17 @@ unsigned int nb_prom_envs = 0;
 const char *prom_envs[MAX_PROM_ENVS];
 int boot_menu;
 
+typedef struct FWBootEntry FWBootEntry;
+
+struct FWBootEntry {
+    QTAILQ_ENTRY(FWBootEntry) link;
+    int32_t bootindex;
+    DeviceState *dev;
+    char *suffix;
+};
+
+QTAILQ_HEAD(, FWBootEntry) fw_boot_order = QTAILQ_HEAD_INITIALIZER(fw_boot_order);
+
 int nb_numa_nodes;
 uint64_t node_mem[MAX_NODES];
 uint64_t node_cpumask[MAX_NODES];
@@ -692,6 +703,35 @@ static void restore_boot_devices(void *opaque)
     qemu_free(standard_boot_devices);
 }
 
+void add_boot_device_path(int32_t bootindex, DeviceState *dev,
+                          const char *suffix)
+{
+    FWBootEntry *node, *i;
+
+    if (bootindex < 0) {
+        return;
+    }
+
+    assert(dev != NULL || suffix != NULL);
+
+    node = qemu_mallocz(sizeof(FWBootEntry));
+    node->bootindex = bootindex;
+    node->suffix = strdup(suffix);
+    node->dev = dev;
+
+    QTAILQ_FOREACH(i, &fw_boot_order, link) {
+        if (i->bootindex == bootindex) {
+            fprintf(stderr, "Two devices with same boot index %d\n", bootindex);
+            exit(1);
+        } else if (i->bootindex < bootindex) {
+            continue;
+        }
+        QTAILQ_INSERT_BEFORE(i, node, link);
+        return;
+    }
+    QTAILQ_INSERT_TAIL(&fw_boot_order, node, link);
+}
+
 static void numa_add(const char *optarg)
 {
     char option[128];
-- 
1.7.2.3


WARNING: multiple messages have this Message-ID (diff)
From: Gleb Natapov <gleb@redhat.com>
To: qemu-devel@nongnu.org
Cc: kvm@vger.kernel.org, mst@redhat.com, armbru@redhat.com,
	blauwirbel@gmail.com, alex.williamson@redhat.com,
	kevin@koconnor.net
Subject: [Qemu-devel] [PATCHv6 12/16] Add bootindex parameter to net/block/fd device
Date: Wed, 17 Nov 2010 18:43:59 +0200	[thread overview]
Message-ID: <1290012243-6087-13-git-send-email-gleb@redhat.com> (raw)
In-Reply-To: <1290012243-6087-1-git-send-email-gleb@redhat.com>

If bootindex is specified on command line a string that describes device
in firmware readable way is added into sorted list. Later this list will
be passed into firmware to control boot order.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
---
 block_int.h     |    4 +++-
 hw/e1000.c      |    4 ++++
 hw/eepro100.c   |    3 +++
 hw/fdc.c        |    8 ++++++++
 hw/ide/qdev.c   |    5 +++++
 hw/ne2000.c     |    3 +++
 hw/pcnet.c      |    4 ++++
 hw/qdev.c       |   32 ++++++++++++++++++++++++++++++++
 hw/qdev.h       |    1 +
 hw/rtl8139.c    |    4 ++++
 hw/scsi-disk.c  |    1 +
 hw/usb-net.c    |    2 ++
 hw/virtio-blk.c |    2 ++
 hw/virtio-net.c |    2 ++
 net.h           |    4 +++-
 sysemu.h        |    2 ++
 vl.c            |   40 ++++++++++++++++++++++++++++++++++++++++
 17 files changed, 119 insertions(+), 2 deletions(-)

diff --git a/block_int.h b/block_int.h
index 3c3adb5..0a0e47d 100644
--- a/block_int.h
+++ b/block_int.h
@@ -227,6 +227,7 @@ typedef struct BlockConf {
     uint16_t logical_block_size;
     uint16_t min_io_size;
     uint32_t opt_io_size;
+    int32_t bootindex;
 } BlockConf;
 
 static inline unsigned int get_physical_block_exp(BlockConf *conf)
@@ -249,6 +250,7 @@ static inline unsigned int get_physical_block_exp(BlockConf *conf)
     DEFINE_PROP_UINT16("physical_block_size", _state,                   \
                        _conf.physical_block_size, 512),                 \
     DEFINE_PROP_UINT16("min_io_size", _state, _conf.min_io_size, 0),  \
-    DEFINE_PROP_UINT32("opt_io_size", _state, _conf.opt_io_size, 0)
+    DEFINE_PROP_UINT32("opt_io_size", _state, _conf.opt_io_size, 0),    \
+    DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1)         \
 
 #endif /* BLOCK_INT_H */
diff --git a/hw/e1000.c b/hw/e1000.c
index 7811699..34ad136 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -30,6 +30,7 @@
 #include "net.h"
 #include "net/checksum.h"
 #include "loader.h"
+#include "sysemu.h"
 
 #include "e1000_hw.h"
 
@@ -1154,6 +1155,9 @@ 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);
+
+    add_boot_device_path(d->conf.bootindex, &pci_dev->qdev, "/ethernet-phy@0");
+
     return 0;
 }
 
diff --git a/hw/eepro100.c b/hw/eepro100.c
index 41d792a..ae96204 100644
--- a/hw/eepro100.c
+++ b/hw/eepro100.c
@@ -46,6 +46,7 @@
 #include "pci.h"
 #include "net.h"
 #include "eeprom93xx.h"
+#include "sysemu.h"
 
 #define KiB 1024
 
@@ -1907,6 +1908,8 @@ static int e100_nic_init(PCIDevice *pci_dev)
     s->vmstate->name = s->nic->nc.model;
     vmstate_register(&pci_dev->qdev, -1, s->vmstate, s);
 
+    add_boot_device_path(s->conf.bootindex, &pci_dev->qdev, "/ethernet-phy@0");
+
     return 0;
 }
 
diff --git a/hw/fdc.c b/hw/fdc.c
index 5ab754b..543aa68 100644
--- a/hw/fdc.c
+++ b/hw/fdc.c
@@ -35,6 +35,7 @@
 #include "sysbus.h"
 #include "qdev-addr.h"
 #include "blockdev.h"
+#include "sysemu.h"
 
 /********************************************************/
 /* debug Floppy devices */
@@ -523,6 +524,8 @@ typedef struct FDCtrlSysBus {
 typedef struct FDCtrlISABus {
     ISADevice busdev;
     struct FDCtrl state;
+    int32_t bootindexA;
+    int32_t bootindexB;
 } FDCtrlISABus;
 
 static uint32_t fdctrl_read (void *opaque, uint32_t reg)
@@ -1992,6 +1995,9 @@ static int isabus_fdc_init1(ISADevice *dev)
     qdev_set_legacy_instance_id(&dev->qdev, iobase, 2);
     ret = fdctrl_init_common(fdctrl);
 
+    add_boot_device_path(isa->bootindexA, &dev->qdev, "/floppy@0");
+    add_boot_device_path(isa->bootindexB, &dev->qdev, "/floppy@1");
+
     return ret;
 }
 
@@ -2051,6 +2057,8 @@ static ISADeviceInfo isa_fdc_info = {
     .qdev.props = (Property[]) {
         DEFINE_PROP_DRIVE("driveA", FDCtrlISABus, state.drives[0].bs),
         DEFINE_PROP_DRIVE("driveB", FDCtrlISABus, state.drives[1].bs),
+        DEFINE_PROP_INT32("bootindexA", FDCtrlISABus, bootindexA, -1),
+        DEFINE_PROP_INT32("bootindexB", FDCtrlISABus, bootindexB, -1),
         DEFINE_PROP_END_OF_LIST(),
     },
 };
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index 01a181b..69a00e2 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -21,6 +21,7 @@
 #include "qemu-error.h"
 #include <hw/ide/internal.h>
 #include "blockdev.h"
+#include "sysemu.h"
 
 /* --------------------------------- */
 
@@ -143,6 +144,10 @@ static int ide_drive_initfn(IDEDevice *dev)
     if (!dev->serial) {
         dev->serial = qemu_strdup(s->drive_serial_str);
     }
+
+    add_boot_device_path(dev->conf.bootindex, &dev->qdev,
+                         dev->unit ? "disk@1" : "disk@0");
+
     return 0;
 }
 
diff --git a/hw/ne2000.c b/hw/ne2000.c
index 126e7cf..a030106 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -26,6 +26,7 @@
 #include "net.h"
 #include "ne2000.h"
 #include "loader.h"
+#include "sysemu.h"
 
 /* debug NE2000 card */
 //#define DEBUG_NE2000
@@ -746,6 +747,8 @@ static int pci_ne2000_init(PCIDevice *pci_dev)
         }
     }
 
+    add_boot_device_path(s->c.bootindex, &pci_dev->qdev, "/ethernet-phy@0");
+
     return 0;
 }
 
diff --git a/hw/pcnet.c b/hw/pcnet.c
index b52935a..f100945 100644
--- a/hw/pcnet.c
+++ b/hw/pcnet.c
@@ -40,6 +40,7 @@
 #include "loader.h"
 #include "qemu-timer.h"
 #include "qemu_socket.h"
+#include "sysemu.h"
 
 #include "pcnet.h"
 
@@ -1898,6 +1899,9 @@ int pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info)
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
     s->nic = qemu_new_nic(info, &s->conf, dev->info->name, dev->id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
+
+    add_boot_device_path(s->conf.bootindex, dev, "/ethernet-phy@0");
+
     return 0;
 }
 
diff --git a/hw/qdev.c b/hw/qdev.c
index 35858cb..cc9bf43 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -820,3 +820,35 @@ int do_device_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
     }
     return qdev_unplug(dev);
 }
+
+static int qdev_get_fw_dev_path_helper(DeviceState *dev, char *p, int size)
+{
+    int l = 0;
+
+    if (dev && dev->parent_bus) {
+        char *d;
+        l = qdev_get_fw_dev_path_helper(dev->parent_bus->parent, p, size);
+        if (dev->parent_bus->info->get_fw_dev_path) {
+            d = dev->parent_bus->info->get_fw_dev_path(dev);
+            l += snprintf(p + l, size - l, "%s", d);
+            qemu_free(d);
+        } else {
+            l += snprintf(p + l, size - l, "%s", dev->info->name);
+        }
+    }
+    l += snprintf(p + l , size - l, "/");
+
+    return l;
+}
+
+char* qdev_get_fw_dev_path(DeviceState *dev)
+{
+    char path[128];
+    int l;
+
+    l = qdev_get_fw_dev_path_helper(dev, path, 128);
+
+    path[l-1] = '\0';
+
+    return strdup(path);
+}
diff --git a/hw/qdev.h b/hw/qdev.h
index dc669b3..13f3597 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -296,6 +296,7 @@ static inline const char *qdev_fw_name(DeviceState *dev)
     return dev->info->fw_name ? : dev->info->alias ? : dev->info->name;
 }
 
+char *qdev_get_fw_dev_path(DeviceState *dev);
 /* This is a nasty hack to allow passing a NULL bus to qdev_create.  */
 extern struct BusInfo system_bus_info;
 
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index d92981d..80a2813 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -52,6 +52,7 @@
 #include "qemu-timer.h"
 #include "net.h"
 #include "loader.h"
+#include "sysemu.h"
 
 /* debug RTL8139 card */
 //#define DEBUG_RTL8139 1
@@ -3387,6 +3388,9 @@ static int pci_rtl8139_init(PCIDevice *dev)
     s->TimerExpire = 0;
     s->timer = qemu_new_timer(vm_clock, rtl8139_timer, s);
     rtl8139_set_next_tctr_time(s, qemu_get_clock(vm_clock));
+
+    add_boot_device_path(s->conf.bootindex, &dev->qdev, "/ethernet-phy@0");
+
     return 0;
 }
 
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 2b22777..705ebf8 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1230,6 +1230,7 @@ static int scsi_disk_initfn(SCSIDevice *dev)
     s->qdev.type = TYPE_DISK;
     qemu_add_vm_change_state_handler(scsi_dma_restart_cb, s);
     bdrv_set_removable(s->bs, is_cd);
+    add_boot_device_path(s->qdev.conf.bootindex, &dev->qdev, ",0");
     return 0;
 }
 
diff --git a/hw/usb-net.c b/hw/usb-net.c
index f6bed21..8492455 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -27,6 +27,7 @@
 #include "usb.h"
 #include "net.h"
 #include "qemu-queue.h"
+#include "sysemu.h"
 
 /*#define TRAFFIC_DEBUG*/
 /* Thanks to NetChip Technologies for donating this product ID.
@@ -1463,6 +1464,7 @@ static int usb_net_initfn(USBDevice *dev)
              s->conf.macaddr.a[4],
              s->conf.macaddr.a[5]);
 
+    add_boot_device_path(s->conf.bootindex, &dev->qdev, "/ethernet@0");
     return 0;
 }
 
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 49528a9..c48dda5 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -548,6 +548,8 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf)
     bdrv_set_removable(s->bs, 0);
     s->bs->buffer_alignment = conf->logical_block_size;
 
+    add_boot_device_path(conf->bootindex, dev, "/disk@0,0");
+
     return &s->vdev;
 }
 
diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 7e1688c..b67c9ee 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -1018,6 +1018,8 @@ VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf,
                     virtio_net_save, virtio_net_load, n);
     n->vmstate = qemu_add_vm_change_state_handler(virtio_net_vmstate_change, n);
 
+    add_boot_device_path(conf->bootindex, dev, "/ethernet-phy@0");
+
     return &n->vdev;
 }
 
diff --git a/net.h b/net.h
index 44c31a9..6ceca50 100644
--- a/net.h
+++ b/net.h
@@ -17,12 +17,14 @@ typedef struct NICConf {
     MACAddr macaddr;
     VLANState *vlan;
     VLANClientState *peer;
+    int32_t bootindex;
 } NICConf;
 
 #define DEFINE_NIC_PROPERTIES(_state, _conf)                            \
     DEFINE_PROP_MACADDR("mac",   _state, _conf.macaddr),                \
     DEFINE_PROP_VLAN("vlan",     _state, _conf.vlan),                   \
-    DEFINE_PROP_NETDEV("netdev", _state, _conf.peer)
+    DEFINE_PROP_NETDEV("netdev", _state, _conf.peer),                   \
+    DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1)
 
 /* VLANs support */
 
diff --git a/sysemu.h b/sysemu.h
index b81a70e..fe9a582 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -188,4 +188,6 @@ void rtc_change_mon_event(struct tm *tm);
 
 void register_devices(void);
 
+void add_boot_device_path(int32_t bootindex, DeviceState *dev,
+                          const char *suffix);
 #endif
diff --git a/vl.c b/vl.c
index 9ee6479..4e5d146 100644
--- a/vl.c
+++ b/vl.c
@@ -228,6 +228,17 @@ unsigned int nb_prom_envs = 0;
 const char *prom_envs[MAX_PROM_ENVS];
 int boot_menu;
 
+typedef struct FWBootEntry FWBootEntry;
+
+struct FWBootEntry {
+    QTAILQ_ENTRY(FWBootEntry) link;
+    int32_t bootindex;
+    DeviceState *dev;
+    char *suffix;
+};
+
+QTAILQ_HEAD(, FWBootEntry) fw_boot_order = QTAILQ_HEAD_INITIALIZER(fw_boot_order);
+
 int nb_numa_nodes;
 uint64_t node_mem[MAX_NODES];
 uint64_t node_cpumask[MAX_NODES];
@@ -692,6 +703,35 @@ static void restore_boot_devices(void *opaque)
     qemu_free(standard_boot_devices);
 }
 
+void add_boot_device_path(int32_t bootindex, DeviceState *dev,
+                          const char *suffix)
+{
+    FWBootEntry *node, *i;
+
+    if (bootindex < 0) {
+        return;
+    }
+
+    assert(dev != NULL || suffix != NULL);
+
+    node = qemu_mallocz(sizeof(FWBootEntry));
+    node->bootindex = bootindex;
+    node->suffix = strdup(suffix);
+    node->dev = dev;
+
+    QTAILQ_FOREACH(i, &fw_boot_order, link) {
+        if (i->bootindex == bootindex) {
+            fprintf(stderr, "Two devices with same boot index %d\n", bootindex);
+            exit(1);
+        } else if (i->bootindex < bootindex) {
+            continue;
+        }
+        QTAILQ_INSERT_BEFORE(i, node, link);
+        return;
+    }
+    QTAILQ_INSERT_TAIL(&fw_boot_order, node, link);
+}
+
 static void numa_add(const char *optarg)
 {
     char option[128];
-- 
1.7.2.3

  parent reply	other threads:[~2010-11-17 16:44 UTC|newest]

Thread overview: 136+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-17 16:43 [PATCHv6 00/16] boot order specification Gleb Natapov
2010-11-17 16:43 ` [Qemu-devel] " Gleb Natapov
2010-11-17 16:43 ` [PATCHv6 01/16] Introduce fw_name field to DeviceInfo structure Gleb Natapov
2010-11-17 16:43   ` [Qemu-devel] " Gleb Natapov
2010-11-17 16:43 ` [PATCHv6 02/16] Introduce new BusInfo callback get_fw_dev_path Gleb Natapov
2010-11-17 16:43   ` [Qemu-devel] " Gleb Natapov
2010-11-17 16:43 ` [PATCHv6 03/16] Keep track of ISA ports ISA device is using in qdev Gleb Natapov
2010-11-17 16:43   ` [Qemu-devel] " Gleb Natapov
2010-11-17 16:43 ` [PATCHv6 04/16] Add get_fw_dev_path callback to ISA bus " Gleb Natapov
2010-11-17 16:43   ` [Qemu-devel] " Gleb Natapov
2010-11-17 16:43 ` [PATCHv6 05/16] Store IDE bus id in IDEBus structure for easy access Gleb Natapov
2010-11-17 16:43   ` [Qemu-devel] " Gleb Natapov
2010-11-17 16:43 ` [PATCHv6 06/16] Add get_fw_dev_path callback to IDE bus Gleb Natapov
2010-11-17 16:43   ` [Qemu-devel] " Gleb Natapov
2010-11-17 16:43 ` [PATCHv6 07/16] Add get_dev_path callback for system bus Gleb Natapov
2010-11-17 16:43   ` [Qemu-devel] " Gleb Natapov
2010-11-17 16:43 ` [PATCHv6 08/16] Add get_fw_dev_path callback for pci bus Gleb Natapov
2010-11-17 16:43   ` [Qemu-devel] " Gleb Natapov
2010-11-17 16:43 ` [PATCHv6 09/16] Record which USBDevice USBPort belongs too Gleb Natapov
2010-11-17 16:43   ` [Qemu-devel] " Gleb Natapov
2010-11-17 16:43 ` [PATCHv6 10/16] Add get_dev_path callback for usb bus Gleb Natapov
2010-11-17 16:43   ` [Qemu-devel] " Gleb Natapov
2010-11-17 16:43 ` [PATCHv6 11/16] Add get_dev_path callback to scsi bus Gleb Natapov
2010-11-17 16:43   ` [Qemu-devel] " Gleb Natapov
2010-11-17 16:43 ` Gleb Natapov [this message]
2010-11-17 16:43   ` [Qemu-devel] [PATCHv6 12/16] Add bootindex parameter to net/block/fd device Gleb Natapov
2010-11-17 16:44 ` [PATCHv6 13/16] Change fw_cfg_add_file() to get full file path as a parameter Gleb Natapov
2010-11-17 16:44   ` [Qemu-devel] " Gleb Natapov
2010-11-17 16:44 ` [PATCHv6 14/16] Add bootindex for option roms Gleb Natapov
2010-11-17 16:44   ` [Qemu-devel] " Gleb Natapov
2010-11-17 16:44 ` [PATCHv6 15/16] Add notifier that will be called when machine is fully created Gleb Natapov
2010-11-17 16:44   ` [Qemu-devel] " Gleb Natapov
2010-11-17 16:44 ` [PATCHv6 16/16] Pass boot device list to firmware Gleb Natapov
2010-11-17 16:44   ` [Qemu-devel] " Gleb Natapov
2010-11-23 15:31 ` [PATCHv6 00/16] boot order specification Gleb Natapov
2010-11-23 15:31   ` [Qemu-devel] " Gleb Natapov
2010-11-23 16:12   ` Anthony Liguori
2010-11-23 16:12     ` [Qemu-devel] " Anthony Liguori
2010-11-23 19:30     ` Blue Swirl
2010-11-23 19:30       ` [Qemu-devel] " Blue Swirl
2010-11-27 20:56     ` Avi Kivity
2010-11-27 20:56       ` [Qemu-devel] " Avi Kivity
2010-11-28  7:54       ` Gleb Natapov
2010-11-28  7:54         ` [Qemu-devel] " Gleb Natapov
2010-11-28  9:38         ` Avi Kivity
2010-11-28  9:38           ` [Qemu-devel] " Avi Kivity
2010-11-28  9:47           ` Gleb Natapov
2010-11-28  9:47             ` [Qemu-devel] " Gleb Natapov
2010-11-28 12:39         ` Blue Swirl
2010-11-28 12:39           ` [Qemu-devel] " Blue Swirl
2010-11-28 13:03           ` Gleb Natapov
2010-11-28 13:03             ` [Qemu-devel] " Gleb Natapov
2010-11-28 13:13         ` Michael S. Tsirkin
2010-11-28 13:13           ` [Qemu-devel] " Michael S. Tsirkin
2010-11-28 13:19           ` Gleb Natapov
2010-11-28 13:19             ` [Qemu-devel] " Gleb Natapov
2010-11-28 13:22             ` Blue Swirl
2010-11-28 13:22               ` [Qemu-devel] " Blue Swirl
2010-11-28 17:02               ` Michael S. Tsirkin
2010-11-28 17:02                 ` [Qemu-devel] " Michael S. Tsirkin
2010-11-28 17:23             ` Michael S. Tsirkin
2010-11-28 17:23               ` [Qemu-devel] " Michael S. Tsirkin
2010-11-28 18:54               ` Gleb Natapov
2010-11-28 18:54                 ` [Qemu-devel] " Gleb Natapov
2010-11-28 19:09                 ` Michael S. Tsirkin
2010-11-28 19:09                   ` [Qemu-devel] " Michael S. Tsirkin
2010-11-28 19:20                   ` Gleb Natapov
2010-11-28 19:20                     ` [Qemu-devel] " Gleb Natapov
2010-11-28 13:25           ` Gleb Natapov
2010-11-28 13:25             ` [Qemu-devel] " Gleb Natapov
2010-11-24  1:19   ` Kevin O'Connor
2010-11-24  1:19     ` [Qemu-devel] " Kevin O'Connor
2010-11-24 10:03     ` Gleb Natapov
2010-11-24 10:03       ` [Qemu-devel] " Gleb Natapov
2010-11-27 15:41       ` Kevin O'Connor
2010-11-27 15:41         ` [Qemu-devel] " Kevin O'Connor
2010-11-27 16:22         ` Gleb Natapov
2010-11-27 16:22           ` [Qemu-devel] " Gleb Natapov
2010-11-27 16:49           ` Kevin O'Connor
2010-11-27 16:49             ` [Qemu-devel] " Kevin O'Connor
2010-11-27 17:06             ` Gleb Natapov
2010-11-27 17:06               ` [Qemu-devel] " Gleb Natapov
2010-11-27 17:47               ` Kevin O'Connor
2010-11-27 17:47                 ` [Qemu-devel] " Kevin O'Connor
2010-11-27 18:15                 ` Gleb Natapov
2010-11-27 18:15                   ` [Qemu-devel] " Gleb Natapov
2010-11-27 18:40                   ` Kevin O'Connor
2010-11-27 18:40                     ` [Qemu-devel] " Kevin O'Connor
2010-11-27 19:04                     ` Gleb Natapov
2010-11-27 19:04                       ` [Qemu-devel] " Gleb Natapov
2010-11-27 21:07                       ` Kevin O'Connor
2010-11-27 21:07                         ` [Qemu-devel] " Kevin O'Connor
2010-11-28  7:45                         ` Gleb Natapov
2010-11-28  7:45                           ` [Qemu-devel] " Gleb Natapov
2010-11-28 17:15                           ` Kevin O'Connor
2010-11-28 17:15                             ` [Qemu-devel] " Kevin O'Connor
2010-11-28 18:47                             ` Gleb Natapov
2010-11-28 18:47                               ` [Qemu-devel] " Gleb Natapov
2010-11-30  1:34                               ` Kevin O'Connor
2010-11-30 14:01                                 ` Gleb Natapov
2010-11-30 14:01                                   ` [Qemu-devel] " Gleb Natapov
2010-12-01  2:53                                   ` Kevin O'Connor
2010-12-01  2:53                                     ` [Qemu-devel] " Kevin O'Connor
2010-12-01 12:27                                     ` Gleb Natapov
2010-12-01 12:27                                       ` [Qemu-devel] " Gleb Natapov
2010-12-02  2:25                                       ` Kevin O'Connor
2010-12-02  2:25                                         ` [Qemu-devel] " Kevin O'Connor
2010-12-02 12:30                                         ` Gleb Natapov
2010-12-02 12:30                                           ` [Qemu-devel] " Gleb Natapov
2010-12-02 15:07                                           ` [SeaBIOS] " Peter Stuge
2010-12-02 15:07                                             ` [Qemu-devel] " Peter Stuge
2010-12-02 17:13                                             ` Gleb Natapov
2010-12-02 17:13                                               ` [Qemu-devel] " Gleb Natapov
2010-12-02 21:22                                           ` Sebastian Herbszt
2010-12-02 21:22                                             ` [Qemu-devel] " Sebastian Herbszt
2010-12-03  2:01                                           ` Kevin O'Connor
2010-12-03  2:01                                             ` [Qemu-devel] " Kevin O'Connor
2010-12-03  5:55                                             ` Gleb Natapov
2010-12-03  5:55                                               ` [Qemu-devel] " Gleb Natapov
2010-11-29 10:50                             ` Gerd Hoffmann
2010-11-29 10:50                               ` [Qemu-devel] " Gerd Hoffmann
2010-11-30  1:55                               ` Kevin O'Connor
2010-11-30 14:59                                 ` Gleb Natapov
2010-11-30 14:59                                   ` [Qemu-devel] " Gleb Natapov
2010-11-28 19:00                           ` [SeaBIOS] " Peter Stuge
2010-11-28 19:00                             ` [Qemu-devel] " Peter Stuge
2010-11-28 19:11                             ` Peter Stuge
2010-11-28 19:11                               ` [Qemu-devel] " Peter Stuge
2010-11-28 19:52                               ` Gleb Natapov
2010-11-28 19:52                                 ` [Qemu-devel] " Gleb Natapov
2010-11-28 19:16                             ` Gleb Natapov
2010-11-28 19:16                               ` [Qemu-devel] " Gleb Natapov
2010-11-29 10:19                     ` Gerd Hoffmann
2010-11-29 10:19                       ` [Qemu-devel] " Gerd Hoffmann
2010-11-29 12:07                       ` Gleb Natapov
2010-11-29 12:07                         ` [Qemu-devel] " Gleb Natapov

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=1290012243-6087-13-git-send-email-gleb@redhat.com \
    --to=gleb@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=armbru@redhat.com \
    --cc=blauwirbel@gmail.com \
    --cc=kevin@koconnor.net \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.