Skip to contentSkip to conversation

OMAP2+: PM/serial: fix console semaphore acquire during suspend

PATCH Superseded Kevin Hilman 3 participants 4 messages Dec 8, 2010 – Dec 10, 2010

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

PATCH v3 1/1 OMAP2+: PM/serial: fix console semaphore acquire during suspend

commit 0d8e2d0dad98a693bad88aea6876ac8b94ad95c6 (OMAP2+: PM/serial:
hold console semaphore while OMAP UARTs are disabled) added use of the console semaphore to protect UARTs from being accessed after disabled during idle, but this causes problems in suspend.

During suspend, the console semaphore is acquired by the console suspend method (console_suspend()) so the try_acquire_console_sem() will always fail and suspend will be aborted.

To fix, introduce a check so the console semaphore is only attempted during idle, and not during suspend. Also use the same check so that the console semaphore is not prematurely released during resume.

Thanks to Paul Walmsley for suggesting adding the same check during resume.

---
Applies to Tony's omap-fixes branch, and recommended for -rc series.

 arch/arm/mach-omap2/pm24xx.c |   35 ++++++++++++++++++++++++++++++++---
 arch/arm/mach-omap2/pm34xx.c |   27 ++++++++++++++++++++-------
 2 files changed, 52 insertions(+), 10 deletions(-)
arch/arm/mach-omap2/pm24xx.c +32 -3
index c85923e..1e031d0 100644
@@ -53,6 +53,19 @@
 #include <plat/powerdomain.h>
 #include <plat/clockdomain.h>
 
+#ifdef CONFIG_SUSPEND
+static suspend_state_t suspend_state = PM_SUSPEND_ON;
+static inline bool is_suspending(void)
+{
+	return (suspend_state != PM_SUSPEND_ON);
+}
+#else
+static inline bool is_suspending(void)
+{
+	return false;
+}
+#endif
+
 static void (*omap2_sram_idle)(void);
 static void (*omap2_sram_suspend)(u32 dllctrl, void __iomem *sdrc_dlla_ctrl,
 				  void __iomem *sdrc_power);
@@ -120,8 +133,9 @@ static void omap2_enter_full_retention(void)
 		goto no_sleep;
 
 	/* Block console output in case it is on one of the OMAP UARTs */
-	if (try_acquire_console_sem())
-		goto no_sleep;
+	if (!is_suspending())
+		if (try_acquire_console_sem())
+			goto no_sleep;
 
 	omap_uart_prepare_idle(0);
 	omap_uart_prepare_idle(1);
@@ -136,7 +150,8 @@ static void omap2_enter_full_retention(void)
 	omap_uart_resume_idle(1);
 	omap_uart_resume_idle(0);
 
-	release_console_sem();
+	if (!is_suspending())
+		release_console_sem();
 
 no_sleep:
 	if (omap2_pm_debug) {
@@ -284,6 +299,12 @@ out:
 	local_irq_enable();
 }
 
+static int omap2_pm_begin(suspend_state_t state)
+{
+	suspend_state = state;
+	return 0;
+}
+
 static int omap2_pm_prepare(void)
 {
 	/* We cannot sleep in idle until we have resumed */
@@ -333,10 +354,18 @@ static void omap2_pm_finish(void)
 	enable_hlt();
 }
 
+static void omap2_pm_end(void)
+{
+	suspend_state = PM_SUSPEND_ON;
+	return;
+}
+
 static struct platform_suspend_ops omap_pm_ops = {
+	.begin		= omap2_pm_begin,
 	.prepare	= omap2_pm_prepare,
 	.enter		= omap2_pm_enter,
 	.finish		= omap2_pm_finish,
+	.end		= omap2_pm_end,
 	.valid		= suspend_valid_only_mem,
 };
 
arch/arm/mach-omap2/pm34xx.c +20 -7
index 0ec8a04..648b8c5 100644
@@ -50,6 +50,19 @@
 #include "sdrc.h"
 #include "control.h"
 
