2019-05-29 14:18:00 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2017-07-11 01:00:26 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Regents of the University of California
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <linux/of.h>
|
2022-03-14 20:38:45 +00:00
|
|
|
#include <asm/hwcap.h>
|
2018-10-02 19:15:05 +00:00
|
|
|
#include <asm/smp.h>
|
2021-12-06 10:46:52 +00:00
|
|
|
#include <asm/pgtable.h>
|
2017-07-11 01:00:26 +00:00
|
|
|
|
2018-10-02 19:15:00 +00:00
|
|
|
/*
|
2019-01-18 14:03:06 +00:00
|
|
|
* Returns the hart ID of the given device tree node, or -ENODEV if the node
|
|
|
|
* isn't an enabled and valid RISC-V hart node.
|
2018-10-02 19:15:00 +00:00
|
|
|
*/
|
2022-05-27 05:17:42 +00:00
|
|
|
int riscv_of_processor_hartid(struct device_node *node, unsigned long *hart)
|
2017-07-11 01:00:26 +00:00
|
|
|
{
|
2019-01-18 14:03:07 +00:00
|
|
|
const char *isa;
|
2017-07-11 01:00:26 +00:00
|
|
|
|
|
|
|
if (!of_device_is_compatible(node, "riscv")) {
|
|
|
|
pr_warn("Found incompatible CPU\n");
|
2019-01-18 14:03:06 +00:00
|
|
|
return -ENODEV;
|
2017-07-11 01:00:26 +00:00
|
|
|
}
|
|
|
|
|
2022-05-27 05:17:42 +00:00
|
|
|
*hart = (unsigned long) of_get_cpu_hwid(node, 0);
|
|
|
|
if (*hart == ~0UL) {
|
2017-07-11 01:00:26 +00:00
|
|
|
pr_warn("Found CPU without hart ID\n");
|
2019-01-18 14:03:06 +00:00
|
|
|
return -ENODEV;
|
2017-07-11 01:00:26 +00:00
|
|
|
}
|
|
|
|
|
2019-01-18 14:03:07 +00:00
|
|
|
if (!of_device_is_available(node)) {
|
2022-05-27 05:17:42 +00:00
|
|
|
pr_info("CPU with hartid=%lu is not available\n", *hart);
|
2019-01-18 14:03:06 +00:00
|
|
|
return -ENODEV;
|
2017-07-11 01:00:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (of_property_read_string(node, "riscv,isa", &isa)) {
|
2022-05-27 05:17:42 +00:00
|
|
|
pr_warn("CPU with hartid=%lu has no \"riscv,isa\" property\n", *hart);
|
2019-01-18 14:03:06 +00:00
|
|
|
return -ENODEV;
|
2017-07-11 01:00:26 +00:00
|
|
|
}
|
|
|
|
if (isa[0] != 'r' || isa[1] != 'v') {
|
2022-05-27 05:17:42 +00:00
|
|
|
pr_warn("CPU with hartid=%lu has an invalid ISA of \"%s\"\n", *hart, isa);
|
2019-01-18 14:03:06 +00:00
|
|
|
return -ENODEV;
|
2017-07-11 01:00:26 +00:00
|
|
|
}
|
|
|
|
|
2022-05-27 05:17:42 +00:00
|
|
|
return 0;
|
2017-07-11 01:00:26 +00:00
|
|
|
}
|
|
|
|
|
2020-06-01 09:15:39 +00:00
|
|
|
/*
|
|
|
|
* Find hart ID of the CPU DT node under which given DT node falls.
|
|
|
|
*
|
|
|
|
* To achieve this, we walk up the DT tree until we find an active
|
|
|
|
* RISC-V core (HART) node and extract the cpuid from it.
|
|
|
|
*/
|
2022-05-27 05:17:42 +00:00
|
|
|
int riscv_of_parent_hartid(struct device_node *node, unsigned long *hartid)
|
2020-06-01 09:15:39 +00:00
|
|
|
{
|
2022-05-27 05:17:42 +00:00
|
|
|
int rc;
|
|
|
|
|
2020-06-01 09:15:39 +00:00
|
|
|
for (; node; node = node->parent) {
|
2022-05-27 05:17:42 +00:00
|
|
|
if (of_device_is_compatible(node, "riscv")) {
|
|
|
|
rc = riscv_of_processor_hartid(node, hartid);
|
|
|
|
if (!rc)
|
|
|
|
return 0;
|
|
|
|
}
|
2020-06-01 09:15:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-07-11 01:00:26 +00:00
|
|
|
#ifdef CONFIG_PROC_FS
|
2022-03-14 20:38:45 +00:00
|
|
|
#define __RISCV_ISA_EXT_DATA(UPROP, EXTID) \
|
|
|
|
{ \
|
|
|
|
.uprop = #UPROP, \
|
|
|
|
.isa_ext_id = EXTID, \
|
|
|
|
}
|
2022-03-28 22:04:17 +00:00
|
|
|
/*
|
2022-03-14 20:38:45 +00:00
|
|
|
* Here are the ordering rules of extension naming defined by RISC-V
|
|
|
|
* specification :
|
|
|
|
* 1. All extensions should be separated from other multi-letter extensions
|
2022-03-19 02:26:33 +00:00
|
|
|
* by an underscore.
|
2022-03-14 20:38:45 +00:00
|
|
|
* 2. The first letter following the 'Z' conventionally indicates the most
|
|
|
|
* closely related alphabetical extension category, IMAFDQLCBKJTPVH.
|
|
|
|
* If multiple 'Z' extensions are named, they should be ordered first
|
|
|
|
* by category, then alphabetically within a category.
|
|
|
|
* 3. Standard supervisor-level extensions (starts with 'S') should be
|
|
|
|
* listed after standard unprivileged extensions. If multiple
|
|
|
|
* supervisor-level extensions are listed, they should be ordered
|
|
|
|
* alphabetically.
|
|
|
|
* 4. Non-standard extensions (starts with 'X') must be listed after all
|
|
|
|
* standard extensions. They must be separated from other multi-letter
|
|
|
|
* extensions by an underscore.
|
|
|
|
*/
|
|
|
|
static struct riscv_isa_ext_data isa_ext_arr[] = {
|
2022-02-19 00:46:58 +00:00
|
|
|
__RISCV_ISA_EXT_DATA(sscofpmf, RISCV_ISA_EXT_SSCOFPMF),
|
2022-05-11 19:29:18 +00:00
|
|
|
__RISCV_ISA_EXT_DATA(svpbmt, RISCV_ISA_EXT_SVPBMT),
|
2022-07-06 23:15:35 +00:00
|
|
|
__RISCV_ISA_EXT_DATA(zicbom, RISCV_ISA_EXT_ZICBOM),
|
2022-03-14 20:38:45 +00:00
|
|
|
__RISCV_ISA_EXT_DATA("", RISCV_ISA_EXT_MAX),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void print_isa_ext(struct seq_file *f)
|
|
|
|
{
|
|
|
|
struct riscv_isa_ext_data *edata;
|
|
|
|
int i = 0, arr_sz;
|
|
|
|
|
|
|
|
arr_sz = ARRAY_SIZE(isa_ext_arr) - 1;
|
|
|
|
|
|
|
|
/* No extension support available */
|
|
|
|
if (arr_sz <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i <= arr_sz; i++) {
|
|
|
|
edata = &isa_ext_arr[i];
|
|
|
|
if (!__riscv_isa_extension_available(NULL, edata->isa_ext_id))
|
|
|
|
continue;
|
|
|
|
seq_printf(f, "_%s", edata->uprop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-28 22:04:17 +00:00
|
|
|
/*
|
2022-03-14 20:38:45 +00:00
|
|
|
* These are the only valid base (single letter) ISA extensions as per the spec.
|
|
|
|
* It also specifies the canonical order in which it appears in the spec.
|
|
|
|
* Some of the extension may just be a place holder for now (B, K, P, J).
|
|
|
|
* This should be updated once corresponding extensions are ratified.
|
|
|
|
*/
|
|
|
|
static const char base_riscv_exts[13] = "imafdqcbkjpvh";
|
2017-07-11 01:00:26 +00:00
|
|
|
|
2019-10-09 22:00:57 +00:00
|
|
|
static void print_isa(struct seq_file *f, const char *isa)
|
2018-10-02 19:14:56 +00:00
|
|
|
{
|
2022-03-14 20:38:45 +00:00
|
|
|
int i;
|
|
|
|
|
2018-10-02 19:15:06 +00:00
|
|
|
seq_puts(f, "isa\t\t: ");
|
2022-03-14 20:38:45 +00:00
|
|
|
/* Print the rv[64/32] part */
|
|
|
|
seq_write(f, isa, 4);
|
|
|
|
for (i = 0; i < sizeof(base_riscv_exts); i++) {
|
|
|
|
if (__riscv_isa_extension_available(NULL, base_riscv_exts[i] - 'a'))
|
|
|
|
/* Print only enabled the base ISA extensions */
|
|
|
|
seq_write(f, &base_riscv_exts[i], 1);
|
|
|
|
}
|
|
|
|
print_isa_ext(f);
|
2018-10-02 19:15:06 +00:00
|
|
|
seq_puts(f, "\n");
|
2018-10-02 19:14:56 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 10:46:52 +00:00
|
|
|
static void print_mmu(struct seq_file *f)
|
2018-10-02 19:14:56 +00:00
|
|
|
{
|
2021-12-06 10:46:52 +00:00
|
|
|
char sv_type[16];
|
|
|
|
|
2022-04-14 17:30:36 +00:00
|
|
|
#ifdef CONFIG_MMU
|
2018-10-02 19:14:56 +00:00
|
|
|
#if defined(CONFIG_32BIT)
|
2021-12-06 10:46:52 +00:00
|
|
|
strncpy(sv_type, "sv32", 5);
|
2018-10-02 19:14:56 +00:00
|
|
|
#elif defined(CONFIG_64BIT)
|
2022-01-27 02:48:43 +00:00
|
|
|
if (pgtable_l5_enabled)
|
|
|
|
strncpy(sv_type, "sv57", 5);
|
|
|
|
else if (pgtable_l4_enabled)
|
2021-12-06 10:46:52 +00:00
|
|
|
strncpy(sv_type, "sv48", 5);
|
|
|
|
else
|
|
|
|
strncpy(sv_type, "sv39", 5);
|
2018-10-02 19:14:56 +00:00
|
|
|
#endif
|
2022-04-14 17:30:36 +00:00
|
|
|
#else
|
|
|
|
strncpy(sv_type, "none", 5);
|
|
|
|
#endif /* CONFIG_MMU */
|
2021-12-06 10:46:52 +00:00
|
|
|
seq_printf(f, "mmu\t\t: %s\n", sv_type);
|
2018-10-02 19:14:56 +00:00
|
|
|
}
|
|
|
|
|
2017-07-11 01:00:26 +00:00
|
|
|
static void *c_start(struct seq_file *m, loff_t *pos)
|
|
|
|
{
|
|
|
|
*pos = cpumask_next(*pos - 1, cpu_online_mask);
|
|
|
|
if ((*pos) < nr_cpu_ids)
|
|
|
|
return (void *)(uintptr_t)(1 + *pos);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *c_next(struct seq_file *m, void *v, loff_t *pos)
|
|
|
|
{
|
|
|
|
(*pos)++;
|
|
|
|
return c_start(m, pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void c_stop(struct seq_file *m, void *v)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static int c_show(struct seq_file *m, void *v)
|
|
|
|
{
|
2018-10-02 19:15:05 +00:00
|
|
|
unsigned long cpu_id = (unsigned long)v - 1;
|
2019-04-24 21:47:58 +00:00
|
|
|
struct device_node *node = of_get_cpu_node(cpu_id, NULL);
|
2021-12-06 10:46:52 +00:00
|
|
|
const char *compat, *isa;
|
2017-07-11 01:00:26 +00:00
|
|
|
|
2018-10-02 19:15:06 +00:00
|
|
|
seq_printf(m, "processor\t: %lu\n", cpu_id);
|
|
|
|
seq_printf(m, "hart\t\t: %lu\n", cpuid_to_hartid_map(cpu_id));
|
2018-10-02 19:14:56 +00:00
|
|
|
if (!of_property_read_string(node, "riscv,isa", &isa))
|
|
|
|
print_isa(m, isa);
|
2021-12-06 10:46:52 +00:00
|
|
|
print_mmu(m);
|
2017-07-11 01:00:26 +00:00
|
|
|
if (!of_property_read_string(node, "compatible", &compat)
|
|
|
|
&& strcmp(compat, "riscv"))
|
2018-10-02 19:15:06 +00:00
|
|
|
seq_printf(m, "uarch\t\t: %s\n", compat);
|
2017-07-11 01:00:26 +00:00
|
|
|
seq_puts(m, "\n");
|
2018-11-20 23:07:50 +00:00
|
|
|
of_node_put(node);
|
2017-07-11 01:00:26 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct seq_operations cpuinfo_op = {
|
|
|
|
.start = c_start,
|
|
|
|
.next = c_next,
|
|
|
|
.stop = c_stop,
|
|
|
|
.show = c_show
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* CONFIG_PROC_FS */
|