diff mbox

[RFC,03/11] dt/irq: add irq_domain_add_simple() helper

Message ID 20110616044141.29371.76366.stgit@ponder (mailing list archive)
State New, archived
Headers show

Commit Message

Grant Likely June 16, 2011, 4:41 a.m. UTC
irq_domain_add_simple() is an easy way to generate an irq translation
domain for simple irq controllers.  It assumes a flat 1:1 mapping from
hardware irq number to an offset of the first linux irq number assigned
to the controller

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
---
 include/linux/irq.h    |   11 +++++++++
 kernel/irq/irqdomain.c |   58 +++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 68 insertions(+), 1 deletions(-)

Comments

Rob Herring June 16, 2011, 2:04 p.m. UTC | #1
Grant,

On 06/15/2011 11:41 PM, Grant Likely wrote:
> irq_domain_add_simple() is an easy way to generate an irq translation
> domain for simple irq controllers.  It assumes a flat 1:1 mapping from
> hardware irq number to an offset of the first linux irq number assigned
> to the controller
> 
> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
> ---
>  include/linux/irq.h    |   11 +++++++++
>  kernel/irq/irqdomain.c |   58 +++++++++++++++++++++++++++++++++++++++++++++++-
>  2 files changed, 68 insertions(+), 1 deletions(-)
> 
> diff --git a/include/linux/irq.h b/include/linux/irq.h
> index a103c01..50830fc 100644
> --- a/include/linux/irq.h
> +++ b/include/linux/irq.h
> @@ -797,6 +797,17 @@ extern unsigned int irq_domain_map(struct irq_domain *domain,
>  				   irq_hw_number_t hwirq);
>  extern void irq_domain_unmap(struct irq_domain *domain, irq_hw_number_t hw);
>  
> +struct of_device_id;
> +#ifdef CONFIG_OF
> +extern void irq_domain_add_simple(struct device_node *controller, int irq_base);
> +extern void irq_domain_generate_simple(struct of_device_id *match,

match should be const

> +					u64 phys_base, unsigned int irq_start);
> +#else

Empty function for irq_domain_add_simple?

> +static inline void irq_domain_generate_simple(struct of_device_id *match,
> +					u64 phys_base, unsigned int irq_start) { }
> +#endif
> +
> +

Rob
Rob Herring June 16, 2011, 2:21 p.m. UTC | #2
Forgot one thing.

On 06/16/2011 09:04 AM, Rob Herring wrote:
> Grant,
> 
> On 06/15/2011 11:41 PM, Grant Likely wrote:
>> irq_domain_add_simple() is an easy way to generate an irq translation
>> domain for simple irq controllers.  It assumes a flat 1:1 mapping from
>> hardware irq number to an offset of the first linux irq number assigned
>> to the controller
>>

The description and headline are a bit out of date since adding
irq_domain_generate_simple.

Rob
Grant Likely June 16, 2011, 4:56 p.m. UTC | #3
On Thu, Jun 16, 2011 at 09:04:51AM -0500, Rob Herring wrote:
> Grant,
> 
> On 06/15/2011 11:41 PM, Grant Likely wrote:
> > irq_domain_add_simple() is an easy way to generate an irq translation
> > domain for simple irq controllers.  It assumes a flat 1:1 mapping from
> > hardware irq number to an offset of the first linux irq number assigned
> > to the controller
> > 
> > Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
> > ---
> >  include/linux/irq.h    |   11 +++++++++
> >  kernel/irq/irqdomain.c |   58 +++++++++++++++++++++++++++++++++++++++++++++++-
> >  2 files changed, 68 insertions(+), 1 deletions(-)
> > 
> > diff --git a/include/linux/irq.h b/include/linux/irq.h
> > index a103c01..50830fc 100644
> > --- a/include/linux/irq.h
> > +++ b/include/linux/irq.h
> > @@ -797,6 +797,17 @@ extern unsigned int irq_domain_map(struct irq_domain *domain,
> >  				   irq_hw_number_t hwirq);
> >  extern void irq_domain_unmap(struct irq_domain *domain, irq_hw_number_t hw);
> >  
> > +struct of_device_id;
> > +#ifdef CONFIG_OF
> > +extern void irq_domain_add_simple(struct device_node *controller, int irq_base);
> > +extern void irq_domain_generate_simple(struct of_device_id *match,
> 
> match should be const

yup

> 
> > +					u64 phys_base, unsigned int irq_start);
> > +#else
> 
> Empty function for irq_domain_add_simple?

Haven't needed it yet.  I'll add it if it comes up.  Honestly, I'm not
even sure if this patch will survive very long once the IRQ
controllers start using irq_domains directly.  This is more of an easy
way to get an irq_domain registration so that DT translations work.

