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