Skip to content

Commit 14bd8c0

Browse files
committed
MIPS: Loongson: Get rid of Loongson 2 #ifdefery all over arch/mips.
It was ugly. Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
1 parent 7b784c6 commit 14bd8c0

5 files changed

Lines changed: 174 additions & 134 deletions

File tree

‎arch/mips/include/asm/cacheops.h‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@
2020
#define Index_Load_Tag_D 0x05
2121
#define Index_Store_Tag_I 0x08
2222
#define Index_Store_Tag_D 0x09
23-
#if defined(CONFIG_CPU_LOONGSON2)
24-
#define Hit_Invalidate_I 0x00
25-
#else
2623
#define Hit_Invalidate_I 0x10
27-
#endif
2824
#define Hit_Invalidate_D 0x11
2925
#define Hit_Writeback_Inv_D 0x15
3026

@@ -84,4 +80,9 @@
8480
#define Index_Store_Data_D 0x1d
8581
#define Index_Store_Data_S 0x1f
8682

83+
/*
84+
* Loongson2-specific cacheops
85+
*/
86+
#define Hit_Invalidate_I_Loongson23 0x00
87+
8788
#endif /* __ASM_CACHEOPS_H */

‎arch/mips/include/asm/r4kcache.h‎

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <asm/asm.h>
1616
#include <asm/cacheops.h>
1717
#include <asm/cpu-features.h>
18+
#include <asm/cpu-type.h>
1819
#include <asm/mipsmtregs.h>
1920

2021
/*
@@ -162,7 +163,15 @@ static inline void flush_scache_line_indexed(unsigned long addr)
162163
static inline void flush_icache_line(unsigned long addr)
163164
{
164165
__iflush_prologue
165-
cache_op(Hit_Invalidate_I, addr);
166+
switch (boot_cpu_type()) {
167+
case CPU_LOONGSON2:
168+
cache_op(Hit_Invalidate_I_Loongson23, addr);
169+
break;
170+
171+
default:
172+
cache_op(Hit_Invalidate_I, addr);
173+
break;
174+
}
166175
__iflush_epilogue
167176
}
168177

@@ -208,7 +217,15 @@ static inline void flush_scache_line(unsigned long addr)
208217
*/
209218
static inline void protected_flush_icache_line(unsigned long addr)
210219
{
211-
protected_cache_op(Hit_Invalidate_I, addr);
220+
switch (boot_cpu_type()) {
221+
case CPU_LOONGSON2:
222+
protected_cache_op(Hit_Invalidate_I_Loongson23, addr);
223+
break;
224+
225+
default:
226+
protected_cache_op(Hit_Invalidate_I, addr);
227+
break;
228+
}
212229
}
213230

214231
/*
@@ -412,8 +429,8 @@ __BUILD_BLAST_CACHE(inv_s, scache, Index_Writeback_Inv_SD, Hit_Invalidate_SD, 64
412429
__BUILD_BLAST_CACHE(inv_s, scache, Index_Writeback_Inv_SD, Hit_Invalidate_SD, 128)
413430

414431
/* build blast_xxx_range, protected_blast_xxx_range */
415-
#define __BUILD_BLAST_CACHE_RANGE(pfx, desc, hitop, prot) \
416-
static inline void prot##blast_##pfx##cache##_range(unsigned long start, \
432+
#define __BUILD_BLAST_CACHE_RANGE(pfx, desc, hitop, prot, extra) \
433+
static inline void prot##extra##blast_##pfx##cache##_range(unsigned long start, \
417434
unsigned long end) \
418435
{ \
419436
unsigned long lsize = cpu_##desc##_line_size(); \
@@ -432,13 +449,15 @@ static inline void prot##blast_##pfx##cache##_range(unsigned long start, \
432449
__##pfx##flush_epilogue \
433450
}
434451

