vfio/platform: initial interrupts support code

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>
This commit is contained in:
Antonios Motakis 2015-03-16 14:08:49 -06:00 коммит произвёл Alex Williamson
Родитель 682704c41e
Коммит 9a36321c8d
3 изменённых файлов: 115 добавлений и 3 удалений

Просмотреть файл

@ -205,10 +205,54 @@ static long vfio_platform_ioctl(void *device_data,
return copy_to_user((void __user *)arg, &info, minsz); return copy_to_user((void __user *)arg, &info, minsz);
} else if (cmd == VFIO_DEVICE_SET_IRQS) } else if (cmd == VFIO_DEVICE_SET_IRQS) {
return -EINVAL; struct vfio_irq_set hdr;
u8 *data = NULL;
int ret = 0;
else if (cmd == VFIO_DEVICE_RESET) 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;
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 -EINVAL;
return -ENOTTY; return -ENOTTY;
@ -458,6 +502,8 @@ int vfio_platform_probe_common(struct vfio_platform_device *vdev,
return ret; return ret;
} }
mutex_init(&vdev->igate);
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(vfio_platform_probe_common); EXPORT_SYMBOL_GPL(vfio_platform_probe_common);

Просмотреть файл

@ -23,6 +23,56 @@
#include "vfio_platform_private.h" #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 vfio_platform_irq_init(struct vfio_platform_device *vdev)
{ {
int cnt = 0, i; int cnt = 0, i;
@ -35,13 +85,22 @@ int vfio_platform_irq_init(struct vfio_platform_device *vdev)
return -ENOMEM; return -ENOMEM;
for (i = 0; i < cnt; i++) { 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].flags = 0;
vdev->irqs[i].count = 1; vdev->irqs[i].count = 1;
vdev->irqs[i].hwirq = hwirq;
} }
vdev->num_irqs = cnt; vdev->num_irqs = cnt;
return 0; return 0;
err:
kfree(vdev->irqs);
return -EINVAL;
} }
void vfio_platform_irq_cleanup(struct vfio_platform_device *vdev) void vfio_platform_irq_cleanup(struct vfio_platform_device *vdev)

Просмотреть файл

@ -30,6 +30,7 @@
struct vfio_platform_irq { struct vfio_platform_irq {
u32 flags; u32 flags;
u32 count; u32 count;
int hwirq;
}; };
struct vfio_platform_region { struct vfio_platform_region {
@ -48,6 +49,7 @@ struct vfio_platform_device {
struct vfio_platform_irq *irqs; struct vfio_platform_irq *irqs;
u32 num_irqs; u32 num_irqs;
int refcnt; int refcnt;
struct mutex igate;
/* /*
* These fields should be filled by the bus specific binder * 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 int vfio_platform_irq_init(struct vfio_platform_device *vdev);
extern void vfio_platform_irq_cleanup(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 */ #endif /* VFIO_PLATFORM_PRIVATE_H */