• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: MIT
2 /*
3  * Copyright © 2020 Intel Corporation
4  */
5 
6 #include <linux/fs.h>
7 #include <drm/drm_print.h>
8 
9 #include "gt/debugfs_gt.h"
10 #include "intel_guc.h"
11 #include "intel_guc_log.h"
12 #include "intel_guc_log_debugfs.h"
13 
guc_log_dump_show(struct seq_file * m,void * data)14 static int guc_log_dump_show(struct seq_file *m, void *data)
15 {
16 	struct drm_printer p = drm_seq_file_printer(m);
17 
18 	return intel_guc_log_dump(m->private, &p, false);
19 }
20 DEFINE_GT_DEBUGFS_ATTRIBUTE(guc_log_dump);
21 
guc_load_err_log_dump_show(struct seq_file * m,void * data)22 static int guc_load_err_log_dump_show(struct seq_file *m, void *data)
23 {
24 	struct drm_printer p = drm_seq_file_printer(m);
25 
26 	return intel_guc_log_dump(m->private, &p, true);
27 }
28 DEFINE_GT_DEBUGFS_ATTRIBUTE(guc_load_err_log_dump);
29 
guc_log_level_get(void * data,u64 * val)30 static int guc_log_level_get(void *data, u64 *val)
31 {
32 	struct intel_guc_log *log = data;
33 
34 	if (!intel_guc_is_used(log_to_guc(log)))
35 		return -ENODEV;
36 
37 	*val = intel_guc_log_get_level(log);
38 
39 	return 0;
40 }
41 
guc_log_level_set(void * data,u64 val)42 static int guc_log_level_set(void *data, u64 val)
43 {
44 	struct intel_guc_log *log = data;
45 
46 	if (!intel_guc_is_used(log_to_guc(log)))
47 		return -ENODEV;
48 
49 	return intel_guc_log_set_level(log, val);
50 }
51 
52 DEFINE_SIMPLE_ATTRIBUTE(guc_log_level_fops,
53 			guc_log_level_get, guc_log_level_set,
54 			"%lld\n");
55 
guc_log_relay_open(struct inode * inode,struct file * file)56 static int guc_log_relay_open(struct inode *inode, struct file *file)
57 {
58 	struct intel_guc_log *log = inode->i_private;
59 
60 	if (!intel_guc_is_ready(log_to_guc(log)))
61 		return -ENODEV;
62 
63 	file->private_data = log;
64 
65 	return intel_guc_log_relay_open(log);
66 }
67 
68 static ssize_t
guc_log_relay_write(struct file * filp,const char __user * ubuf,size_t cnt,loff_t * ppos)69 guc_log_relay_write(struct file *filp,
70 		    const char __user *ubuf,
71 		    size_t cnt,
72 		    loff_t *ppos)
73 {
74 	struct intel_guc_log *log = filp->private_data;
75 	int val;
76 	int ret;
77 
78 	ret = kstrtoint_from_user(ubuf, cnt, 0, &val);
79 	if (ret < 0)
80 		return ret;
81 
82 	/*
83 	 * Enable and start the guc log relay on value of 1.
84 	 * Flush log relay for any other value.
85 	 */
86 	if (val == 1)
87 		ret = intel_guc_log_relay_start(log);
88 	else
89 		intel_guc_log_relay_flush(log);
90 
91 	return ret ?: cnt;
92 }
93 
guc_log_relay_release(struct inode * inode,struct file * file)94 static int guc_log_relay_release(struct inode *inode, struct file *file)
95 {
96 	struct intel_guc_log *log = inode->i_private;
97 
98 	intel_guc_log_relay_close(log);
99 	return 0;
100 }
101 
102 static const struct file_operations guc_log_relay_fops = {
103 	.owner = THIS_MODULE,
104 	.open = guc_log_relay_open,
105 	.write = guc_log_relay_write,
106 	.release = guc_log_relay_release,
107 };
108 
intel_guc_log_debugfs_register(struct intel_guc_log * log,struct dentry * root)109 void intel_guc_log_debugfs_register(struct intel_guc_log *log,
110 				    struct dentry *root)
111 {
112 	static const struct debugfs_gt_file files[] = {
113 		{ "guc_log_dump", &guc_log_dump_fops, NULL },
114 		{ "guc_load_err_log_dump", &guc_load_err_log_dump_fops, NULL },
115 		{ "guc_log_level", &guc_log_level_fops, NULL },
116 		{ "guc_log_relay", &guc_log_relay_fops, NULL },
117 	};
118 
119 	if (!intel_guc_is_supported(log_to_guc(log)))
120 		return;
121 
122 	intel_gt_debugfs_register_files(root, files, ARRAY_SIZE(files), log);
123 }
124