Skip to contentSkip to conversation

Add support for MT8195 SCP 2nd core

PATCH Superseded Tinghan Shen 4 participants 22 messages Jun 8, 2022 – Sep 23, 2022 1 message not in the archive

Subsystems (5)

v2 of 17 Superseded Latest is v17 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add support for MT8195 SCP 2nd core

The mediatek remoteproc driver currently only allows bringing up a single core SCP, e.g. MT8183. It also only bringing up the 1st core in SoCs with a dual-core SCP, e.g. MT8195. This series support to bring-up the 2nd core of the dual-core SCP.

Tinghan Shen (9):
dt-binding: remoteproc: mediatek: Support dual-core SCP
remoteproc: mediatek: Support hanlding scp core 1 wdt timeout
remoteproc: mediatek: Add SCP core 1 register definitions
remoteproc: mediatek: Support probing for the 2nd core of dual-core
SCP
remoteproc: mediatek: Add chip dependent operations for SCP core 1
remoteproc: mediatek: Add SCP core 1 SRAM offset
remoteproc: mediatek: Add SCP core 1 as a rproc subdevice
remoteproc: mediatek: Wait SCP core 1 probe done
mfd: cros_ec: Add SCP core 1 as a new CrOS EC MCU

 .../bindings/remoteproc/mtk,scp.yaml          |  13 +
 drivers/mfd/cros_ec_dev.c                     |   5 +
 drivers/remoteproc/mtk_common.h               |  35 ++
 drivers/remoteproc/mtk_scp.c                  | 322 +++++++++++++++++-
 .../linux/platform_data/cros_ec_commands.h    |   2 +
 include/linux/platform_data/cros_ec_proto.h   |   1 +
 6 files changed, 375 insertions(+), 3 deletions(-)
Signature · 1 line
2.18.0
#1 lore raw

PATCH v2 1/9 dt-binding: remoteproc: mediatek: Support dual-core SCP

The MT8195 SCP co-processor is a dual-core RISC-V MCU.

Add a new property to reference the sibling core and to assign core id to SCP nodes. Also add a new compatile for the driver of SCP 2nd core.

---
 .../devicetree/bindings/remoteproc/mtk,scp.yaml     | 13 +++++++++++++
 1 file changed, 13 insertions(+)
Documentation/devicetree/bindings/remoteproc/mtk,scp.yaml +13 -0
index eec3b9c4c713..4576ff9b1f2d 100644
@@ -20,6 +20,7 @@ properties:
       - mediatek,mt8186-scp
       - mediatek,mt8192-scp
       - mediatek,mt8195-scp
+      - mediatek,mt8195-scp-dual
 
   reg:
     description:
@@ -57,6 +58,17 @@ properties:
   memory-region:
     maxItems: 1
 
+  mediatek,scp-core:
+    $ref: "/schemas/types.yaml#/definitions/phandle-array"
+    description:
+      Reference to the sibling SCP core. This is required to
+      enable support for dual-core SCP.
+    items:
+      - items:
+          - description: Phandle of sibling SCP node.
+          - description: Core id of this SCP node
+            enum: [0, 1]
+
 required:
   - compatible
   - reg
@@ -115,6 +127,7 @@ examples:
         reg-names = "sram", "cfg", "l1tcm";
         clocks = <&infracfg CLK_INFRA_SCPSYS>;
         clock-names = "main";
+        mediatek,scp-core = <&scp_dual 0>;
 
         cros_ec {
             mediatek,rpmsg-name = "cros-ec-rpmsg";
Signature · 1 line
2.18.0
maintainer Reviewed-by on v2 1/9
#2 lore raw

Re: [PATCH v2 1/9] dt-binding: remoteproc: mediatek: Support dual-core SCP

Quoted 11 lines · Tinghan Shen

The MT8195 SCP co-processor is a dual-core RISC-V MCU.

Add a new property to reference the sibling core and to assign core id to SCP nodes. Also add a new compatile for the driver of SCP 2nd core.

---
 .../devicetree/bindings/remoteproc/mtk,scp.yaml     | 13 +++++++++++++
 1 file changed, 13 insertions(+)
#3 lore raw

PATCH v2 2/9 remoteproc: mediatek: Support hanlding scp core 1 wdt timeout

In reply to Tinghan Shen

MT8195 SCP is a dual-core processor. The SCP core 1 watchdog timeout interrupt uses the same interrupt line of SCP core 0 watchdog timeout interrupt.

Add support for handling SCP core 1 watchdog timeout interrupt in the SCP IRQ handler.

---
 drivers/remoteproc/mtk_common.h |  4 ++++
 drivers/remoteproc/mtk_scp.c    | 27 ++++++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 1 deletion(-)
drivers/remoteproc/mtk_common.h +4 -0
index ea6fa1100a00..73e8adf00de3 100644
@@ -54,6 +54,10 @@
 #define MT8192_CORE0_WDT_IRQ		0x10030
 #define MT8192_CORE0_WDT_CFG		0x10034
 
+#define MT8195_SYS_STATUS		0x4004
+#define MT8195_CORE0_WDT		BIT(16)
+#define MT8195_CORE1_WDT		BIT(17)
+
 #define MT8195_L1TCM_SRAM_PDN_RESERVED_RSI_BITS		GENMASK(7, 4)
 
 #define SCP_FW_VER_LEN			32
drivers/remoteproc/mtk_scp.c +26 -1
index 47b2a40e1b4a..3510c6d0bbc8 100644
@@ -212,6 +212,31 @@ static void mt8192_scp_irq_handler(struct mtk_scp *scp)
 	}
 }
 
