1 /* 2 * virtio ccw target implementation 3 * 4 * Copyright 2012,2015 IBM Corp. 5 * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com> 6 * Pierre Morel <pmorel@linux.vnet.ibm.com> 7 * 8 * This work is licensed under the terms of the GNU GPL, version 2 or (at 9 * your option) any later version. See the COPYING file in the top-level 10 * directory. 11 */ 12 13 #include "qemu/osdep.h" 14 #include "qapi/error.h" 15 #include "hw/hw.h" 16 #include "sysemu/block-backend.h" 17 #include "sysemu/blockdev.h" 18 #include "sysemu/sysemu.h" 19 #include "sysemu/kvm.h" 20 #include "net/net.h" 21 #include "hw/virtio/virtio.h" 22 #include "hw/virtio/virtio-serial.h" 23 #include "hw/virtio/virtio-net.h" 24 #include "hw/sysbus.h" 25 #include "qemu/bitops.h" 26 #include "qemu/error-report.h" 27 #include "hw/virtio/virtio-access.h" 28 #include "hw/virtio/virtio-bus.h" 29 #include "hw/s390x/adapter.h" 30 #include "hw/s390x/s390_flic.h" 31 32 #include "hw/s390x/ioinst.h" 33 #include "hw/s390x/css.h" 34 #include "virtio-ccw.h" 35 #include "trace.h" 36 #include "hw/s390x/css-bridge.h" 37 38 #define NR_CLASSIC_INDICATOR_BITS 64 39 40 static void virtio_ccw_bus_new(VirtioBusState *bus, size_t bus_size, 41 VirtioCcwDevice *dev); 42 43 VirtIODevice *virtio_ccw_get_vdev(SubchDev *sch) 44 { 45 VirtIODevice *vdev = NULL; 46 VirtioCcwDevice *dev = sch->driver_data; 47 48 if (dev) { 49 vdev = virtio_bus_get_device(&dev->bus); 50 } 51 return vdev; 52 } 53 54 static void virtio_ccw_start_ioeventfd(VirtioCcwDevice *dev) 55 { 56 virtio_bus_start_ioeventfd(&dev->bus); 57 } 58 59 static void virtio_ccw_stop_ioeventfd(VirtioCcwDevice *dev) 60 { 61 virtio_bus_stop_ioeventfd(&dev->bus); 62 } 63 64 static bool virtio_ccw_ioeventfd_enabled(DeviceState *d) 65 { 66 VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d); 67 68 return (dev->flags & VIRTIO_CCW_FLAG_USE_IOEVENTFD) != 0; 69 } 70 71 static int virtio_ccw_ioeventfd_assign(DeviceState *d, EventNotifier *notifier, 72 int n, bool assign) 73 { 74 VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d); 75 CcwDevice *ccw_dev = CCW_DEVICE(dev); 76 SubchDev *sch = ccw_dev->sch; 77 uint32_t sch_id = (css_build_subchannel_id(sch) << 16) | sch->schid; 78 79 return s390_assign_subch_ioeventfd(notifier, sch_id, n, assign); 80 } 81 82 /* Communication blocks used by several channel commands. */ 83 typedef struct VqInfoBlockLegacy { 84 uint64_t queue; 85 uint32_t align; 86 uint16_t index; 87 uint16_t num; 88 } QEMU_PACKED VqInfoBlockLegacy; 89 90 typedef struct VqInfoBlock { 91 uint64_t desc; 92 uint32_t res0; 93 uint16_t index; 94 uint16_t num; 95 uint64_t avail; 96 uint64_t used; 97 } QEMU_PACKED VqInfoBlock; 98 99 typedef struct VqConfigBlock { 100 uint16_t index; 101 uint16_t num_max; 102 } QEMU_PACKED VqConfigBlock; 103 104 typedef struct VirtioFeatDesc { 105 uint32_t features; 106 uint8_t index; 107 } QEMU_PACKED VirtioFeatDesc; 108 109 typedef struct VirtioThinintInfo { 110 hwaddr summary_indicator; 111 hwaddr device_indicator; 112 uint64_t ind_bit; 113 uint8_t isc; 114 } QEMU_PACKED VirtioThinintInfo; 115 116 typedef struct VirtioRevInfo { 117 uint16_t revision; 118 uint16_t length; 119 uint8_t data[0]; 120 } QEMU_PACKED VirtioRevInfo; 121 122 /* Specify where the virtqueues for the subchannel are in guest memory. */ 123 static int virtio_ccw_set_vqs(SubchDev *sch, VqInfoBlock *info, 124 VqInfoBlockLegacy *linfo) 125 { 126 VirtIODevice *vdev = virtio_ccw_get_vdev(sch); 127 uint16_t index = info ? info->index : linfo->index; 128 uint16_t num = info ? info->num : linfo->num; 129 uint64_t desc = info ? info->desc : linfo->queue; 130 131 if (index >= VIRTIO_QUEUE_MAX) { 132 return -EINVAL; 133 } 134 135 /* Current code in virtio.c relies on 4K alignment. */ 136 if (linfo && desc && (linfo->align != 4096)) { 137 return -EINVAL; 138 } 139 140 if (!vdev) { 141 return -EINVAL; 142 } 143 144 if (info) { 145 virtio_queue_set_rings(vdev, index, desc, info->avail, info->used); 146 } else { 147 virtio_queue_set_addr(vdev, index, desc); 148 } 149 if (!desc) { 150 virtio_queue_set_vector(vdev, index, VIRTIO_NO_VECTOR); 151 } else { 152 if (info) { 153 /* virtio-1 allows changing the ring size. */ 154 if (virtio_queue_get_max_num(vdev, index) < num) { 155 /* Fail if we exceed the maximum number. */ 156 return -EINVAL; 157 } 158 virtio_queue_set_num(vdev, index, num); 159 } else if (virtio_queue_get_num(vdev, index) > num) { 160 /* Fail if we don't have a big enough queue. */ 161 return -EINVAL; 162 } 163 /* We ignore possible increased num for legacy for compatibility. */ 164 virtio_queue_set_vector(vdev, index, index); 165 } 166 /* tell notify handler in case of config change */ 167 vdev->config_vector = VIRTIO_QUEUE_MAX; 168 return 0; 169 } 170 171 static void virtio_ccw_reset_virtio(VirtioCcwDevice *dev, VirtIODevice *vdev) 172 { 173 CcwDevice *ccw_dev = CCW_DEVICE(dev); 174 175 virtio_ccw_stop_ioeventfd(dev); 176 virtio_reset(vdev); 177 if (dev->indicators) { 178 release_indicator(&dev->routes.adapter, dev->indicators); 179 dev->indicators = NULL; 180 } 181 if (dev->indicators2) { 182 release_indicator(&dev->routes.adapter, dev->indicators2); 183 dev->indicators2 = NULL; 184 } 185 if (dev->summary_indicator) { 186 release_indicator(&dev->routes.adapter, dev->summary_indicator); 187 dev->summary_indicator = NULL; 188 } 189 ccw_dev->sch->thinint_active = false; 190 } 191 192 static int virtio_ccw_handle_set_vq(SubchDev *sch, CCW1 ccw, bool check_len, 193 bool is_legacy) 194 { 195 int ret; 196 VqInfoBlock info; 197 VqInfoBlockLegacy linfo; 198 size_t info_len = is_legacy ? sizeof(linfo) : sizeof(info); 199 200 if (check_len) { 201 if (ccw.count != info_len) { 202 return -EINVAL; 203 } 204 } else if (ccw.count < info_len) { 205 /* Can't execute command. */ 206 return -EINVAL; 207 } 208 if (!ccw.cda) { 209 return -EFAULT; 210 } 211 if (is_legacy) { 212 linfo.queue = address_space_ldq_be(&address_space_memory, ccw.cda, 213 MEMTXATTRS_UNSPECIFIED, NULL); 214 linfo.align = address_space_ldl_be(&address_space_memory, 215 ccw.cda + sizeof(linfo.queue), 216 MEMTXATTRS_UNSPECIFIED, 217 NULL); 218 linfo.index = address_space_lduw_be(&address_space_memory, 219 ccw.cda + sizeof(linfo.queue) 220 + sizeof(linfo.align), 221 MEMTXATTRS_UNSPECIFIED, 222 NULL); 223 linfo.num = address_space_lduw_be(&address_space_memory, 224 ccw.cda + sizeof(linfo.queue) 225 + sizeof(linfo.align) 226 + sizeof(linfo.index), 227 MEMTXATTRS_UNSPECIFIED, 228 NULL); 229 ret = virtio_ccw_set_vqs(sch, NULL, &linfo); 230 } else { 231 info.desc = address_space_ldq_be(&address_space_memory, ccw.cda, 232 MEMTXATTRS_UNSPECIFIED, NULL); 233 info.index = address_space_lduw_be(&address_space_memory, 234 ccw.cda + sizeof(info.desc) 235 + sizeof(info.res0), 236 MEMTXATTRS_UNSPECIFIED, NULL); 237 info.num = address_space_lduw_be(&address_space_memory, 238 ccw.cda + sizeof(info.desc) 239 + sizeof(info.res0) 240 + sizeof(info.index), 241 MEMTXATTRS_UNSPECIFIED, NULL); 242 info.avail = address_space_ldq_be(&address_space_memory, 243 ccw.cda + sizeof(info.desc) 244 + sizeof(info.res0) 245 + sizeof(info.index) 246 + sizeof(info.num), 247 MEMTXATTRS_UNSPECIFIED, NULL); 248 info.used = address_space_ldq_be(&address_space_memory, 249 ccw.cda + sizeof(info.desc) 250 + sizeof(info.res0) 251 + sizeof(info.index) 252 + sizeof(info.num) 253 + sizeof(info.avail), 254 MEMTXATTRS_UNSPECIFIED, NULL); 255 ret = virtio_ccw_set_vqs(sch, &info, NULL); 256 } 257 sch->curr_status.scsw.count = 0; 258 return ret; 259 } 260 261 static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) 262 { 263 int ret; 264 VirtioRevInfo revinfo; 265 uint8_t status; 266 VirtioFeatDesc features; 267 void *config; 268 hwaddr indicators; 269 VqConfigBlock vq_config; 270 VirtioCcwDevice *dev = sch->driver_data; 271 VirtIODevice *vdev = virtio_ccw_get_vdev(sch); 272 bool check_len; 273 int len; 274 hwaddr hw_len; 275 VirtioThinintInfo *thinint; 276 277 if (!dev) { 278 return -EINVAL; 279 } 280 281 trace_virtio_ccw_interpret_ccw(sch->cssid, sch->ssid, sch->schid, 282 ccw.cmd_code); 283 check_len = !((ccw.flags & CCW_FLAG_SLI) && !(ccw.flags & CCW_FLAG_DC)); 284 285 if (dev->force_revision_1 && dev->revision < 0 && 286 ccw.cmd_code != CCW_CMD_SET_VIRTIO_REV) { 287 /* 288 * virtio-1 drivers must start with negotiating to a revision >= 1, 289 * so post a command reject for all other commands 290 */ 291 return -ENOSYS; 292 } 293 294 /* Look at the command. */ 295 switch (ccw.cmd_code) { 296 case CCW_CMD_SET_VQ: 297 ret = virtio_ccw_handle_set_vq(sch, ccw, check_len, dev->revision < 1); 298 break; 299 case CCW_CMD_VDEV_RESET: 300 virtio_ccw_reset_virtio(dev, vdev); 301 ret = 0; 302 break; 303 case CCW_CMD_READ_FEAT: 304 if (check_len) { 305 if (ccw.count != sizeof(features)) { 306 ret = -EINVAL; 307 break; 308 } 309 } else if (ccw.count < sizeof(features)) { 310 /* Can't execute command. */ 311 ret = -EINVAL; 312 break; 313 } 314 if (!ccw.cda) { 315 ret = -EFAULT; 316 } else { 317 VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev); 318 319 features.index = address_space_ldub(&address_space_memory, 320 ccw.cda 321 + sizeof(features.features), 322 MEMTXATTRS_UNSPECIFIED, 323 NULL); 324 if (features.index == 0) { 325 if (dev->revision >= 1) { 326 /* Don't offer legacy features for modern devices. */ 327 features.features = (uint32_t) 328 (vdev->host_features & ~vdc->legacy_features); 329 } else { 330 features.features = (uint32_t)vdev->host_features; 331 } 332 } else if ((features.index == 1) && (dev->revision >= 1)) { 333 /* 334 * Only offer feature bits beyond 31 if the guest has 335 * negotiated at least revision 1. 336 */ 337 features.features = (uint32_t)(vdev->host_features >> 32); 338 } else { 339 /* Return zeroes if the guest supports more feature bits. */ 340 features.features = 0; 341 } 342 address_space_stl_le(&address_space_memory, ccw.cda, 343 features.features, MEMTXATTRS_UNSPECIFIED, 344 NULL); 345 sch->curr_status.scsw.count = ccw.count - sizeof(features); 346 ret = 0; 347 } 348 break; 349 case CCW_CMD_WRITE_FEAT: 350 if (check_len) { 351 if (ccw.count != sizeof(features)) { 352 ret = -EINVAL; 353 break; 354 } 355 } else if (ccw.count < sizeof(features)) { 356 /* Can't execute command. */ 357 ret = -EINVAL; 358 break; 359 } 360 if (!ccw.cda) { 361 ret = -EFAULT; 362 } else { 363 features.index = address_space_ldub(&address_space_memory, 364 ccw.cda 365 + sizeof(features.features), 366 MEMTXATTRS_UNSPECIFIED, 367 NULL); 368 features.features = address_space_ldl_le(&address_space_memory, 369 ccw.cda, 370 MEMTXATTRS_UNSPECIFIED, 371 NULL); 372 if (features.index == 0) { 373 virtio_set_features(vdev, 374 (vdev->guest_features & 0xffffffff00000000ULL) | 375 features.features); 376 } else if ((features.index == 1) && (dev->revision >= 1)) { 377 /* 378 * If the guest did not negotiate at least revision 1, 379 * we did not offer it any feature bits beyond 31. Such a 380 * guest passing us any bit here is therefore buggy. 381 */ 382 virtio_set_features(vdev, 383 (vdev->guest_features & 0x00000000ffffffffULL) | 384 ((uint64_t)features.features << 32)); 385 } else { 386 /* 387 * If the guest supports more feature bits, assert that it 388 * passes us zeroes for those we don't support. 389 */ 390 if (features.features) { 391 fprintf(stderr, "Guest bug: features[%i]=%x (expected 0)\n", 392 features.index, features.features); 393 /* XXX: do a unit check here? */ 394 } 395 } 396 sch->curr_status.scsw.count = ccw.count - sizeof(features); 397 ret = 0; 398 } 399 break; 400 case CCW_CMD_READ_CONF: 401 if (check_len) { 402 if (ccw.count > vdev->config_len) { 403 ret = -EINVAL; 404 break; 405 } 406 } 407 len = MIN(ccw.count, vdev->config_len); 408 if (!ccw.cda) { 409 ret = -EFAULT; 410 } else { 411 virtio_bus_get_vdev_config(&dev->bus, vdev->config); 412 /* XXX config space endianness */ 413 cpu_physical_memory_write(ccw.cda, vdev->config, len); 414 sch->curr_status.scsw.count = ccw.count - len; 415 ret = 0; 416 } 417 break; 418 case CCW_CMD_WRITE_CONF: 419 if (check_len) { 420 if (ccw.count > vdev->config_len) { 421 ret = -EINVAL; 422 break; 423 } 424 } 425 len = MIN(ccw.count, vdev->config_len); 426 hw_len = len; 427 if (!ccw.cda) { 428 ret = -EFAULT; 429 } else { 430 config = cpu_physical_memory_map(ccw.cda, &hw_len, 0); 431 if (!config) { 432 ret = -EFAULT; 433 } else { 434 len = hw_len; 435 /* XXX config space endianness */ 436 memcpy(vdev->config, config, len); 437 cpu_physical_memory_unmap(config, hw_len, 0, hw_len); 438 virtio_bus_set_vdev_config(&dev->bus, vdev->config); 439 sch->curr_status.scsw.count = ccw.count - len; 440 ret = 0; 441 } 442 } 443 break; 444 case CCW_CMD_READ_STATUS: 445 if (check_len) { 446 if (ccw.count != sizeof(status)) { 447 ret = -EINVAL; 448 break; 449 } 450 } else if (ccw.count < sizeof(status)) { 451 /* Can't execute command. */ 452 ret = -EINVAL; 453 break; 454 } 455 if (!ccw.cda) { 456 ret = -EFAULT; 457 } else { 458 address_space_stb(&address_space_memory, ccw.cda, vdev->status, 459 MEMTXATTRS_UNSPECIFIED, NULL); 460 sch->curr_status.scsw.count = ccw.count - sizeof(vdev->status);; 461 ret = 0; 462 } 463 break; 464 case CCW_CMD_WRITE_STATUS: 465 if (check_len) { 466 if (ccw.count != sizeof(status)) { 467 ret = -EINVAL; 468 break; 469 } 470 } else if (ccw.count < sizeof(status)) { 471 /* Can't execute command. */ 472 ret = -EINVAL; 473 break; 474 } 475 if (!ccw.cda) { 476 ret = -EFAULT; 477 } else { 478 status = address_space_ldub(&address_space_memory, ccw.cda, 479 MEMTXATTRS_UNSPECIFIED, NULL); 480 if (!(status & VIRTIO_CONFIG_S_DRIVER_OK)) { 481 virtio_ccw_stop_ioeventfd(dev); 482 } 483 if (virtio_set_status(vdev, status) == 0) { 484 if (vdev->status == 0) { 485 virtio_ccw_reset_virtio(dev, vdev); 486 } 487 if (status & VIRTIO_CONFIG_S_DRIVER_OK) { 488 virtio_ccw_start_ioeventfd(dev); 489 } 490 sch->curr_status.scsw.count = ccw.count - sizeof(status); 491 ret = 0; 492 } else { 493 /* Trigger a command reject. */ 494 ret = -ENOSYS; 495 } 496 } 497 break; 498 case CCW_CMD_SET_IND: 499 if (check_len) { 500 if (ccw.count != sizeof(indicators)) { 501 ret = -EINVAL; 502 break; 503 } 504 } else if (ccw.count < sizeof(indicators)) { 505 /* Can't execute command. */ 506 ret = -EINVAL; 507 break; 508 } 509 if (sch->thinint_active) { 510 /* Trigger a command reject. */ 511 ret = -ENOSYS; 512 break; 513 } 514 if (virtio_get_num_queues(vdev) > NR_CLASSIC_INDICATOR_BITS) { 515 /* More queues than indicator bits --> trigger a reject */ 516 ret = -ENOSYS; 517 break; 518 } 519 if (!ccw.cda) { 520 ret = -EFAULT; 521 } else { 522 indicators = address_space_ldq_be(&address_space_memory, ccw.cda, 523 MEMTXATTRS_UNSPECIFIED, NULL); 524 dev->indicators = get_indicator(indicators, sizeof(uint64_t)); 525 sch->curr_status.scsw.count = ccw.count - sizeof(indicators); 526 ret = 0; 527 } 528 break; 529 case CCW_CMD_SET_CONF_IND: 530 if (check_len) { 531 if (ccw.count != sizeof(indicators)) { 532 ret = -EINVAL; 533 break; 534 } 535 } else if (ccw.count < sizeof(indicators)) { 536 /* Can't execute command. */ 537 ret = -EINVAL; 538 break; 539 } 540 if (!ccw.cda) { 541 ret = -EFAULT; 542 } else { 543 indicators = address_space_ldq_be(&address_space_memory, ccw.cda, 544 MEMTXATTRS_UNSPECIFIED, NULL); 545 dev->indicators2 = get_indicator(indicators, sizeof(uint64_t)); 546 sch->curr_status.scsw.count = ccw.count - sizeof(indicators); 547 ret = 0; 548 } 549 break; 550 case CCW_CMD_READ_VQ_CONF: 551 if (check_len) { 552 if (ccw.count != sizeof(vq_config)) { 553 ret = -EINVAL; 554 break; 555 } 556 } else if (ccw.count < sizeof(vq_config)) { 557 /* Can't execute command. */ 558 ret = -EINVAL; 559 break; 560 } 561 if (!ccw.cda) { 562 ret = -EFAULT; 563 } else { 564 vq_config.index = address_space_lduw_be(&address_space_memory, 565 ccw.cda, 566 MEMTXATTRS_UNSPECIFIED, 567 NULL); 568 if (vq_config.index >= VIRTIO_QUEUE_MAX) { 569 ret = -EINVAL; 570 break; 571 } 572 vq_config.num_max = virtio_queue_get_num(vdev, 573 vq_config.index); 574 address_space_stw_be(&address_space_memory, 575 ccw.cda + sizeof(vq_config.index), 576 vq_config.num_max, 577 MEMTXATTRS_UNSPECIFIED, 578 NULL); 579 sch->curr_status.scsw.count = ccw.count - sizeof(vq_config); 580 ret = 0; 581 } 582 break; 583 case CCW_CMD_SET_IND_ADAPTER: 584 if (check_len) { 585 if (ccw.count != sizeof(*thinint)) { 586 ret = -EINVAL; 587 break; 588 } 589 } else if (ccw.count < sizeof(*thinint)) { 590 /* Can't execute command. */ 591 ret = -EINVAL; 592 break; 593 } 594 len = sizeof(*thinint); 595 hw_len = len; 596 if (!ccw.cda) { 597 ret = -EFAULT; 598 } else if (dev->indicators && !sch->thinint_active) { 599 /* Trigger a command reject. */ 600 ret = -ENOSYS; 601 } else { 602 thinint = cpu_physical_memory_map(ccw.cda, &hw_len, 0); 603 if (!thinint) { 604 ret = -EFAULT; 605 } else { 606 uint64_t ind_bit = ldq_be_p(&thinint->ind_bit); 607 608 len = hw_len; 609 dev->summary_indicator = 610 get_indicator(ldq_be_p(&thinint->summary_indicator), 611 sizeof(uint8_t)); 612 dev->indicators = 613 get_indicator(ldq_be_p(&thinint->device_indicator), 614 ind_bit / 8 + 1); 615 dev->thinint_isc = thinint->isc; 616 dev->routes.adapter.ind_offset = ind_bit; 617 dev->routes.adapter.summary_offset = 7; 618 cpu_physical_memory_unmap(thinint, hw_len, 0, hw_len); 619 ret = css_register_io_adapter(CSS_IO_ADAPTER_VIRTIO, 620 dev->thinint_isc, true, false, 621 &dev->routes.adapter.adapter_id); 622 assert(ret == 0); 623 sch->thinint_active = ((dev->indicators != NULL) && 624 (dev->summary_indicator != NULL)); 625 sch->curr_status.scsw.count = ccw.count - len; 626 ret = 0; 627 } 628 } 629 break; 630 case CCW_CMD_SET_VIRTIO_REV: 631 len = sizeof(revinfo); 632 if (ccw.count < len) { 633 ret = -EINVAL; 634 break; 635 } 636 if (!ccw.cda) { 637 ret = -EFAULT; 638 break; 639 } 640 revinfo.revision = 641 address_space_lduw_be(&address_space_memory, ccw.cda, 642 MEMTXATTRS_UNSPECIFIED, NULL); 643 revinfo.length = 644 address_space_lduw_be(&address_space_memory, 645 ccw.cda + sizeof(revinfo.revision), 646 MEMTXATTRS_UNSPECIFIED, NULL); 647 if (ccw.count < len + revinfo.length || 648 (check_len && ccw.count > len + revinfo.length)) { 649 ret = -EINVAL; 650 break; 651 } 652 /* 653 * Once we start to support revisions with additional data, we'll 654 * need to fetch it here. Nothing to do for now, though. 655 */ 656 if (dev->revision >= 0 || 657 revinfo.revision > virtio_ccw_rev_max(dev) || 658 (dev->force_revision_1 && !revinfo.revision)) { 659 ret = -ENOSYS; 660 break; 661 } 662 ret = 0; 663 dev->revision = revinfo.revision; 664 break; 665 default: 666 ret = -ENOSYS; 667 break; 668 } 669 return ret; 670 } 671 672 static void virtio_sch_disable_cb(SubchDev *sch) 673 { 674 VirtioCcwDevice *dev = sch->driver_data; 675 676 dev->revision = -1; 677 } 678 679 static void virtio_ccw_device_realize(VirtioCcwDevice *dev, Error **errp) 680 { 681 VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_GET_CLASS(dev); 682 CcwDevice *ccw_dev = CCW_DEVICE(dev); 683 SubchDev *sch = css_create_virtual_sch(ccw_dev->bus_id, errp); 684 Error *err = NULL; 685 686 if (!sch) { 687 return; 688 } 689 if (!virtio_ccw_rev_max(dev) && dev->force_revision_1) { 690 error_setg(&err, "Invalid value of property max_rev " 691 "(is %d expected >= 1)", virtio_ccw_rev_max(dev)); 692 error_propagate(errp, err); 693 return; 694 } 695 696 sch->driver_data = dev; 697 sch->ccw_cb = virtio_ccw_cb; 698 sch->disable_cb = virtio_sch_disable_cb; 699 sch->id.reserved = 0xff; 700 sch->id.cu_type = VIRTIO_CCW_CU_TYPE; 701 ccw_dev->sch = sch; 702 dev->indicators = NULL; 703 dev->revision = -1; 704 css_sch_build_virtual_schib(sch, 0, VIRTIO_CCW_CHPID_TYPE); 705 706 trace_virtio_ccw_new_device( 707 sch->cssid, sch->ssid, sch->schid, sch->devno, 708 ccw_dev->bus_id.valid ? "user-configured" : "auto-configured"); 709 710 if (!kvm_eventfds_enabled()) { 711 dev->flags &= ~VIRTIO_CCW_FLAG_USE_IOEVENTFD; 712 } 713 714 if (k->realize) { 715 k->realize(dev, &err); 716 } 717 if (err) { 718 error_propagate(errp, err); 719 css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, NULL); 720 ccw_dev->sch = NULL; 721 g_free(sch); 722 } 723 } 724 725 static int virtio_ccw_exit(VirtioCcwDevice *dev) 726 { 727 CcwDevice *ccw_dev = CCW_DEVICE(dev); 728 SubchDev *sch = ccw_dev->sch; 729 730 if (sch) { 731 css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, NULL); 732 g_free(sch); 733 } 734 if (dev->indicators) { 735 release_indicator(&dev->routes.adapter, dev->indicators); 736 dev->indicators = NULL; 737 } 738 return 0; 739 } 740 741 static void virtio_ccw_net_realize(VirtioCcwDevice *ccw_dev, Error **errp) 742 { 743 DeviceState *qdev = DEVICE(ccw_dev); 744 VirtIONetCcw *dev = VIRTIO_NET_CCW(ccw_dev); 745 DeviceState *vdev = DEVICE(&dev->vdev); 746 747 virtio_net_set_netclient_name(&dev->vdev, qdev->id, 748 object_get_typename(OBJECT(qdev))); 749 qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus)); 750 object_property_set_bool(OBJECT(vdev), true, "realized", errp); 751 } 752 753 static void virtio_ccw_net_instance_init(Object *obj) 754 { 755 VirtIONetCcw *dev = VIRTIO_NET_CCW(obj); 756 757 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), 758 TYPE_VIRTIO_NET); 759 object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev), 760 "bootindex", &error_abort); 761 } 762 763 static void virtio_ccw_blk_realize(VirtioCcwDevice *ccw_dev, Error **errp) 764 { 765 VirtIOBlkCcw *dev = VIRTIO_BLK_CCW(ccw_dev); 766 DeviceState *vdev = DEVICE(&dev->vdev); 767 768 qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus)); 769 object_property_set_bool(OBJECT(vdev), true, "realized", errp); 770 } 771 772 static void virtio_ccw_blk_instance_init(Object *obj) 773 { 774 VirtIOBlkCcw *dev = VIRTIO_BLK_CCW(obj); 775 776 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), 777 TYPE_VIRTIO_BLK); 778 object_property_add_alias(obj, "iothread", OBJECT(&dev->vdev),"iothread", 779 &error_abort); 780 object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev), 781 "bootindex", &error_abort); 782 } 783 784 static void virtio_ccw_serial_realize(VirtioCcwDevice *ccw_dev, Error **errp) 785 { 786 VirtioSerialCcw *dev = VIRTIO_SERIAL_CCW(ccw_dev); 787 DeviceState *vdev = DEVICE(&dev->vdev); 788 DeviceState *proxy = DEVICE(ccw_dev); 789 char *bus_name; 790 791 /* 792 * For command line compatibility, this sets the virtio-serial-device bus 793 * name as before. 794 */ 795 if (proxy->id) { 796 bus_name = g_strdup_printf("%s.0", proxy->id); 797 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name); 798 g_free(bus_name); 799 } 800 801 qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus)); 802 object_property_set_bool(OBJECT(vdev), true, "realized", errp); 803 } 804 805 806 static void virtio_ccw_serial_instance_init(Object *obj) 807 { 808 VirtioSerialCcw *dev = VIRTIO_SERIAL_CCW(obj); 809 810 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), 811 TYPE_VIRTIO_SERIAL); 812 } 813 814 static void virtio_ccw_balloon_realize(VirtioCcwDevice *ccw_dev, Error **errp) 815 { 816 VirtIOBalloonCcw *dev = VIRTIO_BALLOON_CCW(ccw_dev); 817 DeviceState *vdev = DEVICE(&dev->vdev); 818 819 qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus)); 820 object_property_set_bool(OBJECT(vdev), true, "realized", errp); 821 } 822 823 static void virtio_ccw_balloon_instance_init(Object *obj) 824 { 825 VirtIOBalloonCcw *dev = VIRTIO_BALLOON_CCW(obj); 826 827 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), 828 TYPE_VIRTIO_BALLOON); 829 object_property_add_alias(obj, "guest-stats", OBJECT(&dev->vdev), 830 "guest-stats", &error_abort); 831 object_property_add_alias(obj, "guest-stats-polling-interval", 832 OBJECT(&dev->vdev), 833 "guest-stats-polling-interval", &error_abort); 834 } 835 836 static void virtio_ccw_scsi_realize(VirtioCcwDevice *ccw_dev, Error **errp) 837 { 838 VirtIOSCSICcw *dev = VIRTIO_SCSI_CCW(ccw_dev); 839 DeviceState *vdev = DEVICE(&dev->vdev); 840 DeviceState *qdev = DEVICE(ccw_dev); 841 char *bus_name; 842 843 /* 844 * For command line compatibility, this sets the virtio-scsi-device bus 845 * name as before. 846 */ 847 if (qdev->id) { 848 bus_name = g_strdup_printf("%s.0", qdev->id); 849 virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name); 850 g_free(bus_name); 851 } 852 853 qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus)); 854 object_property_set_bool(OBJECT(vdev), true, "realized", errp); 855 } 856 857 static void virtio_ccw_scsi_instance_init(Object *obj) 858 { 859 VirtIOSCSICcw *dev = VIRTIO_SCSI_CCW(obj); 860 861 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), 862 TYPE_VIRTIO_SCSI); 863 object_property_add_alias(obj, "iothread", OBJECT(&dev->vdev), "iothread", 864 &error_abort); 865 } 866 867 #ifdef CONFIG_VHOST_SCSI 868 static void vhost_ccw_scsi_realize(VirtioCcwDevice *ccw_dev, Error **errp) 869 { 870 VHostSCSICcw *dev = VHOST_SCSI_CCW(ccw_dev); 871 DeviceState *vdev = DEVICE(&dev->vdev); 872 873 qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus)); 874 object_property_set_bool(OBJECT(vdev), true, "realized", errp); 875 } 876 877 static void vhost_ccw_scsi_instance_init(Object *obj) 878 { 879 VHostSCSICcw *dev = VHOST_SCSI_CCW(obj); 880 881 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), 882 TYPE_VHOST_SCSI); 883 } 884 #endif 885 886 static void virtio_ccw_rng_realize(VirtioCcwDevice *ccw_dev, Error **errp) 887 { 888 VirtIORNGCcw *dev = VIRTIO_RNG_CCW(ccw_dev); 889 DeviceState *vdev = DEVICE(&dev->vdev); 890 Error *err = NULL; 891 892 qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus)); 893 object_property_set_bool(OBJECT(vdev), true, "realized", &err); 894 if (err) { 895 error_propagate(errp, err); 896 return; 897 } 898 899 object_property_set_link(OBJECT(dev), 900 OBJECT(dev->vdev.conf.rng), "rng", 901 NULL); 902 } 903 904 static void virtio_ccw_crypto_realize(VirtioCcwDevice *ccw_dev, Error **errp) 905 { 906 VirtIOCryptoCcw *dev = VIRTIO_CRYPTO_CCW(ccw_dev); 907 DeviceState *vdev = DEVICE(&dev->vdev); 908 Error *err = NULL; 909 910 qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus)); 911 object_property_set_bool(OBJECT(vdev), true, "realized", &err); 912 if (err) { 913 error_propagate(errp, err); 914 return; 915 } 916 917 object_property_set_link(OBJECT(vdev), 918 OBJECT(dev->vdev.conf.cryptodev), "cryptodev", 919 NULL); 920 } 921 922 /* DeviceState to VirtioCcwDevice. Note: used on datapath, 923 * be careful and test performance if you change this. 924 */ 925 static inline VirtioCcwDevice *to_virtio_ccw_dev_fast(DeviceState *d) 926 { 927 CcwDevice *ccw_dev = to_ccw_dev_fast(d); 928 929 return container_of(ccw_dev, VirtioCcwDevice, parent_obj); 930 } 931 932 static uint8_t virtio_set_ind_atomic(SubchDev *sch, uint64_t ind_loc, 933 uint8_t to_be_set) 934 { 935 uint8_t ind_old, ind_new; 936 hwaddr len = 1; 937 uint8_t *ind_addr; 938 939 ind_addr = cpu_physical_memory_map(ind_loc, &len, 1); 940 if (!ind_addr) { 941 error_report("%s(%x.%x.%04x): unable to access indicator", 942 __func__, sch->cssid, sch->ssid, sch->schid); 943 return -1; 944 } 945 do { 946 ind_old = *ind_addr; 947 ind_new = ind_old | to_be_set; 948 } while (atomic_cmpxchg(ind_addr, ind_old, ind_new) != ind_old); 949 trace_virtio_ccw_set_ind(ind_loc, ind_old, ind_new); 950 cpu_physical_memory_unmap(ind_addr, len, 1, len); 951 952 return ind_old; 953 } 954 955 static void virtio_ccw_notify(DeviceState *d, uint16_t vector) 956 { 957 VirtioCcwDevice *dev = to_virtio_ccw_dev_fast(d); 958 CcwDevice *ccw_dev = to_ccw_dev_fast(d); 959 SubchDev *sch = ccw_dev->sch; 960 uint64_t indicators; 961 962 /* queue indicators + secondary indicators */ 963 if (vector >= VIRTIO_QUEUE_MAX + 64) { 964 return; 965 } 966 967 if (vector < VIRTIO_QUEUE_MAX) { 968 if (!dev->indicators) { 969 return; 970 } 971 if (sch->thinint_active) { 972 /* 973 * In the adapter interrupt case, indicators points to a 974 * memory area that may be (way) larger than 64 bit and 975 * ind_bit indicates the start of the indicators in a big 976 * endian notation. 977 */ 978 uint64_t ind_bit = dev->routes.adapter.ind_offset; 979 980 virtio_set_ind_atomic(sch, dev->indicators->addr + 981 (ind_bit + vector) / 8, 982 0x80 >> ((ind_bit + vector) % 8)); 983 if (!virtio_set_ind_atomic(sch, dev->summary_indicator->addr, 984 0x01)) { 985 css_adapter_interrupt(dev->thinint_isc); 986 } 987 } else { 988 indicators = address_space_ldq(&address_space_memory, 989 dev->indicators->addr, 990 MEMTXATTRS_UNSPECIFIED, 991 NULL); 992 indicators |= 1ULL << vector; 993 address_space_stq(&address_space_memory, dev->indicators->addr, 994 indicators, MEMTXATTRS_UNSPECIFIED, NULL); 995 css_conditional_io_interrupt(sch); 996 } 997 } else { 998 if (!dev->indicators2) { 999 return; 1000 } 1001 vector = 0; 1002 indicators = address_space_ldq(&address_space_memory, 1003 dev->indicators2->addr, 1004 MEMTXATTRS_UNSPECIFIED, 1005 NULL); 1006 indicators |= 1ULL << vector; 1007 address_space_stq(&address_space_memory, dev->indicators2->addr, 1008 indicators, MEMTXATTRS_UNSPECIFIED, NULL); 1009 css_conditional_io_interrupt(sch); 1010 } 1011 } 1012 1013 static void virtio_ccw_reset(DeviceState *d) 1014 { 1015 VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d); 1016 VirtIODevice *vdev = virtio_bus_get_device(&dev->bus); 1017 CcwDevice *ccw_dev = CCW_DEVICE(d); 1018 1019 virtio_ccw_reset_virtio(dev, vdev); 1020 css_reset_sch(ccw_dev->sch); 1021 } 1022 1023 static void virtio_ccw_vmstate_change(DeviceState *d, bool running) 1024 { 1025 VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d); 1026 1027 if (running) { 1028 virtio_ccw_start_ioeventfd(dev); 1029 } else { 1030 virtio_ccw_stop_ioeventfd(dev); 1031 } 1032 } 1033 1034 static bool virtio_ccw_query_guest_notifiers(DeviceState *d) 1035 { 1036 CcwDevice *dev = CCW_DEVICE(d); 1037 1038 return !!(dev->sch->curr_status.pmcw.flags & PMCW_FLAGS_MASK_ENA); 1039 } 1040 1041 static int virtio_ccw_get_mappings(VirtioCcwDevice *dev) 1042 { 1043 int r; 1044 CcwDevice *ccw_dev = CCW_DEVICE(dev); 1045 1046 if (!ccw_dev->sch->thinint_active) { 1047 return -EINVAL; 1048 } 1049 1050 r = map_indicator(&dev->routes.adapter, dev->summary_indicator); 1051 if (r) { 1052 return r; 1053 } 1054 r = map_indicator(&dev->routes.adapter, dev->indicators); 1055 if (r) { 1056 return r; 1057 } 1058 dev->routes.adapter.summary_addr = dev->summary_indicator->map; 1059 dev->routes.adapter.ind_addr = dev->indicators->map; 1060 1061 return 0; 1062 } 1063 1064 static int virtio_ccw_setup_irqroutes(VirtioCcwDevice *dev, int nvqs) 1065 { 1066 int i; 1067 VirtIODevice *vdev = virtio_bus_get_device(&dev->bus); 1068 int ret; 1069 S390FLICState *fs = s390_get_flic(); 1070 S390FLICStateClass *fsc = S390_FLIC_COMMON_GET_CLASS(fs); 1071 1072 ret = virtio_ccw_get_mappings(dev); 1073 if (ret) { 1074 return ret; 1075 } 1076 for (i = 0; i < nvqs; i++) { 1077 if (!virtio_queue_get_num(vdev, i)) { 1078 break; 1079 } 1080 } 1081 dev->routes.num_routes = i; 1082 return fsc->add_adapter_routes(fs, &dev->routes); 1083 } 1084 1085 static void virtio_ccw_release_irqroutes(VirtioCcwDevice *dev, int nvqs) 1086 { 1087 S390FLICState *fs = s390_get_flic(); 1088 S390FLICStateClass *fsc = S390_FLIC_COMMON_GET_CLASS(fs); 1089 1090 fsc->release_adapter_routes(fs, &dev->routes); 1091 } 1092 1093 static int virtio_ccw_add_irqfd(VirtioCcwDevice *dev, int n) 1094 { 1095 VirtIODevice *vdev = virtio_bus_get_device(&dev->bus); 1096 VirtQueue *vq = virtio_get_queue(vdev, n); 1097 EventNotifier *notifier = virtio_queue_get_guest_notifier(vq); 1098 1099 return kvm_irqchip_add_irqfd_notifier_gsi(kvm_state, notifier, NULL, 1100 dev->routes.gsi[n]); 1101 } 1102 1103 static void virtio_ccw_remove_irqfd(VirtioCcwDevice *dev, int n) 1104 { 1105 VirtIODevice *vdev = virtio_bus_get_device(&dev->bus); 1106 VirtQueue *vq = virtio_get_queue(vdev, n); 1107 EventNotifier *notifier = virtio_queue_get_guest_notifier(vq); 1108 int ret; 1109 1110 ret = kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state, notifier, 1111 dev->routes.gsi[n]); 1112 assert(ret == 0); 1113 } 1114 1115 static int virtio_ccw_set_guest_notifier(VirtioCcwDevice *dev, int n, 1116 bool assign, bool with_irqfd) 1117 { 1118 VirtIODevice *vdev = virtio_bus_get_device(&dev->bus); 1119 VirtQueue *vq = virtio_get_queue(vdev, n); 1120 EventNotifier *notifier = virtio_queue_get_guest_notifier(vq); 1121 VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); 1122 1123 if (assign) { 1124 int r = event_notifier_init(notifier, 0); 1125 1126 if (r < 0) { 1127 return r; 1128 } 1129 virtio_queue_set_guest_notifier_fd_handler(vq, true, with_irqfd); 1130 if (with_irqfd) { 1131 r = virtio_ccw_add_irqfd(dev, n); 1132 if (r) { 1133 virtio_queue_set_guest_notifier_fd_handler(vq, false, 1134 with_irqfd); 1135 return r; 1136 } 1137 } 1138 /* 1139 * We do not support individual masking for channel devices, so we 1140 * need to manually trigger any guest masking callbacks here. 1141 */ 1142 if (k->guest_notifier_mask && vdev->use_guest_notifier_mask) { 1143 k->guest_notifier_mask(vdev, n, false); 1144 } 1145 /* get lost events and re-inject */ 1146 if (k->guest_notifier_pending && 1147 k->guest_notifier_pending(vdev, n)) { 1148 event_notifier_set(notifier); 1149 } 1150 } else { 1151 if (k->guest_notifier_mask && vdev->use_guest_notifier_mask) { 1152 k->guest_notifier_mask(vdev, n, true); 1153 } 1154 if (with_irqfd) { 1155 virtio_ccw_remove_irqfd(dev, n); 1156 } 1157 virtio_queue_set_guest_notifier_fd_handler(vq, false, with_irqfd); 1158 event_notifier_cleanup(notifier); 1159 } 1160 return 0; 1161 } 1162 1163 static int virtio_ccw_set_guest_notifiers(DeviceState *d, int nvqs, 1164 bool assigned) 1165 { 1166 VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d); 1167 VirtIODevice *vdev = virtio_bus_get_device(&dev->bus); 1168 CcwDevice *ccw_dev = CCW_DEVICE(d); 1169 bool with_irqfd = ccw_dev->sch->thinint_active && kvm_irqfds_enabled(); 1170 int r, n; 1171 1172 if (with_irqfd && assigned) { 1173 /* irq routes need to be set up before assigning irqfds */ 1174 r = virtio_ccw_setup_irqroutes(dev, nvqs); 1175 if (r < 0) { 1176 goto irqroute_error; 1177 } 1178 } 1179 for (n = 0; n < nvqs; n++) { 1180 if (!virtio_queue_get_num(vdev, n)) { 1181 break; 1182 } 1183 r = virtio_ccw_set_guest_notifier(dev, n, assigned, with_irqfd); 1184 if (r < 0) { 1185 goto assign_error; 1186 } 1187 } 1188 if (with_irqfd && !assigned) { 1189 /* release irq routes after irqfds have been released */ 1190 virtio_ccw_release_irqroutes(dev, nvqs); 1191 } 1192 return 0; 1193 1194 assign_error: 1195 while (--n >= 0) { 1196 virtio_ccw_set_guest_notifier(dev, n, !assigned, false); 1197 } 1198 irqroute_error: 1199 if (with_irqfd && assigned) { 1200 virtio_ccw_release_irqroutes(dev, nvqs); 1201 } 1202 return r; 1203 } 1204 1205 static void virtio_ccw_save_queue(DeviceState *d, int n, QEMUFile *f) 1206 { 1207 VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d); 1208 VirtIODevice *vdev = virtio_bus_get_device(&dev->bus); 1209 1210 qemu_put_be16(f, virtio_queue_vector(vdev, n)); 1211 } 1212 1213 static int virtio_ccw_load_queue(DeviceState *d, int n, QEMUFile *f) 1214 { 1215 VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d); 1216 VirtIODevice *vdev = virtio_bus_get_device(&dev->bus); 1217 uint16_t vector; 1218 1219 qemu_get_be16s(f, &vector); 1220 virtio_queue_set_vector(vdev, n , vector); 1221 1222 return 0; 1223 } 1224 1225 static void virtio_ccw_save_config(DeviceState *d, QEMUFile *f) 1226 { 1227 VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d); 1228 CcwDevice *ccw_dev = CCW_DEVICE(d); 1229 SubchDev *s = ccw_dev->sch; 1230 VirtIODevice *vdev = virtio_ccw_get_vdev(s); 1231 1232 subch_device_save(s, f); 1233 if (dev->indicators != NULL) { 1234 qemu_put_be32(f, dev->indicators->len); 1235 qemu_put_be64(f, dev->indicators->addr); 1236 } else { 1237 qemu_put_be32(f, 0); 1238 qemu_put_be64(f, 0UL); 1239 } 1240 if (dev->indicators2 != NULL) { 1241 qemu_put_be32(f, dev->indicators2->len); 1242 qemu_put_be64(f, dev->indicators2->addr); 1243 } else { 1244 qemu_put_be32(f, 0); 1245 qemu_put_be64(f, 0UL); 1246 } 1247 if (dev->summary_indicator != NULL) { 1248 qemu_put_be32(f, dev->summary_indicator->len); 1249 qemu_put_be64(f, dev->summary_indicator->addr); 1250 } else { 1251 qemu_put_be32(f, 0); 1252 qemu_put_be64(f, 0UL); 1253 } 1254 qemu_put_be16(f, vdev->config_vector); 1255 qemu_put_be64(f, dev->routes.adapter.ind_offset); 1256 qemu_put_byte(f, dev->thinint_isc); 1257 qemu_put_be32(f, dev->revision); 1258 } 1259 1260 static int virtio_ccw_load_config(DeviceState *d, QEMUFile *f) 1261 { 1262 VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d); 1263 CcwDevice *ccw_dev = CCW_DEVICE(d); 1264 SubchDev *s = ccw_dev->sch; 1265 VirtIODevice *vdev = virtio_ccw_get_vdev(s); 1266 int len; 1267 1268 s->driver_data = dev; 1269 subch_device_load(s, f); 1270 len = qemu_get_be32(f); 1271 if (len != 0) { 1272 dev->indicators = get_indicator(qemu_get_be64(f), len); 1273 } else { 1274 qemu_get_be64(f); 1275 dev->indicators = NULL; 1276 } 1277 len = qemu_get_be32(f); 1278 if (len != 0) { 1279 dev->indicators2 = get_indicator(qemu_get_be64(f), len); 1280 } else { 1281 qemu_get_be64(f); 1282 dev->indicators2 = NULL; 1283 } 1284 len = qemu_get_be32(f); 1285 if (len != 0) { 1286 dev->summary_indicator = get_indicator(qemu_get_be64(f), len); 1287 } else { 1288 qemu_get_be64(f); 1289 dev->summary_indicator = NULL; 1290 } 1291 qemu_get_be16s(f, &vdev->config_vector); 1292 dev->routes.adapter.ind_offset = qemu_get_be64(f); 1293 dev->thinint_isc = qemu_get_byte(f); 1294 dev->revision = qemu_get_be32(f); 1295 if (s->thinint_active) { 1296 return css_register_io_adapter(CSS_IO_ADAPTER_VIRTIO, 1297 dev->thinint_isc, true, false, 1298 &dev->routes.adapter.adapter_id); 1299 } 1300 1301 return 0; 1302 } 1303 1304 static void virtio_ccw_pre_plugged(DeviceState *d, Error **errp) 1305 { 1306 VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d); 1307 VirtIODevice *vdev = virtio_bus_get_device(&dev->bus); 1308 1309 if (dev->max_rev >= 1) { 1310 virtio_add_feature(&vdev->host_features, VIRTIO_F_VERSION_1); 1311 } 1312 } 1313 1314 /* This is called by virtio-bus just after the device is plugged. */ 1315 static void virtio_ccw_device_plugged(DeviceState *d, Error **errp) 1316 { 1317 VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d); 1318 VirtIODevice *vdev = virtio_bus_get_device(&dev->bus); 1319 CcwDevice *ccw_dev = CCW_DEVICE(d); 1320 SubchDev *sch = ccw_dev->sch; 1321 int n = virtio_get_num_queues(vdev); 1322 S390FLICState *flic = s390_get_flic(); 1323 1324 if (!virtio_has_feature(vdev->host_features, VIRTIO_F_VERSION_1)) { 1325 dev->max_rev = 0; 1326 } 1327 1328 if (virtio_get_num_queues(vdev) > VIRTIO_QUEUE_MAX) { 1329 error_setg(errp, "The number of virtqueues %d " 1330 "exceeds virtio limit %d", n, 1331 VIRTIO_QUEUE_MAX); 1332 return; 1333 } 1334 if (virtio_get_num_queues(vdev) > flic->adapter_routes_max_batch) { 1335 error_setg(errp, "The number of virtqueues %d " 1336 "exceeds flic adapter route limit %d", n, 1337 flic->adapter_routes_max_batch); 1338 return; 1339 } 1340 1341 sch->id.cu_model = virtio_bus_get_vdev_id(&dev->bus); 1342 1343 1344 css_generate_sch_crws(sch->cssid, sch->ssid, sch->schid, 1345 d->hotplugged, 1); 1346 } 1347 1348 static void virtio_ccw_device_unplugged(DeviceState *d) 1349 { 1350 VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d); 1351 1352 virtio_ccw_stop_ioeventfd(dev); 1353 } 1354 /**************** Virtio-ccw Bus Device Descriptions *******************/ 1355 1356 static Property virtio_ccw_net_properties[] = { 1357 DEFINE_PROP_CSS_DEV_ID("devno", VirtioCcwDevice, parent_obj.bus_id), 1358 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags, 1359 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true), 1360 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev, 1361 VIRTIO_CCW_MAX_REV), 1362 DEFINE_PROP_END_OF_LIST(), 1363 }; 1364 1365 static void virtio_ccw_net_class_init(ObjectClass *klass, void *data) 1366 { 1367 DeviceClass *dc = DEVICE_CLASS(klass); 1368 VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass); 1369 1370 k->realize = virtio_ccw_net_realize; 1371 k->exit = virtio_ccw_exit; 1372 dc->reset = virtio_ccw_reset; 1373 dc->props = virtio_ccw_net_properties; 1374 set_bit(DEVICE_CATEGORY_NETWORK, dc->categories); 1375 } 1376 1377 static const TypeInfo virtio_ccw_net = { 1378 .name = TYPE_VIRTIO_NET_CCW, 1379 .parent = TYPE_VIRTIO_CCW_DEVICE, 1380 .instance_size = sizeof(VirtIONetCcw), 1381 .instance_init = virtio_ccw_net_instance_init, 1382 .class_init = virtio_ccw_net_class_init, 1383 }; 1384 1385 static Property virtio_ccw_blk_properties[] = { 1386 DEFINE_PROP_CSS_DEV_ID("devno", VirtioCcwDevice, parent_obj.bus_id), 1387 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags, 1388 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true), 1389 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev, 1390 VIRTIO_CCW_MAX_REV), 1391 DEFINE_PROP_END_OF_LIST(), 1392 }; 1393 1394 static void virtio_ccw_blk_class_init(ObjectClass *klass, void *data) 1395 { 1396 DeviceClass *dc = DEVICE_CLASS(klass); 1397 VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass); 1398 1399 k->realize = virtio_ccw_blk_realize; 1400 k->exit = virtio_ccw_exit; 1401 dc->reset = virtio_ccw_reset; 1402 dc->props = virtio_ccw_blk_properties; 1403 set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); 1404 } 1405 1406 static const TypeInfo virtio_ccw_blk = { 1407 .name = TYPE_VIRTIO_BLK_CCW, 1408 .parent = TYPE_VIRTIO_CCW_DEVICE, 1409 .instance_size = sizeof(VirtIOBlkCcw), 1410 .instance_init = virtio_ccw_blk_instance_init, 1411 .class_init = virtio_ccw_blk_class_init, 1412 }; 1413 1414 static Property virtio_ccw_serial_properties[] = { 1415 DEFINE_PROP_CSS_DEV_ID("devno", VirtioCcwDevice, parent_obj.bus_id), 1416 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags, 1417 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true), 1418 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev, 1419 VIRTIO_CCW_MAX_REV), 1420 DEFINE_PROP_END_OF_LIST(), 1421 }; 1422 1423 static void virtio_ccw_serial_class_init(ObjectClass *klass, void *data) 1424 { 1425 DeviceClass *dc = DEVICE_CLASS(klass); 1426 VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass); 1427 1428 k->realize = virtio_ccw_serial_realize; 1429 k->exit = virtio_ccw_exit; 1430 dc->reset = virtio_ccw_reset; 1431 dc->props = virtio_ccw_serial_properties; 1432 set_bit(DEVICE_CATEGORY_INPUT, dc->categories); 1433 } 1434 1435 static const TypeInfo virtio_ccw_serial = { 1436 .name = TYPE_VIRTIO_SERIAL_CCW, 1437 .parent = TYPE_VIRTIO_CCW_DEVICE, 1438 .instance_size = sizeof(VirtioSerialCcw), 1439 .instance_init = virtio_ccw_serial_instance_init, 1440 .class_init = virtio_ccw_serial_class_init, 1441 }; 1442 1443 static Property virtio_ccw_balloon_properties[] = { 1444 DEFINE_PROP_CSS_DEV_ID("devno", VirtioCcwDevice, parent_obj.bus_id), 1445 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags, 1446 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true), 1447 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev, 1448 VIRTIO_CCW_MAX_REV), 1449 DEFINE_PROP_END_OF_LIST(), 1450 }; 1451 1452 static void virtio_ccw_balloon_class_init(ObjectClass *klass, void *data) 1453 { 1454 DeviceClass *dc = DEVICE_CLASS(klass); 1455 VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass); 1456 1457 k->realize = virtio_ccw_balloon_realize; 1458 k->exit = virtio_ccw_exit; 1459 dc->reset = virtio_ccw_reset; 1460 dc->props = virtio_ccw_balloon_properties; 1461 set_bit(DEVICE_CATEGORY_MISC, dc->categories); 1462 } 1463 1464 static const TypeInfo virtio_ccw_balloon = { 1465 .name = TYPE_VIRTIO_BALLOON_CCW, 1466 .parent = TYPE_VIRTIO_CCW_DEVICE, 1467 .instance_size = sizeof(VirtIOBalloonCcw), 1468 .instance_init = virtio_ccw_balloon_instance_init, 1469 .class_init = virtio_ccw_balloon_class_init, 1470 }; 1471 1472 static Property virtio_ccw_scsi_properties[] = { 1473 DEFINE_PROP_CSS_DEV_ID("devno", VirtioCcwDevice, parent_obj.bus_id), 1474 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags, 1475 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true), 1476 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev, 1477 VIRTIO_CCW_MAX_REV), 1478 DEFINE_PROP_END_OF_LIST(), 1479 }; 1480 1481 static void virtio_ccw_scsi_class_init(ObjectClass *klass, void *data) 1482 { 1483 DeviceClass *dc = DEVICE_CLASS(klass); 1484 VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass); 1485 1486 k->realize = virtio_ccw_scsi_realize; 1487 k->exit = virtio_ccw_exit; 1488 dc->reset = virtio_ccw_reset; 1489 dc->props = virtio_ccw_scsi_properties; 1490 set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); 1491 } 1492 1493 static const TypeInfo virtio_ccw_scsi = { 1494 .name = TYPE_VIRTIO_SCSI_CCW, 1495 .parent = TYPE_VIRTIO_CCW_DEVICE, 1496 .instance_size = sizeof(VirtIOSCSICcw), 1497 .instance_init = virtio_ccw_scsi_instance_init, 1498 .class_init = virtio_ccw_scsi_class_init, 1499 }; 1500 1501 #ifdef CONFIG_VHOST_SCSI 1502 static Property vhost_ccw_scsi_properties[] = { 1503 DEFINE_PROP_CSS_DEV_ID("devno", VirtioCcwDevice, parent_obj.bus_id), 1504 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev, 1505 VIRTIO_CCW_MAX_REV), 1506 DEFINE_PROP_END_OF_LIST(), 1507 }; 1508 1509 static void vhost_ccw_scsi_class_init(ObjectClass *klass, void *data) 1510 { 1511 DeviceClass *dc = DEVICE_CLASS(klass); 1512 VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass); 1513 1514 k->realize = vhost_ccw_scsi_realize; 1515 k->exit = virtio_ccw_exit; 1516 dc->reset = virtio_ccw_reset; 1517 dc->props = vhost_ccw_scsi_properties; 1518 set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); 1519 } 1520 1521 static const TypeInfo vhost_ccw_scsi = { 1522 .name = TYPE_VHOST_SCSI_CCW, 1523 .parent = TYPE_VIRTIO_CCW_DEVICE, 1524 .instance_size = sizeof(VHostSCSICcw), 1525 .instance_init = vhost_ccw_scsi_instance_init, 1526 .class_init = vhost_ccw_scsi_class_init, 1527 }; 1528 #endif 1529 1530 static void virtio_ccw_rng_instance_init(Object *obj) 1531 { 1532 VirtIORNGCcw *dev = VIRTIO_RNG_CCW(obj); 1533 1534 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), 1535 TYPE_VIRTIO_RNG); 1536 object_property_add_alias(obj, "rng", OBJECT(&dev->vdev), 1537 "rng", &error_abort); 1538 } 1539 1540 static Property virtio_ccw_rng_properties[] = { 1541 DEFINE_PROP_CSS_DEV_ID("devno", VirtioCcwDevice, parent_obj.bus_id), 1542 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags, 1543 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true), 1544 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev, 1545 VIRTIO_CCW_MAX_REV), 1546 DEFINE_PROP_END_OF_LIST(), 1547 }; 1548 1549 static void virtio_ccw_rng_class_init(ObjectClass *klass, void *data) 1550 { 1551 DeviceClass *dc = DEVICE_CLASS(klass); 1552 VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass); 1553 1554 k->realize = virtio_ccw_rng_realize; 1555 k->exit = virtio_ccw_exit; 1556 dc->reset = virtio_ccw_reset; 1557 dc->props = virtio_ccw_rng_properties; 1558 set_bit(DEVICE_CATEGORY_MISC, dc->categories); 1559 } 1560 1561 static const TypeInfo virtio_ccw_rng = { 1562 .name = TYPE_VIRTIO_RNG_CCW, 1563 .parent = TYPE_VIRTIO_CCW_DEVICE, 1564 .instance_size = sizeof(VirtIORNGCcw), 1565 .instance_init = virtio_ccw_rng_instance_init, 1566 .class_init = virtio_ccw_rng_class_init, 1567 }; 1568 1569 static Property virtio_ccw_crypto_properties[] = { 1570 DEFINE_PROP_CSS_DEV_ID("devno", VirtioCcwDevice, parent_obj.bus_id), 1571 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags, 1572 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true), 1573 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev, 1574 VIRTIO_CCW_MAX_REV), 1575 DEFINE_PROP_END_OF_LIST(), 1576 }; 1577 1578 static void virtio_ccw_crypto_instance_init(Object *obj) 1579 { 1580 VirtIOCryptoCcw *dev = VIRTIO_CRYPTO_CCW(obj); 1581 VirtioCcwDevice *ccw_dev = VIRTIO_CCW_DEVICE(obj); 1582 1583 ccw_dev->force_revision_1 = true; 1584 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), 1585 TYPE_VIRTIO_CRYPTO); 1586 1587 object_property_add_alias(obj, "cryptodev", OBJECT(&dev->vdev), 1588 "cryptodev", &error_abort); 1589 } 1590 1591 static void virtio_ccw_crypto_class_init(ObjectClass *klass, void *data) 1592 { 1593 DeviceClass *dc = DEVICE_CLASS(klass); 1594 VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass); 1595 1596 k->realize = virtio_ccw_crypto_realize; 1597 k->exit = virtio_ccw_exit; 1598 dc->reset = virtio_ccw_reset; 1599 dc->props = virtio_ccw_crypto_properties; 1600 set_bit(DEVICE_CATEGORY_MISC, dc->categories); 1601 } 1602 1603 static const TypeInfo virtio_ccw_crypto = { 1604 .name = TYPE_VIRTIO_CRYPTO_CCW, 1605 .parent = TYPE_VIRTIO_CCW_DEVICE, 1606 .instance_size = sizeof(VirtIOCryptoCcw), 1607 .instance_init = virtio_ccw_crypto_instance_init, 1608 .class_init = virtio_ccw_crypto_class_init, 1609 }; 1610 1611 static void virtio_ccw_busdev_realize(DeviceState *dev, Error **errp) 1612 { 1613 VirtioCcwDevice *_dev = (VirtioCcwDevice *)dev; 1614 1615 virtio_ccw_bus_new(&_dev->bus, sizeof(_dev->bus), _dev); 1616 virtio_ccw_device_realize(_dev, errp); 1617 } 1618 1619 static int virtio_ccw_busdev_exit(DeviceState *dev) 1620 { 1621 VirtioCcwDevice *_dev = (VirtioCcwDevice *)dev; 1622 VirtIOCCWDeviceClass *_info = VIRTIO_CCW_DEVICE_GET_CLASS(dev); 1623 1624 return _info->exit(_dev); 1625 } 1626 1627 static void virtio_ccw_busdev_unplug(HotplugHandler *hotplug_dev, 1628 DeviceState *dev, Error **errp) 1629 { 1630 VirtioCcwDevice *_dev = to_virtio_ccw_dev_fast(dev); 1631 1632 virtio_ccw_stop_ioeventfd(_dev); 1633 } 1634 1635 static void virtio_ccw_device_class_init(ObjectClass *klass, void *data) 1636 { 1637 DeviceClass *dc = DEVICE_CLASS(klass); 1638 CCWDeviceClass *k = CCW_DEVICE_CLASS(dc); 1639 1640 k->unplug = virtio_ccw_busdev_unplug; 1641 dc->realize = virtio_ccw_busdev_realize; 1642 dc->exit = virtio_ccw_busdev_exit; 1643 dc->bus_type = TYPE_VIRTUAL_CSS_BUS; 1644 } 1645 1646 static const TypeInfo virtio_ccw_device_info = { 1647 .name = TYPE_VIRTIO_CCW_DEVICE, 1648 .parent = TYPE_CCW_DEVICE, 1649 .instance_size = sizeof(VirtioCcwDevice), 1650 .class_init = virtio_ccw_device_class_init, 1651 .class_size = sizeof(VirtIOCCWDeviceClass), 1652 .abstract = true, 1653 }; 1654 1655 /* virtio-ccw-bus */ 1656 1657 static void virtio_ccw_bus_new(VirtioBusState *bus, size_t bus_size, 1658 VirtioCcwDevice *dev) 1659 { 1660 DeviceState *qdev = DEVICE(dev); 1661 char virtio_bus_name[] = "virtio-bus"; 1662 1663 qbus_create_inplace(bus, bus_size, TYPE_VIRTIO_CCW_BUS, 1664 qdev, virtio_bus_name); 1665 } 1666 1667 static void virtio_ccw_bus_class_init(ObjectClass *klass, void *data) 1668 { 1669 VirtioBusClass *k = VIRTIO_BUS_CLASS(klass); 1670 BusClass *bus_class = BUS_CLASS(klass); 1671 1672 bus_class->max_dev = 1; 1673 k->notify = virtio_ccw_notify; 1674 k->vmstate_change = virtio_ccw_vmstate_change; 1675 k->query_guest_notifiers = virtio_ccw_query_guest_notifiers; 1676 k->set_guest_notifiers = virtio_ccw_set_guest_notifiers; 1677 k->save_queue = virtio_ccw_save_queue; 1678 k->load_queue = virtio_ccw_load_queue; 1679 k->save_config = virtio_ccw_save_config; 1680 k->load_config = virtio_ccw_load_config; 1681 k->pre_plugged = virtio_ccw_pre_plugged; 1682 k->device_plugged = virtio_ccw_device_plugged; 1683 k->device_unplugged = virtio_ccw_device_unplugged; 1684 k->ioeventfd_enabled = virtio_ccw_ioeventfd_enabled; 1685 k->ioeventfd_assign = virtio_ccw_ioeventfd_assign; 1686 } 1687 1688 static const TypeInfo virtio_ccw_bus_info = { 1689 .name = TYPE_VIRTIO_CCW_BUS, 1690 .parent = TYPE_VIRTIO_BUS, 1691 .instance_size = sizeof(VirtioCcwBusState), 1692 .class_init = virtio_ccw_bus_class_init, 1693 }; 1694 1695 #ifdef CONFIG_VIRTFS 1696 static Property virtio_ccw_9p_properties[] = { 1697 DEFINE_PROP_CSS_DEV_ID("devno", VirtioCcwDevice, parent_obj.bus_id), 1698 DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags, 1699 VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true), 1700 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev, 1701 VIRTIO_CCW_MAX_REV), 1702 DEFINE_PROP_END_OF_LIST(), 1703 }; 1704 1705 static void virtio_ccw_9p_realize(VirtioCcwDevice *ccw_dev, Error **errp) 1706 { 1707 V9fsCCWState *dev = VIRTIO_9P_CCW(ccw_dev); 1708 DeviceState *vdev = DEVICE(&dev->vdev); 1709 1710 qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus)); 1711 object_property_set_bool(OBJECT(vdev), true, "realized", errp); 1712 } 1713 1714 static void virtio_ccw_9p_class_init(ObjectClass *klass, void *data) 1715 { 1716 DeviceClass *dc = DEVICE_CLASS(klass); 1717 VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass); 1718 1719 k->exit = virtio_ccw_exit; 1720 k->realize = virtio_ccw_9p_realize; 1721 dc->reset = virtio_ccw_reset; 1722 dc->props = virtio_ccw_9p_properties; 1723 set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); 1724 } 1725 1726 static void virtio_ccw_9p_instance_init(Object *obj) 1727 { 1728 V9fsCCWState *dev = VIRTIO_9P_CCW(obj); 1729 1730 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), 1731 TYPE_VIRTIO_9P); 1732 } 1733 1734 static const TypeInfo virtio_ccw_9p_info = { 1735 .name = TYPE_VIRTIO_9P_CCW, 1736 .parent = TYPE_VIRTIO_CCW_DEVICE, 1737 .instance_size = sizeof(V9fsCCWState), 1738 .instance_init = virtio_ccw_9p_instance_init, 1739 .class_init = virtio_ccw_9p_class_init, 1740 }; 1741 #endif 1742 1743 #ifdef CONFIG_VHOST_VSOCK 1744 1745 static Property vhost_vsock_ccw_properties[] = { 1746 DEFINE_PROP_CSS_DEV_ID("devno", VirtioCcwDevice, parent_obj.bus_id), 1747 DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev, 1748 VIRTIO_CCW_MAX_REV), 1749 DEFINE_PROP_END_OF_LIST(), 1750 }; 1751 1752 static void vhost_vsock_ccw_realize(VirtioCcwDevice *ccw_dev, Error **errp) 1753 { 1754 VHostVSockCCWState *dev = VHOST_VSOCK_CCW(ccw_dev); 1755 DeviceState *vdev = DEVICE(&dev->vdev); 1756 Error *err = NULL; 1757 1758 qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus)); 1759 object_property_set_bool(OBJECT(vdev), true, "realized", &err); 1760 if (err) { 1761 error_propagate(errp, err); 1762 } 1763 } 1764 1765 static void vhost_vsock_ccw_class_init(ObjectClass *klass, void *data) 1766 { 1767 DeviceClass *dc = DEVICE_CLASS(klass); 1768 VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass); 1769 1770 k->realize = vhost_vsock_ccw_realize; 1771 k->exit = virtio_ccw_exit; 1772 set_bit(DEVICE_CATEGORY_MISC, dc->categories); 1773 dc->props = vhost_vsock_ccw_properties; 1774 dc->reset = virtio_ccw_reset; 1775 } 1776 1777 static void vhost_vsock_ccw_instance_init(Object *obj) 1778 { 1779 VHostVSockCCWState *dev = VHOST_VSOCK_CCW(obj); 1780 1781 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), 1782 TYPE_VHOST_VSOCK); 1783 } 1784 1785 static const TypeInfo vhost_vsock_ccw_info = { 1786 .name = TYPE_VHOST_VSOCK_CCW, 1787 .parent = TYPE_VIRTIO_CCW_DEVICE, 1788 .instance_size = sizeof(VHostVSockCCWState), 1789 .instance_init = vhost_vsock_ccw_instance_init, 1790 .class_init = vhost_vsock_ccw_class_init, 1791 }; 1792 #endif 1793 1794 static void virtio_ccw_register(void) 1795 { 1796 type_register_static(&virtio_ccw_bus_info); 1797 type_register_static(&virtio_ccw_device_info); 1798 type_register_static(&virtio_ccw_serial); 1799 type_register_static(&virtio_ccw_blk); 1800 type_register_static(&virtio_ccw_net); 1801 type_register_static(&virtio_ccw_balloon); 1802 type_register_static(&virtio_ccw_scsi); 1803 #ifdef CONFIG_VHOST_SCSI 1804 type_register_static(&vhost_ccw_scsi); 1805 #endif 1806 type_register_static(&virtio_ccw_rng); 1807 #ifdef CONFIG_VIRTFS 1808 type_register_static(&virtio_ccw_9p_info); 1809 #endif 1810 #ifdef CONFIG_VHOST_VSOCK 1811 type_register_static(&vhost_vsock_ccw_info); 1812 #endif 1813 type_register_static(&virtio_ccw_crypto); 1814 } 1815 1816 type_init(virtio_ccw_register) 1817