Skip to contentSkip to conversation

RISC-V: Add mvendorid, marchid, and mimpid to /proc/cpuinfo output

PATCH Superseded Anup Patel 6 participants 8 messages Jun 20, 2022 – Jul 26, 2022 RISC-V

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Anup Patel

author
#0 lore raw

PATCH 1/1 RISC-V: Add mvendorid, marchid, and mimpid to /proc/cpuinfo output

Identifying the underlying RISC-V implementation can be important for some of the user space applications. For example, the perf tool uses arch specific CPU implementation id (i.e. CPUID) to select a JSON file describing custom perf events on a CPU.

Currently, there is no way to identify RISC-V implementation so we add mvendorid, marchid, and mimpid to /proc/cpuinfo output.

---
 arch/riscv/kernel/cpu.c | 51 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
arch/riscv/kernel/cpu.c +51 -0
index fba9e9f46a8c..c037b8691bbb 100644
@@ -3,10 +3,13 @@
  * Copyright (C) 2012 Regents of the University of California
  */
 
+#include <linux/cpu.h>
 #include <linux/init.h>
 #include <linux/seq_file.h>
 #include <linux/of.h>
+#include <asm/csr.h>
 #include <asm/hwcap.h>
+#include <asm/sbi.h>
 #include <asm/smp.h>
 #include <asm/pgtable.h>
 
@@ -64,6 +67,50 @@ int riscv_of_parent_hartid(struct device_node *node)
 }
 
 #ifdef CONFIG_PROC_FS
