virtio-ccw.c 53.5 KB
Newer Older
1 2 3
/*
 * virtio ccw target implementation
 *
4
 * Copyright 2012,2014 IBM Corp.
5 6 7 8 9 10 11 12
 * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
 *
 * This work is licensed under the terms of the GNU GPL, version 2 or (at
 * your option) any later version. See the COPYING file in the top-level
 * directory.
 */

#include "hw/hw.h"
13
#include "sysemu/block-backend.h"
14 15 16 17
#include "sysemu/blockdev.h"
#include "sysemu/sysemu.h"
#include "net/net.h"
#include "monitor/monitor.h"
P
Paolo Bonzini 已提交
18 19 20
#include "hw/virtio/virtio.h"
#include "hw/virtio/virtio-serial.h"
#include "hw/virtio/virtio-net.h"
21 22
#include "hw/sysbus.h"
#include "qemu/bitops.h"
P
Paolo Bonzini 已提交
23
#include "hw/virtio/virtio-bus.h"
24 25
#include "hw/s390x/adapter.h"
#include "hw/s390x/s390_flic.h"
26 27 28 29 30 31

#include "ioinst.h"
#include "css.h"
#include "virtio-ccw.h"
#include "trace.h"

32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
static QTAILQ_HEAD(, IndAddr) indicator_addresses =
    QTAILQ_HEAD_INITIALIZER(indicator_addresses);

static IndAddr *get_indicator(hwaddr ind_addr, int len)
{
    IndAddr *indicator;

    QTAILQ_FOREACH(indicator, &indicator_addresses, sibling) {
        if (indicator->addr == ind_addr) {
            indicator->refcnt++;
            return indicator;
        }
    }
    indicator = g_new0(IndAddr, 1);
    indicator->addr = ind_addr;
    indicator->len = len;
    indicator->refcnt = 1;
    QTAILQ_INSERT_TAIL(&indicator_addresses, indicator, sibling);
    return indicator;
}

53 54 55 56 57 58 59 60 61 62
static int s390_io_adapter_map(AdapterInfo *adapter, uint64_t map_addr,
                               bool do_map)
{
    S390FLICState *fs = s390_get_flic();
    S390FLICStateClass *fsc = S390_FLIC_COMMON_GET_CLASS(fs);

    return fsc->io_adapter_map(fs, adapter->adapter_id, map_addr, do_map);
}

static void release_indicator(AdapterInfo *adapter, IndAddr *indicator)
63 64 65 66 67 68 69
{
    assert(indicator->refcnt > 0);
    indicator->refcnt--;
    if (indicator->refcnt > 0) {
        return;
    }
    QTAILQ_REMOVE(&indicator_addresses, indicator, sibling);
70 71 72
    if (indicator->map) {
        s390_io_adapter_map(adapter, indicator->map, false);
    }
73 74 75
    g_free(indicator);
}

76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
static int map_indicator(AdapterInfo *adapter, IndAddr *indicator)
{
    int ret;

    if (indicator->map) {
        return 0; /* already mapped is not an error */
    }
    indicator->map = indicator->addr;
    ret = s390_io_adapter_map(adapter, indicator->map, true);
    if ((ret != 0) && (ret != -ENOSYS)) {
        goto out_err;
    }
    return 0;

out_err:
    indicator->map = 0;
    return ret;
}

95 96
static void virtio_ccw_bus_new(VirtioBusState *bus, size_t bus_size,
                               VirtioCcwDevice *dev);
97

P
Paolo Bonzini 已提交
98
static void virtual_css_bus_reset(BusState *qbus)
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
{
    /* This should actually be modelled via the generic css */
    css_reset();
}


static void virtual_css_bus_class_init(ObjectClass *klass, void *data)
{
    BusClass *k = BUS_CLASS(klass);

    k->reset = virtual_css_bus_reset;
}

static const TypeInfo virtual_css_bus_info = {
    .name = TYPE_VIRTUAL_CSS_BUS,
    .parent = TYPE_BUS,
    .instance_size = sizeof(VirtualCssBus),
    .class_init = virtual_css_bus_class_init,
};

VirtIODevice *virtio_ccw_get_vdev(SubchDev *sch)
{
    VirtIODevice *vdev = NULL;
P
Paolo Bonzini 已提交
122
    VirtioCcwDevice *dev = sch->driver_data;
123

P
Paolo Bonzini 已提交
124 125
    if (dev) {
        vdev = virtio_bus_get_device(&dev->bus);
126 127 128 129
    }
    return vdev;
}

C
Cornelia Huck 已提交
130 131 132
static int virtio_ccw_set_guest2host_notifier(VirtioCcwDevice *dev, int n,
                                              bool assign, bool set_handler)
{
P
Paolo Bonzini 已提交
133 134
    VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
    VirtQueue *vq = virtio_get_queue(vdev, n);
C
Cornelia Huck 已提交
135 136 137 138 139 140 141 142 143 144 145 146
    EventNotifier *notifier = virtio_queue_get_host_notifier(vq);
    int r = 0;
    SubchDev *sch = dev->sch;
    uint32_t sch_id = (css_build_subchannel_id(sch) << 16) | sch->schid;

    if (assign) {
        r = event_notifier_init(notifier, 1);
        if (r < 0) {
            error_report("%s: unable to init event notifier: %d", __func__, r);
            return r;
        }
        virtio_queue_set_host_notifier_fd_handler(vq, true, set_handler);
147
        r = s390_assign_subch_ioeventfd(notifier, sch_id, n, assign);
C
Cornelia Huck 已提交
148 149 150 151 152 153 154 155
        if (r < 0) {
            error_report("%s: unable to assign ioeventfd: %d", __func__, r);
            virtio_queue_set_host_notifier_fd_handler(vq, false, false);
            event_notifier_cleanup(notifier);
            return r;
        }
    } else {
        virtio_queue_set_host_notifier_fd_handler(vq, false, false);
156
        s390_assign_subch_ioeventfd(notifier, sch_id, n, assign);
C
Cornelia Huck 已提交
157 158 159 160 161 162 163
        event_notifier_cleanup(notifier);
    }
    return r;
}

static void virtio_ccw_start_ioeventfd(VirtioCcwDevice *dev)
{
P
Paolo Bonzini 已提交
164
    VirtIODevice *vdev;
C
Cornelia Huck 已提交
165 166 167
    int n, r;

    if (!(dev->flags & VIRTIO_CCW_FLAG_USE_IOEVENTFD) ||
168
        dev->ioeventfd_disabled ||
C
Cornelia Huck 已提交
169 170 171
        dev->ioeventfd_started) {
        return;
    }
P
Paolo Bonzini 已提交
172
    vdev = virtio_bus_get_device(&dev->bus);
C
Cornelia Huck 已提交
173
    for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) {
P
Paolo Bonzini 已提交
174
        if (!virtio_queue_get_num(vdev, n)) {
C
Cornelia Huck 已提交
175 176 177 178 179 180 181 182 183 184 185 186
            continue;
        }
        r = virtio_ccw_set_guest2host_notifier(dev, n, true, true);
        if (r < 0) {
            goto assign_error;
        }
    }
    dev->ioeventfd_started = true;
    return;

  assign_error:
    while (--n >= 0) {
P
Paolo Bonzini 已提交
187
        if (!virtio_queue_get_num(vdev, n)) {
C
Cornelia Huck 已提交
188 189 190 191 192 193 194 195 196 197 198 199 200
            continue;
        }
        r = virtio_ccw_set_guest2host_notifier(dev, n, false, false);
        assert(r >= 0);
    }
    dev->ioeventfd_started = false;
    /* Disable ioeventfd for this device. */
    dev->flags &= ~VIRTIO_CCW_FLAG_USE_IOEVENTFD;
    error_report("%s: failed. Fallback to userspace (slower).", __func__);
}

static void virtio_ccw_stop_ioeventfd(VirtioCcwDevice *dev)
{
P
Paolo Bonzini 已提交
201
    VirtIODevice *vdev;
C
Cornelia Huck 已提交
202 203 204 205 206
    int n, r;

    if (!dev->ioeventfd_started) {
        return;
    }
P
Paolo Bonzini 已提交
207
    vdev = virtio_bus_get_device(&dev->bus);
C
Cornelia Huck 已提交
208
    for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) {
P
Paolo Bonzini 已提交
209
        if (!virtio_queue_get_num(vdev, n)) {
C
Cornelia Huck 已提交
210 211 212 213 214 215 216 217
            continue;
        }
        r = virtio_ccw_set_guest2host_notifier(dev, n, false, false);
        assert(r >= 0);
    }
    dev->ioeventfd_started = false;
}

