]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
irqdesc: Add a resource managed version of irq_alloc_descs()
authorBartosz Golaszewski <bgolaszewski@baylibre.com>
Fri, 10 Feb 2017 12:23:23 +0000 (13:23 +0100)
committerThomas Gleixner <tglx@linutronix.de>
Fri, 10 Feb 2017 13:39:20 +0000 (14:39 +0100)
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>
Documentation/driver-model/devres.txt
include/linux/irq.h
kernel/irq/devres.c

index ca9d1eb46bc00e38f1f1250775ce43cac241e9a7..bf34d5b3a7330e5c26f9c6eebe977ed853804959 100644 (file)
@@ -306,6 +306,11 @@ IRQ
   devm_request_any_context_irq()
   devm_request_irq()
   devm_request_threaded_irq()
+  devm_irq_alloc_descs()
+  devm_irq_alloc_desc()
+  devm_irq_alloc_desc_at()
+  devm_irq_alloc_desc_from()
+  devm_irq_alloc_descs_from()
 
 LED
   devm_led_classdev_register()
index e79875574b393f33ed183fdc8f44277a49c26ba8..d915caecafa1b11b3aa4c5afcb4850db5f588733 100644 (file)
@@ -715,6 +715,10 @@ unsigned int arch_dynirq_lower_bound(unsigned int from);
 int __irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node,
                      struct module *owner, const struct cpumask *affinity);
 
+int __devm_irq_alloc_descs(struct device *dev, int irq, unsigned int from,
+                          unsigned int cnt, int node, struct module *owner,
+                          const struct cpumask *affinity);
+
 /* use macros to avoid needing export.h for THIS_MODULE */
 #define irq_alloc_descs(irq, from, cnt, node)  \
        __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,
 #define irq_alloc_descs_from(from, cnt, node)  \
        irq_alloc_descs(-1, from, cnt, node)
 
+#define devm_irq_alloc_descs(dev, irq, from, cnt, node)                \
+       __devm_irq_alloc_descs(dev, irq, from, cnt, node, THIS_MODULE, NULL)
+
+#define devm_irq_alloc_desc(dev, node)                         \
+       devm_irq_alloc_descs(dev, -1, 0, 1, node)
+
+#define devm_irq_alloc_desc_at(dev, at, node)                  \
+       devm_irq_alloc_descs(dev, at, at, 1, node)
+
+#define devm_irq_alloc_desc_from(dev, from, node)              \
+       devm_irq_alloc_descs(dev, -1, from, 1, node)
+
+#define devm_irq_alloc_descs_from(dev, from, cnt, node)                \
+       devm_irq_alloc_descs(dev, -1, from, cnt, node)
+
 void irq_free_descs(unsigned int irq, unsigned int cnt);
 static inline void irq_free_desc(unsigned int irq)
 {
index 74d90a75426881881cc7e42ff3fcdba91efd76c9..18babef39361c4cba1ebb31487dd5ec6945a50bd 100644 (file)
@@ -2,6 +2,7 @@
 #include <linux/interrupt.h>
 #include <linux/device.h>
 #include <linux/gfp.h>
+#include <linux/irq.h>
 
 /*
  * 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)
        free_irq(irq, dev_id);
 }
 EXPORT_SYMBOL(devm_free_irq);
+
+struct irq_desc_devres {
+       unsigned int from;
+       unsigned int cnt;
+};
+
+static void devm_irq_desc_release(struct device *dev, void *res)
+{
+       struct irq_desc_devres *this = res;
+
+       irq_free_descs(this->from, this->cnt);
+}
+
+/**
+ * __devm_irq_alloc_descs - Allocate and initialize a range of irq descriptors
+ *                         for a managed device
+ * @dev:       Device to allocate the descriptors for
+ * @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)
+ * @affinity:  Optional pointer to an affinity mask array of size @cnt
+ *             which hints where the irq descriptors should be allocated
+ *             and which default affinities to use
+ *
+ * Returns the first irq number or error code.
+ *
+ * Note: Use the provided wrappers (devm_irq_alloc_desc*) for simplicity.
+ */
+int __devm_irq_alloc_descs(struct device *dev, int irq, unsigned int from,
+                          unsigned int cnt, int node, struct module *owner,
+                          const struct cpumask *affinity)
+{
+       struct irq_desc_devres *dr;
+       int base;
+
+       dr = devres_alloc(devm_irq_desc_release, sizeof(*dr), GFP_KERNEL);
+       if (!dr)
+               return -ENOMEM;
+
+       base = __irq_alloc_descs(irq, from, cnt, node, owner, affinity);
+       if (base < 0) {
+               devres_free(dr);
+               return base;
+       }
+
+       dr->from = base;
+       dr->cnt = cnt;
+       devres_add(dev, dr);
+
+       return base;
+}
+EXPORT_SYMBOL_GPL(__devm_irq_alloc_descs);