[RFC PATCH 08/20] hw/virtio-balloon.c: Add virtio-balloon device.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Evgeny Voevodin <e.voevodin@xxxxxxxxxxx>

Signed-off-by: Evgeny Voevodin <e.voevodin@xxxxxxxxxxx>
[Minor change : fixing the properties by adding 'transport' and 'host_features'.
		adding error report when transport property not set.]
Signed-off-by: KONRAD Frederic <fred.konrad@xxxxxxxxxxxxx>
---
 hw/virtio-balloon.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/virtio-balloon.h | 12 ++++++++++
 2 files changed, 75 insertions(+)

diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index dd1a650..ed9e8b3 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -20,6 +20,8 @@
 #include "cpu.h"
 #include "balloon.h"
 #include "virtio-balloon.h"
+#include "virtio-transport.h"
+#include "virtio-pci.h"
 #include "kvm.h"
 #include "exec-memory.h"
 
@@ -272,3 +274,64 @@ 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;
+    }
+
+    if (s->trl == NULL)
+    {
+        error_report("transport property not set");
+        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_balloon_properties[] = {
+    DEFINE_PROP_TRANSPORT("transport", VirtIOBaloonState, trl),
+    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)
diff --git a/hw/virtio-balloon.h b/hw/virtio-balloon.h
index 73300dd..8534f52 100644
--- a/hw/virtio-balloon.h
+++ b/hw/virtio-balloon.h
@@ -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,14 @@ typedef struct VirtIOBalloonStat {
     uint64_t val;
 } QEMU_PACKED VirtIOBalloonStat;
 
+typedef struct {
+    DeviceState qdev;
+
+    uint32_t host_features;
+
+    VirtIOTransportLink *trl;
+} VirtIOBaloonState;
+
+#define VIRTIO_BALLOON_FROM_QDEV(dev) DO_UPCAST(VirtIOBaloonState, qdev, dev)
+
 #endif
-- 
1.7.11.7

_______________________________________________
kvmarm mailing list
kvmarm@xxxxxxxxxxxxxxxxxxxxx
https://lists.cs.columbia.edu/cucslists/listinfo/kvmarm


[Index of Archives]     [Linux KVM]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux