aboutsummaryrefslogtreecommitdiff
path: root/target/riscv/tcg
diff options
context:
space:
mode:
authorDaniel Henrique Barboza <dbarboza@ventanamicro.com>2023-10-23 12:39:26 -0300
committerAlistair Francis <alistair.francis@wdc.com>2023-11-07 11:06:02 +1000
commit082412166044a96c69c174e262f282cc6d73f019 (patch)
tree6151173e2cb2eb6b02964c57fac5ca0c2aca95cc /target/riscv/tcg
parentb31dee8a7d3e515b5129f8ec57fb38cc193fac6e (diff)
downloadqemu-082412166044a96c69c174e262f282cc6d73f019.zip
qemu-082412166044a96c69c174e262f282cc6d73f019.tar.gz
qemu-082412166044a96c69c174e262f282cc6d73f019.tar.bz2
target/riscv: add zihpm extension flag for TCG
zihpm is the Hardware Performance Counters extension described in chapter 12 of the unprivileged spec. It describes support for 29 unprivileged performance counters, hpmcounter3-hpmcounter31. As with zicntr, QEMU already implements zihpm before it was even an extension. zihpm is also part of the RVA22 profile, so add it to QEMU to complement the future profile implementation. Default it to 'true' for all existing CPUs since it was always present in the code. As for disabling it, there is already code in place in target/riscv/csr.c in all predicates for these counters (ctr() and mctr()) that disables them if cpu->cfg.pmu_num is zero. Thus, setting cpu->cfg.pmu_num to zero if 'zihpm=false' is enough to disable the extension. Set cpu->pmu_avail_ctrs mask to zero as well since this is also checked to verify if the counters exist. Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Message-ID: <20231023153927.435083-4-dbarboza@ventanamicro.com> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Diffstat (limited to 'target/riscv/tcg')
-rw-r--r--target/riscv/tcg/tcg-cpu.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
index a1e4ed2..093bda2 100644
--- a/target/riscv/tcg/tcg-cpu.c
+++ b/target/riscv/tcg/tcg-cpu.c
@@ -549,6 +549,19 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
cpu->cfg.ext_zicntr = false;
}
+ if (cpu->cfg.ext_zihpm && !cpu->cfg.ext_zicsr) {
+ if (cpu_cfg_ext_is_user_set(CPU_CFG_OFFSET(ext_zihpm))) {
+ error_setg(errp, "zihpm requires zicsr");
+ return;
+ }
+ cpu->cfg.ext_zihpm = false;
+ }
+
+ if (!cpu->cfg.ext_zihpm) {
+ cpu->cfg.pmu_num = 0;
+ cpu->pmu_avail_ctrs = 0;
+ }
+
/*
* Disable isa extensions based on priv spec after we
* validated and set everything we need.