xref: /linux/drivers/gpu/drm/xe/xe_guc_debugfs.c (revision 08516de501fae647fb29bf3b62718de56cc24014)
1 // SPDX-License-Identifier: MIT
2 /*
3  * Copyright © 2022 Intel Corporation
4  */
5 
6 #include "xe_guc_debugfs.h"
7 
8 #include <drm/drm_debugfs.h>
9 #include <drm/drm_managed.h>
10 
11 #include "xe_device.h"
12 #include "xe_gt.h"
13 #include "xe_guc.h"
14 #include "xe_guc_ct.h"
15 #include "xe_guc_log.h"
16 #include "xe_macros.h"
17 
18 static struct xe_gt *
19 guc_to_gt(struct xe_guc *guc)
20 {
21 	return container_of(guc, struct xe_gt, uc.guc);
22 }
23 
24 static struct xe_device *
25 guc_to_xe(struct xe_guc *guc)
26 {
27 	return gt_to_xe(guc_to_gt(guc));
28 }
29 
30 static struct xe_guc *node_to_guc(struct drm_info_node *node)
31 {
32 	return node->info_ent->data;
33 }
34 
35 static int guc_info(struct seq_file *m, void *data)
36 {
37 	struct xe_guc *guc = node_to_guc(m->private);
38 	struct xe_device *xe = guc_to_xe(guc);
39 	struct drm_printer p = drm_seq_file_printer(m);
40 
41 	xe_device_mem_access_get(xe);
42 	xe_guc_print_info(guc, &p);
43 	xe_device_mem_access_put(xe);
44 
45 	return 0;
46 }
47 
48 static int guc_log(struct seq_file *m, void *data)
49 {
50 	struct xe_guc *guc = node_to_guc(m->private);
51 	struct xe_device *xe = guc_to_xe(guc);
52 	struct drm_printer p = drm_seq_file_printer(m);
53 
54 	xe_device_mem_access_get(xe);
55 	xe_guc_log_print(&guc->log, &p);
56 	xe_device_mem_access_put(xe);
57 
58 	return 0;
59 }
60 
61 #ifdef XE_GUC_CT_SELFTEST
62 static int guc_ct_selftest(struct seq_file *m, void *data)
63 {
64 	struct xe_guc *guc = node_to_guc(m->private);
65 	struct xe_device *xe = guc_to_xe(guc);
66 	struct drm_printer p = drm_seq_file_printer(m);
67 
68 	xe_device_mem_access_get(xe);
69 	xe_guc_ct_selftest(&guc->ct, &p);
70 	xe_device_mem_access_put(xe);
71 
72 	return 0;
73 }
74 #endif
75 
76 static const struct drm_info_list debugfs_list[] = {
77 	{"guc_info", guc_info, 0},
78 	{"guc_log", guc_log, 0},
79 #ifdef XE_GUC_CT_SELFTEST
80 	{"guc_ct_selftest", guc_ct_selftest, 0},
81 #endif
82 };
83 
84 void xe_guc_debugfs_register(struct xe_guc *guc, struct dentry *parent)
85 {
86 	struct drm_minor *minor = guc_to_xe(guc)->drm.primary;
87 	struct drm_info_list *local;
88 	int i;
89 
90 #define DEBUGFS_SIZE	ARRAY_SIZE(debugfs_list) * sizeof(struct drm_info_list)
91 	local = drmm_kmalloc(&guc_to_xe(guc)->drm, DEBUGFS_SIZE, GFP_KERNEL);
92 	if (!local) {
93 		XE_WARN_ON("Couldn't allocate memory");
94 		return;
95 	}
96 
97 	memcpy(local, debugfs_list, DEBUGFS_SIZE);
98 #undef DEBUGFS_SIZE
99 
100 	for (i = 0; i < ARRAY_SIZE(debugfs_list); ++i)
101 		local[i].data = guc;
102 
103 	drm_debugfs_create_files(local,
104 				 ARRAY_SIZE(debugfs_list),
105 				 parent, minor);
106 }
107