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