xref: /linux/drivers/gpu/drm/xe/xe_huc_debugfs.c (revision c0d6f52f9b62479d61f8cd4faf9fb2f8bce6e301)
1 // SPDX-License-Identifier: MIT
2 /*
3  * Copyright © 2022 Intel Corporation
4  */
5 
6 #include "xe_huc_debugfs.h"
7 
8 #include <drm/drm_debugfs.h>
9 #include <drm/drm_managed.h>
10 #include <drm/drm_print.h>
11 
12 #include "xe_gt_types.h"
13 #include "xe_huc.h"
14 #include "xe_pm.h"
15 
16 static struct xe_gt *
17 huc_to_gt(struct xe_huc *huc)
18 {
19 	return container_of(huc, struct xe_gt, uc.huc);
20 }
21 
22 static struct xe_device *
23 huc_to_xe(struct xe_huc *huc)
24 {
25 	return gt_to_xe(huc_to_gt(huc));
26 }
27 
28 static struct xe_huc *node_to_huc(struct drm_info_node *node)
29 {
30 	return node->info_ent->data;
31 }
32 
33 static int huc_info(struct seq_file *m, void *data)
34 {
35 	struct xe_huc *huc = node_to_huc(m->private);
36 	struct xe_device *xe = huc_to_xe(huc);
37 	struct drm_printer p = drm_seq_file_printer(m);
38 
39 	guard(xe_pm_runtime)(xe);
40 	xe_huc_print_info(huc, &p);
41 
42 	return 0;
43 }
44 
45 static const struct drm_info_list debugfs_list[] = {
46 	{"huc_info", huc_info, 0},
47 };
48 
49 void xe_huc_debugfs_register(struct xe_huc *huc, struct dentry *parent)
50 {
51 	struct drm_minor *minor = huc_to_xe(huc)->drm.primary;
52 	struct drm_info_list *local;
53 	int i;
54 
55 #define DEBUGFS_SIZE	(ARRAY_SIZE(debugfs_list) * sizeof(struct drm_info_list))
56 	local = drmm_kmalloc(&huc_to_xe(huc)->drm, DEBUGFS_SIZE, GFP_KERNEL);
57 	if (!local)
58 		return;
59 
60 	memcpy(local, debugfs_list, DEBUGFS_SIZE);
61 #undef DEBUGFS_SIZE
62 
63 	for (i = 0; i < ARRAY_SIZE(debugfs_list); ++i)
64 		local[i].data = huc;
65 
66 	drm_debugfs_create_files(local,
67 				 ARRAY_SIZE(debugfs_list),
68 				 parent, minor);
69 }
70