xref: /linux/drivers/gpu/drm/xe/xe_gsc_debugfs.c (revision 1b5d39e6672fdee158c3306f5cb2df8975c77e5a)
1 // SPDX-License-Identifier: MIT
2 /*
3  * Copyright © 2022 Intel Corporation
4  */
5 
6 #include "xe_gsc_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_gsc.h"
14 #include "xe_macros.h"
15 #include "xe_pm.h"
16 
17 static struct xe_gt *
18 gsc_to_gt(struct xe_gsc *gsc)
19 {
20 	return container_of(gsc, struct xe_gt, uc.gsc);
21 }
22 
23 static struct xe_device *
24 gsc_to_xe(struct xe_gsc *gsc)
25 {
26 	return gt_to_xe(gsc_to_gt(gsc));
27 }
28 
29 static struct xe_gsc *node_to_gsc(struct drm_info_node *node)
30 {
31 	return node->info_ent->data;
32 }
33 
34 static int gsc_info(struct seq_file *m, void *data)
35 {
36 	struct xe_gsc *gsc = node_to_gsc(m->private);
37 	struct xe_device *xe = gsc_to_xe(gsc);
38 	struct drm_printer p = drm_seq_file_printer(m);
39 
40 	guard(xe_pm_runtime)(xe);
41 	xe_gsc_print_info(gsc, &p);
42 
43 	return 0;
44 }
45 
46 static const struct drm_info_list debugfs_list[] = {
47 	{"gsc_info", gsc_info, 0},
48 };
49 
50 void xe_gsc_debugfs_register(struct xe_gsc *gsc, struct dentry *parent)
51 {
52 	struct drm_minor *minor = gsc_to_xe(gsc)->drm.primary;
53 	struct drm_info_list *local;
54 	int i;
55 
56 #define DEBUGFS_SIZE	(ARRAY_SIZE(debugfs_list) * sizeof(struct drm_info_list))
57 	local = drmm_kmalloc(&gsc_to_xe(gsc)->drm, DEBUGFS_SIZE, GFP_KERNEL);
58 	if (!local)
59 		return;
60 
61 	memcpy(local, debugfs_list, DEBUGFS_SIZE);
62 #undef DEBUGFS_SIZE
63 
64 	for (i = 0; i < ARRAY_SIZE(debugfs_list); ++i)
65 		local[i].data = gsc;
66 
67 	drm_debugfs_create_files(local,
68 				 ARRAY_SIZE(debugfs_list),
69 				 parent, minor);
70 }
71