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_sriov_vf_ccs.h" 35 #include "xe_tuning.h" 36 #include "xe_uc_debugfs.h" 37 #include "xe_wa.h" 38 39 /** 40 * xe_gt_debugfs_simple_show - A show callback for struct drm_info_list 41 * @m: the &seq_file 42 * @data: data used by the drm debugfs helpers 43 * 44 * This callback can be used in struct drm_info_list to describe debugfs 45 * files that are &xe_gt specific. 46 * 47 * It is assumed that those debugfs files will be created on directory entry 48 * which struct dentry d_inode->i_private points to &xe_gt. 49 * 50 * This function assumes that &m->private will be set to the &struct 51 * drm_info_node corresponding to the instance of the info on a given &struct 52 * drm_minor (see struct drm_info_list.show for details). 53 * 54 * This function also assumes that struct drm_info_list.data will point to the 55 * function code that will actually print a file content:: 56 * 57 * int (*print)(struct xe_gt *, struct drm_printer *) 58 * 59 * Example:: 60 * 61 * int foo(struct xe_gt *gt, struct drm_printer *p) 62 * { 63 * drm_printf(p, "GT%u\n", gt->info.id); 64 * return 0; 65 * } 66 * 67 * static const struct drm_info_list bar[] = { 68 * { name = "foo", .show = xe_gt_debugfs_simple_show, .data = foo }, 69 * }; 70 * 71 * dir = debugfs_create_dir("gt", parent); 72 * dir->d_inode->i_private = gt; 73 * drm_debugfs_create_files(bar, ARRAY_SIZE(bar), dir, minor); 74 * 75 * Return: 0 on success or a negative error code on failure. 76 */ 77 int xe_gt_debugfs_simple_show(struct seq_file *m, void *data) 78 { 79 struct drm_printer p = drm_seq_file_printer(m); 80 struct drm_info_node *node = m->private; 81 struct dentry *parent = node->dent->d_parent; 82 struct xe_gt *gt = parent->d_inode->i_private; 83 int (*print)(struct xe_gt *, struct drm_printer *) = node->info_ent->data; 84 85 if (WARN_ON(!print)) 86 return -EINVAL; 87 88 return print(gt, &p); 89 } 90 91 static int hw_engines(struct xe_gt *gt, struct drm_printer *p) 92 { 93 struct xe_device *xe = gt_to_xe(gt); 94 struct xe_hw_engine *hwe; 95 enum xe_hw_engine_id id; 96 unsigned int fw_ref; 97 int ret = 0; 98 99 xe_pm_runtime_get(xe); 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 ret = -ETIMEDOUT; 103 goto fw_put; 104 } 105 106 for_each_hw_engine(hwe, gt, id) 107 xe_hw_engine_print(hwe, p); 108 109 fw_put: 110 xe_force_wake_put(gt_to_fw(gt), fw_ref); 111 xe_pm_runtime_put(xe); 112 113 return ret; 114 } 115 116 static int powergate_info(struct xe_gt *gt, struct drm_printer *p) 117 { 118 int ret; 119 120 xe_pm_runtime_get(gt_to_xe(gt)); 121 ret = xe_gt_idle_pg_print(gt, p); 122 xe_pm_runtime_put(gt_to_xe(gt)); 123 124 return ret; 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 tunings(struct xe_gt *gt, struct drm_printer *p) 195 { 196 xe_pm_runtime_get(gt_to_xe(gt)); 197 xe_tuning_dump(gt, p); 198 xe_pm_runtime_put(gt_to_xe(gt)); 199 200 return 0; 201 } 202 203 static int pat(struct xe_gt *gt, struct drm_printer *p) 204 { 205 xe_pm_runtime_get(gt_to_xe(gt)); 206 xe_pat_dump(gt, p); 207 xe_pm_runtime_put(gt_to_xe(gt)); 208 209 return 0; 210 } 211 212 static int mocs(struct xe_gt *gt, struct drm_printer *p) 213 { 214 xe_pm_runtime_get(gt_to_xe(gt)); 215 xe_mocs_dump(gt, p); 216 xe_pm_runtime_put(gt_to_xe(gt)); 217 218 return 0; 219 } 220 221 static int rcs_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_RENDER); 225 xe_pm_runtime_put(gt_to_xe(gt)); 226 227 return 0; 228 } 229 230 static int ccs_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_COMPUTE); 234 xe_pm_runtime_put(gt_to_xe(gt)); 235 236 return 0; 237 } 238 239 static int bcs_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_COPY); 243 xe_pm_runtime_put(gt_to_xe(gt)); 244 245 return 0; 246 } 247 248 static int vcs_default_lrc(struct xe_gt *gt, struct drm_printer *p) 249 { 250 xe_pm_runtime_get(gt_to_xe(gt)); 251 xe_lrc_dump_default(p, gt, XE_ENGINE_CLASS_VIDEO_DECODE); 252 xe_pm_runtime_put(gt_to_xe(gt)); 253 254 return 0; 255 } 256 257 static int vecs_default_lrc(struct xe_gt *gt, struct drm_printer *p) 258 { 259 xe_pm_runtime_get(gt_to_xe(gt)); 260 xe_lrc_dump_default(p, gt, XE_ENGINE_CLASS_VIDEO_ENHANCE); 261 xe_pm_runtime_put(gt_to_xe(gt)); 262 263 return 0; 264 } 265 266 static int hwconfig(struct xe_gt *gt, struct drm_printer *p) 267 { 268 xe_pm_runtime_get(gt_to_xe(gt)); 269 xe_guc_hwconfig_dump(>->uc.guc, p); 270 xe_pm_runtime_put(gt_to_xe(gt)); 271 272 return 0; 273 } 274 275 /* 276 * only for GT debugfs files which can be safely used on the VF as well: 277 * - without access to the GT privileged registers 278 * - without access to the PF specific data 279 */ 280 static const struct drm_info_list vf_safe_debugfs_list[] = { 281 {"topology", .show = xe_gt_debugfs_simple_show, .data = topology}, 282 {"ggtt", .show = xe_gt_debugfs_simple_show, .data = ggtt}, 283 {"register-save-restore", .show = xe_gt_debugfs_simple_show, .data = register_save_restore}, 284 {"workarounds", .show = xe_gt_debugfs_simple_show, .data = workarounds}, 285 {"tunings", .show = xe_gt_debugfs_simple_show, .data = tunings}, 286 {"default_lrc_rcs", .show = xe_gt_debugfs_simple_show, .data = rcs_default_lrc}, 287 {"default_lrc_ccs", .show = xe_gt_debugfs_simple_show, .data = ccs_default_lrc}, 288 {"default_lrc_bcs", .show = xe_gt_debugfs_simple_show, .data = bcs_default_lrc}, 289 {"default_lrc_vcs", .show = xe_gt_debugfs_simple_show, .data = vcs_default_lrc}, 290 {"default_lrc_vecs", .show = xe_gt_debugfs_simple_show, .data = vecs_default_lrc}, 291 {"hwconfig", .show = xe_gt_debugfs_simple_show, .data = hwconfig}, 292 }; 293 294 /* everything else should be added here */ 295 static const struct drm_info_list pf_only_debugfs_list[] = { 296 {"hw_engines", .show = xe_gt_debugfs_simple_show, .data = hw_engines}, 297 {"mocs", .show = xe_gt_debugfs_simple_show, .data = mocs}, 298 {"pat", .show = xe_gt_debugfs_simple_show, .data = pat}, 299 {"powergate_info", .show = xe_gt_debugfs_simple_show, .data = powergate_info}, 300 {"steering", .show = xe_gt_debugfs_simple_show, .data = steering}, 301 }; 302 303 static ssize_t write_to_gt_call(const char __user *userbuf, size_t count, loff_t *ppos, 304 void (*call)(struct xe_gt *), struct xe_gt *gt) 305 { 306 bool yes; 307 int ret; 308 309 if (*ppos) 310 return -EINVAL; 311 ret = kstrtobool_from_user(userbuf, count, &yes); 312 if (ret < 0) 313 return ret; 314 if (yes) 315 call(gt); 316 return count; 317 } 318 319 static ssize_t stats_write(struct file *file, const char __user *userbuf, 320 size_t count, loff_t *ppos) 321 { 322 struct seq_file *s = file->private_data; 323 struct xe_gt *gt = s->private; 324 325 return write_to_gt_call(userbuf, count, ppos, xe_gt_stats_clear, gt); 326 } 327 328 static int stats_show(struct seq_file *s, void *unused) 329 { 330 struct drm_printer p = drm_seq_file_printer(s); 331 struct xe_gt *gt = s->private; 332 333 return xe_gt_stats_print_info(gt, &p); 334 } 335 DEFINE_SHOW_STORE_ATTRIBUTE(stats); 336 337 static void force_reset(struct xe_gt *gt) 338 { 339 struct xe_device *xe = gt_to_xe(gt); 340 341 xe_pm_runtime_get(xe); 342 xe_gt_reset_async(gt); 343 xe_pm_runtime_put(xe); 344 } 345 346 static ssize_t force_reset_write(struct file *file, 347 const char __user *userbuf, 348 size_t count, loff_t *ppos) 349 { 350 struct seq_file *s = file->private_data; 351 struct xe_gt *gt = s->private; 352 353 return write_to_gt_call(userbuf, count, ppos, force_reset, gt); 354 } 355 356 static int force_reset_show(struct seq_file *s, void *unused) 357 { 358 struct xe_gt *gt = s->private; 359 360 force_reset(gt); /* to be deprecated! */ 361 return 0; 362 } 363 DEFINE_SHOW_STORE_ATTRIBUTE(force_reset); 364 365 static void force_reset_sync(struct xe_gt *gt) 366 { 367 struct xe_device *xe = gt_to_xe(gt); 368 369 xe_pm_runtime_get(xe); 370 xe_gt_reset(gt); 371 xe_pm_runtime_put(xe); 372 } 373 374 static ssize_t force_reset_sync_write(struct file *file, 375 const char __user *userbuf, 376 size_t count, loff_t *ppos) 377 { 378 struct seq_file *s = file->private_data; 379 struct xe_gt *gt = s->private; 380 381 return write_to_gt_call(userbuf, count, ppos, force_reset_sync, gt); 382 } 383 384 static int force_reset_sync_show(struct seq_file *s, void *unused) 385 { 386 struct xe_gt *gt = s->private; 387 388 force_reset_sync(gt); /* to be deprecated! */ 389 return 0; 390 } 391 DEFINE_SHOW_STORE_ATTRIBUTE(force_reset_sync); 392 393 void xe_gt_debugfs_register(struct xe_gt *gt) 394 { 395 struct xe_device *xe = gt_to_xe(gt); 396 struct drm_minor *minor = gt_to_xe(gt)->drm.primary; 397 struct dentry *parent = gt->tile->debugfs; 398 struct dentry *root; 399 char symlink[16]; 400 char name[8]; 401 402 xe_gt_assert(gt, minor->debugfs_root); 403 404 if (IS_ERR(parent)) 405 return; 406 407 snprintf(name, sizeof(name), "gt%d", gt->info.id); 408 root = debugfs_create_dir(name, parent); 409 if (IS_ERR(root)) { 410 drm_warn(&xe->drm, "Create GT directory failed"); 411 return; 412 } 413 414 /* 415 * Store the xe_gt pointer as private data of the gt/ directory node 416 * so other GT specific attributes under that directory may refer to 417 * it by looking at its parent node private data. 418 */ 419 root->d_inode->i_private = gt; 420 421 /* VF safe */ 422 debugfs_create_file("stats", 0600, root, gt, &stats_fops); 423 debugfs_create_file("force_reset", 0600, root, gt, &force_reset_fops); 424 debugfs_create_file("force_reset_sync", 0600, root, gt, &force_reset_sync_fops); 425 426 drm_debugfs_create_files(vf_safe_debugfs_list, 427 ARRAY_SIZE(vf_safe_debugfs_list), 428 root, minor); 429 430 if (!IS_SRIOV_VF(xe)) 431 drm_debugfs_create_files(pf_only_debugfs_list, 432 ARRAY_SIZE(pf_only_debugfs_list), 433 root, minor); 434 435 xe_uc_debugfs_register(>->uc, root); 436 437 if (IS_SRIOV_PF(xe)) 438 xe_gt_sriov_pf_debugfs_register(gt, root); 439 else if (IS_SRIOV_VF(xe)) 440 xe_gt_sriov_vf_debugfs_register(gt, root); 441 442 /* 443 * Backwards compatibility only: create a link for the legacy clients 444 * who may expect gt/ directory at the root level, not the tile level. 445 */ 446 snprintf(symlink, sizeof(symlink), "tile%u/%s", gt->tile->id, name); 447 debugfs_create_symlink(name, minor->debugfs_root, symlink); 448 } 449