2 * QEMU S390 virtio target
4 * Copyright (c) 2009 Alexander Graf <agraf@suse.de>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
21 #include "block/block.h"
22 #include "sysemu/sysemu.h"
23 #include "hw/boards.h"
24 #include "monitor/monitor.h"
25 #include "hw/loader.h"
27 #include "hw/virtio/virtio.h"
28 #include "hw/virtio/virtio-rng.h"
29 #include "hw/virtio/virtio-serial.h"
30 #include "hw/virtio/virtio-net.h"
31 #include "hw/virtio/vhost-scsi.h"
32 #include "hw/sysbus.h"
33 #include "sysemu/kvm.h"
35 #include "hw/s390x/s390-virtio-bus.h"
36 #include "hw/virtio/virtio-bus.h"
38 /* #define DEBUG_S390 */
41 #define dprintf(fmt, ...) \
42 do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
44 #define dprintf(fmt, ...) \
48 #define VIRTIO_EXT_CODE 0x2603
50 static void virtio_s390_bus_new(VirtioBusState
*bus
, VirtIOS390Device
*dev
);
52 static const TypeInfo s390_virtio_bus_info
= {
53 .name
= TYPE_S390_VIRTIO_BUS
,
55 .instance_size
= sizeof(VirtIOS390Bus
),
58 static const VirtIOBindings virtio_s390_bindings
;
60 static ram_addr_t
s390_virtio_device_num_vq(VirtIOS390Device
*dev
);
62 /* length of VirtIO device pages */
63 const hwaddr virtio_size
= S390_DEVICE_PAGES
* TARGET_PAGE_SIZE
;
65 static void s390_virtio_bus_reset(void *opaque
)
67 VirtIOS390Bus
*bus
= opaque
;
68 bus
->next_ring
= bus
->dev_page
+ TARGET_PAGE_SIZE
;
71 void s390_virtio_reset_idx(VirtIOS390Device
*dev
)
77 num_vq
= s390_virtio_device_num_vq(dev
);
78 for (i
= 0; i
< num_vq
; i
++) {
79 idx_addr
= virtio_queue_get_avail_addr(dev
->vdev
, i
) +
80 VIRTIO_VRING_AVAIL_IDX_OFFS
;
81 stw_phys(idx_addr
, 0);
82 idx_addr
= virtio_queue_get_used_addr(dev
->vdev
, i
) +
83 VIRTIO_VRING_USED_IDX_OFFS
;
84 stw_phys(idx_addr
, 0);
88 VirtIOS390Bus
*s390_virtio_bus_init(ram_addr_t
*ram_size
)
94 /* Create bridge device */
95 dev
= qdev_create(NULL
, "s390-virtio-bridge");
96 qdev_init_nofail(dev
);
98 /* Create bus on bridge device */
100 _bus
= qbus_create(TYPE_S390_VIRTIO_BUS
, dev
, "s390-virtio");
101 bus
= DO_UPCAST(VirtIOS390Bus
, bus
, _bus
);
103 bus
->dev_page
= *ram_size
;
104 bus
->dev_offs
= bus
->dev_page
;
105 bus
->next_ring
= bus
->dev_page
+ TARGET_PAGE_SIZE
;
107 /* Enable hotplugging */
108 _bus
->allow_hotplug
= 1;
110 /* Allocate RAM for VirtIO device pages (descriptors, queues, rings) */
111 *ram_size
+= S390_DEVICE_PAGES
* TARGET_PAGE_SIZE
;
113 qemu_register_reset(s390_virtio_bus_reset
, bus
);
117 static void s390_virtio_irq(S390CPU
*cpu
, int config_change
, uint64_t token
)
120 kvm_s390_virtio_irq(cpu
, config_change
, token
);
122 cpu_inject_ext(cpu
, VIRTIO_EXT_CODE
, config_change
, token
);
126 static int s390_virtio_device_init(VirtIOS390Device
*dev
, VirtIODevice
*vdev
)
131 bus
= DO_UPCAST(VirtIOS390Bus
, bus
, dev
->qdev
.parent_bus
);
133 dev
->dev_offs
= bus
->dev_offs
;
134 dev
->feat_len
= sizeof(uint32_t); /* always keep 32 bits features */
136 dev_len
= VIRTIO_DEV_OFFS_CONFIG
;
137 dev_len
+= s390_virtio_device_num_vq(dev
) * VIRTIO_VQCONFIG_LEN
;
138 dev_len
+= dev
->feat_len
* 2;
139 dev_len
+= vdev
->config_len
;
141 bus
->dev_offs
+= dev_len
;
143 virtio_bind_device(vdev
, &virtio_s390_bindings
, DEVICE(dev
));
144 dev
->host_features
= vdev
->get_features(vdev
, dev
->host_features
);
145 s390_virtio_device_sync(dev
);
146 s390_virtio_reset_idx(dev
);
147 if (dev
->qdev
.hotplugged
) {
148 S390CPU
*cpu
= s390_cpu_addr2state(0);
149 s390_virtio_irq(cpu
, VIRTIO_PARAM_DEV_ADD
, dev
->dev_offs
);
155 static int s390_virtio_net_init(VirtIOS390Device
*s390_dev
)
157 VirtIONetS390
*dev
= VIRTIO_NET_S390(s390_dev
);
158 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
160 virtio_net_set_config_size(&dev
->vdev
, s390_dev
->host_features
);
161 qdev_set_parent_bus(vdev
, BUS(&s390_dev
->bus
));
162 if (qdev_init(vdev
) < 0) {
166 return s390_virtio_device_init(s390_dev
, VIRTIO_DEVICE(vdev
));
169 static void s390_virtio_net_instance_init(Object
*obj
)
171 VirtIONetS390
*dev
= VIRTIO_NET_S390(obj
);
172 object_initialize(OBJECT(&dev
->vdev
), TYPE_VIRTIO_NET
);
173 object_property_add_child(obj
, "virtio-backend", OBJECT(&dev
->vdev
), NULL
);
176 static int s390_virtio_blk_init(VirtIOS390Device
*s390_dev
)
178 VirtIOBlkS390
*dev
= VIRTIO_BLK_S390(s390_dev
);
179 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
180 virtio_blk_set_conf(vdev
, &(dev
->blk
));
181 qdev_set_parent_bus(vdev
, BUS(&s390_dev
->bus
));
182 if (qdev_init(vdev
) < 0) {
185 return s390_virtio_device_init(s390_dev
, VIRTIO_DEVICE(vdev
));
188 static void s390_virtio_blk_instance_init(Object
*obj
)
190 VirtIOBlkS390
*dev
= VIRTIO_BLK_S390(obj
);
191 object_initialize(OBJECT(&dev
->vdev
), TYPE_VIRTIO_BLK
);
192 object_property_add_child(obj
, "virtio-backend", OBJECT(&dev
->vdev
), NULL
);
195 static int s390_virtio_serial_init(VirtIOS390Device
*s390_dev
)
197 VirtIOSerialS390
*dev
= VIRTIO_SERIAL_S390(s390_dev
);
198 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
199 DeviceState
*qdev
= DEVICE(s390_dev
);
203 bus
= DO_UPCAST(VirtIOS390Bus
, bus
, qdev
->parent_bus
);
205 qdev_set_parent_bus(vdev
, BUS(&s390_dev
->bus
));
206 if (qdev_init(vdev
) < 0) {
210 r
= s390_virtio_device_init(s390_dev
, VIRTIO_DEVICE(vdev
));
212 bus
->console
= s390_dev
;
218 static void s390_virtio_serial_instance_init(Object
*obj
)
220 VirtIOSerialS390
*dev
= VIRTIO_SERIAL_S390(obj
);
221 object_initialize(OBJECT(&dev
->vdev
), TYPE_VIRTIO_SERIAL
);
222 object_property_add_child(obj
, "virtio-backend", OBJECT(&dev
->vdev
), NULL
);
225 static int s390_virtio_scsi_init(VirtIOS390Device
*s390_dev
)
227 VirtIOSCSIS390
*dev
= VIRTIO_SCSI_S390(s390_dev
);
228 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
230 qdev_set_parent_bus(vdev
, BUS(&s390_dev
->bus
));
231 if (qdev_init(vdev
) < 0) {
235 return s390_virtio_device_init(s390_dev
, VIRTIO_DEVICE(vdev
));
238 static void s390_virtio_scsi_instance_init(Object
*obj
)
240 VirtIOSCSIS390
*dev
= VIRTIO_SCSI_S390(obj
);
241 object_initialize(OBJECT(&dev
->vdev
), TYPE_VIRTIO_SCSI
);
242 object_property_add_child(obj
, "virtio-backend", OBJECT(&dev
->vdev
), NULL
);
245 #ifdef CONFIG_VHOST_SCSI
246 static int s390_vhost_scsi_init(VirtIOS390Device
*s390_dev
)
248 VHostSCSIS390
*dev
= VHOST_SCSI_S390(s390_dev
);
249 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
251 qdev_set_parent_bus(vdev
, BUS(&s390_dev
->bus
));
252 if (qdev_init(vdev
) < 0) {
256 return s390_virtio_device_init(s390_dev
, VIRTIO_DEVICE(vdev
));
259 static void s390_vhost_scsi_instance_init(Object
*obj
)
261 VHostSCSIS390
*dev
= VHOST_SCSI_S390(obj
);
262 object_initialize(OBJECT(&dev
->vdev
), TYPE_VHOST_SCSI
);
263 object_property_add_child(obj
, "virtio-backend", OBJECT(&dev
->vdev
), NULL
);
268 static int s390_virtio_rng_init(VirtIOS390Device
*s390_dev
)
270 VirtIORNGS390
*dev
= VIRTIO_RNG_S390(s390_dev
);
271 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
273 qdev_set_parent_bus(vdev
, BUS(&s390_dev
->bus
));
274 if (qdev_init(vdev
) < 0) {
278 object_property_set_link(OBJECT(dev
),
279 OBJECT(dev
->vdev
.conf
.default_backend
), "rng",
282 return s390_virtio_device_init(s390_dev
, VIRTIO_DEVICE(vdev
));
285 static void s390_virtio_rng_instance_init(Object
*obj
)
287 VirtIORNGS390
*dev
= VIRTIO_RNG_S390(obj
);
288 object_initialize(OBJECT(&dev
->vdev
), TYPE_VIRTIO_RNG
);
289 object_property_add_child(obj
, "virtio-backend", OBJECT(&dev
->vdev
), NULL
);
290 object_property_add_link(obj
, "rng", TYPE_RNG_BACKEND
,
291 (Object
**)&dev
->vdev
.conf
.rng
, NULL
);
294 static uint64_t s390_virtio_device_vq_token(VirtIOS390Device
*dev
, int vq
)
296 ram_addr_t token_off
;
298 token_off
= (dev
->dev_offs
+ VIRTIO_DEV_OFFS_CONFIG
) +
299 (vq
* VIRTIO_VQCONFIG_LEN
) +
300 VIRTIO_VQCONFIG_OFFS_TOKEN
;
302 return ldq_be_phys(token_off
);
305 static ram_addr_t
s390_virtio_device_num_vq(VirtIOS390Device
*dev
)
307 VirtIODevice
*vdev
= dev
->vdev
;
310 for (num_vq
= 0; num_vq
< VIRTIO_PCI_QUEUE_MAX
; num_vq
++) {
311 if (!virtio_queue_get_num(vdev
, num_vq
)) {
319 static ram_addr_t
s390_virtio_next_ring(VirtIOS390Bus
*bus
)
321 ram_addr_t r
= bus
->next_ring
;
323 bus
->next_ring
+= VIRTIO_RING_LEN
;
327 void s390_virtio_device_sync(VirtIOS390Device
*dev
)
329 VirtIOS390Bus
*bus
= DO_UPCAST(VirtIOS390Bus
, bus
, dev
->qdev
.parent_bus
);
334 virtio_reset(dev
->vdev
);
337 stb_phys(dev
->dev_offs
+ VIRTIO_DEV_OFFS_TYPE
, dev
->vdev
->device_id
);
339 stb_phys(dev
->dev_offs
+ VIRTIO_DEV_OFFS_NUM_VQ
, s390_virtio_device_num_vq(dev
));
340 stb_phys(dev
->dev_offs
+ VIRTIO_DEV_OFFS_FEATURE_LEN
, dev
->feat_len
);
342 stb_phys(dev
->dev_offs
+ VIRTIO_DEV_OFFS_CONFIG_LEN
, dev
->vdev
->config_len
);
344 num_vq
= s390_virtio_device_num_vq(dev
);
345 stb_phys(dev
->dev_offs
+ VIRTIO_DEV_OFFS_NUM_VQ
, num_vq
);
347 /* Sync virtqueues */
348 for (i
= 0; i
< num_vq
; i
++) {
349 ram_addr_t vq
= (dev
->dev_offs
+ VIRTIO_DEV_OFFS_CONFIG
) +
350 (i
* VIRTIO_VQCONFIG_LEN
);
353 vring
= s390_virtio_next_ring(bus
);
354 virtio_queue_set_addr(dev
->vdev
, i
, vring
);
355 virtio_queue_set_vector(dev
->vdev
, i
, i
);
356 stq_be_phys(vq
+ VIRTIO_VQCONFIG_OFFS_ADDRESS
, vring
);
357 stw_be_phys(vq
+ VIRTIO_VQCONFIG_OFFS_NUM
, virtio_queue_get_num(dev
->vdev
, i
));
360 cur_offs
= dev
->dev_offs
;
361 cur_offs
+= VIRTIO_DEV_OFFS_CONFIG
;
362 cur_offs
+= num_vq
* VIRTIO_VQCONFIG_LEN
;
364 /* Sync feature bitmap */
365 stl_le_phys(cur_offs
, dev
->host_features
);
367 dev
->feat_offs
= cur_offs
+ dev
->feat_len
;
368 cur_offs
+= dev
->feat_len
* 2;
370 /* Sync config space */
371 if (dev
->vdev
->get_config
) {
372 dev
->vdev
->get_config(dev
->vdev
, dev
->vdev
->config
);
375 cpu_physical_memory_write(cur_offs
,
376 dev
->vdev
->config
, dev
->vdev
->config_len
);
377 cur_offs
+= dev
->vdev
->config_len
;
380 void s390_virtio_device_update_status(VirtIOS390Device
*dev
)
382 VirtIODevice
*vdev
= dev
->vdev
;
385 virtio_set_status(vdev
, ldub_phys(dev
->dev_offs
+ VIRTIO_DEV_OFFS_STATUS
));
387 /* Update guest supported feature bitmap */
389 features
= bswap32(ldl_be_phys(dev
->feat_offs
));
390 virtio_set_features(vdev
, features
);
393 VirtIOS390Device
*s390_virtio_bus_console(VirtIOS390Bus
*bus
)
398 /* Find a device by vring address */
399 VirtIOS390Device
*s390_virtio_bus_find_vring(VirtIOS390Bus
*bus
,
406 QTAILQ_FOREACH(kid
, &bus
->bus
.children
, sibling
) {
407 VirtIOS390Device
*dev
= (VirtIOS390Device
*)kid
->child
;
409 for(i
= 0; i
< VIRTIO_PCI_QUEUE_MAX
; i
++) {
410 if (!virtio_queue_get_addr(dev
->vdev
, i
))
412 if (virtio_queue_get_addr(dev
->vdev
, i
) == mem
) {
424 /* Find a device by device descriptor location */
425 VirtIOS390Device
*s390_virtio_bus_find_mem(VirtIOS390Bus
*bus
, ram_addr_t mem
)
429 QTAILQ_FOREACH(kid
, &bus
->bus
.children
, sibling
) {
430 VirtIOS390Device
*dev
= (VirtIOS390Device
*)kid
->child
;
431 if (dev
->dev_offs
== mem
) {
439 /* DeviceState to VirtIOS390Device. Note: used on datapath,
440 * be careful and test performance if you change this.
442 static inline VirtIOS390Device
*to_virtio_s390_device_fast(DeviceState
*d
)
444 return container_of(d
, VirtIOS390Device
, qdev
);
447 /* DeviceState to VirtIOS390Device. TODO: use QOM. */
448 static inline VirtIOS390Device
*to_virtio_s390_device(DeviceState
*d
)
450 return container_of(d
, VirtIOS390Device
, qdev
);
453 static void virtio_s390_notify(DeviceState
*d
, uint16_t vector
)
455 VirtIOS390Device
*dev
= to_virtio_s390_device_fast(d
);
456 uint64_t token
= s390_virtio_device_vq_token(dev
, vector
);
457 S390CPU
*cpu
= s390_cpu_addr2state(0);
459 s390_virtio_irq(cpu
, 0, token
);
462 static unsigned virtio_s390_get_features(DeviceState
*d
)
464 VirtIOS390Device
*dev
= to_virtio_s390_device(d
);
465 return dev
->host_features
;
468 /**************** S390 Virtio Bus Device Descriptions *******************/
470 static const VirtIOBindings virtio_s390_bindings
= {
471 .notify
= virtio_s390_notify
,
472 .get_features
= virtio_s390_get_features
,
475 static Property s390_virtio_net_properties
[] = {
476 DEFINE_NIC_PROPERTIES(VirtIONetS390
, vdev
.nic_conf
),
477 DEFINE_VIRTIO_NET_FEATURES(VirtIOS390Device
, host_features
),
478 DEFINE_VIRTIO_NET_PROPERTIES(VirtIONetS390
, vdev
.net_conf
),
479 DEFINE_PROP_END_OF_LIST(),
482 static void s390_virtio_net_class_init(ObjectClass
*klass
, void *data
)
484 DeviceClass
*dc
= DEVICE_CLASS(klass
);
485 VirtIOS390DeviceClass
*k
= VIRTIO_S390_DEVICE_CLASS(klass
);
487 k
->init
= s390_virtio_net_init
;
488 dc
->props
= s390_virtio_net_properties
;
491 static const TypeInfo s390_virtio_net
= {
492 .name
= TYPE_VIRTIO_NET_S390
,
493 .parent
= TYPE_VIRTIO_S390_DEVICE
,
494 .instance_size
= sizeof(VirtIONetS390
),
495 .instance_init
= s390_virtio_net_instance_init
,
496 .class_init
= s390_virtio_net_class_init
,
499 static Property s390_virtio_blk_properties
[] = {
500 DEFINE_VIRTIO_BLK_PROPERTIES(VirtIOBlkS390
, blk
),
501 DEFINE_PROP_END_OF_LIST(),
504 static void s390_virtio_blk_class_init(ObjectClass
*klass
, void *data
)
506 DeviceClass
*dc
= DEVICE_CLASS(klass
);
507 VirtIOS390DeviceClass
*k
= VIRTIO_S390_DEVICE_CLASS(klass
);
509 k
->init
= s390_virtio_blk_init
;
510 dc
->props
= s390_virtio_blk_properties
;
513 static const TypeInfo s390_virtio_blk
= {
514 .name
= "virtio-blk-s390",
515 .parent
= TYPE_VIRTIO_S390_DEVICE
,
516 .instance_size
= sizeof(VirtIOBlkS390
),
517 .instance_init
= s390_virtio_blk_instance_init
,
518 .class_init
= s390_virtio_blk_class_init
,
521 static Property s390_virtio_serial_properties
[] = {
522 DEFINE_VIRTIO_SERIAL_PROPERTIES(VirtIOSerialS390
, vdev
.serial
),
523 DEFINE_PROP_END_OF_LIST(),
526 static void s390_virtio_serial_class_init(ObjectClass
*klass
, void *data
)
528 DeviceClass
*dc
= DEVICE_CLASS(klass
);
529 VirtIOS390DeviceClass
*k
= VIRTIO_S390_DEVICE_CLASS(klass
);
531 k
->init
= s390_virtio_serial_init
;
532 dc
->props
= s390_virtio_serial_properties
;
535 static const TypeInfo s390_virtio_serial
= {
536 .name
= TYPE_VIRTIO_SERIAL_S390
,
537 .parent
= TYPE_VIRTIO_S390_DEVICE
,
538 .instance_size
= sizeof(VirtIOSerialS390
),
539 .instance_init
= s390_virtio_serial_instance_init
,
540 .class_init
= s390_virtio_serial_class_init
,
543 static void s390_virtio_rng_class_init(ObjectClass
*klass
, void *data
)
545 VirtIOS390DeviceClass
*k
= VIRTIO_S390_DEVICE_CLASS(klass
);
547 k
->init
= s390_virtio_rng_init
;
550 static const TypeInfo s390_virtio_rng
= {
551 .name
= TYPE_VIRTIO_RNG_S390
,
552 .parent
= TYPE_VIRTIO_S390_DEVICE
,
553 .instance_size
= sizeof(VirtIORNGS390
),
554 .instance_init
= s390_virtio_rng_instance_init
,
555 .class_init
= s390_virtio_rng_class_init
,
558 static int s390_virtio_busdev_init(DeviceState
*dev
)
560 VirtIOS390Device
*_dev
= (VirtIOS390Device
*)dev
;
561 VirtIOS390DeviceClass
*_info
= VIRTIO_S390_DEVICE_GET_CLASS(dev
);
563 virtio_s390_bus_new(&_dev
->bus
, _dev
);
565 return _info
->init(_dev
);
568 static void s390_virtio_busdev_reset(DeviceState
*dev
)
570 VirtIOS390Device
*_dev
= (VirtIOS390Device
*)dev
;
572 virtio_reset(_dev
->vdev
);
575 static void virtio_s390_device_class_init(ObjectClass
*klass
, void *data
)
577 DeviceClass
*dc
= DEVICE_CLASS(klass
);
579 dc
->init
= s390_virtio_busdev_init
;
580 dc
->bus_type
= TYPE_S390_VIRTIO_BUS
;
581 dc
->unplug
= qdev_simple_unplug_cb
;
582 dc
->reset
= s390_virtio_busdev_reset
;
585 static const TypeInfo virtio_s390_device_info
= {
586 .name
= TYPE_VIRTIO_S390_DEVICE
,
587 .parent
= TYPE_DEVICE
,
588 .instance_size
= sizeof(VirtIOS390Device
),
589 .class_init
= virtio_s390_device_class_init
,
590 .class_size
= sizeof(VirtIOS390DeviceClass
),
594 static Property s390_virtio_scsi_properties
[] = {
595 DEFINE_VIRTIO_SCSI_PROPERTIES(VirtIOSCSIS390
, vdev
.parent_obj
.conf
),
596 DEFINE_VIRTIO_SCSI_FEATURES(VirtIOS390Device
, host_features
),
597 DEFINE_PROP_END_OF_LIST(),
600 static void s390_virtio_scsi_class_init(ObjectClass
*klass
, void *data
)
602 DeviceClass
*dc
= DEVICE_CLASS(klass
);
603 VirtIOS390DeviceClass
*k
= VIRTIO_S390_DEVICE_CLASS(klass
);
605 k
->init
= s390_virtio_scsi_init
;
606 dc
->props
= s390_virtio_scsi_properties
;
609 static const TypeInfo s390_virtio_scsi
= {
610 .name
= TYPE_VIRTIO_SCSI_S390
,
611 .parent
= TYPE_VIRTIO_S390_DEVICE
,
612 .instance_size
= sizeof(VirtIOSCSIS390
),
613 .instance_init
= s390_virtio_scsi_instance_init
,
614 .class_init
= s390_virtio_scsi_class_init
,
617 #ifdef CONFIG_VHOST_SCSI
618 static Property s390_vhost_scsi_properties
[] = {
619 DEFINE_VIRTIO_COMMON_FEATURES(VirtIOS390Device
, host_features
),
620 DEFINE_VHOST_SCSI_PROPERTIES(VHostSCSIS390
, vdev
.parent_obj
.conf
),
621 DEFINE_PROP_END_OF_LIST(),
624 static void s390_vhost_scsi_class_init(ObjectClass
*klass
, void *data
)
626 DeviceClass
*dc
= DEVICE_CLASS(klass
);
627 VirtIOS390DeviceClass
*k
= VIRTIO_S390_DEVICE_CLASS(klass
);
629 k
->init
= s390_vhost_scsi_init
;
630 dc
->props
= s390_vhost_scsi_properties
;
633 static const TypeInfo s390_vhost_scsi
= {
634 .name
= TYPE_VHOST_SCSI_S390
,
635 .parent
= TYPE_VIRTIO_S390_DEVICE
,
636 .instance_size
= sizeof(VHostSCSIS390
),
637 .instance_init
= s390_vhost_scsi_instance_init
,
638 .class_init
= s390_vhost_scsi_class_init
,
642 /***************** S390 Virtio Bus Bridge Device *******************/
643 /* Only required to have the virtio bus as child in the system bus */
645 static int s390_virtio_bridge_init(SysBusDevice
*dev
)
651 static void s390_virtio_bridge_class_init(ObjectClass
*klass
, void *data
)
653 DeviceClass
*dc
= DEVICE_CLASS(klass
);
654 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
656 k
->init
= s390_virtio_bridge_init
;
660 static const TypeInfo s390_virtio_bridge_info
= {
661 .name
= "s390-virtio-bridge",
662 .parent
= TYPE_SYS_BUS_DEVICE
,
663 .instance_size
= sizeof(SysBusDevice
),
664 .class_init
= s390_virtio_bridge_class_init
,
667 /* virtio-s390-bus */
669 static void virtio_s390_bus_new(VirtioBusState
*bus
, VirtIOS390Device
*dev
)
671 DeviceState
*qdev
= DEVICE(dev
);
673 qbus_create_inplace((BusState
*)bus
, TYPE_VIRTIO_S390_BUS
, qdev
, NULL
);
675 qbus
->allow_hotplug
= 1;
678 static void virtio_s390_bus_class_init(ObjectClass
*klass
, void *data
)
680 VirtioBusClass
*k
= VIRTIO_BUS_CLASS(klass
);
681 BusClass
*bus_class
= BUS_CLASS(klass
);
682 bus_class
->max_dev
= 1;
683 k
->notify
= virtio_s390_notify
;
684 k
->get_features
= virtio_s390_get_features
;
687 static const TypeInfo virtio_s390_bus_info
= {
688 .name
= TYPE_VIRTIO_S390_BUS
,
689 .parent
= TYPE_VIRTIO_BUS
,
690 .instance_size
= sizeof(VirtioS390BusState
),
691 .class_init
= virtio_s390_bus_class_init
,
694 static void s390_virtio_register_types(void)
696 type_register_static(&virtio_s390_bus_info
);
697 type_register_static(&s390_virtio_bus_info
);
698 type_register_static(&virtio_s390_device_info
);
699 type_register_static(&s390_virtio_serial
);
700 type_register_static(&s390_virtio_blk
);
701 type_register_static(&s390_virtio_net
);
702 type_register_static(&s390_virtio_scsi
);
703 type_register_static(&s390_vhost_scsi
);
704 type_register_static(&s390_virtio_rng
);
705 type_register_static(&s390_virtio_bridge_info
);
708 type_init(s390_virtio_register_types
)