mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 00:03:54 -06:00
target/riscv: Implement hgeie and hgeip CSRs
The hgeie and hgeip CSRs are required for emulating an external interrupt controller capable of injecting virtual external interrupt to Guest/VM running at VS-level. Signed-off-by: Anup Patel <anup.patel@wdc.com> Signed-off-by: Anup Patel <anup@brainfault.org> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Frank Chang <frank.chang@sifive.com> Message-id: 20220204174700.534953-4-anup@brainfault.org Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
This commit is contained in:
parent
881df35d3d
commit
cd032fe75c
6 changed files with 121 additions and 38 deletions
|
@ -663,27 +663,53 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
|
|||
static void riscv_cpu_set_irq(void *opaque, int irq, int level)
|
||||
{
|
||||
RISCVCPU *cpu = RISCV_CPU(opaque);
|
||||
CPURISCVState *env = &cpu->env;
|
||||
|
||||
switch (irq) {
|
||||
case IRQ_U_SOFT:
|
||||
case IRQ_S_SOFT:
|
||||
case IRQ_VS_SOFT:
|
||||
case IRQ_M_SOFT:
|
||||
case IRQ_U_TIMER:
|
||||
case IRQ_S_TIMER:
|
||||
case IRQ_VS_TIMER:
|
||||
case IRQ_M_TIMER:
|
||||
case IRQ_U_EXT:
|
||||
case IRQ_S_EXT:
|
||||
case IRQ_VS_EXT:
|
||||
case IRQ_M_EXT:
|
||||
if (kvm_enabled()) {
|
||||
kvm_riscv_set_irq(cpu, irq, level);
|
||||
} else {
|
||||
riscv_cpu_update_mip(cpu, 1 << irq, BOOL_TO_MASK(level));
|
||||
if (irq < IRQ_LOCAL_MAX) {
|
||||
switch (irq) {
|
||||
case IRQ_U_SOFT:
|
||||
case IRQ_S_SOFT:
|
||||
case IRQ_VS_SOFT:
|
||||
case IRQ_M_SOFT:
|
||||
case IRQ_U_TIMER:
|
||||
case IRQ_S_TIMER:
|
||||
case IRQ_VS_TIMER:
|
||||
case IRQ_M_TIMER:
|
||||
case IRQ_U_EXT:
|
||||
case IRQ_S_EXT:
|
||||
case IRQ_VS_EXT:
|
||||
case IRQ_M_EXT:
|
||||
if (kvm_enabled()) {
|
||||
kvm_riscv_set_irq(cpu, irq, level);
|
||||
} else {
|
||||
riscv_cpu_update_mip(cpu, 1 << irq, BOOL_TO_MASK(level));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
} else if (irq < (IRQ_LOCAL_MAX + IRQ_LOCAL_GUEST_MAX)) {
|
||||
/* Require H-extension for handling guest local interrupts */
|
||||
if (!riscv_has_ext(env, RVH)) {
|
||||
g_assert_not_reached();
|
||||
}
|
||||
|
||||
/* Compute bit position in HGEIP CSR */
|
||||
irq = irq - IRQ_LOCAL_MAX + 1;
|
||||
if (env->geilen < irq) {
|
||||
g_assert_not_reached();
|
||||
}
|
||||
|
||||
/* Update HGEIP CSR */
|
||||
env->hgeip &= ~((target_ulong)1 << irq);
|
||||
if (level) {
|
||||
env->hgeip |= (target_ulong)1 << irq;
|
||||
}
|
||||
|
||||
/* Update mip.SGEIP bit */
|
||||
riscv_cpu_update_mip(cpu, MIP_SGEIP,
|
||||
BOOL_TO_MASK(!!(env->hgeie & env->hgeip)));
|
||||
} else {
|
||||
g_assert_not_reached();
|
||||
}
|
||||
}
|
||||
|
@ -696,7 +722,8 @@ static void riscv_cpu_init(Object *obj)
|
|||
cpu_set_cpustate_pointers(cpu);
|
||||
|
||||
#ifndef CONFIG_USER_ONLY
|
||||
qdev_init_gpio_in(DEVICE(cpu), riscv_cpu_set_irq, IRQ_LOCAL_MAX);
|
||||
qdev_init_gpio_in(DEVICE(cpu), riscv_cpu_set_irq,
|
||||
IRQ_LOCAL_MAX + IRQ_LOCAL_GUEST_MAX);
|
||||
#endif /* CONFIG_USER_ONLY */
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue