Add the command line parameter "--gicv3" to request GICv3 emulation in the kernel. Connect that to the already existing GICv3 code. Signed-off-by: Andre Przywara <andre.przywara@xxxxxxx> --- tools/kvm/arm/aarch64/arm-cpu.c | 5 ++++- .../kvm/arm/aarch64/include/kvm/kvm-config-arch.h | 4 +++- tools/kvm/arm/gic.c | 17 +++++++++++++++++ tools/kvm/arm/include/arm-common/kvm-config-arch.h | 1 + tools/kvm/arm/kvm.c | 4 +++- 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/tools/kvm/arm/aarch64/arm-cpu.c b/tools/kvm/arm/aarch64/arm-cpu.c index 35771e0..e3514ea 100644 --- a/tools/kvm/arm/aarch64/arm-cpu.c +++ b/tools/kvm/arm/aarch64/arm-cpu.c @@ -12,7 +12,10 @@ static void generate_fdt_nodes(void *fdt, struct kvm *kvm, u32 gic_phandle) { int timer_interrupts[4] = {13, 14, 11, 10}; - gic__generate_fdt_nodes(fdt, gic_phandle, KVM_DEV_TYPE_ARM_VGIC_V2); + gic__generate_fdt_nodes(fdt, gic_phandle, + kvm->cfg.arch.gicv3 ? + KVM_DEV_TYPE_ARM_VGIC_V3 : + KVM_DEV_TYPE_ARM_VGIC_V2); timer__generate_fdt_nodes(fdt, kvm, timer_interrupts); } diff --git a/tools/kvm/arm/aarch64/include/kvm/kvm-config-arch.h b/tools/kvm/arm/aarch64/include/kvm/kvm-config-arch.h index 89860ae..780a6d1 100644 --- a/tools/kvm/arm/aarch64/include/kvm/kvm-config-arch.h +++ b/tools/kvm/arm/aarch64/include/kvm/kvm-config-arch.h @@ -3,7 +3,9 @@ #define ARM_OPT_ARCH_RUN(cfg) \ OPT_BOOLEAN('\0', "aarch32", &(cfg)->aarch32_guest, \ - "Run AArch32 guest"), + "Run AArch32 guest"), \ + OPT_BOOLEAN('\0', "gicv3", &(cfg)->gicv3, \ + "use a GICv3 interrupt controller in the guest"), #include "arm-common/kvm-config-arch.h" diff --git a/tools/kvm/arm/gic.c b/tools/kvm/arm/gic.c index 5141868..15dc99d 100644 --- a/tools/kvm/arm/gic.c +++ b/tools/kvm/arm/gic.c @@ -76,6 +76,7 @@ static int gic__create_device(struct kvm *kvm, u32 type) case KVM_DEV_TYPE_ARM_VGIC_V3: dist_attr.attr = KVM_VGIC_V3_ADDR_TYPE_DIST; redist_addr = dist_addr - nr_redists * ARM_GIC_REDIST_SIZE; + pr_info("creating GICv3 KVM device"); break; default: return -ENODEV; @@ -119,6 +120,17 @@ static int gic__create_irqchip(struct kvm *kvm) return err; } +static int gicv3__init_irqchip(struct kvm *kvm) +{ + if (kvm->nrcpus > 255) { + pr_warning("%d CPUS greater than maximum of %d -- truncating\n", + kvm->nrcpus, 255); + kvm->nrcpus = 255; + } + + return gic__create_device(kvm, KVM_DEV_TYPE_ARM_VGIC_V3); +} + static int gicv2__init_irqchip(struct kvm *kvm) { int err; @@ -150,6 +162,9 @@ int gic__init_irqchip(struct kvm *kvm, u32 type) switch (type) { case KVM_DEV_TYPE_ARM_VGIC_V2: return gicv2__init_irqchip(kvm); + case KVM_DEV_TYPE_ARM_VGIC_V3: + nr_redists = kvm->cfg.nrcpus; + return gicv3__init_irqchip(kvm); } return -ENODEV; } @@ -196,6 +211,8 @@ void gic__generate_fdt_nodes(void *fdt, u32 phandle, u32 type) compatible = "arm,gic-v3"; reg_prop[2] = ARM_GIC_DIST_BASE - nr_redists * ARM_GIC_REDIST_SIZE; reg_prop[3] = ARM_GIC_REDIST_SIZE * nr_redists; + pr_info("creating FDT for a GICv3 with %d redistributors", + nr_redists); break; default: return; diff --git a/tools/kvm/arm/include/arm-common/kvm-config-arch.h b/tools/kvm/arm/include/arm-common/kvm-config-arch.h index f3baf39..088b012 100644 --- a/tools/kvm/arm/include/arm-common/kvm-config-arch.h +++ b/tools/kvm/arm/include/arm-common/kvm-config-arch.h @@ -7,6 +7,7 @@ struct kvm_config_arch { const char *dump_dtb_filename; unsigned int force_cntfrq; bool aarch32_guest; + bool gicv3; }; #define OPT_ARCH_RUN(pfx, cfg) \ diff --git a/tools/kvm/arm/kvm.c b/tools/kvm/arm/kvm.c index faf4702..3858170 100644 --- a/tools/kvm/arm/kvm.c +++ b/tools/kvm/arm/kvm.c @@ -80,6 +80,8 @@ void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size) MADV_MERGEABLE); /* Initialise the virtual GIC. */ - if (gic__init_irqchip(kvm, KVM_DEV_TYPE_ARM_VGIC_V2)) + if (gic__init_irqchip(kvm, kvm->cfg.arch.gicv3 ? + KVM_DEV_TYPE_ARM_VGIC_V3 : + KVM_DEV_TYPE_ARM_VGIC_V2)) die("Failed to initialise virtual GIC"); } -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html