Skip to contentSkip to conversation

Virtio-mmio refactoring.

RFC In review Evgeny Voevodin 3 participants 17 messages Sep 17, 2012 – Sep 28, 2012 Arm Samsung Exynos

lore
Share & tools
lore
#0 lore raw

v2 cover Virtio-mmio refactoring.

Previous RFC you can find at
http://lists.gnu.org/archive/html/qemu-devel/2012-04/msg03665.html
Yes, long time ago...
Since I'm not sure when I'll be able to continue on this, I'm publishing this work as is.
In this patchset I tried to split virtio-xxx-pci devices into virtio-pci + virtio-xxx (blk, net, serial,...). Also virtio-mmio transport is introduced based on Peter's work which is accessible
here: http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg01870.html

The main idea was to let users specify
-device virtio-pci,id=virtio-pci.0
-device virtio-blk,transport=virtio-pci.0,...

and

-device virtio-mmio,id=virtio-mmio.0
-device virtio-blk,transport=virtio-mmio.0,...

I created virtio-pci and virtio-mmio transport devices and tried to enclose back-end functionality into virtio-blk, virtio-net, etc. On initialization of transport device it creates a bus to which a back-end device could be connected. Each back-end device is implemented in corresponding source file. As for PCI transport, I temporary placed it in a new virtio-pci-new.c file to not break a functionality of still presented virtio-xxx-pci devices.

Known issues to be resolved:
1. On creation of back-end we need to resolve somehow if props were explicitly set by user.
2. Back-end device can't be initialized if there are no free bus created by transport, so you can't specify
-device virtio-blk,transport=virtio-pci.0,...
-device virtio-pci,id=virtio-pci.0
3. Implement virtio-xxx-devices such that they just create virtio-pci and virtio-xxx devices during initialization.
4. Refactor all remaining back-ends since I just tried blk, net, serial and balloon.
5. Refactor s390
6. Further?

Evgeny Voevodin (9):
Virtio: Add transport bindings. hw/qdev-properties.c: Add "transport" property. hw/pci.c: Make pci_add_option_rom global visible hw/virtio-serial-bus.c: Add virtio-serial device. hw/virtio-balloon.c: Add virtio-balloon device. hw/virtio-net.c: Add virtio-net device. hw/virtio-blk.c: Add virtio-blk device. hw/virtio-pci-new.c: Add VirtIOPCI device. hw/exynos4210.c: Create two virtio-mmio transport instances.

Peter Maydell (3):
virtio: Add support for guest setting of queue size
virtio: Support transports which can specify the vring alignment Add MMIO based virtio transport

 hw/Makefile.objs       |    3 +
 hw/exynos4210.c        |   13 +
 hw/pci.c               |    3 +-
 hw/pci.h               |    2 +
 hw/qdev-properties.c   |   29 ++
 hw/qdev.h              |    3 +
 hw/virtio-balloon.c    |   42 +++
 hw/virtio-balloon.h    |    9 +
 hw/virtio-blk.c        |   65 ++++
 hw/virtio-blk.h        |   15 +
 hw/virtio-mmio.c       |  400 +++++++++++++++++++++
 hw/virtio-net.c        |   59 +++
 hw/virtio-net.h        |   16 +
 hw/virtio-pci-new.c    |  925 ++++++++++++++++++++++++++++++++++++++++++++++++
 hw/virtio-pci.h        |   18 +
 hw/virtio-serial-bus.c |   44 +++
 hw/virtio-serial.h     |   11 +
 hw/virtio-transport.c  |  147 ++++++++
 hw/virtio-transport.h  |   74 ++++
 hw/virtio.c            |   20 +-
 hw/virtio.h            |    2 +
 21 files changed, 1896 insertions(+), 4 deletions(-)
 create mode 100644 hw/virtio-mmio.c
 create mode 100644 hw/virtio-pci-new.c
 create mode 100644 hw/virtio-transport.c
 create mode 100644 hw/virtio-transport.h
Signature · 1 line
1.7.9.5
#1 lore raw

RFC v2 1/12 virtio: Add support for guest setting of queue size

From: Peter Maydell <[email protected]>

The MMIO virtio transport spec allows the guest to tell the host how large the queue size is. Add virtio_queue_set_num() function which implements this in the QEMU common virtio support code.

---
 hw/virtio.c |    6 ++++++
 hw/virtio.h |    1 +
 2 files changed, 7 insertions(+)
hw/virtio.c +6 -0
index 209c763..5334326 100644
@@ -628,6 +628,12 @@ target_phys_addr_t virtio_queue_get_addr(VirtIODevice *vdev, int n)
     return vdev->vq[n].pa;
 }
 
