Skip to contentSkip to conversation

irq: add irq_domain translation infrastructure

RFC PATCH In review Grant Likely 3 participants 5 messages May 26, 2011 – Jun 27, 2011

Subsystems (8)
Arm (32-bit) x86 PowerPC MIPS +4 more subsystems
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 irq: add irq_domain translation infrastructure

This patch adds irq_domain infrastructure for translating from hardware irq numbers to linux irqs. This is particularly important for architectures adding device tree support because the current implementation (excluding PowerPC and SPARC) cannot handle translation for more than a single interrupt controller. irq_domain supports device tree translation for any number of interrupt controllers.

This patch converts x86, Microblaze, ARM and MIPS to use irq_domain for device tree irq translation. x86 is untested beyond compiling it, and the patch definitely breaks MIPS and Microblaze because I haven't added the code to either of them to actually register an irq_domain yet (easy to fix), but on ARM it works. I'm circulating this for comments to make sure I'm on the right path before I fix up the MIPS and Microblaze bits.

PowerPC has /not/ been converted to use this new infrastructure. It is still missing some features before it can replace the virq infrastructure already in powerpc (see documentation on irq_domain_map/unmap for details). Followup patches will add the missing pieces and migrate PowerPC to use irq_domain.

SPARC has its own method of managing interrupts from the device tree and is unaffected by this change.

---
 arch/arm/include/asm/prom.h           |    5 -
 arch/arm/kernel/devtree.c             |   14 ---
 arch/microblaze/include/asm/irq.h     |   10 --
 arch/microblaze/kernel/irq.c          |    7 --
 arch/mips/include/asm/irq.h           |    5 -
 arch/mips/kernel/prom.c               |   14 ---
 arch/powerpc/include/asm/irq.h        |    1 
 arch/x86/include/asm/irq_controller.h |   12 ---
 arch/x86/include/asm/prom.h           |   10 --
 arch/x86/kernel/devicetree.c          |  101 ++++++++----------------
 include/linux/irq.h                   |   81 ++++++++++++++++++++
 include/linux/of_irq.h                |    2 
 kernel/irq/Makefile                   |    2 
 kernel/irq/irqdomain.c                |  137 +++++++++++++++++++++++++++++++++
 14 files changed, 257 insertions(+), 144 deletions(-)
 delete mode 100644 arch/x86/include/asm/irq_controller.h
 create mode 100644 kernel/irq/irqdomain.c
arch/arm/include/asm/prom.h +0 -5
index 11b8708..6f65ca8 100644
@@ -16,11 +16,6 @@
 #include <asm/setup.h>
 #include <asm/irq.h>
 
-static inline void irq_dispose_mapping(unsigned int virq)
-{
-	return;
-}
-
 extern struct machine_desc *setup_machine_fdt(unsigned int dt_phys);
 extern void arm_dt_memblock_reserve(void);
 
arch/arm/kernel/devtree.c +0 -14
index a701e42..1e0b613 100644
@@ -129,17 +129,3 @@ struct machine_desc * __init setup_machine_fdt(unsigned int dt_phys)
 
 	return mdesc_best;
 }
-
-/**
- * irq_create_of_mapping - Hook to resolve OF irq specifier into a Linux irq#
- *
- * Currently the mapping mechanism is trivial; simple flat hwirq numbers are
- * mapped 1:1 onto Linux irq numbers.  Cascaded irq controllers are not
- * supported.
- */
-unsigned int irq_create_of_mapping(struct device_node *controller,
-				   const u32 *intspec, unsigned int intsize)
-{
-	return intspec[0];
-}
-EXPORT_SYMBOL_GPL(irq_create_of_mapping);
arch/microblaze/include/asm/irq.h +1 -9
index cc54187..6a6d83b 100644
@@ -16,6 +16,7 @@
  * be big enough to enclose whatever representation is used by a given
  * platform.
  */
+#define _IRQ_HW_NUMBER_T
 typedef unsigned long irq_hw_number_t;
 
 extern unsigned int nr_irq;
@@ -25,15 +26,6 @@ extern unsigned int nr_irq;
 struct pt_regs;
 extern void do_IRQ(struct pt_regs *regs);
 
