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