Commit 383987fd authored by Jason Gunthorpe's avatar Jason Gunthorpe Committed by Alex Williamson

vfio/gvt: Use mdev_get_type_group_id()

intel_gvt_init_vgpu_type_groups() makes gvt->types 1:1 with the
supported_type_groups array, so the type_group_id is also the index into
gvt->types. Use it directly and remove the string matching.
Reviewed-by: default avatarKevin Tian <kevin.tian@intel.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Message-Id: <16-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com>
Reviewed-by: default avatarZhenyu Wang <zhenyuw@linux.intel.com>
Signed-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
parent 07e543f4
...@@ -46,22 +46,12 @@ static const char * const supported_hypervisors[] = { ...@@ -46,22 +46,12 @@ static const char * const supported_hypervisors[] = {
[INTEL_GVT_HYPERVISOR_KVM] = "KVM", [INTEL_GVT_HYPERVISOR_KVM] = "KVM",
}; };
static struct intel_vgpu_type *intel_gvt_find_vgpu_type(struct intel_gvt *gvt, static struct intel_vgpu_type *
const char *name) intel_gvt_find_vgpu_type(struct intel_gvt *gvt, unsigned int type_group_id)
{ {
const char *driver_name = if (WARN_ON(type_group_id >= gvt->num_types))
dev_driver_string(&gvt->gt->i915->drm.pdev->dev); return NULL;
int i; return &gvt->types[type_group_id];
name += strlen(driver_name) + 1;
for (i = 0; i < gvt->num_types; i++) {
struct intel_vgpu_type *t = &gvt->types[i];
if (!strncmp(t->name, name, sizeof(t->name)))
return t;
}
return NULL;
} }
static ssize_t available_instances_show(struct kobject *kobj, static ssize_t available_instances_show(struct kobject *kobj,
...@@ -71,7 +61,7 @@ static ssize_t available_instances_show(struct kobject *kobj, ...@@ -71,7 +61,7 @@ static ssize_t available_instances_show(struct kobject *kobj,
unsigned int num = 0; unsigned int num = 0;
void *gvt = kdev_to_i915(dev)->gvt; void *gvt = kdev_to_i915(dev)->gvt;
type = intel_gvt_find_vgpu_type(gvt, kobject_name(kobj)); type = intel_gvt_find_vgpu_type(gvt, mtype_get_type_group_id(kobj));
if (!type) if (!type)
num = 0; num = 0;
else else
...@@ -92,7 +82,7 @@ static ssize_t description_show(struct kobject *kobj, struct device *dev, ...@@ -92,7 +82,7 @@ static ssize_t description_show(struct kobject *kobj, struct device *dev,
struct intel_vgpu_type *type; struct intel_vgpu_type *type;
void *gvt = kdev_to_i915(dev)->gvt; void *gvt = kdev_to_i915(dev)->gvt;
type = intel_gvt_find_vgpu_type(gvt, kobject_name(kobj)); type = intel_gvt_find_vgpu_type(gvt, mtype_get_type_group_id(kobj));
if (!type) if (!type)
return 0; return 0;
......
...@@ -569,8 +569,8 @@ struct intel_gvt_ops { ...@@ -569,8 +569,8 @@ struct intel_gvt_ops {
void (*vgpu_reset)(struct intel_vgpu *); void (*vgpu_reset)(struct intel_vgpu *);
void (*vgpu_activate)(struct intel_vgpu *); void (*vgpu_activate)(struct intel_vgpu *);
void (*vgpu_deactivate)(struct intel_vgpu *); void (*vgpu_deactivate)(struct intel_vgpu *);
struct intel_vgpu_type *(*gvt_find_vgpu_type)(struct intel_gvt *gvt, struct intel_vgpu_type *(*gvt_find_vgpu_type)(
const char *name); struct intel_gvt *gvt, unsigned int type_group_id);
bool (*get_gvt_attrs)(struct attribute_group ***intel_vgpu_type_groups); bool (*get_gvt_attrs)(struct attribute_group ***intel_vgpu_type_groups);
int (*vgpu_query_plane)(struct intel_vgpu *vgpu, void *); int (*vgpu_query_plane)(struct intel_vgpu *vgpu, void *);
int (*vgpu_get_dmabuf)(struct intel_vgpu *vgpu, unsigned int); int (*vgpu_get_dmabuf)(struct intel_vgpu *vgpu, unsigned int);
......
...@@ -700,10 +700,9 @@ static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev) ...@@ -700,10 +700,9 @@ static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev)
pdev = mdev_parent_dev(mdev); pdev = mdev_parent_dev(mdev);
gvt = kdev_to_i915(pdev)->gvt; gvt = kdev_to_i915(pdev)->gvt;
type = intel_gvt_ops->gvt_find_vgpu_type(gvt, kobject_name(kobj)); type = intel_gvt_ops->gvt_find_vgpu_type(gvt,
mdev_get_type_group_id(mdev));
if (!type) { if (!type) {
gvt_vgpu_err("failed to find type %s to create\n",
kobject_name(kobj));
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
......
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