Skip to content

Commit d8ab94f

Browse files
MrVanmathieupoirier
authored andcommitted
remoteproc: imx_rproc: Add support for System Manager LMM API
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. Depending on SM configuration, M7 can be used as follows: (1) M7 in a separate Logical Machine (LM) from A55 cores, that Linux can't control (2) M7 in a separate LM from A55 cores that Linux can control using LMM protocol. (3) M7 runs in same Logical Machine as A55 cores, so Linux can control it using CPU protocol So extend the driver to using LMM and CPU protocol to manage the M7 core. - 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 separate LM), if Linux LM ID is not same as M7 LM ID(linux and M7 in same LM), use LMM protocol to start/stop. CPU protocol support will be added in the following patch. 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. - For above case , after using SCMI_IMX_LMM_POWER_ON to check permission, SCMI_IMX_LMM_SHUTDOWN API should be called to shutdown the M7 LM to save power only when M7 LM is going to be started by remoteproc framework. Otherwise bypass SCMI_IMX_LMM_SHUTDOWN API if M7 LM is started before booting Linux. 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> Reviewed-by: Frank Li <Frank.Li@nxp.com> Signed-off-by: Peng Fan <peng.fan@nxp.com> Link: https://lore.kernel.org/r/20260109-imx95-rproc-2026-1-8-v6-4-d2fefb36263d@nxp.com Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
1 parent edd2a99 commit d8ab94f

3 files changed

Lines changed: 171 additions & 0 deletions

File tree

drivers/remoteproc/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ config IMX_REMOTEPROC
2727
tristate "i.MX remoteproc support"
2828
depends on ARCH_MXC
2929
depends on HAVE_ARM_SMCCC
30+
depends on IMX_SCMI_CPU_DRV || !IMX_SCMI_CPU_DRV
31+
depends on IMX_SCMI_LMM_DRV || !IMX_SCMI_LMM_DRV
3032
select MAILBOX
3133
help
3234
Say y here to support iMX's remote processors via the remote

drivers/remoteproc/imx_rproc.c

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/clk.h>
99
#include <linux/err.h>
1010
#include <linux/firmware/imx/sci.h>
11+
#include <linux/firmware/imx/sm.h>
1112
#include <linux/interrupt.h>
1213
#include <linux/kernel.h>
1314
#include <linux/mailbox_client.h>
@@ -22,6 +23,7 @@
2223
#include <linux/reboot.h>
2324
#include <linux/regmap.h>
2425
#include <linux/remoteproc.h>
26+
#include <linux/scmi_imx_protocol.h>
2527
#include <linux/workqueue.h>
2628

