blob: 7ec03050506fe32eb566e0315a3ccc754459548f [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001From a548dc00536e2cc6e7e7f95487f5261b3133a0d7 Mon Sep 17 00:00:00 2001
2From: Diana Craciun <diana.craciun@nxp.com>
3Date: Wed, 18 Sep 2019 18:26:14 +0300
4Subject: [PATCH] vfio/fsl-mc: Implement VFIO_DEVICE_GET_INFO ioctl
5
6Allow userspace to get fsl-mc device info (number of regions
7and irqs).
8
9Signed-off-by: Bharat Bhushan <Bharat.Bhushan@nxp.com>
10Signed-off-by: Diana Craciun <diana.craciun@nxp.com>
11---
12 drivers/vfio/fsl-mc/vfio_fsl_mc.c | 22 +++++++++++++++++++++-
13 1 file changed, 21 insertions(+), 1 deletion(-)
14
15--- a/drivers/vfio/fsl-mc/vfio_fsl_mc.c
16+++ b/drivers/vfio/fsl-mc/vfio_fsl_mc.c
17@@ -32,10 +32,30 @@ static void vfio_fsl_mc_release(void *de
18 static long vfio_fsl_mc_ioctl(void *device_data, unsigned int cmd,
19 unsigned long arg)
20 {
21+ unsigned long minsz;
22+ struct vfio_fsl_mc_device *vdev = device_data;
23+ struct fsl_mc_device *mc_dev = vdev->mc_dev;
24+
25 switch (cmd) {
26 case VFIO_DEVICE_GET_INFO:
27 {
28- return -EINVAL;
29+ struct vfio_device_info info;
30+
31+ minsz = offsetofend(struct vfio_device_info, num_irqs);
32+
33+ if (copy_from_user(&info, (void __user *)arg, minsz))
34+ return -EFAULT;
35+
36+ if (info.argsz < minsz)
37+ return -EINVAL;
38+
39+ info.flags = VFIO_DEVICE_FLAGS_FSL_MC;
40+ info.num_regions = mc_dev->obj_desc.region_count;
41+ info.num_irqs = mc_dev->obj_desc.irq_count;
42+
43+ return copy_to_user((void __user *)arg, &info, minsz) ?
44+ -EFAULT : 0;
45+
46 }
47 case VFIO_DEVICE_GET_REGION_INFO:
48 {