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
= 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_set_features(vdev
, features
.features
);
406 * If the guest supports more feature bits, assert that it
407 * passes us zeroes for those we don't support.
409 if (features
.features
) {
410 fprintf(stderr
, "Guest bug: features[%i]=%x (expected 0)\n",
411 features
.index
, features
.features
);
412 /* XXX: do a unit check here? */
415 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(features
);
419 case CCW_CMD_READ_CONF
:
421 if (ccw
.count
> vdev
->config_len
) {
426 len
= MIN(ccw
.count
, vdev
->config_len
);
430 virtio_bus_get_vdev_config(&dev
->bus
, vdev
->config
);
431 /* XXX config space endianness */
432 cpu_physical_memory_write(ccw
.cda
, vdev
->config
, len
);
433 sch
->curr_status
.scsw
.count
= ccw
.count
- len
;
437 case CCW_CMD_WRITE_CONF
:
439 if (ccw
.count
> vdev
->config_len
) {
444 len
= MIN(ccw
.count
, vdev
->config_len
);
449 config
= cpu_physical_memory_map(ccw
.cda
, &hw_len
, 0);
454 /* XXX config space endianness */
455 memcpy(vdev
->config
, config
, len
);
456 cpu_physical_memory_unmap(config
, hw_len
, 0, hw_len
);
457 virtio_bus_set_vdev_config(&dev
->bus
, vdev
->config
);
458 sch
->curr_status
.scsw
.count
= ccw
.count
- len
;
463 case CCW_CMD_WRITE_STATUS
:
465 if (ccw
.count
!= sizeof(status
)) {
469 } else if (ccw
.count
< sizeof(status
)) {
470 /* Can't execute command. */
477 status
= ldub_phys(&address_space_memory
, ccw
.cda
);
478 if (!(status
& VIRTIO_CONFIG_S_DRIVER_OK
)) {
479 virtio_ccw_stop_ioeventfd(dev
);
481 virtio_set_status(vdev
, status
);
482 if (vdev
->status
== 0) {
485 if (status
& VIRTIO_CONFIG_S_DRIVER_OK
) {
486 virtio_ccw_start_ioeventfd(dev
);
488 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(status
);
492 case CCW_CMD_SET_IND
:
494 if (ccw
.count
!= sizeof(indicators
)) {
498 } else if (ccw
.count
< sizeof(indicators
)) {
499 /* Can't execute command. */
503 if (sch
->thinint_active
) {
504 /* Trigger a command reject. */
511 indicators
= ldq_be_phys(&address_space_memory
, ccw
.cda
);
512 dev
->indicators
= get_indicator(indicators
, sizeof(uint64_t));
513 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(indicators
);
517 case CCW_CMD_SET_CONF_IND
:
519 if (ccw
.count
!= sizeof(indicators
)) {
523 } else if (ccw
.count
< sizeof(indicators
)) {
524 /* Can't execute command. */
531 indicators
= ldq_be_phys(&address_space_memory
, ccw
.cda
);
532 dev
->indicators2
= get_indicator(indicators
, sizeof(uint64_t));
533 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(indicators
);
537 case CCW_CMD_READ_VQ_CONF
:
539 if (ccw
.count
!= sizeof(vq_config
)) {
543 } else if (ccw
.count
< sizeof(vq_config
)) {
544 /* Can't execute command. */
551 vq_config
.index
= lduw_be_phys(&address_space_memory
, ccw
.cda
);
552 vq_config
.num_max
= virtio_queue_get_num(vdev
,
554 stw_be_phys(&address_space_memory
,
555 ccw
.cda
+ sizeof(vq_config
.index
), vq_config
.num_max
);
556 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(vq_config
);
560 case CCW_CMD_SET_IND_ADAPTER
:
562 if (ccw
.count
!= sizeof(*thinint
)) {
566 } else if (ccw
.count
< sizeof(*thinint
)) {
567 /* Can't execute command. */
571 len
= sizeof(*thinint
);
575 } else if (dev
->indicators
&& !sch
->thinint_active
) {
576 /* Trigger a command reject. */
579 thinint
= cpu_physical_memory_map(ccw
.cda
, &hw_len
, 0);
583 uint64_t ind_bit
= ldq_be_p(&thinint
->ind_bit
);
586 dev
->summary_indicator
=
587 get_indicator(ldq_be_p(&thinint
->summary_indicator
),
590 get_indicator(ldq_be_p(&thinint
->device_indicator
),
592 dev
->thinint_isc
= thinint
->isc
;
593 dev
->routes
.adapter
.ind_offset
= ind_bit
;
594 dev
->routes
.adapter
.summary_offset
= 7;
595 cpu_physical_memory_unmap(thinint
, hw_len
, 0, hw_len
);
596 ret
= css_register_io_adapter(CSS_IO_ADAPTER_VIRTIO
,
597 dev
->thinint_isc
, true, false,
598 &dev
->routes
.adapter
.adapter_id
);
600 sch
->thinint_active
= ((dev
->indicators
!= NULL
) &&
601 (dev
->summary_indicator
!= NULL
));
602 sch
->curr_status
.scsw
.count
= ccw
.count
- len
;
614 static void virtio_ccw_device_realize(VirtioCcwDevice
*dev
,
615 VirtIODevice
*vdev
, Error
**errp
)
617 unsigned int cssid
= 0;
618 unsigned int ssid
= 0;
621 bool have_devno
= false;
625 DeviceState
*parent
= DEVICE(dev
);
627 sch
= g_malloc0(sizeof(SubchDev
));
629 sch
->driver_data
= dev
;
632 dev
->indicators
= NULL
;
634 /* Initialize subchannel structure. */
635 sch
->channel_prog
= 0x0;
636 sch
->last_cmd_valid
= false;
637 sch
->thinint_active
= false;
639 * Use a device number if provided. Otherwise, fall back to subchannel
643 num
= sscanf(dev
->bus_id
, "%x.%x.%04x", &cssid
, &ssid
, &devno
);
645 if ((cssid
> MAX_CSSID
) || (ssid
> MAX_SSID
)) {
646 error_setg(errp
, "Invalid cssid or ssid: cssid %x, ssid %x",
650 /* Enforce use of virtual cssid. */
651 if (cssid
!= VIRTUAL_CSSID
) {
652 error_setg(errp
, "cssid %x not valid for virtio devices",
656 if (css_devno_used(cssid
, ssid
, devno
)) {
657 error_setg(errp
, "Device %x.%x.%04x already exists",
666 error_setg(errp
, "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
);
682 error_setg(errp
, "No free subchannel found for %x.%x.%04x",
686 trace_virtio_ccw_new_device(cssid
, ssid
, schid
, devno
,
689 cssid
= VIRTUAL_CSSID
;
690 for (ssid
= 0; ssid
<= MAX_SSID
; ssid
++) {
691 for (schid
= 0; schid
<= MAX_SCHID
; schid
++) {
692 if (!css_find_subch(1, cssid
, ssid
, schid
)) {
698 * If the devno is already taken, look further in this
701 while (css_devno_used(cssid
, ssid
, devno
)) {
702 if (devno
== MAX_SCHID
) {
704 } else if (devno
== schid
- 1) {
705 error_setg(errp
, "No free devno found");
712 css_subch_assign(cssid
, ssid
, schid
, devno
, sch
);
722 error_setg(errp
, "Virtual channel subsystem is full!");
725 trace_virtio_ccw_new_device(cssid
, ssid
, schid
, devno
,
729 /* Build initial schib. */
730 css_sch_build_virtual_schib(sch
, 0, VIRTIO_CCW_CHPID_TYPE
);
732 sch
->ccw_cb
= virtio_ccw_cb
;
734 /* Build senseid data. */
735 memset(&sch
->id
, 0, sizeof(SenseId
));
736 sch
->id
.reserved
= 0xff;
737 sch
->id
.cu_type
= VIRTIO_CCW_CU_TYPE
;
738 sch
->id
.cu_model
= vdev
->device_id
;
740 /* Only the first 32 feature bits are used. */
741 dev
->host_features
[0] = virtio_bus_get_vdev_features(&dev
->bus
,
742 dev
->host_features
[0]);
744 virtio_add_feature(&dev
->host_features
[0], VIRTIO_F_NOTIFY_ON_EMPTY
);
745 virtio_add_feature(&dev
->host_features
[0], VIRTIO_F_BAD_FEATURE
);
747 css_generate_sch_crws(sch
->cssid
, sch
->ssid
, sch
->schid
,
748 parent
->hotplugged
, 1);
756 static int virtio_ccw_exit(VirtioCcwDevice
*dev
)
758 SubchDev
*sch
= dev
->sch
;
761 css_subch_assign(sch
->cssid
, sch
->ssid
, sch
->schid
, sch
->devno
, NULL
);
764 if (dev
->indicators
) {
765 release_indicator(&dev
->routes
.adapter
, dev
->indicators
);
766 dev
->indicators
= NULL
;
771 static void virtio_ccw_net_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
773 DeviceState
*qdev
= DEVICE(ccw_dev
);
774 VirtIONetCcw
*dev
= VIRTIO_NET_CCW(ccw_dev
);
775 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
778 virtio_net_set_config_size(&dev
->vdev
, ccw_dev
->host_features
[0]);
779 virtio_net_set_netclient_name(&dev
->vdev
, qdev
->id
,
780 object_get_typename(OBJECT(qdev
)));
781 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
782 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
784 error_propagate(errp
, err
);
788 virtio_ccw_device_realize(ccw_dev
, VIRTIO_DEVICE(vdev
), errp
);
791 static void virtio_ccw_net_instance_init(Object
*obj
)
793 VirtIONetCcw
*dev
= VIRTIO_NET_CCW(obj
);
795 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
797 object_property_add_alias(obj
, "bootindex", OBJECT(&dev
->vdev
),
798 "bootindex", &error_abort
);
801 static void virtio_ccw_blk_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
803 VirtIOBlkCcw
*dev
= VIRTIO_BLK_CCW(ccw_dev
);
804 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
807 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
808 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
810 error_propagate(errp
, err
);
814 virtio_ccw_device_realize(ccw_dev
, VIRTIO_DEVICE(vdev
), errp
);
817 static void virtio_ccw_blk_instance_init(Object
*obj
)
819 VirtIOBlkCcw
*dev
= VIRTIO_BLK_CCW(obj
);
821 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
823 object_property_add_alias(obj
, "iothread", OBJECT(&dev
->vdev
),"iothread",
825 object_property_add_alias(obj
, "bootindex", OBJECT(&dev
->vdev
),
826 "bootindex", &error_abort
);
829 static void virtio_ccw_serial_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
831 VirtioSerialCcw
*dev
= VIRTIO_SERIAL_CCW(ccw_dev
);
832 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
833 DeviceState
*proxy
= DEVICE(ccw_dev
);
838 * For command line compatibility, this sets the virtio-serial-device bus
842 bus_name
= g_strdup_printf("%s.0", proxy
->id
);
843 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev
), bus_name
);
847 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
848 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
850 error_propagate(errp
, err
);
854 virtio_ccw_device_realize(ccw_dev
, VIRTIO_DEVICE(vdev
), errp
);
858 static void virtio_ccw_serial_instance_init(Object
*obj
)
860 VirtioSerialCcw
*dev
= VIRTIO_SERIAL_CCW(obj
);
862 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
866 static void virtio_ccw_balloon_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
868 VirtIOBalloonCcw
*dev
= VIRTIO_BALLOON_CCW(ccw_dev
);
869 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
872 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
873 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
875 error_propagate(errp
, err
);
879 virtio_ccw_device_realize(ccw_dev
, VIRTIO_DEVICE(vdev
), errp
);
882 static void balloon_ccw_stats_get_all(Object
*obj
, struct Visitor
*v
,
883 void *opaque
, const char *name
,
886 VirtIOBalloonCcw
*dev
= opaque
;
887 object_property_get(OBJECT(&dev
->vdev
), v
, "guest-stats", errp
);
890 static void balloon_ccw_stats_get_poll_interval(Object
*obj
, struct Visitor
*v
,
891 void *opaque
, const char *name
,
894 VirtIOBalloonCcw
*dev
= opaque
;
895 object_property_get(OBJECT(&dev
->vdev
), v
, "guest-stats-polling-interval",
899 static void balloon_ccw_stats_set_poll_interval(Object
*obj
, struct Visitor
*v
,
900 void *opaque
, const char *name
,
903 VirtIOBalloonCcw
*dev
= opaque
;
904 object_property_set(OBJECT(&dev
->vdev
), v
, "guest-stats-polling-interval",
908 static void virtio_ccw_balloon_instance_init(Object
*obj
)
910 VirtIOBalloonCcw
*dev
= VIRTIO_BALLOON_CCW(obj
);
911 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
912 TYPE_VIRTIO_BALLOON
);
913 object_property_add(obj
, "guest-stats", "guest statistics",
914 balloon_ccw_stats_get_all
, NULL
, NULL
, dev
, NULL
);
916 object_property_add(obj
, "guest-stats-polling-interval", "int",
917 balloon_ccw_stats_get_poll_interval
,
918 balloon_ccw_stats_set_poll_interval
,
922 static void virtio_ccw_scsi_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
924 VirtIOSCSICcw
*dev
= VIRTIO_SCSI_CCW(ccw_dev
);
925 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
926 DeviceState
*qdev
= DEVICE(ccw_dev
);
931 * For command line compatibility, this sets the virtio-scsi-device bus
935 bus_name
= g_strdup_printf("%s.0", qdev
->id
);
936 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev
), bus_name
);
940 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
941 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
943 error_propagate(errp
, err
);
947 virtio_ccw_device_realize(ccw_dev
, VIRTIO_DEVICE(vdev
), errp
);
950 static void virtio_ccw_scsi_instance_init(Object
*obj
)
952 VirtIOSCSICcw
*dev
= VIRTIO_SCSI_CCW(obj
);
954 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
956 object_property_add_alias(obj
, "iothread", OBJECT(&dev
->vdev
), "iothread",
960 #ifdef CONFIG_VHOST_SCSI
961 static void vhost_ccw_scsi_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
963 VHostSCSICcw
*dev
= VHOST_SCSI_CCW(ccw_dev
);
964 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
967 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
968 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
970 error_propagate(errp
, err
);
974 virtio_ccw_device_realize(ccw_dev
, VIRTIO_DEVICE(vdev
), errp
);
977 static void vhost_ccw_scsi_instance_init(Object
*obj
)
979 VHostSCSICcw
*dev
= VHOST_SCSI_CCW(obj
);
981 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
986 static void virtio_ccw_rng_realize(VirtioCcwDevice
*ccw_dev
, Error
**errp
)
988 VirtIORNGCcw
*dev
= VIRTIO_RNG_CCW(ccw_dev
);
989 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
992 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
993 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
995 error_propagate(errp
, err
);
999 object_property_set_link(OBJECT(dev
),
1000 OBJECT(dev
->vdev
.conf
.rng
), "rng",
1003 virtio_ccw_device_realize(ccw_dev
, VIRTIO_DEVICE(vdev
), errp
);
1006 /* DeviceState to VirtioCcwDevice. Note: used on datapath,
1007 * be careful and test performance if you change this.
1009 static inline VirtioCcwDevice
*to_virtio_ccw_dev_fast(DeviceState
*d
)
1011 return container_of(d
, VirtioCcwDevice
, parent_obj
);
1014 static uint8_t virtio_set_ind_atomic(SubchDev
*sch
, uint64_t ind_loc
,
1017 uint8_t ind_old
, ind_new
;
1021 ind_addr
= cpu_physical_memory_map(ind_loc
, &len
, 1);
1023 error_report("%s(%x.%x.%04x): unable to access indicator",
1024 __func__
, sch
->cssid
, sch
->ssid
, sch
->schid
);
1028 ind_old
= *ind_addr
;
1029 ind_new
= ind_old
| to_be_set
;
1030 } while (atomic_cmpxchg(ind_addr
, ind_old
, ind_new
) != ind_old
);
1031 cpu_physical_memory_unmap(ind_addr
, len
, 1, len
);
1036 static void virtio_ccw_notify(DeviceState
*d
, uint16_t vector
)
1038 VirtioCcwDevice
*dev
= to_virtio_ccw_dev_fast(d
);
1039 SubchDev
*sch
= dev
->sch
;
1040 uint64_t indicators
;
1042 if (vector
>= 128) {
1046 if (vector
< VIRTIO_PCI_QUEUE_MAX
) {
1047 if (!dev
->indicators
) {
1050 if (sch
->thinint_active
) {
1052 * In the adapter interrupt case, indicators points to a
1053 * memory area that may be (way) larger than 64 bit and
1054 * ind_bit indicates the start of the indicators in a big
1057 uint64_t ind_bit
= dev
->routes
.adapter
.ind_offset
;
1059 virtio_set_ind_atomic(sch
, dev
->indicators
->addr
+
1060 (ind_bit
+ vector
) / 8,
1061 0x80 >> ((ind_bit
+ vector
) % 8));
1062 if (!virtio_set_ind_atomic(sch
, dev
->summary_indicator
->addr
,
1064 css_adapter_interrupt(dev
->thinint_isc
);
1067 indicators
= ldq_phys(&address_space_memory
, dev
->indicators
->addr
);
1068 indicators
|= 1ULL << vector
;
1069 stq_phys(&address_space_memory
, dev
->indicators
->addr
, indicators
);
1070 css_conditional_io_interrupt(sch
);
1073 if (!dev
->indicators2
) {
1077 indicators
= ldq_phys(&address_space_memory
, dev
->indicators2
->addr
);
1078 indicators
|= 1ULL << vector
;
1079 stq_phys(&address_space_memory
, dev
->indicators2
->addr
, indicators
);
1080 css_conditional_io_interrupt(sch
);
1084 static unsigned virtio_ccw_get_features(DeviceState
*d
)
1086 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1088 /* Only the first 32 feature bits are used. */
1089 return dev
->host_features
[0];
1092 static void virtio_ccw_reset(DeviceState
*d
)
1094 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1095 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1097 virtio_ccw_stop_ioeventfd(dev
);
1099 css_reset_sch(dev
->sch
);
1100 if (dev
->indicators
) {
1101 release_indicator(&dev
->routes
.adapter
, dev
->indicators
);
1102 dev
->indicators
= NULL
;
1104 if (dev
->indicators2
) {
1105 release_indicator(&dev
->routes
.adapter
, dev
->indicators2
);
1106 dev
->indicators2
= NULL
;
1108 if (dev
->summary_indicator
) {
1109 release_indicator(&dev
->routes
.adapter
, dev
->summary_indicator
);
1110 dev
->summary_indicator
= NULL
;
1114 static void virtio_ccw_vmstate_change(DeviceState
*d
, bool running
)
1116 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1119 virtio_ccw_start_ioeventfd(dev
);
1121 virtio_ccw_stop_ioeventfd(dev
);
1125 static bool virtio_ccw_query_guest_notifiers(DeviceState
*d
)
1127 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1129 return !!(dev
->sch
->curr_status
.pmcw
.flags
& PMCW_FLAGS_MASK_ENA
);
1132 static int virtio_ccw_set_host_notifier(DeviceState
*d
, int n
, bool assign
)
1134 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1136 /* Stop using the generic ioeventfd, we are doing eventfd handling
1137 * ourselves below */
1138 dev
->ioeventfd_disabled
= assign
;
1140 virtio_ccw_stop_ioeventfd(dev
);
1142 return virtio_ccw_set_guest2host_notifier(dev
, n
, assign
, false);
1145 static int virtio_ccw_get_mappings(VirtioCcwDevice
*dev
)
1149 if (!dev
->sch
->thinint_active
) {
1153 r
= map_indicator(&dev
->routes
.adapter
, dev
->summary_indicator
);
1157 r
= map_indicator(&dev
->routes
.adapter
, dev
->indicators
);
1161 dev
->routes
.adapter
.summary_addr
= dev
->summary_indicator
->map
;
1162 dev
->routes
.adapter
.ind_addr
= dev
->indicators
->map
;
1167 static int virtio_ccw_setup_irqroutes(VirtioCcwDevice
*dev
, int nvqs
)
1170 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1172 S390FLICState
*fs
= s390_get_flic();
1173 S390FLICStateClass
*fsc
= S390_FLIC_COMMON_GET_CLASS(fs
);
1175 ret
= virtio_ccw_get_mappings(dev
);
1179 for (i
= 0; i
< nvqs
; i
++) {
1180 if (!virtio_queue_get_num(vdev
, i
)) {
1184 dev
->routes
.num_routes
= i
;
1185 return fsc
->add_adapter_routes(fs
, &dev
->routes
);
1188 static void virtio_ccw_release_irqroutes(VirtioCcwDevice
*dev
, int nvqs
)
1190 S390FLICState
*fs
= s390_get_flic();
1191 S390FLICStateClass
*fsc
= S390_FLIC_COMMON_GET_CLASS(fs
);
1193 fsc
->release_adapter_routes(fs
, &dev
->routes
);
1196 static int virtio_ccw_add_irqfd(VirtioCcwDevice
*dev
, int n
)
1198 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1199 VirtQueue
*vq
= virtio_get_queue(vdev
, n
);
1200 EventNotifier
*notifier
= virtio_queue_get_guest_notifier(vq
);
1202 return kvm_irqchip_add_irqfd_notifier(kvm_state
, notifier
, NULL
,
1203 dev
->routes
.gsi
[n
]);
1206 static void virtio_ccw_remove_irqfd(VirtioCcwDevice
*dev
, int n
)
1208 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1209 VirtQueue
*vq
= virtio_get_queue(vdev
, n
);
1210 EventNotifier
*notifier
= virtio_queue_get_guest_notifier(vq
);
1213 ret
= kvm_irqchip_remove_irqfd_notifier(kvm_state
, notifier
,
1214 dev
->routes
.gsi
[n
]);
1218 static int virtio_ccw_set_guest_notifier(VirtioCcwDevice
*dev
, int n
,
1219 bool assign
, bool with_irqfd
)
1221 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1222 VirtQueue
*vq
= virtio_get_queue(vdev
, n
);
1223 EventNotifier
*notifier
= virtio_queue_get_guest_notifier(vq
);
1224 VirtioDeviceClass
*k
= VIRTIO_DEVICE_GET_CLASS(vdev
);
1227 int r
= event_notifier_init(notifier
, 0);
1232 virtio_queue_set_guest_notifier_fd_handler(vq
, true, with_irqfd
);
1234 r
= virtio_ccw_add_irqfd(dev
, n
);
1236 virtio_queue_set_guest_notifier_fd_handler(vq
, false,
1242 * We do not support individual masking for channel devices, so we
1243 * need to manually trigger any guest masking callbacks here.
1245 if (k
->guest_notifier_mask
) {
1246 k
->guest_notifier_mask(vdev
, n
, false);
1248 /* get lost events and re-inject */
1249 if (k
->guest_notifier_pending
&&
1250 k
->guest_notifier_pending(vdev
, n
)) {
1251 event_notifier_set(notifier
);
1254 if (k
->guest_notifier_mask
) {
1255 k
->guest_notifier_mask(vdev
, n
, true);
1258 virtio_ccw_remove_irqfd(dev
, n
);
1260 virtio_queue_set_guest_notifier_fd_handler(vq
, false, with_irqfd
);
1261 event_notifier_cleanup(notifier
);
1266 static int virtio_ccw_set_guest_notifiers(DeviceState
*d
, int nvqs
,
1269 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1270 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1271 bool with_irqfd
= dev
->sch
->thinint_active
&& kvm_irqfds_enabled();
1274 if (with_irqfd
&& assigned
) {
1275 /* irq routes need to be set up before assigning irqfds */
1276 r
= virtio_ccw_setup_irqroutes(dev
, nvqs
);
1278 goto irqroute_error
;
1281 for (n
= 0; n
< nvqs
; n
++) {
1282 if (!virtio_queue_get_num(vdev
, n
)) {
1285 r
= virtio_ccw_set_guest_notifier(dev
, n
, assigned
, with_irqfd
);
1290 if (with_irqfd
&& !assigned
) {
1291 /* release irq routes after irqfds have been released */
1292 virtio_ccw_release_irqroutes(dev
, nvqs
);
1298 virtio_ccw_set_guest_notifier(dev
, n
, !assigned
, false);
1301 if (with_irqfd
&& assigned
) {
1302 virtio_ccw_release_irqroutes(dev
, nvqs
);
1307 static void virtio_ccw_save_queue(DeviceState
*d
, int n
, QEMUFile
*f
)
1309 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1310 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1312 qemu_put_be16(f
, virtio_queue_vector(vdev
, n
));
1315 static int virtio_ccw_load_queue(DeviceState
*d
, int n
, QEMUFile
*f
)
1317 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1318 VirtIODevice
*vdev
= virtio_bus_get_device(&dev
->bus
);
1321 qemu_get_be16s(f
, &vector
);
1322 virtio_queue_set_vector(vdev
, n
, vector
);
1327 static void virtio_ccw_save_config(DeviceState
*d
, QEMUFile
*f
)
1329 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1330 SubchDev
*s
= dev
->sch
;
1332 subch_device_save(s
, f
);
1333 if (dev
->indicators
!= NULL
) {
1334 qemu_put_be32(f
, dev
->indicators
->len
);
1335 qemu_put_be64(f
, dev
->indicators
->addr
);
1337 qemu_put_be32(f
, 0);
1338 qemu_put_be64(f
, 0UL);
1340 if (dev
->indicators2
!= NULL
) {
1341 qemu_put_be32(f
, dev
->indicators2
->len
);
1342 qemu_put_be64(f
, dev
->indicators2
->addr
);
1344 qemu_put_be32(f
, 0);
1345 qemu_put_be64(f
, 0UL);
1347 if (dev
->summary_indicator
!= NULL
) {
1348 qemu_put_be32(f
, dev
->summary_indicator
->len
);
1349 qemu_put_be64(f
, dev
->summary_indicator
->addr
);
1351 qemu_put_be32(f
, 0);
1352 qemu_put_be64(f
, 0UL);
1354 qemu_put_be64(f
, dev
->routes
.adapter
.ind_offset
);
1355 qemu_put_byte(f
, dev
->thinint_isc
);
1358 static int virtio_ccw_load_config(DeviceState
*d
, QEMUFile
*f
)
1360 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
1361 SubchDev
*s
= dev
->sch
;
1364 s
->driver_data
= dev
;
1365 subch_device_load(s
, f
);
1366 len
= qemu_get_be32(f
);
1368 dev
->indicators
= get_indicator(qemu_get_be64(f
), len
);
1371 dev
->indicators
= NULL
;
1373 len
= qemu_get_be32(f
);
1375 dev
->indicators2
= get_indicator(qemu_get_be64(f
), len
);
1378 dev
->indicators2
= NULL
;
1380 len
= qemu_get_be32(f
);
1382 dev
->summary_indicator
= get_indicator(qemu_get_be64(f
), len
);
1385 dev
->summary_indicator
= NULL
;
1387 dev
->routes
.adapter
.ind_offset
= qemu_get_be64(f
);
1388 dev
->thinint_isc
= qemu_get_byte(f
);
1389 if (s
->thinint_active
) {
1390 return css_register_io_adapter(CSS_IO_ADAPTER_VIRTIO
,
1391 dev
->thinint_isc
, true, false,
1392 &dev
->routes
.adapter
.adapter_id
);
1398 /**************** Virtio-ccw Bus Device Descriptions *******************/
1400 static Property virtio_ccw_net_properties
[] = {
1401 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1402 DEFINE_VIRTIO_NET_FEATURES(VirtioCcwDevice
, host_features
[0]),
1403 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1404 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1405 DEFINE_PROP_END_OF_LIST(),
1408 static void virtio_ccw_net_class_init(ObjectClass
*klass
, void *data
)
1410 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1411 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1413 k
->realize
= virtio_ccw_net_realize
;
1414 k
->exit
= virtio_ccw_exit
;
1415 dc
->reset
= virtio_ccw_reset
;
1416 dc
->props
= virtio_ccw_net_properties
;
1419 static const TypeInfo virtio_ccw_net
= {
1420 .name
= TYPE_VIRTIO_NET_CCW
,
1421 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1422 .instance_size
= sizeof(VirtIONetCcw
),
1423 .instance_init
= virtio_ccw_net_instance_init
,
1424 .class_init
= virtio_ccw_net_class_init
,
1427 static Property virtio_ccw_blk_properties
[] = {
1428 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1429 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1430 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1431 DEFINE_PROP_END_OF_LIST(),
1434 static void virtio_ccw_blk_class_init(ObjectClass
*klass
, void *data
)
1436 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1437 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1439 k
->realize
= virtio_ccw_blk_realize
;
1440 k
->exit
= virtio_ccw_exit
;
1441 dc
->reset
= virtio_ccw_reset
;
1442 dc
->props
= virtio_ccw_blk_properties
;
1445 static const TypeInfo virtio_ccw_blk
= {
1446 .name
= TYPE_VIRTIO_BLK_CCW
,
1447 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1448 .instance_size
= sizeof(VirtIOBlkCcw
),
1449 .instance_init
= virtio_ccw_blk_instance_init
,
1450 .class_init
= virtio_ccw_blk_class_init
,
1453 static Property virtio_ccw_serial_properties
[] = {
1454 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1455 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1456 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1457 DEFINE_PROP_END_OF_LIST(),
1460 static void virtio_ccw_serial_class_init(ObjectClass
*klass
, void *data
)
1462 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1463 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1465 k
->realize
= virtio_ccw_serial_realize
;
1466 k
->exit
= virtio_ccw_exit
;
1467 dc
->reset
= virtio_ccw_reset
;
1468 dc
->props
= virtio_ccw_serial_properties
;
1471 static const TypeInfo virtio_ccw_serial
= {
1472 .name
= TYPE_VIRTIO_SERIAL_CCW
,
1473 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1474 .instance_size
= sizeof(VirtioSerialCcw
),
1475 .instance_init
= virtio_ccw_serial_instance_init
,
1476 .class_init
= virtio_ccw_serial_class_init
,
1479 static Property virtio_ccw_balloon_properties
[] = {
1480 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1481 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1482 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1483 DEFINE_PROP_END_OF_LIST(),
1486 static void virtio_ccw_balloon_class_init(ObjectClass
*klass
, void *data
)
1488 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1489 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1491 k
->realize
= virtio_ccw_balloon_realize
;
1492 k
->exit
= virtio_ccw_exit
;
1493 dc
->reset
= virtio_ccw_reset
;
1494 dc
->props
= virtio_ccw_balloon_properties
;
1497 static const TypeInfo virtio_ccw_balloon
= {
1498 .name
= TYPE_VIRTIO_BALLOON_CCW
,
1499 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1500 .instance_size
= sizeof(VirtIOBalloonCcw
),
1501 .instance_init
= virtio_ccw_balloon_instance_init
,
1502 .class_init
= virtio_ccw_balloon_class_init
,
1505 static Property virtio_ccw_scsi_properties
[] = {
1506 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1507 DEFINE_VIRTIO_SCSI_FEATURES(VirtioCcwDevice
, host_features
[0]),
1508 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1509 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1510 DEFINE_PROP_END_OF_LIST(),
1513 static void virtio_ccw_scsi_class_init(ObjectClass
*klass
, void *data
)
1515 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1516 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1518 k
->realize
= virtio_ccw_scsi_realize
;
1519 k
->exit
= virtio_ccw_exit
;
1520 dc
->reset
= virtio_ccw_reset
;
1521 dc
->props
= virtio_ccw_scsi_properties
;
1524 static const TypeInfo virtio_ccw_scsi
= {
1525 .name
= TYPE_VIRTIO_SCSI_CCW
,
1526 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1527 .instance_size
= sizeof(VirtIOSCSICcw
),
1528 .instance_init
= virtio_ccw_scsi_instance_init
,
1529 .class_init
= virtio_ccw_scsi_class_init
,
1532 #ifdef CONFIG_VHOST_SCSI
1533 static Property vhost_ccw_scsi_properties
[] = {
1534 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1535 DEFINE_PROP_END_OF_LIST(),
1538 static void vhost_ccw_scsi_class_init(ObjectClass
*klass
, void *data
)
1540 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1541 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1543 k
->realize
= vhost_ccw_scsi_realize
;
1544 k
->exit
= virtio_ccw_exit
;
1545 dc
->reset
= virtio_ccw_reset
;
1546 dc
->props
= vhost_ccw_scsi_properties
;
1549 static const TypeInfo vhost_ccw_scsi
= {
1550 .name
= TYPE_VHOST_SCSI_CCW
,
1551 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1552 .instance_size
= sizeof(VHostSCSICcw
),
1553 .instance_init
= vhost_ccw_scsi_instance_init
,
1554 .class_init
= vhost_ccw_scsi_class_init
,
1558 static void virtio_ccw_rng_instance_init(Object
*obj
)
1560 VirtIORNGCcw
*dev
= VIRTIO_RNG_CCW(obj
);
1562 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
1564 object_property_add_alias(obj
, "rng", OBJECT(&dev
->vdev
),
1565 "rng", &error_abort
);
1568 static Property virtio_ccw_rng_properties
[] = {
1569 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
1570 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice
, flags
,
1571 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT
, true),
1572 DEFINE_PROP_END_OF_LIST(),
1575 static void virtio_ccw_rng_class_init(ObjectClass
*klass
, void *data
)
1577 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1578 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
1580 k
->realize
= virtio_ccw_rng_realize
;
1581 k
->exit
= virtio_ccw_exit
;
1582 dc
->reset
= virtio_ccw_reset
;
1583 dc
->props
= virtio_ccw_rng_properties
;
1586 static const TypeInfo virtio_ccw_rng
= {
1587 .name
= TYPE_VIRTIO_RNG_CCW
,
1588 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
1589 .instance_size
= sizeof(VirtIORNGCcw
),
1590 .instance_init
= virtio_ccw_rng_instance_init
,
1591 .class_init
= virtio_ccw_rng_class_init
,
1594 static void virtio_ccw_busdev_realize(DeviceState
*dev
, Error
**errp
)
1596 VirtioCcwDevice
*_dev
= (VirtioCcwDevice
*)dev
;
1597 VirtIOCCWDeviceClass
*_info
= VIRTIO_CCW_DEVICE_GET_CLASS(dev
);
1599 virtio_ccw_bus_new(&_dev
->bus
, sizeof(_dev
->bus
), _dev
);
1600 _info
->realize(_dev
, errp
);
1603 static int virtio_ccw_busdev_exit(DeviceState
*dev
)
1605 VirtioCcwDevice
*_dev
= (VirtioCcwDevice
*)dev
;
1606 VirtIOCCWDeviceClass
*_info
= VIRTIO_CCW_DEVICE_GET_CLASS(dev
);
1608 return _info
->exit(_dev
);
1611 static void virtio_ccw_busdev_unplug(HotplugHandler
*hotplug_dev
,
1612 DeviceState
*dev
, Error
**errp
)
1614 VirtioCcwDevice
*_dev
= (VirtioCcwDevice
*)dev
;
1615 SubchDev
*sch
= _dev
->sch
;
1617 virtio_ccw_stop_ioeventfd(_dev
);
1620 * We should arrive here only for device_del, since we don't support
1621 * direct hot(un)plug of channels, but only through virtio.
1623 assert(sch
!= NULL
);
1624 /* Subchannel is now disabled and no longer valid. */
1625 sch
->curr_status
.pmcw
.flags
&= ~(PMCW_FLAGS_MASK_ENA
|
1626 PMCW_FLAGS_MASK_DNV
);
1628 css_generate_sch_crws(sch
->cssid
, sch
->ssid
, sch
->schid
, 1, 0);
1630 object_unparent(OBJECT(dev
));
1633 static Property virtio_ccw_properties
[] = {
1634 DEFINE_VIRTIO_COMMON_FEATURES(VirtioCcwDevice
, host_features
[0]),
1635 DEFINE_PROP_END_OF_LIST(),
1638 static void virtio_ccw_device_class_init(ObjectClass
*klass
, void *data
)
1640 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1642 dc
->props
= virtio_ccw_properties
;
1643 dc
->realize
= virtio_ccw_busdev_realize
;
1644 dc
->exit
= virtio_ccw_busdev_exit
;
1645 dc
->bus_type
= TYPE_VIRTUAL_CSS_BUS
;
1648 static const TypeInfo virtio_ccw_device_info
= {
1649 .name
= TYPE_VIRTIO_CCW_DEVICE
,
1650 .parent
= TYPE_DEVICE
,
1651 .instance_size
= sizeof(VirtioCcwDevice
),
1652 .class_init
= virtio_ccw_device_class_init
,
1653 .class_size
= sizeof(VirtIOCCWDeviceClass
),
1657 /***************** Virtual-css Bus Bridge Device ********************/
1658 /* Only required to have the virtio bus as child in the system bus */
1660 static int virtual_css_bridge_init(SysBusDevice
*dev
)
1666 static void virtual_css_bridge_class_init(ObjectClass
*klass
, void *data
)
1668 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
1669 HotplugHandlerClass
*hc
= HOTPLUG_HANDLER_CLASS(klass
);
1671 k
->init
= virtual_css_bridge_init
;
1672 hc
->unplug
= virtio_ccw_busdev_unplug
;
1675 static const TypeInfo virtual_css_bridge_info
= {
1676 .name
= "virtual-css-bridge",
1677 .parent
= TYPE_SYS_BUS_DEVICE
,
1678 .instance_size
= sizeof(SysBusDevice
),
1679 .class_init
= virtual_css_bridge_class_init
,
1680 .interfaces
= (InterfaceInfo
[]) {
1681 { TYPE_HOTPLUG_HANDLER
},
1686 /* virtio-ccw-bus */
1688 static void virtio_ccw_bus_new(VirtioBusState
*bus
, size_t bus_size
,
1689 VirtioCcwDevice
*dev
)
1691 DeviceState
*qdev
= DEVICE(dev
);
1692 char virtio_bus_name
[] = "virtio-bus";
1694 qbus_create_inplace(bus
, bus_size
, TYPE_VIRTIO_CCW_BUS
,
1695 qdev
, virtio_bus_name
);
1698 static void virtio_ccw_bus_class_init(ObjectClass
*klass
, void *data
)
1700 VirtioBusClass
*k
= VIRTIO_BUS_CLASS(klass
);
1701 BusClass
*bus_class
= BUS_CLASS(klass
);
1703 bus_class
->max_dev
= 1;
1704 k
->notify
= virtio_ccw_notify
;
1705 k
->get_features
= virtio_ccw_get_features
;
1706 k
->vmstate_change
= virtio_ccw_vmstate_change
;
1707 k
->query_guest_notifiers
= virtio_ccw_query_guest_notifiers
;
1708 k
->set_host_notifier
= virtio_ccw_set_host_notifier
;
1709 k
->set_guest_notifiers
= virtio_ccw_set_guest_notifiers
;
1710 k
->save_queue
= virtio_ccw_save_queue
;
1711 k
->load_queue
= virtio_ccw_load_queue
;
1712 k
->save_config
= virtio_ccw_save_config
;
1713 k
->load_config
= virtio_ccw_load_config
;
1716 static const TypeInfo virtio_ccw_bus_info
= {
1717 .name
= TYPE_VIRTIO_CCW_BUS
,
1718 .parent
= TYPE_VIRTIO_BUS
,
1719 .instance_size
= sizeof(VirtioCcwBusState
),
1720 .class_init
= virtio_ccw_bus_class_init
,
1723 static void virtio_ccw_register(void)
1725 type_register_static(&virtio_ccw_bus_info
);
1726 type_register_static(&virtual_css_bus_info
);
1727 type_register_static(&virtio_ccw_device_info
);
1728 type_register_static(&virtio_ccw_serial
);
1729 type_register_static(&virtio_ccw_blk
);
1730 type_register_static(&virtio_ccw_net
);
1731 type_register_static(&virtio_ccw_balloon
);
1732 type_register_static(&virtio_ccw_scsi
);
1733 #ifdef CONFIG_VHOST_SCSI
1734 type_register_static(&vhost_ccw_scsi
);
1736 type_register_static(&virtio_ccw_rng
);
1737 type_register_static(&virtual_css_bridge_info
);
1740 type_init(virtio_ccw_register
)