1 // SPDX-License-Identifier: MIT
2 /*
3 * Copyright © 2022 Intel Corporation
4 */
5
6 #include "xe_gt_debugfs.h"
7
8 #include <linux/debugfs.h>
9
10 #include <drm/drm_debugfs.h>
11 #include <drm/drm_managed.h>
12
13 #include "xe_device.h"
14 #include "xe_force_wake.h"
15 #include "xe_ggtt.h"
16 #include "xe_gt.h"
17 #include "xe_gt_mcr.h"
18 #include "xe_gt_idle.h"
19 #include "xe_gt_sriov_pf_debugfs.h"
20 #include "xe_gt_sriov_vf_debugfs.h"
21 #include "xe_gt_stats.h"
22 #include "xe_gt_topology.h"
23 #include "xe_guc_hwconfig.h"
24 #include "xe_hw_engine.h"
25 #include "xe_lrc.h"
26 #include "xe_macros.h"
27 #include "xe_mocs.h"
28 #include "xe_pat.h"
29 #include "xe_pm.h"
30 #include "xe_reg_sr.h"
31 #include "xe_reg_whitelist.h"
32 #include "xe_sriov.h"
33 #include "xe_tuning.h"
34 #include "xe_uc_debugfs.h"
35 #include "xe_wa.h"
36
37 /**
38 * xe_gt_debugfs_simple_show - A show callback for struct drm_info_list
39 * @m: the &seq_file
40 * @data: data used by the drm debugfs helpers
41 *
42 * This callback can be used in struct drm_info_list to describe debugfs
43 * files that are &xe_gt specific.
44 *
45 * It is assumed that those debugfs files will be created on directory entry
46 * which struct dentry d_inode->i_private points to &xe_gt.
47 *
48 * This function assumes that &m->private will be set to the &struct
49 * drm_info_node corresponding to the instance of the info on a given &struct
50 * drm_minor (see struct drm_info_list.show for details).
51 *
52 * This function also assumes that struct drm_info_list.data will point to the
53 * function code that will actually print a file content::
54 *
55 * int (*print)(struct xe_gt *, struct drm_printer *)
56 *
57 * Example::
58 *
59 * int foo(struct xe_gt *gt, struct drm_printer *p)
60 * {
61 * drm_printf(p, "GT%u\n", gt->info.id);
62 * return 0;
63 * }
64 *
65 * static const struct drm_info_list bar[] = {
66 * { name = "foo", .show = xe_gt_debugfs_simple_show, .data = foo },
67 * };
68 *
69 * dir = debugfs_create_dir("gt", parent);
70 * dir->d_inode->i_private = gt;
71 * drm_debugfs_create_files(bar, ARRAY_SIZE(bar), dir, minor);
72 *
73 * Return: 0 on success or a negative error code on failure.
74 */
xe_gt_debugfs_simple_show(struct seq_file * m,void * data)75 int xe_gt_debugfs_simple_show(struct seq_file *m, void *data)
76 {
77 struct drm_printer p = drm_seq_file_printer(m);
78 struct drm_info_node *node = m->private;
79 struct dentry *parent = node->dent->d_parent;
80 struct xe_gt *gt = parent->d_inode->i_private;
81 int (*print)(struct xe_gt *, struct drm_printer *) = node->info_ent->data;
82
83 if (WARN_ON(!print))
84 return -EINVAL;
85
86 return print(gt, &p);
87 }
88
hw_engines(struct xe_gt * gt,struct drm_printer * p)89 static int hw_engines(struct xe_gt *gt, struct drm_printer *p)
90 {
91 struct xe_device *xe = gt_to_xe(gt);
92 struct xe_hw_engine *hwe;
93 enum xe_hw_engine_id id;
94 unsigned int fw_ref;
95 int ret = 0;
96
97 xe_pm_runtime_get(xe);
98 fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
99 if (!xe_force_wake_ref_has_domain(fw_ref, XE_FORCEWAKE_ALL)) {
100 ret = -ETIMEDOUT;
101 goto fw_put;
102 }
103
104 for_each_hw_engine(hwe, gt, id)
105 xe_hw_engine_print(hwe, p);
106
107 fw_put:
108 xe_force_wake_put(gt_to_fw(gt), fw_ref);
109 xe_pm_runtime_put(xe);
110
111 return ret;
112 }
113
powergate_info(struct xe_gt * gt,struct drm_printer * p)114 static int powergate_info(struct xe_gt *gt, struct drm_printer *p)
115 {
116 int ret;
117
118 xe_pm_runtime_get(gt_to_xe(gt));
119 ret = xe_gt_idle_pg_print(gt, p);
120 xe_pm_runtime_put(gt_to_xe(gt));
121
122 return ret;
123 }
124
sa_info(struct xe_gt * gt,struct drm_printer * p)125 static int sa_info(struct xe_gt *gt, struct drm_printer *p)
126 {
127 struct xe_tile *tile = gt_to_tile(gt);
128
129 xe_pm_runtime_get(gt_to_xe(gt));
130 drm_suballoc_dump_debug_info(&tile->mem.kernel_bb_pool->base, p,
131 tile->mem.kernel_bb_pool->gpu_addr);
132 xe_pm_runtime_put(gt_to_xe(gt));
133
134 return 0;
135 }
136
topology(struct xe_gt * gt,struct drm_printer * p)137 static int topology(struct xe_gt *gt, struct drm_printer *p)
138 {
139 xe_pm_runtime_get(gt_to_xe(gt));
140 xe_gt_topology_dump(gt, p);
141 xe_pm_runtime_put(gt_to_xe(gt));
142
143 return 0;
144 }
145
steering(struct xe_gt * gt,struct drm_printer * p)146 static int steering(struct xe_gt *gt, struct drm_printer *p)
147 {
148 xe_pm_runtime_get(gt_to_xe(gt));
149 xe_gt_mcr_steering_dump(gt, p);
150 xe_pm_runtime_put(gt_to_xe(gt));
151
152 return 0;
153 }
154
ggtt(struct xe_gt * gt,struct drm_printer * p)155 static int ggtt(struct xe_gt *gt, struct drm_printer *p)
156 {
157 int ret;
158
159 xe_pm_runtime_get(gt_to_xe(gt));
160 ret = xe_ggtt_dump(gt_to_tile(gt)->mem.ggtt, p);
161 xe_pm_runtime_put(gt_to_xe(gt));
162
163 return ret;
164 }
165
register_save_restore(struct xe_gt * gt,struct drm_printer * p)166 static int register_save_restore(struct xe_gt *gt, struct drm_printer *p)
167 {
168 struct xe_hw_engine *hwe;
169 enum xe_hw_engine_id id;
170
171 xe_pm_runtime_get(gt_to_xe(gt));
172
173 xe_reg_sr_dump(>->reg_sr, p);
174 drm_printf(p, "\n");
175
176 drm_printf(p, "Engine\n");
177 for_each_hw_engine(hwe, gt, id)
178 xe_reg_sr_dump(&hwe->reg_sr, p);
179 drm_printf(p, "\n");
180
181 drm_printf(p, "LRC\n");
182 for_each_hw_engine(hwe, gt, id)
183 xe_reg_sr_dump(&hwe->reg_lrc, p);
184 drm_printf(p, "\n");
185
186 drm_printf(p, "Whitelist\n");
187 for_each_hw_engine(hwe, gt, id)
188 xe_reg_whitelist_dump(&hwe->reg_whitelist, p);
189
190 xe_pm_runtime_put(gt_to_xe(gt));
191
192 return 0;
193 }
194
workarounds(struct xe_gt * gt,struct drm_printer * p)195 static int workarounds(struct xe_gt *gt, struct drm_printer *p)
196 {
197 xe_pm_runtime_get(gt_to_xe(gt));
198 xe_wa_dump(gt, p);
199 xe_pm_runtime_put(gt_to_xe(gt));
200
201 return 0;
202 }
203
tunings(struct xe_gt * gt,struct drm_printer * p)204 static int tunings(struct xe_gt *gt, struct drm_printer *p)
205 {
206 xe_pm_runtime_get(gt_to_xe(gt));
207 xe_tuning_dump(gt, p);
208 xe_pm_runtime_put(gt_to_xe(gt));
209
210 return 0;
211 }
212
pat(struct xe_gt * gt,struct drm_printer * p)213 static int pat(struct xe_gt *gt, struct drm_printer *p)
214 {
215 xe_pm_runtime_get(gt_to_xe(gt));
216 xe_pat_dump(gt, p);
217 xe_pm_runtime_put(gt_to_xe(gt));
218
219 return 0;
220 }
221
mocs(struct xe_gt * gt,struct drm_printer * p)222 static int mocs(struct xe_gt *gt, struct drm_printer *p)
223 {
224 xe_pm_runtime_get(gt_to_xe(gt));
225 xe_mocs_dump(gt, p);
226 xe_pm_runtime_put(gt_to_xe(gt));
227
228 return 0;
229 }
230
rcs_default_lrc(struct xe_gt * gt,struct drm_printer * p)231 static int rcs_default_lrc(struct xe_gt *gt, struct drm_printer *p)
232 {
233 xe_pm_runtime_get(gt_to_xe(gt));
234 xe_lrc_dump_default(p, gt, XE_ENGINE_CLASS_RENDER);
235 xe_pm_runtime_put(gt_to_xe(gt));
236
237 return 0;
238 }
239
ccs_default_lrc(struct xe_gt * gt,struct drm_printer * p)240 static int ccs_default_lrc(struct xe_gt *gt, struct drm_printer *p)
241 {
242 xe_pm_runtime_get(gt_to_xe(gt));
243 xe_lrc_dump_default(p, gt, XE_ENGINE_CLASS_COMPUTE);
244 xe_pm_runtime_put(gt_to_xe(gt));
245
246 return 0;
247 }
248
bcs_default_lrc(struct xe_gt * gt,struct drm_printer * p)249 static int bcs_default_lrc(struct xe_gt *gt, struct drm_printer *p)
250 {
251 xe_pm_runtime_get(gt_to_xe(gt));
252 xe_lrc_dump_default(p, gt, XE_ENGINE_CLASS_COPY);
253 xe_pm_runtime_put(gt_to_xe(gt));
254
255 return 0;
256 }
257
vcs_default_lrc(struct xe_gt * gt,struct drm_printer * p)258 static int vcs_default_lrc(struct xe_gt *gt, struct drm_printer *p)
259 {
260 xe_pm_runtime_get(gt_to_xe(gt));
261 xe_lrc_dump_default(p, gt, XE_ENGINE_CLASS_VIDEO_DECODE);
262 xe_pm_runtime_put(gt_to_xe(gt));
263
264 return 0;
265 }
266
vecs_default_lrc(struct xe_gt * gt,struct drm_printer * p)267 static int vecs_default_lrc(struct xe_gt *gt, struct drm_printer *p)
268 {
269 xe_pm_runtime_get(gt_to_xe(gt));
270 xe_lrc_dump_default(p, gt, XE_ENGINE_CLASS_VIDEO_ENHANCE);
271 xe_pm_runtime_put(gt_to_xe(gt));
272
273 return 0;
274 }
275
hwconfig(struct xe_gt * gt,struct drm_printer * p)276 static int hwconfig(struct xe_gt *gt, struct drm_printer *p)
277 {
278 xe_pm_runtime_get(gt_to_xe(gt));
279 xe_guc_hwconfig_dump(>->uc.guc, p);
280 xe_pm_runtime_put(gt_to_xe(gt));
281
282 return 0;
283 }
284
285 /*
286 * only for GT debugfs files which can be safely used on the VF as well:
287 * - without access to the GT privileged registers
288 * - without access to the PF specific data
289 */
290 static const struct drm_info_list vf_safe_debugfs_list[] = {
291 {"sa_info", .show = xe_gt_debugfs_simple_show, .data = sa_info},
292 {"topology", .show = xe_gt_debugfs_simple_show, .data = topology},
293 {"ggtt", .show = xe_gt_debugfs_simple_show, .data = ggtt},
294 {"register-save-restore", .show = xe_gt_debugfs_simple_show, .data = register_save_restore},
295 {"workarounds", .show = xe_gt_debugfs_simple_show, .data = workarounds},
296 {"tunings", .show = xe_gt_debugfs_simple_show, .data = tunings},
297 {"default_lrc_rcs", .show = xe_gt_debugfs_simple_show, .data = rcs_default_lrc},
298 {"default_lrc_ccs", .show = xe_gt_debugfs_simple_show, .data = ccs_default_lrc},
299 {"default_lrc_bcs", .show = xe_gt_debugfs_simple_show, .data = bcs_default_lrc},
300 {"default_lrc_vcs", .show = xe_gt_debugfs_simple_show, .data = vcs_default_lrc},
301 {"default_lrc_vecs", .show = xe_gt_debugfs_simple_show, .data = vecs_default_lrc},
302 {"stats", .show = xe_gt_debugfs_simple_show, .data = xe_gt_stats_print_info},
303 {"hwconfig", .show = xe_gt_debugfs_simple_show, .data = hwconfig},
304 };
305
306 /* everything else should be added here */
307 static const struct drm_info_list pf_only_debugfs_list[] = {
308 {"hw_engines", .show = xe_gt_debugfs_simple_show, .data = hw_engines},
309 {"mocs", .show = xe_gt_debugfs_simple_show, .data = mocs},
310 {"pat", .show = xe_gt_debugfs_simple_show, .data = pat},
311 {"powergate_info", .show = xe_gt_debugfs_simple_show, .data = powergate_info},
312 {"steering", .show = xe_gt_debugfs_simple_show, .data = steering},
313 };
314
write_to_gt_call(const char __user * userbuf,size_t count,loff_t * ppos,void (* call)(struct xe_gt *),struct xe_gt * gt)315 static ssize_t write_to_gt_call(const char __user *userbuf, size_t count, loff_t *ppos,
316 void (*call)(struct xe_gt *), struct xe_gt *gt)
317 {
318 bool yes;
319 int ret;
320
321 if (*ppos)
322 return -EINVAL;
323 ret = kstrtobool_from_user(userbuf, count, &yes);
324 if (ret < 0)
325 return ret;
326 if (yes)
327 call(gt);
328 return count;
329 }
330
force_reset(struct xe_gt * gt)331 static void force_reset(struct xe_gt *gt)
332 {
333 struct xe_device *xe = gt_to_xe(gt);
334
335 xe_pm_runtime_get(xe);
336 xe_gt_reset_async(gt);
337 xe_pm_runtime_put(xe);
338 }
339
force_reset_write(struct file * file,const char __user * userbuf,size_t count,loff_t * ppos)340 static ssize_t force_reset_write(struct file *file,
341 const char __user *userbuf,
342 size_t count, loff_t *ppos)
343 {
344 struct seq_file *s = file->private_data;
345 struct xe_gt *gt = s->private;
346
347 return write_to_gt_call(userbuf, count, ppos, force_reset, gt);
348 }
349
force_reset_show(struct seq_file * s,void * unused)350 static int force_reset_show(struct seq_file *s, void *unused)
351 {
352 struct xe_gt *gt = s->private;
353
354 force_reset(gt); /* to be deprecated! */
355 return 0;
356 }
357 DEFINE_SHOW_STORE_ATTRIBUTE(force_reset);
358
force_reset_sync(struct xe_gt * gt)359 static void force_reset_sync(struct xe_gt *gt)
360 {
361 struct xe_device *xe = gt_to_xe(gt);
362
363 xe_pm_runtime_get(xe);
364 xe_gt_reset(gt);
365 xe_pm_runtime_put(xe);
366 }
367
force_reset_sync_write(struct file * file,const char __user * userbuf,size_t count,loff_t * ppos)368 static ssize_t force_reset_sync_write(struct file *file,
369 const char __user *userbuf,
370 size_t count, loff_t *ppos)
371 {
372 struct seq_file *s = file->private_data;
373 struct xe_gt *gt = s->private;
374
375 return write_to_gt_call(userbuf, count, ppos, force_reset_sync, gt);
376 }
377
force_reset_sync_show(struct seq_file * s,void * unused)378 static int force_reset_sync_show(struct seq_file *s, void *unused)
379 {
380 struct xe_gt *gt = s->private;
381
382 force_reset_sync(gt); /* to be deprecated! */
383 return 0;
384 }
385 DEFINE_SHOW_STORE_ATTRIBUTE(force_reset_sync);
386
xe_gt_debugfs_register(struct xe_gt * gt)387 void xe_gt_debugfs_register(struct xe_gt *gt)
388 {
389 struct xe_device *xe = gt_to_xe(gt);
390 struct drm_minor *minor = gt_to_xe(gt)->drm.primary;
391 struct dentry *root;
392 char name[8];
393
394 xe_gt_assert(gt, minor->debugfs_root);
395
396 snprintf(name, sizeof(name), "gt%d", gt->info.id);
397 root = debugfs_create_dir(name, minor->debugfs_root);
398 if (IS_ERR(root)) {
399 drm_warn(&xe->drm, "Create GT directory failed");
400 return;
401 }
402
403 /*
404 * Store the xe_gt pointer as private data of the gt/ directory node
405 * so other GT specific attributes under that directory may refer to
406 * it by looking at its parent node private data.
407 */
408 root->d_inode->i_private = gt;
409
410 /* VF safe */
411 debugfs_create_file("force_reset", 0600, root, gt, &force_reset_fops);
412 debugfs_create_file("force_reset_sync", 0600, root, gt, &force_reset_sync_fops);
413
414 drm_debugfs_create_files(vf_safe_debugfs_list,
415 ARRAY_SIZE(vf_safe_debugfs_list),
416 root, minor);
417
418 if (!IS_SRIOV_VF(xe))
419 drm_debugfs_create_files(pf_only_debugfs_list,
420 ARRAY_SIZE(pf_only_debugfs_list),
421 root, minor);
422
423 xe_uc_debugfs_register(>->uc, root);
424
425 if (IS_SRIOV_PF(xe))
426 xe_gt_sriov_pf_debugfs_register(gt, root);
427 else if (IS_SRIOV_VF(xe))
428 xe_gt_sriov_vf_debugfs_register(gt, root);
429 }
430