Skip to content

Commit 1c00460

Browse files
committed
LoongArch: Consolidate CPU names in /proc/cpuinfo
Some processors have no IOCSR.VENDOR and IOCSR.CPUNAME, some processors have these registers but there is no valid information. Consolidate CPU names in /proc/cpuinfo: 1. Add "PRID" to display the PRID & Core-Name; 2. Let "Model Name" display "Unknown" if no valid name. Signed-off-by: Huacai Chen <[email protected]>
1 parent 20d7338 commit 1c00460

File tree

3 files changed

+34
-23
lines changed

3 files changed

+34
-23
lines changed

arch/loongarch/include/asm/cpu.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,27 @@ enum cpu_type_enum {
5555
CPU_LAST
5656
};
5757

58+
static inline char *id_to_core_name(unsigned int id)
59+
{
60+
if ((id & PRID_COMP_MASK) != PRID_COMP_LOONGSON)
61+
return "Unknown";
62+
63+
switch (id & PRID_SERIES_MASK) {
64+
case PRID_SERIES_LA132:
65+
return "LA132";
66+
case PRID_SERIES_LA264:
67+
return "LA264";
68+
case PRID_SERIES_LA364:
69+
return "LA364";
70+
case PRID_SERIES_LA464:
71+
return "LA464";
72+
case PRID_SERIES_LA664:
73+
return "LA664";
74+
default:
75+
return "Unknown";
76+
}
77+
}
78+
5879
#endif /* !__ASSEMBLER__ */
5980

6081
/*

arch/loongarch/kernel/cpu-probe.c

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ static inline void cpu_probe_loongson(struct cpuinfo_loongarch *c, unsigned int
277277
uint32_t config;
278278
uint64_t *vendor = (void *)(&cpu_full_name[VENDOR_OFFSET]);
279279
uint64_t *cpuname = (void *)(&cpu_full_name[CPUNAME_OFFSET]);
280-
const char *core_name = "Unknown";
280+
const char *core_name = id_to_core_name(c->processor_id);
281281

282282
switch (BIT(fls(c->isa_level) - 1)) {
283283
case LOONGARCH_CPU_ISA_LA32R:
@@ -291,35 +291,23 @@ static inline void cpu_probe_loongson(struct cpuinfo_loongarch *c, unsigned int
291291
break;
292292
}
293293

294-
switch (c->processor_id & PRID_SERIES_MASK) {
295-
case PRID_SERIES_LA132:
296-
core_name = "LA132";
297-
break;
298-
case PRID_SERIES_LA264:
299-
core_name = "LA264";
300-
break;
301-
case PRID_SERIES_LA364:
302-
core_name = "LA364";
303-
break;
304-
case PRID_SERIES_LA464:
305-
core_name = "LA464";
306-
break;
307-
case PRID_SERIES_LA664:
308-
core_name = "LA664";
309-
break;
310-
}
311-
312294
pr_info("%s Processor probed (%s Core)\n", __cpu_family[cpu], core_name);
313295

314-
if (!cpu_has_iocsr)
296+
if (!cpu_has_iocsr) {
297+
__cpu_full_name[cpu] = "Unknown";
315298
return;
316-
317-
if (!__cpu_full_name[cpu])
318-
__cpu_full_name[cpu] = cpu_full_name;
299+
}
319300

320301
*vendor = iocsr_read64(LOONGARCH_IOCSR_VENDOR);
321302
*cpuname = iocsr_read64(LOONGARCH_IOCSR_CPUNAME);
322303

304+
if (!__cpu_full_name[cpu]) {
305+
if (((char *)vendor)[0] == 0)
306+
__cpu_full_name[cpu] = "Unknown";
307+
else
308+
__cpu_full_name[cpu] = cpu_full_name;
309+
}
310+
323311
config = iocsr_read32(LOONGARCH_IOCSR_FEATURES);
324312
if (config & IOCSRF_CSRIPI)
325313
c->options |= LOONGARCH_CPU_CSRIPI;

arch/loongarch/kernel/proc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ static int show_cpuinfo(struct seq_file *m, void *v)
1717
{
1818
unsigned long n = (unsigned long) v - 1;
1919
unsigned int isa = cpu_data[n].isa_level;
20+
unsigned int prid = cpu_data[n].processor_id;
2021
unsigned int version = cpu_data[n].processor_id & 0xff;
2122
unsigned int fp_version = cpu_data[n].fpu_vers;
2223

@@ -37,6 +38,7 @@ static int show_cpuinfo(struct seq_file *m, void *v)
3738
seq_printf(m, "global_id\t\t: %d\n", cpu_data[n].global_id);
3839
seq_printf(m, "CPU Family\t\t: %s\n", __cpu_family[n]);
3940
seq_printf(m, "Model Name\t\t: %s\n", __cpu_full_name[n]);
41+
seq_printf(m, "PRID\t\t\t: %s (%08x)\n", id_to_core_name(prid), prid);
4042
seq_printf(m, "CPU Revision\t\t: 0x%02x\n", version);
4143
seq_printf(m, "FPU Revision\t\t: 0x%02x\n", fp_version);
4244
seq_printf(m, "CPU MHz\t\t\t: %llu.%02llu\n",

0 commit comments

Comments
 (0)