2 * virtio ccw target implementation
4 * Copyright 2012 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.h"
19 #include "hw/virtio-serial.h"
20 #include "hw/virtio-net.h"
21 #include "hw/sysbus.h"
22 #include "qemu/bitops.h"
23 #include "hw/virtio-bus.h"
27 #include "virtio-ccw.h"
30 static int virtual_css_bus_reset(BusState
*qbus
)
32 /* This should actually be modelled via the generic css */
35 /* we dont traverse ourself, return 0 */
40 static void virtual_css_bus_class_init(ObjectClass
*klass
, void *data
)
42 BusClass
*k
= BUS_CLASS(klass
);
44 k
->reset
= virtual_css_bus_reset
;
47 static const TypeInfo virtual_css_bus_info
= {
48 .name
= TYPE_VIRTUAL_CSS_BUS
,
50 .instance_size
= sizeof(VirtualCssBus
),
51 .class_init
= virtual_css_bus_class_init
,
54 static const VirtIOBindings virtio_ccw_bindings
;
56 VirtIODevice
*virtio_ccw_get_vdev(SubchDev
*sch
)
58 VirtIODevice
*vdev
= NULL
;
60 if (sch
->driver_data
) {
61 vdev
= ((VirtioCcwDevice
*)sch
->driver_data
)->vdev
;
66 VirtualCssBus
*virtual_css_bus_init(void)
72 /* Create bridge device */
73 dev
= qdev_create(NULL
, "virtual-css-bridge");
74 qdev_init_nofail(dev
);
76 /* Create bus on bridge device */
77 bus
= qbus_create(TYPE_VIRTUAL_CSS_BUS
, dev
, "virtual-css");
78 cbus
= VIRTUAL_CSS_BUS(bus
);
80 /* Enable hotplugging */
81 bus
->allow_hotplug
= 1;
86 /* Communication blocks used by several channel commands. */
87 typedef struct VqInfoBlock
{
92 } QEMU_PACKED VqInfoBlock
;
94 typedef struct VqConfigBlock
{
97 } QEMU_PACKED VqConfigBlock
;
99 typedef struct VirtioFeatDesc
{
102 } QEMU_PACKED VirtioFeatDesc
;
104 /* Specify where the virtqueues for the subchannel are in guest memory. */
105 static int virtio_ccw_set_vqs(SubchDev
*sch
, uint64_t addr
, uint32_t align
,
106 uint16_t index
, uint16_t num
)
108 VirtioCcwDevice
*dev
= sch
->driver_data
;
110 if (index
> VIRTIO_PCI_QUEUE_MAX
) {
114 /* Current code in virtio.c relies on 4K alignment. */
115 if (addr
&& (align
!= 4096)) {
123 virtio_queue_set_addr(dev
->vdev
, index
, addr
);
125 virtio_queue_set_vector(dev
->vdev
, index
, 0);
127 /* Fail if we don't have a big enough queue. */
128 /* TODO: Add interface to handle vring.num changing */
129 if (virtio_queue_get_num(dev
->vdev
, index
) > num
) {
132 virtio_queue_set_vector(dev
->vdev
, index
, index
);
134 /* tell notify handler in case of config change */
135 dev
->vdev
->config_vector
= VIRTIO_PCI_QUEUE_MAX
;
139 static int virtio_ccw_cb(SubchDev
*sch
, CCW1 ccw
)
144 VirtioFeatDesc features
;
147 VqConfigBlock vq_config
;
148 VirtioCcwDevice
*dev
= sch
->driver_data
;
157 trace_virtio_ccw_interpret_ccw(sch
->cssid
, sch
->ssid
, sch
->schid
,
159 check_len
= !((ccw
.flags
& CCW_FLAG_SLI
) && !(ccw
.flags
& CCW_FLAG_DC
));
161 /* Look at the command. */
162 switch (ccw
.cmd_code
) {
165 if (ccw
.count
!= sizeof(info
)) {
169 } else if (ccw
.count
< sizeof(info
)) {
170 /* Can't execute command. */
177 info
.queue
= ldq_phys(ccw
.cda
);
178 info
.align
= ldl_phys(ccw
.cda
+ sizeof(info
.queue
));
179 info
.index
= lduw_phys(ccw
.cda
+ sizeof(info
.queue
)
180 + sizeof(info
.align
));
181 info
.num
= lduw_phys(ccw
.cda
+ sizeof(info
.queue
)
183 + sizeof(info
.index
));
184 ret
= virtio_ccw_set_vqs(sch
, info
.queue
, info
.align
, info
.index
,
186 sch
->curr_status
.scsw
.count
= 0;
189 case CCW_CMD_VDEV_RESET
:
190 virtio_reset(dev
->vdev
);
193 case CCW_CMD_READ_FEAT
:
195 if (ccw
.count
!= sizeof(features
)) {
199 } else if (ccw
.count
< sizeof(features
)) {
200 /* Can't execute command. */
207 features
.index
= ldub_phys(ccw
.cda
+ sizeof(features
.features
));
208 if (features
.index
< ARRAY_SIZE(dev
->host_features
)) {
209 features
.features
= dev
->host_features
[features
.index
];
211 /* Return zeroes if the guest supports more feature bits. */
212 features
.features
= 0;
214 stl_le_phys(ccw
.cda
, features
.features
);
215 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(features
);
219 case CCW_CMD_WRITE_FEAT
:
221 if (ccw
.count
!= sizeof(features
)) {
225 } else if (ccw
.count
< sizeof(features
)) {
226 /* Can't execute command. */
233 features
.index
= ldub_phys(ccw
.cda
+ sizeof(features
.features
));
234 features
.features
= ldl_le_phys(ccw
.cda
);
235 if (features
.index
< ARRAY_SIZE(dev
->host_features
)) {
236 if (dev
->vdev
->set_features
) {
237 dev
->vdev
->set_features(dev
->vdev
, features
.features
);
239 dev
->vdev
->guest_features
= features
.features
;
242 * If the guest supports more feature bits, assert that it
243 * passes us zeroes for those we don't support.
245 if (features
.features
) {
246 fprintf(stderr
, "Guest bug: features[%i]=%x (expected 0)\n",
247 features
.index
, features
.features
);
248 /* XXX: do a unit check here? */
251 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(features
);
255 case CCW_CMD_READ_CONF
:
257 if (ccw
.count
> dev
->vdev
->config_len
) {
262 len
= MIN(ccw
.count
, dev
->vdev
->config_len
);
266 dev
->vdev
->get_config(dev
->vdev
, dev
->vdev
->config
);
267 /* XXX config space endianness */
268 cpu_physical_memory_write(ccw
.cda
, dev
->vdev
->config
, len
);
269 sch
->curr_status
.scsw
.count
= ccw
.count
- len
;
273 case CCW_CMD_WRITE_CONF
:
275 if (ccw
.count
> dev
->vdev
->config_len
) {
280 len
= MIN(ccw
.count
, dev
->vdev
->config_len
);
285 config
= cpu_physical_memory_map(ccw
.cda
, &hw_len
, 0);
290 /* XXX config space endianness */
291 memcpy(dev
->vdev
->config
, config
, len
);
292 cpu_physical_memory_unmap(config
, hw_len
, 0, hw_len
);
293 if (dev
->vdev
->set_config
) {
294 dev
->vdev
->set_config(dev
->vdev
, dev
->vdev
->config
);
296 sch
->curr_status
.scsw
.count
= ccw
.count
- len
;
301 case CCW_CMD_WRITE_STATUS
:
303 if (ccw
.count
!= sizeof(status
)) {
307 } else if (ccw
.count
< sizeof(status
)) {
308 /* Can't execute command. */
315 status
= ldub_phys(ccw
.cda
);
316 virtio_set_status(dev
->vdev
, status
);
317 if (dev
->vdev
->status
== 0) {
318 virtio_reset(dev
->vdev
);
320 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(status
);
324 case CCW_CMD_SET_IND
:
326 if (ccw
.count
!= sizeof(indicators
)) {
330 } else if (ccw
.count
< sizeof(indicators
)) {
331 /* Can't execute command. */
335 indicators
= ldq_phys(ccw
.cda
);
339 dev
->indicators
= indicators
;
340 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(indicators
);
344 case CCW_CMD_SET_CONF_IND
:
346 if (ccw
.count
!= sizeof(indicators
)) {
350 } else if (ccw
.count
< sizeof(indicators
)) {
351 /* Can't execute command. */
355 indicators
= ldq_phys(ccw
.cda
);
359 dev
->indicators2
= indicators
;
360 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(indicators
);
364 case CCW_CMD_READ_VQ_CONF
:
366 if (ccw
.count
!= sizeof(vq_config
)) {
370 } else if (ccw
.count
< sizeof(vq_config
)) {
371 /* Can't execute command. */
378 vq_config
.index
= lduw_phys(ccw
.cda
);
379 vq_config
.num_max
= virtio_queue_get_num(dev
->vdev
,
381 stw_phys(ccw
.cda
+ sizeof(vq_config
.index
), vq_config
.num_max
);
382 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(vq_config
);
393 static int virtio_ccw_device_init(VirtioCcwDevice
*dev
, VirtIODevice
*vdev
)
395 unsigned int cssid
= 0;
396 unsigned int ssid
= 0;
399 bool have_devno
= false;
404 DeviceState
*parent
= DEVICE(dev
);
406 sch
= g_malloc0(sizeof(SubchDev
));
408 sch
->driver_data
= dev
;
414 /* Initialize subchannel structure. */
415 sch
->channel_prog
= 0x0;
416 sch
->last_cmd_valid
= false;
419 * Use a device number if provided. Otherwise, fall back to subchannel
423 num
= sscanf(dev
->bus_id
, "%x.%x.%04x", &cssid
, &ssid
, &devno
);
425 if ((cssid
> MAX_CSSID
) || (ssid
> MAX_SSID
)) {
427 error_report("Invalid cssid or ssid: cssid %x, ssid %x",
431 /* Enforce use of virtual cssid. */
432 if (cssid
!= VIRTUAL_CSSID
) {
434 error_report("cssid %x not valid for virtio devices", cssid
);
437 if (css_devno_used(cssid
, ssid
, devno
)) {
439 error_report("Device %x.%x.%04x already exists", cssid
, ssid
,
449 error_report("Malformed devno parameter '%s'", dev
->bus_id
);
454 /* Find the next free id. */
456 for (schid
= 0; schid
<= MAX_SCHID
; schid
++) {
457 if (!css_find_subch(1, cssid
, ssid
, schid
)) {
459 css_subch_assign(cssid
, ssid
, schid
, devno
, sch
);
466 error_report("No free subchannel found for %x.%x.%04x", cssid
, ssid
,
470 trace_virtio_ccw_new_device(cssid
, ssid
, schid
, devno
,
473 cssid
= VIRTUAL_CSSID
;
474 for (ssid
= 0; ssid
<= MAX_SSID
; ssid
++) {
475 for (schid
= 0; schid
<= MAX_SCHID
; schid
++) {
476 if (!css_find_subch(1, cssid
, ssid
, schid
)) {
482 * If the devno is already taken, look further in this
485 while (css_devno_used(cssid
, ssid
, devno
)) {
486 if (devno
== MAX_SCHID
) {
488 } else if (devno
== schid
- 1) {
490 error_report("No free devno found");
497 css_subch_assign(cssid
, ssid
, schid
, devno
, sch
);
508 error_report("Virtual channel subsystem is full!");
511 trace_virtio_ccw_new_device(cssid
, ssid
, schid
, devno
,
515 /* Build initial schib. */
516 css_sch_build_virtual_schib(sch
, 0, VIRTIO_CCW_CHPID_TYPE
);
518 sch
->ccw_cb
= virtio_ccw_cb
;
520 /* Build senseid data. */
521 memset(&sch
->id
, 0, sizeof(SenseId
));
522 sch
->id
.reserved
= 0xff;
523 sch
->id
.cu_type
= VIRTIO_CCW_CU_TYPE
;
524 sch
->id
.cu_model
= dev
->vdev
->device_id
;
526 virtio_bind_device(vdev
, &virtio_ccw_bindings
, DEVICE(dev
));
527 /* Only the first 32 feature bits are used. */
528 dev
->host_features
[0] = vdev
->get_features(vdev
, dev
->host_features
[0]);
529 dev
->host_features
[0] |= 0x1 << VIRTIO_F_NOTIFY_ON_EMPTY
;
530 dev
->host_features
[0] |= 0x1 << VIRTIO_F_BAD_FEATURE
;
532 css_generate_sch_crws(sch
->cssid
, sch
->ssid
, sch
->schid
,
533 parent
->hotplugged
, 1);
542 static int virtio_ccw_exit(VirtioCcwDevice
*dev
)
544 SubchDev
*sch
= dev
->sch
;
547 css_subch_assign(sch
->cssid
, sch
->ssid
, sch
->schid
, sch
->devno
, NULL
);
554 static int virtio_ccw_net_init(VirtioCcwDevice
*dev
)
558 vdev
= virtio_net_init((DeviceState
*)dev
, &dev
->nic
, &dev
->net
,
559 dev
->host_features
[0]);
564 return virtio_ccw_device_init(dev
, vdev
);
567 static int virtio_ccw_net_exit(VirtioCcwDevice
*dev
)
569 virtio_net_exit(dev
->vdev
);
570 return virtio_ccw_exit(dev
);
573 static int virtio_ccw_blk_init(VirtioCcwDevice
*ccw_dev
)
575 VirtIOBlkCcw
*dev
= VIRTIO_BLK_CCW(ccw_dev
);
576 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
577 virtio_blk_set_conf(vdev
, &(dev
->blk
));
578 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
579 if (qdev_init(vdev
) < 0) {
583 return virtio_ccw_device_init(ccw_dev
, VIRTIO_DEVICE(vdev
));
586 static void virtio_ccw_blk_instance_init(Object
*obj
)
588 VirtIOBlkCcw
*dev
= VIRTIO_BLK_CCW(obj
);
589 object_initialize(OBJECT(&dev
->vdev
), TYPE_VIRTIO_BLK
);
590 object_property_add_child(obj
, "virtio-backend", OBJECT(&dev
->vdev
), NULL
);
593 static int virtio_ccw_serial_init(VirtioCcwDevice
*dev
)
597 vdev
= virtio_serial_init((DeviceState
*)dev
, &dev
->serial
);
602 return virtio_ccw_device_init(dev
, vdev
);
605 static int virtio_ccw_serial_exit(VirtioCcwDevice
*dev
)
607 virtio_serial_exit(dev
->vdev
);
608 return virtio_ccw_exit(dev
);
611 static int virtio_ccw_balloon_init(VirtioCcwDevice
*ccw_dev
)
613 VirtIOBalloonCcw
*dev
= VIRTIO_BALLOON_CCW(ccw_dev
);
614 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
616 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
617 if (qdev_init(vdev
) < 0) {
621 return virtio_ccw_device_init(ccw_dev
, VIRTIO_DEVICE(vdev
));
624 static void virtio_ccw_balloon_instance_init(Object
*obj
)
626 VirtIOBalloonCcw
*dev
= VIRTIO_BALLOON_CCW(obj
);
627 object_initialize(OBJECT(&dev
->vdev
), TYPE_VIRTIO_BALLOON
);
628 object_property_add_child(obj
, "virtio-backend", OBJECT(&dev
->vdev
), NULL
);
631 static int virtio_ccw_scsi_init(VirtioCcwDevice
*ccw_dev
)
633 VirtIOSCSICcw
*dev
= VIRTIO_SCSI_CCW(ccw_dev
);
634 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
636 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
637 if (qdev_init(vdev
) < 0) {
641 return virtio_ccw_device_init(ccw_dev
, VIRTIO_DEVICE(vdev
));
644 static void virtio_ccw_scsi_instance_init(Object
*obj
)
646 VirtIOSCSICcw
*dev
= VIRTIO_SCSI_CCW(obj
);
647 object_initialize(OBJECT(&dev
->vdev
), TYPE_VIRTIO_SCSI
);
648 object_property_add_child(obj
, "virtio-backend", OBJECT(&dev
->vdev
), NULL
);
651 static int virtio_ccw_rng_init(VirtioCcwDevice
*dev
)
655 if (dev
->rng
.rng
== NULL
) {
656 dev
->rng
.default_backend
= RNG_RANDOM(object_new(TYPE_RNG_RANDOM
));
657 object_property_add_child(OBJECT(dev
), "default-backend",
658 OBJECT(dev
->rng
.default_backend
), NULL
);
659 object_property_set_link(OBJECT(dev
), OBJECT(dev
->rng
.default_backend
),
662 vdev
= virtio_rng_init((DeviceState
*)dev
, &dev
->rng
);
666 return virtio_ccw_device_init(dev
, vdev
);
669 static int virtio_ccw_rng_exit(VirtioCcwDevice
*dev
)
671 virtio_rng_exit(dev
->vdev
);
672 return virtio_ccw_exit(dev
);
675 /* DeviceState to VirtioCcwDevice. Note: used on datapath,
676 * be careful and test performance if you change this.
678 static inline VirtioCcwDevice
*to_virtio_ccw_dev_fast(DeviceState
*d
)
680 return container_of(d
, VirtioCcwDevice
, parent_obj
);
683 static void virtio_ccw_notify(DeviceState
*d
, uint16_t vector
)
685 VirtioCcwDevice
*dev
= to_virtio_ccw_dev_fast(d
);
686 SubchDev
*sch
= dev
->sch
;
693 if (vector
< VIRTIO_PCI_QUEUE_MAX
) {
694 indicators
= ldq_phys(dev
->indicators
);
695 indicators
|= 1ULL << vector
;
696 stq_phys(dev
->indicators
, indicators
);
699 indicators
= ldq_phys(dev
->indicators2
);
700 indicators
|= 1ULL << vector
;
701 stq_phys(dev
->indicators2
, indicators
);
704 css_conditional_io_interrupt(sch
);
708 static unsigned virtio_ccw_get_features(DeviceState
*d
)
710 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
712 /* Only the first 32 feature bits are used. */
713 return dev
->host_features
[0];
716 static void virtio_ccw_reset(DeviceState
*d
)
718 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
720 virtio_reset(dev
->vdev
);
721 css_reset_sch(dev
->sch
);
724 /**************** Virtio-ccw Bus Device Descriptions *******************/
726 static const VirtIOBindings virtio_ccw_bindings
= {
727 .notify
= virtio_ccw_notify
,
728 .get_features
= virtio_ccw_get_features
,
731 static Property virtio_ccw_net_properties
[] = {
732 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
733 DEFINE_VIRTIO_NET_FEATURES(VirtioCcwDevice
, host_features
[0]),
734 DEFINE_NIC_PROPERTIES(VirtioCcwDevice
, nic
),
735 DEFINE_PROP_UINT32("x-txtimer", VirtioCcwDevice
,
736 net
.txtimer
, TX_TIMER_INTERVAL
),
737 DEFINE_PROP_INT32("x-txburst", VirtioCcwDevice
,
738 net
.txburst
, TX_BURST
),
739 DEFINE_PROP_STRING("tx", VirtioCcwDevice
, net
.tx
),
740 DEFINE_PROP_END_OF_LIST(),
743 static void virtio_ccw_net_class_init(ObjectClass
*klass
, void *data
)
745 DeviceClass
*dc
= DEVICE_CLASS(klass
);
746 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
748 k
->init
= virtio_ccw_net_init
;
749 k
->exit
= virtio_ccw_net_exit
;
750 dc
->reset
= virtio_ccw_reset
;
751 dc
->props
= virtio_ccw_net_properties
;
754 static const TypeInfo virtio_ccw_net
= {
755 .name
= "virtio-net-ccw",
756 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
757 .instance_size
= sizeof(VirtioCcwDevice
),
758 .class_init
= virtio_ccw_net_class_init
,
761 static Property virtio_ccw_blk_properties
[] = {
762 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
763 DEFINE_VIRTIO_BLK_FEATURES(VirtioCcwDevice
, host_features
[0]),
764 DEFINE_VIRTIO_BLK_PROPERTIES(VirtIOBlkCcw
, blk
),
765 DEFINE_PROP_END_OF_LIST(),
768 static void virtio_ccw_blk_class_init(ObjectClass
*klass
, void *data
)
770 DeviceClass
*dc
= DEVICE_CLASS(klass
);
771 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
773 k
->init
= virtio_ccw_blk_init
;
774 k
->exit
= virtio_ccw_exit
;
775 dc
->reset
= virtio_ccw_reset
;
776 dc
->props
= virtio_ccw_blk_properties
;
779 static const TypeInfo virtio_ccw_blk
= {
780 .name
= TYPE_VIRTIO_BLK_CCW
,
781 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
782 .instance_size
= sizeof(VirtIOBlkCcw
),
783 .instance_init
= virtio_ccw_blk_instance_init
,
784 .class_init
= virtio_ccw_blk_class_init
,
787 static Property virtio_ccw_serial_properties
[] = {
788 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
789 DEFINE_PROP_UINT32("max_ports", VirtioCcwDevice
,
790 serial
.max_virtserial_ports
, 31),
791 DEFINE_VIRTIO_COMMON_FEATURES(VirtioCcwDevice
, host_features
[0]),
792 DEFINE_PROP_END_OF_LIST(),
795 static void virtio_ccw_serial_class_init(ObjectClass
*klass
, void *data
)
797 DeviceClass
*dc
= DEVICE_CLASS(klass
);
798 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
800 k
->init
= virtio_ccw_serial_init
;
801 k
->exit
= virtio_ccw_serial_exit
;
802 dc
->reset
= virtio_ccw_reset
;
803 dc
->props
= virtio_ccw_serial_properties
;
806 static const TypeInfo virtio_ccw_serial
= {
807 .name
= "virtio-serial-ccw",
808 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
809 .instance_size
= sizeof(VirtioCcwDevice
),
810 .class_init
= virtio_ccw_serial_class_init
,
813 static Property virtio_ccw_balloon_properties
[] = {
814 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
815 DEFINE_VIRTIO_COMMON_FEATURES(VirtioCcwDevice
, host_features
[0]),
816 DEFINE_PROP_END_OF_LIST(),
819 static void virtio_ccw_balloon_class_init(ObjectClass
*klass
, void *data
)
821 DeviceClass
*dc
= DEVICE_CLASS(klass
);
822 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
824 k
->init
= virtio_ccw_balloon_init
;
825 k
->exit
= virtio_ccw_exit
;
826 dc
->reset
= virtio_ccw_reset
;
827 dc
->props
= virtio_ccw_balloon_properties
;
830 static const TypeInfo virtio_ccw_balloon
= {
831 .name
= TYPE_VIRTIO_BALLOON_CCW
,
832 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
833 .instance_size
= sizeof(VirtIOBalloonCcw
),
834 .instance_init
= virtio_ccw_balloon_instance_init
,
835 .class_init
= virtio_ccw_balloon_class_init
,
838 static Property virtio_ccw_scsi_properties
[] = {
839 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
840 DEFINE_VIRTIO_SCSI_PROPERTIES(VirtIOSCSICcw
, vdev
.conf
),
841 DEFINE_VIRTIO_SCSI_FEATURES(VirtioCcwDevice
, host_features
[0]),
842 DEFINE_PROP_END_OF_LIST(),
845 static void virtio_ccw_scsi_class_init(ObjectClass
*klass
, void *data
)
847 DeviceClass
*dc
= DEVICE_CLASS(klass
);
848 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
850 k
->init
= virtio_ccw_scsi_init
;
851 k
->exit
= virtio_ccw_exit
;
852 dc
->reset
= virtio_ccw_reset
;
853 dc
->props
= virtio_ccw_scsi_properties
;
856 static const TypeInfo virtio_ccw_scsi
= {
857 .name
= TYPE_VIRTIO_SCSI_CCW
,
858 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
859 .instance_size
= sizeof(VirtIOSCSICcw
),
860 .instance_init
= virtio_ccw_scsi_instance_init
,
861 .class_init
= virtio_ccw_scsi_class_init
,
864 static void virtio_ccw_rng_initfn(Object
*obj
)
866 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(obj
);
868 object_property_add_link(obj
, "rng", TYPE_RNG_BACKEND
,
869 (Object
**)&dev
->rng
.rng
, NULL
);
872 static Property virtio_ccw_rng_properties
[] = {
873 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
874 DEFINE_VIRTIO_COMMON_FEATURES(VirtioCcwDevice
, host_features
[0]),
875 DEFINE_PROP_UINT64("max-bytes", VirtioCcwDevice
, rng
.max_bytes
, INT64_MAX
),
876 DEFINE_PROP_UINT32("period", VirtioCcwDevice
, rng
.period_ms
, 1 << 16),
877 DEFINE_PROP_END_OF_LIST(),
880 static void virtio_ccw_rng_class_init(ObjectClass
*klass
, void *data
)
882 DeviceClass
*dc
= DEVICE_CLASS(klass
);
883 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
885 k
->init
= virtio_ccw_rng_init
;
886 k
->exit
= virtio_ccw_rng_exit
;
887 dc
->reset
= virtio_ccw_reset
;
888 dc
->props
= virtio_ccw_rng_properties
;
891 static const TypeInfo virtio_ccw_rng
= {
892 .name
= "virtio-rng-ccw",
893 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
894 .instance_size
= sizeof(VirtioCcwDevice
),
895 .instance_init
= virtio_ccw_rng_initfn
,
896 .class_init
= virtio_ccw_rng_class_init
,
899 static int virtio_ccw_busdev_init(DeviceState
*dev
)
901 VirtioCcwDevice
*_dev
= (VirtioCcwDevice
*)dev
;
902 VirtIOCCWDeviceClass
*_info
= VIRTIO_CCW_DEVICE_GET_CLASS(dev
);
904 virtio_ccw_bus_new(&_dev
->bus
, _dev
);
906 return _info
->init(_dev
);
909 static int virtio_ccw_busdev_exit(DeviceState
*dev
)
911 VirtioCcwDevice
*_dev
= (VirtioCcwDevice
*)dev
;
912 VirtIOCCWDeviceClass
*_info
= VIRTIO_CCW_DEVICE_GET_CLASS(dev
);
914 return _info
->exit(_dev
);
917 static int virtio_ccw_busdev_unplug(DeviceState
*dev
)
919 VirtioCcwDevice
*_dev
= (VirtioCcwDevice
*)dev
;
920 SubchDev
*sch
= _dev
->sch
;
923 * We should arrive here only for device_del, since we don't support
924 * direct hot(un)plug of channels, but only through virtio.
927 /* Subchannel is now disabled and no longer valid. */
928 sch
->curr_status
.pmcw
.flags
&= ~(PMCW_FLAGS_MASK_ENA
|
929 PMCW_FLAGS_MASK_DNV
);
931 css_generate_sch_crws(sch
->cssid
, sch
->ssid
, sch
->schid
, 1, 0);
937 static void virtio_ccw_device_class_init(ObjectClass
*klass
, void *data
)
939 DeviceClass
*dc
= DEVICE_CLASS(klass
);
941 dc
->init
= virtio_ccw_busdev_init
;
942 dc
->exit
= virtio_ccw_busdev_exit
;
943 dc
->unplug
= virtio_ccw_busdev_unplug
;
944 dc
->bus_type
= TYPE_VIRTUAL_CSS_BUS
;
948 static const TypeInfo virtio_ccw_device_info
= {
949 .name
= TYPE_VIRTIO_CCW_DEVICE
,
950 .parent
= TYPE_DEVICE
,
951 .instance_size
= sizeof(VirtioCcwDevice
),
952 .class_init
= virtio_ccw_device_class_init
,
953 .class_size
= sizeof(VirtIOCCWDeviceClass
),
957 /***************** Virtual-css Bus Bridge Device ********************/
958 /* Only required to have the virtio bus as child in the system bus */
960 static int virtual_css_bridge_init(SysBusDevice
*dev
)
966 static void virtual_css_bridge_class_init(ObjectClass
*klass
, void *data
)
968 DeviceClass
*dc
= DEVICE_CLASS(klass
);
969 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
971 k
->init
= virtual_css_bridge_init
;
975 static const TypeInfo virtual_css_bridge_info
= {
976 .name
= "virtual-css-bridge",
977 .parent
= TYPE_SYS_BUS_DEVICE
,
978 .instance_size
= sizeof(SysBusDevice
),
979 .class_init
= virtual_css_bridge_class_init
,
984 void virtio_ccw_bus_new(VirtioBusState
*bus
, VirtioCcwDevice
*dev
)
986 DeviceState
*qdev
= DEVICE(dev
);
989 qbus_create_inplace((BusState
*)bus
, TYPE_VIRTIO_CCW_BUS
, qdev
, NULL
);
991 qbus
->allow_hotplug
= 1;
994 static void virtio_ccw_bus_class_init(ObjectClass
*klass
, void *data
)
996 VirtioBusClass
*k
= VIRTIO_BUS_CLASS(klass
);
997 BusClass
*bus_class
= BUS_CLASS(klass
);
999 bus_class
->max_dev
= 1;
1000 k
->notify
= virtio_ccw_notify
;
1001 k
->get_features
= virtio_ccw_get_features
;
1004 static const TypeInfo virtio_ccw_bus_info
= {
1005 .name
= TYPE_VIRTIO_CCW_BUS
,
1006 .parent
= TYPE_VIRTIO_BUS
,
1007 .instance_size
= sizeof(VirtioCcwBusState
),
1008 .class_init
= virtio_ccw_bus_class_init
,
1011 static void virtio_ccw_register(void)
1013 type_register_static(&virtio_ccw_bus_info
);
1014 type_register_static(&virtual_css_bus_info
);
1015 type_register_static(&virtio_ccw_device_info
);
1016 type_register_static(&virtio_ccw_serial
);
1017 type_register_static(&virtio_ccw_blk
);
1018 type_register_static(&virtio_ccw_net
);
1019 type_register_static(&virtio_ccw_balloon
);
1020 type_register_static(&virtio_ccw_scsi
);
1021 type_register_static(&virtio_ccw_rng
);
1022 type_register_static(&virtual_css_bridge_info
);
1025 type_init(virtio_ccw_register
)