From patchwork Fri Jun 7 22:30:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinghai Lu X-Patchwork-Id: 2690901 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id AF81E3FC23 for ; Fri, 7 Jun 2013 22:38:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756375Ab3FGWiV (ORCPT ); Fri, 7 Jun 2013 18:38:21 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:51320 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756621Ab3FGWbh (ORCPT ); Fri, 7 Jun 2013 18:31:37 -0400 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r57MVDVp018006 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 7 Jun 2013 22:31:14 GMT Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r57MVEXa006533 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 7 Jun 2013 22:31:15 GMT Received: from abhmt103.oracle.com (abhmt103.oracle.com [141.146.116.55]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r57MVEOq019335; Fri, 7 Jun 2013 22:31:14 GMT Received: from linux-siqj.site (/10.132.126.191) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 07 Jun 2013 15:31:14 -0700 From: Yinghai Lu To: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Bjorn Helgaas , "Rafael J. Wysocki" Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Yinghai Lu , Alexander Gordeev Subject: [PATCH v3 10/27] genirq: Split __irq_reserve_irqs from irq_alloc_descs Date: Fri, 7 Jun 2013 15:30:56 -0700 Message-Id: <1370644273-10495-11-git-send-email-yinghai@kernel.org> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1370644273-10495-1-git-send-email-yinghai@kernel.org> References: <1370644273-10495-1-git-send-email-yinghai@kernel.org> X-Source-IP: acsinet22.oracle.com [141.146.126.238] Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org irq_alloc_descs and irq_reserve_irqs are almost the same. Separate code out to __irq_reserved_irqs, and other two reuse __irq_reserve_irqs. We will use __irq_reserve_irqs for coming ioapic hotplug support. Signed-off-by: Yinghai Lu Cc: Alexander Gordeev Reviewed-by: Alexander Gordeev --- include/linux/irq.h | 1 + kernel/irq/irqdesc.c | 54 ++++++++++++++++++++++++++++++---------------------- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/include/linux/irq.h b/include/linux/irq.h index bc4e066..4e0fcbb 100644 --- a/include/linux/irq.h +++ b/include/linux/irq.h @@ -600,6 +600,7 @@ int __irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node, void irq_free_descs(unsigned int irq, unsigned int cnt); int irq_reserve_irqs(unsigned int from, unsigned int cnt); +int __irq_reserve_irqs(int irq, unsigned int from, unsigned int cnt); static inline void irq_free_desc(unsigned int irq) { diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c index 192a302..3b9fb92 100644 --- a/kernel/irq/irqdesc.c +++ b/kernel/irq/irqdesc.c @@ -340,18 +340,15 @@ void irq_free_descs(unsigned int from, unsigned int cnt) EXPORT_SYMBOL_GPL(irq_free_descs); /** - * irq_alloc_descs - allocate and initialize a range of irq descriptors - * @irq: Allocate for specific irq number if irq >= 0 + * __irq_reserve_descs - reserve and initialize a range of irq descriptors + * @irq: Reserve for specific irq number if irq >= 0 * @from: Start the search from this irq number - * @cnt: Number of consecutive irqs to allocate. - * @node: Preferred node on which the irq descriptor should be allocated - * @owner: Owning module (can be NULL) + * @cnt: Number of consecutive irqs to reserve. * * Returns the first irq number or error code */ int __ref -__irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node, - struct module *owner) +__irq_reserve_irqs(int irq, unsigned int from, unsigned int cnt) { int start, ret; @@ -369,7 +366,7 @@ __irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node, start = bitmap_find_next_zero_area(allocated_irqs, IRQ_BITMAP_BITS, from, cnt, 0); ret = -EEXIST; - if (irq >=0 && start != irq) + if (irq >= 0 && start != irq) goto err; if (start + cnt > nr_irqs) { @@ -380,12 +377,36 @@ __irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node, bitmap_set(allocated_irqs, start, cnt); mutex_unlock(&sparse_irq_lock); - return alloc_descs(start, cnt, node, owner); + return start; err: mutex_unlock(&sparse_irq_lock); return ret; } + +/** + * irq_alloc_descs - allocate and initialize a range of irq descriptors + * @irq: Allocate for specific irq number if irq >= 0 + * @from: Start the search from this irq number + * @cnt: Number of consecutive irqs to allocate. + * @node: Preferred node on which the irq descriptor should be allocated + * @owner: Owning module (can be NULL) + * + * Returns the first irq number or error code + */ +int __ref +__irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node, + struct module *owner) +{ + int start; + + start = __irq_reserve_irqs(irq, from, cnt); + + if (start < 0) + return start; + + return alloc_descs(start, cnt, node, owner); +} EXPORT_SYMBOL_GPL(__irq_alloc_descs); /** @@ -397,20 +418,7 @@ EXPORT_SYMBOL_GPL(__irq_alloc_descs); */ int irq_reserve_irqs(unsigned int from, unsigned int cnt) { - unsigned int start; - int ret = 0; - - if (!cnt || (from + cnt) > nr_irqs) - return -EINVAL; - - mutex_lock(&sparse_irq_lock); - start = bitmap_find_next_zero_area(allocated_irqs, nr_irqs, from, cnt, 0); - if (start == from) - bitmap_set(allocated_irqs, start, cnt); - else - ret = -EEXIST; - mutex_unlock(&sparse_irq_lock); - return ret; + return __irq_reserve_irqs(from, from, cnt); } /**