virtio-ccw: fix sanity check for vector
[qemu/kevin.git] / hw / s390x / virtio-ccw.c
blob95a6c142b8a5cf4eb8016be2a652d840d1cff48d
1 /*
2 * virtio ccw target implementation
4 * Copyright 2012,2015 IBM Corp.
5 * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
6 * Pierre Morel <pmorel@linux.vnet.ibm.com>
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.
13 #include "hw/hw.h"
14 #include "sysemu/block-backend.h"
15 #include "sysemu/blockdev.h"
16 #include "sysemu/sysemu.h"
17 #include "net/net.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 "qemu/error-report.h"
24 #include "hw/virtio/virtio-access.h"
25 #include "hw/virtio/virtio-bus.h"
26 #include "hw/s390x/adapter.h"
27 #include "hw/s390x/s390_flic.h"
29 #include "ioinst.h"
30 #include "css.h"
31 #include "virtio-ccw.h"
32 #include "trace.h"
34 static QTAILQ_HEAD(, IndAddr) indicator_addresses =
35 QTAILQ_HEAD_INITIALIZER(indicator_addresses);
37 static IndAddr *get_indicator(hwaddr ind_addr, int len)
39 IndAddr *indicator;
41 QTAILQ_FOREACH(indicator, &indicator_addresses, sibling) {
42 if (indicator->addr == ind_addr) {
43 indicator->refcnt++;
44 return indicator;
47 indicator = g_new0(IndAddr, 1);
48 indicator->addr = ind_addr;
49 indicator->len = len;
50 indicator->refcnt = 1;
51 QTAILQ_INSERT_TAIL(&indicator_addresses, indicator, sibling);
52 return indicator;
55 static int s390_io_adapter_map(AdapterInfo *adapter, uint64_t map_addr,
56 bool do_map)
58 S390FLICState *fs = s390_get_flic();
59 S390FLICStateClass *fsc = S390_FLIC_COMMON_GET_CLASS(fs);
61 return fsc->io_adapter_map(fs, adapter->adapter_id, map_addr, do_map);
64 static void release_indicator(AdapterInfo *adapter, IndAddr *indicator)
66 assert(indicator->refcnt > 0);
67 indicator->refcnt--;
68 if (indicator->refcnt > 0) {
69 return;
71 QTAILQ_REMOVE(&indicator_addresses, indicator, sibling);
72 if (indicator->map) {
73 s390_io_adapter_map(adapter, indicator->map, false);
75 g_free(indicator);
78 static int map_indicator(AdapterInfo *adapter, IndAddr *indicator)
80 int ret;
82 if (indicator->map) {
83 return 0; /* already mapped is not an error */
85 indicator->map = indicator->addr;
86 ret = s390_io_adapter_map(adapter, indicator->map, true);
87 if ((ret != 0) && (ret != -ENOSYS)) {
88 goto out_err;
90 return 0;
92 out_err:
93 indicator->map = 0;
94 return ret;
97 static void virtio_ccw_bus_new(VirtioBusState *bus, size_t bus_size,
98 VirtioCcwDevice *dev);
100 static void virtual_css_bus_reset(BusState *qbus)
102 /* This should actually be modelled via the generic css */
103 css_reset();
107 static void virtual_css_bus_class_init(ObjectClass *klass, void *data)
109 BusClass *k = BUS_CLASS(klass);
111 k->reset = virtual_css_bus_reset;
114 static const TypeInfo virtual_css_bus_info = {
115 .name = TYPE_VIRTUAL_CSS_BUS,
116 .parent = TYPE_BUS,
117 .instance_size = sizeof(VirtualCssBus),
118 .class_init = virtual_css_bus_class_init,
121 VirtIODevice *virtio_ccw_get_vdev(SubchDev *sch)
123 VirtIODevice *vdev = NULL;
124 VirtioCcwDevice *dev = sch->driver_data;
126 if (dev) {
127 vdev = virtio_bus_get_device(&dev->bus);
129 return vdev;
132 static int virtio_ccw_set_guest2host_notifier(VirtioCcwDevice *dev, int n,
133 bool assign, bool set_handler)
135 VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
136 VirtQueue *vq = virtio_get_queue(vdev, n);
137 EventNotifier *notifier = virtio_queue_get_host_notifier(vq);
138 int r = 0;
139 SubchDev *sch = dev->sch;
140 uint32_t sch_id = (css_build_subchannel_id(sch) << 16) | sch->schid;
142 if (assign) {
143 r = event_notifier_init(notifier, 1);
144 if (r < 0) {
145 error_report("%s: unable to init event notifier: %d", __func__, r);
146 return r;
148 virtio_queue_set_host_notifier_fd_handler(vq, true, set_handler);
149 r = s390_assign_subch_ioeventfd(notifier, sch_id, n, assign);
150 if (r < 0) {
151 error_report("%s: unable to assign ioeventfd: %d", __func__, r);
152 virtio_queue_set_host_notifier_fd_handler(vq, false, false);
153 event_notifier_cleanup(notifier);
154 return r;
156 } else {
157 virtio_queue_set_host_notifier_fd_handler(vq, false, false);
158 s390_assign_subch_ioeventfd(notifier, sch_id, n, assign);
159 event_notifier_cleanup(notifier);
161 return r;
164 static void virtio_ccw_start_ioeventfd(VirtioCcwDevice *dev)
166 VirtIODevice *vdev;
167 int n, r;
169 if (!(dev->flags & VIRTIO_CCW_FLAG_USE_IOEVENTFD) ||
170 dev->ioeventfd_disabled ||
171 dev->ioeventfd_started) {
172 return;
174 vdev = virtio_bus_get_device(&dev->bus);
175 for (n = 0; n < VIRTIO_CCW_QUEUE_MAX; n++) {
176 if (!virtio_queue_get_num(vdev, n)) {
177 continue;
179 r = virtio_ccw_set_guest2host_notifier(dev, n, true, true);
180 if (r < 0) {
181 goto assign_error;
184 dev->ioeventfd_started = true;
185 return;
187 assign_error:
188 while (--n >= 0) {
189 if (!virtio_queue_get_num(vdev, n)) {
190 continue;
192 r = virtio_ccw_set_guest2host_notifier(dev, n, false, false);
193 assert(r >= 0);
195 dev->ioeventfd_started = false;
196 /* Disable ioeventfd for this device. */
197 dev->flags &= ~VIRTIO_CCW_FLAG_USE_IOEVENTFD;
198 error_report("%s: failed. Fallback to userspace (slower).", __func__);
201 static void virtio_ccw_stop_ioeventfd(VirtioCcwDevice *dev)
203 VirtIODevice *vdev;
204 int n, r;
206 if (!dev->ioeventfd_started) {
207 return;
209 vdev = virtio_bus_get_device(&dev->bus);
210 for (n = 0; n < VIRTIO_CCW_QUEUE_MAX; n++) {
211 if (!virtio_queue_get_num(vdev, n)) {
212 continue;
214 r = virtio_ccw_set_guest2host_notifier(dev, n, false, false);
215 assert(r >= 0);
217 dev->ioeventfd_started = false;
220 VirtualCssBus *virtual_css_bus_init(void)
222 VirtualCssBus *cbus;
223 BusState *bus;
224 DeviceState *dev;
226 /* Create bridge device */
227 dev = qdev_create(NULL, "virtual-css-bridge");
228 qdev_init_nofail(dev);
230 /* Create bus on bridge device */
231 bus = qbus_create(TYPE_VIRTUAL_CSS_BUS, dev, "virtual-css");
232 cbus = VIRTUAL_CSS_BUS(bus);
234 /* Enable hotplugging */
235 qbus_set_hotplug_handler(bus, dev, &error_abort);
237 return cbus;
240 /* Communication blocks used by several channel commands. */
241 typedef struct VqInfoBlockLegacy {
242 uint64_t queue;
243 uint32_t align;
244 uint16_t index;
245 uint16_t num;
246 } QEMU_PACKED VqInfoBlockLegacy;
248 typedef struct VqInfoBlock {
249 uint64_t desc;
250 uint32_t res0;
251 uint16_t index;
252 uint16_t num;
253 uint64_t avail;
254 uint64_t used;
255 } QEMU_PACKED VqInfoBlock;
257 typedef struct VqConfigBlock {
258 uint16_t index;
259 uint16_t num_max;
260 } QEMU_PACKED VqConfigBlock;
262 typedef struct VirtioFeatDesc {
263 uint32_t features;
264 uint8_t index;
265 } QEMU_PACKED VirtioFeatDesc;
267 typedef struct VirtioThinintInfo {
268 hwaddr summary_indicator;
269 hwaddr device_indicator;
270 uint64_t ind_bit;
271 uint8_t isc;
272 } QEMU_PACKED VirtioThinintInfo;
274 typedef struct VirtioRevInfo {
275 uint16_t revision;
276 uint16_t length;
277 uint8_t data[0];
278 } QEMU_PACKED VirtioRevInfo;
280 /* Specify where the virtqueues for the subchannel are in guest memory. */
281 static int virtio_ccw_set_vqs(SubchDev *sch, VqInfoBlock *info,
282 VqInfoBlockLegacy *linfo)
284 VirtIODevice *vdev = virtio_ccw_get_vdev(sch);
285 uint16_t index = info ? info->index : linfo->index;
286 uint16_t num = info ? info->num : linfo->num;
287 uint64_t desc = info ? info->desc : linfo->queue;
289 if (index >= VIRTIO_CCW_QUEUE_MAX) {
290 return -EINVAL;
293 /* Current code in virtio.c relies on 4K alignment. */
294 if (linfo && desc && (linfo->align != 4096)) {
295 return -EINVAL;
298 if (!vdev) {
299 return -EINVAL;
302 if (info) {
303 virtio_queue_set_rings(vdev, index, desc, info->avail, info->used);
304 } else {
305 virtio_queue_set_addr(vdev, index, desc);
307 if (!desc) {
308 virtio_queue_set_vector(vdev, index, VIRTIO_NO_VECTOR);
309 } else {
310 if (info) {
311 /* virtio-1 allows changing the ring size. */
312 if (virtio_queue_get_num(vdev, index) < num) {
313 /* Fail if we exceed the maximum number. */
314 return -EINVAL;
316 virtio_queue_set_num(vdev, index, num);
317 } else if (virtio_queue_get_num(vdev, index) > num) {
318 /* Fail if we don't have a big enough queue. */
319 return -EINVAL;
321 /* We ignore possible increased num for legacy for compatibility. */
322 virtio_queue_set_vector(vdev, index, index);
324 /* tell notify handler in case of config change */
325 vdev->config_vector = VIRTIO_CCW_QUEUE_MAX;
326 return 0;
329 static void virtio_ccw_reset_virtio(VirtioCcwDevice *dev, VirtIODevice *vdev)
331 virtio_ccw_stop_ioeventfd(dev);
332 virtio_reset(vdev);
333 if (dev->indicators) {
334 release_indicator(&dev->routes.adapter, dev->indicators);
335 dev->indicators = NULL;
337 if (dev->indicators2) {
338 release_indicator(&dev->routes.adapter, dev->indicators2);
339 dev->indicators2 = NULL;
341 if (dev->summary_indicator) {
342 release_indicator(&dev->routes.adapter, dev->summary_indicator);
343 dev->summary_indicator = NULL;
345 dev->sch->thinint_active = false;
348 static int virtio_ccw_handle_set_vq(SubchDev *sch, CCW1 ccw, bool check_len,
349 bool is_legacy)
351 int ret;
352 VqInfoBlock info;
353 VqInfoBlockLegacy linfo;
354 size_t info_len = is_legacy ? sizeof(linfo) : sizeof(info);
356 if (check_len) {
357 if (ccw.count != info_len) {
358 return -EINVAL;
360 } else if (ccw.count < info_len) {
361 /* Can't execute command. */
362 return -EINVAL;
364 if (!ccw.cda) {
365 return -EFAULT;
367 if (is_legacy) {
368 linfo.queue = address_space_ldq_be(&address_space_memory, ccw.cda,
369 MEMTXATTRS_UNSPECIFIED, NULL);
370 linfo.align = address_space_ldl_be(&address_space_memory,
371 ccw.cda + sizeof(linfo.queue),
372 MEMTXATTRS_UNSPECIFIED,
373 NULL);
374 linfo.index = address_space_lduw_be(&address_space_memory,
375 ccw.cda + sizeof(linfo.queue)
376 + sizeof(linfo.align),
377 MEMTXATTRS_UNSPECIFIED,
378 NULL);
379 linfo.num = address_space_lduw_be(&address_space_memory,
380 ccw.cda + sizeof(linfo.queue)
381 + sizeof(linfo.align)
382 + sizeof(linfo.index),
383 MEMTXATTRS_UNSPECIFIED,
384 NULL);
385 ret = virtio_ccw_set_vqs(sch, NULL, &linfo);
386 } else {
387 info.desc = address_space_ldq_be(&address_space_memory, ccw.cda,
388 MEMTXATTRS_UNSPECIFIED, NULL);
389 info.index = address_space_lduw_be(&address_space_memory,
390 ccw.cda + sizeof(info.desc)
391 + sizeof(info.res0),
392 MEMTXATTRS_UNSPECIFIED, NULL);
393 info.num = address_space_lduw_be(&address_space_memory,
394 ccw.cda + sizeof(info.desc)
395 + sizeof(info.res0)
396 + sizeof(info.index),
397 MEMTXATTRS_UNSPECIFIED, NULL);
398 info.avail = address_space_ldq_be(&address_space_memory,
399 ccw.cda + sizeof(info.desc)
400 + sizeof(info.res0)
401 + sizeof(info.index)
402 + sizeof(info.num),
403 MEMTXATTRS_UNSPECIFIED, NULL);
404 info.used = address_space_ldq_be(&address_space_memory,
405 ccw.cda + sizeof(info.desc)
406 + sizeof(info.res0)
407 + sizeof(info.index)
408 + sizeof(info.num)
409 + sizeof(info.avail),
410 MEMTXATTRS_UNSPECIFIED, NULL);
411 ret = virtio_ccw_set_vqs(sch, &info, NULL);
413 sch->curr_status.scsw.count = 0;
414 return ret;
417 static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
419 int ret;
420 VirtioRevInfo revinfo;
421 uint8_t status;
422 VirtioFeatDesc features;
423 void *config;
424 hwaddr indicators;
425 VqConfigBlock vq_config;
426 VirtioCcwDevice *dev = sch->driver_data;
427 VirtIODevice *vdev = virtio_ccw_get_vdev(sch);
428 bool check_len;
429 int len;
430 hwaddr hw_len;
431 VirtioThinintInfo *thinint;
433 if (!dev) {
434 return -EINVAL;
437 trace_virtio_ccw_interpret_ccw(sch->cssid, sch->ssid, sch->schid,
438 ccw.cmd_code);
439 check_len = !((ccw.flags & CCW_FLAG_SLI) && !(ccw.flags & CCW_FLAG_DC));
441 /* Look at the command. */
442 switch (ccw.cmd_code) {
443 case CCW_CMD_SET_VQ:
444 ret = virtio_ccw_handle_set_vq(sch, ccw, check_len, dev->revision < 1);
445 break;
446 case CCW_CMD_VDEV_RESET:
447 virtio_ccw_reset_virtio(dev, vdev);
448 ret = 0;
449 break;
450 case CCW_CMD_READ_FEAT:
451 if (check_len) {
452 if (ccw.count != sizeof(features)) {
453 ret = -EINVAL;
454 break;
456 } else if (ccw.count < sizeof(features)) {
457 /* Can't execute command. */
458 ret = -EINVAL;
459 break;
461 if (!ccw.cda) {
462 ret = -EFAULT;
463 } else {
464 features.index = address_space_ldub(&address_space_memory,
465 ccw.cda
466 + sizeof(features.features),
467 MEMTXATTRS_UNSPECIFIED,
468 NULL);
469 if (features.index == 0) {
470 if (dev->revision >= 1) {
471 /* Don't offer legacy features for modern devices. */
472 features.features = (uint32_t)
473 (vdev->host_features & ~VIRTIO_LEGACY_FEATURES);
474 } else {
475 features.features = (uint32_t)vdev->host_features;
477 } else if ((features.index == 1) && (dev->revision >= 1)) {
479 * Only offer feature bits beyond 31 if the guest has
480 * negotiated at least revision 1.
482 features.features = (uint32_t)(vdev->host_features >> 32);
483 } else {
484 /* Return zeroes if the guest supports more feature bits. */
485 features.features = 0;
487 address_space_stl_le(&address_space_memory, ccw.cda,
488 features.features, MEMTXATTRS_UNSPECIFIED,
489 NULL);
490 sch->curr_status.scsw.count = ccw.count - sizeof(features);
491 ret = 0;
493 break;
494 case CCW_CMD_WRITE_FEAT:
495 if (check_len) {
496 if (ccw.count != sizeof(features)) {
497 ret = -EINVAL;
498 break;
500 } else if (ccw.count < sizeof(features)) {
501 /* Can't execute command. */
502 ret = -EINVAL;
503 break;
505 if (!ccw.cda) {
506 ret = -EFAULT;
507 } else {
508 features.index = address_space_ldub(&address_space_memory,
509 ccw.cda
510 + sizeof(features.features),
511 MEMTXATTRS_UNSPECIFIED,
512 NULL);
513 features.features = address_space_ldl_le(&address_space_memory,
514 ccw.cda,
515 MEMTXATTRS_UNSPECIFIED,
516 NULL);
517 if (features.index == 0) {
518 virtio_set_features(vdev,
519 (vdev->guest_features & 0xffffffff00000000ULL) |
520 features.features);
521 } else if ((features.index == 1) && (dev->revision >= 1)) {
523 * If the guest did not negotiate at least revision 1,
524 * we did not offer it any feature bits beyond 31. Such a
525 * guest passing us any bit here is therefore buggy.
527 virtio_set_features(vdev,
528 (vdev->guest_features & 0x00000000ffffffffULL) |
529 ((uint64_t)features.features << 32));
530 } else {
532 * If the guest supports more feature bits, assert that it
533 * passes us zeroes for those we don't support.
535 if (features.features) {
536 fprintf(stderr, "Guest bug: features[%i]=%x (expected 0)\n",
537 features.index, features.features);
538 /* XXX: do a unit check here? */
541 sch->curr_status.scsw.count = ccw.count - sizeof(features);
542 ret = 0;
544 break;
545 case CCW_CMD_READ_CONF:
546 if (check_len) {
547 if (ccw.count > vdev->config_len) {
548 ret = -EINVAL;
549 break;
552 len = MIN(ccw.count, vdev->config_len);
553 if (!ccw.cda) {
554 ret = -EFAULT;
555 } else {
556 virtio_bus_get_vdev_config(&dev->bus, vdev->config);
557 /* XXX config space endianness */
558 cpu_physical_memory_write(ccw.cda, vdev->config, len);
559 sch->curr_status.scsw.count = ccw.count - len;
560 ret = 0;
562 break;
563 case CCW_CMD_WRITE_CONF:
564 if (check_len) {
565 if (ccw.count > vdev->config_len) {
566 ret = -EINVAL;
567 break;
570 len = MIN(ccw.count, vdev->config_len);
571 hw_len = len;
572 if (!ccw.cda) {
573 ret = -EFAULT;
574 } else {
575 config = cpu_physical_memory_map(ccw.cda, &hw_len, 0);
576 if (!config) {
577 ret = -EFAULT;
578 } else {
579 len = hw_len;
580 /* XXX config space endianness */
581 memcpy(vdev->config, config, len);
582 cpu_physical_memory_unmap(config, hw_len, 0, hw_len);
583 virtio_bus_set_vdev_config(&dev->bus, vdev->config);
584 sch->curr_status.scsw.count = ccw.count - len;
585 ret = 0;
588 break;
589 case CCW_CMD_WRITE_STATUS:
590 if (check_len) {
591 if (ccw.count != sizeof(status)) {
592 ret = -EINVAL;
593 break;
595 } else if (ccw.count < sizeof(status)) {
596 /* Can't execute command. */
597 ret = -EINVAL;
598 break;
600 if (!ccw.cda) {
601 ret = -EFAULT;
602 } else {
603 status = address_space_ldub(&address_space_memory, ccw.cda,
604 MEMTXATTRS_UNSPECIFIED, NULL);
605 if (!(status & VIRTIO_CONFIG_S_DRIVER_OK)) {
606 virtio_ccw_stop_ioeventfd(dev);
608 if (virtio_set_status(vdev, status) == 0) {
609 if (vdev->status == 0) {
610 virtio_ccw_reset_virtio(dev, vdev);
612 if (status & VIRTIO_CONFIG_S_DRIVER_OK) {
613 virtio_ccw_start_ioeventfd(dev);
615 sch->curr_status.scsw.count = ccw.count - sizeof(status);
616 ret = 0;
617 } else {
618 /* Trigger a command reject. */
619 ret = -ENOSYS;
622 break;
623 case CCW_CMD_SET_IND:
624 if (check_len) {
625 if (ccw.count != sizeof(indicators)) {
626 ret = -EINVAL;
627 break;
629 } else if (ccw.count < sizeof(indicators)) {
630 /* Can't execute command. */
631 ret = -EINVAL;
632 break;
634 if (sch->thinint_active) {
635 /* Trigger a command reject. */
636 ret = -ENOSYS;
637 break;
639 if (!ccw.cda) {
640 ret = -EFAULT;
641 } else {
642 indicators = address_space_ldq_be(&address_space_memory, ccw.cda,
643 MEMTXATTRS_UNSPECIFIED, NULL);
644 dev->indicators = get_indicator(indicators, sizeof(uint64_t));
645 sch->curr_status.scsw.count = ccw.count - sizeof(indicators);
646 ret = 0;
648 break;
649 case CCW_CMD_SET_CONF_IND:
650 if (check_len) {
651 if (ccw.count != sizeof(indicators)) {
652 ret = -EINVAL;
653 break;
655 } else if (ccw.count < sizeof(indicators)) {
656 /* Can't execute command. */
657 ret = -EINVAL;
658 break;
660 if (!ccw.cda) {
661 ret = -EFAULT;
662 } else {
663 indicators = address_space_ldq_be(&address_space_memory, ccw.cda,
664 MEMTXATTRS_UNSPECIFIED, NULL);
665 dev->indicators2 = get_indicator(indicators, sizeof(uint64_t));
666 sch->curr_status.scsw.count = ccw.count - sizeof(indicators);
667 ret = 0;
669 break;
670 case CCW_CMD_READ_VQ_CONF:
671 if (check_len) {
672 if (ccw.count != sizeof(vq_config)) {
673 ret = -EINVAL;
674 break;
676 } else if (ccw.count < sizeof(vq_config)) {
677 /* Can't execute command. */
678 ret = -EINVAL;
679 break;
681 if (!ccw.cda) {
682 ret = -EFAULT;
683 } else {
684 vq_config.index = address_space_lduw_be(&address_space_memory,
685 ccw.cda,
686 MEMTXATTRS_UNSPECIFIED,
687 NULL);
688 if (vq_config.index >= VIRTIO_CCW_QUEUE_MAX) {
689 ret = -EINVAL;
690 break;
692 vq_config.num_max = virtio_queue_get_num(vdev,
693 vq_config.index);
694 address_space_stw_be(&address_space_memory,
695 ccw.cda + sizeof(vq_config.index),
696 vq_config.num_max,
697 MEMTXATTRS_UNSPECIFIED,
698 NULL);
699 sch->curr_status.scsw.count = ccw.count - sizeof(vq_config);
700 ret = 0;
702 break;
703 case CCW_CMD_SET_IND_ADAPTER:
704 if (check_len) {
705 if (ccw.count != sizeof(*thinint)) {
706 ret = -EINVAL;
707 break;
709 } else if (ccw.count < sizeof(*thinint)) {
710 /* Can't execute command. */
711 ret = -EINVAL;
712 break;
714 len = sizeof(*thinint);
715 hw_len = len;
716 if (!ccw.cda) {
717 ret = -EFAULT;
718 } else if (dev->indicators && !sch->thinint_active) {
719 /* Trigger a command reject. */
720 ret = -ENOSYS;
721 } else {
722 thinint = cpu_physical_memory_map(ccw.cda, &hw_len, 0);
723 if (!thinint) {
724 ret = -EFAULT;
725 } else {
726 uint64_t ind_bit = ldq_be_p(&thinint->ind_bit);
728 len = hw_len;
729 dev->summary_indicator =
730 get_indicator(ldq_be_p(&thinint->summary_indicator),
731 sizeof(uint8_t));
732 dev->indicators =
733 get_indicator(ldq_be_p(&thinint->device_indicator),
734 ind_bit / 8 + 1);
735 dev->thinint_isc = thinint->isc;
736 dev->routes.adapter.ind_offset = ind_bit;
737 dev->routes.adapter.summary_offset = 7;
738 cpu_physical_memory_unmap(thinint, hw_len, 0, hw_len);
739 ret = css_register_io_adapter(CSS_IO_ADAPTER_VIRTIO,
740 dev->thinint_isc, true, false,
741 &dev->routes.adapter.adapter_id);
742 assert(ret == 0);
743 sch->thinint_active = ((dev->indicators != NULL) &&
744 (dev->summary_indicator != NULL));
745 sch->curr_status.scsw.count = ccw.count - len;
746 ret = 0;
749 break;
750 case CCW_CMD_SET_VIRTIO_REV:
751 len = sizeof(revinfo);
752 if (ccw.count < len) {
753 ret = -EINVAL;
754 break;
756 if (!ccw.cda) {
757 ret = -EFAULT;
758 break;
760 revinfo.revision =
761 address_space_lduw_be(&address_space_memory, ccw.cda,
762 MEMTXATTRS_UNSPECIFIED, NULL);
763 revinfo.length =
764 address_space_lduw_be(&address_space_memory,
765 ccw.cda + sizeof(revinfo.revision),
766 MEMTXATTRS_UNSPECIFIED, NULL);
767 if (ccw.count < len + revinfo.length ||
768 (check_len && ccw.count > len + revinfo.length)) {
769 ret = -EINVAL;
770 break;
773 * Once we start to support revisions with additional data, we'll
774 * need to fetch it here. Nothing to do for now, though.
776 if (dev->revision >= 0 ||
777 revinfo.revision > virtio_ccw_rev_max(dev)) {
778 ret = -ENOSYS;
779 break;
781 ret = 0;
782 dev->revision = revinfo.revision;
783 break;
784 default:
785 ret = -ENOSYS;
786 break;
788 return ret;
791 static void virtio_sch_disable_cb(SubchDev *sch)
793 VirtioCcwDevice *dev = sch->driver_data;
795 dev->revision = -1;
798 static void virtio_ccw_device_realize(VirtioCcwDevice *dev, Error **errp)
800 unsigned int cssid = 0;
801 unsigned int ssid = 0;
802 unsigned int schid;
803 unsigned int devno;
804 bool have_devno = false;
805 bool found = false;
806 SubchDev *sch;
807 int num;
808 Error *err = NULL;
809 VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_GET_CLASS(dev);
811 sch = g_malloc0(sizeof(SubchDev));
813 sch->driver_data = dev;
814 dev->sch = sch;
816 dev->indicators = NULL;
818 /* Initialize subchannel structure. */
819 sch->channel_prog = 0x0;
820 sch->last_cmd_valid = false;
821 sch->thinint_active = false;
823 * Use a device number if provided. Otherwise, fall back to subchannel
824 * number.
826 if (dev->bus_id) {
827 num = sscanf(dev->bus_id, "%x.%x.%04x", &cssid, &ssid, &devno);
828 if (num == 3) {
829 if ((cssid > MAX_CSSID) || (ssid > MAX_SSID)) {
830 error_setg(errp, "Invalid cssid or ssid: cssid %x, ssid %x",
831 cssid, ssid);
832 goto out_err;
834 /* Enforce use of virtual cssid. */
835 if (cssid != VIRTUAL_CSSID) {
836 error_setg(errp, "cssid %x not valid for virtio devices",
837 cssid);
838 goto out_err;
840 if (css_devno_used(cssid, ssid, devno)) {
841 error_setg(errp, "Device %x.%x.%04x already exists",
842 cssid, ssid, devno);
843 goto out_err;
845 sch->cssid = cssid;
846 sch->ssid = ssid;
847 sch->devno = devno;
848 have_devno = true;
849 } else {
850 error_setg(errp, "Malformed devno parameter '%s'", dev->bus_id);
851 goto out_err;
855 /* Find the next free id. */
856 if (have_devno) {
857 for (schid = 0; schid <= MAX_SCHID; schid++) {
858 if (!css_find_subch(1, cssid, ssid, schid)) {
859 sch->schid = schid;
860 css_subch_assign(cssid, ssid, schid, devno, sch);
861 found = true;
862 break;
865 if (!found) {
866 error_setg(errp, "No free subchannel found for %x.%x.%04x",
867 cssid, ssid, devno);
868 goto out_err;
870 trace_virtio_ccw_new_device(cssid, ssid, schid, devno,
871 "user-configured");
872 } else {
873 cssid = VIRTUAL_CSSID;
874 for (ssid = 0; ssid <= MAX_SSID; ssid++) {
875 for (schid = 0; schid <= MAX_SCHID; schid++) {
876 if (!css_find_subch(1, cssid, ssid, schid)) {
877 sch->cssid = cssid;
878 sch->ssid = ssid;
879 sch->schid = schid;
880 devno = schid;
882 * If the devno is already taken, look further in this
883 * subchannel set.
885 while (css_devno_used(cssid, ssid, devno)) {
886 if (devno == MAX_SCHID) {
887 devno = 0;
888 } else if (devno == schid - 1) {
889 error_setg(errp, "No free devno found");
890 goto out_err;
891 } else {
892 devno++;
895 sch->devno = devno;
896 css_subch_assign(cssid, ssid, schid, devno, sch);
897 found = true;
898 break;
901 if (found) {
902 break;
905 if (!found) {
906 error_setg(errp, "Virtual channel subsystem is full!");
907 goto out_err;
909 trace_virtio_ccw_new_device(cssid, ssid, schid, devno,
910 "auto-configured");
913 /* Build initial schib. */
914 css_sch_build_virtual_schib(sch, 0, VIRTIO_CCW_CHPID_TYPE);
916 sch->ccw_cb = virtio_ccw_cb;
917 sch->disable_cb = virtio_sch_disable_cb;
919 /* Build senseid data. */
920 memset(&sch->id, 0, sizeof(SenseId));
921 sch->id.reserved = 0xff;
922 sch->id.cu_type = VIRTIO_CCW_CU_TYPE;
924 dev->revision = -1;
926 if (k->realize) {
927 k->realize(dev, &err);
929 if (err) {
930 error_propagate(errp, err);
931 css_subch_assign(cssid, ssid, schid, devno, NULL);
932 goto out_err;
935 return;
937 out_err:
938 dev->sch = NULL;
939 g_free(sch);
942 static int virtio_ccw_exit(VirtioCcwDevice *dev)
944 SubchDev *sch = dev->sch;
946 if (sch) {
947 css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, NULL);
948 g_free(sch);
950 if (dev->indicators) {
951 release_indicator(&dev->routes.adapter, dev->indicators);
952 dev->indicators = NULL;
954 return 0;
957 static void virtio_ccw_net_realize(VirtioCcwDevice *ccw_dev, Error **errp)
959 DeviceState *qdev = DEVICE(ccw_dev);
960 VirtIONetCcw *dev = VIRTIO_NET_CCW(ccw_dev);
961 DeviceState *vdev = DEVICE(&dev->vdev);
962 Error *err = NULL;
964 virtio_net_set_netclient_name(&dev->vdev, qdev->id,
965 object_get_typename(OBJECT(qdev)));
966 qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
967 object_property_set_bool(OBJECT(vdev), true, "realized", &err);
968 if (err) {
969 error_propagate(errp, err);
973 static void virtio_ccw_net_instance_init(Object *obj)
975 VirtIONetCcw *dev = VIRTIO_NET_CCW(obj);
977 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
978 TYPE_VIRTIO_NET);
979 object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev),
980 "bootindex", &error_abort);
983 static void virtio_ccw_blk_realize(VirtioCcwDevice *ccw_dev, Error **errp)
985 VirtIOBlkCcw *dev = VIRTIO_BLK_CCW(ccw_dev);
986 DeviceState *vdev = DEVICE(&dev->vdev);
987 Error *err = NULL;
989 qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
990 object_property_set_bool(OBJECT(vdev), true, "realized", &err);
991 if (err) {
992 error_propagate(errp, err);
996 static void virtio_ccw_blk_instance_init(Object *obj)
998 VirtIOBlkCcw *dev = VIRTIO_BLK_CCW(obj);
1000 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
1001 TYPE_VIRTIO_BLK);
1002 object_property_add_alias(obj, "iothread", OBJECT(&dev->vdev),"iothread",
1003 &error_abort);
1004 object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev),
1005 "bootindex", &error_abort);
1008 static void virtio_ccw_serial_realize(VirtioCcwDevice *ccw_dev, Error **errp)
1010 VirtioSerialCcw *dev = VIRTIO_SERIAL_CCW(ccw_dev);
1011 DeviceState *vdev = DEVICE(&dev->vdev);
1012 DeviceState *proxy = DEVICE(ccw_dev);
1013 Error *err = NULL;
1014 char *bus_name;
1017 * For command line compatibility, this sets the virtio-serial-device bus
1018 * name as before.
1020 if (proxy->id) {
1021 bus_name = g_strdup_printf("%s.0", proxy->id);
1022 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name);
1023 g_free(bus_name);
1026 qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
1027 object_property_set_bool(OBJECT(vdev), true, "realized", &err);
1028 if (err) {
1029 error_propagate(errp, err);
1034 static void virtio_ccw_serial_instance_init(Object *obj)
1036 VirtioSerialCcw *dev = VIRTIO_SERIAL_CCW(obj);
1038 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
1039 TYPE_VIRTIO_SERIAL);
1042 static void virtio_ccw_balloon_realize(VirtioCcwDevice *ccw_dev, Error **errp)
1044 VirtIOBalloonCcw *dev = VIRTIO_BALLOON_CCW(ccw_dev);
1045 DeviceState *vdev = DEVICE(&dev->vdev);
1046 Error *err = NULL;
1048 qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
1049 object_property_set_bool(OBJECT(vdev), true, "realized", &err);
1050 if (err) {
1051 error_propagate(errp, err);
1055 static void virtio_ccw_balloon_instance_init(Object *obj)
1057 VirtIOBalloonCcw *dev = VIRTIO_BALLOON_CCW(obj);
1059 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
1060 TYPE_VIRTIO_BALLOON);
1061 object_property_add_alias(obj, "guest-stats", OBJECT(&dev->vdev),
1062 "guest-stats", &error_abort);
1063 object_property_add_alias(obj, "guest-stats-polling-interval",
1064 OBJECT(&dev->vdev),
1065 "guest-stats-polling-interval", &error_abort);
1068 static void virtio_ccw_scsi_realize(VirtioCcwDevice *ccw_dev, Error **errp)
1070 VirtIOSCSICcw *dev = VIRTIO_SCSI_CCW(ccw_dev);
1071 DeviceState *vdev = DEVICE(&dev->vdev);
1072 DeviceState *qdev = DEVICE(ccw_dev);
1073 Error *err = NULL;
1074 char *bus_name;
1077 * For command line compatibility, this sets the virtio-scsi-device bus
1078 * name as before.
1080 if (qdev->id) {
1081 bus_name = g_strdup_printf("%s.0", qdev->id);
1082 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name);
1083 g_free(bus_name);
1086 qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
1087 object_property_set_bool(OBJECT(vdev), true, "realized", &err);
1088 if (err) {
1089 error_propagate(errp, err);
1093 static void virtio_ccw_scsi_instance_init(Object *obj)
1095 VirtIOSCSICcw *dev = VIRTIO_SCSI_CCW(obj);
1097 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
1098 TYPE_VIRTIO_SCSI);
1099 object_property_add_alias(obj, "iothread", OBJECT(&dev->vdev), "iothread",
1100 &error_abort);
1103 #ifdef CONFIG_VHOST_SCSI
1104 static void vhost_ccw_scsi_realize(VirtioCcwDevice *ccw_dev, Error **errp)
1106 VHostSCSICcw *dev = VHOST_SCSI_CCW(ccw_dev);
1107 DeviceState *vdev = DEVICE(&dev->vdev);
1108 Error *err = NULL;
1110 qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
1111 object_property_set_bool(OBJECT(vdev), true, "realized", &err);
1112 if (err) {
1113 error_propagate(errp, err);
1117 static void vhost_ccw_scsi_instance_init(Object *obj)
1119 VHostSCSICcw *dev = VHOST_SCSI_CCW(obj);
1121 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
1122 TYPE_VHOST_SCSI);
1124 #endif
1126 static void virtio_ccw_rng_realize(VirtioCcwDevice *ccw_dev, Error **errp)
1128 VirtIORNGCcw *dev = VIRTIO_RNG_CCW(ccw_dev);
1129 DeviceState *vdev = DEVICE(&dev->vdev);
1130 Error *err = NULL;
1132 qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
1133 object_property_set_bool(OBJECT(vdev), true, "realized", &err);
1134 if (err) {
1135 error_propagate(errp, err);
1136 return;
1139 object_property_set_link(OBJECT(dev),
1140 OBJECT(dev->vdev.conf.rng), "rng",
1141 NULL);
1144 /* DeviceState to VirtioCcwDevice. Note: used on datapath,
1145 * be careful and test performance if you change this.
1147 static inline VirtioCcwDevice *to_virtio_ccw_dev_fast(DeviceState *d)
1149 return container_of(d, VirtioCcwDevice, parent_obj);
1152 static uint8_t virtio_set_ind_atomic(SubchDev *sch, uint64_t ind_loc,
1153 uint8_t to_be_set)
1155 uint8_t ind_old, ind_new;
1156 hwaddr len = 1;
1157 uint8_t *ind_addr;
1159 ind_addr = cpu_physical_memory_map(ind_loc, &len, 1);
1160 if (!ind_addr) {
1161 error_report("%s(%x.%x.%04x): unable to access indicator",
1162 __func__, sch->cssid, sch->ssid, sch->schid);
1163 return -1;
1165 do {
1166 ind_old = *ind_addr;
1167 ind_new = ind_old | to_be_set;
1168 } while (atomic_cmpxchg(ind_addr, ind_old, ind_new) != ind_old);
1169 cpu_physical_memory_unmap(ind_addr, len, 1, len);
1171 return ind_old;
1174 static void virtio_ccw_notify(DeviceState *d, uint16_t vector)
1176 VirtioCcwDevice *dev = to_virtio_ccw_dev_fast(d);
1177 SubchDev *sch = dev->sch;
1178 uint64_t indicators;
1180 /* queue indicators + secondary indicators */
1181 if (vector >= VIRTIO_CCW_QUEUE_MAX + 64) {
1182 return;
1185 if (vector < VIRTIO_CCW_QUEUE_MAX) {
1186 if (!dev->indicators) {
1187 return;
1189 if (sch->thinint_active) {
1191 * In the adapter interrupt case, indicators points to a
1192 * memory area that may be (way) larger than 64 bit and
1193 * ind_bit indicates the start of the indicators in a big
1194 * endian notation.
1196 uint64_t ind_bit = dev->routes.adapter.ind_offset;
1198 virtio_set_ind_atomic(sch, dev->indicators->addr +
1199 (ind_bit + vector) / 8,
1200 0x80 >> ((ind_bit + vector) % 8));
1201 if (!virtio_set_ind_atomic(sch, dev->summary_indicator->addr,
1202 0x01)) {
1203 css_adapter_interrupt(dev->thinint_isc);
1205 } else {
1206 indicators = address_space_ldq(&address_space_memory,
1207 dev->indicators->addr,
1208 MEMTXATTRS_UNSPECIFIED,
1209 NULL);
1210 indicators |= 1ULL << vector;
1211 address_space_stq(&address_space_memory, dev->indicators->addr,
1212 indicators, MEMTXATTRS_UNSPECIFIED, NULL);
1213 css_conditional_io_interrupt(sch);
1215 } else {
1216 if (!dev->indicators2) {
1217 return;
1219 vector = 0;
1220 indicators = address_space_ldq(&address_space_memory,
1221 dev->indicators2->addr,
1222 MEMTXATTRS_UNSPECIFIED,
1223 NULL);
1224 indicators |= 1ULL << vector;
1225 address_space_stq(&address_space_memory, dev->indicators2->addr,
1226 indicators, MEMTXATTRS_UNSPECIFIED, NULL);
1227 css_conditional_io_interrupt(sch);
1231 static void virtio_ccw_reset(DeviceState *d)
1233 VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
1234 VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
1236 virtio_ccw_reset_virtio(dev, vdev);
1237 css_reset_sch(dev->sch);
1240 static void virtio_ccw_vmstate_change(DeviceState *d, bool running)
1242 VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
1244 if (running) {
1245 virtio_ccw_start_ioeventfd(dev);
1246 } else {
1247 virtio_ccw_stop_ioeventfd(dev);
1251 static bool virtio_ccw_query_guest_notifiers(DeviceState *d)
1253 VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
1255 return !!(dev->sch->curr_status.pmcw.flags & PMCW_FLAGS_MASK_ENA);
1258 static int virtio_ccw_set_host_notifier(DeviceState *d, int n, bool assign)
1260 VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
1262 /* Stop using the generic ioeventfd, we are doing eventfd handling
1263 * ourselves below */
1264 dev->ioeventfd_disabled = assign;
1265 if (assign) {
1266 virtio_ccw_stop_ioeventfd(dev);
1268 return virtio_ccw_set_guest2host_notifier(dev, n, assign, false);
1271 static int virtio_ccw_get_mappings(VirtioCcwDevice *dev)
1273 int r;
1275 if (!dev->sch->thinint_active) {
1276 return -EINVAL;
1279 r = map_indicator(&dev->routes.adapter, dev->summary_indicator);
1280 if (r) {
1281 return r;
1283 r = map_indicator(&dev->routes.adapter, dev->indicators);
1284 if (r) {
1285 return r;
1287 dev->routes.adapter.summary_addr = dev->summary_indicator->map;
1288 dev->routes.adapter.ind_addr = dev->indicators->map;
1290 return 0;
1293 static int virtio_ccw_setup_irqroutes(VirtioCcwDevice *dev, int nvqs)
1295 int i;
1296 VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
1297 int ret;
1298 S390FLICState *fs = s390_get_flic();
1299 S390FLICStateClass *fsc = S390_FLIC_COMMON_GET_CLASS(fs);
1301 ret = virtio_ccw_get_mappings(dev);
1302 if (ret) {
1303 return ret;
1305 for (i = 0; i < nvqs; i++) {
1306 if (!virtio_queue_get_num(vdev, i)) {
1307 break;
1310 dev->routes.num_routes = i;
1311 return fsc->add_adapter_routes(fs, &dev->routes);
1314 static void virtio_ccw_release_irqroutes(VirtioCcwDevice *dev, int nvqs)
1316 S390FLICState *fs = s390_get_flic();
1317 S390FLICStateClass *fsc = S390_FLIC_COMMON_GET_CLASS(fs);
1319 fsc->release_adapter_routes(fs, &dev->routes);
1322 static int virtio_ccw_add_irqfd(VirtioCcwDevice *dev, int n)
1324 VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
1325 VirtQueue *vq = virtio_get_queue(vdev, n);
1326 EventNotifier *notifier = virtio_queue_get_guest_notifier(vq);
1328 return kvm_irqchip_add_irqfd_notifier_gsi(kvm_state, notifier, NULL,
1329 dev->routes.gsi[n]);
1332 static void virtio_ccw_remove_irqfd(VirtioCcwDevice *dev, int n)
1334 VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
1335 VirtQueue *vq = virtio_get_queue(vdev, n);
1336 EventNotifier *notifier = virtio_queue_get_guest_notifier(vq);
1337 int ret;
1339 ret = kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state, notifier,
1340 dev->routes.gsi[n]);
1341 assert(ret == 0);
1344 static int virtio_ccw_set_guest_notifier(VirtioCcwDevice *dev, int n,
1345 bool assign, bool with_irqfd)
1347 VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
1348 VirtQueue *vq = virtio_get_queue(vdev, n);
1349 EventNotifier *notifier = virtio_queue_get_guest_notifier(vq);
1350 VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
1352 if (assign) {
1353 int r = event_notifier_init(notifier, 0);
1355 if (r < 0) {
1356 return r;
1358 virtio_queue_set_guest_notifier_fd_handler(vq, true, with_irqfd);
1359 if (with_irqfd) {
1360 r = virtio_ccw_add_irqfd(dev, n);
1361 if (r) {
1362 virtio_queue_set_guest_notifier_fd_handler(vq, false,
1363 with_irqfd);
1364 return r;
1368 * We do not support individual masking for channel devices, so we
1369 * need to manually trigger any guest masking callbacks here.
1371 if (k->guest_notifier_mask) {
1372 k->guest_notifier_mask(vdev, n, false);
1374 /* get lost events and re-inject */
1375 if (k->guest_notifier_pending &&
1376 k->guest_notifier_pending(vdev, n)) {
1377 event_notifier_set(notifier);
1379 } else {
1380 if (k->guest_notifier_mask) {
1381 k->guest_notifier_mask(vdev, n, true);
1383 if (with_irqfd) {
1384 virtio_ccw_remove_irqfd(dev, n);
1386 virtio_queue_set_guest_notifier_fd_handler(vq, false, with_irqfd);
1387 event_notifier_cleanup(notifier);
1389 return 0;
1392 static int virtio_ccw_set_guest_notifiers(DeviceState *d, int nvqs,
1393 bool assigned)
1395 VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
1396 VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
1397 bool with_irqfd = dev->sch->thinint_active && kvm_irqfds_enabled();
1398 int r, n;
1400 if (with_irqfd && assigned) {
1401 /* irq routes need to be set up before assigning irqfds */
1402 r = virtio_ccw_setup_irqroutes(dev, nvqs);
1403 if (r < 0) {
1404 goto irqroute_error;
1407 for (n = 0; n < nvqs; n++) {
1408 if (!virtio_queue_get_num(vdev, n)) {
1409 break;
1411 r = virtio_ccw_set_guest_notifier(dev, n, assigned, with_irqfd);
1412 if (r < 0) {
1413 goto assign_error;
1416 if (with_irqfd && !assigned) {
1417 /* release irq routes after irqfds have been released */
1418 virtio_ccw_release_irqroutes(dev, nvqs);
1420 return 0;
1422 assign_error:
1423 while (--n >= 0) {
1424 virtio_ccw_set_guest_notifier(dev, n, !assigned, false);
1426 irqroute_error:
1427 if (with_irqfd && assigned) {
1428 virtio_ccw_release_irqroutes(dev, nvqs);
1430 return r;
1433 static void virtio_ccw_save_queue(DeviceState *d, int n, QEMUFile *f)
1435 VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
1436 VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
1438 qemu_put_be16(f, virtio_queue_vector(vdev, n));
1441 static int virtio_ccw_load_queue(DeviceState *d, int n, QEMUFile *f)
1443 VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
1444 VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
1445 uint16_t vector;
1447 qemu_get_be16s(f, &vector);
1448 virtio_queue_set_vector(vdev, n , vector);
1450 return 0;
1453 static void virtio_ccw_save_config(DeviceState *d, QEMUFile *f)
1455 VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
1456 SubchDev *s = dev->sch;
1457 VirtIODevice *vdev = virtio_ccw_get_vdev(s);
1459 subch_device_save(s, f);
1460 if (dev->indicators != NULL) {
1461 qemu_put_be32(f, dev->indicators->len);
1462 qemu_put_be64(f, dev->indicators->addr);
1463 } else {
1464 qemu_put_be32(f, 0);
1465 qemu_put_be64(f, 0UL);
1467 if (dev->indicators2 != NULL) {
1468 qemu_put_be32(f, dev->indicators2->len);
1469 qemu_put_be64(f, dev->indicators2->addr);
1470 } else {
1471 qemu_put_be32(f, 0);
1472 qemu_put_be64(f, 0UL);
1474 if (dev->summary_indicator != NULL) {
1475 qemu_put_be32(f, dev->summary_indicator->len);
1476 qemu_put_be64(f, dev->summary_indicator->addr);
1477 } else {
1478 qemu_put_be32(f, 0);
1479 qemu_put_be64(f, 0UL);
1481 qemu_put_be16(f, vdev->config_vector);
1482 qemu_put_be64(f, dev->routes.adapter.ind_offset);
1483 qemu_put_byte(f, dev->thinint_isc);
1484 qemu_put_be32(f, dev->revision);
1487 static int virtio_ccw_load_config(DeviceState *d, QEMUFile *f)
1489 VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
1490 SubchDev *s = dev->sch;
1491 VirtIODevice *vdev = virtio_ccw_get_vdev(s);
1492 int len;
1494 s->driver_data = dev;
1495 subch_device_load(s, f);
1496 len = qemu_get_be32(f);
1497 if (len != 0) {
1498 dev->indicators = get_indicator(qemu_get_be64(f), len);
1499 } else {
1500 qemu_get_be64(f);
1501 dev->indicators = NULL;
1503 len = qemu_get_be32(f);
1504 if (len != 0) {
1505 dev->indicators2 = get_indicator(qemu_get_be64(f), len);
1506 } else {
1507 qemu_get_be64(f);
1508 dev->indicators2 = NULL;
1510 len = qemu_get_be32(f);
1511 if (len != 0) {
1512 dev->summary_indicator = get_indicator(qemu_get_be64(f), len);
1513 } else {
1514 qemu_get_be64(f);
1515 dev->summary_indicator = NULL;
1517 qemu_get_be16s(f, &vdev->config_vector);
1518 dev->routes.adapter.ind_offset = qemu_get_be64(f);
1519 dev->thinint_isc = qemu_get_byte(f);
1520 dev->revision = qemu_get_be32(f);
1521 if (s->thinint_active) {
1522 return css_register_io_adapter(CSS_IO_ADAPTER_VIRTIO,
1523 dev->thinint_isc, true, false,
1524 &dev->routes.adapter.adapter_id);
1527 return 0;
1530 /* This is called by virtio-bus just after the device is plugged. */
1531 static void virtio_ccw_device_plugged(DeviceState *d, Error **errp)
1533 VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
1534 VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
1535 SubchDev *sch = dev->sch;
1536 int n = virtio_get_num_queues(vdev);
1538 if (virtio_get_num_queues(vdev) > VIRTIO_CCW_QUEUE_MAX) {
1539 error_setg(errp, "The nubmer of virtqueues %d "
1540 "exceeds ccw limit %d", n,
1541 VIRTIO_CCW_QUEUE_MAX);
1542 return;
1545 if (!kvm_eventfds_enabled()) {
1546 dev->flags &= ~VIRTIO_CCW_FLAG_USE_IOEVENTFD;
1549 sch->id.cu_model = virtio_bus_get_vdev_id(&dev->bus);
1551 if (dev->max_rev >= 1) {
1552 virtio_add_feature(&vdev->host_features, VIRTIO_F_VERSION_1);
1555 css_generate_sch_crws(sch->cssid, sch->ssid, sch->schid,
1556 d->hotplugged, 1);
1559 static void virtio_ccw_post_plugged(DeviceState *d, Error **errp)
1561 VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
1562 VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
1564 if (!virtio_host_has_feature(vdev, VIRTIO_F_VERSION_1)) {
1565 /* A backend didn't support modern virtio. */
1566 dev->max_rev = 0;
1570 static void virtio_ccw_device_unplugged(DeviceState *d)
1572 VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
1574 virtio_ccw_stop_ioeventfd(dev);
1576 /**************** Virtio-ccw Bus Device Descriptions *******************/
1578 static Property virtio_ccw_net_properties[] = {
1579 DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
1580 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
1581 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1582 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev,
1583 VIRTIO_CCW_MAX_REV),
1584 DEFINE_PROP_END_OF_LIST(),
1587 static void virtio_ccw_net_class_init(ObjectClass *klass, void *data)
1589 DeviceClass *dc = DEVICE_CLASS(klass);
1590 VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1592 k->realize = virtio_ccw_net_realize;
1593 k->exit = virtio_ccw_exit;
1594 dc->reset = virtio_ccw_reset;
1595 dc->props = virtio_ccw_net_properties;
1596 set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
1599 static const TypeInfo virtio_ccw_net = {
1600 .name = TYPE_VIRTIO_NET_CCW,
1601 .parent = TYPE_VIRTIO_CCW_DEVICE,
1602 .instance_size = sizeof(VirtIONetCcw),
1603 .instance_init = virtio_ccw_net_instance_init,
1604 .class_init = virtio_ccw_net_class_init,
1607 static Property virtio_ccw_blk_properties[] = {
1608 DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
1609 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
1610 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1611 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev,
1612 VIRTIO_CCW_MAX_REV),
1613 DEFINE_PROP_END_OF_LIST(),
1616 static void virtio_ccw_blk_class_init(ObjectClass *klass, void *data)
1618 DeviceClass *dc = DEVICE_CLASS(klass);
1619 VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1621 k->realize = virtio_ccw_blk_realize;
1622 k->exit = virtio_ccw_exit;
1623 dc->reset = virtio_ccw_reset;
1624 dc->props = virtio_ccw_blk_properties;
1625 set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
1628 static const TypeInfo virtio_ccw_blk = {
1629 .name = TYPE_VIRTIO_BLK_CCW,
1630 .parent = TYPE_VIRTIO_CCW_DEVICE,
1631 .instance_size = sizeof(VirtIOBlkCcw),
1632 .instance_init = virtio_ccw_blk_instance_init,
1633 .class_init = virtio_ccw_blk_class_init,
1636 static Property virtio_ccw_serial_properties[] = {
1637 DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
1638 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
1639 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1640 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev,
1641 VIRTIO_CCW_MAX_REV),
1642 DEFINE_PROP_END_OF_LIST(),
1645 static void virtio_ccw_serial_class_init(ObjectClass *klass, void *data)
1647 DeviceClass *dc = DEVICE_CLASS(klass);
1648 VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1650 k->realize = virtio_ccw_serial_realize;
1651 k->exit = virtio_ccw_exit;
1652 dc->reset = virtio_ccw_reset;
1653 dc->props = virtio_ccw_serial_properties;
1654 set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
1657 static const TypeInfo virtio_ccw_serial = {
1658 .name = TYPE_VIRTIO_SERIAL_CCW,
1659 .parent = TYPE_VIRTIO_CCW_DEVICE,
1660 .instance_size = sizeof(VirtioSerialCcw),
1661 .instance_init = virtio_ccw_serial_instance_init,
1662 .class_init = virtio_ccw_serial_class_init,
1665 static Property virtio_ccw_balloon_properties[] = {
1666 DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
1667 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
1668 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1669 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev,
1670 VIRTIO_CCW_MAX_REV),
1671 DEFINE_PROP_END_OF_LIST(),
1674 static void virtio_ccw_balloon_class_init(ObjectClass *klass, void *data)
1676 DeviceClass *dc = DEVICE_CLASS(klass);
1677 VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1679 k->realize = virtio_ccw_balloon_realize;
1680 k->exit = virtio_ccw_exit;
1681 dc->reset = virtio_ccw_reset;
1682 dc->props = virtio_ccw_balloon_properties;
1683 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
1686 static const TypeInfo virtio_ccw_balloon = {
1687 .name = TYPE_VIRTIO_BALLOON_CCW,
1688 .parent = TYPE_VIRTIO_CCW_DEVICE,
1689 .instance_size = sizeof(VirtIOBalloonCcw),
1690 .instance_init = virtio_ccw_balloon_instance_init,
1691 .class_init = virtio_ccw_balloon_class_init,
1694 static Property virtio_ccw_scsi_properties[] = {
1695 DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
1696 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
1697 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1698 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev,
1699 VIRTIO_CCW_MAX_REV),
1700 DEFINE_PROP_END_OF_LIST(),
1703 static void virtio_ccw_scsi_class_init(ObjectClass *klass, void *data)
1705 DeviceClass *dc = DEVICE_CLASS(klass);
1706 VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1708 k->realize = virtio_ccw_scsi_realize;
1709 k->exit = virtio_ccw_exit;
1710 dc->reset = virtio_ccw_reset;
1711 dc->props = virtio_ccw_scsi_properties;
1712 set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
1715 static const TypeInfo virtio_ccw_scsi = {
1716 .name = TYPE_VIRTIO_SCSI_CCW,
1717 .parent = TYPE_VIRTIO_CCW_DEVICE,
1718 .instance_size = sizeof(VirtIOSCSICcw),
1719 .instance_init = virtio_ccw_scsi_instance_init,
1720 .class_init = virtio_ccw_scsi_class_init,
1723 #ifdef CONFIG_VHOST_SCSI
1724 static Property vhost_ccw_scsi_properties[] = {
1725 DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
1726 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev,
1727 VIRTIO_CCW_MAX_REV),
1728 DEFINE_PROP_END_OF_LIST(),
1731 static void vhost_ccw_scsi_class_init(ObjectClass *klass, void *data)
1733 DeviceClass *dc = DEVICE_CLASS(klass);
1734 VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1736 k->realize = vhost_ccw_scsi_realize;
1737 k->exit = virtio_ccw_exit;
1738 dc->reset = virtio_ccw_reset;
1739 dc->props = vhost_ccw_scsi_properties;
1740 set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
1743 static const TypeInfo vhost_ccw_scsi = {
1744 .name = TYPE_VHOST_SCSI_CCW,
1745 .parent = TYPE_VIRTIO_CCW_DEVICE,
1746 .instance_size = sizeof(VHostSCSICcw),
1747 .instance_init = vhost_ccw_scsi_instance_init,
1748 .class_init = vhost_ccw_scsi_class_init,
1750 #endif
1752 static void virtio_ccw_rng_instance_init(Object *obj)
1754 VirtIORNGCcw *dev = VIRTIO_RNG_CCW(obj);
1756 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
1757 TYPE_VIRTIO_RNG);
1758 object_property_add_alias(obj, "rng", OBJECT(&dev->vdev),
1759 "rng", &error_abort);
1762 static Property virtio_ccw_rng_properties[] = {
1763 DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
1764 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
1765 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1766 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev,
1767 VIRTIO_CCW_MAX_REV),
1768 DEFINE_PROP_END_OF_LIST(),
1771 static void virtio_ccw_rng_class_init(ObjectClass *klass, void *data)
1773 DeviceClass *dc = DEVICE_CLASS(klass);
1774 VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1776 k->realize = virtio_ccw_rng_realize;
1777 k->exit = virtio_ccw_exit;
1778 dc->reset = virtio_ccw_reset;
1779 dc->props = virtio_ccw_rng_properties;
1780 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
1783 static const TypeInfo virtio_ccw_rng = {
1784 .name = TYPE_VIRTIO_RNG_CCW,
1785 .parent = TYPE_VIRTIO_CCW_DEVICE,
1786 .instance_size = sizeof(VirtIORNGCcw),
1787 .instance_init = virtio_ccw_rng_instance_init,
1788 .class_init = virtio_ccw_rng_class_init,
1791 static void virtio_ccw_busdev_realize(DeviceState *dev, Error **errp)
1793 VirtioCcwDevice *_dev = (VirtioCcwDevice *)dev;
1795 virtio_ccw_bus_new(&_dev->bus, sizeof(_dev->bus), _dev);
1796 virtio_ccw_device_realize(_dev, errp);
1799 static int virtio_ccw_busdev_exit(DeviceState *dev)
1801 VirtioCcwDevice *_dev = (VirtioCcwDevice *)dev;
1802 VirtIOCCWDeviceClass *_info = VIRTIO_CCW_DEVICE_GET_CLASS(dev);
1804 return _info->exit(_dev);
1807 static void virtio_ccw_busdev_unplug(HotplugHandler *hotplug_dev,
1808 DeviceState *dev, Error **errp)
1810 VirtioCcwDevice *_dev = (VirtioCcwDevice *)dev;
1811 SubchDev *sch = _dev->sch;
1813 virtio_ccw_stop_ioeventfd(_dev);
1816 * We should arrive here only for device_del, since we don't support
1817 * direct hot(un)plug of channels, but only through virtio.
1819 assert(sch != NULL);
1820 /* Subchannel is now disabled and no longer valid. */
1821 sch->curr_status.pmcw.flags &= ~(PMCW_FLAGS_MASK_ENA |
1822 PMCW_FLAGS_MASK_DNV);
1824 css_generate_sch_crws(sch->cssid, sch->ssid, sch->schid, 1, 0);
1826 object_unparent(OBJECT(dev));
1829 static void virtio_ccw_device_class_init(ObjectClass *klass, void *data)
1831 DeviceClass *dc = DEVICE_CLASS(klass);
1833 dc->realize = virtio_ccw_busdev_realize;
1834 dc->exit = virtio_ccw_busdev_exit;
1835 dc->bus_type = TYPE_VIRTUAL_CSS_BUS;
1838 static const TypeInfo virtio_ccw_device_info = {
1839 .name = TYPE_VIRTIO_CCW_DEVICE,
1840 .parent = TYPE_DEVICE,
1841 .instance_size = sizeof(VirtioCcwDevice),
1842 .class_init = virtio_ccw_device_class_init,
1843 .class_size = sizeof(VirtIOCCWDeviceClass),
1844 .abstract = true,
1847 /***************** Virtual-css Bus Bridge Device ********************/
1848 /* Only required to have the virtio bus as child in the system bus */
1850 static int virtual_css_bridge_init(SysBusDevice *dev)
1852 /* nothing */
1853 return 0;
1856 static void virtual_css_bridge_class_init(ObjectClass *klass, void *data)
1858 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
1859 HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);
1860 DeviceClass *dc = DEVICE_CLASS(klass);
1862 k->init = virtual_css_bridge_init;
1863 hc->unplug = virtio_ccw_busdev_unplug;
1864 set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
1867 static const TypeInfo virtual_css_bridge_info = {
1868 .name = "virtual-css-bridge",
1869 .parent = TYPE_SYS_BUS_DEVICE,
1870 .instance_size = sizeof(SysBusDevice),
1871 .class_init = virtual_css_bridge_class_init,
1872 .interfaces = (InterfaceInfo[]) {
1873 { TYPE_HOTPLUG_HANDLER },
1878 /* virtio-ccw-bus */
1880 static void virtio_ccw_bus_new(VirtioBusState *bus, size_t bus_size,
1881 VirtioCcwDevice *dev)
1883 DeviceState *qdev = DEVICE(dev);
1884 char virtio_bus_name[] = "virtio-bus";
1886 qbus_create_inplace(bus, bus_size, TYPE_VIRTIO_CCW_BUS,
1887 qdev, virtio_bus_name);
1890 static void virtio_ccw_bus_class_init(ObjectClass *klass, void *data)
1892 VirtioBusClass *k = VIRTIO_BUS_CLASS(klass);
1893 BusClass *bus_class = BUS_CLASS(klass);
1895 bus_class->max_dev = 1;
1896 k->notify = virtio_ccw_notify;
1897 k->vmstate_change = virtio_ccw_vmstate_change;
1898 k->query_guest_notifiers = virtio_ccw_query_guest_notifiers;
1899 k->set_host_notifier = virtio_ccw_set_host_notifier;
1900 k->set_guest_notifiers = virtio_ccw_set_guest_notifiers;
1901 k->save_queue = virtio_ccw_save_queue;
1902 k->load_queue = virtio_ccw_load_queue;
1903 k->save_config = virtio_ccw_save_config;
1904 k->load_config = virtio_ccw_load_config;
1905 k->device_plugged = virtio_ccw_device_plugged;
1906 k->post_plugged = virtio_ccw_post_plugged;
1907 k->device_unplugged = virtio_ccw_device_unplugged;
1910 static const TypeInfo virtio_ccw_bus_info = {
1911 .name = TYPE_VIRTIO_CCW_BUS,
1912 .parent = TYPE_VIRTIO_BUS,
1913 .instance_size = sizeof(VirtioCcwBusState),
1914 .class_init = virtio_ccw_bus_class_init,
1917 #ifdef CONFIG_VIRTFS
1918 static Property virtio_ccw_9p_properties[] = {
1919 DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
1920 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
1921 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1922 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev,
1923 VIRTIO_CCW_MAX_REV),
1924 DEFINE_PROP_END_OF_LIST(),
1927 static void virtio_ccw_9p_realize(VirtioCcwDevice *ccw_dev, Error **errp)
1929 V9fsCCWState *dev = VIRTIO_9P_CCW(ccw_dev);
1930 DeviceState *vdev = DEVICE(&dev->vdev);
1931 Error *err = NULL;
1933 qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
1934 object_property_set_bool(OBJECT(vdev), true, "realized", &err);
1935 if (err) {
1936 error_propagate(errp, err);
1940 static void virtio_ccw_9p_class_init(ObjectClass *klass, void *data)
1942 DeviceClass *dc = DEVICE_CLASS(klass);
1943 VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1945 k->exit = virtio_ccw_exit;
1946 k->realize = virtio_ccw_9p_realize;
1947 dc->reset = virtio_ccw_reset;
1948 dc->props = virtio_ccw_9p_properties;
1949 set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
1952 static void virtio_ccw_9p_instance_init(Object *obj)
1954 V9fsCCWState *dev = VIRTIO_9P_CCW(obj);
1956 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
1957 TYPE_VIRTIO_9P);
1960 static const TypeInfo virtio_ccw_9p_info = {
1961 .name = TYPE_VIRTIO_9P_CCW,
1962 .parent = TYPE_VIRTIO_CCW_DEVICE,
1963 .instance_size = sizeof(V9fsCCWState),
1964 .instance_init = virtio_ccw_9p_instance_init,
1965 .class_init = virtio_ccw_9p_class_init,
1967 #endif
1969 static void virtio_ccw_register(void)
1971 type_register_static(&virtio_ccw_bus_info);
1972 type_register_static(&virtual_css_bus_info);
1973 type_register_static(&virtio_ccw_device_info);
1974 type_register_static(&virtio_ccw_serial);
1975 type_register_static(&virtio_ccw_blk);
1976 type_register_static(&virtio_ccw_net);
1977 type_register_static(&virtio_ccw_balloon);
1978 type_register_static(&virtio_ccw_scsi);
1979 #ifdef CONFIG_VHOST_SCSI
1980 type_register_static(&vhost_ccw_scsi);
1981 #endif
1982 type_register_static(&virtio_ccw_rng);
1983 type_register_static(&virtual_css_bridge_info);
1984 #ifdef CONFIG_VIRTFS
1985 type_register_static(&virtio_ccw_9p_info);
1986 #endif
1989 type_init(virtio_ccw_register)