]> git.proxmox.com Git - mirror_qemu.git/blob - hw/s390x/s390-virtio-bus.c
hw: Convert from BlockDriverState to BlockBackend, mostly
[mirror_qemu.git] / hw / s390x / s390-virtio-bus.c
1 /*
2 * QEMU S390 virtio target
3 *
4 * Copyright (c) 2009 Alexander Graf <agraf@suse.de>
5 *
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.
10 *
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.
15 *
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/>.
18 */
19
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"
34
35 #include "hw/s390x/s390-virtio-bus.h"
36 #include "hw/virtio/virtio-bus.h"
37
38 /* #define DEBUG_S390 */
39
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
47
48 static void virtio_s390_bus_new(VirtioBusState *bus, size_t bus_size,
49 VirtIOS390Device *dev);
50
51 static const TypeInfo s390_virtio_bus_info = {
52 .name = TYPE_S390_VIRTIO_BUS,
53 .parent = TYPE_BUS,
54 .instance_size = sizeof(VirtIOS390Bus),
55 };
56
57 static ram_addr_t s390_virtio_device_num_vq(VirtIOS390Device *dev);
58
59 /* length of VirtIO device pages */
60 const hwaddr virtio_size = S390_DEVICE_PAGES * TARGET_PAGE_SIZE;
61
62 static void s390_virtio_bus_reset(void *opaque)
63 {
64 VirtIOS390Bus *bus = opaque;
65 bus->next_ring = bus->dev_page + TARGET_PAGE_SIZE;
66 }
67
68 void s390_virtio_reset_idx(VirtIOS390Device *dev)
69 {
70 int i;
71 hwaddr idx_addr;
72 uint8_t num_vq;
73
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);
82 }
83 }
84
85 VirtIOS390Bus *s390_virtio_bus_init(ram_addr_t *ram_size)
86 {
87 VirtIOS390Bus *bus;
88 BusState *_bus;
89 DeviceState *dev;
90
91 /* Create bridge device */
92 dev = qdev_create(NULL, "s390-virtio-bridge");
93 qdev_init_nofail(dev);
94
95 /* Create bus on bridge device */
96
97 _bus = qbus_create(TYPE_S390_VIRTIO_BUS, dev, "s390-virtio");
98 bus = DO_UPCAST(VirtIOS390Bus, bus, _bus);
99
100 bus->dev_page = *ram_size;
101 bus->dev_offs = bus->dev_page;
102 bus->next_ring = bus->dev_page + TARGET_PAGE_SIZE;
103
104 /* Enable hotplugging */
105 qbus_set_hotplug_handler(_bus, dev, &error_abort);
106
107 /* Allocate RAM for VirtIO device pages (descriptors, queues, rings) */
108 *ram_size += S390_DEVICE_PAGES * TARGET_PAGE_SIZE;
109
110 qemu_register_reset(s390_virtio_bus_reset, bus);
111 return bus;
112 }
113
114 static int s390_virtio_device_init(VirtIOS390Device *dev, VirtIODevice *vdev)
115 {
116 VirtIOS390Bus *bus;
117 int dev_len;
118
119 bus = DO_UPCAST(VirtIOS390Bus, bus, dev->qdev.parent_bus);
120 dev->vdev = vdev;
121 dev->dev_offs = bus->dev_offs;
122 dev->feat_len = sizeof(uint32_t); /* always keep 32 bits features */
123
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);
128
129 bus->dev_offs += dev_len;
130
131 dev->host_features = virtio_bus_get_vdev_features(&dev->bus,
132 dev->host_features);
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);
137 }
138
139 return 0;
140 }
141
142 static int s390_virtio_net_init(VirtIOS390Device *s390_dev)
143 {
144 DeviceState *qdev = DEVICE(s390_dev);
145 VirtIONetS390 *dev = VIRTIO_NET_S390(s390_dev);
146 DeviceState *vdev = DEVICE(&dev->vdev);
147
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) {
153 return -1;
154 }
155
156 return s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
157 }
158
159 static void s390_virtio_net_instance_init(Object *obj)
160 {
161 VirtIONetS390 *dev = VIRTIO_NET_S390(obj);
162
163 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
164 TYPE_VIRTIO_NET);
165 object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev),
166 "bootindex", &error_abort);
167 }
168
169 static int s390_virtio_blk_init(VirtIOS390Device *s390_dev)
170 {
171 VirtIOBlkS390 *dev = VIRTIO_BLK_S390(s390_dev);
172 DeviceState *vdev = DEVICE(&dev->vdev);
173 qdev_set_parent_bus(vdev, BUS(&s390_dev->bus));
174 if (qdev_init(vdev) < 0) {
175 return -1;
176 }
177 return s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
178 }
179
180 static void s390_virtio_blk_instance_init(Object *obj)
181 {
182 VirtIOBlkS390 *dev = VIRTIO_BLK_S390(obj);
183
184 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
185 TYPE_VIRTIO_BLK);
186 object_property_add_alias(obj, "iothread", OBJECT(&dev->vdev),"iothread",
187 &error_abort);
188 object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev),
189 "bootindex", &error_abort);
190 }
191
192 static int s390_virtio_serial_init(VirtIOS390Device *s390_dev)
193 {
194 VirtIOSerialS390 *dev = VIRTIO_SERIAL_S390(s390_dev);
195 DeviceState *vdev = DEVICE(&dev->vdev);
196 DeviceState *qdev = DEVICE(s390_dev);
197 VirtIOS390Bus *bus;
198 int r;
199 char *bus_name;
200
201 bus = DO_UPCAST(VirtIOS390Bus, bus, qdev->parent_bus);
202
203 /*
204 * For command line compatibility, this sets the virtio-serial-device bus
205 * name as before.
206 */
207 if (qdev->id) {
208 bus_name = g_strdup_printf("%s.0", qdev->id);
209 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name);
210 g_free(bus_name);
211 }
212
213 qdev_set_parent_bus(vdev, BUS(&s390_dev->bus));
214 if (qdev_init(vdev) < 0) {
215 return -1;
216 }
217
218 r = s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
219 if (!r) {
220 bus->console = s390_dev;
221 }
222
223 return r;
224 }
225
226 static void s390_virtio_serial_instance_init(Object *obj)
227 {
228 VirtIOSerialS390 *dev = VIRTIO_SERIAL_S390(obj);
229
230 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
231 TYPE_VIRTIO_SERIAL);
232 }
233
234 static int s390_virtio_scsi_init(VirtIOS390Device *s390_dev)
235 {
236 VirtIOSCSIS390 *dev = VIRTIO_SCSI_S390(s390_dev);
237 DeviceState *vdev = DEVICE(&dev->vdev);
238 DeviceState *qdev = DEVICE(s390_dev);
239 char *bus_name;
240
241 /*
242 * For command line compatibility, this sets the virtio-scsi-device bus
243 * name as before.
244 */
245 if (qdev->id) {
246 bus_name = g_strdup_printf("%s.0", qdev->id);
247 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name);
248 g_free(bus_name);
249 }
250
251 qdev_set_parent_bus(vdev, BUS(&s390_dev->bus));
252 if (qdev_init(vdev) < 0) {
253 return -1;
254 }
255
256 return s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
257 }
258
259 static void s390_virtio_scsi_instance_init(Object *obj)
260 {
261 VirtIOSCSIS390 *dev = VIRTIO_SCSI_S390(obj);
262
263 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
264 TYPE_VIRTIO_SCSI);
265 }
266
267 #ifdef CONFIG_VHOST_SCSI
268 static int s390_vhost_scsi_init(VirtIOS390Device *s390_dev)
269 {
270 VHostSCSIS390 *dev = VHOST_SCSI_S390(s390_dev);
271 DeviceState *vdev = DEVICE(&dev->vdev);
272
273 qdev_set_parent_bus(vdev, BUS(&s390_dev->bus));
274 if (qdev_init(vdev) < 0) {
275 return -1;
276 }
277
278 return s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
279 }
280
281 static void s390_vhost_scsi_instance_init(Object *obj)
282 {
283 VHostSCSIS390 *dev = VHOST_SCSI_S390(obj);
284
285 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
286 TYPE_VHOST_SCSI);
287 }
288 #endif
289
290
291 static int s390_virtio_rng_init(VirtIOS390Device *s390_dev)
292 {
293 VirtIORNGS390 *dev = VIRTIO_RNG_S390(s390_dev);
294 DeviceState *vdev = DEVICE(&dev->vdev);
295
296 qdev_set_parent_bus(vdev, BUS(&s390_dev->bus));
297 if (qdev_init(vdev) < 0) {
298 return -1;
299 }
300
301 object_property_set_link(OBJECT(dev),
302 OBJECT(dev->vdev.conf.rng), "rng",
303 NULL);
304
305 return s390_virtio_device_init(s390_dev, VIRTIO_DEVICE(vdev));
306 }
307
308 static void s390_virtio_rng_instance_init(Object *obj)
309 {
310 VirtIORNGS390 *dev = VIRTIO_RNG_S390(obj);
311
312 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
313 TYPE_VIRTIO_RNG);
314 object_property_add_link(obj, "rng", TYPE_RNG_BACKEND,
315 (Object **)&dev->vdev.conf.rng,
316 qdev_prop_allow_set_link_before_realize,
317 OBJ_PROP_LINK_UNREF_ON_RELEASE, NULL);
318 }
319
320 static uint64_t s390_virtio_device_vq_token(VirtIOS390Device *dev, int vq)
321 {
322 ram_addr_t token_off;
323
324 token_off = (dev->dev_offs + VIRTIO_DEV_OFFS_CONFIG) +
325 (vq * VIRTIO_VQCONFIG_LEN) +
326 VIRTIO_VQCONFIG_OFFS_TOKEN;
327
328 return ldq_be_phys(&address_space_memory, token_off);
329 }
330
331 static ram_addr_t s390_virtio_device_num_vq(VirtIOS390Device *dev)
332 {
333 VirtIODevice *vdev = dev->vdev;
334 int num_vq;
335
336 for (num_vq = 0; num_vq < VIRTIO_PCI_QUEUE_MAX; num_vq++) {
337 if (!virtio_queue_get_num(vdev, num_vq)) {
338 break;
339 }
340 }
341
342 return num_vq;
343 }
344
345 static ram_addr_t s390_virtio_next_ring(VirtIOS390Bus *bus)
346 {
347 ram_addr_t r = bus->next_ring;
348
349 bus->next_ring += VIRTIO_RING_LEN;
350 return r;
351 }
352
353 void s390_virtio_device_sync(VirtIOS390Device *dev)
354 {
355 VirtIOS390Bus *bus = DO_UPCAST(VirtIOS390Bus, bus, dev->qdev.parent_bus);
356 ram_addr_t cur_offs;
357 uint8_t num_vq;
358 int i;
359
360 virtio_reset(dev->vdev);
361
362 /* Sync dev space */
363 stb_phys(&address_space_memory,
364 dev->dev_offs + VIRTIO_DEV_OFFS_TYPE, dev->vdev->device_id);
365
366 stb_phys(&address_space_memory,
367 dev->dev_offs + VIRTIO_DEV_OFFS_NUM_VQ,
368 s390_virtio_device_num_vq(dev));
369 stb_phys(&address_space_memory,
370 dev->dev_offs + VIRTIO_DEV_OFFS_FEATURE_LEN, dev->feat_len);
371
372 stb_phys(&address_space_memory,
373 dev->dev_offs + VIRTIO_DEV_OFFS_CONFIG_LEN, dev->vdev->config_len);
374
375 num_vq = s390_virtio_device_num_vq(dev);
376 stb_phys(&address_space_memory,
377 dev->dev_offs + VIRTIO_DEV_OFFS_NUM_VQ, num_vq);
378
379 /* Sync virtqueues */
380 for (i = 0; i < num_vq; i++) {
381 ram_addr_t vq = (dev->dev_offs + VIRTIO_DEV_OFFS_CONFIG) +
382 (i * VIRTIO_VQCONFIG_LEN);
383 ram_addr_t vring;
384
385 vring = s390_virtio_next_ring(bus);
386 virtio_queue_set_addr(dev->vdev, i, vring);
387 virtio_queue_set_vector(dev->vdev, i, i);
388 stq_be_phys(&address_space_memory,
389 vq + VIRTIO_VQCONFIG_OFFS_ADDRESS, vring);
390 stw_be_phys(&address_space_memory,
391 vq + VIRTIO_VQCONFIG_OFFS_NUM,
392 virtio_queue_get_num(dev->vdev, i));
393 }
394
395 cur_offs = dev->dev_offs;
396 cur_offs += VIRTIO_DEV_OFFS_CONFIG;
397 cur_offs += num_vq * VIRTIO_VQCONFIG_LEN;
398
399 /* Sync feature bitmap */
400 stl_le_phys(&address_space_memory, cur_offs, dev->host_features);
401
402 dev->feat_offs = cur_offs + dev->feat_len;
403 cur_offs += dev->feat_len * 2;
404
405 /* Sync config space */
406 virtio_bus_get_vdev_config(&dev->bus, dev->vdev->config);
407
408 cpu_physical_memory_write(cur_offs,
409 dev->vdev->config, dev->vdev->config_len);
410 cur_offs += dev->vdev->config_len;
411 }
412
413 void s390_virtio_device_update_status(VirtIOS390Device *dev)
414 {
415 VirtIODevice *vdev = dev->vdev;
416 uint32_t features;
417
418 virtio_set_status(vdev, ldub_phys(&address_space_memory,
419 dev->dev_offs + VIRTIO_DEV_OFFS_STATUS));
420
421 /* Update guest supported feature bitmap */
422
423 features = bswap32(ldl_be_phys(&address_space_memory, dev->feat_offs));
424 virtio_set_features(vdev, features);
425 }
426
427 VirtIOS390Device *s390_virtio_bus_console(VirtIOS390Bus *bus)
428 {
429 return bus->console;
430 }
431
432 /* Find a device by vring address */
433 VirtIOS390Device *s390_virtio_bus_find_vring(VirtIOS390Bus *bus,
434 ram_addr_t mem,
435 int *vq_num)
436 {
437 BusChild *kid;
438 int i;
439
440 QTAILQ_FOREACH(kid, &bus->bus.children, sibling) {
441 VirtIOS390Device *dev = (VirtIOS390Device *)kid->child;
442
443 for(i = 0; i < VIRTIO_PCI_QUEUE_MAX; i++) {
444 if (!virtio_queue_get_addr(dev->vdev, i))
445 break;
446 if (virtio_queue_get_addr(dev->vdev, i) == mem) {
447 if (vq_num) {
448 *vq_num = i;
449 }
450 return dev;
451 }
452 }
453 }
454
455 return NULL;
456 }
457
458 /* Find a device by device descriptor location */
459 VirtIOS390Device *s390_virtio_bus_find_mem(VirtIOS390Bus *bus, ram_addr_t mem)
460 {
461 BusChild *kid;
462
463 QTAILQ_FOREACH(kid, &bus->bus.children, sibling) {
464 VirtIOS390Device *dev = (VirtIOS390Device *)kid->child;
465 if (dev->dev_offs == mem) {
466 return dev;
467 }
468 }
469
470 return NULL;
471 }
472
473 /* DeviceState to VirtIOS390Device. Note: used on datapath,
474 * be careful and test performance if you change this.
475 */
476 static inline VirtIOS390Device *to_virtio_s390_device_fast(DeviceState *d)
477 {
478 return container_of(d, VirtIOS390Device, qdev);
479 }
480
481 /* DeviceState to VirtIOS390Device. TODO: use QOM. */
482 static inline VirtIOS390Device *to_virtio_s390_device(DeviceState *d)
483 {
484 return container_of(d, VirtIOS390Device, qdev);
485 }
486
487 static void virtio_s390_notify(DeviceState *d, uint16_t vector)
488 {
489 VirtIOS390Device *dev = to_virtio_s390_device_fast(d);
490 uint64_t token = s390_virtio_device_vq_token(dev, vector);
491
492 s390_virtio_irq(0, token);
493 }
494
495 static unsigned virtio_s390_get_features(DeviceState *d)
496 {
497 VirtIOS390Device *dev = to_virtio_s390_device(d);
498 return dev->host_features;
499 }
500
501 /**************** S390 Virtio Bus Device Descriptions *******************/
502
503 static Property s390_virtio_net_properties[] = {
504 DEFINE_VIRTIO_COMMON_FEATURES(VirtIOS390Device, host_features),
505 DEFINE_VIRTIO_NET_FEATURES(VirtIOS390Device, host_features),
506 DEFINE_PROP_END_OF_LIST(),
507 };
508
509 static void s390_virtio_net_class_init(ObjectClass *klass, void *data)
510 {
511 DeviceClass *dc = DEVICE_CLASS(klass);
512 VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
513
514 k->init = s390_virtio_net_init;
515 dc->props = s390_virtio_net_properties;
516 }
517
518 static const TypeInfo s390_virtio_net = {
519 .name = TYPE_VIRTIO_NET_S390,
520 .parent = TYPE_VIRTIO_S390_DEVICE,
521 .instance_size = sizeof(VirtIONetS390),
522 .instance_init = s390_virtio_net_instance_init,
523 .class_init = s390_virtio_net_class_init,
524 };
525
526 static void s390_virtio_blk_class_init(ObjectClass *klass, void *data)
527 {
528 VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
529
530 k->init = s390_virtio_blk_init;
531 }
532
533 static const TypeInfo s390_virtio_blk = {
534 .name = "virtio-blk-s390",
535 .parent = TYPE_VIRTIO_S390_DEVICE,
536 .instance_size = sizeof(VirtIOBlkS390),
537 .instance_init = s390_virtio_blk_instance_init,
538 .class_init = s390_virtio_blk_class_init,
539 };
540
541 static Property s390_virtio_serial_properties[] = {
542 DEFINE_PROP_END_OF_LIST(),
543 };
544
545 static void s390_virtio_serial_class_init(ObjectClass *klass, void *data)
546 {
547 DeviceClass *dc = DEVICE_CLASS(klass);
548 VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
549
550 k->init = s390_virtio_serial_init;
551 dc->props = s390_virtio_serial_properties;
552 }
553
554 static const TypeInfo s390_virtio_serial = {
555 .name = TYPE_VIRTIO_SERIAL_S390,
556 .parent = TYPE_VIRTIO_S390_DEVICE,
557 .instance_size = sizeof(VirtIOSerialS390),
558 .instance_init = s390_virtio_serial_instance_init,
559 .class_init = s390_virtio_serial_class_init,
560 };
561
562 static Property s390_virtio_rng_properties[] = {
563 DEFINE_VIRTIO_COMMON_FEATURES(VirtIOS390Device, host_features),
564 DEFINE_PROP_END_OF_LIST(),
565 };
566
567 static void s390_virtio_rng_class_init(ObjectClass *klass, void *data)
568 {
569 DeviceClass *dc = DEVICE_CLASS(klass);
570 VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
571
572 k->init = s390_virtio_rng_init;
573 dc->props = s390_virtio_rng_properties;
574 }
575
576 static const TypeInfo s390_virtio_rng = {
577 .name = TYPE_VIRTIO_RNG_S390,
578 .parent = TYPE_VIRTIO_S390_DEVICE,
579 .instance_size = sizeof(VirtIORNGS390),
580 .instance_init = s390_virtio_rng_instance_init,
581 .class_init = s390_virtio_rng_class_init,
582 };
583
584 static int s390_virtio_busdev_init(DeviceState *dev)
585 {
586 VirtIOS390Device *_dev = (VirtIOS390Device *)dev;
587 VirtIOS390DeviceClass *_info = VIRTIO_S390_DEVICE_GET_CLASS(dev);
588
589 virtio_s390_bus_new(&_dev->bus, sizeof(_dev->bus), _dev);
590
591 return _info->init(_dev);
592 }
593
594 static void s390_virtio_busdev_reset(DeviceState *dev)
595 {
596 VirtIOS390Device *_dev = (VirtIOS390Device *)dev;
597
598 virtio_reset(_dev->vdev);
599 }
600
601 static void virtio_s390_device_class_init(ObjectClass *klass, void *data)
602 {
603 DeviceClass *dc = DEVICE_CLASS(klass);
604
605 dc->init = s390_virtio_busdev_init;
606 dc->bus_type = TYPE_S390_VIRTIO_BUS;
607 dc->reset = s390_virtio_busdev_reset;
608 }
609
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),
616 .abstract = true,
617 };
618
619 static Property s390_virtio_scsi_properties[] = {
620 DEFINE_VIRTIO_COMMON_FEATURES(VirtIOS390Device, host_features),
621 DEFINE_VIRTIO_SCSI_FEATURES(VirtIOS390Device, host_features),
622 DEFINE_PROP_END_OF_LIST(),
623 };
624
625 static void s390_virtio_scsi_class_init(ObjectClass *klass, void *data)
626 {
627 DeviceClass *dc = DEVICE_CLASS(klass);
628 VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
629
630 k->init = s390_virtio_scsi_init;
631 dc->props = s390_virtio_scsi_properties;
632 }
633
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,
640 };
641
642 #ifdef CONFIG_VHOST_SCSI
643 static Property s390_vhost_scsi_properties[] = {
644 DEFINE_VIRTIO_COMMON_FEATURES(VirtIOS390Device, host_features),
645 DEFINE_PROP_END_OF_LIST(),
646 };
647
648 static void s390_vhost_scsi_class_init(ObjectClass *klass, void *data)
649 {
650 DeviceClass *dc = DEVICE_CLASS(klass);
651 VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
652
653 k->init = s390_vhost_scsi_init;
654 dc->props = s390_vhost_scsi_properties;
655 }
656
657 static const TypeInfo s390_vhost_scsi = {
658 .name = TYPE_VHOST_SCSI_S390,
659 .parent = TYPE_VIRTIO_S390_DEVICE,
660 .instance_size = sizeof(VHostSCSIS390),
661 .instance_init = s390_vhost_scsi_instance_init,
662 .class_init = s390_vhost_scsi_class_init,
663 };
664 #endif
665
666 /***************** S390 Virtio Bus Bridge Device *******************/
667 /* Only required to have the virtio bus as child in the system bus */
668
669 static int s390_virtio_bridge_init(SysBusDevice *dev)
670 {
671 /* nothing */
672 return 0;
673 }
674
675 static void s390_virtio_bridge_class_init(ObjectClass *klass, void *data)
676 {
677 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
678
679 k->init = s390_virtio_bridge_init;
680 }
681
682 static const TypeInfo s390_virtio_bridge_info = {
683 .name = "s390-virtio-bridge",
684 .parent = TYPE_SYS_BUS_DEVICE,
685 .instance_size = sizeof(SysBusDevice),
686 .class_init = s390_virtio_bridge_class_init,
687 .interfaces = (InterfaceInfo[]) {
688 { TYPE_HOTPLUG_HANDLER },
689 { }
690 }
691 };
692
693 /* virtio-s390-bus */
694
695 static void virtio_s390_bus_new(VirtioBusState *bus, size_t bus_size,
696 VirtIOS390Device *dev)
697 {
698 DeviceState *qdev = DEVICE(dev);
699 char virtio_bus_name[] = "virtio-bus";
700
701 qbus_create_inplace(bus, bus_size, TYPE_VIRTIO_S390_BUS,
702 qdev, virtio_bus_name);
703 }
704
705 static void virtio_s390_bus_class_init(ObjectClass *klass, void *data)
706 {
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;
712 }
713
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,
719 };
720
721 static void s390_virtio_register_types(void)
722 {
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);
732 #endif
733 type_register_static(&s390_virtio_rng);
734 type_register_static(&s390_virtio_bridge_info);
735 }
736
737 type_init(s390_virtio_register_types)