xref: /openbmc/qemu/hw/s390x/virtio-ccw.c (revision 878096ee)
1 /*
2  * virtio ccw target implementation
3  *
4  * Copyright 2012 IBM Corp.
5  * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
6  *
7  * This work is licensed under the terms of the GNU GPL, version 2 or (at
8  * your option) any later version. See the COPYING file in the top-level
9  * directory.
10  */
11 
12 #include "hw/hw.h"
13 #include "block/block.h"
14 #include "sysemu/blockdev.h"
15 #include "sysemu/sysemu.h"
16 #include "net/net.h"
17 #include "monitor/monitor.h"
18 #include "hw/virtio/virtio.h"
19 #include "hw/virtio/virtio-serial.h"
20 #include "hw/virtio/virtio-net.h"
21 #include "hw/sysbus.h"
22 #include "qemu/bitops.h"
23 #include "hw/virtio/virtio-bus.h"
24 
25 #include "ioinst.h"
26 #include "css.h"
27 #include "virtio-ccw.h"
28 #include "trace.h"
29 
30 static void virtio_ccw_bus_new(VirtioBusState *bus, VirtioCcwDevice *dev);
31 
32 static int virtual_css_bus_reset(BusState *qbus)
33 {
34     /* This should actually be modelled via the generic css */
35     css_reset();
36 
37     /* we dont traverse ourself, return 0 */
38     return 0;
39 }
40 
41 
42 static void virtual_css_bus_class_init(ObjectClass *klass, void *data)
43 {
44     BusClass *k = BUS_CLASS(klass);
45 
46     k->reset = virtual_css_bus_reset;
47 }
48 
49 static const TypeInfo virtual_css_bus_info = {
50     .name = TYPE_VIRTUAL_CSS_BUS,
51     .parent = TYPE_BUS,
52     .instance_size = sizeof(VirtualCssBus),
53     .class_init = virtual_css_bus_class_init,
54 };
55 
56 VirtIODevice *virtio_ccw_get_vdev(SubchDev *sch)
57 {
58     VirtIODevice *vdev = NULL;
59 
60     if (sch->driver_data) {
61         vdev = ((VirtioCcwDevice *)sch->driver_data)->vdev;
62     }
63     return vdev;
64 }
65 
66 static int virtio_ccw_set_guest2host_notifier(VirtioCcwDevice *dev, int n,
67                                               bool assign, bool set_handler)
68 {
69     VirtQueue *vq = virtio_get_queue(dev->vdev, n);
70     EventNotifier *notifier = virtio_queue_get_host_notifier(vq);
71     int r = 0;
72     SubchDev *sch = dev->sch;
73     uint32_t sch_id = (css_build_subchannel_id(sch) << 16) | sch->schid;
74 
75     if (assign) {
76         r = event_notifier_init(notifier, 1);
77         if (r < 0) {
78             error_report("%s: unable to init event notifier: %d", __func__, r);
79             return r;
80         }
81         virtio_queue_set_host_notifier_fd_handler(vq, true, set_handler);
82         r = s390_assign_subch_ioeventfd(event_notifier_get_fd(notifier), sch_id,
83                                         n, assign);
84         if (r < 0) {
85             error_report("%s: unable to assign ioeventfd: %d", __func__, r);
86             virtio_queue_set_host_notifier_fd_handler(vq, false, false);
87             event_notifier_cleanup(notifier);
88             return r;
89         }
90     } else {
91         virtio_queue_set_host_notifier_fd_handler(vq, false, false);
92         s390_assign_subch_ioeventfd(event_notifier_get_fd(notifier), sch_id,
93                                     n, assign);
94         event_notifier_cleanup(notifier);
95     }
96     return r;
97 }
98 
99 static void virtio_ccw_start_ioeventfd(VirtioCcwDevice *dev)
100 {
101     int n, r;
102 
103     if (!(dev->flags & VIRTIO_CCW_FLAG_USE_IOEVENTFD) ||
104         dev->ioeventfd_disabled ||
105         dev->ioeventfd_started) {
106         return;
107     }
108     for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) {
109         if (!virtio_queue_get_num(dev->vdev, n)) {
110             continue;
111         }
112         r = virtio_ccw_set_guest2host_notifier(dev, n, true, true);
113         if (r < 0) {
114             goto assign_error;
115         }
116     }
117     dev->ioeventfd_started = true;
118     return;
119 
120   assign_error:
121     while (--n >= 0) {
122         if (!virtio_queue_get_num(dev->vdev, n)) {
123             continue;
124         }
125         r = virtio_ccw_set_guest2host_notifier(dev, n, false, false);
126         assert(r >= 0);
127     }
128     dev->ioeventfd_started = false;
129     /* Disable ioeventfd for this device. */
130     dev->flags &= ~VIRTIO_CCW_FLAG_USE_IOEVENTFD;
131     error_report("%s: failed. Fallback to userspace (slower).", __func__);
132 }
133 
134 static void virtio_ccw_stop_ioeventfd(VirtioCcwDevice *dev)
135 {
136     int n, r;
137 
138     if (!dev->ioeventfd_started) {
139         return;
140     }
141     for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) {
142         if (!virtio_queue_get_num(dev->vdev, n)) {
143             continue;
144         }
145         r = virtio_ccw_set_guest2host_notifier(dev, n, false, false);
146         assert(r >= 0);
147     }
148     dev->ioeventfd_started = false;
149 }
150 
151 VirtualCssBus *virtual_css_bus_init(void)
152 {
153     VirtualCssBus *cbus;
154     BusState *bus;
155     DeviceState *dev;
156 
157     /* Create bridge device */
158     dev = qdev_create(NULL, "virtual-css-bridge");
159     qdev_init_nofail(dev);
160 
161     /* Create bus on bridge device */
162     bus = qbus_create(TYPE_VIRTUAL_CSS_BUS, dev, "virtual-css");
163     cbus = VIRTUAL_CSS_BUS(bus);
164 
165     /* Enable hotplugging */
166     bus->allow_hotplug = 1;
167 
168     return cbus;
169 }
170 
171 /* Communication blocks used by several channel commands. */
172 typedef struct VqInfoBlock {
173     uint64_t queue;
174     uint32_t align;
175     uint16_t index;
176     uint16_t num;
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 /* Specify where the virtqueues for the subchannel are in guest memory. */
190 static int virtio_ccw_set_vqs(SubchDev *sch, uint64_t addr, uint32_t align,
191                               uint16_t index, uint16_t num)
192 {
193     VirtioCcwDevice *dev = sch->driver_data;
194 
195     if (index > VIRTIO_PCI_QUEUE_MAX) {
196         return -EINVAL;
197     }
198 
199     /* Current code in virtio.c relies on 4K alignment. */
200     if (addr && (align != 4096)) {
201         return -EINVAL;
202     }
203 
204     if (!dev) {
205         return -EINVAL;
206     }
207 
208     virtio_queue_set_addr(dev->vdev, index, addr);
209     if (!addr) {
210         virtio_queue_set_vector(dev->vdev, index, 0);
211     } else {
212         /* Fail if we don't have a big enough queue. */
213         /* TODO: Add interface to handle vring.num changing */
214         if (virtio_queue_get_num(dev->vdev, index) > num) {
215             return -EINVAL;
216         }
217         virtio_queue_set_vector(dev->vdev, index, index);
218     }
219     /* tell notify handler in case of config change */
220     dev->vdev->config_vector = VIRTIO_PCI_QUEUE_MAX;
221     return 0;
222 }
223 
224 static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
225 {
226     int ret;
227     VqInfoBlock info;
228     uint8_t status;
229     VirtioFeatDesc features;
230     void *config;
231     hwaddr indicators;
232     VqConfigBlock vq_config;
233     VirtioCcwDevice *dev = sch->driver_data;
234     bool check_len;
235     int len;
236     hwaddr hw_len;
237 
238     if (!dev) {
239         return -EINVAL;
240     }
241 
242     trace_virtio_ccw_interpret_ccw(sch->cssid, sch->ssid, sch->schid,
243                                    ccw.cmd_code);
244     check_len = !((ccw.flags & CCW_FLAG_SLI) && !(ccw.flags & CCW_FLAG_DC));
245 
246     /* Look at the command. */
247     switch (ccw.cmd_code) {
248     case CCW_CMD_SET_VQ:
249         if (check_len) {
250             if (ccw.count != sizeof(info)) {
251                 ret = -EINVAL;
252                 break;
253             }
254         } else if (ccw.count < sizeof(info)) {
255             /* Can't execute command. */
256             ret = -EINVAL;
257             break;
258         }
259         if (!ccw.cda) {
260             ret = -EFAULT;
261         } else {
262             info.queue = ldq_phys(ccw.cda);
263             info.align = ldl_phys(ccw.cda + sizeof(info.queue));
264             info.index = lduw_phys(ccw.cda + sizeof(info.queue)
265                                    + sizeof(info.align));
266             info.num = lduw_phys(ccw.cda + sizeof(info.queue)
267                                  + sizeof(info.align)
268                                  + sizeof(info.index));
269             ret = virtio_ccw_set_vqs(sch, info.queue, info.align, info.index,
270                                      info.num);
271             sch->curr_status.scsw.count = 0;
272         }
273         break;
274     case CCW_CMD_VDEV_RESET:
275         virtio_ccw_stop_ioeventfd(dev);
276         virtio_reset(dev->vdev);
277         ret = 0;
278         break;
279     case CCW_CMD_READ_FEAT:
280         if (check_len) {
281             if (ccw.count != sizeof(features)) {
282                 ret = -EINVAL;
283                 break;
284             }
285         } else if (ccw.count < sizeof(features)) {
286             /* Can't execute command. */
287             ret = -EINVAL;
288             break;
289         }
290         if (!ccw.cda) {
291             ret = -EFAULT;
292         } else {
293             features.index = ldub_phys(ccw.cda + sizeof(features.features));
294             if (features.index < ARRAY_SIZE(dev->host_features)) {
295                 features.features = dev->host_features[features.index];
296             } else {
297                 /* Return zeroes if the guest supports more feature bits. */
298                 features.features = 0;
299             }
300             stl_le_phys(ccw.cda, features.features);
301             sch->curr_status.scsw.count = ccw.count - sizeof(features);
302             ret = 0;
303         }
304         break;
305     case CCW_CMD_WRITE_FEAT:
306         if (check_len) {
307             if (ccw.count != sizeof(features)) {
308                 ret = -EINVAL;
309                 break;
310             }
311         } else if (ccw.count < sizeof(features)) {
312             /* Can't execute command. */
313             ret = -EINVAL;
314             break;
315         }
316         if (!ccw.cda) {
317             ret = -EFAULT;
318         } else {
319             features.index = ldub_phys(ccw.cda + sizeof(features.features));
320             features.features = ldl_le_phys(ccw.cda);
321             if (features.index < ARRAY_SIZE(dev->host_features)) {
322                 virtio_bus_set_vdev_features(&dev->bus, features.features);
323                 dev->vdev->guest_features = features.features;
324             } else {
325                 /*
326                  * If the guest supports more feature bits, assert that it
327                  * passes us zeroes for those we don't support.
328                  */
329                 if (features.features) {
330                     fprintf(stderr, "Guest bug: features[%i]=%x (expected 0)\n",
331                             features.index, features.features);
332                     /* XXX: do a unit check here? */
333                 }
334             }
335             sch->curr_status.scsw.count = ccw.count - sizeof(features);
336             ret = 0;
337         }
338         break;
339     case CCW_CMD_READ_CONF:
340         if (check_len) {
341             if (ccw.count > dev->vdev->config_len) {
342                 ret = -EINVAL;
343                 break;
344             }
345         }
346         len = MIN(ccw.count, dev->vdev->config_len);
347         if (!ccw.cda) {
348             ret = -EFAULT;
349         } else {
350             virtio_bus_get_vdev_config(&dev->bus, dev->vdev->config);
351             /* XXX config space endianness */
352             cpu_physical_memory_write(ccw.cda, dev->vdev->config, len);
353             sch->curr_status.scsw.count = ccw.count - len;
354             ret = 0;
355         }
356         break;
357     case CCW_CMD_WRITE_CONF:
358         if (check_len) {
359             if (ccw.count > dev->vdev->config_len) {
360                 ret = -EINVAL;
361                 break;
362             }
363         }
364         len = MIN(ccw.count, dev->vdev->config_len);
365         hw_len = len;
366         if (!ccw.cda) {
367             ret = -EFAULT;
368         } else {
369             config = cpu_physical_memory_map(ccw.cda, &hw_len, 0);
370             if (!config) {
371                 ret = -EFAULT;
372             } else {
373                 len = hw_len;
374                 /* XXX config space endianness */
375                 memcpy(dev->vdev->config, config, len);
376                 cpu_physical_memory_unmap(config, hw_len, 0, hw_len);
377                 virtio_bus_set_vdev_config(&dev->bus, dev->vdev->config);
378                 sch->curr_status.scsw.count = ccw.count - len;
379                 ret = 0;
380             }
381         }
382         break;
383     case CCW_CMD_WRITE_STATUS:
384         if (check_len) {
385             if (ccw.count != sizeof(status)) {
386                 ret = -EINVAL;
387                 break;
388             }
389         } else if (ccw.count < sizeof(status)) {
390             /* Can't execute command. */
391             ret = -EINVAL;
392             break;
393         }
394         if (!ccw.cda) {
395             ret = -EFAULT;
396         } else {
397             status = ldub_phys(ccw.cda);
398             if (!(status & VIRTIO_CONFIG_S_DRIVER_OK)) {
399                 virtio_ccw_stop_ioeventfd(dev);
400             }
401             virtio_set_status(dev->vdev, status);
402             if (dev->vdev->status == 0) {
403                 virtio_reset(dev->vdev);
404             }
405             if (status & VIRTIO_CONFIG_S_DRIVER_OK) {
406                 virtio_ccw_start_ioeventfd(dev);
407             }
408             sch->curr_status.scsw.count = ccw.count - sizeof(status);
409             ret = 0;
410         }
411         break;
412     case CCW_CMD_SET_IND:
413         if (check_len) {
414             if (ccw.count != sizeof(indicators)) {
415                 ret = -EINVAL;
416                 break;
417             }
418         } else if (ccw.count < sizeof(indicators)) {
419             /* Can't execute command. */
420             ret = -EINVAL;
421             break;
422         }
423         if (!ccw.cda) {
424             ret = -EFAULT;
425         } else {
426             indicators = ldq_phys(ccw.cda);
427             dev->indicators = indicators;
428             sch->curr_status.scsw.count = ccw.count - sizeof(indicators);
429             ret = 0;
430         }
431         break;
432     case CCW_CMD_SET_CONF_IND:
433         if (check_len) {
434             if (ccw.count != sizeof(indicators)) {
435                 ret = -EINVAL;
436                 break;
437             }
438         } else if (ccw.count < sizeof(indicators)) {
439             /* Can't execute command. */
440             ret = -EINVAL;
441             break;
442         }
443         if (!ccw.cda) {
444             ret = -EFAULT;
445         } else {
446             indicators = ldq_phys(ccw.cda);
447             dev->indicators2 = indicators;
448             sch->curr_status.scsw.count = ccw.count - sizeof(indicators);
449             ret = 0;
450         }
451         break;
452     case CCW_CMD_READ_VQ_CONF:
453         if (check_len) {
454             if (ccw.count != sizeof(vq_config)) {
455                 ret = -EINVAL;
456                 break;
457             }
458         } else if (ccw.count < sizeof(vq_config)) {
459             /* Can't execute command. */
460             ret = -EINVAL;
461             break;
462         }
463         if (!ccw.cda) {
464             ret = -EFAULT;
465         } else {
466             vq_config.index = lduw_phys(ccw.cda);
467             vq_config.num_max = virtio_queue_get_num(dev->vdev,
468                                                      vq_config.index);
469             stw_phys(ccw.cda + sizeof(vq_config.index), vq_config.num_max);
470             sch->curr_status.scsw.count = ccw.count - sizeof(vq_config);
471             ret = 0;
472         }
473         break;
474     default:
475         ret = -ENOSYS;
476         break;
477     }
478     return ret;
479 }
480 
481 static int virtio_ccw_device_init(VirtioCcwDevice *dev, VirtIODevice *vdev)
482 {
483     unsigned int cssid = 0;
484     unsigned int ssid = 0;
485     unsigned int schid;
486     unsigned int devno;
487     bool have_devno = false;
488     bool found = false;
489     SubchDev *sch;
490     int ret;
491     int num;
492     DeviceState *parent = DEVICE(dev);
493 
494     sch = g_malloc0(sizeof(SubchDev));
495 
496     sch->driver_data = dev;
497     dev->sch = sch;
498 
499     dev->vdev = vdev;
500     dev->indicators = 0;
501 
502     /* Initialize subchannel structure. */
503     sch->channel_prog = 0x0;
504     sch->last_cmd_valid = false;
505     sch->orb = NULL;
506     /*
507      * Use a device number if provided. Otherwise, fall back to subchannel
508      * number.
509      */
510     if (dev->bus_id) {
511         num = sscanf(dev->bus_id, "%x.%x.%04x", &cssid, &ssid, &devno);
512         if (num == 3) {
513             if ((cssid > MAX_CSSID) || (ssid > MAX_SSID)) {
514                 ret = -EINVAL;
515                 error_report("Invalid cssid or ssid: cssid %x, ssid %x",
516                              cssid, ssid);
517                 goto out_err;
518             }
519             /* Enforce use of virtual cssid. */
520             if (cssid != VIRTUAL_CSSID) {
521                 ret = -EINVAL;
522                 error_report("cssid %x not valid for virtio devices", cssid);
523                 goto out_err;
524             }
525             if (css_devno_used(cssid, ssid, devno)) {
526                 ret = -EEXIST;
527                 error_report("Device %x.%x.%04x already exists", cssid, ssid,
528                              devno);
529                 goto out_err;
530             }
531             sch->cssid = cssid;
532             sch->ssid = ssid;
533             sch->devno = devno;
534             have_devno = true;
535         } else {
536             ret = -EINVAL;
537             error_report("Malformed devno parameter '%s'", dev->bus_id);
538             goto out_err;
539         }
540     }
541 
542     /* Find the next free id. */
543     if (have_devno) {
544         for (schid = 0; schid <= MAX_SCHID; schid++) {
545             if (!css_find_subch(1, cssid, ssid, schid)) {
546                 sch->schid = schid;
547                 css_subch_assign(cssid, ssid, schid, devno, sch);
548                 found = true;
549                 break;
550             }
551         }
552         if (!found) {
553             ret = -ENODEV;
554             error_report("No free subchannel found for %x.%x.%04x", cssid, ssid,
555                          devno);
556             goto out_err;
557         }
558         trace_virtio_ccw_new_device(cssid, ssid, schid, devno,
559                                     "user-configured");
560     } else {
561         cssid = VIRTUAL_CSSID;
562         for (ssid = 0; ssid <= MAX_SSID; ssid++) {
563             for (schid = 0; schid <= MAX_SCHID; schid++) {
564                 if (!css_find_subch(1, cssid, ssid, schid)) {
565                     sch->cssid = cssid;
566                     sch->ssid = ssid;
567                     sch->schid = schid;
568                     devno = schid;
569                     /*
570                      * If the devno is already taken, look further in this
571                      * subchannel set.
572                      */
573                     while (css_devno_used(cssid, ssid, devno)) {
574                         if (devno == MAX_SCHID) {
575                             devno = 0;
576                         } else if (devno == schid - 1) {
577                             ret = -ENODEV;
578                             error_report("No free devno found");
579                             goto out_err;
580                         } else {
581                             devno++;
582                         }
583                     }
584                     sch->devno = devno;
585                     css_subch_assign(cssid, ssid, schid, devno, sch);
586                     found = true;
587                     break;
588                 }
589             }
590             if (found) {
591                 break;
592             }
593         }
594         if (!found) {
595             ret = -ENODEV;
596             error_report("Virtual channel subsystem is full!");
597             goto out_err;
598         }
599         trace_virtio_ccw_new_device(cssid, ssid, schid, devno,
600                                     "auto-configured");
601     }
602 
603     /* Build initial schib. */
604     css_sch_build_virtual_schib(sch, 0, VIRTIO_CCW_CHPID_TYPE);
605 
606     sch->ccw_cb = virtio_ccw_cb;
607 
608     /* Build senseid data. */
609     memset(&sch->id, 0, sizeof(SenseId));
610     sch->id.reserved = 0xff;
611     sch->id.cu_type = VIRTIO_CCW_CU_TYPE;
612     sch->id.cu_model = dev->vdev->device_id;
613 
614     /* Only the first 32 feature bits are used. */
615     dev->host_features[0] = virtio_bus_get_vdev_features(&dev->bus,
616                                                          dev->host_features[0]);
617 
618     dev->host_features[0] |= 0x1 << VIRTIO_F_NOTIFY_ON_EMPTY;
619     dev->host_features[0] |= 0x1 << VIRTIO_F_BAD_FEATURE;
620 
621     css_generate_sch_crws(sch->cssid, sch->ssid, sch->schid,
622                           parent->hotplugged, 1);
623     return 0;
624 
625 out_err:
626     dev->sch = NULL;
627     g_free(sch);
628     return ret;
629 }
630 
631 static int virtio_ccw_exit(VirtioCcwDevice *dev)
632 {
633     SubchDev *sch = dev->sch;
634 
635     virtio_ccw_stop_ioeventfd(dev);
636     if (sch) {
637         css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, NULL);
638         g_free(sch);
639     }
640     dev->indicators = 0;
641     return 0;
642 }
643 
644 static int virtio_ccw_net_init(VirtioCcwDevice *ccw_dev)
645 {
646     DeviceState *qdev = DEVICE(ccw_dev);
647     VirtIONetCcw *dev = VIRTIO_NET_CCW(ccw_dev);
648     DeviceState *vdev = DEVICE(&dev->vdev);
649 
650     virtio_net_set_config_size(&dev->vdev, ccw_dev->host_features[0]);
651     virtio_net_set_netclient_name(&dev->vdev, qdev->id,
652                                   object_get_typename(OBJECT(qdev)));
653     qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
654     if (qdev_init(vdev) < 0) {
655         return -1;
656     }
657 
658     return virtio_ccw_device_init(ccw_dev, VIRTIO_DEVICE(vdev));
659 }
660 
661 static void virtio_ccw_net_instance_init(Object *obj)
662 {
663     VirtIONetCcw *dev = VIRTIO_NET_CCW(obj);
664     object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_NET);
665     object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
666 }
667 
668 static int virtio_ccw_blk_init(VirtioCcwDevice *ccw_dev)
669 {
670     VirtIOBlkCcw *dev = VIRTIO_BLK_CCW(ccw_dev);
671     DeviceState *vdev = DEVICE(&dev->vdev);
672     virtio_blk_set_conf(vdev, &(dev->blk));
673     qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
674     if (qdev_init(vdev) < 0) {
675         return -1;
676     }
677 
678     return virtio_ccw_device_init(ccw_dev, VIRTIO_DEVICE(vdev));
679 }
680 
681 static void virtio_ccw_blk_instance_init(Object *obj)
682 {
683     VirtIOBlkCcw *dev = VIRTIO_BLK_CCW(obj);
684     object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_BLK);
685     object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
686 }
687 
688 static int virtio_ccw_serial_init(VirtioCcwDevice *ccw_dev)
689 {
690     VirtioSerialCcw *dev = VIRTIO_SERIAL_CCW(ccw_dev);
691     DeviceState *vdev = DEVICE(&dev->vdev);
692     DeviceState *proxy = DEVICE(ccw_dev);
693     char *bus_name;
694 
695     /*
696      * For command line compatibility, this sets the virtio-serial-device bus
697      * name as before.
698      */
699     if (proxy->id) {
700         bus_name = g_strdup_printf("%s.0", proxy->id);
701         virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name);
702         g_free(bus_name);
703     }
704 
705     qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
706     if (qdev_init(vdev) < 0) {
707         return -1;
708     }
709 
710     return virtio_ccw_device_init(ccw_dev, VIRTIO_DEVICE(vdev));
711 }
712 
713 
714 static void virtio_ccw_serial_instance_init(Object *obj)
715 {
716     VirtioSerialCcw *dev = VIRTIO_SERIAL_CCW(obj);
717     object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_SERIAL);
718     object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
719 }
720 
721 static int virtio_ccw_balloon_init(VirtioCcwDevice *ccw_dev)
722 {
723     VirtIOBalloonCcw *dev = VIRTIO_BALLOON_CCW(ccw_dev);
724     DeviceState *vdev = DEVICE(&dev->vdev);
725 
726     qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
727     if (qdev_init(vdev) < 0) {
728         return -1;
729     }
730 
731     return virtio_ccw_device_init(ccw_dev, VIRTIO_DEVICE(vdev));
732 }
733 
734 static void balloon_ccw_stats_get_all(Object *obj, struct Visitor *v,
735                                       void *opaque, const char *name,
736                                       Error **errp)
737 {
738     VirtIOBalloonCcw *dev = opaque;
739     object_property_get(OBJECT(&dev->vdev), v, "guest-stats", errp);
740 }
741 
742 static void balloon_ccw_stats_get_poll_interval(Object *obj, struct Visitor *v,
743                                                 void *opaque, const char *name,
744                                                 Error **errp)
745 {
746     VirtIOBalloonCcw *dev = opaque;
747     object_property_get(OBJECT(&dev->vdev), v, "guest-stats-polling-interval",
748                         errp);
749 }
750 
751 static void balloon_ccw_stats_set_poll_interval(Object *obj, struct Visitor *v,
752                                                 void *opaque, const char *name,
753                                                 Error **errp)
754 {
755     VirtIOBalloonCcw *dev = opaque;
756     object_property_set(OBJECT(&dev->vdev), v, "guest-stats-polling-interval",
757                         errp);
758 }
759 
760 static void virtio_ccw_balloon_instance_init(Object *obj)
761 {
762     VirtIOBalloonCcw *dev = VIRTIO_BALLOON_CCW(obj);
763     object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_BALLOON);
764     object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
765 
766     object_property_add(obj, "guest-stats", "guest statistics",
767                         balloon_ccw_stats_get_all, NULL, NULL, dev, NULL);
768 
769     object_property_add(obj, "guest-stats-polling-interval", "int",
770                         balloon_ccw_stats_get_poll_interval,
771                         balloon_ccw_stats_set_poll_interval,
772                         NULL, dev, NULL);
773 }
774 
775 static int virtio_ccw_scsi_init(VirtioCcwDevice *ccw_dev)
776 {
777     VirtIOSCSICcw *dev = VIRTIO_SCSI_CCW(ccw_dev);
778     DeviceState *vdev = DEVICE(&dev->vdev);
779     DeviceState *qdev = DEVICE(ccw_dev);
780     char *bus_name;
781 
782     /*
783      * For command line compatibility, this sets the virtio-scsi-device bus
784      * name as before.
785      */
786     if (qdev->id) {
787         bus_name = g_strdup_printf("%s.0", qdev->id);
788         virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name);
789         g_free(bus_name);
790     }
791 
792     qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
793     if (qdev_init(vdev) < 0) {
794         return -1;
795     }
796 
797     return virtio_ccw_device_init(ccw_dev, VIRTIO_DEVICE(vdev));
798 }
799 
800 static void virtio_ccw_scsi_instance_init(Object *obj)
801 {
802     VirtIOSCSICcw *dev = VIRTIO_SCSI_CCW(obj);
803     object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_SCSI);
804     object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
805 }
806 
807 #ifdef CONFIG_VHOST_SCSI
808 static int vhost_ccw_scsi_init(VirtioCcwDevice *ccw_dev)
809 {
810     VHostSCSICcw *dev = VHOST_SCSI_CCW(ccw_dev);
811     DeviceState *vdev = DEVICE(&dev->vdev);
812 
813     qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
814     if (qdev_init(vdev) < 0) {
815         return -1;
816     }
817 
818     return virtio_ccw_device_init(ccw_dev, VIRTIO_DEVICE(vdev));
819 }
820 
821 static void vhost_ccw_scsi_instance_init(Object *obj)
822 {
823     VHostSCSICcw *dev = VHOST_SCSI_CCW(obj);
824     object_initialize(OBJECT(&dev->vdev), TYPE_VHOST_SCSI);
825     object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
826 }
827 #endif
828 
829 static int virtio_ccw_rng_init(VirtioCcwDevice *ccw_dev)
830 {
831     VirtIORNGCcw *dev = VIRTIO_RNG_CCW(ccw_dev);
832     DeviceState *vdev = DEVICE(&dev->vdev);
833 
834     qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
835     if (qdev_init(vdev) < 0) {
836         return -1;
837     }
838 
839     object_property_set_link(OBJECT(dev),
840                              OBJECT(dev->vdev.conf.rng), "rng",
841                              NULL);
842 
843     return virtio_ccw_device_init(ccw_dev, VIRTIO_DEVICE(vdev));
844 }
845 
846 /* DeviceState to VirtioCcwDevice. Note: used on datapath,
847  * be careful and test performance if you change this.
848  */
849 static inline VirtioCcwDevice *to_virtio_ccw_dev_fast(DeviceState *d)
850 {
851     return container_of(d, VirtioCcwDevice, parent_obj);
852 }
853 
854 static void virtio_ccw_notify(DeviceState *d, uint16_t vector)
855 {
856     VirtioCcwDevice *dev = to_virtio_ccw_dev_fast(d);
857     SubchDev *sch = dev->sch;
858     uint64_t indicators;
859 
860     if (vector >= 128) {
861         return;
862     }
863 
864     if (vector < VIRTIO_PCI_QUEUE_MAX) {
865         if (!dev->indicators) {
866             return;
867         }
868         indicators = ldq_phys(dev->indicators);
869         indicators |= 1ULL << vector;
870         stq_phys(dev->indicators, indicators);
871     } else {
872         if (!dev->indicators2) {
873             return;
874         }
875         vector = 0;
876         indicators = ldq_phys(dev->indicators2);
877         indicators |= 1ULL << vector;
878         stq_phys(dev->indicators2, indicators);
879     }
880 
881     css_conditional_io_interrupt(sch);
882 
883 }
884 
885 static unsigned virtio_ccw_get_features(DeviceState *d)
886 {
887     VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
888 
889     /* Only the first 32 feature bits are used. */
890     return dev->host_features[0];
891 }
892 
893 static void virtio_ccw_reset(DeviceState *d)
894 {
895     VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
896 
897     virtio_ccw_stop_ioeventfd(dev);
898     virtio_reset(dev->vdev);
899     css_reset_sch(dev->sch);
900     dev->indicators = 0;
901     dev->indicators2 = 0;
902 }
903 
904 static void virtio_ccw_vmstate_change(DeviceState *d, bool running)
905 {
906     VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
907 
908     if (running) {
909         virtio_ccw_start_ioeventfd(dev);
910     } else {
911         virtio_ccw_stop_ioeventfd(dev);
912     }
913 }
914 
915 static bool virtio_ccw_query_guest_notifiers(DeviceState *d)
916 {
917     VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
918 
919     return !!(dev->sch->curr_status.pmcw.flags & PMCW_FLAGS_MASK_ENA);
920 }
921 
922 static int virtio_ccw_set_host_notifier(DeviceState *d, int n, bool assign)
923 {
924     VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
925 
926     /* Stop using the generic ioeventfd, we are doing eventfd handling
927      * ourselves below */
928     dev->ioeventfd_disabled = assign;
929     if (assign) {
930         virtio_ccw_stop_ioeventfd(dev);
931     }
932     return virtio_ccw_set_guest2host_notifier(dev, n, assign, false);
933 }
934 
935 static int virtio_ccw_set_guest_notifier(VirtioCcwDevice *dev, int n,
936                                          bool assign, bool with_irqfd)
937 {
938     VirtQueue *vq = virtio_get_queue(dev->vdev, n);
939     EventNotifier *notifier = virtio_queue_get_guest_notifier(vq);
940     VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(dev->vdev);
941 
942     if (assign) {
943         int r = event_notifier_init(notifier, 0);
944 
945         if (r < 0) {
946             return r;
947         }
948         virtio_queue_set_guest_notifier_fd_handler(vq, true, with_irqfd);
949         /* We do not support irqfd for classic I/O interrupts, because the
950          * classic interrupts are intermixed with the subchannel status, that
951          * is queried with test subchannel. We want to use vhost, though.
952          * Lets make sure to have vhost running and wire up the irq fd to
953          * land in qemu (and only the irq fd) in this code.
954          */
955         if (k->guest_notifier_mask) {
956             k->guest_notifier_mask(dev->vdev, n, false);
957         }
958         /* get lost events and re-inject */
959         if (k->guest_notifier_pending &&
960             k->guest_notifier_pending(dev->vdev, n)) {
961             event_notifier_set(notifier);
962         }
963     } else {
964         if (k->guest_notifier_mask) {
965             k->guest_notifier_mask(dev->vdev, n, true);
966         }
967         virtio_queue_set_guest_notifier_fd_handler(vq, false, with_irqfd);
968         event_notifier_cleanup(notifier);
969     }
970     return 0;
971 }
972 
973 static int virtio_ccw_set_guest_notifiers(DeviceState *d, int nvqs,
974                                           bool assigned)
975 {
976     VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
977     VirtIODevice *vdev = dev->vdev;
978     int r, n;
979 
980     for (n = 0; n < nvqs; n++) {
981         if (!virtio_queue_get_num(vdev, n)) {
982             break;
983         }
984         /* false -> true, as soon as irqfd works */
985         r = virtio_ccw_set_guest_notifier(dev, n, assigned, false);
986         if (r < 0) {
987             goto assign_error;
988         }
989     }
990     return 0;
991 
992 assign_error:
993     while (--n >= 0) {
994         virtio_ccw_set_guest_notifier(dev, n, !assigned, false);
995     }
996     return r;
997 }
998 
999 /**************** Virtio-ccw Bus Device Descriptions *******************/
1000 
1001 static Property virtio_ccw_net_properties[] = {
1002     DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
1003     DEFINE_VIRTIO_NET_FEATURES(VirtioCcwDevice, host_features[0]),
1004     DEFINE_VIRTIO_NET_PROPERTIES(VirtIONetCcw, vdev.net_conf),
1005     DEFINE_NIC_PROPERTIES(VirtIONetCcw, vdev.nic_conf),
1006     DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
1007                     VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1008     DEFINE_PROP_END_OF_LIST(),
1009 };
1010 
1011 static void virtio_ccw_net_class_init(ObjectClass *klass, void *data)
1012 {
1013     DeviceClass *dc = DEVICE_CLASS(klass);
1014     VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1015 
1016     k->init = virtio_ccw_net_init;
1017     k->exit = virtio_ccw_exit;
1018     dc->reset = virtio_ccw_reset;
1019     dc->props = virtio_ccw_net_properties;
1020 }
1021 
1022 static const TypeInfo virtio_ccw_net = {
1023     .name          = TYPE_VIRTIO_NET_CCW,
1024     .parent        = TYPE_VIRTIO_CCW_DEVICE,
1025     .instance_size = sizeof(VirtIONetCcw),
1026     .instance_init = virtio_ccw_net_instance_init,
1027     .class_init    = virtio_ccw_net_class_init,
1028 };
1029 
1030 static Property virtio_ccw_blk_properties[] = {
1031     DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
1032     DEFINE_VIRTIO_BLK_FEATURES(VirtioCcwDevice, host_features[0]),
1033     DEFINE_VIRTIO_BLK_PROPERTIES(VirtIOBlkCcw, blk),
1034     DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
1035                     VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1036     DEFINE_PROP_END_OF_LIST(),
1037 };
1038 
1039 static void virtio_ccw_blk_class_init(ObjectClass *klass, void *data)
1040 {
1041     DeviceClass *dc = DEVICE_CLASS(klass);
1042     VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1043 
1044     k->init = virtio_ccw_blk_init;
1045     k->exit = virtio_ccw_exit;
1046     dc->reset = virtio_ccw_reset;
1047     dc->props = virtio_ccw_blk_properties;
1048 }
1049 
1050 static const TypeInfo virtio_ccw_blk = {
1051     .name          = TYPE_VIRTIO_BLK_CCW,
1052     .parent        = TYPE_VIRTIO_CCW_DEVICE,
1053     .instance_size = sizeof(VirtIOBlkCcw),
1054     .instance_init = virtio_ccw_blk_instance_init,
1055     .class_init    = virtio_ccw_blk_class_init,
1056 };
1057 
1058 static Property virtio_ccw_serial_properties[] = {
1059     DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
1060     DEFINE_VIRTIO_SERIAL_PROPERTIES(VirtioSerialCcw, vdev.serial),
1061     DEFINE_VIRTIO_COMMON_FEATURES(VirtioCcwDevice, host_features[0]),
1062     DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
1063                     VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1064     DEFINE_PROP_END_OF_LIST(),
1065 };
1066 
1067 static void virtio_ccw_serial_class_init(ObjectClass *klass, void *data)
1068 {
1069     DeviceClass *dc = DEVICE_CLASS(klass);
1070     VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1071 
1072     k->init = virtio_ccw_serial_init;
1073     k->exit = virtio_ccw_exit;
1074     dc->reset = virtio_ccw_reset;
1075     dc->props = virtio_ccw_serial_properties;
1076 }
1077 
1078 static const TypeInfo virtio_ccw_serial = {
1079     .name          = TYPE_VIRTIO_SERIAL_CCW,
1080     .parent        = TYPE_VIRTIO_CCW_DEVICE,
1081     .instance_size = sizeof(VirtioSerialCcw),
1082     .instance_init = virtio_ccw_serial_instance_init,
1083     .class_init    = virtio_ccw_serial_class_init,
1084 };
1085 
1086 static Property virtio_ccw_balloon_properties[] = {
1087     DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
1088     DEFINE_VIRTIO_COMMON_FEATURES(VirtioCcwDevice, host_features[0]),
1089     DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
1090                     VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1091     DEFINE_PROP_END_OF_LIST(),
1092 };
1093 
1094 static void virtio_ccw_balloon_class_init(ObjectClass *klass, void *data)
1095 {
1096     DeviceClass *dc = DEVICE_CLASS(klass);
1097     VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1098 
1099     k->init = virtio_ccw_balloon_init;
1100     k->exit = virtio_ccw_exit;
1101     dc->reset = virtio_ccw_reset;
1102     dc->props = virtio_ccw_balloon_properties;
1103 }
1104 
1105 static const TypeInfo virtio_ccw_balloon = {
1106     .name          = TYPE_VIRTIO_BALLOON_CCW,
1107     .parent        = TYPE_VIRTIO_CCW_DEVICE,
1108     .instance_size = sizeof(VirtIOBalloonCcw),
1109     .instance_init = virtio_ccw_balloon_instance_init,
1110     .class_init    = virtio_ccw_balloon_class_init,
1111 };
1112 
1113 static Property virtio_ccw_scsi_properties[] = {
1114     DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
1115     DEFINE_VIRTIO_SCSI_PROPERTIES(VirtIOSCSICcw, vdev.parent_obj.conf),
1116     DEFINE_VIRTIO_SCSI_FEATURES(VirtioCcwDevice, host_features[0]),
1117     DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
1118                     VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1119     DEFINE_PROP_END_OF_LIST(),
1120 };
1121 
1122 static void virtio_ccw_scsi_class_init(ObjectClass *klass, void *data)
1123 {
1124     DeviceClass *dc = DEVICE_CLASS(klass);
1125     VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1126 
1127     k->init = virtio_ccw_scsi_init;
1128     k->exit = virtio_ccw_exit;
1129     dc->reset = virtio_ccw_reset;
1130     dc->props = virtio_ccw_scsi_properties;
1131 }
1132 
1133 static const TypeInfo virtio_ccw_scsi = {
1134     .name          = TYPE_VIRTIO_SCSI_CCW,
1135     .parent        = TYPE_VIRTIO_CCW_DEVICE,
1136     .instance_size = sizeof(VirtIOSCSICcw),
1137     .instance_init = virtio_ccw_scsi_instance_init,
1138     .class_init    = virtio_ccw_scsi_class_init,
1139 };
1140 
1141 #ifdef CONFIG_VHOST_SCSI
1142 static Property vhost_ccw_scsi_properties[] = {
1143     DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
1144     DEFINE_VHOST_SCSI_PROPERTIES(VirtIOSCSICcw, vdev.parent_obj.conf),
1145     DEFINE_VIRTIO_COMMON_FEATURES(VirtioCcwDevice, host_features[0]),
1146     DEFINE_PROP_END_OF_LIST(),
1147 };
1148 
1149 static void vhost_ccw_scsi_class_init(ObjectClass *klass, void *data)
1150 {
1151     DeviceClass *dc = DEVICE_CLASS(klass);
1152     VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1153 
1154     k->init = vhost_ccw_scsi_init;
1155     k->exit = virtio_ccw_exit;
1156     dc->reset = virtio_ccw_reset;
1157     dc->props = vhost_ccw_scsi_properties;
1158 }
1159 
1160 static const TypeInfo vhost_ccw_scsi = {
1161     .name          = TYPE_VHOST_SCSI_CCW,
1162     .parent        = TYPE_VIRTIO_CCW_DEVICE,
1163     .instance_size = sizeof(VirtIOSCSICcw),
1164     .instance_init = vhost_ccw_scsi_instance_init,
1165     .class_init    = vhost_ccw_scsi_class_init,
1166 };
1167 #endif
1168 
1169 static void virtio_ccw_rng_instance_init(Object *obj)
1170 {
1171     VirtIORNGCcw *dev = VIRTIO_RNG_CCW(obj);
1172     object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_RNG);
1173     object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
1174     object_property_add_link(obj, "rng", TYPE_RNG_BACKEND,
1175                              (Object **)&dev->vdev.conf.rng, NULL);
1176 }
1177 
1178 static Property virtio_ccw_rng_properties[] = {
1179     DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
1180     DEFINE_VIRTIO_COMMON_FEATURES(VirtioCcwDevice, host_features[0]),
1181     DEFINE_VIRTIO_RNG_PROPERTIES(VirtIORNGCcw, vdev.conf),
1182     DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
1183                     VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1184     DEFINE_PROP_END_OF_LIST(),
1185 };
1186 
1187 static void virtio_ccw_rng_class_init(ObjectClass *klass, void *data)
1188 {
1189     DeviceClass *dc = DEVICE_CLASS(klass);
1190     VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1191 
1192     k->init = virtio_ccw_rng_init;
1193     k->exit = virtio_ccw_exit;
1194     dc->reset = virtio_ccw_reset;
1195     dc->props = virtio_ccw_rng_properties;
1196 }
1197 
1198 static const TypeInfo virtio_ccw_rng = {
1199     .name          = TYPE_VIRTIO_RNG_CCW,
1200     .parent        = TYPE_VIRTIO_CCW_DEVICE,
1201     .instance_size = sizeof(VirtIORNGCcw),
1202     .instance_init = virtio_ccw_rng_instance_init,
1203     .class_init    = virtio_ccw_rng_class_init,
1204 };
1205 
1206 static int virtio_ccw_busdev_init(DeviceState *dev)
1207 {
1208     VirtioCcwDevice *_dev = (VirtioCcwDevice *)dev;
1209     VirtIOCCWDeviceClass *_info = VIRTIO_CCW_DEVICE_GET_CLASS(dev);
1210 
1211     virtio_ccw_bus_new(&_dev->bus, _dev);
1212 
1213     return _info->init(_dev);
1214 }
1215 
1216 static int virtio_ccw_busdev_exit(DeviceState *dev)
1217 {
1218     VirtioCcwDevice *_dev = (VirtioCcwDevice *)dev;
1219     VirtIOCCWDeviceClass *_info = VIRTIO_CCW_DEVICE_GET_CLASS(dev);
1220 
1221     return _info->exit(_dev);
1222 }
1223 
1224 static int virtio_ccw_busdev_unplug(DeviceState *dev)
1225 {
1226     VirtioCcwDevice *_dev = (VirtioCcwDevice *)dev;
1227     SubchDev *sch = _dev->sch;
1228 
1229     /*
1230      * We should arrive here only for device_del, since we don't support
1231      * direct hot(un)plug of channels, but only through virtio.
1232      */
1233     assert(sch != NULL);
1234     /* Subchannel is now disabled and no longer valid. */
1235     sch->curr_status.pmcw.flags &= ~(PMCW_FLAGS_MASK_ENA |
1236                                      PMCW_FLAGS_MASK_DNV);
1237 
1238     css_generate_sch_crws(sch->cssid, sch->ssid, sch->schid, 1, 0);
1239 
1240     qdev_free(dev);
1241     return 0;
1242 }
1243 
1244 static void virtio_ccw_device_class_init(ObjectClass *klass, void *data)
1245 {
1246     DeviceClass *dc = DEVICE_CLASS(klass);
1247 
1248     dc->init = virtio_ccw_busdev_init;
1249     dc->exit = virtio_ccw_busdev_exit;
1250     dc->unplug = virtio_ccw_busdev_unplug;
1251     dc->bus_type = TYPE_VIRTUAL_CSS_BUS;
1252 
1253 }
1254 
1255 static const TypeInfo virtio_ccw_device_info = {
1256     .name = TYPE_VIRTIO_CCW_DEVICE,
1257     .parent = TYPE_DEVICE,
1258     .instance_size = sizeof(VirtioCcwDevice),
1259     .class_init = virtio_ccw_device_class_init,
1260     .class_size = sizeof(VirtIOCCWDeviceClass),
1261     .abstract = true,
1262 };
1263 
1264 /***************** Virtual-css Bus Bridge Device ********************/
1265 /* Only required to have the virtio bus as child in the system bus */
1266 
1267 static int virtual_css_bridge_init(SysBusDevice *dev)
1268 {
1269     /* nothing */
1270     return 0;
1271 }
1272 
1273 static void virtual_css_bridge_class_init(ObjectClass *klass, void *data)
1274 {
1275     DeviceClass *dc = DEVICE_CLASS(klass);
1276     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
1277 
1278     k->init = virtual_css_bridge_init;
1279     dc->no_user = 1;
1280 }
1281 
1282 static const TypeInfo virtual_css_bridge_info = {
1283     .name          = "virtual-css-bridge",
1284     .parent        = TYPE_SYS_BUS_DEVICE,
1285     .instance_size = sizeof(SysBusDevice),
1286     .class_init    = virtual_css_bridge_class_init,
1287 };
1288 
1289 /* virtio-ccw-bus */
1290 
1291 static void virtio_ccw_bus_new(VirtioBusState *bus, VirtioCcwDevice *dev)
1292 {
1293     DeviceState *qdev = DEVICE(dev);
1294     BusState *qbus;
1295     char virtio_bus_name[] = "virtio-bus";
1296 
1297     qbus_create_inplace((BusState *)bus, TYPE_VIRTIO_CCW_BUS, qdev,
1298                         virtio_bus_name);
1299     qbus = BUS(bus);
1300     qbus->allow_hotplug = 1;
1301 }
1302 
1303 static void virtio_ccw_bus_class_init(ObjectClass *klass, void *data)
1304 {
1305     VirtioBusClass *k = VIRTIO_BUS_CLASS(klass);
1306     BusClass *bus_class = BUS_CLASS(klass);
1307 
1308     bus_class->max_dev = 1;
1309     k->notify = virtio_ccw_notify;
1310     k->get_features = virtio_ccw_get_features;
1311     k->vmstate_change = virtio_ccw_vmstate_change;
1312     k->query_guest_notifiers = virtio_ccw_query_guest_notifiers;
1313     k->set_host_notifier = virtio_ccw_set_host_notifier;
1314     k->set_guest_notifiers = virtio_ccw_set_guest_notifiers;
1315 }
1316 
1317 static const TypeInfo virtio_ccw_bus_info = {
1318     .name = TYPE_VIRTIO_CCW_BUS,
1319     .parent = TYPE_VIRTIO_BUS,
1320     .instance_size = sizeof(VirtioCcwBusState),
1321     .class_init = virtio_ccw_bus_class_init,
1322 };
1323 
1324 static void virtio_ccw_register(void)
1325 {
1326     type_register_static(&virtio_ccw_bus_info);
1327     type_register_static(&virtual_css_bus_info);
1328     type_register_static(&virtio_ccw_device_info);
1329     type_register_static(&virtio_ccw_serial);
1330     type_register_static(&virtio_ccw_blk);
1331     type_register_static(&virtio_ccw_net);
1332     type_register_static(&virtio_ccw_balloon);
1333     type_register_static(&virtio_ccw_scsi);
1334 #ifdef CONFIG_VHOST_SCSI
1335     type_register_static(&vhost_ccw_scsi);
1336 #endif
1337     type_register_static(&virtio_ccw_rng);
1338     type_register_static(&virtual_css_bridge_info);
1339 }
1340 
1341 type_init(virtio_ccw_register)
1342