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_topology.h" 19 #include "xe_hw_engine.h" 20 #include "xe_lrc.h" 21 #include "xe_macros.h" 22 #include "xe_pat.h" 23 #include "xe_pm.h" 24 #include "xe_reg_sr.h" 25 #include "xe_reg_whitelist.h" 26 #include "xe_uc_debugfs.h" 27 #include "xe_wa.h" 28 29 /** 30 * xe_gt_debugfs_simple_show - A show callback for struct drm_info_list 31 * @m: the &seq_file 32 * @data: data used by the drm debugfs helpers 33 * 34 * This callback can be used in struct drm_info_list to describe debugfs 35 * files that are &xe_gt specific. 36 * 37 * It is assumed that those debugfs files will be created on directory entry 38 * which struct dentry d_inode->i_private points to &xe_gt. 39 * 40 * This function assumes that &m->private will be set to the &struct 41 * drm_info_node corresponding to the instance of the info on a given &struct 42 * drm_minor (see struct drm_info_list.show for details). 43 * 44 * This function also assumes that struct drm_info_list.data will point to the 45 * function code that will actually print a file content:: 46 * 47 * int (*print)(struct xe_gt *, struct drm_printer *) 48 * 49 * Example:: 50 * 51 * int foo(struct xe_gt *gt, struct drm_printer *p) 52 * { 53 * drm_printf(p, "GT%u\n", gt->info.id); 54 * return 0; 55 * } 56 * 57 * static const struct drm_info_list bar[] = { 58 * { name = "foo", .show = xe_gt_debugfs_simple_show, .data = foo }, 59 * }; 60 * 61 * dir = debugfs_create_dir("gt", parent); 62 * dir->d_inode->i_private = gt; 63 * drm_debugfs_create_files(bar, ARRAY_SIZE(bar), dir, minor); 64 * 65 * Return: 0 on success or a negative error code on failure. 66 */ 67 int xe_gt_debugfs_simple_show(struct seq_file *m, void *data) 68 { 69 struct drm_printer p = drm_seq_file_printer(m); 70 struct drm_info_node *node = m->private; 71 struct dentry *parent = node->dent->d_parent; 72 struct xe_gt *gt = parent->d_inode->i_private; 73 int (*print)(struct xe_gt *, struct drm_printer *) = node->info_ent->data; 74 75 if (WARN_ON(!print)) 76 return -EINVAL; 77 78 return print(gt, &p); 79 } 80 81 static int hw_engines(struct xe_gt *gt, struct drm_printer *p) 82 { 83 struct xe_device *xe = gt_to_xe(gt); 84 struct xe_hw_engine *hwe; 85 enum xe_hw_engine_id id; 86 int err; 87 88 xe_pm_runtime_get(xe); 89 err = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL); 90 if (err) { 91 xe_pm_runtime_put(xe); 92 return err; 93 } 94 95 for_each_hw_engine(hwe, gt, id) 96 xe_hw_engine_print(hwe, p); 97 98 err = xe_force_wake_put(gt_to_fw(gt), XE_FORCEWAKE_ALL); 99 xe_pm_runtime_put(xe); 100 if (err) 101 return err; 102 103 return 0; 104 } 105 106 static int force_reset(struct xe_gt *gt, struct drm_printer *p) 107 { 108 xe_pm_runtime_get(gt_to_xe(gt)); 109 xe_gt_reset_async(gt); 110 xe_pm_runtime_put(gt_to_xe(gt)); 111 112 return 0; 113 } 114 115 static int sa_info(struct xe_gt *gt, struct drm_printer *p) 116 { 117 struct xe_tile *tile = gt_to_tile(gt); 118 119 xe_pm_runtime_get(gt_to_xe(gt)); 120 drm_suballoc_dump_debug_info(&tile->mem.kernel_bb_pool->base, p, 121 tile->mem.kernel_bb_pool->gpu_addr); 122 xe_pm_runtime_put(gt_to_xe(gt)); 123 124 return 0; 125 } 126 127 static int topology(struct xe_gt *gt, struct drm_printer *p) 128 { 129 xe_pm_runtime_get(gt_to_xe(gt)); 130 xe_gt_topology_dump(gt, p); 131 xe_pm_runtime_put(gt_to_xe(gt)); 132 133 return 0; 134 } 135 136 static int steering(struct xe_gt *gt, struct drm_printer *p) 137 { 138 xe_pm_runtime_get(gt_to_xe(gt)); 139 xe_gt_mcr_steering_dump(gt, p); 140 xe_pm_runtime_put(gt_to_xe(gt)); 141 142 return 0; 143 } 144 145 static int ggtt(struct xe_gt *gt, struct drm_printer *p) 146 { 147 int ret; 148 149 xe_pm_runtime_get(gt_to_xe(gt)); 150 ret = xe_ggtt_dump(gt_to_tile(gt)->mem.ggtt, p); 151 xe_pm_runtime_put(gt_to_xe(gt)); 152 153 return ret; 154 } 155 156 static int register_save_restore(struct xe_gt *gt, struct drm_printer *p) 157 { 158 struct xe_hw_engine *hwe; 159 enum xe_hw_engine_id id; 160 161 xe_pm_runtime_get(gt_to_xe(gt)); 162 163 xe_reg_sr_dump(>->reg_sr, p); 164 drm_printf(p, "\n"); 165 166 drm_printf(p, "Engine\n"); 167 for_each_hw_engine(hwe, gt, id) 168 xe_reg_sr_dump(&hwe->reg_sr, p); 169 drm_printf(p, "\n"); 170 171 drm_printf(p, "LRC\n"); 172 for_each_hw_engine(hwe, gt, id) 173 xe_reg_sr_dump(&hwe->reg_lrc, p); 174 drm_printf(p, "\n"); 175 176 drm_printf(p, "Whitelist\n"); 177 for_each_hw_engine(hwe, gt, id) 178 xe_reg_whitelist_dump(&hwe->reg_whitelist, p); 179 180 xe_pm_runtime_put(gt_to_xe(gt)); 181 182 return 0; 183 } 184 185 static int workarounds(struct xe_gt *gt, struct drm_printer *p) 186 { 187 xe_pm_runtime_get(gt_to_xe(gt)); 188 xe_wa_dump(gt, p); 189 xe_pm_runtime_put(gt_to_xe(gt)); 190 191 return 0; 192 } 193 194 static int pat(struct xe_gt *gt, struct drm_printer *p) 195 { 196 xe_pm_runtime_get(gt_to_xe(gt)); 197 xe_pat_dump(gt, p); 198 xe_pm_runtime_put(gt_to_xe(gt)); 199 200 return 0; 201 } 202 203 static int rcs_default_lrc(struct xe_gt *gt, struct drm_printer *p) 204 { 205 xe_pm_runtime_get(gt_to_xe(gt)); 206 xe_lrc_dump_default(p, gt, XE_ENGINE_CLASS_RENDER); 207 xe_pm_runtime_put(gt_to_xe(gt)); 208 209 return 0; 210 } 211 212 static int ccs_default_lrc(struct xe_gt *gt, struct drm_printer *p) 213 { 214 xe_pm_runtime_get(gt_to_xe(gt)); 215 xe_lrc_dump_default(p, gt, XE_ENGINE_CLASS_COMPUTE); 216 xe_pm_runtime_put(gt_to_xe(gt)); 217 218 return 0; 219 } 220 221 static int bcs_default_lrc(struct xe_gt *gt, struct drm_printer *p) 222 { 223 xe_pm_runtime_get(gt_to_xe(gt)); 224 xe_lrc_dump_default(p, gt, XE_ENGINE_CLASS_COPY); 225 xe_pm_runtime_put(gt_to_xe(gt)); 226 227 return 0; 228 } 229 230 static int vcs_default_lrc(struct xe_gt *gt, struct drm_printer *p) 231 { 232 xe_pm_runtime_get(gt_to_xe(gt)); 233 xe_lrc_dump_default(p, gt, XE_ENGINE_CLASS_VIDEO_DECODE); 234 xe_pm_runtime_put(gt_to_xe(gt)); 235 236 return 0; 237 } 238 239 static int vecs_default_lrc(struct xe_gt *gt, struct drm_printer *p) 240 { 241 xe_pm_runtime_get(gt_to_xe(gt)); 242 xe_lrc_dump_default(p, gt, XE_ENGINE_CLASS_VIDEO_ENHANCE); 243 xe_pm_runtime_put(gt_to_xe(gt)); 244 245 return 0; 246 } 247 248 static const struct drm_info_list debugfs_list[] = { 249 {"hw_engines", .show = xe_gt_debugfs_simple_show, .data = hw_engines}, 250 {"force_reset", .show = xe_gt_debugfs_simple_show, .data = force_reset}, 251 {"sa_info", .show = xe_gt_debugfs_simple_show, .data = sa_info}, 252 {"topology", .show = xe_gt_debugfs_simple_show, .data = topology}, 253 {"steering", .show = xe_gt_debugfs_simple_show, .data = steering}, 254 {"ggtt", .show = xe_gt_debugfs_simple_show, .data = ggtt}, 255 {"register-save-restore", .show = xe_gt_debugfs_simple_show, .data = register_save_restore}, 256 {"workarounds", .show = xe_gt_debugfs_simple_show, .data = workarounds}, 257 {"pat", .show = xe_gt_debugfs_simple_show, .data = pat}, 258 {"default_lrc_rcs", .show = xe_gt_debugfs_simple_show, .data = rcs_default_lrc}, 259 {"default_lrc_ccs", .show = xe_gt_debugfs_simple_show, .data = ccs_default_lrc}, 260 {"default_lrc_bcs", .show = xe_gt_debugfs_simple_show, .data = bcs_default_lrc}, 261 {"default_lrc_vcs", .show = xe_gt_debugfs_simple_show, .data = vcs_default_lrc}, 262 {"default_lrc_vecs", .show = xe_gt_debugfs_simple_show, .data = vecs_default_lrc}, 263 }; 264 265 void xe_gt_debugfs_register(struct xe_gt *gt) 266 { 267 struct xe_device *xe = gt_to_xe(gt); 268 struct drm_minor *minor = gt_to_xe(gt)->drm.primary; 269 struct dentry *root; 270 char name[8]; 271 272 xe_gt_assert(gt, minor->debugfs_root); 273 274 snprintf(name, sizeof(name), "gt%d", gt->info.id); 275 root = debugfs_create_dir(name, minor->debugfs_root); 276 if (IS_ERR(root)) { 277 drm_warn(&xe->drm, "Create GT directory failed"); 278 return; 279 } 280 281 /* 282 * Store the xe_gt pointer as private data of the gt/ directory node 283 * so other GT specific attributes under that directory may refer to 284 * it by looking at its parent node private data. 285 */ 286 root->d_inode->i_private = gt; 287 288 drm_debugfs_create_files(debugfs_list, 289 ARRAY_SIZE(debugfs_list), 290 root, minor); 291 292 xe_uc_debugfs_register(>->uc, root); 293 } 294