+
+struct riscv_cpuinfo {
+	unsigned long mvendorid;
+	unsigned long marchid;
+	unsigned long mimpid;
+};
+static DEFINE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo);
+
+static int riscv_cpuinfo_starting(unsigned int cpu)
+{
+	struct riscv_cpuinfo *ci = this_cpu_ptr(&riscv_cpuinfo);
+
+#if defined(CONFIG_RISCV_SBI)
+	ci->mvendorid = sbi_spec_is_0_1() ? 0 : sbi_get_mvendorid();
+	ci->marchid = sbi_spec_is_0_1() ? 0 : sbi_get_marchid();
+	ci->mimpid = sbi_spec_is_0_1() ? 0 : sbi_get_mimpid();
+#elif defined(CONFIG_RISCV_M_MODE)
+	ci->mvendorid = csr_read(CSR_MVENDORID);
+	ci->marchid = csr_read(CSR_MARCHID);
+	ci->mimpid = csr_read(CSR_MIMPID);
+#else
+	ci->mvendorid = 0;
+	ci->marchid = 0;
+	ci->mimpid = 0;
+#endif
+
+	return 0;
+}
+
+static int __init riscv_cpuinfo_init(void)
+{
+	int ret;
+
+	ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "riscv/cpuinfo:starting",
+				riscv_cpuinfo_starting, NULL);
+	if (ret < 0) {
+		pr_err("cpuinfo: failed to register hotplug callbacks.\n");
+		return ret;
+	}
+
+	return 0;
+}
+device_initcall(riscv_cpuinfo_init);
+
 #define __RISCV_ISA_EXT_DATA(UPROP, EXTID) \
 	{							\
 		.uprop = #UPROP,				\
@@ -178,6 +225,7 @@ static int c_show(struct seq_file *m, void *v)
 {
 	unsigned long cpu_id = (unsigned long)v - 1;
 	struct device_node *node = of_get_cpu_node(cpu_id, NULL);
+	struct riscv_cpuinfo *ci = per_cpu_ptr(&riscv_cpuinfo, cpu_id);
 	const char *compat, *isa;
 
 	seq_printf(m, "processor\t: %lu\n", cpu_id);
@@ -188,6 +236,9 @@ static int c_show(struct seq_file *m, void *v)
 	if (!of_property_read_string(node, "compatible", &compat)
 	    && strcmp(compat, "riscv"))
 		seq_printf(m, "uarch\t\t: %s\n", compat);
+	seq_printf(m, "mvendorid\t: 0x%lx\n", ci->mvendorid);
+	seq_printf(m, "marchid\t\t: 0x%lx\n", ci->marchid);
+	seq_printf(m, "mimpid\t\t: 0x%lx\n", ci->mimpid);
 	seq_puts(m, "\n");
 	of_node_put(node);
 
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Anup Patel

Identifying the underlying RISC-V implementation can be important for some of the user space applications. For example, the perf tool uses arch specific CPU implementation id (i.e. CPUID) to select a JSON file describing custom perf events on a CPU.

Currently, there is no way to identify RISC-V implementation so we add mvendorid, marchid, and mimpid to /proc/cpuinfo output.

Looks good to me. I only tested on QEMU where all values default to 0.

Quoted 82 lines
---
  arch/riscv/kernel/cpu.c | 51 +++++++++++++++++++++++++++++++++++++++++
  1 file changed, 51 insertions(+)
arch/riscv/kernel/cpu.c +48 -0
index fba9e9f46a8c..c037b8691bbb 100644
@@ -3,10 +3,13 @@
   * Copyright (C) 2012 Regents of the University of California
   */
 
+#include <linux/cpu.h>
  #include <linux/init.h>
  #include <linux/seq_file.h>
  #include <linux/of.h>
+#include <asm/csr.h>
  #include <asm/hwcap.h>
+#include <asm/sbi.h>
  #include <asm/smp.h>
  #include <asm/pgtable.h>
 
@@ -64,6 +67,50 @@ int riscv_of_parent_hartid(struct device_node *node)
  }
 
  #ifdef CONFIG_PROC_FS
+
+struct riscv_cpuinfo {
+	unsigned long mvendorid;
+	unsigned long marchid;
+	unsigned long mimpid;
+};
+static DEFINE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo);
+
+static int riscv_cpuinfo_starting(unsigned int cpu)
+{
+	struct riscv_cpuinfo *ci = this_cpu_ptr(&riscv_cpuinfo);
+
+#if defined(CONFIG_RISCV_SBI)
+	ci->mvendorid = sbi_spec_is_0_1() ? 0 : sbi_get_mvendorid();
+	ci->marchid = sbi_spec_is_0_1() ? 0 : sbi_get_marchid();
+	ci->mimpid = sbi_spec_is_0_1() ? 0 : sbi_get_mimpid();
+#elif defined(CONFIG_RISCV_M_MODE)
+	ci->mvendorid = csr_read(CSR_MVENDORID);
+	ci->marchid = csr_read(CSR_MARCHID);
+	ci->mimpid = csr_read(CSR_MIMPID);
+#else
+	ci->mvendorid = 0;
+	ci->marchid = 0;
+	ci->mimpid = 0;
+#endif
+
+	return 0;
+}
+
+static int __init riscv_cpuinfo_init(void)
+{
+	int ret;
+
+	ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "riscv/cpuinfo:starting",
+				riscv_cpuinfo_starting, NULL);
+	if (ret < 0) {
+		pr_err("cpuinfo: failed to register hotplug callbacks.\n");
+		return ret;
+	}
+
+	return 0;
+}
+device_initcall(riscv_cpuinfo_init);
+
  #define __RISCV_ISA_EXT_DATA(UPROP, EXTID) \
  	{							\
  		.uprop = #UPROP,				\
@@ -178,6 +225,7 @@ static int c_show(struct seq_file *m, void *v)
  {
  	unsigned long cpu_id = (unsigned long)v - 1;
  	struct device_node *node = of_get_cpu_node(cpu_id, NULL);
+	struct riscv_cpuinfo *ci = per_cpu_ptr(&riscv_cpuinfo, cpu_id);
  	const char *compat, *isa;
 
  	seq_printf(m, "processor\t: %lu\n", cpu_id);

arch/riscv/kernel/cpu.c static int c_show(struct seq_file *m, void *v) · line 244

Quoted 9 lines
arch/riscv/kernel/cpu.c +3 -0
@@ -188,6 +236,9 @@ static int c_show(struct seq_file *m, void *v)
  	if (!of_property_read_string(node, "compatible", &compat)
  	    && strcmp(compat, "riscv"))
  		seq_printf(m, "uarch\t\t: %s\n", compat);
+	seq_printf(m, "mvendorid\t: 0x%lx\n", ci->mvendorid);
+	seq_printf(m, "marchid\t\t: 0x%lx\n", ci->marchid);
+	seq_printf(m, "mimpid\t\t: 0x%lx\n", ci->mimpid);
  	seq_puts(m, "\n");
  	of_node_put(node);
 

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#2 lore raw
In reply to Anup Patel

Hey Anup,
Tested it & got back the (sadly boring) 0s that are set in my hardware.

Two comments below.

Thanks,
Conor.

Quoted 38 lines · Anup Patel

Identifying the underlying RISC-V implementation can be important for some of the user space applications. For example, the perf tool uses arch specific CPU implementation id (i.e. CPUID) to select a JSON file describing custom perf events on a CPU.

Currently, there is no way to identify RISC-V implementation so we add mvendorid, marchid, and mimpid to /proc/cpuinfo output.

---
 arch/riscv/kernel/cpu.c | 51 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
arch/riscv/kernel/cpu.c +6 -0
index fba9e9f46a8c..c037b8691bbb 100644
@@ -3,10 +3,13 @@
  * Copyright (C) 2012 Regents of the University of California
  */
 
+#include <linux/cpu.h>
 #include <linux/init.h>
 #include <linux/seq_file.h>
 #include <linux/of.h>
+#include <asm/csr.h>
 #include <asm/hwcap.h>
+#include <asm/sbi.h>
 #include <asm/smp.h>
 #include <asm/pgtable.h>
 
@@ -64,6 +67,50 @@ int riscv_of_parent_hartid(struct device_node *node)
 }
 
 #ifdef CONFIG_PROC_FS
+
+struct riscv_cpuinfo {
+	unsigned long mvendorid;

arch/riscv/kernel/cpu.c int riscv_of_parent_hartid(struct device_node *node) · line 82

Quoted 10 lines
arch/riscv/kernel/cpu.c +10 -0
+	unsigned long marchid;
+	unsigned long mimpid;
+};
+static DEFINE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo);
+
+static int riscv_cpuinfo_starting(unsigned int cpu)
+{
+	struct riscv_cpuinfo *ci = this_cpu_ptr(&riscv_cpuinfo);
+
+#if defined(CONFIG_RISCV_SBI)

This should be #if IS_ENABLED(CONFIG_RISCV_SBI) to match the other users

arch/riscv/kernel/cpu.c int riscv_of_parent_hartid(struct device_node *node) · line 86

Quoted 4 lines
arch/riscv/kernel/cpu.c +4 -0
+	ci->mvendorid = sbi_spec_is_0_1() ? 0 : sbi_get_mvendorid();
+	ci->marchid = sbi_spec_is_0_1() ? 0 : sbi_get_marchid();
+	ci->mimpid = sbi_spec_is_0_1() ? 0 : sbi_get_mimpid();
+#elif defined(CONFIG_RISCV_M_MODE)

Ditto

Quoted 48 lines
arch/riscv/kernel/cpu.c +31 -0
+	ci->mvendorid = csr_read(CSR_MVENDORID);
+	ci->marchid = csr_read(CSR_MARCHID);
+	ci->mimpid = csr_read(CSR_MIMPID);
+#else
+	ci->mvendorid = 0;
+	ci->marchid = 0;
+	ci->mimpid = 0;
+#endif
+
+	return 0;
+}
+
+static int __init riscv_cpuinfo_init(void)
+{
+	int ret;
+
+	ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "riscv/cpuinfo:starting",
+				riscv_cpuinfo_starting, NULL);
+	if (ret < 0) {
+		pr_err("cpuinfo: failed to register hotplug callbacks.\n");
+		return ret;
+	}
+
+	return 0;
+}
+device_initcall(riscv_cpuinfo_init);
+
 #define __RISCV_ISA_EXT_DATA(UPROP, EXTID) \
 	{							\
 		.uprop = #UPROP,				\
@@ -178,6 +225,7 @@ static int c_show(struct seq_file *m, void *v)
 {
 	unsigned long cpu_id = (unsigned long)v - 1;
 	struct device_node *node = of_get_cpu_node(cpu_id, NULL);
+	struct riscv_cpuinfo *ci = per_cpu_ptr(&riscv_cpuinfo, cpu_id);
 	const char *compat, *isa;
 
 	seq_printf(m, "processor\t: %lu\n", cpu_id);
@@ -188,6 +236,9 @@ static int c_show(struct seq_file *m, void *v)
 	if (!of_property_read_string(node, "compatible", &compat)
 	    && strcmp(compat, "riscv"))
 		seq_printf(m, "uarch\t\t: %s\n", compat);
+	seq_printf(m, "mvendorid\t: 0x%lx\n", ci->mvendorid);
+	seq_printf(m, "marchid\t\t: 0x%lx\n", ci->marchid);
+	seq_printf(m, "mimpid\t\t: 0x%lx\n", ci->mimpid);
 	seq_puts(m, "\n");
 	of_node_put(node);
 
Tested-by on v1 1/1
#3 lore raw
In reply to Anup Patel

Hello Anup!

Quoted 7 lines · On Mon, 20 Jun 2022 17:25:49 +0530 Anup Patel <[email protected]> wrote:

Identifying the underlying RISC-V implementation can be important for some of the user space applications. For example, the perf tool uses arch specific CPU implementation id (i.e. CPUID) to select a JSON file describing custom perf events on a CPU.

Currently, there is no way to identify RISC-V implementation so we add mvendorid, marchid, and mimpid to /proc/cpuinfo output.

Tested on Sifive Unmatched:

localhost / # cat /proc/cpuinfo
processor : 0
hart : 4
isa : rv64imafdc
mmu : sv39
uarch : sifive,bullet0
mvendorid : 0x489
marchid : 0x8000000000000007
mimpid : 0x20181004

processor : 1
hart : 1
isa : rv64imafdc
mmu : sv39
uarch : sifive,bullet0
mvendorid : 0x489
marchid : 0x8000000000000007
mimpid : 0x20181004

processor : 2
hart : 2
isa : rv64imafdc
mmu : sv39
uarch : sifive,bullet0
mvendorid : 0x489
marchid : 0x8000000000000007
mimpid : 0x20181004

processor : 3
hart : 3
isa : rv64imafdc
mmu : sv39
uarch : sifive,bullet0
mvendorid : 0x489
marchid : 0x8000000000000007
mimpid : 0x20181004

mvendorid, marchid values match the register description in u74 manual.

mimpid seems to be ok, through i can't find exact in U74/Unmatched docs.

Quoted 87 lines
---
 arch/riscv/kernel/cpu.c | 51

+++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)

arch/riscv/kernel/cpu.c +47 -0
index fba9e9f46a8c..c037b8691bbb 100644
@@ -3,10 +3,13 @@
  * Copyright (C) 2012 Regents of the University of California
  */
 
+#include <linux/cpu.h>
 #include <linux/init.h>
 #include <linux/seq_file.h>
 #include <linux/of.h>
+#include <asm/csr.h>
 #include <asm/hwcap.h>
+#include <asm/sbi.h>
 #include <asm/smp.h>
 #include <asm/pgtable.h>
 
@@ -64,6 +67,50 @@ int riscv_of_parent_hartid(struct device_node
 *node) }
 
 #ifdef CONFIG_PROC_FS
