Merge tag 'locking-urgent-2020-12-27' of git://git.kernel.org/pub/scm/linux/kernel...
[linux/fpc-iii.git] / arch / mips / kernel / segment.c
blob0a9bd7b0983b93333d7fcfadc1cece892cc0aa55
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.
6 * Copyright (C) 2013 Imagination Technologies Ltd.
7 */
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>
16 static void build_segment_config(char *str, unsigned int cfg)
18 unsigned int am;
19 static const char * const am_str[] = {
20 "UK", "MK", "MSK", "MUSK", "MUSUK", "USK",
21 "RSRVD", "UUSK"};
23 /* Segment access mode. */
24 am = (cfg & MIPS_SEGCFG_AM) >> MIPS_SEGCFG_AM_SHIFT;
25 str += sprintf(str, "%-5s", am_str[am]);
28 * Access modes MK, MSK and MUSK are mapped segments. Therefore
29 * there is no direct physical address mapping unless it becomes
30 * unmapped uncached at error level due to EU.
32 if ((am == 0) || (am > 3) || (cfg & MIPS_SEGCFG_EU))
33 str += sprintf(str, " %03lx",
34 ((cfg & MIPS_SEGCFG_PA) >> MIPS_SEGCFG_PA_SHIFT));
35 else
36 str += sprintf(str, " UND");
38 if ((am == 0) || (am > 3))
39 str += sprintf(str, " %01ld",
40 ((cfg & MIPS_SEGCFG_C) >> MIPS_SEGCFG_C_SHIFT));
41 else
42 str += sprintf(str, " U");
44 /* Exception configuration. */
45 str += sprintf(str, " %01ld\n",
46 ((cfg & MIPS_SEGCFG_EU) >> MIPS_SEGCFG_EU_SHIFT));
49 static int show_segments(struct seq_file *m, void *v)
51 unsigned int segcfg;
52 char str[42];
54 seq_puts(m, "Segment Virtual Size Access Mode Physical Caching EU\n");
55 seq_puts(m, "------- ------- ---- ----------- -------- ------- --\n");
57 segcfg = read_c0_segctl0();
58 build_segment_config(str, segcfg);
59 seq_printf(m, " 0 e0000000 512M %s", str);
61 segcfg >>= 16;
62 build_segment_config(str, segcfg);
63 seq_printf(m, " 1 c0000000 512M %s", str);
65 segcfg = read_c0_segctl1();
66 build_segment_config(str, segcfg);
67 seq_printf(m, " 2 a0000000 512M %s", str);
69 segcfg >>= 16;
70 build_segment_config(str, segcfg);
71 seq_printf(m, " 3 80000000 512M %s", str);
73 segcfg = read_c0_segctl2();
74 build_segment_config(str, segcfg);
75 seq_printf(m, " 4 40000000 1G %s", str);
77 segcfg >>= 16;
78 build_segment_config(str, segcfg);
79 seq_printf(m, " 5 00000000 1G %s\n", str);
81 return 0;
84 static int segments_open(struct inode *inode, struct file *file)
86 return single_open(file, show_segments, NULL);
89 static const struct file_operations segments_fops = {
90 .open = segments_open,
91 .read = seq_read,
92 .llseek = seq_lseek,
93 .release = single_release,
96 static int __init segments_info(void)
98 if (cpu_has_segments)
99 debugfs_create_file("segments", S_IRUGO, mips_debugfs_dir, NULL,
100 &segments_fops);
101 return 0;
104 device_initcall(segments_info);