Skip to content

Commit 3513369

Browse files
chrisdearmanralfbaechle
authored andcommitted
[MIPS] Allow setting of the cache attribute at run time.
Slightly tacky, but there is a precedent in the sparc archirecture code. Signed-off-by: Chris Dearman <[email protected]> Signed-off-by: Atsushi Nemoto <[email protected]> Signed-off-by: Ralf Baechle <[email protected]>
1 parent bec5052 commit 3513369

File tree

11 files changed

+75
-61
lines changed

11 files changed

+75
-61
lines changed

arch/mips/Kconfig.debug

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,4 @@ config RUNTIME_DEBUG
7373
include/asm-mips/debug.h for debuging macros.
7474
If unsure, say N.
7575

76-
config MIPS_UNCACHED
77-
bool "Run uncached"
78-
depends on DEBUG_KERNEL && !SMP && !SGI_IP27
79-
help
80-
If you say Y here there kernel will disable all CPU caches. This will
81-
reduce the system's performance dramatically but can help finding
82-
otherwise hard to track bugs. It can also useful if you're doing
83-
hardware debugging with a logic analyzer and need to see all traffic
84-
on the bus.
85-
8676
endmenu

arch/mips/configs/mipssim_defconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,6 @@ CONFIG_CROSSCOMPILE=y
641641
CONFIG_CMDLINE="nfsroot=192.168.192.169:/u1/mipsel,timeo=20 ip=dhcp"
642642
# CONFIG_DEBUG_STACK_USAGE is not set
643643
# CONFIG_RUNTIME_DEBUG is not set
644-
# CONFIG_MIPS_UNCACHED is not set
645644

646645
#
647646
# Security options

arch/mips/configs/pnx8550-jbs_defconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,6 @@ CONFIG_CMDLINE="console=ttyS1,38400n8 kgdb=ttyS0 root=/dev/nfs ip=bootp"
12231223
# CONFIG_KGDB is not set
12241224
CONFIG_SYS_SUPPORTS_KGDB=y
12251225
# CONFIG_RUNTIME_DEBUG is not set
1226-
# CONFIG_MIPS_UNCACHED is not set
12271226

12281227
#
12291228
# Security options

arch/mips/configs/pnx8550-stb810_defconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,6 @@ CONFIG_CMDLINE="console=ttyS1,38400n8 kgdb=ttyS0 root=/dev/nfs ip=bootp"
12131213
# CONFIG_KGDB is not set
12141214
CONFIG_SYS_SUPPORTS_KGDB=y
12151215
# CONFIG_RUNTIME_DEBUG is not set
1216-
# CONFIG_MIPS_UNCACHED is not set
12171216

12181217
#
12191218
# Security options

arch/mips/mm/c-r4k.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/linkage.h>
1515
#include <linux/sched.h>
1616
#include <linux/mm.h>
17+
#include <linux/module.h>
1718
#include <linux/bitops.h>
1819

1920
#include <asm/bcache.h>
@@ -1216,9 +1217,25 @@ void au1x00_fixup_config_od(void)
12161217
}
12171218
}
12181219

