1457c8996SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2d963cd95SChen, Gong #include <linux/debugfs.h>
30a54b809SValdis Klētnieks #include <linux/ras.h>
40a54b809SValdis Klētnieks #include "debugfs.h"
5d963cd95SChen, Gong
6011d8261SBorislav Petkov struct dentry *ras_debugfs_dir;
7d963cd95SChen, Gong
8d963cd95SChen, Gong static atomic_t trace_count = ATOMIC_INIT(0);
9d963cd95SChen, Gong
ras_userspace_consumers(void)10d963cd95SChen, Gong int ras_userspace_consumers(void)
11d963cd95SChen, Gong {
12d963cd95SChen, Gong return atomic_read(&trace_count);
13d963cd95SChen, Gong }
14d963cd95SChen, Gong EXPORT_SYMBOL_GPL(ras_userspace_consumers);
15d963cd95SChen, Gong
trace_show(struct seq_file * m,void * v)16d963cd95SChen, Gong static int trace_show(struct seq_file *m, void *v)
17d963cd95SChen, Gong {
1850865c14STony Luck return 0;
19d963cd95SChen, Gong }
20d963cd95SChen, Gong
trace_open(struct inode * inode,struct file * file)21d963cd95SChen, Gong static int trace_open(struct inode *inode, struct file *file)
22d963cd95SChen, Gong {
23d963cd95SChen, Gong atomic_inc(&trace_count);
24d963cd95SChen, Gong return single_open(file, trace_show, NULL);
25d963cd95SChen, Gong }
26d963cd95SChen, Gong
trace_release(struct inode * inode,struct file * file)27d963cd95SChen, Gong static int trace_release(struct inode *inode, struct file *file)
28d963cd95SChen, Gong {
29d963cd95SChen, Gong atomic_dec(&trace_count);
30d963cd95SChen, Gong return single_release(inode, file);
31d963cd95SChen, Gong }
32d963cd95SChen, Gong
33d963cd95SChen, Gong static const struct file_operations trace_fops = {
34d963cd95SChen, Gong .open = trace_open,
35d963cd95SChen, Gong .read = seq_read,
36d963cd95SChen, Gong .llseek = seq_lseek,
37d963cd95SChen, Gong .release = trace_release,
38d963cd95SChen, Gong };
39d963cd95SChen, Gong
ras_add_daemon_trace(void)40d963cd95SChen, Gong int __init ras_add_daemon_trace(void)
41d963cd95SChen, Gong {
42d963cd95SChen, Gong struct dentry *fentry;
43d963cd95SChen, Gong
44d963cd95SChen, Gong if (!ras_debugfs_dir)
45d963cd95SChen, Gong return -ENOENT;
46d963cd95SChen, Gong
47d963cd95SChen, Gong fentry = debugfs_create_file("daemon_active", S_IRUSR, ras_debugfs_dir,
48d963cd95SChen, Gong NULL, &trace_fops);
49*2a1d18a5SOsama Muhammad if (IS_ERR(fentry))
50d963cd95SChen, Gong return -ENODEV;
51d963cd95SChen, Gong
52d963cd95SChen, Gong return 0;
53d963cd95SChen, Gong
54d963cd95SChen, Gong }
55d963cd95SChen, Gong
ras_debugfs_init(void)56d963cd95SChen, Gong void __init ras_debugfs_init(void)
57d963cd95SChen, Gong {
58d963cd95SChen, Gong ras_debugfs_dir = debugfs_create_dir("ras", NULL);
59d963cd95SChen, Gong }
60