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