+void virtio_queue_set_num(VirtIODevice *vdev, int n, int num)
+{
+    vdev->vq[n].vring.num = num;
+    virtqueue_init(&vdev->vq[n]);
+}
+
 int virtio_queue_get_num(VirtIODevice *vdev, int n)
 {
     return vdev->vq[n].vring.num;
hw/virtio.h +1 -0
index 7a4f564..eb9953f 100644
@@ -177,6 +177,7 @@ void virtio_config_writew(VirtIODevice *vdev, uint32_t addr, uint32_t data);
 void virtio_config_writel(VirtIODevice *vdev, uint32_t addr, uint32_t data);
 void virtio_queue_set_addr(VirtIODevice *vdev, int n, target_phys_addr_t addr);
 target_phys_addr_t virtio_queue_get_addr(VirtIODevice *vdev, int n);
+void virtio_queue_set_num(VirtIODevice *vdev, int n, int num);
 int virtio_queue_get_num(VirtIODevice *vdev, int n);
 void virtio_queue_notify(VirtIODevice *vdev, int n);
 uint16_t virtio_queue_vector(VirtIODevice *vdev, int n);
Signature · 1 line
1.7.9.5
#2 lore raw

RFC v2 2/12 virtio: Support transports which can specify the vring alignment

In reply to Evgeny Voevodin

From: Peter Maydell <[email protected]>

Support virtio transports which can specify the vring alignment (ie where the guest communicates this to the host) by providing a new virtio_queue_set_align() function. (The default alignment remains as before.)

FIXME save/load support for this new field!

---
 hw/virtio.c |   14 ++++++++++++--
 hw/virtio.h |    1 +
 2 files changed, 13 insertions(+), 2 deletions(-)
hw/virtio.c +12 -2
index 5334326..4f47d4e 100644
@@ -19,7 +19,9 @@
 #include "qemu-barrier.h"
 
 /* The alignment to use between consumer and producer parts of vring.
- * x86 pagesize again. */
+ * x86 pagesize again. This is the default, used by transports like PCI
+ * which don't provide a means for the guest to tell the host the alignment.
+ */
 #define VIRTIO_PCI_VRING_ALIGN         4096
 
 typedef struct VRingDesc
@@ -53,6 +55,7 @@ typedef struct VRingUsed
 typedef struct VRing
 {
     unsigned int num;
+    unsigned int align;
     target_phys_addr_t desc;
     target_phys_addr_t avail;
     target_phys_addr_t used;
@@ -90,7 +93,7 @@ static void virtqueue_init(VirtQueue *vq)
     vq->vring.avail = pa + vq->vring.num * sizeof(VRingDesc);
     vq->vring.used = vring_align(vq->vring.avail +
                                  offsetof(VRingAvail, ring[vq->vring.num]),
-                                 VIRTIO_PCI_VRING_ALIGN);
+                                 vq->vring.align);
 }
 
 static inline uint64_t vring_desc_addr(target_phys_addr_t desc_pa, int i)
@@ -646,6 +649,12 @@ int virtio_queue_get_id(VirtQueue *vq)
     return vq - &vdev->vq[0];
 }
 
+void virtio_queue_set_align(VirtIODevice *vdev, int n, int align)
+{
+    vdev->vq[n].vring.align = align;
+    virtqueue_init(&vdev->vq[n]);
+}
+
 void virtio_queue_notify_vq(VirtQueue *vq)
 {
     if (vq->vring.desc) {
@@ -686,6 +695,7 @@ VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size,
         abort();
 
     vdev->vq[i].vring.num = queue_size;
+    vdev->vq[i].vring.align = VIRTIO_PCI_VRING_ALIGN;
     vdev->vq[i].handle_output = handle_output;
 
     return &vdev->vq[i];
hw/virtio.h +1 -0
index eb9953f..3f16367 100644
@@ -179,6 +179,7 @@ void virtio_queue_set_addr(VirtIODevice *vdev, int n, target_phys_addr_t addr);
 target_phys_addr_t virtio_queue_get_addr(VirtIODevice *vdev, int n);
 void virtio_queue_set_num(VirtIODevice *vdev, int n, int num);
 int virtio_queue_get_num(VirtIODevice *vdev, int n);
+void virtio_queue_set_align(VirtIODevice *vdev, int n, int align);
 void virtio_queue_notify(VirtIODevice *vdev, int n);
 uint16_t virtio_queue_vector(VirtIODevice *vdev, int n);
 void virtio_queue_set_vector(VirtIODevice *vdev, int n, uint16_t vector);
Signature · 1 line
1.7.9.5
#3 lore raw

RFC v2 3/12 Virtio: Add transport bindings.

In reply to Evgeny Voevodin
---
 hw/Makefile.objs      |    1 +
 hw/virtio-transport.c |  147 +++++++++++++++++++++++++++++++++++++++++++++++++
 hw/virtio-transport.h |   74 +++++++++++++++++++++++++
 3 files changed, 222 insertions(+)
 create mode 100644 hw/virtio-transport.c
 create mode 100644 hw/virtio-transport.h
hw/Makefile.objs +1 -0
index 6dfebd2..db4c16d 100644
@@ -2,6 +2,7 @@ hw-obj-y = usb/ ide/
 hw-obj-y += loader.o
 hw-obj-$(CONFIG_VIRTIO) += virtio-console.o
 hw-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
+hw-obj-$(CONFIG_VIRTIO) += virtio-transport.o
 hw-obj-y += fw_cfg.o
 hw-obj-$(CONFIG_PCI) += pci.o pci_bridge.o pci_bridge_dev.o
 hw-obj-$(CONFIG_PCI) += msix.o msi.o
hw/virtio-transport.c new file +147 -0

147 lines not on this page · raw message

hw/virtio-transport.h new file +74 -0

74 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#4 lore raw

RFC v2 4/12 hw/qdev-properties.c: Add "transport" property.

In reply to Evgeny Voevodin

Virtio back-end devices can be plugged into both transports:
VIRTIO_PCI and VIRTIO_MMIO. In order to choose the desired transport we have a property "transport" in every back-end state struct. By specifying -device virtio-blk-pci user chooses VIRTIO_PCI transport and "transport" property is set automatically. But in order to provide full control to user we need to have "transport" property available to be set through command line:

-device virtio-pci,id=virtio-pci.0
-device virtio-blk,transport=virtio-pci.0,...

---
 hw/qdev-properties.c |   29 +++++++++++++++++++++++++++++
 hw/qdev.h            |    3 +++
 2 files changed, 32 insertions(+)
hw/qdev-properties.c +29 -0
index 8aca0d4..4226a02 100644
@@ -2,6 +2,7 @@
 #include "qdev.h"
 #include "qerror.h"
 #include "blockdev.h"
+#include "virtio-transport.h"
 #include "hw/block-common.h"
 #include "net/hub.h"
 
@@ -526,6 +527,34 @@ PropertyInfo qdev_prop_drive = {
     .release = release_drive,
 };
 
+/* --- virtio transport --- */
+
+static int parse_transport(DeviceState *dev, const char *str, void **ptr)
+{
+    VirtIOTransportLink *trl;
+
+    trl = virtio_find_transport(str);
+
+    if (trl == NULL) {
+        return -ENOENT;
+    }
+
+    *ptr = trl;
+
+    return 0;
+}
+
+static void set_transport(Object *obj, Visitor *v, void *opaque,
+                      const char *name, Error **errp)
+{
+    set_pointer(obj, v, opaque, parse_transport, name, errp);
+}
+
+PropertyInfo qdev_prop_transport = {
+    .name  = "transport",
+    .set   = set_transport,
+};
+
 /* --- character device --- */
 
 static int parse_chr(DeviceState *dev, const char *str, void **ptr)
hw/qdev.h +3 -0
index d699194..bd6aa6e 100644
@@ -233,6 +233,7 @@ extern PropertyInfo qdev_prop_macaddr;
 extern PropertyInfo qdev_prop_losttickpolicy;
 extern PropertyInfo qdev_prop_bios_chs_trans;
 extern PropertyInfo qdev_prop_drive;
+extern PropertyInfo qdev_prop_transport;
 extern PropertyInfo qdev_prop_netdev;
 extern PropertyInfo qdev_prop_vlan;
 extern PropertyInfo qdev_prop_pci_devfn;
@@ -294,6 +295,8 @@ extern PropertyInfo qdev_prop_pci_host_devaddr;
     DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, NetClientState*)
 #define DEFINE_PROP_DRIVE(_n, _s, _f) \
     DEFINE_PROP(_n, _s, _f, qdev_prop_drive, BlockDriverState *)
+#define DEFINE_PROP_TRANSPORT(_n, _s, _f) \
+    DEFINE_PROP(_n, _s, _f, qdev_prop_transport, VirtIOTransportLink *)
 #define DEFINE_PROP_MACADDR(_n, _s, _f)         \
     DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr)
 #define DEFINE_PROP_LOSTTICKPOLICY(_n, _s, _f, _d) \
