Skip to contentSkip to conversation

remoteproc: imx_rproc: allow attaching to running core kicked by the bootloader

PATCH Superseded Hiago De Franco 5 participants 13 messages Jun 17, 2025 – Jun 24, 2025

Subsystems (4)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v5 cover remoteproc: imx_rproc: allow attaching to running core kicked by the bootloader

From: Hiago De Franco <[email protected]>

This patch series depends on Ulf's patches that are currently under review, "pmdomain: Add generic ->sync_state() support to genpd" [1]. Without them, this series is not going to work.

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 patch series implement a new function, dev_pm_genpd_is_on(), which returns the power status of a given power domain (M core power domains IMX_SC_R_M4_0_PID0 and IMX_SC_R_M4_0_MU_1A in this case). If it is already powered on, the driver will attach to it.

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 [2] and from a reported regression [3].

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://lore.kernel.org/lkml/20250404141713.ac2ntcsjsf7epdfa@hiago-nb/

v5:
- pm_runtime_get_sync() removed in favor of pm_runtime_resume_and_get(), checking the return value of it.
- Added pm_runtime_disable() and pm_runtime_put() to imx_rproc_remove().
- Fixed missing "()" in dev_pm_genpd_is_on description.
- Updated dev_pm_genpd_is_on() function description to be explicit the function reflects the current power status of the device and that this might change after the function returns, especially if the genpd is shared.

v4:
- https://lore.kernel.org/lkml/[email protected]/

v3:
- https://lore.kernel.org/all/[email protected]/

v2:
- https://lore.kernel.org/lkml/[email protected]/

v1:
- https://lore.kernel.org/lkml/[email protected]/

Hiago De Franco (3):
pmdomain: core: introduce dev_pm_genpd_is_on()
remoteproc: imx_rproc: skip clock enable when M-core is managed by the
SCU
remoteproc: imx_rproc: detect and attach to pre-booted remote cores

 drivers/pmdomain/core.c        | 33 +++++++++++++++++++++++++++
 drivers/remoteproc/imx_rproc.c | 41 ++++++++++++++++++++++++++++------
 include/linux/pm_domain.h      |  6 +++++
 3 files changed, 73 insertions(+), 7 deletions(-)
Signature · 1 line
2.39.5
#1 lore raw

PATCH v5 1/3 pmdomain: core: introduce dev_pm_genpd_is_on()

From: Hiago De Franco <[email protected]>

This helper function returns the current power status of a given generic power domain.

As example, remoteproc/imx_rproc.c can now use this function to check the power status of the remote core to properly set "attached" or "offline" modes.

---
v4 -> v5:
- s/dev_pm_genpd_is_on/dev_pm_genpd_is_on()/ in function description.
- Updated function description to be explicit the function reflects the current power status and that this might change after the function returns, especially if the genpd is shared.

v3 -> v4:
- New patch.

---
 drivers/pmdomain/core.c   | 33 +++++++++++++++++++++++++++++++++
 include/linux/pm_domain.h |  6 ++++++
 2 files changed, 39 insertions(+)
drivers/pmdomain/core.c +33 -0
index ff5c7f2b69ce..2f387e15cb75 100644
@@ -758,6 +758,39 @@ int dev_pm_genpd_rpm_always_on(struct device *dev, bool on)
 }
 EXPORT_SYMBOL_GPL(dev_pm_genpd_rpm_always_on);
 
