Skip to content

Commit b2edcfc

Browse files
chenhuacairalfbaechle
authored andcommitted
MIPS: Loongson: Add Loongson-3A R2 basic support
Loongson-3 CPU family: Code-name Brand-name PRId Loongson-3A R1 Loongson-3A1000 0x6305 Loongson-3A R2 Loongson-3A2000 0x6308 Loongson-3B R1 Loongson-3B1000 0x6306 Loongson-3B R2 Loongson-3B1500 0x6307 Features of R2 revision of Loongson-3A: - Primary cache includes I-Cache, D-Cache and V-Cache (Victim Cache). - I-Cache, D-Cache and V-Cache are 16-way set-associative, linesize is 64 bytes. - 64 entries of VTLB (classic TLB), 1024 entries of FTLB (8-way set-associative). - Supports DSP/DSPv2 instructions, UserLocal register and Read-Inhibit/ Execute-Inhibit. [ralf@linux-mips.org: Resolved merge conflicts.] Signed-off-by: Huacai Chen <chenhc@lemote.com> Cc: Aurelien Jarno <aurelien@aurel32.net> Cc: Steven J . Hill <sjhill@realitydiluted.com> Cc: Fuxin Zhang <zhangfx@lemote.com> Cc: Zhangjin Wu <wuzhangjin@gmail.com> Cc: linux-mips@linux-mips.org Patchwork: https://patchwork.linux-mips.org/patch/12751/ Patchwork: https://patchwork.linux-mips.org/patch/13136/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
1 parent 2465351 commit b2edcfc

15 files changed

Lines changed: 201 additions & 32 deletions

File tree

‎arch/mips/Kconfig‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,7 @@ config CPU_LOONGSON3
13541354
select CPU_SUPPORTS_HUGEPAGES
13551355
select WEAK_ORDERING
13561356
select WEAK_REORDERING_BEYOND_LLSC
1357+
select MIPS_PGD_C0_CONTEXT
13571358
select ARCH_REQUIRE_GPIOLIB
13581359
help
13591360
The Loongson 3 processor implements the MIPS64R2 instruction
@@ -1823,6 +1824,7 @@ config CPU_BMIPS5000
18231824
config SYS_HAS_CPU_LOONGSON3
18241825
bool
18251826
select CPU_SUPPORTS_CPUFREQ
1827+
select CPU_HAS_RIXI
18261828

18271829
config SYS_HAS_CPU_LOONGSON2E
18281830
bool

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define Cache_I 0x00
2222
#define Cache_D 0x01
2323
#define Cache_T 0x02
24+
#define Cache_V 0x02 /* Loongson-3 */
2425
#define Cache_S 0x03
2526

2627
#define Index_Writeback_Inv 0x00
@@ -107,4 +108,9 @@
107108
*/
108109
#define Hit_Invalidate_I_Loongson2 (Cache_I | 0x00)
109110

111+
/*
112+
* Loongson3-specific cacheops
113+
*/
114+
#define Index_Writeback_Inv_V (Cache_V | Index_Writeback_Inv)
115+
110116
#endif /* __ASM_CACHEOPS_H */