Signature · 1 line
1.7.9.5
#5 lore raw

Re: [Qemu-devel] [RFC v2 04/12] hw/qdev-properties.c: Add "transport" property.

Il 17/09/2012 12:00, Evgeny Voevodin ha scritto:

Review

Quoted 10 lines

Virtio back-end devices can be plugged into both transports:
VIRTIO_PCI and VIRTIO_MMIO. In order to choose the desired transport we have a property "transport" in every back-end state struct. By specifying -device virtio-blk-pci user chooses VIRTIO_PCI transport and "transport" property is set automatically. But in order to provide full control to user we need to have "transport" property available to be set through command line:

(quoted diff) +0 -2
-device virtio-pci,id=virtio-pci.0
-device virtio-blk,transport=virtio-pci.0,...

What's the difference between this and "bus"? i.e.

-device virtio-pci,id=virtio-pci-0
-device virtio-blk,bus=virtio-pci-0.0,...

Paolo

#6 lore raw

Re: [Qemu-devel] [RFC v2 04/12] hw/qdev-properties.c: Add "transport" property.

Quoted 9 lines · Paolo Bonzini

Il 17/09/2012 12:00, Evgeny Voevodin ha scritto:

Quoted 8 lines

Virtio back-end devices can be plugged into both transports:
VIRTIO_PCI and VIRTIO_MMIO. In order to choose the desired transport we have a property "transport" in every back-end state struct. By specifying -device virtio-blk-pci user chooses VIRTIO_PCI transport and "transport" property is set automatically. But in order to provide full control to user we need to have "transport" property available to be set through command line:

Quoted 9 lines

Review

Quoted 2 lines
(quoted diff) +0 -2
-device virtio-pci,id=virtio-pci.0
-device virtio-blk,transport=virtio-pci.0,...

What's the difference between this and "bus"? i.e.

   -device virtio-pci,id=virtio-pci-0
   -device virtio-blk,bus=virtio-pci-0.0,...

Paolo

The difference is that with "transport" I used a linked list like, say, bdrv_states in block.c. It's much simpler then use buses. Also I was planning to use a <link>.
In this approach buses are used only to reflect hierarchy of devices in emulator manager. And yes, cover letter contains quite misleading information because attach to transport is based on a list of links, not on buses. Sorry, I forgot that when wrote the cover.

Signature · 6 lines
Kind regards,
Evgeny Voevodin,
Technical Leader,
Mobile Group,
Samsung Moscow Research Center,
e-mail: [email protected]
#7 lore raw

RFC v2 5/12 hw/pci.c: Make pci_add_option_rom global visible

In reply to Evgeny Voevodin

We need to use this function to load rom for virtio-net backend.

---
 hw/pci.c |    3 +--
 hw/pci.h |    2 ++
 2 files changed, 3 insertions(+), 2 deletions(-)
hw/pci.c +1 -2
index f855cf3..bba69ef 100644
@@ -77,7 +77,6 @@ static const TypeInfo pci_bus_info = {
 static PCIBus *pci_find_bus_nr(PCIBus *bus, int bus_num);
 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, bool is_default_rom);
 static void pci_del_option_rom(PCIDevice *pdev);
 
 static uint16_t pci_default_sub_vendor_id = PCI_SUBVENDOR_ID_REDHAT_QUMRANET;
@@ -1733,7 +1732,7 @@ static void pci_patch_ids(PCIDevice *pdev, uint8_t *ptr, int size)
 }
 
 /* Add an option rom for the device */
