2 * virtio ccw target implementation
4 * Copyright 2012,2014 IBM Corp.
5 * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
7 * This work is licensed under the terms of the GNU GPL, version 2 or (at
8 * your option) any later version. See the COPYING file in the top-level
13 #include "sysemu/block-backend.h"
14 #include "sysemu/blockdev.h"
15 #include "sysemu/sysemu.h"
17 #include "monitor/monitor.h"
18 #include "hw/virtio/virtio.h"
19 #include "hw/virtio/virtio-serial.h"
20 #include "hw/virtio/virtio-net.h"
21 #include "hw/sysbus.h"
22 #include "qemu/bitops.h"
23 #include "hw/virtio/virtio-bus.h"
24 #include "hw/s390x/adapter.h"
25 #include "hw/s390x/s390_flic.h"
29 #include "virtio-ccw.h"
32 static QTAILQ_HEAD(, IndAddr
) indicator_addresses
=
33 QTAILQ_HEAD_INITIALIZER(indicator_addresses
);
35 static IndAddr
*get_indicator(hwaddr ind_addr
, int len
)
39 QTAILQ_FOREACH(indicator
, &indicator_addresses
, sibling
) {
40 if (indicator
->addr
== ind_addr
) {
45 indicator
= g_new0(IndAddr
, 1);
46 indicator
->addr
= ind_addr
;
48 indicator
->refcnt
= 1;
49 QTAILQ_INSERT_TAIL(&indicator_addresses
, indicator
, sibling
);
53 static int s390_io_adapter_map(AdapterInfo
*adapter
, uint64_t map_addr
,
56 S390FLICState
*fs
= s390_get_flic();
57 S390FLICStateClass
*fsc
= S390_FLIC_COMMON_GET_CLASS(fs
);
59 return fsc
->io_adapter_map(fs
, adapter
->adapter_id
, map_addr
, do_map
);
62 static void release_indicator(AdapterInfo
*adapter
, IndAddr
*indicator
)
64 assert(indicator
->refcnt
> 0);
66 if (indicator
->refcnt
> 0) {
69 QTAILQ_REMOVE(&indicator_addresses
, indicator
, sibling
);
71 s390_io_adapter_map(adapter
, indicator
->map
, false);
76 static int map_indicator(AdapterInfo
*adapter
, IndAddr
*indicator
)
81 return 0; /* already mapped is not an error */
83 indicator
->map
= indicator
->addr
;
84 ret
= s390_io_adapter_map(adapter
, indicator
->map
, true);
85 if ((ret
!= 0) && (ret
!= -ENOSYS
)) {
95 static void virtio_ccw_bus_new(VirtioBusState
*bus
, size_t bus_size
,
96 VirtioCcwDevice
*dev
);
98 static void virtual_css_bus_reset(BusState
*qbus
)
100 /* This should actually be modelled via the generic css */
105 static void virtual_css_bus_class_init(ObjectClass
*klass
, void *data
)
107 BusClass
*k
= BUS_CLASS(klass
);
109 k
->reset
= virtual_css_bus_reset
;
112 static const TypeInfo virtual_css_bus_info
= {
113 .name
= TYPE_VIRTUAL_CSS_BUS
,
115 .instance_size
= sizeof(VirtualCssBus
),
116 .class_init
= virtual_css_bus_class_init
,
119 VirtIODevice
*virtio_ccw_get_vdev(SubchDev
*sch
)
121 VirtIODevice
*vdev
= NULL
;
122 VirtioCcwDevice
*dev
= sch
->driver_data
;
125 vdev
= virtio_bus_get_device(&dev
->bus
);
130 static int virtio_ccw_set_guest2host_notifier(VirtioCcwDevice
*dev
, int n
,
131 bool assign
, bool set_handler
)
133 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
134 VirtQueue
*vq
= virtio_get_queue(vdev
, n
);
135 EventNotifier
*notifier
= virtio_queue_get_host_notifier(vq
);
137 SubchDev
*sch
= dev
->sch
;
138 uint32_t sch_id
= (css_build_subchannel_id(sch
) << 16) | sch
->schid
;
141 r
= event_notifier_init(notifier
, 1);
143 error_report("%s: unable to init event notifier: %d", __func__
, r
);
146 virtio_queue_set_host_notifier_fd_handler(vq
, true, set_handler
);
147 r
= s390_assign_subch_ioeventfd(notifier
, sch_id
, n
, assign
);
149 error_report("%s: unable to assign ioeventfd: %d", __func__
, r
);
150 virtio_queue_set_host_notifier_fd_handler(vq
, false, false);
151 event_notifier_cleanup(notifier
);
155 virtio_queue_set_host_notifier_fd_handler(vq
, false, false);
156 s390_assign_subch_ioeventfd(notifier
, sch_id
, n
, assign
);
157 event_notifier_cleanup(notifier
);
162 static void virtio_ccw_start_ioeventfd(VirtioCcwDevice
*dev
)
167 if (!(dev
->flags
& VIRTIO_CCW_FLAG_USE_IOEVENTFD
) ||
168 dev
->ioeventfd_disabled
||
169 dev
->ioeventfd_started
) {
172 vdev
= virtio_bus_get_device(&dev
->bus
);
173 for (n
= 0; n
< VIRTIO_PCI_QUEUE_MAX
; n
++) {
174 if (!virtio_queue_get_num(vdev
, n
)) {
177 r
= virtio_ccw_set_guest2host_notifier(dev
, n
, true, true);
182 dev
->ioeventfd_started
= true;
187 if (!virtio_queue_get_num(vdev
, n
)) {
190 r
= virtio_ccw_set_guest2host_notifier(dev
, n
, false, false);
193 dev
->ioeventfd_started
= false;
194 /* Disable ioeventfd for this device. */
195 dev
->flags
&= ~VIRTIO_CCW_FLAG_USE_IOEVENTFD
;
196 error_report("%s: failed. Fallback to userspace (slower).", __func__
);
199 static void virtio_ccw_stop_ioeventfd(VirtioCcwDevice
*dev
)
204 if (!dev
->ioeventfd_started
) {
207 vdev
= virtio_bus_get_device(&dev
->bus
);
208 for (n
= 0; n
< VIRTIO_PCI_QUEUE_MAX
; n
++) {
209 if (!virtio_queue_get_num(vdev
, n
)) {
212 r
= virtio_ccw_set_guest2host_notifier(dev
, n
, false, false);
215 dev
->ioeventfd_started
= false;
218 VirtualCssBus
*virtual_css_bus_init(void)
224 /* Create bridge device */
225 dev
= qdev_create(NULL
, "virtual-css-bridge");
226 qdev_init_nofail(dev
);
228 /* Create bus on bridge device */
229 bus
= qbus_create(TYPE_VIRTUAL_CSS_BUS
, dev
, "virtual-css");
230 cbus
= VIRTUAL_CSS_BUS(bus
);
232 /* Enable hotplugging */
233 qbus_set_hotplug_handler(bus
, dev
, &error_abort
);
238 /* Communication blocks used by several channel commands. */
239 typedef struct VqInfoBlock
{
244 } QEMU_PACKED VqInfoBlock
;
246 typedef struct VqConfigBlock
{
249 } QEMU_PACKED VqConfigBlock
;
251 typedef struct VirtioFeatDesc
{
254 } QEMU_PACKED VirtioFeatDesc
;
256 typedef struct VirtioThinintInfo
{
257 hwaddr summary_indicator
;
258 hwaddr device_indicator
;
261 } QEMU_PACKED VirtioThinintInfo
;
263 /* Specify where the virtqueues for the subchannel are in guest memory. */
264 static int virtio_ccw_set_vqs(SubchDev
*sch
, uint64_t addr
, uint32_t align
,
265 uint16_t index
, uint16_t num
)
267 VirtIODevice
*vdev
= virtio_ccw_get_vdev(sch
);
269 if (index
>= VIRTIO_PCI_QUEUE_MAX
) {
273 /* Current code in virtio.c relies on 4K alignment. */
274 if (addr
&& (align
!= 4096)) {
282 virtio_queue_set_addr(vdev
, index
, addr
);
284 virtio_queue_set_vector(vdev
, index
, 0);
286 /* Fail if we don't have a big enough queue. */
287 /* TODO: Add interface to handle vring.num changing */
288 if (virtio_queue_get_num(vdev
, index
) > num
) {
291 virtio_queue_set_vector(vdev
, index
, index
);
293 /* tell notify handler in case of config change */
294 vdev
->config_vector
= VIRTIO_PCI_QUEUE_MAX
;
298 static int virtio_ccw_cb(SubchDev
*sch
, CCW1 ccw
)
303 VirtioFeatDesc features
;
306 VqConfigBlock vq_config
;
307 VirtioCcwDevice
*dev
= sch
->driver_data
;
308 VirtIODevice
*vdev
= virtio_ccw_get_vdev(sch
);
312 VirtioThinintInfo
*thinint
;
318 trace_virtio_ccw_interpret_ccw(sch
->cssid
, sch
->ssid
, sch
->schid
,
320 check_len
= !((ccw
.flags
& CCW_FLAG_SLI
) && !(ccw
.flags
& CCW_FLAG_DC
));
322 /* Look at the command. */
323 switch (ccw
.cmd_code
) {
326 if (ccw
.count
!= sizeof(info
)) {
330 } else if (ccw
.count
< sizeof(info
)) {
331 /* Can't execute command. */
338 info
.queue
= address_space_ldq(&address_space_memory
, ccw
.cda
,
339 MEMTXATTRS_UNSPECIFIED
, NULL
);
340 info
.align
= address_space_ldl(&address_space_memory
,
341 ccw
.cda
+ sizeof(info
.queue
),
342 MEMTXATTRS_UNSPECIFIED
,
344 info
.index
= address_space_lduw(&address_space_memory
,
345 ccw
.cda
+ sizeof(info
.queue
)
346 + sizeof(info
.align
),
347 MEMTXATTRS_UNSPECIFIED
,
349 info
.num
= address_space_lduw(&address_space_memory
,
350 ccw
.cda
+ sizeof(info
.queue
)
352 + sizeof(info
.index
),
353 MEMTXATTRS_UNSPECIFIED
,
355 ret
= virtio_ccw_set_vqs(sch
, info
.queue
, info
.align
, info
.index
,
357 sch
->curr_status
.scsw
.count
= 0;
360 case CCW_CMD_VDEV_RESET
:
361 virtio_ccw_stop_ioeventfd(dev
);
365 case CCW_CMD_READ_FEAT
:
367 if (ccw
.count
!= sizeof(features
)) {
371 } else if (ccw
.count
< sizeof(features
)) {
372 /* Can't execute command. */
379 features
.index
= address_space_ldub(&address_space_memory
,
381 + sizeof(features
.features
),
382 MEMTXATTRS_UNSPECIFIED
,
384 if (features
.index
< ARRAY_SIZE(dev
->host_features
)) {
385 features
.features
= dev
->host_features
[features
.index
];
387 /* Return zeroes if the guest supports more feature bits. */
388 features
.features
= 0;
390 address_space_stl_le(&address_space_memory
, ccw
.cda
,
391 features
.features
, MEMTXATTRS_UNSPECIFIED
,
393 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(features
);
397 case CCW_CMD_WRITE_FEAT
:
399 if (ccw
.count
!= sizeof(features
)) {
403 } else if (ccw
.count
< sizeof(features
)) {
404 /* Can't execute command. */
411 features
.index
= address_space_ldub(&address_space_memory
,
413 + sizeof(features
.features
),
414 MEMTXATTRS_UNSPECIFIED
,
416 features
.features
= address_space_ldl_le(&address_space_memory
,
418 MEMTXATTRS_UNSPECIFIED
,
420 if (features
.index
< ARRAY_SIZE(dev
->host_features
)) {
421 virtio_set_features(vdev
, features
.features
);
424 * If the guest supports more feature bits, assert that it
425 * passes us zeroes for those we don't support.
427 if (features
.features
) {
428 fprintf(stderr
, "Guest bug: features[%i]=%x (expected 0)\n",
429 features
.index
, features
.features
);
430 /* XXX: do a unit check here? */
433 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(features
);
437 case CCW_CMD_READ_CONF
:
439 if (ccw
.count
> vdev
->config_len
) {
444 len
= MIN(ccw
.count
, vdev
->config_len
);
448 virtio_bus_get_vdev_config(&dev
->bus
, vdev
->config
);
449 /* XXX config space endianness */
450 cpu_physical_memory_write(ccw
.cda
, vdev
->config
, len
);
451 sch
->curr_status
.scsw
.count
= ccw
.count
- len
;
455 case CCW_CMD_WRITE_CONF
:
457 if (ccw
.count
> vdev
->config_len
) {
462 len
= MIN(ccw
.count
, vdev
->config_len
);
467 config
= cpu_physical_memory_map(ccw
.cda
, &hw_len
, 0);
472 /* XXX config space endianness */
473 memcpy(vdev
->config
, config
, len
);
474 cpu_physical_memory_unmap(config
, hw_len
, 0, hw_len
);
475 virtio_bus_set_vdev_config(&dev
->bus
, vdev
->config
);
476 sch
->curr_status
.scsw
.count
= ccw
.count
- len
;
481 case CCW_CMD_WRITE_STATUS
:
483 if (ccw
.count
!= sizeof(status
)) {
487 } else if (ccw
.count
< sizeof(status
)) {
488 /* Can't execute command. */
495 status
= address_space_ldub(&address_space_memory
, ccw
.cda
,
496 MEMTXATTRS_UNSPECIFIED
, NULL
);
497 if (!(status
& VIRTIO_CONFIG_S_DRIVER_OK
)) {
498 virtio_ccw_stop_ioeventfd(dev
);
500 virtio_set_status(vdev
, status
);
501 if (vdev
->status
== 0) {
504 if (status
& VIRTIO_CONFIG_S_DRIVER_OK
) {
505 virtio_ccw_start_ioeventfd(dev
);
507 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(status
);
511 case CCW_CMD_SET_IND
:
513 if (ccw
.count
!= sizeof(indicators
)) {
517 } else if (ccw
.count
< sizeof(indicators
)) {
518 /* Can't execute command. */
522 if (sch
->thinint_active
) {
523 /* Trigger a command reject. */
530 indicators
= address_space_ldq_be(&address_space_memory
, ccw
.cda
,
531 MEMTXATTRS_UNSPECIFIED
, NULL
);
532 dev
->indicators
= get_indicator(indicators
, sizeof(uint64_t));
533 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(indicators
);
537 case CCW_CMD_SET_CONF_IND
:
539 if (ccw
.count
!= sizeof(indicators
)) {
543 } else if (ccw
.count
< sizeof(indicators
)) {
544 /* Can't execute command. */
551 indicators
= address_space_ldq_be(&address_space_memory
, ccw
.cda
,
552 MEMTXATTRS_UNSPECIFIED
, NULL
);
553 dev
->indicators2
= get_indicator(indicators
, sizeof(uint64_t));
554 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(indicators
);
558 case CCW_CMD_READ_VQ_CONF
:
560 if (ccw
.count
!= sizeof(vq_config
)) {
564 } else if (ccw
.count
< sizeof(vq_config
)) {
565 /* Can't execute command. */
572 vq_config
.index
= address_space_lduw_be(&address_space_memory
,
574 MEMTXATTRS_UNSPECIFIED
,
576 if (vq_config
.index
>= VIRTIO_PCI_QUEUE_MAX
) {
580 vq_config
.num_max
= virtio_queue_get_num(vdev
,
582 address_space_stw_be(&address_space_memory
,
583 ccw
.cda
+ sizeof(vq_config
.index
),
585 MEMTXATTRS_UNSPECIFIED
,
587 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(vq_config
);
591 case CCW_CMD_SET_IND_ADAPTER
:
593 if (ccw
.count
!= sizeof(*thinint
)) {
597 } else if (ccw
.count
< sizeof(*thinint
)) {
598 /* Can't execute command. */
602 len
= sizeof(*thinint
);
606 } else if (dev
->indicators
&& !sch
->thinint_active
) {
607 /* Trigger a command reject. */
610 thinint
= cpu_physical_memory_map(ccw
.cda
, &hw_len
, 0);
614 uint64_t ind_bit
= ldq_be_p(&thinint
->ind_bit
);
617 dev
->summary_indicator
=
618 get_indicator(ldq_be_p(&thinint
->summary_indicator
),
621 get_indicator(ldq_be_p(&thinint
->device_indicator
),
623 dev
->thinint_isc
= thinint
->isc
;
624 dev
->routes
.adapter
.ind_offset
= ind_bit
;
625 dev
->routes
.adapter
.summary_offset
= 7;
626 cpu_physical_memory_unmap(thinint
, hw_len
, 0, hw_len
);
627 ret
= css_register_io_adapter(CSS_IO_ADAPTER_VIRTIO
,
628 dev
->thinint_isc
, true, false,
629 &dev
->routes
.adapter
.adapter_id
);
631 sch
->thinint_active
= ((dev
->indicators
!= NULL
) &&
632 (dev
->summary_indicator
!= NULL
));
633 sch
->curr_status
.scsw
.count
= ccw
.count
- len
;
645 static void virtio_ccw_device_realize(VirtioCcwDevice
*dev
, Error
**errp
)
647 unsigned int cssid
= 0;
648 unsigned int ssid
= 0;
651 bool have_devno
= false;
655 DeviceState
*parent
= DEVICE(dev
);
657 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_GET_CLASS(dev
);
660 sch
= g_malloc0(sizeof(SubchDev
));
662 sch
->driver_data
= dev
;
665 dev
->indicators
= NULL
;
667 /* Initialize subchannel structure. */
668 sch
->channel_prog
= 0x0;
669 sch
->last_cmd_valid
= false;
670 sch
->thinint_active
= false;
672 * Use a device number if provided. Otherwise, fall back to subchannel
676 num
= sscanf(dev
->bus_id
, "%x.%x.%04x", &cssid
, &ssid
, &devno
);
678 if ((cssid
> MAX_CSSID
) || (ssid
> MAX_SSID
)) {
679 error_setg(errp
, "Invalid cssid or ssid: cssid %x, ssid %x",
683 /* Enforce use of virtual cssid. */
684 if (cssid
!= VIRTUAL_CSSID
) {
685 error_setg(errp
, "cssid %x not valid for virtio devices",
689 if (css_devno_used(cssid
, ssid
, devno
)) {
690 error_setg(errp
, "Device %x.%x.%04x already exists",
699 error_setg(errp
, "Malformed devno parameter '%s'", dev
->bus_id
);
704 /* Find the next free id. */
706 for (schid
= 0; schid
<= MAX_SCHID
; schid
++) {
707 if (!css_find_subch(1, cssid
, ssid
, schid
)) {
709 css_subch_assign(cssid
, ssid
, schid
, devno
, sch
);
715 error_setg(errp
, "No free subchannel found for %x.%x.%04x",
719 trace_virtio_ccw_new_device(cssid
, ssid
, schid
, devno
,
722 cssid
= VIRTUAL_CSSID
;
723 for (ssid
= 0; ssid
<= MAX_SSID
; ssid
++) {
724 for (schid
= 0; schid
<= MAX_SCHID
; schid
++) {
725 if (!css_find_subch(1, cssid
, ssid
, schid
)) {
731 * If the devno is already taken, look further in this
734 while (css_devno_used(cssid
, ssid
, devno
)) {
735 if (devno
== MAX_SCHID
) {
737 } else if (devno
== schid
- 1) {
738 error_setg(errp
, "No free devno found");
745 css_subch_assign(cssid
, ssid
, schid
, devno
, sch
);
755 error_setg(errp
, "Virtual channel subsystem is full!");
758 trace_virtio_ccw_new_device(cssid
, ssid
, schid
, devno
,
762 /* Build initial schib. */
763 css_sch_build_virtual_schib(sch
, 0, VIRTIO_CCW_CHPID_TYPE
);
765 sch
->ccw_cb
= virtio_ccw_cb
;
767 /* Build senseid data. */
768 memset(&sch
->id
, 0, sizeof(SenseId
));
769 sch
->id
.reserved
= 0xff;
770 sch
->id
.cu_type
= VIRTIO_CCW_CU_TYPE
;
773 k
->realize(dev
, &err
);
776 error_propagate(errp
, err
);
777 css_subch_assign(cssid
, ssid
, schid
, devno
, NULL
);
781 /* device_id is only set after vdev has been realized */
782 vdev
= virtio_ccw_get_vdev(sch
);
783 sch
->id
.cu_model
= vdev
->device_id
;
785 /* Only the first 32 feature bits are used. */
786 dev
->host_features
[0] = virtio_bus_get_vdev_features(&dev
->bus
,
787 dev
->host_features
[0]);
789 virtio_add_feature(&dev
->host_features
[0], VIRTIO_F_NOTIFY_ON_EMPTY
);
790 virtio_add_feature(&dev
->host_features
[0], VIRTIO_F_BAD_FEATURE
);
792 css_generate_sch_crws(sch
->cssid
, sch
->ssid
, sch
->schid
,
793 parent
->hotplugged
, 1);
801 static int virtio_ccw_exit(VirtioCcwDevice
*dev
)
803 SubchDev
*sch
= dev
->sch
;
806 css_subch_assign(sch
->cssid
, sch
->ssid
, sch
->schid
, sch
->devno
, NULL
);
809 if (dev
->indicators
) {
810 release_indicator(&dev
->routes
.adapter
, dev
->indicators
);
811 dev
->indicators
= NULL
;
816 static void virtio_ccw_net_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
818 DeviceState
*qdev
= DEVICE(ccw_dev
);
819 VirtIONetCcw
*dev
= VIRTIO_NET_CCW(ccw_dev
);
820 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
823 virtio_net_set_config_size(&dev
->vdev
, ccw_dev
->host_features
[0]);
824 virtio_net_set_netclient_name(&dev
->vdev
, qdev
->id
,
825 object_get_typename(OBJECT(qdev
)));
826 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
827 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
829 error_propagate(errp
, err
);
833 static void virtio_ccw_net_instance_init(Object
*obj
)
835 VirtIONetCcw
*dev
= VIRTIO_NET_CCW(obj
);
837 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
839 object_property_add_alias(obj
, "bootindex", OBJECT(&dev
->vdev
),
840 "bootindex", &error_abort
);
843 static void virtio_ccw_blk_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
845 VirtIOBlkCcw
*dev
= VIRTIO_BLK_CCW(ccw_dev
);
846 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
849 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
850 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
852 error_propagate(errp
, err
);
856 static void virtio_ccw_blk_instance_init(Object
*obj
)
858 VirtIOBlkCcw
*dev
= VIRTIO_BLK_CCW(obj
);
860 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
862 object_property_add_alias(obj
, "iothread", OBJECT(&dev
->vdev
),"iothread",
864 object_property_add_alias(obj
, "bootindex", OBJECT(&dev
->vdev
),
865 "bootindex", &error_abort
);
868 static void virtio_ccw_serial_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
870 VirtioSerialCcw
*dev
= VIRTIO_SERIAL_CCW(ccw_dev
);
871 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
872 DeviceState
*proxy
= DEVICE(ccw_dev
);
877 * For command line compatibility, this sets the virtio-serial-device bus
881 bus_name
= g_strdup_printf("%s.0", proxy
->id
);
882 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev
), bus_name
);
886 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
887 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
889 error_propagate(errp
, err
);
894 static void virtio_ccw_serial_instance_init(Object
*obj
)
896 VirtioSerialCcw
*dev
= VIRTIO_SERIAL_CCW(obj
);
898 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
902 static void virtio_ccw_balloon_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
904 VirtIOBalloonCcw
*dev
= VIRTIO_BALLOON_CCW(ccw_dev
);
905 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
908 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
909 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
911 error_propagate(errp
, err
);
915 static void balloon_ccw_stats_get_all(Object
*obj
, struct Visitor
*v
,
916 void *opaque
, const char *name
,
919 VirtIOBalloonCcw
*dev
= opaque
;
920 object_property_get(OBJECT(&dev
->vdev
), v
, "guest-stats", errp
);
923 static void balloon_ccw_stats_get_poll_interval(Object
*obj
, struct Visitor
*v
,
924 void *opaque
, const char *name
,
927 VirtIOBalloonCcw
*dev
= opaque
;
928 object_property_get(OBJECT(&dev
->vdev
), v
, "guest-stats-polling-interval",
932 static void balloon_ccw_stats_set_poll_interval(Object
*obj
, struct Visitor
*v
,
933 void *opaque
, const char *name
,
936 VirtIOBalloonCcw
*dev
= opaque
;
937 object_property_set(OBJECT(&dev
->vdev
), v
, "guest-stats-polling-interval",
941 static void virtio_ccw_balloon_instance_init(Object
*obj
)
943 VirtIOBalloonCcw
*dev
= VIRTIO_BALLOON_CCW(obj
);
944 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
945 TYPE_VIRTIO_BALLOON
);
946 object_property_add(obj
, "guest-stats", "guest statistics",
947 balloon_ccw_stats_get_all
, NULL
, NULL
, dev
, NULL
);
949 object_property_add(obj
, "guest-stats-polling-interval", "int",
950 balloon_ccw_stats_get_poll_interval
,
951 balloon_ccw_stats_set_poll_interval
,
955 static void virtio_ccw_scsi_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
957 VirtIOSCSICcw
*dev
= VIRTIO_SCSI_CCW(ccw_dev
);
958 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
959 DeviceState
*qdev
= DEVICE(ccw_dev
);
964 * For command line compatibility, this sets the virtio-scsi-device bus
968 bus_name
= g_strdup_printf("%s.0", qdev
->id
);
969 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev
), bus_name
);
973 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
974 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
976 error_propagate(errp
, err
);
980 static void virtio_ccw_scsi_instance_init(Object
*obj
)
982 VirtIOSCSICcw
*dev
= VIRTIO_SCSI_CCW(obj
);
984 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
986 object_property_add_alias(obj
, "iothread", OBJECT(&dev
->vdev
), "iothread",
990 #ifdef CONFIG_VHOST_SCSI
991 static void vhost_ccw_scsi_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
993 VHostSCSICcw
*dev
= VHOST_SCSI_CCW(ccw_dev
);
994 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
997 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
998 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
1000 error_propagate(errp
, err
);
1004 static void vhost_ccw_scsi_instance_init(Object
*obj
)
1006 VHostSCSICcw
*dev
= VHOST_SCSI_CCW(obj
);
1008 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
1013 static void virtio_ccw_rng_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
1015 VirtIORNGCcw
*dev
= VIRTIO_RNG_CCW(ccw_dev
);
1016 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
1019 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
1020 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
1022 error_propagate(errp
, err
);
1026 object_property_set_link(OBJECT(dev
),
1027 OBJECT(dev
->vdev
.conf
.rng
), "rng",
1031 /* DeviceState to VirtioCcwDevice. Note: used on datapath,
1032 * be careful and test performance if you change this.
1034 static inline VirtioCcwDevice
*to_virtio_ccw_dev_fast(DeviceState
*d
)
1036 return container_of(d
, VirtioCcwDevice
, parent_obj
);
1039 static uint8_t virtio_set_ind_atomic(SubchDev
*sch
, uint64_t ind_loc
,
1042 uint8_t ind_old
, ind_new
;
1046 ind_addr
= cpu_physical_memory_map(ind_loc
, &len
, 1);
1048 error_report("%s(%x.%x.%04x): unable to access indicator",
1049 __func__
, sch
->cssid
, sch
->ssid
, sch
->schid
);
1053 ind_old
= *ind_addr
;
1054 ind_new
= ind_old
| to_be_set
;
1055 } while (atomic_cmpxchg(ind_addr
, ind_old
, ind_new
) != ind_old
);
1056 cpu_physical_memory_unmap(ind_addr
, len
, 1, len
);
1061 static void virtio_ccw_notify(DeviceState
*d
, uint16_t vector
)
1063 VirtioCcwDevice
*dev
= to_virtio_ccw_dev_fast(d
);
1064 SubchDev
*sch
= dev
->sch
;
1065 uint64_t indicators
;
1067 if (vector
>= 128) {
1071 if (vector
< VIRTIO_PCI_QUEUE_MAX
) {
1072 if (!dev
->indicators
) {
1075 if (sch
->thinint_active
) {
1077 * In the adapter interrupt case, indicators points to a
1078 * memory area that may be (way) larger than 64 bit and
1079 * ind_bit indicates the start of the indicators in a big
1082 uint64_t ind_bit
= dev
->routes
.adapter
.ind_offset
;
1084 virtio_set_ind_atomic(sch
, dev
->indicators
->addr
+
1085 (ind_bit
+ vector
) / 8,
1086 0x80 >> ((ind_bit
+ vector
) % 8));
1087 if (!virtio_set_ind_atomic(sch
, dev
->summary_indicator
->addr
,
1089 css_adapter_interrupt(dev
->thinint_isc
);
1092 indicators
= address_space_ldq(&address_space_memory
,
1093 dev
->indicators
->addr
,
1094 MEMTXATTRS_UNSPECIFIED
,
1096 indicators
|= 1ULL << vector
;
1097 address_space_stq(&address_space_memory
, dev
->indicators
->addr
,
1098 indicators
, MEMTXATTRS_UNSPECIFIED
, NULL
);
1099 css_conditional_io_interrupt(sch
);
1102 if (!dev
->indicators2
) {
1106 indicators
= address_space_ldq(&address_space_memory
,
1107 dev
->indicators2
->addr
,
1108 MEMTXATTRS_UNSPECIFIED
,
1110 indicators
|= 1ULL << vector
;
1111 address_space_stq(&address_space_memory
, dev
->indicators2
->addr
,
1112 indicators
, MEMTXATTRS_UNSPECIFIED
, NULL
);
1113 css_conditional_io_interrupt(sch
);
1117 static unsigned virtio_ccw_get_features(DeviceState
*d
)
1119 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1121 /* Only the first 32 feature bits are used. */
1122 return dev
->host_features
[0];
1125 static void virtio_ccw_reset(DeviceState
*d
)
1127 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1128 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1130 virtio_ccw_stop_ioeventfd(dev
);
1132 css_reset_sch(dev
->sch
);
1133 if (dev
->indicators
) {
1134 release_indicator(&dev
->routes
.adapter
, dev
->indicators
);
1135 dev
->indicators
= NULL
;
1137 if (dev
->indicators2
) {
1138 release_indicator(&dev
->routes
.adapter
, dev
->indicators2
);
1139 dev
->indicators2
= NULL
;
1141 if (dev
->summary_indicator
) {
1142 release_indicator(&dev
->routes
.adapter
, dev
->summary_indicator
);
1143 dev
->summary_indicator
= NULL
;
1147 static void virtio_ccw_vmstate_change(DeviceState
*d
, bool running
)
1149 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1152 virtio_ccw_start_ioeventfd(dev
);
1154 virtio_ccw_stop_ioeventfd(dev
);
1158 static bool virtio_ccw_query_guest_notifiers(DeviceState
*d
)
1160 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1162 return !!(dev
->sch
->curr_status
.pmcw
.flags
& PMCW_FLAGS_MASK_ENA
);
1165 static int virtio_ccw_set_host_notifier(DeviceState
*d
, int n
, bool assign
)
1167 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1169 /* Stop using the generic ioeventfd, we are doing eventfd handling
1170 * ourselves below */
1171 dev
->ioeventfd_disabled
= assign
;
1173 virtio_ccw_stop_ioeventfd(dev
);
1175 return virtio_ccw_set_guest2host_notifier(dev
, n
, assign
, false);
1178 static int virtio_ccw_get_mappings(VirtioCcwDevice
*dev
)
1182 if (!dev
->sch
->thinint_active
) {
1186 r
= map_indicator(&dev
->routes
.adapter
, dev
->summary_indicator
);
1190 r
= map_indicator(&dev
->routes
.adapter
, dev
->indicators
);
1194 dev
->routes
.adapter
.summary_addr
= dev
->summary_indicator
->map
;
1195 dev
->routes
.adapter
.ind_addr
= dev
->indicators
->map
;
1200 static int virtio_ccw_setup_irqroutes(VirtioCcwDevice
*dev
, int nvqs
)
1203 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1205 S390FLICState
*fs
= s390_get_flic();
1206 S390FLICStateClass
*fsc
= S390_FLIC_COMMON_GET_CLASS(fs
);
1208 ret
= virtio_ccw_get_mappings(dev
);
1212 for (i
= 0; i
< nvqs
; i
++) {
1213 if (!virtio_queue_get_num(vdev
, i
)) {
1217 dev
->routes
.num_routes
= i
;
1218 return fsc
->add_adapter_routes(fs
, &dev
->routes
);
1221 static void virtio_ccw_release_irqroutes(VirtioCcwDevice
*dev
, int nvqs
)
1223 S390FLICState
*fs
= s390_get_flic();
1224 S390FLICStateClass
*fsc
= S390_FLIC_COMMON_GET_CLASS(fs
);
1226 fsc
->release_adapter_routes(fs
, &dev
->routes
);
1229 static int virtio_ccw_add_irqfd(VirtioCcwDevice
*dev
, int n
)
1231 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1232 VirtQueue
*vq
= virtio_get_queue(vdev
, n
);
1233 EventNotifier
*notifier
= virtio_queue_get_guest_notifier(vq
);
1235 return kvm_irqchip_add_irqfd_notifier(kvm_state
, notifier
, NULL
,
1236 dev
->routes
.gsi
[n
]);
1239 static void virtio_ccw_remove_irqfd(VirtioCcwDevice
*dev
, int n
)
1241 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1242 VirtQueue
*vq
= virtio_get_queue(vdev
, n
);
1243 EventNotifier
*notifier
= virtio_queue_get_guest_notifier(vq
);
1246 ret
= kvm_irqchip_remove_irqfd_notifier(kvm_state
, notifier
,
1247 dev
->routes
.gsi
[n
]);
1251 static int virtio_ccw_set_guest_notifier(VirtioCcwDevice
*dev
, int n
,
1252 bool assign
, bool with_irqfd
)
1254 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1255 VirtQueue
*vq
= virtio_get_queue(vdev
, n
);
1256 EventNotifier
*notifier
= virtio_queue_get_guest_notifier(vq
);
1257 VirtioDeviceClass
*k
= VIRTIO_DEVICE_GET_CLASS(vdev
);
1260 int r
= event_notifier_init(notifier
, 0);
1265 virtio_queue_set_guest_notifier_fd_handler(vq
, true, with_irqfd
);
1267 r
= virtio_ccw_add_irqfd(dev
, n
);
1269 virtio_queue_set_guest_notifier_fd_handler(vq
, false,
1275 * We do not support individual masking for channel devices, so we
1276 * need to manually trigger any guest masking callbacks here.
1278 if (k
->guest_notifier_mask
) {
1279 k
->guest_notifier_mask(vdev
, n
, false);
1281 /* get lost events and re-inject */
1282 if (k
->guest_notifier_pending
&&
1283 k
->guest_notifier_pending(vdev
, n
)) {
1284 event_notifier_set(notifier
);
1287 if (k
->guest_notifier_mask
) {
1288 k
->guest_notifier_mask(vdev
, n
, true);
1291 virtio_ccw_remove_irqfd(dev
, n
);
1293 virtio_queue_set_guest_notifier_fd_handler(vq
, false, with_irqfd
);
1294 event_notifier_cleanup(notifier
);
1299 static int virtio_ccw_set_guest_notifiers(DeviceState
*d
, int nvqs
,
1302 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1303 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1304 bool with_irqfd
= dev
->sch
->thinint_active
&& kvm_irqfds_enabled();
1307 if (with_irqfd
&& assigned
) {
1308 /* irq routes need to be set up before assigning irqfds */
1309 r
= virtio_ccw_setup_irqroutes(dev
, nvqs
);
1311 goto irqroute_error
;
1314 for (n
= 0; n
< nvqs
; n
++) {
1315 if (!virtio_queue_get_num(vdev
, n
)) {
1318 r
= virtio_ccw_set_guest_notifier(dev
, n
, assigned
, with_irqfd
);
1323 if (with_irqfd
&& !assigned
) {
1324 /* release irq routes after irqfds have been released */
1325 virtio_ccw_release_irqroutes(dev
, nvqs
);
1331 virtio_ccw_set_guest_notifier(dev
, n
, !assigned
, false);
1334 if (with_irqfd
&& assigned
) {
1335 virtio_ccw_release_irqroutes(dev
, nvqs
);
1340 static void virtio_ccw_save_queue(DeviceState
*d
, int n
, QEMUFile
*f
)
1342 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1343 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1345 qemu_put_be16(f
, virtio_queue_vector(vdev
, n
));
1348 static int virtio_ccw_load_queue(DeviceState
*d
, int n
, QEMUFile
*f
)
1350 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1351 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1354 qemu_get_be16s(f
, &vector
);
1355 virtio_queue_set_vector(vdev
, n
, vector
);
1360 static void virtio_ccw_save_config(DeviceState
*d
, QEMUFile
*f
)
1362 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1363 SubchDev
*s
= dev
->sch
;
1365 subch_device_save(s
, f
);
1366 if (dev
->indicators
!= NULL
) {
1367 qemu_put_be32(f
, dev
->indicators
->len
);
1368 qemu_put_be64(f
, dev
->indicators
->addr
);
1370 qemu_put_be32(f
, 0);
1371 qemu_put_be64(f
, 0UL);
1373 if (dev
->indicators2
!= NULL
) {
1374 qemu_put_be32(f
, dev
->indicators2
->len
);
1375 qemu_put_be64(f
, dev
->indicators2
->addr
);
1377 qemu_put_be32(f
, 0);
1378 qemu_put_be64(f
, 0UL);
1380 if (dev
->summary_indicator
!= NULL
) {
1381 qemu_put_be32(f
, dev
->summary_indicator
->len
);
1382 qemu_put_be64(f
, dev
->summary_indicator
->addr
);
1384 qemu_put_be32(f
, 0);
1385 qemu_put_be64(f
, 0UL);
1387 qemu_put_be64(f
, dev
->routes
.adapter
.ind_offset
);
1388 qemu_put_byte(f
, dev
->thinint_isc
);
1391 static int virtio_ccw_load_config(DeviceState
*d
, QEMUFile
*f
)
1393 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1394 SubchDev
*s
= dev
->sch
;
1397 s
->driver_data
= dev
;
1398 subch_device_load(s
, f
);
1399 len
= qemu_get_be32(f
);
1401 dev
->indicators
= get_indicator(qemu_get_be64(f
), len
);
1404 dev
->indicators
= NULL
;
1406 len
= qemu_get_be32(f
);
1408 dev
->indicators2
= get_indicator(qemu_get_be64(f
), len
);
1411 dev
->indicators2
= NULL
;
1413 len
= qemu_get_be32(f
);
1415 dev
->summary_indicator
= get_indicator(qemu_get_be64(f
), len
);
1418 dev
->summary_indicator
= NULL
;
1420 dev
->routes
.adapter
.ind_offset
= qemu_get_be64(f
);
1421 dev
->thinint_isc
= qemu_get_byte(f
);
1422 if (s
->thinint_active
) {
1423 return css_register_io_adapter(CSS_IO_ADAPTER_VIRTIO
,
1424 dev
->thinint_isc
, true, false,
1425 &dev
->routes
.adapter
.adapter_id
);
1431 /**************** Virtio-ccw Bus Device Descriptions *******************/
1433 static Property virtio_ccw_net_properties
[] = {
1434 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1435 DEFINE_VIRTIO_NET_FEATURES(VirtioCcwDevice
, host_features
[0]),
1436 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1437 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1438 DEFINE_PROP_END_OF_LIST(),
1441 static void virtio_ccw_net_class_init(ObjectClass
*klass
, void *data
)
1443 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1444 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1446 k
->realize
= virtio_ccw_net_realize
;
1447 k
->exit
= virtio_ccw_exit
;
1448 dc
->reset
= virtio_ccw_reset
;
1449 dc
->props
= virtio_ccw_net_properties
;
1450 set_bit(DEVICE_CATEGORY_NETWORK
, dc
->categories
);
1453 static const TypeInfo virtio_ccw_net
= {
1454 .name
= TYPE_VIRTIO_NET_CCW
,
1455 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1456 .instance_size
= sizeof(VirtIONetCcw
),
1457 .instance_init
= virtio_ccw_net_instance_init
,
1458 .class_init
= virtio_ccw_net_class_init
,
1461 static Property virtio_ccw_blk_properties
[] = {
1462 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1463 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1464 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1465 DEFINE_PROP_END_OF_LIST(),
1468 static void virtio_ccw_blk_class_init(ObjectClass
*klass
, void *data
)
1470 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1471 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1473 k
->realize
= virtio_ccw_blk_realize
;
1474 k
->exit
= virtio_ccw_exit
;
1475 dc
->reset
= virtio_ccw_reset
;
1476 dc
->props
= virtio_ccw_blk_properties
;
1477 set_bit(DEVICE_CATEGORY_STORAGE
, dc
->categories
);
1480 static const TypeInfo virtio_ccw_blk
= {
1481 .name
= TYPE_VIRTIO_BLK_CCW
,
1482 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1483 .instance_size
= sizeof(VirtIOBlkCcw
),
1484 .instance_init
= virtio_ccw_blk_instance_init
,
1485 .class_init
= virtio_ccw_blk_class_init
,
1488 static Property virtio_ccw_serial_properties
[] = {
1489 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1490 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1491 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1492 DEFINE_PROP_END_OF_LIST(),
1495 static void virtio_ccw_serial_class_init(ObjectClass
*klass
, void *data
)
1497 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1498 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1500 k
->realize
= virtio_ccw_serial_realize
;
1501 k
->exit
= virtio_ccw_exit
;
1502 dc
->reset
= virtio_ccw_reset
;
1503 dc
->props
= virtio_ccw_serial_properties
;
1504 set_bit(DEVICE_CATEGORY_INPUT
, dc
->categories
);
1507 static const TypeInfo virtio_ccw_serial
= {
1508 .name
= TYPE_VIRTIO_SERIAL_CCW
,
1509 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1510 .instance_size
= sizeof(VirtioSerialCcw
),
1511 .instance_init
= virtio_ccw_serial_instance_init
,
1512 .class_init
= virtio_ccw_serial_class_init
,
1515 static Property virtio_ccw_balloon_properties
[] = {
1516 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1517 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1518 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1519 DEFINE_PROP_END_OF_LIST(),
1522 static void virtio_ccw_balloon_class_init(ObjectClass
*klass
, void *data
)
1524 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1525 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1527 k
->realize
= virtio_ccw_balloon_realize
;
1528 k
->exit
= virtio_ccw_exit
;
1529 dc
->reset
= virtio_ccw_reset
;
1530 dc
->props
= virtio_ccw_balloon_properties
;
1531 set_bit(DEVICE_CATEGORY_MISC
, dc
->categories
);
1534 static const TypeInfo virtio_ccw_balloon
= {
1535 .name
= TYPE_VIRTIO_BALLOON_CCW
,
1536 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1537 .instance_size
= sizeof(VirtIOBalloonCcw
),
1538 .instance_init
= virtio_ccw_balloon_instance_init
,
1539 .class_init
= virtio_ccw_balloon_class_init
,
1542 static Property virtio_ccw_scsi_properties
[] = {
1543 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1544 DEFINE_VIRTIO_SCSI_FEATURES(VirtioCcwDevice
, host_features
[0]),
1545 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1546 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1547 DEFINE_PROP_END_OF_LIST(),
1550 static void virtio_ccw_scsi_class_init(ObjectClass
*klass
, void *data
)
1552 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1553 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1555 k
->realize
= virtio_ccw_scsi_realize
;
1556 k
->exit
= virtio_ccw_exit
;
1557 dc
->reset
= virtio_ccw_reset
;
1558 dc
->props
= virtio_ccw_scsi_properties
;
1559 set_bit(DEVICE_CATEGORY_STORAGE
, dc
->categories
);
1562 static const TypeInfo virtio_ccw_scsi
= {
1563 .name
= TYPE_VIRTIO_SCSI_CCW
,
1564 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1565 .instance_size
= sizeof(VirtIOSCSICcw
),
1566 .instance_init
= virtio_ccw_scsi_instance_init
,
1567 .class_init
= virtio_ccw_scsi_class_init
,
1570 #ifdef CONFIG_VHOST_SCSI
1571 static Property vhost_ccw_scsi_properties
[] = {
1572 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1573 DEFINE_PROP_END_OF_LIST(),
1576 static void vhost_ccw_scsi_class_init(ObjectClass
*klass
, void *data
)
1578 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1579 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1581 k
->realize
= vhost_ccw_scsi_realize
;
1582 k
->exit
= virtio_ccw_exit
;
1583 dc
->reset
= virtio_ccw_reset
;
1584 dc
->props
= vhost_ccw_scsi_properties
;
1585 set_bit(DEVICE_CATEGORY_STORAGE
, dc
->categories
);
1588 static const TypeInfo vhost_ccw_scsi
= {
1589 .name
= TYPE_VHOST_SCSI_CCW
,
1590 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1591 .instance_size
= sizeof(VHostSCSICcw
),
1592 .instance_init
= vhost_ccw_scsi_instance_init
,
1593 .class_init
= vhost_ccw_scsi_class_init
,
1597 static void virtio_ccw_rng_instance_init(Object
*obj
)
1599 VirtIORNGCcw
*dev
= VIRTIO_RNG_CCW(obj
);
1601 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
1603 object_property_add_alias(obj
, "rng", OBJECT(&dev
->vdev
),
1604 "rng", &error_abort
);
1607 static Property virtio_ccw_rng_properties
[] = {
1608 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1609 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1610 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1611 DEFINE_PROP_END_OF_LIST(),
1614 static void virtio_ccw_rng_class_init(ObjectClass
*klass
, void *data
)
1616 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1617 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1619 k
->realize
= virtio_ccw_rng_realize
;
1620 k
->exit
= virtio_ccw_exit
;
1621 dc
->reset
= virtio_ccw_reset
;
1622 dc
->props
= virtio_ccw_rng_properties
;
1623 set_bit(DEVICE_CATEGORY_MISC
, dc
->categories
);
1626 static const TypeInfo virtio_ccw_rng
= {
1627 .name
= TYPE_VIRTIO_RNG_CCW
,
1628 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1629 .instance_size
= sizeof(VirtIORNGCcw
),
1630 .instance_init
= virtio_ccw_rng_instance_init
,
1631 .class_init
= virtio_ccw_rng_class_init
,
1634 static void virtio_ccw_busdev_realize(DeviceState
*dev
, Error
**errp
)
1636 VirtioCcwDevice
*_dev
= (VirtioCcwDevice
*)dev
;
1638 virtio_ccw_bus_new(&_dev
->bus
, sizeof(_dev
->bus
), _dev
);
1639 virtio_ccw_device_realize(_dev
, errp
);
1642 static int virtio_ccw_busdev_exit(DeviceState
*dev
)
1644 VirtioCcwDevice
*_dev
= (VirtioCcwDevice
*)dev
;
1645 VirtIOCCWDeviceClass
*_info
= VIRTIO_CCW_DEVICE_GET_CLASS(dev
);
1647 return _info
->exit(_dev
);
1650 static void virtio_ccw_busdev_unplug(HotplugHandler
*hotplug_dev
,
1651 DeviceState
*dev
, Error
**errp
)
1653 VirtioCcwDevice
*_dev
= (VirtioCcwDevice
*)dev
;
1654 SubchDev
*sch
= _dev
->sch
;
1656 virtio_ccw_stop_ioeventfd(_dev
);
1659 * We should arrive here only for device_del, since we don't support
1660 * direct hot(un)plug of channels, but only through virtio.
1662 assert(sch
!= NULL
);
1663 /* Subchannel is now disabled and no longer valid. */
1664 sch
->curr_status
.pmcw
.flags
&= ~(PMCW_FLAGS_MASK_ENA
|
1665 PMCW_FLAGS_MASK_DNV
);
1667 css_generate_sch_crws(sch
->cssid
, sch
->ssid
, sch
->schid
, 1, 0);
1669 object_unparent(OBJECT(dev
));
1672 static Property virtio_ccw_properties
[] = {
1673 DEFINE_VIRTIO_COMMON_FEATURES(VirtioCcwDevice
, host_features
[0]),
1674 DEFINE_PROP_END_OF_LIST(),
1677 static void virtio_ccw_device_class_init(ObjectClass
*klass
, void *data
)
1679 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1681 dc
->props
= virtio_ccw_properties
;
1682 dc
->realize
= virtio_ccw_busdev_realize
;
1683 dc
->exit
= virtio_ccw_busdev_exit
;
1684 dc
->bus_type
= TYPE_VIRTUAL_CSS_BUS
;
1687 static const TypeInfo virtio_ccw_device_info
= {
1688 .name
= TYPE_VIRTIO_CCW_DEVICE
,
1689 .parent
= TYPE_DEVICE
,
1690 .instance_size
= sizeof(VirtioCcwDevice
),
1691 .class_init
= virtio_ccw_device_class_init
,
1692 .class_size
= sizeof(VirtIOCCWDeviceClass
),
1696 /***************** Virtual-css Bus Bridge Device ********************/
1697 /* Only required to have the virtio bus as child in the system bus */
1699 static int virtual_css_bridge_init(SysBusDevice
*dev
)
1705 static void virtual_css_bridge_class_init(ObjectClass
*klass
, void *data
)
1707 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
1708 HotplugHandlerClass
*hc
= HOTPLUG_HANDLER_CLASS(klass
);
1709 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1711 k
->init
= virtual_css_bridge_init
;
1712 hc
->unplug
= virtio_ccw_busdev_unplug
;
1713 set_bit(DEVICE_CATEGORY_BRIDGE
, dc
->categories
);
1716 static const TypeInfo virtual_css_bridge_info
= {
1717 .name
= "virtual-css-bridge",
1718 .parent
= TYPE_SYS_BUS_DEVICE
,
1719 .instance_size
= sizeof(SysBusDevice
),
1720 .class_init
= virtual_css_bridge_class_init
,
1721 .interfaces
= (InterfaceInfo
[]) {
1722 { TYPE_HOTPLUG_HANDLER
},
1727 /* virtio-ccw-bus */
1729 static void virtio_ccw_bus_new(VirtioBusState
*bus
, size_t bus_size
,
1730 VirtioCcwDevice
*dev
)
1732 DeviceState
*qdev
= DEVICE(dev
);
1733 char virtio_bus_name
[] = "virtio-bus";
1735 qbus_create_inplace(bus
, bus_size
, TYPE_VIRTIO_CCW_BUS
,
1736 qdev
, virtio_bus_name
);
1739 static void virtio_ccw_bus_class_init(ObjectClass
*klass
, void *data
)
1741 VirtioBusClass
*k
= VIRTIO_BUS_CLASS(klass
);
1742 BusClass
*bus_class
= BUS_CLASS(klass
);
1744 bus_class
->max_dev
= 1;
1745 k
->notify
= virtio_ccw_notify
;
1746 k
->get_features
= virtio_ccw_get_features
;
1747 k
->vmstate_change
= virtio_ccw_vmstate_change
;
1748 k
->query_guest_notifiers
= virtio_ccw_query_guest_notifiers
;
1749 k
->set_host_notifier
= virtio_ccw_set_host_notifier
;
1750 k
->set_guest_notifiers
= virtio_ccw_set_guest_notifiers
;
1751 k
->save_queue
= virtio_ccw_save_queue
;
1752 k
->load_queue
= virtio_ccw_load_queue
;
1753 k
->save_config
= virtio_ccw_save_config
;
1754 k
->load_config
= virtio_ccw_load_config
;
1757 static const TypeInfo virtio_ccw_bus_info
= {
1758 .name
= TYPE_VIRTIO_CCW_BUS
,
1759 .parent
= TYPE_VIRTIO_BUS
,
1760 .instance_size
= sizeof(VirtioCcwBusState
),
1761 .class_init
= virtio_ccw_bus_class_init
,
1764 static void virtio_ccw_register(void)
1766 type_register_static(&virtio_ccw_bus_info
);
1767 type_register_static(&virtual_css_bus_info
);
1768 type_register_static(&virtio_ccw_device_info
);
1769 type_register_static(&virtio_ccw_serial
);
1770 type_register_static(&virtio_ccw_blk
);
1771 type_register_static(&virtio_ccw_net
);
1772 type_register_static(&virtio_ccw_balloon
);
1773 type_register_static(&virtio_ccw_scsi
);
1774 #ifdef CONFIG_VHOST_SCSI
1775 type_register_static(&vhost_ccw_scsi
);
1777 type_register_static(&virtio_ccw_rng
);
1778 type_register_static(&virtual_css_bridge_info
);
1781 type_init(virtio_ccw_register
)