s390-virtio: use common features
[qemu/qmp-unstable.git] / hw / s390x / s390-virtio-bus.c
blob4a33c6a4091511aa5621ede9b8b5ac5a8b093a8e
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 "sysemu/block-backend.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 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,
53 .parent = TYPE_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)
70 int i;
71 hwaddr idx_addr;
72 uint8_t num_vq;
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_used_addr(dev->vdev, i) +
81 VIRTIO_VRING_USED_IDX_OFFS;
82 address_space_stw(&address_space_memory, idx_addr, 0,
83 MEMTXATTRS_UNSPECIFIED, NULL);
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 qbus_set_hotplug_handler(_bus, dev, &error_abort);
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_device_init(VirtIOS390Device *dev,
117 VirtIODevice *vdev)
119 VirtIOS390Bus *bus;
120 int dev_len;
122 bus = DO_UPCAST(VirtIOS390Bus, bus, dev->qdev.parent_bus);
123 dev->vdev = vdev;
124 dev->dev_offs = bus->dev_offs;
125 dev->feat_len = sizeof(uint32_t); /* always keep 32 bits features */
127 dev_len = VIRTIO_DEV_OFFS_CONFIG;
128 dev_len += s390_virtio_device_num_vq(dev) * VIRTIO_VQCONFIG_LEN;
129 dev_len += dev->feat_len * 2;
130 dev_len += virtio_bus_get_vdev_config_len(&dev->bus);
132 bus->dev_offs += dev_len;
134 dev->host_features = virtio_bus_get_vdev_features(&dev->bus,
135 dev->host_features);
136 s390_virtio_device_sync(dev);
137 s390_virtio_reset_idx(dev);
138 if (dev->qdev.hotplugged) {
139 s390_virtio_irq(VIRTIO_PARAM_DEV_ADD, dev->dev_offs);
143 static void s390_virtio_net_realize(VirtIOS390Device *s390_dev, Error **errp)
145 DeviceState *qdev = DEVICE(s390_dev);
146 VirtIONetS390 *dev = VIRTIO_NET_S390(s390_dev);
147 DeviceState *vdev = DEVICE(&dev->vdev);
148 Error *err = NULL;
150 virtio_net_set_config_size(&dev->vdev, s390_dev->host_features);
151 virtio_net_set_netclient_name(&dev->vdev, qdev->id,
152 object_get_typename(OBJECT(qdev)));
153 qdev_set_parent_bus(vdev, BUS(&s390_dev->bus));
154 object_property_set_bool(OBJECT(vdev), true, "realized", &err);
155 if (err) {
156 error_propagate(errp, err);
157 return;
160 s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
163 static void s390_virtio_net_instance_init(Object *obj)
165 VirtIONetS390 *dev = VIRTIO_NET_S390(obj);
167 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
168 TYPE_VIRTIO_NET);
169 object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev),
170 "bootindex", &error_abort);
173 static void s390_virtio_blk_realize(VirtIOS390Device *s390_dev, Error **errp)
175 VirtIOBlkS390 *dev = VIRTIO_BLK_S390(s390_dev);
176 DeviceState *vdev = DEVICE(&dev->vdev);
177 Error *err = NULL;
179 qdev_set_parent_bus(vdev, BUS(&s390_dev->bus));
180 object_property_set_bool(OBJECT(vdev), true, "realized", &err);
181 if (err) {
182 error_propagate(errp, err);
183 return;
185 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);
192 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
193 TYPE_VIRTIO_BLK);
194 object_property_add_alias(obj, "iothread", OBJECT(&dev->vdev),"iothread",
195 &error_abort);
196 object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev),
197 "bootindex", &error_abort);
200 static void s390_virtio_serial_realize(VirtIOS390Device *s390_dev, Error **errp)
202 VirtIOSerialS390 *dev = VIRTIO_SERIAL_S390(s390_dev);
203 DeviceState *vdev = DEVICE(&dev->vdev);
204 DeviceState *qdev = DEVICE(s390_dev);
205 Error *err = NULL;
206 VirtIOS390Bus *bus;
207 char *bus_name;
209 bus = DO_UPCAST(VirtIOS390Bus, bus, qdev->parent_bus);
212 * For command line compatibility, this sets the virtio-serial-device bus
213 * name as before.
215 if (qdev->id) {
216 bus_name = g_strdup_printf("%s.0", qdev->id);
217 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name);
218 g_free(bus_name);
221 qdev_set_parent_bus(vdev, BUS(&s390_dev->bus));
222 object_property_set_bool(OBJECT(vdev), true, "realized", &err);
223 if (err) {
224 error_propagate(errp, err);
225 return;
228 s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
229 bus->console = s390_dev;
232 static void s390_virtio_serial_instance_init(Object *obj)
234 VirtIOSerialS390 *dev = VIRTIO_SERIAL_S390(obj);
236 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
237 TYPE_VIRTIO_SERIAL);
240 static void s390_virtio_scsi_realize(VirtIOS390Device *s390_dev, Error **errp)
242 VirtIOSCSIS390 *dev = VIRTIO_SCSI_S390(s390_dev);
243 DeviceState *vdev = DEVICE(&dev->vdev);
244 DeviceState *qdev = DEVICE(s390_dev);
245 Error *err = NULL;
246 char *bus_name;
249 * For command line compatibility, this sets the virtio-scsi-device bus
250 * name as before.
252 if (qdev->id) {
253 bus_name = g_strdup_printf("%s.0", qdev->id);
254 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name);
255 g_free(bus_name);
258 qdev_set_parent_bus(vdev, BUS(&s390_dev->bus));
259 object_property_set_bool(OBJECT(vdev), true, "realized", &err);
260 if (err) {
261 error_propagate(errp, err);
262 return;
265 s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
268 static void s390_virtio_scsi_instance_init(Object *obj)
270 VirtIOSCSIS390 *dev = VIRTIO_SCSI_S390(obj);
272 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
273 TYPE_VIRTIO_SCSI);
276 #ifdef CONFIG_VHOST_SCSI
277 static void s390_vhost_scsi_realize(VirtIOS390Device *s390_dev, Error **errp)
279 VHostSCSIS390 *dev = VHOST_SCSI_S390(s390_dev);
280 DeviceState *vdev = DEVICE(&dev->vdev);
281 Error *err = NULL;
283 qdev_set_parent_bus(vdev, BUS(&s390_dev->bus));
284 object_property_set_bool(OBJECT(vdev), true, "realized", &err);
285 if (err) {
286 error_propagate(errp, err);
287 return;
290 s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
293 static void s390_vhost_scsi_instance_init(Object *obj)
295 VHostSCSIS390 *dev = VHOST_SCSI_S390(obj);
297 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
298 TYPE_VHOST_SCSI);
300 #endif
303 static void s390_virtio_rng_realize(VirtIOS390Device *s390_dev, Error **errp)
305 VirtIORNGS390 *dev = VIRTIO_RNG_S390(s390_dev);
306 DeviceState *vdev = DEVICE(&dev->vdev);
307 Error *err = NULL;
309 qdev_set_parent_bus(vdev, BUS(&s390_dev->bus));
310 object_property_set_bool(OBJECT(vdev), true, "realized", &err);
311 if (err) {
312 error_propagate(errp, err);
313 return;
316 object_property_set_link(OBJECT(dev),
317 OBJECT(dev->vdev.conf.rng), "rng",
318 NULL);
320 s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
323 static void s390_virtio_rng_instance_init(Object *obj)
325 VirtIORNGS390 *dev = VIRTIO_RNG_S390(obj);
327 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
328 TYPE_VIRTIO_RNG);
329 object_property_add_alias(obj, "rng", OBJECT(&dev->vdev),
330 "rng", &error_abort);
333 static uint64_t s390_virtio_device_vq_token(VirtIOS390Device *dev, int vq)
335 ram_addr_t token_off;
337 token_off = (dev->dev_offs + VIRTIO_DEV_OFFS_CONFIG) +
338 (vq * VIRTIO_VQCONFIG_LEN) +
339 VIRTIO_VQCONFIG_OFFS_TOKEN;
341 return address_space_ldq_be(&address_space_memory, token_off,
342 MEMTXATTRS_UNSPECIFIED, NULL);
345 static ram_addr_t s390_virtio_device_num_vq(VirtIOS390Device *dev)
347 VirtIODevice *vdev = dev->vdev;
348 int num_vq;
350 for (num_vq = 0; num_vq < VIRTIO_PCI_QUEUE_MAX; num_vq++) {
351 if (!virtio_queue_get_num(vdev, num_vq)) {
352 break;
356 return num_vq;
359 static ram_addr_t s390_virtio_next_ring(VirtIOS390Bus *bus)
361 ram_addr_t r = bus->next_ring;
363 bus->next_ring += VIRTIO_RING_LEN;
364 return r;
367 void s390_virtio_device_sync(VirtIOS390Device *dev)
369 VirtIOS390Bus *bus = DO_UPCAST(VirtIOS390Bus, bus, dev->qdev.parent_bus);
370 ram_addr_t cur_offs;
371 uint8_t num_vq;
372 int i;
374 virtio_reset(dev->vdev);
376 /* Sync dev space */
377 address_space_stb(&address_space_memory,
378 dev->dev_offs + VIRTIO_DEV_OFFS_TYPE,
379 dev->vdev->device_id,
380 MEMTXATTRS_UNSPECIFIED,
381 NULL);
383 address_space_stb(&address_space_memory,
384 dev->dev_offs + VIRTIO_DEV_OFFS_NUM_VQ,
385 s390_virtio_device_num_vq(dev),
386 MEMTXATTRS_UNSPECIFIED,
387 NULL);
388 address_space_stb(&address_space_memory,
389 dev->dev_offs + VIRTIO_DEV_OFFS_FEATURE_LEN,
390 dev->feat_len,
391 MEMTXATTRS_UNSPECIFIED,
392 NULL);
394 address_space_stb(&address_space_memory,
395 dev->dev_offs + VIRTIO_DEV_OFFS_CONFIG_LEN,
396 dev->vdev->config_len,
397 MEMTXATTRS_UNSPECIFIED,
398 NULL);
400 num_vq = s390_virtio_device_num_vq(dev);
401 address_space_stb(&address_space_memory,
402 dev->dev_offs + VIRTIO_DEV_OFFS_NUM_VQ, num_vq,
403 MEMTXATTRS_UNSPECIFIED, NULL);
405 /* Sync virtqueues */
406 for (i = 0; i < num_vq; i++) {
407 ram_addr_t vq = (dev->dev_offs + VIRTIO_DEV_OFFS_CONFIG) +
408 (i * VIRTIO_VQCONFIG_LEN);
409 ram_addr_t vring;
411 vring = s390_virtio_next_ring(bus);
412 virtio_queue_set_addr(dev->vdev, i, vring);
413 virtio_queue_set_vector(dev->vdev, i, i);
414 address_space_stq_be(&address_space_memory,
415 vq + VIRTIO_VQCONFIG_OFFS_ADDRESS, vring,
416 MEMTXATTRS_UNSPECIFIED, NULL);
417 address_space_stw_be(&address_space_memory,
418 vq + VIRTIO_VQCONFIG_OFFS_NUM,
419 virtio_queue_get_num(dev->vdev, i),
420 MEMTXATTRS_UNSPECIFIED,
421 NULL);
424 cur_offs = dev->dev_offs;
425 cur_offs += VIRTIO_DEV_OFFS_CONFIG;
426 cur_offs += num_vq * VIRTIO_VQCONFIG_LEN;
428 /* Sync feature bitmap */
429 address_space_stl_le(&address_space_memory, cur_offs, dev->host_features,
430 MEMTXATTRS_UNSPECIFIED, NULL);
432 dev->feat_offs = cur_offs + dev->feat_len;
433 cur_offs += dev->feat_len * 2;
435 /* Sync config space */
436 virtio_bus_get_vdev_config(&dev->bus, dev->vdev->config);
438 cpu_physical_memory_write(cur_offs,
439 dev->vdev->config, dev->vdev->config_len);
440 cur_offs += dev->vdev->config_len;
443 void s390_virtio_device_update_status(VirtIOS390Device *dev)
445 VirtIODevice *vdev = dev->vdev;
446 uint32_t features;
448 virtio_set_status(vdev,
449 address_space_ldub(&address_space_memory,
450 dev->dev_offs + VIRTIO_DEV_OFFS_STATUS,
451 MEMTXATTRS_UNSPECIFIED, NULL));
453 /* Update guest supported feature bitmap */
455 features = bswap32(address_space_ldl_be(&address_space_memory,
456 dev->feat_offs,
457 MEMTXATTRS_UNSPECIFIED, NULL));
458 virtio_set_features(vdev, features);
461 /* Find a device by vring address */
462 VirtIOS390Device *s390_virtio_bus_find_vring(VirtIOS390Bus *bus,
463 ram_addr_t mem,
464 int *vq_num)
466 BusChild *kid;
467 int i;
469 QTAILQ_FOREACH(kid, &bus->bus.children, sibling) {
470 VirtIOS390Device *dev = (VirtIOS390Device *)kid->child;
472 for(i = 0; i < VIRTIO_PCI_QUEUE_MAX; i++) {
473 if (!virtio_queue_get_addr(dev->vdev, i))
474 break;
475 if (virtio_queue_get_addr(dev->vdev, i) == mem) {
476 if (vq_num) {
477 *vq_num = i;
479 return dev;
484 return NULL;
487 /* Find a device by device descriptor location */
488 VirtIOS390Device *s390_virtio_bus_find_mem(VirtIOS390Bus *bus, ram_addr_t mem)
490 BusChild *kid;
492 QTAILQ_FOREACH(kid, &bus->bus.children, sibling) {
493 VirtIOS390Device *dev = (VirtIOS390Device *)kid->child;
494 if (dev->dev_offs == mem) {
495 return dev;
499 return NULL;
502 /* DeviceState to VirtIOS390Device. Note: used on datapath,
503 * be careful and test performance if you change this.
505 static inline VirtIOS390Device *to_virtio_s390_device_fast(DeviceState *d)
507 return container_of(d, VirtIOS390Device, qdev);
510 /* DeviceState to VirtIOS390Device. TODO: use QOM. */
511 static inline VirtIOS390Device *to_virtio_s390_device(DeviceState *d)
513 return container_of(d, VirtIOS390Device, qdev);
516 static void virtio_s390_notify(DeviceState *d, uint16_t vector)
518 VirtIOS390Device *dev = to_virtio_s390_device_fast(d);
519 uint64_t token = s390_virtio_device_vq_token(dev, vector);
521 s390_virtio_irq(0, token);
524 static unsigned virtio_s390_get_features(DeviceState *d)
526 VirtIOS390Device *dev = to_virtio_s390_device(d);
527 return dev->host_features;
530 /**************** S390 Virtio Bus Device Descriptions *******************/
532 static Property s390_virtio_net_properties[] = {
533 DEFINE_VIRTIO_NET_FEATURES(VirtIOS390Device, host_features),
534 DEFINE_PROP_END_OF_LIST(),
537 static void s390_virtio_net_class_init(ObjectClass *klass, void *data)
539 DeviceClass *dc = DEVICE_CLASS(klass);
540 VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
542 k->realize = s390_virtio_net_realize;
543 dc->props = s390_virtio_net_properties;
544 set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
547 static const TypeInfo s390_virtio_net = {
548 .name = TYPE_VIRTIO_NET_S390,
549 .parent = TYPE_VIRTIO_S390_DEVICE,
550 .instance_size = sizeof(VirtIONetS390),
551 .instance_init = s390_virtio_net_instance_init,
552 .class_init = s390_virtio_net_class_init,
555 static void s390_virtio_blk_class_init(ObjectClass *klass, void *data)
557 VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
558 DeviceClass *dc = DEVICE_CLASS(klass);
560 k->realize = s390_virtio_blk_realize;
561 set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
564 static const TypeInfo s390_virtio_blk = {
565 .name = "virtio-blk-s390",
566 .parent = TYPE_VIRTIO_S390_DEVICE,
567 .instance_size = sizeof(VirtIOBlkS390),
568 .instance_init = s390_virtio_blk_instance_init,
569 .class_init = s390_virtio_blk_class_init,
572 static Property s390_virtio_serial_properties[] = {
573 DEFINE_PROP_END_OF_LIST(),
576 static void s390_virtio_serial_class_init(ObjectClass *klass, void *data)
578 DeviceClass *dc = DEVICE_CLASS(klass);
579 VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
581 k->realize = s390_virtio_serial_realize;
582 dc->props = s390_virtio_serial_properties;
583 set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
586 static const TypeInfo s390_virtio_serial = {
587 .name = TYPE_VIRTIO_SERIAL_S390,
588 .parent = TYPE_VIRTIO_S390_DEVICE,
589 .instance_size = sizeof(VirtIOSerialS390),
590 .instance_init = s390_virtio_serial_instance_init,
591 .class_init = s390_virtio_serial_class_init,
594 static void s390_virtio_rng_class_init(ObjectClass *klass, void *data)
596 DeviceClass *dc = DEVICE_CLASS(klass);
597 VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
599 k->realize = s390_virtio_rng_realize;
600 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
603 static const TypeInfo s390_virtio_rng = {
604 .name = TYPE_VIRTIO_RNG_S390,
605 .parent = TYPE_VIRTIO_S390_DEVICE,
606 .instance_size = sizeof(VirtIORNGS390),
607 .instance_init = s390_virtio_rng_instance_init,
608 .class_init = s390_virtio_rng_class_init,
611 static void s390_virtio_busdev_realize(DeviceState *dev, Error **errp)
613 VirtIOS390Device *_dev = (VirtIOS390Device *)dev;
614 VirtIOS390DeviceClass *_info = VIRTIO_S390_DEVICE_GET_CLASS(dev);
616 virtio_s390_bus_new(&_dev->bus, sizeof(_dev->bus), _dev);
618 _info->realize(_dev, errp);
621 static void s390_virtio_busdev_reset(DeviceState *dev)
623 VirtIOS390Device *_dev = (VirtIOS390Device *)dev;
625 virtio_reset(_dev->vdev);
628 static Property virtio_s390_properties[] = {
629 DEFINE_VIRTIO_COMMON_FEATURES(VirtIOS390Device, host_features),
630 DEFINE_PROP_END_OF_LIST(),
633 static void virtio_s390_device_class_init(ObjectClass *klass, void *data)
635 DeviceClass *dc = DEVICE_CLASS(klass);
637 dc->props = virtio_s390_properties;
638 dc->realize = s390_virtio_busdev_realize;
639 dc->bus_type = TYPE_S390_VIRTIO_BUS;
640 dc->reset = s390_virtio_busdev_reset;
643 static const TypeInfo virtio_s390_device_info = {
644 .name = TYPE_VIRTIO_S390_DEVICE,
645 .parent = TYPE_DEVICE,
646 .instance_size = sizeof(VirtIOS390Device),
647 .class_init = virtio_s390_device_class_init,
648 .class_size = sizeof(VirtIOS390DeviceClass),
649 .abstract = true,
652 static Property s390_virtio_scsi_properties[] = {
653 DEFINE_VIRTIO_SCSI_FEATURES(VirtIOS390Device, host_features),
654 DEFINE_PROP_END_OF_LIST(),
657 static void s390_virtio_scsi_class_init(ObjectClass *klass, void *data)
659 DeviceClass *dc = DEVICE_CLASS(klass);
660 VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
662 k->realize = s390_virtio_scsi_realize;
663 dc->props = s390_virtio_scsi_properties;
664 set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
667 static const TypeInfo s390_virtio_scsi = {
668 .name = TYPE_VIRTIO_SCSI_S390,
669 .parent = TYPE_VIRTIO_S390_DEVICE,
670 .instance_size = sizeof(VirtIOSCSIS390),
671 .instance_init = s390_virtio_scsi_instance_init,
672 .class_init = s390_virtio_scsi_class_init,
675 #ifdef CONFIG_VHOST_SCSI
676 static void s390_vhost_scsi_class_init(ObjectClass *klass, void *data)
678 DeviceClass *dc = DEVICE_CLASS(klass);
679 VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
681 k->realize = s390_vhost_scsi_realize;
682 set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
685 static const TypeInfo s390_vhost_scsi = {
686 .name = TYPE_VHOST_SCSI_S390,
687 .parent = TYPE_VIRTIO_S390_DEVICE,
688 .instance_size = sizeof(VHostSCSIS390),
689 .instance_init = s390_vhost_scsi_instance_init,
690 .class_init = s390_vhost_scsi_class_init,
692 #endif
694 /***************** S390 Virtio Bus Bridge Device *******************/
695 /* Only required to have the virtio bus as child in the system bus */
697 static int s390_virtio_bridge_init(SysBusDevice *dev)
699 /* nothing */
700 return 0;
703 static void s390_virtio_bridge_class_init(ObjectClass *klass, void *data)
705 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
706 DeviceClass *dc = DEVICE_CLASS(klass);
708 k->init = s390_virtio_bridge_init;
709 set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
712 static const TypeInfo s390_virtio_bridge_info = {
713 .name = "s390-virtio-bridge",
714 .parent = TYPE_SYS_BUS_DEVICE,
715 .instance_size = sizeof(SysBusDevice),
716 .class_init = s390_virtio_bridge_class_init,
717 .interfaces = (InterfaceInfo[]) {
718 { TYPE_HOTPLUG_HANDLER },
723 /* virtio-s390-bus */
725 static void virtio_s390_bus_new(VirtioBusState *bus, size_t bus_size,
726 VirtIOS390Device *dev)
728 DeviceState *qdev = DEVICE(dev);
729 char virtio_bus_name[] = "virtio-bus";
731 qbus_create_inplace(bus, bus_size, TYPE_VIRTIO_S390_BUS,
732 qdev, virtio_bus_name);
735 static void virtio_s390_bus_class_init(ObjectClass *klass, void *data)
737 VirtioBusClass *k = VIRTIO_BUS_CLASS(klass);
738 BusClass *bus_class = BUS_CLASS(klass);
739 bus_class->max_dev = 1;
740 k->notify = virtio_s390_notify;
741 k->get_features = virtio_s390_get_features;
744 static const TypeInfo virtio_s390_bus_info = {
745 .name = TYPE_VIRTIO_S390_BUS,
746 .parent = TYPE_VIRTIO_BUS,
747 .instance_size = sizeof(VirtioS390BusState),
748 .class_init = virtio_s390_bus_class_init,
751 static void s390_virtio_register_types(void)
753 type_register_static(&virtio_s390_bus_info);
754 type_register_static(&s390_virtio_bus_info);
755 type_register_static(&virtio_s390_device_info);
756 type_register_static(&s390_virtio_serial);
757 type_register_static(&s390_virtio_blk);
758 type_register_static(&s390_virtio_net);
759 type_register_static(&s390_virtio_scsi);
760 #ifdef CONFIG_VHOST_SCSI
761 type_register_static(&s390_vhost_scsi);
762 #endif
763 type_register_static(&s390_virtio_rng);
764 type_register_static(&s390_virtio_bridge_info);
767 type_init(s390_virtio_register_types)