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 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 stw_phys(&address_space_memory
, idx_addr
, 0);
79 idx_addr
= virtio_queue_get_used_addr(dev
->vdev
, i
) +
80 VIRTIO_VRING_USED_IDX_OFFS
;
81 stw_phys(&address_space_memory
, idx_addr
, 0);
85 VirtIOS390Bus
*s390_virtio_bus_init(ram_addr_t
*ram_size
)
91 /* Create bridge device */
92 dev
= qdev_create(NULL
, "s390-virtio-bridge");
93 qdev_init_nofail(dev
);
95 /* Create bus on bridge device */
97 _bus
= qbus_create(TYPE_S390_VIRTIO_BUS
, dev
, "s390-virtio");
98 bus
= DO_UPCAST(VirtIOS390Bus
, bus
, _bus
);
100 bus
->dev_page
= *ram_size
;
101 bus
->dev_offs
= bus
->dev_page
;
102 bus
->next_ring
= bus
->dev_page
+ TARGET_PAGE_SIZE
;
104 /* Enable hotplugging */
105 _bus
->allow_hotplug
= 1;
107 /* Allocate RAM for VirtIO device pages (descriptors, queues, rings) */
108 *ram_size
+= S390_DEVICE_PAGES
* TARGET_PAGE_SIZE
;
110 qemu_register_reset(s390_virtio_bus_reset
, bus
);
114 static int s390_virtio_device_init(VirtIOS390Device
*dev
, VirtIODevice
*vdev
)
119 bus
= DO_UPCAST(VirtIOS390Bus
, bus
, dev
->qdev
.parent_bus
);
121 dev
->dev_offs
= bus
->dev_offs
;
122 dev
->feat_len
= sizeof(uint32_t); /* always keep 32 bits features */
124 dev_len
= VIRTIO_DEV_OFFS_CONFIG
;
125 dev_len
+= s390_virtio_device_num_vq(dev
) * VIRTIO_VQCONFIG_LEN
;
126 dev_len
+= dev
->feat_len
* 2;
127 dev_len
+= virtio_bus_get_vdev_config_len(&dev
->bus
);
129 bus
->dev_offs
+= dev_len
;
131 dev
->host_features
= virtio_bus_get_vdev_features(&dev
->bus
,
133 s390_virtio_device_sync(dev
);
134 s390_virtio_reset_idx(dev
);
135 if (dev
->qdev
.hotplugged
) {
136 s390_virtio_irq(VIRTIO_PARAM_DEV_ADD
, dev
->dev_offs
);
142 static int s390_virtio_net_init(VirtIOS390Device
*s390_dev
)
144 DeviceState
*qdev
= DEVICE(s390_dev
);
145 VirtIONetS390
*dev
= VIRTIO_NET_S390(s390_dev
);
146 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
148 virtio_net_set_config_size(&dev
->vdev
, s390_dev
->host_features
);
149 virtio_net_set_netclient_name(&dev
->vdev
, qdev
->id
,
150 object_get_typename(OBJECT(qdev
)));
151 qdev_set_parent_bus(vdev
, BUS(&s390_dev
->bus
));
152 if (qdev_init(vdev
) < 0) {
156 return s390_virtio_device_init(s390_dev
, VIRTIO_DEVICE(vdev
));
159 static void s390_virtio_net_instance_init(Object
*obj
)
161 VirtIONetS390
*dev
= VIRTIO_NET_S390(obj
);
162 object_initialize(&dev
->vdev
, sizeof(dev
->vdev
), TYPE_VIRTIO_NET
);
163 object_property_add_child(obj
, "virtio-backend", OBJECT(&dev
->vdev
), NULL
);
166 static int s390_virtio_blk_init(VirtIOS390Device
*s390_dev
)
168 VirtIOBlkS390
*dev
= VIRTIO_BLK_S390(s390_dev
);
169 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
170 virtio_blk_set_conf(vdev
, &(dev
->blk
));
171 qdev_set_parent_bus(vdev
, BUS(&s390_dev
->bus
));
172 if (qdev_init(vdev
) < 0) {
175 return s390_virtio_device_init(s390_dev
, VIRTIO_DEVICE(vdev
));
178 static void s390_virtio_blk_instance_init(Object
*obj
)
180 VirtIOBlkS390
*dev
= VIRTIO_BLK_S390(obj
);
181 object_initialize(&dev
->vdev
, sizeof(dev
->vdev
), TYPE_VIRTIO_BLK
);
182 object_property_add_child(obj
, "virtio-backend", OBJECT(&dev
->vdev
), NULL
);
185 static int s390_virtio_serial_init(VirtIOS390Device
*s390_dev
)
187 VirtIOSerialS390
*dev
= VIRTIO_SERIAL_S390(s390_dev
);
188 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
189 DeviceState
*qdev
= DEVICE(s390_dev
);
194 bus
= DO_UPCAST(VirtIOS390Bus
, bus
, qdev
->parent_bus
);
197 * For command line compatibility, this sets the virtio-serial-device bus
201 bus_name
= g_strdup_printf("%s.0", qdev
->id
);
202 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev
), bus_name
);
206 qdev_set_parent_bus(vdev
, BUS(&s390_dev
->bus
));
207 if (qdev_init(vdev
) < 0) {
211 r
= s390_virtio_device_init(s390_dev
, VIRTIO_DEVICE(vdev
));
213 bus
->console
= s390_dev
;
219 static void s390_virtio_serial_instance_init(Object
*obj
)
221 VirtIOSerialS390
*dev
= VIRTIO_SERIAL_S390(obj
);
222 object_initialize(&dev
->vdev
, sizeof(dev
->vdev
), TYPE_VIRTIO_SERIAL
);
223 object_property_add_child(obj
, "virtio-backend", OBJECT(&dev
->vdev
), NULL
);
226 static int s390_virtio_scsi_init(VirtIOS390Device
*s390_dev
)
228 VirtIOSCSIS390
*dev
= VIRTIO_SCSI_S390(s390_dev
);
229 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
230 DeviceState
*qdev
= DEVICE(s390_dev
);
234 * For command line compatibility, this sets the virtio-scsi-device bus
238 bus_name
= g_strdup_printf("%s.0", qdev
->id
);
239 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev
), bus_name
);
243 qdev_set_parent_bus(vdev
, BUS(&s390_dev
->bus
));
244 if (qdev_init(vdev
) < 0) {
248 return s390_virtio_device_init(s390_dev
, VIRTIO_DEVICE(vdev
));
251 static void s390_virtio_scsi_instance_init(Object
*obj
)
253 VirtIOSCSIS390
*dev
= VIRTIO_SCSI_S390(obj
);
254 object_initialize(&dev
->vdev
, sizeof(dev
->vdev
), TYPE_VIRTIO_SCSI
);
255 object_property_add_child(obj
, "virtio-backend", OBJECT(&dev
->vdev
), NULL
);
258 #ifdef CONFIG_VHOST_SCSI
259 static int s390_vhost_scsi_init(VirtIOS390Device
*s390_dev
)
261 VHostSCSIS390
*dev
= VHOST_SCSI_S390(s390_dev
);
262 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
264 qdev_set_parent_bus(vdev
, BUS(&s390_dev
->bus
));
265 if (qdev_init(vdev
) < 0) {
269 return s390_virtio_device_init(s390_dev
, VIRTIO_DEVICE(vdev
));
272 static void s390_vhost_scsi_instance_init(Object
*obj
)
274 VHostSCSIS390
*dev
= VHOST_SCSI_S390(obj
);
275 object_initialize(&dev
->vdev
, sizeof(dev
->vdev
), TYPE_VHOST_SCSI
);
276 object_property_add_child(obj
, "virtio-backend", OBJECT(&dev
->vdev
), NULL
);
281 static int s390_virtio_rng_init(VirtIOS390Device
*s390_dev
)
283 VirtIORNGS390
*dev
= VIRTIO_RNG_S390(s390_dev
);
284 DeviceState
*vdev
= DEVICE(&dev
->vdev
);
286 qdev_set_parent_bus(vdev
, BUS(&s390_dev
->bus
));
287 if (qdev_init(vdev
) < 0) {
291 object_property_set_link(OBJECT(dev
),
292 OBJECT(dev
->vdev
.conf
.rng
), "rng",
295 return s390_virtio_device_init(s390_dev
, VIRTIO_DEVICE(vdev
));
298 static void s390_virtio_rng_instance_init(Object
*obj
)
300 VirtIORNGS390
*dev
= VIRTIO_RNG_S390(obj
);
301 object_initialize(&dev
->vdev
, sizeof(dev
->vdev
), TYPE_VIRTIO_RNG
);
302 object_property_add_child(obj
, "virtio-backend", OBJECT(&dev
->vdev
), NULL
);
303 object_property_add_link(obj
, "rng", TYPE_RNG_BACKEND
,
304 (Object
**)&dev
->vdev
.conf
.rng
,
305 qdev_prop_allow_set_link_before_realize
,
306 OBJ_PROP_LINK_UNREF_ON_RELEASE
, NULL
);
309 static uint64_t s390_virtio_device_vq_token(VirtIOS390Device
*dev
, int vq
)
311 ram_addr_t token_off
;
313 token_off
= (dev
->dev_offs
+ VIRTIO_DEV_OFFS_CONFIG
) +
314 (vq
* VIRTIO_VQCONFIG_LEN
) +
315 VIRTIO_VQCONFIG_OFFS_TOKEN
;
317 return ldq_be_phys(&address_space_memory
, token_off
);
320 static ram_addr_t
s390_virtio_device_num_vq(VirtIOS390Device
*dev
)
322 VirtIODevice
*vdev
= dev
->vdev
;
325 for (num_vq
= 0; num_vq
< VIRTIO_PCI_QUEUE_MAX
; num_vq
++) {
326 if (!virtio_queue_get_num(vdev
, num_vq
)) {
334 static ram_addr_t
s390_virtio_next_ring(VirtIOS390Bus
*bus
)
336 ram_addr_t r
= bus
->next_ring
;
338 bus
->next_ring
+= VIRTIO_RING_LEN
;
342 void s390_virtio_device_sync(VirtIOS390Device
*dev
)
344 VirtIOS390Bus
*bus
= DO_UPCAST(VirtIOS390Bus
, bus
, dev
->qdev
.parent_bus
);
349 virtio_reset(dev
->vdev
);
352 stb_phys(&address_space_memory
,
353 dev
->dev_offs
+ VIRTIO_DEV_OFFS_TYPE
, dev
->vdev
->device_id
);
355 stb_phys(&address_space_memory
,
356 dev
->dev_offs
+ VIRTIO_DEV_OFFS_NUM_VQ
,
357 s390_virtio_device_num_vq(dev
));
358 stb_phys(&address_space_memory
,
359 dev
->dev_offs
+ VIRTIO_DEV_OFFS_FEATURE_LEN
, dev
->feat_len
);
361 stb_phys(&address_space_memory
,
362 dev
->dev_offs
+ VIRTIO_DEV_OFFS_CONFIG_LEN
, dev
->vdev
->config_len
);
364 num_vq
= s390_virtio_device_num_vq(dev
);
365 stb_phys(&address_space_memory
,
366 dev
->dev_offs
+ VIRTIO_DEV_OFFS_NUM_VQ
, num_vq
);
368 /* Sync virtqueues */
369 for (i
= 0; i
< num_vq
; i
++) {
370 ram_addr_t vq
= (dev
->dev_offs
+ VIRTIO_DEV_OFFS_CONFIG
) +
371 (i
* VIRTIO_VQCONFIG_LEN
);
374 vring
= s390_virtio_next_ring(bus
);
375 virtio_queue_set_addr(dev
->vdev
, i
, vring
);
376 virtio_queue_set_vector(dev
->vdev
, i
, i
);
377 stq_be_phys(&address_space_memory
,
378 vq
+ VIRTIO_VQCONFIG_OFFS_ADDRESS
, vring
);
379 stw_be_phys(&address_space_memory
,
380 vq
+ VIRTIO_VQCONFIG_OFFS_NUM
,
381 virtio_queue_get_num(dev
->vdev
, i
));
384 cur_offs
= dev
->dev_offs
;
385 cur_offs
+= VIRTIO_DEV_OFFS_CONFIG
;
386 cur_offs
+= num_vq
* VIRTIO_VQCONFIG_LEN
;
388 /* Sync feature bitmap */
389 stl_le_phys(&address_space_memory
, cur_offs
, dev
->host_features
);
391 dev
->feat_offs
= cur_offs
+ dev
->feat_len
;
392 cur_offs
+= dev
->feat_len
* 2;
394 /* Sync config space */
395 virtio_bus_get_vdev_config(&dev
->bus
, dev
->vdev
->config
);
397 cpu_physical_memory_write(cur_offs
,
398 dev
->vdev
->config
, dev
->vdev
->config_len
);
399 cur_offs
+= dev
->vdev
->config_len
;
402 void s390_virtio_device_update_status(VirtIOS390Device
*dev
)
404 VirtIODevice
*vdev
= dev
->vdev
;
407 virtio_set_status(vdev
, ldub_phys(&address_space_memory
,
408 dev
->dev_offs
+ VIRTIO_DEV_OFFS_STATUS
));
410 /* Update guest supported feature bitmap */
412 features
= bswap32(ldl_be_phys(&address_space_memory
, dev
->feat_offs
));
413 virtio_set_features(vdev
, features
);
416 VirtIOS390Device
*s390_virtio_bus_console(VirtIOS390Bus
*bus
)
421 /* Find a device by vring address */
422 VirtIOS390Device
*s390_virtio_bus_find_vring(VirtIOS390Bus
*bus
,
429 QTAILQ_FOREACH(kid
, &bus
->bus
.children
, sibling
) {
430 VirtIOS390Device
*dev
= (VirtIOS390Device
*)kid
->child
;
432 for(i
= 0; i
< VIRTIO_PCI_QUEUE_MAX
; i
++) {
433 if (!virtio_queue_get_addr(dev
->vdev
, i
))
435 if (virtio_queue_get_addr(dev
->vdev
, i
) == mem
) {
447 /* Find a device by device descriptor location */
448 VirtIOS390Device
*s390_virtio_bus_find_mem(VirtIOS390Bus
*bus
, ram_addr_t mem
)
452 QTAILQ_FOREACH(kid
, &bus
->bus
.children
, sibling
) {
453 VirtIOS390Device
*dev
= (VirtIOS390Device
*)kid
->child
;
454 if (dev
->dev_offs
== mem
) {
462 /* DeviceState to VirtIOS390Device. Note: used on datapath,
463 * be careful and test performance if you change this.
465 static inline VirtIOS390Device
*to_virtio_s390_device_fast(DeviceState
*d
)
467 return container_of(d
, VirtIOS390Device
, qdev
);
470 /* DeviceState to VirtIOS390Device. TODO: use QOM. */
471 static inline VirtIOS390Device
*to_virtio_s390_device(DeviceState
*d
)
473 return container_of(d
, VirtIOS390Device
, qdev
);
476 static void virtio_s390_notify(DeviceState
*d
, uint16_t vector
)
478 VirtIOS390Device
*dev
= to_virtio_s390_device_fast(d
);
479 uint64_t token
= s390_virtio_device_vq_token(dev
, vector
);
481 s390_virtio_irq(0, token
);
484 static unsigned virtio_s390_get_features(DeviceState
*d
)
486 VirtIOS390Device
*dev
= to_virtio_s390_device(d
);
487 return dev
->host_features
;
490 /**************** S390 Virtio Bus Device Descriptions *******************/
492 static Property s390_virtio_net_properties
[] = {
493 DEFINE_NIC_PROPERTIES(VirtIONetS390
, vdev
.nic_conf
),
494 DEFINE_VIRTIO_NET_FEATURES(VirtIOS390Device
, host_features
),
495 DEFINE_VIRTIO_NET_PROPERTIES(VirtIONetS390
, vdev
.net_conf
),
496 DEFINE_PROP_END_OF_LIST(),
499 static void s390_virtio_net_class_init(ObjectClass
*klass
, void *data
)
501 DeviceClass
*dc
= DEVICE_CLASS(klass
);
502 VirtIOS390DeviceClass
*k
= VIRTIO_S390_DEVICE_CLASS(klass
);
504 k
->init
= s390_virtio_net_init
;
505 dc
->props
= s390_virtio_net_properties
;
508 static const TypeInfo s390_virtio_net
= {
509 .name
= TYPE_VIRTIO_NET_S390
,
510 .parent
= TYPE_VIRTIO_S390_DEVICE
,
511 .instance_size
= sizeof(VirtIONetS390
),
512 .instance_init
= s390_virtio_net_instance_init
,
513 .class_init
= s390_virtio_net_class_init
,
516 static Property s390_virtio_blk_properties
[] = {
517 DEFINE_VIRTIO_BLK_PROPERTIES(VirtIOBlkS390
, blk
),
518 DEFINE_PROP_END_OF_LIST(),
521 static void s390_virtio_blk_class_init(ObjectClass
*klass
, void *data
)
523 DeviceClass
*dc
= DEVICE_CLASS(klass
);
524 VirtIOS390DeviceClass
*k
= VIRTIO_S390_DEVICE_CLASS(klass
);
526 k
->init
= s390_virtio_blk_init
;
527 dc
->props
= s390_virtio_blk_properties
;
530 static const TypeInfo s390_virtio_blk
= {
531 .name
= "virtio-blk-s390",
532 .parent
= TYPE_VIRTIO_S390_DEVICE
,
533 .instance_size
= sizeof(VirtIOBlkS390
),
534 .instance_init
= s390_virtio_blk_instance_init
,
535 .class_init
= s390_virtio_blk_class_init
,
538 static Property s390_virtio_serial_properties
[] = {
539 DEFINE_VIRTIO_SERIAL_PROPERTIES(VirtIOSerialS390
, vdev
.serial
),
540 DEFINE_PROP_END_OF_LIST(),
543 static void s390_virtio_serial_class_init(ObjectClass
*klass
, void *data
)
545 DeviceClass
*dc
= DEVICE_CLASS(klass
);
546 VirtIOS390DeviceClass
*k
= VIRTIO_S390_DEVICE_CLASS(klass
);
548 k
->init
= s390_virtio_serial_init
;
549 dc
->props
= s390_virtio_serial_properties
;
552 static const TypeInfo s390_virtio_serial
= {
553 .name
= TYPE_VIRTIO_SERIAL_S390
,
554 .parent
= TYPE_VIRTIO_S390_DEVICE
,
555 .instance_size
= sizeof(VirtIOSerialS390
),
556 .instance_init
= s390_virtio_serial_instance_init
,
557 .class_init
= s390_virtio_serial_class_init
,
560 static Property s390_virtio_rng_properties
[] = {
561 DEFINE_VIRTIO_COMMON_FEATURES(VirtIOS390Device
, host_features
),
562 DEFINE_VIRTIO_RNG_PROPERTIES(VirtIORNGS390
, vdev
.conf
),
563 DEFINE_PROP_END_OF_LIST(),
566 static void s390_virtio_rng_class_init(ObjectClass
*klass
, void *data
)
568 DeviceClass
*dc
= DEVICE_CLASS(klass
);
569 VirtIOS390DeviceClass
*k
= VIRTIO_S390_DEVICE_CLASS(klass
);
571 k
->init
= s390_virtio_rng_init
;
572 dc
->props
= s390_virtio_rng_properties
;
575 static const TypeInfo s390_virtio_rng
= {
576 .name
= TYPE_VIRTIO_RNG_S390
,
577 .parent
= TYPE_VIRTIO_S390_DEVICE
,
578 .instance_size
= sizeof(VirtIORNGS390
),
579 .instance_init
= s390_virtio_rng_instance_init
,
580 .class_init
= s390_virtio_rng_class_init
,
583 static int s390_virtio_busdev_init(DeviceState
*dev
)
585 VirtIOS390Device
*_dev
= (VirtIOS390Device
*)dev
;
586 VirtIOS390DeviceClass
*_info
= VIRTIO_S390_DEVICE_GET_CLASS(dev
);
588 virtio_s390_bus_new(&_dev
->bus
, sizeof(_dev
->bus
), _dev
);
590 return _info
->init(_dev
);
593 static void s390_virtio_busdev_reset(DeviceState
*dev
)
595 VirtIOS390Device
*_dev
= (VirtIOS390Device
*)dev
;
597 virtio_reset(_dev
->vdev
);
600 static void virtio_s390_device_class_init(ObjectClass
*klass
, void *data
)
602 DeviceClass
*dc
= DEVICE_CLASS(klass
);
604 dc
->init
= s390_virtio_busdev_init
;
605 dc
->bus_type
= TYPE_S390_VIRTIO_BUS
;
606 dc
->unplug
= qdev_simple_unplug_cb
;
607 dc
->reset
= s390_virtio_busdev_reset
;
610 static const TypeInfo virtio_s390_device_info
= {
611 .name
= TYPE_VIRTIO_S390_DEVICE
,
612 .parent
= TYPE_DEVICE
,
613 .instance_size
= sizeof(VirtIOS390Device
),
614 .class_init
= virtio_s390_device_class_init
,
615 .class_size
= sizeof(VirtIOS390DeviceClass
),
619 static Property s390_virtio_scsi_properties
[] = {
620 DEFINE_VIRTIO_SCSI_PROPERTIES(VirtIOSCSIS390
, vdev
.parent_obj
.conf
),
621 DEFINE_VIRTIO_SCSI_FEATURES(VirtIOS390Device
, host_features
),
622 DEFINE_PROP_END_OF_LIST(),
625 static void s390_virtio_scsi_class_init(ObjectClass
*klass
, void *data
)
627 DeviceClass
*dc
= DEVICE_CLASS(klass
);
628 VirtIOS390DeviceClass
*k
= VIRTIO_S390_DEVICE_CLASS(klass
);
630 k
->init
= s390_virtio_scsi_init
;
631 dc
->props
= s390_virtio_scsi_properties
;
634 static const TypeInfo s390_virtio_scsi
= {
635 .name
= TYPE_VIRTIO_SCSI_S390
,
636 .parent
= TYPE_VIRTIO_S390_DEVICE
,
637 .instance_size
= sizeof(VirtIOSCSIS390
),
638 .instance_init
= s390_virtio_scsi_instance_init
,
639 .class_init
= s390_virtio_scsi_class_init
,
642 #ifdef CONFIG_VHOST_SCSI
643 static Property s390_vhost_scsi_properties
[] = {
644 DEFINE_VIRTIO_COMMON_FEATURES(VirtIOS390Device
, host_features
),
645 DEFINE_VHOST_SCSI_PROPERTIES(VHostSCSIS390
, vdev
.parent_obj
.conf
),
646 DEFINE_PROP_END_OF_LIST(),
649 static void s390_vhost_scsi_class_init(ObjectClass
*klass
, void *data
)
651 DeviceClass
*dc
= DEVICE_CLASS(klass
);
652 VirtIOS390DeviceClass
*k
= VIRTIO_S390_DEVICE_CLASS(klass
);
654 k
->init
= s390_vhost_scsi_init
;
655 dc
->props
= s390_vhost_scsi_properties
;
658 static const TypeInfo s390_vhost_scsi
= {
659 .name
= TYPE_VHOST_SCSI_S390
,
660 .parent
= TYPE_VIRTIO_S390_DEVICE
,
661 .instance_size
= sizeof(VHostSCSIS390
),
662 .instance_init
= s390_vhost_scsi_instance_init
,
663 .class_init
= s390_vhost_scsi_class_init
,
667 /***************** S390 Virtio Bus Bridge Device *******************/
668 /* Only required to have the virtio bus as child in the system bus */
670 static int s390_virtio_bridge_init(SysBusDevice
*dev
)
676 static void s390_virtio_bridge_class_init(ObjectClass
*klass
, void *data
)
678 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
680 k
->init
= s390_virtio_bridge_init
;
683 static const TypeInfo s390_virtio_bridge_info
= {
684 .name
= "s390-virtio-bridge",
685 .parent
= TYPE_SYS_BUS_DEVICE
,
686 .instance_size
= sizeof(SysBusDevice
),
687 .class_init
= s390_virtio_bridge_class_init
,
690 /* virtio-s390-bus */
692 static void virtio_s390_bus_new(VirtioBusState
*bus
, size_t bus_size
,
693 VirtIOS390Device
*dev
)
695 DeviceState
*qdev
= DEVICE(dev
);
697 char virtio_bus_name
[] = "virtio-bus";
699 qbus_create_inplace(bus
, bus_size
, TYPE_VIRTIO_S390_BUS
,
700 qdev
, virtio_bus_name
);
702 qbus
->allow_hotplug
= 1;
705 static void virtio_s390_bus_class_init(ObjectClass
*klass
, void *data
)
707 VirtioBusClass
*k
= VIRTIO_BUS_CLASS(klass
);
708 BusClass
*bus_class
= BUS_CLASS(klass
);
709 bus_class
->max_dev
= 1;
710 k
->notify
= virtio_s390_notify
;
711 k
->get_features
= virtio_s390_get_features
;
714 static const TypeInfo virtio_s390_bus_info
= {
715 .name
= TYPE_VIRTIO_S390_BUS
,
716 .parent
= TYPE_VIRTIO_BUS
,
717 .instance_size
= sizeof(VirtioS390BusState
),
718 .class_init
= virtio_s390_bus_class_init
,
721 static void s390_virtio_register_types(void)
723 type_register_static(&virtio_s390_bus_info
);
724 type_register_static(&s390_virtio_bus_info
);
725 type_register_static(&virtio_s390_device_info
);
726 type_register_static(&s390_virtio_serial
);
727 type_register_static(&s390_virtio_blk
);
728 type_register_static(&s390_virtio_net
);
729 type_register_static(&s390_virtio_scsi
);
730 #ifdef CONFIG_VHOST_SCSI
731 type_register_static(&s390_vhost_scsi
);
733 type_register_static(&s390_virtio_rng
);
734 type_register_static(&s390_virtio_bridge_info
);
737 type_init(s390_virtio_register_types
)