Skip to content

Commit c5d71cb

Browse files
fred1gaozhenyw
authored andcommitted
drm/i915/gvt: Move vGPU type related code into gvt file
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. v2: - remove the useless mdev_* gvt_ops. add get_gvt_attr ops for MPT module. intel_gvt_{init,cleanup}_vgpu_type_groups are initialized in gvt part. (Wang, Zhi) - set gvt_vgpu_type_groups[i] to NULL. (Zhang,Xiong) Signed-off-by: fred gao <fred.gao@intel.com> Reviewed-by: Zhi Wang <zhi.a.wang@intel.com> Signed-off-by: Zhi Wang <zhi.a.wang@intel.com>
1 parent e2c43c0 commit c5d71cb

2 files changed

Lines changed: 138 additions & 0 deletions

File tree

‎drivers/gpu/drm/i915/gvt/gvt.c‎

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
#include "i915_drv.h"
3838
#include "gvt.h"
39+
#include <linux/vfio.h>
40+
#include <linux/mdev.h>
3941

4042
struct intel_gvt_host intel_gvt_host;
4143

@@ -44,6 +46,129 @@ static const char * const supported_hypervisors[] = {
4446
[INTEL_GVT_HYPERVISOR_KVM] = "KVM",
4547
};
4648

49+
static struct intel_vgpu_type *intel_gvt_find_vgpu_type(struct intel_gvt *gvt,
50+
const char *name)
51+
{
52+
int i;
53+
struct intel_vgpu_type *t;
54+
const char *driver_name = dev_driver_string(
55+
&gvt->dev_priv->drm.pdev->dev);
56+
57+
for (i = 0; i < gvt->num_types; i++) {
58+
t = &gvt->types[i];
59+
if (!strncmp(t->name, name + strlen(driver_name) + 1,
60+
sizeof(t->name)))
61+
return t;
62+
}
63+
64+
return NULL;
65+
}
66+
67+
static ssize_t available_instances_show(struct kobject *kobj,
68+
struct device *dev, char *buf)
69+
{
70+
struct intel_vgpu_type *type;
71+
unsigned int num = 0;
72+
void *gvt = kdev_to_i915(dev)->gvt;
73+
74+
type = intel_gvt_find_vgpu_type(gvt, kobject_name(kobj));
75+
if (!type)
76+
num = 0;
77+
else
78+
num = type->avail_instance;
79+
80+
return sprintf(buf, "%u\n", num);
81+
}
82+
83+
static ssize_t device_api_show(struct kobject *kobj, struct device *dev,
84+
char *buf)
85+
{
86+
return sprintf(buf, "%s\n", VFIO_DEVICE_API_PCI_STRING);
87+
}
88+
89+
static ssize_t description_show(struct kobject *kobj, struct device *dev,
90+
char *buf)
91+
{
92+
struct intel_vgpu_type *type;
93+
void *gvt = kdev_to_i915(dev)->gvt;
94+
95+
type = intel_gvt_find_vgpu_type(gvt, kobject_name(kobj));
96+
if (!type)
97+
return 0;
98+
99+
return sprintf(buf, "low_gm_size: %dMB\nhigh_gm_size: %dMB\n"
100+
"fence: %d\nresolution: %s\n"
101+
"weight: %d\n",
102+
BYTES_TO_MB(type->low_gm_size),
103+
BYTES_TO_MB(type->high_gm_size),
104+
type->fence, vgpu_edid_str(type->resolution),
105+
type->weight);
106+
}
107+
108+
static MDEV_TYPE_ATTR_RO(available_instances);
109+
static MDEV_TYPE_ATTR_RO(device_api);
110+
static MDEV_TYPE_ATTR_RO(description);
111+
112+
static struct attribute *gvt_type_attrs[] = {
113+
&mdev_type_attr_available_instances.attr,
114+
&mdev_type_attr_device_api.attr,
115+
&mdev_type_attr_description.attr,
116+
NULL,
117+
};
118+
119+
static struct attribute_group *gvt_vgpu_type_groups[] = {
120+
[0 ... NR_MAX_INTEL_VGPU_TYPES - 1] = NULL,
121+
};
122+
123+
static bool intel_get_gvt_attrs(struct attribute ***type_attrs,
124+
struct attribute_group ***intel_vgpu_type_groups)
125+
{
126+
*type_attrs = gvt_type_attrs;
127+
*intel_vgpu_type_groups = gvt_vgpu_type_groups;
128+
return true;
129+
}
130+
131+
static bool intel_gvt_init_vgpu_type_groups(struct intel_gvt *gvt)
132+
{
133+
int i, j;
134+
struct intel_vgpu_type *type;
135+
struct attribute_group *group;
136+
137+
for (i = 0; i < gvt->num_types; i++) {
138+
type = &gvt->types[i];
139+
140+
group = kzalloc(sizeof(struct attribute_group), GFP_KERNEL);
141+
if (WARN_ON(!group))
142+
goto unwind;
143+
144+
group->name = type->name;
145+
group->attrs = gvt_type_attrs;
146+
gvt_vgpu_type_groups[i] = group;
147+
}
148+
149+
return true;
150+
151+
unwind:
152+
for (j = 0; j < i; j++) {
153+
group = gvt_vgpu_type_groups[j];
154+
kfree(group);
155+
}
156+
157+
return false;
158+
}
159+
160+
static void intel_gvt_cleanup_vgpu_type_groups(struct intel_gvt *gvt)
161+
{
162+
int i;
163+
struct attribute_group *group;
164+
165+
for (i = 0; i < gvt->num_types; i++) {
166+
group = gvt_vgpu_type_groups[i];
167+
gvt_vgpu_type_groups[i] = NULL;
168+
kfree(group);
169+
}
170+
}
171+
47172
static const struct intel_gvt_ops intel_gvt_ops = {
48173
.emulate_cfg_read = intel_vgpu_emulate_cfg_read,
49174
.emulate_cfg_write = intel_vgpu_emulate_cfg_write,
@@ -54,6 +179,8 @@ static const struct intel_gvt_ops intel_gvt_ops = {
54179
.vgpu_reset = intel_gvt_reset_vgpu,
55180
.vgpu_activate = intel_gvt_activate_vgpu,
56181
.vgpu_deactivate = intel_gvt_deactivate_vgpu,
182+
.gvt_find_vgpu_type = intel_gvt_find_vgpu_type,
183+
.get_gvt_attrs = intel_get_gvt_attrs,
57184
};
58185

59186
/**
@@ -202,6 +329,7 @@ void intel_gvt_clean_device(struct drm_i915_private *dev_priv)
202329
intel_gvt_free_firmware(gvt);
203330

204331
intel_gvt_hypervisor_host_exit(&dev_priv->drm.pdev->dev, gvt);
332+
intel_gvt_cleanup_vgpu_type_groups(gvt);
205333
intel_gvt_clean_vgpu_types(gvt);
206334

207335
idr_destroy(&gvt->vgpu_idr);
@@ -292,6 +420,12 @@ int intel_gvt_init_device(struct drm_i915_private *dev_priv)
292420
if (ret)
293421
goto out_clean_thread;
294422

423+
ret = intel_gvt_init_vgpu_type_groups(gvt);
424+
if (ret == false) {
425+
gvt_err("failed to init vgpu type groups: %d\n", ret);
426+
goto out_clean_types;
427+
}
428+
295429
ret = intel_gvt_hypervisor_host_init(&dev_priv->drm.pdev->dev, gvt,
296430
&intel_gvt_ops);
297431
if (ret) {

‎drivers/gpu/drm/i915/gvt/gvt.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,10 @@ struct intel_gvt_ops {
533533
void (*vgpu_reset)(struct intel_vgpu *);
534534
void (*vgpu_activate)(struct intel_vgpu *);
535535
void (*vgpu_deactivate)(struct intel_vgpu *);
536+
struct intel_vgpu_type *(*gvt_find_vgpu_type)(struct intel_gvt *gvt,
537+
const char *name);
538+
bool (*get_gvt_attrs)(struct attribute ***type_attrs,
539+
struct attribute_group ***intel_vgpu_type_groups);
536540
};
537541

538542

0 commit comments

Comments
 (0)