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