irqdomain: augment add_simple() to allocate descs
authorLinus Walleij <linus.walleij@linaro.org>
Thu, 27 Sep 2012 12:59:39 +0000 (14:59 +0200)
committerLinus Walleij <linus.walleij@linaro.org>
Wed, 10 Oct 2012 06:57:26 +0000 (08:57 +0200)
Currently we rely on all IRQ chip instances to dynamically
allocate their IRQ descriptors unless they use the linear
IRQ domain. So for irqdomain_add_legacy() and
irqdomain_add_simple() the caller need to make sure that
descriptors are allocated.

Let's slightly augment the yet unused irqdomain_add_simple()
to also allocate descriptors as a means to simplify usage
and avoid code duplication throughout the kernel.

We warn if descriptors cannot be allocated, e.g. if a
platform has the bad habit of hogging descriptors at boot
time.

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Grant Likely <grant.likely@secretlab.ca>
Cc: Paul Mundt <lethal@linux-sh.org>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Lee Jones <lee.jones@linaro.org>
Reviewed-by: Rob Herring <rob.herring@calxeda.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
kernel/irq/irqdomain.c

index 49a77727db42603e8e0ac963416d0f6b57823636..4e69e24d3d7d94b4c895735765e06f2f47a95db0 100644 (file)
@@ -148,7 +148,8 @@ static unsigned int irq_domain_legacy_revmap(struct irq_domain *domain,
  * @host_data: Controller private data pointer
  *
  * Allocates a legacy irq_domain if irq_base is positive or a linear
- * domain otherwise.
+ * domain otherwise. For the legacy domain, IRQ descriptors will also
+ * be allocated.
  *
  * This is intended to implement the expected behaviour for most
  * interrupt controllers which is that a linear mapping should
@@ -162,11 +163,33 @@ struct irq_domain *irq_domain_add_simple(struct device_node *of_node,
                                         const struct irq_domain_ops *ops,
                                         void *host_data)
 {
-       if (first_irq > 0)
-               return irq_domain_add_legacy(of_node, size, first_irq, 0,
+       if (first_irq > 0) {
+               int irq_base;
+
+               if (IS_ENABLED(CONFIG_SPARSE_IRQ)) {
+                       /*
+                        * Set the descriptor allocator to search for a
+                        * 1-to-1 mapping, such as irq_alloc_desc_at().
+                        * Use of_node_to_nid() which is defined to
+                        * numa_node_id() on platforms that have no custom
+                        * implementation.
+                        */
+                       irq_base = irq_alloc_descs(first_irq, first_irq, size,
+                                                  of_node_to_nid(of_node));
+                       if (irq_base < 0) {
+                               WARN(1, "Cannot allocate irq_descs @ IRQ%d, assuming pre-allocated\n",
+                                    first_irq);
+                               irq_base = first_irq;
+                       }
+               } else
+                       irq_base = first_irq;
+
+               return irq_domain_add_legacy(of_node, size, irq_base, 0,
                                             ops, host_data);
-       else
-               return irq_domain_add_linear(of_node, size, ops, host_data);
+       }
+
+       /* A linear domain is the default */
+       return irq_domain_add_linear(of_node, size, ops, host_data);
 }
 
 /**