Skip to content

Commit e7bd34a

Browse files
committed
sh: Support explicit L1 cache disabling.
This reworks the cache mode configuration in Kconfig, and allows for explicit selection of write-back/write-through/off configurations. All of the cache flushing routines are optimized away for the off case. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent ac91998 commit e7bd34a

9 files changed

Lines changed: 86 additions & 31 deletions

File tree

‎arch/sh/kernel/cpu/init.c‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,15 @@ static void __init cache_init(void)
143143
flags &= ~CCR_CACHE_EMODE;
144144
#endif
145145

146-
#ifdef CONFIG_SH_WRITETHROUGH
147-
/* Turn on Write-through caching */
146+
#if defined(CONFIG_CACHE_WRITETHROUGH)
147+
/* Write-through */
148148
flags |= CCR_CACHE_WT;
149-
#else
150-
/* .. or default to Write-back */
149+
#elif defined(CONFIG_CACHE_WRITEBACK)
150+
/* Write-back */
151151
flags |= CCR_CACHE_CB;
152+
#else
153+
/* Off */
154+
flags &= ~CCR_CACHE_ENABLE;
152155
#endif
153156

154157
ctrl_outl(flags, CCR);

‎arch/sh/kernel/sh_ksyms.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,17 @@ DECLARE_EXPORT(__movstrSI12_i4);
128128
#endif /* __GNUC__ == 4 */
129129
#endif
130130

131-
#if defined(CONFIG_CPU_SH4) || defined(CONFIG_SH7705_CACHE_32KB)
131+
#if !defined(CONFIG_CACHE_OFF) && (defined(CONFIG_CPU_SH4) || \
132+
defined(CONFIG_SH7705_CACHE_32KB))
132133
/* needed by some modules */
133134
EXPORT_SYMBOL(flush_cache_all);
134135
EXPORT_SYMBOL(flush_cache_range);
135136
EXPORT_SYMBOL(flush_dcache_page);
136137
EXPORT_SYMBOL(__flush_purge_region);
137138
#endif
138139

139-
#if defined(CONFIG_MMU) && (defined(CONFIG_CPU_SH4) || \
140-
defined(CONFIG_SH7705_CACHE_32KB))
140+
#if !defined(CONFIG_CACHE_OFF) && defined(CONFIG_MMU) && \
141+
(defined(CONFIG_CPU_SH4) || defined(CONFIG_SH7705_CACHE_32KB))
141142
EXPORT_SYMBOL(clear_user_page);
142143
#endif
143144

‎arch/sh/mm/Kconfig‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Processor families
33
#
44
config CPU_SH2
5-
select SH_WRITETHROUGH if !CPU_SH2A
65
bool
76

87
config CPU_SH2A
@@ -414,8 +413,17 @@ config SH_DIRECT_MAPPED
414413
Turn this option off for platforms that do not have a direct-mapped
415414
cache, and you have no need to run the caches in such a configuration.
416415

417-
config SH_WRITETHROUGH
418-
bool "Use write-through caching"
416+
choice
417+
prompt "Cache mode"
418+
default CACHE_WRITEBACK if CPU_SH2A || CPU_SH3 || CPU_SH4
419+
default CACHE_WRITETHROUGH if (CPU_SH2 && !CPU_SH2A)
420+
421+
config CACHE_WRITEBACK
422+
bool "Write-back"
423+
depends on CPU_SH2A || CPU_SH3 || CPU_SH4
424+
425+
config CACHE_WRITETHROUGH
426+
bool "Write-through"
419427
help
420428
Selecting this option will configure the caches in write-through
421429
mode, as opposed to the default write-back configuration.
@@ -426,4 +434,9 @@ config SH_WRITETHROUGH
426434

427435
If unsure, say N.
428436

437+
config CACHE_OFF
438+
bool "Off"
439+
440+
endchoice
441+
429442
endmenu

‎arch/sh/mm/Makefile‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,26 @@
44

55
obj-y := init.o extable.o consistent.o
66

