Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / ras / debugfs.c
blob42afd3de68b22edcf52af72177040b2048c498c4
1 // SPDX-License-Identifier: GPL-2.0-only
2 #include <linux/debugfs.h>
3 #include <linux/ras.h>
4 #include "debugfs.h"
6 static struct dentry *ras_debugfs_dir;
8 static atomic_t trace_count = ATOMIC_INIT(0);
10 struct dentry *ras_get_debugfs_root(void)
12 return ras_debugfs_dir;
14 EXPORT_SYMBOL_GPL(ras_get_debugfs_root);
16 int ras_userspace_consumers(void)
18 return atomic_read(&trace_count);
20 EXPORT_SYMBOL_GPL(ras_userspace_consumers);
22 static int trace_show(struct seq_file *m, void *v)
24 return 0;
27 static int trace_open(struct inode *inode, struct file *file)
29 atomic_inc(&trace_count);
30 return single_open(file, trace_show, NULL);
33 static int trace_release(struct inode *inode, struct file *file)
35 atomic_dec(&trace_count);
36 return single_release(inode, file);
39 static const struct file_operations trace_fops = {
40 .open = trace_open,
41 .read = seq_read,
42 .llseek = seq_lseek,
43 .release = trace_release,
46 int __init ras_add_daemon_trace(void)
48 struct dentry *fentry;
50 if (!ras_debugfs_dir)
51 return -ENOENT;
53 fentry = debugfs_create_file("daemon_active", S_IRUSR, ras_debugfs_dir,
54 NULL, &trace_fops);
55 if (IS_ERR(fentry))
56 return -ENODEV;
58 return 0;
62 void __init ras_debugfs_init(void)
64 ras_debugfs_dir = debugfs_create_dir("ras", NULL);