+/**
+ * dev_pm_genpd_is_on() - Get device's current power domain status
+ *
+ * @dev: Device to get the current power status
+ *
+ * This function checks whether the generic power domain associated with the
+ * given device is on or not by verifying if genpd_status_on equals
+ * GENPD_STATE_ON.
+ *
+ * Note: this function returns the power status of the genpd at the time of the
+ * call. The power status may change after due to activity from other devices
+ * sharing the same genpd. Therefore, this information should not be relied for
+ * long-term decisions about the device power state.
+ *
+ * Return: 'true' if the device's power domain is on, 'false' otherwise.
+ */
+bool dev_pm_genpd_is_on(struct device *dev)
+{
+	struct generic_pm_domain *genpd;
+	bool is_on;
+
+	genpd = dev_to_genpd_safe(dev);
+	if (!genpd)
+		return false;
+
+	genpd_lock(genpd);
+	is_on = genpd_status_on(genpd);
+	genpd_unlock(genpd);
+
+	return is_on;
+}
+EXPORT_SYMBOL_GPL(dev_pm_genpd_is_on);
+
 /**
  * pm_genpd_inc_rejected() - Adjust the rejected/usage counts for an idle-state.
  *
include/linux/pm_domain.h +6 -0
index 0b18160901a2..c12580b6579b 100644
@@ -301,6 +301,7 @@ void dev_pm_genpd_synced_poweroff(struct device *dev);
 int dev_pm_genpd_set_hwmode(struct device *dev, bool enable);
 bool dev_pm_genpd_get_hwmode(struct device *dev);
 int dev_pm_genpd_rpm_always_on(struct device *dev, bool on);
+bool dev_pm_genpd_is_on(struct device *dev);
 
 extern struct dev_power_governor simple_qos_governor;
 extern struct dev_power_governor pm_domain_always_on_gov;
@@ -393,6 +394,11 @@ static inline int dev_pm_genpd_rpm_always_on(struct device *dev, bool on)
 	return -EOPNOTSUPP;
 }
 
+static inline bool dev_pm_genpd_is_on(struct device *dev)
+{
+	return false;
+}
+
 #define simple_qos_governor		(*(struct dev_power_governor *)(NULL))
 #define pm_domain_always_on_gov		(*(struct dev_power_governor *)(NULL))
 #endif
Signature · 1 line
2.39.5
maintainer Reviewed-by on v5 1/3
#2 lore raw

Re: [PATCH v5 1/3] pmdomain: core: introduce dev_pm_genpd_is_on()

Quoted 11 lines · Hiago De Franco

From: Hiago De Franco <[email protected]>

This helper function returns the current power status of a given generic power domain.

As example, remoteproc/imx_rproc.c can now use this function to check the power status of the remote core to properly set "attached" or "offline" modes.

Regards,
Bjorn

Quoted 85 lines

---
v4 -> v5:
- s/dev_pm_genpd_is_on/dev_pm_genpd_is_on()/ in function description.
- Updated function description to be explicit the function reflects the current power status and that this might change after the function returns, especially if the genpd is shared.

v3 -> v4:
- New patch.

---
 drivers/pmdomain/core.c   | 33 +++++++++++++++++++++++++++++++++
 include/linux/pm_domain.h |  6 ++++++
 2 files changed, 39 insertions(+)
drivers/pmdomain/core.c +33 -0
index ff5c7f2b69ce..2f387e15cb75 100644
@@ -758,6 +758,39 @@ int dev_pm_genpd_rpm_always_on(struct device *dev, bool on)
 }
 EXPORT_SYMBOL_GPL(dev_pm_genpd_rpm_always_on);
 
+/**
+ * dev_pm_genpd_is_on() - Get device's current power domain status
+ *
+ * @dev: Device to get the current power status
+ *
+ * This function checks whether the generic power domain associated with the
+ * given device is on or not by verifying if genpd_status_on equals
+ * GENPD_STATE_ON.
+ *
+ * Note: this function returns the power status of the genpd at the time of the
+ * call. The power status may change after due to activity from other devices
+ * sharing the same genpd. Therefore, this information should not be relied for
+ * long-term decisions about the device power state.
+ *
+ * Return: 'true' if the device's power domain is on, 'false' otherwise.
+ */
+bool dev_pm_genpd_is_on(struct device *dev)
+{
+	struct generic_pm_domain *genpd;
+	bool is_on;
+
+	genpd = dev_to_genpd_safe(dev);
+	if (!genpd)
+		return false;
+
+	genpd_lock(genpd);
+	is_on = genpd_status_on(genpd);
+	genpd_unlock(genpd);
+
+	return is_on;
+}
+EXPORT_SYMBOL_GPL(dev_pm_genpd_is_on);
+
 /**
  * pm_genpd_inc_rejected() - Adjust the rejected/usage counts for an idle-state.
  *
include/linux/pm_domain.h +6 -0
index 0b18160901a2..c12580b6579b 100644
@@ -301,6 +301,7 @@ void dev_pm_genpd_synced_poweroff(struct device *dev);
 int dev_pm_genpd_set_hwmode(struct device *dev, bool enable);
 bool dev_pm_genpd_get_hwmode(struct device *dev);
 int dev_pm_genpd_rpm_always_on(struct device *dev, bool on);
+bool dev_pm_genpd_is_on(struct device *dev);
 
 extern struct dev_power_governor simple_qos_governor;
 extern struct dev_power_governor pm_domain_always_on_gov;
@@ -393,6 +394,11 @@ static inline int dev_pm_genpd_rpm_always_on(struct device *dev, bool on)
 	return -EOPNOTSUPP;
 }
 
+static inline bool dev_pm_genpd_is_on(struct device *dev)
+{
+	return false;
+}
+
 #define simple_qos_governor		(*(struct dev_power_governor *)(NULL))
 #define pm_domain_always_on_gov		(*(struct dev_power_governor *)(NULL))
 #endif
Signature · 1 line
2.39.5
#3 lore raw

PATCH v5 2/3 remoteproc: imx_rproc: skip clock enable when M-core is managed by the SCU

In reply to Hiago De Franco

From: Hiago De Franco <[email protected]>

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.

---
v4 -> v5:
- Unchanged.
v3 -> v4:
- Unchanged.
v2 -> v3:
- Unchanged.
v1 -> v2:
- Commit description updated, as suggested. Fixed Peng Fan email.

---
 drivers/remoteproc/imx_rproc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/remoteproc/imx_rproc.c +2 -2
index 74299af1d7f1..627e57a88db2 100644
@@ -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);
Signature · 1 line
2.39.5
maintainer
#4 lore raw

Re: [PATCH v5 2/3] remoteproc: imx_rproc: skip clock enable when M-core is managed by the SCU

Hi Hiago,

Quoted 5 lines · Hiago De Franco

From: Hiago De Franco <[email protected]>

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.

Ok

Quoted 2 lines

But when M-core is started, the SCFW will automatically enable the clock

I find the "But when M-core is started" part confusing. Started by who? And are you making a distinction between "powered up" and "started"? It is not possible for someone that doesn't have HW documentation to understand what is going on.

Quoted 43 lines

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.

---
v4 -> v5:
- Unchanged.
v3 -> v4:
- Unchanged.
v2 -> v3:
- Unchanged.
v1 -> v2:
- Commit description updated, as suggested. Fixed Peng Fan email.

---
 drivers/remoteproc/imx_rproc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/remoteproc/imx_rproc.c +2 -2
index 74299af1d7f1..627e57a88db2 100644
@@ -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);
Signature · 1 line
2.39.5
#5 lore raw

Re: [PATCH v5 2/3] remoteproc: imx_rproc: skip clock enable when M-core is managed by the SCU

Hi Mathieu,

Quoted 12 lines · Mathieu Poirier

Hi Hiago,

Quoted 5 lines · Hiago De Franco

From: Hiago De Franco <[email protected]>

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.

Ok

Quoted 1 line
Quoted 6 lines
Quoted 1 line

But when M-core is started, the SCFW will automatically enable the clock

I find the "But when M-core is started" part confusing. Started by who? And are you making a distinction between "powered up" and "started"? It is not possible for someone that doesn't have HW documentation to understand what is going on.

Ok, understood, I will improve this in the next revision. Just to make clear, I am talking about Cortex-A bootloader starting Cortex-M (U-Boot bootaux command in this case). This means powered up, started and running.

Quoted 44 lines
Quoted 44 lines

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.

---
v4 -> v5:
- Unchanged.
v3 -> v4:
- Unchanged.
v2 -> v3:
- Unchanged.
v1 -> v2:
- Commit description updated, as suggested. Fixed Peng Fan email.

---
 drivers/remoteproc/imx_rproc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/remoteproc/imx_rproc.c +2 -2
index 74299af1d7f1..627e57a88db2 100644
@@ -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);
Signature · 1 line
2.39.5
#6 lore raw

PATCH v5 3/3 remoteproc: imx_rproc: detect and attach to pre-booted remote cores

In reply to Hiago De Franco

From: Hiago De Franco <[email protected]>

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 dev_pm_genpd_is_on(), enabling the driver to detect when the remote core is already running and properly attach to it if all the power domain devices are on.

To accomplish this, we need to avoid passing any attach_data or flags to dev_pm_domain_attach_list(), letting the platform device become a consumer of the power domain provider. With that the current power state of the genpds will not change, allowing the detection of the remote core power state.

We enable and sync the device runtime PM during probe to make sure the power domains are correctly managed when the core is controlled by the kernel.

---
v4 -> v5:
- pm_runtime_get_sync() removed in favor of pm_runtime_resume_and_get(). Now it also checks the return value of this function.
- Added pm_runtime_disable() and pm_runtime_put() to imx_rproc_remove() function.
v3 -> v4:
- Changed to use the new dev_pm_genpd_is_on() function instead, as suggested by Ulf. This will now get the power status of the two remote cores power domains to decided if imx_rpoc needs to attach or not. In order to do that, pm_runtime_enable() and pm_runtime_get_sync() were introduced and pd_data was removed.
v2 -> v3:
- Unchanged.
v1 -> v2:
- Dropped unecessary include. Removed the imx_rproc_is_on function, as suggested.

---
 drivers/remoteproc/imx_rproc.c | 37 +++++++++++++++++++++++++++++-----
 1 file changed, 32 insertions(+), 5 deletions(-)
drivers/remoteproc/imx_rproc.c +32 -5
index 627e57a88db2..b53083f2553e 100644
@@ -18,6 +18,7 @@
 #include <linux/of_reserved_mem.h>
 #include <linux/platform_device.h>
 #include <linux/pm_domain.h>
+#include <linux/pm_runtime.h>
 #include <linux/reboot.h>
 #include <linux/regmap.h>
 #include <linux/remoteproc.h>
@@ -890,10 +891,8 @@ static int imx_rproc_partition_notify(struct notifier_block *nb,
 static int imx_rproc_attach_pd(struct imx_rproc *priv)
 {
 	struct device *dev = priv->dev;
-	int ret;
-	struct dev_pm_domain_attach_data pd_data = {
-		.pd_flags = PD_FLAG_DEV_LINK_ON,
-	};
+	int ret, i;
+	bool detached = true;
 
 	/*
 	 * If there is only one power-domain entry, the platform driver framework
@@ -902,7 +901,22 @@ static int imx_rproc_attach_pd(struct imx_rproc *priv)
 	if (dev->pm_domain)
 		return 0;
 
-	ret = dev_pm_domain_attach_list(dev, &pd_data, &priv->pd_list);
+	ret = dev_pm_domain_attach_list(dev, NULL, &priv->pd_list);
+	/*
+	 * If all the power domain devices are already turned on, the remote
+	 * core is already up when the kernel booted (e.g. kicked by the
+	 * bootloader). In this case attach to it.
+	 */
+	for (i = 0; i < ret; i++) {
+		if (!dev_pm_genpd_is_on(priv->pd_list->pd_devs[i])) {
+			detached = false;
+			break;
+		}
+	}
+
+	if (detached)
+		priv->rproc->state = RPROC_DETACHED;
+
 	return ret < 0 ? ret : 0;
 }
 
