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