-static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)
+int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)
 {
     int size;
     char *path;
hw/pci.h +2 -0
index 4b6ab3d..5f47618 100644
@@ -274,6 +274,8 @@ void pci_register_bar(PCIDevice *pci_dev, int region_num,
                       uint8_t attr, MemoryRegion *memory);
 pcibus_t pci_get_bar_addr(PCIDevice *pci_dev, int region_num);
 
+int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom);
+
 int pci_add_capability(PCIDevice *pdev, uint8_t cap_id,
                        uint8_t offset, uint8_t size);
 
Signature · 1 line
1.7.9.5
#8 lore raw

RFC v2 6/12 Add MMIO based virtio transport

In reply to Evgeny Voevodin

From: Peter Maydell <[email protected]>

Add support for the generic MMIO based virtio transport.

This patch is a modyfied patch of
Peter Maydell <[email protected]>. Changes are to have virtio-mmio bridge device which provides virtio-mmio bus. To this bus virtio-mmio-transport device is connected and in turn provides virtio-transport bus. Then virtio backends could be connected to this bus.

Also this patch includes some fixes for bugs spotted by Ying-Shiuan Pan <[email protected]>.

Conflicts:

Makefile.objs

---
 hw/Makefile.objs |    1 +
 hw/virtio-mmio.c |  400 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 401 insertions(+)
 create mode 100644 hw/virtio-mmio.c
hw/Makefile.objs +1 -0
index db4c16d..0c112af 100644
@@ -3,6 +3,7 @@ hw-obj-y += loader.o
 hw-obj-$(CONFIG_VIRTIO) += virtio-console.o
 hw-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
 hw-obj-$(CONFIG_VIRTIO) += virtio-transport.o
+hw-obj-$(CONFIG_VIRTIO) += virtio-mmio.o
 hw-obj-y += fw_cfg.o
 hw-obj-$(CONFIG_PCI) += pci.o pci_bridge.o pci_bridge_dev.o
 hw-obj-$(CONFIG_PCI) += msix.o msi.o
hw/virtio-mmio.c new file +400 -0

400 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#9 lore raw

RFC v2 7/12 hw/virtio-serial-bus.c: Add virtio-serial device.

In reply to Evgeny Voevodin
---
 hw/virtio-serial-bus.c |   44 ++++++++++++++++++++++++++++++++++++++++++++
 hw/virtio-serial.h     |   11 +++++++++++
 2 files changed, 55 insertions(+)
hw/virtio-serial-bus.c +44 -0
index 82073f5..699a485 100644
@@ -24,6 +24,7 @@
 #include "sysbus.h"
 #include "trace.h"
 #include "virtio-serial.h"
+#include "virtio-transport.h"
 
 /* The virtio-serial bus on top of which the ports will ride as devices */
 struct VirtIOSerialBus {
@@ -1014,3 +1015,46 @@ static void virtio_serial_register_types(void)
 }
 
 type_init(virtio_serial_register_types)
+
+/******************** VirtIOSer Device **********************/
+
+static int virtio_serialdev_init(DeviceState *dev)
+{
+    VirtIODevice *vdev;
+    VirtIOSerState *s = VIRTIO_SERIAL_FROM_QDEV(dev);
+    vdev = virtio_serial_init(dev, &s->serial);
+    if (!vdev) {
+        return -1;
+    }
+
+    assert(s->trl != NULL);
+
+    return virtio_call_backend_init_cb(dev, s->trl, vdev);
+}
+
+static Property virtio_serial_properties[] = {
+    DEFINE_PROP_UINT32("max_ports", VirtIOSerState,
+                       serial.max_virtserial_ports, 31),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_serial_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    dc->init = virtio_serialdev_init;
+    dc->props = virtio_serial_properties;
+}
+
+static TypeInfo virtio_serial_info = {
+    .name = "virtio-serial",
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(VirtIOSerState),
+    .class_init = virtio_serial_class_init,
+};
+
+static void virtio_ser_register_types(void)
+{
+    type_register_static(&virtio_serial_info);
+}
+
+type_init(virtio_ser_register_types)
hw/virtio-serial.h +11 -0
index 16e3982..c6b916a 100644
@@ -15,8 +15,10 @@
 #ifndef _QEMU_VIRTIO_SERIAL_H
 #define _QEMU_VIRTIO_SERIAL_H
 
+#include "sysbus.h"
 #include "qdev.h"
 #include "virtio.h"
+#include "virtio-transport.h"
 
 /* == Interface shared between the guest kernel and qemu == */
 
@@ -173,6 +175,15 @@ struct VirtIOSerialPort {
     bool throttled;
 };
 