218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
VirtualCssBus *virtual_css_bus_init(void)
{
    VirtualCssBus *cbus;
    BusState *bus;
    DeviceState *dev;

    /* Create bridge device */
    dev = qdev_create(NULL, "virtual-css-bridge");
    qdev_init_nofail(dev);

    /* Create bus on bridge device */
    bus = qbus_create(TYPE_VIRTUAL_CSS_BUS, dev, "virtual-css");
    cbus = VIRTUAL_CSS_BUS(bus);

    /* Enable hotplugging */
233
    qbus_set_hotplug_handler(bus, dev, &error_abort);
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255

    return cbus;
}

/* Communication blocks used by several channel commands. */
typedef struct VqInfoBlock {
    uint64_t queue;
    uint32_t align;
    uint16_t index;
    uint16_t num;
} QEMU_PACKED VqInfoBlock;

typedef struct VqConfigBlock {
    uint16_t index;
    uint16_t num_max;
} QEMU_PACKED VqConfigBlock;

typedef struct VirtioFeatDesc {
    uint32_t features;
    uint8_t index;
} QEMU_PACKED VirtioFeatDesc;

256 257 258 259 260 261 262
typedef struct VirtioThinintInfo {
    hwaddr summary_indicator;
    hwaddr device_indicator;
    uint64_t ind_bit;
    uint8_t isc;
} QEMU_PACKED VirtioThinintInfo;

263 264 265 266
/* Specify where the virtqueues for the subchannel are in guest memory. */
static int virtio_ccw_set_vqs(SubchDev *sch, uint64_t addr, uint32_t align,
                              uint16_t index, uint16_t num)
{
P
Paolo Bonzini 已提交
267
    VirtIODevice *vdev = virtio_ccw_get_vdev(sch);
268

269
    if (index >= VIRTIO_PCI_QUEUE_MAX) {
270 271 272 273 274 275 276 277
        return -EINVAL;
    }

    /* Current code in virtio.c relies on 4K alignment. */
    if (addr && (align != 4096)) {
        return -EINVAL;
    }

P
Paolo Bonzini 已提交
278
    if (!vdev) {
279 280 281
        return -EINVAL;
    }

P
Paolo Bonzini 已提交
282
    virtio_queue_set_addr(vdev, index, addr);
283
    if (!addr) {
P
Paolo Bonzini 已提交
284
        virtio_queue_set_vector(vdev, index, 0);
285 286 287
    } else {
        /* Fail if we don't have a big enough queue. */
        /* TODO: Add interface to handle vring.num changing */
P
Paolo Bonzini 已提交
288
        if (virtio_queue_get_num(vdev, index) > num) {
289 290
            return -EINVAL;
        }
P
Paolo Bonzini 已提交
291
        virtio_queue_set_vector(vdev, index, index);
292 293
    }
    /* tell notify handler in case of config change */
P
Paolo Bonzini 已提交
294
    vdev->config_vector = VIRTIO_PCI_QUEUE_MAX;
295 296 297 298 299 300 301 302 303 304 305 306 307
    return 0;
}

