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 "block/block.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 bus
->allow_hotplug
= 1;
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
= ldq_phys(&address_space_memory
, ccw
.cda
);
339 info
.align
= ldl_phys(&address_space_memory
,
340 ccw
.cda
+ sizeof(info
.queue
));
341 info
.index
= lduw_phys(&address_space_memory
,
342 ccw
.cda
+ sizeof(info
.queue
)
343 + sizeof(info
.align
));
344 info
.num
= lduw_phys(&address_space_memory
,
345 ccw
.cda
+ sizeof(info
.queue
)
347 + sizeof(info
.index
));
348 ret
= virtio_ccw_set_vqs(sch
, info
.queue
, info
.align
, info
.index
,
350 sch
->curr_status
.scsw
.count
= 0;
353 case CCW_CMD_VDEV_RESET
:
354 virtio_ccw_stop_ioeventfd(dev
);
358 case CCW_CMD_READ_FEAT
:
360 if (ccw
.count
!= sizeof(features
)) {
364 } else if (ccw
.count
< sizeof(features
)) {
365 /* Can't execute command. */
372 features
.index
= ldub_phys(&address_space_memory
,
373 ccw
.cda
+ sizeof(features
.features
));
374 if (features
.index
< ARRAY_SIZE(dev
->host_features
)) {
375 features
.features
= dev
->host_features
[features
.index
];
377 /* Return zeroes if the guest supports more feature bits. */
378 features
.features
= 0;
380 stl_le_phys(&address_space_memory
, ccw
.cda
, features
.features
);
381 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(features
);
385 case CCW_CMD_WRITE_FEAT
:
387 if (ccw
.count
!= sizeof(features
)) {
391 } else if (ccw
.count
< sizeof(features
)) {
392 /* Can't execute command. */
399 features
.index
= ldub_phys(&address_space_memory
,
400 ccw
.cda
+ sizeof(features
.features
));
401 features
.features
= ldl_le_phys(&address_space_memory
, ccw
.cda
);
402 if (features
.index
< ARRAY_SIZE(dev
->host_features
)) {
403 virtio_bus_set_vdev_features(&dev
->bus
, features
.features
);
404 vdev
->guest_features
= features
.features
;
407 * If the guest supports more feature bits, assert that it
408 * passes us zeroes for those we don't support.
410 if (features
.features
) {
411 fprintf(stderr
, "Guest bug: features[%i]=%x (expected 0)\n",
412 features
.index
, features
.features
);
413 /* XXX: do a unit check here? */
416 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(features
);
420 case CCW_CMD_READ_CONF
:
422 if (ccw
.count
> vdev
->config_len
) {
427 len
= MIN(ccw
.count
, vdev
->config_len
);
431 virtio_bus_get_vdev_config(&dev
->bus
, vdev
->config
);
432 /* XXX config space endianness */
433 cpu_physical_memory_write(ccw
.cda
, vdev
->config
, len
);
434 sch
->curr_status
.scsw
.count
= ccw
.count
- len
;
438 case CCW_CMD_WRITE_CONF
:
440 if (ccw
.count
> vdev
->config_len
) {
445 len
= MIN(ccw
.count
, vdev
->config_len
);
450 config
= cpu_physical_memory_map(ccw
.cda
, &hw_len
, 0);
455 /* XXX config space endianness */
456 memcpy(vdev
->config
, config
, len
);
457 cpu_physical_memory_unmap(config
, hw_len
, 0, hw_len
);
458 virtio_bus_set_vdev_config(&dev
->bus
, vdev
->config
);
459 sch
->curr_status
.scsw
.count
= ccw
.count
- len
;
464 case CCW_CMD_WRITE_STATUS
:
466 if (ccw
.count
!= sizeof(status
)) {
470 } else if (ccw
.count
< sizeof(status
)) {
471 /* Can't execute command. */
478 status
= ldub_phys(&address_space_memory
, ccw
.cda
);
479 if (!(status
& VIRTIO_CONFIG_S_DRIVER_OK
)) {
480 virtio_ccw_stop_ioeventfd(dev
);
482 virtio_set_status(vdev
, status
);
483 if (vdev
->status
== 0) {
486 if (status
& VIRTIO_CONFIG_S_DRIVER_OK
) {
487 virtio_ccw_start_ioeventfd(dev
);
489 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(status
);
493 case CCW_CMD_SET_IND
:
495 if (ccw
.count
!= sizeof(indicators
)) {
499 } else if (ccw
.count
< sizeof(indicators
)) {
500 /* Can't execute command. */
504 if (sch
->thinint_active
) {
505 /* Trigger a command reject. */
512 indicators
= ldq_phys(&address_space_memory
, ccw
.cda
);
513 dev
->indicators
= get_indicator(indicators
, sizeof(uint64_t));
514 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(indicators
);
518 case CCW_CMD_SET_CONF_IND
:
520 if (ccw
.count
!= sizeof(indicators
)) {
524 } else if (ccw
.count
< sizeof(indicators
)) {
525 /* Can't execute command. */
532 indicators
= ldq_phys(&address_space_memory
, ccw
.cda
);
533 dev
->indicators2
= get_indicator(indicators
, sizeof(uint64_t));
534 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(indicators
);
538 case CCW_CMD_READ_VQ_CONF
:
540 if (ccw
.count
!= sizeof(vq_config
)) {
544 } else if (ccw
.count
< sizeof(vq_config
)) {
545 /* Can't execute command. */
552 vq_config
.index
= lduw_phys(&address_space_memory
, ccw
.cda
);
553 vq_config
.num_max
= virtio_queue_get_num(vdev
,
555 stw_phys(&address_space_memory
,
556 ccw
.cda
+ sizeof(vq_config
.index
), vq_config
.num_max
);
557 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(vq_config
);
561 case CCW_CMD_SET_IND_ADAPTER
:
563 if (ccw
.count
!= sizeof(*thinint
)) {
567 } else if (ccw
.count
< sizeof(*thinint
)) {
568 /* Can't execute command. */
572 len
= sizeof(*thinint
);
576 } else if (dev
->indicators
&& !sch
->thinint_active
) {
577 /* Trigger a command reject. */
580 thinint
= cpu_physical_memory_map(ccw
.cda
, &hw_len
, 0);
585 dev
->summary_indicator
=
586 get_indicator(thinint
->summary_indicator
, sizeof(uint8_t));
587 dev
->indicators
= get_indicator(thinint
->device_indicator
,
588 thinint
->ind_bit
/ 8 + 1);
589 dev
->thinint_isc
= thinint
->isc
;
590 dev
->routes
.adapter
.ind_offset
= thinint
->ind_bit
;
591 dev
->routes
.adapter
.summary_offset
= 7;
592 cpu_physical_memory_unmap(thinint
, hw_len
, 0, hw_len
);
593 ret
= css_register_io_adapter(CSS_IO_ADAPTER_VIRTIO
,
594 dev
->thinint_isc
, true, false,
595 &dev
->routes
.adapter
.adapter_id
);
597 sch
->thinint_active
= ((dev
->indicators
!= NULL
) &&
598 (dev
->summary_indicator
!= NULL
));
599 sch
->curr_status
.scsw
.count
= ccw
.count
- len
;
611 static int virtio_ccw_device_init(VirtioCcwDevice
*dev
, VirtIODevice
*vdev
)
613 unsigned int cssid
= 0;
614 unsigned int ssid
= 0;
617 bool have_devno
= false;
622 DeviceState
*parent
= DEVICE(dev
);
624 sch
= g_malloc0(sizeof(SubchDev
));
626 sch
->driver_data
= dev
;
629 dev
->indicators
= NULL
;
631 /* Initialize subchannel structure. */
632 sch
->channel_prog
= 0x0;
633 sch
->last_cmd_valid
= false;
634 sch
->thinint_active
= false;
636 * Use a device number if provided. Otherwise, fall back to subchannel
640 num
= sscanf(dev
->bus_id
, "%x.%x.%04x", &cssid
, &ssid
, &devno
);
642 if ((cssid
> MAX_CSSID
) || (ssid
> MAX_SSID
)) {
644 error_report("Invalid cssid or ssid: cssid %x, ssid %x",
648 /* Enforce use of virtual cssid. */
649 if (cssid
!= VIRTUAL_CSSID
) {
651 error_report("cssid %x not valid for virtio devices", cssid
);
654 if (css_devno_used(cssid
, ssid
, devno
)) {
656 error_report("Device %x.%x.%04x already exists", cssid
, ssid
,
666 error_report("Malformed devno parameter '%s'", dev
->bus_id
);
671 /* Find the next free id. */
673 for (schid
= 0; schid
<= MAX_SCHID
; schid
++) {
674 if (!css_find_subch(1, cssid
, ssid
, schid
)) {
676 css_subch_assign(cssid
, ssid
, schid
, devno
, sch
);
683 error_report("No free subchannel found for %x.%x.%04x", cssid
, ssid
,
687 trace_virtio_ccw_new_device(cssid
, ssid
, schid
, devno
,
690 cssid
= VIRTUAL_CSSID
;
691 for (ssid
= 0; ssid
<= MAX_SSID
; ssid
++) {
692 for (schid
= 0; schid
<= MAX_SCHID
; schid
++) {
693 if (!css_find_subch(1, cssid
, ssid
, schid
)) {
699 * If the devno is already taken, look further in this
702 while (css_devno_used(cssid
, ssid
, devno
)) {
703 if (devno
== MAX_SCHID
) {
705 } else if (devno
== schid
- 1) {
707 error_report("No free devno found");
714 css_subch_assign(cssid
, ssid
, schid
, devno
, sch
);
725 error_report("Virtual channel subsystem is full!");
728 trace_virtio_ccw_new_device(cssid
, ssid
, schid
, devno
,
732 /* Build initial schib. */
733 css_sch_build_virtual_schib(sch
, 0, VIRTIO_CCW_CHPID_TYPE
);
735 sch
->ccw_cb
= virtio_ccw_cb
;
737 /* Build senseid data. */
738 memset(&sch
->id
, 0, sizeof(SenseId
));
739 sch
->id
.reserved
= 0xff;
740 sch
->id
.cu_type
= VIRTIO_CCW_CU_TYPE
;
741 sch
->id
.cu_model
= vdev
->device_id
;
743 /* Only the first 32 feature bits are used. */
744 dev
->host_features
[0] = virtio_bus_get_vdev_features(&dev
->bus
,
745 dev
->host_features
[0]);
747 dev
->host_features
[0] |= 0x1 << VIRTIO_F_NOTIFY_ON_EMPTY
;
748 dev
->host_features
[0] |= 0x1 << VIRTIO_F_BAD_FEATURE
;
750 css_generate_sch_crws(sch
->cssid
, sch
->ssid
, sch
->schid
,
751 parent
->hotplugged
, 1);
760 static int virtio_ccw_exit(VirtioCcwDevice
*dev
)
762 SubchDev
*sch
= dev
->sch
;
765 css_subch_assign(sch
->cssid
, sch
->ssid
, sch
->schid
, sch
->devno
, NULL
);
768 if (dev
->indicators
) {
769 release_indicator(&dev
->routes
.adapter
, dev
->indicators
);
770 dev
->indicators
= NULL
;
775 static int virtio_ccw_net_init(VirtioCcwDevice
*ccw_dev
)
777 DeviceState
*qdev
= DEVICE(ccw_dev
);
778 VirtIONetCcw
*dev
= VIRTIO_NET_CCW(ccw_dev
);
779 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
781 virtio_net_set_config_size(&dev
->vdev
, ccw_dev
->host_features
[0]);
782 virtio_net_set_netclient_name(&dev
->vdev
, qdev
->id
,
783 object_get_typename(OBJECT(qdev
)));
784 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
785 if (qdev_init(vdev
) < 0) {
789 return virtio_ccw_device_init(ccw_dev
, VIRTIO_DEVICE(vdev
));
792 static void virtio_ccw_net_instance_init(Object
*obj
)
794 VirtIONetCcw
*dev
= VIRTIO_NET_CCW(obj
);
795 object_initialize(&dev
->vdev
, sizeof(dev
->vdev
), TYPE_VIRTIO_NET
);
796 object_property_add_child(obj
, "virtio-backend", OBJECT(&dev
->vdev
), NULL
);
799 static int virtio_ccw_blk_init(VirtioCcwDevice
*ccw_dev
)
801 VirtIOBlkCcw
*dev
= VIRTIO_BLK_CCW(ccw_dev
);
802 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
803 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
804 if (qdev_init(vdev
) < 0) {
808 return virtio_ccw_device_init(ccw_dev
, VIRTIO_DEVICE(vdev
));
811 static void virtio_ccw_blk_instance_init(Object
*obj
)
813 VirtIOBlkCcw
*dev
= VIRTIO_BLK_CCW(obj
);
814 object_initialize(&dev
->vdev
, sizeof(dev
->vdev
), TYPE_VIRTIO_BLK
);
815 object_property_add_child(obj
, "virtio-backend", OBJECT(&dev
->vdev
), NULL
);
816 object_unref(OBJECT(&dev
->vdev
));
817 qdev_alias_all_properties(DEVICE(&dev
->vdev
), obj
);
820 static int virtio_ccw_serial_init(VirtioCcwDevice
*ccw_dev
)
822 VirtioSerialCcw
*dev
= VIRTIO_SERIAL_CCW(ccw_dev
);
823 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
824 DeviceState
*proxy
= DEVICE(ccw_dev
);
828 * For command line compatibility, this sets the virtio-serial-device bus
832 bus_name
= g_strdup_printf("%s.0", proxy
->id
);
833 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev
), bus_name
);
837 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
838 if (qdev_init(vdev
) < 0) {
842 return virtio_ccw_device_init(ccw_dev
, VIRTIO_DEVICE(vdev
));
846 static void virtio_ccw_serial_instance_init(Object
*obj
)
848 VirtioSerialCcw
*dev
= VIRTIO_SERIAL_CCW(obj
);
849 object_initialize(&dev
->vdev
, sizeof(dev
->vdev
), TYPE_VIRTIO_SERIAL
);
850 object_property_add_child(obj
, "virtio-backend", OBJECT(&dev
->vdev
), NULL
);
853 static int virtio_ccw_balloon_init(VirtioCcwDevice
*ccw_dev
)
855 VirtIOBalloonCcw
*dev
= VIRTIO_BALLOON_CCW(ccw_dev
);
856 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
858 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
859 if (qdev_init(vdev
) < 0) {
863 return virtio_ccw_device_init(ccw_dev
, VIRTIO_DEVICE(vdev
));
866 static void balloon_ccw_stats_get_all(Object
*obj
, struct Visitor
*v
,
867 void *opaque
, const char *name
,
870 VirtIOBalloonCcw
*dev
= opaque
;
871 object_property_get(OBJECT(&dev
->vdev
), v
, "guest-stats", errp
);
874 static void balloon_ccw_stats_get_poll_interval(Object
*obj
, struct Visitor
*v
,
875 void *opaque
, const char *name
,
878 VirtIOBalloonCcw
*dev
= opaque
;
879 object_property_get(OBJECT(&dev
->vdev
), v
, "guest-stats-polling-interval",
883 static void balloon_ccw_stats_set_poll_interval(Object
*obj
, struct Visitor
*v
,
884 void *opaque
, const char *name
,
887 VirtIOBalloonCcw
*dev
= opaque
;
888 object_property_set(OBJECT(&dev
->vdev
), v
, "guest-stats-polling-interval",
892 static void virtio_ccw_balloon_instance_init(Object
*obj
)
894 VirtIOBalloonCcw
*dev
= VIRTIO_BALLOON_CCW(obj
);
895 object_initialize(&dev
->vdev
, sizeof(dev
->vdev
), TYPE_VIRTIO_BALLOON
);
896 object_property_add_child(obj
, "virtio-backend", OBJECT(&dev
->vdev
), NULL
);
898 object_property_add(obj
, "guest-stats", "guest statistics",
899 balloon_ccw_stats_get_all
, NULL
, NULL
, dev
, NULL
);
901 object_property_add(obj
, "guest-stats-polling-interval", "int",
902 balloon_ccw_stats_get_poll_interval
,
903 balloon_ccw_stats_set_poll_interval
,
907 static int virtio_ccw_scsi_init(VirtioCcwDevice
*ccw_dev
)
909 VirtIOSCSICcw
*dev
= VIRTIO_SCSI_CCW(ccw_dev
);
910 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
911 DeviceState
*qdev
= DEVICE(ccw_dev
);
915 * For command line compatibility, this sets the virtio-scsi-device bus
919 bus_name
= g_strdup_printf("%s.0", qdev
->id
);
920 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev
), bus_name
);
924 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
925 if (qdev_init(vdev
) < 0) {
929 return virtio_ccw_device_init(ccw_dev
, VIRTIO_DEVICE(vdev
));
932 static void virtio_ccw_scsi_instance_init(Object
*obj
)
934 VirtIOSCSICcw
*dev
= VIRTIO_SCSI_CCW(obj
);
935 object_initialize(&dev
->vdev
, sizeof(dev
->vdev
), TYPE_VIRTIO_SCSI
);
936 object_property_add_child(obj
, "virtio-backend", OBJECT(&dev
->vdev
), NULL
);
939 #ifdef CONFIG_VHOST_SCSI
940 static int vhost_ccw_scsi_init(VirtioCcwDevice
*ccw_dev
)
942 VHostSCSICcw
*dev
= VHOST_SCSI_CCW(ccw_dev
);
943 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
945 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
946 if (qdev_init(vdev
) < 0) {
950 return virtio_ccw_device_init(ccw_dev
, VIRTIO_DEVICE(vdev
));
953 static void vhost_ccw_scsi_instance_init(Object
*obj
)
955 VHostSCSICcw
*dev
= VHOST_SCSI_CCW(obj
);
956 object_initialize(&dev
->vdev
, sizeof(dev
->vdev
), TYPE_VHOST_SCSI
);
957 object_property_add_child(obj
, "virtio-backend", OBJECT(&dev
->vdev
), NULL
);
961 static int virtio_ccw_rng_init(VirtioCcwDevice
*ccw_dev
)
963 VirtIORNGCcw
*dev
= VIRTIO_RNG_CCW(ccw_dev
);
964 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
966 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
967 if (qdev_init(vdev
) < 0) {
971 object_property_set_link(OBJECT(dev
),
972 OBJECT(dev
->vdev
.conf
.rng
), "rng",
975 return virtio_ccw_device_init(ccw_dev
, VIRTIO_DEVICE(vdev
));
978 /* DeviceState to VirtioCcwDevice. Note: used on datapath,
979 * be careful and test performance if you change this.
981 static inline VirtioCcwDevice
*to_virtio_ccw_dev_fast(DeviceState
*d
)
983 return container_of(d
, VirtioCcwDevice
, parent_obj
);
986 static uint8_t virtio_set_ind_atomic(SubchDev
*sch
, uint64_t ind_loc
,
989 uint8_t ind_old
, ind_new
;
993 ind_addr
= cpu_physical_memory_map(ind_loc
, &len
, 1);
995 error_report("%s(%x.%x.%04x): unable to access indicator",
996 __func__
, sch
->cssid
, sch
->ssid
, sch
->schid
);
1000 ind_old
= *ind_addr
;
1001 ind_new
= ind_old
| to_be_set
;
1002 } while (atomic_cmpxchg(ind_addr
, ind_old
, ind_new
) != ind_old
);
1003 cpu_physical_memory_unmap(ind_addr
, len
, 1, len
);
1008 static void virtio_ccw_notify(DeviceState
*d
, uint16_t vector
)
1010 VirtioCcwDevice
*dev
= to_virtio_ccw_dev_fast(d
);
1011 SubchDev
*sch
= dev
->sch
;
1012 uint64_t indicators
;
1014 if (vector
>= 128) {
1018 if (vector
< VIRTIO_PCI_QUEUE_MAX
) {
1019 if (!dev
->indicators
) {
1022 if (sch
->thinint_active
) {
1024 * In the adapter interrupt case, indicators points to a
1025 * memory area that may be (way) larger than 64 bit and
1026 * ind_bit indicates the start of the indicators in a big
1029 uint64_t ind_bit
= dev
->routes
.adapter
.ind_offset
;
1031 virtio_set_ind_atomic(sch
, dev
->indicators
->addr
+
1032 (ind_bit
+ vector
) / 8,
1033 0x80 >> ((ind_bit
+ vector
) % 8));
1034 if (!virtio_set_ind_atomic(sch
, dev
->summary_indicator
->addr
,
1036 css_adapter_interrupt(dev
->thinint_isc
);
1039 indicators
= ldq_phys(&address_space_memory
, dev
->indicators
->addr
);
1040 indicators
|= 1ULL << vector
;
1041 stq_phys(&address_space_memory
, dev
->indicators
->addr
, indicators
);
1042 css_conditional_io_interrupt(sch
);
1045 if (!dev
->indicators2
) {
1049 indicators
= ldq_phys(&address_space_memory
, dev
->indicators2
->addr
);
1050 indicators
|= 1ULL << vector
;
1051 stq_phys(&address_space_memory
, dev
->indicators2
->addr
, indicators
);
1052 css_conditional_io_interrupt(sch
);
1056 static unsigned virtio_ccw_get_features(DeviceState
*d
)
1058 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1060 /* Only the first 32 feature bits are used. */
1061 return dev
->host_features
[0];
1064 static void virtio_ccw_reset(DeviceState
*d
)
1066 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1067 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1069 virtio_ccw_stop_ioeventfd(dev
);
1071 css_reset_sch(dev
->sch
);
1072 if (dev
->indicators
) {
1073 release_indicator(&dev
->routes
.adapter
, dev
->indicators
);
1074 dev
->indicators
= NULL
;
1076 if (dev
->indicators2
) {
1077 release_indicator(&dev
->routes
.adapter
, dev
->indicators2
);
1078 dev
->indicators2
= NULL
;
1080 if (dev
->summary_indicator
) {
1081 release_indicator(&dev
->routes
.adapter
, dev
->summary_indicator
);
1082 dev
->summary_indicator
= NULL
;
1086 static void virtio_ccw_vmstate_change(DeviceState
*d
, bool running
)
1088 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1091 virtio_ccw_start_ioeventfd(dev
);
1093 virtio_ccw_stop_ioeventfd(dev
);
1097 static bool virtio_ccw_query_guest_notifiers(DeviceState
*d
)
1099 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1101 return !!(dev
->sch
->curr_status
.pmcw
.flags
& PMCW_FLAGS_MASK_ENA
);
1104 static int virtio_ccw_set_host_notifier(DeviceState
*d
, int n
, bool assign
)
1106 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1108 /* Stop using the generic ioeventfd, we are doing eventfd handling
1109 * ourselves below */
1110 dev
->ioeventfd_disabled
= assign
;
1112 virtio_ccw_stop_ioeventfd(dev
);
1114 return virtio_ccw_set_guest2host_notifier(dev
, n
, assign
, false);
1117 static int virtio_ccw_get_mappings(VirtioCcwDevice
*dev
)
1121 if (!dev
->sch
->thinint_active
) {
1125 r
= map_indicator(&dev
->routes
.adapter
, dev
->summary_indicator
);
1129 r
= map_indicator(&dev
->routes
.adapter
, dev
->indicators
);
1133 dev
->routes
.adapter
.summary_addr
= dev
->summary_indicator
->map
;
1134 dev
->routes
.adapter
.ind_addr
= dev
->indicators
->map
;
1139 static int virtio_ccw_setup_irqroutes(VirtioCcwDevice
*dev
, int nvqs
)
1142 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1144 S390FLICState
*fs
= s390_get_flic();
1145 S390FLICStateClass
*fsc
= S390_FLIC_COMMON_GET_CLASS(fs
);
1147 ret
= virtio_ccw_get_mappings(dev
);
1151 for (i
= 0; i
< nvqs
; i
++) {
1152 if (!virtio_queue_get_num(vdev
, i
)) {
1156 dev
->routes
.num_routes
= i
;
1157 return fsc
->add_adapter_routes(fs
, &dev
->routes
);
1160 static void virtio_ccw_release_irqroutes(VirtioCcwDevice
*dev
, int nvqs
)
1162 S390FLICState
*fs
= s390_get_flic();
1163 S390FLICStateClass
*fsc
= S390_FLIC_COMMON_GET_CLASS(fs
);
1165 fsc
->release_adapter_routes(fs
, &dev
->routes
);
1168 static int virtio_ccw_add_irqfd(VirtioCcwDevice
*dev
, int n
)
1170 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1171 VirtQueue
*vq
= virtio_get_queue(vdev
, n
);
1172 EventNotifier
*notifier
= virtio_queue_get_guest_notifier(vq
);
1174 return kvm_irqchip_add_irqfd_notifier(kvm_state
, notifier
, NULL
,
1175 dev
->routes
.gsi
[n
]);
1178 static void virtio_ccw_remove_irqfd(VirtioCcwDevice
*dev
, int n
)
1180 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1181 VirtQueue
*vq
= virtio_get_queue(vdev
, n
);
1182 EventNotifier
*notifier
= virtio_queue_get_guest_notifier(vq
);
1185 ret
= kvm_irqchip_remove_irqfd_notifier(kvm_state
, notifier
,
1186 dev
->routes
.gsi
[n
]);
1190 static int virtio_ccw_set_guest_notifier(VirtioCcwDevice
*dev
, int n
,
1191 bool assign
, bool with_irqfd
)
1193 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1194 VirtQueue
*vq
= virtio_get_queue(vdev
, n
);
1195 EventNotifier
*notifier
= virtio_queue_get_guest_notifier(vq
);
1196 VirtioDeviceClass
*k
= VIRTIO_DEVICE_GET_CLASS(vdev
);
1199 int r
= event_notifier_init(notifier
, 0);
1204 virtio_queue_set_guest_notifier_fd_handler(vq
, true, with_irqfd
);
1206 r
= virtio_ccw_add_irqfd(dev
, n
);
1208 virtio_queue_set_guest_notifier_fd_handler(vq
, false,
1214 * We do not support individual masking for channel devices, so we
1215 * need to manually trigger any guest masking callbacks here.
1217 if (k
->guest_notifier_mask
) {
1218 k
->guest_notifier_mask(vdev
, n
, false);
1220 /* get lost events and re-inject */
1221 if (k
->guest_notifier_pending
&&
1222 k
->guest_notifier_pending(vdev
, n
)) {
1223 event_notifier_set(notifier
);
1226 if (k
->guest_notifier_mask
) {
1227 k
->guest_notifier_mask(vdev
, n
, true);
1230 virtio_ccw_remove_irqfd(dev
, n
);
1232 virtio_queue_set_guest_notifier_fd_handler(vq
, false, with_irqfd
);
1233 event_notifier_cleanup(notifier
);
1238 static int virtio_ccw_set_guest_notifiers(DeviceState
*d
, int nvqs
,
1241 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1242 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1243 bool with_irqfd
= dev
->sch
->thinint_active
&& kvm_irqfds_enabled();
1246 if (with_irqfd
&& assigned
) {
1247 /* irq routes need to be set up before assigning irqfds */
1248 r
= virtio_ccw_setup_irqroutes(dev
, nvqs
);
1250 goto irqroute_error
;
1253 for (n
= 0; n
< nvqs
; n
++) {
1254 if (!virtio_queue_get_num(vdev
, n
)) {
1257 r
= virtio_ccw_set_guest_notifier(dev
, n
, assigned
, with_irqfd
);
1262 if (with_irqfd
&& !assigned
) {
1263 /* release irq routes after irqfds have been released */
1264 virtio_ccw_release_irqroutes(dev
, nvqs
);
1270 virtio_ccw_set_guest_notifier(dev
, n
, !assigned
, false);
1273 if (with_irqfd
&& assigned
) {
1274 virtio_ccw_release_irqroutes(dev
, nvqs
);
1279 static void virtio_ccw_save_queue(DeviceState
*d
, int n
, QEMUFile
*f
)
1281 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1282 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1284 qemu_put_be16(f
, virtio_queue_vector(vdev
, n
));
1287 static int virtio_ccw_load_queue(DeviceState
*d
, int n
, QEMUFile
*f
)
1289 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1290 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1293 qemu_get_be16s(f
, &vector
);
1294 virtio_queue_set_vector(vdev
, n
, vector
);
1299 static void virtio_ccw_save_config(DeviceState
*d
, QEMUFile
*f
)
1301 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1302 SubchDev
*s
= dev
->sch
;
1304 subch_device_save(s
, f
);
1305 if (dev
->indicators
!= NULL
) {
1306 qemu_put_be32(f
, dev
->indicators
->len
);
1307 qemu_put_be64(f
, dev
->indicators
->addr
);
1309 qemu_put_be32(f
, 0);
1310 qemu_put_be64(f
, 0UL);
1312 if (dev
->indicators2
!= NULL
) {
1313 qemu_put_be32(f
, dev
->indicators2
->len
);
1314 qemu_put_be64(f
, dev
->indicators2
->addr
);
1316 qemu_put_be32(f
, 0);
1317 qemu_put_be64(f
, 0UL);
1319 if (dev
->summary_indicator
!= NULL
) {
1320 qemu_put_be32(f
, dev
->summary_indicator
->len
);
1321 qemu_put_be64(f
, dev
->summary_indicator
->addr
);
1323 qemu_put_be32(f
, 0);
1324 qemu_put_be64(f
, 0UL);
1326 qemu_put_be64(f
, dev
->routes
.adapter
.ind_offset
);
1327 qemu_put_byte(f
, dev
->thinint_isc
);
1330 static int virtio_ccw_load_config(DeviceState
*d
, QEMUFile
*f
)
1332 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1333 SubchDev
*s
= dev
->sch
;
1336 s
->driver_data
= dev
;
1337 subch_device_load(s
, f
);
1338 len
= qemu_get_be32(f
);
1340 dev
->indicators
= get_indicator(qemu_get_be64(f
), len
);
1343 dev
->indicators
= NULL
;
1345 len
= qemu_get_be32(f
);
1347 dev
->indicators2
= get_indicator(qemu_get_be64(f
), len
);
1350 dev
->indicators2
= NULL
;
1352 len
= qemu_get_be32(f
);
1354 dev
->summary_indicator
= get_indicator(qemu_get_be64(f
), len
);
1357 dev
->summary_indicator
= NULL
;
1359 dev
->routes
.adapter
.ind_offset
= qemu_get_be64(f
);
1360 dev
->thinint_isc
= qemu_get_byte(f
);
1361 if (s
->thinint_active
) {
1362 return css_register_io_adapter(CSS_IO_ADAPTER_VIRTIO
,
1363 dev
->thinint_isc
, true, false,
1364 &dev
->routes
.adapter
.adapter_id
);
1370 /**************** Virtio-ccw Bus Device Descriptions *******************/
1372 static Property virtio_ccw_net_properties
[] = {
1373 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1374 DEFINE_VIRTIO_NET_FEATURES(VirtioCcwDevice
, host_features
[0]),
1375 DEFINE_VIRTIO_NET_PROPERTIES(VirtIONetCcw
, vdev
.net_conf
),
1376 DEFINE_NIC_PROPERTIES(VirtIONetCcw
, vdev
.nic_conf
),
1377 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1378 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1379 DEFINE_PROP_END_OF_LIST(),
1382 static void virtio_ccw_net_class_init(ObjectClass
*klass
, void *data
)
1384 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1385 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1387 k
->init
= virtio_ccw_net_init
;
1388 k
->exit
= virtio_ccw_exit
;
1389 dc
->reset
= virtio_ccw_reset
;
1390 dc
->props
= virtio_ccw_net_properties
;
1393 static const TypeInfo virtio_ccw_net
= {
1394 .name
= TYPE_VIRTIO_NET_CCW
,
1395 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1396 .instance_size
= sizeof(VirtIONetCcw
),
1397 .instance_init
= virtio_ccw_net_instance_init
,
1398 .class_init
= virtio_ccw_net_class_init
,
1401 static Property virtio_ccw_blk_properties
[] = {
1402 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1403 DEFINE_VIRTIO_BLK_FEATURES(VirtioCcwDevice
, host_features
[0]),
1404 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1405 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1406 DEFINE_PROP_END_OF_LIST(),
1409 static void virtio_ccw_blk_class_init(ObjectClass
*klass
, void *data
)
1411 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1412 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1414 k
->init
= virtio_ccw_blk_init
;
1415 k
->exit
= virtio_ccw_exit
;
1416 dc
->reset
= virtio_ccw_reset
;
1417 dc
->props
= virtio_ccw_blk_properties
;
1420 static const TypeInfo virtio_ccw_blk
= {
1421 .name
= TYPE_VIRTIO_BLK_CCW
,
1422 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1423 .instance_size
= sizeof(VirtIOBlkCcw
),
1424 .instance_init
= virtio_ccw_blk_instance_init
,
1425 .class_init
= virtio_ccw_blk_class_init
,
1428 static Property virtio_ccw_serial_properties
[] = {
1429 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1430 DEFINE_VIRTIO_SERIAL_PROPERTIES(VirtioSerialCcw
, vdev
.serial
),
1431 DEFINE_VIRTIO_COMMON_FEATURES(VirtioCcwDevice
, host_features
[0]),
1432 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1433 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1434 DEFINE_PROP_END_OF_LIST(),
1437 static void virtio_ccw_serial_class_init(ObjectClass
*klass
, void *data
)
1439 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1440 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1442 k
->init
= virtio_ccw_serial_init
;
1443 k
->exit
= virtio_ccw_exit
;
1444 dc
->reset
= virtio_ccw_reset
;
1445 dc
->props
= virtio_ccw_serial_properties
;
1448 static const TypeInfo virtio_ccw_serial
= {
1449 .name
= TYPE_VIRTIO_SERIAL_CCW
,
1450 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1451 .instance_size
= sizeof(VirtioSerialCcw
),
1452 .instance_init
= virtio_ccw_serial_instance_init
,
1453 .class_init
= virtio_ccw_serial_class_init
,
1456 static Property virtio_ccw_balloon_properties
[] = {
1457 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1458 DEFINE_VIRTIO_COMMON_FEATURES(VirtioCcwDevice
, host_features
[0]),
1459 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1460 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1461 DEFINE_PROP_END_OF_LIST(),
1464 static void virtio_ccw_balloon_class_init(ObjectClass
*klass
, void *data
)
1466 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1467 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1469 k
->init
= virtio_ccw_balloon_init
;
1470 k
->exit
= virtio_ccw_exit
;
1471 dc
->reset
= virtio_ccw_reset
;
1472 dc
->props
= virtio_ccw_balloon_properties
;
1475 static const TypeInfo virtio_ccw_balloon
= {
1476 .name
= TYPE_VIRTIO_BALLOON_CCW
,
1477 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1478 .instance_size
= sizeof(VirtIOBalloonCcw
),
1479 .instance_init
= virtio_ccw_balloon_instance_init
,
1480 .class_init
= virtio_ccw_balloon_class_init
,
1483 static Property virtio_ccw_scsi_properties
[] = {
1484 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1485 DEFINE_VIRTIO_SCSI_PROPERTIES(VirtIOSCSICcw
, vdev
.parent_obj
.conf
),
1486 DEFINE_VIRTIO_SCSI_FEATURES(VirtioCcwDevice
, host_features
[0]),
1487 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1488 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1489 DEFINE_PROP_END_OF_LIST(),
1492 static void virtio_ccw_scsi_class_init(ObjectClass
*klass
, void *data
)
1494 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1495 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1497 k
->init
= virtio_ccw_scsi_init
;
1498 k
->exit
= virtio_ccw_exit
;
1499 dc
->reset
= virtio_ccw_reset
;
1500 dc
->props
= virtio_ccw_scsi_properties
;
1503 static const TypeInfo virtio_ccw_scsi
= {
1504 .name
= TYPE_VIRTIO_SCSI_CCW
,
1505 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1506 .instance_size
= sizeof(VirtIOSCSICcw
),
1507 .instance_init
= virtio_ccw_scsi_instance_init
,
1508 .class_init
= virtio_ccw_scsi_class_init
,
1511 #ifdef CONFIG_VHOST_SCSI
1512 static Property vhost_ccw_scsi_properties
[] = {
1513 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1514 DEFINE_VHOST_SCSI_PROPERTIES(VirtIOSCSICcw
, vdev
.parent_obj
.conf
),
1515 DEFINE_VIRTIO_COMMON_FEATURES(VirtioCcwDevice
, host_features
[0]),
1516 DEFINE_PROP_END_OF_LIST(),
1519 static void vhost_ccw_scsi_class_init(ObjectClass
*klass
, void *data
)
1521 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1522 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1524 k
->init
= vhost_ccw_scsi_init
;
1525 k
->exit
= virtio_ccw_exit
;
1526 dc
->reset
= virtio_ccw_reset
;
1527 dc
->props
= vhost_ccw_scsi_properties
;
1530 static const TypeInfo vhost_ccw_scsi
= {
1531 .name
= TYPE_VHOST_SCSI_CCW
,
1532 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1533 .instance_size
= sizeof(VirtIOSCSICcw
),
1534 .instance_init
= vhost_ccw_scsi_instance_init
,
1535 .class_init
= vhost_ccw_scsi_class_init
,
1539 static void virtio_ccw_rng_instance_init(Object
*obj
)
1541 VirtIORNGCcw
*dev
= VIRTIO_RNG_CCW(obj
);
1542 object_initialize(&dev
->vdev
, sizeof(dev
->vdev
), TYPE_VIRTIO_RNG
);
1543 object_property_add_child(obj
, "virtio-backend", OBJECT(&dev
->vdev
), NULL
);
1544 object_property_add_link(obj
, "rng", TYPE_RNG_BACKEND
,
1545 (Object
**)&dev
->vdev
.conf
.rng
,
1546 qdev_prop_allow_set_link_before_realize
,
1547 OBJ_PROP_LINK_UNREF_ON_RELEASE
, NULL
);
1550 static Property virtio_ccw_rng_properties
[] = {
1551 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1552 DEFINE_VIRTIO_COMMON_FEATURES(VirtioCcwDevice
, host_features
[0]),
1553 DEFINE_VIRTIO_RNG_PROPERTIES(VirtIORNGCcw
, vdev
.conf
),
1554 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1555 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1556 DEFINE_PROP_END_OF_LIST(),
1559 static void virtio_ccw_rng_class_init(ObjectClass
*klass
, void *data
)
1561 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1562 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1564 k
->init
= virtio_ccw_rng_init
;
1565 k
->exit
= virtio_ccw_exit
;
1566 dc
->reset
= virtio_ccw_reset
;
1567 dc
->props
= virtio_ccw_rng_properties
;
1570 static const TypeInfo virtio_ccw_rng
= {
1571 .name
= TYPE_VIRTIO_RNG_CCW
,
1572 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1573 .instance_size
= sizeof(VirtIORNGCcw
),
1574 .instance_init
= virtio_ccw_rng_instance_init
,
1575 .class_init
= virtio_ccw_rng_class_init
,
1578 static int virtio_ccw_busdev_init(DeviceState
*dev
)
1580 VirtioCcwDevice
*_dev
= (VirtioCcwDevice
*)dev
;
1581 VirtIOCCWDeviceClass
*_info
= VIRTIO_CCW_DEVICE_GET_CLASS(dev
);
1583 virtio_ccw_bus_new(&_dev
->bus
, sizeof(_dev
->bus
), _dev
);
1585 return _info
->init(_dev
);
1588 static int virtio_ccw_busdev_exit(DeviceState
*dev
)
1590 VirtioCcwDevice
*_dev
= (VirtioCcwDevice
*)dev
;
1591 VirtIOCCWDeviceClass
*_info
= VIRTIO_CCW_DEVICE_GET_CLASS(dev
);
1593 return _info
->exit(_dev
);
1596 static int virtio_ccw_busdev_unplug(DeviceState
*dev
)
1598 VirtioCcwDevice
*_dev
= (VirtioCcwDevice
*)dev
;
1599 SubchDev
*sch
= _dev
->sch
;
1601 virtio_ccw_stop_ioeventfd(_dev
);
1604 * We should arrive here only for device_del, since we don't support
1605 * direct hot(un)plug of channels, but only through virtio.
1607 assert(sch
!= NULL
);
1608 /* Subchannel is now disabled and no longer valid. */
1609 sch
->curr_status
.pmcw
.flags
&= ~(PMCW_FLAGS_MASK_ENA
|
1610 PMCW_FLAGS_MASK_DNV
);
1612 css_generate_sch_crws(sch
->cssid
, sch
->ssid
, sch
->schid
, 1, 0);
1614 object_unparent(OBJECT(dev
));
1618 static void virtio_ccw_device_class_init(ObjectClass
*klass
, void *data
)
1620 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1622 dc
->init
= virtio_ccw_busdev_init
;
1623 dc
->exit
= virtio_ccw_busdev_exit
;
1624 dc
->unplug
= virtio_ccw_busdev_unplug
;
1625 dc
->bus_type
= TYPE_VIRTUAL_CSS_BUS
;
1629 static const TypeInfo virtio_ccw_device_info
= {
1630 .name
= TYPE_VIRTIO_CCW_DEVICE
,
1631 .parent
= TYPE_DEVICE
,
1632 .instance_size
= sizeof(VirtioCcwDevice
),
1633 .class_init
= virtio_ccw_device_class_init
,
1634 .class_size
= sizeof(VirtIOCCWDeviceClass
),
1638 /***************** Virtual-css Bus Bridge Device ********************/
1639 /* Only required to have the virtio bus as child in the system bus */
1641 static int virtual_css_bridge_init(SysBusDevice
*dev
)
1647 static void virtual_css_bridge_class_init(ObjectClass
*klass
, void *data
)
1649 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
1651 k
->init
= virtual_css_bridge_init
;
1654 static const TypeInfo virtual_css_bridge_info
= {
1655 .name
= "virtual-css-bridge",
1656 .parent
= TYPE_SYS_BUS_DEVICE
,
1657 .instance_size
= sizeof(SysBusDevice
),
1658 .class_init
= virtual_css_bridge_class_init
,
1661 /* virtio-ccw-bus */
1663 static void virtio_ccw_bus_new(VirtioBusState
*bus
, size_t bus_size
,
1664 VirtioCcwDevice
*dev
)
1666 DeviceState
*qdev
= DEVICE(dev
);
1668 char virtio_bus_name
[] = "virtio-bus";
1670 qbus_create_inplace(bus
, bus_size
, TYPE_VIRTIO_CCW_BUS
,
1671 qdev
, virtio_bus_name
);
1673 qbus
->allow_hotplug
= 1;
1676 static void virtio_ccw_bus_class_init(ObjectClass
*klass
, void *data
)
1678 VirtioBusClass
*k
= VIRTIO_BUS_CLASS(klass
);
1679 BusClass
*bus_class
= BUS_CLASS(klass
);
1681 bus_class
->max_dev
= 1;
1682 k
->notify
= virtio_ccw_notify
;
1683 k
->get_features
= virtio_ccw_get_features
;
1684 k
->vmstate_change
= virtio_ccw_vmstate_change
;
1685 k
->query_guest_notifiers
= virtio_ccw_query_guest_notifiers
;
1686 k
->set_host_notifier
= virtio_ccw_set_host_notifier
;
1687 k
->set_guest_notifiers
= virtio_ccw_set_guest_notifiers
;
1688 k
->save_queue
= virtio_ccw_save_queue
;
1689 k
->load_queue
= virtio_ccw_load_queue
;
1690 k
->save_config
= virtio_ccw_save_config
;
1691 k
->load_config
= virtio_ccw_load_config
;
1694 static const TypeInfo virtio_ccw_bus_info
= {
1695 .name
= TYPE_VIRTIO_CCW_BUS
,
1696 .parent
= TYPE_VIRTIO_BUS
,
1697 .instance_size
= sizeof(VirtioCcwBusState
),
1698 .class_init
= virtio_ccw_bus_class_init
,
1701 static void virtio_ccw_register(void)
1703 type_register_static(&virtio_ccw_bus_info
);
1704 type_register_static(&virtual_css_bus_info
);
1705 type_register_static(&virtio_ccw_device_info
);
1706 type_register_static(&virtio_ccw_serial
);
1707 type_register_static(&virtio_ccw_blk
);
1708 type_register_static(&virtio_ccw_net
);
1709 type_register_static(&virtio_ccw_balloon
);
1710 type_register_static(&virtio_ccw_scsi
);
1711 #ifdef CONFIG_VHOST_SCSI
1712 type_register_static(&vhost_ccw_scsi
);
1714 type_register_static(&virtio_ccw_rng
);
1715 type_register_static(&virtual_css_bridge_info
);
1718 type_init(virtio_ccw_register
)