SMBIOS: Use bitmaps to prevent incompatible comand line options
[qemu/ar7.git] / hw / s390x / s390-virtio-bus.c
blob9c71afa0317e2ed6d8a727839a3279d94f39c0e1
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, size_t bus_size,
51 VirtIOS390Device *dev);
53 static const TypeInfo s390_virtio_bus_info = {
54 .name = TYPE_S390_VIRTIO_BUS,
55 .parent = TYPE_BUS,
56 .instance_size = sizeof(VirtIOS390Bus),
59 static ram_addr_t s390_virtio_device_num_vq(VirtIOS390Device *dev);
61 /* length of VirtIO device pages */
62 const hwaddr virtio_size = S390_DEVICE_PAGES * TARGET_PAGE_SIZE;
64 static void s390_virtio_bus_reset(void *opaque)
66 VirtIOS390Bus *bus = opaque;
67 bus->next_ring = bus->dev_page + TARGET_PAGE_SIZE;
70 void s390_virtio_reset_idx(VirtIOS390Device *dev)
72 int i;
73 hwaddr idx_addr;
74 uint8_t num_vq;
76 num_vq = s390_virtio_device_num_vq(dev);
77 for (i = 0; i < num_vq; i++) {
78 idx_addr = virtio_queue_get_avail_addr(dev->vdev, i) +
79 VIRTIO_VRING_AVAIL_IDX_OFFS;
80 stw_phys(&address_space_memory, idx_addr, 0);
81 idx_addr = virtio_queue_get_used_addr(dev->vdev, i) +
82 VIRTIO_VRING_USED_IDX_OFFS;
83 stw_phys(&address_space_memory, idx_addr, 0);
87 VirtIOS390Bus *s390_virtio_bus_init(ram_addr_t *ram_size)
89 VirtIOS390Bus *bus;
90 BusState *_bus;
91 DeviceState *dev;
93 /* Create bridge device */
94 dev = qdev_create(NULL, "s390-virtio-bridge");
95 qdev_init_nofail(dev);
97 /* Create bus on bridge device */
99 _bus = qbus_create(TYPE_S390_VIRTIO_BUS, dev, "s390-virtio");
100 bus = DO_UPCAST(VirtIOS390Bus, bus, _bus);
102 bus->dev_page = *ram_size;
103 bus->dev_offs = bus->dev_page;
104 bus->next_ring = bus->dev_page + TARGET_PAGE_SIZE;
106 /* Enable hotplugging */
107 _bus->allow_hotplug = 1;
109 /* Allocate RAM for VirtIO device pages (descriptors, queues, rings) */
110 *ram_size += S390_DEVICE_PAGES * TARGET_PAGE_SIZE;
112 qemu_register_reset(s390_virtio_bus_reset, bus);
113 return bus;
116 static void s390_virtio_irq(S390CPU *cpu, int config_change, uint64_t token)
118 if (kvm_enabled()) {
119 kvm_s390_virtio_irq(cpu, config_change, token);
120 } else {
121 cpu_inject_ext(cpu, VIRTIO_EXT_CODE, config_change, token);
125 static int s390_virtio_device_init(VirtIOS390Device *dev, VirtIODevice *vdev)
127 VirtIOS390Bus *bus;
128 int dev_len;
130 bus = DO_UPCAST(VirtIOS390Bus, bus, dev->qdev.parent_bus);
131 dev->vdev = vdev;
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,
143 dev->host_features);
144 s390_virtio_device_sync(dev);
145 s390_virtio_reset_idx(dev);
146 if (dev->qdev.hotplugged) {
147 S390CPU *cpu = s390_cpu_addr2state(0);
148 s390_virtio_irq(cpu, VIRTIO_PARAM_DEV_ADD, dev->dev_offs);
151 return 0;
154 static int s390_virtio_net_init(VirtIOS390Device *s390_dev)
156 DeviceState *qdev = DEVICE(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 virtio_net_set_netclient_name(&dev->vdev, qdev->id,
162 object_get_typename(OBJECT(qdev)));
163 qdev_set_parent_bus(vdev, BUS(&s390_dev->bus));
164 if (qdev_init(vdev) < 0) {
165 return -1;
168 return s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
171 static void s390_virtio_net_instance_init(Object *obj)
173 VirtIONetS390 *dev = VIRTIO_NET_S390(obj);
174 object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_NET);
175 object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
178 static int s390_virtio_blk_init(VirtIOS390Device *s390_dev)
180 VirtIOBlkS390 *dev = VIRTIO_BLK_S390(s390_dev);
181 DeviceState *vdev = DEVICE(&dev->vdev);
182 virtio_blk_set_conf(vdev, &(dev->blk));
183 qdev_set_parent_bus(vdev, BUS(&s390_dev->bus));
184 if (qdev_init(vdev) < 0) {
185 return -1;
187 return s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
190 static void s390_virtio_blk_instance_init(Object *obj)
192 VirtIOBlkS390 *dev = VIRTIO_BLK_S390(obj);
193 object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_BLK);
194 object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
197 static int s390_virtio_serial_init(VirtIOS390Device *s390_dev)
199 VirtIOSerialS390 *dev = VIRTIO_SERIAL_S390(s390_dev);
200 DeviceState *vdev = DEVICE(&dev->vdev);
201 DeviceState *qdev = DEVICE(s390_dev);
202 VirtIOS390Bus *bus;
203 int r;
204 char *bus_name;
206 bus = DO_UPCAST(VirtIOS390Bus, bus, qdev->parent_bus);
209 * For command line compatibility, this sets the virtio-serial-device bus
210 * name as before.
212 if (qdev->id) {
213 bus_name = g_strdup_printf("%s.0", qdev->id);
214 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name);
215 g_free(bus_name);
218 qdev_set_parent_bus(vdev, BUS(&s390_dev->bus));
219 if (qdev_init(vdev) < 0) {
220 return -1;
223 r = s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
224 if (!r) {
225 bus->console = s390_dev;
228 return r;
231 static void s390_virtio_serial_instance_init(Object *obj)
233 VirtIOSerialS390 *dev = VIRTIO_SERIAL_S390(obj);
234 object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_SERIAL);
235 object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
238 static int s390_virtio_scsi_init(VirtIOS390Device *s390_dev)
240 VirtIOSCSIS390 *dev = VIRTIO_SCSI_S390(s390_dev);
241 DeviceState *vdev = DEVICE(&dev->vdev);
242 DeviceState *qdev = DEVICE(s390_dev);
243 char *bus_name;
246 * For command line compatibility, this sets the virtio-scsi-device bus
247 * name as before.
249 if (qdev->id) {
250 bus_name = g_strdup_printf("%s.0", qdev->id);
251 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name);
252 g_free(bus_name);
255 qdev_set_parent_bus(vdev, BUS(&s390_dev->bus));
256 if (qdev_init(vdev) < 0) {
257 return -1;
260 return s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
263 static void s390_virtio_scsi_instance_init(Object *obj)
265 VirtIOSCSIS390 *dev = VIRTIO_SCSI_S390(obj);
266 object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_SCSI);
267 object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
270 #ifdef CONFIG_VHOST_SCSI
271 static int s390_vhost_scsi_init(VirtIOS390Device *s390_dev)
273 VHostSCSIS390 *dev = VHOST_SCSI_S390(s390_dev);
274 DeviceState *vdev = DEVICE(&dev->vdev);
276 qdev_set_parent_bus(vdev, BUS(&s390_dev->bus));
277 if (qdev_init(vdev) < 0) {
278 return -1;
281 return s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
284 static void s390_vhost_scsi_instance_init(Object *obj)
286 VHostSCSIS390 *dev = VHOST_SCSI_S390(obj);
287 object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VHOST_SCSI);
288 object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
290 #endif
293 static int s390_virtio_rng_init(VirtIOS390Device *s390_dev)
295 VirtIORNGS390 *dev = VIRTIO_RNG_S390(s390_dev);
296 DeviceState *vdev = DEVICE(&dev->vdev);
298 qdev_set_parent_bus(vdev, BUS(&s390_dev->bus));
299 if (qdev_init(vdev) < 0) {
300 return -1;
303 object_property_set_link(OBJECT(dev),
304 OBJECT(dev->vdev.conf.rng), "rng",
305 NULL);
307 return s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
310 static void s390_virtio_rng_instance_init(Object *obj)
312 VirtIORNGS390 *dev = VIRTIO_RNG_S390(obj);
313 object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_RNG);
314 object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
315 object_property_add_link(obj, "rng", TYPE_RNG_BACKEND,
316 (Object **)&dev->vdev.conf.rng,
317 qdev_prop_allow_set_link_before_realize,
318 OBJ_PROP_LINK_UNREF_ON_RELEASE, NULL);
321 static uint64_t s390_virtio_device_vq_token(VirtIOS390Device *dev, int vq)
323 ram_addr_t token_off;
325 token_off = (dev->dev_offs + VIRTIO_DEV_OFFS_CONFIG) +
326 (vq * VIRTIO_VQCONFIG_LEN) +
327 VIRTIO_VQCONFIG_OFFS_TOKEN;
329 return ldq_be_phys(&address_space_memory, token_off);
332 static ram_addr_t s390_virtio_device_num_vq(VirtIOS390Device *dev)
334 VirtIODevice *vdev = dev->vdev;
335 int num_vq;
337 for (num_vq = 0; num_vq < VIRTIO_PCI_QUEUE_MAX; num_vq++) {
338 if (!virtio_queue_get_num(vdev, num_vq)) {
339 break;
343 return num_vq;
346 static ram_addr_t s390_virtio_next_ring(VirtIOS390Bus *bus)
348 ram_addr_t r = bus->next_ring;
350 bus->next_ring += VIRTIO_RING_LEN;
351 return r;
354 void s390_virtio_device_sync(VirtIOS390Device *dev)
356 VirtIOS390Bus *bus = DO_UPCAST(VirtIOS390Bus, bus, dev->qdev.parent_bus);
357 ram_addr_t cur_offs;
358 uint8_t num_vq;
359 int i;
361 virtio_reset(dev->vdev);
363 /* Sync dev space */
364 stb_phys(&address_space_memory,
365 dev->dev_offs + VIRTIO_DEV_OFFS_TYPE, dev->vdev->device_id);
367 stb_phys(&address_space_memory,
368 dev->dev_offs + VIRTIO_DEV_OFFS_NUM_VQ,
369 s390_virtio_device_num_vq(dev));
370 stb_phys(&address_space_memory,
371 dev->dev_offs + VIRTIO_DEV_OFFS_FEATURE_LEN, dev->feat_len);
373 stb_phys(&address_space_memory,
374 dev->dev_offs + VIRTIO_DEV_OFFS_CONFIG_LEN, dev->vdev->config_len);
376 num_vq = s390_virtio_device_num_vq(dev);
377 stb_phys(&address_space_memory,
378 dev->dev_offs + VIRTIO_DEV_OFFS_NUM_VQ, num_vq);
380 /* Sync virtqueues */
381 for (i = 0; i < num_vq; i++) {
382 ram_addr_t vq = (dev->dev_offs + VIRTIO_DEV_OFFS_CONFIG) +
383 (i * VIRTIO_VQCONFIG_LEN);
384 ram_addr_t vring;
386 vring = s390_virtio_next_ring(bus);
387 virtio_queue_set_addr(dev->vdev, i, vring);
388 virtio_queue_set_vector(dev->vdev, i, i);
389 stq_be_phys(&address_space_memory,
390 vq + VIRTIO_VQCONFIG_OFFS_ADDRESS, vring);
391 stw_be_phys(&address_space_memory,
392 vq + VIRTIO_VQCONFIG_OFFS_NUM,
393 virtio_queue_get_num(dev->vdev, i));
396 cur_offs = dev->dev_offs;
397 cur_offs += VIRTIO_DEV_OFFS_CONFIG;
398 cur_offs += num_vq * VIRTIO_VQCONFIG_LEN;
400 /* Sync feature bitmap */
401 stl_le_phys(&address_space_memory, cur_offs, dev->host_features);
403 dev->feat_offs = cur_offs + dev->feat_len;
404 cur_offs += dev->feat_len * 2;
406 /* Sync config space */
407 virtio_bus_get_vdev_config(&dev->bus, dev->vdev->config);
409 cpu_physical_memory_write(cur_offs,
410 dev->vdev->config, dev->vdev->config_len);
411 cur_offs += dev->vdev->config_len;
414 void s390_virtio_device_update_status(VirtIOS390Device *dev)
416 VirtIODevice *vdev = dev->vdev;
417 uint32_t features;
419 virtio_set_status(vdev, ldub_phys(&address_space_memory,
420 dev->dev_offs + VIRTIO_DEV_OFFS_STATUS));
422 /* Update guest supported feature bitmap */
424 features = bswap32(ldl_be_phys(&address_space_memory, dev->feat_offs));
425 virtio_set_features(vdev, features);
428 VirtIOS390Device *s390_virtio_bus_console(VirtIOS390Bus *bus)
430 return bus->console;
433 /* Find a device by vring address */
434 VirtIOS390Device *s390_virtio_bus_find_vring(VirtIOS390Bus *bus,
435 ram_addr_t mem,
436 int *vq_num)
438 BusChild *kid;
439 int i;
441 QTAILQ_FOREACH(kid, &bus->bus.children, sibling) {
442 VirtIOS390Device *dev = (VirtIOS390Device *)kid->child;
444 for(i = 0; i < VIRTIO_PCI_QUEUE_MAX; i++) {
445 if (!virtio_queue_get_addr(dev->vdev, i))
446 break;
447 if (virtio_queue_get_addr(dev->vdev, i) == mem) {
448 if (vq_num) {
449 *vq_num = i;
451 return dev;
456 return NULL;
459 /* Find a device by device descriptor location */
460 VirtIOS390Device *s390_virtio_bus_find_mem(VirtIOS390Bus *bus, ram_addr_t mem)
462 BusChild *kid;
464 QTAILQ_FOREACH(kid, &bus->bus.children, sibling) {
465 VirtIOS390Device *dev = (VirtIOS390Device *)kid->child;
466 if (dev->dev_offs == mem) {
467 return dev;
471 return NULL;
474 /* DeviceState to VirtIOS390Device. Note: used on datapath,
475 * be careful and test performance if you change this.
477 static inline VirtIOS390Device *to_virtio_s390_device_fast(DeviceState *d)
479 return container_of(d, VirtIOS390Device, qdev);
482 /* DeviceState to VirtIOS390Device. TODO: use QOM. */
483 static inline VirtIOS390Device *to_virtio_s390_device(DeviceState *d)
485 return container_of(d, VirtIOS390Device, qdev);
488 static void virtio_s390_notify(DeviceState *d, uint16_t vector)
490 VirtIOS390Device *dev = to_virtio_s390_device_fast(d);
491 uint64_t token = s390_virtio_device_vq_token(dev, vector);
492 S390CPU *cpu = s390_cpu_addr2state(0);
494 s390_virtio_irq(cpu, 0, token);
497 static unsigned virtio_s390_get_features(DeviceState *d)
499 VirtIOS390Device *dev = to_virtio_s390_device(d);
500 return dev->host_features;
503 /**************** S390 Virtio Bus Device Descriptions *******************/
505 static Property s390_virtio_net_properties[] = {
506 DEFINE_NIC_PROPERTIES(VirtIONetS390, vdev.nic_conf),
507 DEFINE_VIRTIO_NET_FEATURES(VirtIOS390Device, host_features),
508 DEFINE_VIRTIO_NET_PROPERTIES(VirtIONetS390, vdev.net_conf),
509 DEFINE_PROP_END_OF_LIST(),
512 static void s390_virtio_net_class_init(ObjectClass *klass, void *data)
514 DeviceClass *dc = DEVICE_CLASS(klass);
515 VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
517 k->init = s390_virtio_net_init;
518 dc->props = s390_virtio_net_properties;
521 static const TypeInfo s390_virtio_net = {
522 .name = TYPE_VIRTIO_NET_S390,
523 .parent = TYPE_VIRTIO_S390_DEVICE,
524 .instance_size = sizeof(VirtIONetS390),
525 .instance_init = s390_virtio_net_instance_init,
526 .class_init = s390_virtio_net_class_init,
529 static Property s390_virtio_blk_properties[] = {
530 DEFINE_VIRTIO_BLK_PROPERTIES(VirtIOBlkS390, blk),
531 DEFINE_PROP_END_OF_LIST(),
534 static void s390_virtio_blk_class_init(ObjectClass *klass, void *data)
536 DeviceClass *dc = DEVICE_CLASS(klass);
537 VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
539 k->init = s390_virtio_blk_init;
540 dc->props = s390_virtio_blk_properties;
543 static const TypeInfo s390_virtio_blk = {
544 .name = "virtio-blk-s390",
545 .parent = TYPE_VIRTIO_S390_DEVICE,
546 .instance_size = sizeof(VirtIOBlkS390),
547 .instance_init = s390_virtio_blk_instance_init,
548 .class_init = s390_virtio_blk_class_init,
551 static Property s390_virtio_serial_properties[] = {
552 DEFINE_VIRTIO_SERIAL_PROPERTIES(VirtIOSerialS390, vdev.serial),
553 DEFINE_PROP_END_OF_LIST(),
556 static void s390_virtio_serial_class_init(ObjectClass *klass, void *data)
558 DeviceClass *dc = DEVICE_CLASS(klass);
559 VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
561 k->init = s390_virtio_serial_init;
562 dc->props = s390_virtio_serial_properties;
565 static const TypeInfo s390_virtio_serial = {
566 .name = TYPE_VIRTIO_SERIAL_S390,
567 .parent = TYPE_VIRTIO_S390_DEVICE,
568 .instance_size = sizeof(VirtIOSerialS390),
569 .instance_init = s390_virtio_serial_instance_init,
570 .class_init = s390_virtio_serial_class_init,
573 static Property s390_virtio_rng_properties[] = {
574 DEFINE_VIRTIO_COMMON_FEATURES(VirtIOS390Device, host_features),
575 DEFINE_VIRTIO_RNG_PROPERTIES(VirtIORNGS390, vdev.conf),
576 DEFINE_PROP_END_OF_LIST(),
579 static void s390_virtio_rng_class_init(ObjectClass *klass, void *data)
581 DeviceClass *dc = DEVICE_CLASS(klass);
582 VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
584 k->init = s390_virtio_rng_init;
585 dc->props = s390_virtio_rng_properties;
588 static const TypeInfo s390_virtio_rng = {
589 .name = TYPE_VIRTIO_RNG_S390,
590 .parent = TYPE_VIRTIO_S390_DEVICE,
591 .instance_size = sizeof(VirtIORNGS390),
592 .instance_init = s390_virtio_rng_instance_init,
593 .class_init = s390_virtio_rng_class_init,
596 static int s390_virtio_busdev_init(DeviceState *dev)
598 VirtIOS390Device *_dev = (VirtIOS390Device *)dev;
599 VirtIOS390DeviceClass *_info = VIRTIO_S390_DEVICE_GET_CLASS(dev);
601 virtio_s390_bus_new(&_dev->bus, sizeof(_dev->bus), _dev);
603 return _info->init(_dev);
606 static void s390_virtio_busdev_reset(DeviceState *dev)
608 VirtIOS390Device *_dev = (VirtIOS390Device *)dev;
610 virtio_reset(_dev->vdev);
613 static void virtio_s390_device_class_init(ObjectClass *klass, void *data)
615 DeviceClass *dc = DEVICE_CLASS(klass);
617 dc->init = s390_virtio_busdev_init;
618 dc->bus_type = TYPE_S390_VIRTIO_BUS;
619 dc->unplug = qdev_simple_unplug_cb;
620 dc->reset = s390_virtio_busdev_reset;
623 static const TypeInfo virtio_s390_device_info = {
624 .name = TYPE_VIRTIO_S390_DEVICE,
625 .parent = TYPE_DEVICE,
626 .instance_size = sizeof(VirtIOS390Device),
627 .class_init = virtio_s390_device_class_init,
628 .class_size = sizeof(VirtIOS390DeviceClass),
629 .abstract = true,
632 static Property s390_virtio_scsi_properties[] = {
633 DEFINE_VIRTIO_SCSI_PROPERTIES(VirtIOSCSIS390, vdev.parent_obj.conf),
634 DEFINE_VIRTIO_SCSI_FEATURES(VirtIOS390Device, host_features),
635 DEFINE_PROP_END_OF_LIST(),
638 static void s390_virtio_scsi_class_init(ObjectClass *klass, void *data)
640 DeviceClass *dc = DEVICE_CLASS(klass);
641 VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
643 k->init = s390_virtio_scsi_init;
644 dc->props = s390_virtio_scsi_properties;
647 static const TypeInfo s390_virtio_scsi = {
648 .name = TYPE_VIRTIO_SCSI_S390,
649 .parent = TYPE_VIRTIO_S390_DEVICE,
650 .instance_size = sizeof(VirtIOSCSIS390),
651 .instance_init = s390_virtio_scsi_instance_init,
652 .class_init = s390_virtio_scsi_class_init,
655 #ifdef CONFIG_VHOST_SCSI
656 static Property s390_vhost_scsi_properties[] = {
657 DEFINE_VIRTIO_COMMON_FEATURES(VirtIOS390Device, host_features),
658 DEFINE_VHOST_SCSI_PROPERTIES(VHostSCSIS390, vdev.parent_obj.conf),
659 DEFINE_PROP_END_OF_LIST(),
662 static void s390_vhost_scsi_class_init(ObjectClass *klass, void *data)
664 DeviceClass *dc = DEVICE_CLASS(klass);
665 VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
667 k->init = s390_vhost_scsi_init;
668 dc->props = s390_vhost_scsi_properties;
671 static const TypeInfo s390_vhost_scsi = {
672 .name = TYPE_VHOST_SCSI_S390,
673 .parent = TYPE_VIRTIO_S390_DEVICE,
674 .instance_size = sizeof(VHostSCSIS390),
675 .instance_init = s390_vhost_scsi_instance_init,
676 .class_init = s390_vhost_scsi_class_init,
678 #endif
680 /***************** S390 Virtio Bus Bridge Device *******************/
681 /* Only required to have the virtio bus as child in the system bus */
683 static int s390_virtio_bridge_init(SysBusDevice *dev)
685 /* nothing */
686 return 0;
689 static void s390_virtio_bridge_class_init(ObjectClass *klass, void *data)
691 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
693 k->init = s390_virtio_bridge_init;
696 static const TypeInfo s390_virtio_bridge_info = {
697 .name = "s390-virtio-bridge",
698 .parent = TYPE_SYS_BUS_DEVICE,
699 .instance_size = sizeof(SysBusDevice),
700 .class_init = s390_virtio_bridge_class_init,
703 /* virtio-s390-bus */
705 static void virtio_s390_bus_new(VirtioBusState *bus, size_t bus_size,
706 VirtIOS390Device *dev)
708 DeviceState *qdev = DEVICE(dev);
709 BusState *qbus;
710 char virtio_bus_name[] = "virtio-bus";
712 qbus_create_inplace(bus, bus_size, TYPE_VIRTIO_S390_BUS,
713 qdev, virtio_bus_name);
714 qbus = BUS(bus);
715 qbus->allow_hotplug = 1;
718 static void virtio_s390_bus_class_init(ObjectClass *klass, void *data)
720 VirtioBusClass *k = VIRTIO_BUS_CLASS(klass);
721 BusClass *bus_class = BUS_CLASS(klass);
722 bus_class->max_dev = 1;
723 k->notify = virtio_s390_notify;
724 k->get_features = virtio_s390_get_features;
727 static const TypeInfo virtio_s390_bus_info = {
728 .name = TYPE_VIRTIO_S390_BUS,
729 .parent = TYPE_VIRTIO_BUS,
730 .instance_size = sizeof(VirtioS390BusState),
731 .class_init = virtio_s390_bus_class_init,
734 static void s390_virtio_register_types(void)
736 type_register_static(&virtio_s390_bus_info);
737 type_register_static(&s390_virtio_bus_info);
738 type_register_static(&virtio_s390_device_info);
739 type_register_static(&s390_virtio_serial);
740 type_register_static(&s390_virtio_blk);
741 type_register_static(&s390_virtio_net);
742 type_register_static(&s390_virtio_scsi);
743 #ifdef CONFIG_VHOST_SCSI
744 type_register_static(&s390_vhost_scsi);
745 #endif
746 type_register_static(&s390_virtio_rng);
747 type_register_static(&s390_virtio_bridge_info);
750 type_init(s390_virtio_register_types)