Skip to contentSkip to conversation

serial: sh-sci: Use pm_runtime_get_sync()/put()

PATCH In review Ulrich Hecht 4 participants 8 messages Apr 13, 2018 – Oct 3, 2018 TTY layer and serial drivers

lore
Share & tools
lore
#0 lore raw

cover serial: sh-sci: Use pm_runtime_get_sync()/put()

Hi!

These patches make sure that the device is up while the suspend/resume code is executed. Up-port from the BSP, tested not to break stuff.

CU
Uli

Hien Dang (2):
serial: sh-sci: Use pm_runtime_get_sync()/put() on suspend
serial: sh-sci: Use pm_runtime_get_sync()/put() on resume

 drivers/tty/serial/sh-sci.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/2 serial: sh-sci: Use pm_runtime_get_sync()/put() on suspend

From: Hien Dang <[email protected]>

Since commit '39dd0f234fc37d ("PM / Domains: Allow runtime PM during system PM phases")', runtime PM may be in suspended state when the module registers are backed up. It is therefore necessary to ensure the device is on during suspend by using pm_runtime_get_sync()/pm_runtime_put().

[uli: edited description for clarity]
---
 drivers/tty/serial/sh-sci.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/tty/serial/sh-sci.c +4 -1
index fdbbff5..22d7a78 100644
@@ -3246,8 +3246,11 @@ static __maybe_unused int sci_suspend(struct device *dev)
 {
 	struct sci_port *sport = dev_get_drvdata(dev);
 
-	if (sport)
+	if (sport) {
+		pm_runtime_get_sync(sport->port.dev);
 		uart_suspend_port(&sci_uart_driver, &sport->port);
+		pm_runtime_put(sport->port.dev);
+	}
 
 	return 0;
 }
Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/2 serial: sh-sci: Use pm_runtime_get_sync()/put() on resume

In reply to Ulrich Hecht

From: Hien Dang <[email protected]>

Since commit '39dd0f234fc37d ("PM / Domains: Allow runtime PM during system PM phases")', runtime PM may be in suspended state during the system suspend phase. It is therefore necessary to call pm_runtime_get_sync()/ pm_runtime_put() when accessing the hardware.

This modification is the counterpart for the resume case. It ensures stability of the system, should the kernel allow the devices's runtime suspend state to change during the system resume phase as well.

[uli: edited description for clarity]
---
 drivers/tty/serial/sh-sci.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/tty/serial/sh-sci.c +4 -1
index 22d7a78..d5a1acb 100644
@@ -3259,8 +3259,11 @@ static __maybe_unused int sci_resume(struct device *dev)
 {
 	struct sci_port *sport = dev_get_drvdata(dev);
 
-	if (sport)
+	if (sport) {
+		pm_runtime_get_sync(sport->port.dev);
 		uart_resume_port(&sci_uart_driver, &sport->port);
+		pm_runtime_put(sport->port.dev);
+	}
 
 	return 0;
 }
Signature · 1 line
2.7.4
#3 lore raw
In reply to Ulrich Hecht

Hi Ulrich,

Quoted 6 lines · Ulrich Hecht

These patches make sure that the device is up while the suspend/resume code is executed. Up-port from the BSP, tested not to break stuff.

Hien Dang (2):
serial: sh-sci: Use pm_runtime_get_sync()/put() on suspend
serial: sh-sci: Use pm_runtime_get_sync()/put() on resume

I don't think it makes much sense to split this in two parts...

Furthermore, shouldn't this be handled by the serial core, calling uart_change_pm()?

It looks like uart_resume_port() already changes the port's state to enabled, while uart_suspend_port() assumes the port is already enabled, and disables it.

Perhaps handling is not correct for some code paths?

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#4 lore raw
Quoted 10 lines
Quoted 7 lines

These patches make sure that the device is up while the suspend/resume code is executed. Up-port from the BSP, tested not to break stuff.

