From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
To: qemu-devel@nongnu.org
Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com,
bmeng@tinylab.org, liweiwei@iscas.ac.cn,
zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com,
Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Subject: [PATCH 4/6] target/riscv/tcg: implement rva22u64 profile
Date: Tue, 26 Sep 2023 16:49:48 -0300 [thread overview]
Message-ID: <20230926194951.183767-5-dbarboza@ventanamicro.com> (raw)
In-Reply-To: <20230926194951.183767-1-dbarboza@ventanamicro.com>
The TCG emulation implements all the extensions described in the
RVA22U64 profile, both mandatory and optional. The mandatory extensions
will be enabled via the profile flag. We'll leave the optional
extensions to be enabled by hand.
Given that this is the first profile we're implementing in TCG we'll
need some wiring first. 'cpu_set_profile', our set() callback for the
profile user flag that we'll expose, will do the heavy lifting. We'll
assign misa_ext and misa_ext_mask based on the profile .misa_ext, and
enable all extensions from .ext_offsets[].
We'll also update the user choice hash 'multi_ext_user_opts' for each
extension. The idea is to reflect that setting a profile is the same as
setting all extensions of the profile in the command line. This will
prevent us from mishandling those by accident during realize() time, in
particular in validate_set_extensions(), when we might enable/disable
extensions based on certain criterias.
After cpu_set_profile() is figured out then it's a matter of exposing
the user flag for the profile using the profile name (in this case,
'rva22u64') during riscv_cpu_add_user_properties().
We will expose the profile option for vendor CPUs in the next patch
since it requires special handling. Expose it to generic CPUs only for
now.
Here's an example with the 'rv64' CPU:
$ qemu-system-riscv64 -M virt -cpu rv64,rva22u64=true (...)
# cat /proc/cpuinfo
processor : 0
hart : 0
isa : rv64imafdch_zicbom_zicboz_zicntr_zicsr_zifencei_zihintntl_zihintpause_zihpm_zawrs_zfa_zfhmin_zca_zcd_zba_zbb_zbc_zbs_zkt_sstc_svadu
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
---
target/riscv/tcg/tcg-cpu.c | 55 ++++++++++++++++++++++++++++++++++++++
1 file changed, 55 insertions(+)
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
index 11e34782b9..03435521c9 100644
--- a/target/riscv/tcg/tcg-cpu.c
+++ b/target/riscv/tcg/tcg-cpu.c
@@ -740,6 +740,57 @@ static void riscv_cpu_add_misa_properties(Object *cpu_obj)
}
}
+static void cpu_set_profile(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ const RISCVCPUProfile *profile = opaque;
+ RISCVCPU *cpu = RISCV_CPU(obj);
+ CPURISCVState *env = &cpu->env;
+ int i = 0;
+ bool value;
+
+ if (!visit_type_bool(v, name, &value, errp)) {
+ return;
+ }
+
+ /* We won't disable extensions if the user disables the profile */
+ if (!value) {
+ return;
+ }
+
+ env->misa_ext |= profile->misa_ext;
+ env->misa_ext_mask |= profile->misa_ext;
+
+ for (i = 0;; i++) {
+ int ext_offset = profile->ext_offsets[i];
+
+ if (ext_offset == RISCV_PROFILE_EXT_LIST_END) {
+ break;
+ }
+
+ isa_ext_update_enabled(cpu, ext_offset, true);
+ g_hash_table_insert(multi_ext_user_opts,
+ GUINT_TO_POINTER(ext_offset),
+ (gpointer)true);
+ }
+}
+
+static void cpu_get_profile(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ bool value;
+
+ visit_type_bool(v, name, &value, errp);
+}
+
+static void riscv_cpu_add_profile_prop(Object *cpu_obj,
+ const RISCVCPUProfile *profile)
+{
+ object_property_add(cpu_obj, profile->name, "bool",
+ cpu_get_profile, cpu_set_profile,
+ NULL, (void *)profile);
+}
+
static void cpu_set_multi_ext_cfg(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
@@ -834,6 +885,10 @@ static void riscv_cpu_add_user_properties(Object *obj)
riscv_cpu_add_multiext_prop_array(obj, riscv_cpu_vendor_exts);
riscv_cpu_add_multiext_prop_array(obj, riscv_cpu_experimental_exts);
+ if (object_dynamic_cast(obj, TYPE_RISCV_DYNAMIC_CPU) != NULL) {
+ riscv_cpu_add_profile_prop(obj, &RVA22U64);
+ }
+
for (Property *prop = riscv_cpu_options; prop && prop->name; prop++) {
qdev_property_add_static(DEVICE(obj), prop);
}
--
2.41.0
next prev parent reply other threads:[~2023-09-26 19:51 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-26 19:49 [PATCH 0/6] riscv: RVA22U64 profile support Daniel Henrique Barboza
2023-09-26 19:49 ` [PATCH 1/6] target/riscv/cpu.c: add zicntr extension flag Daniel Henrique Barboza
2023-09-26 19:49 ` [PATCH 2/6] target/riscv/cpu.c: add zihpm " Daniel Henrique Barboza
2023-09-26 19:49 ` [PATCH 3/6] target/riscv: add rva22u64 profile definition Daniel Henrique Barboza
2023-09-26 19:49 ` Daniel Henrique Barboza [this message]
2023-09-26 19:49 ` [PATCH 5/6] target/riscv/tcg-cpu.c: enable profile support for vendor CPUs Daniel Henrique Barboza
2023-09-26 19:49 ` [PATCH 6/6] target/riscv/kvm: add 'rva22u64' flag as unavailable Daniel Henrique Barboza
2023-09-29 10:10 ` [PATCH 0/6] riscv: RVA22U64 profile support Andrea Bolognani
2023-09-29 10:46 ` Daniel P. Berrangé
2023-09-29 11:29 ` Daniel Henrique Barboza
2023-09-29 11:55 ` Daniel P. Berrangé
2023-09-29 12:49 ` Daniel Henrique Barboza
2023-09-29 12:52 ` Daniel P. Berrangé
2023-09-29 13:26 ` Daniel Henrique Barboza
2023-09-29 13:32 ` Daniel P. Berrangé
2023-10-09 2:32 ` Alistair Francis
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=20230926194951.183767-5-dbarboza@ventanamicro.com \
--to=dbarboza@ventanamicro.com \
--cc=alistair.francis@wdc.com \
--cc=bmeng@tinylab.org \
--cc=liweiwei@iscas.ac.cn \
--cc=palmer@rivosinc.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=zhiwei_liu@linux.alibaba.com \
/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).