2023-08-03 08:28:05

by Dhruva Gole

[permalink] [raw]
Subject: [PATCH V6 0/4] firmware: ti_sci: Introduce system suspend support

Abstract
********

This series introduces necessary ti_sci driver functionality to support
DeepSleep mode (suspend to mem) on TI K3 AM62x. DeepSleep mode is
described in section "6.2.4.4 DeepSleep" of the AM62x Technical Reference
Manual [0].

Summary
*******

This V6 series is a fixup and rebase of the patch series by
Dave Gerlach [1]. It applies on top of next-20230731.

The kernel triggers entry to DeepSleep mode through the mem suspend
transition with the following:

* At the bootloader stage, one is expected to package the TIFS stub
which then gets pulled into the Tightly coupled memory of the Device Mgr
R5 when it starts up. If using U-Boot, then it requires tispl.bin to
contain the TIFS stub. Refer to ti-u-boot patch [3] for further
details. The supported firmware version is from TI Processor SDK
>= 09.00 ie. tag 09.00.00.006 from ti-linux-firmware [4].

* Use a TF-A binary that supports PSCI_SYSTEM_SUSPEND call. This causes
system to use PSCI system suspend as last step of mem sleep.

* The firmware requires that the OS sends a TISCI_MSG_PREPARE_SLEEP
message in order to provide details about suspend, so we must add the
ability to send this message. We also add TISCI_MSG_LPM_WAKE_REASON
and TISCI_MSG_SET_IO_ISOLATION messages as part of a new PM ops. These
messages are part of the TISCI PM Low Power Mode API [2]. (Patch 2)

* A memory address must be provided to the firmware using the above
message, which is allocated and managed by dma_alloc_attrs()
and friends. This memory address can be used by the firmware to
save necessary context at that physical location in the DDR RAM. (Patch 3)

* While entering DeepSleep, it's also good to take precautions inorder to
prevent any external current from directly entering the internal IPs and
potentially damaging them. Hence, we send a ti_sci_cmd_set_io_isolation
which essentially tells the DM R5 Firmware to isolate all the I/O's or pads
from the IPs that they were connected to in active state. This is also
something that is required when for example we want an I/O daisychain wakeup
to wake the system from DeepSleep. More on this in the AM62x Processors TRM [0]
under section "6.2.4.11 I/O Power Management and Daisy Chaining" (Patch 1)

* Finally, the ti_sci driver must actually send TISCI_MSG_PREPARE_SLEEP
message to firmware with the above information included, which it
does during the driver suspend handler when PM_MEM_SUSPEND is the
determined state being entered. (Patch 4)

It currently enables only DeepSleep mode, but even if any additional
modes are needed to be supported in future, they would not require any
changes to the TISCI LPM APIs [2]. The enabling of additional modes
would be done via GenPD changes that is currently in the works.

Testing:
*******

In can be tested with the following branch:
https://github.com/DhruvaG2000/v-linux/commits/lpm-upstream-6.5

Tested on SK-AM62B [6] here:
https://gist.github.com/DhruvaG2000/8410fac048c677c40cd94f5169b5b0b4

Limitations:
************

Currently, DeepSleep is only supported on SK-AM62B with DDR4.
Boards with LPDDR part like Beagle Play and AM62x LP have a known FW issue.

Base commit:
************

commit ec8939156379 (tag: next-20230731) ("Add linux-next specific files for 20230731")

origin:
linux-next https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git

Changelog:
**********

v6:
- Loading of FS Stub from linux no longer needed, hence drop that patch,
- Drop 1/6 and 5/6 from the previous series [4].
- Add system suspend resume callbacks which were removed in
commit 9225bcdedf16297a346082e7d23b0e8434aa98ed ("firmware: ti_sci: Use
system_state to determine polling")
- Use IO isolation while putting the system in suspend to RAM

v5:
- link [5]
- Add support (patch 3) for detecting the low power modes (LPM) of the
FW/SoC with a recently introduced core TISCI_MSG_QUERY_FW_CAPS message.
- Use TISCI_MSG_QUERY_FW_CAPS instead of misusing the TISCI_MSG_PREPARE_SLEEP
to detect the FW/SoC low power caps (patch 4).
- Take into account the supported LPMs in ti_sci_prepare_system_suspend()
and handle the case when CONFIG_SUSPEND is not enabled (patch 6) that
was reported by Roger Quadros and LKP.
- Pick up Rob Herring's "Reviewed-by" tag for the binding patch.

v4:
- Fix checkpacth warnings in patches 2 and 3.
- Drop the links with anchors in patch 2.

v3:
- Fix the compile warnings on 32-bit platforms reported by the kernel
test robot in patches (3,5).
- Pick up Roger's "Tested-by" tags.

v2:
- Addressed comments received for v1 series [1].
- Updated v1 patch 5 to use pm notifier to avoid firmware loading
issues.
- Dropped the reserved region requirement and allocate DMA memory
instead. The reserved region binding patch is also removed.
- Introduce two more TISCI LPM messages that are supported in SysFW.
- Fixes in error handling.

References:
***********

[0] https://www.ti.com/lit/pdf/spruiv7
[1] https://lore.kernel.org/lkml/[email protected]
[2] https://software-dl.ti.com/tisci/esd/latest/2_tisci_msgs/pm/lpm.html
[3] https://git.ti.com/cgit/ti-u-boot/ti-u-boot/commit/?h=ti-u-boot-2023.04&id=91886b68025c7ad121e62d1fc1fa4601eeb736cd
[4] https://git.ti.com/cgit/processor-firmware/ti-linux-firmware/commit/?h=ti-linux-firmware-next&id=905eb58564581d951d148f45828e8c8a142a5938
[5] https://lore.kernel.org/all/[email protected]/
[6] https://www.ti.com/tool/SK-AM62B


Cc: Vibhore <[email protected]>
Cc: Kevin Hilman <[email protected]>
Cc: Vignesh R <[email protected]>
Cc: Tony Lindgren <[email protected]>

Dave Gerlach (2):
firmware: ti_sci: Introduce Power Management Ops
firmware: ti_sci: Allocate memory for Low Power Modes

Dhruva Gole (1):
firmware: ti_sci: Introduce system suspend resume support

Georgi Vlaev (1):
firmware: ti_sci: Add support for querying the firmware caps

drivers/firmware/ti_sci.c | 336 +++++++++++++++++++++++++
drivers/firmware/ti_sci.h | 90 ++++++-
include/linux/soc/ti/ti_sci_protocol.h | 44 ++++
3 files changed, 469 insertions(+), 1 deletion(-)

--
2.34.1



2023-08-03 09:02:44

by Dhruva Gole

[permalink] [raw]
Subject: [PATCH V6 4/4] firmware: ti_sci: Introduce system suspend resume support

Introduce system suspend resume calls that will allow the ti_sci
driver to support deep sleep low power mode when the user space issues a
suspend to mem.

Also, write a ti_sci_prepare_system_suspend call to be used in the driver
suspend handler to allow the system to identify the low power mode being
entered and if necessary, send TISCI_MSG_PREPARE_SLEEP with information
about the mode is being entered and the address for allocated memory for
storing the context during Deep Sleep.

We're using "pm_suspend_target_state" to map the kernel's target suspend
state to SysFW low power mode. Make sure this is available only when
CONFIG_SUSPEND is enabled.

Co-developed-by: Dave Gerlach <[email protected]>
Signed-off-by: Dave Gerlach <[email protected]>
Signed-off-by: Vibhore Vardhan <[email protected]>
Signed-off-by: Georgi Vlaev <[email protected]>
Signed-off-by: Dhruva Gole <[email protected]>
---
drivers/firmware/ti_sci.c | 63 +++++++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+)

diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c
index 0334ade19868..172b726e00a6 100644
--- a/drivers/firmware/ti_sci.c
+++ b/drivers/firmware/ti_sci.c
@@ -22,6 +22,7 @@
#include <linux/slab.h>
#include <linux/soc/ti/ti-msgmgr.h>
#include <linux/soc/ti/ti_sci_protocol.h>
+#include <linux/suspend.h>
#include <linux/reboot.h>

#include "ti_sci.h"
@@ -3521,6 +3522,67 @@ static int tisci_reboot_handler(struct notifier_block *nb, unsigned long mode,
return NOTIFY_BAD;
}

+static int ti_sci_prepare_system_suspend(struct ti_sci_info *info)
+{
+#if IS_ENABLED(CONFIG_SUSPEND)
+ u8 mode;
+
+ /* Map and validate the target Linux suspend state to TISCI LPM. */
+ switch (pm_suspend_target_state) {
+ case PM_SUSPEND_MEM:
+ /* S2MEM is not supported by the firmware. */
+ if (!(info->fw_caps & MSG_FLAG_CAPS_LPM_DEEP_SLEEP))
+ return 0;
+ mode = TISCI_MSG_VALUE_SLEEP_MODE_DEEP_SLEEP;
+ break;
+ default:
+ /*
+ * Do not fail if we don't have action to take for a
+ * specific suspend mode.
+ */
+ return 0;
+ }
+
+ return ti_sci_cmd_prepare_sleep(&info->handle, mode,
+ (u32)(info->ctx_mem_addr & 0xffffffff),
+ (u32)((u64)info->ctx_mem_addr >> 32), 0);
+#else
+ return 0;
+#endif
+}
+
+static int ti_sci_suspend(struct device *dev)
+{
+ struct ti_sci_info *info = dev_get_drvdata(dev);
+ int ret;
+
+ ret = ti_sci_cmd_set_io_isolation(&info->handle, TISCI_MSG_VALUE_IO_ENABLE);
+ if (ret)
+ return ret;
+ dev_dbg(dev, "%s: set I/O isolation: %d\n", __func__, ret);
+
+ ret = ti_sci_prepare_system_suspend(info);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
+static int ti_sci_resume(struct device *dev)
+{
+ struct ti_sci_info *info = dev_get_drvdata(dev);
+ int ret;
+
+ ret = ti_sci_cmd_set_io_isolation(&info->handle, TISCI_MSG_VALUE_IO_DISABLE);
+ if (ret)
+ return ret;
+ dev_dbg(dev, "%s: disable I/O isolation: %d\n", __func__, ret);
+
+ return 0;
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(ti_sci_pm_ops, ti_sci_suspend, ti_sci_resume);
+
static int ti_sci_init_suspend(struct platform_device *pdev,
struct ti_sci_info *info)
{
@@ -3759,6 +3821,7 @@ static struct platform_driver ti_sci_driver = {
.driver = {
.name = "ti-sci",
.of_match_table = of_match_ptr(ti_sci_of_match),
+ .pm = &ti_sci_pm_ops,
},
};
module_platform_driver(ti_sci_driver);
--
2.34.1


2023-08-03 16:26:18

by Andrew Davis

[permalink] [raw]
Subject: Re: [PATCH V6 4/4] firmware: ti_sci: Introduce system suspend resume support

On 8/3/23 1:42 AM, Dhruva Gole wrote:
> Introduce system suspend resume calls that will allow the ti_sci
> driver to support deep sleep low power mode when the user space issues a
> suspend to mem.
>
> Also, write a ti_sci_prepare_system_suspend call to be used in the driver
> suspend handler to allow the system to identify the low power mode being
> entered and if necessary, send TISCI_MSG_PREPARE_SLEEP with information
> about the mode is being entered and the address for allocated memory for
> storing the context during Deep Sleep.
>
> We're using "pm_suspend_target_state" to map the kernel's target suspend
> state to SysFW low power mode. Make sure this is available only when
> CONFIG_SUSPEND is enabled.
>
> Co-developed-by: Dave Gerlach <[email protected]>
> Signed-off-by: Dave Gerlach <[email protected]>
> Signed-off-by: Vibhore Vardhan <[email protected]>
> Signed-off-by: Georgi Vlaev <[email protected]>
> Signed-off-by: Dhruva Gole <[email protected]>
> ---
> drivers/firmware/ti_sci.c | 63 +++++++++++++++++++++++++++++++++++++++
> 1 file changed, 63 insertions(+)
>
> diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c
> index 0334ade19868..172b726e00a6 100644
> --- a/drivers/firmware/ti_sci.c
> +++ b/drivers/firmware/ti_sci.c
> @@ -22,6 +22,7 @@
> #include <linux/slab.h>
> #include <linux/soc/ti/ti-msgmgr.h>
> #include <linux/soc/ti/ti_sci_protocol.h>
> +#include <linux/suspend.h>
> #include <linux/reboot.h>
>
> #include "ti_sci.h"
> @@ -3521,6 +3522,67 @@ static int tisci_reboot_handler(struct notifier_block *nb, unsigned long mode,
> return NOTIFY_BAD;
> }
>
> +static int ti_sci_prepare_system_suspend(struct ti_sci_info *info)
> +{
> +#if IS_ENABLED(CONFIG_SUSPEND)
> + u8 mode;
> +
> + /* Map and validate the target Linux suspend state to TISCI LPM. */
> + switch (pm_suspend_target_state) {
> + case PM_SUSPEND_MEM:
> + /* S2MEM is not supported by the firmware. */
> + if (!(info->fw_caps & MSG_FLAG_CAPS_LPM_DEEP_SLEEP))
> + return 0;
> + mode = TISCI_MSG_VALUE_SLEEP_MODE_DEEP_SLEEP;
> + break;
> + default:
> + /*
> + * Do not fail if we don't have action to take for a
> + * specific suspend mode.
> + */
> + return 0;
> + }
> +
> + return ti_sci_cmd_prepare_sleep(&info->handle, mode,
> + (u32)(info->ctx_mem_addr & 0xffffffff),
> + (u32)((u64)info->ctx_mem_addr >> 32), 0);
> +#else
> + return 0;
> +#endif
> +}
> +
> +static int ti_sci_suspend(struct device *dev)
> +{
> + struct ti_sci_info *info = dev_get_drvdata(dev);
> + int ret;
> +
> + ret = ti_sci_cmd_set_io_isolation(&info->handle, TISCI_MSG_VALUE_IO_ENABLE);

After this the will the IOs be in isolation? Or does the firmware wait
until power down begins later?

Andrew

> + if (ret)
> + return ret;
> + dev_dbg(dev, "%s: set I/O isolation: %d\n", __func__, ret);
> +
> + ret = ti_sci_prepare_system_suspend(info);
> + if (ret)
> + return ret;
> +
> + return 0;
> +}
> +
> +static int ti_sci_resume(struct device *dev)
> +{
> + struct ti_sci_info *info = dev_get_drvdata(dev);
> + int ret;
> +
> + ret = ti_sci_cmd_set_io_isolation(&info->handle, TISCI_MSG_VALUE_IO_DISABLE);
> + if (ret)
> + return ret;
> + dev_dbg(dev, "%s: disable I/O isolation: %d\n", __func__, ret);
> +
> + return 0;
> +}
> +
> +static DEFINE_SIMPLE_DEV_PM_OPS(ti_sci_pm_ops, ti_sci_suspend, ti_sci_resume);
> +
> static int ti_sci_init_suspend(struct platform_device *pdev,
> struct ti_sci_info *info)
> {
> @@ -3759,6 +3821,7 @@ static struct platform_driver ti_sci_driver = {
> .driver = {
> .name = "ti-sci",
> .of_match_table = of_match_ptr(ti_sci_of_match),
> + .pm = &ti_sci_pm_ops,
> },
> };
> module_platform_driver(ti_sci_driver);

2023-08-03 17:06:13

by Dhruva Gole

[permalink] [raw]
Subject: Re: [PATCH V6 4/4] firmware: ti_sci: Introduce system suspend resume support

On Aug 03, 2023 at 11:00:11 -0500, Andrew Davis wrote:
> On 8/3/23 10:55 AM, Dhruva Gole wrote:
> > On Aug 03, 2023 at 10:26:32 -0500, Andrew Davis wrote:
> > > On 8/3/23 1:42 AM, Dhruva Gole wrote:
> > > > Introduce system suspend resume calls that will allow the ti_sci
> > > > driver to support deep sleep low power mode when the user space issues a
> > > > suspend to mem.
> > > >
> > > > Also, write a ti_sci_prepare_system_suspend call to be used in the driver
> > > > suspend handler to allow the system to identify the low power mode being
> > > > entered and if necessary, send TISCI_MSG_PREPARE_SLEEP with information
> > > > about the mode is being entered and the address for allocated memory for
> > > > storing the context during Deep Sleep.
> > > >
> > > > We're using "pm_suspend_target_state" to map the kernel's target suspend
> > > > state to SysFW low power mode. Make sure this is available only when
> > > > CONFIG_SUSPEND is enabled.
> > > >
> > > > Co-developed-by: Dave Gerlach <[email protected]>
> > > > Signed-off-by: Dave Gerlach <[email protected]>
> > > > Signed-off-by: Vibhore Vardhan <[email protected]>
> > > > Signed-off-by: Georgi Vlaev <[email protected]>
> > > > Signed-off-by: Dhruva Gole <[email protected]>
> > > > ---
> > > > drivers/firmware/ti_sci.c | 63 +++++++++++++++++++++++++++++++++++++++
> > > > 1 file changed, 63 insertions(+)
> > > >
> > [..snip..]
> > > > +static int ti_sci_suspend(struct device *dev)
> > > > +{
> > > > + struct ti_sci_info *info = dev_get_drvdata(dev);
> > > > + int ret;
> > > > +
> > > > + ret = ti_sci_cmd_set_io_isolation(&info->handle, TISCI_MSG_VALUE_IO_ENABLE);
> > >
> > > After this the will the IOs be in isolation? Or does the firmware wait
> > > until power down begins later?
> >
> > From what I understand,
> > IOs will be in isolation immediately
> >
>
> That is what I understand too, so then any device that may need to do some
> external communication for its suspend will not function, this must be the
> last driver _suspend() the system calls, how do you enforce that?

I will make use of .suspend_noirq callbacks in that case. Does that
sound better, or is there anything else I may not be aware of?

>
> Andrew
>
> > >
> > > Andrew
> > >
[..snip..]
> >

--
Best regards,
Dhruva Gole <[email protected]>

2023-08-03 17:10:02

by Andrew Davis

[permalink] [raw]
Subject: Re: [PATCH V6 0/4] firmware: ti_sci: Introduce system suspend support

On 8/3/23 1:42 AM, Dhruva Gole wrote:
> Abstract
> ********
>
> This series introduces necessary ti_sci driver functionality to support
> DeepSleep mode (suspend to mem) on TI K3 AM62x. DeepSleep mode is
> described in section "6.2.4.4 DeepSleep" of the AM62x Technical Reference
> Manual [0].
>
> Summary
> *******
>
> This V6 series is a fixup and rebase of the patch series by
> Dave Gerlach [1]. It applies on top of next-20230731.
>
> The kernel triggers entry to DeepSleep mode through the mem suspend
> transition with the following:
>
> * At the bootloader stage, one is expected to package the TIFS stub
> which then gets pulled into the Tightly coupled memory of the Device Mgr
> R5 when it starts up. If using U-Boot, then it requires tispl.bin to
> contain the TIFS stub. Refer to ti-u-boot patch [3] for further
> details. The supported firmware version is from TI Processor SDK
> >= 09.00 ie. tag 09.00.00.006 from ti-linux-firmware [4].
>
> * Use a TF-A binary that supports PSCI_SYSTEM_SUSPEND call. This causes
> system to use PSCI system suspend as last step of mem sleep.

What happens if we do not have this TIFS stub or not using a TF-A that
supports PSCI_SYSTEM_SUSPEND (or mistakenly thinks it does due to firmware
bugs (this is a known issue for AM64, I'm only phrasing it like a hypothetical :)
)), can we safely return if suspend fails here?

Andrew

>
> * The firmware requires that the OS sends a TISCI_MSG_PREPARE_SLEEP
> message in order to provide details about suspend, so we must add the
> ability to send this message. We also add TISCI_MSG_LPM_WAKE_REASON
> and TISCI_MSG_SET_IO_ISOLATION messages as part of a new PM ops. These
> messages are part of the TISCI PM Low Power Mode API [2]. (Patch 2)
>
> * A memory address must be provided to the firmware using the above
> message, which is allocated and managed by dma_alloc_attrs()
> and friends. This memory address can be used by the firmware to
> save necessary context at that physical location in the DDR RAM. (Patch 3)
>
> * While entering DeepSleep, it's also good to take precautions inorder to
> prevent any external current from directly entering the internal IPs and
> potentially damaging them. Hence, we send a ti_sci_cmd_set_io_isolation
> which essentially tells the DM R5 Firmware to isolate all the I/O's or pads
> from the IPs that they were connected to in active state. This is also
> something that is required when for example we want an I/O daisychain wakeup
> to wake the system from DeepSleep. More on this in the AM62x Processors TRM [0]
> under section "6.2.4.11 I/O Power Management and Daisy Chaining" (Patch 1)
>
> * Finally, the ti_sci driver must actually send TISCI_MSG_PREPARE_SLEEP
> message to firmware with the above information included, which it
> does during the driver suspend handler when PM_MEM_SUSPEND is the
> determined state being entered. (Patch 4)
>
> It currently enables only DeepSleep mode, but even if any additional
> modes are needed to be supported in future, they would not require any
> changes to the TISCI LPM APIs [2]. The enabling of additional modes
> would be done via GenPD changes that is currently in the works.
>
> Testing:
> *******
>
> In can be tested with the following branch:
> https://github.com/DhruvaG2000/v-linux/commits/lpm-upstream-6.5
>
> Tested on SK-AM62B [6] here:
> https://gist.github.com/DhruvaG2000/8410fac048c677c40cd94f5169b5b0b4
>
> Limitations:
> ************
>
> Currently, DeepSleep is only supported on SK-AM62B with DDR4.
> Boards with LPDDR part like Beagle Play and AM62x LP have a known FW issue.
>
> Base commit:
> ************
>
> commit ec8939156379 (tag: next-20230731) ("Add linux-next specific files for 20230731")
>
> origin:
> linux-next https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
>
> Changelog:
> **********
>
> v6:
> - Loading of FS Stub from linux no longer needed, hence drop that patch,
> - Drop 1/6 and 5/6 from the previous series [4].
> - Add system suspend resume callbacks which were removed in
> commit 9225bcdedf16297a346082e7d23b0e8434aa98ed ("firmware: ti_sci: Use
> system_state to determine polling")
> - Use IO isolation while putting the system in suspend to RAM
>
> v5:
> - link [5]
> - Add support (patch 3) for detecting the low power modes (LPM) of the
> FW/SoC with a recently introduced core TISCI_MSG_QUERY_FW_CAPS message.
> - Use TISCI_MSG_QUERY_FW_CAPS instead of misusing the TISCI_MSG_PREPARE_SLEEP
> to detect the FW/SoC low power caps (patch 4).
> - Take into account the supported LPMs in ti_sci_prepare_system_suspend()
> and handle the case when CONFIG_SUSPEND is not enabled (patch 6) that
> was reported by Roger Quadros and LKP.
> - Pick up Rob Herring's "Reviewed-by" tag for the binding patch.
>
> v4:
> - Fix checkpacth warnings in patches 2 and 3.
> - Drop the links with anchors in patch 2.
>
> v3:
> - Fix the compile warnings on 32-bit platforms reported by the kernel
> test robot in patches (3,5).
> - Pick up Roger's "Tested-by" tags.
>
> v2:
> - Addressed comments received for v1 series [1].
> - Updated v1 patch 5 to use pm notifier to avoid firmware loading
> issues.
> - Dropped the reserved region requirement and allocate DMA memory
> instead. The reserved region binding patch is also removed.
> - Introduce two more TISCI LPM messages that are supported in SysFW.
> - Fixes in error handling.
>
> References:
> ***********
>
> [0] https://www.ti.com/lit/pdf/spruiv7
> [1] https://lore.kernel.org/lkml/[email protected]
> [2] https://software-dl.ti.com/tisci/esd/latest/2_tisci_msgs/pm/lpm.html
> [3] https://git.ti.com/cgit/ti-u-boot/ti-u-boot/commit/?h=ti-u-boot-2023.04&id=91886b68025c7ad121e62d1fc1fa4601eeb736cd
> [4] https://git.ti.com/cgit/processor-firmware/ti-linux-firmware/commit/?h=ti-linux-firmware-next&id=905eb58564581d951d148f45828e8c8a142a5938
> [5] https://lore.kernel.org/all/[email protected]/
> [6] https://www.ti.com/tool/SK-AM62B
>
>
> Cc: Vibhore <[email protected]>
> Cc: Kevin Hilman <[email protected]>
> Cc: Vignesh R <[email protected]>
> Cc: Tony Lindgren <[email protected]>
>
> Dave Gerlach (2):
> firmware: ti_sci: Introduce Power Management Ops
> firmware: ti_sci: Allocate memory for Low Power Modes
>
> Dhruva Gole (1):
> firmware: ti_sci: Introduce system suspend resume support
>
> Georgi Vlaev (1):
> firmware: ti_sci: Add support for querying the firmware caps
>
> drivers/firmware/ti_sci.c | 336 +++++++++++++++++++++++++
> drivers/firmware/ti_sci.h | 90 ++++++-
> include/linux/soc/ti/ti_sci_protocol.h | 44 ++++
> 3 files changed, 469 insertions(+), 1 deletion(-)
>

2023-08-03 17:34:08

by Dhruva Gole

[permalink] [raw]
Subject: Re: [PATCH V6 4/4] firmware: ti_sci: Introduce system suspend resume support

On Aug 03, 2023 at 10:26:32 -0500, Andrew Davis wrote:
> On 8/3/23 1:42 AM, Dhruva Gole wrote:
> > Introduce system suspend resume calls that will allow the ti_sci
> > driver to support deep sleep low power mode when the user space issues a
> > suspend to mem.
> >
> > Also, write a ti_sci_prepare_system_suspend call to be used in the driver
> > suspend handler to allow the system to identify the low power mode being
> > entered and if necessary, send TISCI_MSG_PREPARE_SLEEP with information
> > about the mode is being entered and the address for allocated memory for
> > storing the context during Deep Sleep.
> >
> > We're using "pm_suspend_target_state" to map the kernel's target suspend
> > state to SysFW low power mode. Make sure this is available only when
> > CONFIG_SUSPEND is enabled.
> >
> > Co-developed-by: Dave Gerlach <[email protected]>
> > Signed-off-by: Dave Gerlach <[email protected]>
> > Signed-off-by: Vibhore Vardhan <[email protected]>
> > Signed-off-by: Georgi Vlaev <[email protected]>
> > Signed-off-by: Dhruva Gole <[email protected]>
> > ---
> > drivers/firmware/ti_sci.c | 63 +++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 63 insertions(+)
> >
[..snip..]
> > +static int ti_sci_suspend(struct device *dev)
> > +{
> > + struct ti_sci_info *info = dev_get_drvdata(dev);
> > + int ret;
> > +
> > + ret = ti_sci_cmd_set_io_isolation(&info->handle, TISCI_MSG_VALUE_IO_ENABLE);
>
> After this the will the IOs be in isolation? Or does the firmware wait
> until power down begins later?

From what I understand,
IOs will be in isolation immediately

>
> Andrew
>
> > + if (ret)
> > + return ret;
> > + dev_dbg(dev, "%s: set I/O isolation: %d\n", __func__, ret);
> > +
> > + ret = ti_sci_prepare_system_suspend(info);
> > + if (ret)
> > + return ret;
> > +
> > + return 0;
> > +}
> > +
> > +static int ti_sci_resume(struct device *dev)
> > +{
> > + struct ti_sci_info *info = dev_get_drvdata(dev);
> > + int ret;
> > +
> > + ret = ti_sci_cmd_set_io_isolation(&info->handle, TISCI_MSG_VALUE_IO_DISABLE);
> > + if (ret)
> > + return ret;
> > + dev_dbg(dev, "%s: disable I/O isolation: %d\n", __func__, ret);
> > +
> > + return 0;
> > +}
> > +
> > +static DEFINE_SIMPLE_DEV_PM_OPS(ti_sci_pm_ops, ti_sci_suspend, ti_sci_resume);
> > +
> > static int ti_sci_init_suspend(struct platform_device *pdev,
> > struct ti_sci_info *info)
> > {
> > @@ -3759,6 +3821,7 @@ static struct platform_driver ti_sci_driver = {
> > .driver = {
> > .name = "ti-sci",
> > .of_match_table = of_match_ptr(ti_sci_of_match),
> > + .pm = &ti_sci_pm_ops,
> > },
> > };
> > module_platform_driver(ti_sci_driver);

--
Best regards,
Dhruva Gole <[email protected]>

2023-08-03 17:39:00

by Andrew Davis

[permalink] [raw]
Subject: Re: [PATCH V6 4/4] firmware: ti_sci: Introduce system suspend resume support

On 8/3/23 10:55 AM, Dhruva Gole wrote:
> On Aug 03, 2023 at 10:26:32 -0500, Andrew Davis wrote:
>> On 8/3/23 1:42 AM, Dhruva Gole wrote:
>>> Introduce system suspend resume calls that will allow the ti_sci
>>> driver to support deep sleep low power mode when the user space issues a
>>> suspend to mem.
>>>
>>> Also, write a ti_sci_prepare_system_suspend call to be used in the driver
>>> suspend handler to allow the system to identify the low power mode being
>>> entered and if necessary, send TISCI_MSG_PREPARE_SLEEP with information
>>> about the mode is being entered and the address for allocated memory for
>>> storing the context during Deep Sleep.
>>>
>>> We're using "pm_suspend_target_state" to map the kernel's target suspend
>>> state to SysFW low power mode. Make sure this is available only when
>>> CONFIG_SUSPEND is enabled.
>>>
>>> Co-developed-by: Dave Gerlach <[email protected]>
>>> Signed-off-by: Dave Gerlach <[email protected]>
>>> Signed-off-by: Vibhore Vardhan <[email protected]>
>>> Signed-off-by: Georgi Vlaev <[email protected]>
>>> Signed-off-by: Dhruva Gole <[email protected]>
>>> ---
>>> drivers/firmware/ti_sci.c | 63 +++++++++++++++++++++++++++++++++++++++
>>> 1 file changed, 63 insertions(+)
>>>
> [..snip..]
>>> +static int ti_sci_suspend(struct device *dev)
>>> +{
>>> + struct ti_sci_info *info = dev_get_drvdata(dev);
>>> + int ret;
>>> +
>>> + ret = ti_sci_cmd_set_io_isolation(&info->handle, TISCI_MSG_VALUE_IO_ENABLE);
>>
>> After this the will the IOs be in isolation? Or does the firmware wait
>> until power down begins later?
>
> From what I understand,
> IOs will be in isolation immediately
>

That is what I understand too, so then any device that may need to do some
external communication for its suspend will not function, this must be the
last driver _suspend() the system calls, how do you enforce that?

Andrew

>>
>> Andrew
>>
>>> + if (ret)
>>> + return ret;
>>> + dev_dbg(dev, "%s: set I/O isolation: %d\n", __func__, ret);
>>> +
>>> + ret = ti_sci_prepare_system_suspend(info);
>>> + if (ret)
>>> + return ret;
>>> +
>>> + return 0;
>>> +}
>>> +
>>> +static int ti_sci_resume(struct device *dev)
>>> +{
>>> + struct ti_sci_info *info = dev_get_drvdata(dev);
>>> + int ret;
>>> +
>>> + ret = ti_sci_cmd_set_io_isolation(&info->handle, TISCI_MSG_VALUE_IO_DISABLE);
>>> + if (ret)
>>> + return ret;
>>> + dev_dbg(dev, "%s: disable I/O isolation: %d\n", __func__, ret);
>>> +
>>> + return 0;
>>> +}
>>> +
>>> +static DEFINE_SIMPLE_DEV_PM_OPS(ti_sci_pm_ops, ti_sci_suspend, ti_sci_resume);
>>> +
>>> static int ti_sci_init_suspend(struct platform_device *pdev,
>>> struct ti_sci_info *info)
>>> {
>>> @@ -3759,6 +3821,7 @@ static struct platform_driver ti_sci_driver = {
>>> .driver = {
>>> .name = "ti-sci",
>>> .of_match_table = of_match_ptr(ti_sci_of_match),
>>> + .pm = &ti_sci_pm_ops,
>>> },
>>> };
>>> module_platform_driver(ti_sci_driver);
>

2023-08-07 22:03:15

by Kevin Hilman

[permalink] [raw]
Subject: Re: [PATCH V6 4/4] firmware: ti_sci: Introduce system suspend resume support

Dhruva Gole <[email protected]> writes:

> On Aug 03, 2023 at 11:00:11 -0500, Andrew Davis wrote:
>> On 8/3/23 10:55 AM, Dhruva Gole wrote:
>> > On Aug 03, 2023 at 10:26:32 -0500, Andrew Davis wrote:
>> > > On 8/3/23 1:42 AM, Dhruva Gole wrote:
>> > > > Introduce system suspend resume calls that will allow the ti_sci
>> > > > driver to support deep sleep low power mode when the user space issues a
>> > > > suspend to mem.
>> > > >
>> > > > Also, write a ti_sci_prepare_system_suspend call to be used in the driver
>> > > > suspend handler to allow the system to identify the low power mode being
>> > > > entered and if necessary, send TISCI_MSG_PREPARE_SLEEP with information
>> > > > about the mode is being entered and the address for allocated memory for
>> > > > storing the context during Deep Sleep.
>> > > >
>> > > > We're using "pm_suspend_target_state" to map the kernel's target suspend
>> > > > state to SysFW low power mode. Make sure this is available only when
>> > > > CONFIG_SUSPEND is enabled.
>> > > >
>> > > > Co-developed-by: Dave Gerlach <[email protected]>
>> > > > Signed-off-by: Dave Gerlach <[email protected]>
>> > > > Signed-off-by: Vibhore Vardhan <[email protected]>
>> > > > Signed-off-by: Georgi Vlaev <[email protected]>
>> > > > Signed-off-by: Dhruva Gole <[email protected]>
>> > > > ---
>> > > > drivers/firmware/ti_sci.c | 63 +++++++++++++++++++++++++++++++++++++++
>> > > > 1 file changed, 63 insertions(+)
>> > > >
>> > [..snip..]
>> > > > +static int ti_sci_suspend(struct device *dev)
>> > > > +{
>> > > > + struct ti_sci_info *info = dev_get_drvdata(dev);
>> > > > + int ret;
>> > > > +
>> > > > + ret = ti_sci_cmd_set_io_isolation(&info->handle, TISCI_MSG_VALUE_IO_ENABLE);
>> > >
>> > > After this the will the IOs be in isolation? Or does the firmware wait
>> > > until power down begins later?
>> >
>> > From what I understand,
>> > IOs will be in isolation immediately
>> >
>>
>> That is what I understand too, so then any device that may need to do some
>> external communication for its suspend will not function, this must be the
>> last driver _suspend() the system calls, how do you enforce that?
>
> I will make use of .suspend_noirq callbacks in that case. Does that
> sound better, or is there anything else I may not be aware of?

Using _noirq just moves the problem. What if other drivers are also
using _noirq callbacks and run after the SCI driver? You still cannot
guarantee ordering.

It seems to me that the IO isolation stuff is a system-wide operation,
and should probably be handled at the platform suspend_ops level
(e.g. suspend_ops->prepare_late()). This would ensure that it runs
*after* all the driver hooks (even driver _noirq hooks.) and right
before the full suspend (or s2idle.)

Now, all that being said, I noticed that in v7, you didn't move this to
_noirq, but instead suggested that this be handled by TF-A. I suppose
that's an option also, but my suggestion above should work also.

Kevin

2023-08-08 20:32:57

by Dhruva Gole

[permalink] [raw]
Subject: Re: [PATCH V6 4/4] firmware: ti_sci: Introduce system suspend resume support

Kevin,

Thanks for the suggestion. I have a rough proposal inline, please can
you take a look? I will test those changes and respin this series
accordingly

On Aug 07, 2023 at 14:57:05 -0700, Kevin Hilman wrote:
> Dhruva Gole <[email protected]> writes:
>
> > On Aug 03, 2023 at 11:00:11 -0500, Andrew Davis wrote:
> >> On 8/3/23 10:55 AM, Dhruva Gole wrote:
> >> > On Aug 03, 2023 at 10:26:32 -0500, Andrew Davis wrote:
> >> > > On 8/3/23 1:42 AM, Dhruva Gole wrote:
> >> > > > Introduce system suspend resume calls that will allow the ti_sci
> >> > > > driver to support deep sleep low power mode when the user space issues a
> >> > > > suspend to mem.
> >> > > >
> >> > > > Also, write a ti_sci_prepare_system_suspend call to be used in the driver
> >> > > > suspend handler to allow the system to identify the low power mode being
> >> > > > entered and if necessary, send TISCI_MSG_PREPARE_SLEEP with information
> >> > > > about the mode is being entered and the address for allocated memory for
> >> > > > storing the context during Deep Sleep.
> >> > > >
> >> > > > We're using "pm_suspend_target_state" to map the kernel's target suspend
> >> > > > state to SysFW low power mode. Make sure this is available only when
> >> > > > CONFIG_SUSPEND is enabled.
> >> > > >
> >> > > > Co-developed-by: Dave Gerlach <[email protected]>
> >> > > > Signed-off-by: Dave Gerlach <[email protected]>
> >> > > > Signed-off-by: Vibhore Vardhan <[email protected]>
> >> > > > Signed-off-by: Georgi Vlaev <[email protected]>
> >> > > > Signed-off-by: Dhruva Gole <[email protected]>
> >> > > > ---
> >> > > > drivers/firmware/ti_sci.c | 63 +++++++++++++++++++++++++++++++++++++++
> >> > > > 1 file changed, 63 insertions(+)
> >> > > >
> >> > [..snip..]
> >> > > > +static int ti_sci_suspend(struct device *dev)
> >> > > > +{
> >> > > > + struct ti_sci_info *info = dev_get_drvdata(dev);
> >> > > > + int ret;
> >> > > > +
> >> > > > + ret = ti_sci_cmd_set_io_isolation(&info->handle, TISCI_MSG_VALUE_IO_ENABLE);
> >> > >
> >> > > After this the will the IOs be in isolation? Or does the firmware wait
> >> > > until power down begins later?
> >> >
> >> > From what I understand,
> >> > IOs will be in isolation immediately
> >> >
> >>
> >> That is what I understand too, so then any device that may need to do some
> >> external communication for its suspend will not function, this must be the
> >> last driver _suspend() the system calls, how do you enforce that?
> >
> > I will make use of .suspend_noirq callbacks in that case. Does that
> > sound better, or is there anything else I may not be aware of?
>
> Using _noirq just moves the problem. What if other drivers are also
> using _noirq callbacks and run after the SCI driver? You still cannot

True, this thought occurred to me as well which is why I was thinking
that moving it to ATF might be a better choice.

> guarantee ordering.
>
> It seems to me that the IO isolation stuff is a system-wide operation,
> and should probably be handled at the platform suspend_ops level
> (e.g. suspend_ops->prepare_late()). This would ensure that it runs

I must have missed this approach! Are you suggesting something like what
was done for am335?

static const struct platform_suspend_ops am33xx_pm_ops

have a similar code for tisci..?

static const struct platform_suspend_ops tisci_pm_ops = {
.prepare_late = tisci_set_io_isolation
};

And then while resuming we may want the pinctrl driver to scan for the
wk_evt bit[0] before the isolation is disabled, so we want the
tisci_resume/ remove isolation to be called later than that.

So I a wondering if the code below makes sense?

static const struct platform_suspend_ops tisci_pm_ops = {
.prepare_late = tisci_suspend // also includes set isolation
.end = tisci_resume // Disables isolation
};

However a minor drawback here maybe that the serial logs on the resume
path may not appear when using a serial console for example. However
they should be able to easily access using dmesg.

> *after* all the driver hooks (even driver _noirq hooks.) and right
> before the full suspend (or s2idle.)
>
> Now, all that being said, I noticed that in v7, you didn't move this to
> _noirq, but instead suggested that this be handled by TF-A. I suppose
> that's an option also, but my suggestion above should work also.

Thanks for the pointer! I do believe it will make more sense to do it
from linux itself unless we have no way to do it in linux.

>
> Kevin


[0] Table 5-517. Description Of The Pad Configuration Register Bits
https://www.ti.com/lit/pdf/spruid7

NOTE: The hardware works in such a way that as soon as the IO isolation
is disabled the wake_evt information is lost so the pinctrl-single
driver won't be able to know what pin woke it up if we disable io
isolation before it has the chance to look at the padconf registers

--
Best regards,
Dhruva Gole <[email protected]>

2023-08-09 01:51:09

by Kevin Hilman

[permalink] [raw]
Subject: Re: [PATCH V6 4/4] firmware: ti_sci: Introduce system suspend resume support

Hi Dhruva,

Dhruva Gole <[email protected]> writes:

> Kevin,
>
> Thanks for the suggestion. I have a rough proposal inline, please can
> you take a look? I will test those changes and respin this series
> accordingly
>
> On Aug 07, 2023 at 14:57:05 -0700, Kevin Hilman wrote:
>> Dhruva Gole <[email protected]> writes:
>>
>> > On Aug 03, 2023 at 11:00:11 -0500, Andrew Davis wrote:
>> >> On 8/3/23 10:55 AM, Dhruva Gole wrote:
>> >> > On Aug 03, 2023 at 10:26:32 -0500, Andrew Davis wrote:
>> >> > > On 8/3/23 1:42 AM, Dhruva Gole wrote:
>> >> > > > Introduce system suspend resume calls that will allow the ti_sci
>> >> > > > driver to support deep sleep low power mode when the user space issues a
>> >> > > > suspend to mem.
>> >> > > >
>> >> > > > Also, write a ti_sci_prepare_system_suspend call to be used in the driver
>> >> > > > suspend handler to allow the system to identify the low power mode being
>> >> > > > entered and if necessary, send TISCI_MSG_PREPARE_SLEEP with information
>> >> > > > about the mode is being entered and the address for allocated memory for
>> >> > > > storing the context during Deep Sleep.
>> >> > > >
>> >> > > > We're using "pm_suspend_target_state" to map the kernel's target suspend
>> >> > > > state to SysFW low power mode. Make sure this is available only when
>> >> > > > CONFIG_SUSPEND is enabled.
>> >> > > >
>> >> > > > Co-developed-by: Dave Gerlach <[email protected]>
>> >> > > > Signed-off-by: Dave Gerlach <[email protected]>
>> >> > > > Signed-off-by: Vibhore Vardhan <[email protected]>
>> >> > > > Signed-off-by: Georgi Vlaev <[email protected]>
>> >> > > > Signed-off-by: Dhruva Gole <[email protected]>
>> >> > > > ---
>> >> > > > drivers/firmware/ti_sci.c | 63 +++++++++++++++++++++++++++++++++++++++
>> >> > > > 1 file changed, 63 insertions(+)
>> >> > > >
>> >> > [..snip..]
>> >> > > > +static int ti_sci_suspend(struct device *dev)
>> >> > > > +{
>> >> > > > + struct ti_sci_info *info = dev_get_drvdata(dev);
>> >> > > > + int ret;
>> >> > > > +
>> >> > > > + ret = ti_sci_cmd_set_io_isolation(&info->handle, TISCI_MSG_VALUE_IO_ENABLE);
>> >> > >
>> >> > > After this the will the IOs be in isolation? Or does the firmware wait
>> >> > > until power down begins later?
>> >> >
>> >> > From what I understand,
>> >> > IOs will be in isolation immediately
>> >> >
>> >>
>> >> That is what I understand too, so then any device that may need to do some
>> >> external communication for its suspend will not function, this must be the
>> >> last driver _suspend() the system calls, how do you enforce that?
>> >
>> > I will make use of .suspend_noirq callbacks in that case. Does that
>> > sound better, or is there anything else I may not be aware of?
>>
>> Using _noirq just moves the problem. What if other drivers are also
>> using _noirq callbacks and run after the SCI driver? You still cannot
>
> True, this thought occurred to me as well which is why I was thinking
> that moving it to ATF might be a better choice.
>
>> guarantee ordering.
>>
>> It seems to me that the IO isolation stuff is a system-wide operation,
>> and should probably be handled at the platform suspend_ops level
>> (e.g. suspend_ops->prepare_late()). This would ensure that it runs
>
> I must have missed this approach! Are you suggesting something like what
> was done for am335?
>
> static const struct platform_suspend_ops am33xx_pm_ops
>
> have a similar code for tisci..?
>
> static const struct platform_suspend_ops tisci_pm_ops = {
> .prepare_late = tisci_set_io_isolation
> };

Yes, with the minor nit that I would make a tisci_prepare_late()
function, which then calls _set_io_isolation(), since there may be some
other things we want to do in the "late" prepare for other LPM modes.

Also, for the additional LPM modes (more than DeepSleep), we're looking
at using suspend-to-idle (s2idle) to manage those. So in addition to
platform_suspend_ops->prepare_late(), you should add this function to
s2idle_ops->prepare_late() also.

> And then while resuming we may want the pinctrl driver to scan for the
> wk_evt bit[0] before the isolation is disabled, so we want the
> tisci_resume/ remove isolation to be called later than that.
>
> So I a wondering if the code below makes sense?
>
> static const struct platform_suspend_ops tisci_pm_ops = {
> .prepare_late = tisci_suspend // also includes set isolation
> .end = tisci_resume // Disables isolation
> };
>
> However a minor drawback here maybe that the serial logs on the resume
> path may not appear when using a serial console for example. However
> they should be able to easily access using dmesg.

I'm not sure I fully understand this usecase, but using ->end() seems
drastic. If IO isolation is disabled that long, won't that cause
problems for driver's ->resume callbacks that want to touch hardware?

To me, it sounds like you might want to use ->resume_early() or maybe
->resume_noirq() in the pinctrl driver for this so that IO isolation can
be disabled sooner?

>> *after* all the driver hooks (even driver _noirq hooks.) and right
>> before the full suspend (or s2idle.)
>>
>> Now, all that being said, I noticed that in v7, you didn't move this to
>> _noirq, but instead suggested that this be handled by TF-A. I suppose
>> that's an option also, but my suggestion above should work also.
>
> Thanks for the pointer! I do believe it will make more sense to do it
> from linux itself unless we have no way to do it in linux.
>
>>
>> Kevin
>
>
> [0] Table 5-517. Description Of The Pad Configuration Register Bits
> https://www.ti.com/lit/pdf/spruid7
>
> NOTE: The hardware works in such a way that as soon as the IO isolation
> is disabled the wake_evt information is lost so the pinctrl-single
> driver won't be able to know what pin woke it up if we disable io
> isolation before it has the chance to look at the padconf registers

Ah, OK. So yeah, as I hinted at above, what about using
->resume_noirq() in the pinctrl driver to get the wake_evt information,
and then use the s2idle_ops->restore_early() to disable IO isolation,
since this happens after all the driver's noirq hooks have run.

Kevin


2023-08-09 08:02:02

by Tony Lindgren

[permalink] [raw]
Subject: Re: [PATCH V6 4/4] firmware: ti_sci: Introduce system suspend resume support

* Kevin Hilman <[email protected]> [230809 00:20]:
> To me, it sounds like you might want to use ->resume_early() or maybe
> ->resume_noirq() in the pinctrl driver for this so that IO isolation can
> be disabled sooner?

For calls that need to happen just before the SoC is disabled or first
thing on resume path, cpu_cluster_pm_enter() and cpu_cluster_pm_exit()
notifiers work nice and allow distributing the code across the related
SoC specific code and device drivers. See for example the usage in
drivers/irqchip/irq-gic.c for CPU_CLUSTER_PM_ENTER.

Regards,

Tony

2023-08-09 18:15:28

by Kevin Hilman

[permalink] [raw]
Subject: Re: [PATCH V6 4/4] firmware: ti_sci: Introduce system suspend resume support

Tony Lindgren <[email protected]> writes:

> * Kevin Hilman <[email protected]> [230809 00:20]:
>> To me, it sounds like you might want to use ->resume_early() or maybe
>> ->resume_noirq() in the pinctrl driver for this so that IO isolation can
>> be disabled sooner?
>
> For calls that need to happen just before the SoC is disabled or first
> thing on resume path, cpu_cluster_pm_enter() and cpu_cluster_pm_exit()
> notifiers work nice and allow distributing the code across the related
> SoC specific code and device drivers. See for example the usage in
> drivers/irqchip/irq-gic.c for CPU_CLUSTER_PM_ENTER.

Indeed, this is an option too, but for things that already have "full"
drivers (e.g. not an irqchip), they already have a full range of PM
callbacks, and adding another set of callbacks/notifiers for cpu_pm_* is
a bit clunky IMO.

That being said, for things like this IO isolation stuff that is
system-wide, and needs to happen very late in suspend (and/or very early
in suspend), cpu_pm_ is worth considering if the same cannot be done
with the normal PM callbacks.

Kevin