From patchwork Fri Jan 23 16:35:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 5696251 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id EBD49C058D for ; Fri, 23 Jan 2015 16:36:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 04537202E5 for ; Fri, 23 Jan 2015 16:36:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E6D35202C8 for ; Fri, 23 Jan 2015 16:35:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756058AbbAWQfz (ORCPT ); Fri, 23 Jan 2015 11:35:55 -0500 Received: from cam-admin0.cambridge.arm.com ([217.140.96.50]:40589 "EHLO cam-admin0.cambridge.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756057AbbAWQfa (ORCPT ); Fri, 23 Jan 2015 11:35:30 -0500 Received: from e106785-lin.cambridge.arm.com ([10.1.203.153]) by cam-admin0.cambridge.arm.com (8.12.6/8.12.6) with ESMTP id t0NGZAwv018471; Fri, 23 Jan 2015 16:35:18 GMT From: Andre Przywara To: penberg@kernel.org, will.deacon@arm.com Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, marc.zyngier@arm.com Subject: [PATCH 07/11] kvmtool: prepare for instantiating different IRQ chip devices Date: Fri, 23 Jan 2015 16:35:06 +0000 Message-Id: <1422030910-17881-8-git-send-email-andre.przywara@arm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1422030910-17881-1-git-send-email-andre.przywara@arm.com> References: <1422030910-17881-1-git-send-email-andre.przywara@arm.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Extend the vGIC handling code to deal with different IRQ chip devices instead of hard-coding the GICv2 in. Signed-off-by: Andre Przywara --- 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"); }