Skip to content

Commit 2b5e773

Browse files
brglKAGA-KOKO
authored andcommitted
irqdesc: Add a resource managed version of irq_alloc_descs()
Add a devres flavor of __devm_irq_alloc_descs() and corresponding helper macros. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Cc: Marc Zyngier <marc.zyngier@arm.com> Cc: linux-doc@vger.kernel.org Cc: Jonathan Corbet <corbet@lwn.net> Link: http://lkml.kernel.org/r/1486729403-21132-1-git-send-email-bgolaszewski@baylibre.com Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent b4f2d7c commit 2b5e773

3 files changed

Lines changed: 79 additions & 0 deletions

File tree

‎Documentation/driver-model/devres.txt‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,11 @@ IRQ
306306
devm_request_any_context_irq()
307307
devm_request_irq()
308308
devm_request_threaded_irq()
309+
devm_irq_alloc_descs()
310+
devm_irq_alloc_desc()
311+
devm_irq_alloc_desc_at()
312+
devm_irq_alloc_desc_from()
313+
devm_irq_alloc_descs_from()
309314

310315
LED
311316
devm_led_classdev_register()

‎include/linux/irq.h‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,10 @@ unsigned int arch_dynirq_lower_bound(unsigned int from);
715715
int __irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node,
716716
struct module *owner, const struct cpumask *affinity);
717717

718+
int __devm_irq_alloc_descs(struct device *dev, int irq, unsigned int from,
719+
unsigned int cnt, int node, struct module *owner,
720+
const struct cpumask *affinity);
721+
718722
/* use macros to avoid needing export.h for THIS_MODULE */
719723
#define irq_alloc_descs(irq, from, cnt, node) \
720724
__irq_alloc_descs(irq, from, cnt, node, THIS_MODULE, NULL)
@@ -731,6 +735,21 @@ int __irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node,
731735
#define irq_alloc_descs_from(from, cnt, node) \
732736
irq_alloc_descs(-1, from, cnt, node)
733737

738+
#define devm_irq_alloc_descs(dev, irq, from, cnt, node) \
739+
__devm_irq_alloc_descs(dev, irq, from, cnt, node, THIS_MODULE, NULL)
740+
741+
#define devm_irq_alloc_desc(dev, node) \
742+
devm_irq_alloc_descs(dev, -1, 0, 1, node)
743+
744+
#define devm_irq_alloc_desc_at(dev, at, node) \
745+
devm_irq_alloc_descs(dev, at, at, 1, node)
746+
747+
#define devm_irq_alloc_desc_from(dev, from, node) \
748+
devm_irq_alloc_descs(dev, -1, from, 1, node)
749+
750+
#define devm_irq_alloc_descs_from(dev, from, cnt, node) \
751+
devm_irq_alloc_descs(dev, -1, from, cnt, node)
752+
734753
void irq_free_descs(unsigned int irq, unsigned int cnt);
735754
static inline void irq_free_desc(unsigned int irq)
736755
{

‎kernel/irq/devres.c‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <linux/interrupt.h>
33
#include <linux/device.h>
44
#include <linux/gfp.h>
5+
#include <linux/irq.h>
56

67
/*
78
* Device resource management aware IRQ request/free implementation.
@@ -137,3 +138,57 @@ void devm_free_irq(struct device *dev, unsigned int irq, void *dev_id)
137138
free_irq(irq, dev_id);
138139
}
139140
EXPORT_SYMBOL(devm_free_irq);
141+
142+
struct irq_desc_devres {
143+
unsigned int from;
144+
unsigned int cnt;
145+
};
146+
147+
static void devm_irq_desc_release(struct device *dev, void *res)
148+
{
149+
struct irq_desc_devres *this = res;
150+
151+
irq_free_descs(this->from, this->cnt);
152+
}
153+
154+
/**
155+
* __devm_irq_alloc_descs - Allocate and initialize a range of irq descriptors
156+
* for a managed device
157+
* @dev: Device to allocate the descriptors for
158+
* @irq: Allocate for specific irq number if irq >= 0
159+
* @from: Start the search from this irq number
160+
* @cnt: Number of consecutive irqs to allocate
161+
* @node: Preferred node on which the irq descriptor should be allocated
162+
* @owner: Owning module (can be NULL)
163+
* @affinity: Optional pointer to an affinity mask array of size @cnt
164+
* which hints where the irq descriptors should be allocated
165+
* and which default affinities to use
166+
*
167+
* Returns the first irq number or error code.
168+
*
169+
* Note: Use the provided wrappers (devm_irq_alloc_desc*) for simplicity.
170+
*/
171+
int __devm_irq_alloc_descs(struct device *dev, int irq, unsigned int from,
172+
unsigned int cnt, int node, struct module *owner,
173+
const struct cpumask *affinity)
174+
{
175+
struct irq_desc_devres *dr;
176+
int base;
177+
178+
dr = devres_alloc(devm_irq_desc_release, sizeof(*dr), GFP_KERNEL);
179+
if (!dr)
180+
return -ENOMEM;
181+
182+
base = __irq_alloc_descs(irq, from, cnt, node, owner, affinity);
183+
if (base < 0) {
184+
devres_free(dr);
185+
return base;
186+
}
187+
188+
dr->from = base;
189+
dr->cnt = cnt;
190+
devres_add(dev, dr);
191+
192+
return base;
193+
}
194+
EXPORT_SYMBOL_GPL(__devm_irq_alloc_descs);

0 commit comments

Comments
 (0)