@@ -1146,6 +1160,15 @@ static int imx_rproc_probe(struct platform_device *pdev)
 		}
 	}
 
+	if (dcfg->method == IMX_RPROC_SCU_API) {
+		pm_runtime_enable(dev);
+		ret = pm_runtime_resume_and_get(dev);
+		if (ret) {
+			dev_err(dev, "pm_runtime get failed: %d\n", ret);
+			goto err_put_clk;
+		}
+	}
+
 	ret = rproc_add(rproc);
 	if (ret) {
 		dev_err(dev, "rproc_add failed\n");
@@ -1171,6 +1194,10 @@ static void imx_rproc_remove(struct platform_device *pdev)
 	struct rproc *rproc = platform_get_drvdata(pdev);
 	struct imx_rproc *priv = rproc->priv;
 
+	if (priv->dcfg->method == IMX_RPROC_SCU_API) {
+		pm_runtime_disable(priv->dev);
+		pm_runtime_put(priv->dev);
+	}
 	clk_disable_unprepare(priv->clk);
 	rproc_del(rproc);
 	imx_rproc_put_scu(rproc);
Signature · 1 line
2.39.5
Reviewed-by on v5 3/3
#7 lore raw

Re: [PATCH v5 3/3] remoteproc: imx_rproc: detect and attach to pre-booted remote cores

Quoted 19 lines · Hiago De Franco

From: Hiago De Franco <[email protected]>

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 dev_pm_genpd_is_on(), enabling the driver to detect when the remote core is already running and properly attach to it if all the power domain devices are on.

To accomplish this, we need to avoid passing any attach_data or flags to dev_pm_domain_attach_list(), letting the platform device become a consumer of the power domain provider. With that the current power state of the genpds will not change, allowing the detection of the remote core power state.

Quoted 6 lines

We enable and sync the device runtime PM during probe to make sure the power domains are correctly managed when the core is controlled by the kernel.

Kind regards
Uffe

Quoted 101 lines

---
v4 -> v5:
- pm_runtime_get_sync() removed in favor of pm_runtime_resume_and_get(). Now it also checks the return value of this function.
- Added pm_runtime_disable() and pm_runtime_put() to imx_rproc_remove() function.
v3 -> v4:
- Changed to use the new dev_pm_genpd_is_on() function instead, as suggested by Ulf. This will now get the power status of the two remote cores power domains to decided if imx_rpoc needs to attach or not. In order to do that, pm_runtime_enable() and pm_runtime_get_sync() were introduced and pd_data was removed.
v2 -> v3:
- Unchanged.
v1 -> v2:
- Dropped unecessary include. Removed the imx_rproc_is_on function, as suggested.

---
 drivers/remoteproc/imx_rproc.c | 37 +++++++++++++++++++++++++++++-----
 1 file changed, 32 insertions(+), 5 deletions(-)
drivers/remoteproc/imx_rproc.c +32 -6
index 627e57a88db2..b53083f2553e 100644
@@ -18,6 +18,7 @@
 #include <linux/of_reserved_mem.h>
 #include <linux/platform_device.h>
 #include <linux/pm_domain.h>
+#include <linux/pm_runtime.h>
 #include <linux/reboot.h>
 #include <linux/regmap.h>
 #include <linux/remoteproc.h>
@@ -890,10 +891,8 @@ static int imx_rproc_partition_notify(struct notifier_block *nb,
 static int imx_rproc_attach_pd(struct imx_rproc *priv)
 {
        struct device *dev = priv->dev;
-       int ret;
-       struct dev_pm_domain_attach_data pd_data = {
-               .pd_flags = PD_FLAG_DEV_LINK_ON,
-       };
+       int ret, i;
+       bool detached = true;
 
        /*
         * If there is only one power-domain entry, the platform driver framework
@@ -902,7 +901,22 @@ static int imx_rproc_attach_pd(struct imx_rproc *priv)
        if (dev->pm_domain)
                return 0;
 
-       ret = dev_pm_domain_attach_list(dev, &pd_data, &priv->pd_list);
+       ret = dev_pm_domain_attach_list(dev, NULL, &priv->pd_list);
+       /*
+        * If all the power domain devices are already turned on, the remote
+        * core is already up when the kernel booted (e.g. kicked by the
+        * bootloader). In this case attach to it.
+        */
+       for (i = 0; i < ret; i++) {
+               if (!dev_pm_genpd_is_on(priv->pd_list->pd_devs[i])) {
+                       detached = false;
+                       break;
+               }
+       }
+
+       if (detached)
+               priv->rproc->state = RPROC_DETACHED;
+
        return ret < 0 ? ret : 0;
 }
 
@@ -1146,6 +1160,15 @@ static int imx_rproc_probe(struct platform_device *pdev)
                }
        }
 