-/** FIXME - not implement
- * irq_dispose_mapping - Unmap an interrupt
- * @virq: linux virq number of the interrupt to unmap
- */
-static inline void irq_dispose_mapping(unsigned int virq)
-{
-	return;
-}
-
 struct irq_host;
 
 /**
arch/microblaze/kernel/irq.c +0 -7
index ce7ac84..59bb560 100644
@@ -54,10 +54,3 @@ unsigned int irq_create_mapping(struct irq_host *host, irq_hw_number_t hwirq)
 	return hwirq;
 }
 EXPORT_SYMBOL_GPL(irq_create_mapping);
-
-unsigned int irq_create_of_mapping(struct device_node *controller,
-				   const u32 *intspec, unsigned int intsize)
-{
-	return intspec[0];
-}
-EXPORT_SYMBOL_GPL(irq_create_of_mapping);
arch/mips/include/asm/irq.h +0 -5
index 0ec0129..dc650ae 100644
@@ -16,11 +16,6 @@
 
 #include <irq.h>
 
-static inline void irq_dispose_mapping(unsigned int virq)
-{
-	return;
-}
-
 #ifdef CONFIG_I8259
 static inline int irq_canonicalize(int irq)
 {
arch/mips/kernel/prom.c +0 -14
index 5b7eade..010aaaf 100644
@@ -60,20 +60,6 @@ void __init early_init_dt_setup_initrd_arch(unsigned long start,
 }
 #endif
 
-/*
- * irq_create_of_mapping - Hook to resolve OF irq specifier into a Linux irq#
- *
- * Currently the mapping mechanism is trivial; simple flat hwirq numbers are
- * mapped 1:1 onto Linux irq numbers.  Cascaded irq controllers are not
- * supported.
- */
-unsigned int irq_create_of_mapping(struct device_node *controller,
-				   const u32 *intspec, unsigned int intsize)
-{
-	return intspec[0];
-}
-EXPORT_SYMBOL_GPL(irq_create_of_mapping);
-
 void __init early_init_devtree(void *params)
 {
 	/* Setup flat device-tree pointer */
arch/powerpc/include/asm/irq.h +1 -0
index 1bff591..66bf09e 100644
@@ -45,6 +45,7 @@ extern atomic_t ppc_n_lost_interrupts;
  * be big enough to enclose whatever representation is used by a given
  * platform.
  */
+#define _IRQ_HW_NUMBER_T
 typedef unsigned long irq_hw_number_t;
 
 /* Interrupt controller "host" data structure. This could be defined as a
arch/x86/include/asm/irq_controller.h deleted +0 -12
deleted file mode 100644
index 423bbbd..0000000
@@ -1,12 +0,0 @@
-#ifndef __IRQ_CONTROLLER__
-#define __IRQ_CONTROLLER__
-
-struct irq_domain {
-	int (*xlate)(struct irq_domain *h, const u32 *intspec, u32 intsize,
-			u32 *out_hwirq, u32 *out_type);
-	void *priv;
-	struct device_node *controller;
-	struct list_head l;
-};
-
-#endif
arch/x86/include/asm/prom.h +0 -10
index 971e0b4..2c8101e 100644
@@ -21,7 +21,6 @@
 #include <asm/irq.h>
 #include <asm/atomic.h>
 #include <asm/setup.h>
-#include <asm/irq_controller.h>
 
 #ifdef CONFIG_OF
 extern int of_ioapic;
@@ -54,15 +53,6 @@ extern char cmd_line[COMMAND_LINE_SIZE];
 #define pci_address_to_pio pci_address_to_pio
 unsigned long pci_address_to_pio(phys_addr_t addr);
 
-/**
- * irq_dispose_mapping - Unmap an interrupt
- * @virq: linux virq number of the interrupt to unmap
- *
- * FIXME: We really should implement proper virq handling like power,
- * but that's going to be major surgery.
- */
-static inline void irq_dispose_mapping(unsigned int virq) { }
-
 #define HAVE_ARCH_DEVTREE_FIXUPS
 
 #endif /* __ASSEMBLY__ */
arch/x86/kernel/devicetree.c +34 -67

147 lines not on this page · raw message

include/linux/irq.h +81 -0

116 lines not on this page · raw message

include/linux/of_irq.h +2 -0
index e6955f5..67a2a57 100644
@@ -63,6 +63,7 @@ extern int of_irq_map_one(struct device_node *device, int index,
 extern unsigned int irq_create_of_mapping(struct device_node *controller,
 					  const u32 *intspec,
 					  unsigned int intsize);
+extern void irq_dispose_mapping(unsigned int irq);
 extern int of_irq_to_resource(struct device_node *dev, int index,
 			      struct resource *r);
 extern int of_irq_count(struct device_node *dev);
@@ -70,6 +71,7 @@ extern int of_irq_to_resource_table(struct device_node *dev,
 		struct resource *res, int nr_irqs);
 extern struct device_node *of_irq_find_parent(struct device_node *child);
 
+
 #endif /* CONFIG_OF_IRQ */
 #endif /* CONFIG_OF */
 #endif /* __OF_IRQ_H */
kernel/irq/Makefile +1 -1
index 7329005..aa8feed 100644
@@ -1,5 +1,5 @@
 
-obj-y := irqdesc.o handle.o manage.o spurious.o resend.o chip.o dummychip.o devres.o
+obj-y := irqdesc.o handle.o manage.o spurious.o resend.o chip.o dummychip.o devres.o irqdomain.o
 obj-$(CONFIG_GENERIC_IRQ_CHIP) += generic-chip.o
 obj-$(CONFIG_GENERIC_IRQ_PROBE) += autoprobe.o
 obj-$(CONFIG_PROC_FS) += proc.o
kernel/irq/irqdomain.c new file +137 -0

137 lines not on this page · raw message

#1 lore raw
Quoted 14 lines · * Grant Likely | 2011-05-26 00:54:38 [-0600]:
arch/x86/kernel/devicetree.c +4 -2
index 39645b6..9891cd4 100644
@@ -371,36 +321,49 @@ static struct of_ioapic_type of_ioapic_type[] =
 	},
 };
 
