Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Bartosz Golaszewski and committed by
Thomas Gleixner
2b5e7730 b4f2d7c3

+79
+5
Documentation/driver-model/devres.txt
··· 306 306 devm_request_any_context_irq() 307 307 devm_request_irq() 308 308 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() 309 314 310 315 LED 311 316 devm_led_classdev_register()
+19
include/linux/irq.h
··· 715 715 int __irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node, 716 716 struct module *owner, const struct cpumask *affinity); 717 717 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 + 718 722 /* use macros to avoid needing export.h for THIS_MODULE */ 719 723 #define irq_alloc_descs(irq, from, cnt, node) \ 720 724 __irq_alloc_descs(irq, from, cnt, node, THIS_MODULE, NULL) ··· 734 730 735 731 #define irq_alloc_descs_from(from, cnt, node) \ 736 732 irq_alloc_descs(-1, from, cnt, node) 733 + 734 + #define devm_irq_alloc_descs(dev, irq, from, cnt, node) \ 735 + __devm_irq_alloc_descs(dev, irq, from, cnt, node, THIS_MODULE, NULL) 736 + 737 + #define devm_irq_alloc_desc(dev, node) \ 738 + devm_irq_alloc_descs(dev, -1, 0, 1, node) 739 + 740 + #define devm_irq_alloc_desc_at(dev, at, node) \ 741 + devm_irq_alloc_descs(dev, at, at, 1, node) 742 + 743 + #define devm_irq_alloc_desc_from(dev, from, node) \ 744 + devm_irq_alloc_descs(dev, -1, from, 1, node) 745 + 746 + #define devm_irq_alloc_descs_from(dev, from, cnt, node) \ 747 + devm_irq_alloc_descs(dev, -1, from, cnt, node) 737 748 738 749 void irq_free_descs(unsigned int irq, unsigned int cnt); 739 750 static inline void irq_free_desc(unsigned int irq)
+55
kernel/irq/devres.c
··· 2 2 #include <linux/interrupt.h> 3 3 #include <linux/device.h> 4 4 #include <linux/gfp.h> 5 + #include <linux/irq.h> 5 6 6 7 /* 7 8 * Device resource management aware IRQ request/free implementation. ··· 138 137 free_irq(irq, dev_id); 139 138 } 140 139 EXPORT_SYMBOL(devm_free_irq); 140 + 141 + struct irq_desc_devres { 142 + unsigned int from; 143 + unsigned int cnt; 144 + }; 145 + 146 + static void devm_irq_desc_release(struct device *dev, void *res) 147 + { 148 + struct irq_desc_devres *this = res; 149 + 150 + irq_free_descs(this->from, this->cnt); 151 + } 152 + 153 + /** 154 + * __devm_irq_alloc_descs - Allocate and initialize a range of irq descriptors 155 + * for a managed device 156 + * @dev: Device to allocate the descriptors for 157 + * @irq: Allocate for specific irq number if irq >= 0 158 + * @from: Start the search from this irq number 159 + * @cnt: Number of consecutive irqs to allocate 160 + * @node: Preferred node on which the irq descriptor should be allocated 161 + * @owner: Owning module (can be NULL) 162 + * @affinity: Optional pointer to an affinity mask array of size @cnt 163 + * which hints where the irq descriptors should be allocated 164 + * and which default affinities to use 165 + * 166 + * Returns the first irq number or error code. 167 + * 168 + * Note: Use the provided wrappers (devm_irq_alloc_desc*) for simplicity. 169 + */ 170 + int __devm_irq_alloc_descs(struct device *dev, int irq, unsigned int from, 171 + unsigned int cnt, int node, struct module *owner, 172 + const struct cpumask *affinity) 173 + { 174 + struct irq_desc_devres *dr; 175 + int base; 176 + 177 + dr = devres_alloc(devm_irq_desc_release, sizeof(*dr), GFP_KERNEL); 178 + if (!dr) 179 + return -ENOMEM; 180 + 181 + base = __irq_alloc_descs(irq, from, cnt, node, owner, affinity); 182 + if (base < 0) { 183 + devres_free(dr); 184 + return base; 185 + } 186 + 187 + dr->from = base; 188 + dr->cnt = cnt; 189 + devres_add(dev, dr); 190 + 191 + return base; 192 + } 193 + EXPORT_SYMBOL_GPL(__devm_irq_alloc_descs);