435-
__BUILD_BLAST_CACHE_RANGE(d, dcache, Hit_Writeback_Inv_D, protected_)
436-
__BUILD_BLAST_CACHE_RANGE(s, scache, Hit_Writeback_Inv_SD, protected_)
437-
__BUILD_BLAST_CACHE_RANGE(i, icache, Hit_Invalidate_I, protected_)
438-
__BUILD_BLAST_CACHE_RANGE(d, dcache, Hit_Writeback_Inv_D, )
439-
__BUILD_BLAST_CACHE_RANGE(s, scache, Hit_Writeback_Inv_SD, )
452+
__BUILD_BLAST_CACHE_RANGE(d, dcache, Hit_Writeback_Inv_D, protected_, )
453+
__BUILD_BLAST_CACHE_RANGE(s, scache, Hit_Writeback_Inv_SD, protected_, )
454+
__BUILD_BLAST_CACHE_RANGE(i, icache, Hit_Invalidate_I, protected_, )
455+
__BUILD_BLAST_CACHE_RANGE(i, icache, Hit_Invalidate_I_Loongson23, \
456+
protected_, loongson23_)
457+
__BUILD_BLAST_CACHE_RANGE(d, dcache, Hit_Writeback_Inv_D, , )
458+
__BUILD_BLAST_CACHE_RANGE(s, scache, Hit_Writeback_Inv_SD, , )
440459
/* blast_inv_dcache_range */
441-
__BUILD_BLAST_CACHE_RANGE(inv_d, dcache, Hit_Invalidate_D, )
442-
__BUILD_BLAST_CACHE_RANGE(inv_s, scache, Hit_Invalidate_SD, )
460+
__BUILD_BLAST_CACHE_RANGE(inv_d, dcache, Hit_Invalidate_D, , )
461+
__BUILD_BLAST_CACHE_RANGE(inv_s, scache, Hit_Invalidate_SD, , )
443462

444463
#endif /* _ASM_R4KCACHE_H */

‎arch/mips/mm/c-r4k.c‎

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -346,22 +346,27 @@ static void r4k_blast_scache_setup(void)
346346

347347
static inline void local_r4k___flush_cache_all(void * args)
348348
{
349-
#if defined(CONFIG_CPU_LOONGSON2)
350-
r4k_blast_scache();
351-
return;
352-
#endif
353-
r4k_blast_dcache();
354-
r4k_blast_icache();
355-
356349
switch (current_cpu_type()) {
350+
case CPU_LOONGSON2:
357351
case CPU_R4000SC:
358352
case CPU_R4000MC:
359353
case CPU_R4400SC:
360354
case CPU_R4400MC:
361355
case CPU_R10000:
362356
case CPU_R12000:
363357
case CPU_R14000:
358+
/*
359+
* These caches are inclusive caches, that is, if something
360+
* is not cached in the S-cache, we know it also won't be
361+
* in one of the primary caches.
362+
*/
364363
r4k_blast_scache();
364+
break;
365+
366+
default:
367+
r4k_blast_dcache();
368+
r4k_blast_icache();
369+
break;
365370
}
366371
}
367372

@@ -572,8 +577,17 @@ static inline void local_r4k_flush_icache_range(unsigned long start, unsigned lo
572577

573578
if (end - start > icache_size)
574579
r4k_blast_icache();
575-
else
576-
protected_blast_icache_range(start, end);
580+
else {
581+
switch (boot_cpu_type()) {
582+
case CPU_LOONGSON2:
583+
protected_blast_icache_range(start, end);
584+
break;
585+
586+
default:
587+
protected_loongson23_blast_icache_range(start, end);
588+
break;
589+
}
590+
}
577591
}
578592

579593
static inline void local_r4k_flush_icache_range_ipi(void *args)
@@ -1109,15 +1123,14 @@ static void probe_pcache(void)
11091123
case CPU_ALCHEMY:
11101124
c->icache.flags |= MIPS_CACHE_IC_F_DC;
11111125
break;
1112-
}
11131126

1114-
#ifdef CONFIG_CPU_LOONGSON2
1115-
/*
1116-
* LOONGSON2 has 4 way icache, but when using indexed cache op,
1117-
* one op will act on all 4 ways
1118-
*/
1119-
c->icache.ways = 1;
1120-
#endif
1127+
case CPU_LOONGSON2:
1128+
/*
1129+
* LOONGSON2 has 4 way icache, but when using indexed cache op,
1130+
* one op will act on all 4 ways
1131+
*/
1132+
c->icache.ways = 1;
1133+
}
11211134

11221135
printk("Primary instruction cache %ldkB, %s, %s, linesize %d bytes.\n",
11231136
icache_size >> 10,
@@ -1193,7 +1206,6 @@ static int probe_scache(void)
11931206
return 1;
11941207
}
11951208