+typedef struct {
+    DeviceState qdev;
+    /* virtio-serial */
+    virtio_serial_conf serial;
+    VirtIOTransportLink *trl;
+} VirtIOSerState;
+
+#define VIRTIO_SERIAL_FROM_QDEV(dev) DO_UPCAST(VirtIOSerState, qdev, dev)
+
 /* Interface to the virtio-serial bus */
 
 /*
Signature · 1 line
1.7.9.5
#10 lore raw

RFC v2 8/12 hw/virtio-balloon.c: Add virtio-balloon device.

In reply to Evgeny Voevodin
---
 hw/virtio-balloon.c |   42 ++++++++++++++++++++++++++++++++++++++++++
 hw/virtio-balloon.h |    9 +++++++++
 2 files changed, 51 insertions(+)
hw/virtio-balloon.c +42 -0
index dd1a650..d6fe2aa 100644
@@ -20,6 +20,7 @@
 #include "cpu.h"
 #include "balloon.h"
 #include "virtio-balloon.h"
+#include "virtio-transport.h"
 #include "kvm.h"
 #include "exec-memory.h"
 
@@ -272,3 +273,44 @@ void virtio_balloon_exit(VirtIODevice *vdev)
     unregister_savevm(s->qdev, "virtio-balloon", s);
     virtio_cleanup(vdev);
 }
+
+/******************** VirtIOBaloon Device **********************/
+
+static int virtio_balloondev_init(DeviceState *dev)
+{
+    VirtIODevice *vdev;
+    VirtIOBaloonState *s = VIRTIO_BALLOON_FROM_QDEV(dev);
+    vdev = virtio_balloon_init(dev);
+    if (!vdev) {
+        return -1;
+    }
+
+    assert(s->trl != NULL);
+
+    return virtio_call_backend_init_cb(dev, s->trl, vdev);
+}
+
+static Property virtio_balloon_properties[] = {
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_balloon_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    dc->init = virtio_balloondev_init;
+    dc->props = virtio_balloon_properties;
+}
+
+static TypeInfo virtio_balloon_info = {
+    .name = "virtio-balloon",
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(VirtIOBaloonState),
+    .class_init = virtio_balloon_class_init,
+};
+
+static void virtio_baloon_register_types(void)
+{
+    type_register_static(&virtio_balloon_info);
+}
+
+type_init(virtio_baloon_register_types)
hw/virtio-balloon.h +9 -0
index 73300dd..b925186 100644
@@ -15,8 +15,10 @@
 #ifndef _QEMU_VIRTIO_BALLOON_H
 #define _QEMU_VIRTIO_BALLOON_H
 
+#include "sysbus.h"
 #include "virtio.h"
 #include "pci.h"
+#include "virtio-transport.h"
 
 /* from Linux's linux/virtio_balloon.h */
 
@@ -52,4 +54,11 @@ typedef struct VirtIOBalloonStat {
     uint64_t val;
 } QEMU_PACKED VirtIOBalloonStat;
 
+typedef struct {
+    DeviceState qdev;
+    VirtIOTransportLink *trl;
+} VirtIOBaloonState;
+
+#define VIRTIO_BALLOON_FROM_QDEV(dev) DO_UPCAST(VirtIOBaloonState, qdev, dev)
+
 #endif
Signature · 1 line
1.7.9.5
#11 lore raw

RFC v2 9/12 hw/virtio-net.c: Add virtio-net device.

In reply to Evgeny Voevodin
---
 hw/virtio-net.c |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/virtio-net.h |   16 +++++++++++++++
 2 files changed, 75 insertions(+)
hw/virtio-net.c +59 -0
index b1998b2..b7cfb1c 100644
@@ -13,6 +13,8 @@
 
 #include "iov.h"
 #include "virtio.h"
+#include "virtio-transport.h"
+#include "virtio-pci.h"
 #include "net.h"
 #include "net/checksum.h"
 #include "net/tap.h"
@@ -1080,3 +1082,60 @@ void virtio_net_exit(VirtIODevice *vdev)
     qemu_del_net_client(&n->nic->nc);
     virtio_cleanup(&n->vdev);
 }
+
+/******************** VirtIONet Device **********************/
+
+static int virtio_netdev_init(DeviceState *dev)
+{
+    VirtIODevice *vdev;
+    VirtIONetState *s = VIRTIO_NET_FROM_QDEV(dev);
+
+    assert(s->trl != NULL);
+
+    vdev = virtio_net_init(dev, &s->nic, &s->net);
+
+    /* Pass default host_features to transport */
+    s->trl->host_features = s->host_features;
+
+    if (virtio_call_backend_init_cb(dev, s->trl, vdev) != 0) {
+        return -1;
+    }
+
+    /* Binding should be ready here, let's get final features */
+    if (vdev->binding->get_features) {
+       s->host_features = vdev->binding->get_features(vdev->binding_opaque);
+    }
+    return 0;
+}
+
+static Property virtio_net_properties[] = {
+    DEFINE_VIRTIO_NET_FEATURES(VirtIONetState, host_features),
+    DEFINE_NIC_PROPERTIES(VirtIONetState, nic),
+    DEFINE_PROP_UINT32("x-txtimer", VirtIONetState, net.txtimer,
+            TX_TIMER_INTERVAL),
+    DEFINE_PROP_INT32("x-txburst", VirtIONetState, net.txburst, TX_BURST),
+    DEFINE_PROP_STRING("tx", VirtIONetState, net.tx),
+    DEFINE_PROP_TRANSPORT("transport", VirtIONetState, trl),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_net_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    dc->init = virtio_netdev_init;
+    dc->props = virtio_net_properties;
+}
+
+static TypeInfo virtio_net_info = {
+    .name = "virtio-net",
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(VirtIONetState),
+    .class_init = virtio_net_class_init,
+};
+
+static void virtio_net_register_types(void)
+{
+    type_register_static(&virtio_net_info);
+}
+
+type_init(virtio_net_register_types)
hw/virtio-net.h +16 -0
index 36aa463..8dd49d3 100644
@@ -14,7 +14,9 @@
 #ifndef _QEMU_VIRTIO_NET_H
 #define _QEMU_VIRTIO_NET_H
 
+#include "sysbus.h"
 #include "virtio.h"
+#include "virtio-transport.h"
 #include "net.h"
 #include "pci.h"
 