+       if (dcfg->method == IMX_RPROC_SCU_API) {
+               pm_runtime_enable(dev);
+               ret = pm_runtime_resume_and_get(dev);
+               if (ret) {
+                       dev_err(dev, "pm_runtime get failed: %d\n", ret);
+                       goto err_put_clk;
+               }
+       }
+
        ret = rproc_add(rproc);
        if (ret) {
                dev_err(dev, "rproc_add failed\n");
@@ -1171,6 +1194,10 @@ static void imx_rproc_remove(struct platform_device *pdev)
        struct rproc *rproc = platform_get_drvdata(pdev);
        struct imx_rproc *priv = rproc->priv;
 
+       if (priv->dcfg->method == IMX_RPROC_SCU_API) {
+               pm_runtime_disable(priv->dev);
+               pm_runtime_put(priv->dev);
+       }
        clk_disable_unprepare(priv->clk);
        rproc_del(rproc);
        imx_rproc_put_scu(rproc);
--

2.39.5

maintainer
#8 lore raw

Re: [PATCH v5 3/3] remoteproc: imx_rproc: detect and attach to pre-booted remote cores

In reply to Hiago De Franco
Quoted 5 lines · Hiago De Franco

From: Hiago De Franco <[email protected]>

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

Again, we have a nomenclature issue here with "If the core was kicked by the bootloader". What does "kicked" mean here? Is it just powered and held in reset or is it executing. And are you referring to the A core or the M core?

Quoted 67 lines

by the bootloader, it is in the same partition as Linux and it is already up and running.

This adds power mode verification through dev_pm_genpd_is_on(), enabling the driver to detect when the remote core is already running and properly attach to it if all the power domain devices are on.

To accomplish this, we need to avoid passing any attach_data or flags to dev_pm_domain_attach_list(), letting the platform device become a consumer of the power domain provider. With that the current power state of the genpds will not change, allowing the detection of the remote core power state.

We enable and sync the device runtime PM during probe to make sure the power domains are correctly managed when the core is controlled by the kernel.

---
v4 -> v5:
- pm_runtime_get_sync() removed in favor of pm_runtime_resume_and_get(). Now it also checks the return value of this function.
- Added pm_runtime_disable() and pm_runtime_put() to imx_rproc_remove() function.
v3 -> v4:
- Changed to use the new dev_pm_genpd_is_on() function instead, as suggested by Ulf. This will now get the power status of the two remote cores power domains to decided if imx_rpoc needs to attach or not. In order to do that, pm_runtime_enable() and pm_runtime_get_sync() were introduced and pd_data was removed.
v2 -> v3:
- Unchanged.
v1 -> v2:
- Dropped unecessary include. Removed the imx_rproc_is_on function, as suggested.

---
 drivers/remoteproc/imx_rproc.c | 37 +++++++++++++++++++++++++++++-----
 1 file changed, 32 insertions(+), 5 deletions(-)
drivers/remoteproc/imx_rproc.c +3 -4
index 627e57a88db2..b53083f2553e 100644
@@ -18,6 +18,7 @@
 #include <linux/of_reserved_mem.h>
 #include <linux/platform_device.h>
 #include <linux/pm_domain.h>
+#include <linux/pm_runtime.h>
 #include <linux/reboot.h>
 #include <linux/regmap.h>
 #include <linux/remoteproc.h>
@@ -890,10 +891,8 @@ static int imx_rproc_partition_notify(struct notifier_block *nb,
 static int imx_rproc_attach_pd(struct imx_rproc *priv)
 {
 	struct device *dev = priv->dev;
-	int ret;
-	struct dev_pm_domain_attach_data pd_data = {
-		.pd_flags = PD_FLAG_DEV_LINK_ON,
-	};
+	int ret, i;
+	bool detached = true;
 
 	/*
 	 * If there is only one power-domain entry, the platform driver framework

drivers/remoteproc/imx_rproc.c static int imx_rproc_attach_pd(struct imx_rproc *priv) · line 908

Quoted 9 lines
drivers/remoteproc/imx_rproc.c +5 -1
@@ -902,7 +901,22 @@ static int imx_rproc_attach_pd(struct imx_rproc *priv)
 	if (dev->pm_domain)
 		return 0;
 
-	ret = dev_pm_domain_attach_list(dev, &pd_data, &priv->pd_list);
+	ret = dev_pm_domain_attach_list(dev, NULL, &priv->pd_list);
+	/*
+	 * If all the power domain devices are already turned on, the remote
+	 * core is already up when the kernel booted (e.g. kicked by the
+	 * bootloader). In this case attach to it.

Same comment as above. What got kicked? A core or M core. And what does "kicked" mean? I can guess what is happening but guessing rarely leads to anything positive.

In the next revision, please use other words than "kicked".

drivers/remoteproc/imx_rproc.c static int imx_rproc_attach_pd(struct imx_rproc *priv) · line 919

Quoted 11 lines
drivers/remoteproc/imx_rproc.c +11 -0
+	 */
+	for (i = 0; i < ret; i++) {
+		if (!dev_pm_genpd_is_on(priv->pd_list->pd_devs[i])) {
+			detached = false;
+			break;
+		}
+	}
+
+	if (detached)
+		priv->rproc->state = RPROC_DETACHED;
+

Ok for the above.

Quoted 33 lines
drivers/remoteproc/imx_rproc.c +13 -0
 	return ret < 0 ? ret : 0;
 }
 
@@ -1146,6 +1160,15 @@ static int imx_rproc_probe(struct platform_device *pdev)
 		}
 	}
 
