Skip to contentSkip to conversation

ARM: OMAP: handle lazy IRQ disable properly

RFC In review Imre Deak 3 participants 6 messages Apr 2, 2006 – May 27, 2006 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

Imre Deak

author
#0 lore raw

RFC 1/1 ARM: OMAP: handle lazy IRQ disable properly

GPIO IRQs can't be disabled at the moment, since the ARM lazy IRQ masking is not handled properly by the current GPIO IRQ handler.

Implementing it properly would solve the following issues, which the standard do_edge_IRQ, do_level_IRQ handlers already do:

- Account for disable_irq delaying the IRQ masking till the next interrupt. The IRQ dispatcher should check whether the IRQ line is disabled through irq_desc.disable_depth and if so it should not call the IRQ handler and should leave the IRQ masked. enable_irq will do later the unmasking.

- Try to avoid lost edge triggered interrupts. We won't reenter an already running IRQ handler, but will call it again in the next iteration of the IRQ dispatch loop.

- Avoid a possible stack overflow. This can happen when the next interrupt is generated before the device driver gets the chance to act upon the first interrupt. Since we run edge triggered IRQ handlers unmasked this could lead to an unbounded recursion in the IRQ dispatcher. This is at least the case with the ads7846 touchscreen controller.

--Imre

arch/arm/plat-omap/gpio.c +34 -0
index d3c8ea7..642f5eb 100644
@@ -736,6 +736,7 @@ static void gpio_irq_handler(unsigned in
 	u32 isr;
 	unsigned int gpio_irq;
 	struct gpio_bank *bank;
+	u32 retrigger = 0;
 
 	desc->chip->ack(irq);
 
@@ -785,16 +786,49 @@ static void gpio_irq_handler(unsigned in
 		if (!level_mask)
 			desc->chip->unmask(irq);
 
+		isr |= retrigger;
+		retrigger = 0;
 		if (!isr)
 			break;
 
 		gpio_irq = bank->virtual_irq_start;
 		for (; isr != 0; isr >>= 1, gpio_irq++) {
 			struct irqdesc *d;
+			int irq_mask;
 			if (!(isr & 1))
 				continue;
 			d = irq_desc + gpio_irq;
+			/* Don't run the handler if it's already running
+			 * or was disabled lazely.
+			 */
+			if (unlikely((d->disable_depth || d->running))) {
+				irq_mask = 1 <<
+					(gpio_irq - bank->virtual_irq_start);
+				/* The unmasking will be done by
+				 * enable_irq in case it is disabled or
+				 * after returning from the handler if
+				 * it's already running.
+				 */
+				_enable_gpio_irqbank(bank, irq_mask, 0);
+				if (!d->disable_depth) {
+					/* Level triggered interrupts
+					 * won't ever be reentered
+					 */
+					BUG_ON(level_mask & irq_mask);
+					d->pending = 1;
+				}
+				continue;
+			}
+			d->running = 1;
 			desc_handle_irq(gpio_irq, d, regs);
+			d->running = 0;
+			if (unlikely(d->pending && !d->disable_depth)) {
+				irq_mask = 1 <<
+					(gpio_irq - bank->virtual_irq_start);
+				d->pending = 0;
+				_enable_gpio_irqbank(bank, irq_mask, 1);
+				retrigger |= irq_mask;
+			}
 		}
 
 		if (cpu_is_omap24xx()) {

A message that is not in the archive (sent off-list or not yet received): 1147882410.22799.5.camel@orphique

author
#2 lore raw

Hi,

Quoted 10 lines · ext Ladislav Michl
Quoted 2 lines · Imre Deak

GPIO IRQs can't be disabled at the moment, since the ARM lazy IRQ masking is not handled properly by the current GPIO IRQ handler.

Imre,

I updated linux-omap git tree yesterday and found that it no longer boots on VoiceBlue (5910) board; smc91x driver doesn't get any interrupts. Reverting following commit made it work again.

Quoted 7 lines

diff-tree e829dc78d9908b3949c2994b331c5279049b9098 Author: Imre Deak <[email protected]>
Date: Thu May 11 16:13:42 2006 +0300

ARM: OMAP: GPIO IRQ lazy IRQ disable fix

It is not exactly the same as the one you provided here, but it seems it is based on it.

I missed the fact that some OMAPs have IRQ mask others IRQ enable register.. Could you try it with the attached patch?

--Imre

Quoted 3 lines

Best regards,
ladis

arch/arm/plat-omap/gpio.c +7 -1
index cd1e508..0fb4081 100644
@@ -540,19 +540,24 @@ static inline void _clear_gpio_irqstatus
 static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank)
 {
 	void __iomem *reg = bank->base;
+	int inv = 0;
+	u32 mask;
 
 	switch (bank->method) {
 	case METHOD_MPUIO:
 		reg += OMAP_MPUIO_GPIO_MASKIT;
+		inv = 1;
 		break;
 	case METHOD_GPIO_1510:
 		reg += OMAP1510_GPIO_INT_MASK;
+		inv = 1;
 		break;
 	case METHOD_GPIO_1610:
 		reg += OMAP1610_GPIO_IRQENABLE1;
 		break;
 	case METHOD_GPIO_730:
 		reg += OMAP730_GPIO_INT_MASK;
+		inv = 1;
 		break;
 	case METHOD_GPIO_24XX:
 		reg += OMAP24XX_GPIO_IRQENABLE1;
@@ -562,7 +567,8 @@ static u32 _get_gpio_irqbank_mask(struct
 		return 0;
 	}
 
-	return __raw_readl(reg);
+	mask = __raw_readl(reg);
+	return inv ? !mask : mask;
 }
 
 static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask, int enable)
author
#3 lore raw
Quoted 16 lines · Imre Deak

Hi,

Quoted 13 lines · ext Ladislav Michl
Quoted 2 lines · Imre Deak

GPIO IRQs can't be disabled at the moment, since the ARM lazy IRQ masking is not handled properly by the current GPIO IRQ handler.

Imre,

I updated linux-omap git tree yesterday and found that it no longer boots on VoiceBlue (5910) board; smc91x driver doesn't get any interrupts. Reverting following commit made it work again.

diff-tree e829dc78d9908b3949c2994b331c5279049b9098 Author: Imre Deak <[email protected]>
Date: Thu May 11 16:13:42 2006 +0300

Quoted 7 lines
Quoted 4 lines

ARM: OMAP: GPIO IRQ lazy IRQ disable fix

It is not exactly the same as the one you provided here, but it seems it is based on it.

I missed the fact that some OMAPs have IRQ mask others IRQ enable register.. Could you try it with the attached patch?

Or rather this one. Have to check the bank size as well and invert properly.

--Imre

Quoted 5 lines
Quoted 4 lines

Best regards,
ladis

arch/arm/plat-omap/gpio.c +16 -1
index cd1e508..beb1e1a 100644
@@ -540,29 +540,44 @@ static inline void _clear_gpio_irqstatus
 static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank)
 {
 	void __iomem *reg = bank->base;
+	int inv = 0;
+	u32 l;
+	u32 mask;
 
 	switch (bank->method) {
 	case METHOD_MPUIO:
 		reg += OMAP_MPUIO_GPIO_MASKIT;
+		mask = 0x0f;
+		inv = 1;
 		break;
 	case METHOD_GPIO_1510:
 		reg += OMAP1510_GPIO_INT_MASK;
+		mask = 0x0f;
+		inv = 1;
 		break;
 	case METHOD_GPIO_1610:
 		reg += OMAP1610_GPIO_IRQENABLE1;
+		mask = 0x0f;
 		break;
 	case METHOD_GPIO_730:
 		reg += OMAP730_GPIO_INT_MASK;
+		mask = 0xff;
+		inv = 1;
 		break;
 	case METHOD_GPIO_24XX:
 		reg += OMAP24XX_GPIO_IRQENABLE1;
+		mask = 0xff;
 		break;
 	default:
 		BUG();
 		return 0;
 	}
 
-	return __raw_readl(reg);
+	l = __raw_readl(reg);
+	if (inv)
+		l = ~l;
+	l &= mask;
+	return l;
 }
 
 static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask, int enable)