@@ -187,4 +189,18 @@ struct virtio_net_ctrl_mac {
         DEFINE_PROP_BIT("ctrl_rx", _state, _field, VIRTIO_NET_F_CTRL_RX, true), \
         DEFINE_PROP_BIT("ctrl_vlan", _state, _field, VIRTIO_NET_F_CTRL_VLAN, true), \
         DEFINE_PROP_BIT("ctrl_rx_extra", _state, _field, VIRTIO_NET_F_CTRL_RX_EXTRA, true)
+
+typedef struct {
+    DeviceState qdev;
+    /* virtio-net */
+    NICConf nic;
+    virtio_net_conf net;
+
+    uint32_t host_features;
+
+    VirtIOTransportLink *trl;
+} VirtIONetState;
+
+#define VIRTIO_NET_FROM_QDEV(dev) DO_UPCAST(VirtIONetState, qdev, dev)
+
 #endif
Signature · 1 line
1.7.9.5
#12 lore raw

RFC v2 10/12 hw/virtio-blk.c: Add virtio-blk device.

In reply to Evgeny Voevodin
---
 hw/virtio-blk.c |   65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/virtio-blk.h |   15 +++++++++++++
 2 files changed, 80 insertions(+)
hw/virtio-blk.c +65 -0
index 6f6d172..0a23352 100644
@@ -16,6 +16,8 @@
 #include "trace.h"
 #include "hw/block-common.h"
 #include "blockdev.h"
+#include "virtio-transport.h"
+#include "virtio-pci.h"
 #include "virtio-blk.h"
 #include "scsi-defs.h"
 #ifdef __linux__
@@ -665,3 +667,66 @@ void virtio_blk_exit(VirtIODevice *vdev)
     blockdev_mark_auto_del(s->bs);
     virtio_cleanup(vdev);
 }
+
+/******************** VirtIOBlk Device **********************/
+
+static int virtio_blkdev_init(DeviceState *dev)
+{
+    VirtIODevice *vdev;
+    VirtIOBlockState *s = VIRTIO_BLK_FROM_QDEV(dev);
+
+    assert(s->trl != NULL);
+
+    vdev = virtio_blk_init(dev, &s->blk);
+    if (!vdev) {
+        return -1;
+    }
+
+    /* Pass default host_features to transport */
+    s->trl->host_features = s->host_features;
+
+    if (virtio_call_backend_init_cb(dev, s->trl, vdev) != 0) {
+        return -1;
+    }
+
+    /* Binding should be ready here, let's get final features */
+    if (vdev->binding->get_features) {
+       s->host_features = vdev->binding->get_features(vdev->binding_opaque);
+    }
+    return 0;
+}
+
+static Property virtio_blkdev_properties[] = {
+    DEFINE_BLOCK_PROPERTIES(VirtIOBlockState, blk.conf),
+    DEFINE_BLOCK_CHS_PROPERTIES(VirtIOBlockState, blk.conf),
+    DEFINE_PROP_STRING("serial", VirtIOBlockState, blk.serial),
+#ifdef __linux__
+    DEFINE_PROP_BIT("scsi", VirtIOBlockState, blk.scsi, 0, true),
+#endif
+    DEFINE_PROP_BIT("config-wce", VirtIOBlockState, blk.config_wce, 0, true),
+    DEFINE_VIRTIO_BLK_FEATURES(VirtIOBlockState, host_features),
+
+    DEFINE_PROP_TRANSPORT("transport", VirtIOBlockState, trl),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_blkdev_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    dc->init = virtio_blkdev_init;
+    dc->props = virtio_blkdev_properties;
+}
+
+static TypeInfo virtio_blkdev_info = {
+    .name = "virtio-blk",
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(VirtIOBlockState),
+    .class_init = virtio_blkdev_class_init,
+};
+
+static void virtio_blk_register_types(void)
+{
+    type_register_static(&virtio_blkdev_info);
+}
+
+type_init(virtio_blk_register_types)
hw/virtio-blk.h +15 -0
index f0740d0..0886818 100644
@@ -14,7 +14,9 @@
 #ifndef _QEMU_VIRTIO_BLK_H
 #define _QEMU_VIRTIO_BLK_H
 
+#include "sysbus.h"
 #include "virtio.h"
+#include "virtio-transport.h"
 #include "hw/block-common.h"
 
 /* from Linux's linux/virtio_blk.h */
@@ -111,4 +113,17 @@ struct VirtIOBlkConf
         DEFINE_VIRTIO_COMMON_FEATURES(_state, _field), \
         DEFINE_PROP_BIT("config-wce", _state, _field, VIRTIO_BLK_F_CONFIG_WCE, true)
 
+
+typedef struct {
+    DeviceState qdev;
+    /* virtio-blk */
+    VirtIOBlkConf blk;
+
+    uint32_t host_features;
+
+    VirtIOTransportLink *trl;
+} VirtIOBlockState;
+
+#define VIRTIO_BLK_FROM_QDEV(dev) DO_UPCAST(VirtIOBlockState, qdev, dev)
+
 #endif
Signature · 1 line
1.7.9.5
#13 lore raw

RFC v2 11/12 hw/virtio-pci-new.c: Add VirtIOPCI device.

In reply to Evgeny Voevodin

This commit adds VirtIOPCI device implementation which is temporary held in virtio-pci-new.c file. We need this file until virtio-xxx-pci devices in hw/virtio-pci.c are not implemented in the way that they just create virtio-pci and virtio-xxx devices during initialization.

---
 hw/Makefile.objs    |    1 +
 hw/virtio-pci-new.c |  925 +++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/virtio-pci.h     |   18 +
 3 files changed, 944 insertions(+)
 create mode 100644 hw/virtio-pci-new.c
hw/Makefile.objs +1 -0
index 0c112af..e5bda7f 100644
@@ -2,6 +2,7 @@ hw-obj-y = usb/ ide/
 hw-obj-y += loader.o
 hw-obj-$(CONFIG_VIRTIO) += virtio-console.o
 hw-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