+#ifdef CONFIG_SUSPEND
+static suspend_state_t suspend_state = PM_SUSPEND_ON;
+static inline bool is_suspending(void)
+{
+	return (suspend_state != PM_SUSPEND_ON);
+}
+#else
+static inline bool is_suspending(void)
+{
+	return false;
+}
+#endif
+
 /* Scratchpad offsets */
 #define OMAP343X_TABLE_ADDRESS_OFFSET	   0xc4
 #define OMAP343X_TABLE_VALUE_OFFSET	   0xc0
@@ -387,10 +400,11 @@ void omap_sram_idle(void)
 	}
 
 	/* Block console output in case it is on one of the OMAP UARTs */
-	if (per_next_state < PWRDM_POWER_ON ||
-	    core_next_state < PWRDM_POWER_ON)
-		if (try_acquire_console_sem())
-			goto console_still_active;
+	if (!is_suspending())
+		if (per_next_state < PWRDM_POWER_ON ||
+		    core_next_state < PWRDM_POWER_ON)
+			if (try_acquire_console_sem())
+				goto console_still_active;
 
 	/* PER */
 	if (per_next_state < PWRDM_POWER_ON) {
@@ -470,7 +484,8 @@ void omap_sram_idle(void)
 		omap_uart_resume_idle(3);
 	}
 
-	release_console_sem();
+	if (!is_suspending())
+		release_console_sem();
 
 console_still_active:
 	/* Disable IO-PAD and IO-CHAIN wakeup */
@@ -514,8 +529,6 @@ out:
 }
 
 #ifdef CONFIG_SUSPEND
-static suspend_state_t suspend_state;
-
 static int omap3_pm_prepare(void)
 {
 	disable_hlt();
Signature · 1 line
1.7.2.1
#1 lore raw

PATCH v3 1/1 OMAP2+: PM/serial: fix console semaphore acquire during suspend

Quoted 9 lines · Kevin Hilman
(quoted diff) +0 -0
@@ -120,8 +133,9 @@ static void omap2_enter_full_retention(void)
 ? ? ? ? ? ? ? ?goto no_sleep;
 

? ? ? ?/* Block console output in case it is on one of the OMAP UARTs */
- ? ? ? if (try_acquire_console_sem())
- ? ? ? ? ? ? ? goto no_sleep;
+ ? ? ? if (!is_suspending())
+ ? ? ? ? ? ? ? if (try_acquire_console_sem())
+ ? ? ? ? ? ? ? ? ? ? ? goto no_sleep;

Combine into one if?
Hi Kevin,

<snip>

Quoted 13 lines

? ? ? ?omap_uart_prepare_idle(0);
? ? ? ?omap_uart_prepare_idle(1);

(quoted diff) +2 -1
@@ -136,7 +150,8 @@ static void omap2_enter_full_retention(void)
 ? ? ? ?omap_uart_resume_idle(1);
 ? ? ? ?omap_uart_resume_idle(0);
 
- ? ? ? release_console_sem();
+ ? ? ? if (!is_suspending())
+ ? ? ? ? ? ? ? release_console_sem();
 

?no_sleep:
? ? ? ?if (omap2_pm_debug) {

arch/arm/mach-omap2/pm24xx.c out: · line 306

Quoted 8 lines
arch/arm/mach-omap2/pm24xx.c +5 -0
@@ -284,6 +299,12 @@ out:
 ? ? ? ?local_irq_enable();
 ?}
 
+static int omap2_pm_begin(suspend_state_t state)
+{
+ ? ? ? suspend_state = state;
+ ? ? ? return 0;
+}

Do you really need a return code here?

arch/arm/mach-omap2/pm24xx.c static void omap2_pm_finish(void) · line 361

Quoted 12 lines
(quoted diff) +0 -0
 ?static int omap2_pm_prepare(void)
 ?{

? ? ? ?/* We cannot sleep in idle until we have resumed */

arch/arm/mach-omap2/pm24xx.c +5 -0
@@ -333,10 +354,18 @@ static void omap2_pm_finish(void)
 ? ? ? ?enable_hlt();
 ?}
 
+static void omap2_pm_end(void)
+{
+ ? ? ? suspend_state = PM_SUSPEND_ON;
+ ? ? ? return;
+}

Redundant return.

Quoted 39 lines
(quoted diff) +3 -0
+
 ?static struct platform_suspend_ops omap_pm_ops = {
+ ? ? ? .begin ? ? ? ? ?= omap2_pm_begin,
 ? ? ? ?.prepare ? ? ? ?= omap2_pm_prepare,
 ? ? ? ?.enter ? ? ? ? ?= omap2_pm_enter,
 ? ? ? ?.finish ? ? ? ? = omap2_pm_finish,
+ ? ? ? .end ? ? ? ? ? ?= omap2_pm_end,
 ? ? ? ?.valid ? ? ? ? ?= suspend_valid_only_mem,
 ?};
 
arch/arm/mach-omap2/pm34xx.c +0 -0
index 0ec8a04..648b8c5 100644
@@ -50,6 +50,19 @@

?#include "sdrc.h"
?#include "control.h"

arch/arm/mach-omap2/pm34xx.c +13 -0
+#ifdef CONFIG_SUSPEND
+static suspend_state_t suspend_state = PM_SUSPEND_ON;
+static inline bool is_suspending(void)
+{
+ ? ? ? return (suspend_state != PM_SUSPEND_ON);
+}
+#else
+static inline bool is_suspending(void)
+{
+ ? ? ? return false;
+}
+#endif
+

?/* Scratchpad offsets */
?#define OMAP343X_TABLE_ADDRESS_OFFSET ? ? 0xc4
?#define OMAP343X_TABLE_VALUE_OFFSET ? ? ? 0xc0

arch/arm/mach-omap2/pm34xx.c +0 -0
@@ -387,10 +400,11 @@ void omap_sram_idle(void)
 ? ? ? ?}
 

