From patchwork Fri Jan 23 16:35:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 5696291 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 4890A9F665 for ; Fri, 23 Jan 2015 16:36:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6E5C3202C8 for ; Fri, 23 Jan 2015 16:36:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 72D3F202E6 for ; Fri, 23 Jan 2015 16:36:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756233AbbAWQf5 (ORCPT ); Fri, 23 Jan 2015 11:35:57 -0500 Received: from cam-admin0.cambridge.arm.com ([217.140.96.50]:40588 "EHLO cam-admin0.cambridge.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756056AbbAWQfa (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 t0NGZAwr018471; Fri, 23 Jan 2015 16:35:17 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 03/11] kvmtool: AArch{32, 64}: use KVM_CREATE_DEVICE & co to instanciate the GIC Date: Fri, 23 Jan 2015 16:35:02 +0000 Message-Id: <1422030910-17881-4-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 From: Marc Zyngier As of 3.14, KVM/arm supports the creation/configuration of the GIC through a more generic device API, which is now the preferred way to do so. Plumb the new API in, and allow the old code to be used as a fallback. [Andre: Rename some functions on the way to differentiate between creation and initialisation more clearly.] Signed-off-by: Marc Zyngier Signed-off-by: Andre Przywara --- tools/kvm/arm/gic.c | 60 ++++++++++++++++++++++++++++---- tools/kvm/arm/include/arm-common/gic.h | 2 +- tools/kvm/arm/kvm.c | 6 ++-- 3 files changed, 57 insertions(+), 11 deletions(-) diff --git a/tools/kvm/arm/gic.c b/tools/kvm/arm/gic.c index 5d8cbe6..ce5f7fa 100644 --- a/tools/kvm/arm/gic.c +++ b/tools/kvm/arm/gic.c @@ -7,7 +7,41 @@ #include #include -int gic__init_irqchip(struct kvm *kvm) +static int gic_fd = -1; + +static int gic__create_device(struct kvm *kvm) +{ + 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, + }; + struct kvm_device_attr cpu_if_attr = { + .group = KVM_DEV_ARM_VGIC_GRP_ADDR, + .attr = KVM_VGIC_V2_ADDR_TYPE_CPU, + .addr = (u64)(unsigned long)&cpu_if_addr, + }; + 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, + }; + + err = ioctl(kvm->vm_fd, KVM_CREATE_DEVICE, &gic_device); + if (err) + return err; + + gic_fd = gic_device.fd; + + 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); +} + +static int gic__create_irqchip(struct kvm *kvm) { int err; struct kvm_arm_device_addr gic_addr[] = { @@ -23,12 +57,6 @@ int gic__init_irqchip(struct kvm *kvm) } }; - if (kvm->nrcpus > GIC_MAX_CPUS) { - pr_warning("%d CPUS greater than maximum of %d -- truncating\n", - kvm->nrcpus, GIC_MAX_CPUS); - kvm->nrcpus = GIC_MAX_CPUS; - } - err = ioctl(kvm->vm_fd, KVM_CREATE_IRQCHIP); if (err) return err; @@ -41,6 +69,24 @@ int gic__init_irqchip(struct kvm *kvm) return err; } +int gic__create(struct kvm *kvm) +{ + int err; + + if (kvm->nrcpus > GIC_MAX_CPUS) { + pr_warning("%d CPUS greater than maximum of %d -- truncating\n", + kvm->nrcpus, GIC_MAX_CPUS); + kvm->nrcpus = GIC_MAX_CPUS; + } + + /* Try the new way first, and fallback on legacy method otherwise */ + err = gic__create_device(kvm); + if (err) + err = gic__create_irqchip(kvm); + + return err; +} + void gic__generate_fdt_nodes(void *fdt, u32 phandle) { u64 reg_prop[] = { diff --git a/tools/kvm/arm/include/arm-common/gic.h b/tools/kvm/arm/include/arm-common/gic.h index 5487125..9bbe81e 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); +int gic__create(struct kvm *kvm); void gic__generate_fdt_nodes(void *fdt, u32 phandle); #endif /* ARM_COMMON__GIC_H */ diff --git a/tools/kvm/arm/kvm.c b/tools/kvm/arm/kvm.c index 58ad9fa..bcd2533 100644 --- a/tools/kvm/arm/kvm.c +++ b/tools/kvm/arm/kvm.c @@ -81,7 +81,7 @@ void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size) madvise(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size, MADV_MERGEABLE | MADV_HUGEPAGE); - /* Initialise the virtual GIC. */ - if (gic__init_irqchip(kvm)) - die("Failed to initialise virtual GIC"); + /* Create the virtual GIC. */ + if (gic__create(kvm)) + die("Failed to create virtual GIC"); }