From patchwork Wed Nov 22 18:58:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 10070753 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8719A601D5 for ; Wed, 22 Nov 2017 18:56:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7BCAA29D74 for ; Wed, 22 Nov 2017 18:56:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 708DD29D96; Wed, 22 Nov 2017 18:56:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49D7429D74 for ; Wed, 22 Nov 2017 18:56:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752114AbdKVS43 (ORCPT ); Wed, 22 Nov 2017 13:56:29 -0500 Received: from foss.arm.com ([217.140.101.70]:54998 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752097AbdKVS41 (ORCPT ); Wed, 22 Nov 2017 13:56:27 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8BFE01435; Wed, 22 Nov 2017 10:56:26 -0800 (PST) Received: from e106794-lin.cambridge.arm.com (e106794-lin.cambridge.arm.com [10.1.210.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 361C83F487; Wed, 22 Nov 2017 10:56:25 -0800 (PST) From: Jean-Philippe Brucker To: kvm@vger.kernel.org Cc: Will.Deacon@arm.com, Robin.Murphy@arm.com, Lorenzo.Pieralisi@arm.com, Marc.Zyngier@arm.com, Punit.Agrawal@arm.com, alex.williamson@redhat.com Subject: [PATCH v4 kvmtool 02/12] pci: allow to specify IRQ type for PCI devices Date: Wed, 22 Nov 2017 18:58:13 +0000 Message-Id: <20171122185823.7765-3-jean-philippe.brucker@arm.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171122185823.7765-1-jean-philippe.brucker@arm.com> References: <20171122185823.7765-1-jean-philippe.brucker@arm.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently all our virtual device interrupts are edge-triggered. But we're going to need level-triggered interrupts when passing physical devices. Let the device configure its interrupt kind. Keep edge as default, to avoid changing existing users. Signed-off-by: Jean-Philippe Brucker --- arm/pci.c | 3 ++- include/kvm/pci.h | 6 ++++++ pci.c | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/arm/pci.c b/arm/pci.c index 813df26a822e..744b14c26a84 100644 --- a/arm/pci.c +++ b/arm/pci.c @@ -77,6 +77,7 @@ void pci__generate_fdt_nodes(void *fdt) u8 dev_num = dev_hdr->dev_num; u8 pin = pci_hdr->irq_pin; u8 irq = pci_hdr->irq_line; + u32 irq_flags = pci_hdr->irq_type; *entry = (struct of_interrupt_map_entry) { .pci_irq_mask = { @@ -93,7 +94,7 @@ void pci__generate_fdt_nodes(void *fdt) .gic_irq = { .type = cpu_to_fdt32(GIC_FDT_IRQ_TYPE_SPI), .num = cpu_to_fdt32(irq - GIC_SPI_IRQ_BASE), - .flags = cpu_to_fdt32(IRQ_TYPE_EDGE_RISING), + .flags = cpu_to_fdt32(irq_flags), }, }; diff --git a/include/kvm/pci.h b/include/kvm/pci.h index 56649d87dfb4..5d9c0f3b045f 100644 --- a/include/kvm/pci.h +++ b/include/kvm/pci.h @@ -9,6 +9,7 @@ #include "kvm/devices.h" #include "kvm/kvm.h" #include "kvm/msi.h" +#include "kvm/fdt.h" /* * PCI Configuration Mechanism #1 I/O ports. See Section 3.7.4.1. @@ -105,6 +106,11 @@ struct pci_device_header { /* Private to lkvm */ u32 bar_size[6]; struct pci_config_operations cfg_ops; + /* + * PCI INTx# are level-triggered, but virtual device often feature + * edge-triggered INTx# for convenience. + */ + enum irq_type irq_type; }; int pci__init(struct kvm *kvm); diff --git a/pci.c b/pci.c index e48e24b8c7b1..5a8c2ef41e93 100644 --- a/pci.c +++ b/pci.c @@ -39,6 +39,9 @@ void pci__assign_irq(struct device_header *dev_hdr) */ pci_hdr->irq_pin = 1; pci_hdr->irq_line = irq__alloc_line(); + + if (!pci_hdr->irq_type) + pci_hdr->irq_type = IRQ_TYPE_EDGE_RISING; } static void *pci_config_address_ptr(u16 port)