| 1 | // SPDX-License-Identifier: MIT |
| 2 | /* |
| 3 | * Copyright © 2022 Intel Corporation |
| 4 | */ |
| 5 | |
| 6 | #include "xe_debugfs.h" |
| 7 | |
| 8 | #include <linux/debugfs.h> |
| 9 | #include <linux/fault-inject.h> |
| 10 | #include <linux/string_helpers.h> |
| 11 | |
| 12 | #include <drm/drm_debugfs.h> |
| 13 | |
| 14 | #include "regs/xe_pmt.h" |
| 15 | #include "xe_bo.h" |
| 16 | #include "xe_device.h" |
| 17 | #include "xe_force_wake.h" |
| 18 | #include "xe_gt_debugfs.h" |
| 19 | #include "xe_gt_printk.h" |
| 20 | #include "xe_guc_ads.h" |
| 21 | #include "xe_mmio.h" |
| 22 | #include "xe_pm.h" |
| 23 | #include "xe_psmi.h" |
| 24 | #include "xe_pxp_debugfs.h" |
| 25 | #include "xe_sriov.h" |
| 26 | #include "xe_sriov_pf_debugfs.h" |
| 27 | #include "xe_sriov_vf.h" |
| 28 | #include "xe_step.h" |
| 29 | #include "xe_tile_debugfs.h" |
| 30 | #include "xe_vsec.h" |
| 31 | #include "xe_wa.h" |
| 32 | |
| 33 | #ifdef CONFIG_DRM_XE_DEBUG |
| 34 | #include "xe_bo_evict.h" |
| 35 | #include "xe_migrate.h" |
| 36 | #include "xe_vm.h" |
| 37 | #endif |
| 38 | |
| 39 | DECLARE_FAULT_ATTR(gt_reset_failure); |
| 40 | DECLARE_FAULT_ATTR(inject_csc_hw_error); |
| 41 | |
| 42 | static void read_residency_counter(struct xe_device *xe, struct xe_mmio *mmio, |
| 43 | u32 offset, const char *name, struct drm_printer *p) |
| 44 | { |
| 45 | u64 residency = 0; |
| 46 | int ret; |
| 47 | |
| 48 | ret = xe_pmt_telem_read(to_pci_dev(xe->drm.dev), |
| 49 | guid: xe_mmio_read32(mmio, PUNIT_TELEMETRY_GUID), |
| 50 | data: &residency, user_offset: offset, count: sizeof(residency)); |
| 51 | if (ret != sizeof(residency)) { |
| 52 | drm_warn(&xe->drm, "%s counter failed to read, ret %d\n" , name, ret); |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | drm_printf(p, f: "%s : %llu\n" , name, residency); |
| 57 | } |
| 58 | |
| 59 | static struct xe_device *node_to_xe(struct drm_info_node *node) |
| 60 | { |
| 61 | return to_xe_device(dev: node->minor->dev); |
| 62 | } |
| 63 | |
| 64 | static int info(struct seq_file *m, void *data) |
| 65 | { |
| 66 | struct xe_device *xe = node_to_xe(node: m->private); |
| 67 | struct drm_printer p = drm_seq_file_printer(f: m); |
| 68 | struct xe_gt *gt; |
| 69 | u8 id; |
| 70 | |
| 71 | xe_pm_runtime_get(xe); |
| 72 | |
| 73 | drm_printf(p: &p, f: "graphics_verx100 %d\n" , xe->info.graphics_verx100); |
| 74 | drm_printf(p: &p, f: "media_verx100 %d\n" , xe->info.media_verx100); |
| 75 | drm_printf(p: &p, f: "stepping G:%s M:%s B:%s\n" , |
| 76 | xe_step_name(step: xe->info.step.graphics), |
| 77 | xe_step_name(step: xe->info.step.media), |
| 78 | xe_step_name(step: xe->info.step.basedie)); |
| 79 | drm_printf(p: &p, f: "is_dgfx %s\n" , str_yes_no(v: xe->info.is_dgfx)); |
| 80 | drm_printf(p: &p, f: "platform %d\n" , xe->info.platform); |
| 81 | drm_printf(p: &p, f: "subplatform %d\n" , |
| 82 | xe->info.subplatform > XE_SUBPLATFORM_NONE ? xe->info.subplatform : 0); |
| 83 | drm_printf(p: &p, f: "devid 0x%x\n" , xe->info.devid); |
| 84 | drm_printf(p: &p, f: "revid %d\n" , xe->info.revid); |
| 85 | drm_printf(p: &p, f: "tile_count %d\n" , xe->info.tile_count); |
| 86 | drm_printf(p: &p, f: "vm_max_level %d\n" , xe->info.vm_max_level); |
| 87 | drm_printf(p: &p, f: "force_execlist %s\n" , str_yes_no(v: xe->info.force_execlist)); |
| 88 | drm_printf(p: &p, f: "has_flat_ccs %s\n" , str_yes_no(v: xe->info.has_flat_ccs)); |
| 89 | drm_printf(p: &p, f: "has_usm %s\n" , str_yes_no(v: xe->info.has_usm)); |
| 90 | drm_printf(p: &p, f: "skip_guc_pc %s\n" , str_yes_no(v: xe->info.skip_guc_pc)); |
| 91 | for_each_gt(gt, xe, id) { |
| 92 | drm_printf(p: &p, f: "gt%d force wake %d\n" , id, |
| 93 | xe_force_wake_ref(fw: gt_to_fw(gt), domain: XE_FW_GT)); |
| 94 | drm_printf(p: &p, f: "gt%d engine_mask 0x%llx\n" , id, |
| 95 | gt->info.engine_mask); |
| 96 | } |
| 97 | |
| 98 | xe_pm_runtime_put(xe); |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | static int sriov_info(struct seq_file *m, void *data) |
| 103 | { |
| 104 | struct xe_device *xe = node_to_xe(node: m->private); |
| 105 | struct drm_printer p = drm_seq_file_printer(f: m); |
| 106 | |
| 107 | xe_sriov_print_info(xe, p: &p); |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | static int workarounds(struct xe_device *xe, struct drm_printer *p) |
| 112 | { |
| 113 | xe_pm_runtime_get(xe); |
| 114 | xe_wa_device_dump(xe, p); |
| 115 | xe_pm_runtime_put(xe); |
| 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | static int workaround_info(struct seq_file *m, void *data) |
| 121 | { |
| 122 | struct xe_device *xe = node_to_xe(node: m->private); |
| 123 | struct drm_printer p = drm_seq_file_printer(f: m); |
| 124 | |
| 125 | workarounds(xe, p: &p); |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | static int dgfx_pkg_residencies_show(struct seq_file *m, void *data) |
| 130 | { |
| 131 | struct xe_device *xe; |
| 132 | struct xe_mmio *mmio; |
| 133 | struct drm_printer p; |
| 134 | |
| 135 | xe = node_to_xe(node: m->private); |
| 136 | p = drm_seq_file_printer(f: m); |
| 137 | xe_pm_runtime_get(xe); |
| 138 | mmio = xe_root_tile_mmio(xe); |
| 139 | static const struct { |
| 140 | u32 offset; |
| 141 | const char *name; |
| 142 | } residencies[] = { |
| 143 | {BMG_G2_RESIDENCY_OFFSET, "Package G2" }, |
| 144 | {BMG_G6_RESIDENCY_OFFSET, "Package G6" }, |
| 145 | {BMG_G7_RESIDENCY_OFFSET, "Package G7" }, |
| 146 | {BMG_G8_RESIDENCY_OFFSET, "Package G8" }, |
| 147 | {BMG_G10_RESIDENCY_OFFSET, "Package G10" }, |
| 148 | {BMG_MODS_RESIDENCY_OFFSET, "Package ModS" } |
| 149 | }; |
| 150 | |
| 151 | for (int i = 0; i < ARRAY_SIZE(residencies); i++) |
| 152 | read_residency_counter(xe, mmio, offset: residencies[i].offset, name: residencies[i].name, p: &p); |
| 153 | |
| 154 | xe_pm_runtime_put(xe); |
| 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | static int dgfx_pcie_link_residencies_show(struct seq_file *m, void *data) |
| 159 | { |
| 160 | struct xe_device *xe; |
| 161 | struct xe_mmio *mmio; |
| 162 | struct drm_printer p; |
| 163 | |
| 164 | xe = node_to_xe(node: m->private); |
| 165 | p = drm_seq_file_printer(f: m); |
| 166 | xe_pm_runtime_get(xe); |
| 167 | mmio = xe_root_tile_mmio(xe); |
| 168 | |
| 169 | static const struct { |
| 170 | u32 offset; |
| 171 | const char *name; |
| 172 | } residencies[] = { |
| 173 | {BMG_PCIE_LINK_L0_RESIDENCY_OFFSET, "PCIE LINK L0 RESIDENCY" }, |
| 174 | {BMG_PCIE_LINK_L1_RESIDENCY_OFFSET, "PCIE LINK L1 RESIDENCY" }, |
| 175 | {BMG_PCIE_LINK_L1_2_RESIDENCY_OFFSET, "PCIE LINK L1.2 RESIDENCY" } |
| 176 | }; |
| 177 | |
| 178 | for (int i = 0; i < ARRAY_SIZE(residencies); i++) |
| 179 | read_residency_counter(xe, mmio, offset: residencies[i].offset, name: residencies[i].name, p: &p); |
| 180 | |
| 181 | xe_pm_runtime_put(xe); |
| 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | static const struct drm_info_list debugfs_list[] = { |
| 186 | {"info" , info, 0}, |
| 187 | { .name = "sriov_info" , .show = sriov_info, }, |
| 188 | { .name = "workarounds" , .show = workaround_info, }, |
| 189 | }; |
| 190 | |
| 191 | static const struct drm_info_list debugfs_residencies[] = { |
| 192 | { .name = "dgfx_pkg_residencies" , .show = dgfx_pkg_residencies_show, }, |
| 193 | { .name = "dgfx_pcie_link_residencies" , .show = dgfx_pcie_link_residencies_show, }, |
| 194 | }; |
| 195 | |
| 196 | static int forcewake_open(struct inode *inode, struct file *file) |
| 197 | { |
| 198 | struct xe_device *xe = inode->i_private; |
| 199 | struct xe_gt *gt; |
| 200 | u8 id, last_gt; |
| 201 | unsigned int fw_ref; |
| 202 | |
| 203 | xe_pm_runtime_get(xe); |
| 204 | for_each_gt(gt, xe, id) { |
| 205 | last_gt = id; |
| 206 | |
| 207 | fw_ref = xe_force_wake_get(fw: gt_to_fw(gt), domains: XE_FORCEWAKE_ALL); |
| 208 | if (!xe_force_wake_ref_has_domain(fw_ref, domain: XE_FORCEWAKE_ALL)) |
| 209 | goto err_fw_get; |
| 210 | } |
| 211 | |
| 212 | return 0; |
| 213 | |
| 214 | err_fw_get: |
| 215 | for_each_gt(gt, xe, id) { |
| 216 | if (id < last_gt) |
| 217 | xe_force_wake_put(fw: gt_to_fw(gt), fw_ref: XE_FORCEWAKE_ALL); |
| 218 | else if (id == last_gt) |
| 219 | xe_force_wake_put(fw: gt_to_fw(gt), fw_ref); |
| 220 | else |
| 221 | break; |
| 222 | } |
| 223 | |
| 224 | xe_pm_runtime_put(xe); |
| 225 | return -ETIMEDOUT; |
| 226 | } |
| 227 | |
| 228 | static int forcewake_release(struct inode *inode, struct file *file) |
| 229 | { |
| 230 | struct xe_device *xe = inode->i_private; |
| 231 | struct xe_gt *gt; |
| 232 | u8 id; |
| 233 | |
| 234 | for_each_gt(gt, xe, id) |
| 235 | xe_force_wake_put(fw: gt_to_fw(gt), fw_ref: XE_FORCEWAKE_ALL); |
| 236 | xe_pm_runtime_put(xe); |
| 237 | |
| 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | static const struct file_operations forcewake_all_fops = { |
| 242 | .owner = THIS_MODULE, |
| 243 | .open = forcewake_open, |
| 244 | .release = forcewake_release, |
| 245 | }; |
| 246 | |
| 247 | static ssize_t wedged_mode_show(struct file *f, char __user *ubuf, |
| 248 | size_t size, loff_t *pos) |
| 249 | { |
| 250 | struct xe_device *xe = file_inode(f)->i_private; |
| 251 | char buf[32]; |
| 252 | int len = 0; |
| 253 | |
| 254 | len = scnprintf(buf, size: sizeof(buf), fmt: "%d\n" , xe->wedged.mode); |
| 255 | |
| 256 | return simple_read_from_buffer(to: ubuf, count: size, ppos: pos, from: buf, available: len); |
| 257 | } |
| 258 | |
| 259 | static int __wedged_mode_set_reset_policy(struct xe_gt *gt, enum xe_wedged_mode mode) |
| 260 | { |
| 261 | bool enable_engine_reset; |
| 262 | int ret; |
| 263 | |
| 264 | enable_engine_reset = (mode != XE_WEDGED_MODE_UPON_ANY_HANG_NO_RESET); |
| 265 | ret = xe_guc_ads_scheduler_policy_toggle_reset(ads: >->uc.guc.ads, |
| 266 | enable_engine_reset); |
| 267 | if (ret) |
| 268 | xe_gt_err(gt, "Failed to update GuC ADS scheduler policy (%pe)\n" , ERR_PTR(ret)); |
| 269 | |
| 270 | return ret; |
| 271 | } |
| 272 | |
| 273 | static int wedged_mode_set_reset_policy(struct xe_device *xe, enum xe_wedged_mode mode) |
| 274 | { |
| 275 | struct xe_gt *gt; |
| 276 | int ret; |
| 277 | u8 id; |
| 278 | |
| 279 | guard(xe_pm_runtime)(T: xe); |
| 280 | for_each_gt(gt, xe, id) { |
| 281 | ret = __wedged_mode_set_reset_policy(gt, mode); |
| 282 | if (ret) { |
| 283 | if (id > 0) { |
| 284 | xe->wedged.inconsistent_reset = true; |
| 285 | drm_err(&xe->drm, "Inconsistent reset policy state between GTs\n" ); |
| 286 | } |
| 287 | return ret; |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | xe->wedged.inconsistent_reset = false; |
| 292 | |
| 293 | return 0; |
| 294 | } |
| 295 | |
| 296 | static bool wedged_mode_needs_policy_update(struct xe_device *xe, enum xe_wedged_mode mode) |
| 297 | { |
| 298 | if (xe->wedged.inconsistent_reset) |
| 299 | return true; |
| 300 | |
| 301 | if (xe->wedged.mode == mode) |
| 302 | return false; |
| 303 | |
| 304 | if (xe->wedged.mode == XE_WEDGED_MODE_UPON_ANY_HANG_NO_RESET || |
| 305 | mode == XE_WEDGED_MODE_UPON_ANY_HANG_NO_RESET) |
| 306 | return true; |
| 307 | |
| 308 | return false; |
| 309 | } |
| 310 | |
| 311 | static ssize_t wedged_mode_set(struct file *f, const char __user *ubuf, |
| 312 | size_t size, loff_t *pos) |
| 313 | { |
| 314 | struct xe_device *xe = file_inode(f)->i_private; |
| 315 | u32 wedged_mode; |
| 316 | ssize_t ret; |
| 317 | |
| 318 | ret = kstrtouint_from_user(s: ubuf, count: size, base: 0, res: &wedged_mode); |
| 319 | if (ret) |
| 320 | return ret; |
| 321 | |
| 322 | if (wedged_mode > 2) |
| 323 | return -EINVAL; |
| 324 | |
| 325 | if (wedged_mode_needs_policy_update(xe, mode: wedged_mode)) { |
| 326 | ret = wedged_mode_set_reset_policy(xe, mode: wedged_mode); |
| 327 | if (ret) |
| 328 | return ret; |
| 329 | } |
| 330 | |
| 331 | xe->wedged.mode = wedged_mode; |
| 332 | |
| 333 | return size; |
| 334 | } |
| 335 | |
| 336 | static const struct file_operations wedged_mode_fops = { |
| 337 | .owner = THIS_MODULE, |
| 338 | .read = wedged_mode_show, |
| 339 | .write = wedged_mode_set, |
| 340 | }; |
| 341 | |
| 342 | static ssize_t atomic_svm_timeslice_ms_show(struct file *f, char __user *ubuf, |
| 343 | size_t size, loff_t *pos) |
| 344 | { |
| 345 | struct xe_device *xe = file_inode(f)->i_private; |
| 346 | char buf[32]; |
| 347 | int len = 0; |
| 348 | |
| 349 | len = scnprintf(buf, size: sizeof(buf), fmt: "%d\n" , xe->atomic_svm_timeslice_ms); |
| 350 | |
| 351 | return simple_read_from_buffer(to: ubuf, count: size, ppos: pos, from: buf, available: len); |
| 352 | } |
| 353 | |
| 354 | static ssize_t atomic_svm_timeslice_ms_set(struct file *f, |
| 355 | const char __user *ubuf, |
| 356 | size_t size, loff_t *pos) |
| 357 | { |
| 358 | struct xe_device *xe = file_inode(f)->i_private; |
| 359 | u32 atomic_svm_timeslice_ms; |
| 360 | ssize_t ret; |
| 361 | |
| 362 | ret = kstrtouint_from_user(s: ubuf, count: size, base: 0, res: &atomic_svm_timeslice_ms); |
| 363 | if (ret) |
| 364 | return ret; |
| 365 | |
| 366 | xe->atomic_svm_timeslice_ms = atomic_svm_timeslice_ms; |
| 367 | |
| 368 | return size; |
| 369 | } |
| 370 | |
| 371 | static const struct file_operations atomic_svm_timeslice_ms_fops = { |
| 372 | .owner = THIS_MODULE, |
| 373 | .read = atomic_svm_timeslice_ms_show, |
| 374 | .write = atomic_svm_timeslice_ms_set, |
| 375 | }; |
| 376 | |
| 377 | static ssize_t disable_late_binding_show(struct file *f, char __user *ubuf, |
| 378 | size_t size, loff_t *pos) |
| 379 | { |
| 380 | struct xe_device *xe = file_inode(f)->i_private; |
| 381 | struct xe_late_bind *late_bind = &xe->late_bind; |
| 382 | char buf[32]; |
| 383 | int len; |
| 384 | |
| 385 | len = scnprintf(buf, size: sizeof(buf), fmt: "%d\n" , late_bind->disable); |
| 386 | |
| 387 | return simple_read_from_buffer(to: ubuf, count: size, ppos: pos, from: buf, available: len); |
| 388 | } |
| 389 | |
| 390 | static ssize_t disable_late_binding_set(struct file *f, const char __user *ubuf, |
| 391 | size_t size, loff_t *pos) |
| 392 | { |
| 393 | struct xe_device *xe = file_inode(f)->i_private; |
| 394 | struct xe_late_bind *late_bind = &xe->late_bind; |
| 395 | bool val; |
| 396 | int ret; |
| 397 | |
| 398 | ret = kstrtobool_from_user(s: ubuf, count: size, res: &val); |
| 399 | if (ret) |
| 400 | return ret; |
| 401 | |
| 402 | late_bind->disable = val; |
| 403 | return size; |
| 404 | } |
| 405 | |
| 406 | static const struct file_operations disable_late_binding_fops = { |
| 407 | .owner = THIS_MODULE, |
| 408 | .read = disable_late_binding_show, |
| 409 | .write = disable_late_binding_set, |
| 410 | }; |
| 411 | |
| 412 | void xe_debugfs_register(struct xe_device *xe) |
| 413 | { |
| 414 | struct ttm_device *bdev = &xe->ttm; |
| 415 | struct drm_minor *minor = xe->drm.primary; |
| 416 | struct dentry *root = minor->debugfs_root; |
| 417 | struct ttm_resource_manager *man; |
| 418 | struct xe_tile *tile; |
| 419 | struct xe_gt *gt; |
| 420 | u32 mem_type; |
| 421 | u8 tile_id; |
| 422 | u8 id; |
| 423 | |
| 424 | drm_debugfs_create_files(files: debugfs_list, |
| 425 | ARRAY_SIZE(debugfs_list), |
| 426 | root, minor); |
| 427 | |
| 428 | if (xe->info.platform == XE_BATTLEMAGE && !IS_SRIOV_VF(xe)) { |
| 429 | drm_debugfs_create_files(files: debugfs_residencies, |
| 430 | ARRAY_SIZE(debugfs_residencies), |
| 431 | root, minor); |
| 432 | fault_create_debugfs_attr(name: "inject_csc_hw_error" , parent: root, |
| 433 | attr: &inject_csc_hw_error); |
| 434 | } |
| 435 | |
| 436 | debugfs_create_file("forcewake_all" , 0400, root, xe, |
| 437 | &forcewake_all_fops); |
| 438 | |
| 439 | debugfs_create_file("wedged_mode" , 0600, root, xe, |
| 440 | &wedged_mode_fops); |
| 441 | |
| 442 | debugfs_create_file("atomic_svm_timeslice_ms" , 0600, root, xe, |
| 443 | &atomic_svm_timeslice_ms_fops); |
| 444 | |
| 445 | debugfs_create_file("disable_late_binding" , 0600, root, xe, |
| 446 | &disable_late_binding_fops); |
| 447 | |
| 448 | for (mem_type = XE_PL_VRAM0; mem_type <= XE_PL_VRAM1; ++mem_type) { |
| 449 | man = ttm_manager_type(bdev, mem_type); |
| 450 | |
| 451 | if (man) { |
| 452 | char name[16]; |
| 453 | |
| 454 | snprintf(buf: name, size: sizeof(name), fmt: "vram%d_mm" , mem_type - XE_PL_VRAM0); |
| 455 | ttm_resource_manager_create_debugfs(man, parent: root, name); |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | man = ttm_manager_type(bdev, XE_PL_TT); |
| 460 | ttm_resource_manager_create_debugfs(man, parent: root, name: "gtt_mm" ); |
| 461 | |
| 462 | man = ttm_manager_type(bdev, XE_PL_STOLEN); |
| 463 | if (man) |
| 464 | ttm_resource_manager_create_debugfs(man, parent: root, name: "stolen_mm" ); |
| 465 | |
| 466 | for_each_tile(tile, xe, tile_id) |
| 467 | xe_tile_debugfs_register(tile); |
| 468 | |
| 469 | for_each_gt(gt, xe, id) |
| 470 | xe_gt_debugfs_register(gt); |
| 471 | |
| 472 | xe_pxp_debugfs_register(pxp: xe->pxp); |
| 473 | |
| 474 | xe_psmi_debugfs_register(xe); |
| 475 | |
| 476 | fault_create_debugfs_attr(name: "fail_gt_reset" , parent: root, attr: >_reset_failure); |
| 477 | |
| 478 | if (IS_SRIOV_PF(xe)) |
| 479 | xe_sriov_pf_debugfs_register(xe, root); |
| 480 | else if (IS_SRIOV_VF(xe)) |
| 481 | xe_sriov_vf_debugfs_register(xe, root); |
| 482 | } |
| 483 | |