From: Atish Patra <atishp@rivosinc.com>
To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org
Cc: Atish Patra <atishp@rivosinc.com>,
palmer@dabbelt.com, liwei1518@gmail.com,
zhiwei_liu@linux.alibaba.com, bin.meng@windriver.com,
dbarboza@ventanamicro.com, alistair.francis@wdc.com
Subject: [PATCH 2/3] target/riscv: Enforce WARL behavior for scounteren/hcounteren
Date: Mon, 29 Apr 2024 12:28:05 -0700 [thread overview]
Message-ID: <20240429-countinhibit_fix-v1-2-802ec1e99133@rivosinc.com> (raw)
In-Reply-To: <20240429-countinhibit_fix-v1-0-802ec1e99133@rivosinc.com>
scounteren/hcountern are also WARL registers similar to mcountern.
Only set the bits for the available counters during the write to
preserve the WARL behavior.
Signed-off-by: Atish Patra <atishp@rivosinc.com>
---
target/riscv/csr.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
index 68ca31aff47d..a01911541d67 100644
--- a/target/riscv/csr.c
+++ b/target/riscv/csr.c
@@ -2843,7 +2843,11 @@ static RISCVException read_scounteren(CPURISCVState *env, int csrno,
static RISCVException write_scounteren(CPURISCVState *env, int csrno,
target_ulong val)
{
- env->scounteren = val;
+ RISCVCPU *cpu = env_archcpu(env);
+
+ /* WARL register - disable unavailable counters */
+ env->scounteren = val & (cpu->pmu_avail_ctrs | COUNTEREN_CY | COUNTEREN_TM |
+ COUNTEREN_IR);
return RISCV_EXCP_NONE;
}
@@ -3475,7 +3479,11 @@ static RISCVException read_hcounteren(CPURISCVState *env, int csrno,
static RISCVException write_hcounteren(CPURISCVState *env, int csrno,
target_ulong val)
{
- env->hcounteren = val;
+ RISCVCPU *cpu = env_archcpu(env);
+
+ /* WARL register - disable unavailable counters */
+ env->hcounteren = val & (cpu->pmu_avail_ctrs | COUNTEREN_CY | COUNTEREN_TM |
+ COUNTEREN_IR);
return RISCV_EXCP_NONE;
}
--
2.34.1
next prev parent reply other threads:[~2024-04-29 19:29 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-29 19:28 [PATCH 0/3] Assorted fixes for PMU Atish Patra
2024-04-29 19:28 ` [PATCH 1/3] target/riscv: Save counter values during countinhibit update Atish Patra
2024-04-30 18:00 ` Daniel Henrique Barboza
2024-05-02 12:39 ` Andrew Jones
2024-05-09 20:26 ` Atish Kumar Patra
2024-05-10 8:33 ` Andrew Jones
2024-05-14 6:22 ` Alistair Francis
2024-04-29 19:28 ` Atish Patra [this message]
2024-04-30 18:02 ` [PATCH 2/3] target/riscv: Enforce WARL behavior for scounteren/hcounteren Daniel Henrique Barboza
2024-05-14 6:23 ` Alistair Francis
2024-04-29 19:28 ` [PATCH 3/3] target/riscv: Fix the predicate functions for mhpmeventhX CSRs Atish Patra
2024-05-14 6:29 ` [PATCH 0/3] Assorted fixes for PMU Alistair Francis
2024-05-14 7:15 ` Atish Kumar Patra
2024-05-14 10:18 ` Alistair Francis
2024-05-14 16:51 ` Atish Patra
2024-05-14 9:15 ` Peter Maydell
2024-05-14 16:52 ` Atish Patra
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=20240429-countinhibit_fix-v1-2-802ec1e99133@rivosinc.com \
--to=atishp@rivosinc.com \
--cc=alistair.francis@wdc.com \
--cc=bin.meng@windriver.com \
--cc=dbarboza@ventanamicro.com \
--cc=liwei1518@gmail.com \
--cc=palmer@dabbelt.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).