* [PATCH v3 0/3] remoteproc: imx_rproc: allow attaching to running core kicked by the bootloader
@ 2025-05-19 17:15 Hiago De Franco
2025-05-19 17:15 ` [PATCH v3 1/3] firmware: imx: introduce imx_sc_pm_get_resource_power_mode() Hiago De Franco
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Hiago De Franco @ 2025-05-19 17:15 UTC (permalink / raw)
To: Mathieu Poirier, Ulf Hansson, linux-pm, linux-remoteproc
Cc: Shawn Guo, Sascha Hauer, Bjorn Andersson, Hiago De Franco, imx,
linux-arm-kernel, linux-kernel, Peng Fan, daniel.baluta,
iuliana.prodan, Fabio Estevam, Pengutronix Kernel Team
From: Hiago De Franco <hiago.franco@toradex.com>
For the i.MX8X and i.MX8 family SoCs, currently when the remotecore is
started by the bootloader and the M core and A core are in the same
partition, the driver is not capable to detect the remote core and
report the correct state of it.
This series of patches implement an API call to the SCU which will
return the power mode of a given resource (M core in this case) and if
it is already powered on, the driver will attach to it. This SCU API is
being added to the new file drivers/firmware/imx/power.c, where all PM
related APIs should go.
Finally, the imx_rproc_clk_enable() function was also changed to make it
return before dev_clk_get() is called, as it currently generates an SCU
fault reset if the remote core is already running and the kernel tries
to enable the clock again. These changes are a follow up from a v1 sent
to imx_rproc [1] and from a reported regression [2].
[1] https://lore.kernel.org/lkml/20250423155131.101473-1-hiagofranco@gmail.com/
[2] https://lore.kernel.org/lkml/20250404141713.ac2ntcsjsf7epdfa@hiago-nb/
v3:
- New file introduced, drivers/firmware/imx/power.c, to handle the PM
(Power Management) API functions, as suggested in v2.
- First patch, "firmware: imx: move get power mode function from
scu-pd.c to misc.c" was dropped to make the reviewing process easier
and in favor of firmware/imx/power.c file. Moving the power mode
function from scu-pd.c as proposed will be sent later in a different
future patch, as suggested.
v2:
- https://lore.kernel.org/lkml/20250507160056.11876-1-hiagofranco@gmail.com/
v1:
- https://lore.kernel.org/lkml/20250505154849.64889-1-hiagofranco@gmail.com/
Hiago De Franco (3):
firmware: imx: introduce imx_sc_pm_get_resource_power_mode()
remoteproc: imx_rproc: skip clock enable when M-core is managed by the
SCU
remoteproc: imx_rproc: add power mode check for remote core attachment
drivers/firmware/imx/Makefile | 2 +-
drivers/firmware/imx/power.c | 52 +++++++++++++++++++++++++++++
drivers/remoteproc/imx_rproc.c | 17 ++++++++--
include/linux/firmware/imx/svc/pm.h | 9 +++++
4 files changed, 77 insertions(+), 3 deletions(-)
create mode 100644 drivers/firmware/imx/power.c
--
2.39.5
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v3 1/3] firmware: imx: introduce imx_sc_pm_get_resource_power_mode()
2025-05-19 17:15 [PATCH v3 0/3] remoteproc: imx_rproc: allow attaching to running core kicked by the bootloader Hiago De Franco
@ 2025-05-19 17:15 ` Hiago De Franco
2025-05-19 17:15 ` [PATCH v3 2/3] remoteproc: imx_rproc: skip clock enable when M-core is managed by the SCU Hiago De Franco
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Hiago De Franco @ 2025-05-19 17:15 UTC (permalink / raw)
To: Mathieu Poirier, Ulf Hansson, linux-pm, linux-remoteproc
Cc: Shawn Guo, Sascha Hauer, Bjorn Andersson, Hiago De Franco, imx,
linux-arm-kernel, linux-kernel, Peng Fan, daniel.baluta,
iuliana.prodan, Fabio Estevam, Pengutronix Kernel Team, Peng Fan
From: Hiago De Franco <hiago.franco@toradex.com>
This SCU API returns the power mode of a given resource.
As example, remoteproc/imx_rproc.c can now use this function to check
the power mode of the remote core to properly set "attached" or
"offline" modes.
Since there is no proper firmware/imx file to place this function, also
introduce firmware/imx/power.c file to keep all the PM functions inside.
Signed-off-by: Hiago De Franco <hiago.franco@toradex.com>
Suggested-by: Peng Fan <peng.fan@nxp.com>
---
v3: New patch.
---
drivers/firmware/imx/Makefile | 2 +-
drivers/firmware/imx/power.c | 52 +++++++++++++++++++++++++++++
include/linux/firmware/imx/svc/pm.h | 9 +++++
3 files changed, 62 insertions(+), 1 deletion(-)
create mode 100644 drivers/firmware/imx/power.c
diff --git a/drivers/firmware/imx/Makefile b/drivers/firmware/imx/Makefile
index 8d046c341be8..5f5548e34459 100644
--- a/drivers/firmware/imx/Makefile
+++ b/drivers/firmware/imx/Makefile
@@ -1,4 +1,4 @@
# SPDX-License-Identifier: GPL-2.0
obj-$(CONFIG_IMX_DSP) += imx-dsp.o
-obj-$(CONFIG_IMX_SCU) += imx-scu.o misc.o imx-scu-irq.o rm.o imx-scu-soc.o
+obj-$(CONFIG_IMX_SCU) += imx-scu.o misc.o imx-scu-irq.o rm.o imx-scu-soc.o power.o
obj-${CONFIG_IMX_SCMI_MISC_DRV} += sm-misc.o
diff --git a/drivers/firmware/imx/power.c b/drivers/firmware/imx/power.c
new file mode 100644
index 000000000000..b982cebba72a
--- /dev/null
+++ b/drivers/firmware/imx/power.c
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * File containing client-side RPC functions for the PM (Power Management)
+ * service. These function are ported to clients that communicate to the SC.
+ */
+
+#include <linux/firmware/imx/svc/pm.h>
+
+struct imx_sc_msg_req_get_resource_power_mode {
+ struct imx_sc_rpc_msg hdr;
+ union {
+ struct {
+ u16 resource;
+ } req;
+ struct {
+ u8 mode;
+ } resp;
+ } data;
+} __packed __aligned(4);
+
+/**
+ * imx_sc_pm_get_resource_power_mode - Get power mode from a given resource.
+ * @ipc: IPC handle.
+ * @resource: Resource to check the power mode.
+ *
+ * Return: Returns < 0 for errors or the following for success:
+ * * %IMX_SC_PM_PW_MODE_OFF - Power off
+ * * %IMX_SC_PM_PW_MODE_STBY - Power in standby
+ * * %IMX_SC_PM_PW_MODE_LP - Power in low-power
+ * * %IMX_SC_PM_PW_MODE_ON - Power on
+ *
+ */
+int imx_sc_pm_get_resource_power_mode(struct imx_sc_ipc *ipc, u32 resource)
+{
+ struct imx_sc_msg_req_get_resource_power_mode msg;
+ struct imx_sc_rpc_msg *hdr = &msg.hdr;
+ int ret;
+
+ hdr->ver = IMX_SC_RPC_VERSION;
+ hdr->svc = IMX_SC_RPC_SVC_PM;
+ hdr->func = IMX_SC_PM_FUNC_GET_RESOURCE_POWER_MODE;
+ hdr->size = 2;
+
+ msg.data.req.resource = resource;
+
+ ret = imx_scu_call_rpc(ipc, &msg, true);
+ if (ret)
+ return ret;
+
+ return msg.data.resp.mode;
+}
+EXPORT_SYMBOL(imx_sc_pm_get_resource_power_mode);
diff --git a/include/linux/firmware/imx/svc/pm.h b/include/linux/firmware/imx/svc/pm.h
index 1f6975dd37b0..56e93a953295 100644
--- a/include/linux/firmware/imx/svc/pm.h
+++ b/include/linux/firmware/imx/svc/pm.h
@@ -82,4 +82,13 @@ enum imx_sc_pm_func {
#define IMX_SC_PM_PARENT_PLL2 3 /* Parent in PLL2 or PLL0/4 */
#define IMX_SC_PM_PARENT_BYPS 4 /* Parent is a bypass clock. */
+#if IS_ENABLED(CONFIG_IMX_SCU)
+int imx_sc_pm_get_resource_power_mode(struct imx_sc_ipc *ipc, u32 resource);
+#else
+static inline int imx_sc_pm_get_resource_power_mode(struct imx_sc_ipc *ipc,
+ u32 resource)
+{
+ return -EOPNOTSUPP;
+}
+#endif
#endif /* _SC_PM_API_H */
--
2.39.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3 2/3] remoteproc: imx_rproc: skip clock enable when M-core is managed by the SCU
2025-05-19 17:15 [PATCH v3 0/3] remoteproc: imx_rproc: allow attaching to running core kicked by the bootloader Hiago De Franco
2025-05-19 17:15 ` [PATCH v3 1/3] firmware: imx: introduce imx_sc_pm_get_resource_power_mode() Hiago De Franco
@ 2025-05-19 17:15 ` Hiago De Franco
2025-05-19 17:15 ` [PATCH v3 3/3] remoteproc: imx_rproc: add power mode check for remote core attachment Hiago De Franco
2025-05-21 4:22 ` [PATCH v3 0/3] remoteproc: imx_rproc: allow attaching to running core kicked by the bootloader Peng Fan
3 siblings, 0 replies; 5+ messages in thread
From: Hiago De Franco @ 2025-05-19 17:15 UTC (permalink / raw)
To: Mathieu Poirier, Ulf Hansson, linux-pm, linux-remoteproc
Cc: Shawn Guo, Sascha Hauer, Bjorn Andersson, Hiago De Franco, imx,
linux-arm-kernel, linux-kernel, Peng Fan, daniel.baluta,
iuliana.prodan, Fabio Estevam, Pengutronix Kernel Team, Peng Fan
From: Hiago De Franco <hiago.franco@toradex.com>
For the i.MX8X and i.MX8 family SoCs, when the M-core is powered up
by the bootloader, M-core and Linux are in same SCFW (System Controller
Firmware) partition, so linux has permission to control M-core.
But when M-core is started, the SCFW will automatically enable the clock
and configure the rate, and any users that want to enable the clock will
get error 'LOCKED' from SCFW. So current imx_rproc.c probe function
fails because clk_prepare_enable also fails. With that, the M-core power
domain is powered off when it is still running, causing a SCU (System
Controller Unit) fault reset, and the system restarts.
To address the issue, ignore handling the clk for i.MX8X and i.MX8 M-core,
because SCFW will automatically enable and configure the clock.
Signed-off-by: Hiago De Franco <hiago.franco@toradex.com>
Suggested-by: Peng Fan <peng.fan@nxp.com>
---
v3: Unchanged.
v2: Commit description updated, as suggested. Fixed Peng Fan email.
v1: https://lore.kernel.org/lkml/20250505154849.64889-2-hiagofranco@gmail.com/
---
drivers/remoteproc/imx_rproc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 74299af1d7f1..627e57a88db2 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -1029,8 +1029,8 @@ static int imx_rproc_clk_enable(struct imx_rproc *priv)
struct device *dev = priv->dev;
int ret;
- /* Remote core is not under control of Linux */
- if (dcfg->method == IMX_RPROC_NONE)
+ /* Remote core is not under control of Linux or it is managed by SCU API */
+ if (dcfg->method == IMX_RPROC_NONE || dcfg->method == IMX_RPROC_SCU_API)
return 0;
priv->clk = devm_clk_get(dev, NULL);
--
2.39.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3 3/3] remoteproc: imx_rproc: add power mode check for remote core attachment
2025-05-19 17:15 [PATCH v3 0/3] remoteproc: imx_rproc: allow attaching to running core kicked by the bootloader Hiago De Franco
2025-05-19 17:15 ` [PATCH v3 1/3] firmware: imx: introduce imx_sc_pm_get_resource_power_mode() Hiago De Franco
2025-05-19 17:15 ` [PATCH v3 2/3] remoteproc: imx_rproc: skip clock enable when M-core is managed by the SCU Hiago De Franco
@ 2025-05-19 17:15 ` Hiago De Franco
2025-05-21 4:22 ` [PATCH v3 0/3] remoteproc: imx_rproc: allow attaching to running core kicked by the bootloader Peng Fan
3 siblings, 0 replies; 5+ messages in thread
From: Hiago De Franco @ 2025-05-19 17:15 UTC (permalink / raw)
To: Mathieu Poirier, Ulf Hansson, linux-pm, linux-remoteproc
Cc: Shawn Guo, Sascha Hauer, Bjorn Andersson, Hiago De Franco, imx,
linux-arm-kernel, linux-kernel, Peng Fan, daniel.baluta,
iuliana.prodan, Fabio Estevam, Pengutronix Kernel Team, Peng Fan
From: Hiago De Franco <hiago.franco@toradex.com>
When the remote core is started before Linux boots (e.g., by the
bootloader), the driver currently is not able to attach because it only
checks for cores running in different partitions. If the core was kicked
by the bootloader, it is in the same partition as Linux and it is
already up and running.
This adds power mode verification through the SCU interface, enabling
the driver to detect when the remote core is already running and
properly attach to it.
Signed-off-by: Hiago De Franco <hiago.franco@toradex.com>
Suggested-by: Peng Fan <peng.fan@nxp.com>
---
v3: Unchanged.
v2: Dropped unecessary include. Removed the imx_rproc_is_on function, as
suggested.
v1: https://lore.kernel.org/lkml/20250505154849.64889-4-hiagofranco@gmail.com/
---
drivers/remoteproc/imx_rproc.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 627e57a88db2..9b6e9e41b7fc 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -949,6 +949,19 @@ static int imx_rproc_detect_mode(struct imx_rproc *priv)
if (of_property_read_u32(dev->of_node, "fsl,entry-address", &priv->entry))
return -EINVAL;
+ /*
+ * If remote core is already running (e.g. kicked by
+ * the bootloader), attach to it.
+ */
+ ret = imx_sc_pm_get_resource_power_mode(priv->ipc_handle,
+ priv->rsrc_id);
+ if (ret < 0)
+ dev_err(dev, "failed to get power resource %d mode, ret %d\n",
+ priv->rsrc_id, ret);
+
+ if (ret == IMX_SC_PM_PW_MODE_ON)
+ priv->rproc->state = RPROC_DETACHED;
+
return imx_rproc_attach_pd(priv);
}
--
2.39.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3 0/3] remoteproc: imx_rproc: allow attaching to running core kicked by the bootloader
2025-05-19 17:15 [PATCH v3 0/3] remoteproc: imx_rproc: allow attaching to running core kicked by the bootloader Hiago De Franco
` (2 preceding siblings ...)
2025-05-19 17:15 ` [PATCH v3 3/3] remoteproc: imx_rproc: add power mode check for remote core attachment Hiago De Franco
@ 2025-05-21 4:22 ` Peng Fan
3 siblings, 0 replies; 5+ messages in thread
From: Peng Fan @ 2025-05-21 4:22 UTC (permalink / raw)
To: Hiago De Franco
Cc: Mathieu Poirier, Ulf Hansson, linux-pm, linux-remoteproc,
Shawn Guo, Sascha Hauer, Bjorn Andersson, Hiago De Franco, imx,
linux-arm-kernel, linux-kernel, daniel.baluta, iuliana.prodan,
Fabio Estevam, Pengutronix Kernel Team
On Mon, May 19, 2025 at 02:15:11PM -0300, Hiago De Franco wrote:
>From: Hiago De Franco <hiago.franco@toradex.com>
Let's wait for V2 discussion a bit, then I will give a look if we reach
an agreement on using firmware power API here.
Thanks,
Peng
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-05-21 3:16 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-19 17:15 [PATCH v3 0/3] remoteproc: imx_rproc: allow attaching to running core kicked by the bootloader Hiago De Franco
2025-05-19 17:15 ` [PATCH v3 1/3] firmware: imx: introduce imx_sc_pm_get_resource_power_mode() Hiago De Franco
2025-05-19 17:15 ` [PATCH v3 2/3] remoteproc: imx_rproc: skip clock enable when M-core is managed by the SCU Hiago De Franco
2025-05-19 17:15 ` [PATCH v3 3/3] remoteproc: imx_rproc: add power mode check for remote core attachment Hiago De Franco
2025-05-21 4:22 ` [PATCH v3 0/3] remoteproc: imx_rproc: allow attaching to running core kicked by the bootloader Peng Fan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox