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