aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/vfio
diff options
context:
space:
mode:
authorAntonios Motakis <a.motakis@virtualopensystems.com>2015-03-16 16:08:53 -0400
committerAlex Williamson <alex.williamson@redhat.com>2015-03-16 16:08:53 -0400
commit09bbcb8810c4673cb96477e0e83c9bcdfadc7741 (patch)
tree73ad0b7630c6287f949b803089fb162973c8c13e /drivers/vfio
parent9269c393e7a971f98c0f54d7fc350ac7636d1fa5 (diff)
vfio: pass an opaque pointer on virqfd initialization
VFIO_PCI passes the VFIO device structure *vdev via eventfd to the handler that implements masking/unmasking of IRQs via an eventfd. We can replace it in the virqfd infrastructure with an opaque type so we can make use of the mechanism from other VFIO bus drivers. Signed-off-by: Antonios Motakis <a.motakis@virtualopensystems.com> Signed-off-by: Baptiste Reynal <b.reynal@virtualopensystems.com> Reviewed-by: Eric Auger <eric.auger@linaro.org> Tested-by: Eric Auger <eric.auger@linaro.org> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Diffstat (limited to 'drivers/vfio')
-rw-r--r--drivers/vfio/pci/vfio_pci_intrs.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c
index de069796b2fd..c84a129cc527 100644
--- a/drivers/vfio/pci/vfio_pci_intrs.c
+++ b/drivers/vfio/pci/vfio_pci_intrs.c
@@ -31,10 +31,10 @@
31 * IRQfd - generic 31 * IRQfd - generic
32 */ 32 */
33struct virqfd { 33struct virqfd {
34 struct vfio_pci_device *vdev; 34 void *opaque;
35 struct eventfd_ctx *eventfd; 35 struct eventfd_ctx *eventfd;
36 int (*handler)(struct vfio_pci_device *, void *); 36 int (*handler)(void *, void *);
37 void (*thread)(struct vfio_pci_device *, void *); 37 void (*thread)(void *, void *);
38 void *data; 38 void *data;
39 struct work_struct inject; 39 struct work_struct inject;
40 wait_queue_t wait; 40 wait_queue_t wait;
@@ -74,7 +74,7 @@ static int virqfd_wakeup(wait_queue_t *wait, unsigned mode, int sync, void *key)
74 if (flags & POLLIN) { 74 if (flags & POLLIN) {
75 /* An event has been signaled, call function */ 75 /* An event has been signaled, call function */
76 if ((!virqfd->handler || 76 if ((!virqfd->handler ||
77 virqfd->handler(virqfd->vdev, virqfd->data)) && 77 virqfd->handler(virqfd->opaque, virqfd->data)) &&
78 virqfd->thread) 78 virqfd->thread)
79 schedule_work(&virqfd->inject); 79 schedule_work(&virqfd->inject);
80 } 80 }
@@ -124,12 +124,12 @@ static void virqfd_inject(struct work_struct *work)
124{ 124{
125 struct virqfd *virqfd = container_of(work, struct virqfd, inject); 125 struct virqfd *virqfd = container_of(work, struct virqfd, inject);
126 if (virqfd->thread) 126 if (virqfd->thread)
127 virqfd->thread(virqfd->vdev, virqfd->data); 127 virqfd->thread(virqfd->opaque, virqfd->data);
128} 128}
129 129
130int vfio_virqfd_enable(struct vfio_pci_device *vdev, 130int vfio_virqfd_enable(void *opaque,
131 int (*handler)(struct vfio_pci_device *, void *), 131 int (*handler)(void *, void *),
132 void (*thread)(struct vfio_pci_device *, void *), 132 void (*thread)(void *, void *),
133 void *data, struct virqfd **pvirqfd, int fd) 133 void *data, struct virqfd **pvirqfd, int fd)
134{ 134{
135 struct fd irqfd; 135 struct fd irqfd;
@@ -143,7 +143,7 @@ int vfio_virqfd_enable(struct vfio_pci_device *vdev,
143 return -ENOMEM; 143 return -ENOMEM;
144 144
145 virqfd->pvirqfd = pvirqfd; 145 virqfd->pvirqfd = pvirqfd;
146 virqfd->vdev = vdev; 146 virqfd->opaque = opaque;
147 virqfd->handler = handler; 147 virqfd->handler = handler;
148 virqfd->thread = thread; 148 virqfd->thread = thread;
149 virqfd->data = data; 149 virqfd->data = data;
@@ -196,7 +196,7 @@ int vfio_virqfd_enable(struct vfio_pci_device *vdev,
196 * before we registered and trigger it as if we didn't miss it. 196 * before we registered and trigger it as if we didn't miss it.
197 */ 197 */
198 if (events & POLLIN) { 198 if (events & POLLIN) {
199 if ((!handler || handler(vdev, data)) && thread) 199 if ((!handler || handler(opaque, data)) && thread)
200 schedule_work(&virqfd->inject); 200 schedule_work(&virqfd->inject);
201 } 201 }
202 202
@@ -243,8 +243,10 @@ EXPORT_SYMBOL_GPL(vfio_virqfd_disable);
243/* 243/*
244 * INTx 244 * INTx
245 */ 245 */
246static void vfio_send_intx_eventfd(struct vfio_pci_device *vdev, void *unused) 246static void vfio_send_intx_eventfd(void *opaque, void *unused)
247{ 247{
248 struct vfio_pci_device *vdev = opaque;
249
248 if (likely(is_intx(vdev) && !vdev->virq_disabled)) 250 if (likely(is_intx(vdev) && !vdev->virq_disabled))
249 eventfd_signal(vdev->ctx[0].trigger, 1); 251 eventfd_signal(vdev->ctx[0].trigger, 1);
250} 252}
@@ -287,9 +289,9 @@ void vfio_pci_intx_mask(struct vfio_pci_device *vdev)
287 * a signal is necessary, which can then be handled via a work queue 289 * a signal is necessary, which can then be handled via a work queue
288 * or directly depending on the caller. 290 * or directly depending on the caller.
289 */ 291 */
290static int vfio_pci_intx_unmask_handler(struct vfio_pci_device *vdev, 292static int vfio_pci_intx_unmask_handler(void *opaque, void *unused)
291 void *unused)
292{ 293{
294 struct vfio_pci_device *vdev = opaque;
293 struct pci_dev *pdev = vdev->pdev; 295 struct pci_dev *pdev = vdev->pdev;
294 unsigned long flags; 296 unsigned long flags;
295 int ret = 0; 297 int ret = 0;
@@ -641,7 +643,7 @@ static int vfio_pci_set_intx_unmask(struct vfio_pci_device *vdev,
641 } else if (flags & VFIO_IRQ_SET_DATA_EVENTFD) { 643 } else if (flags & VFIO_IRQ_SET_DATA_EVENTFD) {
642 int32_t fd = *(int32_t *)data; 644 int32_t fd = *(int32_t *)data;
643 if (fd >= 0) 645 if (fd >= 0)
644 return vfio_virqfd_enable(vdev, 646 return vfio_virqfd_enable((void *) vdev,
645 vfio_pci_intx_unmask_handler, 647 vfio_pci_intx_unmask_handler,
646 vfio_send_intx_eventfd, NULL, 648 vfio_send_intx_eventfd, NULL,
647 &vdev->ctx[0].unmask, fd); 649 &vdev->ctx[0].unmask, fd);