Skip to contentSkip to conversation

remoteproc: support i.MX95

PATCH New Peng Fan (OSS) 1 participant 5 messages Feb 2

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover remoteproc: support i.MX95

Support i.MX95 remoteproc. i.MX95 use SCMI Vendor protocol to manage remote cores.

There are three cases for M7:
(1) M7 in a separate Logical Machine(LM) that Linux couldn't control it.
(2) M7 in a separate Logical Machine that Linux could control it using LMM protocol
(3) M7 runs in same Logical Machine as A55, so Linux could control it using CPU protocol

And because needs to do ECC initialization, patch 1 introduces a new flag ATT_ECC to indicate whether the area needs to be cleared for ECC initialization

In patch 2:
The current setup only targets for (2) and (3) to let U-Boot start CM7. Need to 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. 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_is_running, use scmi_imx_cpu_started to check the status of M7.
- For above case (2), Use scmi_imx_lmm_power_boot 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.

patch 3 and 4 is for enabling remoteproc for i.MX95 EVK. The compatible string is in linux-next tree, after it was added to linux upstream imx95.dtsi, we could remove the changes in patch 3 in future.

CI build pass.

---
Changes in v2:
- Moved the config option to defconfig in patch 4
- Updated doc in patch 4
- Explained adding node in imx95-u-boot.dtsi in patch 3 commit log.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Peng Fan (4):
remoteproc: imx: Support ECC initialization
remoteproc: imx: Add i.MX95 support
arm: dts: imx95: Add cm7 node
imx95_evk: Enable remoteproc for i.MX95 EVK

 arch/arm/dts/imx95-u-boot.dtsi    |   4 +
 configs/imx95_15x15_evk_defconfig |   4 +
 configs/imx95_evk.config          |   4 +
 doc/board/nxp/rproc.rst           |  13 +++
 drivers/remoteproc/imx_rproc.c    | 189 +++++++++++++++++++++++++++++++++++++-
 drivers/remoteproc/imx_rproc.h    |   3 +
 6 files changed, 212 insertions(+), 5 deletions(-)

---
base-commit: 6a1bdb7e952d5841f42742fefa907cae5dc8d50a
change-id: 20260129-imx95-rproc-b1b65c8b54cb

Best regards,

Signature · 1 line
Peng Fan <[email protected]>
#1 lore raw

PATCH v2 1/4 remoteproc: imx: Support ECC initialization

From: Peng Fan <[email protected]>

Add a new flag ATT_ECC which indicates the memory region needs ECC initialization. If the flag is set, clearing the whole memory region to initialize ECC. If ECC is not initialized, remote core will crash if directly access the area.

---
 drivers/remoteproc/imx_rproc.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/remoteproc/imx_rproc.c +21 -0
index 9bb55327998..9eecbe70f0b 100644
@@ -46,6 +46,7 @@ struct imx_rproc {
 /* M4 own area. Can be mapped at probe */
 #define ATT_OWN         BIT(31)
 #define ATT_IOMEM       BIT(30)
+#define ATT_ECC         BIT(29)
 
 static int imx_rproc_arm_smc_start(struct udevice *dev)
 {
@@ -202,6 +203,26 @@ static void *imx_rproc_device_to_virt(struct udevice *dev, ulong da, ulong size,
 
 static int imx_rproc_load(struct udevice *dev, ulong addr, ulong size)
 {
+	struct imx_rproc *priv = dev_get_priv(dev);
+	const struct imx_rproc_dcfg *dcfg = priv->dcfg;
+	int i;
+
+	/*
+	 * Before loading elf, need do ECC initialization by clearing the memory
+	 * region, if ATT_ECC is set.
+	 */
+	for (i = 0; i < dcfg->att_size; i++) {
+		const struct imx_rproc_att *att = &dcfg->att[i];
+
+		if (!(att->flags & ATT_ECC))
+			continue;
+
+		if (att->flags & ATT_IOMEM)
+			memset_io((void __iomem *)(long)att->sa, 0, att->size);
+		else
+			memset((void *)(long)att->sa, 0, att->size);
+	}
+
 	return rproc_elf_load_image(dev, addr, size);
 }
 
Signature · 1 line
2.51.0
#2 lore raw

PATCH v2 2/4 remoteproc: imx: Add i.MX95 support

In reply to Peng Fan (OSS)

From: Peng Fan <[email protected]>

i.MX95 uses System Manager(sm) API to start/stop logical machine or cpu. There are two modes:
M7 in a dedicated logical machine, use LMM API
M7 and A55 in same logical machine, use CPU API

Extend the driver to using LMM and CPU protocol to manage the M7 core:
- Detect using LMM or CPU API in probe using API scmi_imx_lmm_info().
- 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. 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_is_running, use scmi_imx_cpu_started to check the status of M7.
- For above case (2), Use scmi_imx_lmm_power_boot 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.
- Add a new ops imx_rproc_ops_sm.

---
 drivers/remoteproc/imx_rproc.c | 168 +++++++++++++++++++++++++++++++++++++++--
 drivers/remoteproc/imx_rproc.h |   3 +
 2 files changed, 166 insertions(+), 5 deletions(-)
drivers/remoteproc/imx_rproc.c +163 -5
index 9eecbe70f0b..3f8cea127ec 100644
@@ -11,6 +11,7 @@
 #include <linux/types.h>
 #include <regmap.h>
 #include <remoteproc.h>
+#include <scmi_nxp_protocols.h>
 #include <syscon.h>
 
 #include "imx_rproc.h"
@@ -37,9 +38,25 @@
 #define IMX_SIP_RPROC_STARTED		0x01
 #define IMX_SIP_RPROC_STOP		0x02
 
+/* Must align with System Manager Firmware */
+#define IMX95_M7_CPUID			1
+#define IMX95_M7_LMID			1
+
+/* Logical Machine API Operation */
+#define IMX_RPROC_FLAGS_SM_LMM_OP	BIT(0)
+/* CPU API Operation */
+#define IMX_RPROC_FLAGS_SM_CPU_OP	BIT(1)
+/* Linux has permission to handle the Logical Machine of remote cores */
+#define IMX_RPROC_FLAGS_SM_LMM_AVAIL	BIT(2)
+
 struct imx_rproc {
 	const struct imx_rproc_dcfg	*dcfg;
 	struct regmap *regmap;
+	u32				flags;
+	/* For System Manager based system */
+	struct udevice			*lmm_dev;
+	struct udevice			*cpu_dev;
+	ulong				reset_vector;
 };
 
 /* att flags: lower 16 bits specifying core, higher 16 bits for flags  */
@@ -65,6 +82,41 @@ static int imx_rproc_mmio_start(struct udevice *dev)
 	return regmap_update_bits(priv->regmap, dcfg->src_reg, dcfg->src_mask, dcfg->src_start);
 }
 
+static int imx_rproc_sm_start(struct udevice *dev)
+{
+	struct imx_rproc *priv = dev_get_priv(dev);
+	const struct imx_rproc_dcfg *dcfg = priv->dcfg;
+	int ret;
+
+	if (priv->flags & IMX_RPROC_FLAGS_SM_CPU_OP) {
+		ret = scmi_imx_cpu_reset_vector_set(priv->cpu_dev, dcfg->cpuid, 0,
+						    priv->reset_vector, true, false, false);
+		if (ret) {
+			dev_err(dev, "Failed to set reset vector cpuid(%u): %d\n",
+				dcfg->cpuid, ret);
+			return ret;
+		}
+
+		return scmi_imx_cpu_start(priv->cpu_dev, dcfg->cpuid, true);
+	}
+
+	ret = scmi_imx_lmm_reset_vector_set(priv->lmm_dev, dcfg->lmid, dcfg->cpuid, 0,
+					    priv->reset_vector);
+	if (ret) {
+		dev_err(dev, "Failed to set reset vector lmid(%u), cpuid(%u): %d\n",
+			dcfg->lmid, dcfg->cpuid, ret);
+		return ret;
+	}
+
+	ret = scmi_imx_lmm_power_boot(priv->lmm_dev, dcfg->lmid, true);
+	if (ret) {
+		dev_err(dev, "Failed to boot lmm(%d): %d\n", ret, dcfg->lmid);
+		return ret;
+	}
+
+	return 0;
+}
+
 static int imx_rproc_start(struct udevice *dev)
 {
 	struct imx_rproc *priv = dev_get_priv(dev);
@@ -100,6 +152,17 @@ static int imx_rproc_mmio_stop(struct udevice *dev)
 	return regmap_update_bits(priv->regmap, dcfg->src_reg, dcfg->src_mask, dcfg->src_stop);
 }
 
+static int imx_rproc_sm_stop(struct udevice *dev)
+{
+	struct imx_rproc *priv = dev_get_priv(dev);
+	const struct imx_rproc_dcfg *dcfg = priv->dcfg;
+
+	if (priv->flags & IMX_RPROC_FLAGS_SM_CPU_OP)
+		return scmi_imx_cpu_start(priv->cpu_dev, dcfg->cpuid, false);
+
+	return scmi_imx_lmm_shutdown(priv->lmm_dev, dcfg->lmid, 0);
+}
+
 static int imx_rproc_stop(struct udevice *dev)
 {
 	struct imx_rproc *priv = dev_get_priv(dev);
@@ -146,6 +209,20 @@ static int imx_rproc_mmio_is_running(struct udevice *dev)
 	return 1;
 }
 
+static int imx_rproc_sm_is_running(struct udevice *dev)
+{
+	struct imx_rproc *priv = dev_get_priv(dev);
+	const struct imx_rproc_dcfg *dcfg = priv->dcfg;
+	int ret;
+	bool started = false;
+
+	ret = scmi_imx_cpu_started(priv->cpu_dev, dcfg->cpuid, &started);
+	if (ret || !started)
+		return 1;
+
+	return 0;
+}
+
 static int imx_rproc_is_running(struct udevice *dev)
 {
 	struct imx_rproc *priv = dev_get_priv(dev);
@@ -207,6 +284,14 @@ static int imx_rproc_load(struct udevice *dev, ulong addr, ulong size)
 	const struct imx_rproc_dcfg *dcfg = priv->dcfg;
 	int i;
 
+	if (IS_ENABLED(CONFIG_IMX_SM_LMM)) {
+		if (!(priv->flags & (IMX_RPROC_FLAGS_SM_LMM_AVAIL | IMX_RPROC_FLAGS_SM_CPU_OP)))
+			return -EACCES;
+	}
+
+	/* Only used for SM based System */
+	priv->reset_vector = rproc_elf_get_boot_addr(dev, addr) & GENMASK(31, 16);
+
 	/*
 	 * Before loading elf, need do ECC initialization by clearing the memory
 	 * region, if ATT_ECC is set.
@@ -239,19 +324,65 @@ static int imx_rproc_probe(struct udevice *dev)
 {
 	struct imx_rproc *priv = dev_get_priv(dev);
 	struct imx_rproc_dcfg *dcfg = (struct imx_rproc_dcfg *)dev_get_driver_data(dev);
+	struct scmi_imx_lmm_info info;
 	ofnode node;
+	int ret;
 
 	node = dev_ofnode(dev);
 
 	priv->dcfg = dcfg;
 
-	if (dcfg->method != IMX_RPROC_MMIO)
+	if (dcfg->method == IMX_RPROC_MMIO) {
+		priv->regmap = syscon_regmap_lookup_by_phandle(dev, "syscon");
+		if (IS_ERR(priv->regmap)) {
+			dev_err(dev, "No syscon: %ld\n", PTR_ERR(priv->regmap));
+			return PTR_ERR(priv->regmap);
+		}
 		return 0;
+	} else {
+		if (IS_ENABLED(CONFIG_IMX_SM_LMM)) {
+			struct udevice *lmm_dev;
+
+			ret = uclass_get_device_by_name(UCLASS_SCMI_BASE, "protocol@80", &lmm_dev);
+			if (ret) {
+				dev_err(dev, "Failed to get SM LMM protocol dev\n");
+				return ret;
+			}
+
+			priv->lmm_dev = lmm_dev;
+
+			ret = scmi_imx_lmm_info(lmm_dev, LMM_ID_DISCOVER, &info);
+			if (ret) {
+				dev_err(dev, "Failed to get lmm info\n");
+				return ret;
+			}
+
+			if (dcfg->lmid != info.lmid) {
+				ret = scmi_imx_lmm_power_boot(lmm_dev, dcfg->lmid, false);
+				if (ret == -EACCES) {
+					dev_err(dev, "Remoteproc not under U-boot control: only support detect running\n");
+				} else if (ret) {
+					dev_err(dev, "power on lmm fail:%d\n", ret);
+					return ret;
+				} else {
+					priv->flags |= IMX_RPROC_FLAGS_SM_LMM_AVAIL;
+				}
+			} else {
+				priv->flags |= IMX_RPROC_FLAGS_SM_CPU_OP;
+			}
+		}
+
+		if (IS_ENABLED(CONFIG_IMX_SM_CPU)) {
+			struct udevice *cpu_dev;
 
-	priv->regmap = syscon_regmap_lookup_by_phandle(dev, "syscon");
-	if (IS_ERR(priv->regmap)) {
-		dev_err(dev, "No syscon: %ld\n", PTR_ERR(priv->regmap));
-		return PTR_ERR(priv->regmap);
+			ret = uclass_get_device_by_name(UCLASS_SCMI_BASE, "protocol@82", &cpu_dev);
+			if (ret) {
+				dev_err(dev, "Failed to get SM LMM protocol dev\n");
+				return ret;
+			}
+
+			priv->cpu_dev = cpu_dev;
+		}
 	}
 
 	return 0;
@@ -372,12 +503,39 @@ static const struct imx_rproc_dcfg imx_rproc_cfg_imx93 = {
 	.ops		= &imx_rproc_ops_arm_smc,
 };
 
+static const struct imx_rproc_att imx_rproc_att_imx95_m7[] = {
+	/* dev addr , sys addr  , size	    , flags */
+	/* TCM CODE NON-SECURE */
+	{ 0x00000000, 0x203C0000, 0x00040000, ATT_OWN | ATT_IOMEM | ATT_ECC },
+
+	/* TCM SYS NON-SECURE*/
+	{ 0x20000000, 0x20400000, 0x00040000, ATT_OWN | ATT_IOMEM | ATT_ECC },
+
+	/* DDR */
+	{ 0x80000000, 0x80000000, 0x50000000, 0 },
+};
+
+static const struct imx_rproc_plat_ops imx_rproc_ops_sm = {
+	.start		= imx_rproc_sm_start,
+	.stop		= imx_rproc_sm_stop,
+	.is_running	= imx_rproc_sm_is_running,
+};
+
+static const struct imx_rproc_dcfg imx_rproc_cfg_imx95_m7 = {
+	.att		= imx_rproc_att_imx95_m7,
+	.att_size	= ARRAY_SIZE(imx_rproc_att_imx95_m7),
+	.ops		= &imx_rproc_ops_sm,
+	.cpuid		= IMX95_M7_CPUID,
+	.lmid		= IMX95_M7_LMID,
+};
+
 static const struct udevice_id imx_rproc_ids[] = {
 	{ .compatible = "fsl,imx8mm-cm4", .data = (ulong)&imx_rproc_cfg_imx8mq },
 	{ .compatible = "fsl,imx8mn-cm7", .data = (ulong)&imx_rproc_cfg_imx8mn, },
 	{ .compatible = "fsl,imx8mp-cm7", .data = (ulong)&imx_rproc_cfg_imx8mn, },
 	{ .compatible = "fsl,imx8mq-cm4", .data = (ulong)&imx_rproc_cfg_imx8mq },
 	{ .compatible = "fsl,imx93-cm33", .data = (ulong)&imx_rproc_cfg_imx93 },
+	{ .compatible = "fsl,imx95-cm7", .data = (ulong)&imx_rproc_cfg_imx95_m7 },
 	{}
 };
 
drivers/remoteproc/imx_rproc.h +3 -0
index 7a82dc4a195..1629bc7f6e7 100644
@@ -51,6 +51,9 @@ struct imx_rproc_dcfg {
 	enum imx_rproc_method		method;
 	u32				flags;
 	const struct imx_rproc_plat_ops	*ops;
+	/* For System Manager(SM) based SoCs, the IDs are from SM firmware */
+	u32				cpuid;
+	u32				lmid;
 };
 
 #endif /* _IMX_RPROC_H */
Signature · 1 line
2.51.0
#3 lore raw

PATCH v2 3/4 arm: dts: imx95: Add cm7 node

In reply to Peng Fan (OSS)

From: Peng Fan <[email protected]>

Add i.MX95 CM7 node for remoteproc usage. The dt-bindings for CM7 was accepted, by the node has not been upstreamed to Linux device tree.

Put the node here to let the driver probe. After Linux upstream repo has this node landed, the node in imx95-u-boot.dtsi could be removed.

---
 arch/arm/dts/imx95-u-boot.dtsi | 4 ++++
 1 file changed, 4 insertions(+)
arch/arm/dts/imx95-u-boot.dtsi +4 -0
index 591cb317508..6dec159752b 100644
@@ -96,6 +96,10 @@
 			};
 		};
 	};
