From patchwork Thu Aug 1 13:25:07 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Petazzoni X-Patchwork-Id: 2836999 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 26B8DC0319 for ; Thu, 1 Aug 2013 13:25:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DE789202BC for ; Thu, 1 Aug 2013 13:25:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ACAD2202E8 for ; Thu, 1 Aug 2013 13:25:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754465Ab3HANZ3 (ORCPT ); Thu, 1 Aug 2013 09:25:29 -0400 Received: from up.free-electrons.com ([94.23.35.102]:53480 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750886Ab3HANZZ (ORCPT ); Thu, 1 Aug 2013 09:25:25 -0400 Received: by mail.free-electrons.com (Postfix, from userid 106) id 66891835; Thu, 1 Aug 2013 15:25:24 +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=-8.4 required=5.0 tests=BAYES_00,KHOP_BIG_TO_CC, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from localhost (col31-4-88-188-83-94.fbx.proxad.net [88.188.83.94]) by mail.free-electrons.com (Postfix) with ESMTPSA id D77007A4; Thu, 1 Aug 2013 15:25:23 +0200 (CEST) From: Thomas Petazzoni To: Bjorn Helgaas , linux-pci@vger.kernel.org, Russell King , Grant Likely , Rob Herring , Thomas Gleixner , Jason Cooper , Andrew Lunn , Gregory Clement Cc: Ezequiel Garcia , linux-arm-kernel@lists.infradead.org, Maen Suleiman , Lior Amsalem , Thierry Reding Subject: [PATCHv6 04/13] irqdomain: add irq_alloc_mapping() function Date: Thu, 1 Aug 2013 15:25:07 +0200 Message-Id: <1375363516-2620-5-git-send-email-thomas.petazzoni@free-electrons.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1375363516-2620-1-git-send-email-thomas.petazzoni@free-electrons.com> References: <1375363516-2620-1-git-send-email-thomas.petazzoni@free-electrons.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.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 --- 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