xref: /linux/drivers/gpu/drm/i915/gt/intel_gt_debugfs.c (revision 4359a011e259a4608afc7fb3635370c9d4ba5943)
1 // SPDX-License-Identifier: MIT
2 /*
3  * Copyright © 2019 Intel Corporation
4  */
5 
6 #include <linux/debugfs.h>
7 
8 #include "i915_drv.h"
9 #include "intel_gt.h"
10 #include "intel_gt_debugfs.h"
11 #include "intel_gt_engines_debugfs.h"
12 #include "intel_gt_mcr.h"
13 #include "intel_gt_pm_debugfs.h"
14 #include "intel_sseu_debugfs.h"
15 #include "pxp/intel_pxp_debugfs.h"
16 #include "uc/intel_uc_debugfs.h"
17 
18 int intel_gt_debugfs_reset_show(struct intel_gt *gt, u64 *val)
19 {
20 	int ret = intel_gt_terminally_wedged(gt);
21 
22 	switch (ret) {
23 	case -EIO:
24 		*val = 1;
25 		return 0;
26 	case 0:
27 		*val = 0;
28 		return 0;
29 	default:
30 		return ret;
31 	}
32 }
33 
34 void intel_gt_debugfs_reset_store(struct intel_gt *gt, u64 val)
35 {
36 	/* Flush any previous reset before applying for a new one */
37 	wait_event(gt->reset.queue,
38 		   !test_bit(I915_RESET_BACKOFF, &gt->reset.flags));
39 
40 	intel_gt_handle_error(gt, val, I915_ERROR_CAPTURE,
41 			      "Manually reset engine mask to %llx", val);
42 }
43 
44 /*
45  * keep the interface clean where the first parameter
46  * is a 'struct intel_gt *' instead of 'void *'
47  */
48 static int __intel_gt_debugfs_reset_show(void *data, u64 *val)
49 {
50 	return intel_gt_debugfs_reset_show(data, val);
51 }
52 
53 static int __intel_gt_debugfs_reset_store(void *data, u64 val)
54 {
55 	intel_gt_debugfs_reset_store(data, val);
56 
57 	return 0;
58 }
59 
60 DEFINE_SIMPLE_ATTRIBUTE(reset_fops, __intel_gt_debugfs_reset_show,
61 			__intel_gt_debugfs_reset_store, "%llu\n");
62 
63 static int steering_show(struct seq_file *m, void *data)
64 {
65 	struct drm_printer p = drm_seq_file_printer(m);
66 	struct intel_gt *gt = m->private;
67 
68 	intel_gt_mcr_report_steering(&p, gt, true);
69 
70 	return 0;
71 }
72 DEFINE_INTEL_GT_DEBUGFS_ATTRIBUTE(steering);
73 
74 static void gt_debugfs_register(struct intel_gt *gt, struct dentry *root)
75 {
76 	static const struct intel_gt_debugfs_file files[] = {
77 		{ "reset", &reset_fops, NULL },
78 		{ "steering", &steering_fops },
79 	};
80 
81 	intel_gt_debugfs_register_files(root, files, ARRAY_SIZE(files), gt);
82 }
83 
84 void intel_gt_debugfs_register(struct intel_gt *gt)
85 {
86 	struct dentry *root;
87 
88 	if (!gt->i915->drm.primary->debugfs_root)
89 		return;
90 
91 	root = debugfs_create_dir("gt", gt->i915->drm.primary->debugfs_root);
92 	if (IS_ERR(root))
93 		return;
94 
95 	gt_debugfs_register(gt, root);
96 
97 	intel_gt_engines_debugfs_register(gt, root);
98 	intel_gt_pm_debugfs_register(gt, root);
99 	intel_sseu_debugfs_register(gt, root);
100 
101 	intel_uc_debugfs_register(&gt->uc, root);
102 	intel_pxp_debugfs_register(&gt->pxp, root);
103 }
104 
105 void intel_gt_debugfs_register_files(struct dentry *root,
106 				     const struct intel_gt_debugfs_file *files,
107 				     unsigned long count, void *data)
108 {
109 	while (count--) {
110 		umode_t mode = files->fops->write ? 0644 : 0444;
111 
112 		if (!files->eval || files->eval(data))
113 			debugfs_create_file(files->name,
114 					    mode, root, data,
115 					    files->fops);
116 
117 		files++;
118 	}
119 }
120