? ? ? ?/* Block console output in case it is on one of the OMAP UARTs */
- ? ? ? if (per_next_state < PWRDM_POWER_ON ||

Quoted 8 lines

- ? ? ? ? ? core_next_state < PWRDM_POWER_ON)
- ? ? ? ? ? ? ? if (try_acquire_console_sem())
- ? ? ? ? ? ? ? ? ? ? ? goto console_still_active;
+ ? ? ? if (!is_suspending())
+ ? ? ? ? ? ? ? if (per_next_state < PWRDM_POWER_ON ||
+ ? ? ? ? ? ? ? ? ? core_next_state < PWRDM_POWER_ON)
+ ? ? ? ? ? ? ? ? ? ? ? if (try_acquire_console_sem())
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? goto console_still_active;

Oh well, 3 nested ifs...

Thanks,
Vitaly

#2 lore raw

PATCH v3 1/1 OMAP2+: PM/serial: fix console semaphore acquire during suspend

Quoted 5 lines · Vitaly Wool
Quoted 3 lines · Kevin Hilman
(quoted diff) +0 -0
@@ -120,8 +133,9 @@ static void omap2_enter_full_retention(void)
 ? ? ? ? ? ? ? ?goto no_sleep;
 
Quoted 8 lines
Quoted 6 lines

? ? ? ?/* Block console output in case it is on one of the OMAP UARTs */
- ? ? ? if (try_acquire_console_sem())
- ? ? ? ? ? ? ? goto no_sleep;
+ ? ? ? if (!is_suspending())
+ ? ? ? ? ? ? ? if (try_acquire_console_sem())
+ ? ? ? ? ? ? ? ? ? ? ? goto no_sleep;

Combine into one if?

personal preference I guess. I prefer it nested.

Quoted 19 lines

<snip>

Quoted 16 lines

? ? ? ?omap_uart_prepare_idle(0);
? ? ? ?omap_uart_prepare_idle(1);

(quoted diff) +2 -1
@@ -136,7 +150,8 @@ static void omap2_enter_full_retention(void)
 ? ? ? ?omap_uart_resume_idle(1);
 ? ? ? ?omap_uart_resume_idle(0);
 
- ? ? ? release_console_sem();
+ ? ? ? if (!is_suspending())
+ ? ? ? ? ? ? ? release_console_sem();
 

?no_sleep:
? ? ? ?if (omap2_pm_debug) {

(quoted diff) +0 -0
@@ -284,6 +299,12 @@ out:
 ? ? ? ?local_irq_enable();
 ?}
 
Quoted 7 lines

arch/arm/mach-omap2/pm24xx.c out: · line 306

Quoted 5 lines
arch/arm/mach-omap2/pm24xx.c +5 -0
+static int omap2_pm_begin(suspend_state_t state)
+{
+ ? ? ? suspend_state = state;
+ ? ? ? return 0;
+}

