Skip to contentSkip to conversation

ARM: stm32: Ping IWDG on exit from PSCI suspend code

PATCH In review Marek Vasut 3 participants 8 messages Apr 19, 2024 – Jun 17, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: stm32: Ping IWDG on exit from PSCI suspend code

Make sure the OS would not get any spurious IWDG pretimeout IRQ right after the system wakes up. This may happen in case the SoC got woken up by another source than the IWDG pretimeout and the pretimeout IRQ arrived immediately afterward, but too late to be handled by the suspend main loop. In case either of the IWDG is enabled, ping it first and then return to the OS.

---
Cc: Igor Opaniuk <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 arch/arm/mach-stm32mp/stm32mp1/psci.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
arch/arm/mach-stm32mp/stm32mp1/psci.c +21 -0
index 4f2379df45f..e99103910d9 100644
@@ -808,6 +808,27 @@ void __secure psci_system_suspend(u32 __always_unused function_id,
 	writel(SYSCFG_CMPENR_MPUEN, STM32_SYSCFG_BASE + SYSCFG_CMPENSETR);
 	clrbits_le32(STM32_SYSCFG_BASE + SYSCFG_CMPCR, SYSCFG_CMPCR_SW_CTRL);
 
+	/*
+	 * Make sure the OS would not get any spurious IWDG pretimeout IRQ
+	 * right after the system wakes up. This may happen in case the SoC
+	 * got woken up by another source than the IWDG pretimeout and the
+	 * pretimeout IRQ arrived immediately afterward, but too late to be
+	 * handled by the main loop above. In case either of the IWDG is
+	 * enabled, ping it first and then return to the OS.
+	 */
+
+	/* Ping IWDG1 and ACK pretimer IRQ */
+	if (gic_enabled[4] & BIT(22)) {
+		writel(IWDG_KR_RELOAD_KEY, STM32_IWDG1_BASE + IWDG_KR);
+		writel(IWDG_EWCR_EWIC, STM32_IWDG1_BASE + IWDG_EWCR);
+	}
+
+	/* Ping IWDG2 and ACK pretimer IRQ */
+	if (gic_enabled[4] & BIT(23)) {
+		writel(IWDG_KR_RELOAD_KEY, STM32_IWDG2_BASE + IWDG_KR);
+		writel(IWDG_EWCR_EWIC, STM32_IWDG2_BASE + IWDG_EWCR);
+	}
+
 	/*
 	 * The system has resumed successfully. Rewrite LR register stored
 	 * on stack with 'ep' value, so that on return from this PSCI call,
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 42 lines · Marek Vasut

Make sure the OS would not get any spurious IWDG pretimeout IRQ right after the system wakes up. This may happen in case the SoC got woken up by another source than the IWDG pretimeout and the pretimeout IRQ arrived immediately afterward, but too late to be handled by the suspend main loop. In case either of the IWDG is enabled, ping it first and then return to the OS.

---
Cc: Igor Opaniuk <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 arch/arm/mach-stm32mp/stm32mp1/psci.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
arch/arm/mach-stm32mp/stm32mp1/psci.c +14 -0
index 4f2379df45f..e99103910d9 100644
@@ -808,6 +808,27 @@ void __secure psci_system_suspend(u32 __always_unused function_id,
 	writel(SYSCFG_CMPENR_MPUEN, STM32_SYSCFG_BASE + SYSCFG_CMPENSETR);
 	clrbits_le32(STM32_SYSCFG_BASE + SYSCFG_CMPCR, SYSCFG_CMPCR_SW_CTRL);
 
+	/*
+	 * Make sure the OS would not get any spurious IWDG pretimeout IRQ
+	 * right after the system wakes up. This may happen in case the SoC
+	 * got woken up by another source than the IWDG pretimeout and the
+	 * pretimeout IRQ arrived immediately afterward, but too late to be
+	 * handled by the main loop above. In case either of the IWDG is
+	 * enabled, ping it first and then return to the OS.
+	 */
+
+	/* Ping IWDG1 and ACK pretimer IRQ */
+	if (gic_enabled[4] & BIT(22)) {
+		writel(IWDG_KR_RELOAD_KEY, STM32_IWDG1_BASE + IWDG_KR);
+		writel(IWDG_EWCR_EWIC, STM32_IWDG1_BASE + IWDG_EWCR);
+	}

arch/arm/mach-stm32mp/stm32mp1/psci.c void __secure psci_system_suspend(u32 __always_unused function_id, · line 834

Quoted 10 lines
arch/arm/mach-stm32mp/stm32mp1/psci.c +7 -0
+
+	/* Ping IWDG2 and ACK pretimer IRQ */
+	if (gic_enabled[4] & BIT(23)) {
+		writel(IWDG_KR_RELOAD_KEY, STM32_IWDG2_BASE + IWDG_KR);
+		writel(IWDG_EWCR_EWIC, STM32_IWDG2_BASE + IWDG_EWCR);
+	}
+
 	/*
 	 * The system has resumed successfully. Rewrite LR register stored
 	 * on stack with 'ep' value, so that on return from this PSCI call,

Thanks
Patrice

Reviewed-by on v1 1/1
#2 lore raw
In reply to Marek Vasut
Quoted 54 lines · Marek Vasut

Make sure the OS would not get any spurious IWDG pretimeout IRQ right after the system wakes up. This may happen in case the SoC got woken up by another source than the IWDG pretimeout and the pretimeout IRQ arrived immediately afterward, but too late to be handled by the suspend main loop. In case either of the IWDG is enabled, ping it first and then return to the OS.

---
Cc: Igor Opaniuk <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 arch/arm/mach-stm32mp/stm32mp1/psci.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
arch/arm/mach-stm32mp/stm32mp1/psci.c +21 -1
index 4f2379df45f..e99103910d9 100644
@@ -808,6 +808,27 @@ void __secure psci_system_suspend(u32 __always_unused function_id,
        writel(SYSCFG_CMPENR_MPUEN, STM32_SYSCFG_BASE + SYSCFG_CMPENSETR);
        clrbits_le32(STM32_SYSCFG_BASE + SYSCFG_CMPCR, SYSCFG_CMPCR_SW_CTRL);
 
+       /*
+        * Make sure the OS would not get any spurious IWDG pretimeout IRQ
+        * right after the system wakes up. This may happen in case the SoC
+        * got woken up by another source than the IWDG pretimeout and the
+        * pretimeout IRQ arrived immediately afterward, but too late to be
+        * handled by the main loop above. In case either of the IWDG is
+        * enabled, ping it first and then return to the OS.
+        */
+
+       /* Ping IWDG1 and ACK pretimer IRQ */
+       if (gic_enabled[4] & BIT(22)) {
+               writel(IWDG_KR_RELOAD_KEY, STM32_IWDG1_BASE + IWDG_KR);
+               writel(IWDG_EWCR_EWIC, STM32_IWDG1_BASE + IWDG_EWCR);
+       }
+
+       /* Ping IWDG2 and ACK pretimer IRQ */
+       if (gic_enabled[4] & BIT(23)) {
+               writel(IWDG_KR_RELOAD_KEY, STM32_IWDG2_BASE + IWDG_KR);
+               writel(IWDG_EWCR_EWIC, STM32_IWDG2_BASE + IWDG_EWCR);
+       }
+
        /*
         * The system has resumed successfully. Rewrite LR register stored
         * on stack with 'ep' value, so that on return from this PSCI call,
--
Quoted 2 lines

2.43.0

Signature · 6 lines
Best regards - Freundliche Grüsse - Meilleures salutations

Igor Opaniuk
Senior Software Engineer, Embedded & Security
E: [email protected]
W: www.foundries.io
#3 lore raw
Quoted 51 lines · Igor Opaniuk
Quoted 50 lines · Marek Vasut

Make sure the OS would not get any spurious IWDG pretimeout IRQ right after the system wakes up. This may happen in case the SoC got woken up by another source than the IWDG pretimeout and the pretimeout IRQ arrived immediately afterward, but too late to be handled by the suspend main loop. In case either of the IWDG is enabled, ping it first and then return to the OS.

---
Cc: Igor Opaniuk <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 arch/arm/mach-stm32mp/stm32mp1/psci.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
arch/arm/mach-stm32mp/stm32mp1/psci.c +21 -0
index 4f2379df45f..e99103910d9 100644
@@ -808,6 +808,27 @@ void __secure psci_system_suspend(u32 __always_unused function_id,
        writel(SYSCFG_CMPENR_MPUEN, STM32_SYSCFG_BASE + SYSCFG_CMPENSETR);
        clrbits_le32(STM32_SYSCFG_BASE + SYSCFG_CMPCR, SYSCFG_CMPCR_SW_CTRL);
 
+       /*
+        * Make sure the OS would not get any spurious IWDG pretimeout IRQ
+        * right after the system wakes up. This may happen in case the SoC
+        * got woken up by another source than the IWDG pretimeout and the
+        * pretimeout IRQ arrived immediately afterward, but too late to be
+        * handled by the main loop above. In case either of the IWDG is
+        * enabled, ping it first and then return to the OS.
+        */
+
+       /* Ping IWDG1 and ACK pretimer IRQ */
+       if (gic_enabled[4] & BIT(22)) {
+               writel(IWDG_KR_RELOAD_KEY, STM32_IWDG1_BASE + IWDG_KR);
+               writel(IWDG_EWCR_EWIC, STM32_IWDG1_BASE + IWDG_EWCR);
+       }
+
+       /* Ping IWDG2 and ACK pretimer IRQ */
+       if (gic_enabled[4] & BIT(23)) {
+               writel(IWDG_KR_RELOAD_KEY, STM32_IWDG2_BASE + IWDG_KR);
+               writel(IWDG_EWCR_EWIC, STM32_IWDG2_BASE + IWDG_EWCR);
+       }
+
Quoted 9 lines
Quoted 6 lines
arch/arm/mach-stm32mp/stm32mp1/psci.c +0 -1
        /*
         * The system has resumed successfully. Rewrite LR register stored
         * on stack with 'ep' value, so that on return from this PSCI call,
--

2.43.0

Applied to u-boot-stm32/next

Thanks
Patrice

#4 lore raw
In reply to Marek Vasut
Quoted 42 lines · Marek Vasut

Make sure the OS would not get any spurious IWDG pretimeout IRQ right after the system wakes up. This may happen in case the SoC got woken up by another source than the IWDG pretimeout and the pretimeout IRQ arrived immediately afterward, but too late to be handled by the suspend main loop. In case either of the IWDG is enabled, ping it first and then return to the OS.

---
Cc: Igor Opaniuk <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 arch/arm/mach-stm32mp/stm32mp1/psci.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
arch/arm/mach-stm32mp/stm32mp1/psci.c +14 -0
index 4f2379df45f..e99103910d9 100644
@@ -808,6 +808,27 @@ void __secure psci_system_suspend(u32 __always_unused function_id,
 	writel(SYSCFG_CMPENR_MPUEN, STM32_SYSCFG_BASE + SYSCFG_CMPENSETR);
 	clrbits_le32(STM32_SYSCFG_BASE + SYSCFG_CMPCR, SYSCFG_CMPCR_SW_CTRL);
 
+	/*
+	 * Make sure the OS would not get any spurious IWDG pretimeout IRQ
+	 * right after the system wakes up. This may happen in case the SoC
+	 * got woken up by another source than the IWDG pretimeout and the
+	 * pretimeout IRQ arrived immediately afterward, but too late to be
+	 * handled by the main loop above. In case either of the IWDG is
+	 * enabled, ping it first and then return to the OS.
+	 */
+
+	/* Ping IWDG1 and ACK pretimer IRQ */
+	if (gic_enabled[4] & BIT(22)) {
+		writel(IWDG_KR_RELOAD_KEY, STM32_IWDG1_BASE + IWDG_KR);
+		writel(IWDG_EWCR_EWIC, STM32_IWDG1_BASE + IWDG_EWCR);
+	}

arch/arm/mach-stm32mp/stm32mp1/psci.c void __secure psci_system_suspend(u32 __always_unused function_id, · line 834

Quoted 10 lines
arch/arm/mach-stm32mp/stm32mp1/psci.c +7 -0
+
+	/* Ping IWDG2 and ACK pretimer IRQ */
+	if (gic_enabled[4] & BIT(23)) {
+		writel(IWDG_KR_RELOAD_KEY, STM32_IWDG2_BASE + IWDG_KR);
+		writel(IWDG_EWCR_EWIC, STM32_IWDG2_BASE + IWDG_EWCR);
+	}
+
 	/*
 	 * The system has resumed successfully. Rewrite LR register stored
 	 * on stack with 'ep' value, so that on return from this PSCI call,

Applied to u-boot-stm32/next

Thanks
Patrice

#5 lore raw
Quoted 48 lines · Patrice CHOTARD
Quoted 45 lines · Marek Vasut

Make sure the OS would not get any spurious IWDG pretimeout IRQ right after the system wakes up. This may happen in case the SoC got woken up by another source than the IWDG pretimeout and the pretimeout IRQ arrived immediately afterward, but too late to be handled by the suspend main loop. In case either of the IWDG is enabled, ping it first and then return to the OS.

---
Cc: Igor Opaniuk <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
  arch/arm/mach-stm32mp/stm32mp1/psci.c | 21 +++++++++++++++++++++
  1 file changed, 21 insertions(+)
arch/arm/mach-stm32mp/stm32mp1/psci.c +17 -0
index 4f2379df45f..e99103910d9 100644
@@ -808,6 +808,27 @@ void __secure psci_system_suspend(u32 __always_unused function_id,
  	writel(SYSCFG_CMPENR_MPUEN, STM32_SYSCFG_BASE + SYSCFG_CMPENSETR);
  	clrbits_le32(STM32_SYSCFG_BASE + SYSCFG_CMPCR, SYSCFG_CMPCR_SW_CTRL);
 
+	/*
+	 * Make sure the OS would not get any spurious IWDG pretimeout IRQ
+	 * right after the system wakes up. This may happen in case the SoC
+	 * got woken up by another source than the IWDG pretimeout and the
+	 * pretimeout IRQ arrived immediately afterward, but too late to be
+	 * handled by the main loop above. In case either of the IWDG is
+	 * enabled, ping it first and then return to the OS.
+	 */
+
+	/* Ping IWDG1 and ACK pretimer IRQ */
+	if (gic_enabled[4] & BIT(22)) {
+		writel(IWDG_KR_RELOAD_KEY, STM32_IWDG1_BASE + IWDG_KR);
+		writel(IWDG_EWCR_EWIC, STM32_IWDG1_BASE + IWDG_EWCR);
+	}
+
+	/* Ping IWDG2 and ACK pretimer IRQ */
+	if (gic_enabled[4] & BIT(23)) {
Quoted 8 lines

arch/arm/mach-stm32mp/stm32mp1/psci.c void __secure psci_system_suspend(u32 __always_unused function_id, · line 834

Quoted 7 lines
arch/arm/mach-stm32mp/stm32mp1/psci.c +4 -0
+		writel(IWDG_KR_RELOAD_KEY, STM32_IWDG2_BASE + IWDG_KR);
+		writel(IWDG_EWCR_EWIC, STM32_IWDG2_BASE + IWDG_EWCR);
+	}
+
  	/*
  	 * The system has resumed successfully. Rewrite LR register stored
  	 * on stack with 'ep' value, so that on return from this PSCI call,

Applied to u-boot-stm32/next

This is a fix, should go into /master .

#6 lore raw
Quoted 57 lines · Marek Vasut
Quoted 47 lines · Patrice CHOTARD
Quoted 44 lines · Marek Vasut

Make sure the OS would not get any spurious IWDG pretimeout IRQ right after the system wakes up. This may happen in case the SoC got woken up by another source than the IWDG pretimeout and the pretimeout IRQ arrived immediately afterward, but too late to be handled by the suspend main loop. In case either of the IWDG is enabled, ping it first and then return to the OS.

---
Cc: Igor Opaniuk <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
Cc: [email protected]
---
  arch/arm/mach-stm32mp/stm32mp1/psci.c | 21 +++++++++++++++++++++

  1 file changed, 21 insertions(+)
arch/arm/mach-stm32mp/stm32mp1/psci.c +0 -0
index 4f2379df45f..e99103910d9 100644
@@ -808,6 +808,27 @@ void __secure psci_system_suspend(u32 __always_unused function_id,
       writel(SYSCFG_CMPENR_MPUEN, STM32_SYSCFG_BASE + SYSCFG_CMPENSETR);
       clrbits_le32(STM32_SYSCFG_BASE + SYSCFG_CMPCR, SYSCFG_CMPCR_SW_CTRL);

  +    /*
+     * Make sure the OS would not get any spurious IWDG pretimeout IRQ +     * right after the system wakes up. This may happen in case the SoC +     * got woken up by another source than the IWDG pretimeout and the +     * pretimeout IRQ arrived immediately afterward, but too late to be +     * handled by the main loop above. In case either of the IWDG is +     * enabled, ping it first and then return to the OS.
+     */

arch/arm/mach-stm32mp/stm32mp1/psci.c +9 -0
+
+    /* Ping IWDG1 and ACK pretimer IRQ */
+    if (gic_enabled[4] & BIT(22)) {
+        writel(IWDG_KR_RELOAD_KEY, STM32_IWDG1_BASE + IWDG_KR);
+        writel(IWDG_EWCR_EWIC, STM32_IWDG1_BASE + IWDG_EWCR);
+    }
+
+    /* Ping IWDG2 and ACK pretimer IRQ */
+    if (gic_enabled[4] & BIT(23)) {
Quoted 8 lines
Quoted 7 lines

+        writel(IWDG_KR_RELOAD_KEY, STM32_IWDG2_BASE + IWDG_KR); +        writel(IWDG_EWCR_EWIC, STM32_IWDG2_BASE + IWDG_EWCR); +    }
+
      /*
       * The system has resumed successfully. Rewrite LR register stored
       * on stack with 'ep' value, so that on return from this PSCI call,

Applied to u-boot-stm32/next

Quoted 1 line

This is a fix, should go into /master .

Ah yes :-( , i will send another PR for fixes on monday

Thanks for pointing this

PAtrice

#7 lore raw
Quoted 60 lines · Patrice CHOTARD
Quoted 57 lines · Marek Vasut
Quoted 55 lines · Patrice CHOTARD
Quoted 41 lines · Marek Vasut

Make sure the OS would not get any spurious IWDG pretimeout IRQ right after the system wakes up. This may happen in case the SoC got woken up by another source than the IWDG pretimeout and the pretimeout IRQ arrived immediately afterward, but too late to be handled by the suspend main loop. In case either of the IWDG is enabled, ping it first and then return to the OS.

---
Cc: Igor Opaniuk <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
   arch/arm/mach-stm32mp/stm32mp1/psci.c | 21 +++++++++++++++++++++
   1 file changed, 21 insertions(+)
arch/arm/mach-stm32mp/stm32mp1/psci.c +13 -0
index 4f2379df45f..e99103910d9 100644
@@ -808,6 +808,27 @@ void __secure psci_system_suspend(u32 __always_unused function_id,
       writel(SYSCFG_CMPENR_MPUEN, STM32_SYSCFG_BASE + SYSCFG_CMPENSETR);
       clrbits_le32(STM32_SYSCFG_BASE + SYSCFG_CMPCR, SYSCFG_CMPCR_SW_CTRL);
   +    /*
+     * Make sure the OS would not get any spurious IWDG pretimeout IRQ
+     * right after the system wakes up. This may happen in case the SoC
+     * got woken up by another source than the IWDG pretimeout and the
+     * pretimeout IRQ arrived immediately afterward, but too late to be
+     * handled by the main loop above. In case either of the IWDG is
+     * enabled, ping it first and then return to the OS.
+     */
+
+    /* Ping IWDG1 and ACK pretimer IRQ */
+    if (gic_enabled[4] & BIT(22)) {
+        writel(IWDG_KR_RELOAD_KEY, STM32_IWDG1_BASE + IWDG_KR);
+        writel(IWDG_EWCR_EWIC, STM32_IWDG1_BASE + IWDG_EWCR);
+    }

arch/arm/mach-stm32mp/stm32mp1/psci.c void __secure psci_system_suspend(u32 __always_unused function_id, · line 833

Quoted 10 lines
arch/arm/mach-stm32mp/stm32mp1/psci.c +7 -0
+
+    /* Ping IWDG2 and ACK pretimer IRQ */
+    if (gic_enabled[4] & BIT(23)) {
+        writel(IWDG_KR_RELOAD_KEY, STM32_IWDG2_BASE + IWDG_KR);
+        writel(IWDG_EWCR_EWIC, STM32_IWDG2_BASE + IWDG_EWCR);
+    }
+
       /*
        * The system has resumed successfully. Rewrite LR register stored
        * on stack with 'ep' value, so that on return from this PSCI call,

Applied to u-boot-stm32/next

Quoted 3 lines
Quoted 1 line

This is a fix, should go into /master .

Ah yes :-( , i will send another PR for fixes on monday

Thank you !