Skip to content

Commit 37443ef

Browse files
committed
sh: Migrate SH-4 cacheflush ops to function pointers.
This paves the way for allowing individual CPUs to overload the individual flushing routines that they care about without having to depend on weak aliases. SH-4 is converted over initially, as it wires up pretty much everything. The majority of the other CPUs will simply use the default no-op implementation with their own region flushers wired up. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent 916e978 commit 37443ef

9 files changed

Lines changed: 159 additions & 135 deletions

File tree

‎arch/sh/include/asm/cacheflush.h‎

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,11 @@
11
#ifndef __ASM_SH_CACHEFLUSH_H
22
#define __ASM_SH_CACHEFLUSH_H
33

4-
#include <linux/mm.h>
5-
64
#ifdef __KERNEL__
75

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

30-
/*
31-
* Consistent DMA requires that the __flush_xxx() primitives must be set
32-
* for any of the enabled non-coherent caches (most of the UP CPUs),
33-
* regardless of PIPT or VIPT cache configurations.
34-
*/
35-
36-
/* Flush (write-back only) a region (smaller than a page) */
37-
extern void __flush_wback_region(void *start, int size);
38-
/* Flush (write-back & invalidate) a region (smaller than a page) */
39-
extern void __flush_purge_region(void *start, int size);
40-
/* Flush (invalidate only) a region (smaller than a page) */
41-
extern void __flush_invalidate_region(void *start, int size);
42-
#endif
43-
449
#define ARCH_HAS_FLUSH_ANON_PAGE
4510
extern void __flush_anon_page(struct page *page, unsigned long);
4611

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
/*
2-
* include/asm-sh/cpu-sh2/cacheflush.h
3-
*
42
* Copyright (C) 2003 Paul Mundt
53
*
64
* This file is subject to the terms and conditions of the GNU General Public
75
* License. See the file "COPYING" in the main directory of this archive
86
* for more details.
97
*/
10-
#ifndef __ASM_CPU_SH2_CACHEFLUSH_H
11-
#define __ASM_CPU_SH2_CACHEFLUSH_H
8+
#ifndef __ASM_CPU_SH_CACHEFLUSH_H
9+
#define __ASM_CPU_SH_CACHEFLUSH_H
1210

1311
/*
1412
* Cache flushing:
@@ -22,18 +20,23 @@
2220
* - flush_dcache_page(pg) flushes(wback&invalidates) a page for dcache
2321
* - flush_icache_range(start, end) flushes(invalidates) a range for icache
2422
* - flush_icache_page(vma, pg) flushes(invalidates) a page for icache
25-
*
26-
* Caches are indexed (effectively) by physical address on SH-2, so
27-
* we don't need them.
23+
* - flush_cache_sigtramp(vaddr) flushes the signal trampoline
2824
*/
29-
#define flush_cache_all() do { } while (0)
30-
#define flush_cache_mm(mm) do { } while (0)
31-
#define flush_cache_dup_mm(mm) do { } while (0)
32-
#define flush_cache_range(vma, start, end) do { } while (0)
33-
#define flush_cache_page(vma, vmaddr, pfn) do { } while (0)
34-
#define flush_dcache_page(page) do { } while (0)
35-
#define flush_icache_range(start, end) do { } while (0)
36-
#define flush_icache_page(vma,pg) do { } while (0)
37-
#define flush_cache_sigtramp(vaddr) do { } while (0)
25+
extern void (*flush_cache_all)(void);
26+
extern void (*flush_cache_mm)(struct mm_struct *mm);
27+
extern void (*flush_cache_dup_mm)(struct mm_struct *mm);
28+
extern void (*flush_cache_page)(struct vm_area_struct *vma,
29+
unsigned long addr, unsigned long pfn);
30+
extern void (*flush_cache_range)(struct vm_area_struct *vma,
31+
unsigned long start, unsigned long end);
32+
extern void (*flush_dcache_page)(struct page *page);
33+
extern void (*flush_icache_range)(unsigned long start, unsigned long end);
34+
extern void (*flush_icache_page)(struct vm_area_struct *vma,
35+
struct page *page);
36+
extern void (*flush_cache_sigtramp)(unsigned long address);
37+
38+
extern void (*__flush_wback_region)(void *start, int size);
39+
extern void (*__flush_purge_region)(void *start, int size);
40+
extern void (*__flush_invalidate_region)(void *start, int size);
3841

