Extend the vGIC handling code to deal with different IRQ chip devices instead of hard-coding the GICv2 in. Signed-off-by: Andre Przywara <andre.przywara@xxxxxxx> --- tools/kvm/arm/aarch32/arm-cpu.c | 2 +- tools/kvm/arm/aarch64/arm-cpu.c | 2 +- tools/kvm/arm/gic.c | 52 ++++++++++++++++++++++++-------- tools/kvm/arm/include/arm-common/gic.h | 4 +-- tools/kvm/arm/kvm.c | 2 +- 5 files changed, 45 insertions(+), 17 deletions(-) diff --git a/tools/kvm/arm/aarch32/arm-cpu.c b/tools/kvm/arm/aarch32/arm-cpu.c index 946e443..ce68dc6 100644 --- a/tools/kvm/arm/aarch32/arm-cpu.c +++ b/tools/kvm/arm/aarch32/arm-cpu.c @@ -12,7 +12,7 @@ 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); + gic__generate_fdt_nodes(fdt, gic_phandle, KVM_DEV_TYPE_ARM_VGIC_V2); timer__generate_fdt_nodes(fdt, kvm, timer_interrupts); } diff --git a/tools/kvm/arm/aarch64/arm-cpu.c b/tools/kvm/arm/aarch64/arm-cpu.c index 8efe877..a70d6bb 100644 --- a/tools/kvm/arm/aarch64/arm-cpu.c +++ b/tools/kvm/arm/aarch64/arm-cpu.c @@ -12,7 +12,7 @@ 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); + gic__generate_fdt_nodes(fdt, gic_phandle, KVM_DEV_TYPE_ARM_VGIC_V2); timer__generate_fdt_nodes(fdt, kvm, timer_interrupts); } diff --git a/tools/kvm/arm/gic.c b/tools/kvm/arm/gic.c index 8d47562..f4bda339 100644 --- a/tools/kvm/arm/gic.c +++ b/tools/kvm/arm/gic.c @@ -11,13 +11,13 @@ static int gic_fd = -1; -static int gic__create_device(struct kvm *kvm) +static int gic__create_device(struct kvm *kvm, u32 type) { int err; u64 cpu_if_addr = ARM_GIC_CPUI_BASE; u64 dist_addr = ARM_GIC_DIST_BASE; struct kvm_create_device gic_device = { - .type = KVM_DEV_TYPE_ARM_VGIC_V2, + .type = type, }; struct kvm_device_attr cpu_if_attr = { .group = KVM_DEV_ARM_VGIC_GRP_ADDR, @@ -36,11 +36,19 @@ static int gic__create_device(struct kvm *kvm) gic_fd = gic_device.fd; - err = ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &cpu_if_attr); - if (err) - return err; + switch (type) { + case KVM_DEV_TYPE_ARM_VGIC_V2: + err = ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &cpu_if_attr); + if (err) + return err; + break; + default: + return -ENODEV; + } - return ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &dist_attr); + err = ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &dist_attr); + + return err; } static int gic__create_irqchip(struct kvm *kvm) @@ -71,7 +79,7 @@ static int gic__create_irqchip(struct kvm *kvm) return err; } -int gic__create(struct kvm *kvm) +static int gicv2__create_irqchip(struct kvm *kvm) { int err; @@ -82,13 +90,22 @@ int gic__create(struct kvm *kvm) } /* Try the new way first, and fallback on legacy method otherwise */ - err = gic__create_device(kvm); + err = gic__create_device(kvm, KVM_DEV_TYPE_ARM_VGIC_V2); if (err) err = gic__create_irqchip(kvm); return err; } +int gic__create(struct kvm *kvm, u32 type) +{ + switch (type) { + case KVM_DEV_TYPE_ARM_VGIC_V2: + return gicv2__create_irqchip(kvm); + } + return -ENODEV; +} + /* * Sets the number of used interrupts and finalizes the GIC init explicitly. */ @@ -131,15 +148,26 @@ static int gic__init_gic(struct kvm *kvm) } late_init(gic__init_gic) -void gic__generate_fdt_nodes(void *fdt, u32 phandle) +void gic__generate_fdt_nodes(void *fdt, u32 phandle, u32 type) { + const char *compatible; u64 reg_prop[] = { - cpu_to_fdt64(ARM_GIC_DIST_BASE), cpu_to_fdt64(ARM_GIC_DIST_SIZE), - cpu_to_fdt64(ARM_GIC_CPUI_BASE), cpu_to_fdt64(ARM_GIC_CPUI_SIZE), + cpu_to_fdt64(ARM_GIC_DIST_BASE), + cpu_to_fdt64(ARM_GIC_DIST_SIZE), + cpu_to_fdt64(ARM_GIC_CPUI_BASE), + cpu_to_fdt64(ARM_GIC_CPUI_SIZE), }; + switch (type) { + case KVM_DEV_TYPE_ARM_VGIC_V2: + compatible = "arm,cortex-a15-gic"; + break; + default: + return; + } + _FDT(fdt_begin_node(fdt, "intc")); - _FDT(fdt_property_string(fdt, "compatible", "arm,cortex-a15-gic")); + _FDT(fdt_property_string(fdt, "compatible", compatible)); _FDT(fdt_property_cell(fdt, "#interrupt-cells", GIC_FDT_IRQ_NUM_CELLS)); _FDT(fdt_property(fdt, "interrupt-controller", NULL, 0)); _FDT(fdt_property(fdt, "reg", reg_prop, sizeof(reg_prop))); diff --git a/tools/kvm/arm/include/arm-common/gic.h b/tools/kvm/arm/include/arm-common/gic.h index 9bbe81e..149f2ca 100644 --- a/tools/kvm/arm/include/arm-common/gic.h +++ b/tools/kvm/arm/include/arm-common/gic.h @@ -29,7 +29,7 @@ struct kvm; int gic__alloc_irqnum(void); -int gic__create(struct kvm *kvm); -void gic__generate_fdt_nodes(void *fdt, u32 phandle); +int gic__create(struct kvm *kvm, u32 type); +void gic__generate_fdt_nodes(void *fdt, u32 phandle, u32 type); #endif /* ARM_COMMON__GIC_H */ diff --git a/tools/kvm/arm/kvm.c b/tools/kvm/arm/kvm.c index bcd2533..8d31fd7 100644 --- a/tools/kvm/arm/kvm.c +++ b/tools/kvm/arm/kvm.c @@ -82,6 +82,6 @@ void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size) MADV_MERGEABLE | MADV_HUGEPAGE); /* Create the virtual GIC. */ - if (gic__create(kvm)) + if (gic__create(kvm, KVM_DEV_TYPE_ARM_VGIC_V2)) die("Failed to create 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