[PATCH v1 1/4] drm/i915/gvt: move vGPU type related code into gvt file
fred gao
fred.gao at intel.com
Wed Sep 13 08:43:02 UTC 2017
In this patch, all the vGPU type related code will be merged into
same gvt file and the common interface will be exposed to both
XenGT and KvmGT.
Signed-off-by: fred gao <fred.gao at intel.com>
---
drivers/gpu/drm/i915/gvt/gvt.c | 123 +++++++++++++++++++++++++++++++++++++++++
drivers/gpu/drm/i915/gvt/gvt.h | 29 ++++++++++
2 files changed, 152 insertions(+)
diff --git a/drivers/gpu/drm/i915/gvt/gvt.c b/drivers/gpu/drm/i915/gvt/gvt.c
index e40af70..357ce1a 100644
--- a/drivers/gpu/drm/i915/gvt/gvt.c
+++ b/drivers/gpu/drm/i915/gvt/gvt.c
@@ -36,6 +36,8 @@
#include "i915_drv.h"
#include "gvt.h"
+#include <linux/vfio.h>
+#include <linux/mdev.h>
struct intel_gvt_host intel_gvt_host;
@@ -55,8 +57,129 @@ static const struct intel_gvt_ops intel_gvt_ops = {
.vgpu_activate = intel_gvt_activate_vgpu,
.vgpu_deactivate = intel_gvt_deactivate_vgpu,
.vgpu_save_restore = intel_gvt_save_restore,
+ .gvt_find_vgpu_type = intel_gvt_find_vgpu_type,
+ .gvt_init_vgpu_type_groups = intel_gvt_init_vgpu_type_groups,
+ .gvt_cleanup_vgpu_type_groups = intel_gvt_cleanup_vgpu_type_groups,
+ .mdev_available_instances_show = available_instances_show,
+ .mdev_device_api_show = device_api_show,
+ .mdev_description_show = description_show,
};
+struct intel_vgpu_type *intel_gvt_find_vgpu_type(struct intel_gvt *gvt,
+ const char *name)
+{
+ int i;
+ struct intel_vgpu_type *t;
+ const char *driver_name = dev_driver_string(
+ &gvt->dev_priv->drm.pdev->dev);
+ gvt_err("find vgput type %s\n", name);
+
+ for (i = 0; i < gvt->num_types; i++) {
+ t = &gvt->types[i];
+ if (!strncmp(t->name, name + strlen(driver_name) + 1,
+ sizeof(t->name)))
+ return t;
+ }
+
+ return NULL;
+}
+
+ssize_t available_instances_show(struct kobject *kobj,
+ struct device *dev, char *buf)
+{
+ struct intel_vgpu_type *type;
+ unsigned int num = 0;
+ void *gvt = kdev_to_i915(dev)->gvt;
+
+ type = intel_gvt_find_vgpu_type(gvt, kobject_name(kobj));
+ if (!type)
+ num = 0;
+ else
+ num = type->avail_instance;
+
+ return sprintf(buf, "%u\n", num);
+}
+
+ssize_t device_api_show(struct kobject *kobj, struct device *dev,
+ char *buf)
+{
+ return sprintf(buf, "%s\n", VFIO_DEVICE_API_PCI_STRING);
+}
+
+ssize_t description_show(struct kobject *kobj, struct device *dev,
+ char *buf)
+{
+ struct intel_vgpu_type *type;
+ void *gvt = kdev_to_i915(dev)->gvt;
+
+ type = intel_gvt_find_vgpu_type(gvt, kobject_name(kobj));
+ gvt_err("decripton show e %s\n", type->name);
+ if (!type)
+ return 0;
+
+ return sprintf(buf, "low_gm_size: %dMB\nhigh_gm_size: %dMB\n"
+ "fence: %d\nresolution: %s\n"
+ "weight: %d\n",
+ BYTES_TO_MB(type->low_gm_size),
+ BYTES_TO_MB(type->high_gm_size),
+ type->fence, vgpu_edid_str(type->resolution),
+ type->weight);
+}
+
+static MDEV_TYPE_ATTR_RO(available_instances);
+static MDEV_TYPE_ATTR_RO(device_api);
+static MDEV_TYPE_ATTR_RO(description);
+
+static struct attribute *type_attrs[] = {
+ &mdev_type_attr_available_instances.attr,
+ &mdev_type_attr_device_api.attr,
+ &mdev_type_attr_description.attr,
+ NULL,
+};
+
+bool intel_gvt_init_vgpu_type_groups(struct intel_gvt *gvt,
+ struct attribute_group *intel_vgpu_type_groups[])
+{
+ int i, j;
+ struct intel_vgpu_type *type;
+ struct attribute_group *group;
+
+ for (i = 0; i < gvt->num_types; i++) {
+ type = &gvt->types[i];
+
+ group = kzalloc(sizeof(struct attribute_group), GFP_KERNEL);
+ if (WARN_ON(!group))
+ goto unwind;
+
+ group->name = type->name;
+ group->attrs = type_attrs;
+ intel_vgpu_type_groups[i] = group;
+ }
+ gvt_err("ntel_gvt_init_vgpu_type_groups\n");
+
+ return true;
+
+unwind:
+ for (j = 0; j < i; j++) {
+ group = intel_vgpu_type_groups[j];
+ kfree(group);
+ }
+
+ return false;
+}
+
+void intel_gvt_cleanup_vgpu_type_groups(struct intel_gvt *gvt,
+ struct attribute_group *intel_vgpu_type_groups[])
+{
+ int i;
+ struct attribute_group *group;
+
+ for (i = 0; i < gvt->num_types; i++) {
+ group = intel_vgpu_type_groups[i];
+ kfree(group);
+ }
+}
+
/**
* intel_gvt_init_host - Load MPT modules and detect if we're running in host
* @gvt: intel gvt device
diff --git a/drivers/gpu/drm/i915/gvt/gvt.h b/drivers/gpu/drm/i915/gvt/gvt.h
index fc2aa60..803288b 100644
--- a/drivers/gpu/drm/i915/gvt/gvt.h
+++ b/drivers/gpu/drm/i915/gvt/gvt.h
@@ -448,6 +448,23 @@ void intel_gvt_deactivate_vgpu(struct intel_vgpu *vgpu);
int intel_gvt_save_restore(struct intel_vgpu *vgpu, char *buf, size_t count,
void *base, uint64_t off, bool restore);
+struct intel_vgpu_type *intel_gvt_find_vgpu_type(struct intel_gvt *gvt,
+ const char *name);
+ssize_t available_instances_show(struct kobject *kobj,
+ struct device *dev, char *buf);
+
+ssize_t device_api_show(struct kobject *kobj, struct device *dev,
+ char *buf);
+
+ssize_t description_show(struct kobject *kobj, struct device *dev,
+ char *buf);
+
+bool intel_gvt_init_vgpu_type_groups(struct intel_gvt *gvt,
+ struct attribute_group *intel_vgpu_type_groups[]);
+
+void intel_gvt_cleanup_vgpu_type_groups(struct intel_gvt *gvt,
+ struct attribute_group *intel_vgpu_type_groups[]);
+
/* validating GM functions */
#define vgpu_gmadr_is_aperture(vgpu, gmadr) \
((gmadr >= vgpu_guest_aperture_gmadr_base(vgpu)) && \
@@ -533,6 +550,18 @@ struct intel_gvt_ops {
void (*vgpu_deactivate)(struct intel_vgpu *);
int (*vgpu_save_restore)(struct intel_vgpu *, char *buf, size_t count,
void *base, uint64_t off, bool restore);
+ struct intel_vgpu_type *(*gvt_find_vgpu_type)(struct intel_gvt *gvt,
+ const char *name);
+ bool (*gvt_init_vgpu_type_groups)(struct intel_gvt *gvt,
+ struct attribute_group *intel_vgpu_type_groups[]);
+ void (*gvt_cleanup_vgpu_type_groups)(struct intel_gvt *gvt,
+ struct attribute_group *intel_vgpu_type_groups[]);
+ ssize_t (*mdev_available_instances_show)(struct kobject *kobj,
+ struct device *dev, char *buf);
+ ssize_t (*mdev_device_api_show)(struct kobject *kobj,
+ struct device *dev, char *buf);
+ ssize_t (*mdev_description_show)(struct kobject *kobj,
+ struct device *dev, char *buf);
};
--
2.7.4
More information about the intel-gvt-dev
mailing list