author
#4 lore raw

PATCH 1/1 ARM: OMAP: fix GPIO IRQ mask handling [was Re: [RFC] ARM: OMAP: handle lazy IRQ disable properly]

[ Ignore the two previous ones they were both bogus:( I tested this on OMAP1510 innovator ]

ARM: OMAP: fix GPIO IRQ mask handling

The GPIO IRQ mask was retrieved incorrectly in cases where we have a mask register instead of an enable register. Also we should only return the valid bits depending on the bank size.

This fixes a bug on 1510/1610 based OMAPs where GPIO IRQs are not delivered.

arch/arm/plat-omap/gpio.c +16 -1
index cd1e508..e75a2ca 100644
@@ -540,29 +540,44 @@ static inline void _clear_gpio_irqstatus
 static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank)
 {
 	void __iomem *reg = bank->base;
+	int inv = 0;
+	u32 l;
+	u32 mask;
 
 	switch (bank->method) {
 	case METHOD_MPUIO:
 		reg += OMAP_MPUIO_GPIO_MASKIT;
+		mask = 0xffff;
+		inv = 1;
 		break;
 	case METHOD_GPIO_1510:
 		reg += OMAP1510_GPIO_INT_MASK;
+		mask = 0xffff;
+		inv = 1;
 		break;
 	case METHOD_GPIO_1610:
 		reg += OMAP1610_GPIO_IRQENABLE1;
+		mask = 0xffff;
 		break;
 	case METHOD_GPIO_730:
 		reg += OMAP730_GPIO_INT_MASK;
+		mask = 0xffffffff;
+		inv = 1;
 		break;
 	case METHOD_GPIO_24XX:
 		reg += OMAP24XX_GPIO_IRQENABLE1;
+		mask = 0xffffffff;
 		break;
 	default:
 		BUG();
 		return 0;
 	}
 
-	return __raw_readl(reg);
+	l = __raw_readl(reg);
+	if (inv)
+		l = ~l;
+	l &= mask;
+	return l;
 }
 
 static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask, int enable)
#5 lore raw

Re: [PATCH] ARM: OMAP: fix GPIO IRQ mask handling [was Re: [RFC] ARM: OMAP: handle lazy IRQ disable properly]

Quoted 11 lines · Imre Deak

[ Ignore the two previous ones they were both bogus:( I tested this on OMAP1510 innovator ]

ARM: OMAP: fix GPIO IRQ mask handling

The GPIO IRQ mask was retrieved incorrectly in cases where we have a mask register instead of an enable register. Also we should only return the valid bits depending on the bank size.

This fixes a bug on 1510/1610 based OMAPs where GPIO IRQs are not delivered.

Great, hopefully this will finally fix the last GPIO irq issues! Pushing today.

Tony

#6 lore raw

Re: [PATCH] ARM: OMAP: fix GPIO IRQ mask handling [was Re: [RFC] ARM: OMAP: handle lazy IRQ disable properly]

Quoted 2 lines · Tony Lindgren

Great, hopefully this will finally fix the last GPIO irq issues!

Just in time to phase in the new generic IRQ infrastructure. :)

One of the GPIO IRQ issues gets resolved there by having the analogue of do_simple_IRQ() test for disabled IRQs like all the other dispatchers. Better do it there than in drivers or platform irq code...

- Dave