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/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"
27 #include "virtio-ccw.h"
30 static void virtio_ccw_bus_new(VirtioBusState
*bus
, VirtioCcwDevice
*dev
);
32 static int virtual_css_bus_reset(BusState
*qbus
)
34 /* This should actually be modelled via the generic css */
37 /* we dont traverse ourself, return 0 */
42 static void virtual_css_bus_class_init(ObjectClass
*klass
, void *data
)
44 BusClass
*k
= BUS_CLASS(klass
);
46 k
->reset
= virtual_css_bus_reset
;
49 static const TypeInfo virtual_css_bus_info
= {
50 .name
= TYPE_VIRTUAL_CSS_BUS
,
52 .instance_size
= sizeof(VirtualCssBus
),
53 .class_init
= virtual_css_bus_class_init
,
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 virtio_bus_set_vdev_features(&dev
->bus
, features
.features
);
237 dev
->vdev
->guest_features
= features
.features
;
240 * If the guest supports more feature bits, assert that it
241 * passes us zeroes for those we don't support.
243 if (features
.features
) {
244 fprintf(stderr
, "Guest bug: features[%i]=%x (expected 0)\n",
245 features
.index
, features
.features
);
246 /* XXX: do a unit check here? */
249 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(features
);
253 case CCW_CMD_READ_CONF
:
255 if (ccw
.count
> dev
->vdev
->config_len
) {
260 len
= MIN(ccw
.count
, dev
->vdev
->config_len
);
264 virtio_bus_get_vdev_config(&dev
->bus
, dev
->vdev
->config
);
265 /* XXX config space endianness */
266 cpu_physical_memory_write(ccw
.cda
, dev
->vdev
->config
, len
);
267 sch
->curr_status
.scsw
.count
= ccw
.count
- len
;
271 case CCW_CMD_WRITE_CONF
:
273 if (ccw
.count
> dev
->vdev
->config_len
) {
278 len
= MIN(ccw
.count
, dev
->vdev
->config_len
);
283 config
= cpu_physical_memory_map(ccw
.cda
, &hw_len
, 0);
288 /* XXX config space endianness */
289 memcpy(dev
->vdev
->config
, config
, len
);
290 cpu_physical_memory_unmap(config
, hw_len
, 0, hw_len
);
291 virtio_bus_set_vdev_config(&dev
->bus
, dev
->vdev
->config
);
292 sch
->curr_status
.scsw
.count
= ccw
.count
- len
;
297 case CCW_CMD_WRITE_STATUS
:
299 if (ccw
.count
!= sizeof(status
)) {
303 } else if (ccw
.count
< sizeof(status
)) {
304 /* Can't execute command. */
311 status
= ldub_phys(ccw
.cda
);
312 virtio_set_status(dev
->vdev
, status
);
313 if (dev
->vdev
->status
== 0) {
314 virtio_reset(dev
->vdev
);
316 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(status
);
320 case CCW_CMD_SET_IND
:
322 if (ccw
.count
!= sizeof(indicators
)) {
326 } else if (ccw
.count
< sizeof(indicators
)) {
327 /* Can't execute command. */
331 indicators
= ldq_phys(ccw
.cda
);
335 dev
->indicators
= indicators
;
336 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(indicators
);
340 case CCW_CMD_SET_CONF_IND
:
342 if (ccw
.count
!= sizeof(indicators
)) {
346 } else if (ccw
.count
< sizeof(indicators
)) {
347 /* Can't execute command. */
351 indicators
= ldq_phys(ccw
.cda
);
355 dev
->indicators2
= indicators
;
356 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(indicators
);
360 case CCW_CMD_READ_VQ_CONF
:
362 if (ccw
.count
!= sizeof(vq_config
)) {
366 } else if (ccw
.count
< sizeof(vq_config
)) {
367 /* Can't execute command. */
374 vq_config
.index
= lduw_phys(ccw
.cda
);
375 vq_config
.num_max
= virtio_queue_get_num(dev
->vdev
,
377 stw_phys(ccw
.cda
+ sizeof(vq_config
.index
), vq_config
.num_max
);
378 sch
->curr_status
.scsw
.count
= ccw
.count
- sizeof(vq_config
);
389 static int virtio_ccw_device_init(VirtioCcwDevice
*dev
, VirtIODevice
*vdev
)
391 unsigned int cssid
= 0;
392 unsigned int ssid
= 0;
395 bool have_devno
= false;
400 DeviceState
*parent
= DEVICE(dev
);
402 sch
= g_malloc0(sizeof(SubchDev
));
404 sch
->driver_data
= dev
;
410 /* Initialize subchannel structure. */
411 sch
->channel_prog
= 0x0;
412 sch
->last_cmd_valid
= false;
415 * Use a device number if provided. Otherwise, fall back to subchannel
419 num
= sscanf(dev
->bus_id
, "%x.%x.%04x", &cssid
, &ssid
, &devno
);
421 if ((cssid
> MAX_CSSID
) || (ssid
> MAX_SSID
)) {
423 error_report("Invalid cssid or ssid: cssid %x, ssid %x",
427 /* Enforce use of virtual cssid. */
428 if (cssid
!= VIRTUAL_CSSID
) {
430 error_report("cssid %x not valid for virtio devices", cssid
);
433 if (css_devno_used(cssid
, ssid
, devno
)) {
435 error_report("Device %x.%x.%04x already exists", cssid
, ssid
,
445 error_report("Malformed devno parameter '%s'", dev
->bus_id
);
450 /* Find the next free id. */
452 for (schid
= 0; schid
<= MAX_SCHID
; schid
++) {
453 if (!css_find_subch(1, cssid
, ssid
, schid
)) {
455 css_subch_assign(cssid
, ssid
, schid
, devno
, sch
);
462 error_report("No free subchannel found for %x.%x.%04x", cssid
, ssid
,
466 trace_virtio_ccw_new_device(cssid
, ssid
, schid
, devno
,
469 cssid
= VIRTUAL_CSSID
;
470 for (ssid
= 0; ssid
<= MAX_SSID
; ssid
++) {
471 for (schid
= 0; schid
<= MAX_SCHID
; schid
++) {
472 if (!css_find_subch(1, cssid
, ssid
, schid
)) {
478 * If the devno is already taken, look further in this
481 while (css_devno_used(cssid
, ssid
, devno
)) {
482 if (devno
== MAX_SCHID
) {
484 } else if (devno
== schid
- 1) {
486 error_report("No free devno found");
493 css_subch_assign(cssid
, ssid
, schid
, devno
, sch
);
504 error_report("Virtual channel subsystem is full!");
507 trace_virtio_ccw_new_device(cssid
, ssid
, schid
, devno
,
511 /* Build initial schib. */
512 css_sch_build_virtual_schib(sch
, 0, VIRTIO_CCW_CHPID_TYPE
);
514 sch
->ccw_cb
= virtio_ccw_cb
;
516 /* Build senseid data. */
517 memset(&sch
->id
, 0, sizeof(SenseId
));
518 sch
->id
.reserved
= 0xff;
519 sch
->id
.cu_type
= VIRTIO_CCW_CU_TYPE
;
520 sch
->id
.cu_model
= dev
->vdev
->device_id
;
522 /* Only the first 32 feature bits are used. */
523 dev
->host_features
[0] = virtio_bus_get_vdev_features(&dev
->bus
,
524 dev
->host_features
[0]);
526 dev
->host_features
[0] |= 0x1 << VIRTIO_F_NOTIFY_ON_EMPTY
;
527 dev
->host_features
[0] |= 0x1 << VIRTIO_F_BAD_FEATURE
;
529 css_generate_sch_crws(sch
->cssid
, sch
->ssid
, sch
->schid
,
530 parent
->hotplugged
, 1);
539 static int virtio_ccw_exit(VirtioCcwDevice
*dev
)
541 SubchDev
*sch
= dev
->sch
;
544 css_subch_assign(sch
->cssid
, sch
->ssid
, sch
->schid
, sch
->devno
, NULL
);
551 static int virtio_ccw_net_init(VirtioCcwDevice
*ccw_dev
)
553 DeviceState
*qdev
= DEVICE(ccw_dev
);
554 VirtIONetCcw
*dev
= VIRTIO_NET_CCW(ccw_dev
);
555 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
557 virtio_net_set_config_size(&dev
->vdev
, ccw_dev
->host_features
[0]);
558 virtio_net_set_netclient_name(&dev
->vdev
, qdev
->id
,
559 object_get_typename(OBJECT(qdev
)));
560 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
561 if (qdev_init(vdev
) < 0) {
565 return virtio_ccw_device_init(ccw_dev
, VIRTIO_DEVICE(vdev
));
568 static void virtio_ccw_net_instance_init(Object
*obj
)
570 VirtIONetCcw
*dev
= VIRTIO_NET_CCW(obj
);
571 object_initialize(OBJECT(&dev
->vdev
), TYPE_VIRTIO_NET
);
572 object_property_add_child(obj
, "virtio-backend", OBJECT(&dev
->vdev
), NULL
);
575 static int virtio_ccw_blk_init(VirtioCcwDevice
*ccw_dev
)
577 VirtIOBlkCcw
*dev
= VIRTIO_BLK_CCW(ccw_dev
);
578 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
579 virtio_blk_set_conf(vdev
, &(dev
->blk
));
580 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
581 if (qdev_init(vdev
) < 0) {
585 return virtio_ccw_device_init(ccw_dev
, VIRTIO_DEVICE(vdev
));
588 static void virtio_ccw_blk_instance_init(Object
*obj
)
590 VirtIOBlkCcw
*dev
= VIRTIO_BLK_CCW(obj
);
591 object_initialize(OBJECT(&dev
->vdev
), TYPE_VIRTIO_BLK
);
592 object_property_add_child(obj
, "virtio-backend", OBJECT(&dev
->vdev
), NULL
);
595 static int virtio_ccw_serial_init(VirtioCcwDevice
*ccw_dev
)
597 VirtioSerialCcw
*dev
= VIRTIO_SERIAL_CCW(ccw_dev
);
598 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
599 DeviceState
*proxy
= DEVICE(ccw_dev
);
603 * For command line compatibility, this sets the virtio-serial-device bus
607 bus_name
= g_strdup_printf("%s.0", proxy
->id
);
608 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev
), bus_name
);
612 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
613 if (qdev_init(vdev
) < 0) {
617 return virtio_ccw_device_init(ccw_dev
, VIRTIO_DEVICE(vdev
));
621 static void virtio_ccw_serial_instance_init(Object
*obj
)
623 VirtioSerialCcw
*dev
= VIRTIO_SERIAL_CCW(obj
);
624 object_initialize(OBJECT(&dev
->vdev
), TYPE_VIRTIO_SERIAL
);
625 object_property_add_child(obj
, "virtio-backend", OBJECT(&dev
->vdev
), NULL
);
628 static int virtio_ccw_balloon_init(VirtioCcwDevice
*ccw_dev
)
630 VirtIOBalloonCcw
*dev
= VIRTIO_BALLOON_CCW(ccw_dev
);
631 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
633 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
634 if (qdev_init(vdev
) < 0) {
638 return virtio_ccw_device_init(ccw_dev
, VIRTIO_DEVICE(vdev
));
641 static void balloon_ccw_stats_get_all(Object
*obj
, struct Visitor
*v
,
642 void *opaque
, const char *name
,
645 VirtIOBalloonCcw
*dev
= opaque
;
646 object_property_get(OBJECT(&dev
->vdev
), v
, "guest-stats", errp
);
649 static void balloon_ccw_stats_get_poll_interval(Object
*obj
, struct Visitor
*v
,
650 void *opaque
, const char *name
,
653 VirtIOBalloonCcw
*dev
= opaque
;
654 object_property_get(OBJECT(&dev
->vdev
), v
, "guest-stats-polling-interval",
658 static void balloon_ccw_stats_set_poll_interval(Object
*obj
, struct Visitor
*v
,
659 void *opaque
, const char *name
,
662 VirtIOBalloonCcw
*dev
= opaque
;
663 object_property_set(OBJECT(&dev
->vdev
), v
, "guest-stats-polling-interval",
667 static void virtio_ccw_balloon_instance_init(Object
*obj
)
669 VirtIOBalloonCcw
*dev
= VIRTIO_BALLOON_CCW(obj
);
670 object_initialize(OBJECT(&dev
->vdev
), TYPE_VIRTIO_BALLOON
);
671 object_property_add_child(obj
, "virtio-backend", OBJECT(&dev
->vdev
), NULL
);
673 object_property_add(obj
, "guest-stats", "guest statistics",
674 balloon_ccw_stats_get_all
, NULL
, NULL
, dev
, NULL
);
676 object_property_add(obj
, "guest-stats-polling-interval", "int",
677 balloon_ccw_stats_get_poll_interval
,
678 balloon_ccw_stats_set_poll_interval
,
682 static int virtio_ccw_scsi_init(VirtioCcwDevice
*ccw_dev
)
684 VirtIOSCSICcw
*dev
= VIRTIO_SCSI_CCW(ccw_dev
);
685 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
686 DeviceState
*qdev
= DEVICE(ccw_dev
);
690 * For command line compatibility, this sets the virtio-scsi-device bus
694 bus_name
= g_strdup_printf("%s.0", qdev
->id
);
695 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev
), bus_name
);
699 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
700 if (qdev_init(vdev
) < 0) {
704 return virtio_ccw_device_init(ccw_dev
, VIRTIO_DEVICE(vdev
));
707 static void virtio_ccw_scsi_instance_init(Object
*obj
)
709 VirtIOSCSICcw
*dev
= VIRTIO_SCSI_CCW(obj
);
710 object_initialize(OBJECT(&dev
->vdev
), TYPE_VIRTIO_SCSI
);
711 object_property_add_child(obj
, "virtio-backend", OBJECT(&dev
->vdev
), NULL
);
714 #ifdef CONFIG_VHOST_SCSI
715 static int vhost_ccw_scsi_init(VirtioCcwDevice
*ccw_dev
)
717 VHostSCSICcw
*dev
= VHOST_SCSI_CCW(ccw_dev
);
718 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
720 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
721 if (qdev_init(vdev
) < 0) {
725 return virtio_ccw_device_init(ccw_dev
, VIRTIO_DEVICE(vdev
));
728 static void vhost_ccw_scsi_instance_init(Object
*obj
)
730 VHostSCSICcw
*dev
= VHOST_SCSI_CCW(obj
);
731 object_initialize(OBJECT(&dev
->vdev
), TYPE_VHOST_SCSI
);
732 object_property_add_child(obj
, "virtio-backend", OBJECT(&dev
->vdev
), NULL
);
736 static int virtio_ccw_rng_init(VirtioCcwDevice
*ccw_dev
)
738 VirtIORNGCcw
*dev
= VIRTIO_RNG_CCW(ccw_dev
);
739 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
741 qdev_set_parent_bus(vdev
, BUS(&ccw_dev
->bus
));
742 if (qdev_init(vdev
) < 0) {
746 object_property_set_link(OBJECT(dev
),
747 OBJECT(dev
->vdev
.conf
.default_backend
), "rng",
750 return virtio_ccw_device_init(ccw_dev
, VIRTIO_DEVICE(vdev
));
753 /* DeviceState to VirtioCcwDevice. Note: used on datapath,
754 * be careful and test performance if you change this.
756 static inline VirtioCcwDevice
*to_virtio_ccw_dev_fast(DeviceState
*d
)
758 return container_of(d
, VirtioCcwDevice
, parent_obj
);
761 static void virtio_ccw_notify(DeviceState
*d
, uint16_t vector
)
763 VirtioCcwDevice
*dev
= to_virtio_ccw_dev_fast(d
);
764 SubchDev
*sch
= dev
->sch
;
771 if (vector
< VIRTIO_PCI_QUEUE_MAX
) {
772 if (!dev
->indicators
) {
775 indicators
= ldq_phys(dev
->indicators
);
776 indicators
|= 1ULL << vector
;
777 stq_phys(dev
->indicators
, indicators
);
779 if (!dev
->indicators2
) {
783 indicators
= ldq_phys(dev
->indicators2
);
784 indicators
|= 1ULL << vector
;
785 stq_phys(dev
->indicators2
, indicators
);
788 css_conditional_io_interrupt(sch
);
792 static unsigned virtio_ccw_get_features(DeviceState
*d
)
794 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
796 /* Only the first 32 feature bits are used. */
797 return dev
->host_features
[0];
800 static void virtio_ccw_reset(DeviceState
*d
)
802 VirtioCcwDevice
*dev
= VIRTIO_CCW_DEVICE(d
);
804 virtio_reset(dev
->vdev
);
805 css_reset_sch(dev
->sch
);
808 /**************** Virtio-ccw Bus Device Descriptions *******************/
810 static Property virtio_ccw_net_properties
[] = {
811 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
812 DEFINE_VIRTIO_NET_FEATURES(VirtioCcwDevice
, host_features
[0]),
813 DEFINE_VIRTIO_NET_PROPERTIES(VirtIONetCcw
, vdev
.net_conf
),
814 DEFINE_NIC_PROPERTIES(VirtIONetCcw
, vdev
.nic_conf
),
815 DEFINE_PROP_END_OF_LIST(),
818 static void virtio_ccw_net_class_init(ObjectClass
*klass
, void *data
)
820 DeviceClass
*dc
= DEVICE_CLASS(klass
);
821 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
823 k
->init
= virtio_ccw_net_init
;
824 k
->exit
= virtio_ccw_exit
;
825 dc
->reset
= virtio_ccw_reset
;
826 dc
->props
= virtio_ccw_net_properties
;
829 static const TypeInfo virtio_ccw_net
= {
830 .name
= TYPE_VIRTIO_NET_CCW
,
831 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
832 .instance_size
= sizeof(VirtIONetCcw
),
833 .instance_init
= virtio_ccw_net_instance_init
,
834 .class_init
= virtio_ccw_net_class_init
,
837 static Property virtio_ccw_blk_properties
[] = {
838 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
839 DEFINE_VIRTIO_BLK_FEATURES(VirtioCcwDevice
, host_features
[0]),
840 DEFINE_VIRTIO_BLK_PROPERTIES(VirtIOBlkCcw
, blk
),
841 DEFINE_PROP_END_OF_LIST(),
844 static void virtio_ccw_blk_class_init(ObjectClass
*klass
, void *data
)
846 DeviceClass
*dc
= DEVICE_CLASS(klass
);
847 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
849 k
->init
= virtio_ccw_blk_init
;
850 k
->exit
= virtio_ccw_exit
;
851 dc
->reset
= virtio_ccw_reset
;
852 dc
->props
= virtio_ccw_blk_properties
;
855 static const TypeInfo virtio_ccw_blk
= {
856 .name
= TYPE_VIRTIO_BLK_CCW
,
857 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
858 .instance_size
= sizeof(VirtIOBlkCcw
),
859 .instance_init
= virtio_ccw_blk_instance_init
,
860 .class_init
= virtio_ccw_blk_class_init
,
863 static Property virtio_ccw_serial_properties
[] = {
864 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
865 DEFINE_VIRTIO_SERIAL_PROPERTIES(VirtioSerialCcw
, vdev
.serial
),
866 DEFINE_VIRTIO_COMMON_FEATURES(VirtioCcwDevice
, host_features
[0]),
867 DEFINE_PROP_END_OF_LIST(),
870 static void virtio_ccw_serial_class_init(ObjectClass
*klass
, void *data
)
872 DeviceClass
*dc
= DEVICE_CLASS(klass
);
873 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
875 k
->init
= virtio_ccw_serial_init
;
876 k
->exit
= virtio_ccw_exit
;
877 dc
->reset
= virtio_ccw_reset
;
878 dc
->props
= virtio_ccw_serial_properties
;
881 static const TypeInfo virtio_ccw_serial
= {
882 .name
= TYPE_VIRTIO_SERIAL_CCW
,
883 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
884 .instance_size
= sizeof(VirtioSerialCcw
),
885 .instance_init
= virtio_ccw_serial_instance_init
,
886 .class_init
= virtio_ccw_serial_class_init
,
889 static Property virtio_ccw_balloon_properties
[] = {
890 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
891 DEFINE_VIRTIO_COMMON_FEATURES(VirtioCcwDevice
, host_features
[0]),
892 DEFINE_PROP_END_OF_LIST(),
895 static void virtio_ccw_balloon_class_init(ObjectClass
*klass
, void *data
)
897 DeviceClass
*dc
= DEVICE_CLASS(klass
);
898 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
900 k
->init
= virtio_ccw_balloon_init
;
901 k
->exit
= virtio_ccw_exit
;
902 dc
->reset
= virtio_ccw_reset
;
903 dc
->props
= virtio_ccw_balloon_properties
;
906 static const TypeInfo virtio_ccw_balloon
= {
907 .name
= TYPE_VIRTIO_BALLOON_CCW
,
908 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
909 .instance_size
= sizeof(VirtIOBalloonCcw
),
910 .instance_init
= virtio_ccw_balloon_instance_init
,
911 .class_init
= virtio_ccw_balloon_class_init
,
914 static Property virtio_ccw_scsi_properties
[] = {
915 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
916 DEFINE_VIRTIO_SCSI_PROPERTIES(VirtIOSCSICcw
, vdev
.parent_obj
.conf
),
917 DEFINE_VIRTIO_SCSI_FEATURES(VirtioCcwDevice
, host_features
[0]),
918 DEFINE_PROP_END_OF_LIST(),
921 static void virtio_ccw_scsi_class_init(ObjectClass
*klass
, void *data
)
923 DeviceClass
*dc
= DEVICE_CLASS(klass
);
924 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
926 k
->init
= virtio_ccw_scsi_init
;
927 k
->exit
= virtio_ccw_exit
;
928 dc
->reset
= virtio_ccw_reset
;
929 dc
->props
= virtio_ccw_scsi_properties
;
932 static const TypeInfo virtio_ccw_scsi
= {
933 .name
= TYPE_VIRTIO_SCSI_CCW
,
934 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
935 .instance_size
= sizeof(VirtIOSCSICcw
),
936 .instance_init
= virtio_ccw_scsi_instance_init
,
937 .class_init
= virtio_ccw_scsi_class_init
,
940 #ifdef CONFIG_VHOST_SCSI
941 static Property vhost_ccw_scsi_properties
[] = {
942 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
943 DEFINE_VHOST_SCSI_PROPERTIES(VirtIOSCSICcw
, vdev
.parent_obj
.conf
),
944 DEFINE_VIRTIO_COMMON_FEATURES(VirtioCcwDevice
, host_features
[0]),
945 DEFINE_PROP_END_OF_LIST(),
948 static void vhost_ccw_scsi_class_init(ObjectClass
*klass
, void *data
)
950 DeviceClass
*dc
= DEVICE_CLASS(klass
);
951 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
953 k
->init
= vhost_ccw_scsi_init
;
954 k
->exit
= virtio_ccw_exit
;
955 dc
->reset
= virtio_ccw_reset
;
956 dc
->props
= vhost_ccw_scsi_properties
;
959 static const TypeInfo vhost_ccw_scsi
= {
960 .name
= TYPE_VHOST_SCSI_CCW
,
961 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
962 .instance_size
= sizeof(VirtIOSCSICcw
),
963 .instance_init
= vhost_ccw_scsi_instance_init
,
964 .class_init
= vhost_ccw_scsi_class_init
,
968 static void virtio_ccw_rng_instance_init(Object
*obj
)
970 VirtIORNGCcw
*dev
= VIRTIO_RNG_CCW(obj
);
971 object_initialize(OBJECT(&dev
->vdev
), TYPE_VIRTIO_RNG
);
972 object_property_add_child(obj
, "virtio-backend", OBJECT(&dev
->vdev
), NULL
);
973 object_property_add_link(obj
, "rng", TYPE_RNG_BACKEND
,
974 (Object
**)&dev
->vdev
.conf
.rng
, NULL
);
977 static Property virtio_ccw_rng_properties
[] = {
978 DEFINE_PROP_STRING("devno", VirtioCcwDevice
, bus_id
),
979 DEFINE_VIRTIO_COMMON_FEATURES(VirtioCcwDevice
, host_features
[0]),
980 DEFINE_VIRTIO_RNG_PROPERTIES(VirtIORNGCcw
, vdev
.conf
),
981 DEFINE_PROP_END_OF_LIST(),
984 static void virtio_ccw_rng_class_init(ObjectClass
*klass
, void *data
)
986 DeviceClass
*dc
= DEVICE_CLASS(klass
);
987 VirtIOCCWDeviceClass
*k
= VIRTIO_CCW_DEVICE_CLASS(klass
);
989 k
->init
= virtio_ccw_rng_init
;
990 k
->exit
= virtio_ccw_exit
;
991 dc
->reset
= virtio_ccw_reset
;
992 dc
->props
= virtio_ccw_rng_properties
;
995 static const TypeInfo virtio_ccw_rng
= {
996 .name
= TYPE_VIRTIO_RNG_CCW
,
997 .parent
= TYPE_VIRTIO_CCW_DEVICE
,
998 .instance_size
= sizeof(VirtIORNGCcw
),
999 .instance_init
= virtio_ccw_rng_instance_init
,
1000 .class_init
= virtio_ccw_rng_class_init
,
1003 static int virtio_ccw_busdev_init(DeviceState
*dev
)
1005 VirtioCcwDevice
*_dev
= (VirtioCcwDevice
*)dev
;
1006 VirtIOCCWDeviceClass
*_info
= VIRTIO_CCW_DEVICE_GET_CLASS(dev
);
1008 virtio_ccw_bus_new(&_dev
->bus
, _dev
);
1010 return _info
->init(_dev
);
1013 static int virtio_ccw_busdev_exit(DeviceState
*dev
)
1015 VirtioCcwDevice
*_dev
= (VirtioCcwDevice
*)dev
;
1016 VirtIOCCWDeviceClass
*_info
= VIRTIO_CCW_DEVICE_GET_CLASS(dev
);
1018 return _info
->exit(_dev
);
1021 static int virtio_ccw_busdev_unplug(DeviceState
*dev
)
1023 VirtioCcwDevice
*_dev
= (VirtioCcwDevice
*)dev
;
1024 SubchDev
*sch
= _dev
->sch
;
1027 * We should arrive here only for device_del, since we don't support
1028 * direct hot(un)plug of channels, but only through virtio.
1030 assert(sch
!= NULL
);
1031 /* Subchannel is now disabled and no longer valid. */
1032 sch
->curr_status
.pmcw
.flags
&= ~(PMCW_FLAGS_MASK_ENA
|
1033 PMCW_FLAGS_MASK_DNV
);
1035 css_generate_sch_crws(sch
->cssid
, sch
->ssid
, sch
->schid
, 1, 0);
1041 static void virtio_ccw_device_class_init(ObjectClass
*klass
, void *data
)
1043 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1045 dc
->init
= virtio_ccw_busdev_init
;
1046 dc
->exit
= virtio_ccw_busdev_exit
;
1047 dc
->unplug
= virtio_ccw_busdev_unplug
;
1048 dc
->bus_type
= TYPE_VIRTUAL_CSS_BUS
;
1052 static const TypeInfo virtio_ccw_device_info
= {
1053 .name
= TYPE_VIRTIO_CCW_DEVICE
,
1054 .parent
= TYPE_DEVICE
,
1055 .instance_size
= sizeof(VirtioCcwDevice
),
1056 .class_init
= virtio_ccw_device_class_init
,
1057 .class_size
= sizeof(VirtIOCCWDeviceClass
),
1061 /***************** Virtual-css Bus Bridge Device ********************/
1062 /* Only required to have the virtio bus as child in the system bus */
1064 static int virtual_css_bridge_init(SysBusDevice
*dev
)
1070 static void virtual_css_bridge_class_init(ObjectClass
*klass
, void *data
)
1072 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1073 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
1075 k
->init
= virtual_css_bridge_init
;
1079 static const TypeInfo virtual_css_bridge_info
= {
1080 .name
= "virtual-css-bridge",
1081 .parent
= TYPE_SYS_BUS_DEVICE
,
1082 .instance_size
= sizeof(SysBusDevice
),
1083 .class_init
= virtual_css_bridge_class_init
,
1086 /* virtio-ccw-bus */
1088 static void virtio_ccw_bus_new(VirtioBusState
*bus
, VirtioCcwDevice
*dev
)
1090 DeviceState
*qdev
= DEVICE(dev
);
1092 char virtio_bus_name
[] = "virtio-bus";
1094 qbus_create_inplace((BusState
*)bus
, TYPE_VIRTIO_CCW_BUS
, qdev
,
1097 qbus
->allow_hotplug
= 1;
1100 static void virtio_ccw_bus_class_init(ObjectClass
*klass
, void *data
)
1102 VirtioBusClass
*k
= VIRTIO_BUS_CLASS(klass
);
1103 BusClass
*bus_class
= BUS_CLASS(klass
);
1105 bus_class
->max_dev
= 1;
1106 k
->notify
= virtio_ccw_notify
;
1107 k
->get_features
= virtio_ccw_get_features
;
1110 static const TypeInfo virtio_ccw_bus_info
= {
1111 .name
= TYPE_VIRTIO_CCW_BUS
,
1112 .parent
= TYPE_VIRTIO_BUS
,
1113 .instance_size
= sizeof(VirtioCcwBusState
),
1114 .class_init
= virtio_ccw_bus_class_init
,
1117 static void virtio_ccw_register(void)
1119 type_register_static(&virtio_ccw_bus_info
);
1120 type_register_static(&virtual_css_bus_info
);
1121 type_register_static(&virtio_ccw_device_info
);
1122 type_register_static(&virtio_ccw_serial
);
1123 type_register_static(&virtio_ccw_blk
);
1124 type_register_static(&virtio_ccw_net
);
1125 type_register_static(&virtio_ccw_balloon
);
1126 type_register_static(&virtio_ccw_scsi
);
1127 #ifdef CONFIG_VHOST_SCSI
1128 type_register_static(&vhost_ccw_scsi
);
1130 type_register_static(&virtio_ccw_rng
);
1131 type_register_static(&virtual_css_bridge_info
);
1134 type_init(virtio_ccw_register
)