[PATCH v1 3/4] drm/i915/gvt: Refactor vGPU type code in xengt part

Zhang, Xiong Y xiong.y.zhang at intel.com
Tue Sep 26 07:23:47 UTC 2017


> A mdev_device with faked intel_vgpu_ops is registered, then the initialized
> vGPU type group can be exposed to user.
> 
> Signed-off-by: fred gao <fred.gao at intel.com>
> ---
>  drivers/gpu/drm/i915/gvt/xengt.c | 107
> +++++++++++++++++++++++++++++++++++++++
>  1 file changed, 107 insertions(+)
> 
> diff --git a/drivers/gpu/drm/i915/gvt/xengt.c
> b/drivers/gpu/drm/i915/gvt/xengt.c
> index 7265115..4cab2d8 100644
> --- a/drivers/gpu/drm/i915/gvt/xengt.c
> +++ b/drivers/gpu/drm/i915/gvt/xengt.c
> @@ -51,6 +51,8 @@
>  #include <i915_pvinfo.h>
>  #include <gvt/gvt.h>
>  #include "xengt.h"
> +#include <linux/vfio.h>
> +#include <linux/mdev.h>
> 
>  MODULE_AUTHOR("Intel Corporation");
>  MODULE_DESCRIPTION("XenGT mediated passthrough driver"); @@
> -1438,6 +1440,99 @@ static void *xengt_gpa_to_va(unsigned long handle,
> unsigned long gpa)
>  		(gpa & (VMEM_BUCK_SIZE - 1));
>  }
> 
> +static int intel_vgpu_create(struct kobject *kobj, struct mdev_device
> +*mdev) {
> +	return 0;
> +}
> +
> +static int intel_vgpu_remove(struct mdev_device *mdev) {
> +	return 0;
> +}
> +
> +static int intel_vgpu_open(struct mdev_device *mdev) {
> +	return 0;
> +}
> +
> +static void intel_vgpu_release(struct mdev_device *mdev) { }
> +
> +static ssize_t intel_vgpu_read(struct mdev_device *mdev, char __user *buf,
> +			size_t count, loff_t *ppos)
> +{
> +	return 0;
> +}
> +
> +static ssize_t intel_vgpu_write(struct mdev_device *mdev,
> +				const char __user *buf,
> +				size_t count, loff_t *ppos)
> +{
> +	return  0;
> +}
> +
> +static int intel_vgpu_mmap(struct mdev_device *mdev, struct
> +vm_area_struct *vma) {
> +	return 0;
> +}
> +
> +static long intel_vgpu_ioctl(struct mdev_device *mdev, unsigned int cmd,
> +			     unsigned long arg)
> +{
> +	return 0;
> +}
> +
> +static ssize_t
> +vgpu_id_show(struct device *dev, struct device_attribute *attr,
> +	     char *buf)
> +{
> +	struct mdev_device *mdev = mdev_from_dev(dev);
> +
> +	if (mdev) {
> +		struct intel_vgpu *vgpu = (struct intel_vgpu *)
> +			mdev_get_drvdata(mdev);
> +		return sprintf(buf, "%d\n", vgpu->id);
> +	}
> +	return sprintf(buf, "\n");
> +}
> +
> +static DEVICE_ATTR_RO(vgpu_id);
> +
> +static struct attribute *intel_vgpu_attrs[] = {
> +	&dev_attr_vgpu_id.attr,
> +	NULL
> +};
> +
> +static const struct attribute_group intel_vgpu_group = {
> +	.name = "intel_vgpu",
> +	.attrs = intel_vgpu_attrs,
> +};
> +
> +static const struct attribute_group *intel_vgpu_groups[] = {
> +	&intel_vgpu_group,
> +	NULL,
> +};
> +
> +static struct attribute_group *intel_vgpu_type_groups[] = {
> +	[0 ... NR_MAX_INTEL_VGPU_TYPES - 1] = NULL, };
> +
> +static const struct mdev_parent_ops intel_vgpu_ops = {
> +	.supported_type_groups	= intel_vgpu_type_groups,
> +	.mdev_attr_groups       = intel_vgpu_groups,
> +	.create			= intel_vgpu_create,
> +	.remove			= intel_vgpu_remove,
> +
> +	.open			= intel_vgpu_open,
> +	.release		= intel_vgpu_release,
> +
> +	.read			= intel_vgpu_read,
> +	.write			= intel_vgpu_write,
> +	.mmap			= intel_vgpu_mmap,
> +	.ioctl			= intel_vgpu_ioctl,
> +};
> +
>  static int xengt_host_init(struct device *dev, void *gvt, const void *ops)  {
>  	int ret = -EFAULT;
> @@ -1448,6 +1543,14 @@ static int xengt_host_init(struct device *dev, void
> *gvt, const void *ops)
>  	xengt_priv.gvt = (struct intel_gvt *)gvt;
>  	intel_gvt_ops = (const struct intel_gvt_ops *)ops;
> 
> +	if (!intel_gvt_ops->gvt_init_vgpu_type_groups(gvt,
> +			intel_vgpu_type_groups))
> +		return -EFAULT;
> +
> +	ret = mdev_register_device(dev, &intel_vgpu_ops);
> +	if (ret)
> +		gvt_err("mdev_ register_device failed ret= %d!\n", ret);
> +
[Zhang, Xiong Y] I think we should just export the similar interface to xengt sysfs like kvmgt, but we couldn't use mdev_register_device() which imply strong dependency on vfio. Actually xengt doesn't have any relationship with vfio and no one will call intel_vgpu_ops in xengt.

>  	ret = xengt_sysfs_init(xengt_priv.gvt);
>  	if (ret) {
>  		xengt_priv.gvt = NULL;
> @@ -1459,6 +1562,10 @@ static int xengt_host_init(struct device *dev, void
> *gvt, const void *ops)
> 
>  static void xengt_host_exit(struct device *dev, void *gvt)  {
> +	intel_gvt_ops->gvt_cleanup_vgpu_type_groups(gvt,
> +			intel_vgpu_type_groups);
> +	mdev_unregister_device(dev);
> +
>  	xengt_sysfs_del();
>  	xengt_priv.gvt = NULL;
>  	intel_gvt_ops = NULL;
> --
> 2.7.4
> 
> _______________________________________________
> intel-gvt-dev mailing list
> intel-gvt-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gvt-dev


More information about the intel-gvt-dev mailing list