1220+
static int __cpuinitdata cca = -1;
1221+
1222+
static int __init cca_setup(char *str)
1223+
{
1224+
get_option(&str, &cca);
1225+
1226+
return 1;
1227+
}
1228+
1229+
__setup("cca=", cca_setup);
1230+
12191231
static void __cpuinit coherency_setup(void)
12201232
{
1221-
change_c0_config(CONF_CM_CMASK, CONF_CM_DEFAULT);
1233+
if (cca < 0 || cca > 7)
1234+
cca = read_c0_config() & CONF_CM_CMASK;
1235+
_page_cachable_default = cca << _CACHE_SHIFT;
1236+
1237+
pr_debug("Using cache attribute %d\n", cca);
1238+
change_c0_config(CONF_CM_CMASK, cca);
12221239

12231240
/*
12241241
* c0_status.cu=0 specifies that updates by the sc instruction use

arch/mips/mm/cache.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,43 +130,58 @@ void __update_cache(struct vm_area_struct *vma, unsigned long address,
130130
}
131131
}
132132

133-
static char cache_panic[] __cpuinitdata =
134-
"Yeee, unsupported cache architecture.";
133+
unsigned long _page_cachable_default;
134+
EXPORT_SYMBOL_GPL(_page_cachable_default);
135+
136+
static inline void setup_protection_map(void)
137+
{
138+
protection_map[0] = PAGE_NONE;
139+
protection_map[1] = PAGE_READONLY;
140+
protection_map[2] = PAGE_COPY;
141+
protection_map[3] = PAGE_COPY;
142+
protection_map[4] = PAGE_READONLY;
143+
protection_map[5] = PAGE_READONLY;
144+
protection_map[6] = PAGE_COPY;
145+
protection_map[7] = PAGE_COPY;
146+
protection_map[8] = PAGE_NONE;
147+
protection_map[9] = PAGE_READONLY;
148+
protection_map[10] = PAGE_SHARED;
149+
protection_map[11] = PAGE_SHARED;
150+
protection_map[12] = PAGE_READONLY;
151+
protection_map[13] = PAGE_READONLY;
152+
protection_map[14] = PAGE_SHARED;
153+
protection_map[15] = PAGE_SHARED;
154+
}
135155

136156
void __devinit cpu_cache_init(void)
137157
{
138158
if (cpu_has_3k_cache) {
139159
extern void __weak r3k_cache_init(void);
140160

141161
r3k_cache_init();
142-
return;
143162
}
144163
if (cpu_has_6k_cache) {
145164
extern void __weak r6k_cache_init(void);
146165

147166
r6k_cache_init();
148-
return;
149167
}
150168
if (cpu_has_4k_cache) {
151169
extern void __weak r4k_cache_init(void);
152170

153171
r4k_cache_init();
154-
return;
155172
}
156173
if (cpu_has_8k_cache) {
157174
extern void __weak r8k_cache_init(void);
158175

159176
r8k_cache_init();
160-
return;
161177
}
162178
if (cpu_has_tx39_cache) {
163179
extern void __weak tx39_cache_init(void);
164180

165181
tx39_cache_init();
166-
return;
167182
}
168183

169-
panic(cache_panic);
184+
setup_protection_map();
170185
}
171186

172187
int __weak __uncached_access(struct file *file, unsigned long addr)

arch/mips/philips/pnx8550/jbs/board_setup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ void __init board_setup(void)
5353

5454
/* clear all three cache coherency fields */
5555
config0 &= ~(0x7 | (7<<25) | (7<<28));
56-
config0 |= (CONF_CM_DEFAULT | (CONF_CM_DEFAULT<<25) |
57-
(CONF_CM_DEFAULT<<28));
56+
config0 |= (_page_cachable_default >> _CACHE_SHIFT) |
57+
(CONF_CM_DEFAULT << 25) | (CONF_CM_DEFAULT << 28);
5858
write_c0_config(config0);
5959
BARRIER;
6060

arch/mips/philips/pnx8550/stb810/board_setup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ void __init board_setup(void)
3939

4040
/* clear all three cache coherency fields */
4141
config0 &= ~(0x7 | (7<<25) | (7<<28));
42-
config0 |= (CONF_CM_DEFAULT | (CONF_CM_DEFAULT<<25) |
43-
(CONF_CM_DEFAULT<<28));
42+
config0 |= (_page_cachable_default >> _CACHE_SHIFT) |
43+
(CONF_CM_DEFAULT << 25) | (CONF_CM_DEFAULT << 28);
4444
write_c0_config(config0);
4545

4646
configpr = read_c0_config7();

include/asm-mips/io.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ static inline void __iomem * __ioremap_mode(phys_t offset, unsigned long size,
273273
* memory-like regions on I/O busses.
274274
*/
275275
#define ioremap_cachable(offset, size) \
276-
__ioremap_mode((offset), (size), PAGE_CACHABLE_DEFAULT)
276+
__ioremap_mode((offset), (size), _page_cachable_default)
277277

278278
/*
279279
* These two are MIPS specific ioremap variant. ioremap_cacheable_cow

include/asm-mips/pgtable-bits.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,6 @@
134134

135135
#define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_ACCESSED | _PAGE_MODIFIED | _CACHE_MASK)
136136

137-
#ifdef CONFIG_MIPS_UNCACHED
138-
#define PAGE_CACHABLE_DEFAULT _CACHE_UNCACHED
139-
#elif defined(CONFIG_DMA_NONCOHERENT)
140-
#define PAGE_CACHABLE_DEFAULT _CACHE_CACHABLE_NONCOHERENT
141-
#elif defined(CONFIG_CPU_RM9000)
142-
#define PAGE_CACHABLE_DEFAULT _CACHE_CWB
143-
#elif defined(CONFIG_SOC_AU1X00)
144-
#define PAGE_CACHABLE_DEFAULT _CACHE_CACHABLE_NONCOHERENT
145-
#else
146-
#define PAGE_CACHABLE_DEFAULT _CACHE_CACHABLE_COW
147-
#endif
148-
149137
#define CONF_CM_DEFAULT (PAGE_CACHABLE_DEFAULT>>_CACHE_SHIFT)
150138

151139
#endif /* _ASM_PGTABLE_BITS_H */

include/asm-mips/pgtable.h

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ struct vm_area_struct;
2323

2424
#define PAGE_NONE __pgprot(_PAGE_PRESENT | _CACHE_CACHABLE_NONCOHERENT)
2525
#define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | \
26-
PAGE_CACHABLE_DEFAULT)
26+
_page_cachable_default)
2727
#define PAGE_COPY __pgprot(_PAGE_PRESENT | _PAGE_READ | \
28-
PAGE_CACHABLE_DEFAULT)
28+
_page_cachable_default)
2929
#define PAGE_READONLY __pgprot(_PAGE_PRESENT | _PAGE_READ | \
30-
PAGE_CACHABLE_DEFAULT)
30+
_page_cachable_default)
3131
#define PAGE_KERNEL __pgprot(_PAGE_PRESENT | __READABLE | __WRITEABLE | \
32-
_PAGE_GLOBAL | PAGE_CACHABLE_DEFAULT)
32+
_PAGE_GLOBAL | _page_cachable_default)
3333
#define PAGE_USERIO __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | \
34-
PAGE_CACHABLE_DEFAULT)
34+
_page_cachable_default)
3535
#define PAGE_KERNEL_UNCACHED __pgprot(_PAGE_PRESENT | __READABLE | \
3636
__WRITEABLE | _PAGE_GLOBAL | _CACHE_UNCACHED)
3737

