Introduces ioctl access to the VFIO AP Matrix device driver
by implementing the VFIO_DEVICE_GET_INFO ioctl. This ioctl
provides the VFIO AP Matrix device driver information to the
guest machine.

Reviewed-by: Pierre Morel <pmo...@linux.vnet.ibm.com>
Signed-off-by: Tony Krowiak <akrow...@linux.vnet.ibm.com>
---
 drivers/s390/crypto/vfio_ap_ops.c |   43 +++++++++++++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/drivers/s390/crypto/vfio_ap_ops.c 
b/drivers/s390/crypto/vfio_ap_ops.c
index e3ff5ab..00179cd 100644
--- a/drivers/s390/crypto/vfio_ap_ops.c
+++ b/drivers/s390/crypto/vfio_ap_ops.c
@@ -101,6 +101,48 @@ static void vfio_ap_mdev_release(struct mdev_device *mdev)
                                 &matrix_mdev->group_notifier);
 }
 
+static int vfio_ap_mdev_get_device_info(unsigned long arg)
+{
+       unsigned long minsz;
+       struct vfio_device_info info;
+
+       minsz = offsetofend(struct vfio_device_info, num_irqs);
+
+       if (copy_from_user(&info, (void __user *)arg, minsz))
+               return -EFAULT;
+
+       if (info.argsz < minsz) {
+               pr_err("%s: Argument size %u less than min size %li",
+                      VFIO_AP_MODULE_NAME, info.argsz, minsz);
+               return -EINVAL;
+       }
+
+       info.flags = VFIO_DEVICE_FLAGS_AP;
+       info.num_regions = 0;
+       info.num_irqs = 0;
+
+       return copy_to_user((void __user *)arg, &info, minsz);
+}
+
+static ssize_t vfio_ap_mdev_ioctl(struct mdev_device *mdev,
+                                   unsigned int cmd, unsigned long arg)
+{
+       int ret;
+
+       switch (cmd) {
+       case VFIO_DEVICE_GET_INFO:
+               ret = vfio_ap_mdev_get_device_info(arg);
+               break;
+       default:
+               pr_err("%s: ioctl command %d is not a supported command",
+                      VFIO_AP_MODULE_NAME, cmd);
+               ret = -EOPNOTSUPP;
+               break;
+       }
+
+       return ret;
+}
+
 static ssize_t name_show(struct kobject *kobj, struct device *dev, char *buf)
 {
        return sprintf(buf, "%s\n", VFIO_AP_MDEV_NAME_HWVIRT);
@@ -804,6 +846,7 @@ static ssize_t matrix_show(struct device *dev, struct 
device_attribute *attr,
        .remove                 = vfio_ap_mdev_remove,
        .open                   = vfio_ap_mdev_open,
        .release                = vfio_ap_mdev_release,
+       .ioctl                  = vfio_ap_mdev_ioctl,
 };
 
 int vfio_ap_mdev_register(struct ap_matrix *ap_matrix)
-- 
1.7.1

Reply via email to