+
+struct riscv_cpuinfo {
+	unsigned long mvendorid;
+	unsigned long marchid;
+	unsigned long mimpid;
+};
+static DEFINE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo);
+
+static int riscv_cpuinfo_starting(unsigned int cpu)
+{
+	struct riscv_cpuinfo *ci = this_cpu_ptr(&riscv_cpuinfo);
+
+#if defined(CONFIG_RISCV_SBI)
+	ci->mvendorid = sbi_spec_is_0_1() ? 0 : sbi_get_mvendorid();
+	ci->marchid = sbi_spec_is_0_1() ? 0 : sbi_get_marchid();
+	ci->mimpid = sbi_spec_is_0_1() ? 0 : sbi_get_mimpid();
+#elif defined(CONFIG_RISCV_M_MODE)
+	ci->mvendorid = csr_read(CSR_MVENDORID);
+	ci->marchid = csr_read(CSR_MARCHID);
+	ci->mimpid = csr_read(CSR_MIMPID);
+#else
+	ci->mvendorid = 0;
+	ci->marchid = 0;
+	ci->mimpid = 0;
+#endif
+
+	return 0;
+}
+
+static int __init riscv_cpuinfo_init(void)
+{
+	int ret;
+
+	ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
 "riscv/cpuinfo:starting",
+				riscv_cpuinfo_starting, NULL);
+	if (ret < 0) {
+		pr_err("cpuinfo: failed to register hotplug
 callbacks.\n");
+		return ret;
+	}
+
+	return 0;
+}
+device_initcall(riscv_cpuinfo_init);
+
 #define __RISCV_ISA_EXT_DATA(UPROP, EXTID) \
