MN10300: Fix IRQ handling

Fix the IRQ handling on the MN10300 arch.

This patch makes a number of significant changes:

(1) It separates the irq_chip definition for edge-triggered interrupts from
the one for level-triggered interrupts.

This is necessary because the MN10300 PIC latches the IRQ channel's
interrupt request bit (GxICR_REQUEST), even after the device has ceased to
assert its interrupt line and the interrupt channel has been disabled in
the PIC. So for level-triggered interrupts we need to clear this bit when
we re-enable - which is achieved by setting GxICR_DETECT but not
GxICR_REQUEST when writing to the register.

Not doing this results in spurious interrupts occurring because calling
mask_ack() at the start of handle_level_irq() is insufficient - it fails
to clear the REQUEST latch because the device that caused the interrupt is
still asserting its interrupt line at this point.

(2) IRQ disablement [irq_chip::disable_irq()] shouldn't clear the interrupt
request flag for edge-triggered interrupts lest it lose an interrupt.

(3) IRQ unmasking [irq_chip::unmask_irq()] also shouldn't clear the interrupt
request flag for edge-triggered interrupts lest it lose an interrupt.

(4) The end() operation is now left to the default (no-operation) as
__do_IRQ() is compiled out. This may affect misrouted_irq(), but
according to Thomas Gleixner it's the correct thing to do.

(5) handle_level_irq() is used for edge-triggered interrupts rather than
handle_edge_irq() as the MN10300 PIC latches interrupt events even on
masked IRQ channels, thus rendering IRQ_PENDING unnecessary. It is
sufficient to call mask_ack() at the start and unmask() at the end.

(6) For level-triggered interrupts, ack() is now NULL as it's not used, and
there is no effective ACK function on the PIC. mask_ack() is now the
same as mask() as the latch continues to latch, even when the channel is
masked.

Further, the patch discards the disable() op implementation as its now the same
as the mask() op implementation, which is used instead.

It also discards the enable() op implementations as they're now the same as
the unmask() op implementations, which are used instead.

Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by David Howells and committed by Linus Torvalds d6478fad 7ac9c1c2

