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 "xe_bo.h" 15 #include "xe_device.h" 16 #include "xe_force_wake.h" 17 #include "xe_gt_debugfs.h" 18 #include "xe_gt_printk.h" 19 #include "xe_guc_ads.h" 20 #include "xe_pm.h" 21 #include "xe_sriov.h" 22 #include "xe_step.h" 23 24 #ifdef CONFIG_DRM_XE_DEBUG 25 #include "xe_bo_evict.h" 26 #include "xe_migrate.h" 27 #include "xe_vm.h" 28 #endif 29 30 DECLARE_FAULT_ATTR(gt_reset_failure); 31 32 static struct xe_device *node_to_xe(struct drm_info_node *node) 33 { 34 return to_xe_device(node->minor->dev); 35 } 36 37 static int info(struct seq_file *m, void *data) 38 { 39 struct xe_device *xe = node_to_xe(m->private); 40 struct drm_printer p = drm_seq_file_printer(m); 41 struct xe_gt *gt; 42 u8 id; 43 44 xe_pm_runtime_get(xe); 45 46 drm_printf(&p, "graphics_verx100 %d\n", xe->info.graphics_verx100); 47 drm_printf(&p, "media_verx100 %d\n", xe->info.media_verx100); 48 drm_printf(&p, "stepping G:%s M:%s B:%s\n", 49 xe_step_name(xe->info.step.graphics), 50 xe_step_name(xe->info.step.media), 51 xe_step_name(xe->info.step.basedie)); 52 drm_printf(&p, "is_dgfx %s\n", str_yes_no(xe->info.is_dgfx)); 53 drm_printf(&p, "platform %d\n", xe->info.platform); 54 drm_printf(&p, "subplatform %d\n", 55 xe->info.subplatform > XE_SUBPLATFORM_NONE ? xe->info.subplatform : 0); 56 drm_printf(&p, "devid 0x%x\n", xe->info.devid); 57 drm_printf(&p, "revid %d\n", xe->info.revid); 58 drm_printf(&p, "tile_count %d\n", xe->info.tile_count); 59 drm_printf(&p, "vm_max_level %d\n", xe->info.vm_max_level); 60 drm_printf(&p, "force_execlist %s\n", str_yes_no(xe->info.force_execlist)); 61 drm_printf(&p, "has_flat_ccs %s\n", str_yes_no(xe->info.has_flat_ccs)); 62 drm_printf(&p, "has_usm %s\n", str_yes_no(xe->info.has_usm)); 63 drm_printf(&p, "skip_guc_pc %s\n", str_yes_no(xe->info.skip_guc_pc)); 64 for_each_gt(gt, xe, id) { 65 drm_printf(&p, "gt%d force wake %d\n", id, 66 xe_force_wake_ref(gt_to_fw(gt), XE_FW_GT)); 67 drm_printf(&p, "gt%d engine_mask 0x%llx\n", id, 68 gt->info.engine_mask); 69 } 70 71 xe_pm_runtime_put(xe); 72 return 0; 73 } 74 75 static int sriov_info(struct seq_file *m, void *data) 76 { 77 struct xe_device *xe = node_to_xe(m->private); 78 struct drm_printer p = drm_seq_file_printer(m); 79 80 xe_sriov_print_info(xe, &p); 81 return 0; 82 } 83 84 static const struct drm_info_list debugfs_list[] = { 85 {"info", info, 0}, 86 { .name = "sriov_info", .show = sriov_info, }, 87 }; 88 89 static int forcewake_open(struct inode *inode, struct file *file) 90 { 91 struct xe_device *xe = inode->i_private; 92 struct xe_gt *gt; 93 u8 id; 94 95 xe_pm_runtime_get(xe); 96 for_each_gt(gt, xe, id) 97 XE_WARN_ON(xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL)); 98 99 return 0; 100 } 101 102 static int forcewake_release(struct inode *inode, struct file *file) 103 { 104 struct xe_device *xe = inode->i_private; 105 struct xe_gt *gt; 106 u8 id; 107 108 for_each_gt(gt, xe, id) 109 XE_WARN_ON(xe_force_wake_put(gt_to_fw(gt), XE_FORCEWAKE_ALL)); 110 xe_pm_runtime_put(xe); 111 112 return 0; 113 } 114 115 static const struct file_operations forcewake_all_fops = { 116 .owner = THIS_MODULE, 117 .open = forcewake_open, 118 .release = forcewake_release, 119 }; 120 121 static ssize_t wedged_mode_show(struct file *f, char __user *ubuf, 122 size_t size, loff_t *pos) 123 { 124 struct xe_device *xe = file_inode(f)->i_private; 125 char buf[32]; 126 int len = 0; 127 128 len = scnprintf(buf, sizeof(buf), "%d\n", xe->wedged.mode); 129 130 return simple_read_from_buffer(ubuf, size, pos, buf, len); 131 } 132 133 static ssize_t wedged_mode_set(struct file *f, const char __user *ubuf, 134 size_t size, loff_t *pos) 135 { 136 struct xe_device *xe = file_inode(f)->i_private; 137 struct xe_gt *gt; 138 u32 wedged_mode; 139 ssize_t ret; 140 u8 id; 141 142 ret = kstrtouint_from_user(ubuf, size, 0, &wedged_mode); 143 if (ret) 144 return ret; 145 146 if (wedged_mode > 2) 147 return -EINVAL; 148 149 if (xe->wedged.mode == wedged_mode) 150 return 0; 151 152 xe->wedged.mode = wedged_mode; 153 154 xe_pm_runtime_get(xe); 155 for_each_gt(gt, xe, id) { 156 ret = xe_guc_ads_scheduler_policy_toggle_reset(>->uc.guc.ads); 157 if (ret) { 158 xe_gt_err(gt, "Failed to update GuC ADS scheduler policy. GuC may still cause engine reset even with wedged_mode=2\n"); 159 return -EIO; 160 } 161 } 162 xe_pm_runtime_put(xe); 163 164 return size; 165 } 166 167 static const struct file_operations wedged_mode_fops = { 168 .owner = THIS_MODULE, 169 .read = wedged_mode_show, 170 .write = wedged_mode_set, 171 }; 172 173 void xe_debugfs_register(struct xe_device *xe) 174 { 175 struct ttm_device *bdev = &xe->ttm; 176 struct drm_minor *minor = xe->drm.primary; 177 struct dentry *root = minor->debugfs_root; 178 struct ttm_resource_manager *man; 179 struct xe_gt *gt; 180 u32 mem_type; 181 u8 id; 182 183 drm_debugfs_create_files(debugfs_list, 184 ARRAY_SIZE(debugfs_list), 185 root, minor); 186 187 debugfs_create_file("forcewake_all", 0400, root, xe, 188 &forcewake_all_fops); 189 190 debugfs_create_file("wedged_mode", 0600, root, xe, 191 &wedged_mode_fops); 192 193 for (mem_type = XE_PL_VRAM0; mem_type <= XE_PL_VRAM1; ++mem_type) { 194 man = ttm_manager_type(bdev, mem_type); 195 196 if (man) { 197 char name[16]; 198 199 snprintf(name, sizeof(name), "vram%d_mm", mem_type - XE_PL_VRAM0); 200 ttm_resource_manager_create_debugfs(man, root, name); 201 } 202 } 203 204 man = ttm_manager_type(bdev, XE_PL_TT); 205 ttm_resource_manager_create_debugfs(man, root, "gtt_mm"); 206 207 man = ttm_manager_type(bdev, XE_PL_STOLEN); 208 if (man) 209 ttm_resource_manager_create_debugfs(man, root, "stolen_mm"); 210 211 for_each_gt(gt, xe, id) 212 xe_gt_debugfs_register(gt); 213 214 fault_create_debugfs_attr("fail_gt_reset", root, >_reset_failure); 215 } 216