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