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 mmio_diff_param *param = data;
62 struct diff_mmio *node;
63 u32 preg, vreg;
64
65 preg = intel_uncore_read_notrace(gvt->gt->uncore, _MMIO(offset));
66 vreg = vgpu_vreg(param->vgpu, offset);
67
68 if (preg != vreg) {
69 node = kmalloc(sizeof(*node), GFP_ATOMIC);
70 if (!node)
71 return -ENOMEM;
72
73 node->offset = offset;
74 node->preg = preg;
75 node->vreg = vreg;
76 list_add(&node->node, ¶m->diff_mmio_list);
77 param->diff++;
78 }
79 param->total++;
80 return 0;
81}
82
83
84static int vgpu_mmio_diff_show(struct seq_file *s, void *unused)
85{
86 struct intel_vgpu *vgpu = s->private;
87 struct intel_gvt *gvt = vgpu->gvt;
88 struct mmio_diff_param param = {
89 .vgpu = vgpu,
90 .total = 0,
91 .diff = 0,
92 };
93 struct diff_mmio *node, *next;
94
95 INIT_LIST_HEAD(¶m.diff_mmio_list);
96
97 mutex_lock(&gvt->lock);
98 spin_lock_bh(&gvt->scheduler.mmio_context_lock);
99
100 mmio_hw_access_pre(gvt->gt);
101
102 intel_gvt_for_each_tracked_mmio(gvt, mmio_diff_handler, ¶m);
103 mmio_hw_access_post(gvt->gt);
104
105 spin_unlock_bh(&gvt->scheduler.mmio_context_lock);
106 mutex_unlock(&gvt->lock);
107
108
109 list_sort(NULL, ¶m.diff_mmio_list, mmio_offset_compare);
110
111 seq_printf(s, "%-8s %-8s %-8s %-8s\n", "Offset", "HW", "vGPU", "Diff");
112 list_for_each_entry_safe(node, next, ¶m.diff_mmio_list, node) {
113 u32 diff = node->preg ^ node->vreg;
114
115 seq_printf(s, "%08x %08x %08x %*pbl\n",
116 node->offset, node->preg, node->vreg,
117 32, &diff);
118 list_del(&node->node);
119 kfree(node);
120 }
121 seq_printf(s, "Total: %d, Diff: %d\n", param.total, param.diff);
122 return 0;
123}
124DEFINE_SHOW_ATTRIBUTE(vgpu_mmio_diff);
125
126static int
127vgpu_scan_nonprivbb_get(void *data, u64 *val)
128{
129 struct intel_vgpu *vgpu = (struct intel_vgpu *)data;
130
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
146 vgpu->scan_nonprivbb = val;
147 return 0;
148}
149
150DEFINE_SIMPLE_ATTRIBUTE(vgpu_scan_nonprivbb_fops,
151 vgpu_scan_nonprivbb_get, vgpu_scan_nonprivbb_set,
152 "0x%llx\n");
153
154
155
156
157
158void intel_gvt_debugfs_add_vgpu(struct intel_vgpu *vgpu)
159{
160 char name[16] = "";
161
162 snprintf(name, 16, "vgpu%d", vgpu->id);
163 vgpu->debugfs = debugfs_create_dir(name, vgpu->gvt->debugfs_root);
164
165 debugfs_create_bool("active", 0444, vgpu->debugfs, &vgpu->active);
166 debugfs_create_file("mmio_diff", 0444, vgpu->debugfs, vgpu,
167 &vgpu_mmio_diff_fops);
168 debugfs_create_file("scan_nonprivbb", 0644, vgpu->debugfs, vgpu,
169 &vgpu_scan_nonprivbb_fops);
170}
171
172
173
174
175
176void intel_gvt_debugfs_remove_vgpu(struct intel_vgpu *vgpu)
177{
178 debugfs_remove_recursive(vgpu->debugfs);
179 vgpu->debugfs = NULL;
180}
181
182
183
184
185
186void intel_gvt_debugfs_init(struct intel_gvt *gvt)
187{
188 struct drm_minor *minor = gvt->gt->i915->drm.primary;
189
190 gvt->debugfs_root = debugfs_create_dir("gvt", minor->debugfs_root);
191
192 debugfs_create_ulong("num_tracked_mmio", 0444, gvt->debugfs_root,
193 &gvt->mmio.num_tracked_mmio);
194}
195
196
197
198
199
200void intel_gvt_debugfs_clean(struct intel_gvt *gvt)
201{
202 debugfs_remove_recursive(gvt->debugfs_root);
203 gvt->debugfs_root = NULL;
204}
205