7-
obj-$(CONFIG_CPU_SH2) += cache-sh2.o
8-
obj-$(CONFIG_CPU_SH3) += cache-sh3.o
9-
obj-$(CONFIG_CPU_SH4) += cache-sh4.o
7+
cache-$(CONFIG_CPU_SH2) := cache-sh2.o
8+
cache-$(CONFIG_CPU_SH3) := cache-sh3.o
9+
cache-$(CONFIG_CPU_SH4) := cache-sh4.o pg-sh4.o
10+
cache-$(CONFIG_CACHE_OFF) :=
1011

1112
mmu-y := tlb-nommu.o pg-nommu.o
1213
mmu-$(CONFIG_CPU_SH3) += fault-nommu.o
1314
mmu-$(CONFIG_CPU_SH4) += fault-nommu.o
1415
mmu-$(CONFIG_MMU) := fault.o clear_page.o copy_page.o tlb-flush.o \
1516
ioremap.o
1617

17-
obj-y += $(mmu-y)
18+
obj-y += $(cache-y) $(mmu-y)
1819

1920
ifdef CONFIG_DEBUG_FS
2021
obj-$(CONFIG_CPU_SH4) += cache-debugfs.o
2122
endif
2223

2324
ifdef CONFIG_MMU
2425
obj-$(CONFIG_CPU_SH3) += tlb-sh3.o
25-
obj-$(CONFIG_CPU_SH4) += tlb-sh4.o pg-sh4.o
26+
obj-$(CONFIG_CPU_SH4) += tlb-sh4.o
2627
obj-$(CONFIG_SH7705_CACHE_32KB) += pg-sh7705.o
2728
endif
2829

