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 for_each_gt(gt, xe, id) { 59 drm_printf(&p, "gt%d force wake %d\n", id, 60 xe_force_wake_ref(gt_to_fw(gt), XE_FW_GT)); 61 drm_printf(&p, "gt%d engine_mask 0x%llx\n", id, 62 gt->info.engine_mask); 63 } 64 65 return 0; 66 } 67 68 static const struct drm_info_list debugfs_list[] = { 69 {"info", info, 0}, 70 }; 71 72 static int forcewake_open(struct inode *inode, struct file *file) 73 { 74 struct xe_device *xe = inode->i_private; 75 struct xe_gt *gt; 76 u8 id; 77 78 xe_device_mem_access_get(xe); 79 80 for_each_gt(gt, xe, id) 81 XE_WARN_ON(xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL)); 82 83 return 0; 84 } 85 86 static int forcewake_release(struct inode *inode, struct file *file) 87 { 88 struct xe_device *xe = inode->i_private; 89 struct xe_gt *gt; 90 u8 id; 91 92 for_each_gt(gt, xe, id) 93 XE_WARN_ON(xe_force_wake_put(gt_to_fw(gt), XE_FORCEWAKE_ALL)); 94 95 xe_device_mem_access_put(xe); 96 97 return 0; 98 } 99 100 static const struct file_operations forcewake_all_fops = { 101 .owner = THIS_MODULE, 102 .open = forcewake_open, 103 .release = forcewake_release, 104 }; 105 106 void xe_debugfs_register(struct xe_device *xe) 107 { 108 struct ttm_device *bdev = &xe->ttm; 109 struct drm_minor *minor = xe->drm.primary; 110 struct dentry *root = minor->debugfs_root; 111 struct ttm_resource_manager *man; 112 struct xe_gt *gt; 113 u32 mem_type; 114 u8 id; 115 116 drm_debugfs_create_files(debugfs_list, 117 ARRAY_SIZE(debugfs_list), 118 root, minor); 119 120 debugfs_create_file("forcewake_all", 0400, root, xe, 121 &forcewake_all_fops); 122 123 for (mem_type = XE_PL_VRAM0; mem_type <= XE_PL_VRAM1; ++mem_type) { 124 man = ttm_manager_type(bdev, mem_type); 125 126 if (man) { 127 char name[16]; 128 129 sprintf(name, "vram%d_mm", mem_type - XE_PL_VRAM0); 130 ttm_resource_manager_create_debugfs(man, root, name); 131 } 132 } 133 134 man = ttm_manager_type(bdev, XE_PL_TT); 135 ttm_resource_manager_create_debugfs(man, root, "gtt_mm"); 136 137 man = ttm_manager_type(bdev, XE_PL_STOLEN); 138 if (man) 139 ttm_resource_manager_create_debugfs(man, root, "stolen_mm"); 140 141 for_each_gt(gt, xe, id) 142 xe_gt_debugfs_register(gt); 143 144 #ifdef CONFIG_FAULT_INJECTION 145 fault_create_debugfs_attr("fail_gt_reset", root, >_reset_failure); 146 #endif 147 148 } 149