arch/riscv/kernel/cpu.c +1 -0
 	{							\
 		.uprop = #UPROP,				\
@@ -178,6 +225,7 @@ static int c_show(struct seq_file *m, void *v)
 {
 	unsigned long cpu_id = (unsigned long)v - 1;
 	struct device_node *node = of_get_cpu_node(cpu_id, NULL);
+	struct riscv_cpuinfo *ci = per_cpu_ptr(&riscv_cpuinfo,
 cpu_id); const char *compat, *isa;
 
 	seq_printf(m, "processor\t: %lu\n", cpu_id);

arch/riscv/kernel/cpu.c static int c_show(struct seq_file *m, void *v) · line 244

Quoted 9 lines
arch/riscv/kernel/cpu.c +3 -0
@@ -188,6 +236,9 @@ static int c_show(struct seq_file *m, void *v)
 	if (!of_property_read_string(node, "compatible", &compat)
 	    && strcmp(compat, "riscv"))
 		seq_printf(m, "uarch\t\t: %s\n", compat);
+	seq_printf(m, "mvendorid\t: 0x%lx\n", ci->mvendorid);
+	seq_printf(m, "marchid\t\t: 0x%lx\n", ci->marchid);
+	seq_printf(m, "mimpid\t\t: 0x%lx\n", ci->mimpid);
 	seq_puts(m, "\n");
 	of_node_put(node);
 

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#4 lore raw
Quoted 53 lines · Nikita Shubin

Hello Anup!

Quoted 7 lines · On Mon, 20 Jun 2022 17:25:49 +0530 Anup Patel <[email protected]> wrote:

Identifying the underlying RISC-V implementation can be important for some of the user space applications. For example, the perf tool uses arch specific CPU implementation id (i.e. CPUID) to select a JSON file describing custom perf events on a CPU.

Currently, there is no way to identify RISC-V implementation so we add mvendorid, marchid, and mimpid to /proc/cpuinfo output.

Tested on Sifive Unmatched:

localhost / # cat /proc/cpuinfo
processor : 0
hart : 4
isa : rv64imafdc
mmu : sv39
uarch : sifive,bullet0
mvendorid : 0x489
marchid : 0x8000000000000007
mimpid : 0x20181004

processor : 1
hart : 1
isa : rv64imafdc
mmu : sv39
uarch : sifive,bullet0
mvendorid : 0x489
marchid : 0x8000000000000007
mimpid : 0x20181004

processor : 2
hart : 2
isa : rv64imafdc
mmu : sv39
uarch : sifive,bullet0
mvendorid : 0x489
marchid : 0x8000000000000007
mimpid : 0x20181004

processor : 3
hart : 3
isa : rv64imafdc
mmu : sv39
uarch : sifive,bullet0
mvendorid : 0x489
marchid : 0x8000000000000007
mimpid : 0x20181004

Quoted 3 lines

mvendorid, marchid values match the register description in u74 manual.

mimpid seems to be ok, through i can't find exact in U74/Unmatched docs.

SiFive main website -> Products -> Documentation -> U74-MC Core Complex Manual -> Page 274: B.2 Machine Implementation ID Register (mimpid).

This mimpid value is not in the table thus it's most likely not part of a particular U74 generator release. Looking at this value we could assume that U74 cores within FU740 predates the general availability.

Cheers,
david

Quoted 97 lines
Quoted 94 lines
---
 arch/riscv/kernel/cpu.c | 51

+++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)

arch/riscv/kernel/cpu.c +47 -0
index fba9e9f46a8c..c037b8691bbb 100644
@@ -3,10 +3,13 @@
  * Copyright (C) 2012 Regents of the University of California
  */
 
+#include <linux/cpu.h>
 #include <linux/init.h>
 #include <linux/seq_file.h>
 #include <linux/of.h>
+#include <asm/csr.h>
 #include <asm/hwcap.h>
+#include <asm/sbi.h>
 #include <asm/smp.h>
 #include <asm/pgtable.h>
 
@@ -64,6 +67,50 @@ int riscv_of_parent_hartid(struct device_node
 *node) }
 
 #ifdef CONFIG_PROC_FS
