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
13 #include "qemu/osdep.h"
15 #include "sysemu/block-backend.h"
16 #include "sysemu/blockdev.h"
17 #include "sysemu/sysemu.h"
19 #include "hw/virtio/virtio.h"
20 #include "hw/virtio/virtio-serial.h"
21 #include "hw/virtio/virtio-net.h"
22 #include "hw/sysbus.h"
23 #include "qemu/bitops.h"
24 #include "qemu/error-report.h"
25 #include "hw/virtio/virtio-access.h"
26 #include "hw/virtio/virtio-bus.h"
27 #include "hw/s390x/adapter.h"
28 #include "hw/s390x/s390_flic.h"
32 #include "virtio-ccw.h"
35 static void virtio_ccw_bus_new(VirtioBusState
*bus
, size_t bus_size
,
36 VirtioCcwDevice
*dev
);
38 static void virtual_css_bus_reset(BusState
*qbus
)
40 /* This should actually be modelled via the generic css */
45 static void virtual_css_bus_class_init(ObjectClass
*klass
, void *data
)
47 BusClass
*k
= BUS_CLASS(klass
);
49 k
->reset
= virtual_css_bus_reset
;
52 static const TypeInfo virtual_css_bus_info
= {
53 .name
= TYPE_VIRTUAL_CSS_BUS
,
55 .instance_size
= sizeof(VirtualCssBus
),
56 .class_init
= virtual_css_bus_class_init
,
59 VirtIODevice
*virtio_ccw_get_vdev(SubchDev
*sch
)
61 VirtIODevice
*vdev
= NULL
;
62 VirtioCcwDevice
*dev
= sch
->driver_data
;
65 vdev
= virtio_bus_get_device(&dev
->bus
);
70 static int virtio_ccw_set_guest2host_notifier(VirtioCcwDevice
*dev
, int n
,
71 bool assign
, bool set_handler
)
73 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
74 VirtQueue
*vq
= virtio_get_queue(vdev
, n
);
75 EventNotifier
*notifier
= virtio_queue_get_host_notifier(vq
);
77 SubchDev
*sch
= dev
->sch
;
78 uint32_t sch_id
= (css_build_subchannel_id(sch
) << 16) | sch
->schid
;
81 r
= event_notifier_init(notifier
, 1);
83 error_report("%s: unable to init event notifier: %d", __func__
, r
);
86 virtio_queue_set_host_notifier_fd_handler(vq
, true, set_handler
);
87 r
= s390_assign_subch_ioeventfd(notifier
, sch_id
, n
, assign
);
89 error_report("%s: unable to assign ioeventfd: %d", __func__
, r
);
90 virtio_queue_set_host_notifier_fd_handler(vq
, false, false);
91 event_notifier_cleanup(notifier
);
95 virtio_queue_set_host_notifier_fd_handler(vq
, false, false);
96 s390_assign_subch_ioeventfd(notifier
, sch_id
, n
, assign
);
97 event_notifier_cleanup(notifier
);
102 static void virtio_ccw_start_ioeventfd(VirtioCcwDevice
*dev
)
107 if (!(dev
->flags
& VIRTIO_CCW_FLAG_USE_IOEVENTFD
) ||
108 dev
->ioeventfd_disabled
||
109 dev
->ioeventfd_started
) {
112 vdev
= virtio_bus_get_device(&dev
->bus
);
113 for (n
= 0; n
< VIRTIO_CCW_QUEUE_MAX
; n
++) {
114 if (!virtio_queue_get_num(vdev
, n
)) {
117 r
= virtio_ccw_set_guest2host_notifier(dev
, n
, true, true);
122 dev
->ioeventfd_started
= true;
127 if (!virtio_queue_get_num(vdev
, n
)) {
130 r
= virtio_ccw_set_guest2host_notifier(dev
, n
, false, false);
133 dev
->ioeventfd_started
= false;
134 /* Disable ioeventfd for this device. */
135 dev
->flags
&= ~VIRTIO_CCW_FLAG_USE_IOEVENTFD
;
136 error_report("%s: failed. Fallback to userspace (slower).", __func__
);
139 static void virtio_ccw_stop_ioeventfd(VirtioCcwDevice
*dev
)
144 if (!dev
->ioeventfd_started
) {
147 vdev
= virtio_bus_get_device(&dev
->bus
);
148 for (n
= 0; n
< VIRTIO_CCW_QUEUE_MAX
; n
++) {
149 if (!virtio_queue_get_num(vdev
, n
)) {
152 r
= virtio_ccw_set_guest2host_notifier(dev
, n
, false, false);
155 dev
->ioeventfd_started
= false;
158 VirtualCssBus
*virtual_css_bus_init(void)
164 /* Create bridge device */
165 dev
= qdev_create(NULL
, "virtual-css-bridge");
166 qdev_init_nofail(dev
);
168 /* Create bus on bridge device */
169 bus
= qbus_create(TYPE_VIRTUAL_CSS_BUS
, dev
, "virtual-css");
170 cbus
= VIRTUAL_CSS_BUS(bus
);
172 /* Enable hotplugging */
173 qbus_set_hotplug_handler(bus
, dev
, &error_abort
);
178 /* Communication blocks used by several channel commands. */
179 typedef struct VqInfoBlockLegacy
{
184 } QEMU_PACKED VqInfoBlockLegacy
;
186 typedef struct VqInfoBlock
{
193 } QEMU_PACKED VqInfoBlock
;
195 typedef struct VqConfigBlock
{
198 } QEMU_PACKED VqConfigBlock
;
200 typedef struct VirtioFeatDesc
{
203 } QEMU_PACKED VirtioFeatDesc
;
205 typedef struct VirtioThinintInfo
{
206 hwaddr summary_indicator
;
207 hwaddr device_indicator
;
210 } QEMU_PACKED VirtioThinintInfo
;
212 typedef struct VirtioRevInfo
{
216 } QEMU_PACKED VirtioRevInfo
;
218 /* Specify where the virtqueues for the subchannel are in guest memory. */
219 static int virtio_ccw_set_vqs(SubchDev
*sch
, VqInfoBlock
*info
,
220 VqInfoBlockLegacy
*linfo
)
222 VirtIODevice
*vdev
= virtio_ccw_get_vdev(sch
);
223 uint16_t index
= info
? info
->index
: linfo
->index
;
224 uint16_t num
= info
? info
->num
: linfo
->num
;
225 uint64_t desc
= info
? info
->desc
: linfo
->queue
;
227 if (index
>= VIRTIO_CCW_QUEUE_MAX
) {
231 /* Current code in virtio.c relies on 4K alignment. */
232 if (linfo
&& desc
&& (linfo
->align
!= 4096)) {
241 virtio_queue_set_rings(vdev
, index
, desc
, info
->avail
, info
->used
);
243 virtio_queue_set_addr(vdev
, index
, desc
);
246 virtio_queue_set_vector(vdev
, index
, VIRTIO_NO_VECTOR
);
249 /* virtio-1 allows changing the ring size. */
250 if (virtio_queue_get_num(vdev
, index
) < num
) {
251 /* Fail if we exceed the maximum number. */
254 virtio_queue_set_num(vdev
, index
, num
);
255 } else if (virtio_queue_get_num(vdev
, index
) > num
) {
256 /* Fail if we don't have a big enough queue. */
259 /* We ignore possible increased num for legacy for compatibility. */
260 virtio_queue_set_vector(vdev
, index
, index
);
262 /* tell notify handler in case of config change */
263 vdev
->config_vector
= VIRTIO_CCW_QUEUE_MAX
;
267 static void virtio_ccw_reset_virtio(VirtioCcwDevice
*dev
, VirtIODevice
*vdev
)
269 virtio_ccw_stop_ioeventfd(dev
);
271 if (dev
->indicators
) {
272 release_indicator(&dev
->routes
.adapter
, dev
->indicators
);
273 dev
->indicators
= NULL
;
275 if (dev
->indicators2
) {
276 release_indicator(&dev
->routes
.adapter
, dev
->indicators2
);
277 dev
->indicators2
= NULL
;
279 if (dev
->summary_indicator
) {
280 release_indicator(&dev
->routes
.adapter
, dev
->summary_indicator
);
281 dev
->summary_indicator
= NULL
;
283 dev
->sch
->thinint_active
= false;
286 static int virtio_ccw_handle_set_vq(SubchDev
*sch
, CCW1 ccw
, bool check_len
,
291 VqInfoBlockLegacy linfo
;
292 size_t info_len
= is_legacy
? sizeof(linfo
) : sizeof(info
);
295 if (ccw
.count
!= info_len
) {
298 } else if (ccw
.count
< info_len
) {
299 /* Can't execute command. */
306 linfo
.queue
= address_space_ldq_be(&address_space_memory
, ccw
.cda
,
307 MEMTXATTRS_UNSPECIFIED
, NULL
);
308 linfo
.align
= address_space_ldl_be(&address_space_memory
,
309 ccw
.cda
+ sizeof(linfo
.queue
),
310 MEMTXATTRS_UNSPECIFIED
,
312 linfo
.index
= address_space_lduw_be(&address_space_memory
,
313 ccw
.cda
+ sizeof(linfo
.queue
)
314 + sizeof(linfo
.align
),
315 MEMTXATTRS_UNSPECIFIED
,
317 linfo
.num
= address_space_lduw_be(&address_space_memory
,
318 ccw
.cda
+ sizeof(linfo
.queue
)
319 + sizeof(linfo
.align
)
320 + sizeof(linfo
.index
),
321 MEMTXATTRS_UNSPECIFIED
,
323 ret
= virtio_ccw_set_vqs(sch
, NULL
, &linfo
);
325 info
.desc
= address_space_ldq_be(&address_space_memory
, ccw
.cda
,
326 MEMTXATTRS_UNSPECIFIED
, NULL
);
327 info
.index
= address_space_lduw_be(&address_space_memory
,
328 ccw
.cda
+ sizeof(info
.desc
)
330 MEMTXATTRS_UNSPECIFIED
, NULL
);
331 info
.num
= address_space_lduw_be(&address_space_memory
,
332 ccw
.cda
+ sizeof(info
.desc
)
334 + sizeof(info
.index
),
335 MEMTXATTRS_UNSPECIFIED
, NULL
);
336 info
.avail
= address_space_ldq_be(&address_space_memory
,
337 ccw
.cda
+ sizeof(info
.desc
)
341 MEMTXATTRS_UNSPECIFIED
, NULL
);
342 info
.used
= address_space_ldq_be(&address_space_memory
,
343 ccw
.cda
+ sizeof(info
.desc
)
347 + sizeof(info
.avail
),
348 MEMTXATTRS_UNSPECIFIED
, NULL
);
349 ret
= virtio_ccw_set_vqs(sch
, &info
, NULL
);
351 sch
->curr_status
.scsw
.count
= 0;
355 static int virtio_ccw_cb(SubchDev
*sch
, CCW1 ccw
)
358 VirtioRevInfo revinfo
;
360 VirtioFeatDesc features
;
363 VqConfigBlock vq_config
;
364 VirtioCcwDevice
*dev
= sch
->driver_data
;
365 VirtIODevice
*vdev
= virtio_ccw_get_vdev(sch
);
369 VirtioThinintInfo
*thinint
;
375 trace_virtio_ccw_interpret_ccw(sch
->cssid
, sch
->ssid
, sch
->schid
,
377 check_len
= !((ccw
.flags
& CCW_FLAG_SLI
) && !(ccw
.flags
& CCW_FLAG_DC
));
379 /* Look at the command. */
380 switch (ccw
.cmd_code
) {
382 ret
= virtio_ccw_handle_set_vq(sch
, ccw
, check_len
, dev
->revision
< 1);
384 case CCW_CMD_VDEV_RESET
:
385 virtio_ccw_reset_virtio(dev
, vdev
);
388 case CCW_CMD_READ_FEAT
:
390 if (ccw
.count
!= sizeof(features
)) {
394 } else if (ccw
.count
< sizeof(features
)) {
395 /* Can't execute command. */
402 features
.index
= address_space_ldub(&address_space_memory
,
404 + sizeof(features
.features
),
405 MEMTXATTRS_UNSPECIFIED
,
407 if (features
.index
== 0) {
408 if (dev
->revision
>= 1) {
409 /* Don't offer legacy features for modern devices. */
410 features
.features
= (uint32_t)
411 (vdev
->host_features
& ~VIRTIO_LEGACY_FEATURES
);
413 features
.features
= (uint32_t)vdev
->host_features
;
415 } else if ((features
.index
== 1) && (dev
->revision
>= 1)) {
417 * Only offer feature bits beyond 31 if the guest has
418 * negotiated at least revision 1.
420 features
.features
= (uint32_t)(vdev
->host_features
>> 32);
422 /* Return zeroes if the guest supports more feature bits. */
423 features
.features
= 0;
425 address_space_stl_le(&address_space_memory
, ccw
.cda
,
426 features
.features
, MEMTXATTRS_UNSPECIFIED
,
428 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(features
);
432 case CCW_CMD_WRITE_FEAT
:
434 if (ccw
.count
!= sizeof(features
)) {
438 } else if (ccw
.count
< sizeof(features
)) {
439 /* Can't execute command. */
446 features
.index
= address_space_ldub(&address_space_memory
,
448 + sizeof(features
.features
),
449 MEMTXATTRS_UNSPECIFIED
,
451 features
.features
= address_space_ldl_le(&address_space_memory
,
453 MEMTXATTRS_UNSPECIFIED
,
455 if (features
.index
== 0) {
456 virtio_set_features(vdev
,
457 (vdev
->guest_features
& 0xffffffff00000000ULL
) |
459 } else if ((features
.index
== 1) && (dev
->revision
>= 1)) {
461 * If the guest did not negotiate at least revision 1,
462 * we did not offer it any feature bits beyond 31. Such a
463 * guest passing us any bit here is therefore buggy.
465 virtio_set_features(vdev
,
466 (vdev
->guest_features
& 0x00000000ffffffffULL
) |
467 ((uint64_t)features
.features
<< 32));
470 * If the guest supports more feature bits, assert that it
471 * passes us zeroes for those we don't support.
473 if (features
.features
) {
474 fprintf(stderr
, "Guest bug: features[%i]=%x (expected 0)\n",
475 features
.index
, features
.features
);
476 /* XXX: do a unit check here? */
479 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(features
);
483 case CCW_CMD_READ_CONF
:
485 if (ccw
.count
> vdev
->config_len
) {
490 len
= MIN(ccw
.count
, vdev
->config_len
);
494 virtio_bus_get_vdev_config(&dev
->bus
, vdev
->config
);
495 /* XXX config space endianness */
496 cpu_physical_memory_write(ccw
.cda
, vdev
->config
, len
);
497 sch
->curr_status
.scsw
.count
= ccw
.count
- len
;
501 case CCW_CMD_WRITE_CONF
:
503 if (ccw
.count
> vdev
->config_len
) {
508 len
= MIN(ccw
.count
, vdev
->config_len
);
513 config
= cpu_physical_memory_map(ccw
.cda
, &hw_len
, 0);
518 /* XXX config space endianness */
519 memcpy(vdev
->config
, config
, len
);
520 cpu_physical_memory_unmap(config
, hw_len
, 0, hw_len
);
521 virtio_bus_set_vdev_config(&dev
->bus
, vdev
->config
);
522 sch
->curr_status
.scsw
.count
= ccw
.count
- len
;
527 case CCW_CMD_WRITE_STATUS
:
529 if (ccw
.count
!= sizeof(status
)) {
533 } else if (ccw
.count
< sizeof(status
)) {
534 /* Can't execute command. */
541 status
= address_space_ldub(&address_space_memory
, ccw
.cda
,
542 MEMTXATTRS_UNSPECIFIED
, NULL
);
543 if (!(status
& VIRTIO_CONFIG_S_DRIVER_OK
)) {
544 virtio_ccw_stop_ioeventfd(dev
);
546 if (virtio_set_status(vdev
, status
) == 0) {
547 if (vdev
->status
== 0) {
548 virtio_ccw_reset_virtio(dev
, vdev
);
550 if (status
& VIRTIO_CONFIG_S_DRIVER_OK
) {
551 virtio_ccw_start_ioeventfd(dev
);
553 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(status
);
556 /* Trigger a command reject. */
561 case CCW_CMD_SET_IND
:
563 if (ccw
.count
!= sizeof(indicators
)) {
567 } else if (ccw
.count
< sizeof(indicators
)) {
568 /* Can't execute command. */
572 if (sch
->thinint_active
) {
573 /* Trigger a command reject. */
580 indicators
= address_space_ldq_be(&address_space_memory
, ccw
.cda
,
581 MEMTXATTRS_UNSPECIFIED
, NULL
);
582 dev
->indicators
= get_indicator(indicators
, sizeof(uint64_t));
583 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(indicators
);
587 case CCW_CMD_SET_CONF_IND
:
589 if (ccw
.count
!= sizeof(indicators
)) {
593 } else if (ccw
.count
< sizeof(indicators
)) {
594 /* Can't execute command. */
601 indicators
= address_space_ldq_be(&address_space_memory
, ccw
.cda
,
602 MEMTXATTRS_UNSPECIFIED
, NULL
);
603 dev
->indicators2
= get_indicator(indicators
, sizeof(uint64_t));
604 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(indicators
);
608 case CCW_CMD_READ_VQ_CONF
:
610 if (ccw
.count
!= sizeof(vq_config
)) {
614 } else if (ccw
.count
< sizeof(vq_config
)) {
615 /* Can't execute command. */
622 vq_config
.index
= address_space_lduw_be(&address_space_memory
,
624 MEMTXATTRS_UNSPECIFIED
,
626 if (vq_config
.index
>= VIRTIO_CCW_QUEUE_MAX
) {
630 vq_config
.num_max
= virtio_queue_get_num(vdev
,
632 address_space_stw_be(&address_space_memory
,
633 ccw
.cda
+ sizeof(vq_config
.index
),
635 MEMTXATTRS_UNSPECIFIED
,
637 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(vq_config
);
641 case CCW_CMD_SET_IND_ADAPTER
:
643 if (ccw
.count
!= sizeof(*thinint
)) {
647 } else if (ccw
.count
< sizeof(*thinint
)) {
648 /* Can't execute command. */
652 len
= sizeof(*thinint
);
656 } else if (dev
->indicators
&& !sch
->thinint_active
) {
657 /* Trigger a command reject. */
660 thinint
= cpu_physical_memory_map(ccw
.cda
, &hw_len
, 0);
664 uint64_t ind_bit
= ldq_be_p(&thinint
->ind_bit
);
667 dev
->summary_indicator
=
668 get_indicator(ldq_be_p(&thinint
->summary_indicator
),
671 get_indicator(ldq_be_p(&thinint
->device_indicator
),
673 dev
->thinint_isc
= thinint
->isc
;
674 dev
->routes
.adapter
.ind_offset
= ind_bit
;
675 dev
->routes
.adapter
.summary_offset
= 7;
676 cpu_physical_memory_unmap(thinint
, hw_len
, 0, hw_len
);
677 ret
= css_register_io_adapter(CSS_IO_ADAPTER_VIRTIO
,
678 dev
->thinint_isc
, true, false,
679 &dev
->routes
.adapter
.adapter_id
);
681 sch
->thinint_active
= ((dev
->indicators
!= NULL
) &&
682 (dev
->summary_indicator
!= NULL
));
683 sch
->curr_status
.scsw
.count
= ccw
.count
- len
;
688 case CCW_CMD_SET_VIRTIO_REV
:
689 len
= sizeof(revinfo
);
690 if (ccw
.count
< len
) {
699 address_space_lduw_be(&address_space_memory
, ccw
.cda
,
700 MEMTXATTRS_UNSPECIFIED
, NULL
);
702 address_space_lduw_be(&address_space_memory
,
703 ccw
.cda
+ sizeof(revinfo
.revision
),
704 MEMTXATTRS_UNSPECIFIED
, NULL
);
705 if (ccw
.count
< len
+ revinfo
.length
||
706 (check_len
&& ccw
.count
> len
+ revinfo
.length
)) {
711 * Once we start to support revisions with additional data, we'll
712 * need to fetch it here. Nothing to do for now, though.
714 if (dev
->revision
>= 0 ||
715 revinfo
.revision
> virtio_ccw_rev_max(dev
)) {
720 dev
->revision
= revinfo
.revision
;
729 static void virtio_sch_disable_cb(SubchDev
*sch
)
731 VirtioCcwDevice
*dev
= sch
->driver_data
;
736 static void virtio_ccw_device_realize(VirtioCcwDevice
*dev
, Error
**errp
)
738 unsigned int cssid
= 0;
739 unsigned int ssid
= 0;
742 bool have_devno
= false;
747 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_GET_CLASS(dev
);
749 sch
= g_malloc0(sizeof(SubchDev
));
751 sch
->driver_data
= dev
;
754 dev
->indicators
= NULL
;
756 /* Initialize subchannel structure. */
757 sch
->channel_prog
= 0x0;
758 sch
->last_cmd_valid
= false;
759 sch
->thinint_active
= false;
761 * Use a device number if provided. Otherwise, fall back to subchannel
765 num
= sscanf(dev
->bus_id
, "%x.%x.%04x", &cssid
, &ssid
, &devno
);
767 if ((cssid
> MAX_CSSID
) || (ssid
> MAX_SSID
)) {
768 error_setg(errp
, "Invalid cssid or ssid: cssid %x, ssid %x",
772 /* Enforce use of virtual cssid. */
773 if (cssid
!= VIRTUAL_CSSID
) {
774 error_setg(errp
, "cssid %x not valid for virtio devices",
778 if (css_devno_used(cssid
, ssid
, devno
)) {
779 error_setg(errp
, "Device %x.%x.%04x already exists",
788 error_setg(errp
, "Malformed devno parameter '%s'", dev
->bus_id
);
793 /* Find the next free id. */
795 for (schid
= 0; schid
<= MAX_SCHID
; schid
++) {
796 if (!css_find_subch(1, cssid
, ssid
, schid
)) {
798 css_subch_assign(cssid
, ssid
, schid
, devno
, sch
);
804 error_setg(errp
, "No free subchannel found for %x.%x.%04x",
808 trace_virtio_ccw_new_device(cssid
, ssid
, schid
, devno
,
811 cssid
= VIRTUAL_CSSID
;
812 for (ssid
= 0; ssid
<= MAX_SSID
; ssid
++) {
813 for (schid
= 0; schid
<= MAX_SCHID
; schid
++) {
814 if (!css_find_subch(1, cssid
, ssid
, schid
)) {
820 * If the devno is already taken, look further in this
823 while (css_devno_used(cssid
, ssid
, devno
)) {
824 if (devno
== MAX_SCHID
) {
826 } else if (devno
== schid
- 1) {
827 error_setg(errp
, "No free devno found");
834 css_subch_assign(cssid
, ssid
, schid
, devno
, sch
);
844 error_setg(errp
, "Virtual channel subsystem is full!");
847 trace_virtio_ccw_new_device(cssid
, ssid
, schid
, devno
,
851 /* Build initial schib. */
852 css_sch_build_virtual_schib(sch
, 0, VIRTIO_CCW_CHPID_TYPE
);
854 sch
->ccw_cb
= virtio_ccw_cb
;
855 sch
->disable_cb
= virtio_sch_disable_cb
;
857 /* Build senseid data. */
858 memset(&sch
->id
, 0, sizeof(SenseId
));
859 sch
->id
.reserved
= 0xff;
860 sch
->id
.cu_type
= VIRTIO_CCW_CU_TYPE
;
865 k
->realize(dev
, &err
);
868 error_propagate(errp
, err
);
869 css_subch_assign(cssid
, ssid
, schid
, devno
, NULL
);
880 static int virtio_ccw_exit(VirtioCcwDevice
*dev
)
882 SubchDev
*sch
= dev
->sch
;
885 css_subch_assign(sch
->cssid
, sch
->ssid
, sch
->schid
, sch
->devno
, NULL
);
888 if (dev
->indicators
) {
889 release_indicator(&dev
->routes
.adapter
, dev
->indicators
);
890 dev
->indicators
= NULL
;
895 static void virtio_ccw_net_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
897 DeviceState
*qdev
= DEVICE(ccw_dev
);
898 VirtIONetCcw
*dev
= VIRTIO_NET_CCW(ccw_dev
);
899 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
902 virtio_net_set_netclient_name(&dev
->vdev
, qdev
->id
,
903 object_get_typename(OBJECT(qdev
)));
904 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
905 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
907 error_propagate(errp
, err
);
911 static void virtio_ccw_net_instance_init(Object
*obj
)
913 VirtIONetCcw
*dev
= VIRTIO_NET_CCW(obj
);
915 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
917 object_property_add_alias(obj
, "bootindex", OBJECT(&dev
->vdev
),
918 "bootindex", &error_abort
);
921 static void virtio_ccw_blk_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
923 VirtIOBlkCcw
*dev
= VIRTIO_BLK_CCW(ccw_dev
);
924 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
927 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
928 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
930 error_propagate(errp
, err
);
934 static void virtio_ccw_blk_instance_init(Object
*obj
)
936 VirtIOBlkCcw
*dev
= VIRTIO_BLK_CCW(obj
);
938 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
940 object_property_add_alias(obj
, "iothread", OBJECT(&dev
->vdev
),"iothread",
942 object_property_add_alias(obj
, "bootindex", OBJECT(&dev
->vdev
),
943 "bootindex", &error_abort
);
946 static void virtio_ccw_serial_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
948 VirtioSerialCcw
*dev
= VIRTIO_SERIAL_CCW(ccw_dev
);
949 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
950 DeviceState
*proxy
= DEVICE(ccw_dev
);
955 * For command line compatibility, this sets the virtio-serial-device bus
959 bus_name
= g_strdup_printf("%s.0", proxy
->id
);
960 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev
), bus_name
);
964 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
965 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
967 error_propagate(errp
, err
);
972 static void virtio_ccw_serial_instance_init(Object
*obj
)
974 VirtioSerialCcw
*dev
= VIRTIO_SERIAL_CCW(obj
);
976 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
980 static void virtio_ccw_balloon_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
982 VirtIOBalloonCcw
*dev
= VIRTIO_BALLOON_CCW(ccw_dev
);
983 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
986 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
987 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
989 error_propagate(errp
, err
);
993 static void virtio_ccw_balloon_instance_init(Object
*obj
)
995 VirtIOBalloonCcw
*dev
= VIRTIO_BALLOON_CCW(obj
);
997 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
998 TYPE_VIRTIO_BALLOON
);
999 object_property_add_alias(obj
, "guest-stats", OBJECT(&dev
->vdev
),
1000 "guest-stats", &error_abort
);
1001 object_property_add_alias(obj
, "guest-stats-polling-interval",
1003 "guest-stats-polling-interval", &error_abort
);
1006 static void virtio_ccw_scsi_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
1008 VirtIOSCSICcw
*dev
= VIRTIO_SCSI_CCW(ccw_dev
);
1009 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
1010 DeviceState
*qdev
= DEVICE(ccw_dev
);
1015 * For command line compatibility, this sets the virtio-scsi-device bus
1019 bus_name
= g_strdup_printf("%s.0", qdev
->id
);
1020 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev
), bus_name
);
1024 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
1025 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
1027 error_propagate(errp
, err
);
1031 static void virtio_ccw_scsi_instance_init(Object
*obj
)
1033 VirtIOSCSICcw
*dev
= VIRTIO_SCSI_CCW(obj
);
1035 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
1037 object_property_add_alias(obj
, "iothread", OBJECT(&dev
->vdev
), "iothread",
1041 #ifdef CONFIG_VHOST_SCSI
1042 static void vhost_ccw_scsi_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
1044 VHostSCSICcw
*dev
= VHOST_SCSI_CCW(ccw_dev
);
1045 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
1048 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
1049 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
1051 error_propagate(errp
, err
);
1055 static void vhost_ccw_scsi_instance_init(Object
*obj
)
1057 VHostSCSICcw
*dev
= VHOST_SCSI_CCW(obj
);
1059 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
1064 static void virtio_ccw_rng_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
1066 VirtIORNGCcw
*dev
= VIRTIO_RNG_CCW(ccw_dev
);
1067 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
1070 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
1071 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
1073 error_propagate(errp
, err
);
1077 object_property_set_link(OBJECT(dev
),
1078 OBJECT(dev
->vdev
.conf
.rng
), "rng",
1082 /* DeviceState to VirtioCcwDevice. Note: used on datapath,
1083 * be careful and test performance if you change this.
1085 static inline VirtioCcwDevice
*to_virtio_ccw_dev_fast(DeviceState
*d
)
1087 return container_of(d
, VirtioCcwDevice
, parent_obj
);
1090 static uint8_t virtio_set_ind_atomic(SubchDev
*sch
, uint64_t ind_loc
,
1093 uint8_t ind_old
, ind_new
;
1097 ind_addr
= cpu_physical_memory_map(ind_loc
, &len
, 1);
1099 error_report("%s(%x.%x.%04x): unable to access indicator",
1100 __func__
, sch
->cssid
, sch
->ssid
, sch
->schid
);
1104 ind_old
= *ind_addr
;
1105 ind_new
= ind_old
| to_be_set
;
1106 } while (atomic_cmpxchg(ind_addr
, ind_old
, ind_new
) != ind_old
);
1107 cpu_physical_memory_unmap(ind_addr
, len
, 1, len
);
1112 static void virtio_ccw_notify(DeviceState
*d
, uint16_t vector
)
1114 VirtioCcwDevice
*dev
= to_virtio_ccw_dev_fast(d
);
1115 SubchDev
*sch
= dev
->sch
;
1116 uint64_t indicators
;
1118 /* queue indicators + secondary indicators */
1119 if (vector
>= VIRTIO_CCW_QUEUE_MAX
+ 64) {
1123 if (vector
< VIRTIO_CCW_QUEUE_MAX
) {
1124 if (!dev
->indicators
) {
1127 if (sch
->thinint_active
) {
1129 * In the adapter interrupt case, indicators points to a
1130 * memory area that may be (way) larger than 64 bit and
1131 * ind_bit indicates the start of the indicators in a big
1134 uint64_t ind_bit
= dev
->routes
.adapter
.ind_offset
;
1136 virtio_set_ind_atomic(sch
, dev
->indicators
->addr
+
1137 (ind_bit
+ vector
) / 8,
1138 0x80 >> ((ind_bit
+ vector
) % 8));
1139 if (!virtio_set_ind_atomic(sch
, dev
->summary_indicator
->addr
,
1141 css_adapter_interrupt(dev
->thinint_isc
);
1144 indicators
= address_space_ldq(&address_space_memory
,
1145 dev
->indicators
->addr
,
1146 MEMTXATTRS_UNSPECIFIED
,
1148 indicators
|= 1ULL << vector
;
1149 address_space_stq(&address_space_memory
, dev
->indicators
->addr
,
1150 indicators
, MEMTXATTRS_UNSPECIFIED
, NULL
);
1151 css_conditional_io_interrupt(sch
);
1154 if (!dev
->indicators2
) {
1158 indicators
= address_space_ldq(&address_space_memory
,
1159 dev
->indicators2
->addr
,
1160 MEMTXATTRS_UNSPECIFIED
,
1162 indicators
|= 1ULL << vector
;
1163 address_space_stq(&address_space_memory
, dev
->indicators2
->addr
,
1164 indicators
, MEMTXATTRS_UNSPECIFIED
, NULL
);
1165 css_conditional_io_interrupt(sch
);
1169 static void virtio_ccw_reset(DeviceState
*d
)
1171 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1172 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1174 virtio_ccw_reset_virtio(dev
, vdev
);
1175 css_reset_sch(dev
->sch
);
1178 static void virtio_ccw_vmstate_change(DeviceState
*d
, bool running
)
1180 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1183 virtio_ccw_start_ioeventfd(dev
);
1185 virtio_ccw_stop_ioeventfd(dev
);
1189 static bool virtio_ccw_query_guest_notifiers(DeviceState
*d
)
1191 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1193 return !!(dev
->sch
->curr_status
.pmcw
.flags
& PMCW_FLAGS_MASK_ENA
);
1196 static int virtio_ccw_set_host_notifier(DeviceState
*d
, int n
, bool assign
)
1198 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1200 /* Stop using the generic ioeventfd, we are doing eventfd handling
1201 * ourselves below */
1202 dev
->ioeventfd_disabled
= assign
;
1204 virtio_ccw_stop_ioeventfd(dev
);
1206 return virtio_ccw_set_guest2host_notifier(dev
, n
, assign
, false);
1209 static int virtio_ccw_get_mappings(VirtioCcwDevice
*dev
)
1213 if (!dev
->sch
->thinint_active
) {
1217 r
= map_indicator(&dev
->routes
.adapter
, dev
->summary_indicator
);
1221 r
= map_indicator(&dev
->routes
.adapter
, dev
->indicators
);
1225 dev
->routes
.adapter
.summary_addr
= dev
->summary_indicator
->map
;
1226 dev
->routes
.adapter
.ind_addr
= dev
->indicators
->map
;
1231 static int virtio_ccw_setup_irqroutes(VirtioCcwDevice
*dev
, int nvqs
)
1234 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1236 S390FLICState
*fs
= s390_get_flic();
1237 S390FLICStateClass
*fsc
= S390_FLIC_COMMON_GET_CLASS(fs
);
1239 ret
= virtio_ccw_get_mappings(dev
);
1243 for (i
= 0; i
< nvqs
; i
++) {
1244 if (!virtio_queue_get_num(vdev
, i
)) {
1248 dev
->routes
.num_routes
= i
;
1249 return fsc
->add_adapter_routes(fs
, &dev
->routes
);
1252 static void virtio_ccw_release_irqroutes(VirtioCcwDevice
*dev
, int nvqs
)
1254 S390FLICState
*fs
= s390_get_flic();
1255 S390FLICStateClass
*fsc
= S390_FLIC_COMMON_GET_CLASS(fs
);
1257 fsc
->release_adapter_routes(fs
, &dev
->routes
);
1260 static int virtio_ccw_add_irqfd(VirtioCcwDevice
*dev
, int n
)
1262 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1263 VirtQueue
*vq
= virtio_get_queue(vdev
, n
);
1264 EventNotifier
*notifier
= virtio_queue_get_guest_notifier(vq
);
1266 return kvm_irqchip_add_irqfd_notifier_gsi(kvm_state
, notifier
, NULL
,
1267 dev
->routes
.gsi
[n
]);
1270 static void virtio_ccw_remove_irqfd(VirtioCcwDevice
*dev
, int n
)
1272 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1273 VirtQueue
*vq
= virtio_get_queue(vdev
, n
);
1274 EventNotifier
*notifier
= virtio_queue_get_guest_notifier(vq
);
1277 ret
= kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state
, notifier
,
1278 dev
->routes
.gsi
[n
]);
1282 static int virtio_ccw_set_guest_notifier(VirtioCcwDevice
*dev
, int n
,
1283 bool assign
, bool with_irqfd
)
1285 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1286 VirtQueue
*vq
= virtio_get_queue(vdev
, n
);
1287 EventNotifier
*notifier
= virtio_queue_get_guest_notifier(vq
);
1288 VirtioDeviceClass
*k
= VIRTIO_DEVICE_GET_CLASS(vdev
);
1291 int r
= event_notifier_init(notifier
, 0);
1296 virtio_queue_set_guest_notifier_fd_handler(vq
, true, with_irqfd
);
1298 r
= virtio_ccw_add_irqfd(dev
, n
);
1300 virtio_queue_set_guest_notifier_fd_handler(vq
, false,
1306 * We do not support individual masking for channel devices, so we
1307 * need to manually trigger any guest masking callbacks here.
1309 if (k
->guest_notifier_mask
) {
1310 k
->guest_notifier_mask(vdev
, n
, false);
1312 /* get lost events and re-inject */
1313 if (k
->guest_notifier_pending
&&
1314 k
->guest_notifier_pending(vdev
, n
)) {
1315 event_notifier_set(notifier
);
1318 if (k
->guest_notifier_mask
) {
1319 k
->guest_notifier_mask(vdev
, n
, true);
1322 virtio_ccw_remove_irqfd(dev
, n
);
1324 virtio_queue_set_guest_notifier_fd_handler(vq
, false, with_irqfd
);
1325 event_notifier_cleanup(notifier
);
1330 static int virtio_ccw_set_guest_notifiers(DeviceState
*d
, int nvqs
,
1333 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1334 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1335 bool with_irqfd
= dev
->sch
->thinint_active
&& kvm_irqfds_enabled();
1338 if (with_irqfd
&& assigned
) {
1339 /* irq routes need to be set up before assigning irqfds */
1340 r
= virtio_ccw_setup_irqroutes(dev
, nvqs
);
1342 goto irqroute_error
;
1345 for (n
= 0; n
< nvqs
; n
++) {
1346 if (!virtio_queue_get_num(vdev
, n
)) {
1349 r
= virtio_ccw_set_guest_notifier(dev
, n
, assigned
, with_irqfd
);
1354 if (with_irqfd
&& !assigned
) {
1355 /* release irq routes after irqfds have been released */
1356 virtio_ccw_release_irqroutes(dev
, nvqs
);
1362 virtio_ccw_set_guest_notifier(dev
, n
, !assigned
, false);
1365 if (with_irqfd
&& assigned
) {
1366 virtio_ccw_release_irqroutes(dev
, nvqs
);
1371 static void virtio_ccw_save_queue(DeviceState
*d
, int n
, QEMUFile
*f
)
1373 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1374 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1376 qemu_put_be16(f
, virtio_queue_vector(vdev
, n
));
1379 static int virtio_ccw_load_queue(DeviceState
*d
, int n
, QEMUFile
*f
)
1381 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1382 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1385 qemu_get_be16s(f
, &vector
);
1386 virtio_queue_set_vector(vdev
, n
, vector
);
1391 static void virtio_ccw_save_config(DeviceState
*d
, QEMUFile
*f
)
1393 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1394 SubchDev
*s
= dev
->sch
;
1395 VirtIODevice
*vdev
= virtio_ccw_get_vdev(s
);
1397 subch_device_save(s
, f
);
1398 if (dev
->indicators
!= NULL
) {
1399 qemu_put_be32(f
, dev
->indicators
->len
);
1400 qemu_put_be64(f
, dev
->indicators
->addr
);
1402 qemu_put_be32(f
, 0);
1403 qemu_put_be64(f
, 0UL);
1405 if (dev
->indicators2
!= NULL
) {
1406 qemu_put_be32(f
, dev
->indicators2
->len
);
1407 qemu_put_be64(f
, dev
->indicators2
->addr
);
1409 qemu_put_be32(f
, 0);
1410 qemu_put_be64(f
, 0UL);
1412 if (dev
->summary_indicator
!= NULL
) {
1413 qemu_put_be32(f
, dev
->summary_indicator
->len
);
1414 qemu_put_be64(f
, dev
->summary_indicator
->addr
);
1416 qemu_put_be32(f
, 0);
1417 qemu_put_be64(f
, 0UL);
1419 qemu_put_be16(f
, vdev
->config_vector
);
1420 qemu_put_be64(f
, dev
->routes
.adapter
.ind_offset
);
1421 qemu_put_byte(f
, dev
->thinint_isc
);
1422 qemu_put_be32(f
, dev
->revision
);
1425 static int virtio_ccw_load_config(DeviceState
*d
, QEMUFile
*f
)
1427 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1428 SubchDev
*s
= dev
->sch
;
1429 VirtIODevice
*vdev
= virtio_ccw_get_vdev(s
);
1432 s
->driver_data
= dev
;
1433 subch_device_load(s
, f
);
1434 len
= qemu_get_be32(f
);
1436 dev
->indicators
= get_indicator(qemu_get_be64(f
), len
);
1439 dev
->indicators
= NULL
;
1441 len
= qemu_get_be32(f
);
1443 dev
->indicators2
= get_indicator(qemu_get_be64(f
), len
);
1446 dev
->indicators2
= NULL
;
1448 len
= qemu_get_be32(f
);
1450 dev
->summary_indicator
= get_indicator(qemu_get_be64(f
), len
);
1453 dev
->summary_indicator
= NULL
;
1455 qemu_get_be16s(f
, &vdev
->config_vector
);
1456 dev
->routes
.adapter
.ind_offset
= qemu_get_be64(f
);
1457 dev
->thinint_isc
= qemu_get_byte(f
);
1458 dev
->revision
= qemu_get_be32(f
);
1459 if (s
->thinint_active
) {
1460 return css_register_io_adapter(CSS_IO_ADAPTER_VIRTIO
,
1461 dev
->thinint_isc
, true, false,
1462 &dev
->routes
.adapter
.adapter_id
);
1468 /* This is called by virtio-bus just after the device is plugged. */
1469 static void virtio_ccw_device_plugged(DeviceState
*d
, Error
**errp
)
1471 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1472 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1473 SubchDev
*sch
= dev
->sch
;
1474 int n
= virtio_get_num_queues(vdev
);
1476 if (virtio_get_num_queues(vdev
) > VIRTIO_CCW_QUEUE_MAX
) {
1477 error_setg(errp
, "The nubmer of virtqueues %d "
1478 "exceeds ccw limit %d", n
,
1479 VIRTIO_CCW_QUEUE_MAX
);
1483 if (!kvm_eventfds_enabled()) {
1484 dev
->flags
&= ~VIRTIO_CCW_FLAG_USE_IOEVENTFD
;
1487 sch
->id
.cu_model
= virtio_bus_get_vdev_id(&dev
->bus
);
1489 if (dev
->max_rev
>= 1) {
1490 virtio_add_feature(&vdev
->host_features
, VIRTIO_F_VERSION_1
);
1493 css_generate_sch_crws(sch
->cssid
, sch
->ssid
, sch
->schid
,
1497 static void virtio_ccw_post_plugged(DeviceState
*d
, Error
**errp
)
1499 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1500 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1502 if (!virtio_host_has_feature(vdev
, VIRTIO_F_VERSION_1
)) {
1503 /* A backend didn't support modern virtio. */
1508 static void virtio_ccw_device_unplugged(DeviceState
*d
)
1510 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1512 virtio_ccw_stop_ioeventfd(dev
);
1514 /**************** Virtio-ccw Bus Device Descriptions *******************/
1516 static Property virtio_ccw_net_properties
[] = {
1517 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1518 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1519 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1520 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice
, max_rev
,
1521 VIRTIO_CCW_MAX_REV
),
1522 DEFINE_PROP_END_OF_LIST(),
1525 static void virtio_ccw_net_class_init(ObjectClass
*klass
, void *data
)
1527 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1528 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1530 k
->realize
= virtio_ccw_net_realize
;
1531 k
->exit
= virtio_ccw_exit
;
1532 dc
->reset
= virtio_ccw_reset
;
1533 dc
->props
= virtio_ccw_net_properties
;
1534 set_bit(DEVICE_CATEGORY_NETWORK
, dc
->categories
);
1537 static const TypeInfo virtio_ccw_net
= {
1538 .name
= TYPE_VIRTIO_NET_CCW
,
1539 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1540 .instance_size
= sizeof(VirtIONetCcw
),
1541 .instance_init
= virtio_ccw_net_instance_init
,
1542 .class_init
= virtio_ccw_net_class_init
,
1545 static Property virtio_ccw_blk_properties
[] = {
1546 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1547 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1548 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1549 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice
, max_rev
,
1550 VIRTIO_CCW_MAX_REV
),
1551 DEFINE_PROP_END_OF_LIST(),
1554 static void virtio_ccw_blk_class_init(ObjectClass
*klass
, void *data
)
1556 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1557 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1559 k
->realize
= virtio_ccw_blk_realize
;
1560 k
->exit
= virtio_ccw_exit
;
1561 dc
->reset
= virtio_ccw_reset
;
1562 dc
->props
= virtio_ccw_blk_properties
;
1563 set_bit(DEVICE_CATEGORY_STORAGE
, dc
->categories
);
1566 static const TypeInfo virtio_ccw_blk
= {
1567 .name
= TYPE_VIRTIO_BLK_CCW
,
1568 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1569 .instance_size
= sizeof(VirtIOBlkCcw
),
1570 .instance_init
= virtio_ccw_blk_instance_init
,
1571 .class_init
= virtio_ccw_blk_class_init
,
1574 static Property virtio_ccw_serial_properties
[] = {
1575 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1576 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1577 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1578 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice
, max_rev
,
1579 VIRTIO_CCW_MAX_REV
),
1580 DEFINE_PROP_END_OF_LIST(),
1583 static void virtio_ccw_serial_class_init(ObjectClass
*klass
, void *data
)
1585 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1586 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1588 k
->realize
= virtio_ccw_serial_realize
;
1589 k
->exit
= virtio_ccw_exit
;
1590 dc
->reset
= virtio_ccw_reset
;
1591 dc
->props
= virtio_ccw_serial_properties
;
1592 set_bit(DEVICE_CATEGORY_INPUT
, dc
->categories
);
1595 static const TypeInfo virtio_ccw_serial
= {
1596 .name
= TYPE_VIRTIO_SERIAL_CCW
,
1597 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1598 .instance_size
= sizeof(VirtioSerialCcw
),
1599 .instance_init
= virtio_ccw_serial_instance_init
,
1600 .class_init
= virtio_ccw_serial_class_init
,
1603 static Property virtio_ccw_balloon_properties
[] = {
1604 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1605 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1606 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1607 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice
, max_rev
,
1608 VIRTIO_CCW_MAX_REV
),
1609 DEFINE_PROP_END_OF_LIST(),
1612 static void virtio_ccw_balloon_class_init(ObjectClass
*klass
, void *data
)
1614 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1615 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1617 k
->realize
= virtio_ccw_balloon_realize
;
1618 k
->exit
= virtio_ccw_exit
;
1619 dc
->reset
= virtio_ccw_reset
;
1620 dc
->props
= virtio_ccw_balloon_properties
;
1621 set_bit(DEVICE_CATEGORY_MISC
, dc
->categories
);
1624 static const TypeInfo virtio_ccw_balloon
= {
1625 .name
= TYPE_VIRTIO_BALLOON_CCW
,
1626 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1627 .instance_size
= sizeof(VirtIOBalloonCcw
),
1628 .instance_init
= virtio_ccw_balloon_instance_init
,
1629 .class_init
= virtio_ccw_balloon_class_init
,
1632 static Property virtio_ccw_scsi_properties
[] = {
1633 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1634 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1635 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1636 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice
, max_rev
,
1637 VIRTIO_CCW_MAX_REV
),
1638 DEFINE_PROP_END_OF_LIST(),
1641 static void virtio_ccw_scsi_class_init(ObjectClass
*klass
, void *data
)
1643 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1644 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1646 k
->realize
= virtio_ccw_scsi_realize
;
1647 k
->exit
= virtio_ccw_exit
;
1648 dc
->reset
= virtio_ccw_reset
;
1649 dc
->props
= virtio_ccw_scsi_properties
;
1650 set_bit(DEVICE_CATEGORY_STORAGE
, dc
->categories
);
1653 static const TypeInfo virtio_ccw_scsi
= {
1654 .name
= TYPE_VIRTIO_SCSI_CCW
,
1655 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1656 .instance_size
= sizeof(VirtIOSCSICcw
),
1657 .instance_init
= virtio_ccw_scsi_instance_init
,
1658 .class_init
= virtio_ccw_scsi_class_init
,
1661 #ifdef CONFIG_VHOST_SCSI
1662 static Property vhost_ccw_scsi_properties
[] = {
1663 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1664 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice
, max_rev
,
1665 VIRTIO_CCW_MAX_REV
),
1666 DEFINE_PROP_END_OF_LIST(),
1669 static void vhost_ccw_scsi_class_init(ObjectClass
*klass
, void *data
)
1671 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1672 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1674 k
->realize
= vhost_ccw_scsi_realize
;
1675 k
->exit
= virtio_ccw_exit
;
1676 dc
->reset
= virtio_ccw_reset
;
1677 dc
->props
= vhost_ccw_scsi_properties
;
1678 set_bit(DEVICE_CATEGORY_STORAGE
, dc
->categories
);
1681 static const TypeInfo vhost_ccw_scsi
= {
1682 .name
= TYPE_VHOST_SCSI_CCW
,
1683 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1684 .instance_size
= sizeof(VHostSCSICcw
),
1685 .instance_init
= vhost_ccw_scsi_instance_init
,
1686 .class_init
= vhost_ccw_scsi_class_init
,
1690 static void virtio_ccw_rng_instance_init(Object
*obj
)
1692 VirtIORNGCcw
*dev
= VIRTIO_RNG_CCW(obj
);
1694 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
1696 object_property_add_alias(obj
, "rng", OBJECT(&dev
->vdev
),
1697 "rng", &error_abort
);
1700 static Property virtio_ccw_rng_properties
[] = {
1701 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1702 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1703 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1704 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice
, max_rev
,
1705 VIRTIO_CCW_MAX_REV
),
1706 DEFINE_PROP_END_OF_LIST(),
1709 static void virtio_ccw_rng_class_init(ObjectClass
*klass
, void *data
)
1711 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1712 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1714 k
->realize
= virtio_ccw_rng_realize
;
1715 k
->exit
= virtio_ccw_exit
;
1716 dc
->reset
= virtio_ccw_reset
;
1717 dc
->props
= virtio_ccw_rng_properties
;
1718 set_bit(DEVICE_CATEGORY_MISC
, dc
->categories
);
1721 static const TypeInfo virtio_ccw_rng
= {
1722 .name
= TYPE_VIRTIO_RNG_CCW
,
1723 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1724 .instance_size
= sizeof(VirtIORNGCcw
),
1725 .instance_init
= virtio_ccw_rng_instance_init
,
1726 .class_init
= virtio_ccw_rng_class_init
,
1729 static void virtio_ccw_busdev_realize(DeviceState
*dev
, Error
**errp
)
1731 VirtioCcwDevice
*_dev
= (VirtioCcwDevice
*)dev
;
1733 virtio_ccw_bus_new(&_dev
->bus
, sizeof(_dev
->bus
), _dev
);
1734 virtio_ccw_device_realize(_dev
, errp
);
1737 static int virtio_ccw_busdev_exit(DeviceState
*dev
)
1739 VirtioCcwDevice
*_dev
= (VirtioCcwDevice
*)dev
;
1740 VirtIOCCWDeviceClass
*_info
= VIRTIO_CCW_DEVICE_GET_CLASS(dev
);
1742 return _info
->exit(_dev
);
1745 static void virtio_ccw_busdev_unplug(HotplugHandler
*hotplug_dev
,
1746 DeviceState
*dev
, Error
**errp
)
1748 VirtioCcwDevice
*_dev
= (VirtioCcwDevice
*)dev
;
1749 SubchDev
*sch
= _dev
->sch
;
1751 virtio_ccw_stop_ioeventfd(_dev
);
1754 * We should arrive here only for device_del, since we don't support
1755 * direct hot(un)plug of channels, but only through virtio.
1757 assert(sch
!= NULL
);
1758 /* Subchannel is now disabled and no longer valid. */
1759 sch
->curr_status
.pmcw
.flags
&= ~(PMCW_FLAGS_MASK_ENA
|
1760 PMCW_FLAGS_MASK_DNV
);
1762 css_generate_sch_crws(sch
->cssid
, sch
->ssid
, sch
->schid
, 1, 0);
1764 object_unparent(OBJECT(dev
));
1767 static void virtio_ccw_device_class_init(ObjectClass
*klass
, void *data
)
1769 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1771 dc
->realize
= virtio_ccw_busdev_realize
;
1772 dc
->exit
= virtio_ccw_busdev_exit
;
1773 dc
->bus_type
= TYPE_VIRTUAL_CSS_BUS
;
1776 static const TypeInfo virtio_ccw_device_info
= {
1777 .name
= TYPE_VIRTIO_CCW_DEVICE
,
1778 .parent
= TYPE_DEVICE
,
1779 .instance_size
= sizeof(VirtioCcwDevice
),
1780 .class_init
= virtio_ccw_device_class_init
,
1781 .class_size
= sizeof(VirtIOCCWDeviceClass
),
1785 /***************** Virtual-css Bus Bridge Device ********************/
1786 /* Only required to have the virtio bus as child in the system bus */
1788 static int virtual_css_bridge_init(SysBusDevice
*dev
)
1794 static void virtual_css_bridge_class_init(ObjectClass
*klass
, void *data
)
1796 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
1797 HotplugHandlerClass
*hc
= HOTPLUG_HANDLER_CLASS(klass
);
1798 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1800 k
->init
= virtual_css_bridge_init
;
1801 hc
->unplug
= virtio_ccw_busdev_unplug
;
1802 set_bit(DEVICE_CATEGORY_BRIDGE
, dc
->categories
);
1805 static const TypeInfo virtual_css_bridge_info
= {
1806 .name
= "virtual-css-bridge",
1807 .parent
= TYPE_SYS_BUS_DEVICE
,
1808 .instance_size
= sizeof(SysBusDevice
),
1809 .class_init
= virtual_css_bridge_class_init
,
1810 .interfaces
= (InterfaceInfo
[]) {
1811 { TYPE_HOTPLUG_HANDLER
},
1816 /* virtio-ccw-bus */
1818 static void virtio_ccw_bus_new(VirtioBusState
*bus
, size_t bus_size
,
1819 VirtioCcwDevice
*dev
)
1821 DeviceState
*qdev
= DEVICE(dev
);
1822 char virtio_bus_name
[] = "virtio-bus";
1824 qbus_create_inplace(bus
, bus_size
, TYPE_VIRTIO_CCW_BUS
,
1825 qdev
, virtio_bus_name
);
1828 static void virtio_ccw_bus_class_init(ObjectClass
*klass
, void *data
)
1830 VirtioBusClass
*k
= VIRTIO_BUS_CLASS(klass
);
1831 BusClass
*bus_class
= BUS_CLASS(klass
);
1833 bus_class
->max_dev
= 1;
1834 k
->notify
= virtio_ccw_notify
;
1835 k
->vmstate_change
= virtio_ccw_vmstate_change
;
1836 k
->query_guest_notifiers
= virtio_ccw_query_guest_notifiers
;
1837 k
->set_host_notifier
= virtio_ccw_set_host_notifier
;
1838 k
->set_guest_notifiers
= virtio_ccw_set_guest_notifiers
;
1839 k
->save_queue
= virtio_ccw_save_queue
;
1840 k
->load_queue
= virtio_ccw_load_queue
;
1841 k
->save_config
= virtio_ccw_save_config
;
1842 k
->load_config
= virtio_ccw_load_config
;
1843 k
->device_plugged
= virtio_ccw_device_plugged
;
1844 k
->post_plugged
= virtio_ccw_post_plugged
;
1845 k
->device_unplugged
= virtio_ccw_device_unplugged
;
1848 static const TypeInfo virtio_ccw_bus_info
= {
1849 .name
= TYPE_VIRTIO_CCW_BUS
,
1850 .parent
= TYPE_VIRTIO_BUS
,
1851 .instance_size
= sizeof(VirtioCcwBusState
),
1852 .class_init
= virtio_ccw_bus_class_init
,
1855 #ifdef CONFIG_VIRTFS
1856 static Property virtio_ccw_9p_properties
[] = {
1857 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1858 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1859 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1860 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice
, max_rev
,
1861 VIRTIO_CCW_MAX_REV
),
1862 DEFINE_PROP_END_OF_LIST(),
1865 static void virtio_ccw_9p_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
1867 V9fsCCWState
*dev
= VIRTIO_9P_CCW(ccw_dev
);
1868 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
1871 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
1872 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
1874 error_propagate(errp
, err
);
1878 static void virtio_ccw_9p_class_init(ObjectClass
*klass
, void *data
)
1880 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1881 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1883 k
->exit
= virtio_ccw_exit
;
1884 k
->realize
= virtio_ccw_9p_realize
;
1885 dc
->reset
= virtio_ccw_reset
;
1886 dc
->props
= virtio_ccw_9p_properties
;
1887 set_bit(DEVICE_CATEGORY_STORAGE
, dc
->categories
);
1890 static void virtio_ccw_9p_instance_init(Object
*obj
)
1892 V9fsCCWState
*dev
= VIRTIO_9P_CCW(obj
);
1894 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
1898 static const TypeInfo virtio_ccw_9p_info
= {
1899 .name
= TYPE_VIRTIO_9P_CCW
,
1900 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1901 .instance_size
= sizeof(V9fsCCWState
),
1902 .instance_init
= virtio_ccw_9p_instance_init
,
1903 .class_init
= virtio_ccw_9p_class_init
,
1907 static void virtio_ccw_register(void)
1909 type_register_static(&virtio_ccw_bus_info
);
1910 type_register_static(&virtual_css_bus_info
);
1911 type_register_static(&virtio_ccw_device_info
);
1912 type_register_static(&virtio_ccw_serial
);
1913 type_register_static(&virtio_ccw_blk
);
1914 type_register_static(&virtio_ccw_net
);
1915 type_register_static(&virtio_ccw_balloon
);
1916 type_register_static(&virtio_ccw_scsi
);
1917 #ifdef CONFIG_VHOST_SCSI
1918 type_register_static(&vhost_ccw_scsi
);
1920 type_register_static(&virtio_ccw_rng
);
1921 type_register_static(&virtual_css_bridge_info
);
1922 #ifdef CONFIG_VIRTFS
1923 type_register_static(&virtio_ccw_9p_info
);
1927 type_init(virtio_ccw_register
)