+	if (dcfg->method == IMX_RPROC_SCU_API) {
+		pm_runtime_enable(dev);
+		ret = pm_runtime_resume_and_get(dev);
+		if (ret) {
+			dev_err(dev, "pm_runtime get failed: %d\n", ret);
+			goto err_put_clk;
+		}
+	}
+
 	ret = rproc_add(rproc);
 	if (ret) {
 		dev_err(dev, "rproc_add failed\n");
@@ -1171,6 +1194,10 @@ static void imx_rproc_remove(struct platform_device *pdev)
 	struct rproc *rproc = platform_get_drvdata(pdev);
 	struct imx_rproc *priv = rproc->priv;
 
+	if (priv->dcfg->method == IMX_RPROC_SCU_API) {
+		pm_runtime_disable(priv->dev);
+		pm_runtime_put(priv->dev);
+	}
 	clk_disable_unprepare(priv->clk);
 	rproc_del(rproc);
 	imx_rproc_put_scu(rproc);
Signature · 1 line
2.39.5
#9 lore raw

Re: [PATCH v5 3/3] remoteproc: imx_rproc: detect and attach to pre-booted remote cores

Quoted 10 lines · Mathieu Poirier
Quoted 5 lines · Hiago De Franco

From: Hiago De Franco <[email protected]>

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

Again, we have a nomenclature issue here with "If the core was kicked by the bootloader". What does "kicked" mean here? Is it just powered and held in reset or is it executing. And are you referring to the A core or the M core?

Ok, same here, I will improve this in the next revision. Thanks.

Quoted 83 lines
Quoted 69 lines

by the bootloader, it is in the same partition as Linux and it is already up and running.

This adds power mode verification through dev_pm_genpd_is_on(), enabling the driver to detect when the remote core is already running and properly attach to it if all the power domain devices are on.

To accomplish this, we need to avoid passing any attach_data or flags to dev_pm_domain_attach_list(), letting the platform device become a consumer of the power domain provider. With that the current power state of the genpds will not change, allowing the detection of the remote core power state.

We enable and sync the device runtime PM during probe to make sure the power domains are correctly managed when the core is controlled by the kernel.

---
v4 -> v5:
- pm_runtime_get_sync() removed in favor of pm_runtime_resume_and_get(). Now it also checks the return value of this function.
- Added pm_runtime_disable() and pm_runtime_put() to imx_rproc_remove() function.
v3 -> v4:
- Changed to use the new dev_pm_genpd_is_on() function instead, as suggested by Ulf. This will now get the power status of the two remote cores power domains to decided if imx_rpoc needs to attach or not. In order to do that, pm_runtime_enable() and pm_runtime_get_sync() were introduced and pd_data was removed.
v2 -> v3:
- Unchanged.
v1 -> v2:
- Dropped unecessary include. Removed the imx_rproc_is_on function, as suggested.

---
 drivers/remoteproc/imx_rproc.c | 37 +++++++++++++++++++++++++++++-----
 1 file changed, 32 insertions(+), 5 deletions(-)
drivers/remoteproc/imx_rproc.c +3 -4
index 627e57a88db2..b53083f2553e 100644
@@ -18,6 +18,7 @@
 #include <linux/of_reserved_mem.h>
 #include <linux/platform_device.h>
 #include <linux/pm_domain.h>
+#include <linux/pm_runtime.h>
 #include <linux/reboot.h>
 #include <linux/regmap.h>
 #include <linux/remoteproc.h>
@@ -890,10 +891,8 @@ static int imx_rproc_partition_notify(struct notifier_block *nb,
 static int imx_rproc_attach_pd(struct imx_rproc *priv)
 {
 	struct device *dev = priv->dev;
-	int ret;
-	struct dev_pm_domain_attach_data pd_data = {
-		.pd_flags = PD_FLAG_DEV_LINK_ON,
-	};
+	int ret, i;
+	bool detached = true;
 
 	/*
 	 * If there is only one power-domain entry, the platform driver framework

drivers/remoteproc/imx_rproc.c static int imx_rproc_attach_pd(struct imx_rproc *priv) · line 908

Quoted 9 lines
drivers/remoteproc/imx_rproc.c +5 -1
@@ -902,7 +901,22 @@ static int imx_rproc_attach_pd(struct imx_rproc *priv)
 	if (dev->pm_domain)
 		return 0;
 
-	ret = dev_pm_domain_attach_list(dev, &pd_data, &priv->pd_list);
+	ret = dev_pm_domain_attach_list(dev, NULL, &priv->pd_list);
+	/*
+	 * If all the power domain devices are already turned on, the remote
+	 * core is already up when the kernel booted (e.g. kicked by the
+	 * bootloader). In this case attach to it.

Same comment as above. What got kicked? A core or M core. And what does "kicked" mean? I can guess what is happening but guessing rarely leads to anything positive.

Quoted 1 line

In the next revision, please use other words than "kicked".

Noted, thanks.

Quoted 49 lines

drivers/remoteproc/imx_rproc.c static int imx_rproc_attach_pd(struct imx_rproc *priv) · line 919

Quoted 13 lines
drivers/remoteproc/imx_rproc.c +11 -0
+	 */
+	for (i = 0; i < ret; i++) {
+		if (!dev_pm_genpd_is_on(priv->pd_list->pd_devs[i])) {
+			detached = false;
+			break;
+		}
+	}
+
+	if (detached)
+		priv->rproc->state = RPROC_DETACHED;
+

Ok for the above.

Quoted 33 lines
drivers/remoteproc/imx_rproc.c +13 -0
 	return ret < 0 ? ret : 0;
 }
 
@@ -1146,6 +1160,15 @@ static int imx_rproc_probe(struct platform_device *pdev)
 		}
 	}
 
