Skip to contentSkip to conversation

ARM: timer-sp: ensure interrupt is cleared at sp804_of_init

PATCH Superseded Chanho Min 2 participants 3 messages Sep 17, 2014 – Sep 18, 2014 Arm (32-bit)

lore
Share & tools
lore

Chanho Min

author
#0 lore raw

PATCH v2 1/1 ARM: timer-sp: ensure interrupt is cleared at sp804_of_init

sp804 may not be added to the tick device if the higher device is already registered. In this case, If pending interrupt is existed (usually It will be passed from the boot loader), inetrrupt is occured without event_handler then it cause kernel panic. So Interrupts should be cleared before clockevent is registered.

Changes since v1:
- Move to sp804_of_init
- Clear TIMER2 interrupt
- Update commit log

---
 arch/arm/common/timer-sp.c |    4 ++++
 1 file changed, 4 insertions(+)
arch/arm/common/timer-sp.c +4 -0
index fd6bff0..e3cc08e 100644
@@ -226,6 +226,10 @@ static void __init sp804_of_init(struct device_node *np)
 	writel(0, base + TIMER_CTRL);
 	writel(0, base + TIMER_2_BASE + TIMER_CTRL);
 
+	/* Ensure interrupt is cleared */
+	writel(1, base + TIMER_INTCLR);
+	writel(1, base + TIMER_2_BASE + TIMER_INTCLR);
+
 	if (initialized || !of_device_is_available(np))
 		goto err;
 
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 21 lines · Chanho Min

sp804 may not be added to the tick device if the higher device is already registered. In this case, If pending interrupt is existed (usually It will be passed from the boot loader), inetrrupt is occured without event_handler then it cause kernel panic. So Interrupts should be cleared before clockevent is registered.

Changes since v1:
- Move to sp804_of_init
- Clear TIMER2 interrupt
- Update commit log

---
 arch/arm/common/timer-sp.c |    4 ++++
 1 file changed, 4 insertions(+)
arch/arm/common/timer-sp.c +0 -0
index fd6bff0..e3cc08e 100644

arch/arm/common/timer-sp.c static void __init sp804_of_init(struct device_node *np) · line 231

Quoted 6 lines
arch/arm/common/timer-sp.c +3 -0
@@ -226,6 +226,10 @@ static void __init sp804_of_init(struct device_node *np)
 	writel(0, base + TIMER_CTRL);
 	writel(0, base + TIMER_2_BASE + TIMER_CTRL);
 
+	/* Ensure interrupt is cleared */
+	writel(1, base + TIMER_INTCLR);
+	writel(1, base + TIMER_2_BASE + TIMER_INTCLR);

NAK.

This is really not necessary for two reasons, and incorrect for a third reason:

1. If the control register is cleared, interrupts are disabled. When interrupts are disabled, the IRQ line from the timer module is deasserted irrespective of the internal interrupt state of the timer.

2. We only enable the interrupt when we set the timer up to run in either periodic or one-shot modes. If the timer is not used, the interrupt remains masked.

3. Even if this was necessary (which it isn't), only doing this in the sp804_of_init() path is wrong - there are other initialisation paths in this code, and there's no reason why one should have a different behaviour to the others.

If you've found this by running the kernel with QEMU, then it's probably a QEMU bug if it raises an interrupt during the above code.

Signature · 2 lines
FTTC broadband for 0.8mile line: currently at 9.5Mbps down 400kbps up
according to speedtest.net.
author
#2 lore raw

PATCH v2 1/1 ARM: timer-sp: ensure interrupt is cleared at sp804_of_init

Quoted 39 lines

-----Original Message-----
From: Russell King - ARM Linux [mailto:linux at arm.linux.org.uk]
Sent: Wednesday, September 17, 2014 8:58 PM
To: Chanho Min
Cc: Stephen Boyd; Michael Opdenacker; Linus Walleij; linux-arm-kernel at lists.infradead.org; linux- kernel at vger.kernel.org; Jongsung Kim
Subject: Re: [PATCH v2] ARM: timer-sp: ensure interrupt is cleared at sp804_of_init

Quoted 21 lines · Chanho Min

sp804 may not be added to the tick device if the higher device is already registered. In this case, If pending interrupt is existed (usually It will be passed from the boot loader), inetrrupt is occured without event_handler then it cause kernel panic. So Interrupts should be cleared before clockevent is registered.

Changes since v1:
- Move to sp804_of_init
- Clear TIMER2 interrupt
- Update commit log

---
 arch/arm/common/timer-sp.c |    4 ++++
 1 file changed, 4 insertions(+)
arch/arm/common/timer-sp.c +0 -0
index fd6bff0..e3cc08e 100644

arch/arm/common/timer-sp.c static void __init sp804_of_init(struct device_node *np) · line 231

Quoted 6 lines
arch/arm/common/timer-sp.c +3 -0
@@ -226,6 +226,10 @@ static void __init sp804_of_init(struct device_node *np)
 	writel(0, base + TIMER_CTRL);
 	writel(0, base + TIMER_2_BASE + TIMER_CTRL);
 
+	/* Ensure interrupt is cleared */
+	writel(1, base + TIMER_INTCLR);
+	writel(1, base + TIMER_2_BASE + TIMER_INTCLR);

NAK.

Quoted 7 lines

This is really not necessary for two reasons, and incorrect for a third reason:

1. If the control register is cleared, interrupts are disabled. When interrupts are disabled, the IRQ line from the timer module is deasserted irrespective of the internal interrupt state of the timer.

Even if the control register is cleared and interrupts are disabled, It is not harmful before timer is enabled but It is rather harmful if interrupt is asserted before timer up. My patch just ensure interrupt is cleared before timer up

Quoted 4 lines

2. We only enable the interrupt when we set the timer up to run in either periodic or one-shot modes. If the timer is not used, the interrupt remains masked.

In our test, setup_irq enables the interrupt irrespective of the timer up/down.

Quoted 4 lines

3. Even if this was necessary (which it isn't), only doing this in the sp804_of_init() path is wrong - there are other initialisation paths in this code, and there's no reason why one should have a different behaviour to the others.

So Can another approach be acceptable as bellows?

arch/arm/common/timer-sp.c +2 -2
index fd6bff0..4aed813 100644
@@ -121,8 +121,8 @@ static irqreturn_t sp804_timer_interrupt(int irq, void *dev_id)
 
        /* clear the interrupt */
        writel(1, clkevt_base + TIMER_INTCLR);
-
-       evt->event_handler(evt);
+       if(evt->event_handler)
+               evt->event_handler(evt);
 
        return IRQ_HANDLED;
 }
Quoted 6 lines

If you've found this by running the kernel with QEMU, then it's probably a QEMU bug if it raises an interrupt during the above code.

--
FTTC broadband for 0.8mile line: currently at 9.5Mbps down 400kbps up according to speedtest.net.

Chaho