exec: Make ldl_*_phys input an AddressSpace
[qemu.git] / hw / s390x / virtio-ccw.c
1 /*
2 * virtio ccw target implementation
3 *
4 * Copyright 2012 IBM Corp.
5 * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
6 *
7 * This work is licensed under the terms of the GNU GPL, version 2 or (at
8 * your option) any later version. See the COPYING file in the top-level
9 * directory.
10 */
11
12 #include "hw/hw.h"
13 #include "block/block.h"
14 #include "sysemu/blockdev.h"
15 #include "sysemu/sysemu.h"
16 #include "net/net.h"
17 #include "monitor/monitor.h"
18 #include "hw/virtio/virtio.h"
19 #include "hw/virtio/virtio-serial.h"
20 #include "hw/virtio/virtio-net.h"
21 #include "hw/sysbus.h"
22 #include "qemu/bitops.h"
23 #include "hw/virtio/virtio-bus.h"
24
25 #include "ioinst.h"
26 #include "css.h"
27 #include "virtio-ccw.h"
28 #include "trace.h"
29
30 static void virtio_ccw_bus_new(VirtioBusState *bus, size_t bus_size,
31 VirtioCcwDevice *dev);
32
33 static void virtual_css_bus_reset(BusState *qbus)
34 {
35 /* This should actually be modelled via the generic css */
36 css_reset();
37 }
38
39
40 static void virtual_css_bus_class_init(ObjectClass *klass, void *data)
41 {
42 BusClass *k = BUS_CLASS(klass);
43
44 k->reset = virtual_css_bus_reset;
45 }
46
47 static const TypeInfo virtual_css_bus_info = {
48 .name = TYPE_VIRTUAL_CSS_BUS,
49 .parent = TYPE_BUS,
50 .instance_size = sizeof(VirtualCssBus),
51 .class_init = virtual_css_bus_class_init,
52 };
53
54 VirtIODevice *virtio_ccw_get_vdev(SubchDev *sch)
55 {
56 VirtIODevice *vdev = NULL;
57 VirtioCcwDevice *dev = sch->driver_data;
58
59 if (dev) {
60 vdev = virtio_bus_get_device(&dev->bus);
61 }
62 return vdev;
63 }
64
65 static int virtio_ccw_set_guest2host_notifier(VirtioCcwDevice *dev, int n,
66 bool assign, bool set_handler)
67 {
68 VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
69 VirtQueue *vq = virtio_get_queue(vdev, n);
70 EventNotifier *notifier = virtio_queue_get_host_notifier(vq);
71 int r = 0;
72 SubchDev *sch = dev->sch;
73 uint32_t sch_id = (css_build_subchannel_id(sch) << 16) | sch->schid;
74
75 if (assign) {
76 r = event_notifier_init(notifier, 1);
77 if (r < 0) {
78 error_report("%s: unable to init event notifier: %d", __func__, r);
79 return r;
80 }
81 virtio_queue_set_host_notifier_fd_handler(vq, true, set_handler);
82 r = s390_assign_subch_ioeventfd(notifier, sch_id, n, assign);
83 if (r < 0) {
84 error_report("%s: unable to assign ioeventfd: %d", __func__, r);
85 virtio_queue_set_host_notifier_fd_handler(vq, false, false);
86 event_notifier_cleanup(notifier);
87 return r;
88 }
89 } else {
90 virtio_queue_set_host_notifier_fd_handler(vq, false, false);
91 s390_assign_subch_ioeventfd(notifier, sch_id, n, assign);
92 event_notifier_cleanup(notifier);
93 }
94 return r;
95 }
96
97 static void virtio_ccw_start_ioeventfd(VirtioCcwDevice *dev)
98 {
99 VirtIODevice *vdev;
100 int n, r;
101
102 if (!(dev->flags & VIRTIO_CCW_FLAG_USE_IOEVENTFD) ||
103 dev->ioeventfd_disabled ||
104 dev->ioeventfd_started) {
105 return;
106 }
107 vdev = virtio_bus_get_device(&dev->bus);
108 for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) {
109 if (!virtio_queue_get_num(vdev, n)) {
110 continue;
111 }
112 r = virtio_ccw_set_guest2host_notifier(dev, n, true, true);
113 if (r < 0) {
114 goto assign_error;
115 }
116 }
117 dev->ioeventfd_started = true;
118 return;
119
120 assign_error:
121 while (--n >= 0) {
122 if (!virtio_queue_get_num(vdev, n)) {
123 continue;
124 }
125 r = virtio_ccw_set_guest2host_notifier(dev, n, false, false);
126 assert(r >= 0);
127 }
128 dev->ioeventfd_started = false;
129 /* Disable ioeventfd for this device. */
130 dev->flags &= ~VIRTIO_CCW_FLAG_USE_IOEVENTFD;
131 error_report("%s: failed. Fallback to userspace (slower).", __func__);
132 }
133
134 static void virtio_ccw_stop_ioeventfd(VirtioCcwDevice *dev)
135 {
136 VirtIODevice *vdev;
137 int n, r;
138
139 if (!dev->ioeventfd_started) {
140 return;
141 }
142 vdev = virtio_bus_get_device(&dev->bus);
143 for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) {
144 if (!virtio_queue_get_num(vdev, n)) {
145 continue;
146 }
147 r = virtio_ccw_set_guest2host_notifier(dev, n, false, false);
148 assert(r >= 0);
149 }
150 dev->ioeventfd_started = false;
151 }
152
153 VirtualCssBus *virtual_css_bus_init(void)
154 {
155 VirtualCssBus *cbus;
156 BusState *bus;
157 DeviceState *dev;
158
159 /* Create bridge device */
160 dev = qdev_create(NULL, "virtual-css-bridge");
161 qdev_init_nofail(dev);
162
163 /* Create bus on bridge device */
164 bus = qbus_create(TYPE_VIRTUAL_CSS_BUS, dev, "virtual-css");
165 cbus = VIRTUAL_CSS_BUS(bus);
166
167 /* Enable hotplugging */
168 bus->allow_hotplug = 1;
169
170 return cbus;
171 }
172
173 /* Communication blocks used by several channel commands. */
174 typedef struct VqInfoBlock {
175 uint64_t queue;
176 uint32_t align;
177 uint16_t index;
178 uint16_t num;
179 } QEMU_PACKED VqInfoBlock;
180
181 typedef struct VqConfigBlock {
182 uint16_t index;
183 uint16_t num_max;
184 } QEMU_PACKED VqConfigBlock;
185
186 typedef struct VirtioFeatDesc {
187 uint32_t features;
188 uint8_t index;
189 } QEMU_PACKED VirtioFeatDesc;
190
191 /* Specify where the virtqueues for the subchannel are in guest memory. */
192 static int virtio_ccw_set_vqs(SubchDev *sch, uint64_t addr, uint32_t align,
193 uint16_t index, uint16_t num)
194 {
195 VirtIODevice *vdev = virtio_ccw_get_vdev(sch);
196
197 if (index > VIRTIO_PCI_QUEUE_MAX) {
198 return -EINVAL;
199 }
200
201 /* Current code in virtio.c relies on 4K alignment. */
202 if (addr && (align != 4096)) {
203 return -EINVAL;
204 }
205
206 if (!vdev) {
207 return -EINVAL;
208 }
209
210 virtio_queue_set_addr(vdev, index, addr);
211 if (!addr) {
212 virtio_queue_set_vector(vdev, index, 0);
213 } else {
214 /* Fail if we don't have a big enough queue. */
215 /* TODO: Add interface to handle vring.num changing */
216 if (virtio_queue_get_num(vdev, index) > num) {
217 return -EINVAL;
218 }
219 virtio_queue_set_vector(vdev, index, index);
220 }
221 /* tell notify handler in case of config change */
222 vdev->config_vector = VIRTIO_PCI_QUEUE_MAX;
223 return 0;
224 }
225
226 static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
227 {
228 int ret;
229 VqInfoBlock info;
230 uint8_t status;
231 VirtioFeatDesc features;
232 void *config;
233 hwaddr indicators;
234 VqConfigBlock vq_config;
235 VirtioCcwDevice *dev = sch->driver_data;
236 VirtIODevice *vdev = virtio_ccw_get_vdev(sch);
237 bool check_len;
238 int len;
239 hwaddr hw_len;
240
241 if (!dev) {
242 return -EINVAL;
243 }
244
245 trace_virtio_ccw_interpret_ccw(sch->cssid, sch->ssid, sch->schid,
246 ccw.cmd_code);
247 check_len = !((ccw.flags & CCW_FLAG_SLI) && !(ccw.flags & CCW_FLAG_DC));
248
249 /* Look at the command. */
250 switch (ccw.cmd_code) {
251 case CCW_CMD_SET_VQ:
252 if (check_len) {
253 if (ccw.count != sizeof(info)) {
254 ret = -EINVAL;
255 break;
256 }
257 } else if (ccw.count < sizeof(info)) {
258 /* Can't execute command. */
259 ret = -EINVAL;
260 break;
261 }
262 if (!ccw.cda) {
263 ret = -EFAULT;
264 } else {
265 info.queue = ldq_phys(ccw.cda);
266 info.align = ldl_phys(&address_space_memory,
267 ccw.cda + sizeof(info.queue));
268 info.index = lduw_phys(ccw.cda + sizeof(info.queue)
269 + sizeof(info.align));
270 info.num = lduw_phys(ccw.cda + sizeof(info.queue)
271 + sizeof(info.align)
272 + sizeof(info.index));
273 ret = virtio_ccw_set_vqs(sch, info.queue, info.align, info.index,
274 info.num);
275 sch->curr_status.scsw.count = 0;
276 }
277 break;
278 case CCW_CMD_VDEV_RESET:
279 virtio_ccw_stop_ioeventfd(dev);
280 virtio_reset(vdev);
281 ret = 0;
282 break;
283 case CCW_CMD_READ_FEAT:
284 if (check_len) {
285 if (ccw.count != sizeof(features)) {
286 ret = -EINVAL;
287 break;
288 }
289 } else if (ccw.count < sizeof(features)) {
290 /* Can't execute command. */
291 ret = -EINVAL;
292 break;
293 }
294 if (!ccw.cda) {
295 ret = -EFAULT;
296 } else {
297 features.index = ldub_phys(ccw.cda + sizeof(features.features));
298 if (features.index < ARRAY_SIZE(dev->host_features)) {
299 features.features = dev->host_features[features.index];
300 } else {
301 /* Return zeroes if the guest supports more feature bits. */
302 features.features = 0;
303 }
304 stl_le_phys(ccw.cda, features.features);
305 sch->curr_status.scsw.count = ccw.count - sizeof(features);
306 ret = 0;
307 }
308 break;
309 case CCW_CMD_WRITE_FEAT:
310 if (check_len) {
311 if (ccw.count != sizeof(features)) {
312 ret = -EINVAL;
313 break;
314 }
315 } else if (ccw.count < sizeof(features)) {
316 /* Can't execute command. */
317 ret = -EINVAL;
318 break;
319 }
320 if (!ccw.cda) {
321 ret = -EFAULT;
322 } else {
323 features.index = ldub_phys(ccw.cda + sizeof(features.features));
324 features.features = ldl_le_phys(&address_space_memory, ccw.cda);
325 if (features.index < ARRAY_SIZE(dev->host_features)) {
326 virtio_bus_set_vdev_features(&dev->bus, features.features);
327 vdev->guest_features = features.features;
328 } else {
329 /*
330 * If the guest supports more feature bits, assert that it
331 * passes us zeroes for those we don't support.
332 */
333 if (features.features) {
334 fprintf(stderr, "Guest bug: features[%i]=%x (expected 0)\n",
335 features.index, features.features);
336 /* XXX: do a unit check here? */
337 }
338 }
339 sch->curr_status.scsw.count = ccw.count - sizeof(features);
340 ret = 0;
341 }
342 break;
343 case CCW_CMD_READ_CONF:
344 if (check_len) {
345 if (ccw.count > vdev->config_len) {
346 ret = -EINVAL;
347 break;
348 }
349 }
350 len = MIN(ccw.count, vdev->config_len);
351 if (!ccw.cda) {
352 ret = -EFAULT;
353 } else {
354 virtio_bus_get_vdev_config(&dev->bus, vdev->config);
355 /* XXX config space endianness */
356 cpu_physical_memory_write(ccw.cda, vdev->config, len);
357 sch->curr_status.scsw.count = ccw.count - len;
358 ret = 0;
359 }
360 break;
361 case CCW_CMD_WRITE_CONF:
362 if (check_len) {
363 if (ccw.count > vdev->config_len) {
364 ret = -EINVAL;
365 break;
366 }
367 }
368 len = MIN(ccw.count, vdev->config_len);
369 hw_len = len;
370 if (!ccw.cda) {
371 ret = -EFAULT;
372 } else {
373 config = cpu_physical_memory_map(ccw.cda, &hw_len, 0);
374 if (!config) {
375 ret = -EFAULT;
376 } else {
377 len = hw_len;
378 /* XXX config space endianness */
379 memcpy(vdev->config, config, len);
380 cpu_physical_memory_unmap(config, hw_len, 0, hw_len);
381 virtio_bus_set_vdev_config(&dev->bus, vdev->config);
382 sch->curr_status.scsw.count = ccw.count - len;
383 ret = 0;
384 }
385 }
386 break;
387 case CCW_CMD_WRITE_STATUS:
388 if (check_len) {
389 if (ccw.count != sizeof(status)) {
390 ret = -EINVAL;
391 break;
392 }
393 } else if (ccw.count < sizeof(status)) {
394 /* Can't execute command. */
395 ret = -EINVAL;
396 break;
397 }
398 if (!ccw.cda) {
399 ret = -EFAULT;
400 } else {
401 status = ldub_phys(ccw.cda);
402 if (!(status & VIRTIO_CONFIG_S_DRIVER_OK)) {
403 virtio_ccw_stop_ioeventfd(dev);
404 }
405 virtio_set_status(vdev, status);
406 if (vdev->status == 0) {
407 virtio_reset(vdev);
408 }
409 if (status & VIRTIO_CONFIG_S_DRIVER_OK) {
410 virtio_ccw_start_ioeventfd(dev);
411 }
412 sch->curr_status.scsw.count = ccw.count - sizeof(status);
413 ret = 0;
414 }
415 break;
416 case CCW_CMD_SET_IND:
417 if (check_len) {
418 if (ccw.count != sizeof(indicators)) {
419 ret = -EINVAL;
420 break;
421 }
422 } else if (ccw.count < sizeof(indicators)) {
423 /* Can't execute command. */
424 ret = -EINVAL;
425 break;
426 }
427 if (!ccw.cda) {
428 ret = -EFAULT;
429 } else {
430 indicators = ldq_phys(ccw.cda);
431 dev->indicators = indicators;
432 sch->curr_status.scsw.count = ccw.count - sizeof(indicators);
433 ret = 0;
434 }
435 break;
436 case CCW_CMD_SET_CONF_IND:
437 if (check_len) {
438 if (ccw.count != sizeof(indicators)) {
439 ret = -EINVAL;
440 break;
441 }
442 } else if (ccw.count < sizeof(indicators)) {
443 /* Can't execute command. */
444 ret = -EINVAL;
445 break;
446 }
447 if (!ccw.cda) {
448 ret = -EFAULT;
449 } else {
450 indicators = ldq_phys(ccw.cda);
451 dev->indicators2 = indicators;
452 sch->curr_status.scsw.count = ccw.count - sizeof(indicators);
453 ret = 0;
454 }
455 break;
456 case CCW_CMD_READ_VQ_CONF:
457 if (check_len) {
458 if (ccw.count != sizeof(vq_config)) {
459 ret = -EINVAL;
460 break;
461 }
462 } else if (ccw.count < sizeof(vq_config)) {
463 /* Can't execute command. */
464 ret = -EINVAL;
465 break;
466 }
467 if (!ccw.cda) {
468 ret = -EFAULT;
469 } else {
470 vq_config.index = lduw_phys(ccw.cda);
471 vq_config.num_max = virtio_queue_get_num(vdev,
472 vq_config.index);
473 stw_phys(ccw.cda + sizeof(vq_config.index), vq_config.num_max);
474 sch->curr_status.scsw.count = ccw.count - sizeof(vq_config);
475 ret = 0;
476 }
477 break;
478 default:
479 ret = -ENOSYS;
480 break;
481 }
482 return ret;
483 }
484
485 static int virtio_ccw_device_init(VirtioCcwDevice *dev, VirtIODevice *vdev)
486 {
487 unsigned int cssid = 0;
488 unsigned int ssid = 0;
489 unsigned int schid;
490 unsigned int devno;
491 bool have_devno = false;
492 bool found = false;
493 SubchDev *sch;
494 int ret;
495 int num;
496 DeviceState *parent = DEVICE(dev);
497
498 sch = g_malloc0(sizeof(SubchDev));
499
500 sch->driver_data = dev;
501 dev->sch = sch;
502
503 dev->indicators = 0;
504
505 /* Initialize subchannel structure. */
506 sch->channel_prog = 0x0;
507 sch->last_cmd_valid = false;
508 sch->orb = NULL;
509 /*
510 * Use a device number if provided. Otherwise, fall back to subchannel
511 * number.
512 */
513 if (dev->bus_id) {
514 num = sscanf(dev->bus_id, "%x.%x.%04x", &cssid, &ssid, &devno);
515 if (num == 3) {
516 if ((cssid > MAX_CSSID) || (ssid > MAX_SSID)) {
517 ret = -EINVAL;
518 error_report("Invalid cssid or ssid: cssid %x, ssid %x",
519 cssid, ssid);
520 goto out_err;
521 }
522 /* Enforce use of virtual cssid. */
523 if (cssid != VIRTUAL_CSSID) {
524 ret = -EINVAL;
525 error_report("cssid %x not valid for virtio devices", cssid);
526 goto out_err;
527 }
528 if (css_devno_used(cssid, ssid, devno)) {
529 ret = -EEXIST;
530 error_report("Device %x.%x.%04x already exists", cssid, ssid,
531 devno);
532 goto out_err;
533 }
534 sch->cssid = cssid;
535 sch->ssid = ssid;
536 sch->devno = devno;
537 have_devno = true;
538 } else {
539 ret = -EINVAL;
540 error_report("Malformed devno parameter '%s'", dev->bus_id);
541 goto out_err;
542 }
543 }
544
545 /* Find the next free id. */
546 if (have_devno) {
547 for (schid = 0; schid <= MAX_SCHID; schid++) {
548 if (!css_find_subch(1, cssid, ssid, schid)) {
549 sch->schid = schid;
550 css_subch_assign(cssid, ssid, schid, devno, sch);
551 found = true;
552 break;
553 }
554 }
555 if (!found) {
556 ret = -ENODEV;
557 error_report("No free subchannel found for %x.%x.%04x", cssid, ssid,
558 devno);
559 goto out_err;
560 }
561 trace_virtio_ccw_new_device(cssid, ssid, schid, devno,
562 "user-configured");
563 } else {
564 cssid = VIRTUAL_CSSID;
565 for (ssid = 0; ssid <= MAX_SSID; ssid++) {
566 for (schid = 0; schid <= MAX_SCHID; schid++) {
567 if (!css_find_subch(1, cssid, ssid, schid)) {
568 sch->cssid = cssid;
569 sch->ssid = ssid;
570 sch->schid = schid;
571 devno = schid;
572 /*
573 * If the devno is already taken, look further in this
574 * subchannel set.
575 */
576 while (css_devno_used(cssid, ssid, devno)) {
577 if (devno == MAX_SCHID) {
578 devno = 0;
579 } else if (devno == schid - 1) {
580 ret = -ENODEV;
581 error_report("No free devno found");
582 goto out_err;
583 } else {
584 devno++;
585 }
586 }
587 sch->devno = devno;
588 css_subch_assign(cssid, ssid, schid, devno, sch);
589 found = true;
590 break;
591 }
592 }
593 if (found) {
594 break;
595 }
596 }
597 if (!found) {
598 ret = -ENODEV;
599 error_report("Virtual channel subsystem is full!");
600 goto out_err;
601 }
602 trace_virtio_ccw_new_device(cssid, ssid, schid, devno,
603 "auto-configured");
604 }
605
606 /* Build initial schib. */
607 css_sch_build_virtual_schib(sch, 0, VIRTIO_CCW_CHPID_TYPE);
608
609 sch->ccw_cb = virtio_ccw_cb;
610
611 /* Build senseid data. */
612 memset(&sch->id, 0, sizeof(SenseId));
613 sch->id.reserved = 0xff;
614 sch->id.cu_type = VIRTIO_CCW_CU_TYPE;
615 sch->id.cu_model = vdev->device_id;
616
617 /* Only the first 32 feature bits are used. */
618 dev->host_features[0] = virtio_bus_get_vdev_features(&dev->bus,
619 dev->host_features[0]);
620
621 dev->host_features[0] |= 0x1 << VIRTIO_F_NOTIFY_ON_EMPTY;
622 dev->host_features[0] |= 0x1 << VIRTIO_F_BAD_FEATURE;
623
624 css_generate_sch_crws(sch->cssid, sch->ssid, sch->schid,
625 parent->hotplugged, 1);
626 return 0;
627
628 out_err:
629 dev->sch = NULL;
630 g_free(sch);
631 return ret;
632 }
633
634 static int virtio_ccw_exit(VirtioCcwDevice *dev)
635 {
636 SubchDev *sch = dev->sch;
637
638 if (sch) {
639 css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, NULL);
640 g_free(sch);
641 }
642 dev->indicators = 0;
643 return 0;
644 }
645
646 static int virtio_ccw_net_init(VirtioCcwDevice *ccw_dev)
647 {
648 DeviceState *qdev = DEVICE(ccw_dev);
649 VirtIONetCcw *dev = VIRTIO_NET_CCW(ccw_dev);
650 DeviceState *vdev = DEVICE(&dev->vdev);
651
652 virtio_net_set_config_size(&dev->vdev, ccw_dev->host_features[0]);
653 virtio_net_set_netclient_name(&dev->vdev, qdev->id,
654 object_get_typename(OBJECT(qdev)));
655 qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
656 if (qdev_init(vdev) < 0) {
657 return -1;
658 }
659
660 return virtio_ccw_device_init(ccw_dev, VIRTIO_DEVICE(vdev));
661 }
662
663 static void virtio_ccw_net_instance_init(Object *obj)
664 {
665 VirtIONetCcw *dev = VIRTIO_NET_CCW(obj);
666 object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_NET);
667 object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
668 }
669
670 static int virtio_ccw_blk_init(VirtioCcwDevice *ccw_dev)
671 {
672 VirtIOBlkCcw *dev = VIRTIO_BLK_CCW(ccw_dev);
673 DeviceState *vdev = DEVICE(&dev->vdev);
674 virtio_blk_set_conf(vdev, &(dev->blk));
675 qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
676 if (qdev_init(vdev) < 0) {
677 return -1;
678 }
679
680 return virtio_ccw_device_init(ccw_dev, VIRTIO_DEVICE(vdev));
681 }
682
683 static void virtio_ccw_blk_instance_init(Object *obj)
684 {
685 VirtIOBlkCcw *dev = VIRTIO_BLK_CCW(obj);
686 object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_BLK);
687 object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
688 }
689
690 static int virtio_ccw_serial_init(VirtioCcwDevice *ccw_dev)
691 {
692 VirtioSerialCcw *dev = VIRTIO_SERIAL_CCW(ccw_dev);
693 DeviceState *vdev = DEVICE(&dev->vdev);
694 DeviceState *proxy = DEVICE(ccw_dev);
695 char *bus_name;
696
697 /*
698 * For command line compatibility, this sets the virtio-serial-device bus
699 * name as before.
700 */
701 if (proxy->id) {
702 bus_name = g_strdup_printf("%s.0", proxy->id);
703 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name);
704 g_free(bus_name);
705 }
706
707 qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
708 if (qdev_init(vdev) < 0) {
709 return -1;
710 }
711
712 return virtio_ccw_device_init(ccw_dev, VIRTIO_DEVICE(vdev));
713 }
714
715
716 static void virtio_ccw_serial_instance_init(Object *obj)
717 {
718 VirtioSerialCcw *dev = VIRTIO_SERIAL_CCW(obj);
719 object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_SERIAL);
720 object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
721 }
722
723 static int virtio_ccw_balloon_init(VirtioCcwDevice *ccw_dev)
724 {
725 VirtIOBalloonCcw *dev = VIRTIO_BALLOON_CCW(ccw_dev);
726 DeviceState *vdev = DEVICE(&dev->vdev);
727
728 qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
729 if (qdev_init(vdev) < 0) {
730 return -1;
731 }
732
733 return virtio_ccw_device_init(ccw_dev, VIRTIO_DEVICE(vdev));
734 }
735
736 static void balloon_ccw_stats_get_all(Object *obj, struct Visitor *v,
737 void *opaque, const char *name,
738 Error **errp)
739 {
740 VirtIOBalloonCcw *dev = opaque;
741 object_property_get(OBJECT(&dev->vdev), v, "guest-stats", errp);
742 }
743
744 static void balloon_ccw_stats_get_poll_interval(Object *obj, struct Visitor *v,
745 void *opaque, const char *name,
746 Error **errp)
747 {
748 VirtIOBalloonCcw *dev = opaque;
749 object_property_get(OBJECT(&dev->vdev), v, "guest-stats-polling-interval",
750 errp);
751 }
752
753 static void balloon_ccw_stats_set_poll_interval(Object *obj, struct Visitor *v,
754 void *opaque, const char *name,
755 Error **errp)
756 {
757 VirtIOBalloonCcw *dev = opaque;
758 object_property_set(OBJECT(&dev->vdev), v, "guest-stats-polling-interval",
759 errp);
760 }
761
762 static void virtio_ccw_balloon_instance_init(Object *obj)
763 {
764 VirtIOBalloonCcw *dev = VIRTIO_BALLOON_CCW(obj);
765 object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_BALLOON);
766 object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
767
768 object_property_add(obj, "guest-stats", "guest statistics",
769 balloon_ccw_stats_get_all, NULL, NULL, dev, NULL);
770
771 object_property_add(obj, "guest-stats-polling-interval", "int",
772 balloon_ccw_stats_get_poll_interval,
773 balloon_ccw_stats_set_poll_interval,
774 NULL, dev, NULL);
775 }
776
777 static int virtio_ccw_scsi_init(VirtioCcwDevice *ccw_dev)
778 {
779 VirtIOSCSICcw *dev = VIRTIO_SCSI_CCW(ccw_dev);
780 DeviceState *vdev = DEVICE(&dev->vdev);
781 DeviceState *qdev = DEVICE(ccw_dev);
782 char *bus_name;
783
784 /*
785 * For command line compatibility, this sets the virtio-scsi-device bus
786 * name as before.
787 */
788 if (qdev->id) {
789 bus_name = g_strdup_printf("%s.0", qdev->id);
790 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name);
791 g_free(bus_name);
792 }
793
794 qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
795 if (qdev_init(vdev) < 0) {
796 return -1;
797 }
798
799 return virtio_ccw_device_init(ccw_dev, VIRTIO_DEVICE(vdev));
800 }
801
802 static void virtio_ccw_scsi_instance_init(Object *obj)
803 {
804 VirtIOSCSICcw *dev = VIRTIO_SCSI_CCW(obj);
805 object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_SCSI);
806 object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
807 }
808
809 #ifdef CONFIG_VHOST_SCSI
810 static int vhost_ccw_scsi_init(VirtioCcwDevice *ccw_dev)
811 {
812 VHostSCSICcw *dev = VHOST_SCSI_CCW(ccw_dev);
813 DeviceState *vdev = DEVICE(&dev->vdev);
814
815 qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
816 if (qdev_init(vdev) < 0) {
817 return -1;
818 }
819
820 return virtio_ccw_device_init(ccw_dev, VIRTIO_DEVICE(vdev));
821 }
822
823 static void vhost_ccw_scsi_instance_init(Object *obj)
824 {
825 VHostSCSICcw *dev = VHOST_SCSI_CCW(obj);
826 object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VHOST_SCSI);
827 object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
828 }
829 #endif
830
831 static int virtio_ccw_rng_init(VirtioCcwDevice *ccw_dev)
832 {
833 VirtIORNGCcw *dev = VIRTIO_RNG_CCW(ccw_dev);
834 DeviceState *vdev = DEVICE(&dev->vdev);
835
836 qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
837 if (qdev_init(vdev) < 0) {
838 return -1;
839 }
840
841 object_property_set_link(OBJECT(dev),
842 OBJECT(dev->vdev.conf.rng), "rng",
843 NULL);
844
845 return virtio_ccw_device_init(ccw_dev, VIRTIO_DEVICE(vdev));
846 }
847
848 /* DeviceState to VirtioCcwDevice. Note: used on datapath,
849 * be careful and test performance if you change this.
850 */
851 static inline VirtioCcwDevice *to_virtio_ccw_dev_fast(DeviceState *d)
852 {
853 return container_of(d, VirtioCcwDevice, parent_obj);
854 }
855
856 static void virtio_ccw_notify(DeviceState *d, uint16_t vector)
857 {
858 VirtioCcwDevice *dev = to_virtio_ccw_dev_fast(d);
859 SubchDev *sch = dev->sch;
860 uint64_t indicators;
861
862 if (vector >= 128) {
863 return;
864 }
865
866 if (vector < VIRTIO_PCI_QUEUE_MAX) {
867 if (!dev->indicators) {
868 return;
869 }
870 indicators = ldq_phys(dev->indicators);
871 indicators |= 1ULL << vector;
872 stq_phys(dev->indicators, indicators);
873 } else {
874 if (!dev->indicators2) {
875 return;
876 }
877 vector = 0;
878 indicators = ldq_phys(dev->indicators2);
879 indicators |= 1ULL << vector;
880 stq_phys(dev->indicators2, indicators);
881 }
882
883 css_conditional_io_interrupt(sch);
884
885 }
886
887 static unsigned virtio_ccw_get_features(DeviceState *d)
888 {
889 VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
890
891 /* Only the first 32 feature bits are used. */
892 return dev->host_features[0];
893 }
894
895 static void virtio_ccw_reset(DeviceState *d)
896 {
897 VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
898 VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
899
900 virtio_ccw_stop_ioeventfd(dev);
901 virtio_reset(vdev);
902 css_reset_sch(dev->sch);
903 dev->indicators = 0;
904 dev->indicators2 = 0;
905 }
906
907 static void virtio_ccw_vmstate_change(DeviceState *d, bool running)
908 {
909 VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
910
911 if (running) {
912 virtio_ccw_start_ioeventfd(dev);
913 } else {
914 virtio_ccw_stop_ioeventfd(dev);
915 }
916 }
917
918 static bool virtio_ccw_query_guest_notifiers(DeviceState *d)
919 {
920 VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
921
922 return !!(dev->sch->curr_status.pmcw.flags & PMCW_FLAGS_MASK_ENA);
923 }
924
925 static int virtio_ccw_set_host_notifier(DeviceState *d, int n, bool assign)
926 {
927 VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
928
929 /* Stop using the generic ioeventfd, we are doing eventfd handling
930 * ourselves below */
931 dev->ioeventfd_disabled = assign;
932 if (assign) {
933 virtio_ccw_stop_ioeventfd(dev);
934 }
935 return virtio_ccw_set_guest2host_notifier(dev, n, assign, false);
936 }
937
938 static int virtio_ccw_set_guest_notifier(VirtioCcwDevice *dev, int n,
939 bool assign, bool with_irqfd)
940 {
941 VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
942 VirtQueue *vq = virtio_get_queue(vdev, n);
943 EventNotifier *notifier = virtio_queue_get_guest_notifier(vq);
944 VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
945
946 if (assign) {
947 int r = event_notifier_init(notifier, 0);
948
949 if (r < 0) {
950 return r;
951 }
952 virtio_queue_set_guest_notifier_fd_handler(vq, true, with_irqfd);
953 /* We do not support irqfd for classic I/O interrupts, because the
954 * classic interrupts are intermixed with the subchannel status, that
955 * is queried with test subchannel. We want to use vhost, though.
956 * Lets make sure to have vhost running and wire up the irq fd to
957 * land in qemu (and only the irq fd) in this code.
958 */
959 if (k->guest_notifier_mask) {
960 k->guest_notifier_mask(vdev, n, false);
961 }
962 /* get lost events and re-inject */
963 if (k->guest_notifier_pending &&
964 k->guest_notifier_pending(vdev, n)) {
965 event_notifier_set(notifier);
966 }
967 } else {
968 if (k->guest_notifier_mask) {
969 k->guest_notifier_mask(vdev, n, true);
970 }
971 virtio_queue_set_guest_notifier_fd_handler(vq, false, with_irqfd);
972 event_notifier_cleanup(notifier);
973 }
974 return 0;
975 }
976
977 static int virtio_ccw_set_guest_notifiers(DeviceState *d, int nvqs,
978 bool assigned)
979 {
980 VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
981 VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
982 int r, n;
983
984 for (n = 0; n < nvqs; n++) {
985 if (!virtio_queue_get_num(vdev, n)) {
986 break;
987 }
988 /* false -> true, as soon as irqfd works */
989 r = virtio_ccw_set_guest_notifier(dev, n, assigned, false);
990 if (r < 0) {
991 goto assign_error;
992 }
993 }
994 return 0;
995
996 assign_error:
997 while (--n >= 0) {
998 virtio_ccw_set_guest_notifier(dev, n, !assigned, false);
999 }
1000 return r;
1001 }
1002
1003 /**************** Virtio-ccw Bus Device Descriptions *******************/
1004
1005 static Property virtio_ccw_net_properties[] = {
1006 DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
1007 DEFINE_VIRTIO_NET_FEATURES(VirtioCcwDevice, host_features[0]),
1008 DEFINE_VIRTIO_NET_PROPERTIES(VirtIONetCcw, vdev.net_conf),
1009 DEFINE_NIC_PROPERTIES(VirtIONetCcw, vdev.nic_conf),
1010 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
1011 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1012 DEFINE_PROP_END_OF_LIST(),
1013 };
1014
1015 static void virtio_ccw_net_class_init(ObjectClass *klass, void *data)
1016 {
1017 DeviceClass *dc = DEVICE_CLASS(klass);
1018 VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1019
1020 k->init = virtio_ccw_net_init;
1021 k->exit = virtio_ccw_exit;
1022 dc->reset = virtio_ccw_reset;
1023 dc->props = virtio_ccw_net_properties;
1024 }
1025
1026 static const TypeInfo virtio_ccw_net = {
1027 .name = TYPE_VIRTIO_NET_CCW,
1028 .parent = TYPE_VIRTIO_CCW_DEVICE,
1029 .instance_size = sizeof(VirtIONetCcw),
1030 .instance_init = virtio_ccw_net_instance_init,
1031 .class_init = virtio_ccw_net_class_init,
1032 };
1033
1034 static Property virtio_ccw_blk_properties[] = {
1035 DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
1036 DEFINE_VIRTIO_BLK_FEATURES(VirtioCcwDevice, host_features[0]),
1037 DEFINE_VIRTIO_BLK_PROPERTIES(VirtIOBlkCcw, blk),
1038 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
1039 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1040 #ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
1041 DEFINE_PROP_BIT("x-data-plane", VirtIOBlkCcw, blk.data_plane, 0, false),
1042 #endif
1043 DEFINE_PROP_END_OF_LIST(),
1044 };
1045
1046 static void virtio_ccw_blk_class_init(ObjectClass *klass, void *data)
1047 {
1048 DeviceClass *dc = DEVICE_CLASS(klass);
1049 VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1050
1051 k->init = virtio_ccw_blk_init;
1052 k->exit = virtio_ccw_exit;
1053 dc->reset = virtio_ccw_reset;
1054 dc->props = virtio_ccw_blk_properties;
1055 }
1056
1057 static const TypeInfo virtio_ccw_blk = {
1058 .name = TYPE_VIRTIO_BLK_CCW,
1059 .parent = TYPE_VIRTIO_CCW_DEVICE,
1060 .instance_size = sizeof(VirtIOBlkCcw),
1061 .instance_init = virtio_ccw_blk_instance_init,
1062 .class_init = virtio_ccw_blk_class_init,
1063 };
1064
1065 static Property virtio_ccw_serial_properties[] = {
1066 DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
1067 DEFINE_VIRTIO_SERIAL_PROPERTIES(VirtioSerialCcw, vdev.serial),
1068 DEFINE_VIRTIO_COMMON_FEATURES(VirtioCcwDevice, host_features[0]),
1069 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
1070 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1071 DEFINE_PROP_END_OF_LIST(),
1072 };
1073
1074 static void virtio_ccw_serial_class_init(ObjectClass *klass, void *data)
1075 {
1076 DeviceClass *dc = DEVICE_CLASS(klass);
1077 VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1078
1079 k->init = virtio_ccw_serial_init;
1080 k->exit = virtio_ccw_exit;
1081 dc->reset = virtio_ccw_reset;
1082 dc->props = virtio_ccw_serial_properties;
1083 }
1084
1085 static const TypeInfo virtio_ccw_serial = {
1086 .name = TYPE_VIRTIO_SERIAL_CCW,
1087 .parent = TYPE_VIRTIO_CCW_DEVICE,
1088 .instance_size = sizeof(VirtioSerialCcw),
1089 .instance_init = virtio_ccw_serial_instance_init,
1090 .class_init = virtio_ccw_serial_class_init,
1091 };
1092
1093 static Property virtio_ccw_balloon_properties[] = {
1094 DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
1095 DEFINE_VIRTIO_COMMON_FEATURES(VirtioCcwDevice, host_features[0]),
1096 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
1097 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1098 DEFINE_PROP_END_OF_LIST(),
1099 };
1100
1101 static void virtio_ccw_balloon_class_init(ObjectClass *klass, void *data)
1102 {
1103 DeviceClass *dc = DEVICE_CLASS(klass);
1104 VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1105
1106 k->init = virtio_ccw_balloon_init;
1107 k->exit = virtio_ccw_exit;
1108 dc->reset = virtio_ccw_reset;
1109 dc->props = virtio_ccw_balloon_properties;
1110 }
1111
1112 static const TypeInfo virtio_ccw_balloon = {
1113 .name = TYPE_VIRTIO_BALLOON_CCW,
1114 .parent = TYPE_VIRTIO_CCW_DEVICE,
1115 .instance_size = sizeof(VirtIOBalloonCcw),
1116 .instance_init = virtio_ccw_balloon_instance_init,
1117 .class_init = virtio_ccw_balloon_class_init,
1118 };
1119
1120 static Property virtio_ccw_scsi_properties[] = {
1121 DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
1122 DEFINE_VIRTIO_SCSI_PROPERTIES(VirtIOSCSICcw, vdev.parent_obj.conf),
1123 DEFINE_VIRTIO_SCSI_FEATURES(VirtioCcwDevice, host_features[0]),
1124 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
1125 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1126 DEFINE_PROP_END_OF_LIST(),
1127 };
1128
1129 static void virtio_ccw_scsi_class_init(ObjectClass *klass, void *data)
1130 {
1131 DeviceClass *dc = DEVICE_CLASS(klass);
1132 VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1133
1134 k->init = virtio_ccw_scsi_init;
1135 k->exit = virtio_ccw_exit;
1136 dc->reset = virtio_ccw_reset;
1137 dc->props = virtio_ccw_scsi_properties;
1138 }
1139
1140 static const TypeInfo virtio_ccw_scsi = {
1141 .name = TYPE_VIRTIO_SCSI_CCW,
1142 .parent = TYPE_VIRTIO_CCW_DEVICE,
1143 .instance_size = sizeof(VirtIOSCSICcw),
1144 .instance_init = virtio_ccw_scsi_instance_init,
1145 .class_init = virtio_ccw_scsi_class_init,
1146 };
1147
1148 #ifdef CONFIG_VHOST_SCSI
1149 static Property vhost_ccw_scsi_properties[] = {
1150 DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
1151 DEFINE_VHOST_SCSI_PROPERTIES(VirtIOSCSICcw, vdev.parent_obj.conf),
1152 DEFINE_VIRTIO_COMMON_FEATURES(VirtioCcwDevice, host_features[0]),
1153 DEFINE_PROP_END_OF_LIST(),
1154 };
1155
1156 static void vhost_ccw_scsi_class_init(ObjectClass *klass, void *data)
1157 {
1158 DeviceClass *dc = DEVICE_CLASS(klass);
1159 VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1160
1161 k->init = vhost_ccw_scsi_init;
1162 k->exit = virtio_ccw_exit;
1163 dc->reset = virtio_ccw_reset;
1164 dc->props = vhost_ccw_scsi_properties;
1165 }
1166
1167 static const TypeInfo vhost_ccw_scsi = {
1168 .name = TYPE_VHOST_SCSI_CCW,
1169 .parent = TYPE_VIRTIO_CCW_DEVICE,
1170 .instance_size = sizeof(VirtIOSCSICcw),
1171 .instance_init = vhost_ccw_scsi_instance_init,
1172 .class_init = vhost_ccw_scsi_class_init,
1173 };
1174 #endif
1175
1176 static void virtio_ccw_rng_instance_init(Object *obj)
1177 {
1178 VirtIORNGCcw *dev = VIRTIO_RNG_CCW(obj);
1179 object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_RNG);
1180 object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
1181 object_property_add_link(obj, "rng", TYPE_RNG_BACKEND,
1182 (Object **)&dev->vdev.conf.rng, NULL);
1183 }
1184
1185 static Property virtio_ccw_rng_properties[] = {
1186 DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
1187 DEFINE_VIRTIO_COMMON_FEATURES(VirtioCcwDevice, host_features[0]),
1188 DEFINE_VIRTIO_RNG_PROPERTIES(VirtIORNGCcw, vdev.conf),
1189 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
1190 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1191 DEFINE_PROP_END_OF_LIST(),
1192 };
1193
1194 static void virtio_ccw_rng_class_init(ObjectClass *klass, void *data)
1195 {
1196 DeviceClass *dc = DEVICE_CLASS(klass);
1197 VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
1198
1199 k->init = virtio_ccw_rng_init;
1200 k->exit = virtio_ccw_exit;
1201 dc->reset = virtio_ccw_reset;
1202 dc->props = virtio_ccw_rng_properties;
1203 }
1204
1205 static const TypeInfo virtio_ccw_rng = {
1206 .name = TYPE_VIRTIO_RNG_CCW,
1207 .parent = TYPE_VIRTIO_CCW_DEVICE,
1208 .instance_size = sizeof(VirtIORNGCcw),
1209 .instance_init = virtio_ccw_rng_instance_init,
1210 .class_init = virtio_ccw_rng_class_init,
1211 };
1212
1213 static int virtio_ccw_busdev_init(DeviceState *dev)
1214 {
1215 VirtioCcwDevice *_dev = (VirtioCcwDevice *)dev;
1216 VirtIOCCWDeviceClass *_info = VIRTIO_CCW_DEVICE_GET_CLASS(dev);
1217
1218 virtio_ccw_bus_new(&_dev->bus, sizeof(_dev->bus), _dev);
1219
1220 return _info->init(_dev);
1221 }
1222
1223 static int virtio_ccw_busdev_exit(DeviceState *dev)
1224 {
1225 VirtioCcwDevice *_dev = (VirtioCcwDevice *)dev;
1226 VirtIOCCWDeviceClass *_info = VIRTIO_CCW_DEVICE_GET_CLASS(dev);
1227
1228 return _info->exit(_dev);
1229 }
1230
1231 static int virtio_ccw_busdev_unplug(DeviceState *dev)
1232 {
1233 VirtioCcwDevice *_dev = (VirtioCcwDevice *)dev;
1234 SubchDev *sch = _dev->sch;
1235
1236 virtio_ccw_stop_ioeventfd(_dev);
1237
1238 /*
1239 * We should arrive here only for device_del, since we don't support
1240 * direct hot(un)plug of channels, but only through virtio.
1241 */
1242 assert(sch != NULL);
1243 /* Subchannel is now disabled and no longer valid. */
1244 sch->curr_status.pmcw.flags &= ~(PMCW_FLAGS_MASK_ENA |
1245 PMCW_FLAGS_MASK_DNV);
1246
1247 css_generate_sch_crws(sch->cssid, sch->ssid, sch->schid, 1, 0);
1248
1249 object_unparent(OBJECT(dev));
1250 return 0;
1251 }
1252
1253 static void virtio_ccw_device_class_init(ObjectClass *klass, void *data)
1254 {
1255 DeviceClass *dc = DEVICE_CLASS(klass);
1256
1257 dc->init = virtio_ccw_busdev_init;
1258 dc->exit = virtio_ccw_busdev_exit;
1259 dc->unplug = virtio_ccw_busdev_unplug;
1260 dc->bus_type = TYPE_VIRTUAL_CSS_BUS;
1261
1262 }
1263
1264 static const TypeInfo virtio_ccw_device_info = {
1265 .name = TYPE_VIRTIO_CCW_DEVICE,
1266 .parent = TYPE_DEVICE,
1267 .instance_size = sizeof(VirtioCcwDevice),
1268 .class_init = virtio_ccw_device_class_init,
1269 .class_size = sizeof(VirtIOCCWDeviceClass),
1270 .abstract = true,
1271 };
1272
1273 /***************** Virtual-css Bus Bridge Device ********************/
1274 /* Only required to have the virtio bus as child in the system bus */
1275
1276 static int virtual_css_bridge_init(SysBusDevice *dev)
1277 {
1278 /* nothing */
1279 return 0;
1280 }
1281
1282 static void virtual_css_bridge_class_init(ObjectClass *klass, void *data)
1283 {
1284 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
1285
1286 k->init = virtual_css_bridge_init;
1287 }
1288
1289 static const TypeInfo virtual_css_bridge_info = {
1290 .name = "virtual-css-bridge",
1291 .parent = TYPE_SYS_BUS_DEVICE,
1292 .instance_size = sizeof(SysBusDevice),
1293 .class_init = virtual_css_bridge_class_init,
1294 };
1295
1296 /* virtio-ccw-bus */
1297
1298 static void virtio_ccw_bus_new(VirtioBusState *bus, size_t bus_size,
1299 VirtioCcwDevice *dev)
1300 {
1301 DeviceState *qdev = DEVICE(dev);
1302 BusState *qbus;
1303 char virtio_bus_name[] = "virtio-bus";
1304
1305 qbus_create_inplace(bus, bus_size, TYPE_VIRTIO_CCW_BUS,
1306 qdev, virtio_bus_name);
1307 qbus = BUS(bus);
1308 qbus->allow_hotplug = 1;
1309 }
1310
1311 static void virtio_ccw_bus_class_init(ObjectClass *klass, void *data)
1312 {
1313 VirtioBusClass *k = VIRTIO_BUS_CLASS(klass);
1314 BusClass *bus_class = BUS_CLASS(klass);
1315
1316 bus_class->max_dev = 1;
1317 k->notify = virtio_ccw_notify;
1318 k->get_features = virtio_ccw_get_features;
1319 k->vmstate_change = virtio_ccw_vmstate_change;
1320 k->query_guest_notifiers = virtio_ccw_query_guest_notifiers;
1321 k->set_host_notifier = virtio_ccw_set_host_notifier;
1322 k->set_guest_notifiers = virtio_ccw_set_guest_notifiers;
1323 }
1324
1325 static const TypeInfo virtio_ccw_bus_info = {
1326 .name = TYPE_VIRTIO_CCW_BUS,
1327 .parent = TYPE_VIRTIO_BUS,
1328 .instance_size = sizeof(VirtioCcwBusState),
1329 .class_init = virtio_ccw_bus_class_init,
1330 };
1331
1332 static void virtio_ccw_register(void)
1333 {
1334 type_register_static(&virtio_ccw_bus_info);
1335 type_register_static(&virtual_css_bus_info);
1336 type_register_static(&virtio_ccw_device_info);
1337 type_register_static(&virtio_ccw_serial);
1338 type_register_static(&virtio_ccw_blk);
1339 type_register_static(&virtio_ccw_net);
1340 type_register_static(&virtio_ccw_balloon);
1341 type_register_static(&virtio_ccw_scsi);
1342 #ifdef CONFIG_VHOST_SCSI
1343 type_register_static(&vhost_ccw_scsi);
1344 #endif
1345 type_register_static(&virtio_ccw_rng);
1346 type_register_static(&virtual_css_bridge_info);
1347 }
1348
1349 type_init(virtio_ccw_register)