From patchwork Fri Jan 23 16:35:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 5696231 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 72B879F357 for ; Fri, 23 Jan 2015 16:35:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7C273202C8 for ; Fri, 23 Jan 2015 16:35:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7996C202E6 for ; Fri, 23 Jan 2015 16:35:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756077AbbAWQfc (ORCPT ); Fri, 23 Jan 2015 11:35:32 -0500 Received: from cam-admin0.cambridge.arm.com ([217.140.96.50]:40582 "EHLO cam-admin0.cambridge.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756046AbbAWQfa (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 t0NGZAx0018471; 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 10/11] kvmtool: add support for supplying GICv3 redistributor addresses Date: Fri, 23 Jan 2015 16:35:09 +0000 Message-Id: <1422030910-17881-11-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 The code currently is assuming fixed sized memory regions for the distributor and CPU interface. GICv3 needs a dynamic allocation of it's redistributor region, since it's size depends on the number of vCPUs. Also add the necessary code to create a GICv3 IRQ chip instance. Signed-off-by: Andre Przywara --- tools/kvm/arm/gic.c | 30 ++++++++++++++++++++++++--- tools/kvm/arm/include/arm-common/kvm-arch.h | 18 ++++++++++++---- tools/kvm/arm/kvm-cpu.c | 4 +++- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/tools/kvm/arm/gic.c b/tools/kvm/arm/gic.c index f4bda339..9435715 100644 --- a/tools/kvm/arm/gic.c +++ b/tools/kvm/arm/gic.c @@ -10,12 +10,14 @@ #include static int gic_fd = -1; +static int nr_redists; 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; + u64 redist_addr; struct kvm_create_device gic_device = { .type = type, }; @@ -26,9 +28,13 @@ static int gic__create_device(struct kvm *kvm, u32 type) }; struct kvm_device_attr dist_attr = { .group = KVM_DEV_ARM_VGIC_GRP_ADDR, - .attr = KVM_VGIC_V2_ADDR_TYPE_DIST, .addr = (u64)(unsigned long)&dist_addr, }; + struct kvm_device_attr redist_attr = { + .group = KVM_DEV_ARM_VGIC_GRP_ADDR, + .attr = KVM_VGIC_V3_ADDR_TYPE_REDIST, + .addr = (u64)(unsigned long)&redist_addr, + }; err = ioctl(kvm->vm_fd, KVM_CREATE_DEVICE, &gic_device); if (err) @@ -41,12 +47,22 @@ static int gic__create_device(struct kvm *kvm, u32 type) err = ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &cpu_if_attr); if (err) return err; + dist_attr.attr = KVM_VGIC_V2_ADDR_TYPE_DIST; + break; + 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; break; default: return -ENODEV; } err = ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &dist_attr); + if (err) + return err; + + if (type == KVM_DEV_TYPE_ARM_VGIC_V3) + err = ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &redist_attr); return err; } @@ -154,17 +170,25 @@ void gic__generate_fdt_nodes(void *fdt, u32 phandle, u32 type) 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), + 0, 0, /* to be filled */ }; switch (type) { case KVM_DEV_TYPE_ARM_VGIC_V2: compatible = "arm,cortex-a15-gic"; + reg_prop[2] = ARM_GIC_CPUI_BASE; + reg_prop[3] = ARM_GIC_CPUI_SIZE; + break; + case KVM_DEV_TYPE_ARM_VGIC_V3: + 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; break; default: return; } + reg_prop[2] = cpu_to_fdt64(reg_prop[2]); + reg_prop[3] = cpu_to_fdt64(reg_prop[3]); _FDT(fdt_begin_node(fdt, "intc")); _FDT(fdt_property_string(fdt, "compatible", compatible)); diff --git a/tools/kvm/arm/include/arm-common/kvm-arch.h b/tools/kvm/arm/include/arm-common/kvm-arch.h index 082131d..be66a76 100644 --- a/tools/kvm/arm/include/arm-common/kvm-arch.h +++ b/tools/kvm/arm/include/arm-common/kvm-arch.h @@ -17,10 +17,8 @@ #define ARM_GIC_DIST_BASE (ARM_AXI_AREA - ARM_GIC_DIST_SIZE) #define ARM_GIC_CPUI_BASE (ARM_GIC_DIST_BASE - ARM_GIC_CPUI_SIZE) -#define ARM_GIC_SIZE (ARM_GIC_DIST_SIZE + ARM_GIC_CPUI_SIZE) #define ARM_IOPORT_SIZE (ARM_MMIO_AREA - ARM_IOPORT_AREA) -#define ARM_VIRTIO_MMIO_SIZE (ARM_AXI_AREA - (ARM_MMIO_AREA + ARM_GIC_SIZE)) #define ARM_PCI_CFG_SIZE (1ULL << 24) #define ARM_PCI_MMIO_SIZE (ARM_MEMORY_AREA - \ (ARM_AXI_AREA + ARM_PCI_CFG_SIZE)) @@ -30,6 +28,13 @@ #define KVM_PCI_MMIO_AREA (KVM_PCI_CFG_AREA + ARM_PCI_CFG_SIZE) #define KVM_VIRTIO_MMIO_AREA ARM_MMIO_AREA +/* + * On a GICv3 there must be one redistributor per vCPU. + * The value here is the size for one, we multiply this at runtime with + * the number of requested vCPUs to get the actual size. + */ +#define ARM_GIC_REDIST_SIZE 0x20000 + #define KVM_IRQ_OFFSET GIC_SPI_IRQ_BASE #define KVM_VM_TYPE 0 @@ -45,9 +50,14 @@ static inline bool arm_addr_in_ioport_region(u64 phys_addr) return phys_addr >= KVM_IOPORT_AREA && phys_addr < limit; } -static inline bool arm_addr_in_virtio_mmio_region(u64 phys_addr) +static inline bool arm_addr_in_virtio_mmio_region(int nr_redists, u64 phys_addr) { - u64 limit = KVM_VIRTIO_MMIO_AREA + ARM_VIRTIO_MMIO_SIZE; + u64 limit = ARM_AXI_AREA - ARM_GIC_DIST_SIZE; + + if (nr_redists) + limit -= ARM_GIC_REDIST_SIZE * nr_redists; + else + limit -= ARM_GIC_CPUI_SIZE; return phys_addr >= KVM_VIRTIO_MMIO_AREA && phys_addr < limit; } diff --git a/tools/kvm/arm/kvm-cpu.c b/tools/kvm/arm/kvm-cpu.c index ab08815..a3344fa 100644 --- a/tools/kvm/arm/kvm-cpu.c +++ b/tools/kvm/arm/kvm-cpu.c @@ -142,7 +142,9 @@ bool kvm_cpu__handle_exit(struct kvm_cpu *vcpu) bool kvm_cpu__emulate_mmio(struct kvm_cpu *vcpu, u64 phys_addr, u8 *data, u32 len, u8 is_write) { - if (arm_addr_in_virtio_mmio_region(phys_addr)) { + int nr_redists = 0; + + if (arm_addr_in_virtio_mmio_region(nr_redists, phys_addr)) { return kvm__emulate_mmio(vcpu, phys_addr, data, len, is_write); } else if (arm_addr_in_ioport_region(phys_addr)) { int direction = is_write ? KVM_EXIT_IO_OUT : KVM_EXIT_IO_IN;