Message ID | 20230526062509.31682-6-yongxuan.wang@sifive.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Add RISC-V KVM AIA Support | expand |
On 5/26/23 03:25, Yong-Xuan Wang wrote: > - Do not set the mmio operations of APLIC and IMSIC when using KVM AIA > - Send interrupt signal to KVM AIA via KVM_IRQ_LINE API > > Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com> > Reviewed-by: Jim Shu <jim.shu@sifive.com> > --- Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> > hw/intc/riscv_aplic.c | 19 +++++++++++++++---- > hw/intc/riscv_imsic.c | 16 +++++++++++----- > 2 files changed, 26 insertions(+), 9 deletions(-) > > diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c > index afc5b54dbb..adf5427f22 100644 > --- a/hw/intc/riscv_aplic.c > +++ b/hw/intc/riscv_aplic.c > @@ -31,6 +31,7 @@ > #include "hw/irq.h" > #include "target/riscv/cpu.h" > #include "sysemu/sysemu.h" > +#include "sysemu/kvm.h" > #include "migration/vmstate.h" > > #define APLIC_MAX_IDC (1UL << 14) > @@ -479,6 +480,11 @@ static void riscv_aplic_request(void *opaque, int irq, int level) > > assert((0 < irq) && (irq < aplic->num_irqs)); > > + if (kvm_irqchip_in_kernel()) { > + kvm_set_irq(kvm_state, irq, !!level); > + return; > + } > + > sourcecfg = aplic->sourcecfg[irq]; > if (sourcecfg & APLIC_SOURCECFG_D) { > childidx = sourcecfg & APLIC_SOURCECFG_CHILDIDX_MASK; > @@ -814,9 +820,11 @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp) > aplic->iforce = g_new0(uint32_t, aplic->num_harts); > aplic->ithreshold = g_new0(uint32_t, aplic->num_harts); > > - memory_region_init_io(&aplic->mmio, OBJECT(dev), &riscv_aplic_ops, aplic, > - TYPE_RISCV_APLIC, aplic->aperture_size); > - sysbus_init_mmio(SYS_BUS_DEVICE(dev), &aplic->mmio); > + if (!kvm_irqchip_in_kernel()) { > + memory_region_init_io(&aplic->mmio, OBJECT(dev), &riscv_aplic_ops, > + aplic, TYPE_RISCV_APLIC, aplic->aperture_size); > + sysbus_init_mmio(SYS_BUS_DEVICE(dev), &aplic->mmio); > + } > > /* > * Only root APLICs have hardware IRQ lines. All non-root APLICs > @@ -958,7 +966,10 @@ DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, > qdev_prop_set_bit(dev, "mmode", mmode); > > sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); > - sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); > + > + if (!kvm_irqchip_in_kernel()) { > + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); > + } > > if (parent) { > riscv_aplic_add_child(parent, dev); > diff --git a/hw/intc/riscv_imsic.c b/hw/intc/riscv_imsic.c > index fea3385b51..8bfa480f7c 100644 > --- a/hw/intc/riscv_imsic.c > +++ b/hw/intc/riscv_imsic.c > @@ -32,6 +32,7 @@ > #include "target/riscv/cpu.h" > #include "target/riscv/cpu_bits.h" > #include "sysemu/sysemu.h" > +#include "sysemu/kvm.h" > #include "migration/vmstate.h" > > #define IMSIC_MMIO_PAGE_LE 0x00 > @@ -325,10 +326,12 @@ static void riscv_imsic_realize(DeviceState *dev, Error **errp) > imsic->eithreshold = g_new0(uint32_t, imsic->num_pages); > imsic->eistate = g_new0(uint32_t, imsic->num_eistate); > > - memory_region_init_io(&imsic->mmio, OBJECT(dev), &riscv_imsic_ops, > - imsic, TYPE_RISCV_IMSIC, > - IMSIC_MMIO_SIZE(imsic->num_pages)); > - sysbus_init_mmio(SYS_BUS_DEVICE(dev), &imsic->mmio); > + if (!kvm_irqchip_in_kernel()) { > + memory_region_init_io(&imsic->mmio, OBJECT(dev), &riscv_imsic_ops, > + imsic, TYPE_RISCV_IMSIC, > + IMSIC_MMIO_SIZE(imsic->num_pages)); > + sysbus_init_mmio(SYS_BUS_DEVICE(dev), &imsic->mmio); > + } > > /* Claim the CPU interrupt to be triggered by this IMSIC */ > if (riscv_cpu_claim_interrupts(rcpu, > @@ -432,7 +435,10 @@ DeviceState *riscv_imsic_create(hwaddr addr, uint32_t hartid, bool mmode, > qdev_prop_set_uint32(dev, "num-irqs", num_ids + 1); > > sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); > - sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); > + > + if (!kvm_irqchip_in_kernel()) { > + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); > + } > > for (i = 0; i < num_pages; i++) { > if (!i) {
diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c index afc5b54dbb..adf5427f22 100644 --- a/hw/intc/riscv_aplic.c +++ b/hw/intc/riscv_aplic.c @@ -31,6 +31,7 @@ #include "hw/irq.h" #include "target/riscv/cpu.h" #include "sysemu/sysemu.h" +#include "sysemu/kvm.h" #include "migration/vmstate.h" #define APLIC_MAX_IDC (1UL << 14) @@ -479,6 +480,11 @@ static void riscv_aplic_request(void *opaque, int irq, int level) assert((0 < irq) && (irq < aplic->num_irqs)); + if (kvm_irqchip_in_kernel()) { + kvm_set_irq(kvm_state, irq, !!level); + return; + } + sourcecfg = aplic->sourcecfg[irq]; if (sourcecfg & APLIC_SOURCECFG_D) { childidx = sourcecfg & APLIC_SOURCECFG_CHILDIDX_MASK; @@ -814,9 +820,11 @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp) aplic->iforce = g_new0(uint32_t, aplic->num_harts); aplic->ithreshold = g_new0(uint32_t, aplic->num_harts); - memory_region_init_io(&aplic->mmio, OBJECT(dev), &riscv_aplic_ops, aplic, - TYPE_RISCV_APLIC, aplic->aperture_size); - sysbus_init_mmio(SYS_BUS_DEVICE(dev), &aplic->mmio); + if (!kvm_irqchip_in_kernel()) { + memory_region_init_io(&aplic->mmio, OBJECT(dev), &riscv_aplic_ops, + aplic, TYPE_RISCV_APLIC, aplic->aperture_size); + sysbus_init_mmio(SYS_BUS_DEVICE(dev), &aplic->mmio); + } /* * Only root APLICs have hardware IRQ lines. All non-root APLICs @@ -958,7 +966,10 @@ DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, qdev_prop_set_bit(dev, "mmode", mmode); sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); - sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); + + if (!kvm_irqchip_in_kernel()) { + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); + } if (parent) { riscv_aplic_add_child(parent, dev); diff --git a/hw/intc/riscv_imsic.c b/hw/intc/riscv_imsic.c index fea3385b51..8bfa480f7c 100644 --- a/hw/intc/riscv_imsic.c +++ b/hw/intc/riscv_imsic.c @@ -32,6 +32,7 @@ #include "target/riscv/cpu.h" #include "target/riscv/cpu_bits.h" #include "sysemu/sysemu.h" +#include "sysemu/kvm.h" #include "migration/vmstate.h" #define IMSIC_MMIO_PAGE_LE 0x00 @@ -325,10 +326,12 @@ static void riscv_imsic_realize(DeviceState *dev, Error **errp) imsic->eithreshold = g_new0(uint32_t, imsic->num_pages); imsic->eistate = g_new0(uint32_t, imsic->num_eistate); - memory_region_init_io(&imsic->mmio, OBJECT(dev), &riscv_imsic_ops, - imsic, TYPE_RISCV_IMSIC, - IMSIC_MMIO_SIZE(imsic->num_pages)); - sysbus_init_mmio(SYS_BUS_DEVICE(dev), &imsic->mmio); + if (!kvm_irqchip_in_kernel()) { + memory_region_init_io(&imsic->mmio, OBJECT(dev), &riscv_imsic_ops, + imsic, TYPE_RISCV_IMSIC, + IMSIC_MMIO_SIZE(imsic->num_pages)); + sysbus_init_mmio(SYS_BUS_DEVICE(dev), &imsic->mmio); + } /* Claim the CPU interrupt to be triggered by this IMSIC */ if (riscv_cpu_claim_interrupts(rcpu, @@ -432,7 +435,10 @@ DeviceState *riscv_imsic_create(hwaddr addr, uint32_t hartid, bool mmode, qdev_prop_set_uint32(dev, "num-irqs", num_ids + 1); sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); - sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); + + if (!kvm_irqchip_in_kernel()) { + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); + } for (i = 0; i < num_pages; i++) { if (!i) {