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