+51 -32
+49 -30
arch/mn10300/kernel/irq.c
··· 20 20 atomic_t irq_err_count; 21 21 22 22 /* 23 - * MN10300 INTC controller operations 23 + * MN10300 interrupt controller operations 24 24 */ 25 - static void mn10300_cpupic_disable(unsigned int irq) 26 - { 27 - u16 tmp = GxICR(irq); 28 - GxICR(irq) = (tmp & GxICR_LEVEL) | GxICR_DETECT; 29 - tmp = GxICR(irq); 30 - } 31 - 32 - static void mn10300_cpupic_enable(unsigned int irq) 33 - { 34 - u16 tmp = GxICR(irq); 35 - GxICR(irq) = (tmp & GxICR_LEVEL) | GxICR_ENABLE; 36 - tmp = GxICR(irq); 37 - } 38 - 39 25 static void mn10300_cpupic_ack(unsigned int irq) 40 26 { 41 27 u16 tmp; ··· 46 60 static void mn10300_cpupic_unmask(unsigned int irq) 47 61 { 48 62 u16 tmp = GxICR(irq); 49 - GxICR(irq) = (tmp & GxICR_LEVEL) | GxICR_ENABLE | GxICR_DETECT; 50 - tmp = GxICR(irq); 51 - } 52 - 53 - static void mn10300_cpupic_end(unsigned int irq) 54 - { 55 - u16 tmp = GxICR(irq); 56 63 GxICR(irq) = (tmp & GxICR_LEVEL) | GxICR_ENABLE; 57 64 tmp = GxICR(irq); 58 65 } 59 66 60 - static struct irq_chip mn10300_cpu_pic = { 61 - .name = "cpu", 62 - .disable = mn10300_cpupic_disable, 63 - .enable = mn10300_cpupic_enable, 67 + static void mn10300_cpupic_unmask_clear(unsigned int irq) 68 + { 69 + /* the MN10300 PIC latches its interrupt request bit, even after the 70 + * device has ceased to assert its interrupt line and the interrupt 71 + * channel has been disabled in the PIC, so for level-triggered 72 + * interrupts we need to clear the request bit when we re-enable */ 73 + u16 tmp = GxICR(irq); 74 + GxICR(irq) = (tmp & GxICR_LEVEL) | GxICR_ENABLE | GxICR_DETECT; 75 + tmp = GxICR(irq); 76 + } 77 + 78 + /* 79 + * MN10300 PIC level-triggered IRQ handling. 80 + * 81 + * The PIC has no 'ACK' function per se. It is possible to clear individual 82 + * channel latches, but each latch relatches whether or not the channel is 83 + * masked, so we need to clear the latch when we unmask the channel. 84 + * 85 + * Also for this reason, we don't supply an ack() op (it's unused anyway if 86 + * mask_ack() is provided), and mask_ack() just masks. 87 + */ 88 + static struct irq_chip mn10300_cpu_pic_level = { 89 + .name = "cpu_l", 90 + .disable = mn10300_cpupic_mask, 91 + .enable = mn10300_cpupic_unmask_clear, 92 + .ack = NULL, 93 + .mask = mn10300_cpupic_mask, 94 + .mask_ack = mn10300_cpupic_mask, 95 + .unmask = mn10300_cpupic_unmask_clear, 96 + }; 97 + 98 + /* 99 + * MN10300 PIC edge-triggered IRQ handling. 100 + * 101 + * We use the latch clearing function of the PIC as the 'ACK' function. 102 + */ 103 + static struct irq_chip mn10300_cpu_pic_edge = { 104 + .name = "cpu_e", 105 + .disable = mn10300_cpupic_mask, 106 + .enable = mn10300_cpupic_unmask, 64 107 .ack = mn10300_cpupic_ack, 65 108 .mask = mn10300_cpupic_mask, 66 109 .mask_ack = mn10300_cpupic_mask_ack, 67 110 .unmask = mn10300_cpupic_unmask, 68 - .end = mn10300_cpupic_end, 69 111 }; 70 112 71 113 /* ··· 128 114 */ 129 115 void set_intr_postackable(int irq) 130 116 { 131 - set_irq_handler(irq, handle_level_irq); 117 + set_irq_chip_and_handler(irq, &mn10300_cpu_pic_level, 118 + handle_level_irq); 132 119 } 133 120 134 121 /* ··· 141 126 142 127 for (irq = 0; irq < NR_IRQS; irq++) 143 128 if (irq_desc[irq].chip == &no_irq_type) 144 - set_irq_chip_and_handler(irq, &mn10300_cpu_pic, 145 - handle_edge_irq); 129 + /* due to the PIC latching interrupt requests, even 130 + * when the IRQ is disabled, IRQ_PENDING is superfluous 131 + * and we can use handle_level_irq() for edge-triggered 132 + * interrupts */ 133 + set_irq_chip_and_handler(irq, &mn10300_cpu_pic_edge, 134 + handle_level_irq); 146 135 unit_init_IRQ(); 147 136 } 148 137
+1 -1
arch/mn10300/unit-asb2303/unit-init.c
··· 51 51 switch (GET_XIRQ_TRIGGER(extnum)) { 52 52 case XIRQ_TRIGGER_HILEVEL: 53 53 case XIRQ_TRIGGER_LOWLEVEL: 54 - set_irq_handler(XIRQ2IRQ(extnum), handle_level_irq); 54 + set_intr_postackable(XIRQ2IRQ(extnum)); 55 55 break; 56 56 default: 57 57 break;
+1 -1
arch/mn10300/unit-asb2305/unit-init.c
··· 52 52 switch (GET_XIRQ_TRIGGER(extnum)) { 53 53 case XIRQ_TRIGGER_HILEVEL: 54 54 case XIRQ_TRIGGER_LOWLEVEL: 55 - set_irq_handler(XIRQ2IRQ(extnum), handle_level_irq); 55 + set_intr_postackable(XIRQ2IRQ(extnum)); 56 56 break; 57 57 default: 58 58 break;