‎arch/mips/include/asm/cpu-info.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct cpuinfo_mips {
6060
int tlbsizeftlbways;
6161
struct cache_desc icache; /* Primary I-cache */
6262
struct cache_desc dcache; /* Primary D or combined I/D cache */
63+
struct cache_desc vcache; /* Victim cache, between pcache and scache */
6364
struct cache_desc scache; /* Secondary cache */
6465
struct cache_desc tcache; /* Tertiary/split secondary cache */
6566
int srsets; /* Shadow register sets */

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#define PRID_COMP_LEXRA 0x0b0000
4343
#define PRID_COMP_NETLOGIC 0x0c0000
4444
#define PRID_COMP_CAVIUM 0x0d0000
45+
#define PRID_COMP_LOONGSON 0x140000
4546
#define PRID_COMP_INGENIC_D0 0xd00000 /* JZ4740, JZ4750 */
4647
#define PRID_COMP_INGENIC_D1 0xd10000 /* JZ4770, JZ4775 */
4748
#define PRID_COMP_INGENIC_E1 0xe10000 /* JZ4780 */
@@ -241,9 +242,10 @@
241242
#define PRID_REV_LOONGSON1B 0x0020
242243
#define PRID_REV_LOONGSON2E 0x0002
243244
#define PRID_REV_LOONGSON2F 0x0003
244-
#define PRID_REV_LOONGSON3A 0x0005
245+
#define PRID_REV_LOONGSON3A_R1 0x0005
245246
#define PRID_REV_LOONGSON3B_R1 0x0006
246247
#define PRID_REV_LOONGSON3B_R2 0x0007
248+
#define PRID_REV_LOONGSON3A_R2 0x0008
247249

248250
/*
249251
* Older processors used to encode processor version and revision in two

‎arch/mips/include/asm/mach-loongson64/cpu-feature-overrides.h‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616
#ifndef __ASM_MACH_LOONGSON64_CPU_FEATURE_OVERRIDES_H
1717
#define __ASM_MACH_LOONGSON64_CPU_FEATURE_OVERRIDES_H
1818

19-
#define cpu_dcache_line_size() 32
20-
#define cpu_icache_line_size() 32
21-
#define cpu_scache_line_size() 32
22-
23-
2419
#define cpu_has_32fpr 1
2520
#define cpu_has_3k_cache 0
2621
#define cpu_has_4k_cache 1
@@ -31,31 +26,28 @@
3126
#define cpu_has_counter 1
3227
#define cpu_has_dc_aliases (PAGE_SIZE < 0x4000)
3328
#define cpu_has_divec 0
34-
#define cpu_has_dsp 0
35-
#define cpu_has_dsp2 0
3629
#define cpu_has_ejtag 0
37-
#define cpu_has_ic_fills_f_dc 0
3830
#define cpu_has_inclusive_pcaches 1
3931
#define cpu_has_llsc 1
4032
#define cpu_has_mcheck 0
4133
#define cpu_has_mdmx 0
4234
#define cpu_has_mips16 0
43-
#define cpu_has_mips32r2 0
4435
#define cpu_has_mips3d 0
45-
#define cpu_has_mips64r2 0
4636
#define cpu_has_mipsmt 0
47-
#define cpu_has_prefetch 0
4837
#define cpu_has_smartmips 0
4938
#define cpu_has_tlb 1
5039
#define cpu_has_tx39_cache 0
51-
#define cpu_has_userlocal 0
5240
#define cpu_has_vce 0
5341
#define cpu_has_veic 0
5442
#define cpu_has_vint 0
5543
#define cpu_has_vtag_icache 0
5644
#define cpu_has_watch 1
5745
#define cpu_has_local_ebase 0
5846

59-
#define cpu_has_wsbh IS_ENABLED(CONFIG_CPU_LOONGSON3)
47+
#ifdef CONFIG_CPU_LOONGSON3
48+
#define cpu_has_wsbh 1
49+
#define cpu_has_ic_fills_f_dc 1
50+
#define cpu_hwrena_impl_bits 0xc0000000
51+
#endif
6052

6153
#endif /* __ASM_MACH_LOONGSON64_CPU_FEATURE_OVERRIDES_H */

‎arch/mips/include/asm/mach-loongson64/kernel-entry-init.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
or t0, (0x1 << 7)
2424
mtc0 t0, $16, 3
2525
/* Set ELPA on LOONGSON3 pagegrain */
26-
li t0, (0x1 << 29)
26+
mfc0 t0, $5, 1
27+
or t0, (0x1 << 29)
2728
mtc0 t0, $5, 1
2829
_ehb
2930
.set pop
@@ -42,7 +43,8 @@
4243
or t0, (0x1 << 7)
4344
mtc0 t0, $16, 3
4445
/* Set ELPA on LOONGSON3 pagegrain */
45-
li t0, (0x1 << 29)
46+
mfc0 t0, $5, 1
47+
or t0, (0x1 << 29)
4648
mtc0 t0, $5, 1
4749
_ehb
4850
.set pop

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,8 @@
636636
#define MIPS_CONF6_SYND (_ULCAST_(1) << 13)
637637
/* proAptiv FTLB on/off bit */
638638
#define MIPS_CONF6_FTLBEN (_ULCAST_(1) << 15)
639+
/* Loongson-3 FTLB on/off bit */
640+
#define MIPS_CONF6_FTLBDIS (_ULCAST_(1) << 22)
639641
/* FTLB probability bits */
640642
#define MIPS_CONF6_FTLBP_SHIFT (16)
641643

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ static inline pte_t pte_mkdirty(pte_t pte)
384384
static inline pte_t pte_mkyoung(pte_t pte)
385385
{
386386
pte_val(pte) |= _PAGE_ACCESSED;
387-
#if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR6)
387+
#if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR6) || defined(CONFIG_CPU_LOONGSON3)
388388
if (!(pte_val(pte) & _PAGE_NO_READ))
389389
pte_val(pte) |= _PAGE_SILENT_READ;
390390
else
@@ -570,7 +570,7 @@ static inline pmd_t pmd_mkyoung(pmd_t pmd)
570570
{
571571
pmd_val(pmd) |= _PAGE_ACCESSED;
572572

573-
#if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR6)
573+
#if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR6) || defined(CONFIG_CPU_LOONGSON3)
574574
if (!(pmd_val(pmd) & _PAGE_NO_READ))
575575
pmd_val(pmd) |= _PAGE_SILENT_READ;
576576
else

‎arch/mips/kernel/cpu-probe.c‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,16 @@ static int set_ftlb_enable(struct cpuinfo_mips *c, int enable)
562562
write_c0_config7(config | (calculate_ftlb_probability(c)
563563
<< MIPS_CONF7_FTLBP_SHIFT));
564564
break;
565+
case CPU_LOONGSON3:
566+
/* Loongson-3 cores use Config6 to enable the FTLB */
567+
config = read_c0_config6();
568+
if (enable)
569+
/* Enable FTLB */
570+
write_c0_config6(config & ~MIPS_CONF6_FTLBDIS);
571+
else
572+
/* Disable FTLB */
573+
write_c0_config6(config | MIPS_CONF6_FTLBDIS);
574+
break;
565575
default:
566576
return 1;
567577
}
@@ -1178,7 +1188,7 @@ static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu)
11781188
set_isa(c, MIPS_CPU_ISA_III);
11791189
c->fpu_msk31 |= FPU_CSR_CONDX;
11801190
break;
1181-
case PRID_REV_LOONGSON3A:
1191+
case PRID_REV_LOONGSON3A_R1:
11821192
c->cputype = CPU_LOONGSON3;
11831193
__cpu_name[cpu] = "ICT Loongson-3";
11841194
set_elf_platform(cpu, "loongson3a");
@@ -1512,6 +1522,29 @@ static inline void cpu_probe_cavium(struct cpuinfo_mips *c, unsigned int cpu)
15121522
}
15131523
}
15141524

