1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright © 2022 Intel Corporation 4 */ 5 6 #include "xe_debugfs.h" 7 8 #include <linux/string_helpers.h> 9 10 #include <drm/drm_debugfs.h> 11 12 #include "xe_bo.h" 13 #include "xe_device.h" 14 #include "xe_gt_debugfs.h" 15 #include "xe_pm.h" 16 #include "xe_step.h" 17 18 #ifdef CONFIG_DRM_XE_DEBUG 19 #include "xe_bo_evict.h" 20 #include "xe_migrate.h" 21 #include "xe_vm.h" 22 #endif 23 24 #ifdef CONFIG_FAULT_INJECTION 25 #include <linux/fault-inject.h> /* XXX: fault-inject.h is broken */ 26 DECLARE_FAULT_ATTR(gt_reset_failure); 27 #endif 28 29 static struct xe_device *node_to_xe(struct drm_info_node *node) 30 { 31 return to_xe_device(node->minor->dev); 32 } 33 34 static int info(struct seq_file *m, void *data) 35 { 36 struct xe_device *xe = node_to_xe(m->private); 37 struct drm_printer p = drm_seq_file_printer(m); 38 struct xe_gt *gt; 39 u8 id; 40 41 xe_pm_runtime_get(xe); 42 43 drm_printf(&p, "graphics_verx100 %d\n", xe->info.graphics_verx100); 44 drm_printf(&p, "media_verx100 %d\n", xe->info.media_verx100); 45 drm_printf(&p, "stepping G:%s M:%s D:%s B:%s\n", 46 xe_step_name(xe->info.step.graphics), 47 xe_step_name(xe->info.step.media), 48 xe_step_name(xe->info.step.display), 49 xe_step_name(xe->info.step.basedie)); 50 drm_printf(&p, "is_dgfx %s\n", str_yes_no(xe->info.is_dgfx)); 51 drm_printf(&p, "platform %d\n", xe->info.platform); 52 drm_printf(&p, "subplatform %d\n", 53 xe->info.subplatform > XE_SUBPLATFORM_NONE ? xe->info.subplatform : 0); 54 drm_printf(&p, "devid 0x%x\n", xe->info.devid); 55 drm_printf(&p, "revid %d\n", xe->info.revid); 56 drm_printf(&p, "tile_count %d\n", xe->info.tile_count); 57 drm_printf(&p, "vm_max_level %d\n", xe->info.vm_max_level); 58 drm_printf(&p, "force_execlist %s\n", str_yes_no(xe->info.force_execlist)); 59 drm_printf(&p, "has_flat_ccs %s\n", str_yes_no(xe->info.has_flat_ccs)); 60 drm_printf(&p, "has_usm %s\n", str_yes_no(xe->info.has_usm)); 61 drm_printf(&p, "skip_guc_pc %s\n", str_yes_no(xe->info.skip_guc_pc)); 62 for_each_gt(gt, xe, id) { 63 drm_printf(&p, "gt%d force wake %d\n", id, 64 xe_force_wake_ref(gt_to_fw(gt), XE_FW_GT)); 65 drm_printf(&p, "gt%d engine_mask 0x%llx\n", id, 66 gt->info.engine_mask); 67 } 68 69 xe_pm_runtime_put(xe); 70 return 0; 71 } 72 73 static const struct drm_info_list debugfs_list[] = { 74 {"info", info, 0}, 75 }; 76 77 static int forcewake_open(struct inode *inode, struct file *file) 78 { 79 struct xe_device *xe = inode->i_private; 80 struct xe_gt *gt; 81 u8 id; 82 83 xe_pm_runtime_get(xe); 84 for_each_gt(gt, xe, id) 85 XE_WARN_ON(xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL)); 86 87 return 0; 88 } 89 90 static int forcewake_release(struct inode *inode, struct file *file) 91 { 92 struct xe_device *xe = inode->i_private; 93 struct xe_gt *gt; 94 u8 id; 95 96 for_each_gt(gt, xe, id) 97 XE_WARN_ON(xe_force_wake_put(gt_to_fw(gt), XE_FORCEWAKE_ALL)); 98 xe_pm_runtime_put(xe); 99 100 return 0; 101 } 102 103 static const struct file_operations forcewake_all_fops = { 104 .owner = THIS_MODULE, 105 .open = forcewake_open, 106 .release = forcewake_release, 107 }; 108 109 void xe_debugfs_register(struct xe_device *xe) 110 { 111 struct ttm_device *bdev = &xe->ttm; 112 struct drm_minor *minor = xe->drm.primary; 113 struct dentry *root = minor->debugfs_root; 114 struct ttm_resource_manager *man; 115 struct xe_gt *gt; 116 u32 mem_type; 117 u8 id; 118 119 drm_debugfs_create_files(debugfs_list, 120 ARRAY_SIZE(debugfs_list), 121 root, minor); 122 123 debugfs_create_file("forcewake_all", 0400, root, xe, 124 &forcewake_all_fops); 125 126 for (mem_type = XE_PL_VRAM0; mem_type <= XE_PL_VRAM1; ++mem_type) { 127 man = ttm_manager_type(bdev, mem_type); 128 129 if (man) { 130 char name[16]; 131 132 sprintf(name, "vram%d_mm", mem_type - XE_PL_VRAM0); 133 ttm_resource_manager_create_debugfs(man, root, name); 134 } 135 } 136 137 man = ttm_manager_type(bdev, XE_PL_TT); 138 ttm_resource_manager_create_debugfs(man, root, "gtt_mm"); 139 140 man = ttm_manager_type(bdev, XE_PL_STOLEN); 141 if (man) 142 ttm_resource_manager_create_debugfs(man, root, "stolen_mm"); 143 144 for_each_gt(gt, xe, id) 145 xe_gt_debugfs_register(gt); 146 147 #ifdef CONFIG_FAULT_INJECTION 148 fault_create_debugfs_attr("fail_gt_reset", root, >_reset_failure); 149 #endif 150 151 } 152