xref: /openbmc/qemu/hw/s390x/virtio-ccw.c (revision 83974cf4)
1 /*
2  * virtio ccw target implementation
3  *
4  * Copyright 2012,2015 IBM Corp.
5  * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
6  *            Pierre Morel <pmorel@linux.vnet.ibm.com>
7  *
8  * This work is licensed under the terms of the GNU GPL, version 2 or (at
9  * your option) any later version. See the COPYING file in the top-level
10  * directory.
11  */
12 
13 #include "qemu/osdep.h"
14 #include "qapi/error.h"
15 #include "hw/hw.h"
16 #include "sysemu/block-backend.h"
17 #include "sysemu/blockdev.h"
18 #include "sysemu/sysemu.h"
19 #include "sysemu/kvm.h"
20 #include "net/net.h"
21 #include "hw/virtio/virtio.h"
22 #include "hw/virtio/virtio-serial.h"
23 #include "hw/virtio/virtio-net.h"
24 #include "hw/sysbus.h"
25 #include "qemu/bitops.h"
26 #include "qemu/error-report.h"
27 #include "hw/virtio/virtio-access.h"
28 #include "hw/virtio/virtio-bus.h"
29 #include "hw/s390x/adapter.h"
30 #include "hw/s390x/s390_flic.h"
31 
32 #include "hw/s390x/ioinst.h"
33 #include "hw/s390x/css.h"
34 #include "virtio-ccw.h"
35 #include "trace.h"
36 #include "hw/s390x/css-bridge.h"
37 #include "hw/s390x/s390-virtio-ccw.h"
38 
39 #define NR_CLASSIC_INDICATOR_BITS 64
40 
41 static int virtio_ccw_dev_post_load(void *opaque, int version_id)
42 {
43     VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(opaque);
44     CcwDevice *ccw_dev = CCW_DEVICE(dev);
45     CCWDeviceClass *ck = CCW_DEVICE_GET_CLASS(ccw_dev);
46 
47     ccw_dev->sch->driver_data = dev;
48     if (ccw_dev->sch->thinint_active) {
49         dev->routes.adapter.adapter_id = css_get_adapter_id(
50                                          CSS_IO_ADAPTER_VIRTIO,
51                                          dev->thinint_isc);
52     }
53     /* Re-fill subch_id after loading the subchannel states.*/
54     if (ck->refill_ids) {
55         ck->refill_ids(ccw_dev);
56     }
57     return 0;
58 }
59 
60 typedef struct VirtioCcwDeviceTmp {
61     VirtioCcwDevice *parent;
62     uint16_t config_vector;
63 } VirtioCcwDeviceTmp;
64 
65 static int virtio_ccw_dev_tmp_pre_save(void *opaque)
66 {
67     VirtioCcwDeviceTmp *tmp = opaque;
68     VirtioCcwDevice *dev = tmp->parent;
69     VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
70 
71     tmp->config_vector = vdev->config_vector;
72 
73     return 0;
74 }
75 
76 static int virtio_ccw_dev_tmp_post_load(void *opaque, int version_id)
77 {
78     VirtioCcwDeviceTmp *tmp = opaque;
79     VirtioCcwDevice *dev = tmp->parent;
80     VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
81 
82     vdev->config_vector = tmp->config_vector;
83     return 0;
84 }
85 
86 const VMStateDescription vmstate_virtio_ccw_dev_tmp = {
87     .name = "s390_virtio_ccw_dev_tmp",
88     .pre_save = virtio_ccw_dev_tmp_pre_save,
89     .post_load = virtio_ccw_dev_tmp_post_load,
90     .fields = (VMStateField[]) {
91         VMSTATE_UINT16(config_vector, VirtioCcwDeviceTmp),
92         VMSTATE_END_OF_LIST()
93     }
94 };
95 
96 const VMStateDescription vmstate_virtio_ccw_dev = {
97     .name = "s390_virtio_ccw_dev",
98     .version_id = 1,
99     .minimum_version_id = 1,
100     .post_load = virtio_ccw_dev_post_load,
101     .fields = (VMStateField[]) {
102         VMSTATE_CCW_DEVICE(parent_obj, VirtioCcwDevice),
103         VMSTATE_PTR_TO_IND_ADDR(indicators, VirtioCcwDevice),
104         VMSTATE_PTR_TO_IND_ADDR(indicators2, VirtioCcwDevice),
105         VMSTATE_PTR_TO_IND_ADDR(summary_indicator, VirtioCcwDevice),
106         /*
107          * Ugly hack because VirtIODevice does not migrate itself.
108          * This also makes legacy via vmstate_save_state possible.
109          */
110         VMSTATE_WITH_TMP(VirtioCcwDevice, VirtioCcwDeviceTmp,
111                          vmstate_virtio_ccw_dev_tmp),
112         VMSTATE_STRUCT(routes, VirtioCcwDevice, 1, vmstate_adapter_routes,
113                        AdapterRoutes),
114         VMSTATE_UINT8(thinint_isc, VirtioCcwDevice),
115         VMSTATE_INT32(revision, VirtioCcwDevice),
116         VMSTATE_END_OF_LIST()
117     }
118 };
119 
120 static void virtio_ccw_bus_new(VirtioBusState *bus, size_t bus_size,
121                                VirtioCcwDevice *dev);
122 
123 VirtIODevice *virtio_ccw_get_vdev(SubchDev *sch)
124 {
125     VirtIODevice *vdev = NULL;
126     VirtioCcwDevice *dev = sch->driver_data;
127 
128     if (dev) {
129         vdev = virtio_bus_get_device(&dev->bus);
130     }
131     return vdev;
132 }
133 
134 static void virtio_ccw_start_ioeventfd(VirtioCcwDevice *dev)
135 {
136     virtio_bus_start_ioeventfd(&dev->bus);
137 }
138 
139 static void virtio_ccw_stop_ioeventfd(VirtioCcwDevice *dev)
140 {
141     virtio_bus_stop_ioeventfd(&dev->bus);
142 }
143 
144 static bool virtio_ccw_ioeventfd_enabled(DeviceState *d)
145 {
146     VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
147 
148     return (dev->flags & VIRTIO_CCW_FLAG_USE_IOEVENTFD) != 0;
149 }
150 
151 static int virtio_ccw_ioeventfd_assign(DeviceState *d, EventNotifier *notifier,
152                                        int n, bool assign)
153 {
154     VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
155     CcwDevice *ccw_dev = CCW_DEVICE(dev);
156     SubchDev *sch = ccw_dev->sch;
157     uint32_t sch_id = (css_build_subchannel_id(sch) << 16) | sch->schid;
158 
159     return s390_assign_subch_ioeventfd(notifier, sch_id, n, assign);
160 }
161 
162 /* Communication blocks used by several channel commands. */
163 typedef struct VqInfoBlockLegacy {
164     uint64_t queue;
165     uint32_t align;
166     uint16_t index;
167     uint16_t num;
168 } QEMU_PACKED VqInfoBlockLegacy;
169 
170 typedef struct VqInfoBlock {
171     uint64_t desc;
172     uint32_t res0;
173     uint16_t index;
174     uint16_t num;
175     uint64_t avail;
176     uint64_t used;
177 } QEMU_PACKED VqInfoBlock;
178 
179 typedef struct VqConfigBlock {
180     uint16_t index;
181     uint16_t num_max;
182 } QEMU_PACKED VqConfigBlock;
183 
184 typedef struct VirtioFeatDesc {
185     uint32_t features;
186     uint8_t index;
187 } QEMU_PACKED VirtioFeatDesc;
188 
189 typedef struct VirtioThinintInfo {
190     hwaddr summary_indicator;
191     hwaddr device_indicator;
192     uint64_t ind_bit;
193     uint8_t isc;
194 } QEMU_PACKED VirtioThinintInfo;
195 
196 typedef struct VirtioRevInfo {
197     uint16_t revision;
198     uint16_t length;
199     uint8_t data[0];
200 } QEMU_PACKED VirtioRevInfo;
201 
202 /* Specify where the virtqueues for the subchannel are in guest memory. */
203 static int virtio_ccw_set_vqs(SubchDev *sch, VqInfoBlock *info,
204                               VqInfoBlockLegacy *linfo)
205 {
206     VirtIODevice *vdev = virtio_ccw_get_vdev(sch);
207     uint16_t index = info ? info->index : linfo->index;
208     uint16_t num = info ? info->num : linfo->num;
209     uint64_t desc = info ? info->desc : linfo->queue;
210 
211     if (index >= VIRTIO_QUEUE_MAX) {
212         return -EINVAL;
213     }
214 
215     /* Current code in virtio.c relies on 4K alignment. */
216     if (linfo && desc && (linfo->align != 4096)) {
217         return -EINVAL;
218     }
219 
220     if (!vdev) {
221         return -EINVAL;
222     }
223 
224     if (info) {
225         virtio_queue_set_rings(vdev, index, desc, info->avail, info->used);
226     } else {
227         virtio_queue_set_addr(vdev, index, desc);
228     }
229     if (!desc) {
230         virtio_queue_set_vector(vdev, index, VIRTIO_NO_VECTOR);
231     } else {
232         if (info) {
233             /* virtio-1 allows changing the ring size. */
234             if (virtio_queue_get_max_num(vdev, index) < num) {
235                 /* Fail if we exceed the maximum number. */
236                 return -EINVAL;
237             }
238             virtio_queue_set_num(vdev, index, num);
239         } else if (virtio_queue_get_num(vdev, index) > num) {
240             /* Fail if we don't have a big enough queue. */
241             return -EINVAL;
242         }
243         /* We ignore possible increased num for legacy for compatibility. */
244         virtio_queue_set_vector(vdev, index, index);
245     }
246     /* tell notify handler in case of config change */
247     vdev->config_vector = VIRTIO_QUEUE_MAX;
248     return 0;
249 }
250 
251 static void virtio_ccw_reset_virtio(VirtioCcwDevice *dev, VirtIODevice *vdev)
252 {
253     CcwDevice *ccw_dev = CCW_DEVICE(dev);
254 
255     virtio_ccw_stop_ioeventfd(dev);
256     virtio_reset(vdev);
257     if (dev->indicators) {
258         release_indicator(&dev->routes.adapter, dev->indicators);
259         dev->indicators = NULL;
260     }
261     if (dev->indicators2) {
262         release_indicator(&dev->routes.adapter, dev->indicators2);
263         dev->indicators2 = NULL;
264     }
265     if (dev->summary_indicator) {
266         release_indicator(&dev->routes.adapter, dev->summary_indicator);
267         dev->summary_indicator = NULL;
268     }
269     ccw_dev->sch->thinint_active = false;
270 }
271 
272 static int virtio_ccw_handle_set_vq(SubchDev *sch, CCW1 ccw, bool check_len,
273                                     bool is_legacy)
274 {
275     int ret;
276     VqInfoBlock info;
277     VqInfoBlockLegacy linfo;
278     size_t info_len = is_legacy ? sizeof(linfo) : sizeof(info);
279 
280     if (check_len) {
281         if (ccw.count != info_len) {
282             return -EINVAL;
283         }
284     } else if (ccw.count < info_len) {
285         /* Can't execute command. */
286         return -EINVAL;
287     }
288     if (!ccw.cda) {
289         return -EFAULT;
290     }
291     if (is_legacy) {
292         ccw_dstream_read(&sch->cds, linfo);
293         be64_to_cpus(&linfo.queue);
294         be32_to_cpus(&linfo.align);
295         be16_to_cpus(&linfo.index);
296         be16_to_cpus(&linfo.num);
297         ret = virtio_ccw_set_vqs(sch, NULL, &linfo);
298     } else {
299         ccw_dstream_read(&sch->cds, info);
300         be64_to_cpus(&info.desc);
301         be16_to_cpus(&info.index);
302         be16_to_cpus(&info.num);
303         be64_to_cpus(&info.avail);
304         be64_to_cpus(&info.used);
305         ret = virtio_ccw_set_vqs(sch, &info, NULL);
306     }
307     sch->curr_status.scsw.count = 0;
308     return ret;
309 }
310 
311 static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
312 {
313     int ret;
314     VirtioRevInfo revinfo;
315     uint8_t status;
316     VirtioFeatDesc features;
317     hwaddr indicators;
318     VqConfigBlock vq_config;
319     VirtioCcwDevice *dev = sch->driver_data;
320     VirtIODevice *vdev = virtio_ccw_get_vdev(sch);
321     bool check_len;
322     int len;
323     VirtioThinintInfo thinint;
324 
325     if (!dev) {
326         return -EINVAL;
327     }
328 
329     trace_virtio_ccw_interpret_ccw(sch->cssid, sch->ssid, sch->schid,
330                                    ccw.cmd_code);
331     check_len = !((ccw.flags & CCW_FLAG_SLI) && !(ccw.flags & CCW_FLAG_DC));
332 
333     if (dev->force_revision_1 && dev->revision < 0 &&
334         ccw.cmd_code != CCW_CMD_SET_VIRTIO_REV) {
335         /*
336          * virtio-1 drivers must start with negotiating to a revision >= 1,
337          * so post a command reject for all other commands
338          */
339         return -ENOSYS;
340     }
341 
342     /* Look at the command. */
343     switch (ccw.cmd_code) {
344     case CCW_CMD_SET_VQ:
345         ret = virtio_ccw_handle_set_vq(sch, ccw, check_len, dev->revision < 1);
346         break;
347     case CCW_CMD_VDEV_RESET:
348         virtio_ccw_reset_virtio(dev, vdev);
349         ret = 0;
350         break;
351     case CCW_CMD_READ_FEAT:
352         if (check_len) {
353             if (ccw.count != sizeof(features)) {
354                 ret = -EINVAL;
355                 break;
356             }
357         } else if (ccw.count < sizeof(features)) {
358             /* Can't execute command. */
359             ret = -EINVAL;
360             break;
361         }
362         if (!ccw.cda) {
363             ret = -EFAULT;
364         } else {
365             VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
366 
367             ccw_dstream_advance(&sch->cds, sizeof(features.features));
368             ccw_dstream_read(&sch->cds, features.index);
369             if (features.index == 0) {
370                 if (dev->revision >= 1) {
371                     /* Don't offer legacy features for modern devices. */
372                     features.features = (uint32_t)
373                         (vdev->host_features & ~vdc->legacy_features);
374                 } else {
375                     features.features = (uint32_t)vdev->host_features;
376                 }
377             } else if ((features.index == 1) && (dev->revision >= 1)) {
378                 /*
379                  * Only offer feature bits beyond 31 if the guest has
380                  * negotiated at least revision 1.
381                  */
382                 features.features = (uint32_t)(vdev->host_features >> 32);
383             } else {
384                 /* Return zeroes if the guest supports more feature bits. */
385                 features.features = 0;
386             }
387             ccw_dstream_rewind(&sch->cds);
388             cpu_to_le32s(&features.features);
389             ccw_dstream_write(&sch->cds, features.features);
390             sch->curr_status.scsw.count = ccw.count - sizeof(features);
391             ret = 0;
392         }
393         break;
394     case CCW_CMD_WRITE_FEAT:
395         if (check_len) {
396             if (ccw.count != sizeof(features)) {
397                 ret = -EINVAL;
398                 break;
399             }
400         } else if (ccw.count < sizeof(features)) {
401             /* Can't execute command. */
402             ret = -EINVAL;
403             break;
404         }
405         if (!ccw.cda) {
406             ret = -EFAULT;
407         } else {
408             ccw_dstream_read(&sch->cds, features);
409             le32_to_cpus(&features.features);
410             if (features.index == 0) {
411                 virtio_set_features(vdev,
412                                     (vdev->guest_features & 0xffffffff00000000ULL) |
413                                     features.features);
414             } else if ((features.index == 1) && (dev->revision >= 1)) {
415                 /*
416                  * If the guest did not negotiate at least revision 1,
417                  * we did not offer it any feature bits beyond 31. Such a
418                  * guest passing us any bit here is therefore buggy.
419                  */
420                 virtio_set_features(vdev,
421                                     (vdev->guest_features & 0x00000000ffffffffULL) |
422                                     ((uint64_t)features.features << 32));
423             } else {
424                 /*
425                  * If the guest supports more feature bits, assert that it
426                  * passes us zeroes for those we don't support.
427                  */
428                 if (features.features) {
429                     fprintf(stderr, "Guest bug: features[%i]=%x (expected 0)\n",
430                             features.index, features.features);
431                     /* XXX: do a unit check here? */
432                 }
433             }
434             sch->curr_status.scsw.count = ccw.count - sizeof(features);
435             ret = 0;
436         }
437         break;
438     case CCW_CMD_READ_CONF:
439         if (check_len) {
440             if (ccw.count > vdev->config_len) {
441                 ret = -EINVAL;
442                 break;
443             }
444         }
445         len = MIN(ccw.count, vdev->config_len);
446         if (!ccw.cda) {
447             ret = -EFAULT;
448         } else {
449             virtio_bus_get_vdev_config(&dev->bus, vdev->config);
450             ccw_dstream_write_buf(&sch->cds, vdev->config, len);
451             sch->curr_status.scsw.count = ccw.count - len;
452             ret = 0;
453         }
454         break;
455     case CCW_CMD_WRITE_CONF:
456         if (check_len) {
457             if (ccw.count > vdev->config_len) {
458                 ret = -EINVAL;
459                 break;
460             }
461         }
462         len = MIN(ccw.count, vdev->config_len);
463         if (!ccw.cda) {
464             ret = -EFAULT;
465         } else {
466             ret = ccw_dstream_read_buf(&sch->cds, vdev->config, len);
467             if (!ret) {
468                 virtio_bus_set_vdev_config(&dev->bus, vdev->config);
469                 sch->curr_status.scsw.count = ccw.count - len;
470             }
471         }
472         break;
473     case CCW_CMD_READ_STATUS:
474         if (check_len) {
475             if (ccw.count != sizeof(status)) {
476                 ret = -EINVAL;
477                 break;
478             }
479         } else if (ccw.count < sizeof(status)) {
480             /* Can't execute command. */
481             ret = -EINVAL;
482             break;
483         }
484         if (!ccw.cda) {
485             ret = -EFAULT;
486         } else {
487             address_space_stb(&address_space_memory, ccw.cda, vdev->status,
488                                         MEMTXATTRS_UNSPECIFIED, NULL);
489             sch->curr_status.scsw.count = ccw.count - sizeof(vdev->status);;
490             ret = 0;
491         }
492         break;
493     case CCW_CMD_WRITE_STATUS:
494         if (check_len) {
495             if (ccw.count != sizeof(status)) {
496                 ret = -EINVAL;
497                 break;
498             }
499         } else if (ccw.count < sizeof(status)) {
500             /* Can't execute command. */
501             ret = -EINVAL;
502             break;
503         }
504         if (!ccw.cda) {
505             ret = -EFAULT;
506         } else {
507             ccw_dstream_read(&sch->cds, status);
508             if (!(status & VIRTIO_CONFIG_S_DRIVER_OK)) {
509                 virtio_ccw_stop_ioeventfd(dev);
510             }
511             if (virtio_set_status(vdev, status) == 0) {
512                 if (vdev->status == 0) {
513                     virtio_ccw_reset_virtio(dev, vdev);
514                 }
515                 if (status & VIRTIO_CONFIG_S_DRIVER_OK) {
516                     virtio_ccw_start_ioeventfd(dev);
517                 }
518                 sch->curr_status.scsw.count = ccw.count - sizeof(status);
519                 ret = 0;
520             } else {
521                 /* Trigger a command reject. */
522                 ret = -ENOSYS;
523             }
524         }
525         break;
526     case CCW_CMD_SET_IND:
527         if (check_len) {
528             if (ccw.count != sizeof(indicators)) {
529                 ret = -EINVAL;
530                 break;
531             }
532         } else if (ccw.count < sizeof(indicators)) {
533             /* Can't execute command. */
534             ret = -EINVAL;
535             break;
536         }
537         if (sch->thinint_active) {
538             /* Trigger a command reject. */
539             ret = -ENOSYS;
540             break;
541         }
542         if (virtio_get_num_queues(vdev) > NR_CLASSIC_INDICATOR_BITS) {
543             /* More queues than indicator bits --> trigger a reject */
544             ret = -ENOSYS;
545             break;
546         }
547         if (!ccw.cda) {
548             ret = -EFAULT;
549         } else {
550             ccw_dstream_read(&sch->cds, indicators);
551             be64_to_cpus(&indicators);
552             dev->indicators = get_indicator(indicators, sizeof(uint64_t));
553             sch->curr_status.scsw.count = ccw.count - sizeof(indicators);
554             ret = 0;
555         }
556         break;
557     case CCW_CMD_SET_CONF_IND:
558         if (check_len) {
559             if (ccw.count != sizeof(indicators)) {
560                 ret = -EINVAL;
561                 break;
562             }
563         } else if (ccw.count < sizeof(indicators)) {
564             /* Can't execute command. */
565             ret = -EINVAL;
566             break;
567         }
568         if (!ccw.cda) {
569             ret = -EFAULT;
570         } else {
571             ccw_dstream_read(&sch->cds, indicators);
572             be64_to_cpus(&indicators);
573             dev->indicators2 = get_indicator(indicators, sizeof(uint64_t));
574             sch->curr_status.scsw.count = ccw.count - sizeof(indicators);
575             ret = 0;
576         }
577         break;
578     case CCW_CMD_READ_VQ_CONF:
579         if (check_len) {
580             if (ccw.count != sizeof(vq_config)) {
581                 ret = -EINVAL;
582                 break;
583             }
584         } else if (ccw.count < sizeof(vq_config)) {
585             /* Can't execute command. */
586             ret = -EINVAL;
587             break;
588         }
589         if (!ccw.cda) {
590             ret = -EFAULT;
591         } else {
592             ccw_dstream_read(&sch->cds, vq_config.index);
593             be16_to_cpus(&vq_config.index);
594             if (vq_config.index >= VIRTIO_QUEUE_MAX) {
595                 ret = -EINVAL;
596                 break;
597             }
598             vq_config.num_max = virtio_queue_get_num(vdev,
599                                                      vq_config.index);
600             cpu_to_be16s(&vq_config.num_max);
601             ccw_dstream_write(&sch->cds, vq_config.num_max);
602             sch->curr_status.scsw.count = ccw.count - sizeof(vq_config);
603             ret = 0;
604         }
605         break;
606     case CCW_CMD_SET_IND_ADAPTER:
607         if (check_len) {
608             if (ccw.count != sizeof(thinint)) {
609                 ret = -EINVAL;
610                 break;
611             }
612         } else if (ccw.count < sizeof(thinint)) {
613             /* Can't execute command. */
614             ret = -EINVAL;
615             break;
616         }
617         if (!ccw.cda) {
618             ret = -EFAULT;
619         } else if (dev->indicators && !sch->thinint_active) {
620             /* Trigger a command reject. */
621             ret = -ENOSYS;
622         } else {
623             if (ccw_dstream_read(&sch->cds, thinint)) {
624                 ret = -EFAULT;
625             } else {
626                 be64_to_cpus(&thinint.ind_bit);
627                 be64_to_cpus(&thinint.summary_indicator);
628                 be64_to_cpus(&thinint.device_indicator);
629 
630                 dev->summary_indicator =
631                     get_indicator(thinint.summary_indicator, sizeof(uint8_t));
632                 dev->indicators =
633                     get_indicator(thinint.device_indicator,
634                                   thinint.ind_bit / 8 + 1);
635                 dev->thinint_isc = thinint.isc;
636                 dev->routes.adapter.ind_offset = thinint.ind_bit;
637                 dev->routes.adapter.summary_offset = 7;
638                 dev->routes.adapter.adapter_id = css_get_adapter_id(
639                                                  CSS_IO_ADAPTER_VIRTIO,
640                                                  dev->thinint_isc);
641                 sch->thinint_active = ((dev->indicators != NULL) &&
642                                        (dev->summary_indicator != NULL));
643                 sch->curr_status.scsw.count = ccw.count - sizeof(thinint);
644                 ret = 0;
645             }
646         }
647         break;
648     case CCW_CMD_SET_VIRTIO_REV:
649         len = sizeof(revinfo);
650         if (ccw.count < len) {
651             ret = -EINVAL;
652             break;
653         }
654         if (!ccw.cda) {
655             ret = -EFAULT;
656             break;
657         }
658         ccw_dstream_read_buf(&sch->cds, &revinfo, 4);
659         be16_to_cpus(&revinfo.revision);
660         be16_to_cpus(&revinfo.length);
661         if (ccw.count < len + revinfo.length ||
662             (check_len && ccw.count > len + revinfo.length)) {
663             ret = -EINVAL;
664             break;
665         }
666         /*
667          * Once we start to support revisions with additional data, we'll
668          * need to fetch it here. Nothing to do for now, though.
669          */
670         if (dev->revision >= 0 ||
671             revinfo.revision > virtio_ccw_rev_max(dev) ||
672             (dev->force_revision_1 && !revinfo.revision)) {
673             ret = -ENOSYS;
674             break;
675         }
676         ret = 0;
677         dev->revision = revinfo.revision;
678         break;
679     default:
680         ret = -ENOSYS;
681         break;
682     }
683     return ret;
684 }
685 
686 static void virtio_sch_disable_cb(SubchDev *sch)
687 {
688     VirtioCcwDevice *dev = sch->driver_data;
689 
690     dev->revision = -1;
691 }
692 
693 static void virtio_ccw_device_realize(VirtioCcwDevice *dev, Error **errp)
694 {
695     VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_GET_CLASS(dev);
696     CcwDevice *ccw_dev = CCW_DEVICE(dev);
697     CCWDeviceClass *ck = CCW_DEVICE_GET_CLASS(ccw_dev);
698     DeviceState *parent = DEVICE(ccw_dev);
699     BusState *qbus = qdev_get_parent_bus(parent);
700     VirtualCssBus *cbus = VIRTUAL_CSS_BUS(qbus);
701     SubchDev *sch;
702     Error *err = NULL;
703 
704     sch = css_create_sch(ccw_dev->devno, true, cbus->squash_mcss, errp);
705     if (!sch) {
706         return;
707     }
708     if (!virtio_ccw_rev_max(dev) && dev->force_revision_1) {
709         error_setg(&err, "Invalid value of property max_rev "
710                    "(is %d expected >= 1)", virtio_ccw_rev_max(dev));
711         goto out_err;
712     }
713 
714     sch->driver_data = dev;
715     sch->ccw_cb = virtio_ccw_cb;
716     sch->disable_cb = virtio_sch_disable_cb;
717     sch->id.reserved = 0xff;
718     sch->id.cu_type = VIRTIO_CCW_CU_TYPE;
719     sch->do_subchannel_work = do_subchannel_work_virtual;
720     ccw_dev->sch = sch;
721     dev->indicators = NULL;
722     dev->revision = -1;
723     css_sch_build_virtual_schib(sch, 0, VIRTIO_CCW_CHPID_TYPE);
724 
725     trace_virtio_ccw_new_device(
726         sch->cssid, sch->ssid, sch->schid, sch->devno,
727         ccw_dev->devno.valid ? "user-configured" : "auto-configured");
728 
729     if (kvm_enabled() && !kvm_eventfds_enabled()) {
730         dev->flags &= ~VIRTIO_CCW_FLAG_USE_IOEVENTFD;
731     }
732 
733     if (k->realize) {
734         k->realize(dev, &err);
735         if (err) {
736             goto out_err;
737         }
738     }
739 
740     ck->realize(ccw_dev, &err);
741     if (err) {
742         goto out_err;
743     }
744 
745     return;
746 
747 out_err:
748     error_propagate(errp, err);
749     css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, NULL);
750     ccw_dev->sch = NULL;
751     g_free(sch);
752 }
753 
754 static int virtio_ccw_exit(VirtioCcwDevice *dev)
755 {
756     CcwDevice *ccw_dev = CCW_DEVICE(dev);
757     SubchDev *sch = ccw_dev->sch;
758 
759     if (sch) {
760         css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, NULL);
761         g_free(sch);
762     }
763     if (dev->indicators) {
764         release_indicator(&dev->routes.adapter, dev->indicators);
765         dev->indicators = NULL;
766     }
767     return 0;
768 }
769 
770 static void virtio_ccw_net_realize(VirtioCcwDevice *ccw_dev, Error **errp)
771 {
772     DeviceState *qdev = DEVICE(ccw_dev);
773     VirtIONetCcw *dev = VIRTIO_NET_CCW(ccw_dev);
774     DeviceState *vdev = DEVICE(&dev->vdev);
775 
776     virtio_net_set_netclient_name(&dev->vdev, qdev->id,
777                                   object_get_typename(OBJECT(qdev)));
778     qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
779     object_property_set_bool(OBJECT(vdev), true, "realized", errp);
780 }
781 
782 static void virtio_ccw_net_instance_init(Object *obj)
783 {
784     VirtIONetCcw *dev = VIRTIO_NET_CCW(obj);
785 
786     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
787                                 TYPE_VIRTIO_NET);
788     object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev),
789                               "bootindex", &error_abort);
790 }
791 
792 static void virtio_ccw_blk_realize(VirtioCcwDevice *ccw_dev, Error **errp)
793 {
794     VirtIOBlkCcw *dev = VIRTIO_BLK_CCW(ccw_dev);
795     DeviceState *vdev = DEVICE(&dev->vdev);
796 
797     qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
798     object_property_set_bool(OBJECT(vdev), true, "realized", errp);
799 }
800 
801 static void virtio_ccw_blk_instance_init(Object *obj)
802 {
803     VirtIOBlkCcw *dev = VIRTIO_BLK_CCW(obj);
804 
805     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
806                                 TYPE_VIRTIO_BLK);
807     object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev),
808                               "bootindex", &error_abort);
809 }
810 
811 static void virtio_ccw_serial_realize(VirtioCcwDevice *ccw_dev, Error **errp)
812 {
813     VirtioSerialCcw *dev = VIRTIO_SERIAL_CCW(ccw_dev);
814     DeviceState *vdev = DEVICE(&dev->vdev);
815     DeviceState *proxy = DEVICE(ccw_dev);
816     char *bus_name;
817 
818     /*
819      * For command line compatibility, this sets the virtio-serial-device bus
820      * name as before.
821      */
822     if (proxy->id) {
823         bus_name = g_strdup_printf("%s.0", proxy->id);
824         virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name);
825         g_free(bus_name);
826     }
827 
828     qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
829     object_property_set_bool(OBJECT(vdev), true, "realized", errp);
830 }
831 
832 
833 static void virtio_ccw_serial_instance_init(Object *obj)
834 {
835     VirtioSerialCcw *dev = VIRTIO_SERIAL_CCW(obj);
836 
837     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
838                                 TYPE_VIRTIO_SERIAL);
839 }
840 
841 static void virtio_ccw_balloon_realize(VirtioCcwDevice *ccw_dev, Error **errp)
842 {
843     VirtIOBalloonCcw *dev = VIRTIO_BALLOON_CCW(ccw_dev);
844     DeviceState *vdev = DEVICE(&dev->vdev);
845 
846     qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
847     object_property_set_bool(OBJECT(vdev), true, "realized", errp);
848 }
849 
850 static void virtio_ccw_balloon_instance_init(Object *obj)
851 {
852     VirtIOBalloonCcw *dev = VIRTIO_BALLOON_CCW(obj);
853 
854     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
855                                 TYPE_VIRTIO_BALLOON);
856     object_property_add_alias(obj, "guest-stats", OBJECT(&dev->vdev),
857                               "guest-stats", &error_abort);
858     object_property_add_alias(obj, "guest-stats-polling-interval",
859                               OBJECT(&dev->vdev),
860                               "guest-stats-polling-interval", &error_abort);
861 }
862 
863 static void virtio_ccw_scsi_realize(VirtioCcwDevice *ccw_dev, Error **errp)
864 {
865     VirtIOSCSICcw *dev = VIRTIO_SCSI_CCW(ccw_dev);
866     DeviceState *vdev = DEVICE(&dev->vdev);
867     DeviceState *qdev = DEVICE(ccw_dev);
868     char *bus_name;
869 
870     /*
871      * For command line compatibility, this sets the virtio-scsi-device bus
872      * name as before.
873      */
874     if (qdev->id) {
875         bus_name = g_strdup_printf("%s.0", qdev->id);
876         virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name);
877         g_free(bus_name);
878     }
879 
880     qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
881     object_property_set_bool(OBJECT(vdev), true, "realized", errp);
882 }
883 
884 static void virtio_ccw_scsi_instance_init(Object *obj)
885 {
886     VirtIOSCSICcw *dev = VIRTIO_SCSI_CCW(obj);
887 
888     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
889                                 TYPE_VIRTIO_SCSI);
890 }
891 
892 #ifdef CONFIG_VHOST_SCSI
893 static void vhost_ccw_scsi_realize(VirtioCcwDevice *ccw_dev, Error **errp)
894 {
895     VHostSCSICcw *dev = VHOST_SCSI_CCW(ccw_dev);
896     DeviceState *vdev = DEVICE(&dev->vdev);
897 
898     qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
899     object_property_set_bool(OBJECT(vdev), true, "realized", errp);
900 }
901 
902 static void vhost_ccw_scsi_instance_init(Object *obj)
903 {
904     VHostSCSICcw *dev = VHOST_SCSI_CCW(obj);
905 
906     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
907                                 TYPE_VHOST_SCSI);
908 }
909 #endif
910 
911 static void virtio_ccw_rng_realize(VirtioCcwDevice *ccw_dev, Error **errp)
912 {
913     VirtIORNGCcw *dev = VIRTIO_RNG_CCW(ccw_dev);
914     DeviceState *vdev = DEVICE(&dev->vdev);
915     Error *err = NULL;
916 
917     qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
918     object_property_set_bool(OBJECT(vdev), true, "realized", &err);
919     if (err) {
920         error_propagate(errp, err);
921         return;
922     }
923 
924     object_property_set_link(OBJECT(dev),
925                              OBJECT(dev->vdev.conf.rng), "rng",
926                              NULL);
927 }
928 
929 static void virtio_ccw_crypto_realize(VirtioCcwDevice *ccw_dev, Error **errp)
930 {
931     VirtIOCryptoCcw *dev = VIRTIO_CRYPTO_CCW(ccw_dev);
932     DeviceState *vdev = DEVICE(&dev->vdev);
933     Error *err = NULL;
934 
935     qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
936     object_property_set_bool(OBJECT(vdev), true, "realized", &err);
937     if (err) {
938         error_propagate(errp, err);
939         return;
940     }
941 
942     object_property_set_link(OBJECT(vdev),
943                              OBJECT(dev->vdev.conf.cryptodev), "cryptodev",
944                              NULL);
945 }
946 
947 static void virtio_ccw_gpu_realize(VirtioCcwDevice *ccw_dev, Error **errp)
948 {
949     VirtIOGPUCcw *dev = VIRTIO_GPU_CCW(ccw_dev);
950     DeviceState *vdev = DEVICE(&dev->vdev);
951 
952     qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
953     object_property_set_bool(OBJECT(vdev), true, "realized", errp);
954 }
955 
956 /* DeviceState to VirtioCcwDevice. Note: used on datapath,
957  * be careful and test performance if you change this.
958  */
959 static inline VirtioCcwDevice *to_virtio_ccw_dev_fast(DeviceState *d)
960 {
961     CcwDevice *ccw_dev = to_ccw_dev_fast(d);
962 
963     return container_of(ccw_dev, VirtioCcwDevice, parent_obj);
964 }
965 
966 static uint8_t virtio_set_ind_atomic(SubchDev *sch, uint64_t ind_loc,
967                                      uint8_t to_be_set)
968 {
969     uint8_t ind_old, ind_new;
970     hwaddr len = 1;
971     uint8_t *ind_addr;
972 
973     ind_addr = cpu_physical_memory_map(ind_loc, &len, 1);
974     if (!ind_addr) {
975         error_report("%s(%x.%x.%04x): unable to access indicator",
976                      __func__, sch->cssid, sch->ssid, sch->schid);
977         return -1;
978     }
979     do {
980         ind_old = *ind_addr;
981         ind_new = ind_old | to_be_set;
982     } while (atomic_cmpxchg(ind_addr, ind_old, ind_new) != ind_old);
983     trace_virtio_ccw_set_ind(ind_loc, ind_old, ind_new);
984     cpu_physical_memory_unmap(ind_addr, len, 1, len);
985 
986     return ind_old;
987 }
988 
989 static void virtio_ccw_notify(DeviceState *d, uint16_t vector)
990 {
991     VirtioCcwDevice *dev = to_virtio_ccw_dev_fast(d);
992     CcwDevice *ccw_dev = to_ccw_dev_fast(d);
993     SubchDev *sch = ccw_dev->sch;
994     uint64_t indicators;
995 
996     /* queue indicators + secondary indicators */
997     if (vector >= VIRTIO_QUEUE_MAX + 64) {
998         return;
999     }
1000 
1001     if (vector < VIRTIO_QUEUE_MAX) {
1002         if (!dev->indicators) {
1003             return;
1004         }
1005         if (sch->thinint_active) {
1006             /*
1007              * In the adapter interrupt case, indicators points to a
1008              * memory area that may be (way) larger than 64 bit and
1009              * ind_bit indicates the start of the indicators in a big
1010              * endian notation.
1011              */
1012             uint64_t ind_bit = dev->routes.adapter.ind_offset;
1013 
1014             virtio_set_ind_atomic(sch, dev->indicators->addr +
1015                                   (ind_bit + vector) / 8,
1016                                   0x80 >> ((ind_bit + vector) % 8));
1017             if (!virtio_set_ind_atomic(sch, dev->summary_indicator->addr,
1018                                        0x01)) {
1019                 css_adapter_interrupt(CSS_IO_ADAPTER_VIRTIO, dev->thinint_isc);
1020             }
1021         } else {
1022             indicators = address_space_ldq(&address_space_memory,
1023                                            dev->indicators->addr,
1024                                            MEMTXATTRS_UNSPECIFIED,
1025                                            NULL);
1026             indicators |= 1ULL << vector;
1027             address_space_stq(&address_space_memory, dev->indicators->addr,
1028                               indicators, MEMTXATTRS_UNSPECIFIED, NULL);
1029             css_conditional_io_interrupt(sch);
1030         }
1031     } else {
1032         if (!dev->indicators2) {
1033             return;
1034         }
1035         vector = 0;
1036         indicators = address_space_ldq(&address_space_memory,
1037                                        dev->indicators2->addr,
1038                                        MEMTXATTRS_UNSPECIFIED,
1039                                        NULL);
1040         indicators |= 1ULL << vector;
1041         address_space_stq(&address_space_memory, dev->indicators2->addr,
1042                           indicators, MEMTXATTRS_UNSPECIFIED, NULL);
1043         css_conditional_io_interrupt(sch);
1044     }
1045 }
1046 
1047 static void virtio_ccw_reset(DeviceState *d)
1048 {
1049     VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
1050     VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
1051     CcwDevice *ccw_dev = CCW_DEVICE(d);
1052 
1053     virtio_ccw_reset_virtio(dev, vdev);
1054     css_reset_sch(ccw_dev->sch);
1055 }
1056 
1057 static void virtio_ccw_vmstate_change(DeviceState *d, bool running)
1058 {
1059     VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
1060 
1061     if (running) {
1062         virtio_ccw_start_ioeventfd(dev);
1063     } else {
1064         virtio_ccw_stop_ioeventfd(dev);
1065     }
1066 }
1067 
1068 static bool virtio_ccw_query_guest_notifiers(DeviceState *d)
1069 {
1070     CcwDevice *dev = CCW_DEVICE(d);
1071 
1072     return !!(dev->sch->curr_status.pmcw.flags & PMCW_FLAGS_MASK_ENA);
1073 }
1074 
1075 static int virtio_ccw_get_mappings(VirtioCcwDevice *dev)
1076 {
1077     int r;
1078     CcwDevice *ccw_dev = CCW_DEVICE(dev);
1079 
1080     if (!ccw_dev->sch->thinint_active) {
1081         return -EINVAL;
1082     }
1083 
1084     r = map_indicator(&dev->routes.adapter, dev->summary_indicator);
1085     if (r) {
1086         return r;
1087     }
1088     r = map_indicator(&dev->routes.adapter, dev->indicators);
1089     if (r) {
1090         return r;
1091     }
1092     dev->routes.adapter.summary_addr = dev->summary_indicator->map;
1093     dev->routes.adapter.ind_addr = dev->indicators->map;
1094 
1095     return 0;
1096 }
1097 
1098 static int virtio_ccw_setup_irqroutes(VirtioCcwDevice *dev, int nvqs)
1099 {
1100     int i;
1101     VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
1102     int ret;
1103     S390FLICState *fs = s390_get_flic();
1104     S390FLICStateClass *fsc = S390_FLIC_COMMON_GET_CLASS(fs);
1105 
1106     ret = virtio_ccw_get_mappings(dev);
1107     if (ret) {
1108         return ret;
1109     }
1110     for (i = 0; i < nvqs; i++) {
1111         if (!virtio_queue_get_num(vdev, i)) {
1112             break;
1113         }
1114     }
1115     dev->routes.num_routes = i;
1116     return fsc->add_adapter_routes(fs, &dev->routes);
1117 }
1118 
1119 static void virtio_ccw_release_irqroutes(VirtioCcwDevice *dev, int nvqs)
1120 {
1121     S390FLICState *fs = s390_get_flic();
1122     S390FLICStateClass *fsc = S390_FLIC_COMMON_GET_CLASS(fs);
1123 
1124     fsc->release_adapter_routes(fs, &dev->routes);
1125 }
1126 
1127 static int virtio_ccw_add_irqfd(VirtioCcwDevice *dev, int n)
1128 {
1129     VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
1130     VirtQueue *vq = virtio_get_queue(vdev, n);
1131     EventNotifier *notifier = virtio_queue_get_guest_notifier(vq);
1132 
1133     return kvm_irqchip_add_irqfd_notifier_gsi(kvm_state, notifier, NULL,
1134                                               dev->routes.gsi[n]);
1135 }
1136 
1137 static void virtio_ccw_remove_irqfd(VirtioCcwDevice *dev, int n)
1138 {
1139     VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
1140     VirtQueue *vq = virtio_get_queue(vdev, n);
1141     EventNotifier *notifier = virtio_queue_get_guest_notifier(vq);
1142     int ret;
1143 
1144     ret = kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state, notifier,
1145                                                 dev->routes.gsi[n]);
1146     assert(ret == 0);
1147 }
1148 
1149 static int virtio_ccw_set_guest_notifier(VirtioCcwDevice *dev, int n,
1150                                          bool assign, bool with_irqfd)
1151 {
1152     VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
1153     VirtQueue *vq = virtio_get_queue(vdev, n);
1154     EventNotifier *notifier = virtio_queue_get_guest_notifier(vq);
1155     VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
1156 
1157     if (assign) {
1158         int r = event_notifier_init(notifier, 0);
1159 
1160         if (r < 0) {
1161             return r;
1162         }
1163         virtio_queue_set_guest_notifier_fd_handler(vq, true, with_irqfd);
1164         if (with_irqfd) {
1165             r = virtio_ccw_add_irqfd(dev, n);
1166             if (r) {
1167                 virtio_queue_set_guest_notifier_fd_handler(vq, false,
1168                                                            with_irqfd);
1169                 return r;
1170             }
1171         }
1172         /*
1173          * We do not support individual masking for channel devices, so we
1174          * need to manually trigger any guest masking callbacks here.
1175          */
1176         if (k->guest_notifier_mask && vdev->use_guest_notifier_mask) {
1177             k->guest_notifier_mask(vdev, n, false);
1178         }
1179         /* get lost events and re-inject */
1180         if (k->guest_notifier_pending &&
1181             k->guest_notifier_pending(vdev, n)) {
1182             event_notifier_set(notifier);
1183         }
1184     } else {
1185         if (k->guest_notifier_mask && vdev->use_guest_notifier_mask) {
1186             k->guest_notifier_mask(vdev, n, true);
1187         }
1188         if (with_irqfd) {
1189             virtio_ccw_remove_irqfd(dev, n);
1190         }
1191         virtio_queue_set_guest_notifier_fd_handler(vq, false, with_irqfd);
1192         event_notifier_cleanup(notifier);
1193     }
1194     return 0;
1195 }
1196 
1197 static int virtio_ccw_set_guest_notifiers(DeviceState *d, int nvqs,
1198                                           bool assigned)
1199 {
1200     VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
1201     VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
1202     CcwDevice *ccw_dev = CCW_DEVICE(d);
1203     bool with_irqfd = ccw_dev->sch->thinint_active && kvm_irqfds_enabled();
1204     int r, n;
1205 
1206     if (with_irqfd && assigned) {
1207         /* irq routes need to be set up before assigning irqfds */
1208         r = virtio_ccw_setup_irqroutes(dev, nvqs);
1209         if (r < 0) {
1210             goto irqroute_error;
1211         }
1212     }
1213     for (n = 0; n < nvqs; n++) {
1214         if (!virtio_queue_get_num(vdev, n)) {
1215             break;
1216         }
1217         r = virtio_ccw_set_guest_notifier(dev, n, assigned, with_irqfd);
1218         if (r < 0) {
1219             goto assign_error;
1220         }
1221     }
1222     if (with_irqfd && !assigned) {
1223         /* release irq routes after irqfds have been released */
1224         virtio_ccw_release_irqroutes(dev, nvqs);
1225     }
1226     return 0;
1227 
1228 assign_error:
1229     while (--n >= 0) {
1230         virtio_ccw_set_guest_notifier(dev, n, !assigned, false);
1231     }
1232 irqroute_error:
1233     if (with_irqfd && assigned) {
1234         virtio_ccw_release_irqroutes(dev, nvqs);
1235     }
1236     return r;
1237 }
1238 
1239 static void virtio_ccw_save_queue(DeviceState *d, int n, QEMUFile *f)
1240 {
1241     VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
1242     VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
1243 
1244     qemu_put_be16(f, virtio_queue_vector(vdev, n));
1245 }
1246 
1247 static int virtio_ccw_load_queue(DeviceState *d, int n, QEMUFile *f)
1248 {
1249     VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
1250     VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
1251     uint16_t vector;
1252 
1253     qemu_get_be16s(f, &vector);
1254     virtio_queue_set_vector(vdev, n , vector);
1255 
1256     return 0;
1257 }
1258 
1259 static void virtio_ccw_save_config(DeviceState *d, QEMUFile *f)
1260 {
1261     VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
1262     vmstate_save_state(f, &vmstate_virtio_ccw_dev, dev, NULL);
1263 }
1264 
1265 static int virtio_ccw_load_config(DeviceState *d, QEMUFile *f)
1266 {
1267     VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
1268     return vmstate_load_state(f, &vmstate_virtio_ccw_dev, dev, 1);
1269 }
1270 
1271 static void virtio_ccw_pre_plugged(DeviceState *d, Error **errp)
1272 {
1273    VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
1274    VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
1275 
1276     if (dev->max_rev >= 1) {
1277         virtio_add_feature(&vdev->host_features, VIRTIO_F_VERSION_1);
1278     }
1279 }
1280 
1281 /* This is called by virtio-bus just after the device is plugged. */
1282 static void virtio_ccw_device_plugged(DeviceState *d, Error **errp)
1283 {
1284     VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
1285     VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
1286     CcwDevice *ccw_dev = CCW_DEVICE(d);
1287     SubchDev *sch = ccw_dev->sch;
1288     int n = virtio_get_num_queues(vdev);
1289     S390FLICState *flic = s390_get_flic();
1290 
1291     if (!virtio_has_feature(vdev->host_features, VIRTIO_F_VERSION_1)) {
1292         dev->max_rev = 0;
1293     }
1294 
1295     if (virtio_get_num_queues(vdev) > VIRTIO_QUEUE_MAX) {
1296         error_setg(errp, "The number of virtqueues %d "
1297                    "exceeds virtio limit %d", n,
1298                    VIRTIO_QUEUE_MAX);
1299         return;
1300     }
1301     if (virtio_get_num_queues(vdev) > flic->adapter_routes_max_batch) {
1302         error_setg(errp, "The number of virtqueues %d "
1303                    "exceeds flic adapter route limit %d", n,
1304                    flic->adapter_routes_max_batch);
1305         return;
1306     }
1307 
1308     sch->id.cu_model = virtio_bus_get_vdev_id(&dev->bus);
1309 
1310 
1311     css_generate_sch_crws(sch->cssid, sch->ssid, sch->schid,
1312                           d->hotplugged, 1);
1313 }
1314 
1315 static void virtio_ccw_device_unplugged(DeviceState *d)
1316 {
1317     VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
1318 
1319     virtio_ccw_stop_ioeventfd(dev);
1320 }
1321 /**************** Virtio-ccw Bus Device Descriptions *******************/
1322 
1323 static Property virtio_ccw_net_properties[] = {
1324     DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
1325                     VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1326     DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev,
1327                        VIRTIO_CCW_MAX_REV),
1328     DEFINE_PROP_END_OF_LIST(),
1329 };
1330 
1331 static void virtio_ccw_net_class_init(ObjectClass *klass, void *data)
1332 {
1333     DeviceClass *dc = DEVICE_CLASS(klass);
1334     VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1335 
1336     k->realize = virtio_ccw_net_realize;
1337     k->exit = virtio_ccw_exit;
1338     dc->reset = virtio_ccw_reset;
1339     dc->props = virtio_ccw_net_properties;
1340     set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
1341 }
1342 
1343 static const TypeInfo virtio_ccw_net = {
1344     .name          = TYPE_VIRTIO_NET_CCW,
1345     .parent        = TYPE_VIRTIO_CCW_DEVICE,
1346     .instance_size = sizeof(VirtIONetCcw),
1347     .instance_init = virtio_ccw_net_instance_init,
1348     .class_init    = virtio_ccw_net_class_init,
1349 };
1350 
1351 static Property virtio_ccw_blk_properties[] = {
1352     DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
1353                     VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1354     DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev,
1355                        VIRTIO_CCW_MAX_REV),
1356     DEFINE_PROP_END_OF_LIST(),
1357 };
1358 
1359 static void virtio_ccw_blk_class_init(ObjectClass *klass, void *data)
1360 {
1361     DeviceClass *dc = DEVICE_CLASS(klass);
1362     VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1363 
1364     k->realize = virtio_ccw_blk_realize;
1365     k->exit = virtio_ccw_exit;
1366     dc->reset = virtio_ccw_reset;
1367     dc->props = virtio_ccw_blk_properties;
1368     set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
1369 }
1370 
1371 static const TypeInfo virtio_ccw_blk = {
1372     .name          = TYPE_VIRTIO_BLK_CCW,
1373     .parent        = TYPE_VIRTIO_CCW_DEVICE,
1374     .instance_size = sizeof(VirtIOBlkCcw),
1375     .instance_init = virtio_ccw_blk_instance_init,
1376     .class_init    = virtio_ccw_blk_class_init,
1377 };
1378 
1379 static Property virtio_ccw_serial_properties[] = {
1380     DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
1381                     VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1382     DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev,
1383                        VIRTIO_CCW_MAX_REV),
1384     DEFINE_PROP_END_OF_LIST(),
1385 };
1386 
1387 static void virtio_ccw_serial_class_init(ObjectClass *klass, void *data)
1388 {
1389     DeviceClass *dc = DEVICE_CLASS(klass);
1390     VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1391 
1392     k->realize = virtio_ccw_serial_realize;
1393     k->exit = virtio_ccw_exit;
1394     dc->reset = virtio_ccw_reset;
1395     dc->props = virtio_ccw_serial_properties;
1396     set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
1397 }
1398 
1399 static const TypeInfo virtio_ccw_serial = {
1400     .name          = TYPE_VIRTIO_SERIAL_CCW,
1401     .parent        = TYPE_VIRTIO_CCW_DEVICE,
1402     .instance_size = sizeof(VirtioSerialCcw),
1403     .instance_init = virtio_ccw_serial_instance_init,
1404     .class_init    = virtio_ccw_serial_class_init,
1405 };
1406 
1407 static Property virtio_ccw_balloon_properties[] = {
1408     DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
1409                     VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1410     DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev,
1411                        VIRTIO_CCW_MAX_REV),
1412     DEFINE_PROP_END_OF_LIST(),
1413 };
1414 
1415 static void virtio_ccw_balloon_class_init(ObjectClass *klass, void *data)
1416 {
1417     DeviceClass *dc = DEVICE_CLASS(klass);
1418     VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1419 
1420     k->realize = virtio_ccw_balloon_realize;
1421     k->exit = virtio_ccw_exit;
1422     dc->reset = virtio_ccw_reset;
1423     dc->props = virtio_ccw_balloon_properties;
1424     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
1425 }
1426 
1427 static const TypeInfo virtio_ccw_balloon = {
1428     .name          = TYPE_VIRTIO_BALLOON_CCW,
1429     .parent        = TYPE_VIRTIO_CCW_DEVICE,
1430     .instance_size = sizeof(VirtIOBalloonCcw),
1431     .instance_init = virtio_ccw_balloon_instance_init,
1432     .class_init    = virtio_ccw_balloon_class_init,
1433 };
1434 
1435 static Property virtio_ccw_scsi_properties[] = {
1436     DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
1437                     VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1438     DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev,
1439                        VIRTIO_CCW_MAX_REV),
1440     DEFINE_PROP_END_OF_LIST(),
1441 };
1442 
1443 static void virtio_ccw_scsi_class_init(ObjectClass *klass, void *data)
1444 {
1445     DeviceClass *dc = DEVICE_CLASS(klass);
1446     VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1447 
1448     k->realize = virtio_ccw_scsi_realize;
1449     k->exit = virtio_ccw_exit;
1450     dc->reset = virtio_ccw_reset;
1451     dc->props = virtio_ccw_scsi_properties;
1452     set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
1453 }
1454 
1455 static const TypeInfo virtio_ccw_scsi = {
1456     .name          = TYPE_VIRTIO_SCSI_CCW,
1457     .parent        = TYPE_VIRTIO_CCW_DEVICE,
1458     .instance_size = sizeof(VirtIOSCSICcw),
1459     .instance_init = virtio_ccw_scsi_instance_init,
1460     .class_init    = virtio_ccw_scsi_class_init,
1461 };
1462 
1463 #ifdef CONFIG_VHOST_SCSI
1464 static Property vhost_ccw_scsi_properties[] = {
1465     DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev,
1466                        VIRTIO_CCW_MAX_REV),
1467     DEFINE_PROP_END_OF_LIST(),
1468 };
1469 
1470 static void vhost_ccw_scsi_class_init(ObjectClass *klass, void *data)
1471 {
1472     DeviceClass *dc = DEVICE_CLASS(klass);
1473     VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1474 
1475     k->realize = vhost_ccw_scsi_realize;
1476     k->exit = virtio_ccw_exit;
1477     dc->reset = virtio_ccw_reset;
1478     dc->props = vhost_ccw_scsi_properties;
1479     set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
1480 }
1481 
1482 static const TypeInfo vhost_ccw_scsi = {
1483     .name          = TYPE_VHOST_SCSI_CCW,
1484     .parent        = TYPE_VIRTIO_CCW_DEVICE,
1485     .instance_size = sizeof(VHostSCSICcw),
1486     .instance_init = vhost_ccw_scsi_instance_init,
1487     .class_init    = vhost_ccw_scsi_class_init,
1488 };
1489 #endif
1490 
1491 static void virtio_ccw_rng_instance_init(Object *obj)
1492 {
1493     VirtIORNGCcw *dev = VIRTIO_RNG_CCW(obj);
1494 
1495     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
1496                                 TYPE_VIRTIO_RNG);
1497 }
1498 
1499 static Property virtio_ccw_rng_properties[] = {
1500     DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
1501                     VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1502     DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev,
1503                        VIRTIO_CCW_MAX_REV),
1504     DEFINE_PROP_END_OF_LIST(),
1505 };
1506 
1507 static void virtio_ccw_rng_class_init(ObjectClass *klass, void *data)
1508 {
1509     DeviceClass *dc = DEVICE_CLASS(klass);
1510     VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1511 
1512     k->realize = virtio_ccw_rng_realize;
1513     k->exit = virtio_ccw_exit;
1514     dc->reset = virtio_ccw_reset;
1515     dc->props = virtio_ccw_rng_properties;
1516     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
1517 }
1518 
1519 static const TypeInfo virtio_ccw_rng = {
1520     .name          = TYPE_VIRTIO_RNG_CCW,
1521     .parent        = TYPE_VIRTIO_CCW_DEVICE,
1522     .instance_size = sizeof(VirtIORNGCcw),
1523     .instance_init = virtio_ccw_rng_instance_init,
1524     .class_init    = virtio_ccw_rng_class_init,
1525 };
1526 
1527 static Property virtio_ccw_crypto_properties[] = {
1528     DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
1529                     VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1530     DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev,
1531                        VIRTIO_CCW_MAX_REV),
1532     DEFINE_PROP_END_OF_LIST(),
1533 };
1534 
1535 static void virtio_ccw_crypto_instance_init(Object *obj)
1536 {
1537     VirtIOCryptoCcw *dev = VIRTIO_CRYPTO_CCW(obj);
1538     VirtioCcwDevice *ccw_dev = VIRTIO_CCW_DEVICE(obj);
1539 
1540     ccw_dev->force_revision_1 = true;
1541     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
1542                                 TYPE_VIRTIO_CRYPTO);
1543 }
1544 
1545 static void virtio_ccw_crypto_class_init(ObjectClass *klass, void *data)
1546 {
1547     DeviceClass *dc = DEVICE_CLASS(klass);
1548     VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1549 
1550     k->realize = virtio_ccw_crypto_realize;
1551     k->exit = virtio_ccw_exit;
1552     dc->reset = virtio_ccw_reset;
1553     dc->props = virtio_ccw_crypto_properties;
1554     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
1555 }
1556 
1557 static const TypeInfo virtio_ccw_crypto = {
1558     .name          = TYPE_VIRTIO_CRYPTO_CCW,
1559     .parent        = TYPE_VIRTIO_CCW_DEVICE,
1560     .instance_size = sizeof(VirtIOCryptoCcw),
1561     .instance_init = virtio_ccw_crypto_instance_init,
1562     .class_init    = virtio_ccw_crypto_class_init,
1563 };
1564 
1565 static Property virtio_ccw_gpu_properties[] = {
1566     DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
1567                     VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1568     DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev,
1569                        VIRTIO_CCW_MAX_REV),
1570     DEFINE_PROP_END_OF_LIST(),
1571 };
1572 
1573 static void virtio_ccw_gpu_instance_init(Object *obj)
1574 {
1575     VirtIOGPUCcw *dev = VIRTIO_GPU_CCW(obj);
1576     VirtioCcwDevice *ccw_dev = VIRTIO_CCW_DEVICE(obj);
1577 
1578     ccw_dev->force_revision_1 = true;
1579     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
1580                                 TYPE_VIRTIO_GPU);
1581 }
1582 
1583 static void virtio_ccw_gpu_class_init(ObjectClass *klass, void *data)
1584 {
1585     DeviceClass *dc = DEVICE_CLASS(klass);
1586     VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1587 
1588     k->realize = virtio_ccw_gpu_realize;
1589     k->exit = virtio_ccw_exit;
1590     dc->reset = virtio_ccw_reset;
1591     dc->props = virtio_ccw_gpu_properties;
1592     dc->hotpluggable = false;
1593     set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
1594 }
1595 
1596 static const TypeInfo virtio_ccw_gpu = {
1597     .name          = TYPE_VIRTIO_GPU_CCW,
1598     .parent        = TYPE_VIRTIO_CCW_DEVICE,
1599     .instance_size = sizeof(VirtIOGPUCcw),
1600     .instance_init = virtio_ccw_gpu_instance_init,
1601     .class_init    = virtio_ccw_gpu_class_init,
1602 };
1603 
1604 static void virtio_ccw_busdev_realize(DeviceState *dev, Error **errp)
1605 {
1606     VirtioCcwDevice *_dev = (VirtioCcwDevice *)dev;
1607 
1608     virtio_ccw_bus_new(&_dev->bus, sizeof(_dev->bus), _dev);
1609     virtio_ccw_device_realize(_dev, errp);
1610 }
1611 
1612 static int virtio_ccw_busdev_exit(DeviceState *dev)
1613 {
1614     VirtioCcwDevice *_dev = (VirtioCcwDevice *)dev;
1615     VirtIOCCWDeviceClass *_info = VIRTIO_CCW_DEVICE_GET_CLASS(dev);
1616 
1617     return _info->exit(_dev);
1618 }
1619 
1620 static void virtio_ccw_busdev_unplug(HotplugHandler *hotplug_dev,
1621                                      DeviceState *dev, Error **errp)
1622 {
1623     VirtioCcwDevice *_dev = to_virtio_ccw_dev_fast(dev);
1624 
1625     virtio_ccw_stop_ioeventfd(_dev);
1626 }
1627 
1628 static void virtio_ccw_device_class_init(ObjectClass *klass, void *data)
1629 {
1630     DeviceClass *dc = DEVICE_CLASS(klass);
1631     CCWDeviceClass *k = CCW_DEVICE_CLASS(dc);
1632 
1633     k->unplug = virtio_ccw_busdev_unplug;
1634     dc->realize = virtio_ccw_busdev_realize;
1635     dc->exit = virtio_ccw_busdev_exit;
1636     dc->bus_type = TYPE_VIRTUAL_CSS_BUS;
1637 }
1638 
1639 static const TypeInfo virtio_ccw_device_info = {
1640     .name = TYPE_VIRTIO_CCW_DEVICE,
1641     .parent = TYPE_CCW_DEVICE,
1642     .instance_size = sizeof(VirtioCcwDevice),
1643     .class_init = virtio_ccw_device_class_init,
1644     .class_size = sizeof(VirtIOCCWDeviceClass),
1645     .abstract = true,
1646 };
1647 
1648 /* virtio-ccw-bus */
1649 
1650 static void virtio_ccw_bus_new(VirtioBusState *bus, size_t bus_size,
1651                                VirtioCcwDevice *dev)
1652 {
1653     DeviceState *qdev = DEVICE(dev);
1654     char virtio_bus_name[] = "virtio-bus";
1655 
1656     qbus_create_inplace(bus, bus_size, TYPE_VIRTIO_CCW_BUS,
1657                         qdev, virtio_bus_name);
1658 }
1659 
1660 static void virtio_ccw_bus_class_init(ObjectClass *klass, void *data)
1661 {
1662     VirtioBusClass *k = VIRTIO_BUS_CLASS(klass);
1663     BusClass *bus_class = BUS_CLASS(klass);
1664 
1665     bus_class->max_dev = 1;
1666     k->notify = virtio_ccw_notify;
1667     k->vmstate_change = virtio_ccw_vmstate_change;
1668     k->query_guest_notifiers = virtio_ccw_query_guest_notifiers;
1669     k->set_guest_notifiers = virtio_ccw_set_guest_notifiers;
1670     k->save_queue = virtio_ccw_save_queue;
1671     k->load_queue = virtio_ccw_load_queue;
1672     k->save_config = virtio_ccw_save_config;
1673     k->load_config = virtio_ccw_load_config;
1674     k->pre_plugged = virtio_ccw_pre_plugged;
1675     k->device_plugged = virtio_ccw_device_plugged;
1676     k->device_unplugged = virtio_ccw_device_unplugged;
1677     k->ioeventfd_enabled = virtio_ccw_ioeventfd_enabled;
1678     k->ioeventfd_assign = virtio_ccw_ioeventfd_assign;
1679 }
1680 
1681 static const TypeInfo virtio_ccw_bus_info = {
1682     .name = TYPE_VIRTIO_CCW_BUS,
1683     .parent = TYPE_VIRTIO_BUS,
1684     .instance_size = sizeof(VirtioCcwBusState),
1685     .class_init = virtio_ccw_bus_class_init,
1686 };
1687 
1688 #ifdef CONFIG_VIRTFS
1689 static Property virtio_ccw_9p_properties[] = {
1690     DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
1691             VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1692     DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev,
1693                        VIRTIO_CCW_MAX_REV),
1694     DEFINE_PROP_END_OF_LIST(),
1695 };
1696 
1697 static void virtio_ccw_9p_realize(VirtioCcwDevice *ccw_dev, Error **errp)
1698 {
1699     V9fsCCWState *dev = VIRTIO_9P_CCW(ccw_dev);
1700     DeviceState *vdev = DEVICE(&dev->vdev);
1701 
1702     qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
1703     object_property_set_bool(OBJECT(vdev), true, "realized", errp);
1704 }
1705 
1706 static void virtio_ccw_9p_class_init(ObjectClass *klass, void *data)
1707 {
1708     DeviceClass *dc = DEVICE_CLASS(klass);
1709     VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1710 
1711     k->exit = virtio_ccw_exit;
1712     k->realize = virtio_ccw_9p_realize;
1713     dc->reset = virtio_ccw_reset;
1714     dc->props = virtio_ccw_9p_properties;
1715     set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
1716 }
1717 
1718 static void virtio_ccw_9p_instance_init(Object *obj)
1719 {
1720     V9fsCCWState *dev = VIRTIO_9P_CCW(obj);
1721 
1722     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
1723                                 TYPE_VIRTIO_9P);
1724 }
1725 
1726 static const TypeInfo virtio_ccw_9p_info = {
1727     .name          = TYPE_VIRTIO_9P_CCW,
1728     .parent        = TYPE_VIRTIO_CCW_DEVICE,
1729     .instance_size = sizeof(V9fsCCWState),
1730     .instance_init = virtio_ccw_9p_instance_init,
1731     .class_init    = virtio_ccw_9p_class_init,
1732 };
1733 #endif
1734 
1735 #ifdef CONFIG_VHOST_VSOCK
1736 
1737 static Property vhost_vsock_ccw_properties[] = {
1738     DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev,
1739                        VIRTIO_CCW_MAX_REV),
1740     DEFINE_PROP_END_OF_LIST(),
1741 };
1742 
1743 static void vhost_vsock_ccw_realize(VirtioCcwDevice *ccw_dev, Error **errp)
1744 {
1745     VHostVSockCCWState *dev = VHOST_VSOCK_CCW(ccw_dev);
1746     DeviceState *vdev = DEVICE(&dev->vdev);
1747     Error *err = NULL;
1748 
1749     qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
1750     object_property_set_bool(OBJECT(vdev), true, "realized", &err);
1751     error_propagate(errp, err);
1752 }
1753 
1754 static void vhost_vsock_ccw_class_init(ObjectClass *klass, void *data)
1755 {
1756     DeviceClass *dc = DEVICE_CLASS(klass);
1757     VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1758 
1759     k->realize = vhost_vsock_ccw_realize;
1760     k->exit = virtio_ccw_exit;
1761     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
1762     dc->props = vhost_vsock_ccw_properties;
1763     dc->reset = virtio_ccw_reset;
1764 }
1765 
1766 static void vhost_vsock_ccw_instance_init(Object *obj)
1767 {
1768     VHostVSockCCWState *dev = VHOST_VSOCK_CCW(obj);
1769 
1770     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
1771                                 TYPE_VHOST_VSOCK);
1772 }
1773 
1774 static const TypeInfo vhost_vsock_ccw_info = {
1775     .name          = TYPE_VHOST_VSOCK_CCW,
1776     .parent        = TYPE_VIRTIO_CCW_DEVICE,
1777     .instance_size = sizeof(VHostVSockCCWState),
1778     .instance_init = vhost_vsock_ccw_instance_init,
1779     .class_init    = vhost_vsock_ccw_class_init,
1780 };
1781 #endif
1782 
1783 static void virtio_ccw_register(void)
1784 {
1785     type_register_static(&virtio_ccw_bus_info);
1786     type_register_static(&virtio_ccw_device_info);
1787     type_register_static(&virtio_ccw_serial);
1788     type_register_static(&virtio_ccw_blk);
1789     type_register_static(&virtio_ccw_net);
1790     type_register_static(&virtio_ccw_balloon);
1791     type_register_static(&virtio_ccw_scsi);
1792 #ifdef CONFIG_VHOST_SCSI
1793     type_register_static(&vhost_ccw_scsi);
1794 #endif
1795     type_register_static(&virtio_ccw_rng);
1796 #ifdef CONFIG_VIRTFS
1797     type_register_static(&virtio_ccw_9p_info);
1798 #endif
1799 #ifdef CONFIG_VHOST_VSOCK
1800     type_register_static(&vhost_vsock_ccw_info);
1801 #endif
1802     type_register_static(&virtio_ccw_crypto);
1803     type_register_static(&virtio_ccw_gpu);
1804 }
1805 
1806 type_init(virtio_ccw_register)
1807