static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
{
    int ret;
    VqInfoBlock info;
    uint8_t status;
    VirtioFeatDesc features;
    void *config;
    hwaddr indicators;
    VqConfigBlock vq_config;
    VirtioCcwDevice *dev = sch->driver_data;
P
Paolo Bonzini 已提交
308
    VirtIODevice *vdev = virtio_ccw_get_vdev(sch);
309 310 311
    bool check_len;
    int len;
    hwaddr hw_len;
312
    VirtioThinintInfo *thinint;
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337

    if (!dev) {
        return -EINVAL;
    }

    trace_virtio_ccw_interpret_ccw(sch->cssid, sch->ssid, sch->schid,
                                   ccw.cmd_code);
    check_len = !((ccw.flags & CCW_FLAG_SLI) && !(ccw.flags & CCW_FLAG_DC));

    /* Look at the command. */
    switch (ccw.cmd_code) {
    case CCW_CMD_SET_VQ:
        if (check_len) {
            if (ccw.count != sizeof(info)) {
                ret = -EINVAL;
                break;
            }
        } else if (ccw.count < sizeof(info)) {
            /* Can't execute command. */
            ret = -EINVAL;
            break;
        }
        if (!ccw.cda) {
            ret = -EFAULT;
        } else {
338
            info.queue = ldq_phys(&address_space_memory, ccw.cda);
339 340
            info.align = ldl_phys(&address_space_memory,
                                  ccw.cda + sizeof(info.queue));
341 342
            info.index = lduw_phys(&address_space_memory,
                                   ccw.cda + sizeof(info.queue)
343
                                   + sizeof(info.align));
344 345
            info.num = lduw_phys(&address_space_memory,
                                 ccw.cda + sizeof(info.queue)
346 347 348 349 350 351 352 353
                                 + sizeof(info.align)
                                 + sizeof(info.index));
            ret = virtio_ccw_set_vqs(sch, info.queue, info.align, info.index,
                                     info.num);
            sch->curr_status.scsw.count = 0;
        }
        break;
    case CCW_CMD_VDEV_RESET:
C
Cornelia Huck 已提交
354
        virtio_ccw_stop_ioeventfd(dev);
P
Paolo Bonzini 已提交
355
        virtio_reset(vdev);
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
        ret = 0;
        break;
    case CCW_CMD_READ_FEAT:
        if (check_len) {
            if (ccw.count != sizeof(features)) {
                ret = -EINVAL;
                break;
            }
        } else if (ccw.count < sizeof(features)) {
            /* Can't execute command. */
            ret = -EINVAL;
            break;
        }
        if (!ccw.cda) {
            ret = -EFAULT;
        } else {
372 373
            features.index = ldub_phys(&address_space_memory,
                                       ccw.cda + sizeof(features.features));
374 375 376 377 378 379
            if (features.index < ARRAY_SIZE(dev->host_features)) {
                features.features = dev->host_features[features.index];
            } else {
                /* Return zeroes if the guest supports more feature bits. */
                features.features = 0;
            }
380
            stl_le_phys(&address_space_memory, ccw.cda, features.features);
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
            sch->curr_status.scsw.count = ccw.count - sizeof(features);
            ret = 0;
        }
        break;
    case CCW_CMD_WRITE_FEAT:
        if (check_len) {
            if (ccw.count != sizeof(features)) {
                ret = -EINVAL;
                break;
            }
        } else if (ccw.count < sizeof(features)) {
            /* Can't execute command. */
            ret = -EINVAL;
            break;
        }
        if (!ccw.cda) {
            ret = -EFAULT;
        } else {
399 400
            features.index = ldub_phys(&address_space_memory,
                                       ccw.cda + sizeof(features.features));
401
            features.features = ldl_le_phys(&address_space_memory, ccw.cda);
402
            if (features.index < ARRAY_SIZE(dev->host_features)) {
403
                virtio_set_features(vdev, features.features);
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
            } else {
                /*
                 * If the guest supports more feature bits, assert that it
                 * passes us zeroes for those we don't support.
                 */
                if (features.features) {
                    fprintf(stderr, "Guest bug: features[%i]=%x (expected 0)\n",
                            features.index, features.features);
                    /* XXX: do a unit check here? */
                }
            }
            sch->curr_status.scsw.count = ccw.count - sizeof(features);
            ret = 0;
        }
        break;
    case CCW_CMD_READ_CONF:
        if (check_len) {
P
Paolo Bonzini 已提交
421
            if (ccw.count > vdev->config_len) {
422 423 424 425
                ret = -EINVAL;
                break;
            }
        }
P
Paolo Bonzini 已提交
426
        len = MIN(ccw.count, vdev->config_len);
427 428 429
        if (!ccw.cda) {
            ret = -EFAULT;
        } else {
P
Paolo Bonzini 已提交
430
            virtio_bus_get_vdev_config(&dev->bus, vdev->config);
431
            /* XXX config space endianness */
P
Paolo Bonzini 已提交
432
            cpu_physical_memory_write(ccw.cda, vdev->config, len);
433 434 435 436 437 438
            sch->curr_status.scsw.count = ccw.count - len;
            ret = 0;
        }
        break;
    case CCW_CMD_WRITE_CONF:
        if (check_len) {
P
Paolo Bonzini 已提交
439
            if (ccw.count > vdev->config_len) {
440 441 442 443
                ret = -EINVAL;
                break;
            }
        }
P
Paolo Bonzini 已提交
444
        len = MIN(ccw.count, vdev->config_len);
445 446 447 448 449 450 451 452 453 454
        hw_len = len;
        if (!ccw.cda) {
            ret = -EFAULT;
        } else {
            config = cpu_physical_memory_map(ccw.cda, &hw_len, 0);
            if (!config) {
                ret = -EFAULT;
            } else {
                len = hw_len;
                /* XXX config space endianness */
P
Paolo Bonzini 已提交
455
                memcpy(vdev->config, config, len);
456
                cpu_physical_memory_unmap(config, hw_len, 0, hw_len);
P
Paolo Bonzini 已提交
457
                virtio_bus_set_vdev_config(&dev->bus, vdev->config);
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476
                sch->curr_status.scsw.count = ccw.count - len;
                ret = 0;
            }
        }
        break;
    case CCW_CMD_WRITE_STATUS:
        if (check_len) {
            if (ccw.count != sizeof(status)) {
                ret = -EINVAL;
                break;
            }
        } else if (ccw.count < sizeof(status)) {
            /* Can't execute command. */
            ret = -EINVAL;
            break;
        }
        if (!ccw.cda) {
            ret = -EFAULT;
        } else {
477
            status = ldub_phys(&address_space_memory, ccw.cda);
C
Cornelia Huck 已提交
478 479 480
            if (!(status & VIRTIO_CONFIG_S_DRIVER_OK)) {
                virtio_ccw_stop_ioeventfd(dev);
            }
P
Paolo Bonzini 已提交
481 482 483
            virtio_set_status(vdev, status);
            if (vdev->status == 0) {
                virtio_reset(vdev);
484
            }
C
Cornelia Huck 已提交
485 486 487
            if (status & VIRTIO_CONFIG_S_DRIVER_OK) {
                virtio_ccw_start_ioeventfd(dev);
            }
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
            sch->curr_status.scsw.count = ccw.count - sizeof(status);
            ret = 0;
        }
        break;
    case CCW_CMD_SET_IND:
        if (check_len) {
            if (ccw.count != sizeof(indicators)) {
                ret = -EINVAL;
                break;
            }
        } else if (ccw.count < sizeof(indicators)) {
            /* Can't execute command. */
            ret = -EINVAL;
            break;
        }
503 504 505 506 507
        if (sch->thinint_active) {
            /* Trigger a command reject. */
            ret = -ENOSYS;
            break;
        }
508
        if (!ccw.cda) {
509 510
            ret = -EFAULT;
        } else {
C
Cornelia Huck 已提交
511
            indicators = ldq_be_phys(&address_space_memory, ccw.cda);
512
            dev->indicators = get_indicator(indicators, sizeof(uint64_t));
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
            sch->curr_status.scsw.count = ccw.count - sizeof(indicators);
            ret = 0;
        }
        break;
    case CCW_CMD_SET_CONF_IND:
        if (check_len) {
            if (ccw.count != sizeof(indicators)) {
                ret = -EINVAL;
                break;
            }
        } else if (ccw.count < sizeof(indicators)) {
            /* Can't execute command. */
            ret = -EINVAL;
            break;
        }
528
        if (!ccw.cda) {
529 530
            ret = -EFAULT;
        } else {
C
Cornelia Huck 已提交
531
            indicators = ldq_be_phys(&address_space_memory, ccw.cda);
532
            dev->indicators2 = get_indicator(indicators, sizeof(uint64_t));
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
            sch->curr_status.scsw.count = ccw.count - sizeof(indicators);
            ret = 0;
        }
        break;
    case CCW_CMD_READ_VQ_CONF:
        if (check_len) {
            if (ccw.count != sizeof(vq_config)) {
                ret = -EINVAL;
                break;
            }
        } else if (ccw.count < sizeof(vq_config)) {
            /* Can't execute command. */
            ret = -EINVAL;
            break;
        }
        if (!ccw.cda) {
            ret = -EFAULT;
        } else {
C
Cornelia Huck 已提交
551
            vq_config.index = lduw_be_phys(&address_space_memory, ccw.cda);
P
Paolo Bonzini 已提交
552
            vq_config.num_max = virtio_queue_get_num(vdev,
553
                                                     vq_config.index);
C
Cornelia Huck 已提交
554 555
            stw_be_phys(&address_space_memory,
                        ccw.cda + sizeof(vq_config.index), vq_config.num_max);
556 557 558 559
            sch->curr_status.scsw.count = ccw.count - sizeof(vq_config);
            ret = 0;
        }
        break;
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582
    case CCW_CMD_SET_IND_ADAPTER:
        if (check_len) {
            if (ccw.count != sizeof(*thinint)) {
                ret = -EINVAL;
                break;
            }
        } else if (ccw.count < sizeof(*thinint)) {
            /* Can't execute command. */
            ret = -EINVAL;
            break;
        }
        len = sizeof(*thinint);
        hw_len = len;
        if (!ccw.cda) {
            ret = -EFAULT;
        } else if (dev->indicators && !sch->thinint_active) {
            /* Trigger a command reject. */
            ret = -ENOSYS;
        } else {
            thinint = cpu_physical_memory_map(ccw.cda, &hw_len, 0);
            if (!thinint) {
                ret = -EFAULT;
            } else {
C
Cornelia Huck 已提交
583 584
                uint64_t ind_bit = ldq_be_p(&thinint->ind_bit);

585
                len = hw_len;
586
                dev->summary_indicator =
C
Cornelia Huck 已提交
587 588 589 590 591
                    get_indicator(ldq_be_p(&thinint->summary_indicator),
                                  sizeof(uint8_t));
                dev->indicators =
                    get_indicator(ldq_be_p(&thinint->device_indicator),
                                  ind_bit / 8 + 1);
592
                dev->thinint_isc = thinint->isc;
C
Cornelia Huck 已提交
593
                dev->routes.adapter.ind_offset = ind_bit;
594
                dev->routes.adapter.summary_offset = 7;
595
                cpu_physical_memory_unmap(thinint, hw_len, 0, hw_len);
596 597
                ret = css_register_io_adapter(CSS_IO_ADAPTER_VIRTIO,
                                              dev->thinint_isc, true, false,
598
                                              &dev->routes.adapter.adapter_id);
599
                assert(ret == 0);
600 601
                sch->thinint_active = ((dev->indicators != NULL) &&
                                       (dev->summary_indicator != NULL));
602 603 604 605 606
                sch->curr_status.scsw.count = ccw.count - len;
                ret = 0;
            }
        }
        break;
607
    default:
C
Cornelia Huck 已提交
608
        ret = -ENOSYS;
609 610 611 612 613
        break;
    }
    return ret;
}

