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_sa.h" 33 #include "xe_sriov.h" 34 #include "xe_tuning.h" 35 #include "xe_uc_debugfs.h" 36 #include "xe_wa.h" 37 38 /** 39 * xe_gt_debugfs_simple_show - A show callback for struct drm_info_list 40 * @m: the &seq_file 41 * @data: data used by the drm debugfs helpers 42 * 43 * This callback can be used in struct drm_info_list to describe debugfs 44 * files that are &xe_gt specific. 45 * 46 * It is assumed that those debugfs files will be created on directory entry 47 * which struct dentry d_inode->i_private points to &xe_gt. 48 * 49 * This function assumes that &m->private will be set to the &struct 50 * drm_info_node corresponding to the instance of the info on a given &struct 51 * drm_minor (see struct drm_info_list.show for details). 52 * 53 * This function also assumes that struct drm_info_list.data will point to the 54 * function code that will actually print a file content:: 55 * 56 * int (*print)(struct xe_gt *, struct drm_printer *) 57 * 58 * Example:: 59 * 60 * int foo(struct xe_gt *gt, struct drm_printer *p) 61 * { 62 * drm_printf(p, "GT%u\n", gt->info.id); 63 * return 0; 64 * } 65 * 66 * static const struct drm_info_list bar[] = { 67 * { name = "foo", .show = xe_gt_debugfs_simple_show, .data = foo }, 68 * }; 69 * 70 * dir = debugfs_create_dir("gt", parent); 71 * dir->d_inode->i_private = gt; 72 * drm_debugfs_create_files(bar, ARRAY_SIZE(bar), dir, minor); 73 * 74 * Return: 0 on success or a negative error code on failure. 75 */ 76 int xe_gt_debugfs_simple_show(struct seq_file *m, void *data) 77 { 78 struct drm_printer p = drm_seq_file_printer(m); 79 struct drm_info_node *node = m->private; 80 struct dentry *parent = node->dent->d_parent; 81 struct xe_gt *gt = parent->d_inode->i_private; 82 int (*print)(struct xe_gt *, struct drm_printer *) = node->info_ent->data; 83 84 if (WARN_ON(!print)) 85 return -EINVAL; 86 87 return print(gt, &p); 88 } 89 90 static int hw_engines(struct xe_gt *gt, struct drm_printer *p) 91 { 92 struct xe_device *xe = gt_to_xe(gt); 93 struct xe_hw_engine *hwe; 94 enum xe_hw_engine_id id; 95 unsigned int fw_ref; 96 int ret = 0; 97 98 xe_pm_runtime_get(xe); 99 fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL); 100 if (!xe_force_wake_ref_has_domain(fw_ref, XE_FORCEWAKE_ALL)) { 101 ret = -ETIMEDOUT; 102 goto fw_put; 103 } 104 105 for_each_hw_engine(hwe, gt, id) 106 xe_hw_engine_print(hwe, p); 107 108 fw_put: 109 xe_force_wake_put(gt_to_fw(gt), fw_ref); 110 xe_pm_runtime_put(xe); 111 112 return ret; 113 } 114 115 static int powergate_info(struct xe_gt *gt, struct drm_printer *p) 116 { 117 int ret; 118 119 xe_pm_runtime_get(gt_to_xe(gt)); 120 ret = xe_gt_idle_pg_print(gt, p); 121 xe_pm_runtime_put(gt_to_xe(gt)); 122 123 return ret; 124 } 125 126 static int sa_info(struct xe_gt *gt, struct drm_printer *p) 127 { 128 struct xe_tile *tile = gt_to_tile(gt); 129 130 xe_pm_runtime_get(gt_to_xe(gt)); 131 drm_suballoc_dump_debug_info(&tile->mem.kernel_bb_pool->base, p, 132 xe_sa_manager_gpu_addr(tile->mem.kernel_bb_pool)); 133 xe_pm_runtime_put(gt_to_xe(gt)); 134 135 return 0; 136 } 137 138 static int sa_info_vf_ccs(struct xe_gt *gt, struct drm_printer *p) 139 { 140 struct xe_tile *tile = gt_to_tile(gt); 141 struct xe_sa_manager *bb_pool; 142 enum xe_sriov_vf_ccs_rw_ctxs ctx_id; 143 144 if (!IS_VF_CCS_READY(gt_to_xe(gt))) 145 return 0; 146 147 xe_pm_runtime_get(gt_to_xe(gt)); 148 149 for_each_ccs_rw_ctx(ctx_id) { 150 bb_pool = tile->sriov.vf.ccs[ctx_id].mem.ccs_bb_pool; 151 if (!bb_pool) 152 break; 153 154 drm_printf(p, "ccs %s bb suballoc info\n", ctx_id ? "write" : "read"); 155 drm_printf(p, "-------------------------\n"); 156 drm_suballoc_dump_debug_info(&bb_pool->base, p, xe_sa_manager_gpu_addr(bb_pool)); 157 drm_puts(p, "\n"); 158 } 159 160 xe_pm_runtime_put(gt_to_xe(gt)); 161 162 return 0; 163 } 164 165 static int topology(struct xe_gt *gt, struct drm_printer *p) 166 { 167 xe_pm_runtime_get(gt_to_xe(gt)); 168 xe_gt_topology_dump(gt, p); 169 xe_pm_runtime_put(gt_to_xe(gt)); 170 171 return 0; 172 } 173 174 static int steering(struct xe_gt *gt, struct drm_printer *p) 175 { 176 xe_pm_runtime_get(gt_to_xe(gt)); 177 xe_gt_mcr_steering_dump(gt, p); 178 xe_pm_runtime_put(gt_to_xe(gt)); 179 180 return 0; 181 } 182 183 static int ggtt(struct xe_gt *gt, struct drm_printer *p) 184 { 185 int ret; 186 187 xe_pm_runtime_get(gt_to_xe(gt)); 188 ret = xe_ggtt_dump(gt_to_tile(gt)->mem.ggtt, p); 189 xe_pm_runtime_put(gt_to_xe(gt)); 190 191 return ret; 192 } 193 194 static int register_save_restore(struct xe_gt *gt, struct drm_printer *p) 195 { 196 struct xe_hw_engine *hwe; 197 enum xe_hw_engine_id id; 198 199 xe_pm_runtime_get(gt_to_xe(gt)); 200 201 xe_reg_sr_dump(>->reg_sr, p); 202 drm_printf(p, "\n"); 203 204 drm_printf(p, "Engine\n"); 205 for_each_hw_engine(hwe, gt, id) 206 xe_reg_sr_dump(&hwe->reg_sr, p); 207 drm_printf(p, "\n"); 208 209 drm_printf(p, "LRC\n"); 210 for_each_hw_engine(hwe, gt, id) 211 xe_reg_sr_dump(&hwe->reg_lrc, p); 212 drm_printf(p, "\n"); 213 214 drm_printf(p, "Whitelist\n"); 215 for_each_hw_engine(hwe, gt, id) 216 xe_reg_whitelist_dump(&hwe->reg_whitelist, p); 217 218 xe_pm_runtime_put(gt_to_xe(gt)); 219 220 return 0; 221 } 222 223 static int workarounds(struct xe_gt *gt, struct drm_printer *p) 224 { 225 xe_pm_runtime_get(gt_to_xe(gt)); 226 xe_wa_dump(gt, p); 227 xe_pm_runtime_put(gt_to_xe(gt)); 228 229 return 0; 230 } 231 232 static int tunings(struct xe_gt *gt, struct drm_printer *p) 233 { 234 xe_pm_runtime_get(gt_to_xe(gt)); 235 xe_tuning_dump(gt, p); 236 xe_pm_runtime_put(gt_to_xe(gt)); 237 238 return 0; 239 } 240 241 static int pat(struct xe_gt *gt, struct drm_printer *p) 242 { 243 xe_pm_runtime_get(gt_to_xe(gt)); 244 xe_pat_dump(gt, p); 245 xe_pm_runtime_put(gt_to_xe(gt)); 246 247 return 0; 248 } 249 250 static int mocs(struct xe_gt *gt, struct drm_printer *p) 251 { 252 xe_pm_runtime_get(gt_to_xe(gt)); 253 xe_mocs_dump(gt, p); 254 xe_pm_runtime_put(gt_to_xe(gt)); 255 256 return 0; 257 } 258 259 static int rcs_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_RENDER); 263 xe_pm_runtime_put(gt_to_xe(gt)); 264 265 return 0; 266 } 267 268 static int ccs_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_COMPUTE); 272 xe_pm_runtime_put(gt_to_xe(gt)); 273 274 return 0; 275 } 276 277 static int bcs_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_COPY); 281 xe_pm_runtime_put(gt_to_xe(gt)); 282 283 return 0; 284 } 285 286 static int vcs_default_lrc(struct xe_gt *gt, struct drm_printer *p) 287 { 288 xe_pm_runtime_get(gt_to_xe(gt)); 289 xe_lrc_dump_default(p, gt, XE_ENGINE_CLASS_VIDEO_DECODE); 290 xe_pm_runtime_put(gt_to_xe(gt)); 291 292 return 0; 293 } 294 295 static int vecs_default_lrc(struct xe_gt *gt, struct drm_printer *p) 296 { 297 xe_pm_runtime_get(gt_to_xe(gt)); 298 xe_lrc_dump_default(p, gt, XE_ENGINE_CLASS_VIDEO_ENHANCE); 299 xe_pm_runtime_put(gt_to_xe(gt)); 300 301 return 0; 302 } 303 304 static int hwconfig(struct xe_gt *gt, struct drm_printer *p) 305 { 306 xe_pm_runtime_get(gt_to_xe(gt)); 307 xe_guc_hwconfig_dump(>->uc.guc, p); 308 xe_pm_runtime_put(gt_to_xe(gt)); 309 310 return 0; 311 } 312 313 /* 314 * only for GT debugfs files which can be safely used on the VF as well: 315 * - without access to the GT privileged registers 316 * - without access to the PF specific data 317 */ 318 static const struct drm_info_list vf_safe_debugfs_list[] = { 319 {"sa_info", .show = xe_gt_debugfs_simple_show, .data = sa_info}, 320 {"topology", .show = xe_gt_debugfs_simple_show, .data = topology}, 321 {"ggtt", .show = xe_gt_debugfs_simple_show, .data = ggtt}, 322 {"register-save-restore", .show = xe_gt_debugfs_simple_show, .data = register_save_restore}, 323 {"workarounds", .show = xe_gt_debugfs_simple_show, .data = workarounds}, 324 {"tunings", .show = xe_gt_debugfs_simple_show, .data = tunings}, 325 {"default_lrc_rcs", .show = xe_gt_debugfs_simple_show, .data = rcs_default_lrc}, 326 {"default_lrc_ccs", .show = xe_gt_debugfs_simple_show, .data = ccs_default_lrc}, 327 {"default_lrc_bcs", .show = xe_gt_debugfs_simple_show, .data = bcs_default_lrc}, 328 {"default_lrc_vcs", .show = xe_gt_debugfs_simple_show, .data = vcs_default_lrc}, 329 {"default_lrc_vecs", .show = xe_gt_debugfs_simple_show, .data = vecs_default_lrc}, 330 {"stats", .show = xe_gt_debugfs_simple_show, .data = xe_gt_stats_print_info}, 331 {"hwconfig", .show = xe_gt_debugfs_simple_show, .data = hwconfig}, 332 }; 333 334 /* 335 * only for GT debugfs files which are valid on VF. Not valid on PF. 336 */ 337 static const struct drm_info_list vf_only_debugfs_list[] = { 338 {"sa_info_vf_ccs", .show = xe_gt_debugfs_simple_show, .data = sa_info_vf_ccs}, 339 }; 340 341 /* everything else should be added here */ 342 static const struct drm_info_list pf_only_debugfs_list[] = { 343 {"hw_engines", .show = xe_gt_debugfs_simple_show, .data = hw_engines}, 344 {"mocs", .show = xe_gt_debugfs_simple_show, .data = mocs}, 345 {"pat", .show = xe_gt_debugfs_simple_show, .data = pat}, 346 {"powergate_info", .show = xe_gt_debugfs_simple_show, .data = powergate_info}, 347 {"steering", .show = xe_gt_debugfs_simple_show, .data = steering}, 348 }; 349 350 static ssize_t write_to_gt_call(const char __user *userbuf, size_t count, loff_t *ppos, 351 void (*call)(struct xe_gt *), struct xe_gt *gt) 352 { 353 bool yes; 354 int ret; 355 356 if (*ppos) 357 return -EINVAL; 358 ret = kstrtobool_from_user(userbuf, count, &yes); 359 if (ret < 0) 360 return ret; 361 if (yes) 362 call(gt); 363 return count; 364 } 365 366 static void force_reset(struct xe_gt *gt) 367 { 368 struct xe_device *xe = gt_to_xe(gt); 369 370 xe_pm_runtime_get(xe); 371 xe_gt_reset_async(gt); 372 xe_pm_runtime_put(xe); 373 } 374 375 static ssize_t force_reset_write(struct file *file, 376 const char __user *userbuf, 377 size_t count, loff_t *ppos) 378 { 379 struct seq_file *s = file->private_data; 380 struct xe_gt *gt = s->private; 381 382 return write_to_gt_call(userbuf, count, ppos, force_reset, gt); 383 } 384 385 static int force_reset_show(struct seq_file *s, void *unused) 386 { 387 struct xe_gt *gt = s->private; 388 389 force_reset(gt); /* to be deprecated! */ 390 return 0; 391 } 392 DEFINE_SHOW_STORE_ATTRIBUTE(force_reset); 393 394 static void force_reset_sync(struct xe_gt *gt) 395 { 396 struct xe_device *xe = gt_to_xe(gt); 397 398 xe_pm_runtime_get(xe); 399 xe_gt_reset(gt); 400 xe_pm_runtime_put(xe); 401 } 402 403 static ssize_t force_reset_sync_write(struct file *file, 404 const char __user *userbuf, 405 size_t count, loff_t *ppos) 406 { 407 struct seq_file *s = file->private_data; 408 struct xe_gt *gt = s->private; 409 410 return write_to_gt_call(userbuf, count, ppos, force_reset_sync, gt); 411 } 412 413 static int force_reset_sync_show(struct seq_file *s, void *unused) 414 { 415 struct xe_gt *gt = s->private; 416 417 force_reset_sync(gt); /* to be deprecated! */ 418 return 0; 419 } 420 DEFINE_SHOW_STORE_ATTRIBUTE(force_reset_sync); 421 422 void xe_gt_debugfs_register(struct xe_gt *gt) 423 { 424 struct xe_device *xe = gt_to_xe(gt); 425 struct drm_minor *minor = gt_to_xe(gt)->drm.primary; 426 struct dentry *parent = gt->tile->debugfs; 427 struct dentry *root; 428 char symlink[16]; 429 char name[8]; 430 431 xe_gt_assert(gt, minor->debugfs_root); 432 433 if (IS_ERR(parent)) 434 return; 435 436 snprintf(name, sizeof(name), "gt%d", gt->info.id); 437 root = debugfs_create_dir(name, parent); 438 if (IS_ERR(root)) { 439 drm_warn(&xe->drm, "Create GT directory failed"); 440 return; 441 } 442 443 /* 444 * Store the xe_gt pointer as private data of the gt/ directory node 445 * so other GT specific attributes under that directory may refer to 446 * it by looking at its parent node private data. 447 */ 448 root->d_inode->i_private = gt; 449 450 /* VF safe */ 451 debugfs_create_file("force_reset", 0600, root, gt, &force_reset_fops); 452 debugfs_create_file("force_reset_sync", 0600, root, gt, &force_reset_sync_fops); 453 454 drm_debugfs_create_files(vf_safe_debugfs_list, 455 ARRAY_SIZE(vf_safe_debugfs_list), 456 root, minor); 457 458 if (!IS_SRIOV_VF(xe)) 459 drm_debugfs_create_files(pf_only_debugfs_list, 460 ARRAY_SIZE(pf_only_debugfs_list), 461 root, minor); 462 else 463 drm_debugfs_create_files(vf_only_debugfs_list, 464 ARRAY_SIZE(vf_only_debugfs_list), 465 root, minor); 466 467 468 xe_uc_debugfs_register(>->uc, root); 469 470 if (IS_SRIOV_PF(xe)) 471 xe_gt_sriov_pf_debugfs_register(gt, root); 472 else if (IS_SRIOV_VF(xe)) 473 xe_gt_sriov_vf_debugfs_register(gt, root); 474 475 /* 476 * Backwards compatibility only: create a link for the legacy clients 477 * who may expect gt/ directory at the root level, not the tile level. 478 */ 479 snprintf(symlink, sizeof(symlink), "tile%u/%s", gt->tile->id, name); 480 debugfs_create_symlink(name, minor->debugfs_root, symlink); 481 } 482