@@ -33,5 +33,7 @@ int qemu_vfio_pci_init_irq(QEMUVFIOState *s, EventNotifier *e,
int irq_type, Error **errp);
int qemu_vfio_pci_msix_init_irqs(QEMUVFIOState *s,
unsigned *irq_count, Error **errp);
+int qemu_vfio_pci_msix_set_irq(QEMUVFIOState *s, unsigned irq_index,
+ EventNotifier *notifier, Error **errp);
#endif
@@ -232,6 +232,41 @@ int qemu_vfio_pci_init_irq(QEMUVFIOState *s, EventNotifier *e,
return 0;
}
+/**
+ * Initialize a MSIX IRQ and register its event notifier.
+ * @irq_index: MSIX IRQ index
+ * @notifier: notifier for the MSIX IRQ
+ */
+int qemu_vfio_pci_msix_set_irq(QEMUVFIOState *s, unsigned irq_index,
+ EventNotifier *notifier, Error **errp)
+{
+ int r;
+ int fd = event_notifier_get_fd(notifier);
+ size_t irq_set_size;
+ struct vfio_irq_set *irq_set;
+
+ trace_qemu_vfio_pci_msix_set_irq(irq_index, fd);
+ irq_set_size = sizeof(*irq_set) + sizeof(int32_t);
+ irq_set = g_malloc0(irq_set_size);
+ /* Get to a known IRQ state */
+ *irq_set = (struct vfio_irq_set) {
+ .argsz = irq_set_size,
+ .flags = VFIO_IRQ_SET_DATA_EVENTFD | VFIO_IRQ_SET_ACTION_TRIGGER,
+ .index = VFIO_PCI_MSIX_IRQ_INDEX,
+ .start = irq_index,
+ .count = 1,
+ };
+ ((int32_t *)&irq_set->data)[0] = fd;
+ r = ioctl(s->device, VFIO_DEVICE_SET_IRQS, irq_set);
+ g_free(irq_set);
+ if (r) {
+ error_setg_errno(errp, errno, "Failed to setup device interrupt #%u",
+ irq_index);
+ return -errno;
+ }
+ return 0;
+}
+
/**
* Initialize device MSIX IRQs and register event notifiers.
* @irq_count: pointer to number of MSIX IRQs to initialize
@@ -88,6 +88,7 @@ qemu_vfio_dma_map(void *s, void *host, size_t size, bool temporary, uint64_t *io
qemu_vfio_dma_mapped(void *s, void *host, uint64_t iova, size_t size) "s %p host %p <-> iova 0x%"PRIx64" size 0x%zx"
qemu_vfio_dma_unmap(void *s, void *host) "s %p host %p"
qemu_vfio_msix_info_irqs(uint32_t count, unsigned asked) "msix irqs %"PRIu32" (asked: %u)"
+qemu_vfio_pci_msix_set_irq(unsigned irq_index, int fd) "msix irq %u notifier_fd %d"
qemu_vfio_iommu_iova_pgsizes(uint64_t iova_pgsizes) "iommu page size bitmask: 0x%08"PRIx64
qemu_vfio_pci_read_config(void *buf, int ofs, int size, uint64_t region_ofs, uint64_t region_size) "read cfg ptr %p ofs 0x%x size %d (region ofs 0x%"PRIx64" size %"PRId64")"
qemu_vfio_pci_write_config(void *buf, int ofs, int size, uint64_t region_ofs, uint64_t region_size) "write cfg ptr %p ofs 0x%x size %d (region ofs 0x%"PRIx64" size %"PRId64")"
Introduce qemu_vfio_pci_msix_set_irq() to set the event notifier of a specific MSIX IRQ. All other registered IRQs are left unmodified. Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> --- include/qemu/vfio-helpers.h | 2 ++ util/vfio-helpers.c | 35 +++++++++++++++++++++++++++++++++++ util/trace-events | 1 + 3 files changed, 38 insertions(+)