Skip to content

Commit

Permalink
[ot] target/riscv: pmp: exit csr writes early if value was not changed
Browse files Browse the repository at this point in the history
Signed-off-by: Loïc Lefort <[email protected]>
  • Loading branch information
loiclefort committed Dec 6, 2023
1 parent 72c5fa9 commit a98c7d6
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions target/riscv/pmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ static inline uint8_t pmp_read_cfg(CPURISCVState *env, uint32_t pmp_index)
static bool pmp_write_cfg(CPURISCVState *env, uint32_t pmp_index, uint8_t val)
{
if (pmp_index < MAX_RISCV_PMPS) {
if (env->pmp_state.pmp[pmp_index].cfg_reg == val) {
/* no change */
return false;
}

if (!pmp_is_writable(env, pmp_index)) {
qemu_log_mask(LOG_GUEST_ERROR,
"ignoring pmpcfg[%u] write - locked"
Expand All @@ -162,7 +167,7 @@ static bool pmp_write_cfg(CPURISCVState *env, uint32_t pmp_index, uint8_t val)
" - current:0x%02x new:0x%02x\n",
pmp_index, env->pmp_state.pmp[pmp_index].cfg_reg,
val);
} else if (env->pmp_state.pmp[pmp_index].cfg_reg != val) {
} else {
env->pmp_state.pmp[pmp_index].cfg_reg = val;
pmp_update_rule_addr(env, pmp_index);
return true;
Expand Down Expand Up @@ -537,6 +542,11 @@ void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index,
bool is_next_cfg_tor = false;

if (addr_index < MAX_RISCV_PMPS) {
if (env->pmp_state.pmp[addr_index].addr_reg == val) {
/* no change */
return;
}

/*
* In TOR mode, need to check the lock bit of the next pmp
* (if there is a next).
Expand All @@ -557,14 +567,12 @@ void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index,
}

if (pmp_is_writable(env, addr_index)) {
if (env->pmp_state.pmp[addr_index].addr_reg != val) {
env->pmp_state.pmp[addr_index].addr_reg = val;
pmp_update_rule_addr(env, addr_index);
if (is_next_cfg_tor) {
pmp_update_rule_addr(env, addr_index + 1);
}
tlb_flush(env_cpu(env));
env->pmp_state.pmp[addr_index].addr_reg = val;
pmp_update_rule_addr(env, addr_index);
if (is_next_cfg_tor) {
pmp_update_rule_addr(env, addr_index + 1);
}
tlb_flush(env_cpu(env));
} else {
qemu_log_mask(LOG_GUEST_ERROR,
"ignoring pmpaddr[%u] write - locked"
Expand Down

0 comments on commit a98c7d6

Please sign in to comment.