+
+	imx95-cm7 {
+		compatible = "fsl,imx95-cm7";
+	};
 };
 
 &A55_0 {
Signature · 1 line
2.51.0
#4 lore raw

PATCH v2 4/4 imx95_evk: Enable remoteproc for i.MX95 EVK

In reply to Peng Fan (OSS)

From: Peng Fan <[email protected]>

Select remoteproc related configs for i.MX95 EVK to support manage CM7 using 'rproc' cmd.
Update doc to show details on starting CM7 using rproc cmd.

---
 configs/imx95_15x15_evk_defconfig |  4 ++++
 configs/imx95_evk.config          |  4 ++++
 doc/board/nxp/rproc.rst           | 13 +++++++++++++
 3 files changed, 21 insertions(+)
configs/imx95_15x15_evk_defconfig +4 -0
index f3099f14401..11d91e25c3c 100644
@@ -71,6 +71,7 @@ CONFIG_CMD_I2C=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_PCI=y
 CONFIG_CMD_POWEROFF=y
+CONFIG_CMD_REMOTEPROC=y
 CONFIG_CMD_SNTP=y
 CONFIG_CMD_CACHE=y
 CONFIG_CMD_EFIDEBUG=y
@@ -104,6 +105,8 @@ CONFIG_DFU_MMC=y
 CONFIG_DFU_RAM=y
 CONFIG_SPL_FIRMWARE=y
 # CONFIG_SCMI_AGENT_SMCCC is not set
+CONFIG_IMX_SM_CPU=y
+CONFIG_IMX_SM_LMM=y
 CONFIG_IMX_RGPIO2P=y
 CONFIG_DM_PCA953X=y
 CONFIG_ADP5585_GPIO=y
@@ -137,6 +140,7 @@ CONFIG_SPL_DM_REGULATOR=y
 CONFIG_DM_REGULATOR_FIXED=y
 CONFIG_SPL_DM_REGULATOR_FIXED=y
 CONFIG_DM_REGULATOR_GPIO=y
+CONFIG_REMOTEPROC_IMX=y
 CONFIG_DM_RTC=y
 CONFIG_DM_SERIAL=y
 CONFIG_FSL_LPUART=y
configs/imx95_evk.config +4 -0
index 631ec23c335..a803e61dad4 100644
@@ -69,6 +69,7 @@ CONFIG_CMD_I2C=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_PCI=y
 CONFIG_CMD_POWEROFF=y
+CONFIG_CMD_REMOTEPROC=y
 CONFIG_CMD_SNTP=y
 CONFIG_CMD_CACHE=y
 CONFIG_CMD_EFIDEBUG=y
@@ -105,6 +106,8 @@ CONFIG_DFU_MMC=y
 CONFIG_DFU_RAM=y
 CONFIG_SPL_FIRMWARE=y
 # CONFIG_SCMI_AGENT_SMCCC is not set
+CONFIG_IMX_SM_CPU=y
+CONFIG_IMX_SM_LMM=y
 CONFIG_IMX_RGPIO2P=y
 CONFIG_DM_PCA953X=y
 CONFIG_ADP5585_GPIO=y
@@ -139,6 +142,7 @@ CONFIG_SPL_DM_REGULATOR=y
 CONFIG_DM_REGULATOR_FIXED=y
 CONFIG_SPL_DM_REGULATOR_FIXED=y
 CONFIG_DM_REGULATOR_GPIO=y
+CONFIG_REMOTEPROC_IMX=y
 CONFIG_DM_RTC=y
 CONFIG_DM_SERIAL=y
 CONFIG_FSL_LPUART=y
doc/board/nxp/rproc.rst +13 -0
index b023c1fadf6..7836935bbc7 100644
@@ -67,3 +67,16 @@ corresponding board.
     rproc load 0 0x90000000 ${filesize}
 
     rproc start 0
+
+i.MX95-EVK
+-------------------
+
+Steps to start the Cortex-M7 core, need to choose the correct file for
+corresponding board. The example is for i.MX95 15x15 EVK, use imx95-19x19-evk
+if your board is i.MX95 19x19 EVK.
+
+    load mmc 1:2 ${loadaddr} /lib/firmware/imx95-15x15-evk_m7_TCM_rpmsg_lite_str_echo_rtos.elf
+
+    rproc load 0 ${loadaddr} ${filesize}
+
+    rproc start 0
Signature · 1 line
2.51.0