1d8d4d62cSThomas Huth /*
2d8d4d62cSThomas Huth * vhost vsock ccw implementation
3d8d4d62cSThomas Huth *
4d8d4d62cSThomas Huth * This work is licensed under the terms of the GNU GPL, version 2 or (at
5d8d4d62cSThomas Huth * your option) any later version. See the COPYING file in the top-level
6d8d4d62cSThomas Huth * directory.
7d8d4d62cSThomas Huth */
8d8d4d62cSThomas Huth
9d8d4d62cSThomas Huth #include "qemu/osdep.h"
10a27bd6c7SMarkus Armbruster #include "hw/qdev-properties.h"
11d8d4d62cSThomas Huth #include "hw/virtio/virtio.h"
12d8d4d62cSThomas Huth #include "qapi/error.h"
130b8fa32fSMarkus Armbruster #include "qemu/module.h"
14d8d4d62cSThomas Huth #include "virtio-ccw.h"
15*7da50d64SPaolo Bonzini #include "hw/virtio/vhost-vsock.h"
16*7da50d64SPaolo Bonzini
17*7da50d64SPaolo Bonzini #define TYPE_VHOST_VSOCK_CCW "vhost-vsock-ccw"
18*7da50d64SPaolo Bonzini OBJECT_DECLARE_SIMPLE_TYPE(VHostVSockCCWState, VHOST_VSOCK_CCW)
19*7da50d64SPaolo Bonzini
20*7da50d64SPaolo Bonzini struct VHostVSockCCWState {
21*7da50d64SPaolo Bonzini VirtioCcwDevice parent_obj;
22*7da50d64SPaolo Bonzini VHostVSock vdev;
23*7da50d64SPaolo Bonzini };
24d8d4d62cSThomas Huth
25d8d4d62cSThomas Huth static Property vhost_vsock_ccw_properties[] = {
26d8d4d62cSThomas Huth DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev,
27d8d4d62cSThomas Huth VIRTIO_CCW_MAX_REV),
28d8d4d62cSThomas Huth DEFINE_PROP_END_OF_LIST(),
29d8d4d62cSThomas Huth };
30d8d4d62cSThomas Huth
vhost_vsock_ccw_realize(VirtioCcwDevice * ccw_dev,Error ** errp)31d8d4d62cSThomas Huth static void vhost_vsock_ccw_realize(VirtioCcwDevice *ccw_dev, Error **errp)
32d8d4d62cSThomas Huth {
33d8d4d62cSThomas Huth VHostVSockCCWState *dev = VHOST_VSOCK_CCW(ccw_dev);
34d8d4d62cSThomas Huth DeviceState *vdev = DEVICE(&dev->vdev);
35d8d4d62cSThomas Huth
3699ba777eSMarkus Armbruster qdev_realize(vdev, BUS(&ccw_dev->bus), errp);
37d8d4d62cSThomas Huth }
38d8d4d62cSThomas Huth
vhost_vsock_ccw_class_init(ObjectClass * klass,void * data)39d8d4d62cSThomas Huth static void vhost_vsock_ccw_class_init(ObjectClass *klass, void *data)
40d8d4d62cSThomas Huth {
41d8d4d62cSThomas Huth DeviceClass *dc = DEVICE_CLASS(klass);
42d8d4d62cSThomas Huth VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
43d8d4d62cSThomas Huth
44d8d4d62cSThomas Huth k->realize = vhost_vsock_ccw_realize;
45d8d4d62cSThomas Huth set_bit(DEVICE_CATEGORY_MISC, dc->categories);
464f67d30bSMarc-André Lureau device_class_set_props(dc, vhost_vsock_ccw_properties);
47d8d4d62cSThomas Huth }
48d8d4d62cSThomas Huth
vhost_vsock_ccw_instance_init(Object * obj)49d8d4d62cSThomas Huth static void vhost_vsock_ccw_instance_init(Object *obj)
50d8d4d62cSThomas Huth {
51d8d4d62cSThomas Huth VHostVSockCCWState *dev = VHOST_VSOCK_CCW(obj);
52a6704a34SStefano Garzarella VirtioCcwDevice *ccw_dev = VIRTIO_CCW_DEVICE(obj);
53a6704a34SStefano Garzarella VirtIODevice *virtio_dev;
54d8d4d62cSThomas Huth
55d8d4d62cSThomas Huth virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
56d8d4d62cSThomas Huth TYPE_VHOST_VSOCK);
57a6704a34SStefano Garzarella
58a6704a34SStefano Garzarella virtio_dev = VIRTIO_DEVICE(&dev->vdev);
59a6704a34SStefano Garzarella
60a6704a34SStefano Garzarella /*
61a6704a34SStefano Garzarella * To avoid migration issues, we force virtio version 1 only when
62a6704a34SStefano Garzarella * legacy check is enabled in the new machine types (>= 5.1).
63a6704a34SStefano Garzarella */
64a6704a34SStefano Garzarella if (!virtio_legacy_check_disabled(virtio_dev)) {
65a6704a34SStefano Garzarella ccw_dev->force_revision_1 = true;
66a6704a34SStefano Garzarella }
67d8d4d62cSThomas Huth }
68d8d4d62cSThomas Huth
69d8d4d62cSThomas Huth static const TypeInfo vhost_vsock_ccw_info = {
70d8d4d62cSThomas Huth .name = TYPE_VHOST_VSOCK_CCW,
71d8d4d62cSThomas Huth .parent = TYPE_VIRTIO_CCW_DEVICE,
72d8d4d62cSThomas Huth .instance_size = sizeof(VHostVSockCCWState),
73d8d4d62cSThomas Huth .instance_init = vhost_vsock_ccw_instance_init,
74d8d4d62cSThomas Huth .class_init = vhost_vsock_ccw_class_init,
75d8d4d62cSThomas Huth };
76d8d4d62cSThomas Huth
vhost_vsock_ccw_register(void)77d8d4d62cSThomas Huth static void vhost_vsock_ccw_register(void)
78d8d4d62cSThomas Huth {
79d8d4d62cSThomas Huth type_register_static(&vhost_vsock_ccw_info);
80d8d4d62cSThomas Huth }
81d8d4d62cSThomas Huth
82d8d4d62cSThomas Huth type_init(vhost_vsock_ccw_register)
83