+	if (dcfg->method == IMX_RPROC_SCU_API) {
+		pm_runtime_enable(dev);
+		ret = pm_runtime_resume_and_get(dev);
+		if (ret) {
+			dev_err(dev, "pm_runtime get failed: %d\n", ret);
+			goto err_put_clk;
+		}
+	}
+
 	ret = rproc_add(rproc);
 	if (ret) {
 		dev_err(dev, "rproc_add failed\n");
@@ -1171,6 +1194,10 @@ static void imx_rproc_remove(struct platform_device *pdev)
 	struct rproc *rproc = platform_get_drvdata(pdev);
 	struct imx_rproc *priv = rproc->priv;
 
+	if (priv->dcfg->method == IMX_RPROC_SCU_API) {
+		pm_runtime_disable(priv->dev);
+		pm_runtime_put(priv->dev);
+	}
 	clk_disable_unprepare(priv->clk);
 	rproc_del(rproc);
 	imx_rproc_put_scu(rproc);
Signature · 1 line
2.39.5
Reviewed-by on the v5 series
#10 lore raw
In reply to Hiago De Franco
Quoted 45 lines · Hiago De Franco

From: Hiago De Franco <[email protected]>

This patch series depends on Ulf's patches that are currently under review, "pmdomain: Add generic ->sync_state() support to genpd" [1]. Without them, this series is not going to work.

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 patch series implement a new function, dev_pm_genpd_is_on(), which returns the power status of a given power domain (M core power domains IMX_SC_R_M4_0_PID0 and IMX_SC_R_M4_0_MU_1A in this case). If it is already powered on, the driver will attach to it.

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 [2] and from a reported regression [3].

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://lore.kernel.org/lkml/20250404141713.ac2ntcsjsf7epdfa@hiago-nb/

v5:
- pm_runtime_get_sync() removed in favor of pm_runtime_resume_and_get(), checking the return value of it.
- Added pm_runtime_disable() and pm_runtime_put() to imx_rproc_remove().
- Fixed missing "()" in dev_pm_genpd_is_on description.
- Updated dev_pm_genpd_is_on() function description to be explicit the function reflects the current power status of the device and that this might change after the function returns, especially if the genpd is shared.

v4:
- https://lore.kernel.org/lkml/[email protected]/

v3:
- https://lore.kernel.org/all/[email protected]/

v2:
- https://lore.kernel.org/lkml/[email protected]/

Quoted 8 lines

v1:
- https://lore.kernel.org/lkml/[email protected]/

Hiago De Franco (3):
pmdomain: core: introduce dev_pm_genpd_is_on()
remoteproc: imx_rproc: skip clock enable when M-core is managed by the
SCU
remoteproc: imx_rproc: detect and attach to pre-booted remote cores

Quoted 9 lines
drivers/pmdomain/core.c        | 33 +++++++++++++++++++++++++++
drivers/remoteproc/imx_rproc.c | 41 ++++++++++++++++++++++++++++------
include/linux/pm_domain.h      |  6 +++++
3 files changed, 73 insertions(+), 7 deletions(-)
Signature · 1 line
2.39.5
maintainer
#11 lore raw
In reply to Hiago De Franco
Quoted 5 lines · Hiago De Franco

From: Hiago De Franco <[email protected]>

This patch series depends on Ulf's patches that are currently under review, "pmdomain: Add generic ->sync_state() support to genpd" [1]. Without them, this series is not going to work.

Please resend this patchset when [1] and the work in patch 1/3 have been merged.

Thanks,
Mathieu

Quoted 57 lines

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 patch series implement a new function, dev_pm_genpd_is_on(), which returns the power status of a given power domain (M core power domains IMX_SC_R_M4_0_PID0 and IMX_SC_R_M4_0_MU_1A in this case). If it is already powered on, the driver will attach to it.

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 [2] and from a reported regression [3].

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://lore.kernel.org/lkml/20250404141713.ac2ntcsjsf7epdfa@hiago-nb/

v5:
- pm_runtime_get_sync() removed in favor of pm_runtime_resume_and_get(), checking the return value of it.
- Added pm_runtime_disable() and pm_runtime_put() to imx_rproc_remove().
- Fixed missing "()" in dev_pm_genpd_is_on description.
- Updated dev_pm_genpd_is_on() function description to be explicit the function reflects the current power status of the device and that this might change after the function returns, especially if the genpd is shared.

v4:
- https://lore.kernel.org/lkml/[email protected]/

v3:
- https://lore.kernel.org/all/[email protected]/

v2:
- https://lore.kernel.org/lkml/[email protected]/

v1:
- https://lore.kernel.org/lkml/[email protected]/

Hiago De Franco (3):
pmdomain: core: introduce dev_pm_genpd_is_on()
remoteproc: imx_rproc: skip clock enable when M-core is managed by the
SCU
remoteproc: imx_rproc: detect and attach to pre-booted remote cores

 drivers/pmdomain/core.c        | 33 +++++++++++++++++++++++++++
 drivers/remoteproc/imx_rproc.c | 41 ++++++++++++++++++++++++++++------
 include/linux/pm_domain.h      |  6 +++++
 3 files changed, 73 insertions(+), 7 deletions(-)
Signature · 1 line
2.39.5
#12 lore raw
Quoted 8 lines · Mathieu Poirier
Quoted 5 lines · Hiago De Franco

From: Hiago De Franco <[email protected]>

This patch series depends on Ulf's patches that are currently under review, "pmdomain: Add generic ->sync_state() support to genpd" [1]. Without them, this series is not going to work.

Please resend this patchset when [1] and the work in patch 1/3 have been merged.

All right, I will send the v6 with the corrections you mentioned and resend it when the other patches have been merged.

Best regards,
Hiago.

Quoted 61 lines

Thanks,
Mathieu

Quoted 57 lines

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 patch series implement a new function, dev_pm_genpd_is_on(), which returns the power status of a given power domain (M core power domains IMX_SC_R_M4_0_PID0 and IMX_SC_R_M4_0_MU_1A in this case). If it is already powered on, the driver will attach to it.

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 [2] and from a reported regression [3].

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://lore.kernel.org/lkml/20250404141713.ac2ntcsjsf7epdfa@hiago-nb/

v5:
- pm_runtime_get_sync() removed in favor of pm_runtime_resume_and_get(), checking the return value of it.
- Added pm_runtime_disable() and pm_runtime_put() to imx_rproc_remove().
- Fixed missing "()" in dev_pm_genpd_is_on description.
- Updated dev_pm_genpd_is_on() function description to be explicit the function reflects the current power status of the device and that this might change after the function returns, especially if the genpd is shared.

v4:
- https://lore.kernel.org/lkml/[email protected]/

v3:
- https://lore.kernel.org/all/[email protected]/

v2:
- https://lore.kernel.org/lkml/[email protected]/

v1:
- https://lore.kernel.org/lkml/[email protected]/

Hiago De Franco (3):
pmdomain: core: introduce dev_pm_genpd_is_on()
remoteproc: imx_rproc: skip clock enable when M-core is managed by the
SCU
remoteproc: imx_rproc: detect and attach to pre-booted remote cores

 drivers/pmdomain/core.c        | 33 +++++++++++++++++++++++++++
 drivers/remoteproc/imx_rproc.c | 41 ++++++++++++++++++++++++++++------
 include/linux/pm_domain.h      |  6 +++++
 3 files changed, 73 insertions(+), 7 deletions(-)
Signature · 1 line
2.39.5