Skip to content

Commit 7507445

Browse files
chenhuacaipaulburton
authored andcommitted
MIPS: Loongson: Add Loongson-3A R4 basic support
All Loongson-3 CPU family: Code-name Brand-name PRId Loongson-3A R1 Loongson-3A1000 0x6305 Loongson-3A R2 Loongson-3A2000 0x6308 Loongson-3A R2.1 Loongson-3A2000 0x630c Loongson-3A R3 Loongson-3A3000 0x6309 Loongson-3A R3.1 Loongson-3A3000 0x630d Loongson-3A R4 Loongson-3A4000 0xc000 Loongson-3B R1 Loongson-3B1000 0x6306 Loongson-3B R2 Loongson-3B1500 0x6307 Features of R4 revision of Loongson-3A: - All R2/R3 features, including SFB, V-Cache, FTLB, RIXI, DSP, etc. - Support variable ASID bits. - Support MSA and VZ extensions. - Support CPUCFG (CPU config) and CSR (Control and Status Register) extensions. - 64 entries of VTLB (classic TLB), 2048 entries of FTLB (8-way set-associative). Now 64-bit Loongson processors has three types of PRID.IMP: 0x6300 is the classic one so we call it PRID_IMP_LOONGSON_64C (e.g., Loongson-2E/ 2F/3A1000/3B1000/3B1500/3A2000/3A3000), 0x6100 is for some processors which has reduced capabilities so we call it PRID_IMP_LOONGSON_64R (e.g., Loongson-2K), 0xc000 is supposed to cover all new processors in general (e.g., Loongson-3A4000+) so we call it PRID_IMP_LOONGSON_64G. Signed-off-by: Huacai Chen <chenhc@lemote.com> Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com> Signed-off-by: Paul Burton <paul.burton@mips.com> Cc: Ralf Baechle <ralf@linux-mips.org> Cc: James Hogan <jhogan@kernel.org> Cc: linux-mips@linux-mips.org Cc: linux-mips@vger.kernel.org Cc: Fuxin Zhang <zhangfx@lemote.com> Cc: Zhangjin Wu <wuzhangjin@gmail.com> Cc: Huacai Chen <chenhuacai@gmail.com>
1 parent 6a6f9b7 commit 7507445

8 files changed

Lines changed: 111 additions & 50 deletions

File tree

‎arch/mips/Kconfig‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,9 +1387,11 @@ config CPU_LOONGSON3
13871387
select CPU_SUPPORTS_64BIT_KERNEL
13881388
select CPU_SUPPORTS_HIGHMEM
13891389
select CPU_SUPPORTS_HUGEPAGES
1390+
select CPU_SUPPORTS_MSA
13901391
select CPU_HAS_LOAD_STORE_LR
13911392
select WEAK_ORDERING
13921393
select WEAK_REORDERING_BEYOND_LLSC
1394+
select MIPS_ASID_BITS_VARIABLE
13931395
select MIPS_PGD_C0_CONTEXT
13941396
select MIPS_L1_CACHE_SHIFT_6
13951397
select GPIOLIB

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@
9191
#define PRID_IMP_LOONGSON_32 0x4200 /* Loongson-1 */
9292
#define PRID_IMP_R5432 0x5400
9393
#define PRID_IMP_R5500 0x5500
94-
#define PRID_IMP_LOONGSON_64 0x6300 /* Loongson-2/3 */
94+
#define PRID_IMP_LOONGSON_64R 0x6100 /* Reduced Loongson-2 */
95+
#define PRID_IMP_LOONGSON_64C 0x6300 /* Classic Loongson-2 and Loongson-3 */
96+
#define PRID_IMP_LOONGSON_64G 0xc000 /* Generic Loongson-2 and Loongson-3 */
9597