Hien Dang (2):
serial: sh-sci: Use pm_runtime_get_sync()/put() on suspend
serial: sh-sci: Use pm_runtime_get_sync()/put() on resume

I don't think it makes much sense to split this in two parts...

Quoted 8 lines

Furthermore, shouldn't this be handled by the serial core, calling uart_change_pm()?

It looks like uart_resume_port() already changes the port's state to enabled, while uart_suspend_port() assumes the port is already enabled, and disables it.

Perhaps handling is not correct for some code paths?

Ulrich, do you have an answer to Geert's question?

#5 lore raw
In reply to Geert Uytterhoeven
Quoted 13 lines · Geert Uytterhoeven

Hi Ulrich,

Quoted 6 lines · Ulrich Hecht

These patches make sure that the device is up while the suspend/resume code is executed. Up-port from the BSP, tested not to break stuff.

Hien Dang (2):
serial: sh-sci: Use pm_runtime_get_sync()/put() on suspend
serial: sh-sci: Use pm_runtime_get_sync()/put() on resume

I don't think it makes much sense to split this in two parts...

Quoted 8 lines

Furthermore, shouldn't this be handled by the serial core, calling uart_change_pm()?

It looks like uart_resume_port() already changes the port's state to enabled, while uart_suspend_port() assumes the port is already enabled, and disables it.

Perhaps handling is not correct for some code paths?

Ulrich, what is your take on this?

#6 lore raw
In reply to Geert Uytterhoeven

Sorry for the delay...

Quoted 13 lines · Geert Uytterhoeven
Quoted 6 lines · Ulrich Hecht

These patches make sure that the device is up while the suspend/resume code is executed. Up-port from the BSP, tested not to break stuff.

Hien Dang (2):
serial: sh-sci: Use pm_runtime_get_sync()/put() on suspend
serial: sh-sci: Use pm_runtime_get_sync()/put() on resume

I don't think it makes much sense to split this in two parts...

Quoted 8 lines

Furthermore, shouldn't this be handled by the serial core, calling uart_change_pm()?

It looks like uart_resume_port() already changes the port's state to enabled, while uart_suspend_port() assumes the port is already enabled, and disables it.

Perhaps handling is not correct for some code paths?

The way I understand it, the problem this intends to fix is not the state the device ends up in, but that it needs to be powered while registers are read or written.

It seems to me that that the current "resume" code should work in that respect, because it changes the PM state to "on" in uart_resume_port() before any access to hardware registers takes place, so there is nothing that needs to be fixed.

That may be different for the "suspend" part, though, because it assumes that the PM state is "on", and I think that is what the patch asserts to not be a valid assumption anymore. It's hard to tell if that is true, though, because I cannot reproduce the issue here; it just works either way...

CU
Uli

#7 lore raw

Hey guys,

I stumbled over this one again and want to make sure we have a conclusion here.

Quoted 3 lines

The way I understand it, the problem this intends to fix is not the state the device ends up in, but that it needs to be powered while registers are read or written.

I agree.

Quoted 4 lines

It seems to me that that the current "resume" code should work in that respect, because it changes the PM state to "on" in uart_resume_port() before any access to hardware registers takes place, so there is nothing that needs to be fixed.

Ack.

Quoted 5 lines

That may be different for the "suspend" part, though, because it assumes that the PM state is "on", and I think that is what the patch asserts to not be a valid assumption anymore. It's hard to tell if that is true, though, because I cannot reproduce the issue here; it just works either way...

So, do we agree then that *if* there needs to be a fix for that, it should be in uart_suspend_port() by adding some 'uart_change_pm' shortly before accessing the ops-callbacks? I am not super-fit with the uart layer, but can't we assume because of the "Nothing to do if the console is not suspending"-if-block that (for SCIF at least) it means the port is on because it _is_ the console?

(I wonder, though, if the OMAPs won't need such a fix because they seem to use runtime_autosuspend, so their state might be off actually?)

Regards,

Wolfram