From patchwork Mon Nov 17 11:03:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 5318031 Return-Path: X-Original-To: patchwork-linux-arm@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 C30D49F1E1 for ; Mon, 17 Nov 2014 11:04:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CDDCA200F0 for ; Mon, 17 Nov 2014 11:04:39 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CC75D200CA for ; Mon, 17 Nov 2014 11:04:38 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XqK4Y-0001vf-Mq; Mon, 17 Nov 2014 11:02:18 +0000 Received: from mga09.intel.com ([134.134.136.24]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XqK3H-0000wj-BO for linux-arm-kernel@lists.infradead.org; Mon, 17 Nov 2014 11:01:00 +0000 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP; 17 Nov 2014 02:58:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.04,691,1406617200"; d="scan'208";a="487989055" Received: from gerry-dev.bj.intel.com ([10.238.158.52]) by orsmga003.jf.intel.com with ESMTP; 17 Nov 2014 02:58:24 -0800 From: Jiang Liu To: Bjorn Helgaas , Thomas Gleixner , Ingo Molnar , Grant Likely , Marc Zyngier , Yijing Wang , Yingjoe Chen , Borislav Petkov , "H. Peter Anvin" , Matthias Brugger , Jiang Liu , Alexander Gordeev Subject: [Patch V3 6/9] genirq: Introduce msi_domain_{alloc|free}_irqs() Date: Mon, 17 Nov 2014 19:03:19 +0800 Message-Id: <1416222202-28002-7-git-send-email-jiang.liu@linux.intel.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1416222202-28002-1-git-send-email-jiang.liu@linux.intel.com> References: <1416222202-28002-1-git-send-email-jiang.liu@linux.intel.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141117_030059_548065_507FBE8B X-CRM114-Status: GOOD ( 17.63 ) X-Spam-Score: -5.0 (-----) Cc: linux-pci@vger.kernel.org, Tony Luck , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, 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 Introduce msi_domain_{alloc|free}_irqs() to alloc/free interrupts from generic MSI irqdomain. Signed-off-by: Jiang Liu --- include/linux/msi.h | 39 +++++++++++++++++++++++++++++++ kernel/irq/msi.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) diff --git a/include/linux/msi.h b/include/linux/msi.h index 714716a3ffdd..243c4eb485a6 100644 --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -3,6 +3,7 @@ #include #include +#include /* for msi_alloc_info_t */ struct msi_msg { u32 address_lo; /* low 32 bits of msi message address */ @@ -100,7 +101,29 @@ struct irq_chip; struct device_node; struct msi_domain_info; +#ifndef NUM_MSI_ALLOC_SCRATCHPAD_REGS +#define NUM_MSI_ALLOC_SCRATCHPAD_REGS 2 +#endif + +/* + * Default structure for MSI interrupt allocation. + * Arch may overwrite it by defining msi_alloc_info_t. + */ +struct msi_alloc_info { + struct msi_desc *desc; + irq_hw_number_t hwirq; + union { + unsigned long ul; + void *ptr; + } scratchpad[NUM_MSI_ALLOC_SCRATCHPAD_REGS]; +}; + +#ifndef msi_alloc_info_t +typedef struct msi_alloc_info msi_alloc_info_t; +#endif + struct msi_domain_ops { + /* Callbacks for msi_create_irq_domain() */ void (*calc_hwirq)(struct msi_domain_info *info, void *arg, struct msi_desc *desc); irq_hw_number_t (*get_hwirq)(struct msi_domain_info *info, void *arg); @@ -111,6 +134,19 @@ struct msi_domain_ops { void (*msi_free)(struct irq_domain *domain, struct msi_domain_info *info, unsigned int virq); + + /* Callbacks for msi_irq_domain_alloc_irqs() based on msi_descs */ + int (*msi_check)(struct irq_domain *domain, + struct msi_domain_info *info, + struct device *dev); + int (*msi_prepare)(struct irq_domain *domain, + struct device *dev, int nvec, + msi_alloc_info_t *arg); + void (*msi_finish)(msi_alloc_info_t *arg, int retval); + int (*set_desc)(msi_alloc_info_t *arg, + struct msi_desc *desc); + int (*handle_error)(msi_alloc_info_t *arg, + struct msi_desc *desc, int error); }; struct msi_domain_info { @@ -125,6 +161,9 @@ int msi_domain_set_affinity(struct irq_data *data, const struct cpumask *mask, struct irq_domain *msi_create_irq_domain(struct device_node *of_node, struct msi_domain_info *info, struct irq_domain *parent); +int msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev, + int nvec); +void msi_domain_free_irqs(struct irq_domain *domain, struct device *dev); struct msi_domain_info *msi_get_domain_info(struct irq_domain *domain); #endif /* CONFIG_GENERIC_MSI_IRQ_DOMAIN */ diff --git a/kernel/irq/msi.c b/kernel/irq/msi.c index 94d6d87ee23e..586cd8b3a174 100644 --- a/kernel/irq/msi.c +++ b/kernel/irq/msi.c @@ -13,6 +13,9 @@ #include #include +/* Temparory solution for building, will be removed later */ +#include + void __get_cached_msi_msg(struct msi_desc *entry, struct msi_msg *msg) { *msg = entry->msg; @@ -124,6 +127,66 @@ struct irq_domain *msi_create_irq_domain(struct device_node *of_node, return domain; } +int msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev, + int nvec) +{ + int i, ret, virq = -1; + msi_alloc_info_t arg; + struct msi_desc *desc; + struct msi_domain_info *info = domain->host_data; + struct msi_domain_ops *ops = info->ops; + + ret = ops->msi_check(domain, info, dev); + if (ret == 0) + ret = ops->msi_prepare(domain, dev, nvec, &arg); + if (ret) + return ret; + + for_each_msi_entry(desc, dev) { + ret = ops->set_desc(&arg, desc); + if (ret) + goto handle_error; + + virq = __irq_domain_alloc_irqs(domain, -1, desc->nvec_used, + dev_to_node(dev), &arg, false); + if (virq >= 0) { + for (i = 0; i < desc->nvec_used; i++) + irq_set_msi_desc_off(virq, i, desc); + continue; + } + ret = -ENOSPC; +handle_error: + if (ops->handle_error) + ret = ops->handle_error(&arg, desc, ret); + if (ops->msi_finish) + ops->msi_finish(&arg, ret); + return ret; + } + + if (ops->msi_finish) + ops->msi_finish(&arg, 0); + + for_each_msi_entry(desc, dev) { + if (desc->nvec_used == 1) + dev_dbg(dev, "irq %d for MSI\n", virq); + else + dev_dbg(dev, "irq [%d-%d] for MSI\n", + virq, virq + desc->nvec_used - 1); + } + + return 0; +} + +void msi_domain_free_irqs(struct irq_domain *domain, struct device *dev) +{ + struct msi_desc *desc; + + for_each_msi_entry(desc, dev) { + irq_domain_free_irqs(desc->irq, desc->nvec_used); + desc->irq = 0; + } +} + struct msi_domain_info *msi_get_domain_info(struct irq_domain *domain) { return (struct msi_domain_info *)domain->host_data;