From patchwork Tue Feb 4 16:53:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 3577941 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 693739F382 for ; Tue, 4 Feb 2014 16:54:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6135820158 for ; Tue, 4 Feb 2014 16:54:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3A7B92018B for ; Tue, 4 Feb 2014 16:54:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932185AbaBDQyH (ORCPT ); Tue, 4 Feb 2014 11:54:07 -0500 Received: from cam-admin0.cambridge.arm.com ([217.140.96.50]:49551 "EHLO cam-admin0.cambridge.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932156AbaBDQx7 (ORCPT ); Tue, 4 Feb 2014 11:53:59 -0500 Received: from mudshark.cambridge.arm.com (mudshark.cambridge.arm.com [10.1.203.36]) by cam-admin0.cambridge.arm.com (8.12.6/8.12.6) with ESMTP id s14GrYki003321; Tue, 4 Feb 2014 16:53:34 GMT Received: by mudshark.cambridge.arm.com (Postfix, from userid 1000) id 1D364C2B19; Tue, 4 Feb 2014 16:53:33 +0000 (GMT) From: Will Deacon To: kvm@vger.kernel.org Cc: kvmarm@lists.cs.columbia.edu, penberg@kernel.org, marc.zyngier@arm.com, arnd@arndb.de Subject: [PATCH 12/17] kvm tools: irq: make irq__alloc_line generic Date: Tue, 4 Feb 2014 16:53:27 +0000 Message-Id: <1391532812-2043-13-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 1.8.2.2 In-Reply-To: <1391532812-2043-1-git-send-email-will.deacon@arm.com> References: <1391532812-2043-1-git-send-email-will.deacon@arm.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 All architectures are now doing the same thing for irq__alloc_line: 1. Initialise a global counter to some fixed offset 2. Return the current value of the counter and increment it This is better off in core code, with each architecture specifying the initial offset, which is specific to the interrupt controller being used by the guest. Signed-off-by: Will Deacon --- tools/kvm/Makefile | 1 + tools/kvm/arm/gic.c | 12 ------------ tools/kvm/arm/include/arm-common/kvm-arch.h | 4 ++++ tools/kvm/arm/ioport.c | 5 ++--- tools/kvm/arm/irq.c | 7 ------- tools/kvm/irq.c | 9 +++++++++ tools/kvm/powerpc/include/kvm/kvm-arch.h | 2 ++ tools/kvm/powerpc/irq.c | 17 ----------------- tools/kvm/powerpc/xics.c | 28 ++-------------------------- tools/kvm/x86/include/kvm/kvm-arch.h | 2 ++ tools/kvm/x86/irq.c | 7 ------- 11 files changed, 22 insertions(+), 72 deletions(-) create mode 100644 tools/kvm/irq.c diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile index 27fb2fbeae8d..29f18220c749 100644 --- a/tools/kvm/Makefile +++ b/tools/kvm/Makefile @@ -57,6 +57,7 @@ OBJS += guest_compat.o OBJS += hw/rtc.o OBJS += hw/serial.o OBJS += ioport.o +OBJS += irq.o OBJS += kvm-cpu.o OBJS += kvm.o OBJS += main.o diff --git a/tools/kvm/arm/gic.c b/tools/kvm/arm/gic.c index 8d2ff873c2de..5d8cbe64e628 100644 --- a/tools/kvm/arm/gic.c +++ b/tools/kvm/arm/gic.c @@ -7,18 +7,6 @@ #include #include -static int irq_ids; - -int gic__alloc_irqnum(void) -{ - int irq = GIC_SPI_IRQ_BASE + irq_ids++; - - if (irq > GIC_MAX_IRQ) - die("GIC IRQ limit %d reached!", GIC_MAX_IRQ); - - return irq; -} - int gic__init_irqchip(struct kvm *kvm) { int err; diff --git a/tools/kvm/arm/include/arm-common/kvm-arch.h b/tools/kvm/arm/include/arm-common/kvm-arch.h index caef590a44ff..348e88d00b1c 100644 --- a/tools/kvm/arm/include/arm-common/kvm-arch.h +++ b/tools/kvm/arm/include/arm-common/kvm-arch.h @@ -5,6 +5,8 @@ #include #include +#include "arm-common/gic.h" + #define ARM_IOPORT_AREA _AC(0x0000000000000000, UL) #define ARM_MMIO_AREA _AC(0x0000000000010000, UL) #define ARM_AXI_AREA _AC(0x0000000040000000, UL) @@ -28,6 +30,8 @@ #define KVM_PCI_MMIO_AREA (KVM_PCI_CFG_AREA + ARM_PCI_CFG_SIZE) #define KVM_VIRTIO_MMIO_AREA ARM_MMIO_AREA +#define KVM_IRQ_OFFSET GIC_SPI_IRQ_BASE + #define VIRTIO_DEFAULT_TRANS VIRTIO_MMIO static inline bool arm_addr_in_ioport_region(u64 phys_addr) diff --git a/tools/kvm/arm/ioport.c b/tools/kvm/arm/ioport.c index 74ee10ec16ca..bdd30b6fe812 100644 --- a/tools/kvm/arm/ioport.c +++ b/tools/kvm/arm/ioport.c @@ -1,6 +1,5 @@ #include "kvm/ioport.h" - -#include "arm-common/gic.h" +#include "kvm/irq.h" void ioport__setup_arch(struct kvm *kvm) { @@ -8,5 +7,5 @@ void ioport__setup_arch(struct kvm *kvm) void ioport__map_irq(u8 *irq) { - *irq = gic__alloc_irqnum(); + *irq = irq__alloc_line(); } diff --git a/tools/kvm/arm/irq.c b/tools/kvm/arm/irq.c index a39a2c289d27..d8f44dfbfec4 100644 --- a/tools/kvm/arm/irq.c +++ b/tools/kvm/arm/irq.c @@ -2,13 +2,6 @@ #include "kvm/kvm.h" #include "kvm/util.h" -#include "arm-common/gic.h" - -int irq__alloc_line(void) -{ - return gic__alloc_irqnum(); -} - int irq__add_msix_route(struct kvm *kvm, struct msi_msg *msg) { die(__FUNCTION__); diff --git a/tools/kvm/irq.c b/tools/kvm/irq.c new file mode 100644 index 000000000000..33ea8d22e285 --- /dev/null +++ b/tools/kvm/irq.c @@ -0,0 +1,9 @@ +#include "kvm/irq.h" +#include "kvm/kvm-arch.h" + +static u8 next_line = KVM_IRQ_OFFSET; + +int irq__alloc_line(void) +{ + return next_line++; +} diff --git a/tools/kvm/powerpc/include/kvm/kvm-arch.h b/tools/kvm/powerpc/include/kvm/kvm-arch.h index c147c78b71e7..d2b52bf0f617 100644 --- a/tools/kvm/powerpc/include/kvm/kvm-arch.h +++ b/tools/kvm/powerpc/include/kvm/kvm-arch.h @@ -42,6 +42,8 @@ #define KVM_PCI_MMIO_AREA 0x2000000 #define KVM_VIRTIO_MMIO_AREA 0x3000000 +#define KVM_IRQ_OFFSET 16 + #define VIRTIO_DEFAULT_TRANS VIRTIO_PCI struct spapr_phb; diff --git a/tools/kvm/powerpc/irq.c b/tools/kvm/powerpc/irq.c index c187d8f306f2..03f2fe792365 100644 --- a/tools/kvm/powerpc/irq.c +++ b/tools/kvm/powerpc/irq.c @@ -24,23 +24,6 @@ #include "kvm/pci.h" -#include "xics.h" -#include "spapr_pci.h" - -/* - * FIXME: The code in this file assumes an SPAPR guest, using XICS. Make - * generic & cope with multiple PPC platform types. - */ - -int irq__alloc_line(void) -{ - /* - * Have I said how nasty I find this? Line should be dontcare... PHB - * should determine which CPU/XICS IRQ to fire. - */ - return xics_alloc_irqnum(); -} - int irq__add_msix_route(struct kvm *kvm, struct msi_msg *msg) { die(__FUNCTION__); diff --git a/tools/kvm/powerpc/xics.c b/tools/kvm/powerpc/xics.c index 9dc27b8b7752..071b928a7ada 100644 --- a/tools/kvm/powerpc/xics.c +++ b/tools/kvm/powerpc/xics.c @@ -14,6 +14,7 @@ #include "spapr.h" #include "xics.h" #include "kvm/util.h" +#include "kvm/kvm.h" #include #include @@ -41,7 +42,7 @@ struct icp_server_state { struct kvm_cpu *cpu; }; -#define XICS_IRQ_OFFSET 16 +#define XICS_IRQ_OFFSET KVM_IRQ_OFFSET #define XISR_MASK 0x00ffffff #define CPPR_MASK 0xff000000 @@ -273,31 +274,6 @@ static void ics_eoi(struct ics_state *ics, int nr) * Exported functions */ -static int allocated_irqnum = XICS_IRQ_OFFSET; - -/* - * xics_alloc_irqnum(): This is hacky. The problem boils down to the PCI device - * code which just calls kvm__irq_line( .. pcidev->pci_hdr.irq_line ..) at will. - * Each PCI device's IRQ line is allocated by irq__alloc_line() (which - * allocates an IRQ AND allocates a.. PCI device num..). - * - * In future I'd like to at least mimic some kind of 'upstream IRQ controller' - * whereby PCI devices let their PHB know when they want to IRQ, and that - * percolates up. - * - * For now, allocate a REAL xics irq number and (via irq__alloc_line) push - * that into the config space. 8 bits only though! - */ -int xics_alloc_irqnum(void) -{ - int irq = allocated_irqnum++; - - if (irq > 255) - die("Huge numbers of IRQs aren't supported with the daft kvmtool IRQ system."); - - return irq; -} - static target_ulong h_cppr(struct kvm_cpu *vcpu, target_ulong opcode, target_ulong *args) { diff --git a/tools/kvm/x86/include/kvm/kvm-arch.h b/tools/kvm/x86/include/kvm/kvm-arch.h index 8e8389627354..29953a761aa4 100644 --- a/tools/kvm/x86/include/kvm/kvm-arch.h +++ b/tools/kvm/x86/include/kvm/kvm-arch.h @@ -25,6 +25,8 @@ #define KVM_PCI_MMIO_AREA (KVM_MMIO_START + 0x2000000) #define KVM_VIRTIO_MMIO_AREA (KVM_MMIO_START + 0x3000000) +#define KVM_IRQ_OFFSET 5 + #define VIRTIO_DEFAULT_TRANS VIRTIO_PCI struct kvm_arch { diff --git a/tools/kvm/x86/irq.c b/tools/kvm/x86/irq.c index 5bd6aa42987e..72177e7dfd91 100644 --- a/tools/kvm/x86/irq.c +++ b/tools/kvm/x86/irq.c @@ -16,8 +16,6 @@ #define IRQCHIP_SLAVE 1 #define IRQCHIP_IOAPIC 2 -static u8 next_line = 5; - /* First 24 GSIs are routed between IRQCHIPs and IOAPICs */ static u32 gsi = 24; @@ -39,11 +37,6 @@ static int irq__add_routing(u32 gsi, u32 type, u32 irqchip, u32 pin) return 0; } -int irq__alloc_line(void) -{ - return next_line++; -} - int irq__init(struct kvm *kvm) { int i, r;