1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#include <linux/debugfs.h>
24#include <linux/list_sort.h>
25#include "i915_drv.h"
26#include "gvt.h"
27
28struct mmio_diff_param {
29 struct intel_vgpu *vgpu;
30 int total;
31 int diff;
32 struct list_head diff_mmio_list;
33};
34
35struct diff_mmio {
36 struct list_head node;
37 u32 offset;
38 u32 preg;
39 u32 vreg;
40};
41
42
43static int mmio_offset_compare(void *priv,
44 struct list_head *a, struct list_head *b)
45{
46 struct diff_mmio *ma;
47 struct diff_mmio *mb;
48
49 ma = container_of(a, struct diff_mmio, node);
50 mb = container_of(b, struct diff_mmio, node);
51 if (ma->offset < mb->offset)
52 return -1;
53 else if (ma->offset > mb->offset)
54 return 1;
55 return 0;
56}
57
58static inline int mmio_diff_handler(struct intel_gvt *gvt,
59 u32 offset, void *data)
60{
61 struct drm_i915_private *dev_priv = gvt->dev_priv;
62 struct mmio_diff_param *param = data;
63 struct diff_mmio *node;
64 u32 preg, vreg;
65
66 preg = I915_READ_NOTRACE(_MMIO(offset));
67 vreg = vgpu_vreg(param->vgpu, offset);
68
69 if (preg != vreg) {
70 node = kmalloc(sizeof(*node), GFP_KERNEL);
71 if (!node)
72 return -ENOMEM;
73
74 node->offset = offset;
75 node->preg = preg;
76 node->vreg = vreg;
77 list_add(&node->node, ¶m->diff_mmio_list);
78 param->diff++;
79 }
80 param->total++;
81 return 0;
82}
83
84
85static int vgpu_mmio_diff_show(struct seq_file *s, void *unused)
86{
87 struct intel_vgpu *vgpu = s->private;
88 struct intel_gvt *gvt = vgpu->gvt;
89 struct mmio_diff_param param = {
90 .vgpu = vgpu,
91 .total = 0,
92 .diff = 0,
93 };
94 struct diff_mmio *node, *next;
95
96 INIT_LIST_HEAD(¶m.diff_mmio_list);
97
98 mutex_lock(&gvt->lock);
99 spin_lock_bh(&gvt->scheduler.mmio_context_lock);
100
101 mmio_hw_access_pre(gvt->dev_priv);
102
103 intel_gvt_for_each_tracked_mmio(gvt, mmio_diff_handler, ¶m);
104 mmio_hw_access_post(gvt->dev_priv);
105
106 spin_unlock_bh(&gvt->scheduler.mmio_context_lock);
107 mutex_unlock(&gvt->lock);
108
109
110 list_sort(NULL, ¶m.diff_mmio_list, mmio_offset_compare);
111
112 seq_printf(s, "%-8s %-8s %-8s %-8s\n", "Offset", "HW", "vGPU", "Diff");
113 list_for_each_entry_safe(node, next, ¶m.diff_mmio_list, node) {
114 u32 diff = node->preg ^ node->vreg;
115
116 seq_printf(s, "%08x %08x %08x %*pbl\n",
117 node->offset, node->preg, node->vreg,
118 32, &diff);
119 list_del(&node->node);
120 kfree(node);
121 }
122 seq_printf(s, "Total: %d, Diff: %d\n", param.total, param.diff);
123 return 0;
124}
125DEFINE_SHOW_ATTRIBUTE(vgpu_mmio_diff);
126
127static int
128vgpu_scan_nonprivbb_get(void *data, u64 *val)
129{
130 struct intel_vgpu *vgpu = (struct intel_vgpu *)data;
131 *val = vgpu->scan_nonprivbb;
132 return 0;
133}
134
135
136
137
138
139
140
141static int
142vgpu_scan_nonprivbb_set(void *data, u64 val)
143{
144 struct intel_vgpu *vgpu = (struct intel_vgpu *)data;
145 struct drm_i915_private *dev_priv = vgpu->gvt->dev_priv;
146 enum intel_engine_id id;
147 char buf[128], *s;
148 int len;
149
150 val &= (1 << I915_NUM_ENGINES) - 1;
151
152 if (vgpu->scan_nonprivbb == val)
153 return 0;
154
155 if (!val)
156 goto done;
157
158 len = sprintf(buf,
159 "gvt: vgpu %d turns on non-privileged batch buffers scanning on Engines:",
160 vgpu->id);
161
162 s = buf + len;
163
164 for (id = 0; id < I915_NUM_ENGINES; id++) {
165 struct intel_engine_cs *engine;
166
167 engine = dev_priv->engine[id];
168 if (engine && (val & (1 << id))) {
169 len = snprintf(s, 4, "%d, ", engine->id);
170 s += len;
171 } else
172 val &= ~(1 << id);
173 }
174
175 if (val)
176 sprintf(s, "low performance expected.");
177
178 pr_warn("%s\n", buf);
179
180done:
181 vgpu->scan_nonprivbb = val;
182 return 0;
183}
184
185DEFINE_SIMPLE_ATTRIBUTE(vgpu_scan_nonprivbb_fops,
186 vgpu_scan_nonprivbb_get, vgpu_scan_nonprivbb_set,
187 "0x%llx\n");
188
189
190
191
192
193
194
195
196int intel_gvt_debugfs_add_vgpu(struct intel_vgpu *vgpu)
197{
198 struct dentry *ent;
199 char name[10] = "";
200
201 sprintf(name, "vgpu%d", vgpu->id);
202 vgpu->debugfs = debugfs_create_dir(name, vgpu->gvt->debugfs_root);
203 if (!vgpu->debugfs)
204 return -ENOMEM;
205
206 ent = debugfs_create_bool("active", 0444, vgpu->debugfs,
207 &vgpu->active);
208 if (!ent)
209 return -ENOMEM;
210
211 ent = debugfs_create_file("mmio_diff", 0444, vgpu->debugfs,
212 vgpu, &vgpu_mmio_diff_fops);
213 if (!ent)
214 return -ENOMEM;
215
216 ent = debugfs_create_file("scan_nonprivbb", 0644, vgpu->debugfs,
217 vgpu, &vgpu_scan_nonprivbb_fops);
218 if (!ent)
219 return -ENOMEM;
220
221 return 0;
222}
223
224
225
226
227
228void intel_gvt_debugfs_remove_vgpu(struct intel_vgpu *vgpu)
229{
230 debugfs_remove_recursive(vgpu->debugfs);
231 vgpu->debugfs = NULL;
232}
233
234
235
236
237
238
239
240
241int intel_gvt_debugfs_init(struct intel_gvt *gvt)
242{
243 struct drm_minor *minor = gvt->dev_priv->drm.primary;
244 struct dentry *ent;
245
246 gvt->debugfs_root = debugfs_create_dir("gvt", minor->debugfs_root);
247 if (!gvt->debugfs_root) {
248 gvt_err("Cannot create debugfs dir\n");
249 return -ENOMEM;
250 }
251
252 ent = debugfs_create_ulong("num_tracked_mmio", 0444, gvt->debugfs_root,
253 &gvt->mmio.num_tracked_mmio);
254 if (!ent)
255 return -ENOMEM;
256
257 return 0;
258}
259
260
261
262
263
264void intel_gvt_debugfs_clean(struct intel_gvt *gvt)
265{
266 debugfs_remove_recursive(gvt->debugfs_root);
267 gvt->debugfs_root = NULL;
268}
269