1 // SPDX-License-Identifier: MIT
2 /*
3  * Copyright © 2020 Intel Corporation
4  */
5 
6 #include <linux/debugfs.h>
7 #include <linux/string_helpers.h>
8 
9 #include <drm/drm_print.h>
10 
11 #include "gt/intel_gt_debugfs.h"
12 #include "intel_guc_debugfs.h"
13 #include "intel_huc_debugfs.h"
14 #include "intel_uc.h"
15 #include "intel_uc_debugfs.h"
16 
17 static int uc_usage_show(struct seq_file *m, void *data)
18 {
19 	struct intel_uc *uc = m->private;
20 	struct drm_printer p = drm_seq_file_printer(m);
21 
22 	drm_printf(&p, "[guc] supported:%s wanted:%s used:%s\n",
23 		   str_yes_no(intel_uc_supports_guc(uc)),
24 		   str_yes_no(intel_uc_wants_guc(uc)),
25 		   str_yes_no(intel_uc_uses_guc(uc)));
26 	drm_printf(&p, "[huc] supported:%s wanted:%s used:%s\n",
27 		   str_yes_no(intel_uc_supports_huc(uc)),
28 		   str_yes_no(intel_uc_wants_huc(uc)),
29 		   str_yes_no(intel_uc_uses_huc(uc)));
30 	drm_printf(&p, "[submission] supported:%s wanted:%s used:%s\n",
31 		   str_yes_no(intel_uc_supports_guc_submission(uc)),
32 		   str_yes_no(intel_uc_wants_guc_submission(uc)),
33 		   str_yes_no(intel_uc_uses_guc_submission(uc)));
34 
35 	return 0;
36 }
37 DEFINE_INTEL_GT_DEBUGFS_ATTRIBUTE(uc_usage);
38 
39 void intel_uc_debugfs_register(struct intel_uc *uc, struct dentry *gt_root)
40 {
41 	static const struct intel_gt_debugfs_file files[] = {
42 		{ "usage", &uc_usage_fops, NULL },
43 	};
44 	struct dentry *root;
45 
46 	if (!gt_root)
47 		return;
48 
49 	/* GuC and HuC go always in pair, no need to check both */
50 	if (!intel_uc_supports_guc(uc))
51 		return;
52 
53 	root = debugfs_create_dir("uc", gt_root);
54 	if (IS_ERR(root))
55 		return;
56 
57 	uc->guc.dbgfs_node = root;
58 
59 	intel_gt_debugfs_register_files(root, files, ARRAY_SIZE(files), uc);
60 
61 	intel_guc_debugfs_register(&uc->guc, root);
62 	intel_huc_debugfs_register(&uc->huc, root);
63 }
64