Skip to content

Commit 4c540c9

Browse files
RISC-V: Add mvendorid, marchid, and mimpid to /proc/cpuinfo output
I'm merging this in as a single commit as it's a dependency for some other work. * commit '3baca1a4d490484fcd555413f1fec85b2e071912': RISC-V: Add mvendorid, marchid, and mimpid to /proc/cpuinfo output
2 parents 8aeb7b1 + 3baca1a commit 4c540c9

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

arch/riscv/kernel/cpu.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
* Copyright (C) 2012 Regents of the University of California
44
*/
55

6+
#include <linux/cpu.h>
67
#include <linux/init.h>
78
#include <linux/seq_file.h>
89
#include <linux/of.h>
10+
#include <asm/csr.h>
911
#include <asm/hwcap.h>
12+
#include <asm/sbi.h>
1013
#include <asm/smp.h>
1114
#include <asm/pgtable.h>
1215

@@ -68,6 +71,50 @@ int riscv_of_parent_hartid(struct device_node *node, unsigned long *hartid)
6871
}
6972

7073
#ifdef CONFIG_PROC_FS
74+
75+
struct riscv_cpuinfo {
76+
unsigned long mvendorid;
77+
unsigned long marchid;
78+
unsigned long mimpid;
79+
};
80+
static DEFINE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo);
81+
82+
static int riscv_cpuinfo_starting(unsigned int cpu)
83+
{
84+
struct riscv_cpuinfo *ci = this_cpu_ptr(&riscv_cpuinfo);
85+
86+
#if IS_ENABLED(CONFIG_RISCV_SBI)
87+
ci->mvendorid = sbi_spec_is_0_1() ? 0 : sbi_get_mvendorid();
88+
ci->marchid = sbi_spec_is_0_1() ? 0 : sbi_get_marchid();
89+
ci->mimpid = sbi_spec_is_0_1() ? 0 : sbi_get_mimpid();
90+
#elif IS_ENABLED(CONFIG_RISCV_M_MODE)
91+
ci->mvendorid = csr_read(CSR_MVENDORID);
92+
ci->marchid = csr_read(CSR_MARCHID);
93+
ci->mimpid = csr_read(CSR_MIMPID);
94+
#else
95+
ci->mvendorid = 0;
96+
ci->marchid = 0;
97+
ci->mimpid = 0;
98+
#endif
99+
100+
return 0;
101+
}
102+
103+
static int __init riscv_cpuinfo_init(void)
104+
{
105+
int ret;
106+
107+
ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "riscv/cpuinfo:starting",
108+
riscv_cpuinfo_starting, NULL);
109+
if (ret < 0) {
110+
pr_err("cpuinfo: failed to register hotplug callbacks.\n");
111+
return ret;
112+
}
113+
114+
return 0;
115+
}
116+
device_initcall(riscv_cpuinfo_init);
117+
71118
#define __RISCV_ISA_EXT_DATA(UPROP, EXTID) \
72119
{ \
73120
.uprop = #UPROP, \
@@ -185,6 +232,7 @@ static int c_show(struct seq_file *m, void *v)
185232
{
186233
unsigned long cpu_id = (unsigned long)v - 1;
187234
struct device_node *node = of_get_cpu_node(cpu_id, NULL);
235+
struct riscv_cpuinfo *ci = per_cpu_ptr(&riscv_cpuinfo, cpu_id);
188236
const char *compat, *isa;
189237

190238
seq_printf(m, "processor\t: %lu\n", cpu_id);
@@ -195,6 +243,9 @@ static int c_show(struct seq_file *m, void *v)
195243
if (!of_property_read_string(node, "compatible", &compat)
196244
&& strcmp(compat, "riscv"))
197245
seq_printf(m, "uarch\t\t: %s\n", compat);
246+
seq_printf(m, "mvendorid\t: 0x%lx\n", ci->mvendorid);
247+
seq_printf(m, "marchid\t\t: 0x%lx\n", ci->marchid);
248+
seq_printf(m, "mimpid\t\t: 0x%lx\n", ci->mimpid);
198249
seq_puts(m, "\n");
199250
of_node_put(node);
200251

0 commit comments

Comments
 (0)