Skip to contentSkip to conversation

LoongArch: Use a fallback CPU model when IOCSR-based model probing fails

PATCH In review Yao Zi 2 participants 3 messages Apr 30, 2025 – May 1, 2025 LoongArch

lore
Share & tools
lore

Yao Zi

author
#0 lore raw

PATCH 1/1 LoongArch: Use a fallback CPU model when IOCSR-based model probing fails

Reading vendor and cpuname IOCSRs yields 0x258000fff00 instead of human-readable model strings on Loongson 2K0300 SoC, which messes up format of /proc/cpuinfo since it represents as an empty string.

Let's consider IOCSR-based model probing fails if the result model is an empty string. A fallback model name is set in such cases.

---
 arch/loongarch/kernel/cpu-probe.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch/loongarch/kernel/cpu-probe.c +4 -3
index fedaa67cde41..785513d43696 100644
@@ -270,12 +270,13 @@ static inline void cpu_probe_loongson(struct cpuinfo_loongarch *c, unsigned int
 	if (!cpu_has_iocsr)
 		return;
 
-	if (!__cpu_full_name[cpu])
-		__cpu_full_name[cpu] = cpu_full_name;
-
 	*vendor = iocsr_read64(LOONGARCH_IOCSR_VENDOR);
 	*cpuname = iocsr_read64(LOONGARCH_IOCSR_CPUNAME);
 
+	if (!__cpu_full_name[cpu])
+		__cpu_full_name[cpu] = cpu_full_name[0] ? cpu_full_name :
+							  "Loongson-Unknown";
+
 	config = iocsr_read32(LOONGARCH_IOCSR_FEATURES);
 	if (config & IOCSRF_CSRIPI)
 		c->options |= LOONGARCH_CPU_CSRIPI;
Signature · 1 line
2.49.0
maintainer
#1 lore raw

Hi, Yao Zi,

Quoted 4 lines · Yao Zi

Reading vendor and cpuname IOCSRs yields 0x258000fff00 instead of human-readable model strings on Loongson 2K0300 SoC, which messes up format of /proc/cpuinfo since it represents as an empty string.

CPUNAME IOCSR is filled by firmware and readed by kernel. If you read some garbage, that means you need to modify your firmware.

And if there is completely no CPUNAME register, you need to fill it by FDT, see init_cpu_fullname() in arch/loongarch/kernel/env.c.

Huacai

Quoted 34 lines

Let's consider IOCSR-based model probing fails if the result model is an empty string. A fallback model name is set in such cases.

---
 arch/loongarch/kernel/cpu-probe.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch/loongarch/kernel/cpu-probe.c +4 -4
index fedaa67cde41..785513d43696 100644
@@ -270,12 +270,13 @@ static inline void cpu_probe_loongson(struct cpuinfo_loongarch *c, unsigned int
        if (!cpu_has_iocsr)
                return;
 
-       if (!__cpu_full_name[cpu])
-               __cpu_full_name[cpu] = cpu_full_name;
-
        *vendor = iocsr_read64(LOONGARCH_IOCSR_VENDOR);
        *cpuname = iocsr_read64(LOONGARCH_IOCSR_CPUNAME);
 
+       if (!__cpu_full_name[cpu])
+               __cpu_full_name[cpu] = cpu_full_name[0] ? cpu_full_name :
+                                                         "Loongson-Unknown";
+
        config = iocsr_read32(LOONGARCH_IOCSR_FEATURES);
        if (config & IOCSRF_CSRIPI)
                c->options |= LOONGARCH_CPU_CSRIPI;
--

2.49.0

author
#2 lore raw
Quoted 9 lines · Huacai Chen

Hi, Yao Zi,

Quoted 4 lines · Yao Zi

Reading vendor and cpuname IOCSRs yields 0x258000fff00 instead of human-readable model strings on Loongson 2K0300 SoC, which messes up format of /proc/cpuinfo since it represents as an empty string.

CPUNAME IOCSR is filled by firmware and readed by kernel. If you read some garbage, that means you need to modify your firmware.

Thanks for the hint, I'll take a look in my firmware instead.

Quoted 4 lines

And if there is completely no CPUNAME register, you need to fill it by FDT, see init_cpu_fullname() in arch/loongarch/kernel/env.c.

Huacai

Best regards,
Yao Zi

Quoted 34 lines
Quoted 34 lines

Let's consider IOCSR-based model probing fails if the result model is an empty string. A fallback model name is set in such cases.

---
 arch/loongarch/kernel/cpu-probe.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch/loongarch/kernel/cpu-probe.c +4 -4
index fedaa67cde41..785513d43696 100644
@@ -270,12 +270,13 @@ static inline void cpu_probe_loongson(struct cpuinfo_loongarch *c, unsigned int
        if (!cpu_has_iocsr)
                return;
 
-       if (!__cpu_full_name[cpu])
-               __cpu_full_name[cpu] = cpu_full_name;
-
        *vendor = iocsr_read64(LOONGARCH_IOCSR_VENDOR);
        *cpuname = iocsr_read64(LOONGARCH_IOCSR_CPUNAME);
 
+       if (!__cpu_full_name[cpu])
+               __cpu_full_name[cpu] = cpu_full_name[0] ? cpu_full_name :
+                                                         "Loongson-Unknown";
+
        config = iocsr_read32(LOONGARCH_IOCSR_FEATURES);
        if (config & IOCSRF_CSRIPI)
                c->options |= LOONGARCH_CPU_CSRIPI;
--

2.49.0