]> git.karo-electronics.de Git - linux-beck.git/commitdiff
vfio/platform: initial interrupts support code
authorAntonios Motakis <a.motakis@virtualopensystems.com>
Mon, 16 Mar 2015 20:08:49 +0000 (14:08 -0600)
committerAlex Williamson <alex.williamson@redhat.com>
Mon, 16 Mar 2015 20:08:49 +0000 (14:08 -0600)
This patch is a skeleton for the VFIO_DEVICE_SET_IRQS IOCTL, around which
most IRQ functionality is implemented in VFIO.

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>
drivers/vfio/platform/vfio_platform_common.c
drivers/vfio/platform/vfio_platform_irq.c
drivers/vfio/platform/vfio_platform_private.h

index 908d5101e0531d4ebcc993149c90be26ce4fa552..abcff7a1aa667babd2e56cbea20ebdce73fc7fd7 100644 (file)
@@ -205,10 +205,54 @@ static long vfio_platform_ioctl(void *device_data,
 
                return copy_to_user((void __user *)arg, &info, minsz);
 
-       } else if (cmd == VFIO_DEVICE_SET_IRQS)
-               return -EINVAL;
+       } else if (cmd == VFIO_DEVICE_SET_IRQS) {
+               struct vfio_irq_set hdr;
+               u8 *data = NULL;
+               int ret = 0;
+
+               minsz = offsetofend(struct vfio_irq_set, count);
+
+               if (copy_from_user(&hdr, (void __user *)arg, minsz))
+                       return -EFAULT;
+
+               if (hdr.argsz < minsz)
+                       return -EINVAL;
+
+               if (hdr.index >= vdev->num_irqs)
+                       return -EINVAL;
+
+               if (hdr.flags & ~(VFIO_IRQ_SET_DATA_TYPE_MASK |
+                                 VFIO_IRQ_SET_ACTION_TYPE_MASK))
+                       return -EINVAL;
 
-       else if (cmd == VFIO_DEVICE_RESET)
+               if (!(hdr.flags & VFIO_IRQ_SET_DATA_NONE)) {
+                       size_t size;
+
+                       if (hdr.flags & VFIO_IRQ_SET_DATA_BOOL)
+                               size = sizeof(uint8_t);
+                       else if (hdr.flags & VFIO_IRQ_SET_DATA_EVENTFD)
+                               size = sizeof(int32_t);
+                       else
+                               return -EINVAL;
+
+                       if (hdr.argsz - minsz < size)
+                               return -EINVAL;
+
+                       data = memdup_user((void __user *)(arg + minsz), size);
+                       if (IS_ERR(data))
+                               return PTR_ERR(data);
+               }
+
+               mutex_lock(&vdev->igate);
+
+               ret = vfio_platform_set_irqs_ioctl(vdev, hdr.flags, hdr.index,
+                                                  hdr.start, hdr.count, data);
+               mutex_unlock(&vdev->igate);
+               kfree(data);
+
+               return ret;
+
+       } else if (cmd == VFIO_DEVICE_RESET)
                return -EINVAL;
 
        return -ENOTTY;
@@ -458,6 +502,8 @@ int vfio_platform_probe_common(struct vfio_platform_device *vdev,
                return ret;
        }
 
+       mutex_init(&vdev->igate);
+
        return 0;
 }
 EXPORT_SYMBOL_GPL(vfio_platform_probe_common);
index c6c3ec1b9f8288a02b23329fbef5afc73ec4d89c..df5c91936a6899eb51cdd5b2b093da5478625ce2 100644 (file)
 
 #include "vfio_platform_private.h"
 
+static int vfio_platform_set_irq_mask(struct vfio_platform_device *vdev,
+                                     unsigned index, unsigned start,
+                                     unsigned count, uint32_t flags,
+                                     void *data)
+{
+       return -EINVAL;
+}
+
+static int vfio_platform_set_irq_unmask(struct vfio_platform_device *vdev,
+                                       unsigned index, unsigned start,
+                                       unsigned count, uint32_t flags,
+                                       void *data)
+{
+       return -EINVAL;
+}
+
+static int vfio_platform_set_irq_trigger(struct vfio_platform_device *vdev,
+                                        unsigned index, unsigned start,
+                                        unsigned count, uint32_t flags,
+                                        void *data)
+{
+       return -EINVAL;
+}
+
+int vfio_platform_set_irqs_ioctl(struct vfio_platform_device *vdev,
+                                uint32_t flags, unsigned index, unsigned start,
+                                unsigned count, void *data)
+{
+       int (*func)(struct vfio_platform_device *vdev, unsigned index,
+                   unsigned start, unsigned count, uint32_t flags,
+                   void *data) = NULL;
+
+       switch (flags & VFIO_IRQ_SET_ACTION_TYPE_MASK) {
+       case VFIO_IRQ_SET_ACTION_MASK:
+               func = vfio_platform_set_irq_mask;
+               break;
+       case VFIO_IRQ_SET_ACTION_UNMASK:
+               func = vfio_platform_set_irq_unmask;
+               break;
+       case VFIO_IRQ_SET_ACTION_TRIGGER:
+               func = vfio_platform_set_irq_trigger;
+               break;
+       }
+
+       if (!func)
+               return -ENOTTY;
+
+       return func(vdev, index, start, count, flags, data);
+}
+
 int vfio_platform_irq_init(struct vfio_platform_device *vdev)
 {
        int cnt = 0, i;
@@ -35,13 +85,22 @@ int vfio_platform_irq_init(struct vfio_platform_device *vdev)
                return -ENOMEM;
 
        for (i = 0; i < cnt; i++) {
+               int hwirq = vdev->get_irq(vdev, i);
+
+               if (hwirq < 0)
+                       goto err;
+
                vdev->irqs[i].flags = 0;
                vdev->irqs[i].count = 1;
+               vdev->irqs[i].hwirq = hwirq;
        }
 
        vdev->num_irqs = cnt;
 
        return 0;
+err:
+       kfree(vdev->irqs);
+       return -EINVAL;
 }
 
 void vfio_platform_irq_cleanup(struct vfio_platform_device *vdev)
index a2e286ed1407786f8d46fc9405f5e99e7b7b065d..b119a6c5ac23da8d6df36abe82c3e44cab13b705 100644 (file)
@@ -30,6 +30,7 @@
 struct vfio_platform_irq {
        u32                     flags;
        u32                     count;
+       int                     hwirq;
 };
 
 struct vfio_platform_region {
@@ -48,6 +49,7 @@ struct vfio_platform_device {
        struct vfio_platform_irq        *irqs;
        u32                             num_irqs;
        int                             refcnt;
+       struct mutex                    igate;
 
        /*
         * These fields should be filled by the bus specific binder
@@ -69,4 +71,9 @@ extern struct vfio_platform_device *vfio_platform_remove_common
 extern int vfio_platform_irq_init(struct vfio_platform_device *vdev);
 extern void vfio_platform_irq_cleanup(struct vfio_platform_device *vdev);
 
+extern int vfio_platform_set_irqs_ioctl(struct vfio_platform_device *vdev,
+                                       uint32_t flags, unsigned index,
+                                       unsigned start, unsigned count,
+                                       void *data);
+
 #endif /* VFIO_PLATFORM_PRIVATE_H */