@@ -40,23 +40,30 @@ struct vm_area_struct;
4040
* read. Also, write permissions imply read permissions. This is the closest
4141
* we can get by reasonable means..
4242
*/
43-
#define __P000 PAGE_NONE
44-
#define __P001 PAGE_READONLY
45-
#define __P010 PAGE_COPY
46-
#define __P011 PAGE_COPY
47-
#define __P100 PAGE_READONLY
48-
#define __P101 PAGE_READONLY
49-
#define __P110 PAGE_COPY
50-
#define __P111 PAGE_COPY
51-
52-
#define __S000 PAGE_NONE
53-
#define __S001 PAGE_READONLY
54-
#define __S010 PAGE_SHARED
55-
#define __S011 PAGE_SHARED
56-
#define __S100 PAGE_READONLY
57-
#define __S101 PAGE_READONLY
58-
#define __S110 PAGE_SHARED
59-
#define __S111 PAGE_SHARED
43+
44+
/*
45+
* Dummy values to fill the table in mmap.c
46+
* The real values will be generated at runtime
47+
*/
48+
#define __P000 __pgprot(0)
49+
#define __P001 __pgprot(0)
50+
#define __P010 __pgprot(0)
51+
#define __P011 __pgprot(0)
52+
#define __P100 __pgprot(0)
53+
#define __P101 __pgprot(0)
54+
#define __P110 __pgprot(0)
55+
#define __P111 __pgprot(0)
56+
57+
#define __S000 __pgprot(0)
58+
#define __S001 __pgprot(0)
59+
#define __S010 __pgprot(0)
60+
#define __S011 __pgprot(0)
61+
#define __S100 __pgprot(0)
62+
#define __S101 __pgprot(0)
63+
#define __S110 __pgprot(0)
64+
#define __S111 __pgprot(0)
65+
66+
extern unsigned long _page_cachable_default;
6067

6168
/*
6269
* ZERO_PAGE is a global shared page that is always zero; used

0 commit comments

Comments
 (0)