9698
#define PRID_IMP_UNKNOWN 0xff00
9799

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,21 @@
3030
mtc0 t0, CP0_PAGEGRAIN
3131
/* Enable STFill Buffer */
3232
mfc0 t0, CP0_PRID
33+
/* Loongson-3A R4+ */
34+
andi t1, t0, PRID_IMP_MASK
35+
li t2, PRID_IMP_LOONGSON_64G
36+
beq t1, t2, 1f
37+
nop
38+
/* Loongson-3A R2/R3 */
3339
andi t0, (PRID_IMP_MASK | PRID_REV_MASK)
34-
slti t0, (PRID_IMP_LOONGSON_64 | PRID_REV_LOONGSON3A_R2_0)
35-
bnez t0, 1f
40+
slti t0, (PRID_IMP_LOONGSON_64C | PRID_REV_LOONGSON3A_R2_0)
41+
bnez t0, 2f
42+
nop
43+
1:
3644
mfc0 t0, CP0_CONFIG6
3745
or t0, 0x100
3846
mtc0 t0, CP0_CONFIG6
39-
1:
47+
2:
4048
_ehb
4149
.set pop
4250
#endif
@@ -59,13 +67,21 @@
5967
mtc0 t0, CP0_PAGEGRAIN
6068
/* Enable STFill Buffer */
6169
mfc0 t0, CP0_PRID
70+
/* Loongson-3A R4+ */
71+
andi t1, t0, PRID_IMP_MASK
72+
li t2, PRID_IMP_LOONGSON_64G
73+
beq t1, t2, 1f
74+
nop
75+
/* Loongson-3A R2/R3 */
6276
andi t0, (PRID_IMP_MASK | PRID_REV_MASK)
63-
slti t0, (PRID_IMP_LOONGSON_64 | PRID_REV_LOONGSON3A_R2_0)
64-
bnez t0, 1f
77+
slti t0, (PRID_IMP_LOONGSON_64C | PRID_REV_LOONGSON3A_R2_0)
78+
bnez t0, 2f
79+
nop
80+
1:
6581
mfc0 t0, CP0_CONFIG6
6682
or t0, 0x100
6783
mtc0 t0, CP0_CONFIG6
68-
1:
84+
2:
6985
_ehb
7086
.set pop
7187
#endif

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,7 @@ static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu)
15261526
MIPS_CPU_LLSC | MIPS_CPU_BP_GHIST;
15271527
c->tlbsize = 64;
15281528
break;
1529-
case PRID_IMP_LOONGSON_64: /* Loongson-2/3 */
1529+
case PRID_IMP_LOONGSON_64C: /* Loongson-2/3 */
15301530
switch (c->processor_id & PRID_REV_MASK) {
15311531
case PRID_REV_LOONGSON2E:
15321532
c->cputype = CPU_LOONGSON2;
@@ -1565,6 +1565,7 @@ static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu)
15651565
MIPS_CPU_FPU | MIPS_CPU_LLSC |
15661566
MIPS_CPU_32FPR;
15671567
c->tlbsize = 64;
1568+
set_cpu_asid_mask(c, MIPS_ENTRYHI_ASID);
15681569
c->writecombine = _CACHE_UNCACHED_ACCELERATED;
15691570
break;
15701571
case PRID_IMP_LOONGSON_32: /* Loongson-1 */
@@ -1903,7 +1904,7 @@ static inline void cpu_probe_cavium(struct cpuinfo_mips *c, unsigned int cpu)
19031904
static inline void cpu_probe_loongson(struct cpuinfo_mips *c, unsigned int cpu)
19041905
{
19051906
switch (c->processor_id & PRID_IMP_MASK) {
1906-
case PRID_IMP_LOONGSON_64: /* Loongson-2/3 */
1907+
case PRID_IMP_LOONGSON_64C: /* Loongson-2/3 */
19071908
switch (c->processor_id & PRID_REV_MASK) {
19081909
case PRID_REV_LOONGSON3A_R2_0:
19091910
case PRID_REV_LOONGSON3A_R2_1:
@@ -1921,6 +1922,17 @@ static inline void cpu_probe_loongson(struct cpuinfo_mips *c, unsigned int cpu)
19211922
break;
19221923
}
19231924

1925+
decode_configs(c);
1926+
c->options |= MIPS_CPU_FTLB | MIPS_CPU_TLBINV | MIPS_CPU_LDPTE;
1927+
c->writecombine = _CACHE_UNCACHED_ACCELERATED;
1928+
c->ases |= (MIPS_ASE_LOONGSON_MMI | MIPS_ASE_LOONGSON_CAM |
1929+
MIPS_ASE_LOONGSON_EXT | MIPS_ASE_LOONGSON_EXT2);
1930+
break;
1931+
case PRID_IMP_LOONGSON_64G:
1932+
c->cputype = CPU_LOONGSON3;
1933+
__cpu_name[cpu] = "ICT Loongson-3";
1934+
set_elf_platform(cpu, "loongson3a");
1935+
set_isa(c, MIPS_CPU_ISA_M64R2);
19241936
decode_configs(c);
19251937
c->options |= MIPS_CPU_FTLB | MIPS_CPU_TLBINV | MIPS_CPU_LDPTE;
19261938
c->writecombine = _CACHE_UNCACHED_ACCELERATED;

‎arch/mips/kernel/idle.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ void __init check_wait(void)
179179
cpu_wait = r4k_wait;
180180
break;
181181
case CPU_LOONGSON3:
182-
if ((c->processor_id & PRID_REV_MASK) >= PRID_REV_LOONGSON3A_R2_0)
182+
if ((c->processor_id & (PRID_IMP_MASK | PRID_REV_MASK)) >=
183+
(PRID_IMP_LOONGSON_64C | PRID_REV_LOONGSON3A_R2_0))
183184
cpu_wait = r4k_wait;
184185
break;
185186

‎arch/mips/loongson64/loongson-3/smp.c‎

Lines changed: 51 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ static void loongson3_cpu_die(unsigned int cpu)
450450
* flush all L1 entries at first. Then, another core (usually Core 0) can
451451
* safely disable the clock of the target core. loongson3_play_dead() is
452452
* called via CKSEG1 (uncached and unmmaped) */
453-
static void loongson3a_r1_play_dead(int *state_addr)
453+
static void loongson3_type1_play_dead(int *state_addr)
454454
{
455455
register int val;
456456
register long cpuid, core, node, count;
@@ -512,7 +512,7 @@ static void loongson3a_r1_play_dead(int *state_addr)
512512
: "a1");
513513
}
514514

515-
static void loongson3a_r2r3_play_dead(int *state_addr)
515+
static void loongson3_type2_play_dead(int *state_addr)
516516
{
517517
register int val;
518518
register long cpuid, core, node, count;
@@ -532,36 +532,15 @@ static void loongson3a_r2r3_play_dead(int *state_addr)
532532
" cache 1, 3(%[addr]) \n"
533533
" addiu %[sets], %[sets], -1 \n"
534534
" bnez %[sets], 1b \n"
535-
" addiu %[addr], %[addr], 0x40 \n"
536-
" li %[addr], 0x80000000 \n" /* KSEG0 */
537-
"2: cache 2, 0(%[addr]) \n" /* flush L1 VCache */
538-
" cache 2, 1(%[addr]) \n"
539-
" cache 2, 2(%[addr]) \n"
540-
" cache 2, 3(%[addr]) \n"
541-
" cache 2, 4(%[addr]) \n"
542-
" cache 2, 5(%[addr]) \n"
543-
" cache 2, 6(%[addr]) \n"
544-
" cache 2, 7(%[addr]) \n"
545-
" cache 2, 8(%[addr]) \n"
546-
" cache 2, 9(%[addr]) \n"
547-
" cache 2, 10(%[addr]) \n"
548-
" cache 2, 11(%[addr]) \n"
549-
" cache 2, 12(%[addr]) \n"
550-
" cache 2, 13(%[addr]) \n"
551-
" cache 2, 14(%[addr]) \n"
552-
" cache 2, 15(%[addr]) \n"
553-
" addiu %[vsets], %[vsets], -1 \n"
554-
" bnez %[vsets], 2b \n"
555-
" addiu %[addr], %[addr], 0x40 \n"
535+
" addiu %[addr], %[addr], 0x20 \n"
556536
" li %[val], 0x7 \n" /* *state_addr = CPU_DEAD; */
557537
" sw %[val], (%[state_addr]) \n"
558538
" sync \n"
559539
" cache 21, (%[state_addr]) \n" /* flush entry of *state_addr */
560540
" .set pop \n"
561541
: [addr] "=&r" (addr), [val] "=&r" (val)
562542
: [state_addr] "r" (state_addr),
563-
[sets] "r" (cpu_data[smp_processor_id()].dcache.sets),
564-
[vsets] "r" (cpu_data[smp_processor_id()].vcache.sets));
543+
[sets] "r" (cpu_data[smp_processor_id()].dcache.sets));
565544

