1 | // SPDX-License-Identifier: GPL-2.0 |
2 | |
3 | #include <linux/proc_fs.h> |
4 | |
5 | #include "fb_internal.h" |
6 | |
7 | static struct proc_dir_entry *fb_proc_dir_entry; |
8 | |
9 | static void *fb_seq_start(struct seq_file *m, loff_t *pos) |
10 | { |
11 | mutex_lock(®istration_lock); |
12 | |
13 | return (*pos < FB_MAX) ? pos : NULL; |
14 | } |
15 | |
16 | static void fb_seq_stop(struct seq_file *m, void *v) |
17 | { |
18 | mutex_unlock(lock: ®istration_lock); |
19 | } |
20 | |
21 | static void *fb_seq_next(struct seq_file *m, void *v, loff_t *pos) |
22 | { |
23 | (*pos)++; |
24 | |
25 | return (*pos < FB_MAX) ? pos : NULL; |
26 | } |
27 | |
28 | static int fb_seq_show(struct seq_file *m, void *v) |
29 | { |
30 | int i = *(loff_t *)v; |
31 | struct fb_info *fi = registered_fb[i]; |
32 | |
33 | if (fi) |
34 | seq_printf(m, fmt: "%d %s\n" , fi->node, fi->fix.id); |
35 | |
36 | return 0; |
37 | } |
38 | |
39 | static const struct seq_operations __maybe_unused fb_proc_seq_ops = { |
40 | .start = fb_seq_start, |
41 | .stop = fb_seq_stop, |
42 | .next = fb_seq_next, |
43 | .show = fb_seq_show, |
44 | }; |
45 | |
46 | int fb_init_procfs(void) |
47 | { |
48 | struct proc_dir_entry *proc; |
49 | |
50 | proc = proc_create_seq("fb" , 0, NULL, &fb_proc_seq_ops); |
51 | if (!proc) |
52 | return -ENOMEM; |
53 | |
54 | fb_proc_dir_entry = proc; |
55 | |
56 | return 0; |
57 | } |
58 | |
59 | void fb_cleanup_procfs(void) |
60 | { |
61 | proc_remove(fb_proc_dir_entry); |
62 | } |
63 | |