virtio: combine the read of a descriptor
[qemu.git] / hw / vfio / platform.c
blobebc9dcbb993c3547bda4a5da8f55e2b4e4a5265c
1 /*
2 * vfio based device assignment support - platform devices
4 * Copyright Linaro Limited, 2014
6 * Authors:
7 * Kim Phillips <kim.phillips@linaro.org>
8 * Eric Auger <eric.auger@linaro.org>
10 * This work is licensed under the terms of the GNU GPL, version 2. See
11 * the COPYING file in the top-level directory.
13 * Based on vfio based PCI device assignment support:
14 * Copyright Red Hat, Inc. 2012
17 #include "qemu/osdep.h"
18 #include <sys/ioctl.h>
19 #include <linux/vfio.h>
21 #include "hw/vfio/vfio-platform.h"
22 #include "qemu/error-report.h"
23 #include "qemu/range.h"
24 #include "sysemu/sysemu.h"
25 #include "exec/memory.h"
26 #include "qemu/queue.h"
27 #include "hw/sysbus.h"
28 #include "trace.h"
29 #include "hw/platform-bus.h"
30 #include "sysemu/kvm.h"
33 * Functions used whatever the injection method
36 static inline bool vfio_irq_is_automasked(VFIOINTp *intp)
38 return intp->flags & VFIO_IRQ_INFO_AUTOMASKED;
41 /**
42 * vfio_init_intp - allocate, initialize the IRQ struct pointer
43 * and add it into the list of IRQs
44 * @vbasedev: the VFIO device handle
45 * @info: irq info struct retrieved from VFIO driver
47 static VFIOINTp *vfio_init_intp(VFIODevice *vbasedev,
48 struct vfio_irq_info info)
50 int ret;
51 VFIOPlatformDevice *vdev =
52 container_of(vbasedev, VFIOPlatformDevice, vbasedev);
53 SysBusDevice *sbdev = SYS_BUS_DEVICE(vdev);
54 VFIOINTp *intp;
56 intp = g_malloc0(sizeof(*intp));
57 intp->vdev = vdev;
58 intp->pin = info.index;
59 intp->flags = info.flags;
60 intp->state = VFIO_IRQ_INACTIVE;
61 intp->kvm_accel = false;
63 sysbus_init_irq(sbdev, &intp->qemuirq);
65 /* Get an eventfd for trigger */
66 intp->interrupt = g_malloc0(sizeof(EventNotifier));
67 ret = event_notifier_init(intp->interrupt, 0);
68 if (ret) {
69 g_free(intp->interrupt);
70 g_free(intp);
71 error_report("vfio: Error: trigger event_notifier_init failed ");
72 return NULL;
74 if (vfio_irq_is_automasked(intp)) {
75 /* Get an eventfd for resample/unmask */
76 intp->unmask = g_malloc0(sizeof(EventNotifier));
77 ret = event_notifier_init(intp->unmask, 0);
78 if (ret) {
79 g_free(intp->interrupt);
80 g_free(intp->unmask);
81 g_free(intp);
82 error_report("vfio: Error: resamplefd event_notifier_init failed");
83 return NULL;
87 QLIST_INSERT_HEAD(&vdev->intp_list, intp, next);
88 return intp;
91 /**
92 * vfio_set_trigger_eventfd - set VFIO eventfd handling
94 * @intp: IRQ struct handle
95 * @handler: handler to be called on eventfd signaling
97 * Setup VFIO signaling and attach an optional user-side handler
98 * to the eventfd
100 static int vfio_set_trigger_eventfd(VFIOINTp *intp,
101 eventfd_user_side_handler_t handler)
103 VFIODevice *vbasedev = &intp->vdev->vbasedev;
104 struct vfio_irq_set *irq_set;
105 int argsz, ret;
106 int32_t *pfd;
108 argsz = sizeof(*irq_set) + sizeof(*pfd);
109 irq_set = g_malloc0(argsz);
110 irq_set->argsz = argsz;
111 irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD | VFIO_IRQ_SET_ACTION_TRIGGER;
112 irq_set->index = intp->pin;
113 irq_set->start = 0;
114 irq_set->count = 1;
115 pfd = (int32_t *)&irq_set->data;
116 *pfd = event_notifier_get_fd(intp->interrupt);
117 qemu_set_fd_handler(*pfd, (IOHandler *)handler, NULL, intp);
118 ret = ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, irq_set);
119 g_free(irq_set);
120 if (ret < 0) {
121 error_report("vfio: Failed to set trigger eventfd: %m");
122 qemu_set_fd_handler(*pfd, NULL, NULL, NULL);
124 return ret;
128 * Functions only used when eventfds are handled on user-side
129 * ie. without irqfd
133 * vfio_mmap_set_enabled - enable/disable the fast path mode
134 * @vdev: the VFIO platform device
135 * @enabled: the target mmap state
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
142 static void vfio_mmap_set_enabled(VFIOPlatformDevice *vdev, bool enabled)
144 int i;
146 trace_vfio_platform_mmap_set_enabled(enabled);
148 for (i = 0; i < vdev->vbasedev.num_regions; i++) {
149 VFIORegion *region = vdev->regions[i];
151 memory_region_set_enabled(&region->mmap_mem, enabled);
156 * vfio_intp_mmap_enable - timer function, restores the fast path
157 * if there is no more active IRQ
158 * @opaque: actually points to the VFIO platform device
160 * Called on mmap timer timout, this function checks whether the
161 * IRQ is still active and if not, restores the fast path.
162 * by construction a single eventfd is handled at a time.
163 * if the IRQ is still active, the timer is re-programmed.
165 static void vfio_intp_mmap_enable(void *opaque)
167 VFIOINTp *tmp;
168 VFIOPlatformDevice *vdev = (VFIOPlatformDevice *)opaque;
170 qemu_mutex_lock(&vdev->intp_mutex);
171 QLIST_FOREACH(tmp, &vdev->intp_list, next) {
172 if (tmp->state == VFIO_IRQ_ACTIVE) {
173 trace_vfio_platform_intp_mmap_enable(tmp->pin);
174 /* re-program the timer to check active status later */
175 timer_mod(vdev->mmap_timer,
176 qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) +
177 vdev->mmap_timeout);
178 qemu_mutex_unlock(&vdev->intp_mutex);
179 return;
182 vfio_mmap_set_enabled(vdev, true);
183 qemu_mutex_unlock(&vdev->intp_mutex);
187 * vfio_intp_inject_pending_lockheld - Injects a pending IRQ
188 * @opaque: opaque pointer, in practice the VFIOINTp handle
190 * The function is called on a previous IRQ completion, from
191 * vfio_platform_eoi, while the intp_mutex is locked.
192 * Also in such situation, the slow path already is set and
193 * the mmap timer was already programmed.
195 static void vfio_intp_inject_pending_lockheld(VFIOINTp *intp)
197 trace_vfio_platform_intp_inject_pending_lockheld(intp->pin,
198 event_notifier_get_fd(intp->interrupt));
200 intp->state = VFIO_IRQ_ACTIVE;
202 /* trigger the virtual IRQ */
203 qemu_set_irq(intp->qemuirq, 1);
207 * vfio_intp_interrupt - The user-side eventfd handler
208 * @opaque: opaque pointer which in practice is the VFIOINTp handle
210 * the function is entered in event handler context:
211 * the vIRQ is injected into the guest if there is no other active
212 * or pending IRQ.
214 static void vfio_intp_interrupt(VFIOINTp *intp)
216 int ret;
217 VFIOINTp *tmp;
218 VFIOPlatformDevice *vdev = intp->vdev;
219 bool delay_handling = false;
221 qemu_mutex_lock(&vdev->intp_mutex);
222 if (intp->state == VFIO_IRQ_INACTIVE) {
223 QLIST_FOREACH(tmp, &vdev->intp_list, next) {
224 if (tmp->state == VFIO_IRQ_ACTIVE ||
225 tmp->state == VFIO_IRQ_PENDING) {
226 delay_handling = true;
227 break;
231 if (delay_handling) {
233 * the new IRQ gets a pending status and is pushed in
234 * the pending queue
236 intp->state = VFIO_IRQ_PENDING;
237 trace_vfio_intp_interrupt_set_pending(intp->pin);
238 QSIMPLEQ_INSERT_TAIL(&vdev->pending_intp_queue,
239 intp, pqnext);
240 ret = event_notifier_test_and_clear(intp->interrupt);
241 qemu_mutex_unlock(&vdev->intp_mutex);
242 return;
245 trace_vfio_platform_intp_interrupt(intp->pin,
246 event_notifier_get_fd(intp->interrupt));
248 ret = event_notifier_test_and_clear(intp->interrupt);
249 if (!ret) {
250 error_report("Error when clearing fd=%d (ret = %d)",
251 event_notifier_get_fd(intp->interrupt), ret);
254 intp->state = VFIO_IRQ_ACTIVE;
256 /* sets slow path */
257 vfio_mmap_set_enabled(vdev, false);
259 /* trigger the virtual IRQ */
260 qemu_set_irq(intp->qemuirq, 1);
263 * Schedule the mmap timer which will restore fastpath when no IRQ
264 * is active anymore
266 if (vdev->mmap_timeout) {
267 timer_mod(vdev->mmap_timer,
268 qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) +
269 vdev->mmap_timeout);
271 qemu_mutex_unlock(&vdev->intp_mutex);
275 * vfio_platform_eoi - IRQ completion routine
276 * @vbasedev: the VFIO device handle
278 * De-asserts the active virtual IRQ and unmasks the physical IRQ
279 * (effective for level sensitive IRQ auto-masked by the VFIO driver).
280 * Then it handles next pending IRQ if any.
281 * eoi function is called on the first access to any MMIO region
282 * after an IRQ was triggered, trapped since slow path was set.
283 * It is assumed this access corresponds to the IRQ status
284 * register reset. With such a mechanism, a single IRQ can be
285 * handled at a time since there is no way to know which IRQ
286 * was completed by the guest (we would need additional details
287 * about the IRQ status register mask).
289 static void vfio_platform_eoi(VFIODevice *vbasedev)
291 VFIOINTp *intp;
292 VFIOPlatformDevice *vdev =
293 container_of(vbasedev, VFIOPlatformDevice, vbasedev);
295 qemu_mutex_lock(&vdev->intp_mutex);
296 QLIST_FOREACH(intp, &vdev->intp_list, next) {
297 if (intp->state == VFIO_IRQ_ACTIVE) {
298 trace_vfio_platform_eoi(intp->pin,
299 event_notifier_get_fd(intp->interrupt));
300 intp->state = VFIO_IRQ_INACTIVE;
302 /* deassert the virtual IRQ */
303 qemu_set_irq(intp->qemuirq, 0);
305 if (vfio_irq_is_automasked(intp)) {
306 /* unmasks the physical level-sensitive IRQ */
307 vfio_unmask_single_irqindex(vbasedev, intp->pin);
310 /* a single IRQ can be active at a time */
311 break;
314 /* in case there are pending IRQs, handle the first one */
315 if (!QSIMPLEQ_EMPTY(&vdev->pending_intp_queue)) {
316 intp = QSIMPLEQ_FIRST(&vdev->pending_intp_queue);
317 vfio_intp_inject_pending_lockheld(intp);
318 QSIMPLEQ_REMOVE_HEAD(&vdev->pending_intp_queue, pqnext);
320 qemu_mutex_unlock(&vdev->intp_mutex);
324 * vfio_start_eventfd_injection - starts the virtual IRQ injection using
325 * user-side handled eventfds
326 * @sbdev: the sysbus device handle
327 * @irq: the qemu irq handle
330 static void vfio_start_eventfd_injection(SysBusDevice *sbdev, qemu_irq irq)
332 int ret;
333 VFIOPlatformDevice *vdev = VFIO_PLATFORM_DEVICE(sbdev);
334 VFIOINTp *intp;
336 QLIST_FOREACH(intp, &vdev->intp_list, next) {
337 if (intp->qemuirq == irq) {
338 break;
341 assert(intp);
343 ret = vfio_set_trigger_eventfd(intp, vfio_intp_interrupt);
344 if (ret) {
345 error_report("vfio: failed to start eventfd signaling for IRQ %d: %m",
346 intp->pin);
347 abort();
352 * Functions used for irqfd
356 * vfio_set_resample_eventfd - sets the resamplefd for an IRQ
357 * @intp: the IRQ struct handle
358 * programs the VFIO driver to unmask this IRQ when the
359 * intp->unmask eventfd is triggered
361 static int vfio_set_resample_eventfd(VFIOINTp *intp)
363 VFIODevice *vbasedev = &intp->vdev->vbasedev;
364 struct vfio_irq_set *irq_set;
365 int argsz, ret;
366 int32_t *pfd;
368 argsz = sizeof(*irq_set) + sizeof(*pfd);
369 irq_set = g_malloc0(argsz);
370 irq_set->argsz = argsz;
371 irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD | VFIO_IRQ_SET_ACTION_UNMASK;
372 irq_set->index = intp->pin;
373 irq_set->start = 0;
374 irq_set->count = 1;
375 pfd = (int32_t *)&irq_set->data;
376 *pfd = event_notifier_get_fd(intp->unmask);
377 qemu_set_fd_handler(*pfd, NULL, NULL, NULL);
378 ret = ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, irq_set);
379 g_free(irq_set);
380 if (ret < 0) {
381 error_report("vfio: Failed to set resample eventfd: %m");
383 return ret;
387 * vfio_start_irqfd_injection - starts the virtual IRQ injection using
388 * irqfd
390 * @sbdev: the sysbus device handle
391 * @irq: the qemu irq handle
393 * In case the irqfd setup fails, we fallback to userspace handled eventfd
395 static void vfio_start_irqfd_injection(SysBusDevice *sbdev, qemu_irq irq)
397 VFIOPlatformDevice *vdev = VFIO_PLATFORM_DEVICE(sbdev);
398 VFIOINTp *intp;
400 if (!kvm_irqfds_enabled() || !kvm_resamplefds_enabled() ||
401 !vdev->irqfd_allowed) {
402 goto fail_irqfd;
405 QLIST_FOREACH(intp, &vdev->intp_list, next) {
406 if (intp->qemuirq == irq) {
407 break;
410 assert(intp);
412 if (kvm_irqchip_add_irqfd_notifier(kvm_state, intp->interrupt,
413 intp->unmask, irq) < 0) {
414 goto fail_irqfd;
417 if (vfio_set_trigger_eventfd(intp, NULL) < 0) {
418 goto fail_vfio;
420 if (vfio_irq_is_automasked(intp)) {
421 if (vfio_set_resample_eventfd(intp) < 0) {
422 goto fail_vfio;
424 trace_vfio_platform_start_level_irqfd_injection(intp->pin,
425 event_notifier_get_fd(intp->interrupt),
426 event_notifier_get_fd(intp->unmask));
427 } else {
428 trace_vfio_platform_start_edge_irqfd_injection(intp->pin,
429 event_notifier_get_fd(intp->interrupt));
432 intp->kvm_accel = true;
434 return;
435 fail_vfio:
436 kvm_irqchip_remove_irqfd_notifier(kvm_state, intp->interrupt, irq);
437 error_report("vfio: failed to start eventfd signaling for IRQ %d: %m",
438 intp->pin);
439 abort();
440 fail_irqfd:
441 vfio_start_eventfd_injection(sbdev, irq);
442 return;
445 /* VFIO skeleton */
447 static void vfio_platform_compute_needs_reset(VFIODevice *vbasedev)
449 vbasedev->needs_reset = true;
452 /* not implemented yet */
453 static int vfio_platform_hot_reset_multi(VFIODevice *vbasedev)
455 return -1;
459 * vfio_populate_device - Allocate and populate MMIO region
460 * and IRQ structs according to driver returned information
461 * @vbasedev: the VFIO device handle
464 static int vfio_populate_device(VFIODevice *vbasedev)
466 VFIOINTp *intp, *tmp;
467 int i, ret = -1;
468 VFIOPlatformDevice *vdev =
469 container_of(vbasedev, VFIOPlatformDevice, vbasedev);
471 if (!(vbasedev->flags & VFIO_DEVICE_FLAGS_PLATFORM)) {
472 error_report("vfio: Um, this isn't a platform device");
473 return ret;
476 vdev->regions = g_new0(VFIORegion *, vbasedev->num_regions);
478 for (i = 0; i < vbasedev->num_regions; i++) {
479 struct vfio_region_info reg_info = { .argsz = sizeof(reg_info) };
480 VFIORegion *ptr;
482 vdev->regions[i] = g_new0(VFIORegion, 1);
483 ptr = vdev->regions[i];
484 reg_info.index = i;
485 ret = ioctl(vbasedev->fd, VFIO_DEVICE_GET_REGION_INFO, &reg_info);
486 if (ret) {
487 error_report("vfio: Error getting region %d info: %m", i);
488 goto reg_error;
490 ptr->flags = reg_info.flags;
491 ptr->size = reg_info.size;
492 ptr->fd_offset = reg_info.offset;
493 ptr->nr = i;
494 ptr->vbasedev = vbasedev;
496 trace_vfio_platform_populate_regions(ptr->nr,
497 (unsigned long)ptr->flags,
498 (unsigned long)ptr->size,
499 ptr->vbasedev->fd,
500 (unsigned long)ptr->fd_offset);
503 vdev->mmap_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL,
504 vfio_intp_mmap_enable, vdev);
506 QSIMPLEQ_INIT(&vdev->pending_intp_queue);
508 for (i = 0; i < vbasedev->num_irqs; i++) {
509 struct vfio_irq_info irq = { .argsz = sizeof(irq) };
511 irq.index = i;
512 ret = ioctl(vbasedev->fd, VFIO_DEVICE_GET_IRQ_INFO, &irq);
513 if (ret) {
514 error_printf("vfio: error getting device %s irq info",
515 vbasedev->name);
516 goto irq_err;
517 } else {
518 trace_vfio_platform_populate_interrupts(irq.index,
519 irq.count,
520 irq.flags);
521 intp = vfio_init_intp(vbasedev, irq);
522 if (!intp) {
523 error_report("vfio: Error installing IRQ %d up", i);
524 goto irq_err;
528 return 0;
529 irq_err:
530 timer_del(vdev->mmap_timer);
531 QLIST_FOREACH_SAFE(intp, &vdev->intp_list, next, tmp) {
532 QLIST_REMOVE(intp, next);
533 g_free(intp);
535 reg_error:
536 for (i = 0; i < vbasedev->num_regions; i++) {
537 g_free(vdev->regions[i]);
539 g_free(vdev->regions);
540 return ret;
543 /* specialized functions for VFIO Platform devices */
544 static VFIODeviceOps vfio_platform_ops = {
545 .vfio_compute_needs_reset = vfio_platform_compute_needs_reset,
546 .vfio_hot_reset_multi = vfio_platform_hot_reset_multi,
547 .vfio_eoi = vfio_platform_eoi,
551 * vfio_base_device_init - perform preliminary VFIO setup
552 * @vbasedev: the VFIO device handle
554 * Implement the VFIO command sequence that allows to discover
555 * assigned device resources: group extraction, device
556 * fd retrieval, resource query.
557 * Precondition: the device name must be initialized
559 static int vfio_base_device_init(VFIODevice *vbasedev)
561 VFIOGroup *group;
562 VFIODevice *vbasedev_iter;
563 char path[PATH_MAX], iommu_group_path[PATH_MAX], *group_name;
564 ssize_t len;
565 struct stat st;
566 int groupid;
567 int ret;
569 /* name must be set prior to the call */
570 if (!vbasedev->name || strchr(vbasedev->name, '/')) {
571 return -EINVAL;
574 /* Check that the host device exists */
575 g_snprintf(path, sizeof(path), "/sys/bus/platform/devices/%s/",
576 vbasedev->name);
578 if (stat(path, &st) < 0) {
579 error_report("vfio: error: no such host device: %s", path);
580 return -errno;
583 g_strlcat(path, "iommu_group", sizeof(path));
584 len = readlink(path, iommu_group_path, sizeof(iommu_group_path));
585 if (len < 0 || len >= sizeof(iommu_group_path)) {
586 error_report("vfio: error no iommu_group for device");
587 return len < 0 ? -errno : -ENAMETOOLONG;
590 iommu_group_path[len] = 0;
591 group_name = basename(iommu_group_path);
593 if (sscanf(group_name, "%d", &groupid) != 1) {
594 error_report("vfio: error reading %s: %m", path);
595 return -errno;
598 trace_vfio_platform_base_device_init(vbasedev->name, groupid);
600 group = vfio_get_group(groupid, &address_space_memory);
601 if (!group) {
602 error_report("vfio: failed to get group %d", groupid);
603 return -ENOENT;
606 g_snprintf(path, sizeof(path), "%s", vbasedev->name);
608 QLIST_FOREACH(vbasedev_iter, &group->device_list, next) {
609 if (strcmp(vbasedev_iter->name, vbasedev->name) == 0) {
610 error_report("vfio: error: device %s is already attached", path);
611 vfio_put_group(group);
612 return -EBUSY;
615 ret = vfio_get_device(group, path, vbasedev);
616 if (ret) {
617 error_report("vfio: failed to get device %s", path);
618 vfio_put_group(group);
619 return ret;
622 ret = vfio_populate_device(vbasedev);
623 if (ret) {
624 error_report("vfio: failed to populate device %s", path);
625 vfio_put_group(group);
628 return ret;
632 * vfio_map_region - initialize the 2 memory regions for a given
633 * MMIO region index
634 * @vdev: the VFIO platform device handle
635 * @nr: the index of the region
637 * Init the top memory region and the mmapped memory region beneath
638 * VFIOPlatformDevice is used since VFIODevice is not a QOM Object
639 * and could not be passed to memory region functions
641 static void vfio_map_region(VFIOPlatformDevice *vdev, int nr)
643 VFIORegion *region = vdev->regions[nr];
644 uint64_t size = region->size;
645 char name[64];
647 if (!size) {
648 return;
651 g_snprintf(name, sizeof(name), "VFIO %s region %d",
652 vdev->vbasedev.name, nr);
654 /* A "slow" read/write mapping underlies all regions */
655 memory_region_init_io(&region->mem, OBJECT(vdev), &vfio_region_ops,
656 region, name, size);
658 g_strlcat(name, " mmap", sizeof(name));
660 if (vfio_mmap_region(OBJECT(vdev), region, &region->mem,
661 &region->mmap_mem, &region->mmap, size, 0, name)) {
662 error_report("%s unsupported. Performance may be slow", name);
667 * vfio_platform_realize - the device realize function
668 * @dev: device state pointer
669 * @errp: error
671 * initialize the device, its memory regions and IRQ structures
672 * IRQ are started separately
674 static void vfio_platform_realize(DeviceState *dev, Error **errp)
676 VFIOPlatformDevice *vdev = VFIO_PLATFORM_DEVICE(dev);
677 SysBusDevice *sbdev = SYS_BUS_DEVICE(dev);
678 VFIODevice *vbasedev = &vdev->vbasedev;
679 int i, ret;
681 vbasedev->type = VFIO_DEVICE_TYPE_PLATFORM;
682 vbasedev->ops = &vfio_platform_ops;
684 trace_vfio_platform_realize(vbasedev->name, vdev->compat);
686 ret = vfio_base_device_init(vbasedev);
687 if (ret) {
688 error_setg(errp, "vfio: vfio_base_device_init failed for %s",
689 vbasedev->name);
690 return;
693 for (i = 0; i < vbasedev->num_regions; i++) {
694 vfio_map_region(vdev, i);
695 sysbus_init_mmio(sbdev, &vdev->regions[i]->mem);
699 static const VMStateDescription vfio_platform_vmstate = {
700 .name = TYPE_VFIO_PLATFORM,
701 .unmigratable = 1,
704 static Property vfio_platform_dev_properties[] = {
705 DEFINE_PROP_STRING("host", VFIOPlatformDevice, vbasedev.name),
706 DEFINE_PROP_BOOL("x-no-mmap", VFIOPlatformDevice, vbasedev.no_mmap, false),
707 DEFINE_PROP_UINT32("mmap-timeout-ms", VFIOPlatformDevice,
708 mmap_timeout, 1100),
709 DEFINE_PROP_BOOL("x-irqfd", VFIOPlatformDevice, irqfd_allowed, true),
710 DEFINE_PROP_END_OF_LIST(),
713 static void vfio_platform_class_init(ObjectClass *klass, void *data)
715 DeviceClass *dc = DEVICE_CLASS(klass);
716 SysBusDeviceClass *sbc = SYS_BUS_DEVICE_CLASS(klass);
718 dc->realize = vfio_platform_realize;
719 dc->props = vfio_platform_dev_properties;
720 dc->vmsd = &vfio_platform_vmstate;
721 dc->desc = "VFIO-based platform device assignment";
722 sbc->connect_irq_notifier = vfio_start_irqfd_injection;
723 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
726 static const TypeInfo vfio_platform_dev_info = {
727 .name = TYPE_VFIO_PLATFORM,
728 .parent = TYPE_SYS_BUS_DEVICE,
729 .instance_size = sizeof(VFIOPlatformDevice),
730 .class_init = vfio_platform_class_init,
731 .class_size = sizeof(VFIOPlatformDeviceClass),
732 .abstract = true,
735 static void register_vfio_platform_dev_type(void)
737 type_register_static(&vfio_platform_dev_info);
740 type_init(register_vfio_platform_dev_type)