Track if the GIC is GICv5, and provide interface to check that. This avoids having to rely on either struct kvm or passing irqchip information throughout the code, thereby keeping things a tad cleaner in the process. Signed-off-by: Sascha Bischoff --- arm64/gic.c | 20 ++++++++++++++++++++ arm64/include/kvm/gic.h | 1 + 2 files changed, 21 insertions(+) diff --git a/arm64/gic.c b/arm64/gic.c index 67b96734..a49bc9b9 100644 --- a/arm64/gic.c +++ b/arm64/gic.c @@ -19,6 +19,12 @@ static u64 gic_redists_size; static u64 gic_msi_base; static u64 gic_msi_size = 0; static bool vgic_is_init = false; +static bool vgic_is_v5 = false; + +bool gic__is_v5(void) +{ + return vgic_is_v5; +} struct kvm_irqfd_line { unsigned int gsi; @@ -225,6 +231,20 @@ static int gic__create_device(struct kvm *kvm, enum irqchip_type type) if (err) goto out_err; + /* + * If we are using GICv5, then we need to allocate SPIs starting at 0, + * and not at the legacy offset of 32. This must happen before any + * interrupts are allocated. + */ + if ((type == IRQCHIP_GICV5)) { + err = irq__init_irq_offset(0); + if (err) + goto out_err; + + /* Track that we have a GICv5 - needed for FDT */ + vgic_is_v5 = true; + } + return 0; out_err: diff --git a/arm64/include/kvm/gic.h b/arm64/include/kvm/gic.h index 13742bd5..805f4247 100644 --- a/arm64/include/kvm/gic.h +++ b/arm64/include/kvm/gic.h @@ -40,6 +40,7 @@ enum irqchip_type { struct kvm; +bool gic__is_v5(void); int gic__alloc_irqnum(void); int gic__create(struct kvm *kvm, enum irqchip_type type); int gic__create_gicv2m_frame(struct kvm *kvm, u64 msi_frame_addr); -- 2.34.1