irq/of: Cleanup and Enchance irq_domain support.
Subsystems (4)
v2 cover irq/of: Cleanup and Enchance irq_domain support.
From: David Daney <david.daney-YGCgFSpz5w/[email protected]>
Back in early Nov. I send the first version of this patch set. Now things are heating up again in the world of irq_domain, so I wanted to try to get some closure on the issues I had. The Octeon patch is included here to show how I am using irq_domain, but is part of a much larger effort to merge Octeon device tree support.
The basic problem I am attempting to solve is using irq domains when there is a 'non-linear' mapping of hwirq <--> irq within a domain. Octeon has a single set of irq numbers that is used across two different implementations of the interrupt controller as well as more than 10 different SOCs all which use different subsets of the irq number space. The result is that the hwirq to irq mapping function contains many gaps and discontinuities, it is really quite random.
The existing irq domain infrastructure assumes a continuous linear mapping of hwirq to irq that can be encapsulated by the irq_base, hwirq_base and nr_irq elements of struct irq_domain. This is not suitable for the Octeon implementation.
The gist of my change is to add an optional iterator function to irq_domain_ops which knows how to iterate over the irq numbers in a given domain. For simple linear domains (those currently supported), we iterate using the current method based on irq_base, hwirq_base and nr_irq.
Summary of the patches:
1) Get rid of some unused code to make subsequent changes simpler.
2) Cleanup the data type used by various hwirq functions and users.
3) Add the irq iterator, and fix up the ARM GIC code to use it instead of the current irq_domain_for_each_irq().
4) Add the Octeon users of the interface.
In an earlier exchange, Rob Herring had said:
... Handling sparse irqs is a potentially common problem, so we should address that in the core irqdomain code.
Which is what this patch set is doing.
There was a suggestion that perhaps having .to_irq() return a magic value if there was no mapping would also work. However I prefer this approach as it separates the concepts of iteration and mapping of irq numbers.
Please comment.
David Daney (4):
irq: Get rid of irq_domain_for_each_hwirq(). irq/of/ARM: Make irq_domain hwirq type consistent throughout the
kernel.
irq/of/ARM: Enhance irq iteration capability of irq_domain code.
MIPS: Octeon: Add irq_create_of_mapping() and GPIO interrupts.
arch/arm/common/gic.c | 34 +++-- arch/mips/Kconfig | 1 + arch/mips/cavium-octeon/octeon-irq.c | 259 +++++++++++++++++++++++++++++++++- include/linux/irqdomain.h | 23 ++-- kernel/irq/irqdomain.c | 88 ++++++++---- 5 files changed, 354 insertions(+), 51 deletions(-)
Signature · 1 line
1.7.2.3
PATCH v2 1/4 irq: Get rid of irq_domain_for_each_hwirq().
From: David Daney <david.daney-YGCgFSpz5w/[email protected]>
It is not used anywhere in the kernel.
--- include/linux/irqdomain.h | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-)
include/linux/irqdomain.h +0 -3
@@ -81,9 +81,6 @@ static inline unsigned int irq_domain_to_irq(struct irq_domain *d,return d->irq_base + hwirq - d->hwirq_base; } -#define irq_domain_for_each_hwirq (d, hw) \ - for (hw = d->hwirq_base; hw < d->hwirq_base + d->nr_irq; hw++) -#define irq_domain_for_each_irq (d, hw, irq) \ for (hw = d->hwirq_base, irq = irq_domain_to_irq(d, hw); \ hw < d->hwirq_base + d->nr_irq; \
Signature · 1 line
1.7.2.3
PATCH v2 2/4 irq/of/ARM: Make irq_domain hwirq type consistent throughout the kernel.
In reply to David DaneyFrom: David Daney <[email protected]>
There is a mixture of unsigned long and unsigned int being used with hwirq and hwirq_base. Change it so we use unsigned int everywhere.
--- arch/arm/common/gic.c | 2 +- include/linux/irqdomain.h | 6 +++--- kernel/irq/irqdomain.c | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-)
arch/arm/common/gic.c +1 -1
@@ -625,7 +625,7 @@ static void __init gic_pm_init(struct gic_chip_data *gic)static int gic_irq_domain_dt_translate (struct irq_domain *d,struct device_node *controller,const u32 *intspec,unsigned int intsize, -unsigned long *out_hwirq,unsigned int *out_type) +unsigned int *out_hwirq,unsigned int *out_type) {if (d->of_node != controller)return -EINVAL ;
include/linux/irqdomain.h +3 -3
@@ -31,12 +31,12 @@ struct irq_domain;* the hardware irq number and linux irq type value. */ struct irq_domain_ops { -unsigned int (*to_irq)(struct irq_domain *d,unsigned long hwirq); +unsigned int (*to_irq)(struct irq_domain *d,unsigned int hwirq);#ifdef CONFIG_OF int (*dt_translate)(struct irq_domain *d,struct device_node *node,const u32 *intspec,unsigned int intsize, -unsigned long *out_hwirq,unsigned int *out_type); +unsigned int *out_hwirq,unsigned int *out_type);#endif /* CONFIG_OF */ };
@@ -72,7 +72,7 @@ struct irq_domain {* be overridden if the irq_domain implements a .to_irq() hook. */ static inline unsigned int irq_domain_to_irq (struct irq_domain *d, -unsigned long hwirq) +unsigned int hwirq) {if (d->ops->to_irq)return d->ops->to_irq (d, hwirq);
kernel/irq/irqdomain.c +4 -4
@@ -20,7 +20,7 @@ static DEFINE_MUTEX(irq_domain_mutex);void irq_domain_add (struct irq_domain *domain) {struct irq_data *d; -int hwirq, irq; +unsigned int hwirq, irq;/* * This assumes that the irq_domain owner has already allocated
@@ -54,7 +54,7 @@ void irq_domain_add(struct irq_domain *domain)void irq_domain_del (struct irq_domain *domain) {struct irq_data *d; -int hwirq, irq; +unsigned int hwirq, irq;mutex_lock (&irq_domain_mutex);list_del (&domain->list);
@@ -82,7 +82,7 @@ unsigned int irq_create_of_mapping(struct device_node *controller, const u32 *intspec, unsigned int intsize) {struct irq_domain *domain; -unsigned long hwirq; +unsigned int hwirq;unsigned int irq, type;int rc = -EINVAL ;
@@ -129,7 +129,7 @@ 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, -unsigned long *out_hwirq,unsigned int *out_type) +unsigned int *out_hwirq,unsigned int *out_type) {if (d->of_node != controller)return -EINVAL ;
Signature · 1 line
1.7.2.3
PATCH v2 3/4 irq/of/ARM: Enhance irq iteration capability of irq_domain code.
In reply to David DaneyFrom: David Daney <[email protected]>
Not all irq_domain have linear sequences of irq numbers, so add hooks for domain specific iteration of the irqs in the domain.
There is an optional function in irq_domain_ops (each_irq) that iterates over the irqs in the domain calling a callback function on each one. If it is not present, the new helper functions irq_domain_each_irq() and irq_domain_each_hwirq() iterate using the existing semantics.
arch/arm/common/gic.c had to be modified to use the new iteration method as part of the change.
--- arch/arm/common/gic.c | 32 ++++++++++------- include/linux/irqdomain.h | 14 +++++--- kernel/irq/irqdomain.c | 84 ++++++++++++++++++++++++++++++++------------ 3 files changed, 89 insertions(+), 41 deletions(-)
arch/arm/common/gic.c +19 -13
@@ -345,6 +345,24 @@ void __init gic_cascade_irq(unsigned int gic_nr, unsigned int irq)irq_set_chained_handler (irq, gic_handle_cascade_irq); } +static int __init gic_dist_init_domain_cb (struct irq_domain *domain, +unsigned int irq, +unsigned int hwirq) +{ +if (hwirq <32 ) { +irq_set_percpu_devid (irq); +irq_set_chip_and_handler (irq, &gic_chip, + handle_percpu_devid_irq); +set_irq_flags (irq,IRQF_VALID |IRQF_NOAUTOEN ); + }else { +irq_set_chip_and_handler (irq, &gic_chip, + handle_fasteoi_irq); +set_irq_flags (irq,IRQF_VALID |IRQF_PROBE ); + } +irq_set_chip_data (irq, gic); +return 0 ; +} +static void __init gic_dist_init (struct gic_chip_data *gic) {unsigned int i, irq;
@@ -392,19 +410,7 @@ static void __init gic_dist_init(struct gic_chip_data *gic)/* * Setup the Linux IRQ subsystem. */ -irq_domain_for_each_irq (domain, i, irq) { -if (i <32 ) { -irq_set_percpu_devid (irq); -irq_set_chip_and_handler (irq, &gic_chip, - handle_percpu_devid_irq); -set_irq_flags (irq,IRQF_VALID |IRQF_NOAUTOEN ); - }else { -irq_set_chip_and_handler (irq, &gic_chip, - handle_fasteoi_irq); -set_irq_flags (irq,IRQF_VALID |IRQF_PROBE ); - } -irq_set_chip_data (irq, gic); - } +irq_domain_each_irq (domain, gic_dist_init_domain_cb);writel_relaxed (1 , base +GIC_DIST_CTRL ); }
include/linux/irqdomain.h +9 -5
@@ -27,12 +27,16 @@ struct irq_domain;* @to_irq: (optional) given a local hardware irq number, return the linux * irq number. If to_irq is not implemented, then the irq_domain * will use this translation: irq = (domain->irq_base + hwirq) +* @each_irq: (optional) call the cb function for each irq that is a +* member of the domain. * @dt_translate: Given a device tree node and interrupt specifier, decode * the hardware irq number and linux irq type value. */ struct irq_domain_ops {unsigned int (*to_irq)(struct irq_domain *d,unsigned int hwirq); - +int (*each_irq)(struct irq_domain *d, +int (*cb)(struct irq_domain *d, +unsigned int irq,unsigned int hwirq));#ifdef CONFIG_OF int (*dt_translate)(struct irq_domain *d, struct device_node *node, const u32 *intspec, unsigned int intsize,
@@ -81,10 +85,10 @@ static inline unsigned int irq_domain_to_irq(struct irq_domain *d,return d->irq_base + hwirq - d->hwirq_base; } -#define irq_domain_for_each_irq (d, hw, irq) \ - for (hw = d->hwirq_base, irq = irq_domain_to_irq(d, hw); \ - hw < d->hwirq_base + d->nr_irq; \ - hw++, irq = irq_domain_to_irq(d, hw)) +extern int irq_domain_each_irq (struct irq_domain *d, +int (*cb)(struct irq_domain *d, +unsigned int irq, +unsigned int hwirq));extern void irq_domain_add (struct irq_domain *domain);extern void irq_domain_del (struct irq_domain *domain);
kernel/irq/irqdomain.c +61 -23
119 lines not on this page · raw message
Signature · 1 line
1.7.2.3
PATCH v2 4/4 MIPS: Octeon: Add irq_create_of_mapping() and GPIO interrupts.
In reply to David DaneyFrom: David Daney <david.daney-YGCgFSpz5w/[email protected]>
This is needed for Octeon to use the Device Tree.
The GPIO interrupts are configured based on Device Tree properties
--- arch/mips/Kconfig | 1 + arch/mips/cavium-octeon/octeon-irq.c | 259 +++++++++++++++++++++++++++++++++- 2 files changed, 259 insertions(+), 1 deletions(-)
arch/mips/Kconfig +1 -0
@@ -1432,6 +1432,7 @@ config CPU_CAVIUM_OCTEON select WEAK_ORDERING select CPU_SUPPORTS_HIGHMEM select CPU_SUPPORTS_HUGEPAGES + select IRQ_DOMAIN help The Cavium Octeon processor is a highly integrated chip containing many ethernet hardware widgets for networking tasks. The processor
arch/mips/cavium-octeon/octeon-irq.c +258 -1
319 lines not on this page · raw message
Signature · 1 line
1.7.2.3
David,
Quoted 43 lines · David Daney
From: David Daney <[email protected]>
Back in early Nov. I send the first version of this patch set. Now things are heating up again in the world of
irq_domain, so I wanted to try to get some closure on the issues I had. The Octeon patch is included here to show how I am usingirq_domain, but is part of a much larger effort to merge Octeon device tree support.The basic problem I am attempting to solve is using irq domains when there is a 'non-linear' mapping of hwirq <--> irq within a domain. Octeon has a single set of irq numbers that is used across two different implementations of the interrupt controller as well as more than 10 different SOCs all which use different subsets of the irq number space. The result is that the hwirq to irq mapping function contains many gaps and discontinuities, it is really quite random.
The existing irq domain infrastructure assumes a continuous linear mapping of hwirq to irq that can be encapsulated by the
irq_base,hwirq_baseandnr_irqelements of structirq_domain. This is not suitable for the Octeon implementation.The gist of my change is to add an optional iterator function to
irq_domain_opswhich knows how to iterate over the irq numbers in a given domain. For simple linear domains (those currently supported), we iterate using the current method based onirq_base,hwirq_baseandnr_irq.Summary of the patches:
1) Get rid of some unused code to make subsequent changes simpler.
2) Cleanup the data type used by various hwirq functions and users.
3) Add the irq iterator, and fix up the ARM GIC code to use it instead of the current
irq_domain_for_each_irq().4) Add the Octeon users of the interface.
In an earlier exchange, Rob Herring had said:
... Handling sparse irqs is a potentially common problem, so we should address that in the core irqdomain code.
Quoted 8 lines
Which is what this patch set is doing.
There was a suggestion that perhaps having .to_irq() return a magic value if there was no mapping would also work. However I prefer this approach as it separates the concepts of iteration and mapping of irq numbers.
Please comment.
Can we first have a patch that just allows irq domains to be enabled on MIPS. It collides because of multiple versions of irq_create_of_mapping.
Rob
Quoted 53 lines · Rob Herring
David,
Quoted 50 lines · David Daney
From: David Daney <david.daney-YGCgFSpz5w/[email protected]>
Back in early Nov. I send the first version of this patch set. Now things are heating up again in the world of
irq_domain, so I wanted to try to get some closure on the issues I had. The Octeon patch is included here to show how I am usingirq_domain, but is part of a much larger effort to merge Octeon device tree support.The basic problem I am attempting to solve is using irq domains when there is a 'non-linear' mapping of hwirq <--> irq within a domain. Octeon has a single set of irq numbers that is used across two different implementations of the interrupt controller as well as more than 10 different SOCs all which use different subsets of the irq number space. The result is that the hwirq to irq mapping function contains many gaps and discontinuities, it is really quite random.
The existing irq domain infrastructure assumes a continuous linear mapping of hwirq to irq that can be encapsulated by the
irq_base,hwirq_baseandnr_irqelements of structirq_domain. This is not suitable for the Octeon implementation.The gist of my change is to add an optional iterator function to
irq_domain_opswhich knows how to iterate over the irq numbers in a given domain. For simple linear domains (those currently supported), we iterate using the current method based onirq_base,hwirq_baseandnr_irq.Summary of the patches:
1) Get rid of some unused code to make subsequent changes simpler.
2) Cleanup the data type used by various hwirq functions and users.
3) Add the irq iterator, and fix up the ARM GIC code to use it instead of the current
irq_domain_for_each_irq().4) Add the Octeon users of the interface.
In an earlier exchange, Rob Herring had said:
... Handling sparse irqs is a potentially common problem, so we should address that in the core irqdomain code.
Which is what this patch set is doing.
There was a suggestion that perhaps having .to_irq() return a magic value if there was no mapping would also work. However I prefer this approach as it separates the concepts of iteration and mapping of irq numbers.
Quoted 4 lines
Quoted 1 line
Please comment.
Can we first have a patch that just allows irq domains to be enabled on MIPS. It collides because of multiple versions of
irq_create_of_mapping.
I'm working on this. I made some poor decisions when first implementing irq_domain which have made it difficult to bring into sync with powerpc. Right now I'm working on a series to replace the new irq_domain with the existing (working-for-years) powerpc code and converting over all the users. Basically what I should have done in the first place.
g.
Signature · 2 lines
Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd.