xref: /linux/drivers/gpu/drm/xe/xe_guc_debugfs.c (revision db5d28c0bfe566908719bec8e25443aabecbb802)
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 #include "xe_pm.h"
18 
node_to_guc(struct drm_info_node * node)19 static struct xe_guc *node_to_guc(struct drm_info_node *node)
20 {
21 	return node->info_ent->data;
22 }
23 
guc_info(struct seq_file * m,void * data)24 static int guc_info(struct seq_file *m, void *data)
25 {
26 	struct xe_guc *guc = node_to_guc(m->private);
27 	struct xe_device *xe = guc_to_xe(guc);
28 	struct drm_printer p = drm_seq_file_printer(m);
29 
30 	xe_pm_runtime_get(xe);
31 	xe_guc_print_info(guc, &p);
32 	xe_pm_runtime_put(xe);
33 
34 	return 0;
35 }
36 
guc_log(struct seq_file * m,void * data)37 static int guc_log(struct seq_file *m, void *data)
38 {
39 	struct xe_guc *guc = node_to_guc(m->private);
40 	struct xe_device *xe = guc_to_xe(guc);
41 	struct drm_printer p = drm_seq_file_printer(m);
42 
43 	xe_pm_runtime_get(xe);
44 	xe_guc_log_print(&guc->log, &p);
45 	xe_pm_runtime_put(xe);
46 
47 	return 0;
48 }
49 
50 static const struct drm_info_list debugfs_list[] = {
51 	{"guc_info", guc_info, 0},
52 	{"guc_log", guc_log, 0},
53 };
54 
xe_guc_debugfs_register(struct xe_guc * guc,struct dentry * parent)55 void xe_guc_debugfs_register(struct xe_guc *guc, struct dentry *parent)
56 {
57 	struct drm_minor *minor = guc_to_xe(guc)->drm.primary;
58 	struct drm_info_list *local;
59 	int i;
60 
61 #define DEBUGFS_SIZE	(ARRAY_SIZE(debugfs_list) * sizeof(struct drm_info_list))
62 	local = drmm_kmalloc(&guc_to_xe(guc)->drm, DEBUGFS_SIZE, GFP_KERNEL);
63 	if (!local)
64 		return;
65 
66 	memcpy(local, debugfs_list, DEBUGFS_SIZE);
67 #undef DEBUGFS_SIZE
68 
69 	for (i = 0; i < ARRAY_SIZE(debugfs_list); ++i)
70 		local[i].data = guc;
71 
72 	drm_debugfs_create_files(local,
73 				 ARRAY_SIZE(debugfs_list),
74 				 parent, minor);
75 }
76