2729
#include "imx_rproc.h"
@@ -92,9 +94,15 @@ struct imx_rproc_mem {
9294
#define ATT_CORE_MASK 0xffff
9395
#define ATT_CORE(I) BIT((I))
9496

97+
/* Linux has permission to handle the Logical Machine of remote cores */
98+
#define IMX_RPROC_FLAGS_SM_LMM_CTRL BIT(0)
99+
95100
static int imx_rproc_xtr_mbox_init(struct rproc *rproc, bool tx_block);
96101
static void imx_rproc_free_mbox(void *data);
97102

103+
/* Forward declarations for platform operations */
104+
static const struct imx_rproc_plat_ops imx_rproc_ops_sm_lmm;
105+
98106
struct imx_rproc {
99107
struct device *dev;
100108
struct regmap *regmap;
@@ -117,6 +125,11 @@ struct imx_rproc {
117125
u32 core_index;
118126
struct dev_pm_domain_list *pd_list;
119127
const struct imx_rproc_plat_ops *ops;
128+
/*
129+
* For i.MX System Manager based systems
130+
* BIT 0: IMX_RPROC_FLAGS_SM_LMM_CTRL(RPROC LM is under Linux control )
131+
*/
132+
u32 flags;
120133
};
121134

122135
static const struct imx_rproc_att imx_rproc_att_imx93[] = {
@@ -313,6 +326,33 @@ static int imx_rproc_scu_api_start(struct rproc *rproc)
313326
return imx_sc_pm_cpu_start(priv->ipc_handle, priv->rsrc_id, true, priv->entry);
314327
}
315328

329+
static int imx_rproc_sm_lmm_start(struct rproc *rproc)
330+
{
331+
struct imx_rproc *priv = rproc->priv;
332+
const struct imx_rproc_dcfg *dcfg = priv->dcfg;
333+
struct device *dev = priv->dev;
334+
int ret;
335+
336+
/*
337+
* If the remoteproc core can't start the M7, it will already be
338+
* handled in imx_rproc_sm_lmm_prepare().
339+
*/
340+
ret = scmi_imx_lmm_reset_vector_set(dcfg->lmid, dcfg->cpuid, 0, 0);
341+
if (ret) {
342+
dev_err(dev, "Failed to set reset vector lmid(%u), cpuid(%u): %d\n",
343+
dcfg->lmid, dcfg->cpuid, ret);
344+
return ret;
345+
}
346+
347+
ret = scmi_imx_lmm_operation(dcfg->lmid, SCMI_IMX_LMM_BOOT, 0);
348+
if (ret) {
349+
dev_err(dev, "Failed to boot lmm(%d): %d\n", dcfg->lmid, ret);
350+
return ret;
351+
}
352+
353+
return 0;
354+
}
355+
316356
static int imx_rproc_start(struct rproc *rproc)
317357
{
318358
struct imx_rproc *priv = rproc->priv;
@@ -369,6 +409,17 @@ static int imx_rproc_scu_api_stop(struct rproc *rproc)
369409
return imx_sc_pm_cpu_start(priv->ipc_handle, priv->rsrc_id, false, priv->entry);
370410
}
371411

412+
static int imx_rproc_sm_lmm_stop(struct rproc *rproc)
413+
{
414+
struct imx_rproc *priv = rproc->priv;
415+
const struct imx_rproc_dcfg *dcfg = priv->dcfg;
416+
417+
if (!(priv->flags & IMX_RPROC_FLAGS_SM_LMM_CTRL))
418+
return -EACCES;
419+
420+
return scmi_imx_lmm_operation(dcfg->lmid, SCMI_IMX_LMM_SHUTDOWN, 0);
421+
}
422+
372423
static int imx_rproc_stop(struct rproc *rproc)
373424
{
374425
struct imx_rproc *priv = rproc->priv;
@@ -485,6 +536,36 @@ static int imx_rproc_mem_release(struct rproc *rproc,
485536
return 0;
486537
}
487538

539+
static int imx_rproc_sm_lmm_prepare(struct rproc *rproc)
540+
{
541+
struct imx_rproc *priv = rproc->priv;
542+
const struct imx_rproc_dcfg *dcfg = priv->dcfg;
543+
int ret;
544+
545+
/*
546+
* IMX_RPROC_FLAGS_SM_LMM_CTRL not set indicates Linux is not able
547+
* to start/stop M7, then if rproc is not in detached state,
548+
* prepare should fail. If in detached state, this is in rproc_attach()
549+
* path.
550+
*/
551+
if (rproc->state == RPROC_DETACHED)
552+
return 0;
553+
554+
if (!(priv->flags & IMX_RPROC_FLAGS_SM_LMM_CTRL))
555+
return -EACCES;
556+
557+
/* Power on the Logical Machine to make sure TCM is available. */
558+
ret = scmi_imx_lmm_operation(dcfg->lmid, SCMI_IMX_LMM_POWER_ON, 0);
559+
if (ret) {
560+
dev_err(priv->dev, "Failed to power on lmm(%d): %d\n", dcfg->lmid, ret);
561+
return ret;
562+
}
563+
564+
dev_info(priv->dev, "lmm(%d) powered on by Linux\n", dcfg->lmid);
565+
566+
return 0;
567+
}
568+
488569
static int imx_rproc_prepare(struct rproc *rproc)
489570
{
490571
struct imx_rproc *priv = rproc->priv;
@@ -980,6 +1061,84 @@ static int imx_rproc_scu_api_detect_mode(struct rproc *rproc)
9801061
return 0;
9811062
}
9821063

1064+
/* Check whether remoteproc core is responsible for M7 lifecycle */
1065+
static int imx_rproc_sm_lmm_check(struct rproc *rproc, bool started)
1066+
{
1067+
struct imx_rproc *priv = rproc->priv;
1068+
const struct imx_rproc_dcfg *dcfg = priv->dcfg;
1069+
struct device *dev = priv->dev;
1070+
int ret;
1071+
1072+
ret = scmi_imx_lmm_operation(dcfg->lmid, SCMI_IMX_LMM_POWER_ON, 0);
1073+
if (ret) {
1074+
if (ret == -EACCES) {
1075+
/*
1076+
* M7 is booted before Linux and not under Linux Control, so only
1077+
* do IPC between RPROC and Linux, not return failure
1078+
*/
1079+
dev_info(dev, "lmm(%d) not under Linux Control\n", dcfg->lmid);
1080+
return 0;
1081+
}
1082+
1083+
dev_err(dev, "power on lmm(%d) failed: %d\n", dcfg->lmid, ret);
1084+
return ret;
1085+
}
1086+
1087+
/* Shutdown remote processor if not started */
1088+
if (!started) {
1089+
ret = scmi_imx_lmm_operation(dcfg->lmid, SCMI_IMX_LMM_SHUTDOWN, 0);
1090+
if (ret) {
1091+
dev_err(dev, "shutdown lmm(%d) failed: %d\n", dcfg->lmid, ret);
1092+
return ret;
1093+
}
1094+
}
1095+
1096+
priv->flags |= IMX_RPROC_FLAGS_SM_LMM_CTRL;
1097+
1098+
return 0;
1099+
}
1100+
1101+
static int imx_rproc_sm_detect_mode(struct rproc *rproc)
1102+
{
1103+
struct imx_rproc *priv = rproc->priv;
1104+
const struct imx_rproc_dcfg *dcfg = priv->dcfg;
1105+
struct device *dev = priv->dev;
1106+
struct scmi_imx_lmm_info info;
1107+
bool started = false;
1108+
int ret;
1109+
1110+
ret = scmi_imx_cpu_started(dcfg->cpuid, &started);
1111+
if (ret) {
1112+
dev_err(dev, "Failed to detect cpu(%d) status: %d\n", dcfg->cpuid, ret);
1113+
return ret;
1114+
}
1115+
1116+
if (started)
1117+
priv->rproc->state = RPROC_DETACHED;
1118+
1119+
/* Get current Linux Logical Machine ID */
1120+
ret = scmi_imx_lmm_info(LMM_ID_DISCOVER, &info);
1121+
if (ret) {
1122+
dev_err(dev, "Failed to get current LMM ID err: %d\n", ret);
1123+
return ret;
1124+
}
1125+
1126+
/*
1127+
* Check whether M7 is in the same LM as host core(running Linux)
1128+
* If yes, use CPU protocol API to manage M7.
1129+
* If no, use Logical Machine API to manage M7.
1130+
*/
1131+
if (dcfg->lmid == info.lmid) {
1132+
dev_err(dev, "CPU Protocol OPS is not supported\n");
1133+
return -EOPNOTSUPP;
1134+
}
1135+
1136+
priv->ops = &imx_rproc_ops_sm_lmm;
1137+
dev_info(dev, "Using LMM Protocol OPS\n");
1138+
1139+
return imx_rproc_sm_lmm_check(rproc, started);
1140+
}
1141+
9831142
static int imx_rproc_detect_mode(struct imx_rproc *priv)
9841143
{
9851144
/*
@@ -1155,6 +1314,13 @@ static const struct imx_rproc_plat_ops imx_rproc_ops_scu_api = {
11551314
.detect_mode = imx_rproc_scu_api_detect_mode,
11561315
};
11571316

1317+
static const struct imx_rproc_plat_ops imx_rproc_ops_sm_lmm = {
1318+
.detect_mode = imx_rproc_sm_detect_mode,
1319+
.prepare = imx_rproc_sm_lmm_prepare,
1320+
.start = imx_rproc_sm_lmm_start,
1321+
.stop = imx_rproc_sm_lmm_stop,
1322+
};
1323+
11581324
static const struct imx_rproc_dcfg imx_rproc_cfg_imx8mn_mmio = {
11591325
.src_reg = IMX7D_SRC_SCR,
11601326
.src_mask = IMX7D_M4_RST_MASK,

drivers/remoteproc/imx_rproc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ struct imx_rproc_dcfg {
3838
size_t att_size;
3939
u32 flags;
4040
const struct imx_rproc_plat_ops *ops;
41+
/* For System Manager(SM) based SoCs */
42+
u32 cpuid; /* ID of the remote core */
43+
u32 lmid; /* ID of the Logcial Machine */
4144
};
4245

4346
#endif /* _IMX_RPROC_H */

0 commit comments

Comments
 (0)