+static void mt8195_scp_irq_handler(struct mtk_scp *scp)
+{
+	u32 scp_to_host;
+
+	scp_to_host = readl(scp->reg_base + MT8192_SCP2APMCU_IPC_SET);
+
+	if (scp_to_host & MT8192_SCP_IPC_INT_BIT) {
+		scp_ipi_handler(scp);
+
+		/*
+		 * SCP won't send another interrupt until we clear
+		 * MT8192_SCP2APMCU_IPC.
+		 */
+		writel(MT8192_SCP_IPC_INT_BIT,
+		       scp->reg_base + MT8192_SCP2APMCU_IPC_CLR);
+	} else {
+		if (readl(scp->reg_base + MT8195_SYS_STATUS) & MT8195_CORE1_WDT) {
+			writel(1, scp->reg_base + MT8195_CORE1_WDT_IRQ);
+		} else {
+			writel(1, scp->reg_base + MT8192_CORE0_WDT_IRQ);
+			scp_wdt_handler(scp, scp_to_host);
+		}
+	}
+}
+
 static irqreturn_t scp_irq_handler(int irq, void *priv)
 {
 	struct mtk_scp *scp = priv;
@@ -961,7 +986,7 @@ static const struct mtk_scp_of_data mt8192_of_data = {
 static const struct mtk_scp_of_data mt8195_of_data = {
 	.scp_clk_get = mt8195_scp_clk_get,
 	.scp_before_load = mt8195_scp_before_load,
-	.scp_irq_handler = mt8192_scp_irq_handler,
+	.scp_irq_handler = mt8195_scp_irq_handler,
 	.scp_reset_assert = mt8192_scp_reset_assert,
 	.scp_reset_deassert = mt8192_scp_reset_deassert,
 	.scp_stop = mt8195_scp_stop,
Signature · 1 line
2.18.0
maintainer
#4 lore raw

Re: [PATCH v2 2/9] remoteproc: mediatek: Support hanlding scp core 1 wdt timeout

Hi Tinghan,

I have started reviewing this set and I expect comments to be spread out over a few days. I will tell you when I am done.

Please see below for comments...

Quoted 47 lines · Tinghan Shen

MT8195 SCP is a dual-core processor. The SCP core 1 watchdog timeout interrupt uses the same interrupt line of SCP core 0 watchdog timeout interrupt.

Add support for handling SCP core 1 watchdog timeout interrupt in the SCP IRQ handler.

---
 drivers/remoteproc/mtk_common.h |  4 ++++
 drivers/remoteproc/mtk_scp.c    | 27 ++++++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 1 deletion(-)
drivers/remoteproc/mtk_common.h +4 -0
index ea6fa1100a00..73e8adf00de3 100644
@@ -54,6 +54,10 @@
 #define MT8192_CORE0_WDT_IRQ		0x10030
 #define MT8192_CORE0_WDT_CFG		0x10034
 
+#define MT8195_SYS_STATUS		0x4004
+#define MT8195_CORE0_WDT		BIT(16)
+#define MT8195_CORE1_WDT		BIT(17)
+
 #define MT8195_L1TCM_SRAM_PDN_RESERVED_RSI_BITS		GENMASK(7, 4)
 
 #define SCP_FW_VER_LEN			32
drivers/remoteproc/mtk_scp.c +11 -0
index 47b2a40e1b4a..3510c6d0bbc8 100644
@@ -212,6 +212,31 @@ static void mt8192_scp_irq_handler(struct mtk_scp *scp)
 	}
 }
 
+static void mt8195_scp_irq_handler(struct mtk_scp *scp)
+{
+	u32 scp_to_host;
+
+	scp_to_host = readl(scp->reg_base + MT8192_SCP2APMCU_IPC_SET);
+
+	if (scp_to_host & MT8192_SCP_IPC_INT_BIT) {
+		scp_ipi_handler(scp);
+
+		/*
+		 * SCP won't send another interrupt until we clear

drivers/remoteproc/mtk_scp.c static void mt8192_scp_irq_handler(struct mtk_scp *scp) · line 235

Quoted 10 lines
drivers/remoteproc/mtk_scp.c +10 -0
+		 * MT8192_SCP2APMCU_IPC.
+		 */
+		writel(MT8192_SCP_IPC_INT_BIT,
+		       scp->reg_base + MT8192_SCP2APMCU_IPC_CLR);
+	} else {
+		if (readl(scp->reg_base + MT8195_SYS_STATUS) & MT8195_CORE1_WDT) {
+			writel(1, scp->reg_base + MT8195_CORE1_WDT_IRQ);
+		} else {
+			writel(1, scp->reg_base + MT8192_CORE0_WDT_IRQ);
+			scp_wdt_handler(scp, scp_to_host);

Why is scp_wdt_handler() not called when CORE1 signals a watchdog failure? If this is the intended behaviour there is no way for anyone but you to know that it is the case.

Quoted 19 lines
drivers/remoteproc/mtk_scp.c +5 -1
+		}
+	}
+}
+
 static irqreturn_t scp_irq_handler(int irq, void *priv)
 {
 	struct mtk_scp *scp = priv;
@@ -961,7 +986,7 @@ static const struct mtk_scp_of_data mt8192_of_data = {
 static const struct mtk_scp_of_data mt8195_of_data = {
 	.scp_clk_get = mt8195_scp_clk_get,
 	.scp_before_load = mt8195_scp_before_load,
-	.scp_irq_handler = mt8192_scp_irq_handler,
+	.scp_irq_handler = mt8195_scp_irq_handler,
 	.scp_reset_assert = mt8192_scp_reset_assert,
 	.scp_reset_deassert = mt8192_scp_reset_deassert,
 	.scp_stop = mt8195_scp_stop,
Signature · 1 line
2.18.0
#5 lore raw

Re: [PATCH v2 2/9] remoteproc: mediatek: Support hanlding scp core 1 wdt timeout

Hi Mathieu,

Quoted 61 lines

Hi Tinghan,

I have started reviewing this set and I expect comments to be spread out over a few days. I will tell you when I am done.

Please see below for comments...

Quoted 53 lines · Tinghan Shen

MT8195 SCP is a dual-core processor. The SCP core 1 watchdog timeout interrupt uses the same interrupt line of SCP core 0 watchdog timeout interrupt.

Add support for handling SCP core 1 watchdog timeout interrupt in the SCP IRQ handler.

---
 drivers/remoteproc/mtk_common.h |  4 ++++
 drivers/remoteproc/mtk_scp.c    | 27 ++++++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 1 deletion(-)
drivers/remoteproc/mtk_common.h +4 -0
index ea6fa1100a00..73e8adf00de3 100644
@@ -54,6 +54,10 @@
 #define MT8192_CORE0_WDT_IRQ		0x10030
 #define MT8192_CORE0_WDT_CFG		0x10034
 
+#define MT8195_SYS_STATUS		0x4004
+#define MT8195_CORE0_WDT		BIT(16)
+#define MT8195_CORE1_WDT		BIT(17)
+
 #define MT8195_L1TCM_SRAM_PDN_RESERVED_RSI_BITS		GENMASK(7, 4)
 
 #define SCP_FW_VER_LEN			32
drivers/remoteproc/mtk_scp.c +17 -0
index 47b2a40e1b4a..3510c6d0bbc8 100644
@@ -212,6 +212,31 @@ static void mt8192_scp_irq_handler(struct mtk_scp *scp)
 	}
 }
 
+static void mt8195_scp_irq_handler(struct mtk_scp *scp)
+{
+	u32 scp_to_host;
+
+	scp_to_host = readl(scp->reg_base + MT8192_SCP2APMCU_IPC_SET);
+
+	if (scp_to_host & MT8192_SCP_IPC_INT_BIT) {
+		scp_ipi_handler(scp);
+
+		/*
+		 * SCP won't send another interrupt until we clear
+		 * MT8192_SCP2APMCU_IPC.
+		 */
+		writel(MT8192_SCP_IPC_INT_BIT,
+		       scp->reg_base + MT8192_SCP2APMCU_IPC_CLR);
+	} else {
+		if (readl(scp->reg_base + MT8195_SYS_STATUS) & MT8195_CORE1_WDT) {
Quoted 8 lines

drivers/remoteproc/mtk_scp.c static void mt8192_scp_irq_handler(struct mtk_scp *scp) · line 235

Quoted 4 lines
drivers/remoteproc/mtk_scp.c +4 -0
+			writel(1, scp->reg_base + MT8195_CORE1_WDT_IRQ);
+		} else {
+			writel(1, scp->reg_base + MT8192_CORE0_WDT_IRQ);
+			scp_wdt_handler(scp, scp_to_host);

Why is scp_wdt_handler() not called when CORE1 signals a watchdog failure? If this is the intended behaviour there is no way for anyone but you to know that it is the case.

It's becuase the handler of CORE1 timeout doesn't exist at this patch. The CORE1 timeout handler is added at patch 7 of this series.

You're right. This makes people confused.
I'll combine this patch with the CORE1 timeout handler.

Best regards,
TingHan

#6 lore raw

PATCH v2 3/9 remoteproc: mediatek: Add SCP core 1 register definitions

In reply to Tinghan Shen

Add MT8195 SCP core 1 related register definitions.

---
 drivers/remoteproc/mtk_common.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/remoteproc/mtk_common.h +21 -0
index 73e8adf00de3..5582f4207fbf 100644
@@ -47,6 +47,7 @@
 #define MT8192_SCP2SPM_IPC_CLR		0x4094
 #define MT8192_GIPC_IN_SET		0x4098
 #define MT8192_HOST_IPC_INT_BIT		BIT(0)
+#define MT8195_CORE1_HOST_IPC_INT_BIT	BIT(4)
 
 #define MT8192_CORE0_SW_RSTN_CLR	0x10000
 #define MT8192_CORE0_SW_RSTN_SET	0x10004
@@ -60,6 +61,26 @@
 
 #define MT8195_L1TCM_SRAM_PDN_RESERVED_RSI_BITS		GENMASK(7, 4)
 
+#define MT8195_CPU1_SRAM_PD			0x1084
+#define MT8195_SSHUB2APMCU_IPC_SET		0x4088
+#define MT8195_SSHUB2APMCU_IPC_CLR		0x408C
+#define MT8195_CORE1_SW_RSTN_CLR		0x20000
+#define MT8195_CORE1_SW_RSTN_SET		0x20004
+#define MT8195_CORE1_MEM_ATT_PREDEF		0x20008
+#define MT8195_CORE1_WDT_IRQ			0x20030
+#define MT8195_CORE1_WDT_CFG			0x20034
+
+#define MT8195_SEC_CTRL				0x85000
+#define MT8195_CORE_OFFSET_ENABLE_D		BIT(13)
+#define MT8195_CORE_OFFSET_ENABLE_I		BIT(12)
+#define MT8195_L2TCM_OFFSET_RANGE_0_LOW		0x850b0
+#define MT8195_L2TCM_OFFSET_RANGE_0_HIGH	0x850b4
+#define MT8195_L2TCM_OFFSET			0x850d0
+#define SCP_SRAM_REMAP_LOW			0
+#define SCP_SRAM_REMAP_HIGH			1
+#define SCP_SRAM_REMAP_OFFSET			2
+#define SCP_SRAM_REMAP_SIZE			3
+
 #define SCP_FW_VER_LEN			32
 #define SCP_SHARE_BUFFER_SIZE		288
 
Signature · 1 line
2.18.0
maintainer Reviewed-by on v2 3/9
#7 lore raw

Re: [PATCH v2 3/9] remoteproc: mediatek: Add SCP core 1 register definitions

Quoted 35 lines · Tinghan Shen

Add MT8195 SCP core 1 related register definitions.

---
 drivers/remoteproc/mtk_common.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/remoteproc/mtk_common.h +13 -0
index 73e8adf00de3..5582f4207fbf 100644
@@ -47,6 +47,7 @@
 #define MT8192_SCP2SPM_IPC_CLR		0x4094
 #define MT8192_GIPC_IN_SET		0x4098
 #define MT8192_HOST_IPC_INT_BIT		BIT(0)
+#define MT8195_CORE1_HOST_IPC_INT_BIT	BIT(4)
 
 #define MT8192_CORE0_SW_RSTN_CLR	0x10000
 #define MT8192_CORE0_SW_RSTN_SET	0x10004
@@ -60,6 +61,26 @@
 
 #define MT8195_L1TCM_SRAM_PDN_RESERVED_RSI_BITS		GENMASK(7, 4)
 
+#define MT8195_CPU1_SRAM_PD			0x1084
+#define MT8195_SSHUB2APMCU_IPC_SET		0x4088
+#define MT8195_SSHUB2APMCU_IPC_CLR		0x408C
+#define MT8195_CORE1_SW_RSTN_CLR		0x20000
+#define MT8195_CORE1_SW_RSTN_SET		0x20004
+#define MT8195_CORE1_MEM_ATT_PREDEF		0x20008
+#define MT8195_CORE1_WDT_IRQ			0x20030
+#define MT8195_CORE1_WDT_CFG			0x20034
+
+#define MT8195_SEC_CTRL				0x85000
+#define MT8195_CORE_OFFSET_ENABLE_D		BIT(13)
+#define MT8195_CORE_OFFSET_ENABLE_I		BIT(12)

drivers/remoteproc/mtk_common.h line 85

Quoted 10 lines
drivers/remoteproc/mtk_common.h +8 -0
+#define MT8195_L2TCM_OFFSET_RANGE_0_LOW		0x850b0
+#define MT8195_L2TCM_OFFSET_RANGE_0_HIGH	0x850b4
+#define MT8195_L2TCM_OFFSET			0x850d0
+#define SCP_SRAM_REMAP_LOW			0
+#define SCP_SRAM_REMAP_HIGH			1
+#define SCP_SRAM_REMAP_OFFSET			2
+#define SCP_SRAM_REMAP_SIZE			3
+
 #define SCP_FW_VER_LEN			32
 #define SCP_SHARE_BUFFER_SIZE		288
Quoted 4 lines
Signature · 2 lines
-- 
2.18.0
#8 lore raw

PATCH v2 4/9 remoteproc: mediatek: Support probing for the 2nd core of dual-core SCP

In reply to Tinghan Shen

The mtk_scp.c driver only supports the single core SCP and the 1st core of a dual-core SCP. This patch extends it for the 2nd core.

MT8195 SCP is a dual-core MCU. Both cores are housed in the same subsys. They have the same viewpoint of registers and memory.

Core 1 of the SCP features its own set of core configuration registers, interrupt controller, timers, and DMAs. The rest of the peripherals in this subsystem are shared by core 0 and core 1.

As for memory, core 1 has its own cache memory. the SCP SRAM is shared by core 0 and core 1.

---
 drivers/remoteproc/mtk_scp.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
drivers/remoteproc/mtk_scp.c +20 -2
index 3510c6d0bbc8..91b4aefde4ac 100644
@@ -23,6 +23,10 @@
 #define MAX_CODE_SIZE 0x500000
 #define SECTION_NAME_IPI_BUFFER ".ipi_buffer"
 
+#define SCP_CORE_0 0
+#define SCP_CORE_1 1
+#define SCP_CORE_SINGLE 0xF
+
 /**
  * scp_get() - get a reference to SCP.
  *
@@ -836,6 +840,7 @@ static int scp_probe(struct platform_device *pdev)
 	struct resource *res;
 	const char *fw_name = "scp.img";
 	int ret, i;
+	u32 core_id = SCP_CORE_SINGLE;
 
 	ret = rproc_of_parse_firmware(dev, 0, &fw_name);
 	if (ret < 0 && ret != -EINVAL)
@@ -851,8 +856,16 @@ static int scp_probe(struct platform_device *pdev)
 	scp->data = of_device_get_match_data(dev);
 	platform_set_drvdata(pdev, scp);
 
+	ret = of_property_read_u32_index(dev->of_node, "mediatek,scp-core", 1, &core_id);
+	if (ret == 0)
+		dev_info(dev, "Boot SCP dual core %u\n", core_id);
+
 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sram");
-	scp->sram_base = devm_ioremap_resource(dev, res);
+	if (core_id == SCP_CORE_1)
+		scp->sram_base = devm_ioremap(dev, res->start, resource_size(res));
+	else
+		scp->sram_base = devm_ioremap_resource(dev, res);
+
 	if (IS_ERR(scp->sram_base))
 		return dev_err_probe(dev, PTR_ERR(scp->sram_base),
 				     "Failed to parse and map sram memory\n");
@@ -873,7 +886,12 @@ static int scp_probe(struct platform_device *pdev)
 		scp->l1tcm_phys = res->start;
 	}
 
-	scp->reg_base = devm_platform_ioremap_resource_byname(pdev, "cfg");
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "cfg");
+	if (core_id == SCP_CORE_1)
+		scp->reg_base = devm_ioremap(dev, res->start, resource_size(res));
+	else
+		scp->reg_base = devm_ioremap_resource(dev, res);
+
 	if (IS_ERR(scp->reg_base))
 		return dev_err_probe(dev, PTR_ERR(scp->reg_base),
 				     "Failed to parse and map cfg memory\n");
Signature · 1 line
2.18.0
maintainer
#9 lore raw

Re: [PATCH v2 4/9] remoteproc: mediatek: Support probing for the 2nd core of dual-core SCP

Quoted 4 lines · Tinghan Shen

The mtk_scp.c driver only supports the single core SCP and the 1st core of a dual-core SCP. This patch extends it for the 2nd core.

MT8195 SCP is a dual-core MCU. Both cores are housed in the same subsys.

s/subsys/subsystem

Quoted 7 lines

They have the same viewpoint of registers and memory.

Core 1 of the SCP features its own set of core configuration registers, interrupt controller, timers, and DMAs. The rest of the peripherals in this subsystem are shared by core 0 and core 1.

As for memory, core 1 has its own cache memory. the SCP SRAM is shared

/the/The

Quoted 31 lines

by core 0 and core 1.

---
 drivers/remoteproc/mtk_scp.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
drivers/remoteproc/mtk_scp.c +5 -0
index 3510c6d0bbc8..91b4aefde4ac 100644
@@ -23,6 +23,10 @@
 #define MAX_CODE_SIZE 0x500000
 #define SECTION_NAME_IPI_BUFFER ".ipi_buffer"
 
+#define SCP_CORE_0 0
+#define SCP_CORE_1 1
+#define SCP_CORE_SINGLE 0xF
+
 /**
  * scp_get() - get a reference to SCP.
  *
@@ -836,6 +840,7 @@ static int scp_probe(struct platform_device *pdev)
 	struct resource *res;
 	const char *fw_name = "scp.img";
 	int ret, i;
+	u32 core_id = SCP_CORE_SINGLE;
 
 	ret = rproc_of_parse_firmware(dev, 0, &fw_name);
 	if (ret < 0 && ret != -EINVAL)

drivers/remoteproc/mtk_scp.c static int scp_probe(struct platform_device *pdev) · line 861

Quoted 6 lines
drivers/remoteproc/mtk_scp.c +3 -0
@@ -851,8 +856,16 @@ static int scp_probe(struct platform_device *pdev)
 	scp->data = of_device_get_match_data(dev);
 	platform_set_drvdata(pdev, scp);
 
+	ret = of_property_read_u32_index(dev->of_node, "mediatek,scp-core", 1, &core_id);
+	if (ret == 0)
+		dev_info(dev, "Boot SCP dual core %u\n", core_id);

Why is the DT property "mediatek,scp-core" needed at all? Since the compatible "mediatek,mt8195-scp-dual" has already been defined previously in this patchset, initialising the second core, if present, is a matter of looking at the compatile string.

drivers/remoteproc/mtk_scp.c static int scp_probe(struct platform_device *pdev) · line 868

Quoted 8 lines
drivers/remoteproc/mtk_scp.c +6 -1
+
 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sram");
-	scp->sram_base = devm_ioremap_resource(dev, res);
+	if (core_id == SCP_CORE_1)
+		scp->sram_base = devm_ioremap(dev, res->start, resource_size(res));
+	else
+		scp->sram_base = devm_ioremap_resource(dev, res);
+

This looks very broken... For this to work you would need to have two DT
entries with the "mediatek,mt8195-scp-dual" compatible properly, one with "mediatek,scp-core = <&scp_dual1 0>;" and another one with "mediatek,scp-core = <&scp_dual0 1>;".

Which is also very broken... Here you have a binding whose first argument is a reference to the core sibling while the second argument is a characteristic of the current core, which is highly confusing.

I suggest what when you see the compatible binding "mediatek,mt8195-scp", a single core is initialized. If you see "mediatek,mt8195-scp-dual", both cores are initialized as part of the _same_ probe.

If the above analysis is not correct it means I misinterpreted your work and if so, a serious amount of comments is needed _and_ a very detailed example in "mtk,scp.yaml" that leaves no room for interpretation.

I will stop reviewing this patchset until you have clarified how this works.

Thanks,
Mathieu

Quoted 20 lines
drivers/remoteproc/mtk_scp.c +6 -1
 	if (IS_ERR(scp->sram_base))
 		return dev_err_probe(dev, PTR_ERR(scp->sram_base),
 				     "Failed to parse and map sram memory\n");
@@ -873,7 +886,12 @@ static int scp_probe(struct platform_device *pdev)
 		scp->l1tcm_phys = res->start;
 	}
 
-	scp->reg_base = devm_platform_ioremap_resource_byname(pdev, "cfg");
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "cfg");
+	if (core_id == SCP_CORE_1)
+		scp->reg_base = devm_ioremap(dev, res->start, resource_size(res));
+	else
+		scp->reg_base = devm_ioremap_resource(dev, res);
+
 	if (IS_ERR(scp->reg_base))
 		return dev_err_probe(dev, PTR_ERR(scp->reg_base),
 				     "Failed to parse and map cfg memory\n");
Signature · 1 line
2.18.0
#10 lore raw

Re: [PATCH v2 4/9] remoteproc: mediatek: Support probing for the 2nd core of dual-core SCP

Hi Mathieu,

Quoted 51 lines
Quoted 4 lines

The mtk_scp.c driver only supports the single core SCP and the 1st core of a dual-core SCP. This patch extends it for the 2nd core.

MT8195 SCP is a dual-core MCU. Both cores are housed in the same subsys.

s/subsys/subsystem

Quoted 7 lines

They have the same viewpoint of registers and memory.

Core 1 of the SCP features its own set of core configuration registers, interrupt controller, timers, and DMAs. The rest of the peripherals in this subsystem are shared by core 0 and core 1.

As for memory, core 1 has its own cache memory. the SCP SRAM is shared

/the/The

Quoted 34 lines

by core 0 and core 1.

---
 drivers/remoteproc/mtk_scp.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
drivers/remoteproc/mtk_scp.c +5 -0
index 3510c6d0bbc8..91b4aefde4ac 100644
@@ -23,6 +23,10 @@
 #define MAX_CODE_SIZE 0x500000
 #define SECTION_NAME_IPI_BUFFER ".ipi_buffer"
 
+#define SCP_CORE_0 0
+#define SCP_CORE_1 1
+#define SCP_CORE_SINGLE 0xF
+
 /**
  * scp_get() - get a reference to SCP.
  *
@@ -836,6 +840,7 @@ static int scp_probe(struct platform_device *pdev)
 	struct resource *res;
 	const char *fw_name = "scp.img";
 	int ret, i;
+	u32 core_id = SCP_CORE_SINGLE;
 
 	ret = rproc_of_parse_firmware(dev, 0, &fw_name);
 	if (ret < 0 && ret != -EINVAL)
@@ -851,8 +856,16 @@ static int scp_probe(struct platform_device *pdev)
 	scp->data = of_device_get_match_data(dev);
 	platform_set_drvdata(pdev, scp);
 
Quoted 8 lines

drivers/remoteproc/mtk_scp.c static int scp_probe(struct platform_device *pdev) · line 861

Quoted 3 lines
drivers/remoteproc/mtk_scp.c +3 -0
+	ret = of_property_read_u32_index(dev->of_node, "mediatek,scp-core", 1, &core_id);
+	if (ret == 0)
+		dev_info(dev, "Boot SCP dual core %u\n", core_id);

Why is the DT property "mediatek,scp-core" needed at all? Since the compatible "mediatek,mt8195-scp-dual" has already been defined previously in this patchset, initialising the second core, if present, is a matter of looking at the compatile string.

This idea of identify cores by the compatible looks workable. I'll update this series at next version.
Thanks!

Quoted 22 lines

drivers/remoteproc/mtk_scp.c static int scp_probe(struct platform_device *pdev) · line 868

Quoted 9 lines
drivers/remoteproc/mtk_scp.c +6 -1
+
 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sram");
-	scp->sram_base = devm_ioremap_resource(dev, res);
+	if (core_id == SCP_CORE_1)
+		scp->sram_base = devm_ioremap(dev, res->start, resource_size(res));
+	else
+		scp->sram_base = devm_ioremap_resource(dev, res);
+

This looks very broken... For this to work you would need to have two DT
entries with the "mediatek,mt8195-scp-dual" compatible properly, one with "mediatek,scp-core = <&scp_dual1 0>;" and another one with "mediatek,scp-core = <&scp_dual0 1>;".

Which is also very broken... Here you have a binding whose first argument is a reference to the core sibling while the second argument is a characteristic of the current core, which is highly confusing.

I suggest what when you see the compatible binding "mediatek,mt8195-scp", a single core is initialized. If you see "mediatek,mt8195-scp-dual", both cores are initialized as part of the _same_ probe.

Quoted 8 lines

If the above analysis is not correct it means I misinterpreted your work and if so, a serious amount of comments is needed _and_ a very detailed example in "mtk,scp.yaml" that leaves no room for interpretation.

I will stop reviewing this patchset until you have clarified how this works.

Thanks,
Mathieu

There's one problem of initializng the CORE1 using the same probe flow. The register space of CORE0 and CORE1 are overlapped in the device node. Both cores need to use the 'cfg' registers defined in scp yaml. The devm_ioremap_resource catches address overlapping and returns error when probing CORE1 driver.

Best regards,
TingHan

A message that is not in the archive (sent off-list or not yet received): CANLsYkx6kXk8u_ajFbnhdWTkZBLtrq_z02jryLBSVH0x--_ZFw@mail.gmail.com

#12 lore raw

Re: [PATCH v2 4/9] remoteproc: mediatek: Support probing for the 2nd core of dual-core SCP

Quoted 134 lines · Mathieu Poirier
Quoted 123 lines · Tinghan Shen

Hi Mathieu,

Quoted 4 lines
Quoted 4 lines

The mtk_scp.c driver only supports the single core SCP and the 1st core of a dual-core SCP. This patch extends it for the 2nd core.

MT8195 SCP is a dual-core MCU. Both cores are housed in the same

subsys.

Quoted 13 lines

s/subsys/subsystem

Quoted 7 lines

They have the same viewpoint of registers and memory.

Core 1 of the SCP features its own set of core configuration registers, interrupt controller, timers, and DMAs. The rest of the peripherals in this subsystem are shared by core 0 and core 1.

As for memory, core 1 has its own cache memory. the SCP SRAM is shared

/the/The

Quoted 8 lines

Review

Quoted 8 lines

by core 0 and core 1.

---
 drivers/remoteproc/mtk_scp.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/remoteproc/mtk_scp.c

Quoted 20 lines
Quoted 20 lines

index 3510c6d0bbc8..91b4aefde4ac 100644

drivers/remoteproc/mtk_scp.c +5 -0
@@ -23,6 +23,10 @@
 #define MAX_CODE_SIZE 0x500000
 #define SECTION_NAME_IPI_BUFFER ".ipi_buffer"
 
+#define SCP_CORE_0 0
+#define SCP_CORE_1 1
+#define SCP_CORE_SINGLE 0xF
+
 /**
  * scp_get() - get a reference to SCP.
  *
@@ -836,6 +840,7 @@ static int scp_probe(struct platform_device *pdev)
    struct resource *res;
    const char *fw_name = "scp.img";
    int ret, i;
+   u32 core_id = SCP_CORE_SINGLE;
 
Quoted 7 lines

drivers/remoteproc/mtk_scp.c static int scp_probe(struct platform_device *pdev) · line 859

Quoted 7 lines
drivers/remoteproc/mtk_scp.c +1 -0
    ret = rproc_of_parse_firmware(dev, 0, &fw_name);
    if (ret < 0 && ret != -EINVAL)
@@ -851,8 +856,16 @@ static int scp_probe(struct platform_device *pdev)
    scp->data = of_device_get_match_data(dev);
    platform_set_drvdata(pdev, scp);
 
+   ret = of_property_read_u32_index(dev->of_node,

"mediatek,scp-core", 1, &core_id);

Quoted 4 lines

drivers/remoteproc/mtk_scp.c static int scp_probe(struct platform_device *pdev) · line 861

Quoted 2 lines
drivers/remoteproc/mtk_scp.c +2 -0
+   if (ret == 0)
+           dev_info(dev, "Boot SCP dual core %u\n", core_id);

Why is the DT property "mediatek,scp-core" needed at all? Since the

compatible

Quoted 1 line

"mediatek,mt8195-scp-dual" has already been defined previously in this

patchset,

Quoted 2 lines

initialising the second core, if present, is a matter of looking at the compatile string.

This idea of identify cores by the compatible looks workable. I'll update this series at next version.
Thanks!

Quoted 6 lines

drivers/remoteproc/mtk_scp.c static int scp_probe(struct platform_device *pdev)

Quoted 6 lines
drivers/remoteproc/mtk_scp.c +3 -1
+
    res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sram");
-   scp->sram_base = devm_ioremap_resource(dev, res);
+   if (core_id == SCP_CORE_1)
+           scp->sram_base = devm_ioremap(dev, res->start,

resource_size(res));

Quoted 7 lines

drivers/remoteproc/mtk_scp.c static int scp_probe(struct platform_device *pdev) · line 868

Quoted 3 lines
drivers/remoteproc/mtk_scp.c +3 -0
+   else
+           scp->sram_base = devm_ioremap_resource(dev, res);
+

This looks very broken... For this to work you would need to have two DT entries with the "mediatek,mt8195-scp-dual" compatible properly, one with "mediatek,scp-core = <&scp_dual1 0>;" and another one with

"mediatek,scp-core = <&scp_dual0 1>;".

Quoted 2 lines

Which is also very broken... Here you have a binding whose first

argument is a

Quoted 1 line

reference to the core sibling while the second argument is a

characteristic of

Quoted 3 lines

the current core, which is highly confusing.

I suggest what when you see the compatible binding

"mediatek,mt8195-scp", a

Quoted 1 line

single core is initialized. If you see "mediatek,mt8195-scp-dual", both

cores

Quoted 4 lines

are initialized as part of the _same_ probe.

If the above analysis is not correct it means I misinterpreted your work and if so, a serious amount of comments is needed _and_ a very

detailed

Quoted 3 lines

example in "mtk,scp.yaml" that leaves no room for interpretation.

I will stop reviewing this patchset until you have clarified how this

works.

Quoted 3 lines

Thanks,
Mathieu

Quoted 7 lines

There's one problem of initializng the CORE1 using the same probe flow. The register space of CORE0 and CORE1 are overlapped in the device node. Both cores need to use the 'cfg' registers defined in scp yaml. The devm_ioremap_resource catches address overlapping and returns error when
probing CORE1 driver.

Quoted 3 lines

That is exactly why I suggest to initialise both cores within the same probe() function.

Hi Mathieu,

I'm thinking about how to initialise in the same probe() function.
I'm wondering if this implies that using one scp driver to initialize 2 cores? If it is, I assume the dts descriptions for both cores should be contained in one node.

When there's one node for both cores, it looks like that there is a problem of using dma_allocate_coherent(). Each core has its own reserved memory region. When there's only one device for both cores, it's not able to identify the memory region by the device parameter of dma_allocate_coherent().

Is it acceptable to consider manually allocating core 1 device in the probe() when probing core 0?

Best regards,
TingHan

maintainer
#13 lore raw

Re: [PATCH v2 4/9] remoteproc: mediatek: Support probing for the 2nd core of dual-core SCP

Quoted 146 lines · TingHan Shen
Quoted 134 lines · Mathieu Poirier
Quoted 123 lines · Tinghan Shen

Hi Mathieu,

Quoted 4 lines
Quoted 4 lines

The mtk_scp.c driver only supports the single core SCP and the 1st core of a dual-core SCP. This patch extends it for the 2nd core.

MT8195 SCP is a dual-core MCU. Both cores are housed in the same

subsys.

Quoted 13 lines

s/subsys/subsystem

Quoted 7 lines

They have the same viewpoint of registers and memory.

Core 1 of the SCP features its own set of core configuration registers, interrupt controller, timers, and DMAs. The rest of the peripherals in this subsystem are shared by core 0 and core 1.

As for memory, core 1 has its own cache memory. the SCP SRAM is shared

/the/The

Quoted 8 lines

Review

Quoted 8 lines

by core 0 and core 1.

---
 drivers/remoteproc/mtk_scp.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/remoteproc/mtk_scp.c

Quoted 20 lines
Quoted 20 lines

index 3510c6d0bbc8..91b4aefde4ac 100644

drivers/remoteproc/mtk_scp.c +5 -0
@@ -23,6 +23,10 @@
 #define MAX_CODE_SIZE 0x500000
 #define SECTION_NAME_IPI_BUFFER ".ipi_buffer"
 
+#define SCP_CORE_0 0
+#define SCP_CORE_1 1
+#define SCP_CORE_SINGLE 0xF
+
 /**
  * scp_get() - get a reference to SCP.
  *
@@ -836,6 +840,7 @@ static int scp_probe(struct platform_device *pdev)
    struct resource *res;
    const char *fw_name = "scp.img";
    int ret, i;
+   u32 core_id = SCP_CORE_SINGLE;
 
Quoted 7 lines

drivers/remoteproc/mtk_scp.c static int scp_probe(struct platform_device *pdev) · line 859

Quoted 7 lines
drivers/remoteproc/mtk_scp.c +1 -0
    ret = rproc_of_parse_firmware(dev, 0, &fw_name);
    if (ret < 0 && ret != -EINVAL)
@@ -851,8 +856,16 @@ static int scp_probe(struct platform_device *pdev)
    scp->data = of_device_get_match_data(dev);
    platform_set_drvdata(pdev, scp);
 
+   ret = of_property_read_u32_index(dev->of_node,

"mediatek,scp-core", 1, &core_id);

Quoted 4 lines

drivers/remoteproc/mtk_scp.c static int scp_probe(struct platform_device *pdev) · line 861

Quoted 2 lines
drivers/remoteproc/mtk_scp.c +2 -0
+   if (ret == 0)
+           dev_info(dev, "Boot SCP dual core %u\n", core_id);

Why is the DT property "mediatek,scp-core" needed at all? Since the

compatible

Quoted 1 line

"mediatek,mt8195-scp-dual" has already been defined previously in this

patchset,

Quoted 2 lines

initialising the second core, if present, is a matter of looking at the compatile string.

This idea of identify cores by the compatible looks workable. I'll update this series at next version.
Thanks!

Quoted 6 lines

drivers/remoteproc/mtk_scp.c static int scp_probe(struct platform_device *pdev)

Quoted 6 lines
drivers/remoteproc/mtk_scp.c +3 -1
+
    res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sram");
-   scp->sram_base = devm_ioremap_resource(dev, res);
+   if (core_id == SCP_CORE_1)
+           scp->sram_base = devm_ioremap(dev, res->start,

resource_size(res));

Quoted 7 lines

drivers/remoteproc/mtk_scp.c static int scp_probe(struct platform_device *pdev) · line 868

Quoted 3 lines
drivers/remoteproc/mtk_scp.c +3 -0
+   else
+           scp->sram_base = devm_ioremap_resource(dev, res);
+

This looks very broken... For this to work you would need to have two DT entries with the "mediatek,mt8195-scp-dual" compatible properly, one with "mediatek,scp-core = <&scp_dual1 0>;" and another one with

"mediatek,scp-core = <&scp_dual0 1>;".

Quoted 2 lines

Which is also very broken... Here you have a binding whose first

argument is a

Quoted 1 line

reference to the core sibling while the second argument is a

characteristic of

Quoted 3 lines

the current core, which is highly confusing.

I suggest what when you see the compatible binding

"mediatek,mt8195-scp", a

Quoted 1 line

single core is initialized. If you see "mediatek,mt8195-scp-dual", both

cores

Quoted 4 lines

are initialized as part of the _same_ probe.

If the above analysis is not correct it means I misinterpreted your work and if so, a serious amount of comments is needed _and_ a very

detailed

Quoted 3 lines

example in "mtk,scp.yaml" that leaves no room for interpretation.

I will stop reviewing this patchset until you have clarified how this

works.

Quoted 3 lines

Thanks,
Mathieu

Quoted 7 lines

There's one problem of initializng the CORE1 using the same probe flow. The register space of CORE0 and CORE1 are overlapped in the device node. Both cores need to use the 'cfg' registers defined in scp yaml. The devm_ioremap_resource catches address overlapping and returns error when
probing CORE1 driver.

Quoted 3 lines

That is exactly why I suggest to initialise both cores within the same probe() function.

Hi Mathieu,

I'm thinking about how to initialise in the same probe() function.
I'm wondering if this implies that using one scp driver to initialize 2 cores? If it is, I assume the dts descriptions for both cores should be contained in one node.

Quoted 6 lines

When there's one node for both cores, it looks like that there is a problem of using dma_allocate_coherent(). Each core has its own reserved memory region. When there's only one device for both cores, it's not able to identify the memory region by the device parameter of dma_allocate_coherent().

Is it acceptable to consider manually allocating core 1 device in the probe() when probing core 0?

Look at what Suman did for TI's K3 R5[1] and DSP[2] platforms. Reviewing the bindings for both platforms will also give you a good idea of how things work.

[1]. https://elixir.bootlin.com/linux/v6.0-rc5/source/drivers/remoteproc/ti_k3_r5_remoteproc.c#L1683
[2]. https://elixir.bootlin.com/linux/v6.0-rc5/source/drivers/remoteproc/ti_k3_dsp_remoteproc.c#L673

Quoted 12 lines

Best regards,
TingHan

#14 lore raw

Re: [PATCH v2 4/9] remoteproc: mediatek: Support probing for the 2nd core of dual-core SCP

Quoted 152 lines · Mathieu Poirier
Quoted 151 lines · TingHan Shen
Quoted 134 lines · Mathieu Poirier
Quoted 123 lines · Tinghan Shen

Hi Mathieu,

Quoted 4 lines
Quoted 4 lines

The mtk_scp.c driver only supports the single core SCP and the 1st core of a dual-core SCP. This patch extends it for the 2nd core.

MT8195 SCP is a dual-core MCU. Both cores are housed in the same

subsys.

Quoted 13 lines

s/subsys/subsystem

Quoted 7 lines

They have the same viewpoint of registers and memory.

Core 1 of the SCP features its own set of core configuration registers, interrupt controller, timers, and DMAs. The rest of the peripherals in this subsystem are shared by core 0 and core 1.

As for memory, core 1 has its own cache memory. the SCP SRAM is shared

/the/The

Quoted 8 lines

Review

Quoted 8 lines

by core 0 and core 1.

---
 drivers/remoteproc/mtk_scp.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/remoteproc/mtk_scp.c

Quoted 20 lines
Quoted 20 lines

index 3510c6d0bbc8..91b4aefde4ac 100644

drivers/remoteproc/mtk_scp.c +5 -0
@@ -23,6 +23,10 @@
 #define MAX_CODE_SIZE 0x500000
 #define SECTION_NAME_IPI_BUFFER ".ipi_buffer"
 
+#define SCP_CORE_0 0
+#define SCP_CORE_1 1
+#define SCP_CORE_SINGLE 0xF
+
 /**
  * scp_get() - get a reference to SCP.
  *
@@ -836,6 +840,7 @@ static int scp_probe(struct platform_device *pdev)
    struct resource *res;
    const char *fw_name = "scp.img";
    int ret, i;
+   u32 core_id = SCP_CORE_SINGLE;
 
Quoted 7 lines

drivers/remoteproc/mtk_scp.c static int scp_probe(struct platform_device *pdev) · line 859

Quoted 7 lines
drivers/remoteproc/mtk_scp.c +1 -0
    ret = rproc_of_parse_firmware(dev, 0, &fw_name);
    if (ret < 0 && ret != -EINVAL)
@@ -851,8 +856,16 @@ static int scp_probe(struct platform_device *pdev)
    scp->data = of_device_get_match_data(dev);
    platform_set_drvdata(pdev, scp);
 
+   ret = of_property_read_u32_index(dev->of_node,

"mediatek,scp-core", 1, &core_id);

Quoted 4 lines

drivers/remoteproc/mtk_scp.c static int scp_probe(struct platform_device *pdev) · line 861

Quoted 2 lines
drivers/remoteproc/mtk_scp.c +2 -0
+   if (ret == 0)
+           dev_info(dev, "Boot SCP dual core %u\n", core_id);

Why is the DT property "mediatek,scp-core" needed at all? Since the

compatible

Quoted 1 line

"mediatek,mt8195-scp-dual" has already been defined previously in this

patchset,

Quoted 2 lines

initialising the second core, if present, is a matter of looking at the compatile string.

This idea of identify cores by the compatible looks workable. I'll update this series at next version.
Thanks!

Quoted 6 lines

drivers/remoteproc/mtk_scp.c static int scp_probe(struct platform_device *pdev)

Quoted 6 lines
drivers/remoteproc/mtk_scp.c +3 -1
+
    res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sram");
-   scp->sram_base = devm_ioremap_resource(dev, res);
+   if (core_id == SCP_CORE_1)
+           scp->sram_base = devm_ioremap(dev, res->start,

resource_size(res));

Quoted 7 lines

drivers/remoteproc/mtk_scp.c static int scp_probe(struct platform_device *pdev) · line 868

Quoted 3 lines
drivers/remoteproc/mtk_scp.c +3 -0
+   else
+           scp->sram_base = devm_ioremap_resource(dev, res);
+

This looks very broken... For this to work you would need to have two DT entries with the "mediatek,mt8195-scp-dual" compatible properly, one with "mediatek,scp-core = <&scp_dual1 0>;" and another one with

"mediatek,scp-core = <&scp_dual0 1>;".

Quoted 2 lines

Which is also very broken... Here you have a binding whose first

argument is a

Quoted 1 line

reference to the core sibling while the second argument is a

characteristic of

Quoted 3 lines

the current core, which is highly confusing.

I suggest what when you see the compatible binding

"mediatek,mt8195-scp", a

Quoted 1 line

single core is initialized. If you see "mediatek,mt8195-scp-dual", both

cores

Quoted 4 lines

are initialized as part of the _same_ probe.

If the above analysis is not correct it means I misinterpreted your work and if so, a serious amount of comments is needed _and_ a very

detailed

Quoted 3 lines

example in "mtk,scp.yaml" that leaves no room for interpretation.

I will stop reviewing this patchset until you have clarified how this

works.

Quoted 3 lines

Thanks,
Mathieu

Quoted 7 lines

There's one problem of initializng the CORE1 using the same probe flow. The register space of CORE0 and CORE1 are overlapped in the device node. Both cores need to use the 'cfg' registers defined in scp yaml. The devm_ioremap_resource catches address overlapping and returns error when
probing CORE1 driver.

Quoted 3 lines

That is exactly why I suggest to initialise both cores within the same probe() function.

Hi Mathieu,

I'm thinking about how to initialise in the same probe() function.
I'm wondering if this implies that using one scp driver to initialize 2 cores? If it is, I assume the dts descriptions for both cores should be contained in one node.

When there's one node for both cores, it looks like that there is a problem of using dma_allocate_coherent(). Each core has its own reserved memory region. When there's only one device for both cores, it's not able to identify the memory region by the device parameter of dma_allocate_coherent().

Quoted 9 lines
Quoted 1 line

Is it acceptable to consider manually allocating core 1 device in the probe() when probing core 0?

Look at what Suman did for TI's K3 R5[1] and DSP[2] platforms. Reviewing the bindings for both platforms will also give you a good idea of how things work.

[1]. https://urldefense.com/v3/__https://elixir.bootlin.com/linux/v6.0-rc5/source/drivers/remoteproc/ti_k3_r5_remoteproc.c*L1683__;Iw!!CTRNKA9wMg0ARbw!zVcjdLSfKYGO5YQMNGqq339mle8u0VdULX30z0XV4vo3vCb9Wy-w5ixOTmzbv1akubM$
[2]. https://urldefense.com/v3/__https://elixir.bootlin.com/linux/v6.0-rc5/source/drivers/remoteproc/ti_k3_dsp_remoteproc.c*L673__;Iw!!CTRNKA9wMg0ARbw!zVcjdLSfKYGO5YQMNGqq339mle8u0VdULX30z0XV4vo3vCb9Wy-w5ixOTmzbfE2dtBg$

Hi Mathieu,

My plan is changing the dts as following,

scp core 0 {
	// Keep current properties untouched.
	compatible = "mediatek,mt8195-scp";

	// core 0 properties...

	// Add a new property for multi-core scp.
	// if not present, it's single core.
	// if present and core id = 0, it's the main core, otherwise the sub cores.
	mediatek,scp-core = <0>;

	// add sub cores as sub node.
	// sub nodes can find parent by OF API.
	scp core 1 {
		// use the same compatile name as core 0.
		compatible = "mediatek,mt8195-scp";

		// assign id > 0 to sub cores.
		mediatek,scp-core = <1>;

		// core 1 properties...
	};
};

The driver probe/remove behavior will be modified as below,

scp probe() {
	// common init...

	// check core id to have different memory mapping flow
	if (core id == 0)
		// mapping cfg, sram and others
	else
		// mapping sram
		// reuse the cfg paddr/vaddr from core 0
	
	// common init...

	if (core id == 0) {
		ret = of_platform_populate(...)

		// boot core 0 and sub cores
		rproc_add();
	} else {
		// add sub core as sub device to main core
		rproc_add_subdev()

		rproc->auto_boot = false;
		rpoc_add();
	}
}

scp_remove() {

	if (core id == 0)
		of_platform_depopulate()
	else
		rproc_remove_subdev()	
	
	// remove core
}

Best regards,
TingHan

maintainer
#15 lore raw

Re: [PATCH v2 4/9] remoteproc: mediatek: Support probing for the 2nd core of dual-core SCP

Quoted 223 lines · TingHan Shen
Quoted 152 lines · Mathieu Poirier
Quoted 151 lines · TingHan Shen
Quoted 134 lines · Mathieu Poirier
Quoted 123 lines · Tinghan Shen

Hi Mathieu,

Quoted 4 lines
Quoted 4 lines

The mtk_scp.c driver only supports the single core SCP and the 1st core of a dual-core SCP. This patch extends it for the 2nd core.

MT8195 SCP is a dual-core MCU. Both cores are housed in the same

subsys.

Quoted 13 lines

s/subsys/subsystem

Quoted 7 lines

They have the same viewpoint of registers and memory.

Core 1 of the SCP features its own set of core configuration registers, interrupt controller, timers, and DMAs. The rest of the peripherals in this subsystem are shared by core 0 and core 1.

As for memory, core 1 has its own cache memory. the SCP SRAM is shared

/the/The

Quoted 8 lines

Review

Quoted 8 lines

by core 0 and core 1.

---
 drivers/remoteproc/mtk_scp.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/remoteproc/mtk_scp.c

Quoted 20 lines
Quoted 20 lines

index 3510c6d0bbc8..91b4aefde4ac 100644

drivers/remoteproc/mtk_scp.c +5 -0
@@ -23,6 +23,10 @@
 #define MAX_CODE_SIZE 0x500000
 #define SECTION_NAME_IPI_BUFFER ".ipi_buffer"
 
+#define SCP_CORE_0 0
+#define SCP_CORE_1 1
+#define SCP_CORE_SINGLE 0xF
+
 /**
  * scp_get() - get a reference to SCP.
  *
@@ -836,6 +840,7 @@ static int scp_probe(struct platform_device *pdev)
    struct resource *res;
    const char *fw_name = "scp.img";
    int ret, i;
+   u32 core_id = SCP_CORE_SINGLE;
 
Quoted 7 lines

drivers/remoteproc/mtk_scp.c static int scp_probe(struct platform_device *pdev) · line 859

Quoted 7 lines
drivers/remoteproc/mtk_scp.c +1 -0
    ret = rproc_of_parse_firmware(dev, 0, &fw_name);
    if (ret < 0 && ret != -EINVAL)
@@ -851,8 +856,16 @@ static int scp_probe(struct platform_device *pdev)
    scp->data = of_device_get_match_data(dev);
    platform_set_drvdata(pdev, scp);
 
+   ret = of_property_read_u32_index(dev->of_node,

"mediatek,scp-core", 1, &core_id);

Quoted 4 lines

drivers/remoteproc/mtk_scp.c static int scp_probe(struct platform_device *pdev) · line 861

Quoted 2 lines
drivers/remoteproc/mtk_scp.c +2 -0
+   if (ret == 0)
+           dev_info(dev, "Boot SCP dual core %u\n", core_id);

Why is the DT property "mediatek,scp-core" needed at all? Since the

compatible

Quoted 1 line

"mediatek,mt8195-scp-dual" has already been defined previously in this

patchset,

Quoted 2 lines

initialising the second core, if present, is a matter of looking at the compatile string.

This idea of identify cores by the compatible looks workable. I'll update this series at next version.
Thanks!

Quoted 6 lines

drivers/remoteproc/mtk_scp.c static int scp_probe(struct platform_device *pdev) · line 865

Quoted 6 lines
drivers/remoteproc/mtk_scp.c +3 -1
+
    res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sram");
-   scp->sram_base = devm_ioremap_resource(dev, res);
+   if (core_id == SCP_CORE_1)
+           scp->sram_base = devm_ioremap(dev, res->start,

resource_size(res));

Quoted 7 lines

drivers/remoteproc/mtk_scp.c static int scp_probe(struct platform_device *pdev) · line 868

Quoted 3 lines
drivers/remoteproc/mtk_scp.c +3 -0
+   else
+           scp->sram_base = devm_ioremap_resource(dev, res);
+

This looks very broken... For this to work you would need to have two DT entries with the "mediatek,mt8195-scp-dual" compatible properly, one with "mediatek,scp-core = <&scp_dual1 0>;" and another one with

"mediatek,scp-core = <&scp_dual0 1>;".

Quoted 2 lines

Which is also very broken... Here you have a binding whose first

argument is a

Quoted 1 line

reference to the core sibling while the second argument is a

characteristic of

Quoted 3 lines

the current core, which is highly confusing.

I suggest what when you see the compatible binding

"mediatek,mt8195-scp", a

Quoted 1 line

single core is initialized. If you see "mediatek,mt8195-scp-dual", both

cores

Quoted 4 lines

are initialized as part of the _same_ probe.

If the above analysis is not correct it means I misinterpreted your work and if so, a serious amount of comments is needed _and_ a very

detailed

Quoted 3 lines

example in "mtk,scp.yaml" that leaves no room for interpretation.

I will stop reviewing this patchset until you have clarified how this

works.

Quoted 3 lines

Thanks,
Mathieu

Quoted 7 lines

There's one problem of initializng the CORE1 using the same probe flow. The register space of CORE0 and CORE1 are overlapped in the device node. Both cores need to use the 'cfg' registers defined in scp yaml. The devm_ioremap_resource catches address overlapping and returns error when
probing CORE1 driver.

Quoted 3 lines

That is exactly why I suggest to initialise both cores within the same probe() function.

Hi Mathieu,

I'm thinking about how to initialise in the same probe() function.
I'm wondering if this implies that using one scp driver to initialize 2 cores? If it is, I assume the dts descriptions for both cores should be contained in one node.

When there's one node for both cores, it looks like that there is a problem of using dma_allocate_coherent(). Each core has its own reserved memory region. When there's only one device for both cores, it's not able to identify the memory region by the device parameter of dma_allocate_coherent().

Quoted 9 lines
Quoted 1 line

Is it acceptable to consider manually allocating core 1 device in the probe() when probing core 0?

Look at what Suman did for TI's K3 R5[1] and DSP[2] platforms. Reviewing the bindings for both platforms will also give you a good idea of how things work.

[1]. https://urldefense.com/v3/__https://elixir.bootlin.com/linux/v6.0-rc5/source/drivers/remoteproc/ti_k3_r5_remoteproc.c*L1683__;Iw!!CTRNKA9wMg0ARbw!zVcjdLSfKYGO5YQMNGqq339mle8u0VdULX30z0XV4vo3vCb9Wy-w5ixOTmzbv1akubM$
[2]. https://urldefense.com/v3/__https://elixir.bootlin.com/linux/v6.0-rc5/source/drivers/remoteproc/ti_k3_dsp_remoteproc.c*L673__;Iw!!CTRNKA9wMg0ARbw!zVcjdLSfKYGO5YQMNGqq339mle8u0VdULX30z0XV4vo3vCb9Wy-w5ixOTmzbfE2dtBg$

Hi Mathieu,

My plan is changing the dts as following,

scp core 0 {
        // Keep current properties untouched.
        compatible = "mediatek,mt8195-scp";

        // core 0 properties...

        // Add a new property for multi-core scp.
        // if not present, it's single core.
        // if present and core id = 0, it's the main core, otherwise the sub cores.
        mediatek,scp-core = <0>;

        // add sub cores as sub node.
        // sub nodes can find parent by OF API.
        scp core 1 {
                // use the same compatile name as core 0.
                compatible = "mediatek,mt8195-scp";

                // assign id > 0 to sub cores.
                mediatek,scp-core = <1>;

                // core 1 properties...
        };
};

The driver probe/remove behavior will be modified as below,

scp probe() {
        // common init...

        // check core id to have different memory mapping flow
        if (core id == 0)
                // mapping cfg, sram and others
        else
                // mapping sram
                // reuse the cfg paddr/vaddr from core 0

        // common init...

        if (core id == 0) {
                ret = of_platform_populate(...)

                // boot core 0 and sub cores
                rproc_add();
        } else {
                // add sub core as sub device to main core
                rproc_add_subdev()

                rproc->auto_boot = false;
                rpoc_add();
        }
}

scp_remove() {

Quoted 8 lines
        if (core id == 0)
                of_platform_depopulate()
        else
                rproc_remove_subdev()

        // remove core
}

Unfortunately I do not have the bandwidth to look at inlined or pseudo code. I will review this code with the next revision.

Quoted 8 lines

Best regards,
TingHan

#16 lore raw

RE: [PATCH v2 4/9] remoteproc: mediatek: Support probing for the 2nd core of dual-core SCP

In reply to TingHan Shen
Quoted 231 lines

Subject: Re: [PATCH v2 4/9] remoteproc: mediatek: Support probing for the 2nd core of dual-core SCP

Quoted 1 line · Mathieu Poirier

On Fri, 16 Sept 2022 at 06:00, TingHan Shen

Quoted 10 lines · <[email protected]> wrote:
Quoted 10 lines · Mathieu Poirier
Quoted 8 lines
Quoted 4 lines · Tinghan Shen

Hi Mathieu,

Quoted 2 lines
Quoted 2 lines

The mtk_scp.c driver only supports the single core SCP and the 1st core of a dual-core SCP. This patch extends it for the 2nd

core.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

MT8195 SCP is a dual-core MCU. Both cores are housed in the same

subsys.

Quoted 1 line
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

s/subsys/subsystem

Quoted 5 lines

They have the same viewpoint of registers and memory.

Core 1 of the SCP features its own set of core configuration registers, interrupt controller, timers, and DMAs. The rest of the peripherals in this subsystem are shared by core 0 and

core 1.

Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 6 lines
Quoted 3 lines

As for memory, core 1 has its own cache memory. the SCP SRAM is shared

/the/The

Quoted 8 lines

Review

Quoted 8 lines

by core 0 and core 1.

---
 drivers/remoteproc/mtk_scp.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/remoteproc/mtk_scp.c

Quoted 7 lines
Quoted 7 lines

index 3510c6d0bbc8..91b4aefde4ac 100644

drivers/remoteproc/mtk_scp.c +0 -0
@@ -23,6 +23,10 @@
 #define MAX_CODE_SIZE 0x500000  #define

SECTION_NAME_IPI_BUFFER ".ipi_buffer"

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/remoteproc/mtk_scp.c static int scp_probe(struct

Quoted 8 lines
drivers/remoteproc/mtk_scp.c +4 -0
+#define SCP_CORE_0 0
+#define SCP_CORE_1 1
+#define SCP_CORE_SINGLE 0xF
+
 /**
  * scp_get() - get a reference to SCP.
  *
@@ -836,6 +840,7 @@ static int scp_probe(struct

platform_device *pdev)

Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 5 lines
Quoted 5 lines
drivers/remoteproc/mtk_scp.c +1 -0
    struct resource *res;
    const char *fw_name = "scp.img";
    int ret, i;
+   u32 core_id = SCP_CORE_SINGLE;
 
Quoted 7 lines
Quoted 7 lines
drivers/remoteproc/mtk_scp.c +0 -0
    ret = rproc_of_parse_firmware(dev, 0, &fw_name);
    if (ret < 0 && ret != -EINVAL) @@ -851,8 +856,16 @@

static int scp_probe(struct platform_device *pdev)

    scp->data = of_device_get_match_data(dev);
    platform_set_drvdata(pdev, scp);

+ ret = of_property_read_u32_index(dev->of_node,

"mediatek,scp-core", 1, &core_id);

Quoted 6 lines

drivers/remoteproc/mtk_scp.c

Quoted 3 lines
drivers/remoteproc/mtk_scp.c +3 -0
+   if (ret == 0)
+           dev_info(dev, "Boot SCP dual core %u\n",
+ core_id);

Why is the DT property "mediatek,scp-core" needed at all? Since the

compatible

Quoted 2 lines

"mediatek,mt8195-scp-dual" has already been defined previously in this

patchset,

Quoted 2 lines

initialising the second core, if present, is a matter of looking at the compatile string.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

This idea of identify cores by the compatible looks workable. I'll update this series at next version.
Thanks!

Quoted 3 lines
Quoted 3 lines

+
res = platform_get_resource_byname(pdev,

IORESOURCE_MEM, "sram");

Quoted 45 lines
Quoted 45 lines
Quoted 45 lines
Quoted 45 lines
Quoted 3 lines

drivers/remoteproc/mtk_scp.c

Quoted 3 lines
drivers/remoteproc/mtk_scp.c +2 -1
-   scp->sram_base = devm_ioremap_resource(dev, res);
+   if (core_id == SCP_CORE_1)
+           scp->sram_base = devm_ioremap(dev, res->start,

resource_size(res));

Quoted 9 lines

drivers/remoteproc/mtk_scp.c

Quoted 4 lines
drivers/remoteproc/mtk_scp.c +4 -0
+   else
+           scp->sram_base = devm_ioremap_resource(dev,
+ res);
+

This looks very broken... For this to work you would need to have two DT entries with the "mediatek,mt8195-scp-dual" compatible properly, one with "mediatek,scp-core = <&scp_dual1 0>;" and another one with

"mediatek,scp-core = <&scp_dual0 1>;".

Quoted 3 lines

Which is also very broken... Here you have a binding whose first

argument is a

Quoted 1 line

reference to the core sibling while the second argument is a

characteristic of

Quoted 3 lines

the current core, which is highly confusing.

I suggest what when you see the compatible binding

"mediatek,mt8195-scp", a

Quoted 2 lines

single core is initialized. If you see
"mediatek,mt8195-scp-dual", both

cores

Quoted 5 lines

are initialized as part of the _same_ probe.

If the above analysis is not correct it means I misinterpreted your work and if so, a serious amount of comments is needed _and_ a very

detailed

Quoted 4 lines

example in "mtk,scp.yaml" that leaves no room for interpretation.

I will stop reviewing this patchset until you have clarified how this

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

works.

Quoted 3 lines

Thanks,
Mathieu

There's one problem of initializng the CORE1 using the same probe

flow.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

The register space of CORE0 and CORE1 are overlapped in the device

node.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 4 lines

Both cores need to use the 'cfg' registers defined in scp yaml. The devm_ioremap_resource catches address overlapping and returns error when probing CORE1 driver.

That is exactly why I suggest to initialise both cores within the same probe() function.

Quoted 5 lines
Quoted 5 lines

Hi Mathieu,

I'm thinking about how to initialise in the same probe() function. I'm wondering if this implies that using one scp driver to initialize 2 cores? If it is, I assume the dts descriptions for both cores should be contained

in one node.

Quoted 2 lines
Quoted 2 lines

When there's one node for both cores, it looks like that there is a

problem of

Quoted 1 line
Quoted 1 line

using dma_allocate_coherent(). Each core has its own reserved memory

region.

Quoted 1 line
Quoted 1 line

When there's only one device for both cores, it's not able to identify the

memory region

Quoted 3 lines
Quoted 3 lines

by the device parameter of dma_allocate_coherent().

Is it acceptable to consider manually allocating core 1 device in the

probe() when probing core 0?

Quoted 6 lines

Look at what Suman did for TI's K3 R5[1] and DSP[2] platforms. Reviewing the bindings for both platforms will also give you a good idea of how things work.

[1].

https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Furlde
fense.com%2Fv3%2F__https%3A%2F%2Felixir.bootlin.com%2Flinux%2Fv6.0- rc5%2Fsource%2Fdrivers%2Fremoteproc%2Fti_k3_r5_remoteproc.c*L1683_ _%3BIw!!CTRNKA9wMg0ARbw!zVcjdLSfKYGO5YQMNGqq339mle8u0VdULX3 0z0XV4vo3vCb9Wy- w5ixOTmzbv1akubM%24&amp;data=05%7C01%7Cpeng.fan%40nxp.com%7 C2cf76b2f15544cf3d06308da9a23f00a%7C686ea1d3bc2b4c6fa92cd99c5c301 635%7C0%7C0%7C637991776400238974%7CUnknown%7CTWFpbGZsb3d8e yJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D %7C3000%7C%7C%7C&amp;sdata=dz0FlQQmKI4C67XCX%2BZ6%2Bin%2Btq 2DEWLb5YA%2FxGLOxHc%3D&amp;reserved=0

Quoted 1 line

[2].

https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Furlde
fense.com%2Fv3%2F__https%3A%2F%2Felixir.bootlin.com%2Flinux%2Fv6.0- rc5%2Fsource%2Fdrivers%2Fremoteproc%2Fti_k3_dsp_remoteproc.c*L673_ _%3BIw!!CTRNKA9wMg0ARbw!zVcjdLSfKYGO5YQMNGqq339mle8u0VdULX3 0z0XV4vo3vCb9Wy- w5ixOTmzbfE2dtBg%24&amp;data=05%7C01%7Cpeng.fan%40nxp.com%7C 2cf76b2f15544cf3d06308da9a23f00a%7C686ea1d3bc2b4c6fa92cd99c5c3016 35%7C0%7C0%7C637991776400238974%7CUnknown%7CTWFpbGZsb3d8ey JWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D %7C3000%7C%7C%7C&amp;sdata=Yn7MOo2uoDOVRW47O1yq8W3c%2BYg G5URr7RdLKsmpLrk%3D&amp;reserved=0

Quoted 1 line

Hi Mathieu,

My plan is changing the dts as following,

scp core 0 {
	// Keep current properties untouched.
	compatible = "mediatek,mt8195-scp";

	// core 0 properties...

	// Add a new property for multi-core scp.
	// if not present, it's single core.
	// if present and core id = 0, it's the main core, otherwise the sub
cores.
	mediatek,scp-core = <0>;

	// add sub cores as sub node.
	// sub nodes can find parent by OF API.
	scp core 1 {
		// use the same compatile name as core 0.
Quoted 8 lines
		compatible = "mediatek,mt8195-scp";

		// assign id > 0 to sub cores.
		mediatek,scp-core = <1>;

		// core 1 properties...
	};
};

Not know the HW arch, but this looks a bit weird, scp core 1 is a sub node of scp core 0.

Quoted 4 lines

The driver probe/remove behavior will be modified as below,

Quoted 9 lines
scp probe() {
	// common init...

	// check core id to have different memory mapping flow
	if (core id == 0)
		// mapping cfg, sram and others
	else
		// mapping sram
		// reuse the cfg paddr/vaddr from core 0

Oh, I understand why you need ioremap_resource, so core0/1 share same register address space?

Regards,
Peng.

Quoted 34 lines
	// common init...

	if (core id == 0) {
		ret = of_platform_populate(...)

		// boot core 0 and sub cores
		rproc_add();
	} else {
		// add sub core as sub device to main core
		rproc_add_subdev()

		rproc->auto_boot = false;
		rpoc_add();
	}
}

scp_remove() {

	if (core id == 0)
		of_platform_depopulate()
	else
		rproc_remove_subdev()

	// remove core
}

Best regards,
TingHan

#17 lore raw

PATCH v2 5/9 remoteproc: mediatek: Add chip dependent operations for SCP core 1

In reply to Tinghan Shen

The SCP rproc operations has chip dependent callbacks. Implement a version of these callbacks for MT8195 SCP core 1.

---
 drivers/remoteproc/mtk_scp.c | 65 ++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
drivers/remoteproc/mtk_scp.c +65 -0
index 91b4aefde4ac..731a8094c373 100644
@@ -180,6 +180,16 @@ static void mt8192_scp_reset_deassert(struct mtk_scp *scp)
 	writel(1, scp->reg_base + MT8192_CORE0_SW_RSTN_CLR);
 }
 
+static void mt8195_scp_dual_reset_assert(struct mtk_scp *scp)
+{
+	writel(1, scp->reg_base + MT8195_CORE1_SW_RSTN_SET);
+}
+
+static void mt8195_scp_dual_reset_deassert(struct mtk_scp *scp)
+{
+	writel(1, scp->reg_base + MT8195_CORE1_SW_RSTN_CLR);
+}
+
 static void mt8183_scp_irq_handler(struct mtk_scp *scp)
 {
 	u32 scp_to_host;
@@ -241,6 +251,24 @@ static void mt8195_scp_irq_handler(struct mtk_scp *scp)
 	}
 }
 
+static void mt8195_scp_dual_irq_handler(struct mtk_scp *scp)
+{
+	u32 scp_to_host;
+
+	scp_to_host = readl(scp->reg_base + MT8195_SSHUB2APMCU_IPC_SET);
+
+	if (scp_to_host & MT8192_SCP_IPC_INT_BIT) {
+		scp_ipi_handler(scp);
+
+		/*
+		 * SCP won't send another interrupt until we clear
+		 * MT8195_SSHUB2APMCU_IPC_CLR.
+		 */
+		writel(MT8192_SCP_IPC_INT_BIT,
+		       scp->reg_base + MT8195_SSHUB2APMCU_IPC_CLR);
+	}
+}
+
 static irqreturn_t scp_irq_handler(int irq, void *priv)
 {
 	struct mtk_scp *scp = priv;
@@ -474,6 +502,21 @@ static int mt8195_scp_before_load(struct mtk_scp *scp)
 	return 0;
 }
 
+static int mt8195_scp_dual_before_load(struct mtk_scp *scp)
+{
+	u32 sec_ctrl;
+
+	scp_sram_power_on(scp->reg_base + MT8195_CPU1_SRAM_PD, 0);
+
+	/* hold SCP in reset while loading FW. */
+	scp->data->scp_reset_assert(scp);
+
+	/* enable MPU for all memory regions */
+	writel(0xff, scp->reg_base + MT8195_CORE1_MEM_ATT_PREDEF);
+
+	return 0;
+}
+
 static int scp_load(struct rproc *rproc, const struct firmware *fw)
 {
 	struct mtk_scp *scp = rproc->priv;
@@ -646,6 +689,15 @@ static void mt8195_scp_stop(struct mtk_scp *scp)
 	writel(0, scp->reg_base + MT8192_CORE0_WDT_CFG);
 }
 
+static void mt8195_scp_dual_stop(struct mtk_scp *scp)
+{
+	/* Power off CPU SRAM */
+	scp_sram_power_off(scp->reg_base + MT8195_CPU1_SRAM_PD, 0);
+
+	/* Disable SCP watchdog */
+	writel(0, scp->reg_base + MT8195_CORE1_WDT_CFG);
+}
+
 static int scp_stop(struct rproc *rproc)
 {
 	struct mtk_scp *scp = (struct mtk_scp *)rproc->priv;
@@ -1013,11 +1065,24 @@ static const struct mtk_scp_of_data mt8195_of_data = {
 	.host_to_scp_int_bit = MT8192_HOST_IPC_INT_BIT,
 };
 
+static const struct mtk_scp_of_data mt8195_scp_dual_of_data = {
+	.scp_clk_get = mt8195_scp_clk_get,
+	.scp_before_load = mt8195_scp_dual_before_load,
+	.scp_irq_handler = mt8195_scp_dual_irq_handler,
+	.scp_reset_assert = mt8195_scp_dual_reset_assert,
+	.scp_reset_deassert = mt8195_scp_dual_reset_deassert,
+	.scp_stop = mt8195_scp_dual_stop,
+	.scp_da_to_va = mt8192_scp_da_to_va,
+	.host_to_scp_reg = MT8192_GIPC_IN_SET,
+	.host_to_scp_int_bit = MT8195_CORE1_HOST_IPC_INT_BIT,
+};
+
 static const struct of_device_id mtk_scp_of_match[] = {
 	{ .compatible = "mediatek,mt8183-scp", .data = &mt8183_of_data },
 	{ .compatible = "mediatek,mt8186-scp", .data = &mt8186_of_data },
 	{ .compatible = "mediatek,mt8192-scp", .data = &mt8192_of_data },
 	{ .compatible = "mediatek,mt8195-scp", .data = &mt8195_of_data },
+	{ .compatible = "mediatek,mt8195-scp-dual", .data = &mt8195_scp_dual_of_data },
 	{},
 };
 MODULE_DEVICE_TABLE(of, mtk_scp_of_match);
Signature · 1 line
2.18.0
#18 lore raw

PATCH v2 6/9 remoteproc: mediatek: Add SCP core 1 SRAM offset

In reply to Tinghan Shen

Because SCP core 0 and core 1 both boot from address 0 and have the same viewpoint of memory, HW has a set of registers, "SRAM offset", to add offset to accessed address for SCP core 1 to solve this problem.

The "SRAM offset" configuration is composed by specifying a range and an offset. The value of range is from the viewpoint of SCP core 1. When SCP core 1 accessing addresses in the configured range, SCP bus adds an offset to shift the destination on SCP SRAM. This shift is transparent to the software running on SCP core 1.

---
 drivers/remoteproc/mtk_scp.c | 42 ++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
drivers/remoteproc/mtk_scp.c +42 -0
index 731a8094c373..b8a4db581179 100644
@@ -505,6 +505,27 @@ static int mt8195_scp_before_load(struct mtk_scp *scp)
 static int mt8195_scp_dual_before_load(struct mtk_scp *scp)
 {
 	u32 sec_ctrl;
+	struct device *dev = scp->dev;
+	struct device_node *main_np;
+	struct platform_device *main_pdev;
+	struct mtk_scp *scp_core0;
+
+	/* Get sram start address from SCP core 0 */
+	main_np = of_parse_phandle(dev->of_node, "mediatek,scp-core", 0);
+	if (!main_np) {
+		dev_warn(dev, "Invalid SCP main core phandle\n");
+		return -EINVAL;
+	}
+
+	main_pdev = of_find_device_by_node(main_np);
+	of_node_put(main_np);
+
+	if (!main_pdev) {
+		dev_err(dev, "Cannot find SCP core 0 device\n");
+		return -ENODEV;
+	}
+	scp_core0 = platform_get_drvdata(main_pdev);
+	put_device(&main_pdev->dev);
 
 	scp_sram_power_on(scp->reg_base + MT8195_CPU1_SRAM_PD, 0);
 
@@ -514,6 +535,27 @@ static int mt8195_scp_dual_before_load(struct mtk_scp *scp)
 	/* enable MPU for all memory regions */
 	writel(0xff, scp->reg_base + MT8195_CORE1_MEM_ATT_PREDEF);
 
+	/* The value of SRAM offset range is from the viewpoint of SCP core 1.
+	 * This configuration adds an offset on SCP bus when SCP core 1 accesses SCP SRAM
+	 * to solve the SCP core 0 and core 1 both fetch the 1st instruction from the same
+	 * SRAM address.
+	 *
+	 * Because SCP core 0 and core 1 both boot from address 0, this must be configured
+	 * before boot SCP core 1.
+	 *
+	 * Configure the range of SRAM addresses will be added offset.
+	 */
+	writel(0, scp->reg_base + MT8195_L2TCM_OFFSET_RANGE_0_LOW);
+	writel(scp->sram_size, scp->reg_base + MT8195_L2TCM_OFFSET_RANGE_0_HIGH);
+
+	/* configure the offset value */
+	writel(scp->sram_phys - scp_core0->sram_phys, scp->reg_base + MT8195_L2TCM_OFFSET);
+
+	/* enable adding sram offset when fetching instruction and data */
+	sec_ctrl = readl(scp->reg_base + MT8195_SEC_CTRL);
+	sec_ctrl |= MT8195_CORE_OFFSET_ENABLE_I | MT8195_CORE_OFFSET_ENABLE_D;
+	writel(sec_ctrl, scp->reg_base + MT8195_SEC_CTRL);
+
 	return 0;
 }
 
Signature · 1 line
2.18.0
#19 lore raw

PATCH v2 7/9 remoteproc: mediatek: Add SCP core 1 as a rproc subdevice

In reply to Tinghan Shen

Because the clock and SRAM power is controlled by SCP core 0, SCP core 1 has to be boot after SCP core 0. We use the rproc subdev to achieve this purpose.

The watchdog timeout handler of SCP core 1 is added as part of the rproc subdevice. This allows SCP core 0 to handle watchdog timeout coming from SCP core 1.

---
 drivers/remoteproc/mtk_common.h |   9 +++
 drivers/remoteproc/mtk_scp.c    | 130 ++++++++++++++++++++++++++++++++
 2 files changed, 139 insertions(+)
drivers/remoteproc/mtk_common.h +9 -0
index 5582f4207fbf..67b41866a100 100644
@@ -99,6 +99,14 @@ struct scp_ipi_desc {
 	void *priv;
 };
 
+struct scp_subdev_core {
+	struct rproc_subdev subdev;
+	struct mtk_scp *main_scp;
+	void (*scp_dual_wdt_timeout)(struct mtk_scp *scp, u32 scp_to_host);
+};
+
+#define to_subdev_core(d) container_of(d, struct scp_subdev_core, subdev)
+
 struct mtk_scp;
 
 struct mtk_scp_of_data {
@@ -144,6 +152,7 @@ struct mtk_scp {
 	size_t dram_size;
 
 	struct rproc_subdev *rpmsg_subdev;
+	struct rproc_subdev *dual_subdev;
 };
 
 /**
drivers/remoteproc/mtk_scp.c +130 -0

166 lines not on this page · raw message

Signature · 1 line
2.18.0
#20 lore raw

PATCH v2 8/9 remoteproc: mediatek: Wait SCP core 1 probe done

In reply to Tinghan Shen

SCP core 1 driver probing must finish before start loading SCP core 1 image. Add a simple flag checking mechanism when preparing SCP core 1 subdevice.

---
 drivers/remoteproc/mtk_common.h |  1 +
 drivers/remoteproc/mtk_scp.c    | 38 ++++++++++++++++++++++++++++++++-
 2 files changed, 38 insertions(+), 1 deletion(-)
drivers/remoteproc/mtk_common.h +1 -0
index 67b41866a100..89f9e53a5879 100644
@@ -153,6 +153,7 @@ struct mtk_scp {
 
 	struct rproc_subdev *rpmsg_subdev;
 	struct rproc_subdev *dual_subdev;
+	int dual_probe_done;
 };
 
 /**
drivers/remoteproc/mtk_scp.c +37 -1
index d0e9e19e251f..b66bee4beb4d 100644
@@ -937,6 +937,7 @@ static struct mtk_scp *scp_dual_get(struct mtk_scp *scp)
 	struct device *dev = scp->dev;
 	struct device_node *np;
 	struct platform_device *dual_pdev;
+	struct mtk_scp *scp_dual;
 
 	np = of_parse_phandle(dev->of_node, "mediatek,scp-core", 0);
 	dual_pdev = of_find_device_by_node(np);
@@ -947,7 +948,11 @@ static struct mtk_scp *scp_dual_get(struct mtk_scp *scp)
 		return NULL;
 	}
 
-	return platform_get_drvdata(dual_pdev);
+	scp_dual = platform_get_drvdata(dual_pdev);
+	if (!scp_dual)
+		put_device(&dual_pdev->dev);
+
+	return scp_dual;
 }
 
 static void scp_dual_put(struct mtk_scp *scp)
@@ -955,6 +960,33 @@ static void scp_dual_put(struct mtk_scp *scp)
 	put_device(scp->dev);
 }
 
+static int scp_dual_rproc_prepare(struct rproc_subdev *subdev)
+{
+	struct scp_subdev_core *subdev_core = to_subdev_core(subdev);
+	struct mtk_scp *scp = subdev_core->main_scp;
+	unsigned long timeout;
+
+	timeout = jiffies + msecs_to_jiffies(100);
+	while (1) {
+		struct mtk_scp *scp_dual = scp_dual_get(scp);
+
+		if (scp_dual && scp_dual->dual_probe_done) {
+			scp_dual_put(scp_dual);
+			break;
+		}
+
+		if (scp_dual && !scp_dual->dual_probe_done)
+			scp_dual_put(scp_dual);
+
+		if (time_after(jiffies, timeout)) {
+			dev_err(scp->dev, "scp-dual probe timeout\n");
+			return -ETIMEDOUT;
+		}
+	}
+
+	return 0;
+}
+
 static int scp_dual_rproc_start(struct rproc_subdev *subdev)
 {
 	struct scp_subdev_core *subdev_core = to_subdev_core(subdev);
@@ -1014,6 +1046,7 @@ static struct rproc_subdev *scp_dual_create_subdev(struct mtk_scp *scp)
 
 	subdev_core->main_scp = scp;
 	subdev_core->scp_dual_wdt_timeout = scp_dual_wdt_handler;
+	subdev_core->subdev.prepare = scp_dual_rproc_prepare;
 	subdev_core->subdev.start = scp_dual_rproc_start;
 	subdev_core->subdev.stop = scp_dual_rproc_stop;
 
@@ -1155,6 +1188,9 @@ static int scp_probe(struct platform_device *pdev)
 	if (ret)
 		goto remove_subdev;
 
+	if (core_id == SCP_CORE_1)
+		scp->dual_probe_done = 1;
+
 	return 0;
 
 remove_subdev:
Signature · 1 line
2.18.0
#21 lore raw

PATCH v2 9/9 mfd: cros_ec: Add SCP core 1 as a new CrOS EC MCU

In reply to Tinghan Shen

MT8195 System Companion Processors(SCP) is a dual-core RISC-V MCU. Add a new cros feature id to represent the SCP 2nd core.

The 1st core is referred to as 'core 0', and the 2nd core is referred to as 'core 1'.

---
 drivers/mfd/cros_ec_dev.c                      | 5 +++++
 include/linux/platform_data/cros_ec_commands.h | 2 ++
 include/linux/platform_data/cros_ec_proto.h    | 1 +
 3 files changed, 8 insertions(+)
drivers/mfd/cros_ec_dev.c +5 -0
index 546feef851ab..7be2e23525e1 100644
@@ -64,6 +64,11 @@ static const struct cros_feature_to_name cros_mcu_devices[] = {
 		.name	= CROS_EC_DEV_SCP_NAME,
 		.desc	= "System Control Processor",
 	},
+	{
+		.id	= EC_FEATURE_SCP_C1,
+		.name	= CROS_EC_DEV_SCP_C1_NAME,
+		.desc	= "System Control Processor 2nd Core",
+	},
 	{
 		.id	= EC_FEATURE_TOUCHPAD,
 		.name	= CROS_EC_DEV_TP_NAME,
include/linux/platform_data/cros_ec_commands.h +2 -0
index c23554531961..1176cdc92d23 100644
@@ -1296,6 +1296,8 @@ enum ec_feature_code {
 	 * mux.
 	 */
 	EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK = 43,
+	/* The MCU is a System Companion Processor (SCP) 2nd Core. */
+	EC_FEATURE_SCP_C1 = 45,
 };
 
 #define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32)
include/linux/platform_data/cros_ec_proto.h +1 -0
index df3c78c92ca2..12fc60f3c90d 100644
@@ -19,6 +19,7 @@
 #define CROS_EC_DEV_ISH_NAME	"cros_ish"
 #define CROS_EC_DEV_PD_NAME	"cros_pd"
 #define CROS_EC_DEV_SCP_NAME	"cros_scp"
+#define CROS_EC_DEV_SCP_C1_NAME	"cros_scp_c1"
 #define CROS_EC_DEV_TP_NAME	"cros_tp"
 
 /*
Signature · 1 line
2.18.0
#22 lore raw
In reply to Tinghan Shen
Quoted 4 lines · Tinghan Shen

The mediatek remoteproc driver currently only allows bringing up a single core SCP, e.g. MT8183. It also only bringing up the 1st core in SoCs with a dual-core SCP, e.g. MT8195. This series support to bring-up the 2nd core of the dual-core SCP.

Add missing change log.

v1 -> v2:
1. update dt-binding property description
2. remove kconfig for scp dual driver
3. merge mtk_scp_dual.c and mtk_scp_subdev.c to mtk_scp.c

Regards,
TingHan

Quoted 21 lines

Tinghan Shen (9):
dt-binding: remoteproc: mediatek: Support dual-core SCP
remoteproc: mediatek: Support hanlding scp core 1 wdt timeout
remoteproc: mediatek: Add SCP core 1 register definitions
remoteproc: mediatek: Support probing for the 2nd core of dual-core
SCP
remoteproc: mediatek: Add chip dependent operations for SCP core 1
remoteproc: mediatek: Add SCP core 1 SRAM offset
remoteproc: mediatek: Add SCP core 1 as a rproc subdevice
remoteproc: mediatek: Wait SCP core 1 probe done
mfd: cros_ec: Add SCP core 1 as a new CrOS EC MCU

 .../bindings/remoteproc/mtk,scp.yaml          |  13 +
 drivers/mfd/cros_ec_dev.c                     |   5 +
 drivers/remoteproc/mtk_common.h               |  35 ++
 drivers/remoteproc/mtk_scp.c                  | 322 +++++++++++++++++-
 .../linux/platform_data/cros_ec_commands.h    |   2 +
 include/linux/platform_data/cros_ec_proto.h   |   1 +
 6 files changed, 375 insertions(+), 3 deletions(-)