From patchwork Wed Aug 7 09:32:25 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Petazzoni X-Patchwork-Id: 2840083 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 CDC649F498 for ; Wed, 7 Aug 2013 09:35:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C8F3B201E9 for ; Wed, 7 Aug 2013 09:35:10 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 84D8D201B3 for ; Wed, 7 Aug 2013 09:35:09 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V708M-0008VR-5q; Wed, 07 Aug 2013 09:34:22 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1V7082-0001lX-V7; Wed, 07 Aug 2013 09:34:02 +0000 Received: from top.free-electrons.com ([176.31.233.9] helo=mail.free-electrons.com) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1V707o-0001h9-06 for linux-arm-kernel@lists.infradead.org; Wed, 07 Aug 2013 09:33:50 +0000 Received: by mail.free-electrons.com (Postfix, from userid 106) id B37486E6C; Wed, 7 Aug 2013 11:33:33 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,KHOP_BIG_TO_CC, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from localhost (unknown [37.160.138.38]) by mail.free-electrons.com (Postfix) with ESMTPSA id 694C06E6F; Wed, 7 Aug 2013 11:32:58 +0200 (CEST) From: Thomas Petazzoni To: Bjorn Helgaas , linux-pci@vger.kernel.org, Russell King , Benjamin Herrenschmidt , Rob Herring , Thomas Gleixner , Jason Cooper , Andrew Lunn , Gregory Clement Subject: [PATCHv7 04/13] irqdomain: add irq_alloc_mapping() function Date: Wed, 7 Aug 2013 11:32:25 +0200 Message-Id: <1375867954-2320-5-git-send-email-thomas.petazzoni@free-electrons.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1375867954-2320-1-git-send-email-thomas.petazzoni@free-electrons.com> References: <1375867954-2320-1-git-send-email-thomas.petazzoni@free-electrons.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130807_053348_334556_6D90DCB9 X-CRM114-Status: GOOD ( 14.11 ) X-Spam-Score: 0.5 (/) Cc: Lior Amsalem , Maen Suleiman , Thierry Reding , linux-arm-kernel@lists.infradead.org, Ezequiel Garcia X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 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-Virus-Scanned: ClamAV using ClamSMTP This commit extends the irqdomain subsystem with an irq_alloc_mapping() function which allows to let the irqdomain code find an available hwirq number in the range [ 0 ; domain size ] for the given domain, and create a virq mapping for it. Signed-off-by: Thomas Petazzoni Acked-by: Grant Likely Tested-by: Daniel Price --- include/linux/irqdomain.h | 2 ++ kernel/irq/irqdomain.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/linux/irqdomain.h b/include/linux/irqdomain.h index c983ed1..1ffa336 100644 --- a/include/linux/irqdomain.h +++ b/include/linux/irqdomain.h @@ -195,6 +195,8 @@ static inline unsigned int irq_linear_revmap(struct irq_domain *domain, extern unsigned int irq_find_mapping(struct irq_domain *host, irq_hw_number_t hwirq); extern unsigned int irq_create_direct_mapping(struct irq_domain *host); +extern unsigned int irq_alloc_mapping(struct irq_domain *host, + irq_hw_number_t *hwirq); extern int irq_create_strict_mappings(struct irq_domain *domain, unsigned int irq_base, irq_hw_number_t hwirq_base, int count); diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c index 706724e..034bbac 100644 --- a/kernel/irq/irqdomain.c +++ b/kernel/irq/irqdomain.c @@ -375,6 +375,42 @@ unsigned int irq_create_direct_mapping(struct irq_domain *domain) EXPORT_SYMBOL_GPL(irq_create_direct_mapping); /** + * irq_alloc_mapping() - Allocate an irq for mapping + * @domain: domain to allocate the irq for or NULL for default domain + * @hwirq: reference to the returned hwirq + * + * This routine are used for irq controllers which can choose the + * hardware interrupt number from a range [ 0 ; domain size ], such as + * is often the case with PCI MSI controllers. The function will + * returned the allocated hwirq number in the hwirq pointer, and the + * corresponding virq number as the return value. + */ +unsigned int irq_alloc_mapping(struct irq_domain *domain, + irq_hw_number_t *out_hwirq) +{ + irq_hw_number_t hwirq; + int rc; + + pr_debug("irq_alloc_mapping(0x%p)\n", domain); + + for (hwirq = 0; hwirq < domain->revmap_size; hwirq++) + if (domain->linear_revmap[hwirq] == 0) + break; + + if (hwirq == domain->hwirq_max) { + pr_debug("-> no available hwirq found\n"); + return 0; + } + + rc = irq_create_mapping(domain, hwirq); + if (rc) + *out_hwirq = hwirq; + + return rc; +} +EXPORT_SYMBOL_GPL(irq_alloc_mapping); + +/** * irq_create_mapping() - Map a hardware interrupt into linux irq space * @domain: domain owning this hardware interrupt or NULL for default domain * @hwirq: hardware irq number in that domain space