xref: /linux/drivers/gpu/drm/xe/xe_debugfs.c (revision 170aafe35cb98e0f3fbacb446ea86389fbce22ea)
1 // SPDX-License-Identifier: MIT
2 /*
3  * Copyright © 2022 Intel Corporation
4  */
5 
6 #include "xe_debugfs.h"
7 
8 #include <linux/debugfs.h>
9 #include <linux/string_helpers.h>
10 
11 #include <drm/drm_debugfs.h>
12 
13 #include "xe_bo.h"
14 #include "xe_device.h"
15 #include "xe_force_wake.h"
16 #include "xe_gt_debugfs.h"
17 #include "xe_gt_printk.h"
18 #include "xe_guc_ads.h"
19 #include "xe_pm.h"
20 #include "xe_sriov.h"
21 #include "xe_step.h"
22 
23 #ifdef CONFIG_DRM_XE_DEBUG
24 #include "xe_bo_evict.h"
25 #include "xe_migrate.h"
26 #include "xe_vm.h"
27 #endif
28 
29 #ifdef CONFIG_FAULT_INJECTION
30 #include <linux/fault-inject.h> /* XXX: fault-inject.h is broken */
31 DECLARE_FAULT_ATTR(gt_reset_failure);
32 #endif
33 
34 static struct xe_device *node_to_xe(struct drm_info_node *node)
35 {
36 	return to_xe_device(node->minor->dev);
37 }
38 
39 static int info(struct seq_file *m, void *data)
40 {
41 	struct xe_device *xe = node_to_xe(m->private);
42 	struct drm_printer p = drm_seq_file_printer(m);
43 	struct xe_gt *gt;
44 	u8 id;
45 
46 	xe_pm_runtime_get(xe);
47 
48 	drm_printf(&p, "graphics_verx100 %d\n", xe->info.graphics_verx100);
49 	drm_printf(&p, "media_verx100 %d\n", xe->info.media_verx100);
50 	drm_printf(&p, "stepping G:%s M:%s D:%s B:%s\n",
51 		   xe_step_name(xe->info.step.graphics),
52 		   xe_step_name(xe->info.step.media),
53 		   xe_step_name(xe->info.step.display),
54 		   xe_step_name(xe->info.step.basedie));
55 	drm_printf(&p, "is_dgfx %s\n", str_yes_no(xe->info.is_dgfx));
56 	drm_printf(&p, "platform %d\n", xe->info.platform);
57 	drm_printf(&p, "subplatform %d\n",
58 		   xe->info.subplatform > XE_SUBPLATFORM_NONE ? xe->info.subplatform : 0);
59 	drm_printf(&p, "devid 0x%x\n", xe->info.devid);
60 	drm_printf(&p, "revid %d\n", xe->info.revid);
61 	drm_printf(&p, "tile_count %d\n", xe->info.tile_count);
62 	drm_printf(&p, "vm_max_level %d\n", xe->info.vm_max_level);
63 	drm_printf(&p, "force_execlist %s\n", str_yes_no(xe->info.force_execlist));
64 	drm_printf(&p, "has_flat_ccs %s\n", str_yes_no(xe->info.has_flat_ccs));
65 	drm_printf(&p, "has_usm %s\n", str_yes_no(xe->info.has_usm));
66 	drm_printf(&p, "skip_guc_pc %s\n", str_yes_no(xe->info.skip_guc_pc));
67 	for_each_gt(gt, xe, id) {
68 		drm_printf(&p, "gt%d force wake %d\n", id,
69 			   xe_force_wake_ref(gt_to_fw(gt), XE_FW_GT));
70 		drm_printf(&p, "gt%d engine_mask 0x%llx\n", id,
71 			   gt->info.engine_mask);
72 	}
73 
74 	xe_pm_runtime_put(xe);
75 	return 0;
76 }
77 
78 static int sriov_info(struct seq_file *m, void *data)
79 {
80 	struct xe_device *xe = node_to_xe(m->private);
81 	struct drm_printer p = drm_seq_file_printer(m);
82 
83 	xe_sriov_print_info(xe, &p);
84 	return 0;
85 }
86 
87 static const struct drm_info_list debugfs_list[] = {
88 	{"info", info, 0},
89 	{ .name = "sriov_info", .show = sriov_info, },
90 };
91 
92 static int forcewake_open(struct inode *inode, struct file *file)
93 {
94 	struct xe_device *xe = inode->i_private;
95 	struct xe_gt *gt;
96 	u8 id;
97 
98 	xe_pm_runtime_get(xe);
99 	for_each_gt(gt, xe, id)
100 		XE_WARN_ON(xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL));
101 
102 	return 0;
103 }
104 
105 static int forcewake_release(struct inode *inode, struct file *file)
106 {
107 	struct xe_device *xe = inode->i_private;
108 	struct xe_gt *gt;
109 	u8 id;
110 
111 	for_each_gt(gt, xe, id)
112 		XE_WARN_ON(xe_force_wake_put(gt_to_fw(gt), XE_FORCEWAKE_ALL));
113 	xe_pm_runtime_put(xe);
114 
115 	return 0;
116 }
117 
118 static const struct file_operations forcewake_all_fops = {
119 	.owner = THIS_MODULE,
120 	.open = forcewake_open,
121 	.release = forcewake_release,
122 };
123 
124 static ssize_t wedged_mode_show(struct file *f, char __user *ubuf,
125 				size_t size, loff_t *pos)
126 {
127 	struct xe_device *xe = file_inode(f)->i_private;
128 	char buf[32];
129 	int len = 0;
130 
131 	len = scnprintf(buf, sizeof(buf), "%d\n", xe->wedged.mode);
132 
133 	return simple_read_from_buffer(ubuf, size, pos, buf, len);
134 }
135 
136 static ssize_t wedged_mode_set(struct file *f, const char __user *ubuf,
137 			       size_t size, loff_t *pos)
138 {
139 	struct xe_device *xe = file_inode(f)->i_private;
140 	struct xe_gt *gt;
141 	u32 wedged_mode;
142 	ssize_t ret;
143 	u8 id;
144 
145 	ret = kstrtouint_from_user(ubuf, size, 0, &wedged_mode);
146 	if (ret)
147 		return ret;
148 
149 	if (wedged_mode > 2)
150 		return -EINVAL;
151 
152 	if (xe->wedged.mode == wedged_mode)
153 		return 0;
154 
155 	xe->wedged.mode = wedged_mode;
156 
157 	xe_pm_runtime_get(xe);
158 	for_each_gt(gt, xe, id) {
159 		ret = xe_guc_ads_scheduler_policy_toggle_reset(&gt->uc.guc.ads);
160 		if (ret) {
161 			xe_gt_err(gt, "Failed to update GuC ADS scheduler policy. GuC may still cause engine reset even with wedged_mode=2\n");
162 			return -EIO;
163 		}
164 	}
165 	xe_pm_runtime_put(xe);
166 
167 	return size;
168 }
169 
170 static const struct file_operations wedged_mode_fops = {
171 	.owner = THIS_MODULE,
172 	.read = wedged_mode_show,
173 	.write = wedged_mode_set,
174 };
175 
176 void xe_debugfs_register(struct xe_device *xe)
177 {
178 	struct ttm_device *bdev = &xe->ttm;
179 	struct drm_minor *minor = xe->drm.primary;
180 	struct dentry *root = minor->debugfs_root;
181 	struct ttm_resource_manager *man;
182 	struct xe_gt *gt;
183 	u32 mem_type;
184 	u8 id;
185 
186 	drm_debugfs_create_files(debugfs_list,
187 				 ARRAY_SIZE(debugfs_list),
188 				 root, minor);
189 
190 	debugfs_create_file("forcewake_all", 0400, root, xe,
191 			    &forcewake_all_fops);
192 
193 	debugfs_create_file("wedged_mode", 0400, root, xe,
194 			    &wedged_mode_fops);
195 
196 	for (mem_type = XE_PL_VRAM0; mem_type <= XE_PL_VRAM1; ++mem_type) {
197 		man = ttm_manager_type(bdev, mem_type);
198 
199 		if (man) {
200 			char name[16];
201 
202 			snprintf(name, sizeof(name), "vram%d_mm", mem_type - XE_PL_VRAM0);
203 			ttm_resource_manager_create_debugfs(man, root, name);
204 		}
205 	}
206 
207 	man = ttm_manager_type(bdev, XE_PL_TT);
208 	ttm_resource_manager_create_debugfs(man, root, "gtt_mm");
209 
210 	man = ttm_manager_type(bdev, XE_PL_STOLEN);
211 	if (man)
212 		ttm_resource_manager_create_debugfs(man, root, "stolen_mm");
213 
214 	for_each_gt(gt, xe, id)
215 		xe_gt_debugfs_register(gt);
216 
217 #ifdef CONFIG_FAULT_INJECTION
218 	fault_create_debugfs_attr("fail_gt_reset", root, &gt_reset_failure);
219 #endif
220 
221 }
222