xref: /linux/drivers/gpu/drm/xe/xe_huc_debugfs.c (revision dd08ebf6c3525a7ea2186e636df064ea47281987)
1 // SPDX-License-Identifier: MIT
2 /*
3  * Copyright © 2022 Intel Corporation
4  */
5 
6 #include <drm/drm_debugfs.h>
7 #include <drm/drm_managed.h>
8 
9 #include "xe_device.h"
10 #include "xe_gt.h"
11 #include "xe_huc.h"
12 #include "xe_huc_debugfs.h"
13 #include "xe_macros.h"
14 
15 static struct xe_gt *
16 huc_to_gt(struct xe_huc *huc)
17 {
18 	return container_of(huc, struct xe_gt, uc.huc);
19 }
20 
21 static struct xe_device *
22 huc_to_xe(struct xe_huc *huc)
23 {
24 	return gt_to_xe(huc_to_gt(huc));
25 }
26 
27 static struct xe_huc *node_to_huc(struct drm_info_node *node)
28 {
29 	return node->info_ent->data;
30 }
31 
32 static int huc_info(struct seq_file *m, void *data)
33 {
34 	struct xe_huc *huc = node_to_huc(m->private);
35 	struct xe_device *xe = huc_to_xe(huc);
36 	struct drm_printer p = drm_seq_file_printer(m);
37 
38 	xe_device_mem_access_get(xe);
39 	xe_huc_print_info(huc, &p);
40 	xe_device_mem_access_put(xe);
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 		XE_WARN_ON("Couldn't allocate memory");
59 		return;
60 	}
61 
62 	memcpy(local, debugfs_list, DEBUGFS_SIZE);
63 #undef DEBUGFS_SIZE
64 
65 	for (i = 0; i < ARRAY_SIZE(debugfs_list); ++i)
66 		local[i].data = huc;
67 
68 	drm_debugfs_create_files(local,
69 				 ARRAY_SIZE(debugfs_list),
70 				 parent, minor);
71 }
72