Do you really need a return code here?

yes, this function prototype is defined by the driver model, not by me.

Quoted 7 lines
Quoted 7 lines
(quoted diff) +0 -0
 ?static int omap2_pm_prepare(void)
 ?{

? ? ? ?/* We cannot sleep in idle until we have resumed */

(quoted diff) +0 -0
@@ -333,10 +354,18 @@ static void omap2_pm_finish(void)
 ? ? ? ?enable_hlt();
 ?}
 
Quoted 7 lines

arch/arm/mach-omap2/pm24xx.c static void omap2_pm_finish(void) · line 361

Quoted 5 lines
arch/arm/mach-omap2/pm24xx.c +5 -0
+static void omap2_pm_end(void)
+{
+ ? ? ? suspend_state = PM_SUSPEND_ON;
+ ? ? ? return;
+}

Redundant return.

but harmless

Quoted 37 lines
Quoted 37 lines
(quoted diff) +3 -0
+
 ?static struct platform_suspend_ops omap_pm_ops = {
+ ? ? ? .begin ? ? ? ? ?= omap2_pm_begin,
 ? ? ? ?.prepare ? ? ? ?= omap2_pm_prepare,
 ? ? ? ?.enter ? ? ? ? ?= omap2_pm_enter,
 ? ? ? ?.finish ? ? ? ? = omap2_pm_finish,
+ ? ? ? .end ? ? ? ? ? ?= omap2_pm_end,
 ? ? ? ?.valid ? ? ? ? ?= suspend_valid_only_mem,
 ?};
 
arch/arm/mach-omap2/pm34xx.c +0 -0
index 0ec8a04..648b8c5 100644
@@ -50,6 +50,19 @@

?#include "sdrc.h"
?#include "control.h"

arch/arm/mach-omap2/pm34xx.c +13 -0
+#ifdef CONFIG_SUSPEND
+static suspend_state_t suspend_state = PM_SUSPEND_ON;
+static inline bool is_suspending(void)
+{
+ ? ? ? return (suspend_state != PM_SUSPEND_ON);
+}
+#else
+static inline bool is_suspending(void)
+{
+ ? ? ? return false;
+}
+#endif
+

?/* Scratchpad offsets */
?#define OMAP343X_TABLE_ADDRESS_OFFSET ? ? 0xc4
?#define OMAP343X_TABLE_VALUE_OFFSET ? ? ? 0xc0

arch/arm/mach-omap2/pm34xx.c +0 -0
@@ -387,10 +400,11 @@ void omap_sram_idle(void)
 ? ? ? ?}
 
Quoted 12 lines
Quoted 10 lines

? ? ? ?/* Block console output in case it is on one of the OMAP UARTs */
- ? ? ? if (per_next_state < PWRDM_POWER_ON ||
- ? ? ? ? ? core_next_state < PWRDM_POWER_ON)
- ? ? ? ? ? ? ? if (try_acquire_console_sem())
- ? ? ? ? ? ? ? ? ? ? ? goto console_still_active;
+ ? ? ? if (!is_suspending())
+ ? ? ? ? ? ? ? if (per_next_state < PWRDM_POWER_ON ||
+ ? ? ? ? ? ? ? ? ? core_next_state < PWRDM_POWER_ON)
+ ? ? ? ? ? ? ? ? ? ? ? if (try_acquire_console_sem())
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? goto console_still_active;

Oh well, 3 nested ifs...

again, personal preference.

Kevin

maintainer
#3 lore raw

PATCH v3 1/1 OMAP2+: PM/serial: fix console semaphore acquire during suspend

Quoted 11 lines · Kevin Hilman
Quoted 8 lines · Vitaly Wool

arch/arm/mach-omap2/pm24xx.c static void omap2_pm_finish(void) · line 361

Quoted 6 lines
arch/arm/mach-omap2/pm24xx.c +5 -0
+static void omap2_pm_end(void)
+{
+ ? ? ? suspend_state = PM_SUSPEND_ON;
+ ? ? ? return;
+}

Redundant return.

but harmless

I'll queue this fix, will leave out the harmless return.

Regards,

Tony