S390: ccw firmware: Add compiled blob
[qemu/agraf.git] / hw / s390x / s390-virtio-bus.c
bloba7e81d159f2062d4cb5b47c3cd43b254dc699ee5
1 /*
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/>.
20 #include "hw/hw.h"
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"
26 #include "elf.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 */
40 #ifdef DEBUG_S390
41 #define dprintf(fmt, ...) \
42 do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
43 #else
44 #define dprintf(fmt, ...) \
45 do { } while (0)
46 #endif
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,
54 .parent = TYPE_BUS,
55 .instance_size = sizeof(VirtIOS390Bus),
58 static ram_addr_t s390_virtio_device_num_vq(VirtIOS390Device *dev);
60 /* length of VirtIO device pages */
61 const hwaddr virtio_size = S390_DEVICE_PAGES * TARGET_PAGE_SIZE;
63 static void s390_virtio_bus_reset(void *opaque)
65 VirtIOS390Bus *bus = opaque;
66 bus->next_ring = bus->dev_page + TARGET_PAGE_SIZE;
69 void s390_virtio_reset_idx(VirtIOS390Device *dev)
71 int i;
72 hwaddr idx_addr;
73 uint8_t num_vq;
75 num_vq = s390_virtio_device_num_vq(dev);
76 for (i = 0; i < num_vq; i++) {
77 idx_addr = virtio_queue_get_avail_addr(dev->vdev, i) +
78 VIRTIO_VRING_AVAIL_IDX_OFFS;
79 stw_phys(idx_addr, 0);
80 idx_addr = virtio_queue_get_used_addr(dev->vdev, i) +
81 VIRTIO_VRING_USED_IDX_OFFS;
82 stw_phys(idx_addr, 0);
86 VirtIOS390Bus *s390_virtio_bus_init(ram_addr_t *ram_size)
88 VirtIOS390Bus *bus;
89 BusState *_bus;
90 DeviceState *dev;
92 /* Create bridge device */
93 dev = qdev_create(NULL, "s390-virtio-bridge");
94 qdev_init_nofail(dev);
96 /* Create bus on bridge device */
98 _bus = qbus_create(TYPE_S390_VIRTIO_BUS, dev, "s390-virtio");
99 bus = DO_UPCAST(VirtIOS390Bus, bus, _bus);
101 bus->dev_page = *ram_size;
102 bus->dev_offs = bus->dev_page;
103 bus->next_ring = bus->dev_page + TARGET_PAGE_SIZE;
105 /* Enable hotplugging */
106 _bus->allow_hotplug = 1;
108 /* Allocate RAM for VirtIO device pages (descriptors, queues, rings) */
109 *ram_size += S390_DEVICE_PAGES * TARGET_PAGE_SIZE;
111 qemu_register_reset(s390_virtio_bus_reset, bus);
112 return bus;
115 static void s390_virtio_irq(S390CPU *cpu, int config_change, uint64_t token)
117 if (kvm_enabled()) {
118 kvm_s390_virtio_irq(cpu, config_change, token);
119 } else {
120 cpu_inject_ext(cpu, VIRTIO_EXT_CODE, config_change, token);
124 static int s390_virtio_device_init(VirtIOS390Device *dev, VirtIODevice *vdev)
126 VirtIOS390Bus *bus;
127 int dev_len;
129 bus = DO_UPCAST(VirtIOS390Bus, bus, dev->qdev.parent_bus);
130 dev->vdev = vdev;
131 dev->dev_offs = bus->dev_offs;
132 dev->feat_len = sizeof(uint32_t); /* always keep 32 bits features */
134 dev_len = VIRTIO_DEV_OFFS_CONFIG;
135 dev_len += s390_virtio_device_num_vq(dev) * VIRTIO_VQCONFIG_LEN;
136 dev_len += dev->feat_len * 2;
137 dev_len += virtio_bus_get_vdev_config_len(&dev->bus);
139 bus->dev_offs += dev_len;
141 dev->host_features = virtio_bus_get_vdev_features(&dev->bus,
142 dev->host_features);
143 s390_virtio_device_sync(dev);
144 s390_virtio_reset_idx(dev);
145 if (dev->qdev.hotplugged) {
146 S390CPU *cpu = s390_cpu_addr2state(0);
147 s390_virtio_irq(cpu, VIRTIO_PARAM_DEV_ADD, dev->dev_offs);
150 return 0;
153 static int s390_virtio_net_init(VirtIOS390Device *s390_dev)
155 VirtIONetS390 *dev = VIRTIO_NET_S390(s390_dev);
156 DeviceState *vdev = DEVICE(&dev->vdev);
158 virtio_net_set_config_size(&dev->vdev, s390_dev->host_features);
159 qdev_set_parent_bus(vdev, BUS(&s390_dev->bus));
160 if (qdev_init(vdev) < 0) {
161 return -1;
164 return s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
167 static void s390_virtio_net_instance_init(Object *obj)
169 VirtIONetS390 *dev = VIRTIO_NET_S390(obj);
170 object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_NET);
171 object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
174 static int s390_virtio_blk_init(VirtIOS390Device *s390_dev)
176 VirtIOBlkS390 *dev = VIRTIO_BLK_S390(s390_dev);
177 DeviceState *vdev = DEVICE(&dev->vdev);
178 virtio_blk_set_conf(vdev, &(dev->blk));
179 qdev_set_parent_bus(vdev, BUS(&s390_dev->bus));
180 if (qdev_init(vdev) < 0) {
181 return -1;
183 return s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
186 static void s390_virtio_blk_instance_init(Object *obj)
188 VirtIOBlkS390 *dev = VIRTIO_BLK_S390(obj);
189 object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_BLK);
190 object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
193 static int s390_virtio_serial_init(VirtIOS390Device *s390_dev)
195 VirtIOSerialS390 *dev = VIRTIO_SERIAL_S390(s390_dev);
196 DeviceState *vdev = DEVICE(&dev->vdev);
197 DeviceState *qdev = DEVICE(s390_dev);
198 VirtIOS390Bus *bus;
199 int r;
201 bus = DO_UPCAST(VirtIOS390Bus, bus, qdev->parent_bus);
203 qdev_set_parent_bus(vdev, BUS(&s390_dev->bus));
204 if (qdev_init(vdev) < 0) {
205 return -1;
208 r = s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
209 if (!r) {
210 bus->console = s390_dev;
213 return r;
216 static void s390_virtio_serial_instance_init(Object *obj)
218 VirtIOSerialS390 *dev = VIRTIO_SERIAL_S390(obj);
219 object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_SERIAL);
220 object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
223 static int s390_virtio_scsi_init(VirtIOS390Device *s390_dev)
225 VirtIOSCSIS390 *dev = VIRTIO_SCSI_S390(s390_dev);
226 DeviceState *vdev = DEVICE(&dev->vdev);
228 qdev_set_parent_bus(vdev, BUS(&s390_dev->bus));
229 if (qdev_init(vdev) < 0) {
230 return -1;
233 return s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
236 static void s390_virtio_scsi_instance_init(Object *obj)
238 VirtIOSCSIS390 *dev = VIRTIO_SCSI_S390(obj);
239 object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_SCSI);
240 object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
243 #ifdef CONFIG_VHOST_SCSI
244 static int s390_vhost_scsi_init(VirtIOS390Device *s390_dev)
246 VHostSCSIS390 *dev = VHOST_SCSI_S390(s390_dev);
247 DeviceState *vdev = DEVICE(&dev->vdev);
249 qdev_set_parent_bus(vdev, BUS(&s390_dev->bus));
250 if (qdev_init(vdev) < 0) {
251 return -1;
254 return s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
257 static void s390_vhost_scsi_instance_init(Object *obj)
259 VHostSCSIS390 *dev = VHOST_SCSI_S390(obj);
260 object_initialize(OBJECT(&dev->vdev), TYPE_VHOST_SCSI);
261 object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
263 #endif
266 static int s390_virtio_rng_init(VirtIOS390Device *s390_dev)
268 VirtIORNGS390 *dev = VIRTIO_RNG_S390(s390_dev);
269 DeviceState *vdev = DEVICE(&dev->vdev);
271 qdev_set_parent_bus(vdev, BUS(&s390_dev->bus));
272 if (qdev_init(vdev) < 0) {
273 return -1;
276 object_property_set_link(OBJECT(dev),
277 OBJECT(dev->vdev.conf.default_backend), "rng",
278 NULL);
280 return s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
283 static void s390_virtio_rng_instance_init(Object *obj)
285 VirtIORNGS390 *dev = VIRTIO_RNG_S390(obj);
286 object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_RNG);
287 object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
288 object_property_add_link(obj, "rng", TYPE_RNG_BACKEND,
289 (Object **)&dev->vdev.conf.rng, NULL);
292 static uint64_t s390_virtio_device_vq_token(VirtIOS390Device *dev, int vq)
294 ram_addr_t token_off;
296 token_off = (dev->dev_offs + VIRTIO_DEV_OFFS_CONFIG) +
297 (vq * VIRTIO_VQCONFIG_LEN) +
298 VIRTIO_VQCONFIG_OFFS_TOKEN;
300 return ldq_be_phys(token_off);
303 static ram_addr_t s390_virtio_device_num_vq(VirtIOS390Device *dev)
305 VirtIODevice *vdev = dev->vdev;
306 int num_vq;
308 for (num_vq = 0; num_vq < VIRTIO_PCI_QUEUE_MAX; num_vq++) {
309 if (!virtio_queue_get_num(vdev, num_vq)) {
310 break;
314 return num_vq;
317 static ram_addr_t s390_virtio_next_ring(VirtIOS390Bus *bus)
319 ram_addr_t r = bus->next_ring;
321 bus->next_ring += VIRTIO_RING_LEN;
322 return r;
325 void s390_virtio_device_sync(VirtIOS390Device *dev)
327 VirtIOS390Bus *bus = DO_UPCAST(VirtIOS390Bus, bus, dev->qdev.parent_bus);
328 ram_addr_t cur_offs;
329 uint8_t num_vq;
330 int i;
332 virtio_reset(dev->vdev);
334 /* Sync dev space */
335 stb_phys(dev->dev_offs + VIRTIO_DEV_OFFS_TYPE, dev->vdev->device_id);
337 stb_phys(dev->dev_offs + VIRTIO_DEV_OFFS_NUM_VQ, s390_virtio_device_num_vq(dev));
338 stb_phys(dev->dev_offs + VIRTIO_DEV_OFFS_FEATURE_LEN, dev->feat_len);
340 stb_phys(dev->dev_offs + VIRTIO_DEV_OFFS_CONFIG_LEN, dev->vdev->config_len);
342 num_vq = s390_virtio_device_num_vq(dev);
343 stb_phys(dev->dev_offs + VIRTIO_DEV_OFFS_NUM_VQ, num_vq);
345 /* Sync virtqueues */
346 for (i = 0; i < num_vq; i++) {
347 ram_addr_t vq = (dev->dev_offs + VIRTIO_DEV_OFFS_CONFIG) +
348 (i * VIRTIO_VQCONFIG_LEN);
349 ram_addr_t vring;
351 vring = s390_virtio_next_ring(bus);
352 virtio_queue_set_addr(dev->vdev, i, vring);
353 virtio_queue_set_vector(dev->vdev, i, i);
354 stq_be_phys(vq + VIRTIO_VQCONFIG_OFFS_ADDRESS, vring);
355 stw_be_phys(vq + VIRTIO_VQCONFIG_OFFS_NUM, virtio_queue_get_num(dev->vdev, i));
358 cur_offs = dev->dev_offs;
359 cur_offs += VIRTIO_DEV_OFFS_CONFIG;
360 cur_offs += num_vq * VIRTIO_VQCONFIG_LEN;
362 /* Sync feature bitmap */
363 stl_le_phys(cur_offs, dev->host_features);
365 dev->feat_offs = cur_offs + dev->feat_len;
366 cur_offs += dev->feat_len * 2;
368 /* Sync config space */
369 virtio_bus_get_vdev_config(&dev->bus, dev->vdev->config);
371 cpu_physical_memory_write(cur_offs,
372 dev->vdev->config, dev->vdev->config_len);
373 cur_offs += dev->vdev->config_len;
376 void s390_virtio_device_update_status(VirtIOS390Device *dev)
378 VirtIODevice *vdev = dev->vdev;
379 uint32_t features;
381 virtio_set_status(vdev, ldub_phys(dev->dev_offs + VIRTIO_DEV_OFFS_STATUS));
383 /* Update guest supported feature bitmap */
385 features = bswap32(ldl_be_phys(dev->feat_offs));
386 virtio_set_features(vdev, features);
389 VirtIOS390Device *s390_virtio_bus_console(VirtIOS390Bus *bus)
391 return bus->console;
394 /* Find a device by vring address */
395 VirtIOS390Device *s390_virtio_bus_find_vring(VirtIOS390Bus *bus,
396 ram_addr_t mem,
397 int *vq_num)
399 BusChild *kid;
400 int i;
402 QTAILQ_FOREACH(kid, &bus->bus.children, sibling) {
403 VirtIOS390Device *dev = (VirtIOS390Device *)kid->child;
405 for(i = 0; i < VIRTIO_PCI_QUEUE_MAX; i++) {
406 if (!virtio_queue_get_addr(dev->vdev, i))
407 break;
408 if (virtio_queue_get_addr(dev->vdev, i) == mem) {
409 if (vq_num) {
410 *vq_num = i;
412 return dev;
417 return NULL;
420 /* Find a device by device descriptor location */
421 VirtIOS390Device *s390_virtio_bus_find_mem(VirtIOS390Bus *bus, ram_addr_t mem)
423 BusChild *kid;
425 QTAILQ_FOREACH(kid, &bus->bus.children, sibling) {
426 VirtIOS390Device *dev = (VirtIOS390Device *)kid->child;
427 if (dev->dev_offs == mem) {
428 return dev;
432 return NULL;
435 /* DeviceState to VirtIOS390Device. Note: used on datapath,
436 * be careful and test performance if you change this.
438 static inline VirtIOS390Device *to_virtio_s390_device_fast(DeviceState *d)
440 return container_of(d, VirtIOS390Device, qdev);
443 /* DeviceState to VirtIOS390Device. TODO: use QOM. */
444 static inline VirtIOS390Device *to_virtio_s390_device(DeviceState *d)
446 return container_of(d, VirtIOS390Device, qdev);
449 static void virtio_s390_notify(DeviceState *d, uint16_t vector)
451 VirtIOS390Device *dev = to_virtio_s390_device_fast(d);
452 uint64_t token = s390_virtio_device_vq_token(dev, vector);
453 S390CPU *cpu = s390_cpu_addr2state(0);
455 s390_virtio_irq(cpu, 0, token);
458 static unsigned virtio_s390_get_features(DeviceState *d)
460 VirtIOS390Device *dev = to_virtio_s390_device(d);
461 return dev->host_features;
464 /**************** S390 Virtio Bus Device Descriptions *******************/
466 static Property s390_virtio_net_properties[] = {
467 DEFINE_NIC_PROPERTIES(VirtIONetS390, vdev.nic_conf),
468 DEFINE_VIRTIO_NET_FEATURES(VirtIOS390Device, host_features),
469 DEFINE_VIRTIO_NET_PROPERTIES(VirtIONetS390, vdev.net_conf),
470 DEFINE_PROP_END_OF_LIST(),
473 static void s390_virtio_net_class_init(ObjectClass *klass, void *data)
475 DeviceClass *dc = DEVICE_CLASS(klass);
476 VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
478 k->init = s390_virtio_net_init;
479 dc->props = s390_virtio_net_properties;
482 static const TypeInfo s390_virtio_net = {
483 .name = TYPE_VIRTIO_NET_S390,
484 .parent = TYPE_VIRTIO_S390_DEVICE,
485 .instance_size = sizeof(VirtIONetS390),
486 .instance_init = s390_virtio_net_instance_init,
487 .class_init = s390_virtio_net_class_init,
490 static Property s390_virtio_blk_properties[] = {
491 DEFINE_VIRTIO_BLK_PROPERTIES(VirtIOBlkS390, blk),
492 DEFINE_PROP_END_OF_LIST(),
495 static void s390_virtio_blk_class_init(ObjectClass *klass, void *data)
497 DeviceClass *dc = DEVICE_CLASS(klass);
498 VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
500 k->init = s390_virtio_blk_init;
501 dc->props = s390_virtio_blk_properties;
504 static const TypeInfo s390_virtio_blk = {
505 .name = "virtio-blk-s390",
506 .parent = TYPE_VIRTIO_S390_DEVICE,
507 .instance_size = sizeof(VirtIOBlkS390),
508 .instance_init = s390_virtio_blk_instance_init,
509 .class_init = s390_virtio_blk_class_init,
512 static Property s390_virtio_serial_properties[] = {
513 DEFINE_VIRTIO_SERIAL_PROPERTIES(VirtIOSerialS390, vdev.serial),
514 DEFINE_PROP_END_OF_LIST(),
517 static void s390_virtio_serial_class_init(ObjectClass *klass, void *data)
519 DeviceClass *dc = DEVICE_CLASS(klass);
520 VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
522 k->init = s390_virtio_serial_init;
523 dc->props = s390_virtio_serial_properties;
526 static const TypeInfo s390_virtio_serial = {
527 .name = TYPE_VIRTIO_SERIAL_S390,
528 .parent = TYPE_VIRTIO_S390_DEVICE,
529 .instance_size = sizeof(VirtIOSerialS390),
530 .instance_init = s390_virtio_serial_instance_init,
531 .class_init = s390_virtio_serial_class_init,
534 static void s390_virtio_rng_class_init(ObjectClass *klass, void *data)
536 VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
538 k->init = s390_virtio_rng_init;
541 static const TypeInfo s390_virtio_rng = {
542 .name = TYPE_VIRTIO_RNG_S390,
543 .parent = TYPE_VIRTIO_S390_DEVICE,
544 .instance_size = sizeof(VirtIORNGS390),
545 .instance_init = s390_virtio_rng_instance_init,
546 .class_init = s390_virtio_rng_class_init,
549 static int s390_virtio_busdev_init(DeviceState *dev)
551 VirtIOS390Device *_dev = (VirtIOS390Device *)dev;
552 VirtIOS390DeviceClass *_info = VIRTIO_S390_DEVICE_GET_CLASS(dev);
554 virtio_s390_bus_new(&_dev->bus, _dev);
556 return _info->init(_dev);
559 static void s390_virtio_busdev_reset(DeviceState *dev)
561 VirtIOS390Device *_dev = (VirtIOS390Device *)dev;
563 virtio_reset(_dev->vdev);
566 static void virtio_s390_device_class_init(ObjectClass *klass, void *data)
568 DeviceClass *dc = DEVICE_CLASS(klass);
570 dc->init = s390_virtio_busdev_init;
571 dc->bus_type = TYPE_S390_VIRTIO_BUS;
572 dc->unplug = qdev_simple_unplug_cb;
573 dc->reset = s390_virtio_busdev_reset;
576 static const TypeInfo virtio_s390_device_info = {
577 .name = TYPE_VIRTIO_S390_DEVICE,
578 .parent = TYPE_DEVICE,
579 .instance_size = sizeof(VirtIOS390Device),
580 .class_init = virtio_s390_device_class_init,
581 .class_size = sizeof(VirtIOS390DeviceClass),
582 .abstract = true,
585 static Property s390_virtio_scsi_properties[] = {
586 DEFINE_VIRTIO_SCSI_PROPERTIES(VirtIOSCSIS390, vdev.parent_obj.conf),
587 DEFINE_VIRTIO_SCSI_FEATURES(VirtIOS390Device, host_features),
588 DEFINE_PROP_END_OF_LIST(),
591 static void s390_virtio_scsi_class_init(ObjectClass *klass, void *data)
593 DeviceClass *dc = DEVICE_CLASS(klass);
594 VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
596 k->init = s390_virtio_scsi_init;
597 dc->props = s390_virtio_scsi_properties;
600 static const TypeInfo s390_virtio_scsi = {
601 .name = TYPE_VIRTIO_SCSI_S390,
602 .parent = TYPE_VIRTIO_S390_DEVICE,
603 .instance_size = sizeof(VirtIOSCSIS390),
604 .instance_init = s390_virtio_scsi_instance_init,
605 .class_init = s390_virtio_scsi_class_init,
608 #ifdef CONFIG_VHOST_SCSI
609 static Property s390_vhost_scsi_properties[] = {
610 DEFINE_VIRTIO_COMMON_FEATURES(VirtIOS390Device, host_features),
611 DEFINE_VHOST_SCSI_PROPERTIES(VHostSCSIS390, vdev.parent_obj.conf),
612 DEFINE_PROP_END_OF_LIST(),
615 static void s390_vhost_scsi_class_init(ObjectClass *klass, void *data)
617 DeviceClass *dc = DEVICE_CLASS(klass);
618 VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
620 k->init = s390_vhost_scsi_init;
621 dc->props = s390_vhost_scsi_properties;
624 static const TypeInfo s390_vhost_scsi = {
625 .name = TYPE_VHOST_SCSI_S390,
626 .parent = TYPE_VIRTIO_S390_DEVICE,
627 .instance_size = sizeof(VHostSCSIS390),
628 .instance_init = s390_vhost_scsi_instance_init,
629 .class_init = s390_vhost_scsi_class_init,
631 #endif
633 /***************** S390 Virtio Bus Bridge Device *******************/
634 /* Only required to have the virtio bus as child in the system bus */
636 static int s390_virtio_bridge_init(SysBusDevice *dev)
638 /* nothing */
639 return 0;
642 static void s390_virtio_bridge_class_init(ObjectClass *klass, void *data)
644 DeviceClass *dc = DEVICE_CLASS(klass);
645 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
647 k->init = s390_virtio_bridge_init;
648 dc->no_user = 1;
651 static const TypeInfo s390_virtio_bridge_info = {
652 .name = "s390-virtio-bridge",
653 .parent = TYPE_SYS_BUS_DEVICE,
654 .instance_size = sizeof(SysBusDevice),
655 .class_init = s390_virtio_bridge_class_init,
658 /* virtio-s390-bus */
660 static void virtio_s390_bus_new(VirtioBusState *bus, VirtIOS390Device *dev)
662 DeviceState *qdev = DEVICE(dev);
663 BusState *qbus;
664 qbus_create_inplace((BusState *)bus, TYPE_VIRTIO_S390_BUS, qdev, NULL);
665 qbus = BUS(bus);
666 qbus->allow_hotplug = 1;
669 static void virtio_s390_bus_class_init(ObjectClass *klass, void *data)
671 VirtioBusClass *k = VIRTIO_BUS_CLASS(klass);
672 BusClass *bus_class = BUS_CLASS(klass);
673 bus_class->max_dev = 1;
674 k->notify = virtio_s390_notify;
675 k->get_features = virtio_s390_get_features;
678 static const TypeInfo virtio_s390_bus_info = {
679 .name = TYPE_VIRTIO_S390_BUS,
680 .parent = TYPE_VIRTIO_BUS,
681 .instance_size = sizeof(VirtioS390BusState),
682 .class_init = virtio_s390_bus_class_init,
685 static void s390_virtio_register_types(void)
687 type_register_static(&virtio_s390_bus_info);
688 type_register_static(&s390_virtio_bus_info);
689 type_register_static(&virtio_s390_device_info);
690 type_register_static(&s390_virtio_serial);
691 type_register_static(&s390_virtio_blk);
692 type_register_static(&s390_virtio_net);
693 type_register_static(&s390_virtio_scsi);
694 #ifdef CONFIG_VHOST_SCSI
695 type_register_static(&s390_vhost_scsi);
696 #endif
697 type_register_static(&s390_virtio_rng);
698 type_register_static(&s390_virtio_bridge_info);
701 type_init(s390_virtio_register_types)