xref: /openbmc/linux/arch/mips/kernel/segment.c (revision a06c488d)
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/debug.h>
14 #include <asm/mipsregs.h>
15 
16 static void build_segment_config(char *str, unsigned int cfg)
17 {
18 	unsigned int am;
19 	static const char * const am_str[] = {
20 		"UK", "MK", "MSK", "MUSK", "MUSUK", "USK",
21 		"RSRVD", "UUSK"};
22 
23 	/* Segment access mode. */
24 	am = (cfg & MIPS_SEGCFG_AM) >> MIPS_SEGCFG_AM_SHIFT;
25 	str += sprintf(str, "%-5s", am_str[am]);
26 
27 	/*
28 	 * Access modes MK, MSK and MUSK are mapped segments. Therefore
29 	 * there is no direct physical address mapping.
30 	 */
31 	if ((am == 0) || (am > 3)) {
32 		str += sprintf(str, "         %03lx",
33 			((cfg & MIPS_SEGCFG_PA) >> MIPS_SEGCFG_PA_SHIFT));
34 		str += sprintf(str, "         %01ld",
35 			((cfg & MIPS_SEGCFG_C) >> MIPS_SEGCFG_C_SHIFT));
36 	} else {
37 		str += sprintf(str, "         UND");
38 		str += sprintf(str, "         U");
39 	}
40 
41 	/* Exception configuration. */
42 	str += sprintf(str, "       %01ld\n",
43 		((cfg & MIPS_SEGCFG_EU) >> MIPS_SEGCFG_EU_SHIFT));
44 }
45 
46 static int show_segments(struct seq_file *m, void *v)
47 {
48 	unsigned int segcfg;
49 	char str[42];
50 
51 	seq_puts(m, "Segment   Virtual    Size   Access Mode   Physical   Caching   EU\n");
52 	seq_puts(m, "-------   -------    ----   -----------   --------   -------   --\n");
53 
54 	segcfg = read_c0_segctl0();
55 	build_segment_config(str, segcfg);
56 	seq_printf(m, "   0      e0000000   512M      %s", str);
57 
58 	segcfg >>= 16;
59 	build_segment_config(str, segcfg);
60 	seq_printf(m, "   1      c0000000   512M      %s", str);
61 
62 	segcfg = read_c0_segctl1();
63 	build_segment_config(str, segcfg);
64 	seq_printf(m, "   2      a0000000   512M      %s", str);
65 
66 	segcfg >>= 16;
67 	build_segment_config(str, segcfg);
68 	seq_printf(m, "   3      80000000   512M      %s", str);
69 
70 	segcfg = read_c0_segctl2();
71 	build_segment_config(str, segcfg);
72 	seq_printf(m, "   4      40000000    1G       %s", str);
73 
74 	segcfg >>= 16;
75 	build_segment_config(str, segcfg);
76 	seq_printf(m, "   5      00000000    1G       %s\n", str);
77 
78 	return 0;
79 }
80 
81 static int segments_open(struct inode *inode, struct file *file)
82 {
83 	return single_open(file, show_segments, NULL);
84 }
85 
86 static const struct file_operations segments_fops = {
87 	.open		= segments_open,
88 	.read		= seq_read,
89 	.llseek		= seq_lseek,
90 	.release	= single_release,
91 };
92 
93 static int __init segments_info(void)
94 {
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);
111