From: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
To: qemu-devel@nongnu.org
Cc: Alistair.Francis@wdc.com, palmer@dabbelt.com,
bin.meng@windriver.com, liwei1518@gmail.com,
dbarboza@ventanamicro.com, qemu-riscv@nongnu.org,
christoph.muellner@vrull.eu, bjorn@kernel.org,
LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
Subject: [PATCH 1/2] target/riscv: Register vendors CSR
Date: Tue, 30 Jan 2024 19:11:58 +0800 [thread overview]
Message-ID: <20240130111159.532-2-zhiwei_liu@linux.alibaba.com> (raw)
In-Reply-To: <20240130111159.532-1-zhiwei_liu@linux.alibaba.com>
riscv specification allows custom CSRs in decode area. So we should
register all vendor CSRs in cpu realize stage.
Signed-off-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
---
target/riscv/cpu.c | 3 +++
target/riscv/tcg/tcg-cpu.c | 26 ++++++++++++++++++++++++++
target/riscv/tcg/tcg-cpu.h | 1 +
3 files changed, 30 insertions(+)
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index 8cbfc7e781..2dcbc9ff32 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -1113,6 +1113,9 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
return;
}
+ if (tcg_enabled()) {
+ riscv_tcg_cpu_register_vendor_csr(cpu);
+ }
riscv_cpu_register_gdb_regs_for_features(cs);
#ifndef CONFIG_USER_ONLY
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
index 994ca1cdf9..408b2ebffa 100644
--- a/target/riscv/tcg/tcg-cpu.c
+++ b/target/riscv/tcg/tcg-cpu.c
@@ -871,6 +871,32 @@ static void riscv_cpu_validate_profiles(RISCVCPU *cpu)
}
}
+/* This stub just works for making vendors array not empty */
+riscv_csr_operations stub_csr_ops[CSR_TABLE_SIZE];
+static inline bool never_p(const RISCVCPUConfig *cfg)
+{
+ return false;
+}
+
+void riscv_tcg_cpu_register_vendor_csr(RISCVCPU *cpu)
+{
+ static const struct {
+ bool (*guard_func)(const RISCVCPUConfig *);
+ riscv_csr_operations *csr_ops;
+ } vendors[] = {
+ { never_p, stub_csr_ops },
+ };
+ for (size_t i = 0; i < ARRAY_SIZE(vendors); ++i) {
+ if (!vendors[i].guard_func(&cpu->cfg)) {
+ continue;
+ }
+ for (size_t j = 0; j < CSR_TABLE_SIZE &&
+ vendors[i].csr_ops[j].name; j++) {
+ csr_ops[j] = vendors[i].csr_ops[j];
+ }
+ }
+}
+
void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
{
CPURISCVState *env = &cpu->env;
diff --git a/target/riscv/tcg/tcg-cpu.h b/target/riscv/tcg/tcg-cpu.h
index f7b32417f8..3daaebf4fb 100644
--- a/target/riscv/tcg/tcg-cpu.h
+++ b/target/riscv/tcg/tcg-cpu.h
@@ -25,5 +25,6 @@
void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp);
void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp);
bool riscv_cpu_tcg_compatible(RISCVCPU *cpu);
+void riscv_tcg_cpu_register_vendor_csr(RISCVCPU *cpu);
#endif
--
2.25.1
next prev parent reply other threads:[~2024-01-30 11:12 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-30 11:11 [PATCH 0/2] target/riscv: Support mxstatus CSR for thead-c906 LIU Zhiwei
2024-01-30 11:11 ` LIU Zhiwei [this message]
2024-01-31 5:06 ` [PATCH 1/2] target/riscv: Register vendors CSR Richard Henderson
2024-01-31 6:14 ` LIU Zhiwei
2024-01-30 11:11 ` [PATCH 2/2] target/riscv: Support xtheadmaee for thead-c906 LIU Zhiwei
2024-01-30 11:43 ` Christoph Müllner
2024-01-31 18:52 ` Conor Dooley
2024-02-04 5:47 ` LIU Zhiwei
2024-01-31 5:07 ` Richard Henderson
2024-01-31 6:21 ` LIU Zhiwei
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240130111159.532-2-zhiwei_liu@linux.alibaba.com \
--to=zhiwei_liu@linux.alibaba.com \
--cc=Alistair.Francis@wdc.com \
--cc=bin.meng@windriver.com \
--cc=bjorn@kernel.org \
--cc=christoph.muellner@vrull.eu \
--cc=dbarboza@ventanamicro.com \
--cc=liwei1518@gmail.com \
--cc=palmer@dabbelt.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).