plat-versatile: modernize FPGA IRQ controller
Subsystems (4)
PATCH 2/3 plat-versatile: modernize FPGA IRQ controller
This does two things to the FPGA IRQ controller in the versatile family:
- Convert to MULTI_IRQ_HANDLER so we can drop the entry macro from the Integrator.
- Convert to using IRQ domains so we can get rid of the NO_IRQ mess and proceed with device tree and such stuff.
I was unable to split this patch in two. The main reason is the half-done conversion to device tree in Versatile.
Tested on Integrator/AP and Integrator/CP.
--- arch/arm/Kconfig | 1 + .../arm/mach-integrator/include/mach/entry-macro.S | 39 ----------- arch/arm/mach-integrator/integrator_ap.c | 9 +-- arch/arm/mach-integrator/integrator_cp.c | 28 ++------ arch/arm/mach-versatile/core.c | 13 ++-- arch/arm/plat-versatile/Kconfig | 6 ++ arch/arm/plat-versatile/fpga-irq.c | 71 ++++++++++++++++++-- arch/arm/plat-versatile/include/plat/fpga-irq.h | 8 ++- 8 files changed, 94 insertions(+), 81 deletions(-) delete mode 100644 arch/arm/mach-integrator/include/mach/entry-macro.S
arch/arm/Kconfig +1 -0
@@ -280,6 +280,7 @@ config ARCH_INTEGRATOR select NEED_MACH_IO_H select NEED_MACH_MEMORY_H select SPARSE_IRQ + select MULTI_IRQ_HANDLER help Support for ARM's Integrator platform.
arch/arm/mach-integrator/include/mach/entry-macro.S deleted +0 -39
@@ -1,39 +0,0 @@ -/* - * arch/arm/mach-integrator/include/mach/entry-macro.S - * - * Low-level IRQ helper macros for Integrator platforms - * - * This file is licensed under the terms of the GNU General Public - * License version 2. This program is licensed "as is" without any - * warranty of any kind, whether express or implied. - */ -#include <mach/hardware.h> -#include <mach/platform.h> -#include <mach/irqs.h> - - .macro get_irqnr_preamble, base, tmp - .endm - - .macro get_irqnr_and_base, irqnr, irqstat, base, tmp -/* FIXME: should not be using soo many LDRs here */ - ldr \base, =IO_ADDRESS(INTEGRATOR_IC_BASE) - mov \irqnr, #IRQ_PIC_START - ldr \irqstat, [\base, #IRQ_STATUS] @ get masked status - ldr \base, =IO_ADDRESS(INTEGRATOR_HDR_BASE) - teq \irqstat, #0 - ldreq \irqstat, [\base, #(INTEGRATOR_HDR_IC_OFFSET+IRQ_STATUS)] - moveq \irqnr, #IRQ_CIC_START - -1001: tst \irqstat, #15 - bne 1002f - add \irqnr, \irqnr, #4 - movs \irqstat, \irqstat, lsr #4 - bne 1001b -1002: tst \irqstat, #1 - bne 1003f - add \irqnr, \irqnr, #1 - movs \irqstat, \irqstat, lsr #1 - bne 1002b -1003: /* EQ will be set if no irqs pending */ - .endm -
arch/arm/mach-integrator/integrator_ap.c +2 -7
@@ -162,12 +162,6 @@ static void __init ap_map_io(void)#define INTEGRATOR_SC_VALID_INT 0x003fffff -static struct fpga_irq_data sc_irq_data = { - .base =VA_IC_BASE , - .irq_start =0 , - .chip.name ="SC" , -}; -static void __init ap_init_irq (void ) {/* Disable all interrupts initially. */
@@ -178,7 +172,7 @@ static void __init ap_init_irq(void)writel (-1 ,VA_IC_BASE +IRQ_ENABLE_CLEAR );writel (-1 ,VA_IC_BASE +FIQ_ENABLE_CLEAR ); -fpga_irq_init (-1 ,INTEGRATOR_SC_VALID_INT , &sc_irq_data); +fpga_irq_init (VA_IC_BASE ,"SC" ,0 ,-1 ,INTEGRATOR_SC_VALID_INT ,NULL ); }#ifdef CONFIG_PM
@@ -478,6 +472,7 @@ MACHINE_START(INTEGRATOR, "ARM-Integrator") .nr_irqs = NR_IRQS_INTEGRATOR_AP, .init_early = integrator_init_early, .init_irq = ap_init_irq, + .handle_irq = fpga_handle_irq, .timer = &ap_timer, .init_machine = ap_init, .restart = integrator_restart,
arch/arm/mach-integrator/integrator_cp.c +7 -21
@@ -143,24 +143,6 @@ static void __init intcp_map_io(void)iotable_init (intcp_io_desc,ARRAY_SIZE (intcp_io_desc)); } -static struct fpga_irq_data cic_irq_data = { - .base =INTCP_VA_CIC_BASE , - .irq_start =IRQ_CIC_START , - .chip.name ="CIC" , -}; - -static struct fpga_irq_data pic_irq_data = { - .base =INTCP_VA_PIC_BASE , - .irq_start =IRQ_PIC_START , - .chip.name ="PIC" , -}; - -static struct fpga_irq_data sic_irq_data = { - .base =INTCP_VA_SIC_BASE , - .irq_start =IRQ_SIC_START , - .chip.name ="SIC" , -}; -static void __init intcp_init_irq (void ) {u32 pic_mask, cic_mask, sic_mask;
@@ -179,11 +161,14 @@ static void __init intcp_init_irq(void)writel (sic_mask,INTCP_VA_SIC_BASE +IRQ_ENABLE_CLEAR );writel (sic_mask,INTCP_VA_SIC_BASE +FIQ_ENABLE_CLEAR ); -fpga_irq_init (-1 , pic_mask, &pic_irq_data); +fpga_irq_init (INTCP_VA_PIC_BASE ,"PIC" ,IRQ_PIC_START , +-1 , pic_mask,NULL ); -fpga_irq_init (-1 , cic_mask, &cic_irq_data); +fpga_irq_init (INTCP_VA_CIC_BASE ,"CIC" ,IRQ_CIC_START , +-1 , cic_mask,NULL ); -fpga_irq_init (IRQ_CP_CPPLDINT , sic_mask, &sic_irq_data); +fpga_irq_init (INTCP_VA_SIC_BASE ,"SIC" ,IRQ_SIC_START , +IRQ_CP_CPPLDINT , sic_mask,NULL ); }/*
@@ -466,6 +451,7 @@ MACHINE_START(CINTEGRATOR, "ARM-IntegratorCP") .nr_irqs = NR_IRQS_INTEGRATOR_CP, .init_early = intcp_init_early, .init_irq = intcp_init_irq, + .handle_irq = fpga_handle_irq, .timer = &cp_timer, .init_machine = intcp_init, .restart = integrator_restart,
arch/arm/mach-versatile/core.c +5 -8
@@ -66,12 +66,6 @@#define VA_VIC_BASE __io_address(VERSATILE_VIC_BASE)#define VA_SIC_BASE __io_address(VERSATILE_SIC_BASE) -static struct fpga_irq_data sic_irq = { - .base =VA_SIC_BASE , - .irq_start =IRQ_SIC_START , - .chip.name ="SIC" , -}; -#if 1 #define IRQ_MMCI0A IRQ_VICSOURCE22#define IRQ_AACI IRQ_VICSOURCE24
@@ -105,8 +99,11 @@ void __init versatile_init_irq(void)writel (~0 ,VA_SIC_BASE +SIC_IRQ_ENABLE_CLEAR ); -fpga_irq_init (IRQ_VICSOURCE31 , ~PIC_MASK , &sic_irq); -irq_domain_generate_simple (sic_of_match,VERSATILE_SIC_BASE ,IRQ_SIC_START ); + np =of_find_matching_node_by_address (NULL , sic_of_match, +VERSATILE_SIC_BASE ); + +fpga_irq_init (VA_SIC_BASE ,"SIC" ,IRQ_SIC_START , +IRQ_VICSOURCE31 , ~PIC_MASK , np);/* * Interrupts on secondary controller from 0 to 8 are routed to
arch/arm/plat-versatile/Kconfig +6 -0
@@ -5,6 +5,12 @@ config PLAT_VERSATILE_CLCD config PLAT_VERSATILE_FPGA_IRQ bool + select IRQ_DOMAIN + +config PLAT_VERSATILE_FPGA_IRQ_NR + int + default 4 + depends on PLAT_VERSATILE_FPGA_IRQ config PLAT_VERSATILE_LEDS def_bool y if LEDS_CLASS
arch/arm/plat-versatile/fpga-irq.c +66 -5
111 lines not on this page · raw message
arch/arm/plat-versatile/include/plat/fpga-irq.h +7 -1
@@ -5,8 +5,14 @@ struct fpga_irq_data {void __iomem *base;unsigned int irq_start;struct irq_chip chip; + struct irq_domain *domain; }; -void fpga_irq_init (int ,u32 ,struct fpga_irq_data *); +struct device_node ; +struct pt_regs ; + +void fpga_handle_irq (struct pt_regs *regs); +void fpga_irq_init (void __iomem *,const char *,int ,int ,u32 , +struct device_node *node);#endif
Signature · 1 line
1.7.7.6
PATCH 2/3 plat-versatile: modernize FPGA IRQ controller
arch/arm/plat-versatile/fpga-irq.c line 18
Quoted 5 lines · Linus Walleij
arch/arm/plat-versatile/fpga-irq.c +1
-0@@ -12,10 +15,14 @@#define IRQ_ENABLE_SET 0x08#define IRQ_ENABLE_CLEAR 0x0c +/* we cannot allocate memory when VICs are initially registered */
They aren't VICs. A VIC is a totally different interrupt controller.
arch/arm/plat-versatile/fpga-irq.c line 25
Quoted 8 lines
arch/arm/plat-versatile/fpga-irq.c +4
-1+static struct fpga_irq_data fpga_irq_devices[CONFIG_PLAT_VERSATILE_FPGA_IRQ_NR ]; +static int fpga_irq_id; +static void fpga_irq_mask (struct irq_data *d) {struct fpga_irq_data *f =irq_data_get_irq_chip_data (d); -u32 mask =1 << (d->irq - f->irq_start); +u32 mask = (1 << d->hwirq);
1 << d->hwirq will do, no need for excessive parens here.
Quoted 9 lines
arch/arm/plat-versatile/fpga-irq.c +8
-0+/* +* Handle each interrupt in a single FPGA IRQ controller. Returns non-zero +* if we've handled at least one interrupt. This does a single read of the +* status register and handles all interrupts in order from LSB first. +*/ +static int handle_one_fpga (struct fpga_irq_data *f,struct pt_regs *regs) { +int handled =0 ; +int irq;
arch/arm/plat-versatile/fpga-irq.c static void fpga_irq_handle(unsigned int irq, struct irq_desc *desc) · line 73
Quoted 10 lines
arch/arm/plat-versatile/fpga-irq.c +10
-0+u32 status =readl (f->base +IRQ_STATUS ); + +while (status) { + irq =ffs (status) -1 ; +handle_IRQ (irq_find_mapping (f->domain, irq), regs); + status &= ~(1 << irq); + handled =1 ; + } + +return handled;
Buggy. See what happens when you cache the status register, and handle_IRQ enables interrupts after processing the first IRQ to do soft IRQ processing.
PATCH 2/3 plat-versatile: modernize FPGA IRQ controller
Quoted 8 lines · Russell King - ARM Linux
Quoted 5 lines · Linus Walleij
(quoted diff) +0
-0@@ -12,10 +15,14 @@?#define
IRQ_ENABLE_SET? ? ? ? ? ? ?0x08
?#defineIRQ_ENABLE_CLEAR? ?0x0c+/* we cannot allocate memory when VICs are initially registered */
They aren't VICs. ?A VIC is a totally different interrupt controller.
OK copy/paste error...
Quoted 3 lines
Quoted 1 line
+ ? ? u32 mask = (1 <<
d->hwirq);1 <<
d->hwirqwill do, no need for excessive parens here.
OK
Quoted 10 lines
Quoted 10 lines
+static int
handle_one_fpga(struct fpga_irq_data *f, struct pt_regs *regs)?{
+ ? ? int handled = 0;
+ ? ? int irq;
+ ? ? u32 status =readl(f->base + IRQ_STATUS);
+
+ ? ? while (status) {
+ ? ? ? ? ? ? irq = ffs(status) - 1;
+ ? ? ? ? ? ?handle_IRQ(irq_find_mapping(f->domain, irq), regs);
+ ? ? ? ? ? ? status &= ~(1 << irq);
Quoted 8 lines
Quoted 4 lines
+ ? ? ? ? ? ? handled = 1;
+ ? ? }
+
+ ? ? return handled;Buggy. ?See what happens when you cache the status register, and
handle_IRQenables interrupts after processing the first IRQ to do soft IRQ processing.
Hm the code is exactly the same as in arch/arm/common/vic.c I guess once we figure this loop out we may need to go back and fix that driver also so good that we bring it up.
Anyway, IIRC the VIC was written that way since it will traverse all IRQs once, if there are remaining IRQs after that these are treated from this outer loop in the per-instance handler:
asmlinkage void __exception_irq_entry fpga_handle_irq(struct pt_regs *regs)
{
int i, handled;
do {
for (i = 0, handled = 0; i < fpga_irq_id; ++i)
handled |= handle_one_fpga(&fpga_irq_devices[i], regs);
} while (handled);
}This will traverse all flags on all controllers until all flags are low so all handlers get chance to run. (i.e. IRQ0 on controller 0 cannot lock others out.)
It always looked sane to me, but what am I not getting here...
Thanks,
Linus Walleij
PATCH 2/3 plat-versatile: modernize FPGA IRQ controller
Quoted 40 lines · Linus Walleij
Quoted 11 lines · Russell King - ARM Linux
Quoted 10 lines · Linus Walleij
+static int
handle_one_fpga(struct fpga_irq_data *f, struct pt_regs *regs)?{
+ ? ? int handled = 0;
+ ? ? int irq;
+ ? ? u32 status =readl(f->base + IRQ_STATUS);
+
+ ? ? while (status) {
+ ? ? ? ? ? ? irq = ffs(status) - 1;
+ ? ? ? ? ? ?handle_IRQ(irq_find_mapping(f->domain, irq), regs);
+ ? ? ? ? ? ? status &= ~(1 << irq);Quoted 8 lines
Quoted 4 lines
+ ? ? ? ? ? ? handled = 1;
+ ? ? }
+
+ ? ? return handled;Buggy. ?See what happens when you cache the status register, and
handle_IRQenables interrupts after processing the first IRQ to do soft IRQ processing.Hm the code is exactly the same as in
arch/arm/common/vic.cI guess once we figure this loop out we may need to go back and fix that driver also so good that we bring it up.Anyway, IIRC the VIC was written that way since it will traverse all IRQs once, if there are remaining IRQs after that these are treated from this outer loop in the per-instance handler:
asmlinkage void
__exception_irq_entryfpga_handle_irq(struct pt_regs *regs){ int i, handled; do { for (i = 0, handled = 0; i < fpga_irq_id; ++i) handled |= handle_one_fpga(&fpga_irq_devices[i], regs); } while (handled); }
Quoted 5 lines
This will traverse all flags on all controllers until all flags are low so all handlers get chance to run. (i.e. IRQ0 on controller 0 cannot lock others out.)
It always looked sane to me, but what am I not getting here...
See http://lists.arm.linux.org.uk/lurker/message/20120402.214614.e7740b12.en.html
and the rest of that thread.