614 615
static void virtio_ccw_device_realize(VirtioCcwDevice *dev,
                                      VirtIODevice *vdev, Error **errp)
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631
{
    unsigned int cssid = 0;
    unsigned int ssid = 0;
    unsigned int schid;
    unsigned int devno;
    bool have_devno = false;
    bool found = false;
    SubchDev *sch;
    int num;
    DeviceState *parent = DEVICE(dev);

    sch = g_malloc0(sizeof(SubchDev));

    sch->driver_data = dev;
    dev->sch = sch;

632
    dev->indicators = NULL;
633 634 635 636

    /* Initialize subchannel structure. */
    sch->channel_prog = 0x0;
    sch->last_cmd_valid = false;
637
    sch->thinint_active = false;
638 639 640 641 642 643 644 645
    /*
     * Use a device number if provided. Otherwise, fall back to subchannel
     * number.
     */
    if (dev->bus_id) {
        num = sscanf(dev->bus_id, "%x.%x.%04x", &cssid, &ssid, &devno);
        if (num == 3) {
            if ((cssid > MAX_CSSID) || (ssid > MAX_SSID)) {
646 647
                error_setg(errp, "Invalid cssid or ssid: cssid %x, ssid %x",
                           cssid, ssid);
648 649 650 651
                goto out_err;
            }
            /* Enforce use of virtual cssid. */
            if (cssid != VIRTUAL_CSSID) {
652 653
                error_setg(errp, "cssid %x not valid for virtio devices",
                           cssid);
654 655 656
                goto out_err;
            }
            if (css_devno_used(cssid, ssid, devno)) {
657 658
                error_setg(errp, "Device %x.%x.%04x already exists",
                           cssid, ssid, devno);
659 660 661 662 663 664 665
                goto out_err;
            }
            sch->cssid = cssid;
            sch->ssid = ssid;
            sch->devno = devno;
            have_devno = true;
        } else {
666
            error_setg(errp, "Malformed devno parameter '%s'", dev->bus_id);
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681
            goto out_err;
        }
    }

    /* Find the next free id. */
    if (have_devno) {
        for (schid = 0; schid <= MAX_SCHID; schid++) {
            if (!css_find_subch(1, cssid, ssid, schid)) {
                sch->schid = schid;
                css_subch_assign(cssid, ssid, schid, devno, sch);
                found = true;
                break;
            }
        }
        if (!found) {
682 683
            error_setg(errp, "No free subchannel found for %x.%x.%04x",
                       cssid, ssid, devno);
684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704
            goto out_err;
        }
        trace_virtio_ccw_new_device(cssid, ssid, schid, devno,
                                    "user-configured");
    } else {
        cssid = VIRTUAL_CSSID;
        for (ssid = 0; ssid <= MAX_SSID; ssid++) {
            for (schid = 0; schid <= MAX_SCHID; schid++) {
                if (!css_find_subch(1, cssid, ssid, schid)) {
                    sch->cssid = cssid;
                    sch->ssid = ssid;
                    sch->schid = schid;
                    devno = schid;
                    /*
                     * If the devno is already taken, look further in this
                     * subchannel set.
                     */
                    while (css_devno_used(cssid, ssid, devno)) {
                        if (devno == MAX_SCHID) {
                            devno = 0;
                        } else if (devno == schid - 1) {
705
                            error_setg(errp, "No free devno found");
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721
                            goto out_err;
                        } else {
                            devno++;
                        }
                    }
                    sch->devno = devno;
                    css_subch_assign(cssid, ssid, schid, devno, sch);
                    found = true;
                    break;
                }
            }
            if (found) {
                break;
            }
        }
        if (!found) {
722
            error_setg(errp, "Virtual channel subsystem is full!");
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737
            goto out_err;
        }
        trace_virtio_ccw_new_device(cssid, ssid, schid, devno,
                                    "auto-configured");
    }

    /* Build initial schib. */
    css_sch_build_virtual_schib(sch, 0, VIRTIO_CCW_CHPID_TYPE);

    sch->ccw_cb = virtio_ccw_cb;

    /* Build senseid data. */
    memset(&sch->id, 0, sizeof(SenseId));
    sch->id.reserved = 0xff;
    sch->id.cu_type = VIRTIO_CCW_CU_TYPE;
P
Paolo Bonzini 已提交
738
    sch->id.cu_model = vdev->device_id;
739 740

    /* Only the first 32 feature bits are used. */
741 742 743
    dev->host_features[0] = virtio_bus_get_vdev_features(&dev->bus,
                                                         dev->host_features[0]);

744 745
    virtio_add_feature(&dev->host_features[0], VIRTIO_F_NOTIFY_ON_EMPTY);
    virtio_add_feature(&dev->host_features[0], VIRTIO_F_BAD_FEATURE);
746 747 748

    css_generate_sch_crws(sch->cssid, sch->ssid, sch->schid,
                          parent->hotplugged, 1);
749
    return;
750 751 752 753 754 755 756 757 758 759 760 761 762 763

out_err:
    dev->sch = NULL;
    g_free(sch);
}

static int virtio_ccw_exit(VirtioCcwDevice *dev)
{
    SubchDev *sch = dev->sch;

    if (sch) {
        css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, NULL);
        g_free(sch);
    }
764
    if (dev->indicators) {
765
        release_indicator(&dev->routes.adapter, dev->indicators);
766 767
        dev->indicators = NULL;
    }
768 769 770
    return 0;
}

771
static void virtio_ccw_net_realize(VirtioCcwDevice *ccw_dev, Error **errp)
772
{
773
    DeviceState *qdev = DEVICE(ccw_dev);
774 775
    VirtIONetCcw *dev = VIRTIO_NET_CCW(ccw_dev);
    DeviceState *vdev = DEVICE(&dev->vdev);
776
    Error *err = NULL;
777

778
    virtio_net_set_config_size(&dev->vdev, ccw_dev->host_features[0]);
779 780
    virtio_net_set_netclient_name(&dev->vdev, qdev->id,
                                  object_get_typename(OBJECT(qdev)));
781
    qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
782 783 784 785
    object_property_set_bool(OBJECT(vdev), true, "realized", &err);
    if (err) {
        error_propagate(errp, err);
        return;
786 787
    }

788
    virtio_ccw_device_realize(ccw_dev, VIRTIO_DEVICE(vdev), errp);
789 790
}

791
static void virtio_ccw_net_instance_init(Object *obj)
792
{
793
    VirtIONetCcw *dev = VIRTIO_NET_CCW(obj);
794 795 796

    virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
                                TYPE_VIRTIO_NET);
797 798
    object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev),
                              "bootindex", &error_abort);
799 800
}

801
static void virtio_ccw_blk_realize(VirtioCcwDevice *ccw_dev, Error **errp)
802
{
803 804
    VirtIOBlkCcw *dev = VIRTIO_BLK_CCW(ccw_dev);
    DeviceState *vdev = DEVICE(&dev->vdev);
805 806
    Error *err = NULL;

807
    qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
808 809 810 811
    object_property_set_bool(OBJECT(vdev), true, "realized", &err);
    if (err) {
        error_propagate(errp, err);
        return;
812 813
    }

814
    virtio_ccw_device_realize(ccw_dev, VIRTIO_DEVICE(vdev), errp);
815 816
}

817
static void virtio_ccw_blk_instance_init(Object *obj)
818
{
819
    VirtIOBlkCcw *dev = VIRTIO_BLK_CCW(obj);
820 821 822

    virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
                                TYPE_VIRTIO_BLK);
823 824
    object_property_add_alias(obj, "iothread", OBJECT(&dev->vdev),"iothread",
                              &error_abort);
825 826
    object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev),
                              "bootindex", &error_abort);
827 828
}

829
static void virtio_ccw_serial_realize(VirtioCcwDevice *ccw_dev, Error **errp)
830
{
831 832
    VirtioSerialCcw *dev = VIRTIO_SERIAL_CCW(ccw_dev);
    DeviceState *vdev = DEVICE(&dev->vdev);
833
    DeviceState *proxy = DEVICE(ccw_dev);
834
    Error *err = NULL;
835 836 837 838 839 840 841 842 843 844 845
    char *bus_name;

    /*
     * For command line compatibility, this sets the virtio-serial-device bus
     * name as before.
     */
    if (proxy->id) {
        bus_name = g_strdup_printf("%s.0", proxy->id);
        virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name);
        g_free(bus_name);
    }
846

847
    qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
848 849 850 851
    object_property_set_bool(OBJECT(vdev), true, "realized", &err);
    if (err) {
        error_propagate(errp, err);
        return;
852 853
    }

854
    virtio_ccw_device_realize(ccw_dev, VIRTIO_DEVICE(vdev), errp);
855 856
}

857 858

static void virtio_ccw_serial_instance_init(Object *obj)
859
{
860
    VirtioSerialCcw *dev = VIRTIO_SERIAL_CCW(obj);
861 862 863

    virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
                                TYPE_VIRTIO_SERIAL);
864 865
}

866
static void virtio_ccw_balloon_realize(VirtioCcwDevice *ccw_dev, Error **errp)
867
{
868 869
    VirtIOBalloonCcw *dev = VIRTIO_BALLOON_CCW(ccw_dev);
    DeviceState *vdev = DEVICE(&dev->vdev);
870
    Error *err = NULL;
871

872
    qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
873 874 875 876
    object_property_set_bool(OBJECT(vdev), true, "realized", &err);
    if (err) {
        error_propagate(errp, err);
        return;
877 878
    }

879
    virtio_ccw_device_realize(ccw_dev, VIRTIO_DEVICE(vdev), errp);
880 881
}

882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907
static void balloon_ccw_stats_get_all(Object *obj, struct Visitor *v,
                                      void *opaque, const char *name,
                                      Error **errp)
{
    VirtIOBalloonCcw *dev = opaque;
    object_property_get(OBJECT(&dev->vdev), v, "guest-stats", errp);
}

