Skip to content

Commit

Permalink
target/riscv: Split interrupt logic from riscv_cpu_update_mip.
Browse files Browse the repository at this point in the history
This is to allow virtual interrupts to be inserted into S and VS
modes. Given virtual interrupts will be maintained in separate
mvip and hvip CSRs, riscv_cpu_update_mip will no longer be in the
path and interrupts need to be triggered for these cases from
rmw_hvip64 and rmw_mvip64 functions.

Signed-off-by: Rajnesh Kanwal <rkanwal@rivosinc.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20231016111736.28721-5-rkanwal@rivosinc.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
  • Loading branch information
rajnesh-kanwal authored and alistair23 committed Nov 7, 2023
1 parent b901c7e commit 1ebad50
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions target/riscv/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env);
int riscv_cpu_claim_interrupts(RISCVCPU *cpu, uint64_t interrupts);
uint64_t riscv_cpu_update_mip(CPURISCVState *env, uint64_t mask,
uint64_t value);
void riscv_cpu_interrupt(CPURISCVState *env);
#define BOOL_TO_MASK(x) (-!!(x)) /* helper for riscv_cpu_update_mip value */
void riscv_cpu_set_rdtime_fn(CPURISCVState *env, uint64_t (*fn)(void *),
void *arg);
Expand Down
25 changes: 18 additions & 7 deletions target/riscv/cpu_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -620,11 +620,12 @@ int riscv_cpu_claim_interrupts(RISCVCPU *cpu, uint64_t interrupts)
}
}

uint64_t riscv_cpu_update_mip(CPURISCVState *env, uint64_t mask,
uint64_t value)
void riscv_cpu_interrupt(CPURISCVState *env)
{
uint64_t gein, vsgein = 0, vstip = 0;
CPUState *cs = env_cpu(env);
uint64_t gein, vsgein = 0, vstip = 0, old = env->mip;

QEMU_IOTHREAD_LOCK_GUARD();

if (env->virt_enabled) {
gein = get_field(env->hstatus, HSTATUS_VGEIN);
Expand All @@ -633,15 +634,25 @@ uint64_t riscv_cpu_update_mip(CPURISCVState *env, uint64_t mask,

vstip = env->vstime_irq ? MIP_VSTIP : 0;

QEMU_IOTHREAD_LOCK_GUARD();

env->mip = (env->mip & ~mask) | (value & mask);

if (env->mip | vsgein | vstip) {
cpu_interrupt(cs, CPU_INTERRUPT_HARD);
} else {
cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD);
}
}

uint64_t riscv_cpu_update_mip(CPURISCVState *env, uint64_t mask, uint64_t value)
{
uint64_t old = env->mip;

/* No need to update mip for VSTIP */
mask = ((mask == MIP_VSTIP) && env->vstime_irq) ? 0 : mask;

QEMU_IOTHREAD_LOCK_GUARD();

env->mip = (env->mip & ~mask) | (value & mask);

riscv_cpu_interrupt(env);

return old;
}
Expand Down

0 comments on commit 1ebad50

Please sign in to comment.