Skip to contentSkip to conversation

MIPS: Add R16000 detection

PATCH Superseded Joshua Kinard 3 participants 9 messages Jan 19, 2015 – Jan 21, 2015

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 MIPS: Add R16000 detection

From: Joshua Kinard <[email protected]>

This allows the kernel to correctly detect an R16000 MIPS CPU on systems that have those. Otherwise, such systems will detect the CPU as an R14000, due to similarities in the CPU PRId value.

---
 arch/mips/include/asm/cpu-type.h     |    1 +
 arch/mips/include/asm/cpu.h          |    6 +++---
 arch/mips/kernel/cpu-probe.c         |    9 +++++++--
 arch/mips/kernel/perf_event_mipsxx.c |    1 +
 arch/mips/mm/c-r4k.c                 |    4 ++++
 arch/mips/mm/page.c                  |    1 +
 arch/mips/mm/tlb-r4k.c               |    3 ++-
 arch/mips/mm/tlbex.c                 |    1 +
 arch/mips/oprofile/common.c          |    1 +
 arch/mips/oprofile/op_model_mipsxx.c |    1 +
 10 files changed, 22 insertions(+), 6 deletions(-)

linux-mips-add-r16000-detection.patch

arch/mips/include/asm/cpu-type.h +1 -0
index b4e2bd8..d85fc26 100644
@@ -150,6 +150,7 @@ static inline int __pure __get_cpu_type(const int cpu_type)
 	case CPU_R10000:
 	case CPU_R12000:
 	case CPU_R14000:
+	case CPU_R16000:
 #endif
 #ifdef CONFIG_SYS_HAS_CPU_RM7000
 	case CPU_RM7000:
arch/mips/include/asm/cpu.h +3 -3
index 33866fc..53acfce 100644
@@ -67,7 +67,7 @@
 #define PRID_IMP_R4300		0x0b00
 #define PRID_IMP_VR41XX		0x0c00
 #define PRID_IMP_R12000		0x0e00
-#define PRID_IMP_R14000		0x0f00
+#define PRID_IMP_R14000		0x0f00		/* R14K && R16K */
 #define PRID_IMP_R8000		0x1000
 #define PRID_IMP_PR4450		0x1200
 #define PRID_IMP_R4600		0x2000
@@ -283,8 +283,8 @@ enum cpu_type_enum {
 	CPU_R4000PC, CPU_R4000SC, CPU_R4000MC, CPU_R4200, CPU_R4300, CPU_R4310,
 	CPU_R4400PC, CPU_R4400SC, CPU_R4400MC, CPU_R4600, CPU_R4640, CPU_R4650,
 	CPU_R4700, CPU_R5000, CPU_R5500, CPU_NEVADA, CPU_R5432, CPU_R10000,
-	CPU_R12000, CPU_R14000, CPU_VR41XX, CPU_VR4111, CPU_VR4121, CPU_VR4122,
-	CPU_VR4131, CPU_VR4133, CPU_VR4181, CPU_VR4181A, CPU_RM7000,
+	CPU_R12000, CPU_R14000, CPU_R16000, CPU_VR41XX, CPU_VR4111, CPU_VR4121,
+	CPU_VR4122, CPU_VR4131, CPU_VR4133, CPU_VR4181, CPU_VR4181A, CPU_RM7000,
 	CPU_SR71000, CPU_TX49XX,
 
 	/*
arch/mips/kernel/cpu-probe.c +7 -2
index 5342674..3f334a8 100644
@@ -833,8 +833,13 @@ static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu)
 		c->tlbsize = 64;
 		break;
 	case PRID_IMP_R14000:
-		c->cputype = CPU_R14000;
-		__cpu_name[cpu] = "R14000";
+		if (((c->processor_id >> 4) & 0x0f) > 2) {
+			c->cputype = CPU_R16000;
+			__cpu_name[cpu] = "R16000";
+		} else {
+			c->cputype = CPU_R14000;
+			__cpu_name[cpu] = "R14000";
+		}
 		set_isa(c, MIPS_CPU_ISA_IV);
 		c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
 			     MIPS_CPU_FPU | MIPS_CPU_32FPR |
arch/mips/kernel/perf_event_mipsxx.c +1 -0
index 9466184..05dac89 100644
@@ -775,6 +775,7 @@ static int n_counters(void)
 
 	case CPU_R12000:
 	case CPU_R14000:
+	case CPU_R16000:
 		counters = 4;
 		break;
 
arch/mips/mm/c-r4k.c +4 -0
index dd261df..76a7eae 100644
@@ -430,6 +430,7 @@ static inline void local_r4k___flush_cache_all(void * args)
 	case CPU_R10000:
 	case CPU_R12000:
 	case CPU_R14000:
+	case CPU_R16000:
 		/*
 		 * These caches are inclusive caches, that is, if something
 		 * is not cached in the S-cache, we know it also won't be
@@ -1012,6 +1013,7 @@ static void probe_pcache(void)
 	case CPU_R10000:
 	case CPU_R12000:
 	case CPU_R14000:
+	case CPU_R16000:
 		icache_size = 1 << (12 + ((config & R10K_CONF_IC) >> 29));
 		c->icache.linesz = 64;
 		c->icache.ways = 2;
@@ -1240,6 +1242,7 @@ static void probe_pcache(void)
 	case CPU_R10000:
 	case CPU_R12000:
 	case CPU_R14000:
+	case CPU_R16000:
 		break;
 
 	case CPU_74K:
@@ -1437,6 +1440,7 @@ static void setup_scache(void)
 	case CPU_R10000:
 	case CPU_R12000:
 	case CPU_R14000:
+	case CPU_R16000:
 		scache_size = 0x80000 << ((config & R10K_CONF_SS) >> 16);
 		c->scache.linesz = 64 << ((config >> 13) & 1);
 		c->scache.ways = 2;
arch/mips/mm/page.c +1 -0
index b611102..6da7fc3 100644
@@ -143,6 +143,7 @@ static void set_prefetch_parameters(void)
 		case CPU_R10000:
 		case CPU_R12000:
 		case CPU_R14000:
+		case CPU_R16000:
 			/*
 			 * Those values have been experimentally tuned for an
 			 * Origin 200.
arch/mips/mm/tlb-r4k.c +2 -1
index e90b2e8..2a78321 100644
@@ -477,7 +477,8 @@ static void r4k_tlb_configure(void)
 	write_c0_wired(0);
 	if (current_cpu_type() == CPU_R10000 ||
 	    current_cpu_type() == CPU_R12000 ||
-	    current_cpu_type() == CPU_R14000)
+	    current_cpu_type() == CPU_R14000 ||
+	    current_cpu_type() == CPU_R16000)
 		write_c0_framemask(0);
 
 	if (cpu_has_rixi) {
arch/mips/mm/tlbex.c +1 -0
index 3978a3d..3f9ae67 100644
@@ -568,6 +568,7 @@ static void build_tlb_write_entry(u32 **p, struct uasm_label **l,
 	case CPU_R10000:
 	case CPU_R12000:
 	case CPU_R14000:
+	case CPU_R16000:
 	case CPU_4KC:
 	case CPU_4KEC:
 	case CPU_M14KC:
arch/mips/oprofile/common.c +1 -0
index a26cbe3..81f5895 100644
@@ -98,6 +98,7 @@ int __init oprofile_arch_init(struct oprofile_operations *ops)
 	case CPU_R10000:
 	case CPU_R12000:
 	case CPU_R14000:
+	case CPU_R16000:
 	case CPU_XLR:
 		lmodel = &op_model_mipsxx_ops;
 		break;
arch/mips/oprofile/op_model_mipsxx.c +1 -0
index 01f721a..c79ebff 100644
@@ -296,6 +296,7 @@ static inline int n_counters(void)
 
 	case CPU_R12000:
 	case CPU_R14000:
+	case CPU_R16000:
 		counters = 4;
 		break;
 
#1 lore raw
Quoted 64 lines · Joshua Kinard

From: Joshua Kinard <[email protected]>

This allows the kernel to correctly detect an R16000 MIPS CPU on systems that have those. Otherwise, such systems will detect the CPU as an R14000, due to similarities in the CPU PRId value.

---
 arch/mips/include/asm/cpu-type.h     |    1 +
 arch/mips/include/asm/cpu.h          |    6 +++---
 arch/mips/kernel/cpu-probe.c         |    9 +++++++--
 arch/mips/kernel/perf_event_mipsxx.c |    1 +
 arch/mips/mm/c-r4k.c                 |    4 ++++
 arch/mips/mm/page.c                  |    1 +
 arch/mips/mm/tlb-r4k.c               |    3 ++-
 arch/mips/mm/tlbex.c                 |    1 +
 arch/mips/oprofile/common.c          |    1 +
 arch/mips/oprofile/op_model_mipsxx.c |    1 +
 10 files changed, 22 insertions(+), 6 deletions(-)

linux-mips-add-r16000-detection.patch

arch/mips/include/asm/cpu-type.h +1 -0
index b4e2bd8..d85fc26 100644
@@ -150,6 +150,7 @@ static inline int __pure __get_cpu_type(const int cpu_type)
        case CPU_R10000:
        case CPU_R12000:
        case CPU_R14000:
+       case CPU_R16000:
 #endif
 #ifdef CONFIG_SYS_HAS_CPU_RM7000
        case CPU_RM7000:
arch/mips/include/asm/cpu.h +3 -3
index 33866fc..53acfce 100644
@@ -67,7 +67,7 @@
 #define PRID_IMP_R4300         0x0b00
 #define PRID_IMP_VR41XX                0x0c00
 #define PRID_IMP_R12000                0x0e00
-#define PRID_IMP_R14000                0x0f00
+#define PRID_IMP_R14000                0x0f00          /* R14K && R16K */
 #define PRID_IMP_R8000         0x1000
 #define PRID_IMP_PR4450                0x1200
 #define PRID_IMP_R4600         0x2000
@@ -283,8 +283,8 @@ enum cpu_type_enum {
        CPU_R4000PC, CPU_R4000SC, CPU_R4000MC, CPU_R4200, CPU_R4300, CPU_R4310,
        CPU_R4400PC, CPU_R4400SC, CPU_R4400MC, CPU_R4600, CPU_R4640, CPU_R4650,
        CPU_R4700, CPU_R5000, CPU_R5500, CPU_NEVADA, CPU_R5432, CPU_R10000,
-       CPU_R12000, CPU_R14000, CPU_VR41XX, CPU_VR4111, CPU_VR4121, CPU_VR4122,
-       CPU_VR4131, CPU_VR4133, CPU_VR4181, CPU_VR4181A, CPU_RM7000,
+       CPU_R12000, CPU_R14000, CPU_R16000, CPU_VR41XX, CPU_VR4111, CPU_VR4121,
+       CPU_VR4122, CPU_VR4131, CPU_VR4133, CPU_VR4181, CPU_VR4181A, CPU_RM7000,
        CPU_SR71000, CPU_TX49XX,
 
        /*
arch/mips/kernel/cpu-probe.c +0 -0
index 5342674..3f334a8 100644
@@ -833,8 +833,13 @@ static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu)
                c->tlbsize = 64;
                break;

arch/mips/kernel/cpu-probe.c static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu) · line 842

Quoted 10 lines
arch/mips/kernel/cpu-probe.c +7 -2
        case PRID_IMP_R14000:
-               c->cputype = CPU_R14000;
-               __cpu_name[cpu] = "R14000";
+               if (((c->processor_id >> 4) & 0x0f) > 2) {
+                       c->cputype = CPU_R16000;
+                       __cpu_name[cpu] = "R16000";
+               } else {
+                       c->cputype = CPU_R14000;
+                       __cpu_name[cpu] = "R14000";
+               }

It looks like this is the only hunk that has a functional change, and that is simply setting __cpu_name[cpu] to "R16000"

You can do that without adding CPU_R16000 to the enumeration. I don't see that adding it accomplishes anything.

#2 lore raw
Quoted 79 lines · Matt Turner
Quoted 64 lines · Joshua Kinard

From: Joshua Kinard <[email protected]>

This allows the kernel to correctly detect an R16000 MIPS CPU on systems that have those. Otherwise, such systems will detect the CPU as an R14000, due to similarities in the CPU PRId value.

---
 arch/mips/include/asm/cpu-type.h     |    1 +
 arch/mips/include/asm/cpu.h          |    6 +++---
 arch/mips/kernel/cpu-probe.c         |    9 +++++++--
 arch/mips/kernel/perf_event_mipsxx.c |    1 +
 arch/mips/mm/c-r4k.c                 |    4 ++++
 arch/mips/mm/page.c                  |    1 +
 arch/mips/mm/tlb-r4k.c               |    3 ++-
 arch/mips/mm/tlbex.c                 |    1 +
 arch/mips/oprofile/common.c          |    1 +
 arch/mips/oprofile/op_model_mipsxx.c |    1 +
 10 files changed, 22 insertions(+), 6 deletions(-)

linux-mips-add-r16000-detection.patch

arch/mips/include/asm/cpu-type.h +1 -0
index b4e2bd8..d85fc26 100644
@@ -150,6 +150,7 @@ static inline int __pure __get_cpu_type(const int cpu_type)
        case CPU_R10000:
        case CPU_R12000:
        case CPU_R14000:
+       case CPU_R16000:
 #endif
 #ifdef CONFIG_SYS_HAS_CPU_RM7000
        case CPU_RM7000:
arch/mips/include/asm/cpu.h +3 -3
index 33866fc..53acfce 100644
@@ -67,7 +67,7 @@
 #define PRID_IMP_R4300         0x0b00
 #define PRID_IMP_VR41XX                0x0c00
 #define PRID_IMP_R12000                0x0e00
-#define PRID_IMP_R14000                0x0f00
+#define PRID_IMP_R14000                0x0f00          /* R14K && R16K */
 #define PRID_IMP_R8000         0x1000
 #define PRID_IMP_PR4450                0x1200
 #define PRID_IMP_R4600         0x2000
@@ -283,8 +283,8 @@ enum cpu_type_enum {
        CPU_R4000PC, CPU_R4000SC, CPU_R4000MC, CPU_R4200, CPU_R4300, CPU_R4310,
        CPU_R4400PC, CPU_R4400SC, CPU_R4400MC, CPU_R4600, CPU_R4640, CPU_R4650,
        CPU_R4700, CPU_R5000, CPU_R5500, CPU_NEVADA, CPU_R5432, CPU_R10000,
-       CPU_R12000, CPU_R14000, CPU_VR41XX, CPU_VR4111, CPU_VR4121, CPU_VR4122,
-       CPU_VR4131, CPU_VR4133, CPU_VR4181, CPU_VR4181A, CPU_RM7000,
+       CPU_R12000, CPU_R14000, CPU_R16000, CPU_VR41XX, CPU_VR4111, CPU_VR4121,
+       CPU_VR4122, CPU_VR4131, CPU_VR4133, CPU_VR4181, CPU_VR4181A, CPU_RM7000,
        CPU_SR71000, CPU_TX49XX,
 
        /*
arch/mips/kernel/cpu-probe.c +0 -0
index 5342674..3f334a8 100644
@@ -833,8 +833,13 @@ static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu)
                c->tlbsize = 64;
                break;

arch/mips/kernel/cpu-probe.c static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu) · line 842

Quoted 10 lines
arch/mips/kernel/cpu-probe.c +7 -2
        case PRID_IMP_R14000:
-               c->cputype = CPU_R14000;
-               __cpu_name[cpu] = "R14000";
+               if (((c->processor_id >> 4) & 0x0f) > 2) {
+                       c->cputype = CPU_R16000;
+                       __cpu_name[cpu] = "R16000";
+               } else {
+                       c->cputype = CPU_R14000;
+                       __cpu_name[cpu] = "R14000";
+               }

It looks like this is the only hunk that has a functional change, and that is simply setting __cpu_name[cpu] to "R16000"

Quoted 3 lines

You can do that without adding CPU_R16000 to the enumeration. I don't see that adding it accomplishes anything.

It mirrors what CPU_R14000 and CPU_R12000 do. I won't rule out that, down the road, something about the R16K might be different enough from the R14K to require one of these other spots later on, so adding it now isn't going to adversely affect things. Only IP35 has R16K's anyways, which doesn't support Linux just yet. It's a "for the future" patch. Last of the R-series anyways, since the R18000 died before it ever became silicon.

--J

#3 lore raw
Quoted 23 lines · Joshua Kinard
Quoted 22 lines · Matt Turner
Quoted 7 lines · Joshua Kinard
arch/mips/kernel/cpu-probe.c +0 -0
index 5342674..3f334a8 100644
@@ -833,8 +833,13 @@ static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu)
                c->tlbsize = 64;
                break;

arch/mips/kernel/cpu-probe.c static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu) · line 842

Quoted 10 lines
arch/mips/kernel/cpu-probe.c +7 -2
        case PRID_IMP_R14000:
-               c->cputype = CPU_R14000;
-               __cpu_name[cpu] = "R14000";
+               if (((c->processor_id >> 4) & 0x0f) > 2) {
+                       c->cputype = CPU_R16000;
+                       __cpu_name[cpu] = "R16000";
+               } else {
+                       c->cputype = CPU_R14000;
+                       __cpu_name[cpu] = "R14000";
+               }

It looks like this is the only hunk that has a functional change, and that is simply setting __cpu_name[cpu] to "R16000"

Quoted 8 lines
Quoted 3 lines

You can do that without adding CPU_R16000 to the enumeration. I don't see that adding it accomplishes anything.

It mirrors what CPU_R14000 and CPU_R12000 do. I won't rule out that, down the road, something about the R16K might be different enough from the R14K to require one of these other spots later on, so adding it now isn't going to adversely affect things.

That's justification for removing CPU_R14000 as well, not adding CPU_R16000.

Otherwise it's just adding useless code.

#4 lore raw
Quoted 28 lines · Matt Turner
Quoted 27 lines · Joshua Kinard
Quoted 25 lines · Matt Turner
Quoted 7 lines · Joshua Kinard
arch/mips/kernel/cpu-probe.c +0 -0
index 5342674..3f334a8 100644
@@ -833,8 +833,13 @@ static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu)
                c->tlbsize = 64;
                break;

arch/mips/kernel/cpu-probe.c static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu) · line 842

Quoted 10 lines
arch/mips/kernel/cpu-probe.c +7 -2
        case PRID_IMP_R14000:
-               c->cputype = CPU_R14000;
-               __cpu_name[cpu] = "R14000";
+               if (((c->processor_id >> 4) & 0x0f) > 2) {
+                       c->cputype = CPU_R16000;
+                       __cpu_name[cpu] = "R16000";
+               } else {
+                       c->cputype = CPU_R14000;
+                       __cpu_name[cpu] = "R14000";
+               }

It looks like this is the only hunk that has a functional change, and that is simply setting __cpu_name[cpu] to "R16000"

You can do that without adding CPU_R16000 to the enumeration. I don't see that adding it accomplishes anything.

Quoted 8 lines
Quoted 4 lines

It mirrors what CPU_R14000 and CPU_R12000 do. I won't rule out that, down the road, something about the R16K might be different enough from the R14K to require one of these other spots later on, so adding it now isn't going to adversely affect things.

That's justification for removing CPU_R14000 as well, not adding CPU_R16000.

Otherwise it's just adding useless code.

R14000 has a different CPU PRId than R12000 or R10000, so the code that sets the icache/scache linesz wouldn't know to apply to R14K, including the writing the the FrameMask register in CP0. Octane and Origin2K/Onyx2 can both use R14000 CPUs, so this is a bad suggestion, as removing R14000 detection would render those systems inoperable with those CPUs. I know, cause I'm the one that actually sent the R14K patch in 9 years ago w/ commit 44d921b2 .

I'm also for reducing code and all, but this isn't the case in which to do it.
You're quibbling over the addition of an one new enum item, one new if-else
statement, one extra logical-OR conditional to an existing if statement, and nine new case statements, some of which only execute once during the CPU probing portion of boot.

There are likely a lot of better places in the existing code that could use some optimization or dead code removal.

--J

#5 lore raw
Quoted 36 lines · Joshua Kinard
Quoted 35 lines · Matt Turner
Quoted 23 lines · Joshua Kinard
Quoted 22 lines · Matt Turner
Quoted 7 lines · Joshua Kinard
arch/mips/kernel/cpu-probe.c +0 -0
index 5342674..3f334a8 100644
@@ -833,8 +833,13 @@ static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu)
                c->tlbsize = 64;
                break;

arch/mips/kernel/cpu-probe.c static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu) · line 842

Quoted 10 lines
arch/mips/kernel/cpu-probe.c +7 -2
        case PRID_IMP_R14000:
-               c->cputype = CPU_R14000;
-               __cpu_name[cpu] = "R14000";
+               if (((c->processor_id >> 4) & 0x0f) > 2) {
+                       c->cputype = CPU_R16000;
+                       __cpu_name[cpu] = "R16000";
+               } else {
+                       c->cputype = CPU_R14000;
+                       __cpu_name[cpu] = "R14000";
+               }

It looks like this is the only hunk that has a functional change, and that is simply setting __cpu_name[cpu] to "R16000"

Quoted 8 lines
Quoted 3 lines

You can do that without adding CPU_R16000 to the enumeration. I don't see that adding it accomplishes anything.

It mirrors what CPU_R14000 and CPU_R12000 do. I won't rule out that, down the road, something about the R16K might be different enough from the R14K to require one of these other spots later on, so adding it now isn't going to adversely affect things.

That's justification for removing CPU_R14000 as well, not adding CPU_R16000.

Quoted 8 lines
Quoted 1 line

Otherwise it's just adding useless code.

R14000 has a different CPU PRId than R12000 or R10000, so the code that sets the icache/scache linesz wouldn't know to apply to R14K, including the writing the the FrameMask register in CP0. Octane and Origin2K/Onyx2 can both use R14000 CPUs, so this is a bad suggestion, as removing R14000 detection would render those systems inoperable with those CPUs. I know, cause I'm the one that actually sent the R14K patch in 9 years ago w/ commit 44d921b2 .

Sorry, you're not getting it.

git grep -B1 CPU_R14000

Notice how all of the instances of CPU_R14000 are preceded by CPU_R12000? That's because CPU_R14000 doesn't do anything differently.

All you should do to remove CPU_R14000 is to set c->cputype = CPU_R12000 in the PRID_IMP_R14000 case in cpu-probe.c.

#6 lore raw
Quoted 48 lines · Matt Turner
Quoted 36 lines · Joshua Kinard
Quoted 35 lines · Matt Turner
Quoted 23 lines · Joshua Kinard
Quoted 22 lines · Matt Turner
Quoted 7 lines · Joshua Kinard
arch/mips/kernel/cpu-probe.c +0 -0
index 5342674..3f334a8 100644
@@ -833,8 +833,13 @@ static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu)
                c->tlbsize = 64;
                break;

arch/mips/kernel/cpu-probe.c static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu) · line 842

Quoted 10 lines
arch/mips/kernel/cpu-probe.c +7 -2
        case PRID_IMP_R14000:
-               c->cputype = CPU_R14000;
-               __cpu_name[cpu] = "R14000";
+               if (((c->processor_id >> 4) & 0x0f) > 2) {
+                       c->cputype = CPU_R16000;
+                       __cpu_name[cpu] = "R16000";
+               } else {
+                       c->cputype = CPU_R14000;
+                       __cpu_name[cpu] = "R14000";
+               }

It looks like this is the only hunk that has a functional change, and that is simply setting __cpu_name[cpu] to "R16000"

Quoted 8 lines
Quoted 3 lines

You can do that without adding CPU_R16000 to the enumeration. I don't see that adding it accomplishes anything.

It mirrors what CPU_R14000 and CPU_R12000 do. I won't rule out that, down the road, something about the R16K might be different enough from the R14K to require one of these other spots later on, so adding it now isn't going to adversely affect things.

That's justification for removing CPU_R14000 as well, not adding CPU_R16000.

Quoted 8 lines
Quoted 1 line

Otherwise it's just adding useless code.

R14000 has a different CPU PRId than R12000 or R10000, so the code that sets the icache/scache linesz wouldn't know to apply to R14K, including the writing the the FrameMask register in CP0. Octane and Origin2K/Onyx2 can both use R14000 CPUs, so this is a bad suggestion, as removing R14000 detection would render those systems inoperable with those CPUs. I know, cause I'm the one that actually sent the R14K patch in 9 years ago w/ commit 44d921b2 .

Sorry, you're not getting it.

Quoted 7 lines

git grep -B1 CPU_R14000

Notice how all of the instances of CPU_R14000 are preceded by CPU_R12000? That's because CPU_R14000 doesn't do anything differently.

All you should do to remove CPU_R14000 is to set c->cputype = CPU_R12000 in the PRID_IMP_R14000 case in cpu-probe.c.

I see what you're getting at, but I disagree with the reasoning. The code reads clearer when it's explicitly stated the way it is, rather than fudging things and treating an R14K as an R12K for a minor gain of a few cycles.

And since I know there's something "weird" about the R14K right now, one of those case statements might be needed down the road to do something a little bit differently for R14K versus R12K and such (maybe in the TLB code, if I can ever wrap my head around that).

In the end, it's Ralf's call on accepting it.

#7 lore raw
Quoted 10 lines · Joshua Kinard

I see what you're getting at, but I disagree with the reasoning. The code reads clearer when it's explicitly stated the way it is, rather than fudging things and treating an R14K as an R12K for a minor gain of a few cycles.

And since I know there's something "weird" about the R14K right now, one of those case statements might be needed down the road to do something a little bit differently for R14K versus R12K and such (maybe in the TLB code, if I can ever wrap my head around that).

In the end, it's Ralf's call on accepting it.

The way the code of current_cpu_type() is written, gcc can know that it may only return certain values. Which for example means that a system has an R1x0000 but not a MIPS32 processor. It then case use that knowledge to eleminate all dead case and if () statements.

The scheme is not fine grained enough to differenciate between R10000, R12000, R14000. That's possible but that's where madness lies. See __get_cpu_type() in include/asm/cpu-type.h for details.

We have a number of processors types that need no or very little special support code yet have special code to distinguish them. R2000/R3000, R4000/ R4400 are examples. Sometimes we distinguish them just to make sure the expected name is displayed in /proc/cpuinfo.

Ralf

#8 lore raw
In reply to Joshua Kinard
Quoted 5 lines · Joshua Kinard

From: Joshua Kinard <[email protected]>

This allows the kernel to correctly detect an R16000 MIPS CPU on systems that have those. Otherwise, such systems will detect the CPU as an R14000, due to similarities in the CPU PRId value.

Sending a v2 of this one, too. Fixing up the split-r10k bits, I found an additional spot or two for the R16K.

--J

Quoted 181 lines
---
 arch/mips/include/asm/cpu-type.h     |    1 +
 arch/mips/include/asm/cpu.h          |    6 +++---
 arch/mips/kernel/cpu-probe.c         |    9 +++++++--
 arch/mips/kernel/perf_event_mipsxx.c |    1 +
 arch/mips/mm/c-r4k.c                 |    4 ++++
 arch/mips/mm/page.c                  |    1 +
 arch/mips/mm/tlb-r4k.c               |    3 ++-
 arch/mips/mm/tlbex.c                 |    1 +
 arch/mips/oprofile/common.c          |    1 +
 arch/mips/oprofile/op_model_mipsxx.c |    1 +
 10 files changed, 22 insertions(+), 6 deletions(-)

linux-mips-add-r16000-detection.patch

arch/mips/include/asm/cpu-type.h +1 -0
index b4e2bd8..d85fc26 100644
@@ -150,6 +150,7 @@ static inline int __pure __get_cpu_type(const int cpu_type)
 	case CPU_R10000:
 	case CPU_R12000:
 	case CPU_R14000:
+	case CPU_R16000:
 #endif
 #ifdef CONFIG_SYS_HAS_CPU_RM7000
 	case CPU_RM7000:
arch/mips/include/asm/cpu.h +3 -3
index 33866fc..53acfce 100644
@@ -67,7 +67,7 @@
 #define PRID_IMP_R4300		0x0b00
 #define PRID_IMP_VR41XX		0x0c00
 #define PRID_IMP_R12000		0x0e00
-#define PRID_IMP_R14000		0x0f00
+#define PRID_IMP_R14000		0x0f00		/* R14K && R16K */
 #define PRID_IMP_R8000		0x1000
 #define PRID_IMP_PR4450		0x1200
 #define PRID_IMP_R4600		0x2000
@@ -283,8 +283,8 @@ enum cpu_type_enum {
 	CPU_R4000PC, CPU_R4000SC, CPU_R4000MC, CPU_R4200, CPU_R4300, CPU_R4310,
 	CPU_R4400PC, CPU_R4400SC, CPU_R4400MC, CPU_R4600, CPU_R4640, CPU_R4650,
 	CPU_R4700, CPU_R5000, CPU_R5500, CPU_NEVADA, CPU_R5432, CPU_R10000,
-	CPU_R12000, CPU_R14000, CPU_VR41XX, CPU_VR4111, CPU_VR4121, CPU_VR4122,
-	CPU_VR4131, CPU_VR4133, CPU_VR4181, CPU_VR4181A, CPU_RM7000,
+	CPU_R12000, CPU_R14000, CPU_R16000, CPU_VR41XX, CPU_VR4111, CPU_VR4121,
+	CPU_VR4122, CPU_VR4131, CPU_VR4133, CPU_VR4181, CPU_VR4181A, CPU_RM7000,
 	CPU_SR71000, CPU_TX49XX,
 
 	/*
arch/mips/kernel/cpu-probe.c +7 -2
index 5342674..3f334a8 100644
@@ -833,8 +833,13 @@ static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu)
 		c->tlbsize = 64;
 		break;
 	case PRID_IMP_R14000:
-		c->cputype = CPU_R14000;
-		__cpu_name[cpu] = "R14000";
+		if (((c->processor_id >> 4) & 0x0f) > 2) {
+			c->cputype = CPU_R16000;
+			__cpu_name[cpu] = "R16000";
+		} else {
+			c->cputype = CPU_R14000;
+			__cpu_name[cpu] = "R14000";
+		}
 		set_isa(c, MIPS_CPU_ISA_IV);
 		c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
 			     MIPS_CPU_FPU | MIPS_CPU_32FPR |
arch/mips/kernel/perf_event_mipsxx.c +1 -0
index 9466184..05dac89 100644
@@ -775,6 +775,7 @@ static int n_counters(void)
 
 	case CPU_R12000:
 	case CPU_R14000:
+	case CPU_R16000:
 		counters = 4;
 		break;
 
arch/mips/mm/c-r4k.c +4 -0
index dd261df..76a7eae 100644
@@ -430,6 +430,7 @@ static inline void local_r4k___flush_cache_all(void * args)
 	case CPU_R10000:
 	case CPU_R12000:
 	case CPU_R14000:
+	case CPU_R16000:
 		/*
 		 * These caches are inclusive caches, that is, if something
 		 * is not cached in the S-cache, we know it also won't be
@@ -1012,6 +1013,7 @@ static void probe_pcache(void)
 	case CPU_R10000:
 	case CPU_R12000:
 	case CPU_R14000:
+	case CPU_R16000:
 		icache_size = 1 << (12 + ((config & R10K_CONF_IC) >> 29));
 		c->icache.linesz = 64;
 		c->icache.ways = 2;
@@ -1240,6 +1242,7 @@ static void probe_pcache(void)
 	case CPU_R10000:
 	case CPU_R12000:
 	case CPU_R14000:
+	case CPU_R16000:
 		break;
 
 	case CPU_74K:
@@ -1437,6 +1440,7 @@ static void setup_scache(void)
 	case CPU_R10000:
 	case CPU_R12000:
 	case CPU_R14000:
+	case CPU_R16000:
 		scache_size = 0x80000 << ((config & R10K_CONF_SS) >> 16);
 		c->scache.linesz = 64 << ((config >> 13) & 1);
 		c->scache.ways = 2;
arch/mips/mm/page.c +1 -0
index b611102..6da7fc3 100644
@@ -143,6 +143,7 @@ static void set_prefetch_parameters(void)
 		case CPU_R10000:
 		case CPU_R12000:
 		case CPU_R14000:
+		case CPU_R16000:
 			/*
 			 * Those values have been experimentally tuned for an
 			 * Origin 200.
arch/mips/mm/tlb-r4k.c +2 -1
index e90b2e8..2a78321 100644
@@ -477,7 +477,8 @@ static void r4k_tlb_configure(void)
 	write_c0_wired(0);
 	if (current_cpu_type() == CPU_R10000 ||
 	    current_cpu_type() == CPU_R12000 ||
-	    current_cpu_type() == CPU_R14000)
+	    current_cpu_type() == CPU_R14000 ||
+	    current_cpu_type() == CPU_R16000)
 		write_c0_framemask(0);
 
 	if (cpu_has_rixi) {
arch/mips/mm/tlbex.c +1 -0
index 3978a3d..3f9ae67 100644
@@ -568,6 +568,7 @@ static void build_tlb_write_entry(u32 **p, struct uasm_label **l,
 	case CPU_R10000:
 	case CPU_R12000:
 	case CPU_R14000:
+	case CPU_R16000:
 	case CPU_4KC:
 	case CPU_4KEC:
 	case CPU_M14KC:
arch/mips/oprofile/common.c +1 -0
index a26cbe3..81f5895 100644
@@ -98,6 +98,7 @@ int __init oprofile_arch_init(struct oprofile_operations *ops)
 	case CPU_R10000:
 	case CPU_R12000:
 	case CPU_R14000:
+	case CPU_R16000:
 	case CPU_XLR:
 		lmodel = &op_model_mipsxx_ops;
 		break;
arch/mips/oprofile/op_model_mipsxx.c +1 -0
index 01f721a..c79ebff 100644
@@ -296,6 +296,7 @@ static inline int n_counters(void)
 
 	case CPU_R12000:
 	case CPU_R14000:
+	case CPU_R16000:
 		counters = 4;
 		break;