static void balloon_ccw_stats_get_poll_interval(Object *obj, struct Visitor *v,
                                                void *opaque, const char *name,
                                                Error **errp)
{
    VirtIOBalloonCcw *dev = opaque;
    object_property_get(OBJECT(&dev->vdev), v, "guest-stats-polling-interval",
                        errp);
}

static void balloon_ccw_stats_set_poll_interval(Object *obj, struct Visitor *v,
                                                void *opaque, const char *name,
                                                Error **errp)
{
    VirtIOBalloonCcw *dev = opaque;
    object_property_set(OBJECT(&dev->vdev), v, "guest-stats-polling-interval",
                        errp);
}

908
static void virtio_ccw_balloon_instance_init(Object *obj)
909
{
910
    VirtIOBalloonCcw *dev = VIRTIO_BALLOON_CCW(obj);
911 912
    virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
                                TYPE_VIRTIO_BALLOON);
913 914 915 916 917 918 919
    object_property_add(obj, "guest-stats", "guest statistics",
                        balloon_ccw_stats_get_all, NULL, NULL, dev, NULL);

    object_property_add(obj, "guest-stats-polling-interval", "int",
                        balloon_ccw_stats_get_poll_interval,
                        balloon_ccw_stats_set_poll_interval,
                        NULL, dev, NULL);
920 921
}

922
static void virtio_ccw_scsi_realize(VirtioCcwDevice *ccw_dev, Error **errp)
923
{
924 925
    VirtIOSCSICcw *dev = VIRTIO_SCSI_CCW(ccw_dev);
    DeviceState *vdev = DEVICE(&dev->vdev);
926
    DeviceState *qdev = DEVICE(ccw_dev);
927
    Error *err = NULL;
928 929 930 931 932 933 934 935 936 937 938
    char *bus_name;

    /*
     * For command line compatibility, this sets the virtio-scsi-device bus
     * name as before.
     */
    if (qdev->id) {
        bus_name = g_strdup_printf("%s.0", qdev->id);
        virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name);
        g_free(bus_name);
    }
939

940
    qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
941 942 943 944
    object_property_set_bool(OBJECT(vdev), true, "realized", &err);
    if (err) {
        error_propagate(errp, err);
        return;
945 946
    }

947
    virtio_ccw_device_realize(ccw_dev, VIRTIO_DEVICE(vdev), errp);
948 949
}

950
static void virtio_ccw_scsi_instance_init(Object *obj)
951
{
952
    VirtIOSCSICcw *dev = VIRTIO_SCSI_CCW(obj);
953 954 955

    virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
                                TYPE_VIRTIO_SCSI);
956 957
    object_property_add_alias(obj, "iothread", OBJECT(&dev->vdev), "iothread",
                              &error_abort);
958 959
}

960
#ifdef CONFIG_VHOST_SCSI
961
static void vhost_ccw_scsi_realize(VirtioCcwDevice *ccw_dev, Error **errp)
962 963 964
{
    VHostSCSICcw *dev = VHOST_SCSI_CCW(ccw_dev);
    DeviceState *vdev = DEVICE(&dev->vdev);
965
    Error *err = NULL;
966 967

    qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
968 969 970 971
    object_property_set_bool(OBJECT(vdev), true, "realized", &err);
    if (err) {
        error_propagate(errp, err);
        return;
972 973
    }

974
    virtio_ccw_device_realize(ccw_dev, VIRTIO_DEVICE(vdev), errp);
975 976 977 978 979
}

static void vhost_ccw_scsi_instance_init(Object *obj)
{
    VHostSCSICcw *dev = VHOST_SCSI_CCW(obj);
980 981 982

    virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
                                TYPE_VHOST_SCSI);
983 984 985
}
#endif

986
static void virtio_ccw_rng_realize(VirtioCcwDevice *ccw_dev, Error **errp)
C
Cornelia Huck 已提交
987
{
988 989
    VirtIORNGCcw *dev = VIRTIO_RNG_CCW(ccw_dev);
    DeviceState *vdev = DEVICE(&dev->vdev);
990
    Error *err = NULL;
C
Cornelia Huck 已提交
991

992
    qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
993 994 995 996
    object_property_set_bool(OBJECT(vdev), true, "realized", &err);
    if (err) {
        error_propagate(errp, err);
        return;
C
Cornelia Huck 已提交
997 998
    }

999
    object_property_set_link(OBJECT(dev),
1000
                             OBJECT(dev->vdev.conf.rng), "rng",
1001 1002
                             NULL);

1003
    virtio_ccw_device_realize(ccw_dev, VIRTIO_DEVICE(vdev), errp);
C
Cornelia Huck 已提交
1004 1005
}

1006 1007 1008 1009 1010 1011 1012 1013
/* DeviceState to VirtioCcwDevice. Note: used on datapath,
 * be careful and test performance if you change this.
 */
static inline VirtioCcwDevice *to_virtio_ccw_dev_fast(DeviceState *d)
{
    return container_of(d, VirtioCcwDevice, parent_obj);
}

1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035
static uint8_t virtio_set_ind_atomic(SubchDev *sch, uint64_t ind_loc,
                                     uint8_t to_be_set)
{
    uint8_t ind_old, ind_new;
    hwaddr len = 1;
    uint8_t *ind_addr;

    ind_addr = cpu_physical_memory_map(ind_loc, &len, 1);
    if (!ind_addr) {
        error_report("%s(%x.%x.%04x): unable to access indicator",
                     __func__, sch->cssid, sch->ssid, sch->schid);
        return -1;
    }
    do {
        ind_old = *ind_addr;
        ind_new = ind_old | to_be_set;
    } while (atomic_cmpxchg(ind_addr, ind_old, ind_new) != ind_old);
    cpu_physical_memory_unmap(ind_addr, len, 1, len);

    return ind_old;
}

1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046
static void virtio_ccw_notify(DeviceState *d, uint16_t vector)
{
    VirtioCcwDevice *dev = to_virtio_ccw_dev_fast(d);
    SubchDev *sch = dev->sch;
    uint64_t indicators;

    if (vector >= 128) {
        return;
    }

    if (vector < VIRTIO_PCI_QUEUE_MAX) {
1047 1048 1049
        if (!dev->indicators) {
            return;
        }
1050 1051 1052 1053 1054 1055 1056
        if (sch->thinint_active) {
            /*
             * In the adapter interrupt case, indicators points to a
             * memory area that may be (way) larger than 64 bit and
             * ind_bit indicates the start of the indicators in a big
             * endian notation.
             */
1057 1058
            uint64_t ind_bit = dev->routes.adapter.ind_offset;

1059
            virtio_set_ind_atomic(sch, dev->indicators->addr +
1060 1061
                                  (ind_bit + vector) / 8,
                                  0x80 >> ((ind_bit + vector) % 8));
1062
            if (!virtio_set_ind_atomic(sch, dev->summary_indicator->addr,
1063 1064 1065 1066
                                       0x01)) {
                css_adapter_interrupt(dev->thinint_isc);
            }
        } else {
1067
            indicators = ldq_phys(&address_space_memory, dev->indicators->addr);
1068
            indicators |= 1ULL << vector;
1069
            stq_phys(&address_space_memory, dev->indicators->addr, indicators);
1070 1071
            css_conditional_io_interrupt(sch);
        }
1072
    } else {
1073 1074 1075
        if (!dev->indicators2) {
            return;
        }
1076
        vector = 0;
1077
        indicators = ldq_phys(&address_space_memory, dev->indicators2->addr);
1078
        indicators |= 1ULL << vector;
1079
        stq_phys(&address_space_memory, dev->indicators2->addr, indicators);
1080
        css_conditional_io_interrupt(sch);
1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094
    }
}

static unsigned virtio_ccw_get_features(DeviceState *d)
{
    VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);

    /* Only the first 32 feature bits are used. */
    return dev->host_features[0];
}

static void virtio_ccw_reset(DeviceState *d)
{
    VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
P
Paolo Bonzini 已提交
1095
    VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
1096

C
Cornelia Huck 已提交
1097
    virtio_ccw_stop_ioeventfd(dev);
P
Paolo Bonzini 已提交
1098
    virtio_reset(vdev);
1099
    css_reset_sch(dev->sch);
1100
    if (dev->indicators) {
1101
        release_indicator(&dev->routes.adapter, dev->indicators);
1102 1103 1104
        dev->indicators = NULL;
    }
    if (dev->indicators2) {
1105
        release_indicator(&dev->routes.adapter, dev->indicators2);
1106 1107 1108
        dev->indicators2 = NULL;
    }
    if (dev->summary_indicator) {
1109
        release_indicator(&dev->routes.adapter, dev->summary_indicator);
1110 1111
        dev->summary_indicator = NULL;
    }
1112 1113
}

