Linux-libre 5.4.49-gnu
[librecmc/linux-libre.git] / arch / powerpc / mm / ptdump / segment_regs.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2018, Christophe Leroy CS S.I.
4  * <christophe.leroy@c-s.fr>
5  *
6  * This dumps the content of Segment Registers
7  */
8
9 #include <asm/debugfs.h>
10
11 static void seg_show(struct seq_file *m, int i)
12 {
13         u32 val = mfsrin(i << 28);
14
15         seq_printf(m, "0x%01x0000000-0x%01xfffffff ", i, i);
16         seq_printf(m, "Kern key %d ", (val >> 30) & 1);
17         seq_printf(m, "User key %d ", (val >> 29) & 1);
18         if (val & 0x80000000) {
19                 seq_printf(m, "Device 0x%03x", (val >> 20) & 0x1ff);
20                 seq_printf(m, "-0x%05x", val & 0xfffff);
21         } else {
22                 if (val & 0x10000000)
23                         seq_puts(m, "No Exec ");
24                 seq_printf(m, "VSID 0x%06x", val & 0xffffff);
25         }
26         seq_puts(m, "\n");
27 }
28
29 static int sr_show(struct seq_file *m, void *v)
30 {
31         int i;
32
33         seq_puts(m, "---[ User Segments ]---\n");
34         for (i = 0; i < TASK_SIZE >> 28; i++)
35                 seg_show(m, i);
36
37         seq_puts(m, "\n---[ Kernel Segments ]---\n");
38         for (; i < 16; i++)
39                 seg_show(m, i);
40
41         return 0;
42 }
43
44 static int sr_open(struct inode *inode, struct file *file)
45 {
46         return single_open(file, sr_show, NULL);
47 }
48
49 static const struct file_operations sr_fops = {
50         .open           = sr_open,
51         .read           = seq_read,
52         .llseek         = seq_lseek,
53         .release        = single_release,
54 };
55
56 static int __init sr_init(void)
57 {
58         struct dentry *debugfs_file;
59
60         debugfs_file = debugfs_create_file("segment_registers", 0400,
61                                            powerpc_debugfs_root, NULL, &sr_fops);
62         return debugfs_file ? 0 : -ENOMEM;
63 }
64 device_initcall(sr_init);