1196-
#if defined(CONFIG_CPU_LOONGSON2)
11971209
static void __init loongson2_sc_init(void)
11981210
{
11991211
struct cpuinfo_mips *c = &current_cpu_data;
@@ -1209,7 +1221,6 @@ static void __init loongson2_sc_init(void)
12091221

12101222
c->options |= MIPS_CPU_INCLUSIVE_CACHES;
12111223
}
1212-
#endif
12131224

12141225
extern int r5k_sc_init(void);
12151226
extern int rm7k_sc_init(void);
@@ -1259,11 +1270,10 @@ static void setup_scache(void)
12591270
#endif
12601271
return;
12611272

1262-
#if defined(CONFIG_CPU_LOONGSON2)
12631273
case CPU_LOONGSON2:
12641274
loongson2_sc_init();
12651275
return;
1266-
#endif
1276+
12671277
case CPU_XLP:
12681278
/* don't need to worry about L2, fully coherent */
12691279
return;

‎arch/mips/mm/tlb-r4k.c‎

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,26 @@ extern void build_tlb_refill_handler(void);
5252

5353
#endif /* CONFIG_MIPS_MT_SMTC */
5454

55-
#if defined(CONFIG_CPU_LOONGSON2)
5655
/*
5756
* LOONGSON2 has a 4 entry itlb which is a subset of dtlb,
5857
* unfortrunately, itlb is not totally transparent to software.
5958
*/
60-
#define FLUSH_ITLB write_c0_diag(4);
61-
62-
#define FLUSH_ITLB_VM(vma) { if ((vma)->vm_flags & VM_EXEC) write_c0_diag(4); }
63-
64-
#else
65-
66-
#define FLUSH_ITLB
67-
#define FLUSH_ITLB_VM(vma)
59+
static inline void flush_itlb(void)
60+
{
61+
switch (current_cpu_type()) {
62+
case CPU_LOONGSON2:
63+
write_c0_diag(4);
64+
break;
65+
default:
66+
break;
67+
}
68+
}
6869

69-
#endif
70+
static inline void flush_itlb_vm(struct vm_area_struct *vma)
71+
{
72+
if (vma->vm_flags & VM_EXEC)
73+
flush_itlb();
74+
}
7075

7176
void local_flush_tlb_all(void)
7277
{
@@ -93,7 +98,7 @@ void local_flush_tlb_all(void)
9398
}
9499
tlbw_use_hazard();
95100
write_c0_entryhi(old_ctx);
96-
FLUSH_ITLB;
101+
flush_itlb();
97102
EXIT_CRITICAL(flags);
98103
}
99104
EXPORT_SYMBOL(local_flush_tlb_all);
@@ -155,7 +160,7 @@ void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
155160
} else {
156161
drop_mmu_context(mm, cpu);
157162
}
158-
FLUSH_ITLB;
163+
flush_itlb();
159164
EXIT_CRITICAL(flags);
160165
}
161166
}
@@ -197,7 +202,7 @@ void local_flush_tlb_kernel_range(unsigned long start, unsigned long end)
197202
} else {
198203
local_flush_tlb_all();
199204
}
200-
FLUSH_ITLB;
205+
flush_itlb();
201206
EXIT_CRITICAL(flags);
202207
}
203208

@@ -230,7 +235,7 @@ void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
230235

231236
finish:
232237
write_c0_entryhi(oldpid);
233-
FLUSH_ITLB_VM(vma);
238+
flush_itlb_vm(vma);
234239
EXIT_CRITICAL(flags);
235240
}
236241
}
@@ -262,7 +267,7 @@ void local_flush_tlb_one(unsigned long page)
262267
tlbw_use_hazard();
263268
}
264269
write_c0_entryhi(oldpid);
265-
FLUSH_ITLB;
270+
flush_itlb();
266271
EXIT_CRITICAL(flags);
267272
}
268273

@@ -335,7 +340,7 @@ void __update_tlb(struct vm_area_struct * vma, unsigned long address, pte_t pte)
335340
tlb_write_indexed();
336341
}
337342
tlbw_use_hazard();
338-
FLUSH_ITLB_VM(vma);
343+
flush_itlb_vm(vma);
339344
EXIT_CRITICAL(flags);
340345
}
341346

0 commit comments

Comments
 (0)