C
Cornelia Huck 已提交
1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124
static void virtio_ccw_vmstate_change(DeviceState *d, bool running)
{
    VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);

    if (running) {
        virtio_ccw_start_ioeventfd(dev);
    } else {
        virtio_ccw_stop_ioeventfd(dev);
    }
}

1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144
static bool virtio_ccw_query_guest_notifiers(DeviceState *d)
{
    VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);

    return !!(dev->sch->curr_status.pmcw.flags & PMCW_FLAGS_MASK_ENA);
}

static int virtio_ccw_set_host_notifier(DeviceState *d, int n, bool assign)
{
    VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);

    /* Stop using the generic ioeventfd, we are doing eventfd handling
     * ourselves below */
    dev->ioeventfd_disabled = assign;
    if (assign) {
        virtio_ccw_stop_ioeventfd(dev);
    }
    return virtio_ccw_set_guest2host_notifier(dev, n, assign, false);
}

1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217
static int virtio_ccw_get_mappings(VirtioCcwDevice *dev)
{
    int r;

    if (!dev->sch->thinint_active) {
        return -EINVAL;
    }

    r = map_indicator(&dev->routes.adapter, dev->summary_indicator);
    if (r) {
        return r;
    }
    r = map_indicator(&dev->routes.adapter, dev->indicators);
    if (r) {
        return r;
    }
    dev->routes.adapter.summary_addr = dev->summary_indicator->map;
    dev->routes.adapter.ind_addr = dev->indicators->map;

    return 0;
}

static int virtio_ccw_setup_irqroutes(VirtioCcwDevice *dev, int nvqs)
{
    int i;
    VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
    int ret;
    S390FLICState *fs = s390_get_flic();
    S390FLICStateClass *fsc = S390_FLIC_COMMON_GET_CLASS(fs);

    ret = virtio_ccw_get_mappings(dev);
    if (ret) {
        return ret;
    }
    for (i = 0; i < nvqs; i++) {
        if (!virtio_queue_get_num(vdev, i)) {
            break;
        }
    }
    dev->routes.num_routes = i;
    return fsc->add_adapter_routes(fs, &dev->routes);
}

static void virtio_ccw_release_irqroutes(VirtioCcwDevice *dev, int nvqs)
{
    S390FLICState *fs = s390_get_flic();
    S390FLICStateClass *fsc = S390_FLIC_COMMON_GET_CLASS(fs);

    fsc->release_adapter_routes(fs, &dev->routes);
}

static int virtio_ccw_add_irqfd(VirtioCcwDevice *dev, int n)
{
    VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
    VirtQueue *vq = virtio_get_queue(vdev, n);
    EventNotifier *notifier = virtio_queue_get_guest_notifier(vq);

    return kvm_irqchip_add_irqfd_notifier(kvm_state, notifier, NULL,
                                          dev->routes.gsi[n]);
}

static void virtio_ccw_remove_irqfd(VirtioCcwDevice *dev, int n)
{
    VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
    VirtQueue *vq = virtio_get_queue(vdev, n);
    EventNotifier *notifier = virtio_queue_get_guest_notifier(vq);
    int ret;

    ret = kvm_irqchip_remove_irqfd_notifier(kvm_state, notifier,
                                            dev->routes.gsi[n]);
    assert(ret == 0);
}

1218 1219 1220
static int virtio_ccw_set_guest_notifier(VirtioCcwDevice *dev, int n,
                                         bool assign, bool with_irqfd)
{
P
Paolo Bonzini 已提交
1221 1222
    VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
    VirtQueue *vq = virtio_get_queue(vdev, n);
1223
    EventNotifier *notifier = virtio_queue_get_guest_notifier(vq);
P
Paolo Bonzini 已提交
1224
    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
1225 1226 1227 1228 1229 1230 1231 1232

    if (assign) {
        int r = event_notifier_init(notifier, 0);

        if (r < 0) {
            return r;
        }
        virtio_queue_set_guest_notifier_fd_handler(vq, true, with_irqfd);
1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243
        if (with_irqfd) {
            r = virtio_ccw_add_irqfd(dev, n);
            if (r) {
                virtio_queue_set_guest_notifier_fd_handler(vq, false,
                                                           with_irqfd);
                return r;
            }
        }
        /*
         * We do not support individual masking for channel devices, so we
         * need to manually trigger any guest masking callbacks here.
1244 1245
         */
        if (k->guest_notifier_mask) {
P
Paolo Bonzini 已提交
1246
            k->guest_notifier_mask(vdev, n, false);
1247 1248 1249
        }
        /* get lost events and re-inject */
        if (k->guest_notifier_pending &&
P
Paolo Bonzini 已提交
1250
            k->guest_notifier_pending(vdev, n)) {
1251 1252 1253 1254
            event_notifier_set(notifier);
        }
    } else {
        if (k->guest_notifier_mask) {
P
Paolo Bonzini 已提交
1255
            k->guest_notifier_mask(vdev, n, true);
1256
        }
1257 1258 1259
        if (with_irqfd) {
            virtio_ccw_remove_irqfd(dev, n);
        }
1260 1261 1262 1263 1264 1265 1266 1267 1268 1269
        virtio_queue_set_guest_notifier_fd_handler(vq, false, with_irqfd);
        event_notifier_cleanup(notifier);
    }
    return 0;
}

static int virtio_ccw_set_guest_notifiers(DeviceState *d, int nvqs,
                                          bool assigned)
{
    VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
P
Paolo Bonzini 已提交
1270
    VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
1271
    bool with_irqfd = dev->sch->thinint_active && kvm_irqfds_enabled();
1272 1273
    int r, n;

1274 1275 1276 1277 1278 1279 1280
    if (with_irqfd && assigned) {
        /* irq routes need to be set up before assigning irqfds */
        r = virtio_ccw_setup_irqroutes(dev, nvqs);
        if (r < 0) {
            goto irqroute_error;
        }
    }
1281 1282 1283 1284
    for (n = 0; n < nvqs; n++) {
        if (!virtio_queue_get_num(vdev, n)) {
            break;
        }
1285
        r = virtio_ccw_set_guest_notifier(dev, n, assigned, with_irqfd);
1286 1287 1288 1289
        if (r < 0) {
            goto assign_error;
        }
    }
1290 1291 1292 1293
    if (with_irqfd && !assigned) {
        /* release irq routes after irqfds have been released */
        virtio_ccw_release_irqroutes(dev, nvqs);
    }
1294 1295 1296 1297 1298 1299
    return 0;

assign_error:
    while (--n >= 0) {
        virtio_ccw_set_guest_notifier(dev, n, !assigned, false);
    }
1300 1301 1302 1303
irqroute_error:
    if (with_irqfd && assigned) {
        virtio_ccw_release_irqroutes(dev, nvqs);
    }
1304 1305 1306
    return r;
}

1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397
static void virtio_ccw_save_queue(DeviceState *d, int n, QEMUFile *f)
{
    VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
    VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);

    qemu_put_be16(f, virtio_queue_vector(vdev, n));
}

static int virtio_ccw_load_queue(DeviceState *d, int n, QEMUFile *f)
{
    VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
    VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
    uint16_t vector;

    qemu_get_be16s(f, &vector);
    virtio_queue_set_vector(vdev, n , vector);

    return 0;
}

static void virtio_ccw_save_config(DeviceState *d, QEMUFile *f)
{
    VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
    SubchDev *s = dev->sch;

    subch_device_save(s, f);
    if (dev->indicators != NULL) {
        qemu_put_be32(f, dev->indicators->len);
        qemu_put_be64(f, dev->indicators->addr);
    } else {
        qemu_put_be32(f, 0);
        qemu_put_be64(f, 0UL);
    }
    if (dev->indicators2 != NULL) {
        qemu_put_be32(f, dev->indicators2->len);
        qemu_put_be64(f, dev->indicators2->addr);
    } else {
        qemu_put_be32(f, 0);
        qemu_put_be64(f, 0UL);
    }
    if (dev->summary_indicator != NULL) {
        qemu_put_be32(f, dev->summary_indicator->len);
        qemu_put_be64(f, dev->summary_indicator->addr);
    } else {
        qemu_put_be32(f, 0);
        qemu_put_be64(f, 0UL);
    }
    qemu_put_be64(f, dev->routes.adapter.ind_offset);
    qemu_put_byte(f, dev->thinint_isc);
}