566545
__asm__ __volatile__(
567546
" .set push \n"
@@ -576,6 +555,8 @@ static void loongson3a_r2r3_play_dead(int *state_addr)
576555
" andi %[node], %[cpuid], 0xc \n"
577556
" dsll %[node], 42 \n" /* get node id */
578557
" or %[base], %[base], %[node] \n"
558+
" dsrl %[node], 30 \n" /* 15:14 */
559+
" or %[base], %[base], %[node] \n"
579560
"1: li %[count], 0x100 \n" /* wait for init loop */
580561
"2: bnez %[count], 2b \n" /* limit mailbox access */
581562
" addiu %[count], -1 \n"
@@ -595,7 +576,7 @@ static void loongson3a_r2r3_play_dead(int *state_addr)
595576
: "a1");
596577
}
597578

598-
static void loongson3b_play_dead(int *state_addr)
579+
static void loongson3_type3_play_dead(int *state_addr)
599580
{
600581
register int val;
601582
register long cpuid, core, node, count;
@@ -615,15 +596,36 @@ static void loongson3b_play_dead(int *state_addr)
615596
" cache 1, 3(%[addr]) \n"
616597
" addiu %[sets], %[sets], -1 \n"
617598
" bnez %[sets], 1b \n"
618-
" addiu %[addr], %[addr], 0x20 \n"
599+
" addiu %[addr], %[addr], 0x40 \n"
600+
" li %[addr], 0x80000000 \n" /* KSEG0 */
601+
"2: cache 2, 0(%[addr]) \n" /* flush L1 VCache */
602+
" cache 2, 1(%[addr]) \n"
603+
" cache 2, 2(%[addr]) \n"
604+
" cache 2, 3(%[addr]) \n"
605+
" cache 2, 4(%[addr]) \n"
606+
" cache 2, 5(%[addr]) \n"
607+
" cache 2, 6(%[addr]) \n"
608+
" cache 2, 7(%[addr]) \n"
609+
" cache 2, 8(%[addr]) \n"
610+
" cache 2, 9(%[addr]) \n"
611+
" cache 2, 10(%[addr]) \n"
612+
" cache 2, 11(%[addr]) \n"
613+
" cache 2, 12(%[addr]) \n"
614+
" cache 2, 13(%[addr]) \n"
615+
" cache 2, 14(%[addr]) \n"
616+
" cache 2, 15(%[addr]) \n"
617+
" addiu %[vsets], %[vsets], -1 \n"
618+
" bnez %[vsets], 2b \n"
619+
" addiu %[addr], %[addr], 0x40 \n"
619620
" li %[val], 0x7 \n" /* *state_addr = CPU_DEAD; */
620621
" sw %[val], (%[state_addr]) \n"
621622
" sync \n"
622623
" cache 21, (%[state_addr]) \n" /* flush entry of *state_addr */
623624
" .set pop \n"
624625
: [addr] "=&r" (addr), [val] "=&r" (val)
625626
: [state_addr] "r" (state_addr),
626-
[sets] "r" (cpu_data[smp_processor_id()].dcache.sets));
627+
[sets] "r" (cpu_data[smp_processor_id()].dcache.sets),
628+
[vsets] "r" (cpu_data[smp_processor_id()].vcache.sets));
627629

