aboutsummaryrefslogtreecommitdiff
path: root/target/riscv
diff options
context:
space:
mode:
authorAtish Patra <atishp@rivosinc.com>2022-03-29 12:56:57 -0700
committerAlistair Francis <alistair.francis@wdc.com>2022-04-22 10:35:16 +1000
commita775398be2e9ee2f2158dbdd0938593e3d002f62 (patch)
tree3a208c99060ceb35dee25cd8fb23aedd6e15155e /target/riscv
parent0e2c377023b3cc13f097752bd84b3cab0554997d (diff)
downloadqemu-a775398be2e9ee2f2158dbdd0938593e3d002f62.zip
qemu-a775398be2e9ee2f2158dbdd0938593e3d002f62.tar.gz
qemu-a775398be2e9ee2f2158dbdd0938593e3d002f62.tar.bz2
target/riscv: Add isa extenstion strings to the device tree
The Linux kernel parses the ISA extensions from "riscv,isa" DT property. It used to parse only the single letter base extensions until now. A generic ISA extension parsing framework was proposed[1] recently that can parse multi-letter ISA extensions as well. Generate the extended ISA string by appending the available ISA extensions to the "riscv,isa" string if it is enabled so that kernel can process it. [1] https://lkml.org/lkml/2022/2/15/263 Reviewed-by: Anup Patel <anup@brainfault.org> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Frank Chang <frank.chang@sifive.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Tested-by: Bin Meng <bmeng.cn@gmail.com> Signed-off-by: Atish Patra <atishp@rivosinc.com> Suggested-by: Heiko Stubner <heiko@sntech.de> Signed-off-by: Atish Patra <atishp@rivosinc.com> Message-Id: <20220329195657.1725425-1-atishp@rivosinc.com> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Diffstat (limited to 'target/riscv')
-rw-r--r--target/riscv/cpu.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index edc33c4..94f9434 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -36,6 +36,11 @@
static const char riscv_single_letter_exts[] = "IEMAFDQCPVH";
+struct isa_ext_data {
+ const char *name;
+ bool enabled;
+};
+
const char * const riscv_int_regnames[] = {
"x0/zero", "x1/ra", "x2/sp", "x3/gp", "x4/tp", "x5/t0", "x6/t1",
"x7/t2", "x8/s0", "x9/s1", "x10/a0", "x11/a1", "x12/a2", "x13/a3",
@@ -908,6 +913,60 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)
device_class_set_props(dc, riscv_cpu_properties);
}
+#define ISA_EDATA_ENTRY(name, prop) {#name, cpu->cfg.prop}
+
+static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len)
+{
+ char *old = *isa_str;
+ char *new = *isa_str;
+ int i;
+
+ /**
+ * Here are the ordering rules of extension naming defined by RISC-V
+ * specification :
+ * 1. All extensions should be separated from other multi-letter extensions
+ * by an underscore.
+ * 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.
+ */
+ struct isa_ext_data isa_edata_arr[] = {
+ ISA_EDATA_ENTRY(zfh, ext_zfh),
+ ISA_EDATA_ENTRY(zfhmin, ext_zfhmin),
+ ISA_EDATA_ENTRY(zfinx, ext_zfinx),
+ ISA_EDATA_ENTRY(zhinx, ext_zhinx),
+ ISA_EDATA_ENTRY(zhinxmin, ext_zhinxmin),
+ ISA_EDATA_ENTRY(zdinx, ext_zdinx),
+ ISA_EDATA_ENTRY(zba, ext_zba),
+ ISA_EDATA_ENTRY(zbb, ext_zbb),
+ ISA_EDATA_ENTRY(zbc, ext_zbc),
+ ISA_EDATA_ENTRY(zbs, ext_zbs),
+ ISA_EDATA_ENTRY(zve32f, ext_zve32f),
+ ISA_EDATA_ENTRY(zve64f, ext_zve64f),
+ ISA_EDATA_ENTRY(svinval, ext_svinval),
+ ISA_EDATA_ENTRY(svnapot, ext_svnapot),
+ ISA_EDATA_ENTRY(svpbmt, ext_svpbmt),
+ };
+
+ for (i = 0; i < ARRAY_SIZE(isa_edata_arr); i++) {
+ if (isa_edata_arr[i].enabled) {
+ new = g_strconcat(old, "_", isa_edata_arr[i].name, NULL);
+ g_free(old);
+ old = new;
+ }
+ }
+
+ *isa_str = new;
+}
+
char *riscv_isa_string(RISCVCPU *cpu)
{
int i;
@@ -920,6 +979,7 @@ char *riscv_isa_string(RISCVCPU *cpu)
}
}
*p = '\0';
+ riscv_isa_string_ext(cpu, &isa_str, maxlen);
return isa_str;
}