linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] LoongArch: Use a fallback CPU model when IOCSR-based model probing fails
@ 2025-04-30  5:40 Yao Zi
  2025-04-30  7:48 ` Huacai Chen
  0 siblings, 1 reply; 3+ messages in thread
From: Yao Zi @ 2025-04-30  5:40 UTC (permalink / raw)
  To: Huacai Chen, WANG Xuerui, Thomas Gleixner, Tianyang Zhang,
	Jiaxun Yang, Jianmin Lv
  Cc: loongarch, linux-kernel, Mingcong Bai, Kexy Biscuit, 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.

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.

Signed-off-by: Yao Zi <ziyao@disroot.org>
---
 arch/loongarch/kernel/cpu-probe.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/loongarch/kernel/cpu-probe.c b/arch/loongarch/kernel/cpu-probe.c
index fedaa67cde41..785513d43696 100644
--- a/arch/loongarch/kernel/cpu-probe.c
+++ b/arch/loongarch/kernel/cpu-probe.c
@@ -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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] LoongArch: Use a fallback CPU model when IOCSR-based model probing fails
  2025-04-30  5:40 [PATCH] LoongArch: Use a fallback CPU model when IOCSR-based model probing fails Yao Zi
@ 2025-04-30  7:48 ` Huacai Chen
  2025-05-01  1:04   ` Yao Zi
  0 siblings, 1 reply; 3+ messages in thread
From: Huacai Chen @ 2025-04-30  7:48 UTC (permalink / raw)
  To: Yao Zi
  Cc: WANG Xuerui, Thomas Gleixner, Tianyang Zhang, Jiaxun Yang,
	Jianmin Lv, loongarch, linux-kernel, Mingcong Bai, Kexy Biscuit

Hi, Yao Zi,

On Wed, Apr 30, 2025 at 1:41 PM Yao Zi <ziyao@disroot.org> wrote:
>
> 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

>
> 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.
>
> Signed-off-by: Yao Zi <ziyao@disroot.org>
> ---
>  arch/loongarch/kernel/cpu-probe.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/arch/loongarch/kernel/cpu-probe.c b/arch/loongarch/kernel/cpu-probe.c
> index fedaa67cde41..785513d43696 100644
> --- a/arch/loongarch/kernel/cpu-probe.c
> +++ b/arch/loongarch/kernel/cpu-probe.c
> @@ -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
>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] LoongArch: Use a fallback CPU model when IOCSR-based model probing fails
  2025-04-30  7:48 ` Huacai Chen
@ 2025-05-01  1:04   ` Yao Zi
  0 siblings, 0 replies; 3+ messages in thread
From: Yao Zi @ 2025-05-01  1:04 UTC (permalink / raw)
  To: Huacai Chen
  Cc: WANG Xuerui, Thomas Gleixner, Tianyang Zhang, Jiaxun Yang,
	Jianmin Lv, loongarch, linux-kernel, Mingcong Bai, Kexy Biscuit

On Wed, Apr 30, 2025 at 03:48:25PM +0800, Huacai Chen wrote:
> Hi, Yao Zi,
> 
> On Wed, Apr 30, 2025 at 1:41 PM Yao Zi <ziyao@disroot.org> wrote:
> >
> > 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.

> 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

> >
> > 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.
> >
> > Signed-off-by: Yao Zi <ziyao@disroot.org>
> > ---
> >  arch/loongarch/kernel/cpu-probe.c | 7 ++++---
> >  1 file changed, 4 insertions(+), 3 deletions(-)
> >
> > diff --git a/arch/loongarch/kernel/cpu-probe.c b/arch/loongarch/kernel/cpu-probe.c
> > index fedaa67cde41..785513d43696 100644
> > --- a/arch/loongarch/kernel/cpu-probe.c
> > +++ b/arch/loongarch/kernel/cpu-probe.c
> > @@ -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
> >
> >

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-05-01  1:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-30  5:40 [PATCH] LoongArch: Use a fallback CPU model when IOCSR-based model probing fails Yao Zi
2025-04-30  7:48 ` Huacai Chen
2025-05-01  1:04   ` Yao Zi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).