628630
__asm__ __volatile__(
629631
" .set push \n"
@@ -638,8 +640,6 @@ static void loongson3b_play_dead(int *state_addr)
638640
" andi %[node], %[cpuid], 0xc \n"
639641
" dsll %[node], 42 \n" /* get node id */
640642
" or %[base], %[base], %[node] \n"
641-
" dsrl %[node], 30 \n" /* 15:14 */
642-
" or %[base], %[base], %[node] \n"
643643
"1: li %[count], 0x100 \n" /* wait for init loop */
644644
"2: bnez %[count], 2b \n" /* limit mailbox access */
645645
" addiu %[count], -1 \n"
@@ -661,30 +661,42 @@ static void loongson3b_play_dead(int *state_addr)
661661

662662
void play_dead(void)
663663
{
664-
int *state_addr;
664+
int prid_imp, prid_rev, *state_addr;
665665
unsigned int cpu = smp_processor_id();
666666
void (*play_dead_at_ckseg1)(int *);
667667

668668
idle_task_exit();
669-
switch (read_c0_prid() & PRID_REV_MASK) {
669+
670+
prid_imp = read_c0_prid() & PRID_IMP_MASK;
671+
prid_rev = read_c0_prid() & PRID_REV_MASK;
672+
673+
if (prid_imp == PRID_IMP_LOONGSON_64G) {
674+
play_dead_at_ckseg1 =
675+
(void *)CKSEG1ADDR((unsigned long)loongson3_type3_play_dead);
676+
goto out;
677+
}
678+
679+
switch (prid_rev) {
670680
case PRID_REV_LOONGSON3A_R1:
671681
default:
672682
play_dead_at_ckseg1 =
673-
(void *)CKSEG1ADDR((unsigned long)loongson3a_r1_play_dead);
683+
(void *)CKSEG1ADDR((unsigned long)loongson3_type1_play_dead);
684+
break;
685+
case PRID_REV_LOONGSON3B_R1:
686+
case PRID_REV_LOONGSON3B_R2:
687+
play_dead_at_ckseg1 =
688+
(void *)CKSEG1ADDR((unsigned long)loongson3_type2_play_dead);
674689
break;
675690
case PRID_REV_LOONGSON3A_R2_0:
676691
case PRID_REV_LOONGSON3A_R2_1:
677692
case PRID_REV_LOONGSON3A_R3_0:
678693
case PRID_REV_LOONGSON3A_R3_1:
679694
play_dead_at_ckseg1 =
680-
(void *)CKSEG1ADDR((unsigned long)loongson3a_r2r3_play_dead);
681-
break;
682-
case PRID_REV_LOONGSON3B_R1:
683-
case PRID_REV_LOONGSON3B_R2:
684-
play_dead_at_ckseg1 =
685-
(void *)CKSEG1ADDR((unsigned long)loongson3b_play_dead);
695+
(void *)CKSEG1ADDR((unsigned long)loongson3_type3_play_dead);
686696
break;
687697
}
698+
699+
out:
688700
state_addr = &per_cpu(cpu_state, cpu);
689701
mb();
690702
play_dead_at_ckseg1(state_addr);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,8 @@ static void probe_pcache(void)
12671267
c->dcache.ways *
12681268
c->dcache.linesz;
12691269
c->dcache.waybit = 0;
1270-
if ((prid & PRID_REV_MASK) >= PRID_REV_LOONGSON3A_R2_0)
1270+
if ((c->processor_id & (PRID_IMP_MASK | PRID_REV_MASK)) >=
1271+
(PRID_IMP_LOONGSON_64C | PRID_REV_LOONGSON3A_R2_0))
12711272
c->options |= MIPS_CPU_PREFETCH;
12721273
break;
12731274

‎drivers/platform/mips/cpu_hwmon.c‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include <loongson.h>
1010
#include <boot_param.h>
1111
#include <loongson_hwmon.h>
12+
#include <loongson_regs.h>
13+
14+
static int csr_temp_enable = 0;
1215

1316
/*
1417
* Loongson-3 series cpu has two sensors inside,
@@ -20,8 +23,14 @@ int loongson3_cpu_temp(int cpu)
2023
{
2124
u32 reg, prid_rev;
2225

26+
if (csr_temp_enable) {
27+
reg = (csr_readl(LOONGSON_CSR_CPUTEMP) & 0xff);
28+
goto out;
29+
}
30+
2331
reg = LOONGSON_CHIPTEMP(cpu);
2432
prid_rev = read_c0_prid() & PRID_REV_MASK;
33+
2534
switch (prid_rev) {
2635
case PRID_REV_LOONGSON3A_R1:
2736
reg = (reg >> 8) & 0xff;
@@ -34,9 +43,12 @@ int loongson3_cpu_temp(int cpu)
3443
break;
3544
case PRID_REV_LOONGSON3A_R3_0:
3645
case PRID_REV_LOONGSON3A_R3_1:
46+
default:
3747
reg = (reg & 0xffff)*731/0x4000 - 273;
3848
break;
3949
}
50+
51+
out:
4052
return (int)reg * 1000;
4153
}
4254

@@ -159,6 +171,9 @@ static int __init loongson_hwmon_init(void)
159171

160172
pr_info("Loongson Hwmon Enter...\n");
161173

174+
if (cpu_has_csr())
175+
csr_temp_enable = csr_readl(LOONGSON_CSR_FEATURES) & LOONGSON_CSRF_TEMP;
176+
162177
cpu_hwmon_dev = hwmon_device_register(NULL);
163178
if (IS_ERR(cpu_hwmon_dev)) {
164179
ret = -ENOMEM;

0 commit comments

Comments
 (0)