[RFC PATCH 07/20] hw/virtio-serial-bus.c: Add virtio-serial 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'.
		reporting error when transport property not set. ]
Signed-off-by: KONRAD Frederic <fred.konrad@xxxxxxxxxxxxx>
---
 hw/virtio-serial-bus.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/virtio-serial.h     | 14 +++++++++++
 2 files changed, 80 insertions(+)

diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index d20bd8b..c0ac017 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -24,6 +24,8 @@
 #include "sysbus.h"
 #include "trace.h"
 #include "virtio-serial.h"
+#include "virtio-transport.h"
+#include "virtio-pci.h"
 
 /* The virtio-serial bus on top of which the ports will ride as devices */
 struct VirtIOSerialBus {
@@ -1009,3 +1011,67 @@ 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;
+    }
+
+    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_serial_properties[] = {
+    DEFINE_PROP_UINT32("max_ports", VirtIOSerState,
+                       serial.max_virtserial_ports, 31),
+    DEFINE_VIRTIO_COMMON_FEATURES(VirtIOSerState, host_features),
+    DEFINE_PROP_TRANSPORT("transport", VirtIOSerState, trl),
+    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)
diff --git a/hw/virtio-serial.h b/hw/virtio-serial.h
index 16e3982..2e20df8 100644
--- a/hw/virtio-serial.h
+++ b/hw/virtio-serial.h
@@ -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,18 @@ struct VirtIOSerialPort {
     bool throttled;
 };
 
+typedef struct {
+    DeviceState qdev;
+    /* virtio-serial */
+    virtio_serial_conf serial;
+
+    uint32_t host_features;
+
+    VirtIOTransportLink *trl;
+} VirtIOSerState;
+
+#define VIRTIO_SERIAL_FROM_QDEV(dev) DO_UPCAST(VirtIOSerState, qdev, dev)
+
 /* Interface to the virtio-serial bus */
 
 /*
-- 
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