+hw-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci-new.o
 hw-obj-$(CONFIG_VIRTIO) += virtio-transport.o
 hw-obj-$(CONFIG_VIRTIO) += virtio-mmio.o
 hw-obj-y += fw_cfg.o
hw/virtio-pci-new.c new file +925 -0

925 lines not on this page · raw message

hw/virtio-pci.h +18 -0
index ac9d522..2cddd67 100644
@@ -51,8 +51,26 @@ typedef struct {
     VirtIOIRQFD *vector_irqfd;
 } VirtIOPCIProxy;
 
+typedef struct {
+    PCIDevice pci_dev;
+    VirtIODevice *vdev;
+    MemoryRegion bar;
+
+    uint32_t flags;
+    uint32_t class_code;
+    uint32_t nvectors;
+    uint32_t host_features;
+
+    VirtIOTransportLink *trl;
+
+    bool ioeventfd_disabled;
+    bool ioeventfd_started;
+    VirtIOIRQFD *vector_irqfd;
+} VirtIOPCI;
+
 void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev);
 void virtio_pci_reset(DeviceState *d);
+void virtio_pci_reset_(DeviceState *d);
 
 /* Virtio ABI version, if we increment this, we break the guest driver. */
 #define VIRTIO_PCI_ABI_VERSION          0
Signature · 1 line
1.7.9.5
#14 lore raw

RFC v2 12/12 hw/exynos4210.c: Create two virtio-mmio transport instances.

In reply to Evgeny Voevodin

NB: This is for test purposes only.

---
 hw/exynos4210.c |   13 +++++++++++++
 1 file changed, 13 insertions(+)
hw/exynos4210.c +13 -0
index 00d4db8..70fcdd6 100644
@@ -26,6 +26,7 @@
 #include "sysbus.h"
 #include "arm-misc.h"
 #include "loader.h"
+#include "virtio-transport.h"
 #include "exynos4210.h"
 
 #define EXYNOS4210_CHIPID_ADDR         0x10000000
@@ -72,6 +73,10 @@
 /* Display controllers (FIMD) */
 #define EXYNOS4210_FIMD0_BASE_ADDR          0x11C00000
 
+/* VirtIO MMIO */
+#define EXYNOS4210_VIRTIO_MMIO0_BASE_ADDR   0x10AD0000
+#define EXYNOS4210_VIRTIO_MMIO1_BASE_ADDR   0x10AC0000
+
 static uint8_t chipid_and_omr[] = { 0x11, 0x02, 0x21, 0x43,
                                     0x09, 0x00, 0x00, 0x00 };
 
@@ -334,5 +339,13 @@ Exynos4210State *exynos4210_init(MemoryRegion *system_mem,
             s->irq_table[exynos4210_get_irq(11, 2)],
             NULL);
 
+    sysbus_create_simple(VIRTIO_MMIO,
+                         EXYNOS4210_VIRTIO_MMIO0_BASE_ADDR,
+                         s->irq_table[exynos4210_get_irq(37, 3)]);
+
+    sysbus_create_simple(VIRTIO_MMIO,
+                         EXYNOS4210_VIRTIO_MMIO1_BASE_ADDR,
+                         s->irq_table[exynos4210_get_irq(37, 2)]);
+
     return s;
 }
Signature · 1 line
1.7.9.5
#15 lore raw
In reply to Evgeny Voevodin

Hi,

We actually want to add virtio models for arm, therefore these patches are really helpful.

We will try it, start looking at the issues.

Any feedback ?

Quoted 82 lines · Evgeny Voevodin

Previous RFC you can find at
http://lists.gnu.org/archive/html/qemu-devel/2012-04/msg03665.html
Yes, long time ago...
Since I'm not sure when I'll be able to continue on this, I'm publishing this work as is.
In this patchset I tried to split virtio-xxx-pci devices into virtio-pci + virtio-xxx (blk, net, serial,...). Also virtio-mmio transport is introduced based on Peter's work which is accessible
here: http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg01870.html

The main idea was to let users specify

(quoted diff) +0 -2
-device virtio-pci,id=virtio-pci.0
-device virtio-blk,transport=virtio-pci.0,...

and

(quoted diff) +0 -2
-device virtio-mmio,id=virtio-mmio.0
-device virtio-blk,transport=virtio-mmio.0,...

I created virtio-pci and virtio-mmio transport devices and tried to enclose back-end functionality into virtio-blk, virtio-net, etc. On initialization of transport device it creates a bus to which a back-end device could be connected. Each back-end device is implemented in corresponding source file. As for PCI transport, I temporary placed it in a new virtio-pci-new.c file to not break a functionality of still presented virtio-xxx-pci devices.

Known issues to be resolved:
1. On creation of back-end we need to resolve somehow if props were explicitly set by user.
2. Back-end device can't be initialized if there are no free bus created by transport, so you can't specify

(quoted diff) +0 -2
-device virtio-blk,transport=virtio-pci.0,...
-device virtio-pci,id=virtio-pci.0

3. Implement virtio-xxx-devices such that they just create virtio-pci and virtio-xxx devices during initialization.
4. Refactor all remaining back-ends since I just tried blk, net, serial and balloon.
5. Refactor s390
6. Further?

Evgeny Voevodin (9):
Virtio: Add transport bindings. hw/qdev-properties.c: Add "transport" property. hw/pci.c: Make pci_add_option_rom global visible hw/virtio-serial-bus.c: Add virtio-serial device. hw/virtio-balloon.c: Add virtio-balloon device. hw/virtio-net.c: Add virtio-net device. hw/virtio-blk.c: Add virtio-blk device. hw/virtio-pci-new.c: Add VirtIOPCI device. hw/exynos4210.c: Create two virtio-mmio transport instances.