static int virtio_ccw_load_config(DeviceState *d, QEMUFile *f)
{
    VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
    SubchDev *s = dev->sch;
    int len;

    s->driver_data = dev;
    subch_device_load(s, f);
    len = qemu_get_be32(f);
    if (len != 0) {
        dev->indicators = get_indicator(qemu_get_be64(f), len);
    } else {
        qemu_get_be64(f);
        dev->indicators = NULL;
    }
    len = qemu_get_be32(f);
    if (len != 0) {
        dev->indicators2 = get_indicator(qemu_get_be64(f), len);
    } else {
        qemu_get_be64(f);
        dev->indicators2 = NULL;
    }
    len = qemu_get_be32(f);
    if (len != 0) {
        dev->summary_indicator = get_indicator(qemu_get_be64(f), len);
    } else {
        qemu_get_be64(f);
        dev->summary_indicator = NULL;
    }
    dev->routes.adapter.ind_offset = qemu_get_be64(f);
    dev->thinint_isc = qemu_get_byte(f);
    if (s->thinint_active) {
        return css_register_io_adapter(CSS_IO_ADAPTER_VIRTIO,
                                       dev->thinint_isc, true, false,
                                       &dev->routes.adapter.adapter_id);
    }

    return 0;
}

1398 1399 1400 1401 1402
/**************** Virtio-ccw Bus Device Descriptions *******************/

static Property virtio_ccw_net_properties[] = {
    DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
    DEFINE_VIRTIO_NET_FEATURES(VirtioCcwDevice, host_features[0]),
C
Cornelia Huck 已提交
1403 1404
    DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
                    VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1405 1406 1407 1408 1409 1410 1411 1412
    DEFINE_PROP_END_OF_LIST(),
};

static void virtio_ccw_net_class_init(ObjectClass *klass, void *data)
{
    DeviceClass *dc = DEVICE_CLASS(klass);
    VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);

1413
    k->realize = virtio_ccw_net_realize;
1414
    k->exit = virtio_ccw_exit;
1415 1416 1417 1418 1419
    dc->reset = virtio_ccw_reset;
    dc->props = virtio_ccw_net_properties;
}

static const TypeInfo virtio_ccw_net = {
1420
    .name          = TYPE_VIRTIO_NET_CCW,
1421
    .parent        = TYPE_VIRTIO_CCW_DEVICE,
1422 1423
    .instance_size = sizeof(VirtIONetCcw),
    .instance_init = virtio_ccw_net_instance_init,
1424 1425 1426 1427 1428
    .class_init    = virtio_ccw_net_class_init,
};

static Property virtio_ccw_blk_properties[] = {
    DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
C
Cornelia Huck 已提交
1429 1430
    DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
                    VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1431 1432 1433 1434 1435 1436 1437 1438
    DEFINE_PROP_END_OF_LIST(),
};

static void virtio_ccw_blk_class_init(ObjectClass *klass, void *data)
{
    DeviceClass *dc = DEVICE_CLASS(klass);
    VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);

1439
    k->realize = virtio_ccw_blk_realize;
1440
    k->exit = virtio_ccw_exit;
1441 1442 1443 1444 1445
    dc->reset = virtio_ccw_reset;
    dc->props = virtio_ccw_blk_properties;
}

static const TypeInfo virtio_ccw_blk = {
1446
    .name          = TYPE_VIRTIO_BLK_CCW,
1447
    .parent        = TYPE_VIRTIO_CCW_DEVICE,
1448 1449
    .instance_size = sizeof(VirtIOBlkCcw),
    .instance_init = virtio_ccw_blk_instance_init,
1450 1451 1452 1453 1454
    .class_init    = virtio_ccw_blk_class_init,
};

static Property virtio_ccw_serial_properties[] = {
    DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
C
Cornelia Huck 已提交
1455 1456
    DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
                    VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1457 1458 1459 1460 1461 1462 1463 1464
    DEFINE_PROP_END_OF_LIST(),
};

static void virtio_ccw_serial_class_init(ObjectClass *klass, void *data)
{
    DeviceClass *dc = DEVICE_CLASS(klass);
    VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);

1465
    k->realize = virtio_ccw_serial_realize;
1466
    k->exit = virtio_ccw_exit;
1467 1468 1469 1470 1471
    dc->reset = virtio_ccw_reset;
    dc->props = virtio_ccw_serial_properties;
}

static const TypeInfo virtio_ccw_serial = {
1472
    .name          = TYPE_VIRTIO_SERIAL_CCW,
1473
    .parent        = TYPE_VIRTIO_CCW_DEVICE,
1474 1475
    .instance_size = sizeof(VirtioSerialCcw),
    .instance_init = virtio_ccw_serial_instance_init,
1476 1477 1478 1479 1480
    .class_init    = virtio_ccw_serial_class_init,
};

static Property virtio_ccw_balloon_properties[] = {
    DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
C
Cornelia Huck 已提交
1481 1482
    DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
                    VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1483 1484 1485 1486 1487 1488 1489 1490
    DEFINE_PROP_END_OF_LIST(),
};

static void virtio_ccw_balloon_class_init(ObjectClass *klass, void *data)
{
    DeviceClass *dc = DEVICE_CLASS(klass);
    VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);

1491
    k->realize = virtio_ccw_balloon_realize;
1492
    k->exit = virtio_ccw_exit;
1493 1494 1495 1496 1497
    dc->reset = virtio_ccw_reset;
    dc->props = virtio_ccw_balloon_properties;
}

static const TypeInfo virtio_ccw_balloon = {
1498
    .name          = TYPE_VIRTIO_BALLOON_CCW,
1499
    .parent        = TYPE_VIRTIO_CCW_DEVICE,
1500 1501
    .instance_size = sizeof(VirtIOBalloonCcw),
    .instance_init = virtio_ccw_balloon_instance_init,
1502 1503 1504 1505 1506
    .class_init    = virtio_ccw_balloon_class_init,
};

static Property virtio_ccw_scsi_properties[] = {
    DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
1507
    DEFINE_VIRTIO_SCSI_FEATURES(VirtioCcwDevice, host_features[0]),
C
Cornelia Huck 已提交
1508 1509
    DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
                    VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
1510 1511 1512 1513 1514 1515 1516 1517
    DEFINE_PROP_END_OF_LIST(),
};

static void virtio_ccw_scsi_class_init(ObjectClass *klass, void *data)
{
    DeviceClass *dc = DEVICE_CLASS(klass);
    VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);

1518
    k->realize = virtio_ccw_scsi_realize;
1519
    k->exit = virtio_ccw_exit;
1520 1521 1522 1523 1524
    dc->reset = virtio_ccw_reset;
    dc->props = virtio_ccw_scsi_properties;
}

static const TypeInfo virtio_ccw_scsi = {
1525
    .name          = TYPE_VIRTIO_SCSI_CCW,
1526
    .parent        = TYPE_VIRTIO_CCW_DEVICE,
1527 1528
    .instance_size = sizeof(VirtIOSCSICcw),
    .instance_init = virtio_ccw_scsi_instance_init,
1529 1530 1531
    .class_init    = virtio_ccw_scsi_class_init,
};

1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542
#ifdef CONFIG_VHOST_SCSI
static Property vhost_ccw_scsi_properties[] = {
    DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
    DEFINE_PROP_END_OF_LIST(),
};

static void vhost_ccw_scsi_class_init(ObjectClass *klass, void *data)
{
    DeviceClass *dc = DEVICE_CLASS(klass);
    VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);

1543
    k->realize = vhost_ccw_scsi_realize;
1544 1545 1546 1547 1548 1549 1550 1551
    k->exit = virtio_ccw_exit;
    dc->reset = virtio_ccw_reset;
    dc->props = vhost_ccw_scsi_properties;
}

static const TypeInfo vhost_ccw_scsi = {
    .name          = TYPE_VHOST_SCSI_CCW,
    .parent        = TYPE_VIRTIO_CCW_DEVICE,
1552
    .instance_size = sizeof(VHostSCSICcw),
1553 1554 1555 1556 1557
    .instance_init = vhost_ccw_scsi_instance_init,
    .class_init    = vhost_ccw_scsi_class_init,
};
#endif

