irq_domain: Standardise legacy/linear domain selection
Subsystems (3)
PATCH 1/1 irq_domain: Standardise legacy/linear domain selection
A large proportion of interrupt controllers that support legacy mappings do so because non-DT systems need to use fixed IRQ numbers when registering devices via buses but can otherwise use a linear mapping. The interrupt controller itself typically is not affected by the mapping used and best practice is to use a linear mapping where possible so drivers frequently select at runtime depending on if a legacy range has been allocated to them.
Standardise this behaviour by providing irq_domain_register_simple() which will allocate a linear mapping unless a positive first_irq is provided in which case it will fall back to a legacy mapping. This helps make best practice for irq_domain adoption clearer.
--- Documentation/IRQ-domain.txt | 5 +++++ include/linux/irqdomain.h | 5 +++++ kernel/irq/irqdomain.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+)
Documentation/IRQ-domain.txt +5 -0
@@ -93,6 +93,7 @@ Linux IRQ number into the hardware. Most drivers cannot use this mapping. ==== Legacy ==== +irq_domain_add_simple() irq_domain_add_legacy() irq_domain_add_legacy_isa()
@@ -115,3 +116,7 @@ The legacy map should only be used if fixed IRQ mappings must be supported. For example, ISA controllers would use the legacy map for mapping Linux IRQs 0-15 so that existing ISA drivers get the correct IRQ numbers. + +Most users of legacy mappings should use irq_domain_add_simple() which +will use a legacy domain only if an IRQ range is supplied by the +system and will otherwise use a linear domain mapping.
include/linux/irqdomain.h +5 -0
@@ -112,6 +112,11 @@ struct irq_domain { };#ifdef CONFIG_IRQ_DOMAIN +struct irq_domain *irq_domain_add_simple (struct device_node *of_node, +unsigned int size, +unsigned int first_irq, +const struct irq_domain_ops *ops, +void *host_data); struct irq_domain *irq_domain_add_legacy(struct device_node *of_node, unsigned int size, unsigned int first_irq,
kernel/irq/irqdomain.c +30 -0
@@ -140,6 +140,36 @@ static unsigned int irq_domain_legacy_revmap(struct irq_domain *domain, }/** +* irq_domain_add_simple() - Allocate and register a simple irq_domain. +* @of_node: pointer to interrupt controller's device tree node. +* @size: total number of irqs in mapping +* @first_irq: first number of irq block assigned to the domain +* @ops: map/unmap domain callbacks +* @host_data: Controller private data pointer +* +* Allocates a legacy irq_domain if irq_base is positive or a linear +* domain otherwise. +* +* This is intended to implement the expected behaviour for most +* interrupt controllers which is that a linear mapping should +* normally be used unless the system requires a legacy mapping in +* order to support supplying interrupt numbers during non-DT +* registration of devices. +*/ +struct irq_domain *irq_domain_add_simple (struct device_node *of_node, +unsigned int size, +unsigned int first_irq, +const struct irq_domain_ops *ops, +void *host_data) +{ +if (first_irq >0 ) +return irq_domain_add_legacy (of_node, size, first_irq,0 , + ops, host_data); +else +return irq_domain_add_linear (of_node, size, ops, host_data); +} + +/** * irq_domain_add_legacy() - Allocate and register a legacy revmap irq_domain. * @of_node: pointer to interrupt controller's device tree node. * @size: total number of irqs in legacy mapping
Signature · 1 line
1.7.10
Quoted 8 lines · Mark Brown
A large proportion of interrupt controllers that support legacy mappings do so because non-DT systems need to use fixed IRQ numbers when registering devices via buses but can otherwise use a linear mapping. The interrupt controller itself typically is not affected by the mapping used and best practice is to use a linear mapping where possible so drivers frequently select at runtime depending on if a legacy range has been allocated to them.
Quoted 4 lines
Standardise this behaviour by providing
irq_domain_register_simple()which will allocate a linear mapping unless a positivefirst_irqis provided in which case it will fall back to a legacy mapping. This helps make best practice forirq_domainadoption clearer.
We have a hardware which doesn't support ACPI nor DT. We had got a nice issue with irq domains after the gpio driver has been moved to the linear scheme.
Our internal discussion is roughly about misdesigned irq domains concept for that
kind of hardware. In generic case we could have more than one PIC, and more than one hardware that requires real 1:1 mapping of the irq numbers, and kernel doesn't
know about the last mapping until real driver module is loaded (for example a PCI
controller of something).
The issue is in plain array of the numbers that are assigned to the devices. Somehow looks better to have real namespaces, or even hide irq number in the API struct device, request_irq(), but keep reference between driver and PIC via some object.
So, given solution just hides an issue, but doesn't resolve it fully from my p.o.v.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 7 lines · Andy Shevchenko
The issue is in plain array of the numbers that are assigned to the devices. Somehow looks better to have real namespaces, or even hide irq number in the API struct device,
request_irq(), but keep reference between driver and PIC via some object.So, given solution just hides an issue, but doesn't resolve it fully from my p.o.v.
This is unrelated to what you're talking about. The devices concerned are mostly MFDs which use their own interrupts. Where other things need to use the interrupt numbers then legacy mappings should still be used and IRQ domains have no effect at all on the situation.
Grant Likely
AppliedQuoted 8 lines · Mark Brown
A large proportion of interrupt controllers that support legacy mappings do so because non-DT systems need to use fixed IRQ numbers when registering devices via buses but can otherwise use a linear mapping. The interrupt controller itself typically is not affected by the mapping used and best practice is to use a linear mapping where possible so drivers frequently select at runtime depending on if a legacy range has been allocated to them.
Quoted 6 lines
Standardise this behaviour by providing
irq_domain_register_simple()which will allocate a linear mapping unless a positivefirst_irqis provided in which case it will fall back to a legacy mapping. This helps make best practice forirq_domainadoption clearer.Signed-off-by Mark Brown <[email protected]>
Applied, thanks.
g.
Quoted 86 lines
--- Documentation/IRQ-domain.txt | 5 +++++ include/linux/irqdomain.h | 5 +++++ kernel/irq/irqdomain.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+)Documentation/IRQ-domain.txt +5
-0@@ -93,6 +93,7 @@ Linux IRQ number into the hardware. Most drivers cannot use this mapping. ==== Legacy ==== +irq_domain_add_simple() irq_domain_add_legacy() irq_domain_add_legacy_isa()@@ -115,3 +116,7 @@ The legacy map should only be used if fixed IRQ mappings must be supported. For example, ISA controllers would use the legacy map for mapping Linux IRQs 0-15 so that existing ISA drivers get the correct IRQ numbers. + +Most users of legacy mappings should use irq_domain_add_simple() which +will use a legacy domain only if an IRQ range is supplied by the +system and will otherwise use a linear domain mapping.include/linux/irqdomain.h +5
-0@@ -112,6 +112,11 @@ struct irq_domain { };#ifdef CONFIG_IRQ_DOMAIN +struct irq_domain *irq_domain_add_simple (struct device_node *of_node, +unsigned int size, +unsigned int first_irq, +const struct irq_domain_ops *ops, +void *host_data); struct irq_domain *irq_domain_add_legacy(struct device_node *of_node, unsigned int size, unsigned int first_irq,kernel/irq/irqdomain.c +30
-0@@ -140,6 +140,36 @@ static unsigned int irq_domain_legacy_revmap(struct irq_domain *domain, }/** +* irq_domain_add_simple() - Allocate and register a simple irq_domain. +* @of_node: pointer to interrupt controller's device tree node. +* @size: total number of irqs in mapping +* @first_irq: first number of irq block assigned to the domain +* @ops: map/unmap domain callbacks +* @host_data: Controller private data pointer +* +* Allocates a legacy irq_domain if irq_base is positive or a linear +* domain otherwise. +* +* This is intended to implement the expected behaviour for most +* interrupt controllers which is that a linear mapping should +* normally be used unless the system requires a legacy mapping in +* order to support supplying interrupt numbers during non-DT +* registration of devices. +*/ +struct irq_domain *irq_domain_add_simple (struct device_node *of_node, +unsigned int size, +unsigned int first_irq, +const struct irq_domain_ops *ops, +void *host_data) +{ +if (first_irq >0 ) +return irq_domain_add_legacy (of_node, size, first_irq,0 , + ops, host_data); +else +return irq_domain_add_linear (of_node, size, ops, host_data); +} + +/** * irq_domain_add_legacy() - Allocate and register a legacy revmap irq_domain. * @of_node: pointer to interrupt controller's device tree node. * @size: total number of irqs in legacy mapping Signature · 1 line
1.7.10
Signature · 2 lines
Grant Likely, B.Sc, P.Eng. Secret Lab Technologies, Ltd.