From patchwork Thu Jun 19 12:44:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 4383011 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 58F3CBEEAA for ; Thu, 19 Jun 2014 12:44:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 645E720340 for ; Thu, 19 Jun 2014 12:44:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3AD8D202EB for ; Thu, 19 Jun 2014 12:44:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752363AbaFSMoo (ORCPT ); Thu, 19 Jun 2014 08:44:44 -0400 Received: from cam-admin0.cambridge.arm.com ([217.140.96.50]:62806 "EHLO cam-admin0.cambridge.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750977AbaFSMon (ORCPT ); Thu, 19 Jun 2014 08:44:43 -0400 Received: from e106785-lin.cambridge.arm.com (e106785-lin.cambridge.arm.com [10.1.209.161]) by cam-admin0.cambridge.arm.com (8.12.6/8.12.6) with ESMTP id s5JCidwq005003; Thu, 19 Jun 2014 13:44:40 +0100 (BST) From: Andre Przywara To: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Cc: will.deacon@arm.com, marc.zyngier@arm.com Subject: [PATCH 2/4] kvmtool: prepare for instantiating different IRQ chip devices Date: Thu, 19 Jun 2014 13:44:37 +0100 Message-Id: <1403181879-29908-3-git-send-email-andre.przywara@arm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1403181879-29908-1-git-send-email-andre.przywara@arm.com> References: <1403181879-29908-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/aarch64/arm-cpu.c | 2 +- tools/kvm/arm/gic.c | 59 ++++++++++++++++++++++++-------- tools/kvm/arm/include/arm-common/gic.h | 4 +-- tools/kvm/arm/kvm.c | 2 +- tools/kvm/virtio/mmio.c | 2 +- 5 files changed, 49 insertions(+), 20 deletions(-) diff --git a/tools/kvm/arm/aarch64/arm-cpu.c b/tools/kvm/arm/aarch64/arm-cpu.c index ce5ea2f..35771e0 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 c92deaa..770c6e7 100644 --- a/tools/kvm/arm/gic.c +++ b/tools/kvm/arm/gic.c @@ -22,13 +22,13 @@ int gic__alloc_irqnum(void) return irq; } -static int gic__create_device(struct kvm *kvm) +static int gic__create_device(struct kvm *kvm, u32 type) { int err; u32 offset = 0; 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 offset_attr = { .group = KVM_DEV_ARM_VGIC_GRP_ADDR_OFFSET, @@ -51,19 +51,28 @@ static int gic__create_device(struct kvm *kvm) gic_fd = gic_device.fd; - if (!ioctl(gic_fd, KVM_HAS_DEVICE_ATTR, &offset_attr)) { - err = ioctl(gic_fd, KVM_GET_DEVICE_ATTR, &offset_attr); + switch (type) { + case KVM_DEV_TYPE_ARM_VGIC_V2: + if (!ioctl(gic_fd, KVM_HAS_DEVICE_ATTR, &offset_attr)) { + err = ioctl(gic_fd, KVM_GET_DEVICE_ATTR, &offset_attr); + if (err) + return err; + } + + cpu_if_addr += offset; + + err = ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &cpu_if_attr); if (err) return err; + pr_info("creating GICv2 KVM device"); + break; + default: + return -ENODEV; } - cpu_if_addr += offset; + err = ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &dist_attr); - err = ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &cpu_if_attr); - if (err) - return err; - - return ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &dist_attr); + return err; } static int gic__create_irqchip(struct kvm *kvm) @@ -94,7 +103,7 @@ static int gic__create_irqchip(struct kvm *kvm) return err; } -int gic__init_irqchip(struct kvm *kvm) +static int gicv2__init_irqchip(struct kvm *kvm) { int err; int psz; @@ -113,13 +122,22 @@ int gic__init_irqchip(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__init_irqchip(struct kvm *kvm, u32 type) +{ + switch (type) { + case KVM_DEV_TYPE_ARM_VGIC_V2: + return gicv2__init_irqchip(kvm); + } + return -ENODEV; +} + static int gic__init_max_irq(struct kvm *kvm) { u32 nr_irqs = ALIGN(irq_ids, 32) + GIC_SPI_IRQ_BASE; @@ -142,15 +160,26 @@ static int gic__init_max_irq(struct kvm *kvm) } late_init(gic__init_max_irq) -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_DIST_BASE), + cpu_to_fdt64(ARM_GIC_DIST_SIZE), cpu_to_fdt64(cpu_if_addr), cpu_to_fdt64(ARM_GIC_CPUI_SIZE), }; + switch (type) { + case KVM_DEV_TYPE_ARM_VGIC_V2: + compatible = "arm,cortex-a15-gic"; + pr_info("creating FDT for a GICv2"); + 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 850edc7..ac6bdb6 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__init_irqchip(struct kvm *kvm); -void gic__generate_fdt_nodes(void *fdt, u32 phandle); +int gic__init_irqchip(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 008b7fe..faf4702 100644 --- a/tools/kvm/arm/kvm.c +++ b/tools/kvm/arm/kvm.c @@ -80,6 +80,6 @@ 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)) + if (gic__init_irqchip(kvm, KVM_DEV_TYPE_ARM_VGIC_V2)) die("Failed to initialise virtual GIC"); } diff --git a/tools/kvm/virtio/mmio.c b/tools/kvm/virtio/mmio.c index afae6a7..35dc113 100644 --- a/tools/kvm/virtio/mmio.c +++ b/tools/kvm/virtio/mmio.c @@ -293,7 +293,7 @@ int virtio_mmio_init(struct kvm *kvm, void *dev, struct virtio_device *vdev, * * virtio_mmio.devices=0x200@0xd2000000:5,0x200@0xd2000200:6 */ - pr_info("virtio-mmio.devices=0x%x@0x%x:%d\n", VIRTIO_MMIO_IO_SIZE, vmmio->addr, line); + pr_info("virtio-mmio.devices=0x%x@0x%x:%d", VIRTIO_MMIO_IO_SIZE, vmmio->addr, line); return 0; }