1 /* 2 * vfio based device assignment support - platform devices 3 * 4 * Copyright Linaro Limited, 2014 5 * 6 * Authors: 7 * Kim Phillips <kim.phillips@linaro.org> 8 * Eric Auger <eric.auger@linaro.org> 9 * 10 * This work is licensed under the terms of the GNU GPL, version 2. See 11 * the COPYING file in the top-level directory. 12 * 13 * Based on vfio based PCI device assignment support: 14 * Copyright Red Hat, Inc. 2012 15 */ 16 17 #include "qemu/osdep.h" 18 #include "qapi/error.h" 19 #include <sys/ioctl.h> 20 #include <linux/vfio.h> 21 22 #include "hw/vfio/vfio-platform.h" 23 #include "migration/vmstate.h" 24 #include "qemu/error-report.h" 25 #include "qemu/module.h" 26 #include "qemu/range.h" 27 #include "sysemu/sysemu.h" 28 #include "exec/memory.h" 29 #include "exec/address-spaces.h" 30 #include "qemu/queue.h" 31 #include "hw/sysbus.h" 32 #include "trace.h" 33 #include "hw/irq.h" 34 #include "hw/platform-bus.h" 35 #include "sysemu/kvm.h" 36 37 /* 38 * Functions used whatever the injection method 39 */ 40 41 static inline bool vfio_irq_is_automasked(VFIOINTp *intp) 42 { 43 return intp->flags & VFIO_IRQ_INFO_AUTOMASKED; 44 } 45 46 /** 47 * vfio_init_intp - allocate, initialize the IRQ struct pointer 48 * and add it into the list of IRQs 49 * @vbasedev: the VFIO device handle 50 * @info: irq info struct retrieved from VFIO driver 51 * @errp: error object 52 */ 53 static VFIOINTp *vfio_init_intp(VFIODevice *vbasedev, 54 struct vfio_irq_info info, Error **errp) 55 { 56 int ret; 57 VFIOPlatformDevice *vdev = 58 container_of(vbasedev, VFIOPlatformDevice, vbasedev); 59 SysBusDevice *sbdev = SYS_BUS_DEVICE(vdev); 60 VFIOINTp *intp; 61 62 intp = g_malloc0(sizeof(*intp)); 63 intp->vdev = vdev; 64 intp->pin = info.index; 65 intp->flags = info.flags; 66 intp->state = VFIO_IRQ_INACTIVE; 67 intp->kvm_accel = false; 68 69 sysbus_init_irq(sbdev, &intp->qemuirq); 70 71 /* Get an eventfd for trigger */ 72 intp->interrupt = g_malloc0(sizeof(EventNotifier)); 73 ret = event_notifier_init(intp->interrupt, 0); 74 if (ret) { 75 g_free(intp->interrupt); 76 g_free(intp); 77 error_setg_errno(errp, -ret, 78 "failed to initialize trigger eventfd notifier"); 79 return NULL; 80 } 81 if (vfio_irq_is_automasked(intp)) { 82 /* Get an eventfd for resample/unmask */ 83 intp->unmask = g_malloc0(sizeof(EventNotifier)); 84 ret = event_notifier_init(intp->unmask, 0); 85 if (ret) { 86 g_free(intp->interrupt); 87 g_free(intp->unmask); 88 g_free(intp); 89 error_setg_errno(errp, -ret, 90 "failed to initialize resample eventfd notifier"); 91 return NULL; 92 } 93 } 94 95 QLIST_INSERT_HEAD(&vdev->intp_list, intp, next); 96 return intp; 97 } 98 99 /** 100 * vfio_set_trigger_eventfd - set VFIO eventfd handling 101 * 102 * @intp: IRQ struct handle 103 * @handler: handler to be called on eventfd signaling 104 * 105 * Setup VFIO signaling and attach an optional user-side handler 106 * to the eventfd 107 */ 108 static int vfio_set_trigger_eventfd(VFIOINTp *intp, 109 eventfd_user_side_handler_t handler) 110 { 111 VFIODevice *vbasedev = &intp->vdev->vbasedev; 112 int32_t fd = event_notifier_get_fd(intp->interrupt); 113 Error *err = NULL; 114 int ret; 115 116 qemu_set_fd_handler(fd, (IOHandler *)handler, NULL, intp); 117 118 ret = vfio_set_irq_signaling(vbasedev, intp->pin, 0, 119 VFIO_IRQ_SET_ACTION_TRIGGER, fd, &err); 120 if (ret) { 121 error_reportf_err(err, VFIO_MSG_PREFIX, vbasedev->name); 122 qemu_set_fd_handler(fd, NULL, NULL, NULL); 123 } 124 125 return ret; 126 } 127 128 /* 129 * Functions only used when eventfds are handled on user-side 130 * ie. without irqfd 131 */ 132 133 /** 134 * vfio_mmap_set_enabled - enable/disable the fast path mode 135 * @vdev: the VFIO platform device 136 * @enabled: the target mmap state 137 * 138 * enabled = true ~ fast path = MMIO region is mmaped (no KVM TRAP); 139 * enabled = false ~ slow path = MMIO region is trapped and region callbacks 140 * are called; slow path enables to trap the device IRQ status register reset 141 */ 142 143 static void vfio_mmap_set_enabled(VFIOPlatformDevice *vdev, bool enabled) 144 { 145 int i; 146 147 for (i = 0; i < vdev->vbasedev.num_regions; i++) { 148 vfio_region_mmaps_set_enabled(vdev->regions[i], enabled); 149 } 150 } 151 152 /** 153 * vfio_intp_mmap_enable - timer function, restores the fast path 154 * if there is no more active IRQ 155 * @opaque: actually points to the VFIO platform device 156 * 157 * Called on mmap timer timout, this function checks whether the 158 * IRQ is still active and if not, restores the fast path. 159 * by construction a single eventfd is handled at a time. 160 * if the IRQ is still active, the timer is re-programmed. 161 */ 162 static void vfio_intp_mmap_enable(void *opaque) 163 { 164 VFIOINTp *tmp; 165 VFIOPlatformDevice *vdev = (VFIOPlatformDevice *)opaque; 166 167 qemu_mutex_lock(&vdev->intp_mutex); 168 QLIST_FOREACH(tmp, &vdev->intp_list, next) { 169 if (tmp->state == VFIO_IRQ_ACTIVE) { 170 trace_vfio_platform_intp_mmap_enable(tmp->pin); 171 /* re-program the timer to check active status later */ 172 timer_mod(vdev->mmap_timer, 173 qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + 174 vdev->mmap_timeout); 175 qemu_mutex_unlock(&vdev->intp_mutex); 176 return; 177 } 178 } 179 vfio_mmap_set_enabled(vdev, true); 180 qemu_mutex_unlock(&vdev->intp_mutex); 181 } 182 183 /** 184 * vfio_intp_inject_pending_lockheld - Injects a pending IRQ 185 * @opaque: opaque pointer, in practice the VFIOINTp handle 186 * 187 * The function is called on a previous IRQ completion, from 188 * vfio_platform_eoi, while the intp_mutex is locked. 189 * Also in such situation, the slow path already is set and 190 * the mmap timer was already programmed. 191 */ 192 static void vfio_intp_inject_pending_lockheld(VFIOINTp *intp) 193 { 194 trace_vfio_platform_intp_inject_pending_lockheld(intp->pin, 195 event_notifier_get_fd(intp->interrupt)); 196 197 intp->state = VFIO_IRQ_ACTIVE; 198 199 /* trigger the virtual IRQ */ 200 qemu_set_irq(intp->qemuirq, 1); 201 } 202 203 /** 204 * vfio_intp_interrupt - The user-side eventfd handler 205 * @opaque: opaque pointer which in practice is the VFIOINTp handle 206 * 207 * the function is entered in event handler context: 208 * the vIRQ is injected into the guest if there is no other active 209 * or pending IRQ. 210 */ 211 static void vfio_intp_interrupt(VFIOINTp *intp) 212 { 213 int ret; 214 VFIOINTp *tmp; 215 VFIOPlatformDevice *vdev = intp->vdev; 216 bool delay_handling = false; 217 218 qemu_mutex_lock(&vdev->intp_mutex); 219 if (intp->state == VFIO_IRQ_INACTIVE) { 220 QLIST_FOREACH(tmp, &vdev->intp_list, next) { 221 if (tmp->state == VFIO_IRQ_ACTIVE || 222 tmp->state == VFIO_IRQ_PENDING) { 223 delay_handling = true; 224 break; 225 } 226 } 227 } 228 if (delay_handling) { 229 /* 230 * the new IRQ gets a pending status and is pushed in 231 * the pending queue 232 */ 233 intp->state = VFIO_IRQ_PENDING; 234 trace_vfio_intp_interrupt_set_pending(intp->pin); 235 QSIMPLEQ_INSERT_TAIL(&vdev->pending_intp_queue, 236 intp, pqnext); 237 ret = event_notifier_test_and_clear(intp->interrupt); 238 qemu_mutex_unlock(&vdev->intp_mutex); 239 return; 240 } 241 242 trace_vfio_platform_intp_interrupt(intp->pin, 243 event_notifier_get_fd(intp->interrupt)); 244 245 ret = event_notifier_test_and_clear(intp->interrupt); 246 if (!ret) { 247 error_report("Error when clearing fd=%d (ret = %d)", 248 event_notifier_get_fd(intp->interrupt), ret); 249 } 250 251 intp->state = VFIO_IRQ_ACTIVE; 252 253 /* sets slow path */ 254 vfio_mmap_set_enabled(vdev, false); 255 256 /* trigger the virtual IRQ */ 257 qemu_set_irq(intp->qemuirq, 1); 258 259 /* 260 * Schedule the mmap timer which will restore fastpath when no IRQ 261 * is active anymore 262 */ 263 if (vdev->mmap_timeout) { 264 timer_mod(vdev->mmap_timer, 265 qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + 266 vdev->mmap_timeout); 267 } 268 qemu_mutex_unlock(&vdev->intp_mutex); 269 } 270 271 /** 272 * vfio_platform_eoi - IRQ completion routine 273 * @vbasedev: the VFIO device handle 274 * 275 * De-asserts the active virtual IRQ and unmasks the physical IRQ 276 * (effective for level sensitive IRQ auto-masked by the VFIO driver). 277 * Then it handles next pending IRQ if any. 278 * eoi function is called on the first access to any MMIO region 279 * after an IRQ was triggered, trapped since slow path was set. 280 * It is assumed this access corresponds to the IRQ status 281 * register reset. With such a mechanism, a single IRQ can be 282 * handled at a time since there is no way to know which IRQ 283 * was completed by the guest (we would need additional details 284 * about the IRQ status register mask). 285 */ 286 static void vfio_platform_eoi(VFIODevice *vbasedev) 287 { 288 VFIOINTp *intp; 289 VFIOPlatformDevice *vdev = 290 container_of(vbasedev, VFIOPlatformDevice, vbasedev); 291 292 qemu_mutex_lock(&vdev->intp_mutex); 293 QLIST_FOREACH(intp, &vdev->intp_list, next) { 294 if (intp->state == VFIO_IRQ_ACTIVE) { 295 trace_vfio_platform_eoi(intp->pin, 296 event_notifier_get_fd(intp->interrupt)); 297 intp->state = VFIO_IRQ_INACTIVE; 298 299 /* deassert the virtual IRQ */ 300 qemu_set_irq(intp->qemuirq, 0); 301 302 if (vfio_irq_is_automasked(intp)) { 303 /* unmasks the physical level-sensitive IRQ */ 304 vfio_unmask_single_irqindex(vbasedev, intp->pin); 305 } 306 307 /* a single IRQ can be active at a time */ 308 break; 309 } 310 } 311 /* in case there are pending IRQs, handle the first one */ 312 if (!QSIMPLEQ_EMPTY(&vdev->pending_intp_queue)) { 313 intp = QSIMPLEQ_FIRST(&vdev->pending_intp_queue); 314 vfio_intp_inject_pending_lockheld(intp); 315 QSIMPLEQ_REMOVE_HEAD(&vdev->pending_intp_queue, pqnext); 316 } 317 qemu_mutex_unlock(&vdev->intp_mutex); 318 } 319 320 /** 321 * vfio_start_eventfd_injection - starts the virtual IRQ injection using 322 * user-side handled eventfds 323 * @sbdev: the sysbus device handle 324 * @irq: the qemu irq handle 325 */ 326 327 static void vfio_start_eventfd_injection(SysBusDevice *sbdev, qemu_irq irq) 328 { 329 VFIOPlatformDevice *vdev = VFIO_PLATFORM_DEVICE(sbdev); 330 VFIOINTp *intp; 331 332 QLIST_FOREACH(intp, &vdev->intp_list, next) { 333 if (intp->qemuirq == irq) { 334 break; 335 } 336 } 337 assert(intp); 338 339 if (vfio_set_trigger_eventfd(intp, vfio_intp_interrupt)) { 340 abort(); 341 } 342 } 343 344 /* 345 * Functions used for irqfd 346 */ 347 348 /** 349 * vfio_set_resample_eventfd - sets the resamplefd for an IRQ 350 * @intp: the IRQ struct handle 351 * programs the VFIO driver to unmask this IRQ when the 352 * intp->unmask eventfd is triggered 353 */ 354 static int vfio_set_resample_eventfd(VFIOINTp *intp) 355 { 356 int32_t fd = event_notifier_get_fd(intp->unmask); 357 VFIODevice *vbasedev = &intp->vdev->vbasedev; 358 Error *err = NULL; 359 int ret; 360 361 qemu_set_fd_handler(fd, NULL, NULL, NULL); 362 ret = vfio_set_irq_signaling(vbasedev, intp->pin, 0, 363 VFIO_IRQ_SET_ACTION_UNMASK, fd, &err); 364 if (ret) { 365 error_reportf_err(err, VFIO_MSG_PREFIX, vbasedev->name); 366 } 367 return ret; 368 } 369 370 /** 371 * vfio_start_irqfd_injection - starts the virtual IRQ injection using 372 * irqfd 373 * 374 * @sbdev: the sysbus device handle 375 * @irq: the qemu irq handle 376 * 377 * In case the irqfd setup fails, we fallback to userspace handled eventfd 378 */ 379 static void vfio_start_irqfd_injection(SysBusDevice *sbdev, qemu_irq irq) 380 { 381 VFIOPlatformDevice *vdev = VFIO_PLATFORM_DEVICE(sbdev); 382 VFIOINTp *intp; 383 384 if (!kvm_irqfds_enabled() || !kvm_resamplefds_enabled() || 385 !vdev->irqfd_allowed) { 386 goto fail_irqfd; 387 } 388 389 QLIST_FOREACH(intp, &vdev->intp_list, next) { 390 if (intp->qemuirq == irq) { 391 break; 392 } 393 } 394 assert(intp); 395 396 if (kvm_irqchip_add_irqfd_notifier(kvm_state, intp->interrupt, 397 intp->unmask, irq) < 0) { 398 goto fail_irqfd; 399 } 400 401 if (vfio_set_trigger_eventfd(intp, NULL) < 0) { 402 goto fail_vfio; 403 } 404 if (vfio_irq_is_automasked(intp)) { 405 if (vfio_set_resample_eventfd(intp) < 0) { 406 goto fail_vfio; 407 } 408 trace_vfio_platform_start_level_irqfd_injection(intp->pin, 409 event_notifier_get_fd(intp->interrupt), 410 event_notifier_get_fd(intp->unmask)); 411 } else { 412 trace_vfio_platform_start_edge_irqfd_injection(intp->pin, 413 event_notifier_get_fd(intp->interrupt)); 414 } 415 416 intp->kvm_accel = true; 417 418 return; 419 fail_vfio: 420 kvm_irqchip_remove_irqfd_notifier(kvm_state, intp->interrupt, irq); 421 abort(); 422 fail_irqfd: 423 vfio_start_eventfd_injection(sbdev, irq); 424 return; 425 } 426 427 /* VFIO skeleton */ 428 429 static void vfio_platform_compute_needs_reset(VFIODevice *vbasedev) 430 { 431 vbasedev->needs_reset = true; 432 } 433 434 /* not implemented yet */ 435 static int vfio_platform_hot_reset_multi(VFIODevice *vbasedev) 436 { 437 return -1; 438 } 439 440 /** 441 * vfio_populate_device - Allocate and populate MMIO region 442 * and IRQ structs according to driver returned information 443 * @vbasedev: the VFIO device handle 444 * @errp: error object 445 * 446 */ 447 static int vfio_populate_device(VFIODevice *vbasedev, Error **errp) 448 { 449 VFIOINTp *intp, *tmp; 450 int i, ret = -1; 451 VFIOPlatformDevice *vdev = 452 container_of(vbasedev, VFIOPlatformDevice, vbasedev); 453 454 if (!(vbasedev->flags & VFIO_DEVICE_FLAGS_PLATFORM)) { 455 error_setg(errp, "this isn't a platform device"); 456 return ret; 457 } 458 459 vdev->regions = g_new0(VFIORegion *, vbasedev->num_regions); 460 461 for (i = 0; i < vbasedev->num_regions; i++) { 462 char *name = g_strdup_printf("VFIO %s region %d\n", vbasedev->name, i); 463 464 vdev->regions[i] = g_new0(VFIORegion, 1); 465 ret = vfio_region_setup(OBJECT(vdev), vbasedev, 466 vdev->regions[i], i, name); 467 g_free(name); 468 if (ret) { 469 error_setg_errno(errp, -ret, "failed to get region %d info", i); 470 goto reg_error; 471 } 472 } 473 474 vdev->mmap_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL, 475 vfio_intp_mmap_enable, vdev); 476 477 QSIMPLEQ_INIT(&vdev->pending_intp_queue); 478 479 for (i = 0; i < vbasedev->num_irqs; i++) { 480 struct vfio_irq_info irq = { .argsz = sizeof(irq) }; 481 482 irq.index = i; 483 ret = ioctl(vbasedev->fd, VFIO_DEVICE_GET_IRQ_INFO, &irq); 484 if (ret) { 485 error_setg_errno(errp, -ret, "failed to get device irq info"); 486 goto irq_err; 487 } else { 488 trace_vfio_platform_populate_interrupts(irq.index, 489 irq.count, 490 irq.flags); 491 intp = vfio_init_intp(vbasedev, irq, errp); 492 if (!intp) { 493 ret = -1; 494 goto irq_err; 495 } 496 } 497 } 498 return 0; 499 irq_err: 500 timer_del(vdev->mmap_timer); 501 QLIST_FOREACH_SAFE(intp, &vdev->intp_list, next, tmp) { 502 QLIST_REMOVE(intp, next); 503 g_free(intp); 504 } 505 reg_error: 506 for (i = 0; i < vbasedev->num_regions; i++) { 507 if (vdev->regions[i]) { 508 vfio_region_finalize(vdev->regions[i]); 509 } 510 g_free(vdev->regions[i]); 511 } 512 g_free(vdev->regions); 513 return ret; 514 } 515 516 /* specialized functions for VFIO Platform devices */ 517 static VFIODeviceOps vfio_platform_ops = { 518 .vfio_compute_needs_reset = vfio_platform_compute_needs_reset, 519 .vfio_hot_reset_multi = vfio_platform_hot_reset_multi, 520 .vfio_eoi = vfio_platform_eoi, 521 }; 522 523 /** 524 * vfio_base_device_init - perform preliminary VFIO setup 525 * @vbasedev: the VFIO device handle 526 * @errp: error object 527 * 528 * Implement the VFIO command sequence that allows to discover 529 * assigned device resources: group extraction, device 530 * fd retrieval, resource query. 531 * Precondition: the device name must be initialized 532 */ 533 static int vfio_base_device_init(VFIODevice *vbasedev, Error **errp) 534 { 535 VFIOGroup *group; 536 VFIODevice *vbasedev_iter; 537 char *tmp, group_path[PATH_MAX], *group_name; 538 ssize_t len; 539 struct stat st; 540 int groupid; 541 int ret; 542 543 /* @sysfsdev takes precedence over @host */ 544 if (vbasedev->sysfsdev) { 545 g_free(vbasedev->name); 546 vbasedev->name = g_path_get_basename(vbasedev->sysfsdev); 547 } else { 548 if (!vbasedev->name || strchr(vbasedev->name, '/')) { 549 error_setg(errp, "wrong host device name"); 550 return -EINVAL; 551 } 552 553 vbasedev->sysfsdev = g_strdup_printf("/sys/bus/platform/devices/%s", 554 vbasedev->name); 555 } 556 557 if (stat(vbasedev->sysfsdev, &st) < 0) { 558 error_setg_errno(errp, errno, 559 "failed to get the sysfs host device file status"); 560 return -errno; 561 } 562 563 tmp = g_strdup_printf("%s/iommu_group", vbasedev->sysfsdev); 564 len = readlink(tmp, group_path, sizeof(group_path)); 565 g_free(tmp); 566 567 if (len < 0 || len >= sizeof(group_path)) { 568 ret = len < 0 ? -errno : -ENAMETOOLONG; 569 error_setg_errno(errp, -ret, "no iommu_group found"); 570 return ret; 571 } 572 573 group_path[len] = 0; 574 575 group_name = basename(group_path); 576 if (sscanf(group_name, "%d", &groupid) != 1) { 577 error_setg_errno(errp, errno, "failed to read %s", group_path); 578 return -errno; 579 } 580 581 trace_vfio_platform_base_device_init(vbasedev->name, groupid); 582 583 group = vfio_get_group(groupid, &address_space_memory, errp); 584 if (!group) { 585 return -ENOENT; 586 } 587 588 QLIST_FOREACH(vbasedev_iter, &group->device_list, next) { 589 if (strcmp(vbasedev_iter->name, vbasedev->name) == 0) { 590 error_setg(errp, "device is already attached"); 591 vfio_put_group(group); 592 return -EBUSY; 593 } 594 } 595 ret = vfio_get_device(group, vbasedev->name, vbasedev, errp); 596 if (ret) { 597 vfio_put_group(group); 598 return ret; 599 } 600 601 ret = vfio_populate_device(vbasedev, errp); 602 if (ret) { 603 vfio_put_group(group); 604 } 605 606 return ret; 607 } 608 609 /** 610 * vfio_platform_realize - the device realize function 611 * @dev: device state pointer 612 * @errp: error 613 * 614 * initialize the device, its memory regions and IRQ structures 615 * IRQ are started separately 616 */ 617 static void vfio_platform_realize(DeviceState *dev, Error **errp) 618 { 619 VFIOPlatformDevice *vdev = VFIO_PLATFORM_DEVICE(dev); 620 SysBusDevice *sbdev = SYS_BUS_DEVICE(dev); 621 VFIODevice *vbasedev = &vdev->vbasedev; 622 int i, ret; 623 624 vbasedev->type = VFIO_DEVICE_TYPE_PLATFORM; 625 vbasedev->dev = dev; 626 vbasedev->ops = &vfio_platform_ops; 627 628 qemu_mutex_init(&vdev->intp_mutex); 629 630 trace_vfio_platform_realize(vbasedev->sysfsdev ? 631 vbasedev->sysfsdev : vbasedev->name, 632 vdev->compat); 633 634 ret = vfio_base_device_init(vbasedev, errp); 635 if (ret) { 636 goto out; 637 } 638 639 if (!vdev->compat) { 640 GError *gerr = NULL; 641 gchar *contents; 642 gsize length; 643 char *path; 644 645 path = g_strdup_printf("%s/of_node/compatible", vbasedev->sysfsdev); 646 if (!g_file_get_contents(path, &contents, &length, &gerr)) { 647 error_setg(errp, "%s", gerr->message); 648 g_error_free(gerr); 649 g_free(path); 650 return; 651 } 652 g_free(path); 653 vdev->compat = contents; 654 for (vdev->num_compat = 0; length; vdev->num_compat++) { 655 size_t skip = strlen(contents) + 1; 656 contents += skip; 657 length -= skip; 658 } 659 } 660 661 for (i = 0; i < vbasedev->num_regions; i++) { 662 if (vfio_region_mmap(vdev->regions[i])) { 663 warn_report("%s mmap unsupported, performance may be slow", 664 memory_region_name(vdev->regions[i]->mem)); 665 } 666 sysbus_init_mmio(sbdev, vdev->regions[i]->mem); 667 } 668 out: 669 if (!ret) { 670 return; 671 } 672 673 if (vdev->vbasedev.name) { 674 error_prepend(errp, VFIO_MSG_PREFIX, vdev->vbasedev.name); 675 } else { 676 error_prepend(errp, "vfio error: "); 677 } 678 } 679 680 static const VMStateDescription vfio_platform_vmstate = { 681 .name = "vfio-platform", 682 .unmigratable = 1, 683 }; 684 685 static Property vfio_platform_dev_properties[] = { 686 DEFINE_PROP_STRING("host", VFIOPlatformDevice, vbasedev.name), 687 DEFINE_PROP_STRING("sysfsdev", VFIOPlatformDevice, vbasedev.sysfsdev), 688 DEFINE_PROP_BOOL("x-no-mmap", VFIOPlatformDevice, vbasedev.no_mmap, false), 689 DEFINE_PROP_UINT32("mmap-timeout-ms", VFIOPlatformDevice, 690 mmap_timeout, 1100), 691 DEFINE_PROP_BOOL("x-irqfd", VFIOPlatformDevice, irqfd_allowed, true), 692 DEFINE_PROP_END_OF_LIST(), 693 }; 694 695 static void vfio_platform_class_init(ObjectClass *klass, void *data) 696 { 697 DeviceClass *dc = DEVICE_CLASS(klass); 698 SysBusDeviceClass *sbc = SYS_BUS_DEVICE_CLASS(klass); 699 700 dc->realize = vfio_platform_realize; 701 dc->props = vfio_platform_dev_properties; 702 dc->vmsd = &vfio_platform_vmstate; 703 dc->desc = "VFIO-based platform device assignment"; 704 sbc->connect_irq_notifier = vfio_start_irqfd_injection; 705 set_bit(DEVICE_CATEGORY_MISC, dc->categories); 706 /* Supported by TYPE_VIRT_MACHINE */ 707 dc->user_creatable = true; 708 } 709 710 static const TypeInfo vfio_platform_dev_info = { 711 .name = TYPE_VFIO_PLATFORM, 712 .parent = TYPE_SYS_BUS_DEVICE, 713 .instance_size = sizeof(VFIOPlatformDevice), 714 .class_init = vfio_platform_class_init, 715 .class_size = sizeof(VFIOPlatformDeviceClass), 716 }; 717 718 static void register_vfio_platform_dev_type(void) 719 { 720 type_register_static(&vfio_platform_dev_info); 721 } 722 723 type_init(register_vfio_platform_dev_type) 724