Peter Maydell (3):
virtio: Add support for guest setting of queue size
virtio: Support transports which can specify the vring alignment Add MMIO based virtio transport

  hw/Makefile.objs       |    3 +
  hw/exynos4210.c        |   13 +
  hw/pci.c               |    3 +-
  hw/pci.h               |    2 +
  hw/qdev-properties.c   |   29 ++
  hw/qdev.h              |    3 +
  hw/virtio-balloon.c    |   42 +++
  hw/virtio-balloon.h    |    9 +
  hw/virtio-blk.c        |   65 ++++
  hw/virtio-blk.h        |   15 +
  hw/virtio-mmio.c       |  400 +++++++++++++++++++++
  hw/virtio-net.c        |   59 +++
  hw/virtio-net.h        |   16 +
  hw/virtio-pci-new.c    |  925 ++++++++++++++++++++++++++++++++++++++++++++++++
  hw/virtio-pci.h        |   18 +
  hw/virtio-serial-bus.c |   44 +++
  hw/virtio-serial.h     |   11 +
  hw/virtio-transport.c  |  147 ++++++++
  hw/virtio-transport.h  |   74 ++++
  hw/virtio.c            |   20 +-
  hw/virtio.h            |    2 +
  21 files changed, 1896 insertions(+), 4 deletions(-)

create mode 100644 hw/virtio-mmio.c
create mode 100644 hw/virtio-pci-new.c
create mode 100644 hw/virtio-transport.c
create mode 100644 hw/virtio-transport.h

#16 lore raw
Quoted 8 lines · KONRAD Frédéric

Hi,

We actually want to add virtio models for arm, therefore these patches are really helpful.

We will try it, start looking at the issues.

Any feedback ?

Ok. Feel free.

Quoted 85 lines · Evgeny Voevodin
Quoted 82 lines

Previous RFC you can find at
http://lists.gnu.org/archive/html/qemu-devel/2012-04/msg03665.html
Yes, long time ago...
Since I'm not sure when I'll be able to continue on this, I'm publishing this work as is.
In this patchset I tried to split virtio-xxx-pci devices into virtio-pci + virtio-xxx (blk, net, serial,...). Also virtio-mmio transport is introduced based on Peter's work which is accessible
here: http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg01870.html

The main idea was to let users specify

(quoted diff) +0 -4
-device virtio-pci,id=virtio-pci.0
-device virtio-blk,transport=virtio-pci.0,...
  and
 
-device virtio-mmio,id=virtio-mmio.0
-device virtio-blk,transport=virtio-mmio.0,...

I created virtio-pci and virtio-mmio transport devices and tried to enclose back-end functionality into virtio-blk, virtio-net, etc. On initialization of transport device it creates a bus to which a back-end device could be connected. Each back-end device is implemented in corresponding source file. As for PCI transport, I temporary placed it in a new virtio-pci-new.c file to not break a functionality of still presented virtio-xxx-pci devices.

Known issues to be resolved:
1. On creation of back-end we need to resolve somehow if props were explicitly set by user.
2. Back-end device can't be initialized if there are no free bus created by transport, so you can't specify

(quoted diff) +0 -2
-device virtio-blk,transport=virtio-pci.0,...
-device virtio-pci,id=virtio-pci.0

3. Implement virtio-xxx-devices such that they just create virtio-pci and virtio-xxx devices during initialization.
4. Refactor all remaining back-ends since I just tried blk, net, serial and balloon.
5. Refactor s390
6. Further?

Evgeny Voevodin (9):
Virtio: Add transport bindings. hw/qdev-properties.c: Add "transport" property. hw/pci.c: Make pci_add_option_rom global visible hw/virtio-serial-bus.c: Add virtio-serial device. hw/virtio-balloon.c: Add virtio-balloon device. hw/virtio-net.c: Add virtio-net device. hw/virtio-blk.c: Add virtio-blk device. hw/virtio-pci-new.c: Add VirtIOPCI device. hw/exynos4210.c: Create two virtio-mmio transport instances.

Peter Maydell (3):
virtio: Add support for guest setting of queue size
virtio: Support transports which can specify the vring alignment Add MMIO based virtio transport

  hw/Makefile.objs       |    3 +
  hw/exynos4210.c        |   13 +
  hw/pci.c               |    3 +-
  hw/pci.h               |    2 +
  hw/qdev-properties.c   |   29 ++
  hw/qdev.h              |    3 +
  hw/virtio-balloon.c    |   42 +++
  hw/virtio-balloon.h    |    9 +
  hw/virtio-blk.c        |   65 ++++
  hw/virtio-blk.h        |   15 +
  hw/virtio-mmio.c       |  400 +++++++++++++++++++++
  hw/virtio-net.c        |   59 +++
  hw/virtio-net.h        |   16 +
  hw/virtio-pci-new.c    |  925 
++++++++++++++++++++++++++++++++++++++++++++++++
  hw/virtio-pci.h        |   18 +
  hw/virtio-serial-bus.c |   44 +++
  hw/virtio-serial.h     |   11 +
  hw/virtio-transport.c  |  147 ++++++++
  hw/virtio-transport.h  |   74 ++++
  hw/virtio.c            |   20 +-
  hw/virtio.h            |    2 +
  21 files changed, 1896 insertions(+), 4 deletions(-)

create mode 100644 hw/virtio-mmio.c
create mode 100644 hw/virtio-pci-new.c
create mode 100644 hw/virtio-transport.c
create mode 100644 hw/virtio-transport.h

Signature · 6 lines
Kind regards,
Evgeny Voevodin,
Technical Leader,
Mobile Group,
Samsung Moscow Research Center,
e-mail: [email protected]