39-
#endif /* __ASM_CPU_SH2_CACHEFLUSH_H */
42+
#endif /* __ASM_CPU_SH_CACHEFLUSH_H */

‎arch/sh/include/cpu-sh4/cpu/cacheflush.h‎

Lines changed: 0 additions & 31 deletions
This file was deleted.

‎arch/sh/include/cpu-sh5/cpu/cacheflush.h‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33

44
#ifndef __ASSEMBLY__
55

6-
struct vm_area_struct;
7-
struct page;
8-
struct mm_struct;
9-
106
extern void flush_cache_all(void);
117
extern void flush_cache_mm(struct mm_struct *mm);
128
extern void flush_cache_sigtramp(unsigned long vaddr);
@@ -16,10 +12,14 @@ extern void flush_cache_page(struct vm_area_struct *vma, unsigned long addr, uns
1612
extern void flush_dcache_page(struct page *pg);
1713
extern void flush_icache_range(unsigned long start, unsigned long end);
1814

15+
/* XXX .. */
16+
extern void (*__flush_wback_region)(void *start, int size);
17+
extern void (*__flush_purge_region)(void *start, int size);
18+
extern void (*__flush_invalidate_region)(void *start, int size);
19+
1920
#define flush_cache_dup_mm(mm) flush_cache_mm(mm)
2021
#define flush_icache_page(vma, page) do { } while (0)
2122

2223
#endif /* __ASSEMBLY__ */
2324

2425
#endif /* __ASM_SH_CPU_SH5_CACHEFLUSH_H */
25-

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

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@
2626
#define MAX_DCACHE_PAGES 64 /* XXX: Tune for ways */
2727
#define MAX_ICACHE_PAGES 32
2828

29-
static void __flush_dcache_segment_1way(unsigned long start,
30-
unsigned long extent);
31-
static void __flush_dcache_segment_2way(unsigned long start,
32-
unsigned long extent);
33-
static void __flush_dcache_segment_4way(unsigned long start,
34-
unsigned long extent);
35-
3629
static void __flush_cache_4096(unsigned long addr, unsigned long phys,
3730
unsigned long exec_offset);
3831

@@ -44,39 +37,13 @@ static void __flush_cache_4096(unsigned long addr, unsigned long phys,
4437
static void (*__flush_dcache_segment_fn)(unsigned long, unsigned long) =
4538
(void (*)(unsigned long, unsigned long))0xdeadbeef;
4639

47-
/*
48-
* SH-4 has virtually indexed and physically tagged cache.
49-
*/
50-
void __init sh4_cache_init(void)
51-
{
52-
printk("PVR=%08x CVR=%08x PRR=%08x\n",
53-
ctrl_inl(CCN_PVR),
54-
ctrl_inl(CCN_CVR),
55-
ctrl_inl(CCN_PRR));
56-
57-
switch (boot_cpu_data.dcache.ways) {
58-
case 1:
59-
__flush_dcache_segment_fn = __flush_dcache_segment_1way;
60-
break;
61-
case 2:
62-
__flush_dcache_segment_fn = __flush_dcache_segment_2way;
63-
break;
64-
case 4:
65-
__flush_dcache_segment_fn = __flush_dcache_segment_4way;
66-
break;
67-
default:
68-
panic("unknown number of cache ways\n");
69-
break;
70-
}
71-
}
72-
7340
/*
7441
* Write back the range of D-cache, and purge the I-cache.
7542
*
7643
* Called from kernel/module.c:sys_init_module and routine for a.out format,
7744
* signal handler code and kprobes code
7845
*/
79-
void flush_icache_range(unsigned long start, unsigned long end)
46+
static void sh4_flush_icache_range(unsigned long start, unsigned long end)
8047
{
8148
int icacheaddr;
8249
unsigned long flags, v;
@@ -137,7 +104,7 @@ static inline void flush_cache_4096(unsigned long start,
137104
* Write back & invalidate the D-cache of the page.
138105
* (To avoid "alias" issues)
139106
*/
140-
void flush_dcache_page(struct page *page)
107+
static void sh4_flush_dcache_page(struct page *page)
141108
{
142109
struct address_space *mapping = page_mapping(page);
143110

@@ -188,7 +155,7 @@ static inline void flush_dcache_all(void)
188155
wmb();
189156
}
190157

191-
void flush_cache_all(void)
158+
static void sh4_flush_cache_all(void)
192159
{
193160
flush_dcache_all();
194161
flush_icache_all();
@@ -280,7 +247,7 @@ static void __flush_cache_mm(struct mm_struct *mm, unsigned long start,
280247
*
281248
* Caller takes mm->mmap_sem.
282249
*/
283-
void flush_cache_mm(struct mm_struct *mm)
250+
static void sh4_flush_cache_mm(struct mm_struct *mm)
284251
{
285252
if (cpu_context(smp_processor_id(), mm) == NO_CONTEXT)
286253
return;
@@ -320,8 +287,8 @@ void flush_cache_mm(struct mm_struct *mm)
320287
* ADDR: Virtual Address (U0 address)
321288
* PFN: Physical page number
322289
*/
323-
void flush_cache_page(struct vm_area_struct *vma, unsigned long address,
324-
unsigned long pfn)
290+
static void sh4_flush_cache_page(struct vm_area_struct *vma,
291+
unsigned long address, unsigned long pfn)
325292
{
326293
unsigned long phys = pfn << PAGE_SHIFT;
327294
unsigned int alias_mask;
@@ -368,8 +335,8 @@ void flush_cache_page(struct vm_area_struct *vma, unsigned long address,
368335
* Flushing the cache lines for U0 only isn't enough.
369336
* We need to flush for P1 too, which may contain aliases.
370337
*/
371-
void flush_cache_range(struct vm_area_struct *vma, unsigned long start,
372-
unsigned long end)
338+
static void sh4_flush_cache_range(struct vm_area_struct *vma,
339+
unsigned long start, unsigned long end)
373340
{
374341
if (cpu_context(smp_processor_id(), vma->vm_mm) == NO_CONTEXT)
375342
return;
@@ -668,3 +635,41 @@ static void __flush_dcache_segment_4way(unsigned long start,
668635
a3 += linesz;
669636
} while (a0 < a0e);
670637
}
638+
639+
extern void __weak sh4__flush_region_init(void);
640+
641+
/*
642+
* SH-4 has virtually indexed and physically tagged cache.
643+
*/
644+
void __init sh4_cache_init(void)
645+
{
646+
printk("PVR=%08x CVR=%08x PRR=%08x\n",
647+
ctrl_inl(CCN_PVR),
648+
ctrl_inl(CCN_CVR),
649+
ctrl_inl(CCN_PRR));
650+
651+
switch (boot_cpu_data.dcache.ways) {
652+
case 1:
653+
__flush_dcache_segment_fn = __flush_dcache_segment_1way;
654+
break;
655+
case 2:
656+
__flush_dcache_segment_fn = __flush_dcache_segment_2way;
657+
break;
658+
case 4:
659+
__flush_dcache_segment_fn = __flush_dcache_segment_4way;
660+
break;
661+
default:
662+
panic("unknown number of cache ways\n");
663+
break;
664+
}
665+
666+
flush_icache_range = sh4_flush_icache_range;
667+
flush_dcache_page = sh4_flush_dcache_page;
668+
flush_cache_all = sh4_flush_cache_all;
669+
flush_cache_mm = sh4_flush_cache_mm;
670+
flush_cache_dup_mm = sh4_flush_cache_mm;
671+
flush_cache_page = sh4_flush_cache_page;
672+
flush_cache_range = sh4_flush_cache_range;
673+
674+
sh4__flush_region_init();
675+
}

‎arch/sh/mm/cache-sh5.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@
2020
#include <asm/uaccess.h>
2121
#include <asm/mmu_context.h>
2222

23+
extern void __weak sh4__flush_region_init(void);
24+
2325
/* Wired TLB entry for the D-cache */
2426
static unsigned long long dtlb_cache_slot;
2527

2628
void __init cpu_cache_init(void)
2729
{
2830
/* Reserve a slot for dcache colouring in the DTLB */
2931
dtlb_cache_slot = sh64_get_wired_dtlb_entry();
32+
33+
sh4__flush_region_init();
3034
}
3135

3236
void __init kmap_coherent_init(void)

0 commit comments

Comments
 (0)