-static int ioapic_xlate(struct irq_domain *id, const u32 *intspec, u32 intsize,
-			u32 *out_hwirq, u32 *out_type)
+static int ioapic_dt_translate(struct irq_domain *domain,
+				struct device_node *controller,
+				const u32 *intspec, u32 intsize,
+				irq_hw_number_t *out_hwirq, u32 *out_type)

arch/x86/kernel/devicetree.c static struct of_ioapic_type of_ioapic_type[] = · line 335

Quoted 10 lines
arch/x86/kernel/devicetree.c +2 -2
 {
-	struct mp_ioapic_gsi *gsi_cfg;
 	struct io_apic_irq_attr attr;
 	struct of_ioapic_type *it;
 	u32 line, idx, type;
+	int rc;
 
-	if (intsize < 2)
+	if (controller != domain->of_node)
 		return -EINVAL;

Is there a reason not havining the (controller != domain->of_node) check in irq_create_of_mapping()?

Sebastian

#2 lore raw
Quoted 23 lines · Sebastian Andrzej Siewior
Quoted 21 lines · * Grant Likely | 2011-05-26 00:54:38 [-0600]:
arch/x86/kernel/devicetree.c +5 -3
index 39645b6..9891cd4 100644
@@ -371,36 +321,49 @@ static struct of_ioapic_type of_ioapic_type[] =
 	},
 };
 
-static int ioapic_xlate(struct irq_domain *id, const u32 *intspec, u32 intsize,
-			u32 *out_hwirq, u32 *out_type)
+static int ioapic_dt_translate(struct irq_domain *domain,
+				struct device_node *controller,
+				const u32 *intspec, u32 intsize,
+				irq_hw_number_t *out_hwirq, u32 *out_type)
 {
-	struct mp_ioapic_gsi *gsi_cfg;
 	struct io_apic_irq_attr attr;
 	struct of_ioapic_type *it;
 	u32 line, idx, type;
+	int rc;
 
Quoted 6 lines

arch/x86/kernel/devicetree.c static struct of_ioapic_type of_ioapic_type[] = · line 335

Quoted 3 lines
arch/x86/kernel/devicetree.c +1 -1
-	if (intsize < 2)
+	if (controller != domain->of_node)
 		return -EINVAL;

Is there a reason not havining the (controller != domain->of_node) check in irq_create_of_mapping()?

Not all domains are associated with a single OF node.

Take xics, where there can be quite a few "source controllers" which act as device-tree interrupt parents but there's a single global domain.

Cheers,
Ben.

#3 lore raw
Quoted 30 lines · Benjamin Herrenschmidt
Quoted 23 lines · Sebastian Andrzej Siewior
Quoted 21 lines · * Grant Likely | 2011-05-26 00:54:38 [-0600]:
arch/x86/kernel/devicetree.c +5 -3
index 39645b6..9891cd4 100644
@@ -371,36 +321,49 @@ static struct of_ioapic_type of_ioapic_type[] =
 	},
 };
 
