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 "sysemu/block-backend.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 static void virtio_s390_bus_new(VirtioBusState
*bus
, size_t bus_size
,
49 VirtIOS390Device
*dev
);
51 static const TypeInfo s390_virtio_bus_info
= {
52 .name
= TYPE_S390_VIRTIO_BUS
,
54 .instance_size
= sizeof(VirtIOS390Bus
),
57 static ram_addr_t
s390_virtio_device_num_vq(VirtIOS390Device
*dev
);
59 /* length of VirtIO device pages */
60 const hwaddr virtio_size
= S390_DEVICE_PAGES
* TARGET_PAGE_SIZE
;
62 static void s390_virtio_bus_reset(void *opaque
)
64 VirtIOS390Bus
*bus
= opaque
;
65 bus
->next_ring
= bus
->dev_page
+ TARGET_PAGE_SIZE
;
68 void s390_virtio_reset_idx(VirtIOS390Device
*dev
)
74 num_vq
= s390_virtio_device_num_vq(dev
);
75 for (i
= 0; i
< num_vq
; i
++) {
76 idx_addr
= virtio_queue_get_avail_addr(dev
->vdev
, i
) +
77 VIRTIO_VRING_AVAIL_IDX_OFFS
;
78 address_space_stw(&address_space_memory
, idx_addr
, 0,
79 MEMTXATTRS_UNSPECIFIED
, NULL
);
80 idx_addr
= virtio_queue_get_avail_addr(dev
->vdev
, i
) +
81 virtio_queue_get_avail_size(dev
->vdev
, i
);
82 address_space_stw(&address_space_memory
, idx_addr
, 0,
83 MEMTXATTRS_UNSPECIFIED
, NULL
);
84 idx_addr
= virtio_queue_get_used_addr(dev
->vdev
, i
) +
85 VIRTIO_VRING_USED_IDX_OFFS
;
86 address_space_stw(&address_space_memory
, idx_addr
, 0,
87 MEMTXATTRS_UNSPECIFIED
, NULL
);
88 idx_addr
= virtio_queue_get_used_addr(dev
->vdev
, i
) +
89 virtio_queue_get_used_size(dev
->vdev
, i
);
90 address_space_stw(&address_space_memory
, idx_addr
, 0,
91 MEMTXATTRS_UNSPECIFIED
, NULL
);
95 VirtIOS390Bus
*s390_virtio_bus_init(ram_addr_t
*ram_size
)
101 /* Create bridge device */
102 dev
= qdev_create(NULL
, "s390-virtio-bridge");
103 qdev_init_nofail(dev
);
105 /* Create bus on bridge device */
107 _bus
= qbus_create(TYPE_S390_VIRTIO_BUS
, dev
, "s390-virtio");
108 bus
= DO_UPCAST(VirtIOS390Bus
, bus
, _bus
);
110 bus
->dev_page
= *ram_size
;
111 bus
->dev_offs
= bus
->dev_page
;
112 bus
->next_ring
= bus
->dev_page
+ TARGET_PAGE_SIZE
;
114 /* Enable hotplugging */
115 qbus_set_hotplug_handler(_bus
, dev
, &error_abort
);
117 /* Allocate RAM for VirtIO device pages (descriptors, queues, rings) */
118 *ram_size
+= S390_DEVICE_PAGES
* TARGET_PAGE_SIZE
;
120 qemu_register_reset(s390_virtio_bus_reset
, bus
);
124 static void s390_virtio_device_init(VirtIOS390Device
*dev
,
130 bus
= DO_UPCAST(VirtIOS390Bus
, bus
, dev
->qdev
.parent_bus
);
132 dev
->dev_offs
= bus
->dev_offs
;
133 dev
->feat_len
= sizeof(uint32_t); /* always keep 32 bits features */
135 dev_len
= VIRTIO_DEV_OFFS_CONFIG
;
136 dev_len
+= s390_virtio_device_num_vq(dev
) * VIRTIO_VQCONFIG_LEN
;
137 dev_len
+= dev
->feat_len
* 2;
138 dev_len
+= virtio_bus_get_vdev_config_len(&dev
->bus
);
140 bus
->dev_offs
+= dev_len
;
142 dev
->host_features
= virtio_bus_get_vdev_features(&dev
->bus
,
144 s390_virtio_device_sync(dev
);
145 s390_virtio_reset_idx(dev
);
146 if (dev
->qdev
.hotplugged
) {
147 s390_virtio_irq(VIRTIO_PARAM_DEV_ADD
, dev
->dev_offs
);
151 static void s390_virtio_net_realize(VirtIOS390Device
*s390_dev
, Error
**errp
)
153 DeviceState
*qdev
= DEVICE(s390_dev
);
154 VirtIONetS390
*dev
= VIRTIO_NET_S390(s390_dev
);
155 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
158 virtio_net_set_netclient_name(&dev
->vdev
, qdev
->id
,
159 object_get_typename(OBJECT(qdev
)));
160 qdev_set_parent_bus(vdev
, BUS(&s390_dev
->bus
));
161 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
163 error_propagate(errp
, err
);
167 s390_virtio_device_init(s390_dev
, VIRTIO_DEVICE(vdev
));
170 static void s390_virtio_net_instance_init(Object
*obj
)
172 VirtIONetS390
*dev
= VIRTIO_NET_S390(obj
);
174 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
176 object_property_add_alias(obj
, "bootindex", OBJECT(&dev
->vdev
),
177 "bootindex", &error_abort
);
180 static void s390_virtio_blk_realize(VirtIOS390Device
*s390_dev
, Error
**errp
)
182 VirtIOBlkS390
*dev
= VIRTIO_BLK_S390(s390_dev
);
183 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
186 qdev_set_parent_bus(vdev
, BUS(&s390_dev
->bus
));
187 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
189 error_propagate(errp
, err
);
192 s390_virtio_device_init(s390_dev
, VIRTIO_DEVICE(vdev
));
195 static void s390_virtio_blk_instance_init(Object
*obj
)
197 VirtIOBlkS390
*dev
= VIRTIO_BLK_S390(obj
);
199 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
201 object_property_add_alias(obj
, "iothread", OBJECT(&dev
->vdev
),"iothread",
203 object_property_add_alias(obj
, "bootindex", OBJECT(&dev
->vdev
),
204 "bootindex", &error_abort
);
207 static void s390_virtio_serial_realize(VirtIOS390Device
*s390_dev
, Error
**errp
)
209 VirtIOSerialS390
*dev
= VIRTIO_SERIAL_S390(s390_dev
);
210 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
211 DeviceState
*qdev
= DEVICE(s390_dev
);
216 bus
= DO_UPCAST(VirtIOS390Bus
, bus
, qdev
->parent_bus
);
219 * For command line compatibility, this sets the virtio-serial-device bus
223 bus_name
= g_strdup_printf("%s.0", qdev
->id
);
224 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev
), bus_name
);
228 qdev_set_parent_bus(vdev
, BUS(&s390_dev
->bus
));
229 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
231 error_propagate(errp
, err
);
235 s390_virtio_device_init(s390_dev
, VIRTIO_DEVICE(vdev
));
236 bus
->console
= s390_dev
;
239 static void s390_virtio_serial_instance_init(Object
*obj
)
241 VirtIOSerialS390
*dev
= VIRTIO_SERIAL_S390(obj
);
243 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
247 static void s390_virtio_scsi_realize(VirtIOS390Device
*s390_dev
, Error
**errp
)
249 VirtIOSCSIS390
*dev
= VIRTIO_SCSI_S390(s390_dev
);
250 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
251 DeviceState
*qdev
= DEVICE(s390_dev
);
256 * For command line compatibility, this sets the virtio-scsi-device bus
260 bus_name
= g_strdup_printf("%s.0", qdev
->id
);
261 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev
), bus_name
);
265 qdev_set_parent_bus(vdev
, BUS(&s390_dev
->bus
));
266 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
268 error_propagate(errp
, err
);
272 s390_virtio_device_init(s390_dev
, VIRTIO_DEVICE(vdev
));
275 static void s390_virtio_scsi_instance_init(Object
*obj
)
277 VirtIOSCSIS390
*dev
= VIRTIO_SCSI_S390(obj
);
279 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
283 #ifdef CONFIG_VHOST_SCSI
284 static void s390_vhost_scsi_realize(VirtIOS390Device
*s390_dev
, Error
**errp
)
286 VHostSCSIS390
*dev
= VHOST_SCSI_S390(s390_dev
);
287 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
290 qdev_set_parent_bus(vdev
, BUS(&s390_dev
->bus
));
291 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
293 error_propagate(errp
, err
);
297 s390_virtio_device_init(s390_dev
, VIRTIO_DEVICE(vdev
));
300 static void s390_vhost_scsi_instance_init(Object
*obj
)
302 VHostSCSIS390
*dev
= VHOST_SCSI_S390(obj
);
304 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
310 static void s390_virtio_rng_realize(VirtIOS390Device
*s390_dev
, Error
**errp
)
312 VirtIORNGS390
*dev
= VIRTIO_RNG_S390(s390_dev
);
313 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
316 qdev_set_parent_bus(vdev
, BUS(&s390_dev
->bus
));
317 object_property_set_bool(OBJECT(vdev
), true, "realized", &err
);
319 error_propagate(errp
, err
);
323 object_property_set_link(OBJECT(dev
),
324 OBJECT(dev
->vdev
.conf
.rng
), "rng",
327 s390_virtio_device_init(s390_dev
, VIRTIO_DEVICE(vdev
));
330 static void s390_virtio_rng_instance_init(Object
*obj
)
332 VirtIORNGS390
*dev
= VIRTIO_RNG_S390(obj
);
334 virtio_instance_init_common(obj
, &dev
->vdev
, sizeof(dev
->vdev
),
336 object_property_add_alias(obj
, "rng", OBJECT(&dev
->vdev
),
337 "rng", &error_abort
);
340 static uint64_t s390_virtio_device_vq_token(VirtIOS390Device
*dev
, int vq
)
342 ram_addr_t token_off
;
344 token_off
= (dev
->dev_offs
+ VIRTIO_DEV_OFFS_CONFIG
) +
345 (vq
* VIRTIO_VQCONFIG_LEN
) +
346 VIRTIO_VQCONFIG_OFFS_TOKEN
;
348 return address_space_ldq_be(&address_space_memory
, token_off
,
349 MEMTXATTRS_UNSPECIFIED
, NULL
);
352 static ram_addr_t
s390_virtio_device_num_vq(VirtIOS390Device
*dev
)
354 VirtIODevice
*vdev
= dev
->vdev
;
357 for (num_vq
= 0; num_vq
< VIRTIO_PCI_QUEUE_MAX
; num_vq
++) {
358 if (!virtio_queue_get_num(vdev
, num_vq
)) {
366 static ram_addr_t
s390_virtio_next_ring(VirtIOS390Bus
*bus
)
368 ram_addr_t r
= bus
->next_ring
;
370 bus
->next_ring
+= VIRTIO_RING_LEN
;
374 void s390_virtio_device_sync(VirtIOS390Device
*dev
)
376 VirtIOS390Bus
*bus
= DO_UPCAST(VirtIOS390Bus
, bus
, dev
->qdev
.parent_bus
);
381 virtio_reset(dev
->vdev
);
384 address_space_stb(&address_space_memory
,
385 dev
->dev_offs
+ VIRTIO_DEV_OFFS_TYPE
,
386 dev
->vdev
->device_id
,
387 MEMTXATTRS_UNSPECIFIED
,
390 address_space_stb(&address_space_memory
,
391 dev
->dev_offs
+ VIRTIO_DEV_OFFS_NUM_VQ
,
392 s390_virtio_device_num_vq(dev
),
393 MEMTXATTRS_UNSPECIFIED
,
395 address_space_stb(&address_space_memory
,
396 dev
->dev_offs
+ VIRTIO_DEV_OFFS_FEATURE_LEN
,
398 MEMTXATTRS_UNSPECIFIED
,
401 address_space_stb(&address_space_memory
,
402 dev
->dev_offs
+ VIRTIO_DEV_OFFS_CONFIG_LEN
,
403 dev
->vdev
->config_len
,
404 MEMTXATTRS_UNSPECIFIED
,
407 num_vq
= s390_virtio_device_num_vq(dev
);
408 address_space_stb(&address_space_memory
,
409 dev
->dev_offs
+ VIRTIO_DEV_OFFS_NUM_VQ
, num_vq
,
410 MEMTXATTRS_UNSPECIFIED
, NULL
);
412 /* Sync virtqueues */
413 for (i
= 0; i
< num_vq
; i
++) {
414 ram_addr_t vq
= (dev
->dev_offs
+ VIRTIO_DEV_OFFS_CONFIG
) +
415 (i
* VIRTIO_VQCONFIG_LEN
);
418 vring
= s390_virtio_next_ring(bus
);
419 virtio_queue_set_addr(dev
->vdev
, i
, vring
);
420 virtio_queue_set_vector(dev
->vdev
, i
, i
);
421 address_space_stq_be(&address_space_memory
,
422 vq
+ VIRTIO_VQCONFIG_OFFS_ADDRESS
, vring
,
423 MEMTXATTRS_UNSPECIFIED
, NULL
);
424 address_space_stw_be(&address_space_memory
,
425 vq
+ VIRTIO_VQCONFIG_OFFS_NUM
,
426 virtio_queue_get_num(dev
->vdev
, i
),
427 MEMTXATTRS_UNSPECIFIED
,
431 cur_offs
= dev
->dev_offs
;
432 cur_offs
+= VIRTIO_DEV_OFFS_CONFIG
;
433 cur_offs
+= num_vq
* VIRTIO_VQCONFIG_LEN
;
435 /* Sync feature bitmap */
436 address_space_stl_le(&address_space_memory
, cur_offs
, dev
->host_features
,
437 MEMTXATTRS_UNSPECIFIED
, NULL
);
439 dev
->feat_offs
= cur_offs
+ dev
->feat_len
;
440 cur_offs
+= dev
->feat_len
* 2;
442 /* Sync config space */
443 virtio_bus_get_vdev_config(&dev
->bus
, dev
->vdev
->config
);
445 cpu_physical_memory_write(cur_offs
,
446 dev
->vdev
->config
, dev
->vdev
->config_len
);
447 cur_offs
+= dev
->vdev
->config_len
;
450 void s390_virtio_device_update_status(VirtIOS390Device
*dev
)
452 VirtIODevice
*vdev
= dev
->vdev
;
455 virtio_set_status(vdev
,
456 address_space_ldub(&address_space_memory
,
457 dev
->dev_offs
+ VIRTIO_DEV_OFFS_STATUS
,
458 MEMTXATTRS_UNSPECIFIED
, NULL
));
460 /* Update guest supported feature bitmap */
462 features
= bswap32(address_space_ldl_be(&address_space_memory
,
464 MEMTXATTRS_UNSPECIFIED
, NULL
));
465 virtio_set_features(vdev
, features
);
468 /* Find a device by vring address */
469 VirtIOS390Device
*s390_virtio_bus_find_vring(VirtIOS390Bus
*bus
,
476 QTAILQ_FOREACH(kid
, &bus
->bus
.children
, sibling
) {
477 VirtIOS390Device
*dev
= (VirtIOS390Device
*)kid
->child
;
479 for(i
= 0; i
< VIRTIO_PCI_QUEUE_MAX
; i
++) {
480 if (!virtio_queue_get_addr(dev
->vdev
, i
))
482 if (virtio_queue_get_addr(dev
->vdev
, i
) == mem
) {
494 /* Find a device by device descriptor location */
495 VirtIOS390Device
*s390_virtio_bus_find_mem(VirtIOS390Bus
*bus
, ram_addr_t mem
)
499 QTAILQ_FOREACH(kid
, &bus
->bus
.children
, sibling
) {
500 VirtIOS390Device
*dev
= (VirtIOS390Device
*)kid
->child
;
501 if (dev
->dev_offs
== mem
) {
509 /* DeviceState to VirtIOS390Device. Note: used on datapath,
510 * be careful and test performance if you change this.
512 static inline VirtIOS390Device
*to_virtio_s390_device_fast(DeviceState
*d
)
514 return container_of(d
, VirtIOS390Device
, qdev
);
517 /* DeviceState to VirtIOS390Device. TODO: use QOM. */
518 static inline VirtIOS390Device
*to_virtio_s390_device(DeviceState
*d
)
520 return container_of(d
, VirtIOS390Device
, qdev
);
523 static void virtio_s390_notify(DeviceState
*d
, uint16_t vector
)
525 VirtIOS390Device
*dev
= to_virtio_s390_device_fast(d
);
526 uint64_t token
= s390_virtio_device_vq_token(dev
, vector
);
528 s390_virtio_irq(0, token
);
531 static unsigned virtio_s390_get_features(DeviceState
*d
)
533 VirtIOS390Device
*dev
= to_virtio_s390_device(d
);
534 return dev
->host_features
;
537 /**************** S390 Virtio Bus Device Descriptions *******************/
539 static void s390_virtio_net_class_init(ObjectClass
*klass
, void *data
)
541 DeviceClass
*dc
= DEVICE_CLASS(klass
);
542 VirtIOS390DeviceClass
*k
= VIRTIO_S390_DEVICE_CLASS(klass
);
544 k
->realize
= s390_virtio_net_realize
;
545 set_bit(DEVICE_CATEGORY_NETWORK
, dc
->categories
);
548 static const TypeInfo s390_virtio_net
= {
549 .name
= TYPE_VIRTIO_NET_S390
,
550 .parent
= TYPE_VIRTIO_S390_DEVICE
,
551 .instance_size
= sizeof(VirtIONetS390
),
552 .instance_init
= s390_virtio_net_instance_init
,
553 .class_init
= s390_virtio_net_class_init
,
556 static void s390_virtio_blk_class_init(ObjectClass
*klass
, void *data
)
558 VirtIOS390DeviceClass
*k
= VIRTIO_S390_DEVICE_CLASS(klass
);
559 DeviceClass
*dc
= DEVICE_CLASS(klass
);
561 k
->realize
= s390_virtio_blk_realize
;
562 set_bit(DEVICE_CATEGORY_STORAGE
, dc
->categories
);
565 static const TypeInfo s390_virtio_blk
= {
566 .name
= "virtio-blk-s390",
567 .parent
= TYPE_VIRTIO_S390_DEVICE
,
568 .instance_size
= sizeof(VirtIOBlkS390
),
569 .instance_init
= s390_virtio_blk_instance_init
,
570 .class_init
= s390_virtio_blk_class_init
,
573 static Property s390_virtio_serial_properties
[] = {
574 DEFINE_PROP_END_OF_LIST(),
577 static void s390_virtio_serial_class_init(ObjectClass
*klass
, void *data
)
579 DeviceClass
*dc
= DEVICE_CLASS(klass
);
580 VirtIOS390DeviceClass
*k
= VIRTIO_S390_DEVICE_CLASS(klass
);
582 k
->realize
= s390_virtio_serial_realize
;
583 dc
->props
= s390_virtio_serial_properties
;
584 set_bit(DEVICE_CATEGORY_INPUT
, dc
->categories
);
587 static const TypeInfo s390_virtio_serial
= {
588 .name
= TYPE_VIRTIO_SERIAL_S390
,
589 .parent
= TYPE_VIRTIO_S390_DEVICE
,
590 .instance_size
= sizeof(VirtIOSerialS390
),
591 .instance_init
= s390_virtio_serial_instance_init
,
592 .class_init
= s390_virtio_serial_class_init
,
595 static void s390_virtio_rng_class_init(ObjectClass
*klass
, void *data
)
597 DeviceClass
*dc
= DEVICE_CLASS(klass
);
598 VirtIOS390DeviceClass
*k
= VIRTIO_S390_DEVICE_CLASS(klass
);
600 k
->realize
= s390_virtio_rng_realize
;
601 set_bit(DEVICE_CATEGORY_MISC
, dc
->categories
);
604 static const TypeInfo s390_virtio_rng
= {
605 .name
= TYPE_VIRTIO_RNG_S390
,
606 .parent
= TYPE_VIRTIO_S390_DEVICE
,
607 .instance_size
= sizeof(VirtIORNGS390
),
608 .instance_init
= s390_virtio_rng_instance_init
,
609 .class_init
= s390_virtio_rng_class_init
,
612 static void s390_virtio_busdev_realize(DeviceState
*dev
, Error
**errp
)
614 VirtIOS390Device
*_dev
= (VirtIOS390Device
*)dev
;
615 VirtIOS390DeviceClass
*_info
= VIRTIO_S390_DEVICE_GET_CLASS(dev
);
617 virtio_s390_bus_new(&_dev
->bus
, sizeof(_dev
->bus
), _dev
);
619 _info
->realize(_dev
, errp
);
622 static void s390_virtio_busdev_reset(DeviceState
*dev
)
624 VirtIOS390Device
*_dev
= (VirtIOS390Device
*)dev
;
626 virtio_reset(_dev
->vdev
);
629 static Property virtio_s390_properties
[] = {
630 DEFINE_VIRTIO_COMMON_FEATURES(VirtIOS390Device
, host_features
),
631 DEFINE_PROP_END_OF_LIST(),
634 static void virtio_s390_device_class_init(ObjectClass
*klass
, void *data
)
636 DeviceClass
*dc
= DEVICE_CLASS(klass
);
638 dc
->props
= virtio_s390_properties
;
639 dc
->realize
= s390_virtio_busdev_realize
;
640 dc
->bus_type
= TYPE_S390_VIRTIO_BUS
;
641 dc
->reset
= s390_virtio_busdev_reset
;
644 static const TypeInfo virtio_s390_device_info
= {
645 .name
= TYPE_VIRTIO_S390_DEVICE
,
646 .parent
= TYPE_DEVICE
,
647 .instance_size
= sizeof(VirtIOS390Device
),
648 .class_init
= virtio_s390_device_class_init
,
649 .class_size
= sizeof(VirtIOS390DeviceClass
),
653 static void s390_virtio_scsi_class_init(ObjectClass
*klass
, void *data
)
655 DeviceClass
*dc
= DEVICE_CLASS(klass
);
656 VirtIOS390DeviceClass
*k
= VIRTIO_S390_DEVICE_CLASS(klass
);
658 k
->realize
= s390_virtio_scsi_realize
;
659 set_bit(DEVICE_CATEGORY_STORAGE
, dc
->categories
);
662 static const TypeInfo s390_virtio_scsi
= {
663 .name
= TYPE_VIRTIO_SCSI_S390
,
664 .parent
= TYPE_VIRTIO_S390_DEVICE
,
665 .instance_size
= sizeof(VirtIOSCSIS390
),
666 .instance_init
= s390_virtio_scsi_instance_init
,
667 .class_init
= s390_virtio_scsi_class_init
,
670 #ifdef CONFIG_VHOST_SCSI
671 static void s390_vhost_scsi_class_init(ObjectClass
*klass
, void *data
)
673 DeviceClass
*dc
= DEVICE_CLASS(klass
);
674 VirtIOS390DeviceClass
*k
= VIRTIO_S390_DEVICE_CLASS(klass
);
676 k
->realize
= s390_vhost_scsi_realize
;
677 set_bit(DEVICE_CATEGORY_STORAGE
, dc
->categories
);
680 static const TypeInfo s390_vhost_scsi
= {
681 .name
= TYPE_VHOST_SCSI_S390
,
682 .parent
= TYPE_VIRTIO_S390_DEVICE
,
683 .instance_size
= sizeof(VHostSCSIS390
),
684 .instance_init
= s390_vhost_scsi_instance_init
,
685 .class_init
= s390_vhost_scsi_class_init
,
689 /***************** S390 Virtio Bus Bridge Device *******************/
690 /* Only required to have the virtio bus as child in the system bus */
692 static int s390_virtio_bridge_init(SysBusDevice
*dev
)
698 static void s390_virtio_bridge_class_init(ObjectClass
*klass
, void *data
)
700 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
701 DeviceClass
*dc
= DEVICE_CLASS(klass
);
703 k
->init
= s390_virtio_bridge_init
;
704 set_bit(DEVICE_CATEGORY_BRIDGE
, dc
->categories
);
707 static const TypeInfo s390_virtio_bridge_info
= {
708 .name
= "s390-virtio-bridge",
709 .parent
= TYPE_SYS_BUS_DEVICE
,
710 .instance_size
= sizeof(SysBusDevice
),
711 .class_init
= s390_virtio_bridge_class_init
,
712 .interfaces
= (InterfaceInfo
[]) {
713 { TYPE_HOTPLUG_HANDLER
},
718 /* virtio-s390-bus */
720 static void virtio_s390_bus_new(VirtioBusState
*bus
, size_t bus_size
,
721 VirtIOS390Device
*dev
)
723 DeviceState
*qdev
= DEVICE(dev
);
724 char virtio_bus_name
[] = "virtio-bus";
726 qbus_create_inplace(bus
, bus_size
, TYPE_VIRTIO_S390_BUS
,
727 qdev
, virtio_bus_name
);
730 static void virtio_s390_bus_class_init(ObjectClass
*klass
, void *data
)
732 VirtioBusClass
*k
= VIRTIO_BUS_CLASS(klass
);
733 BusClass
*bus_class
= BUS_CLASS(klass
);
734 bus_class
->max_dev
= 1;
735 k
->notify
= virtio_s390_notify
;
736 k
->get_features
= virtio_s390_get_features
;
739 static const TypeInfo virtio_s390_bus_info
= {
740 .name
= TYPE_VIRTIO_S390_BUS
,
741 .parent
= TYPE_VIRTIO_BUS
,
742 .instance_size
= sizeof(VirtioS390BusState
),
743 .class_init
= virtio_s390_bus_class_init
,
746 static void s390_virtio_register_types(void)
748 type_register_static(&virtio_s390_bus_info
);
749 type_register_static(&s390_virtio_bus_info
);
750 type_register_static(&virtio_s390_device_info
);
751 type_register_static(&s390_virtio_serial
);
752 type_register_static(&s390_virtio_blk
);
753 type_register_static(&s390_virtio_net
);
754 type_register_static(&s390_virtio_scsi
);
755 #ifdef CONFIG_VHOST_SCSI
756 type_register_static(&s390_vhost_scsi
);
758 type_register_static(&s390_virtio_rng
);
759 type_register_static(&s390_virtio_bridge_info
);
762 type_init(s390_virtio_register_types
)