1525+
static inline void cpu_probe_loongson(struct cpuinfo_mips *c, unsigned int cpu)
1526+
{
1527+
switch (c->processor_id & PRID_IMP_MASK) {
1528+
case PRID_IMP_LOONGSON_64: /* Loongson-2/3 */
1529+
switch (c->processor_id & PRID_REV_MASK) {
1530+
case PRID_REV_LOONGSON3A_R2:
1531+
c->cputype = CPU_LOONGSON3;
1532+
__cpu_name[cpu] = "ICT Loongson-3";
1533+
set_elf_platform(cpu, "loongson3a");
1534+
set_isa(c, MIPS_CPU_ISA_M64R2);
1535+
break;
1536+
}
1537+
1538+
decode_configs(c);
1539+
c->options |= MIPS_CPU_TLBINV;
1540+
c->writecombine = _CACHE_UNCACHED_ACCELERATED;
1541+
break;
1542+
default:
1543+
panic("Unknown Loongson Processor ID!");
1544+
break;
1545+
}
1546+
}
1547+
15151548
static inline void cpu_probe_ingenic(struct cpuinfo_mips *c, unsigned int cpu)
15161549
{
15171550
decode_configs(c);
@@ -1659,6 +1692,9 @@ void cpu_probe(void)
16591692
case PRID_COMP_CAVIUM:
16601693
cpu_probe_cavium(c, cpu);
16611694
break;
1695+
case PRID_COMP_LOONGSON:
1696+
cpu_probe_loongson(c, cpu);
1697+
break;
16621698
case PRID_COMP_INGENIC_D0:
16631699
case PRID_COMP_INGENIC_D1:
16641700
case PRID_COMP_INGENIC_E1:

‎arch/mips/kernel/idle.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ void __init check_wait(void)
181181
case CPU_XLP:
182182
cpu_wait = r4k_wait;
183183
break;
184+
case CPU_LOONGSON3:
185+
if ((c->processor_id & PRID_REV_MASK) >= PRID_REV_LOONGSON3A_R2)
186+
cpu_wait = r4k_wait;
187+
break;
188+
184189
case CPU_BMIPS5000:
185190
cpu_wait = r4k_wait_irqoff;
186191
break;

0 commit comments

Comments
 (0)