-static int ioapic_xlate(struct irq_domain *id, const u32 *intspec, u32 intsize,
-			u32 *out_hwirq, u32 *out_type)
+static int ioapic_dt_translate(struct irq_domain *domain,
+				struct device_node *controller,
+				const u32 *intspec, u32 intsize,
+				irq_hw_number_t *out_hwirq, u32 *out_type)
 {
-	struct mp_ioapic_gsi *gsi_cfg;
 	struct io_apic_irq_attr attr;
 	struct of_ioapic_type *it;
 	u32 line, idx, type;
+	int rc;
 
Quoted 5 lines

arch/x86/kernel/devicetree.c static struct of_ioapic_type of_ioapic_type[] = · line 335

Quoted 3 lines
arch/x86/kernel/devicetree.c +1 -1
-	if (intsize < 2)
+	if (controller != domain->of_node)
 		return -EINVAL;

Is there a reason not havining the (controller != domain->of_node) check in irq_create_of_mapping()?

Quoted 4 lines

Not all domains are associated with a single OF node.

Take xics, where there can be quite a few "source controllers" which act as device-tree interrupt parents but there's a single global domain.

I see. No, actually I don't. xics is pseries where I don't see the .dts. So you are saying that we have one irq_domain but 2+ different interrupt-parents nodes?

How do you distinguish then between two different controllers lets say xics and a gpio based controller? This implementation calls ->dt_translate until one controller returns 0 which looks like brute force.

xics_host_xlate() returns always zero so you would have to go for
the compatible and check it.
Every device has an interrupt-parent node. Shouldn't the code call exact this irq controller xlate function instead of trying them all?

Quoted 4 lines

Cheers,
Ben.

Sebastian

#4 lore raw
Quoted 3 lines · Sebastian Andrzej Siewior

I see. No, actually I don't. xics is pseries where I don't see the .dts. So you are saying that we have one irq_domain but 2+ different interrupt-parents nodes?

Yes. Basically the various PCI bridges and other interrupt sources like HEA contain what are called "source controllers" that control the targetting of interrupts (toward a CPU thread), priority, masking etc...

Those act as device-tree parents as well, there's pretty much one per PCI host bridge for example since that's where all of the configuration/masking/etc... happens.

However, they then turn interrupts into a special bus message that reaches eventually a presentation controller (there's one per HW thread). Those messages are basically the "HW interrupt numbers" (along with priority info etc...) and that number encodes a "BUID" which identifies the source controller that shot the message.

Thus the "interrupt numbers" are unique accross the fabric and live in a unique number space. It's one domain for all intend and purposes. But several device-nodes.

Now as to whether it's several irq_chip or not .. well, it depends :-) On pHyp and old style pseries, it's a single set of FW call, it's abstracted, so it's also basically one chip. On WSP, the separate source controllers (ICS) are exposed as individual chips.

Quoted 3 lines

How do you distinguish then between two different controllers lets say xics and a gpio based controller? This implementation calls ->dt_translate until one controller returns 0 which looks like brute force.

It's a bit brute force but would work if the xics implementation of that translate call checks that the device-node is indeed a XICS source controller (which can be identified by its compatible property).

Now I have lost track a bit with what Grant is doing, is this the old DT stuff I objected to ? I basically asked him to make the remapping orthogonal from the DT matching.

Quoted 4 lines

xics_host_xlate() returns always zero so you would have to go for the compatible and check it.
Every device has an interrupt-parent node. Shouldn't the code call exact this irq controller xlate function instead of trying them all?

Well, my powerpc code iterates the domains with "match" to check which one claims to own the parent device-node, then calls xlate for that one, but I see why one could collapse those two action after all.

Cheers,
Ben.

Quoted 5 lines
Quoted 4 lines

Cheers,
Ben.

Sebastian