1 // SPDX-License-Identifier: MIT
3 * Copyright © 2020 Intel Corporation
7 #include <drm/drm_print.h>
9 #include "gt/debugfs_gt.h"
10 #include "intel_guc.h"
11 #include "intel_guc_log.h"
12 #include "intel_guc_log_debugfs.h"
14 static int guc_log_dump_show(struct seq_file *m, void *data)
16 struct drm_printer p = drm_seq_file_printer(m);
18 return intel_guc_log_dump(m->private, &p, false);
20 DEFINE_GT_DEBUGFS_ATTRIBUTE(guc_log_dump);
22 static int guc_load_err_log_dump_show(struct seq_file *m, void *data)
24 struct drm_printer p = drm_seq_file_printer(m);
26 return intel_guc_log_dump(m->private, &p, true);
28 DEFINE_GT_DEBUGFS_ATTRIBUTE(guc_load_err_log_dump);
30 static int guc_log_level_get(void *data, u64 *val)
32 struct intel_guc_log *log = data;
34 if (!intel_guc_is_used(log_to_guc(log)))
37 *val = intel_guc_log_get_level(log);
42 static int guc_log_level_set(void *data, u64 val)
44 struct intel_guc_log *log = data;
46 if (!intel_guc_is_used(log_to_guc(log)))
49 return intel_guc_log_set_level(log, val);
52 DEFINE_SIMPLE_ATTRIBUTE(guc_log_level_fops,
53 guc_log_level_get, guc_log_level_set,
56 static int guc_log_relay_open(struct inode *inode, struct file *file)
58 struct intel_guc_log *log = inode->i_private;
60 if (!intel_guc_is_ready(log_to_guc(log)))
63 file->private_data = log;
65 return intel_guc_log_relay_open(log);
69 guc_log_relay_write(struct file *filp,
70 const char __user *ubuf,
74 struct intel_guc_log *log = filp->private_data;
78 ret = kstrtoint_from_user(ubuf, cnt, 0, &val);
83 * Enable and start the guc log relay on value of 1.
84 * Flush log relay for any other value.
87 ret = intel_guc_log_relay_start(log);
89 intel_guc_log_relay_flush(log);
94 static int guc_log_relay_release(struct inode *inode, struct file *file)
96 struct intel_guc_log *log = inode->i_private;
98 intel_guc_log_relay_close(log);
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,
109 void intel_guc_log_debugfs_register(struct intel_guc_log *log,
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 },
119 if (!intel_guc_is_supported(log_to_guc(log)))
122 intel_gt_debugfs_register_files(root, files, ARRAY_SIZE(files), log);