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