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_CCW_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_CCW_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_CCW_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
, VIRTIO_NO_VECTOR
);
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_CCW_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
== 0) {
385 features
.features
= vdev
->host_features
;
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
== 0) {
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 if (virtio_set_status(vdev
, status
) == 0) {
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
);
510 /* Trigger a command reject. */
515 case CCW_CMD_SET_IND
:
517 if (ccw
.count
!= sizeof(indicators
)) {
521 } else if (ccw
.count
< sizeof(indicators
)) {
522 /* Can't execute command. */
526 if (sch
->thinint_active
) {
527 /* Trigger a command reject. */
534 indicators
= address_space_ldq_be(&address_space_memory
, ccw
.cda
,
535 MEMTXATTRS_UNSPECIFIED
, NULL
);
536 dev
->indicators
= get_indicator(indicators
, sizeof(uint64_t));
537 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(indicators
);
541 case CCW_CMD_SET_CONF_IND
:
543 if (ccw
.count
!= sizeof(indicators
)) {
547 } else if (ccw
.count
< sizeof(indicators
)) {
548 /* Can't execute command. */
555 indicators
= address_space_ldq_be(&address_space_memory
, ccw
.cda
,
556 MEMTXATTRS_UNSPECIFIED
, NULL
);
557 dev
->indicators2
= get_indicator(indicators
, sizeof(uint64_t));
558 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(indicators
);
562 case CCW_CMD_READ_VQ_CONF
:
564 if (ccw
.count
!= sizeof(vq_config
)) {
568 } else if (ccw
.count
< sizeof(vq_config
)) {
569 /* Can't execute command. */
576 vq_config
.index
= address_space_lduw_be(&address_space_memory
,
578 MEMTXATTRS_UNSPECIFIED
,
580 if (vq_config
.index
>= VIRTIO_CCW_QUEUE_MAX
) {
584 vq_config
.num_max
= virtio_queue_get_num(vdev
,
586 address_space_stw_be(&address_space_memory
,
587 ccw
.cda
+ sizeof(vq_config
.index
),
589 MEMTXATTRS_UNSPECIFIED
,
591 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(vq_config
);
595 case CCW_CMD_SET_IND_ADAPTER
:
597 if (ccw
.count
!= sizeof(*thinint
)) {
601 } else if (ccw
.count
< sizeof(*thinint
)) {
602 /* Can't execute command. */
606 len
= sizeof(*thinint
);
610 } else if (dev
->indicators
&& !sch
->thinint_active
) {
611 /* Trigger a command reject. */
614 thinint
= cpu_physical_memory_map(ccw
.cda
, &hw_len
, 0);
618 uint64_t ind_bit
= ldq_be_p(&thinint
->ind_bit
);
621 dev
->summary_indicator
=
622 get_indicator(ldq_be_p(&thinint
->summary_indicator
),
625 get_indicator(ldq_be_p(&thinint
->device_indicator
),
627 dev
->thinint_isc
= thinint
->isc
;
628 dev
->routes
.adapter
.ind_offset
= ind_bit
;
629 dev
->routes
.adapter
.summary_offset
= 7;
630 cpu_physical_memory_unmap(thinint
, hw_len
, 0, hw_len
);
631 ret
= css_register_io_adapter(CSS_IO_ADAPTER_VIRTIO
,
632 dev
->thinint_isc
, true, false,
633 &dev
->routes
.adapter
.adapter_id
);
635 sch
->thinint_active
= ((dev
->indicators
!= NULL
) &&
636 (dev
->summary_indicator
!= NULL
));
637 sch
->curr_status
.scsw
.count
= ccw
.count
- len
;
649 static void virtio_ccw_device_realize(VirtioCcwDevice
*dev
, Error
**errp
)
651 unsigned int cssid
= 0;
652 unsigned int ssid
= 0;
655 bool have_devno
= false;
660 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_GET_CLASS(dev
);
662 sch
= g_malloc0(sizeof(SubchDev
));
664 sch
->driver_data
= dev
;
667 dev
->indicators
= NULL
;
669 /* Initialize subchannel structure. */
670 sch
->channel_prog
= 0x0;
671 sch
->last_cmd_valid
= false;
672 sch
->thinint_active
= false;
674 * Use a device number if provided. Otherwise, fall back to subchannel
678 num
= sscanf(dev
->bus_id
, "%x.%x.%04x", &cssid
, &ssid
, &devno
);
680 if ((cssid
> MAX_CSSID
) || (ssid
> MAX_SSID
)) {
681 error_setg(errp
, "Invalid cssid or ssid: cssid %x, ssid %x",
685 /* Enforce use of virtual cssid. */
686 if (cssid
!= VIRTUAL_CSSID
) {
687 error_setg(errp
, "cssid %x not valid for virtio devices",
691 if (css_devno_used(cssid
, ssid
, devno
)) {
692 error_setg(errp
, "Device %x.%x.%04x already exists",
701 error_setg(errp
, "Malformed devno parameter '%s'", dev
->bus_id
);
706 /* Find the next free id. */
708 for (schid
= 0; schid
<= MAX_SCHID
; schid
++) {
709 if (!css_find_subch(1, cssid
, ssid
, schid
)) {
711 css_subch_assign(cssid
, ssid
, schid
, devno
, sch
);
717 error_setg(errp
, "No free subchannel found for %x.%x.%04x",
721 trace_virtio_ccw_new_device(cssid
, ssid
, schid
, devno
,
724 cssid
= VIRTUAL_CSSID
;
725 for (ssid
= 0; ssid
<= MAX_SSID
; ssid
++) {
726 for (schid
= 0; schid
<= MAX_SCHID
; schid
++) {
727 if (!css_find_subch(1, cssid
, ssid
, schid
)) {
733 * If the devno is already taken, look further in this
736 while (css_devno_used(cssid
, ssid
, devno
)) {
737 if (devno
== MAX_SCHID
) {
739 } else if (devno
== schid
- 1) {
740 error_setg(errp
, "No free devno found");
747 css_subch_assign(cssid
, ssid
, schid
, devno
, sch
);
757 error_setg(errp
, "Virtual channel subsystem is full!");
760 trace_virtio_ccw_new_device(cssid
, ssid
, schid
, devno
,
764 /* Build initial schib. */
765 css_sch_build_virtual_schib(sch
, 0, VIRTIO_CCW_CHPID_TYPE
);
767 sch
->ccw_cb
= virtio_ccw_cb
;
769 /* Build senseid data. */
770 memset(&sch
->id
, 0, sizeof(SenseId
));
771 sch
->id
.reserved
= 0xff;
772 sch
->id
.cu_type
= VIRTIO_CCW_CU_TYPE
;
775 k
->realize(dev
, &err
);
778 error_propagate(errp
, err
);
779 css_subch_assign(cssid
, ssid
, schid
, devno
, NULL
);
790 static int virtio_ccw_exit(VirtioCcwDevice
*dev
)
792 SubchDev
*sch
= dev
->sch
;
795 css_subch_assign(sch
->cssid
, sch
->ssid
, sch
->schid
, sch
->devno
, NULL
);
798 if (dev
->indicators
) {
799 release_indicator(&dev
->routes
.adapter
, dev
->indicators
);
800 dev
->indicators
= NULL
;
805 static void virtio_ccw_net_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
807 DeviceState
*qdev
= DEVICE(ccw_dev
);
808 VirtIONetCcw
*dev
= VIRTIO_NET_CCW(ccw_dev
);
809 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
812 virtio_net_set_netclient_name(&dev
->vdev
, qdev
->id
,
813 object_get_typename(OBJECT(qdev
)));
814 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
815 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
817 error_propagate(errp
, err
);
821 static void virtio_ccw_net_instance_init(Object
*obj
)
823 VirtIONetCcw
*dev
= VIRTIO_NET_CCW(obj
);
825 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
827 object_property_add_alias(obj
, "bootindex", OBJECT(&dev
->vdev
),
828 "bootindex", &error_abort
);
831 static void virtio_ccw_blk_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
833 VirtIOBlkCcw
*dev
= VIRTIO_BLK_CCW(ccw_dev
);
834 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
837 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
838 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
840 error_propagate(errp
, err
);
844 static void virtio_ccw_blk_instance_init(Object
*obj
)
846 VirtIOBlkCcw
*dev
= VIRTIO_BLK_CCW(obj
);
848 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
850 object_property_add_alias(obj
, "iothread", OBJECT(&dev
->vdev
),"iothread",
852 object_property_add_alias(obj
, "bootindex", OBJECT(&dev
->vdev
),
853 "bootindex", &error_abort
);
856 static void virtio_ccw_serial_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
858 VirtioSerialCcw
*dev
= VIRTIO_SERIAL_CCW(ccw_dev
);
859 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
860 DeviceState
*proxy
= DEVICE(ccw_dev
);
865 * For command line compatibility, this sets the virtio-serial-device bus
869 bus_name
= g_strdup_printf("%s.0", proxy
->id
);
870 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev
), bus_name
);
874 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
875 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
877 error_propagate(errp
, err
);
882 static void virtio_ccw_serial_instance_init(Object
*obj
)
884 VirtioSerialCcw
*dev
= VIRTIO_SERIAL_CCW(obj
);
886 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
890 static void virtio_ccw_balloon_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
892 VirtIOBalloonCcw
*dev
= VIRTIO_BALLOON_CCW(ccw_dev
);
893 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
896 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
897 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
899 error_propagate(errp
, err
);
903 static void virtio_ccw_balloon_instance_init(Object
*obj
)
905 VirtIOBalloonCcw
*dev
= VIRTIO_BALLOON_CCW(obj
);
907 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
908 TYPE_VIRTIO_BALLOON
);
909 object_property_add_alias(obj
, "guest-stats", OBJECT(&dev
->vdev
),
910 "guest-stats", &error_abort
);
911 object_property_add_alias(obj
, "guest-stats-polling-interval",
913 "guest-stats-polling-interval", &error_abort
);
916 static void virtio_ccw_scsi_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
918 VirtIOSCSICcw
*dev
= VIRTIO_SCSI_CCW(ccw_dev
);
919 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
920 DeviceState
*qdev
= DEVICE(ccw_dev
);
925 * For command line compatibility, this sets the virtio-scsi-device bus
929 bus_name
= g_strdup_printf("%s.0", qdev
->id
);
930 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev
), bus_name
);
934 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
935 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
937 error_propagate(errp
, err
);
941 static void virtio_ccw_scsi_instance_init(Object
*obj
)
943 VirtIOSCSICcw
*dev
= VIRTIO_SCSI_CCW(obj
);
945 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
947 object_property_add_alias(obj
, "iothread", OBJECT(&dev
->vdev
), "iothread",
951 #ifdef CONFIG_VHOST_SCSI
952 static void vhost_ccw_scsi_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
954 VHostSCSICcw
*dev
= VHOST_SCSI_CCW(ccw_dev
);
955 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
958 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
959 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
961 error_propagate(errp
, err
);
965 static void vhost_ccw_scsi_instance_init(Object
*obj
)
967 VHostSCSICcw
*dev
= VHOST_SCSI_CCW(obj
);
969 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
974 static void virtio_ccw_rng_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
976 VirtIORNGCcw
*dev
= VIRTIO_RNG_CCW(ccw_dev
);
977 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
980 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
981 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
983 error_propagate(errp
, err
);
987 object_property_set_link(OBJECT(dev
),
988 OBJECT(dev
->vdev
.conf
.rng
), "rng",
992 /* DeviceState to VirtioCcwDevice. Note: used on datapath,
993 * be careful and test performance if you change this.
995 static inline VirtioCcwDevice
*to_virtio_ccw_dev_fast(DeviceState
*d
)
997 return container_of(d
, VirtioCcwDevice
, parent_obj
);
1000 static uint8_t virtio_set_ind_atomic(SubchDev
*sch
, uint64_t ind_loc
,
1003 uint8_t ind_old
, ind_new
;
1007 ind_addr
= cpu_physical_memory_map(ind_loc
, &len
, 1);
1009 error_report("%s(%x.%x.%04x): unable to access indicator",
1010 __func__
, sch
->cssid
, sch
->ssid
, sch
->schid
);
1014 ind_old
= *ind_addr
;
1015 ind_new
= ind_old
| to_be_set
;
1016 } while (atomic_cmpxchg(ind_addr
, ind_old
, ind_new
) != ind_old
);
1017 cpu_physical_memory_unmap(ind_addr
, len
, 1, len
);
1022 static void virtio_ccw_notify(DeviceState
*d
, uint16_t vector
)
1024 VirtioCcwDevice
*dev
= to_virtio_ccw_dev_fast(d
);
1025 SubchDev
*sch
= dev
->sch
;
1026 uint64_t indicators
;
1028 if (vector
>= 128) {
1032 if (vector
< VIRTIO_CCW_QUEUE_MAX
) {
1033 if (!dev
->indicators
) {
1036 if (sch
->thinint_active
) {
1038 * In the adapter interrupt case, indicators points to a
1039 * memory area that may be (way) larger than 64 bit and
1040 * ind_bit indicates the start of the indicators in a big
1043 uint64_t ind_bit
= dev
->routes
.adapter
.ind_offset
;
1045 virtio_set_ind_atomic(sch
, dev
->indicators
->addr
+
1046 (ind_bit
+ vector
) / 8,
1047 0x80 >> ((ind_bit
+ vector
) % 8));
1048 if (!virtio_set_ind_atomic(sch
, dev
->summary_indicator
->addr
,
1050 css_adapter_interrupt(dev
->thinint_isc
);
1053 indicators
= address_space_ldq(&address_space_memory
,
1054 dev
->indicators
->addr
,
1055 MEMTXATTRS_UNSPECIFIED
,
1057 indicators
|= 1ULL << vector
;
1058 address_space_stq(&address_space_memory
, dev
->indicators
->addr
,
1059 indicators
, MEMTXATTRS_UNSPECIFIED
, NULL
);
1060 css_conditional_io_interrupt(sch
);
1063 if (!dev
->indicators2
) {
1067 indicators
= address_space_ldq(&address_space_memory
,
1068 dev
->indicators2
->addr
,
1069 MEMTXATTRS_UNSPECIFIED
,
1071 indicators
|= 1ULL << vector
;
1072 address_space_stq(&address_space_memory
, dev
->indicators2
->addr
,
1073 indicators
, MEMTXATTRS_UNSPECIFIED
, NULL
);
1074 css_conditional_io_interrupt(sch
);
1078 static void virtio_ccw_reset(DeviceState
*d
)
1080 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1081 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1083 virtio_ccw_stop_ioeventfd(dev
);
1085 css_reset_sch(dev
->sch
);
1086 if (dev
->indicators
) {
1087 release_indicator(&dev
->routes
.adapter
, dev
->indicators
);
1088 dev
->indicators
= NULL
;
1090 if (dev
->indicators2
) {
1091 release_indicator(&dev
->routes
.adapter
, dev
->indicators2
);
1092 dev
->indicators2
= NULL
;
1094 if (dev
->summary_indicator
) {
1095 release_indicator(&dev
->routes
.adapter
, dev
->summary_indicator
);
1096 dev
->summary_indicator
= NULL
;
1100 static void virtio_ccw_vmstate_change(DeviceState
*d
, bool running
)
1102 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1105 virtio_ccw_start_ioeventfd(dev
);
1107 virtio_ccw_stop_ioeventfd(dev
);
1111 static bool virtio_ccw_query_guest_notifiers(DeviceState
*d
)
1113 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1115 return !!(dev
->sch
->curr_status
.pmcw
.flags
& PMCW_FLAGS_MASK_ENA
);
1118 static int virtio_ccw_set_host_notifier(DeviceState
*d
, int n
, bool assign
)
1120 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1122 /* Stop using the generic ioeventfd, we are doing eventfd handling
1123 * ourselves below */
1124 dev
->ioeventfd_disabled
= assign
;
1126 virtio_ccw_stop_ioeventfd(dev
);
1128 return virtio_ccw_set_guest2host_notifier(dev
, n
, assign
, false);
1131 static int virtio_ccw_get_mappings(VirtioCcwDevice
*dev
)
1135 if (!dev
->sch
->thinint_active
) {
1139 r
= map_indicator(&dev
->routes
.adapter
, dev
->summary_indicator
);
1143 r
= map_indicator(&dev
->routes
.adapter
, dev
->indicators
);
1147 dev
->routes
.adapter
.summary_addr
= dev
->summary_indicator
->map
;
1148 dev
->routes
.adapter
.ind_addr
= dev
->indicators
->map
;
1153 static int virtio_ccw_setup_irqroutes(VirtioCcwDevice
*dev
, int nvqs
)
1156 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1158 S390FLICState
*fs
= s390_get_flic();
1159 S390FLICStateClass
*fsc
= S390_FLIC_COMMON_GET_CLASS(fs
);
1161 ret
= virtio_ccw_get_mappings(dev
);
1165 for (i
= 0; i
< nvqs
; i
++) {
1166 if (!virtio_queue_get_num(vdev
, i
)) {
1170 dev
->routes
.num_routes
= i
;
1171 return fsc
->add_adapter_routes(fs
, &dev
->routes
);
1174 static void virtio_ccw_release_irqroutes(VirtioCcwDevice
*dev
, int nvqs
)
1176 S390FLICState
*fs
= s390_get_flic();
1177 S390FLICStateClass
*fsc
= S390_FLIC_COMMON_GET_CLASS(fs
);
1179 fsc
->release_adapter_routes(fs
, &dev
->routes
);
1182 static int virtio_ccw_add_irqfd(VirtioCcwDevice
*dev
, int n
)
1184 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1185 VirtQueue
*vq
= virtio_get_queue(vdev
, n
);
1186 EventNotifier
*notifier
= virtio_queue_get_guest_notifier(vq
);
1188 return kvm_irqchip_add_irqfd_notifier(kvm_state
, notifier
, NULL
,
1189 dev
->routes
.gsi
[n
]);
1192 static void virtio_ccw_remove_irqfd(VirtioCcwDevice
*dev
, int n
)
1194 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1195 VirtQueue
*vq
= virtio_get_queue(vdev
, n
);
1196 EventNotifier
*notifier
= virtio_queue_get_guest_notifier(vq
);
1199 ret
= kvm_irqchip_remove_irqfd_notifier(kvm_state
, notifier
,
1200 dev
->routes
.gsi
[n
]);
1204 static int virtio_ccw_set_guest_notifier(VirtioCcwDevice
*dev
, int n
,
1205 bool assign
, bool with_irqfd
)
1207 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1208 VirtQueue
*vq
= virtio_get_queue(vdev
, n
);
1209 EventNotifier
*notifier
= virtio_queue_get_guest_notifier(vq
);
1210 VirtioDeviceClass
*k
= VIRTIO_DEVICE_GET_CLASS(vdev
);
1213 int r
= event_notifier_init(notifier
, 0);
1218 virtio_queue_set_guest_notifier_fd_handler(vq
, true, with_irqfd
);
1220 r
= virtio_ccw_add_irqfd(dev
, n
);
1222 virtio_queue_set_guest_notifier_fd_handler(vq
, false,
1228 * We do not support individual masking for channel devices, so we
1229 * need to manually trigger any guest masking callbacks here.
1231 if (k
->guest_notifier_mask
) {
1232 k
->guest_notifier_mask(vdev
, n
, false);
1234 /* get lost events and re-inject */
1235 if (k
->guest_notifier_pending
&&
1236 k
->guest_notifier_pending(vdev
, n
)) {
1237 event_notifier_set(notifier
);
1240 if (k
->guest_notifier_mask
) {
1241 k
->guest_notifier_mask(vdev
, n
, true);
1244 virtio_ccw_remove_irqfd(dev
, n
);
1246 virtio_queue_set_guest_notifier_fd_handler(vq
, false, with_irqfd
);
1247 event_notifier_cleanup(notifier
);
1252 static int virtio_ccw_set_guest_notifiers(DeviceState
*d
, int nvqs
,
1255 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1256 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1257 bool with_irqfd
= dev
->sch
->thinint_active
&& kvm_irqfds_enabled();
1260 if (with_irqfd
&& assigned
) {
1261 /* irq routes need to be set up before assigning irqfds */
1262 r
= virtio_ccw_setup_irqroutes(dev
, nvqs
);
1264 goto irqroute_error
;
1267 for (n
= 0; n
< nvqs
; n
++) {
1268 if (!virtio_queue_get_num(vdev
, n
)) {
1271 r
= virtio_ccw_set_guest_notifier(dev
, n
, assigned
, with_irqfd
);
1276 if (with_irqfd
&& !assigned
) {
1277 /* release irq routes after irqfds have been released */
1278 virtio_ccw_release_irqroutes(dev
, nvqs
);
1284 virtio_ccw_set_guest_notifier(dev
, n
, !assigned
, false);
1287 if (with_irqfd
&& assigned
) {
1288 virtio_ccw_release_irqroutes(dev
, nvqs
);
1293 static void virtio_ccw_save_queue(DeviceState
*d
, int n
, QEMUFile
*f
)
1295 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1296 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1298 qemu_put_be16(f
, virtio_queue_vector(vdev
, n
));
1301 static int virtio_ccw_load_queue(DeviceState
*d
, int n
, QEMUFile
*f
)
1303 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1304 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1307 qemu_get_be16s(f
, &vector
);
1308 virtio_queue_set_vector(vdev
, n
, vector
);
1313 static void virtio_ccw_save_config(DeviceState
*d
, QEMUFile
*f
)
1315 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1316 SubchDev
*s
= dev
->sch
;
1318 subch_device_save(s
, f
);
1319 if (dev
->indicators
!= NULL
) {
1320 qemu_put_be32(f
, dev
->indicators
->len
);
1321 qemu_put_be64(f
, dev
->indicators
->addr
);
1323 qemu_put_be32(f
, 0);
1324 qemu_put_be64(f
, 0UL);
1326 if (dev
->indicators2
!= NULL
) {
1327 qemu_put_be32(f
, dev
->indicators2
->len
);
1328 qemu_put_be64(f
, dev
->indicators2
->addr
);
1330 qemu_put_be32(f
, 0);
1331 qemu_put_be64(f
, 0UL);
1333 if (dev
->summary_indicator
!= NULL
) {
1334 qemu_put_be32(f
, dev
->summary_indicator
->len
);
1335 qemu_put_be64(f
, dev
->summary_indicator
->addr
);
1337 qemu_put_be32(f
, 0);
1338 qemu_put_be64(f
, 0UL);
1340 qemu_put_be64(f
, dev
->routes
.adapter
.ind_offset
);
1341 qemu_put_byte(f
, dev
->thinint_isc
);
1344 static int virtio_ccw_load_config(DeviceState
*d
, QEMUFile
*f
)
1346 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1347 SubchDev
*s
= dev
->sch
;
1350 s
->driver_data
= dev
;
1351 subch_device_load(s
, f
);
1352 len
= qemu_get_be32(f
);
1354 dev
->indicators
= get_indicator(qemu_get_be64(f
), len
);
1357 dev
->indicators
= NULL
;
1359 len
= qemu_get_be32(f
);
1361 dev
->indicators2
= get_indicator(qemu_get_be64(f
), len
);
1364 dev
->indicators2
= NULL
;
1366 len
= qemu_get_be32(f
);
1368 dev
->summary_indicator
= get_indicator(qemu_get_be64(f
), len
);
1371 dev
->summary_indicator
= NULL
;
1373 dev
->routes
.adapter
.ind_offset
= qemu_get_be64(f
);
1374 dev
->thinint_isc
= qemu_get_byte(f
);
1375 if (s
->thinint_active
) {
1376 return css_register_io_adapter(CSS_IO_ADAPTER_VIRTIO
,
1377 dev
->thinint_isc
, true, false,
1378 &dev
->routes
.adapter
.adapter_id
);
1384 /* This is called by virtio-bus just after the device is plugged. */
1385 static void virtio_ccw_device_plugged(DeviceState
*d
, Error
**errp
)
1387 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1388 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1389 SubchDev
*sch
= dev
->sch
;
1390 int n
= virtio_get_num_queues(vdev
);
1392 if (virtio_get_num_queues(vdev
) > VIRTIO_CCW_QUEUE_MAX
) {
1393 error_setg(errp
, "The nubmer of virtqueues %d "
1394 "exceeds ccw limit %d", n
,
1395 VIRTIO_CCW_QUEUE_MAX
);
1399 sch
->id
.cu_model
= virtio_bus_get_vdev_id(&dev
->bus
);
1401 css_generate_sch_crws(sch
->cssid
, sch
->ssid
, sch
->schid
,
1405 static void virtio_ccw_device_unplugged(DeviceState
*d
)
1407 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1409 virtio_ccw_stop_ioeventfd(dev
);
1411 /**************** Virtio-ccw Bus Device Descriptions *******************/
1413 static Property virtio_ccw_net_properties
[] = {
1414 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1415 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1416 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1417 DEFINE_PROP_END_OF_LIST(),
1420 static void virtio_ccw_net_class_init(ObjectClass
*klass
, void *data
)
1422 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1423 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1425 k
->realize
= virtio_ccw_net_realize
;
1426 k
->exit
= virtio_ccw_exit
;
1427 dc
->reset
= virtio_ccw_reset
;
1428 dc
->props
= virtio_ccw_net_properties
;
1429 set_bit(DEVICE_CATEGORY_NETWORK
, dc
->categories
);
1432 static const TypeInfo virtio_ccw_net
= {
1433 .name
= TYPE_VIRTIO_NET_CCW
,
1434 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1435 .instance_size
= sizeof(VirtIONetCcw
),
1436 .instance_init
= virtio_ccw_net_instance_init
,
1437 .class_init
= virtio_ccw_net_class_init
,
1440 static Property virtio_ccw_blk_properties
[] = {
1441 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1442 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1443 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1444 DEFINE_PROP_END_OF_LIST(),
1447 static void virtio_ccw_blk_class_init(ObjectClass
*klass
, void *data
)
1449 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1450 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1452 k
->realize
= virtio_ccw_blk_realize
;
1453 k
->exit
= virtio_ccw_exit
;
1454 dc
->reset
= virtio_ccw_reset
;
1455 dc
->props
= virtio_ccw_blk_properties
;
1456 set_bit(DEVICE_CATEGORY_STORAGE
, dc
->categories
);
1459 static const TypeInfo virtio_ccw_blk
= {
1460 .name
= TYPE_VIRTIO_BLK_CCW
,
1461 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1462 .instance_size
= sizeof(VirtIOBlkCcw
),
1463 .instance_init
= virtio_ccw_blk_instance_init
,
1464 .class_init
= virtio_ccw_blk_class_init
,
1467 static Property virtio_ccw_serial_properties
[] = {
1468 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1469 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1470 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1471 DEFINE_PROP_END_OF_LIST(),
1474 static void virtio_ccw_serial_class_init(ObjectClass
*klass
, void *data
)
1476 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1477 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1479 k
->realize
= virtio_ccw_serial_realize
;
1480 k
->exit
= virtio_ccw_exit
;
1481 dc
->reset
= virtio_ccw_reset
;
1482 dc
->props
= virtio_ccw_serial_properties
;
1483 set_bit(DEVICE_CATEGORY_INPUT
, dc
->categories
);
1486 static const TypeInfo virtio_ccw_serial
= {
1487 .name
= TYPE_VIRTIO_SERIAL_CCW
,
1488 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1489 .instance_size
= sizeof(VirtioSerialCcw
),
1490 .instance_init
= virtio_ccw_serial_instance_init
,
1491 .class_init
= virtio_ccw_serial_class_init
,
1494 static Property virtio_ccw_balloon_properties
[] = {
1495 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1496 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1497 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1498 DEFINE_PROP_END_OF_LIST(),
1501 static void virtio_ccw_balloon_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_balloon_realize
;
1507 k
->exit
= virtio_ccw_exit
;
1508 dc
->reset
= virtio_ccw_reset
;
1509 dc
->props
= virtio_ccw_balloon_properties
;
1510 set_bit(DEVICE_CATEGORY_MISC
, dc
->categories
);
1513 static const TypeInfo virtio_ccw_balloon
= {
1514 .name
= TYPE_VIRTIO_BALLOON_CCW
,
1515 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1516 .instance_size
= sizeof(VirtIOBalloonCcw
),
1517 .instance_init
= virtio_ccw_balloon_instance_init
,
1518 .class_init
= virtio_ccw_balloon_class_init
,
1521 static Property virtio_ccw_scsi_properties
[] = {
1522 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1523 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1524 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1525 DEFINE_PROP_END_OF_LIST(),
1528 static void virtio_ccw_scsi_class_init(ObjectClass
*klass
, void *data
)
1530 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1531 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1533 k
->realize
= virtio_ccw_scsi_realize
;
1534 k
->exit
= virtio_ccw_exit
;
1535 dc
->reset
= virtio_ccw_reset
;
1536 dc
->props
= virtio_ccw_scsi_properties
;
1537 set_bit(DEVICE_CATEGORY_STORAGE
, dc
->categories
);
1540 static const TypeInfo virtio_ccw_scsi
= {
1541 .name
= TYPE_VIRTIO_SCSI_CCW
,
1542 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1543 .instance_size
= sizeof(VirtIOSCSICcw
),
1544 .instance_init
= virtio_ccw_scsi_instance_init
,
1545 .class_init
= virtio_ccw_scsi_class_init
,
1548 #ifdef CONFIG_VHOST_SCSI
1549 static Property vhost_ccw_scsi_properties
[] = {
1550 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1551 DEFINE_PROP_END_OF_LIST(),
1554 static void vhost_ccw_scsi_class_init(ObjectClass
*klass
, void *data
)
1556 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1557 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1559 k
->realize
= vhost_ccw_scsi_realize
;
1560 k
->exit
= virtio_ccw_exit
;
1561 dc
->reset
= virtio_ccw_reset
;
1562 dc
->props
= vhost_ccw_scsi_properties
;
1563 set_bit(DEVICE_CATEGORY_STORAGE
, dc
->categories
);
1566 static const TypeInfo vhost_ccw_scsi
= {
1567 .name
= TYPE_VHOST_SCSI_CCW
,
1568 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1569 .instance_size
= sizeof(VHostSCSICcw
),
1570 .instance_init
= vhost_ccw_scsi_instance_init
,
1571 .class_init
= vhost_ccw_scsi_class_init
,
1575 static void virtio_ccw_rng_instance_init(Object
*obj
)
1577 VirtIORNGCcw
*dev
= VIRTIO_RNG_CCW(obj
);
1579 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
1581 object_property_add_alias(obj
, "rng", OBJECT(&dev
->vdev
),
1582 "rng", &error_abort
);
1585 static Property virtio_ccw_rng_properties
[] = {
1586 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1587 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1588 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1589 DEFINE_PROP_END_OF_LIST(),
1592 static void virtio_ccw_rng_class_init(ObjectClass
*klass
, void *data
)
1594 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1595 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1597 k
->realize
= virtio_ccw_rng_realize
;
1598 k
->exit
= virtio_ccw_exit
;
1599 dc
->reset
= virtio_ccw_reset
;
1600 dc
->props
= virtio_ccw_rng_properties
;
1601 set_bit(DEVICE_CATEGORY_MISC
, dc
->categories
);
1604 static const TypeInfo virtio_ccw_rng
= {
1605 .name
= TYPE_VIRTIO_RNG_CCW
,
1606 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1607 .instance_size
= sizeof(VirtIORNGCcw
),
1608 .instance_init
= virtio_ccw_rng_instance_init
,
1609 .class_init
= virtio_ccw_rng_class_init
,
1612 static void virtio_ccw_busdev_realize(DeviceState
*dev
, Error
**errp
)
1614 VirtioCcwDevice
*_dev
= (VirtioCcwDevice
*)dev
;
1616 virtio_ccw_bus_new(&_dev
->bus
, sizeof(_dev
->bus
), _dev
);
1617 virtio_ccw_device_realize(_dev
, errp
);
1620 static int virtio_ccw_busdev_exit(DeviceState
*dev
)
1622 VirtioCcwDevice
*_dev
= (VirtioCcwDevice
*)dev
;
1623 VirtIOCCWDeviceClass
*_info
= VIRTIO_CCW_DEVICE_GET_CLASS(dev
);
1625 return _info
->exit(_dev
);
1628 static void virtio_ccw_busdev_unplug(HotplugHandler
*hotplug_dev
,
1629 DeviceState
*dev
, Error
**errp
)
1631 VirtioCcwDevice
*_dev
= (VirtioCcwDevice
*)dev
;
1632 SubchDev
*sch
= _dev
->sch
;
1634 virtio_ccw_stop_ioeventfd(_dev
);
1637 * We should arrive here only for device_del, since we don't support
1638 * direct hot(un)plug of channels, but only through virtio.
1640 assert(sch
!= NULL
);
1641 /* Subchannel is now disabled and no longer valid. */
1642 sch
->curr_status
.pmcw
.flags
&= ~(PMCW_FLAGS_MASK_ENA
|
1643 PMCW_FLAGS_MASK_DNV
);
1645 css_generate_sch_crws(sch
->cssid
, sch
->ssid
, sch
->schid
, 1, 0);
1647 object_unparent(OBJECT(dev
));
1650 static void virtio_ccw_device_class_init(ObjectClass
*klass
, void *data
)
1652 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1654 dc
->realize
= virtio_ccw_busdev_realize
;
1655 dc
->exit
= virtio_ccw_busdev_exit
;
1656 dc
->bus_type
= TYPE_VIRTUAL_CSS_BUS
;
1659 static const TypeInfo virtio_ccw_device_info
= {
1660 .name
= TYPE_VIRTIO_CCW_DEVICE
,
1661 .parent
= TYPE_DEVICE
,
1662 .instance_size
= sizeof(VirtioCcwDevice
),
1663 .class_init
= virtio_ccw_device_class_init
,
1664 .class_size
= sizeof(VirtIOCCWDeviceClass
),
1668 /***************** Virtual-css Bus Bridge Device ********************/
1669 /* Only required to have the virtio bus as child in the system bus */
1671 static int virtual_css_bridge_init(SysBusDevice
*dev
)
1677 static void virtual_css_bridge_class_init(ObjectClass
*klass
, void *data
)
1679 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
1680 HotplugHandlerClass
*hc
= HOTPLUG_HANDLER_CLASS(klass
);
1681 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1683 k
->init
= virtual_css_bridge_init
;
1684 hc
->unplug
= virtio_ccw_busdev_unplug
;
1685 set_bit(DEVICE_CATEGORY_BRIDGE
, dc
->categories
);
1688 static const TypeInfo virtual_css_bridge_info
= {
1689 .name
= "virtual-css-bridge",
1690 .parent
= TYPE_SYS_BUS_DEVICE
,
1691 .instance_size
= sizeof(SysBusDevice
),
1692 .class_init
= virtual_css_bridge_class_init
,
1693 .interfaces
= (InterfaceInfo
[]) {
1694 { TYPE_HOTPLUG_HANDLER
},
1699 /* virtio-ccw-bus */
1701 static void virtio_ccw_bus_new(VirtioBusState
*bus
, size_t bus_size
,
1702 VirtioCcwDevice
*dev
)
1704 DeviceState
*qdev
= DEVICE(dev
);
1705 char virtio_bus_name
[] = "virtio-bus";
1707 qbus_create_inplace(bus
, bus_size
, TYPE_VIRTIO_CCW_BUS
,
1708 qdev
, virtio_bus_name
);
1711 static void virtio_ccw_bus_class_init(ObjectClass
*klass
, void *data
)
1713 VirtioBusClass
*k
= VIRTIO_BUS_CLASS(klass
);
1714 BusClass
*bus_class
= BUS_CLASS(klass
);
1716 bus_class
->max_dev
= 1;
1717 k
->notify
= virtio_ccw_notify
;
1718 k
->vmstate_change
= virtio_ccw_vmstate_change
;
1719 k
->query_guest_notifiers
= virtio_ccw_query_guest_notifiers
;
1720 k
->set_host_notifier
= virtio_ccw_set_host_notifier
;
1721 k
->set_guest_notifiers
= virtio_ccw_set_guest_notifiers
;
1722 k
->save_queue
= virtio_ccw_save_queue
;
1723 k
->load_queue
= virtio_ccw_load_queue
;
1724 k
->save_config
= virtio_ccw_save_config
;
1725 k
->load_config
= virtio_ccw_load_config
;
1726 k
->device_plugged
= virtio_ccw_device_plugged
;
1727 k
->device_unplugged
= virtio_ccw_device_unplugged
;
1730 static const TypeInfo virtio_ccw_bus_info
= {
1731 .name
= TYPE_VIRTIO_CCW_BUS
,
1732 .parent
= TYPE_VIRTIO_BUS
,
1733 .instance_size
= sizeof(VirtioCcwBusState
),
1734 .class_init
= virtio_ccw_bus_class_init
,
1737 static void virtio_ccw_register(void)
1739 type_register_static(&virtio_ccw_bus_info
);
1740 type_register_static(&virtual_css_bus_info
);
1741 type_register_static(&virtio_ccw_device_info
);
1742 type_register_static(&virtio_ccw_serial
);
1743 type_register_static(&virtio_ccw_blk
);
1744 type_register_static(&virtio_ccw_net
);
1745 type_register_static(&virtio_ccw_balloon
);
1746 type_register_static(&virtio_ccw_scsi
);
1747 #ifdef CONFIG_VHOST_SCSI
1748 type_register_static(&vhost_ccw_scsi
);
1750 type_register_static(&virtio_ccw_rng
);
1751 type_register_static(&virtual_css_bridge_info
);
1754 type_init(virtio_ccw_register
)