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