+
+struct riscv_cpuinfo {
+     unsigned long mvendorid;
+     unsigned long marchid;
+     unsigned long mimpid;
+};
+static DEFINE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo);
+
+static int riscv_cpuinfo_starting(unsigned int cpu)
+{
+     struct riscv_cpuinfo *ci = this_cpu_ptr(&riscv_cpuinfo);
+
+#if defined(CONFIG_RISCV_SBI)
+     ci->mvendorid = sbi_spec_is_0_1() ? 0 : sbi_get_mvendorid();
+     ci->marchid = sbi_spec_is_0_1() ? 0 : sbi_get_marchid();
+     ci->mimpid = sbi_spec_is_0_1() ? 0 : sbi_get_mimpid();
+#elif defined(CONFIG_RISCV_M_MODE)
+     ci->mvendorid = csr_read(CSR_MVENDORID);
+     ci->marchid = csr_read(CSR_MARCHID);
+     ci->mimpid = csr_read(CSR_MIMPID);
+#else
+     ci->mvendorid = 0;
+     ci->marchid = 0;
+     ci->mimpid = 0;
+#endif
+
+     return 0;
+}
+
+static int __init riscv_cpuinfo_init(void)
+{
+     int ret;
+
+     ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
 "riscv/cpuinfo:starting",
+                             riscv_cpuinfo_starting, NULL);
+     if (ret < 0) {
+             pr_err("cpuinfo: failed to register hotplug
 callbacks.\n");
+             return ret;
+     }
+
+     return 0;
+}
+device_initcall(riscv_cpuinfo_init);
+
 #define __RISCV_ISA_EXT_DATA(UPROP, EXTID) \
      {                                                       \
              .uprop = #UPROP,                                \
arch/riscv/kernel/cpu.c +4 -0
@@ -178,6 +225,7 @@ static int c_show(struct seq_file *m, void *v)
 {
      unsigned long cpu_id = (unsigned long)v - 1;
      struct device_node *node = of_get_cpu_node(cpu_id, NULL);
+     struct riscv_cpuinfo *ci = per_cpu_ptr(&riscv_cpuinfo,
 cpu_id); const char *compat, *isa;
 
      seq_printf(m, "processor\t: %lu\n", cpu_id);
@@ -188,6 +236,9 @@ static int c_show(struct seq_file *m, void *v)
      if (!of_property_read_string(node, "compatible", &compat)
          && strcmp(compat, "riscv"))
              seq_printf(m, "uarch\t\t: %s\n", compat);
+     seq_printf(m, "mvendorid\t: 0x%lx\n", ci->mvendorid);
+     seq_printf(m, "marchid\t\t: 0x%lx\n", ci->marchid);
+     seq_printf(m, "mimpid\t\t: 0x%lx\n", ci->mimpid);
      seq_puts(m, "\n");
Quoted 8 lines

arch/riscv/kernel/cpu.c static int c_show(struct seq_file *m, void *v) · line 244

Quoted 2 lines
arch/riscv/kernel/cpu.c +0 -0
      of_node_put(node);
 

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#5 lore raw
In reply to Anup Patel

Hi Palmer,

Quoted 10 lines · Anup Patel

Identifying the underlying RISC-V implementation can be important for some of the user space applications. For example, the perf tool uses arch specific CPU implementation id (i.e. CPUID) to select a JSON file describing custom perf events on a CPU.

Currently, there is no way to identify RISC-V implementation so we add mvendorid, marchid, and mimpid to /proc/cpuinfo output.

Can this patch be considered for 5.20 ?

Regards,
Anup

Quoted 94 lines
---
 arch/riscv/kernel/cpu.c | 51 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
arch/riscv/kernel/cpu.c +51 -1
index fba9e9f46a8c..c037b8691bbb 100644
@@ -3,10 +3,13 @@
  * Copyright (C) 2012 Regents of the University of California
  */
 
+#include <linux/cpu.h>
 #include <linux/init.h>
 #include <linux/seq_file.h>
 #include <linux/of.h>
+#include <asm/csr.h>
 #include <asm/hwcap.h>
+#include <asm/sbi.h>
 #include <asm/smp.h>
 #include <asm/pgtable.h>
 
@@ -64,6 +67,50 @@ int riscv_of_parent_hartid(struct device_node *node)
 }
 
 #ifdef CONFIG_PROC_FS
+
+struct riscv_cpuinfo {
+       unsigned long mvendorid;
+       unsigned long marchid;
+       unsigned long mimpid;
+};
+static DEFINE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo);
+
+static int riscv_cpuinfo_starting(unsigned int cpu)
+{
+       struct riscv_cpuinfo *ci = this_cpu_ptr(&riscv_cpuinfo);
+
+#if defined(CONFIG_RISCV_SBI)
+       ci->mvendorid = sbi_spec_is_0_1() ? 0 : sbi_get_mvendorid();
+       ci->marchid = sbi_spec_is_0_1() ? 0 : sbi_get_marchid();
+       ci->mimpid = sbi_spec_is_0_1() ? 0 : sbi_get_mimpid();
+#elif defined(CONFIG_RISCV_M_MODE)
+       ci->mvendorid = csr_read(CSR_MVENDORID);
+       ci->marchid = csr_read(CSR_MARCHID);
+       ci->mimpid = csr_read(CSR_MIMPID);
+#else
+       ci->mvendorid = 0;
+       ci->marchid = 0;
+       ci->mimpid = 0;
+#endif
+
+       return 0;
+}
+
+static int __init riscv_cpuinfo_init(void)
+{
+       int ret;
+
+       ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "riscv/cpuinfo:starting",
+                               riscv_cpuinfo_starting, NULL);
+       if (ret < 0) {
+               pr_err("cpuinfo: failed to register hotplug callbacks.\n");
+               return ret;
+       }
+
+       return 0;
+}
+device_initcall(riscv_cpuinfo_init);
+
 #define __RISCV_ISA_EXT_DATA(UPROP, EXTID) \
        {                                                       \
                .uprop = #UPROP,                                \
@@ -178,6 +225,7 @@ static int c_show(struct seq_file *m, void *v)
 {
        unsigned long cpu_id = (unsigned long)v - 1;
        struct device_node *node = of_get_cpu_node(cpu_id, NULL);
+       struct riscv_cpuinfo *ci = per_cpu_ptr(&riscv_cpuinfo, cpu_id);
        const char *compat, *isa;
 
        seq_printf(m, "processor\t: %lu\n", cpu_id);
@@ -188,6 +236,9 @@ static int c_show(struct seq_file *m, void *v)
        if (!of_property_read_string(node, "compatible", &compat)
            && strcmp(compat, "riscv"))
                seq_printf(m, "uarch\t\t: %s\n", compat);
+       seq_printf(m, "mvendorid\t: 0x%lx\n", ci->mvendorid);
+       seq_printf(m, "marchid\t\t: 0x%lx\n", ci->marchid);
+       seq_printf(m, "mimpid\t\t: 0x%lx\n", ci->mimpid);
        seq_puts(m, "\n");
        of_node_put(node);
 
--

2.34.1

#6 lore raw

Hey Anup,

Quoted 11 lines · Anup Patel

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Hi Palmer,

Quoted 6 lines · Anup Patel

Identifying the underlying RISC-V implementation can be important for some of the user space applications. For example, the perf tool uses arch specific CPU implementation id (i.e. CPUID) to select a JSON file describing custom perf events on a CPU.

Quoted 6 lines
Quoted 4 lines

Currently, there is no way to identify RISC-V implementation so we add mvendorid, marchid, and mimpid to /proc/cpuinfo output.

Can this patch be considered for 5.20 ?

iirc I mentioned the consistency of using defined() for CONFIG_RISCV_SBI versus IS_ENABLED() elsewhere in arch/riscv/ but I don't recall a response.

Thanks,
Conor.

#7 lore raw
Quoted 18 lines · On Tue, Jul 26, 2022 at 7:10 PM <[email protected]> wrote:

Hey Anup,

Quoted 14 lines · Anup Patel

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Hi Palmer,

Quoted 9 lines · Anup Patel

Identifying the underlying RISC-V implementation can be important for some of the user space applications. For example, the perf tool uses arch specific CPU implementation id (i.e. CPUID) to select a JSON file describing custom perf events on a CPU.

Currently, there is no way to identify RISC-V implementation so we add mvendorid, marchid, and mimpid to /proc/cpuinfo output.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Can this patch be considered for 5.20 ?

iirc I mentioned the consistency of using defined() for CONFIG_RISCV_SBI versus IS_ENABLED() elsewhere in arch/riscv/ but I don't recall a response.

Sorry, I missed your comment. I will address and send v2 soon.

Regards,
Anup

Quoted 3 lines

Thanks,
Conor.