From: Peng Fan <peng.fan@nxp.com>
i.MX95 features a Cortex-M33 core, six Cortex-A55 cores, and
one Cortex-M7 core. The System Control Management Interface(SCMI)
firmware runs on the M33 core. The i.MX95 SCMI firmware named System
Manager(SM) includes vendor extension protocols, Logical Machine
Management(LMM) protocol and CPU protocol and etc.
There are three cases for M7:
(1) M7 in a separate Logical Machine(LM) that Linux can't control it.
(2) M7 in a separate Logical Machine that Linux can control it using
LMM protocol
(3) M7 runs in same Logical Machine as A55, so Linux can control it
using CPU protocol
So extend the driver to using LMM and CPU protocol to manage the M7 core.
- Add IMX_RPROC_SM to indicate the remote core runs on a SoC that
has System Manager.
- Compare linux LM ID(got using scmi_imx_lmm_info) and M7 LM ID(the ID
is fixed as 1 in SM firmware if M7 is in a seprate LM),
if Linux LM ID equals M7 LM ID(linux and M7 in same LM), use CPU
protocol to start/stop. Otherwise, use LMM protocol to start/stop.
Whether using CPU or LMM protocol to start/stop, the M7 status
detection could use CPU protocol to detect started or not. So
in imx_rproc_detect_mode, use scmi_imx_cpu_started to check the
status of M7.
- For above case 1 and 2, Use SCMI_IMX_LMM_POWER_ON to detect whether
the M7 LM is under control of A55 LM.
Current setup relies on pre-Linux software(U-Boot) to do
M7 TCM ECC initialization. In future, we could add the support in Linux
to decouple U-Boot and Linux.
Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
drivers/remoteproc/imx_rproc.c | 113 ++++++++++++++++++++++++++++++++++++++++-
drivers/remoteproc/imx_rproc.h | 5 ++
2 files changed, 116 insertions(+), 2 deletions(-)
diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 74299af1d7f10a0db794de494c52304b2323b89f..b1a117ca5e5795554b67eb7092db2a25fc7de13b 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -8,6 +8,7 @@
#include <linux/clk.h>
#include <linux/err.h>
#include <linux/firmware/imx/sci.h>
+#include <linux/firmware/imx/sm.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/mailbox_client.h>
@@ -21,6 +22,7 @@
#include <linux/reboot.h>
#include <linux/regmap.h>
#include <linux/remoteproc.h>
+#include <linux/scmi_imx_protocol.h>
#include <linux/workqueue.h>
#include "imx_rproc.h"
@@ -91,6 +93,11 @@ struct imx_rproc_mem {
#define ATT_CORE_MASK 0xffff
#define ATT_CORE(I) BIT((I))
+/* Logical Machine Operation */
+#define IMX_RPROC_FLAGS_SM_LMM_OP BIT(0)
+/* Linux has permission to handle the Logical Machine of remote cores */
+#define IMX_RPROC_FLAGS_SM_LMM_AVAIL BIT(1)
+
static int imx_rproc_xtr_mbox_init(struct rproc *rproc, bool tx_block);
static void imx_rproc_free_mbox(struct rproc *rproc);
@@ -115,6 +122,8 @@ struct imx_rproc {
u32 entry; /* cpu start address */
u32 core_index;
struct dev_pm_domain_list *pd_list;
+ /* For i.MX System Manager based systems */
+ u32 flags;
};
static const struct imx_rproc_att imx_rproc_att_imx93[] = {
@@ -393,6 +402,30 @@ static int imx_rproc_start(struct rproc *rproc)
case IMX_RPROC_SCU_API:
ret = imx_sc_pm_cpu_start(priv->ipc_handle, priv->rsrc_id, true, priv->entry);
break;
+ case IMX_RPROC_SM:
+ if (priv->flags & IMX_RPROC_FLAGS_SM_LMM_OP) {
+ if (!(priv->flags & IMX_RPROC_FLAGS_SM_LMM_AVAIL))
+ return -EACCES;
+
+ ret = scmi_imx_lmm_reset_vector_set(dcfg->lmid, dcfg->cpuid, 0, 0);
+ if (ret) {
+ dev_err(dev, "Failed to set reset vector lmid(%u), cpuid(%u): %d\n",
+ dcfg->lmid, dcfg->cpuid, ret);
+ }
+
+ ret = scmi_imx_lmm_operation(dcfg->lmid, SCMI_IMX_LMM_BOOT, 0);
+ if (ret)
+ dev_err(dev, "Failed to boot lmm(%d): %d\n", ret, dcfg->lmid);
+ } else {
+ ret = scmi_imx_cpu_reset_vector_set(dcfg->cpuid, 0, true, false, false);
+ if (ret) {
+ dev_err(dev, "Failed to set reset vector cpuid(%u): %d\n",
+ dcfg->cpuid, ret);
+ }
+
+ ret = scmi_imx_cpu_start(dcfg->cpuid, true);
+ }
+ break;
default:
return -EOPNOTSUPP;
}
@@ -435,6 +468,16 @@ static int imx_rproc_stop(struct rproc *rproc)
case IMX_RPROC_SCU_API:
ret = imx_sc_pm_cpu_start(priv->ipc_handle, priv->rsrc_id, false, priv->entry);
break;
+ case IMX_RPROC_SM:
+ if (priv->flags & IMX_RPROC_FLAGS_SM_LMM_OP) {
+ if (priv->flags & IMX_RPROC_FLAGS_SM_LMM_AVAIL)
+ ret = scmi_imx_lmm_operation(dcfg->lmid, SCMI_IMX_LMM_SHUTDOWN, 0);
+ else
+ ret = -EACCES;
+ } else {
+ ret = scmi_imx_cpu_start(dcfg->cpuid, false);
+ }
+ break;
default:
return -EOPNOTSUPP;
}
@@ -549,9 +592,11 @@ static int imx_rproc_prepare(struct rproc *rproc)
{
struct imx_rproc *priv = rproc->priv;
struct device_node *np = priv->dev->of_node;
+ const struct imx_rproc_dcfg *dcfg = priv->dcfg;
struct of_phandle_iterator it;
struct rproc_mem_entry *mem;
struct reserved_mem *rmem;
+ int ret;
u32 da;
/* Register associated reserved memory regions */
@@ -592,6 +637,38 @@ static int imx_rproc_prepare(struct rproc *rproc)
rproc_add_carveout(rproc, mem);
}
+ switch (dcfg->method) {
+ case IMX_RPROC_SM:
+ if (!(priv->flags & IMX_RPROC_FLAGS_SM_LMM_OP))
+ break;
+ /*
+ * Power on the Logical Machine to make sure TCM is available.
+ * Also serve as permission check. If in different Logical
+ * Machine, and linux has permission to handle the Logical
+ * Machine, set IMX_RPROC_FLAGS_SM_LMM_AVAIL.
+ */
+ ret = scmi_imx_lmm_operation(dcfg->lmid, SCMI_IMX_LMM_POWER_ON, 0);
+ if (ret == 0) {
+ dev_info(priv->dev, "lmm(%d) powered on\n", dcfg->lmid);
+ priv->flags |= IMX_RPROC_FLAGS_SM_LMM_AVAIL;
+ } else if (ret == -EACCES) {
+ dev_info(priv->dev, "lmm(%d) not under Linux Control\n", dcfg->lmid);
+ /*
+ * If remote cores boots up in detached mode, continue;
+ * else linux has no permission, return -EACCES.
+ */
+ if (priv->rproc->state != RPROC_DETACHED)
+ return -EACCES;
+ } else if (ret) {
+ dev_err(priv->dev, "Failed to power on lmm(%d): %d\n", ret, dcfg->lmid);
+ return ret;
+ }
+
+ break;
+ default:
+ break;
+ };
+
return 0;
}
@@ -911,13 +988,41 @@ static int imx_rproc_detect_mode(struct imx_rproc *priv)
struct regmap_config config = { .name = "imx-rproc" };
const struct imx_rproc_dcfg *dcfg = priv->dcfg;
struct device *dev = priv->dev;
+ struct scmi_imx_lmm_info info;
struct regmap *regmap;
struct arm_smccc_res res;
+ bool started = false;
int ret;
u32 val;
u8 pt;
switch (dcfg->method) {
+ case IMX_RPROC_SM:
+ /* Get current Linux Logical Machine ID */
+ ret = scmi_imx_lmm_info(LMM_ID_DISCOVER, &info);
+ if (ret) {
+ dev_err(dev, "Failed to get current LMM ID err: %d\n", ret);
+ return ret;
+ }
+
+ /*
+ * Check whether remote processor is in same Logical Machine as Linux.
+ * If no, need use Logical Machine API to manage remote processor, and
+ * set IMX_RPROC_FLAGS_SM_LMM_OP.
+ * If yes, use CPU protocol API to manage remote processor.
+ */
+ if (dcfg->lmid != info.lmid) {
+ priv->flags |= IMX_RPROC_FLAGS_SM_LMM_OP;
+ dev_info(dev, "Using LMM Protocol OPS\n");
+ } else {
+ dev_info(dev, "Using CPU Protocol OPS\n");
+ }
+
+ scmi_imx_cpu_started(dcfg->cpuid, &started);
+ if (started)
+ priv->rproc->state = RPROC_DETACHED;
+
+ return 0;
case IMX_RPROC_NONE:
priv->rproc->state = RPROC_DETACHED;
return 0;
@@ -1029,8 +1134,12 @@ 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)
+ /*
+ * IMX_RPROC_NONE indicates not under control of Linux.
+ * System Manager(SM) firmware automatically configures clock,
+ * so bypass the clk settings for IMX_RPROC_SM.
+ */
+ if (dcfg->method == IMX_RPROC_NONE || dcfg->method == IMX_RPROC_SM)
return 0;
priv->clk = devm_clk_get(dev, NULL);
diff --git a/drivers/remoteproc/imx_rproc.h b/drivers/remoteproc/imx_rproc.h
index cfd38d37e1467d1d9e6f89be146c0b53262b92a0..6fe8d975ed302967f27b7a4319a899e6f0822976 100644
--- a/drivers/remoteproc/imx_rproc.h
+++ b/drivers/remoteproc/imx_rproc.h
@@ -26,6 +26,8 @@ enum imx_rproc_method {
IMX_RPROC_SCU_API,
/* Through Reset Controller API */
IMX_RPROC_RESET_CONTROLLER,
+ /* Through System Manager */
+ IMX_RPROC_SM,
};
/* dcfg flags */
@@ -42,6 +44,9 @@ struct imx_rproc_dcfg {
size_t att_size;
enum imx_rproc_method method;
u32 flags;
+ /* For System Manager(SM) based SoCs, the IDs are from SM firmware */
+ u32 cpuid;
+ u32 lmid;
};
#endif /* _IMX_RPROC_H */
--
2.37.1
Good day, On Wed, Jun 25, 2025 at 10:23:28AM +0800, Peng Fan (OSS) wrote: > From: Peng Fan <peng.fan@nxp.com> > > i.MX95 features a Cortex-M33 core, six Cortex-A55 cores, and > one Cortex-M7 core. The System Control Management Interface(SCMI) > firmware runs on the M33 core. The i.MX95 SCMI firmware named System > Manager(SM) includes vendor extension protocols, Logical Machine > Management(LMM) protocol and CPU protocol and etc. > > There are three cases for M7: > (1) M7 in a separate Logical Machine(LM) that Linux can't control it. > (2) M7 in a separate Logical Machine that Linux can control it using > LMM protocol > (3) M7 runs in same Logical Machine as A55, so Linux can control it > using CPU protocol > > So extend the driver to using LMM and CPU protocol to manage the M7 core. > - Add IMX_RPROC_SM to indicate the remote core runs on a SoC that > has System Manager. > - Compare linux LM ID(got using scmi_imx_lmm_info) and M7 LM ID(the ID > is fixed as 1 in SM firmware if M7 is in a seprate LM), > if Linux LM ID equals M7 LM ID(linux and M7 in same LM), use CPU > protocol to start/stop. Otherwise, use LMM protocol to start/stop. > Whether using CPU or LMM protocol to start/stop, the M7 status > detection could use CPU protocol to detect started or not. So > in imx_rproc_detect_mode, use scmi_imx_cpu_started to check the > status of M7. > - For above case 1 and 2, Use SCMI_IMX_LMM_POWER_ON to detect whether > the M7 LM is under control of A55 LM. > Thanks for the context, it really helps. > Current setup relies on pre-Linux software(U-Boot) to do > M7 TCM ECC initialization. In future, we could add the support in Linux > to decouple U-Boot and Linux. > > Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com> > Signed-off-by: Peng Fan <peng.fan@nxp.com> > --- > drivers/remoteproc/imx_rproc.c | 113 ++++++++++++++++++++++++++++++++++++++++- > drivers/remoteproc/imx_rproc.h | 5 ++ > 2 files changed, 116 insertions(+), 2 deletions(-) > > diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c > index 74299af1d7f10a0db794de494c52304b2323b89f..b1a117ca5e5795554b67eb7092db2a25fc7de13b 100644 > --- a/drivers/remoteproc/imx_rproc.c > +++ b/drivers/remoteproc/imx_rproc.c > @@ -8,6 +8,7 @@ > #include <linux/clk.h> > #include <linux/err.h> > #include <linux/firmware/imx/sci.h> > +#include <linux/firmware/imx/sm.h> > #include <linux/interrupt.h> > #include <linux/kernel.h> > #include <linux/mailbox_client.h> > @@ -21,6 +22,7 @@ > #include <linux/reboot.h> > #include <linux/regmap.h> > #include <linux/remoteproc.h> > +#include <linux/scmi_imx_protocol.h> > #include <linux/workqueue.h> > > #include "imx_rproc.h" > @@ -91,6 +93,11 @@ struct imx_rproc_mem { > #define ATT_CORE_MASK 0xffff > #define ATT_CORE(I) BIT((I)) > > +/* Logical Machine Operation */ > +#define IMX_RPROC_FLAGS_SM_LMM_OP BIT(0) > +/* Linux has permission to handle the Logical Machine of remote cores */ > +#define IMX_RPROC_FLAGS_SM_LMM_AVAIL BIT(1) > + > static int imx_rproc_xtr_mbox_init(struct rproc *rproc, bool tx_block); > static void imx_rproc_free_mbox(struct rproc *rproc); > > @@ -115,6 +122,8 @@ struct imx_rproc { > u32 entry; /* cpu start address */ > u32 core_index; > struct dev_pm_domain_list *pd_list; > + /* For i.MX System Manager based systems */ > + u32 flags; > }; > > static const struct imx_rproc_att imx_rproc_att_imx93[] = { > @@ -393,6 +402,30 @@ static int imx_rproc_start(struct rproc *rproc) > case IMX_RPROC_SCU_API: > ret = imx_sc_pm_cpu_start(priv->ipc_handle, priv->rsrc_id, true, priv->entry); > break; > + case IMX_RPROC_SM: > + if (priv->flags & IMX_RPROC_FLAGS_SM_LMM_OP) { > + if (!(priv->flags & IMX_RPROC_FLAGS_SM_LMM_AVAIL)) > + return -EACCES; > + > + ret = scmi_imx_lmm_reset_vector_set(dcfg->lmid, dcfg->cpuid, 0, 0); > + if (ret) { > + dev_err(dev, "Failed to set reset vector lmid(%u), cpuid(%u): %d\n", > + dcfg->lmid, dcfg->cpuid, ret); > + } > + > + ret = scmi_imx_lmm_operation(dcfg->lmid, SCMI_IMX_LMM_BOOT, 0); > + if (ret) > + dev_err(dev, "Failed to boot lmm(%d): %d\n", ret, dcfg->lmid); > + } else { > + ret = scmi_imx_cpu_reset_vector_set(dcfg->cpuid, 0, true, false, false); > + if (ret) { > + dev_err(dev, "Failed to set reset vector cpuid(%u): %d\n", > + dcfg->cpuid, ret); > + } > + > + ret = scmi_imx_cpu_start(dcfg->cpuid, true); > + } > + break; > default: > return -EOPNOTSUPP; > } > @@ -435,6 +468,16 @@ static int imx_rproc_stop(struct rproc *rproc) > case IMX_RPROC_SCU_API: > ret = imx_sc_pm_cpu_start(priv->ipc_handle, priv->rsrc_id, false, priv->entry); > break; > + case IMX_RPROC_SM: > + if (priv->flags & IMX_RPROC_FLAGS_SM_LMM_OP) { > + if (priv->flags & IMX_RPROC_FLAGS_SM_LMM_AVAIL) > + ret = scmi_imx_lmm_operation(dcfg->lmid, SCMI_IMX_LMM_SHUTDOWN, 0); > + else > + ret = -EACCES; > + } else { > + ret = scmi_imx_cpu_start(dcfg->cpuid, false); > + } > + break; > default: > return -EOPNOTSUPP; > } > @@ -549,9 +592,11 @@ static int imx_rproc_prepare(struct rproc *rproc) > { > struct imx_rproc *priv = rproc->priv; > struct device_node *np = priv->dev->of_node; > + const struct imx_rproc_dcfg *dcfg = priv->dcfg; > struct of_phandle_iterator it; > struct rproc_mem_entry *mem; > struct reserved_mem *rmem; > + int ret; > u32 da; > > /* Register associated reserved memory regions */ > @@ -592,6 +637,38 @@ static int imx_rproc_prepare(struct rproc *rproc) > rproc_add_carveout(rproc, mem); > } > > + switch (dcfg->method) { > + case IMX_RPROC_SM: > + if (!(priv->flags & IMX_RPROC_FLAGS_SM_LMM_OP)) > + break; > + /* > + * Power on the Logical Machine to make sure TCM is available. > + * Also serve as permission check. If in different Logical > + * Machine, and linux has permission to handle the Logical > + * Machine, set IMX_RPROC_FLAGS_SM_LMM_AVAIL. > + */ > + ret = scmi_imx_lmm_operation(dcfg->lmid, SCMI_IMX_LMM_POWER_ON, 0); > + if (ret == 0) { > + dev_info(priv->dev, "lmm(%d) powered on\n", dcfg->lmid); > + priv->flags |= IMX_RPROC_FLAGS_SM_LMM_AVAIL; This is set all the time imx_rproc_prepare() is called - isn't there a way to set it once at initialisation time? > + } else if (ret == -EACCES) { > + dev_info(priv->dev, "lmm(%d) not under Linux Control\n", dcfg->lmid); > + /* > + * If remote cores boots up in detached mode, continue; > + * else linux has no permission, return -EACCES. > + */ > + if (priv->rproc->state != RPROC_DETACHED) > + return -EACCES; > + } else if (ret) { > + dev_err(priv->dev, "Failed to power on lmm(%d): %d\n", ret, dcfg->lmid); > + return ret; > + } > + > + break; > + default: > + break; > + }; > + Please put this in a function and get rid of the switch{}. > return 0; > } > > @@ -911,13 +988,41 @@ static int imx_rproc_detect_mode(struct imx_rproc *priv) > struct regmap_config config = { .name = "imx-rproc" }; > const struct imx_rproc_dcfg *dcfg = priv->dcfg; > struct device *dev = priv->dev; > + struct scmi_imx_lmm_info info; > struct regmap *regmap; > struct arm_smccc_res res; > + bool started = false; > int ret; > u32 val; > u8 pt; > > switch (dcfg->method) { > + case IMX_RPROC_SM: > + /* Get current Linux Logical Machine ID */ > + ret = scmi_imx_lmm_info(LMM_ID_DISCOVER, &info); > + if (ret) { > + dev_err(dev, "Failed to get current LMM ID err: %d\n", ret); > + return ret; > + } > + > + /* > + * Check whether remote processor is in same Logical Machine as Linux. > + * If no, need use Logical Machine API to manage remote processor, and > + * set IMX_RPROC_FLAGS_SM_LMM_OP. > + * If yes, use CPU protocol API to manage remote processor. > + */ > + if (dcfg->lmid != info.lmid) { > + priv->flags |= IMX_RPROC_FLAGS_SM_LMM_OP; > + dev_info(dev, "Using LMM Protocol OPS\n"); > + } else { > + dev_info(dev, "Using CPU Protocol OPS\n"); > + } > + > + scmi_imx_cpu_started(dcfg->cpuid, &started); Function scmi_imx_cpu_started() returns a value that is not taken into account. > + if (started) > + priv->rproc->state = RPROC_DETACHED; > + > + return 0; > case IMX_RPROC_NONE: > priv->rproc->state = RPROC_DETACHED; > return 0; > @@ -1029,8 +1134,12 @@ 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) > + /* > + * IMX_RPROC_NONE indicates not under control of Linux. > + * System Manager(SM) firmware automatically configures clock, > + * so bypass the clk settings for IMX_RPROC_SM. > + */ > + if (dcfg->method == IMX_RPROC_NONE || dcfg->method == IMX_RPROC_SM) > return 0; > > priv->clk = devm_clk_get(dev, NULL); > diff --git a/drivers/remoteproc/imx_rproc.h b/drivers/remoteproc/imx_rproc.h > index cfd38d37e1467d1d9e6f89be146c0b53262b92a0..6fe8d975ed302967f27b7a4319a899e6f0822976 100644 > --- a/drivers/remoteproc/imx_rproc.h > +++ b/drivers/remoteproc/imx_rproc.h > @@ -26,6 +26,8 @@ enum imx_rproc_method { > IMX_RPROC_SCU_API, > /* Through Reset Controller API */ > IMX_RPROC_RESET_CONTROLLER, > + /* Through System Manager */ > + IMX_RPROC_SM, > }; > > /* dcfg flags */ > @@ -42,6 +44,9 @@ struct imx_rproc_dcfg { > size_t att_size; > enum imx_rproc_method method; > u32 flags; > + /* For System Manager(SM) based SoCs, the IDs are from SM firmware */ > + u32 cpuid; > + u32 lmid; > }; > > #endif /* _IMX_RPROC_H */ > > -- > 2.37.1 >
Hi Mathieu, On Tue, Jul 08, 2025 at 10:32:34AM -0600, Mathieu Poirier wrote: >Good day, Thanks, good day. > >On Wed, Jun 25, 2025 at 10:23:28AM +0800, Peng Fan (OSS) wrote: >> From: Peng Fan <peng.fan@nxp.com> >> >> i.MX95 features a Cortex-M33 core, six Cortex-A55 cores, and >> one Cortex-M7 core. The System Control Management Interface(SCMI) >> firmware runs on the M33 core. The i.MX95 SCMI firmware named System >> Manager(SM) includes vendor extension protocols, Logical Machine >> Management(LMM) protocol and CPU protocol and etc. >> >> There are three cases for M7: >> (1) M7 in a separate Logical Machine(LM) that Linux can't control it. >> (2) M7 in a separate Logical Machine that Linux can control it using >> LMM protocol >> (3) M7 runs in same Logical Machine as A55, so Linux can control it >> using CPU protocol >> >> So extend the driver to using LMM and CPU protocol to manage the M7 core. >> - Add IMX_RPROC_SM to indicate the remote core runs on a SoC that >> has System Manager. >> - Compare linux LM ID(got using scmi_imx_lmm_info) and M7 LM ID(the ID >> is fixed as 1 in SM firmware if M7 is in a seprate LM), >> if Linux LM ID equals M7 LM ID(linux and M7 in same LM), use CPU >> protocol to start/stop. Otherwise, use LMM protocol to start/stop. >> Whether using CPU or LMM protocol to start/stop, the M7 status >> detection could use CPU protocol to detect started or not. So >> in imx_rproc_detect_mode, use scmi_imx_cpu_started to check the >> status of M7. >> - For above case 1 and 2, Use SCMI_IMX_LMM_POWER_ON to detect whether >> the M7 LM is under control of A55 LM. >> > >Thanks for the context, it really helps. Glad that helps. > [....] >> @@ -592,6 +637,38 @@ static int imx_rproc_prepare(struct rproc *rproc) >> rproc_add_carveout(rproc, mem); >> } >> >> + switch (dcfg->method) { >> + case IMX_RPROC_SM: >> + if (!(priv->flags & IMX_RPROC_FLAGS_SM_LMM_OP)) >> + break; >> + /* >> + * Power on the Logical Machine to make sure TCM is available. >> + * Also serve as permission check. If in different Logical >> + * Machine, and linux has permission to handle the Logical >> + * Machine, set IMX_RPROC_FLAGS_SM_LMM_AVAIL. >> + */ >> + ret = scmi_imx_lmm_operation(dcfg->lmid, SCMI_IMX_LMM_POWER_ON, 0); >> + if (ret == 0) { >> + dev_info(priv->dev, "lmm(%d) powered on\n", dcfg->lmid); >> + priv->flags |= IMX_RPROC_FLAGS_SM_LMM_AVAIL; > >This is set all the time imx_rproc_prepare() is called - isn't there a way to >set it once at initialisation time? Yeah. Moving this to probe path should be ok, such as in imx_rproc_detect_mode. The drawback is M7 logical machine will be left in powered up state if moving to probe path before user starts M7 LM. Leaving in here means M7 logcal machine will be only powered up when user does "echo start > /xx/remoteproc-y/state", but needs to set IMX_RPROC_FLAGS_SM_LMM_AVAIL flags each time do preparing. If you prefer moving this logic to probe, I could give a try to move to imx_rproc_detect_mode which is probe path. How do you think? > >> + } else if (ret == -EACCES) { >> + dev_info(priv->dev, "lmm(%d) not under Linux Control\n", dcfg->lmid); >> + /* >> + * If remote cores boots up in detached mode, continue; >> + * else linux has no permission, return -EACCES. >> + */ >> + if (priv->rproc->state != RPROC_DETACHED) >> + return -EACCES; >> + } else if (ret) { >> + dev_err(priv->dev, "Failed to power on lmm(%d): %d\n", ret, dcfg->lmid); >> + return ret; >> + } >> + >> + break; >> + default: >> + break; >> + }; >> + > >Please put this in a function and get rid of the switch{}. ok. Fix in v4 > >> return 0; >> } >> >> @@ -911,13 +988,41 @@ static int imx_rproc_detect_mode(struct imx_rproc *priv) >> struct regmap_config config = { .name = "imx-rproc" }; >> const struct imx_rproc_dcfg *dcfg = priv->dcfg; >> struct device *dev = priv->dev; >> + struct scmi_imx_lmm_info info; >> struct regmap *regmap; >> struct arm_smccc_res res; >> + bool started = false; >> int ret; >> u32 val; >> u8 pt; >> >> switch (dcfg->method) { >> + case IMX_RPROC_SM: >> + /* Get current Linux Logical Machine ID */ >> + ret = scmi_imx_lmm_info(LMM_ID_DISCOVER, &info); >> + if (ret) { >> + dev_err(dev, "Failed to get current LMM ID err: %d\n", ret); >> + return ret; >> + } >> + >> + /* >> + * Check whether remote processor is in same Logical Machine as Linux. >> + * If no, need use Logical Machine API to manage remote processor, and >> + * set IMX_RPROC_FLAGS_SM_LMM_OP. >> + * If yes, use CPU protocol API to manage remote processor. >> + */ >> + if (dcfg->lmid != info.lmid) { >> + priv->flags |= IMX_RPROC_FLAGS_SM_LMM_OP; >> + dev_info(dev, "Using LMM Protocol OPS\n"); >> + } else { >> + dev_info(dev, "Using CPU Protocol OPS\n"); >> + } >> + >> + scmi_imx_cpu_started(dcfg->cpuid, &started); > >Function scmi_imx_cpu_started() returns a value that is not taken into account. > >> + if (started) I will update to "if (started || ret)" in v4, with ret assigned the return value of scmi_imx_cpu_started. Thanks, Peng
On Wed, Jul 09, 2025 at 05:02:31PM +0800, Peng Fan wrote: > Hi Mathieu, > > On Tue, Jul 08, 2025 at 10:32:34AM -0600, Mathieu Poirier wrote: > >Good day, > > Thanks, good day. > > > > >On Wed, Jun 25, 2025 at 10:23:28AM +0800, Peng Fan (OSS) wrote: > >> From: Peng Fan <peng.fan@nxp.com> > >> > >> i.MX95 features a Cortex-M33 core, six Cortex-A55 cores, and > >> one Cortex-M7 core. The System Control Management Interface(SCMI) > >> firmware runs on the M33 core. The i.MX95 SCMI firmware named System > >> Manager(SM) includes vendor extension protocols, Logical Machine > >> Management(LMM) protocol and CPU protocol and etc. > >> > >> There are three cases for M7: > >> (1) M7 in a separate Logical Machine(LM) that Linux can't control it. > >> (2) M7 in a separate Logical Machine that Linux can control it using > >> LMM protocol > >> (3) M7 runs in same Logical Machine as A55, so Linux can control it > >> using CPU protocol > >> > >> So extend the driver to using LMM and CPU protocol to manage the M7 core. > >> - Add IMX_RPROC_SM to indicate the remote core runs on a SoC that > >> has System Manager. > >> - Compare linux LM ID(got using scmi_imx_lmm_info) and M7 LM ID(the ID > >> is fixed as 1 in SM firmware if M7 is in a seprate LM), > >> if Linux LM ID equals M7 LM ID(linux and M7 in same LM), use CPU > >> protocol to start/stop. Otherwise, use LMM protocol to start/stop. > >> Whether using CPU or LMM protocol to start/stop, the M7 status > >> detection could use CPU protocol to detect started or not. So > >> in imx_rproc_detect_mode, use scmi_imx_cpu_started to check the > >> status of M7. > >> - For above case 1 and 2, Use SCMI_IMX_LMM_POWER_ON to detect whether > >> the M7 LM is under control of A55 LM. > >> > > > >Thanks for the context, it really helps. > > Glad that helps. > > > > > [....] > > >> @@ -592,6 +637,38 @@ static int imx_rproc_prepare(struct rproc *rproc) > >> rproc_add_carveout(rproc, mem); > >> } > >> > >> + switch (dcfg->method) { > >> + case IMX_RPROC_SM: > >> + if (!(priv->flags & IMX_RPROC_FLAGS_SM_LMM_OP)) > >> + break; > >> + /* > >> + * Power on the Logical Machine to make sure TCM is available. > >> + * Also serve as permission check. If in different Logical > >> + * Machine, and linux has permission to handle the Logical > >> + * Machine, set IMX_RPROC_FLAGS_SM_LMM_AVAIL. > >> + */ > >> + ret = scmi_imx_lmm_operation(dcfg->lmid, SCMI_IMX_LMM_POWER_ON, 0); > >> + if (ret == 0) { > >> + dev_info(priv->dev, "lmm(%d) powered on\n", dcfg->lmid); > >> + priv->flags |= IMX_RPROC_FLAGS_SM_LMM_AVAIL; > > > >This is set all the time imx_rproc_prepare() is called - isn't there a way to > >set it once at initialisation time? > > Yeah. Moving this to probe path should be ok, such as in imx_rproc_detect_mode. > The drawback is M7 logical machine will be left in powered up state if > moving to probe path before user starts M7 LM. Leaving in here means M7 logcal > machine will be only powered up when user does > "echo start > /xx/remoteproc-y/state", but needs to set > IMX_RPROC_FLAGS_SM_LMM_AVAIL flags each time do preparing. > > If you prefer moving this logic to probe, I could give a try to move > to imx_rproc_detect_mode which is probe path. > > How do you think? Just leave it where it is. Mathieu > > > > >> + } else if (ret == -EACCES) { > >> + dev_info(priv->dev, "lmm(%d) not under Linux Control\n", dcfg->lmid); > >> + /* > >> + * If remote cores boots up in detached mode, continue; > >> + * else linux has no permission, return -EACCES. > >> + */ > >> + if (priv->rproc->state != RPROC_DETACHED) > >> + return -EACCES; > >> + } else if (ret) { > >> + dev_err(priv->dev, "Failed to power on lmm(%d): %d\n", ret, dcfg->lmid); > >> + return ret; > >> + } > >> + > >> + break; > >> + default: > >> + break; > >> + }; > >> + > > > >Please put this in a function and get rid of the switch{}. > > ok. Fix in v4 > > > > >> return 0; > >> } > >> > >> @@ -911,13 +988,41 @@ static int imx_rproc_detect_mode(struct imx_rproc *priv) > >> struct regmap_config config = { .name = "imx-rproc" }; > >> const struct imx_rproc_dcfg *dcfg = priv->dcfg; > >> struct device *dev = priv->dev; > >> + struct scmi_imx_lmm_info info; > >> struct regmap *regmap; > >> struct arm_smccc_res res; > >> + bool started = false; > >> int ret; > >> u32 val; > >> u8 pt; > >> > >> switch (dcfg->method) { > >> + case IMX_RPROC_SM: > >> + /* Get current Linux Logical Machine ID */ > >> + ret = scmi_imx_lmm_info(LMM_ID_DISCOVER, &info); > >> + if (ret) { > >> + dev_err(dev, "Failed to get current LMM ID err: %d\n", ret); > >> + return ret; > >> + } > >> + > >> + /* > >> + * Check whether remote processor is in same Logical Machine as Linux. > >> + * If no, need use Logical Machine API to manage remote processor, and > >> + * set IMX_RPROC_FLAGS_SM_LMM_OP. > >> + * If yes, use CPU protocol API to manage remote processor. > >> + */ > >> + if (dcfg->lmid != info.lmid) { > >> + priv->flags |= IMX_RPROC_FLAGS_SM_LMM_OP; > >> + dev_info(dev, "Using LMM Protocol OPS\n"); > >> + } else { > >> + dev_info(dev, "Using CPU Protocol OPS\n"); > >> + } > >> + > >> + scmi_imx_cpu_started(dcfg->cpuid, &started); > > > >Function scmi_imx_cpu_started() returns a value that is not taken into account. > > > >> + if (started) > > I will update to "if (started || ret)" in v4, with ret assigned the return > value of scmi_imx_cpu_started. > > Thanks, > Peng
On Wed, Jun 25, 2025 at 10:23:28AM +0800, Peng Fan (OSS) wrote: > From: Peng Fan <peng.fan@nxp.com> > > i.MX95 features a Cortex-M33 core, six Cortex-A55 cores, and > one Cortex-M7 core. The System Control Management Interface(SCMI) > firmware runs on the M33 core. The i.MX95 SCMI firmware named System > Manager(SM) includes vendor extension protocols, Logical Machine > Management(LMM) protocol and CPU protocol and etc. > > There are three cases for M7: > (1) M7 in a separate Logical Machine(LM) that Linux can't control it. > (2) M7 in a separate Logical Machine that Linux can control it using > LMM protocol > (3) M7 runs in same Logical Machine as A55, so Linux can control it > using CPU protocol > > So extend the driver to using LMM and CPU protocol to manage the M7 core. > - Add IMX_RPROC_SM to indicate the remote core runs on a SoC that > has System Manager. > - Compare linux LM ID(got using scmi_imx_lmm_info) and M7 LM ID(the ID > is fixed as 1 in SM firmware if M7 is in a seprate LM), > if Linux LM ID equals M7 LM ID(linux and M7 in same LM), use CPU > protocol to start/stop. Otherwise, use LMM protocol to start/stop. > Whether using CPU or LMM protocol to start/stop, the M7 status > detection could use CPU protocol to detect started or not. So > in imx_rproc_detect_mode, use scmi_imx_cpu_started to check the > status of M7. > - For above case 1 and 2, Use SCMI_IMX_LMM_POWER_ON to detect whether > the M7 LM is under control of A55 LM. > > Current setup relies on pre-Linux software(U-Boot) to do > M7 TCM ECC initialization. In future, we could add the support in Linux > to decouple U-Boot and Linux. > > Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com> > Signed-off-by: Peng Fan <peng.fan@nxp.com> > --- Reviewed-by: Frank Li <Frank.Li@nxp.com> > drivers/remoteproc/imx_rproc.c | 113 ++++++++++++++++++++++++++++++++++++++++- > drivers/remoteproc/imx_rproc.h | 5 ++ > 2 files changed, 116 insertions(+), 2 deletions(-) > > diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c > index 74299af1d7f10a0db794de494c52304b2323b89f..b1a117ca5e5795554b67eb7092db2a25fc7de13b 100644 > --- a/drivers/remoteproc/imx_rproc.c > +++ b/drivers/remoteproc/imx_rproc.c > @@ -8,6 +8,7 @@ > #include <linux/clk.h> > #include <linux/err.h> > #include <linux/firmware/imx/sci.h> > +#include <linux/firmware/imx/sm.h> > #include <linux/interrupt.h> > #include <linux/kernel.h> > #include <linux/mailbox_client.h> > @@ -21,6 +22,7 @@ > #include <linux/reboot.h> > #include <linux/regmap.h> > #include <linux/remoteproc.h> > +#include <linux/scmi_imx_protocol.h> > #include <linux/workqueue.h> > > #include "imx_rproc.h" > @@ -91,6 +93,11 @@ struct imx_rproc_mem { > #define ATT_CORE_MASK 0xffff > #define ATT_CORE(I) BIT((I)) > > +/* Logical Machine Operation */ > +#define IMX_RPROC_FLAGS_SM_LMM_OP BIT(0) > +/* Linux has permission to handle the Logical Machine of remote cores */ > +#define IMX_RPROC_FLAGS_SM_LMM_AVAIL BIT(1) > + > static int imx_rproc_xtr_mbox_init(struct rproc *rproc, bool tx_block); > static void imx_rproc_free_mbox(struct rproc *rproc); > > @@ -115,6 +122,8 @@ struct imx_rproc { > u32 entry; /* cpu start address */ > u32 core_index; > struct dev_pm_domain_list *pd_list; > + /* For i.MX System Manager based systems */ > + u32 flags; > }; > > static const struct imx_rproc_att imx_rproc_att_imx93[] = { > @@ -393,6 +402,30 @@ static int imx_rproc_start(struct rproc *rproc) > case IMX_RPROC_SCU_API: > ret = imx_sc_pm_cpu_start(priv->ipc_handle, priv->rsrc_id, true, priv->entry); > break; > + case IMX_RPROC_SM: > + if (priv->flags & IMX_RPROC_FLAGS_SM_LMM_OP) { > + if (!(priv->flags & IMX_RPROC_FLAGS_SM_LMM_AVAIL)) > + return -EACCES; > + > + ret = scmi_imx_lmm_reset_vector_set(dcfg->lmid, dcfg->cpuid, 0, 0); > + if (ret) { > + dev_err(dev, "Failed to set reset vector lmid(%u), cpuid(%u): %d\n", > + dcfg->lmid, dcfg->cpuid, ret); > + } > + > + ret = scmi_imx_lmm_operation(dcfg->lmid, SCMI_IMX_LMM_BOOT, 0); > + if (ret) > + dev_err(dev, "Failed to boot lmm(%d): %d\n", ret, dcfg->lmid); > + } else { > + ret = scmi_imx_cpu_reset_vector_set(dcfg->cpuid, 0, true, false, false); > + if (ret) { > + dev_err(dev, "Failed to set reset vector cpuid(%u): %d\n", > + dcfg->cpuid, ret); > + } > + > + ret = scmi_imx_cpu_start(dcfg->cpuid, true); > + } > + break; > default: > return -EOPNOTSUPP; > } > @@ -435,6 +468,16 @@ static int imx_rproc_stop(struct rproc *rproc) > case IMX_RPROC_SCU_API: > ret = imx_sc_pm_cpu_start(priv->ipc_handle, priv->rsrc_id, false, priv->entry); > break; > + case IMX_RPROC_SM: > + if (priv->flags & IMX_RPROC_FLAGS_SM_LMM_OP) { > + if (priv->flags & IMX_RPROC_FLAGS_SM_LMM_AVAIL) > + ret = scmi_imx_lmm_operation(dcfg->lmid, SCMI_IMX_LMM_SHUTDOWN, 0); > + else > + ret = -EACCES; > + } else { > + ret = scmi_imx_cpu_start(dcfg->cpuid, false); > + } > + break; > default: > return -EOPNOTSUPP; > } > @@ -549,9 +592,11 @@ static int imx_rproc_prepare(struct rproc *rproc) > { > struct imx_rproc *priv = rproc->priv; > struct device_node *np = priv->dev->of_node; > + const struct imx_rproc_dcfg *dcfg = priv->dcfg; > struct of_phandle_iterator it; > struct rproc_mem_entry *mem; > struct reserved_mem *rmem; > + int ret; > u32 da; > > /* Register associated reserved memory regions */ > @@ -592,6 +637,38 @@ static int imx_rproc_prepare(struct rproc *rproc) > rproc_add_carveout(rproc, mem); > } > > + switch (dcfg->method) { > + case IMX_RPROC_SM: > + if (!(priv->flags & IMX_RPROC_FLAGS_SM_LMM_OP)) > + break; > + /* > + * Power on the Logical Machine to make sure TCM is available. > + * Also serve as permission check. If in different Logical > + * Machine, and linux has permission to handle the Logical > + * Machine, set IMX_RPROC_FLAGS_SM_LMM_AVAIL. > + */ > + ret = scmi_imx_lmm_operation(dcfg->lmid, SCMI_IMX_LMM_POWER_ON, 0); > + if (ret == 0) { > + dev_info(priv->dev, "lmm(%d) powered on\n", dcfg->lmid); > + priv->flags |= IMX_RPROC_FLAGS_SM_LMM_AVAIL; > + } else if (ret == -EACCES) { > + dev_info(priv->dev, "lmm(%d) not under Linux Control\n", dcfg->lmid); > + /* > + * If remote cores boots up in detached mode, continue; > + * else linux has no permission, return -EACCES. > + */ > + if (priv->rproc->state != RPROC_DETACHED) > + return -EACCES; > + } else if (ret) { > + dev_err(priv->dev, "Failed to power on lmm(%d): %d\n", ret, dcfg->lmid); > + return ret; > + } > + > + break; > + default: > + break; > + }; > + > return 0; > } > > @@ -911,13 +988,41 @@ static int imx_rproc_detect_mode(struct imx_rproc *priv) > struct regmap_config config = { .name = "imx-rproc" }; > const struct imx_rproc_dcfg *dcfg = priv->dcfg; > struct device *dev = priv->dev; > + struct scmi_imx_lmm_info info; > struct regmap *regmap; > struct arm_smccc_res res; > + bool started = false; > int ret; > u32 val; > u8 pt; > > switch (dcfg->method) { > + case IMX_RPROC_SM: > + /* Get current Linux Logical Machine ID */ > + ret = scmi_imx_lmm_info(LMM_ID_DISCOVER, &info); > + if (ret) { > + dev_err(dev, "Failed to get current LMM ID err: %d\n", ret); > + return ret; > + } > + > + /* > + * Check whether remote processor is in same Logical Machine as Linux. > + * If no, need use Logical Machine API to manage remote processor, and > + * set IMX_RPROC_FLAGS_SM_LMM_OP. > + * If yes, use CPU protocol API to manage remote processor. > + */ > + if (dcfg->lmid != info.lmid) { > + priv->flags |= IMX_RPROC_FLAGS_SM_LMM_OP; > + dev_info(dev, "Using LMM Protocol OPS\n"); > + } else { > + dev_info(dev, "Using CPU Protocol OPS\n"); > + } > + > + scmi_imx_cpu_started(dcfg->cpuid, &started); > + if (started) > + priv->rproc->state = RPROC_DETACHED; > + > + return 0; > case IMX_RPROC_NONE: > priv->rproc->state = RPROC_DETACHED; > return 0; > @@ -1029,8 +1134,12 @@ 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) > + /* > + * IMX_RPROC_NONE indicates not under control of Linux. > + * System Manager(SM) firmware automatically configures clock, > + * so bypass the clk settings for IMX_RPROC_SM. > + */ > + if (dcfg->method == IMX_RPROC_NONE || dcfg->method == IMX_RPROC_SM) > return 0; > > priv->clk = devm_clk_get(dev, NULL); > diff --git a/drivers/remoteproc/imx_rproc.h b/drivers/remoteproc/imx_rproc.h > index cfd38d37e1467d1d9e6f89be146c0b53262b92a0..6fe8d975ed302967f27b7a4319a899e6f0822976 100644 > --- a/drivers/remoteproc/imx_rproc.h > +++ b/drivers/remoteproc/imx_rproc.h > @@ -26,6 +26,8 @@ enum imx_rproc_method { > IMX_RPROC_SCU_API, > /* Through Reset Controller API */ > IMX_RPROC_RESET_CONTROLLER, > + /* Through System Manager */ > + IMX_RPROC_SM, > }; > > /* dcfg flags */ > @@ -42,6 +44,9 @@ struct imx_rproc_dcfg { > size_t att_size; > enum imx_rproc_method method; > u32 flags; > + /* For System Manager(SM) based SoCs, the IDs are from SM firmware */ > + u32 cpuid; > + u32 lmid; > }; > > #endif /* _IMX_RPROC_H */ > > -- > 2.37.1 >
© 2016 - 2025 Red Hat, Inc.