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"
14 #include "qapi/error.h"
16 #include "sysemu/block-backend.h"
17 #include "sysemu/blockdev.h"
18 #include "sysemu/sysemu.h"
19 #include "sysemu/kvm.h"
21 #include "hw/virtio/virtio.h"
22 #include "hw/virtio/virtio-serial.h"
23 #include "hw/virtio/virtio-net.h"
24 #include "hw/sysbus.h"
25 #include "qemu/bitops.h"
26 #include "qemu/error-report.h"
27 #include "hw/virtio/virtio-access.h"
28 #include "hw/virtio/virtio-bus.h"
29 #include "hw/s390x/adapter.h"
30 #include "hw/s390x/s390_flic.h"
32 #include "hw/s390x/ioinst.h"
33 #include "hw/s390x/css.h"
34 #include "virtio-ccw.h"
36 #include "hw/s390x/css-bridge.h"
38 static void virtio_ccw_bus_new(VirtioBusState
*bus
, size_t bus_size
,
39 VirtioCcwDevice
*dev
);
41 VirtIODevice
*virtio_ccw_get_vdev(SubchDev
*sch
)
43 VirtIODevice
*vdev
= NULL
;
44 VirtioCcwDevice
*dev
= sch
->driver_data
;
47 vdev
= virtio_bus_get_device(&dev
->bus
);
52 static void virtio_ccw_start_ioeventfd(VirtioCcwDevice
*dev
)
54 virtio_bus_start_ioeventfd(&dev
->bus
);
57 static void virtio_ccw_stop_ioeventfd(VirtioCcwDevice
*dev
)
59 virtio_bus_stop_ioeventfd(&dev
->bus
);
62 static bool virtio_ccw_ioeventfd_enabled(DeviceState
*d
)
64 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
66 return (dev
->flags
& VIRTIO_CCW_FLAG_USE_IOEVENTFD
) != 0;
69 static int virtio_ccw_ioeventfd_assign(DeviceState
*d
, EventNotifier
*notifier
,
72 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
73 CcwDevice
*ccw_dev
= CCW_DEVICE(dev
);
74 SubchDev
*sch
= ccw_dev
->sch
;
75 uint32_t sch_id
= (css_build_subchannel_id(sch
) << 16) | sch
->schid
;
77 return s390_assign_subch_ioeventfd(notifier
, sch_id
, n
, assign
);
80 /* Communication blocks used by several channel commands. */
81 typedef struct VqInfoBlockLegacy
{
86 } QEMU_PACKED VqInfoBlockLegacy
;
88 typedef struct VqInfoBlock
{
95 } QEMU_PACKED VqInfoBlock
;
97 typedef struct VqConfigBlock
{
100 } QEMU_PACKED VqConfigBlock
;
102 typedef struct VirtioFeatDesc
{
105 } QEMU_PACKED VirtioFeatDesc
;
107 typedef struct VirtioThinintInfo
{
108 hwaddr summary_indicator
;
109 hwaddr device_indicator
;
112 } QEMU_PACKED VirtioThinintInfo
;
114 typedef struct VirtioRevInfo
{
118 } QEMU_PACKED VirtioRevInfo
;
120 /* Specify where the virtqueues for the subchannel are in guest memory. */
121 static int virtio_ccw_set_vqs(SubchDev
*sch
, VqInfoBlock
*info
,
122 VqInfoBlockLegacy
*linfo
)
124 VirtIODevice
*vdev
= virtio_ccw_get_vdev(sch
);
125 uint16_t index
= info
? info
->index
: linfo
->index
;
126 uint16_t num
= info
? info
->num
: linfo
->num
;
127 uint64_t desc
= info
? info
->desc
: linfo
->queue
;
129 if (index
>= VIRTIO_CCW_QUEUE_MAX
) {
133 /* Current code in virtio.c relies on 4K alignment. */
134 if (linfo
&& desc
&& (linfo
->align
!= 4096)) {
143 virtio_queue_set_rings(vdev
, index
, desc
, info
->avail
, info
->used
);
145 virtio_queue_set_addr(vdev
, index
, desc
);
148 virtio_queue_set_vector(vdev
, index
, VIRTIO_NO_VECTOR
);
151 /* virtio-1 allows changing the ring size. */
152 if (virtio_queue_get_max_num(vdev
, index
) < num
) {
153 /* Fail if we exceed the maximum number. */
156 virtio_queue_set_num(vdev
, index
, num
);
157 } else if (virtio_queue_get_num(vdev
, index
) > num
) {
158 /* Fail if we don't have a big enough queue. */
161 /* We ignore possible increased num for legacy for compatibility. */
162 virtio_queue_set_vector(vdev
, index
, index
);
164 /* tell notify handler in case of config change */
165 vdev
->config_vector
= VIRTIO_CCW_QUEUE_MAX
;
169 static void virtio_ccw_reset_virtio(VirtioCcwDevice
*dev
, VirtIODevice
*vdev
)
171 CcwDevice
*ccw_dev
= CCW_DEVICE(dev
);
173 virtio_ccw_stop_ioeventfd(dev
);
175 if (dev
->indicators
) {
176 release_indicator(&dev
->routes
.adapter
, dev
->indicators
);
177 dev
->indicators
= NULL
;
179 if (dev
->indicators2
) {
180 release_indicator(&dev
->routes
.adapter
, dev
->indicators2
);
181 dev
->indicators2
= NULL
;
183 if (dev
->summary_indicator
) {
184 release_indicator(&dev
->routes
.adapter
, dev
->summary_indicator
);
185 dev
->summary_indicator
= NULL
;
187 ccw_dev
->sch
->thinint_active
= false;
190 static int virtio_ccw_handle_set_vq(SubchDev
*sch
, CCW1 ccw
, bool check_len
,
195 VqInfoBlockLegacy linfo
;
196 size_t info_len
= is_legacy
? sizeof(linfo
) : sizeof(info
);
199 if (ccw
.count
!= info_len
) {
202 } else if (ccw
.count
< info_len
) {
203 /* Can't execute command. */
210 linfo
.queue
= address_space_ldq_be(&address_space_memory
, ccw
.cda
,
211 MEMTXATTRS_UNSPECIFIED
, NULL
);
212 linfo
.align
= address_space_ldl_be(&address_space_memory
,
213 ccw
.cda
+ sizeof(linfo
.queue
),
214 MEMTXATTRS_UNSPECIFIED
,
216 linfo
.index
= address_space_lduw_be(&address_space_memory
,
217 ccw
.cda
+ sizeof(linfo
.queue
)
218 + sizeof(linfo
.align
),
219 MEMTXATTRS_UNSPECIFIED
,
221 linfo
.num
= address_space_lduw_be(&address_space_memory
,
222 ccw
.cda
+ sizeof(linfo
.queue
)
223 + sizeof(linfo
.align
)
224 + sizeof(linfo
.index
),
225 MEMTXATTRS_UNSPECIFIED
,
227 ret
= virtio_ccw_set_vqs(sch
, NULL
, &linfo
);
229 info
.desc
= address_space_ldq_be(&address_space_memory
, ccw
.cda
,
230 MEMTXATTRS_UNSPECIFIED
, NULL
);
231 info
.index
= address_space_lduw_be(&address_space_memory
,
232 ccw
.cda
+ sizeof(info
.desc
)
234 MEMTXATTRS_UNSPECIFIED
, NULL
);
235 info
.num
= address_space_lduw_be(&address_space_memory
,
236 ccw
.cda
+ sizeof(info
.desc
)
238 + sizeof(info
.index
),
239 MEMTXATTRS_UNSPECIFIED
, NULL
);
240 info
.avail
= address_space_ldq_be(&address_space_memory
,
241 ccw
.cda
+ sizeof(info
.desc
)
245 MEMTXATTRS_UNSPECIFIED
, NULL
);
246 info
.used
= address_space_ldq_be(&address_space_memory
,
247 ccw
.cda
+ sizeof(info
.desc
)
251 + sizeof(info
.avail
),
252 MEMTXATTRS_UNSPECIFIED
, NULL
);
253 ret
= virtio_ccw_set_vqs(sch
, &info
, NULL
);
255 sch
->curr_status
.scsw
.count
= 0;
259 static int virtio_ccw_cb(SubchDev
*sch
, CCW1 ccw
)
262 VirtioRevInfo revinfo
;
264 VirtioFeatDesc features
;
267 VqConfigBlock vq_config
;
268 VirtioCcwDevice
*dev
= sch
->driver_data
;
269 VirtIODevice
*vdev
= virtio_ccw_get_vdev(sch
);
273 VirtioThinintInfo
*thinint
;
279 trace_virtio_ccw_interpret_ccw(sch
->cssid
, sch
->ssid
, sch
->schid
,
281 check_len
= !((ccw
.flags
& CCW_FLAG_SLI
) && !(ccw
.flags
& CCW_FLAG_DC
));
283 /* Look at the command. */
284 switch (ccw
.cmd_code
) {
286 ret
= virtio_ccw_handle_set_vq(sch
, ccw
, check_len
, dev
->revision
< 1);
288 case CCW_CMD_VDEV_RESET
:
289 virtio_ccw_reset_virtio(dev
, vdev
);
292 case CCW_CMD_READ_FEAT
:
294 if (ccw
.count
!= sizeof(features
)) {
298 } else if (ccw
.count
< sizeof(features
)) {
299 /* Can't execute command. */
306 VirtioDeviceClass
*vdc
= VIRTIO_DEVICE_GET_CLASS(vdev
);
308 features
.index
= address_space_ldub(&address_space_memory
,
310 + sizeof(features
.features
),
311 MEMTXATTRS_UNSPECIFIED
,
313 if (features
.index
== 0) {
314 if (dev
->revision
>= 1) {
315 /* Don't offer legacy features for modern devices. */
316 features
.features
= (uint32_t)
317 (vdev
->host_features
& ~vdc
->legacy_features
);
319 features
.features
= (uint32_t)vdev
->host_features
;
321 } else if ((features
.index
== 1) && (dev
->revision
>= 1)) {
323 * Only offer feature bits beyond 31 if the guest has
324 * negotiated at least revision 1.
326 features
.features
= (uint32_t)(vdev
->host_features
>> 32);
328 /* Return zeroes if the guest supports more feature bits. */
329 features
.features
= 0;
331 address_space_stl_le(&address_space_memory
, ccw
.cda
,
332 features
.features
, MEMTXATTRS_UNSPECIFIED
,
334 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(features
);
338 case CCW_CMD_WRITE_FEAT
:
340 if (ccw
.count
!= sizeof(features
)) {
344 } else if (ccw
.count
< sizeof(features
)) {
345 /* Can't execute command. */
352 features
.index
= address_space_ldub(&address_space_memory
,
354 + sizeof(features
.features
),
355 MEMTXATTRS_UNSPECIFIED
,
357 features
.features
= address_space_ldl_le(&address_space_memory
,
359 MEMTXATTRS_UNSPECIFIED
,
361 if (features
.index
== 0) {
362 virtio_set_features(vdev
,
363 (vdev
->guest_features
& 0xffffffff00000000ULL
) |
365 } else if ((features
.index
== 1) && (dev
->revision
>= 1)) {
367 * If the guest did not negotiate at least revision 1,
368 * we did not offer it any feature bits beyond 31. Such a
369 * guest passing us any bit here is therefore buggy.
371 virtio_set_features(vdev
,
372 (vdev
->guest_features
& 0x00000000ffffffffULL
) |
373 ((uint64_t)features
.features
<< 32));
376 * If the guest supports more feature bits, assert that it
377 * passes us zeroes for those we don't support.
379 if (features
.features
) {
380 fprintf(stderr
, "Guest bug: features[%i]=%x (expected 0)\n",
381 features
.index
, features
.features
);
382 /* XXX: do a unit check here? */
385 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(features
);
389 case CCW_CMD_READ_CONF
:
391 if (ccw
.count
> vdev
->config_len
) {
396 len
= MIN(ccw
.count
, vdev
->config_len
);
400 virtio_bus_get_vdev_config(&dev
->bus
, vdev
->config
);
401 /* XXX config space endianness */
402 cpu_physical_memory_write(ccw
.cda
, vdev
->config
, len
);
403 sch
->curr_status
.scsw
.count
= ccw
.count
- len
;
407 case CCW_CMD_WRITE_CONF
:
409 if (ccw
.count
> vdev
->config_len
) {
414 len
= MIN(ccw
.count
, vdev
->config_len
);
419 config
= cpu_physical_memory_map(ccw
.cda
, &hw_len
, 0);
424 /* XXX config space endianness */
425 memcpy(vdev
->config
, config
, len
);
426 cpu_physical_memory_unmap(config
, hw_len
, 0, hw_len
);
427 virtio_bus_set_vdev_config(&dev
->bus
, vdev
->config
);
428 sch
->curr_status
.scsw
.count
= ccw
.count
- len
;
433 case CCW_CMD_READ_STATUS
:
435 if (ccw
.count
!= sizeof(status
)) {
439 } else if (ccw
.count
< sizeof(status
)) {
440 /* Can't execute command. */
447 address_space_stb(&address_space_memory
, ccw
.cda
, vdev
->status
,
448 MEMTXATTRS_UNSPECIFIED
, NULL
);
449 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(vdev
->status
);;
453 case CCW_CMD_WRITE_STATUS
:
455 if (ccw
.count
!= sizeof(status
)) {
459 } else if (ccw
.count
< sizeof(status
)) {
460 /* Can't execute command. */
467 status
= address_space_ldub(&address_space_memory
, ccw
.cda
,
468 MEMTXATTRS_UNSPECIFIED
, NULL
);
469 if (!(status
& VIRTIO_CONFIG_S_DRIVER_OK
)) {
470 virtio_ccw_stop_ioeventfd(dev
);
472 if (virtio_set_status(vdev
, status
) == 0) {
473 if (vdev
->status
== 0) {
474 virtio_ccw_reset_virtio(dev
, vdev
);
476 if (status
& VIRTIO_CONFIG_S_DRIVER_OK
) {
477 virtio_ccw_start_ioeventfd(dev
);
479 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(status
);
482 /* Trigger a command reject. */
487 case CCW_CMD_SET_IND
:
489 if (ccw
.count
!= sizeof(indicators
)) {
493 } else if (ccw
.count
< sizeof(indicators
)) {
494 /* Can't execute command. */
498 if (sch
->thinint_active
) {
499 /* Trigger a command reject. */
506 indicators
= address_space_ldq_be(&address_space_memory
, ccw
.cda
,
507 MEMTXATTRS_UNSPECIFIED
, NULL
);
508 dev
->indicators
= get_indicator(indicators
, sizeof(uint64_t));
509 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(indicators
);
513 case CCW_CMD_SET_CONF_IND
:
515 if (ccw
.count
!= sizeof(indicators
)) {
519 } else if (ccw
.count
< sizeof(indicators
)) {
520 /* Can't execute command. */
527 indicators
= address_space_ldq_be(&address_space_memory
, ccw
.cda
,
528 MEMTXATTRS_UNSPECIFIED
, NULL
);
529 dev
->indicators2
= get_indicator(indicators
, sizeof(uint64_t));
530 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(indicators
);
534 case CCW_CMD_READ_VQ_CONF
:
536 if (ccw
.count
!= sizeof(vq_config
)) {
540 } else if (ccw
.count
< sizeof(vq_config
)) {
541 /* Can't execute command. */
548 vq_config
.index
= address_space_lduw_be(&address_space_memory
,
550 MEMTXATTRS_UNSPECIFIED
,
552 if (vq_config
.index
>= VIRTIO_CCW_QUEUE_MAX
) {
556 vq_config
.num_max
= virtio_queue_get_num(vdev
,
558 address_space_stw_be(&address_space_memory
,
559 ccw
.cda
+ sizeof(vq_config
.index
),
561 MEMTXATTRS_UNSPECIFIED
,
563 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(vq_config
);
567 case CCW_CMD_SET_IND_ADAPTER
:
569 if (ccw
.count
!= sizeof(*thinint
)) {
573 } else if (ccw
.count
< sizeof(*thinint
)) {
574 /* Can't execute command. */
578 len
= sizeof(*thinint
);
582 } else if (dev
->indicators
&& !sch
->thinint_active
) {
583 /* Trigger a command reject. */
586 thinint
= cpu_physical_memory_map(ccw
.cda
, &hw_len
, 0);
590 uint64_t ind_bit
= ldq_be_p(&thinint
->ind_bit
);
593 dev
->summary_indicator
=
594 get_indicator(ldq_be_p(&thinint
->summary_indicator
),
597 get_indicator(ldq_be_p(&thinint
->device_indicator
),
599 dev
->thinint_isc
= thinint
->isc
;
600 dev
->routes
.adapter
.ind_offset
= ind_bit
;
601 dev
->routes
.adapter
.summary_offset
= 7;
602 cpu_physical_memory_unmap(thinint
, hw_len
, 0, hw_len
);
603 ret
= css_register_io_adapter(CSS_IO_ADAPTER_VIRTIO
,
604 dev
->thinint_isc
, true, false,
605 &dev
->routes
.adapter
.adapter_id
);
607 sch
->thinint_active
= ((dev
->indicators
!= NULL
) &&
608 (dev
->summary_indicator
!= NULL
));
609 sch
->curr_status
.scsw
.count
= ccw
.count
- len
;
614 case CCW_CMD_SET_VIRTIO_REV
:
615 len
= sizeof(revinfo
);
616 if (ccw
.count
< len
) {
625 address_space_lduw_be(&address_space_memory
, ccw
.cda
,
626 MEMTXATTRS_UNSPECIFIED
, NULL
);
628 address_space_lduw_be(&address_space_memory
,
629 ccw
.cda
+ sizeof(revinfo
.revision
),
630 MEMTXATTRS_UNSPECIFIED
, NULL
);
631 if (ccw
.count
< len
+ revinfo
.length
||
632 (check_len
&& ccw
.count
> len
+ revinfo
.length
)) {
637 * Once we start to support revisions with additional data, we'll
638 * need to fetch it here. Nothing to do for now, though.
640 if (dev
->revision
>= 0 ||
641 revinfo
.revision
> virtio_ccw_rev_max(dev
)) {
646 dev
->revision
= revinfo
.revision
;
655 static void virtio_sch_disable_cb(SubchDev
*sch
)
657 VirtioCcwDevice
*dev
= sch
->driver_data
;
662 static void virtio_ccw_device_realize(VirtioCcwDevice
*dev
, Error
**errp
)
664 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_GET_CLASS(dev
);
665 CcwDevice
*ccw_dev
= CCW_DEVICE(dev
);
666 SubchDev
*sch
= css_create_virtual_sch(ccw_dev
->bus_id
, errp
);
673 sch
->driver_data
= dev
;
674 sch
->ccw_cb
= virtio_ccw_cb
;
675 sch
->disable_cb
= virtio_sch_disable_cb
;
676 sch
->id
.reserved
= 0xff;
677 sch
->id
.cu_type
= VIRTIO_CCW_CU_TYPE
;
679 dev
->indicators
= NULL
;
681 css_sch_build_virtual_schib(sch
, 0, VIRTIO_CCW_CHPID_TYPE
);
683 trace_virtio_ccw_new_device(
684 sch
->cssid
, sch
->ssid
, sch
->schid
, sch
->devno
,
685 ccw_dev
->bus_id
.valid
? "user-configured" : "auto-configured");
687 if (!kvm_eventfds_enabled()) {
688 dev
->flags
&= ~VIRTIO_CCW_FLAG_USE_IOEVENTFD
;
692 k
->realize(dev
, &err
);
695 error_propagate(errp
, err
);
696 css_subch_assign(sch
->cssid
, sch
->ssid
, sch
->schid
, sch
->devno
, NULL
);
702 static int virtio_ccw_exit(VirtioCcwDevice
*dev
)
704 CcwDevice
*ccw_dev
= CCW_DEVICE(dev
);
705 SubchDev
*sch
= ccw_dev
->sch
;
708 css_subch_assign(sch
->cssid
, sch
->ssid
, sch
->schid
, sch
->devno
, NULL
);
711 if (dev
->indicators
) {
712 release_indicator(&dev
->routes
.adapter
, dev
->indicators
);
713 dev
->indicators
= NULL
;
718 static void virtio_ccw_net_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
720 DeviceState
*qdev
= DEVICE(ccw_dev
);
721 VirtIONetCcw
*dev
= VIRTIO_NET_CCW(ccw_dev
);
722 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
724 virtio_net_set_netclient_name(&dev
->vdev
, qdev
->id
,
725 object_get_typename(OBJECT(qdev
)));
726 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
727 object_property_set_bool(OBJECT(vdev
), true, "realized", errp
);
730 static void virtio_ccw_net_instance_init(Object
*obj
)
732 VirtIONetCcw
*dev
= VIRTIO_NET_CCW(obj
);
734 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
736 object_property_add_alias(obj
, "bootindex", OBJECT(&dev
->vdev
),
737 "bootindex", &error_abort
);
740 static void virtio_ccw_blk_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
742 VirtIOBlkCcw
*dev
= VIRTIO_BLK_CCW(ccw_dev
);
743 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
745 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
746 object_property_set_bool(OBJECT(vdev
), true, "realized", errp
);
749 static void virtio_ccw_blk_instance_init(Object
*obj
)
751 VirtIOBlkCcw
*dev
= VIRTIO_BLK_CCW(obj
);
753 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
755 object_property_add_alias(obj
, "iothread", OBJECT(&dev
->vdev
),"iothread",
757 object_property_add_alias(obj
, "bootindex", OBJECT(&dev
->vdev
),
758 "bootindex", &error_abort
);
761 static void virtio_ccw_serial_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
763 VirtioSerialCcw
*dev
= VIRTIO_SERIAL_CCW(ccw_dev
);
764 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
765 DeviceState
*proxy
= DEVICE(ccw_dev
);
769 * For command line compatibility, this sets the virtio-serial-device bus
773 bus_name
= g_strdup_printf("%s.0", proxy
->id
);
774 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev
), bus_name
);
778 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
779 object_property_set_bool(OBJECT(vdev
), true, "realized", errp
);
783 static void virtio_ccw_serial_instance_init(Object
*obj
)
785 VirtioSerialCcw
*dev
= VIRTIO_SERIAL_CCW(obj
);
787 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
791 static void virtio_ccw_balloon_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
793 VirtIOBalloonCcw
*dev
= VIRTIO_BALLOON_CCW(ccw_dev
);
794 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
796 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
797 object_property_set_bool(OBJECT(vdev
), true, "realized", errp
);
800 static void virtio_ccw_balloon_instance_init(Object
*obj
)
802 VirtIOBalloonCcw
*dev
= VIRTIO_BALLOON_CCW(obj
);
804 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
805 TYPE_VIRTIO_BALLOON
);
806 object_property_add_alias(obj
, "guest-stats", OBJECT(&dev
->vdev
),
807 "guest-stats", &error_abort
);
808 object_property_add_alias(obj
, "guest-stats-polling-interval",
810 "guest-stats-polling-interval", &error_abort
);
813 static void virtio_ccw_scsi_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
815 VirtIOSCSICcw
*dev
= VIRTIO_SCSI_CCW(ccw_dev
);
816 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
817 DeviceState
*qdev
= DEVICE(ccw_dev
);
821 * For command line compatibility, this sets the virtio-scsi-device bus
825 bus_name
= g_strdup_printf("%s.0", qdev
->id
);
826 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev
), bus_name
);
830 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
831 object_property_set_bool(OBJECT(vdev
), true, "realized", errp
);
834 static void virtio_ccw_scsi_instance_init(Object
*obj
)
836 VirtIOSCSICcw
*dev
= VIRTIO_SCSI_CCW(obj
);
838 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
840 object_property_add_alias(obj
, "iothread", OBJECT(&dev
->vdev
), "iothread",
844 #ifdef CONFIG_VHOST_SCSI
845 static void vhost_ccw_scsi_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
847 VHostSCSICcw
*dev
= VHOST_SCSI_CCW(ccw_dev
);
848 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
850 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
851 object_property_set_bool(OBJECT(vdev
), true, "realized", errp
);
854 static void vhost_ccw_scsi_instance_init(Object
*obj
)
856 VHostSCSICcw
*dev
= VHOST_SCSI_CCW(obj
);
858 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
863 static void virtio_ccw_rng_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
865 VirtIORNGCcw
*dev
= VIRTIO_RNG_CCW(ccw_dev
);
866 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
869 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
870 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
872 error_propagate(errp
, err
);
876 object_property_set_link(OBJECT(dev
),
877 OBJECT(dev
->vdev
.conf
.rng
), "rng",
881 /* DeviceState to VirtioCcwDevice. Note: used on datapath,
882 * be careful and test performance if you change this.
884 static inline VirtioCcwDevice
*to_virtio_ccw_dev_fast(DeviceState
*d
)
886 CcwDevice
*ccw_dev
= to_ccw_dev_fast(d
);
888 return container_of(ccw_dev
, VirtioCcwDevice
, parent_obj
);
891 static uint8_t virtio_set_ind_atomic(SubchDev
*sch
, uint64_t ind_loc
,
894 uint8_t ind_old
, ind_new
;
898 ind_addr
= cpu_physical_memory_map(ind_loc
, &len
, 1);
900 error_report("%s(%x.%x.%04x): unable to access indicator",
901 __func__
, sch
->cssid
, sch
->ssid
, sch
->schid
);
906 ind_new
= ind_old
| to_be_set
;
907 } while (atomic_cmpxchg(ind_addr
, ind_old
, ind_new
) != ind_old
);
908 trace_virtio_ccw_set_ind(ind_loc
, ind_old
, ind_new
);
909 cpu_physical_memory_unmap(ind_addr
, len
, 1, len
);
914 static void virtio_ccw_notify(DeviceState
*d
, uint16_t vector
)
916 VirtioCcwDevice
*dev
= to_virtio_ccw_dev_fast(d
);
917 CcwDevice
*ccw_dev
= to_ccw_dev_fast(d
);
918 SubchDev
*sch
= ccw_dev
->sch
;
921 /* queue indicators + secondary indicators */
922 if (vector
>= VIRTIO_CCW_QUEUE_MAX
+ 64) {
926 if (vector
< VIRTIO_CCW_QUEUE_MAX
) {
927 if (!dev
->indicators
) {
930 if (sch
->thinint_active
) {
932 * In the adapter interrupt case, indicators points to a
933 * memory area that may be (way) larger than 64 bit and
934 * ind_bit indicates the start of the indicators in a big
937 uint64_t ind_bit
= dev
->routes
.adapter
.ind_offset
;
939 virtio_set_ind_atomic(sch
, dev
->indicators
->addr
+
940 (ind_bit
+ vector
) / 8,
941 0x80 >> ((ind_bit
+ vector
) % 8));
942 if (!virtio_set_ind_atomic(sch
, dev
->summary_indicator
->addr
,
944 css_adapter_interrupt(dev
->thinint_isc
);
947 indicators
= address_space_ldq(&address_space_memory
,
948 dev
->indicators
->addr
,
949 MEMTXATTRS_UNSPECIFIED
,
951 indicators
|= 1ULL << vector
;
952 address_space_stq(&address_space_memory
, dev
->indicators
->addr
,
953 indicators
, MEMTXATTRS_UNSPECIFIED
, NULL
);
954 css_conditional_io_interrupt(sch
);
957 if (!dev
->indicators2
) {
961 indicators
= address_space_ldq(&address_space_memory
,
962 dev
->indicators2
->addr
,
963 MEMTXATTRS_UNSPECIFIED
,
965 indicators
|= 1ULL << vector
;
966 address_space_stq(&address_space_memory
, dev
->indicators2
->addr
,
967 indicators
, MEMTXATTRS_UNSPECIFIED
, NULL
);
968 css_conditional_io_interrupt(sch
);
972 static void virtio_ccw_reset(DeviceState
*d
)
974 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
975 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
976 CcwDevice
*ccw_dev
= CCW_DEVICE(d
);
978 virtio_ccw_reset_virtio(dev
, vdev
);
979 css_reset_sch(ccw_dev
->sch
);
982 static void virtio_ccw_vmstate_change(DeviceState
*d
, bool running
)
984 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
987 virtio_ccw_start_ioeventfd(dev
);
989 virtio_ccw_stop_ioeventfd(dev
);
993 static bool virtio_ccw_query_guest_notifiers(DeviceState
*d
)
995 CcwDevice
*dev
= CCW_DEVICE(d
);
997 return !!(dev
->sch
->curr_status
.pmcw
.flags
& PMCW_FLAGS_MASK_ENA
);
1000 static int virtio_ccw_get_mappings(VirtioCcwDevice
*dev
)
1003 CcwDevice
*ccw_dev
= CCW_DEVICE(dev
);
1005 if (!ccw_dev
->sch
->thinint_active
) {
1009 r
= map_indicator(&dev
->routes
.adapter
, dev
->summary_indicator
);
1013 r
= map_indicator(&dev
->routes
.adapter
, dev
->indicators
);
1017 dev
->routes
.adapter
.summary_addr
= dev
->summary_indicator
->map
;
1018 dev
->routes
.adapter
.ind_addr
= dev
->indicators
->map
;
1023 static int virtio_ccw_setup_irqroutes(VirtioCcwDevice
*dev
, int nvqs
)
1026 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1028 S390FLICState
*fs
= s390_get_flic();
1029 S390FLICStateClass
*fsc
= S390_FLIC_COMMON_GET_CLASS(fs
);
1031 ret
= virtio_ccw_get_mappings(dev
);
1035 for (i
= 0; i
< nvqs
; i
++) {
1036 if (!virtio_queue_get_num(vdev
, i
)) {
1040 dev
->routes
.num_routes
= i
;
1041 return fsc
->add_adapter_routes(fs
, &dev
->routes
);
1044 static void virtio_ccw_release_irqroutes(VirtioCcwDevice
*dev
, int nvqs
)
1046 S390FLICState
*fs
= s390_get_flic();
1047 S390FLICStateClass
*fsc
= S390_FLIC_COMMON_GET_CLASS(fs
);
1049 fsc
->release_adapter_routes(fs
, &dev
->routes
);
1052 static int virtio_ccw_add_irqfd(VirtioCcwDevice
*dev
, int n
)
1054 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1055 VirtQueue
*vq
= virtio_get_queue(vdev
, n
);
1056 EventNotifier
*notifier
= virtio_queue_get_guest_notifier(vq
);
1058 return kvm_irqchip_add_irqfd_notifier_gsi(kvm_state
, notifier
, NULL
,
1059 dev
->routes
.gsi
[n
]);
1062 static void virtio_ccw_remove_irqfd(VirtioCcwDevice
*dev
, int n
)
1064 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1065 VirtQueue
*vq
= virtio_get_queue(vdev
, n
);
1066 EventNotifier
*notifier
= virtio_queue_get_guest_notifier(vq
);
1069 ret
= kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state
, notifier
,
1070 dev
->routes
.gsi
[n
]);
1074 static int virtio_ccw_set_guest_notifier(VirtioCcwDevice
*dev
, int n
,
1075 bool assign
, bool with_irqfd
)
1077 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1078 VirtQueue
*vq
= virtio_get_queue(vdev
, n
);
1079 EventNotifier
*notifier
= virtio_queue_get_guest_notifier(vq
);
1080 VirtioDeviceClass
*k
= VIRTIO_DEVICE_GET_CLASS(vdev
);
1083 int r
= event_notifier_init(notifier
, 0);
1088 virtio_queue_set_guest_notifier_fd_handler(vq
, true, with_irqfd
);
1090 r
= virtio_ccw_add_irqfd(dev
, n
);
1092 virtio_queue_set_guest_notifier_fd_handler(vq
, false,
1098 * We do not support individual masking for channel devices, so we
1099 * need to manually trigger any guest masking callbacks here.
1101 if (k
->guest_notifier_mask
&& vdev
->use_guest_notifier_mask
) {
1102 k
->guest_notifier_mask(vdev
, n
, false);
1104 /* get lost events and re-inject */
1105 if (k
->guest_notifier_pending
&&
1106 k
->guest_notifier_pending(vdev
, n
)) {
1107 event_notifier_set(notifier
);
1110 if (k
->guest_notifier_mask
&& vdev
->use_guest_notifier_mask
) {
1111 k
->guest_notifier_mask(vdev
, n
, true);
1114 virtio_ccw_remove_irqfd(dev
, n
);
1116 virtio_queue_set_guest_notifier_fd_handler(vq
, false, with_irqfd
);
1117 event_notifier_cleanup(notifier
);
1122 static int virtio_ccw_set_guest_notifiers(DeviceState
*d
, int nvqs
,
1125 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1126 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1127 CcwDevice
*ccw_dev
= CCW_DEVICE(d
);
1128 bool with_irqfd
= ccw_dev
->sch
->thinint_active
&& kvm_irqfds_enabled();
1131 if (with_irqfd
&& assigned
) {
1132 /* irq routes need to be set up before assigning irqfds */
1133 r
= virtio_ccw_setup_irqroutes(dev
, nvqs
);
1135 goto irqroute_error
;
1138 for (n
= 0; n
< nvqs
; n
++) {
1139 if (!virtio_queue_get_num(vdev
, n
)) {
1142 r
= virtio_ccw_set_guest_notifier(dev
, n
, assigned
, with_irqfd
);
1147 if (with_irqfd
&& !assigned
) {
1148 /* release irq routes after irqfds have been released */
1149 virtio_ccw_release_irqroutes(dev
, nvqs
);
1155 virtio_ccw_set_guest_notifier(dev
, n
, !assigned
, false);
1158 if (with_irqfd
&& assigned
) {
1159 virtio_ccw_release_irqroutes(dev
, nvqs
);
1164 static void virtio_ccw_save_queue(DeviceState
*d
, int n
, QEMUFile
*f
)
1166 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1167 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1169 qemu_put_be16(f
, virtio_queue_vector(vdev
, n
));
1172 static int virtio_ccw_load_queue(DeviceState
*d
, int n
, QEMUFile
*f
)
1174 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1175 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1178 qemu_get_be16s(f
, &vector
);
1179 virtio_queue_set_vector(vdev
, n
, vector
);
1184 static void virtio_ccw_save_config(DeviceState
*d
, QEMUFile
*f
)
1186 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1187 CcwDevice
*ccw_dev
= CCW_DEVICE(d
);
1188 SubchDev
*s
= ccw_dev
->sch
;
1189 VirtIODevice
*vdev
= virtio_ccw_get_vdev(s
);
1191 subch_device_save(s
, f
);
1192 if (dev
->indicators
!= NULL
) {
1193 qemu_put_be32(f
, dev
->indicators
->len
);
1194 qemu_put_be64(f
, dev
->indicators
->addr
);
1196 qemu_put_be32(f
, 0);
1197 qemu_put_be64(f
, 0UL);
1199 if (dev
->indicators2
!= NULL
) {
1200 qemu_put_be32(f
, dev
->indicators2
->len
);
1201 qemu_put_be64(f
, dev
->indicators2
->addr
);
1203 qemu_put_be32(f
, 0);
1204 qemu_put_be64(f
, 0UL);
1206 if (dev
->summary_indicator
!= NULL
) {
1207 qemu_put_be32(f
, dev
->summary_indicator
->len
);
1208 qemu_put_be64(f
, dev
->summary_indicator
->addr
);
1210 qemu_put_be32(f
, 0);
1211 qemu_put_be64(f
, 0UL);
1213 qemu_put_be16(f
, vdev
->config_vector
);
1214 qemu_put_be64(f
, dev
->routes
.adapter
.ind_offset
);
1215 qemu_put_byte(f
, dev
->thinint_isc
);
1216 qemu_put_be32(f
, dev
->revision
);
1219 static int virtio_ccw_load_config(DeviceState
*d
, QEMUFile
*f
)
1221 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1222 CcwDevice
*ccw_dev
= CCW_DEVICE(d
);
1223 SubchDev
*s
= ccw_dev
->sch
;
1224 VirtIODevice
*vdev
= virtio_ccw_get_vdev(s
);
1227 s
->driver_data
= dev
;
1228 subch_device_load(s
, f
);
1229 len
= qemu_get_be32(f
);
1231 dev
->indicators
= get_indicator(qemu_get_be64(f
), len
);
1234 dev
->indicators
= NULL
;
1236 len
= qemu_get_be32(f
);
1238 dev
->indicators2
= get_indicator(qemu_get_be64(f
), len
);
1241 dev
->indicators2
= NULL
;
1243 len
= qemu_get_be32(f
);
1245 dev
->summary_indicator
= get_indicator(qemu_get_be64(f
), len
);
1248 dev
->summary_indicator
= NULL
;
1250 qemu_get_be16s(f
, &vdev
->config_vector
);
1251 dev
->routes
.adapter
.ind_offset
= qemu_get_be64(f
);
1252 dev
->thinint_isc
= qemu_get_byte(f
);
1253 dev
->revision
= qemu_get_be32(f
);
1254 if (s
->thinint_active
) {
1255 return css_register_io_adapter(CSS_IO_ADAPTER_VIRTIO
,
1256 dev
->thinint_isc
, true, false,
1257 &dev
->routes
.adapter
.adapter_id
);
1263 static void virtio_ccw_pre_plugged(DeviceState
*d
, Error
**errp
)
1265 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1266 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1268 if (dev
->max_rev
>= 1) {
1269 virtio_add_feature(&vdev
->host_features
, VIRTIO_F_VERSION_1
);
1273 /* This is called by virtio-bus just after the device is plugged. */
1274 static void virtio_ccw_device_plugged(DeviceState
*d
, Error
**errp
)
1276 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1277 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1278 CcwDevice
*ccw_dev
= CCW_DEVICE(d
);
1279 SubchDev
*sch
= ccw_dev
->sch
;
1280 int n
= virtio_get_num_queues(vdev
);
1282 if (!virtio_has_feature(vdev
->host_features
, VIRTIO_F_VERSION_1
)) {
1286 if (virtio_get_num_queues(vdev
) > VIRTIO_CCW_QUEUE_MAX
) {
1287 error_setg(errp
, "The number of virtqueues %d "
1288 "exceeds ccw limit %d", n
,
1289 VIRTIO_CCW_QUEUE_MAX
);
1293 sch
->id
.cu_model
= virtio_bus_get_vdev_id(&dev
->bus
);
1296 css_generate_sch_crws(sch
->cssid
, sch
->ssid
, sch
->schid
,
1300 static void virtio_ccw_device_unplugged(DeviceState
*d
)
1302 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1304 virtio_ccw_stop_ioeventfd(dev
);
1306 /**************** Virtio-ccw Bus Device Descriptions *******************/
1308 static Property virtio_ccw_net_properties
[] = {
1309 DEFINE_PROP_CSS_DEV_ID("devno", VirtioCcwDevice
, parent_obj
.bus_id
),
1310 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1311 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1312 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice
, max_rev
,
1313 VIRTIO_CCW_MAX_REV
),
1314 DEFINE_PROP_END_OF_LIST(),
1317 static void virtio_ccw_net_class_init(ObjectClass
*klass
, void *data
)
1319 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1320 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1322 k
->realize
= virtio_ccw_net_realize
;
1323 k
->exit
= virtio_ccw_exit
;
1324 dc
->reset
= virtio_ccw_reset
;
1325 dc
->props
= virtio_ccw_net_properties
;
1326 set_bit(DEVICE_CATEGORY_NETWORK
, dc
->categories
);
1329 static const TypeInfo virtio_ccw_net
= {
1330 .name
= TYPE_VIRTIO_NET_CCW
,
1331 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1332 .instance_size
= sizeof(VirtIONetCcw
),
1333 .instance_init
= virtio_ccw_net_instance_init
,
1334 .class_init
= virtio_ccw_net_class_init
,
1337 static Property virtio_ccw_blk_properties
[] = {
1338 DEFINE_PROP_CSS_DEV_ID("devno", VirtioCcwDevice
, parent_obj
.bus_id
),
1339 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1340 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1341 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice
, max_rev
,
1342 VIRTIO_CCW_MAX_REV
),
1343 DEFINE_PROP_END_OF_LIST(),
1346 static void virtio_ccw_blk_class_init(ObjectClass
*klass
, void *data
)
1348 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1349 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1351 k
->realize
= virtio_ccw_blk_realize
;
1352 k
->exit
= virtio_ccw_exit
;
1353 dc
->reset
= virtio_ccw_reset
;
1354 dc
->props
= virtio_ccw_blk_properties
;
1355 set_bit(DEVICE_CATEGORY_STORAGE
, dc
->categories
);
1358 static const TypeInfo virtio_ccw_blk
= {
1359 .name
= TYPE_VIRTIO_BLK_CCW
,
1360 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1361 .instance_size
= sizeof(VirtIOBlkCcw
),
1362 .instance_init
= virtio_ccw_blk_instance_init
,
1363 .class_init
= virtio_ccw_blk_class_init
,
1366 static Property virtio_ccw_serial_properties
[] = {
1367 DEFINE_PROP_CSS_DEV_ID("devno", VirtioCcwDevice
, parent_obj
.bus_id
),
1368 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1369 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1370 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice
, max_rev
,
1371 VIRTIO_CCW_MAX_REV
),
1372 DEFINE_PROP_END_OF_LIST(),
1375 static void virtio_ccw_serial_class_init(ObjectClass
*klass
, void *data
)
1377 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1378 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1380 k
->realize
= virtio_ccw_serial_realize
;
1381 k
->exit
= virtio_ccw_exit
;
1382 dc
->reset
= virtio_ccw_reset
;
1383 dc
->props
= virtio_ccw_serial_properties
;
1384 set_bit(DEVICE_CATEGORY_INPUT
, dc
->categories
);
1387 static const TypeInfo virtio_ccw_serial
= {
1388 .name
= TYPE_VIRTIO_SERIAL_CCW
,
1389 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1390 .instance_size
= sizeof(VirtioSerialCcw
),
1391 .instance_init
= virtio_ccw_serial_instance_init
,
1392 .class_init
= virtio_ccw_serial_class_init
,
1395 static Property virtio_ccw_balloon_properties
[] = {
1396 DEFINE_PROP_CSS_DEV_ID("devno", VirtioCcwDevice
, parent_obj
.bus_id
),
1397 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1398 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1399 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice
, max_rev
,
1400 VIRTIO_CCW_MAX_REV
),
1401 DEFINE_PROP_END_OF_LIST(),
1404 static void virtio_ccw_balloon_class_init(ObjectClass
*klass
, void *data
)
1406 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1407 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1409 k
->realize
= virtio_ccw_balloon_realize
;
1410 k
->exit
= virtio_ccw_exit
;
1411 dc
->reset
= virtio_ccw_reset
;
1412 dc
->props
= virtio_ccw_balloon_properties
;
1413 set_bit(DEVICE_CATEGORY_MISC
, dc
->categories
);
1416 static const TypeInfo virtio_ccw_balloon
= {
1417 .name
= TYPE_VIRTIO_BALLOON_CCW
,
1418 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1419 .instance_size
= sizeof(VirtIOBalloonCcw
),
1420 .instance_init
= virtio_ccw_balloon_instance_init
,
1421 .class_init
= virtio_ccw_balloon_class_init
,
1424 static Property virtio_ccw_scsi_properties
[] = {
1425 DEFINE_PROP_CSS_DEV_ID("devno", VirtioCcwDevice
, parent_obj
.bus_id
),
1426 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1427 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1428 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice
, max_rev
,
1429 VIRTIO_CCW_MAX_REV
),
1430 DEFINE_PROP_END_OF_LIST(),
1433 static void virtio_ccw_scsi_class_init(ObjectClass
*klass
, void *data
)
1435 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1436 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1438 k
->realize
= virtio_ccw_scsi_realize
;
1439 k
->exit
= virtio_ccw_exit
;
1440 dc
->reset
= virtio_ccw_reset
;
1441 dc
->props
= virtio_ccw_scsi_properties
;
1442 set_bit(DEVICE_CATEGORY_STORAGE
, dc
->categories
);
1445 static const TypeInfo virtio_ccw_scsi
= {
1446 .name
= TYPE_VIRTIO_SCSI_CCW
,
1447 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1448 .instance_size
= sizeof(VirtIOSCSICcw
),
1449 .instance_init
= virtio_ccw_scsi_instance_init
,
1450 .class_init
= virtio_ccw_scsi_class_init
,
1453 #ifdef CONFIG_VHOST_SCSI
1454 static Property vhost_ccw_scsi_properties
[] = {
1455 DEFINE_PROP_CSS_DEV_ID("devno", VirtioCcwDevice
, parent_obj
.bus_id
),
1456 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice
, max_rev
,
1457 VIRTIO_CCW_MAX_REV
),
1458 DEFINE_PROP_END_OF_LIST(),
1461 static void vhost_ccw_scsi_class_init(ObjectClass
*klass
, void *data
)
1463 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1464 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1466 k
->realize
= vhost_ccw_scsi_realize
;
1467 k
->exit
= virtio_ccw_exit
;
1468 dc
->reset
= virtio_ccw_reset
;
1469 dc
->props
= vhost_ccw_scsi_properties
;
1470 set_bit(DEVICE_CATEGORY_STORAGE
, dc
->categories
);
1473 static const TypeInfo vhost_ccw_scsi
= {
1474 .name
= TYPE_VHOST_SCSI_CCW
,
1475 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1476 .instance_size
= sizeof(VHostSCSICcw
),
1477 .instance_init
= vhost_ccw_scsi_instance_init
,
1478 .class_init
= vhost_ccw_scsi_class_init
,
1482 static void virtio_ccw_rng_instance_init(Object
*obj
)
1484 VirtIORNGCcw
*dev
= VIRTIO_RNG_CCW(obj
);
1486 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
1488 object_property_add_alias(obj
, "rng", OBJECT(&dev
->vdev
),
1489 "rng", &error_abort
);
1492 static Property virtio_ccw_rng_properties
[] = {
1493 DEFINE_PROP_CSS_DEV_ID("devno", VirtioCcwDevice
, parent_obj
.bus_id
),
1494 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1495 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1496 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice
, max_rev
,
1497 VIRTIO_CCW_MAX_REV
),
1498 DEFINE_PROP_END_OF_LIST(),
1501 static void virtio_ccw_rng_class_init(ObjectClass
*klass
, void *data
)
1503 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1504 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1506 k
->realize
= virtio_ccw_rng_realize
;
1507 k
->exit
= virtio_ccw_exit
;
1508 dc
->reset
= virtio_ccw_reset
;
1509 dc
->props
= virtio_ccw_rng_properties
;
1510 set_bit(DEVICE_CATEGORY_MISC
, dc
->categories
);
1513 static const TypeInfo virtio_ccw_rng
= {
1514 .name
= TYPE_VIRTIO_RNG_CCW
,
1515 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1516 .instance_size
= sizeof(VirtIORNGCcw
),
1517 .instance_init
= virtio_ccw_rng_instance_init
,
1518 .class_init
= virtio_ccw_rng_class_init
,
1521 static void virtio_ccw_busdev_realize(DeviceState
*dev
, Error
**errp
)
1523 VirtioCcwDevice
*_dev
= (VirtioCcwDevice
*)dev
;
1525 virtio_ccw_bus_new(&_dev
->bus
, sizeof(_dev
->bus
), _dev
);
1526 virtio_ccw_device_realize(_dev
, errp
);
1529 static int virtio_ccw_busdev_exit(DeviceState
*dev
)
1531 VirtioCcwDevice
*_dev
= (VirtioCcwDevice
*)dev
;
1532 VirtIOCCWDeviceClass
*_info
= VIRTIO_CCW_DEVICE_GET_CLASS(dev
);
1534 return _info
->exit(_dev
);
1537 static void virtio_ccw_busdev_unplug(HotplugHandler
*hotplug_dev
,
1538 DeviceState
*dev
, Error
**errp
)
1540 VirtioCcwDevice
*_dev
= to_virtio_ccw_dev_fast(dev
);
1542 virtio_ccw_stop_ioeventfd(_dev
);
1545 static void virtio_ccw_device_class_init(ObjectClass
*klass
, void *data
)
1547 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1548 CCWDeviceClass
*k
= CCW_DEVICE_CLASS(dc
);
1550 k
->unplug
= virtio_ccw_busdev_unplug
;
1551 dc
->realize
= virtio_ccw_busdev_realize
;
1552 dc
->exit
= virtio_ccw_busdev_exit
;
1553 dc
->bus_type
= TYPE_VIRTUAL_CSS_BUS
;
1556 static const TypeInfo virtio_ccw_device_info
= {
1557 .name
= TYPE_VIRTIO_CCW_DEVICE
,
1558 .parent
= TYPE_CCW_DEVICE
,
1559 .instance_size
= sizeof(VirtioCcwDevice
),
1560 .class_init
= virtio_ccw_device_class_init
,
1561 .class_size
= sizeof(VirtIOCCWDeviceClass
),
1565 /* virtio-ccw-bus */
1567 static void virtio_ccw_bus_new(VirtioBusState
*bus
, size_t bus_size
,
1568 VirtioCcwDevice
*dev
)
1570 DeviceState
*qdev
= DEVICE(dev
);
1571 char virtio_bus_name
[] = "virtio-bus";
1573 qbus_create_inplace(bus
, bus_size
, TYPE_VIRTIO_CCW_BUS
,
1574 qdev
, virtio_bus_name
);
1577 static void virtio_ccw_bus_class_init(ObjectClass
*klass
, void *data
)
1579 VirtioBusClass
*k
= VIRTIO_BUS_CLASS(klass
);
1580 BusClass
*bus_class
= BUS_CLASS(klass
);
1582 bus_class
->max_dev
= 1;
1583 k
->notify
= virtio_ccw_notify
;
1584 k
->vmstate_change
= virtio_ccw_vmstate_change
;
1585 k
->query_guest_notifiers
= virtio_ccw_query_guest_notifiers
;
1586 k
->set_guest_notifiers
= virtio_ccw_set_guest_notifiers
;
1587 k
->save_queue
= virtio_ccw_save_queue
;
1588 k
->load_queue
= virtio_ccw_load_queue
;
1589 k
->save_config
= virtio_ccw_save_config
;
1590 k
->load_config
= virtio_ccw_load_config
;
1591 k
->pre_plugged
= virtio_ccw_pre_plugged
;
1592 k
->device_plugged
= virtio_ccw_device_plugged
;
1593 k
->device_unplugged
= virtio_ccw_device_unplugged
;
1594 k
->ioeventfd_enabled
= virtio_ccw_ioeventfd_enabled
;
1595 k
->ioeventfd_assign
= virtio_ccw_ioeventfd_assign
;
1598 static const TypeInfo virtio_ccw_bus_info
= {
1599 .name
= TYPE_VIRTIO_CCW_BUS
,
1600 .parent
= TYPE_VIRTIO_BUS
,
1601 .instance_size
= sizeof(VirtioCcwBusState
),
1602 .class_init
= virtio_ccw_bus_class_init
,
1605 #ifdef CONFIG_VIRTFS
1606 static Property virtio_ccw_9p_properties
[] = {
1607 DEFINE_PROP_CSS_DEV_ID("devno", VirtioCcwDevice
, parent_obj
.bus_id
),
1608 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1609 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1610 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice
, max_rev
,
1611 VIRTIO_CCW_MAX_REV
),
1612 DEFINE_PROP_END_OF_LIST(),
1615 static void virtio_ccw_9p_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
1617 V9fsCCWState
*dev
= VIRTIO_9P_CCW(ccw_dev
);
1618 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
1620 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
1621 object_property_set_bool(OBJECT(vdev
), true, "realized", errp
);
1624 static void virtio_ccw_9p_class_init(ObjectClass
*klass
, void *data
)
1626 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1627 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1629 k
->exit
= virtio_ccw_exit
;
1630 k
->realize
= virtio_ccw_9p_realize
;
1631 dc
->reset
= virtio_ccw_reset
;
1632 dc
->props
= virtio_ccw_9p_properties
;
1633 set_bit(DEVICE_CATEGORY_STORAGE
, dc
->categories
);
1636 static void virtio_ccw_9p_instance_init(Object
*obj
)
1638 V9fsCCWState
*dev
= VIRTIO_9P_CCW(obj
);
1640 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
1644 static const TypeInfo virtio_ccw_9p_info
= {
1645 .name
= TYPE_VIRTIO_9P_CCW
,
1646 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1647 .instance_size
= sizeof(V9fsCCWState
),
1648 .instance_init
= virtio_ccw_9p_instance_init
,
1649 .class_init
= virtio_ccw_9p_class_init
,
1653 #ifdef CONFIG_VHOST_VSOCK
1655 static Property vhost_vsock_ccw_properties
[] = {
1656 DEFINE_PROP_CSS_DEV_ID("devno", VirtioCcwDevice
, parent_obj
.bus_id
),
1657 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice
, max_rev
,
1658 VIRTIO_CCW_MAX_REV
),
1659 DEFINE_PROP_END_OF_LIST(),
1662 static void vhost_vsock_ccw_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
1664 VHostVSockCCWState
*dev
= VHOST_VSOCK_CCW(ccw_dev
);
1665 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
1668 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
1669 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
1671 error_propagate(errp
, err
);
1675 static void vhost_vsock_ccw_class_init(ObjectClass
*klass
, void *data
)
1677 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1678 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1680 k
->realize
= vhost_vsock_ccw_realize
;
1681 k
->exit
= virtio_ccw_exit
;
1682 set_bit(DEVICE_CATEGORY_MISC
, dc
->categories
);
1683 dc
->props
= vhost_vsock_ccw_properties
;
1684 dc
->reset
= virtio_ccw_reset
;
1687 static void vhost_vsock_ccw_instance_init(Object
*obj
)
1689 VHostVSockCCWState
*dev
= VHOST_VSOCK_CCW(obj
);
1691 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
1695 static const TypeInfo vhost_vsock_ccw_info
= {
1696 .name
= TYPE_VHOST_VSOCK_CCW
,
1697 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1698 .instance_size
= sizeof(VHostVSockCCWState
),
1699 .instance_init
= vhost_vsock_ccw_instance_init
,
1700 .class_init
= vhost_vsock_ccw_class_init
,
1704 static void virtio_ccw_register(void)
1706 type_register_static(&virtio_ccw_bus_info
);
1707 type_register_static(&virtio_ccw_device_info
);
1708 type_register_static(&virtio_ccw_serial
);
1709 type_register_static(&virtio_ccw_blk
);
1710 type_register_static(&virtio_ccw_net
);
1711 type_register_static(&virtio_ccw_balloon
);
1712 type_register_static(&virtio_ccw_scsi
);
1713 #ifdef CONFIG_VHOST_SCSI
1714 type_register_static(&vhost_ccw_scsi
);
1716 type_register_static(&virtio_ccw_rng
);
1717 #ifdef CONFIG_VIRTFS
1718 type_register_static(&virtio_ccw_9p_info
);
1720 #ifdef CONFIG_VHOST_VSOCK
1721 type_register_static(&vhost_vsock_ccw_info
);
1725 type_init(virtio_ccw_register
)