xref: /linux/drivers/gpu/drm/xe/xe_debugfs.c (revision daa121128a2d2ac6006159e2c47676e4fcd21eab)
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/string_helpers.h>
10 
11 #include <drm/drm_debugfs.h>
12 
13 #include "xe_bo.h"
14 #include "xe_device.h"
15 #include "xe_gt_debugfs.h"
16 #include "xe_pm.h"
17 #include "xe_sriov.h"
18 #include "xe_step.h"
19 
20 #ifdef CONFIG_DRM_XE_DEBUG
21 #include "xe_bo_evict.h"
22 #include "xe_migrate.h"
23 #include "xe_vm.h"
24 #endif
25 
26 #ifdef CONFIG_FAULT_INJECTION
27 #include <linux/fault-inject.h> /* XXX: fault-inject.h is broken */
28 DECLARE_FAULT_ATTR(gt_reset_failure);
29 #endif
30 
31 static struct xe_device *node_to_xe(struct drm_info_node *node)
32 {
33 	return to_xe_device(node->minor->dev);
34 }
35 
36 static int info(struct seq_file *m, void *data)
37 {
38 	struct xe_device *xe = node_to_xe(m->private);
39 	struct drm_printer p = drm_seq_file_printer(m);
40 	struct xe_gt *gt;
41 	u8 id;
42 
43 	xe_pm_runtime_get(xe);
44 
45 	drm_printf(&p, "graphics_verx100 %d\n", xe->info.graphics_verx100);
46 	drm_printf(&p, "media_verx100 %d\n", xe->info.media_verx100);
47 	drm_printf(&p, "stepping G:%s M:%s D:%s B:%s\n",
48 		   xe_step_name(xe->info.step.graphics),
49 		   xe_step_name(xe->info.step.media),
50 		   xe_step_name(xe->info.step.display),
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 void xe_debugfs_register(struct xe_device *xe)
122 {
123 	struct ttm_device *bdev = &xe->ttm;
124 	struct drm_minor *minor = xe->drm.primary;
125 	struct dentry *root = minor->debugfs_root;
126 	struct ttm_resource_manager *man;
127 	struct xe_gt *gt;
128 	u32 mem_type;
129 	u8 id;
130 
131 	drm_debugfs_create_files(debugfs_list,
132 				 ARRAY_SIZE(debugfs_list),
133 				 root, minor);
134 
135 	debugfs_create_file("forcewake_all", 0400, root, xe,
136 			    &forcewake_all_fops);
137 
138 	for (mem_type = XE_PL_VRAM0; mem_type <= XE_PL_VRAM1; ++mem_type) {
139 		man = ttm_manager_type(bdev, mem_type);
140 
141 		if (man) {
142 			char name[16];
143 
144 			snprintf(name, sizeof(name), "vram%d_mm", mem_type - XE_PL_VRAM0);
145 			ttm_resource_manager_create_debugfs(man, root, name);
146 		}
147 	}
148 
149 	man = ttm_manager_type(bdev, XE_PL_TT);
150 	ttm_resource_manager_create_debugfs(man, root, "gtt_mm");
151 
152 	man = ttm_manager_type(bdev, XE_PL_STOLEN);
153 	if (man)
154 		ttm_resource_manager_create_debugfs(man, root, "stolen_mm");
155 
156 	for_each_gt(gt, xe, id)
157 		xe_gt_debugfs_register(gt);
158 
159 #ifdef CONFIG_FAULT_INJECTION
160 	fault_create_debugfs_attr("fail_gt_reset", root, &gt_reset_failure);
161 #endif
162 
163 }
164