Thomas Gleixner | 457c899 | 2019-05-19 13:08:55 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Chen, Gong | d963cd9 | 2014-06-11 14:02:20 -0700 | [diff] [blame] | 2 | #include <linux/debugfs.h> |
Valdis Klētnieks | 0a54b80 | 2019-08-07 18:59:29 -0400 | [diff] [blame] | 3 | #include <linux/ras.h> |
| 4 | #include "debugfs.h" |
Chen, Gong | d963cd9 | 2014-06-11 14:02:20 -0700 | [diff] [blame] | 5 | |
Borislav Petkov | 011d826 | 2017-03-27 11:33:02 +0200 | [diff] [blame] | 6 | struct dentry *ras_debugfs_dir; |
Chen, Gong | d963cd9 | 2014-06-11 14:02:20 -0700 | [diff] [blame] | 7 | |
| 8 | static atomic_t trace_count = ATOMIC_INIT(0); |
| 9 | |
| 10 | int ras_userspace_consumers(void) |
| 11 | { |
| 12 | return atomic_read(&trace_count); |
| 13 | } |
| 14 | EXPORT_SYMBOL_GPL(ras_userspace_consumers); |
| 15 | |
| 16 | static int trace_show(struct seq_file *m, void *v) |
| 17 | { |
| 18 | return atomic_read(&trace_count); |
| 19 | } |
| 20 | |
| 21 | static int trace_open(struct inode *inode, struct file *file) |
| 22 | { |
| 23 | atomic_inc(&trace_count); |
| 24 | return single_open(file, trace_show, NULL); |
| 25 | } |
| 26 | |
| 27 | static int trace_release(struct inode *inode, struct file *file) |
| 28 | { |
| 29 | atomic_dec(&trace_count); |
| 30 | return single_release(inode, file); |
| 31 | } |
| 32 | |
| 33 | static const struct file_operations trace_fops = { |
| 34 | .open = trace_open, |
| 35 | .read = seq_read, |
| 36 | .llseek = seq_lseek, |
| 37 | .release = trace_release, |
| 38 | }; |
| 39 | |
| 40 | int __init ras_add_daemon_trace(void) |
| 41 | { |
| 42 | struct dentry *fentry; |
| 43 | |
| 44 | if (!ras_debugfs_dir) |
| 45 | return -ENOENT; |
| 46 | |
| 47 | fentry = debugfs_create_file("daemon_active", S_IRUSR, ras_debugfs_dir, |
| 48 | NULL, &trace_fops); |
| 49 | if (!fentry) |
| 50 | return -ENODEV; |
| 51 | |
| 52 | return 0; |
| 53 | |
| 54 | } |
| 55 | |
| 56 | void __init ras_debugfs_init(void) |
| 57 | { |
| 58 | ras_debugfs_dir = debugfs_create_dir("ras", NULL); |
| 59 | } |