g.
Grant Likely June 16, 2011, 4:57 p.m. UTC | #4
On Thu, Jun 16, 2011 at 09:21:20AM -0500, Rob Herring wrote:
> Forgot one thing.
> 
> On 06/16/2011 09:04 AM, Rob Herring wrote:
> > Grant,
> > 
> > On 06/15/2011 11:41 PM, Grant Likely wrote:
> >> irq_domain_add_simple() is an easy way to generate an irq translation
> >> domain for simple irq controllers.  It assumes a flat 1:1 mapping from
> >> hardware irq number to an offset of the first linux irq number assigned
> >> to the controller
> >>
> 
> The description and headline are a bit out of date since adding
> irq_domain_generate_simple.

good catch.  Thanks.

g.
diff mbox

Patch

diff --git a/include/linux/irq.h b/include/linux/irq.h
index a103c01..50830fc 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -797,6 +797,17 @@  extern unsigned int irq_domain_map(struct irq_domain *domain,
 				   irq_hw_number_t hwirq);
 extern void irq_domain_unmap(struct irq_domain *domain, irq_hw_number_t hw);
 
+struct of_device_id;
+#ifdef CONFIG_OF
+extern void irq_domain_add_simple(struct device_node *controller, int irq_base);
+extern void irq_domain_generate_simple(struct of_device_id *match,
+					u64 phys_base, unsigned int irq_start);
+#else
+static inline void irq_domain_generate_simple(struct of_device_id *match,
+					u64 phys_base, unsigned int irq_start) { }
+#endif
+
+
 #endif /* !CONFIG_S390 */
 
 #endif /* _LINUX_IRQ_H */
diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c
index 8310d6e..2d03c2d 100644
--- a/kernel/irq/irqdomain.c
+++ b/kernel/irq/irqdomain.c
@@ -1,7 +1,9 @@ 
-
 #include <linux/irq.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/slab.h>
 
 static LIST_HEAD(irq_domain_list);
 static DEFINE_MUTEX(irq_domain_mutex);
@@ -116,6 +118,8 @@  unsigned int irq_create_of_mapping(struct device_node *controller,
 	irq = irq_domain_map(domain, hwirq);
 	if (type != IRQ_TYPE_NONE)
 		irq_set_irq_type(irq, type);
+	pr_debug("%s: mapped hwirq=%i to irq=%i, flags=%x\n",
+		 controller->full_name, (int)hwirq, irq, type);
 	return irq;
 }
 EXPORT_SYMBOL_GPL(irq_create_of_mapping);
@@ -134,4 +138,56 @@  void irq_dispose_mapping(unsigned int irq)
 }
 EXPORT_SYMBOL_GPL(irq_dispose_mapping);
 
+int irq_domain_simple_dt_translate(struct irq_domain *d,
+			    struct device_node *controller,
+			    const u32 *intspec, unsigned int intsize,
+			    irq_hw_number_t *out_hwirq, unsigned int *out_type)
+{
+	if (d->of_node != controller)
+		return -EINVAL;
+	if (intsize != 1)
+		return -EINVAL;
+
+	*out_hwirq = intspec[0];
+	*out_type = IRQ_TYPE_NONE;
+	return 0;
+}
+
+struct irq_domain_ops irq_domain_simple_ops = {
+	.dt_translate = irq_domain_simple_dt_translate,
+};
+
+/**
+ * irq_domain_create_simple() - Set up a 'simple' translation range
+ */
+void irq_domain_add_simple(struct device_node *controller, int irq_base)
+{
+	struct irq_domain *domain;
+
+	domain = kzalloc(sizeof(*domain), GFP_KERNEL);
+	if (!domain) {
+		WARN_ON(1);
+		return;
+	}
+
+	domain->irq_base = irq_base;
+	domain->of_node = of_node_get(controller);
+	domain->ops = &irq_domain_simple_ops;
+	irq_domain_add(domain);
+}
+EXPORT_SYMBOL_GPL(irq_domain_add_simple);
+
+void irq_domain_generate_simple(struct of_device_id *match,
+				u64 phys_base, unsigned int irq_start)
+{
+	struct device_node *node;
+	pr_info("looking for phys_base=%llx, irq_start=%i\n",
+		(unsigned long long) phys_base, (int) irq_start);
+	node = of_find_matching_node_by_address(NULL, match, phys_base);
+	if (node)
+		irq_domain_add_simple(node, irq_start);
+	else
+		pr_info("no node found\n");
+}
+EXPORT_SYMBOL_GPL(irq_domain_generate_simple);
 #endif