xref: /linux/drivers/gpu/drm/xe/xe_guc_debugfs.c (revision a9a95523c84957b7863796b5d1df2f3f5dca4519)
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 static const struct drm_info_list debugfs_list[] = {
62 	{"guc_info", guc_info, 0},
63 	{"guc_log", guc_log, 0},
64 };
65 
66 void xe_guc_debugfs_register(struct xe_guc *guc, struct dentry *parent)
67 {
68 	struct drm_minor *minor = guc_to_xe(guc)->drm.primary;
69 	struct drm_info_list *local;
70 	int i;
71 
72 #define DEBUGFS_SIZE	(ARRAY_SIZE(debugfs_list) * sizeof(struct drm_info_list))
73 	local = drmm_kmalloc(&guc_to_xe(guc)->drm, DEBUGFS_SIZE, GFP_KERNEL);
74 	if (!local)
75 		return;
76 
77 	memcpy(local, debugfs_list, DEBUGFS_SIZE);
78 #undef DEBUGFS_SIZE
79 
80 	for (i = 0; i < ARRAY_SIZE(debugfs_list); ++i)
81 		local[i].data = guc;
82 
83 	drm_debugfs_create_files(local,
84 				 ARRAY_SIZE(debugfs_list),
85 				 parent, minor);
86 }
87