Signed-off-by: Evgeny Voevodin <e.voevo...@samsung.com>
---
 hw/virtio-balloon.c |   42 ++++++++++++++++++++++++++++++++++++++++++
 hw/virtio-balloon.h |    9 +++++++++
 2 files changed, 51 insertions(+)

diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index dd1a650..d6fe2aa 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -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)
diff --git a/hw/virtio-balloon.h b/hw/virtio-balloon.h
index 73300dd..b925186 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,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
-- 
1.7.9.5


Reply via email to