Commit 7f11e689 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Zhi Wang

drm/i915/gvt: pass a struct intel_vgpu to the vfio read/write helpers

Pass the structure we actually care about instead of deriving it from
the mdev_device in the lower level code.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarZhi Wang <zhi.a.wang@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20220411141403.86980-27-hch@lst.deReviewed-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Reviewed-by: default avatarZhi Wang <zhi.a.wang@intel.com>
parent 44566412
...@@ -1007,10 +1007,9 @@ static int intel_vgpu_aperture_rw(struct intel_vgpu *vgpu, u64 off, ...@@ -1007,10 +1007,9 @@ static int intel_vgpu_aperture_rw(struct intel_vgpu *vgpu, u64 off,
return 0; return 0;
} }
static ssize_t intel_vgpu_rw(struct mdev_device *mdev, char *buf, static ssize_t intel_vgpu_rw(struct intel_vgpu *vgpu, char *buf,
size_t count, loff_t *ppos, bool is_write) size_t count, loff_t *ppos, bool is_write)
{ {
struct intel_vgpu *vgpu = mdev_get_drvdata(mdev);
unsigned int index = VFIO_PCI_OFFSET_TO_INDEX(*ppos); unsigned int index = VFIO_PCI_OFFSET_TO_INDEX(*ppos);
u64 pos = *ppos & VFIO_PCI_OFFSET_MASK; u64 pos = *ppos & VFIO_PCI_OFFSET_MASK;
int ret = -EINVAL; int ret = -EINVAL;
...@@ -1056,9 +1055,8 @@ static ssize_t intel_vgpu_rw(struct mdev_device *mdev, char *buf, ...@@ -1056,9 +1055,8 @@ static ssize_t intel_vgpu_rw(struct mdev_device *mdev, char *buf,
return ret == 0 ? count : ret; return ret == 0 ? count : ret;
} }
static bool gtt_entry(struct mdev_device *mdev, loff_t *ppos) static bool gtt_entry(struct intel_vgpu *vgpu, loff_t *ppos)
{ {
struct intel_vgpu *vgpu = mdev_get_drvdata(mdev);
unsigned int index = VFIO_PCI_OFFSET_TO_INDEX(*ppos); unsigned int index = VFIO_PCI_OFFSET_TO_INDEX(*ppos);
struct intel_gvt *gvt = vgpu->gvt; struct intel_gvt *gvt = vgpu->gvt;
int offset; int offset;
...@@ -1078,6 +1076,7 @@ static bool gtt_entry(struct mdev_device *mdev, loff_t *ppos) ...@@ -1078,6 +1076,7 @@ static bool gtt_entry(struct mdev_device *mdev, loff_t *ppos)
static ssize_t intel_vgpu_read(struct mdev_device *mdev, char __user *buf, static ssize_t intel_vgpu_read(struct mdev_device *mdev, char __user *buf,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
struct intel_vgpu *vgpu = mdev_get_drvdata(mdev);
unsigned int done = 0; unsigned int done = 0;
int ret; int ret;
...@@ -1086,10 +1085,10 @@ static ssize_t intel_vgpu_read(struct mdev_device *mdev, char __user *buf, ...@@ -1086,10 +1085,10 @@ static ssize_t intel_vgpu_read(struct mdev_device *mdev, char __user *buf,
/* Only support GGTT entry 8 bytes read */ /* Only support GGTT entry 8 bytes read */
if (count >= 8 && !(*ppos % 8) && if (count >= 8 && !(*ppos % 8) &&
gtt_entry(mdev, ppos)) { gtt_entry(vgpu, ppos)) {
u64 val; u64 val;
ret = intel_vgpu_rw(mdev, (char *)&val, sizeof(val), ret = intel_vgpu_rw(vgpu, (char *)&val, sizeof(val),
ppos, false); ppos, false);
if (ret <= 0) if (ret <= 0)
goto read_err; goto read_err;
...@@ -1101,7 +1100,7 @@ static ssize_t intel_vgpu_read(struct mdev_device *mdev, char __user *buf, ...@@ -1101,7 +1100,7 @@ static ssize_t intel_vgpu_read(struct mdev_device *mdev, char __user *buf,
} else if (count >= 4 && !(*ppos % 4)) { } else if (count >= 4 && !(*ppos % 4)) {
u32 val; u32 val;
ret = intel_vgpu_rw(mdev, (char *)&val, sizeof(val), ret = intel_vgpu_rw(vgpu, (char *)&val, sizeof(val),
ppos, false); ppos, false);
if (ret <= 0) if (ret <= 0)
goto read_err; goto read_err;
...@@ -1113,7 +1112,7 @@ static ssize_t intel_vgpu_read(struct mdev_device *mdev, char __user *buf, ...@@ -1113,7 +1112,7 @@ static ssize_t intel_vgpu_read(struct mdev_device *mdev, char __user *buf,
} else if (count >= 2 && !(*ppos % 2)) { } else if (count >= 2 && !(*ppos % 2)) {
u16 val; u16 val;
ret = intel_vgpu_rw(mdev, (char *)&val, sizeof(val), ret = intel_vgpu_rw(vgpu, (char *)&val, sizeof(val),
ppos, false); ppos, false);
if (ret <= 0) if (ret <= 0)
goto read_err; goto read_err;
...@@ -1125,7 +1124,7 @@ static ssize_t intel_vgpu_read(struct mdev_device *mdev, char __user *buf, ...@@ -1125,7 +1124,7 @@ static ssize_t intel_vgpu_read(struct mdev_device *mdev, char __user *buf,
} else { } else {
u8 val; u8 val;
ret = intel_vgpu_rw(mdev, &val, sizeof(val), ppos, ret = intel_vgpu_rw(vgpu, &val, sizeof(val), ppos,
false); false);
if (ret <= 0) if (ret <= 0)
goto read_err; goto read_err;
...@@ -1152,6 +1151,7 @@ static ssize_t intel_vgpu_write(struct mdev_device *mdev, ...@@ -1152,6 +1151,7 @@ static ssize_t intel_vgpu_write(struct mdev_device *mdev,
const char __user *buf, const char __user *buf,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
struct intel_vgpu *vgpu = mdev_get_drvdata(mdev);
unsigned int done = 0; unsigned int done = 0;
int ret; int ret;
...@@ -1160,13 +1160,13 @@ static ssize_t intel_vgpu_write(struct mdev_device *mdev, ...@@ -1160,13 +1160,13 @@ static ssize_t intel_vgpu_write(struct mdev_device *mdev,
/* Only support GGTT entry 8 bytes write */ /* Only support GGTT entry 8 bytes write */
if (count >= 8 && !(*ppos % 8) && if (count >= 8 && !(*ppos % 8) &&
gtt_entry(mdev, ppos)) { gtt_entry(vgpu, ppos)) {
u64 val; u64 val;
if (copy_from_user(&val, buf, sizeof(val))) if (copy_from_user(&val, buf, sizeof(val)))
goto write_err; goto write_err;
ret = intel_vgpu_rw(mdev, (char *)&val, sizeof(val), ret = intel_vgpu_rw(vgpu, (char *)&val, sizeof(val),
ppos, true); ppos, true);
if (ret <= 0) if (ret <= 0)
goto write_err; goto write_err;
...@@ -1178,7 +1178,7 @@ static ssize_t intel_vgpu_write(struct mdev_device *mdev, ...@@ -1178,7 +1178,7 @@ static ssize_t intel_vgpu_write(struct mdev_device *mdev,
if (copy_from_user(&val, buf, sizeof(val))) if (copy_from_user(&val, buf, sizeof(val)))
goto write_err; goto write_err;
ret = intel_vgpu_rw(mdev, (char *)&val, sizeof(val), ret = intel_vgpu_rw(vgpu, (char *)&val, sizeof(val),
ppos, true); ppos, true);
if (ret <= 0) if (ret <= 0)
goto write_err; goto write_err;
...@@ -1190,7 +1190,7 @@ static ssize_t intel_vgpu_write(struct mdev_device *mdev, ...@@ -1190,7 +1190,7 @@ static ssize_t intel_vgpu_write(struct mdev_device *mdev,
if (copy_from_user(&val, buf, sizeof(val))) if (copy_from_user(&val, buf, sizeof(val)))
goto write_err; goto write_err;
ret = intel_vgpu_rw(mdev, (char *)&val, ret = intel_vgpu_rw(vgpu, (char *)&val,
sizeof(val), ppos, true); sizeof(val), ppos, true);
if (ret <= 0) if (ret <= 0)
goto write_err; goto write_err;
...@@ -1202,7 +1202,7 @@ static ssize_t intel_vgpu_write(struct mdev_device *mdev, ...@@ -1202,7 +1202,7 @@ static ssize_t intel_vgpu_write(struct mdev_device *mdev,
if (copy_from_user(&val, buf, sizeof(val))) if (copy_from_user(&val, buf, sizeof(val)))
goto write_err; goto write_err;
ret = intel_vgpu_rw(mdev, &val, sizeof(val), ret = intel_vgpu_rw(vgpu, &val, sizeof(val),
ppos, true); ppos, true);
if (ret <= 0) if (ret <= 0)
goto write_err; goto write_err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment