MIPS: Tell R4k SC and MC variations apart
PATCH 1/1 MIPS: Tell R4k SC and MC variations apart
There is no reliable way to tell R4000/R4400 SC and MC variations apart, however simple heuristic should give good results. Only the MC version supports coherent caching so we can rely on such a mode having been set for KSEG0 by the power-on firmware to reliably indicate an MC processor. SC processors reportedly hang on coherent cached memory accesses and Linux is linked to a cached load address so the firmware has to use the correct caching mode to download the kernel image in a cached mode successfully.
OTOH if the firmware chooses to use either the non-coherent cached or the uncached mode for KSEG0 on an MC processor, then the SC variant will be reported, just as we currently do, so no regression here.
---
Ralf,
I believe we discussed this once long ago and you had some concerns about
such an approach although I don't recall exactly what they were. I maintain that this heuristic is reasonable, has no drawbacks and has a potential to make some optimisations or errata workarounds easier. Also we can collect data about systems affected to see what their firmware does -- R4000SC/R4400SC DECstations definitely get CP0.Config.K0 right.
Maciej
linux-mips-r4k-mc.patch
arch/mips/kernel/cpu-probe.c +24 -4
@@ -362,13 +362,33 @@ static inline void cpu_probe_legacy(stru __cpu_name[cpu] ="R4000PC" ; } }else { +int cca =read_c0_config () &CONF_CM_CMASK ; +int mc; + +/* +* SC and MC versions can't be reliably told apart, +* but only the latter support coherent caching +* modes so assume the firmware has set the KSEG0 +* coherency attribute reasonably (if uncached, we +* assume SC). +*/ +switch (cca) { +case CONF_CM_CACHABLE_CE : +case CONF_CM_CACHABLE_COW : +case CONF_CM_CACHABLE_CUW : + mc =1 ; +break ; +default : + mc =0 ; +break ; + }if ((c->processor_id &PRID_REV_MASK ) >=PRID_REV_R4400 ) { - c->cputype =CPU_R4400SC ; - __cpu_name[cpu] ="R4400SC" ; + c->cputype = mc ?CPU_R4400MC :CPU_R4400SC ; + __cpu_name[cpu] = mc ?"R4400MC" :"R4400SC" ; }else { - c->cputype =CPU_R4000SC ; - __cpu_name[cpu] ="R4000SC" ; + c->cputype = mc ?CPU_R4000MC :CPU_R4000SC ; + __cpu_name[cpu] = mc ?"R4400SC" :"R4000SC" ; } }
Quoted 55 lines · Maciej W. Rozycki
There is no reliable way to tell R4000/R4400 SC and MC variations apart, however simple heuristic should give good results. Only the MC version supports coherent caching so we can rely on such a mode having been set for KSEG0 by the power-on firmware to reliably indicate an MC processor. SC processors reportedly hang on coherent cached memory accesses and Linux is linked to a cached load address so the firmware has to use the correct caching mode to download the kernel image in a cached mode successfully.
OTOH if the firmware chooses to use either the non-coherent cached or the uncached mode for KSEG0 on an MC processor, then the SC variant will be reported, just as we currently do, so no regression here.
Signed-off-by Maciej W. Rozycki <[email protected]>---
Ralf,I believe we discussed this once long ago and you had some concerns about
such an approach although I don't recall exactly what they were. I maintain that this heuristic is reasonable, has no drawbacks and has a potential to make some optimisations or errata workarounds easier. Also we can collect data about systems affected to see what their firmware does -- R4000SC/R4400SC DECstations definitely get CP0.Config.K0 right.Maciej
linux-mips-r4k-mc.patch
Index:linux/arch/mips/kernel/cpu-probe.c
===================================================================arch/mips/kernel/cpu-probe.c +20
-0@@ -362,13 +362,33 @@ static inline void cpu_probe_legacy(stru __cpu_name[cpu] ="R4000PC" ; } }else { +int cca =read_c0_config () &CONF_CM_CMASK ; +int mc; + +/* +* SC and MC versions can't be reliably told apart, +* but only the latter support coherent caching +* modes so assume the firmware has set the KSEG0 +* coherency attribute reasonably (if uncached, we +* assume SC). +*/ +switch (cca) { +case CONF_CM_CACHABLE_CE : +case CONF_CM_CACHABLE_COW : +case CONF_CM_CACHABLE_CUW : + mc =1 ; +break ; +default : + mc =0 ; +break ; + } if ((c->processor_id & PRID_REV_MASK) >=
arch/mips/kernel/cpu-probe.c static inline void cpu_probe_legacy(stru · line 391
Quoted 10 lines
arch/mips/kernel/cpu-probe.c +4
-4PRID_REV_R4400) { - c->cputype = CPU_R4400SC; - __cpu_name[cpu] = "R4400SC"; + c->cputype = mc ? CPU_R4400MC : CPU_R4400SC; + __cpu_name[cpu] = mc ? "R4400MC" : "R4400SC"; } else { - c->cputype =CPU_R4000SC ; - __cpu_name[cpu] ="R4000SC" ; + c->cputype = mc ?CPU_R4000MC :CPU_R4000SC ; + __cpu_name[cpu] = mc ?"R4400SC" :"R4000SC" ;
I guess the first one should be "R4000MC", not "R4400SC".
Regards
Jonas
PATCH v2 1/1 MIPS: Tell R4k SC and MC variations apart
There is no reliable way to tell R4000/R4400 SC and MC variations apart, however simple heuristic should give good results. Only the MC version supports coherent caching so we can rely on such a mode having been set for KSEG0 by the power-on firmware to reliably indicate an MC processor. SC processors reportedly hang on coherent cached memory accesses and Linux is linked to a cached load address so the firmware has to use the correct caching mode to download the kernel image in a cached mode successfully.
OTOH if the firmware chooses to use either the non-coherent cached or the uncached mode for KSEG0 on an MC processor, then the SC variant will be reported, just as we currently do, so no regression here.
---
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ c->cputype = mc ? CPU_R4000MC : CPU_R4000SC; + __cpu_name[cpu] = mc ? "R4400SC" : "R4000SC";I guess the first one should be "R4000MC", not "R4400SC".
Good catch, thanks, here's an update.
Maciej
linux-mips-r4k-mc.patch
arch/mips/kernel/cpu-probe.c +24 -4
@@ -362,13 +362,33 @@ static inline void cpu_probe_legacy(stru __cpu_name[cpu] ="R4000PC" ; } }else { +int cca =read_c0_config () &CONF_CM_CMASK ; +int mc; + +/* +* SC and MC versions can't be reliably told apart, +* but only the latter support coherent caching +* modes so assume the firmware has set the KSEG0 +* coherency attribute reasonably (if uncached, we +* assume SC). +*/ +switch (cca) { +case CONF_CM_CACHABLE_CE : +case CONF_CM_CACHABLE_COW : +case CONF_CM_CACHABLE_CUW : + mc =1 ; +break ; +default : + mc =0 ; +break ; + }if ((c->processor_id &PRID_REV_MASK ) >=PRID_REV_R4400 ) { - c->cputype =CPU_R4400SC ; - __cpu_name[cpu] ="R4400SC" ; + c->cputype = mc ?CPU_R4400MC :CPU_R4400SC ; + __cpu_name[cpu] = mc ?"R4400MC" :"R4400SC" ; }else { - c->cputype =CPU_R4000SC ; - __cpu_name[cpu] ="R4000SC" ; + c->cputype = mc ?CPU_R4000MC :CPU_R4000SC ; + __cpu_name[cpu] = mc ?"R4400MC" :"R4000SC" ; } }
On Mon, Sep 23, 2013 at 2:35 PM, Maciej W. Rozycki <[email protected]> wrote:
(snip)
Quoted 30 lines
linux-mips-r4k-mc.patch
Index:linux/arch/mips/kernel/cpu-probe.c
===================================================================arch/mips/kernel/cpu-probe.c +20
-0@@ -362,13 +362,33 @@ static inline void cpu_probe_legacy(stru __cpu_name[cpu] ="R4000PC" ; } }else { +int cca =read_c0_config () &CONF_CM_CMASK ; +int mc; + +/* +* SC and MC versions can't be reliably told apart, +* but only the latter support coherent caching +* modes so assume the firmware has set the KSEG0 +* coherency attribute reasonably (if uncached, we +* assume SC). +*/ +switch (cca) { +case CONF_CM_CACHABLE_CE : +case CONF_CM_CACHABLE_COW : +case CONF_CM_CACHABLE_CUW : + mc =1 ; +break ; +default : + mc =0 ; +break ; + } if ((c->processor_id & PRID_REV_MASK) >=
arch/mips/kernel/cpu-probe.c static inline void cpu_probe_legacy(stru · line 391
Quoted 10 lines
arch/mips/kernel/cpu-probe.c +4
-4PRID_REV_R4400) { - c->cputype = CPU_R4400SC; - __cpu_name[cpu] = "R4400SC"; + c->cputype = mc ? CPU_R4400MC : CPU_R4400SC; + __cpu_name[cpu] = mc ? "R4400MC" : "R4400SC"; } else { - c->cputype =CPU_R4000SC ; - __cpu_name[cpu] ="R4000SC" ; + c->cputype = mc ?CPU_R4000MC :CPU_R4000SC ; + __cpu_name[cpu] = mc ?"R4400MC" :"R4000SC" ;
You are still calling it "R4400", not "R4000" as expected.
Jonas
PATCH v3 1/1 MIPS: Tell R4k SC and MC variations apart
There is no reliable way to tell R4000/R4400 SC and MC variations apart, however simple heuristic should give good results. Only the MC version supports coherent caching so we can rely on such a mode having been set for KSEG0 by the power-on firmware to reliably indicate an MC processor. SC processors reportedly hang on coherent cached memory accesses and Linux is linked to a cached load address so the firmware has to use the correct caching mode to download the kernel image in a cached mode successfully.
OTOH if the firmware chooses to use either the non-coherent cached or the uncached mode for KSEG0 on an MC processor, then the SC variant will be reported, just as we currently do, so no regression here.
---
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ c->cputype = mc ? CPU_R4000MC : CPU_R4000SC; + __cpu_name[cpu] = mc ? "R4400MC" : "R4000SC";You are still calling it "R4400", not "R4000" as expected.
Sigh, sorry about that, and thanks for your persistence.
Maciej
linux-mips-r4k-mc.patch
arch/mips/kernel/cpu-probe.c +24 -4
@@ -362,13 +362,33 @@ static inline void cpu_probe_legacy(stru __cpu_name[cpu] ="R4000PC" ; } }else { +int cca =read_c0_config () &CONF_CM_CMASK ; +int mc; + +/* +* SC and MC versions can't be reliably told apart, +* but only the latter support coherent caching +* modes so assume the firmware has set the KSEG0 +* coherency attribute reasonably (if uncached, we +* assume SC). +*/ +switch (cca) { +case CONF_CM_CACHABLE_CE : +case CONF_CM_CACHABLE_COW : +case CONF_CM_CACHABLE_CUW : + mc =1 ; +break ; +default : + mc =0 ; +break ; + }if ((c->processor_id &PRID_REV_MASK ) >=PRID_REV_R4400 ) { - c->cputype =CPU_R4400SC ; - __cpu_name[cpu] ="R4400SC" ; + c->cputype = mc ?CPU_R4400MC :CPU_R4400SC ; + __cpu_name[cpu] = mc ?"R4400MC" :"R4400SC" ; }else { - c->cputype =CPU_R4000SC ; - __cpu_name[cpu] ="R4000SC" ; + c->cputype = mc ?CPU_R4000MC :CPU_R4000SC ; + __cpu_name[cpu] = mc ?"R4000MC" :"R4000SC" ; } }
Ralf Baechle
AppliedQuoted 11 lines · Maciej W. Rozycki
There is no reliable way to tell R4000/R4400 SC and MC variations apart, however simple heuristic should give good results. Only the MC version supports coherent caching so we can rely on such a mode having been set for KSEG0 by the power-on firmware to reliably indicate an MC processor. SC processors reportedly hang on coherent cached memory accesses and Linux is linked to a cached load address so the firmware has to use the correct caching mode to download the kernel image in a cached mode successfully.
OTOH if the firmware chooses to use either the non-coherent cached or the uncached mode for KSEG0 on an MC processor, then the SC variant will be reported, just as we currently do, so no regression here.
Queued for 3.13. Thanks,
Ralf
Quoted 16 lines · Maciej W. Rozycki
There is no reliable way to tell R4000/R4400 SC and MC variations apart, however simple heuristic should give good results. Only the MC version supports coherent caching so we can rely on such a mode having been set for KSEG0 by the power-on firmware to reliably indicate an MC processor. SC processors reportedly hang on coherent cached memory accesses and Linux is linked to a cached load address so the firmware has to use the correct caching mode to download the kernel image in a cached mode successfully.
OTOH if the firmware chooses to use either the non-coherent cached or the uncached mode for KSEG0 on an MC processor, then the SC variant will be reported, just as we currently do, so no regression here.
Signed-off-by Maciej W. Rozycki <[email protected]>---
Ralf,
Quoted 6 lines
I believe we discussed this once long ago and you had some concerns about
such an approach although I don't recall exactly what they were. I maintain that this heuristic is reasonable, has no drawbacks and has a potential to make some optimisations or errata workarounds easier. Also we can collect data about systems affected to see what their firmware does -- R4000SC/R4400SC DECstations definitely get CP0.Config.K0 right.
I'm fairly sure it gets k0 right - otherwise it'd likely not work at all!
My reservations may have been about userland reading /proc/cpuinfo and looking at the CPU type. Some software may know how to handle the PC/SC variants but not the MC versions. But this seems to be a fairly weak concern - and I trust you checked gcc's parsing of /proc/cpuinfo.
Ralf
Quoted 4 lines · Ralf Baechle
My reservations may have been about userland reading
/proc/cpuinfoand looking at the CPU type. Some software may know how to handle the PC/SC variants but not the MC versions. But this seems to be a fairly weak concern - and I trust you checked gcc's parsing of/proc/cpuinfo.
Actually I wasn't actually aware GCC's got /proc/cpuinfo-based native
arch support for the MIPS target these days, thanks for the hint.
I have now checked the relevant source file and support is pretty weak
there, only half a dozen processors are recognised and no R4k model is among them. In any case strstr is used to check for matches there so I'd expect strings like "R4000" or "R4400" without a further suffix to be chosen.
Maciej
Quoted 5 lines · Maciej W. Rozycki
Quoted 4 lines
My reservations may have been about userland reading
/proc/cpuinfoand looking at the CPU type. Some software may know how to handle the PC/SC variants but not the MC versions. But this seems to be a fairly weak concern - and I trust you checked gcc's parsing of/proc/cpuinfo.
Quoted 8 lines
Actually I wasn't actually aware GCC's got
/proc/cpuinfo-basednative
arch support for the MIPS target these days, thanks for the hint.I have now checked the relevant source file and support is pretty weak
there, only half a dozen processors are recognised and no R4k model is among them. In any case strstr is used to check for matches there so I'd expect strings like "R4000" or "R4400" without a further suffix to be chosen.
It'd be worth a change in particular for users how higher end CPUs and enhanced ISAs such as Octeons.
Or should we just default to O32 w/ MIPS I + LL/SC as the MIPS Esperanto forever ...
Ralf