mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-12-27 11:06:41 -05:00
vfio/platform: Provide a get_region_info op
Move it out of vfio_platform_ioctl() and re-indent it. Add it to all platform drivers. Reviewed-by: Kevin Tian <kevin.tian@intel.com> Reviewed-by: Pranjal Shrivastava <praan@google.com> Reviewed-by: Mostafa Saleh <smostafa@google.com> Reviewed-by: Eric Auger <eric.auger@redhat.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Link: https://lore.kernel.org/r/9-v2-2a9e24d62f1b+e10a-vfio_get_region_info_op_jgg@nvidia.com Signed-off-by: Alex Williamson <alex@shazbot.org>
This commit is contained in:
committed by
Alex Williamson
parent
8339fccda8
commit
d4635df279
@@ -115,6 +115,7 @@ static const struct vfio_device_ops vfio_amba_ops = {
|
||||
.open_device = vfio_platform_open_device,
|
||||
.close_device = vfio_platform_close_device,
|
||||
.ioctl = vfio_platform_ioctl,
|
||||
.get_region_info = vfio_platform_ioctl_get_region_info,
|
||||
.read = vfio_platform_read,
|
||||
.write = vfio_platform_write,
|
||||
.mmap = vfio_platform_mmap,
|
||||
|
||||
@@ -101,6 +101,7 @@ static const struct vfio_device_ops vfio_platform_ops = {
|
||||
.open_device = vfio_platform_open_device,
|
||||
.close_device = vfio_platform_close_device,
|
||||
.ioctl = vfio_platform_ioctl,
|
||||
.get_region_info = vfio_platform_ioctl_get_region_info,
|
||||
.read = vfio_platform_read,
|
||||
.write = vfio_platform_write,
|
||||
.mmap = vfio_platform_mmap,
|
||||
|
||||
@@ -272,6 +272,34 @@ int vfio_platform_open_device(struct vfio_device *core_vdev)
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(vfio_platform_open_device);
|
||||
|
||||
int vfio_platform_ioctl_get_region_info(struct vfio_device *core_vdev,
|
||||
struct vfio_region_info __user *arg)
|
||||
{
|
||||
struct vfio_platform_device *vdev =
|
||||
container_of(core_vdev, struct vfio_platform_device, vdev);
|
||||
struct vfio_region_info info;
|
||||
unsigned long minsz;
|
||||
|
||||
minsz = offsetofend(struct vfio_region_info, offset);
|
||||
|
||||
if (copy_from_user(&info, arg, minsz))
|
||||
return -EFAULT;
|
||||
|
||||
if (info.argsz < minsz)
|
||||
return -EINVAL;
|
||||
|
||||
if (info.index >= vdev->num_regions)
|
||||
return -EINVAL;
|
||||
|
||||
/* map offset to the physical address */
|
||||
info.offset = VFIO_PLATFORM_INDEX_TO_OFFSET(info.index);
|
||||
info.size = vdev->regions[info.index].size;
|
||||
info.flags = vdev->regions[info.index].flags;
|
||||
|
||||
return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(vfio_platform_ioctl_get_region_info);
|
||||
|
||||
long vfio_platform_ioctl(struct vfio_device *core_vdev,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
@@ -300,28 +328,6 @@ long vfio_platform_ioctl(struct vfio_device *core_vdev,
|
||||
return copy_to_user((void __user *)arg, &info, minsz) ?
|
||||
-EFAULT : 0;
|
||||
|
||||
} else if (cmd == VFIO_DEVICE_GET_REGION_INFO) {
|
||||
struct vfio_region_info info;
|
||||
|
||||
minsz = offsetofend(struct vfio_region_info, offset);
|
||||
|
||||
if (copy_from_user(&info, (void __user *)arg, minsz))
|
||||
return -EFAULT;
|
||||
|
||||
if (info.argsz < minsz)
|
||||
return -EINVAL;
|
||||
|
||||
if (info.index >= vdev->num_regions)
|
||||
return -EINVAL;
|
||||
|
||||
/* map offset to the physical address */
|
||||
info.offset = VFIO_PLATFORM_INDEX_TO_OFFSET(info.index);
|
||||
info.size = vdev->regions[info.index].size;
|
||||
info.flags = vdev->regions[info.index].flags;
|
||||
|
||||
return copy_to_user((void __user *)arg, &info, minsz) ?
|
||||
-EFAULT : 0;
|
||||
|
||||
} else if (cmd == VFIO_DEVICE_GET_IRQ_INFO) {
|
||||
struct vfio_irq_info info;
|
||||
|
||||
|
||||
@@ -85,6 +85,8 @@ int vfio_platform_open_device(struct vfio_device *core_vdev);
|
||||
void vfio_platform_close_device(struct vfio_device *core_vdev);
|
||||
long vfio_platform_ioctl(struct vfio_device *core_vdev,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
int vfio_platform_ioctl_get_region_info(struct vfio_device *core_vdev,
|
||||
struct vfio_region_info __user *arg);
|
||||
ssize_t vfio_platform_read(struct vfio_device *core_vdev,
|
||||
char __user *buf, size_t count,
|
||||
loff_t *ppos);
|
||||
|
||||
Reference in New Issue
Block a user