1558
static void virtio_ccw_rng_instance_init(Object *obj)
C
Cornelia Huck 已提交
1559
{
1560
    VirtIORNGCcw *dev = VIRTIO_RNG_CCW(obj);
1561 1562 1563

    virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
                                TYPE_VIRTIO_RNG);
1564 1565
    object_property_add_alias(obj, "rng", OBJECT(&dev->vdev),
                              "rng", &error_abort);
C
Cornelia Huck 已提交
1566 1567 1568 1569
}

static Property virtio_ccw_rng_properties[] = {
    DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
C
Cornelia Huck 已提交
1570 1571
    DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
                    VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
C
Cornelia Huck 已提交
1572 1573 1574 1575 1576 1577 1578 1579
    DEFINE_PROP_END_OF_LIST(),
};

static void virtio_ccw_rng_class_init(ObjectClass *klass, void *data)
{
    DeviceClass *dc = DEVICE_CLASS(klass);
    VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);

1580
    k->realize = virtio_ccw_rng_realize;
1581
    k->exit = virtio_ccw_exit;
C
Cornelia Huck 已提交
1582 1583 1584 1585 1586
    dc->reset = virtio_ccw_reset;
    dc->props = virtio_ccw_rng_properties;
}

static const TypeInfo virtio_ccw_rng = {
1587
    .name          = TYPE_VIRTIO_RNG_CCW,
C
Cornelia Huck 已提交
1588
    .parent        = TYPE_VIRTIO_CCW_DEVICE,
1589 1590
    .instance_size = sizeof(VirtIORNGCcw),
    .instance_init = virtio_ccw_rng_instance_init,
C
Cornelia Huck 已提交
1591 1592 1593
    .class_init    = virtio_ccw_rng_class_init,
};

1594
static void virtio_ccw_busdev_realize(DeviceState *dev, Error **errp)
1595 1596 1597 1598
{
    VirtioCcwDevice *_dev = (VirtioCcwDevice *)dev;
    VirtIOCCWDeviceClass *_info = VIRTIO_CCW_DEVICE_GET_CLASS(dev);

1599
    virtio_ccw_bus_new(&_dev->bus, sizeof(_dev->bus), _dev);
1600
    _info->realize(_dev, errp);
1601 1602 1603 1604 1605 1606 1607 1608 1609 1610
}

static int virtio_ccw_busdev_exit(DeviceState *dev)
{
    VirtioCcwDevice *_dev = (VirtioCcwDevice *)dev;
    VirtIOCCWDeviceClass *_info = VIRTIO_CCW_DEVICE_GET_CLASS(dev);

    return _info->exit(_dev);
}

1611 1612
static void virtio_ccw_busdev_unplug(HotplugHandler *hotplug_dev,
                                     DeviceState *dev, Error **errp)
1613 1614 1615 1616
{
    VirtioCcwDevice *_dev = (VirtioCcwDevice *)dev;
    SubchDev *sch = _dev->sch;

1617 1618
    virtio_ccw_stop_ioeventfd(_dev);

1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629
    /*
     * We should arrive here only for device_del, since we don't support
     * direct hot(un)plug of channels, but only through virtio.
     */
    assert(sch != NULL);
    /* Subchannel is now disabled and no longer valid. */
    sch->curr_status.pmcw.flags &= ~(PMCW_FLAGS_MASK_ENA |
                                     PMCW_FLAGS_MASK_DNV);

    css_generate_sch_crws(sch->cssid, sch->ssid, sch->schid, 1, 0);

1630
    object_unparent(OBJECT(dev));
1631 1632
}

1633 1634 1635 1636 1637
static Property virtio_ccw_properties[] = {
    DEFINE_VIRTIO_COMMON_FEATURES(VirtioCcwDevice, host_features[0]),
    DEFINE_PROP_END_OF_LIST(),
};

1638 1639 1640 1641
static void virtio_ccw_device_class_init(ObjectClass *klass, void *data)
{
    DeviceClass *dc = DEVICE_CLASS(klass);

1642
    dc->props = virtio_ccw_properties;
1643
    dc->realize = virtio_ccw_busdev_realize;
1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668
    dc->exit = virtio_ccw_busdev_exit;
    dc->bus_type = TYPE_VIRTUAL_CSS_BUS;
}

static const TypeInfo virtio_ccw_device_info = {
    .name = TYPE_VIRTIO_CCW_DEVICE,
    .parent = TYPE_DEVICE,
    .instance_size = sizeof(VirtioCcwDevice),
    .class_init = virtio_ccw_device_class_init,
    .class_size = sizeof(VirtIOCCWDeviceClass),
    .abstract = true,
};

/***************** Virtual-css Bus Bridge Device ********************/
/* Only required to have the virtio bus as child in the system bus */

static int virtual_css_bridge_init(SysBusDevice *dev)
{
    /* nothing */
    return 0;
}

static void virtual_css_bridge_class_init(ObjectClass *klass, void *data)
{
    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
1669
    HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);
1670 1671

    k->init = virtual_css_bridge_init;
1672
    hc->unplug = virtio_ccw_busdev_unplug;
1673 1674 1675 1676 1677 1678 1679
}

static const TypeInfo virtual_css_bridge_info = {
    .name          = "virtual-css-bridge",
    .parent        = TYPE_SYS_BUS_DEVICE,
    .instance_size = sizeof(SysBusDevice),
    .class_init    = virtual_css_bridge_class_init,
1680 1681 1682 1683
    .interfaces = (InterfaceInfo[]) {
        { TYPE_HOTPLUG_HANDLER },
        { }
    }
1684 1685 1686 1687
};

/* virtio-ccw-bus */

1688 1689
static void virtio_ccw_bus_new(VirtioBusState *bus, size_t bus_size,
                               VirtioCcwDevice *dev)
1690 1691
{
    DeviceState *qdev = DEVICE(dev);
1692
    char virtio_bus_name[] = "virtio-bus";
1693

1694 1695
    qbus_create_inplace(bus, bus_size, TYPE_VIRTIO_CCW_BUS,
                        qdev, virtio_bus_name);
1696 1697 1698 1699 1700 1701 1702 1703 1704 1705
}

static void virtio_ccw_bus_class_init(ObjectClass *klass, void *data)
{
    VirtioBusClass *k = VIRTIO_BUS_CLASS(klass);
    BusClass *bus_class = BUS_CLASS(klass);

    bus_class->max_dev = 1;
    k->notify = virtio_ccw_notify;
    k->get_features = virtio_ccw_get_features;
C
Cornelia Huck 已提交
1706
    k->vmstate_change = virtio_ccw_vmstate_change;
1707 1708 1709
    k->query_guest_notifiers = virtio_ccw_query_guest_notifiers;
    k->set_host_notifier = virtio_ccw_set_host_notifier;
    k->set_guest_notifiers = virtio_ccw_set_guest_notifiers;
1710 1711 1712 1713
    k->save_queue = virtio_ccw_save_queue;
    k->load_queue = virtio_ccw_load_queue;
    k->save_config = virtio_ccw_save_config;
    k->load_config = virtio_ccw_load_config;
1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732
}

static const TypeInfo virtio_ccw_bus_info = {
    .name = TYPE_VIRTIO_CCW_BUS,
    .parent = TYPE_VIRTIO_BUS,
    .instance_size = sizeof(VirtioCcwBusState),
    .class_init = virtio_ccw_bus_class_init,
};

static void virtio_ccw_register(void)
{
    type_register_static(&virtio_ccw_bus_info);
    type_register_static(&virtual_css_bus_info);
    type_register_static(&virtio_ccw_device_info);
    type_register_static(&virtio_ccw_serial);
    type_register_static(&virtio_ccw_blk);
    type_register_static(&virtio_ccw_net);
    type_register_static(&virtio_ccw_balloon);
    type_register_static(&virtio_ccw_scsi);
1733
#ifdef CONFIG_VHOST_SCSI
1734
    type_register_static(&vhost_ccw_scsi);
1735
#endif
C
Cornelia Huck 已提交
1736
    type_register_static(&virtio_ccw_rng);
1737 1738 1739 1740
    type_register_static(&virtual_css_bridge_info);
}

type_init(virtio_ccw_register)