‎arch/sh/mm/pmb.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ int __set_pmb_entry(unsigned long vpn, unsigned long ppn,
145145

146146
ctrl_outl(vpn | PMB_V, mk_pmb_addr(pos));
147147

148-
#ifdef CONFIG_SH_WRITETHROUGH
148+
#ifdef CONFIG_CACHE_WRITETHROUGH
149149
/*
150150
* When we are in 32-bit address extended mode, CCR.CB becomes
151151
* invalid, so care must be taken to manually adjust cacheable

‎arch/sh/mm/tlb-sh4.c‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,27 @@ void update_mmu_cache(struct vm_area_struct * vma,
3434
unsigned long flags;
3535
unsigned long pteval;
3636
unsigned long vpn;
37-
struct page *page;
38-
unsigned long pfn;
3937

4038
/* Ptrace may call this routine. */
4139
if (vma && current->active_mm != vma->vm_mm)
4240
return;
4341

44-
pfn = pte_pfn(pte);
45-
if (pfn_valid(pfn)) {
46-
page = pfn_to_page(pfn);
47-
if (!test_bit(PG_mapped, &page->flags)) {
48-
unsigned long phys = pte_val(pte) & PTE_PHYS_MASK;
49-
__flush_wback_region((void *)P1SEGADDR(phys), PAGE_SIZE);
50-
__set_bit(PG_mapped, &page->flags);
42+
#ifndef CONFIG_CACHE_OFF
43+
{
44+
unsigned long pfn = pte_pfn(pte);
45+
46+
if (pfn_valid(pfn)) {
47+
struct page *page = pfn_to_page(pfn);
48+
49+
if (!test_bit(PG_mapped, &page->flags)) {
50+
unsigned long phys = pte_val(pte) & PTE_PHYS_MASK;
51+
__flush_wback_region((void *)P1SEGADDR(phys),
52+
PAGE_SIZE);
53+
__set_bit(PG_mapped, &page->flags);
54+
}
5155
}
5256
}
57+
#endif
5358

5459
local_irq_save(flags);
5560

@@ -66,7 +71,7 @@ void update_mmu_cache(struct vm_area_struct * vma,
6671

6772
/* Set PTEL register */
6873
pteval &= _PAGE_FLAGS_HARDWARE_MASK; /* drop software flags */
69-
#ifdef CONFIG_SH_WRITETHROUGH
74+
#ifdef CONFIG_CACHE_WRITETHROUGH
7075
pteval |= _PAGE_WT;
7176
#endif
7277
/* conveniently, we want all the software flags to be 0 anyway */

‎include/asm-sh/cacheflush.h‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,47 @@
11
#ifndef __ASM_SH_CACHEFLUSH_H
22
#define __ASM_SH_CACHEFLUSH_H
3+
34
#ifdef __KERNEL__
45

5-
#include <linux/mm.h>
6+
#ifdef CONFIG_CACHE_OFF
7+
/*
8+
* Nothing to do when the cache is disabled, initial flush and explicit
9+
* disabling is handled at CPU init time.
10+
*
11+
* See arch/sh/kernel/cpu/init.c:cache_init().
12+
*/
13+
#define p3_cache_init() do { } while (0)
14+
#define flush_cache_all() do { } while (0)
15+
#define flush_cache_mm(mm) do { } while (0)
16+
#define flush_cache_dup_mm(mm) do { } while (0)
17+
#define flush_cache_range(vma, start, end) do { } while (0)
18+
#define flush_cache_page(vma, vmaddr, pfn) do { } while (0)
19+
#define flush_dcache_page(page) do { } while (0)
20+
#define flush_icache_range(start, end) do { } while (0)
21+
#define flush_icache_page(vma,pg) do { } while (0)
22+
#define flush_dcache_mmap_lock(mapping) do { } while (0)
23+
#define flush_dcache_mmap_unlock(mapping) do { } while (0)
24+
#define flush_cache_sigtramp(vaddr) do { } while (0)
25+
#define flush_icache_user_range(vma,pg,adr,len) do { } while (0)
26+
#define __flush_wback_region(start, size) do { (void)(start); } while (0)
27+
#define __flush_purge_region(start, size) do { (void)(start); } while (0)
28+
#define __flush_invalidate_region(start, size) do { (void)(start); } while (0)
29+
#else
630
#include <asm/cpu/cacheflush.h>
731

32+
/*
33+
* Consistent DMA requires that the __flush_xxx() primitives must be set
34+
* for any of the enabled non-coherent caches (most of the UP CPUs),
35+
* regardless of PIPT or VIPT cache configurations.
36+
*/
37+
838
/* Flush (write-back only) a region (smaller than a page) */
939
extern void __flush_wback_region(void *start, int size);
1040
/* Flush (write-back & invalidate) a region (smaller than a page) */
1141
extern void __flush_purge_region(void *start, int size);
1242
/* Flush (invalidate only) a region (smaller than a page) */
1343
extern void __flush_invalidate_region(void *start, int size);
44+
#endif
1445

1546
#define flush_cache_vmap(start, end) flush_cache_all()
1647
#define flush_cache_vunmap(start, end) flush_cache_all()

‎include/asm-sh/page.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ extern void clear_page_nommu(void *to);
7070
extern void copy_page_nommu(void *to, void *from);
7171
#endif
7272

73-
#if defined(CONFIG_MMU) && (defined(CONFIG_CPU_SH4) || \
74-
defined(CONFIG_SH7705_CACHE_32KB))
73+
#if !defined(CONFIG_CACHE_OFF) && defined(CONFIG_MMU) && \
74+
(defined(CONFIG_CPU_SH4) || defined(CONFIG_SH7705_CACHE_32KB))
7575
struct page;
7676
extern void clear_user_page(void *to, unsigned long address, struct page *pg);
7777
extern void copy_user_page(void *to, void *from, unsigned long address, struct page *pg);
7878
extern void __clear_user_page(void *to, void *orig_to);
7979
extern void __copy_user_page(void *to, void *from, void *orig_to);
80-
#elif defined(CONFIG_CPU_SH2) || defined(CONFIG_CPU_SH3) || !defined(CONFIG_MMU)
80+
#else
8181
#define clear_user_page(page, vaddr, pg) clear_page(page)
8282
#define copy_user_page(to, from, vaddr, pg) copy_page(to, from)
8383
#endif

‎include/asm-sh/pgtable.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,8 @@ struct mm_struct;
563563
extern unsigned int kobjsize(const void *objp);
564564
#endif /* !CONFIG_MMU */
565565

566-
#if defined(CONFIG_CPU_SH4) || defined(CONFIG_SH7705_CACHE_32KB)
566+
#if !defined(CONFIG_CACHE_OFF) && (defined(CONFIG_CPU_SH4) || \
567+
defined(CONFIG_SH7705_CACHE_32KB))
567568
#define __HAVE_ARCH_PTEP_GET_AND_CLEAR
568569
extern pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
569570
#endif

0 commit comments

Comments
 (0)