Commit | Line | Data |
---|---|---|
29f9087c SH |
1 | /* |
2 | * This file is subject to the terms and conditions of the GNU General Public | |
3 | * License. See the file "COPYING" in the main directory of this archive | |
4 | * for more details. | |
5 | * | |
6 | * Copyright (C) 2013 Imagination Technologies Ltd. | |
7 | */ | |
8 | ||
9 | #include <linux/kernel.h> | |
10 | #include <linux/debugfs.h> | |
11 | #include <linux/seq_file.h> | |
12 | #include <asm/cpu.h> | |
13 | #include <asm/mipsregs.h> | |
14 | ||
15 | static void build_segment_config(char *str, unsigned int cfg) | |
16 | { | |
17 | unsigned int am; | |
18 | static const char * const am_str[] = { | |
19 | "UK", "MK", "MSK", "MUSK", "MUSUK", "USK", | |
20 | "RSRVD", "UUSK"}; | |
21 | ||
22 | /* Segment access mode. */ | |
23 | am = (cfg & MIPS_SEGCFG_AM) >> MIPS_SEGCFG_AM_SHIFT; | |
24 | str += sprintf(str, "%-5s", am_str[am]); | |
25 | ||
26 | /* | |
27 | * Access modes MK, MSK and MUSK are mapped segments. Therefore | |
28 | * there is no direct physical address mapping. | |
29 | */ | |
30 | if ((am == 0) || (am > 3)) { | |
31 | str += sprintf(str, " %03lx", | |
32 | ((cfg & MIPS_SEGCFG_PA) >> MIPS_SEGCFG_PA_SHIFT)); | |
33 | str += sprintf(str, " %01ld", | |
34 | ((cfg & MIPS_SEGCFG_C) >> MIPS_SEGCFG_C_SHIFT)); | |
35 | } else { | |
36 | str += sprintf(str, " UND"); | |
37 | str += sprintf(str, " U"); | |
38 | } | |
39 | ||
40 | /* Exception configuration. */ | |
41 | str += sprintf(str, " %01ld\n", | |
42 | ((cfg & MIPS_SEGCFG_EU) >> MIPS_SEGCFG_EU_SHIFT)); | |
43 | } | |
44 | ||
45 | static int show_segments(struct seq_file *m, void *v) | |
46 | { | |
47 | unsigned int segcfg; | |
48 | char str[42]; | |
49 | ||
50 | seq_puts(m, "Segment Virtual Size Access Mode Physical Caching EU\n"); | |
51 | seq_puts(m, "------- ------- ---- ----------- -------- ------- --\n"); | |
52 | ||
53 | segcfg = read_c0_segctl0(); | |
54 | build_segment_config(str, segcfg); | |
55 | seq_printf(m, " 0 e0000000 512M %s", str); | |
56 | ||
57 | segcfg >>= 16; | |
58 | build_segment_config(str, segcfg); | |
59 | seq_printf(m, " 1 c0000000 512M %s", str); | |
60 | ||
61 | segcfg = read_c0_segctl1(); | |
62 | build_segment_config(str, segcfg); | |
63 | seq_printf(m, " 2 a0000000 512M %s", str); | |
64 | ||
65 | segcfg >>= 16; | |
66 | build_segment_config(str, segcfg); | |
67 | seq_printf(m, " 3 80000000 512M %s", str); | |
68 | ||
69 | segcfg = read_c0_segctl2(); | |
70 | build_segment_config(str, segcfg); | |
71 | seq_printf(m, " 4 40000000 1G %s", str); | |
72 | ||
73 | segcfg >>= 16; | |
74 | build_segment_config(str, segcfg); | |
75 | seq_printf(m, " 5 00000000 1G %s\n", str); | |
76 | ||
77 | return 0; | |
78 | } | |
79 | ||
80 | static int segments_open(struct inode *inode, struct file *file) | |
81 | { | |
82 | return single_open(file, show_segments, NULL); | |
83 | } | |
84 | ||
85 | static const struct file_operations segments_fops = { | |
86 | .open = segments_open, | |
87 | .read = seq_read, | |
88 | .llseek = seq_lseek, | |
89 | .release = single_release, | |
90 | }; | |
91 | ||
92 | static int __init segments_info(void) | |
93 | { | |
94 | extern struct dentry *mips_debugfs_dir; | |
95 | struct dentry *segments; | |
96 | ||
97 | if (cpu_has_segments) { | |
98 | if (!mips_debugfs_dir) | |
99 | return -ENODEV; | |
100 | ||
101 | segments = debugfs_create_file("segments", S_IRUGO, | |
102 | mips_debugfs_dir, NULL, | |
103 | &segments_fops); | |
104 | if (!segments) | |
105 | return -ENOMEM; | |
106 | } | |
107 | return 0; | |
108 | } | |
109 | ||
110 | device_initcall(segments_info); |