Skip to contentSkip to conversation

Add support for MT8195 SCP 2nd core

PATCH Superseded Tinghan Shen 2 participants 19 messages Feb 10, 2023 – Feb 13, 2023

Subsystems (3)

v5 of 17 Superseded Latest is v17 →

lore
Share & tools
lore
#0 lore raw

v5 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.

v4 -> v5:
1. move resource release actions to the platform driver remove operation
2. fix dual-core watchdog handling

v3 -> v4:
1. change the representation of dual-core SCP in dts file and update SCP yaml
2. rewrite SCP driver to reflect the change of dts node
3. drop 'remove redundant call of rproc_boot for SCP' in v3 for further investigation

v2 -> v3:
1. change the representation of dual-core SCP in dts file and update SCP yaml
2. rewrite SCP driver to reflect the change of dts node
3. add SCP core 1 node to mt8195.dtsi
4. remove redundant call of rproc_boot for SCP
5. refine IPI error message

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

Tinghan Shen (12):
dt-bindings: remoteproc: mediatek: Improve the rpmsg subnode
definition
arm64: dts: mediatek: mt8183-kukui: Update the node name of SCP rpmsg
subnode
dt-bindings: remoteproc: mediatek: Support MT8195 dual-core SCP
remoteproc: mediatek: Add SCP core 1 register definitions
remoteproc: mediatek: Add MT8195 SCP core 1 operations
remoteproc: mediatek: Extract remoteproc initialization flow
remoteproc: mediatek: Probe multi-core SCP
remoteproc: mediatek: Control SCP core 1 by rproc subdevice
remoteproc: mediatek: Setup MT8195 SCP core 1 SRAM offset
remoteproc: mediatek: Handle MT8195 SCP core 1 watchdog timeout
remoteproc: mediatek: Refine ipi handler error message
arm64: dts: mediatek: mt8195: Add SCP 2nd core

 .../bindings/remoteproc/mtk,scp.yaml          | 176 +++++++-
 .../arm64/boot/dts/mediatek/mt8183-kukui.dtsi |   2 +-
 .../boot/dts/mediatek/mt8195-cherry.dtsi      |   4 +
 arch/arm64/boot/dts/mediatek/mt8195.dtsi      |  30 +-
 drivers/remoteproc/mtk_common.h               |  47 +++
 drivers/remoteproc/mtk_scp.c                  | 392 ++++++++++++++++--
 6 files changed, 594 insertions(+), 57 deletions(-)
Signature · 1 line
2.18.0
#1 lore raw

PATCH v5 1/12 dt-bindings: remoteproc: mediatek: Improve the rpmsg subnode definition

Improve the definition of the rpmsg subnode by assigning a distinct node name and adding the definition source of node properties.

---
 .../bindings/remoteproc/mtk,scp.yaml          | 31 +++++++++----------
 1 file changed, 15 insertions(+), 16 deletions(-)
Documentation/devicetree/bindings/remoteproc/mtk,scp.yaml +15 -16
index 895415772d1d..271081df0e46 100644
@@ -58,6 +58,18 @@ properties:
   memory-region:
     maxItems: 1
 
+  cros-ec-rpmsg:
+    $ref: /schemas/mfd/google,cros-ec.yaml
+    description:
+      This subnode represents the rpmsg device. The properties
+      of this node are defined by the individual bindings for
+      the rpmsg devices.
+
+    required:
+      - mediatek,rpmsg-name
+
+    unevaluatedProperties: false
+
 required:
   - compatible
   - reg
@@ -89,21 +101,7 @@ allOf:
         reg-names:
           maxItems: 2
 
-additionalProperties:
-  type: object
-  description:
-    Subnodes of the SCP represent rpmsg devices. The names of the devices
-    are not important. The properties of these nodes are defined by the
-    individual bindings for the rpmsg devices.
-  properties:
-    mediatek,rpmsg-name:
-      $ref: /schemas/types.yaml#/definitions/string-array
-      description:
-        Contains the name for the rpmsg device. Used to match
-        the subnode to rpmsg device announced by SCP.
-
-  required:
-    - mediatek,rpmsg-name
+additionalProperties: false
 
 examples:
   - |
@@ -118,7 +116,8 @@ examples:
         clocks = <&infracfg CLK_INFRA_SCPSYS>;
         clock-names = "main";
 
-        cros_ec {
+        cros-ec-rpmsg {
+            compatible = "google,cros-ec-rpmsg";
             mediatek,rpmsg-name = "cros-ec-rpmsg";
         };
     };
Signature · 1 line
2.18.0
#2 lore raw

PATCH v5 2/12 arm64: dts: mediatek: mt8183-kukui: Update the node name of SCP rpmsg subnode

In reply to Tinghan Shen

Align the node name with the definition in SCP bindings.

---
 arch/arm64/boot/dts/mediatek/mt8183-kukui.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/mediatek/mt8183-kukui.dtsi +1 -1
index fbe14b13051a..a259eb043de5 100644
@@ -810,7 +810,7 @@
 	pinctrl-names = "default";
 	pinctrl-0 = <&scp_pins>;
 
-	cros_ec {
+	cros-ec-rpmsg {
 		compatible = "google,cros-ec-rpmsg";
 		mediatek,rpmsg-name = "cros-ec-rpmsg";
 	};
Signature · 1 line
2.18.0
#4 lore raw

PATCH v5 3/12 dt-bindings: remoteproc: mediatek: Support MT8195 dual-core SCP

In reply to Tinghan Shen

Extend the SCP binding to describe the MT8195 dual-core SCP.

Under different applications, the MT8195 SCP can be used as single-core or dual-core. This change keeps the single-core definition and adds new definitions for dual-core use case.

---
 .../bindings/remoteproc/mtk,scp.yaml          | 145 +++++++++++++++++-
 1 file changed, 141 insertions(+), 4 deletions(-)
Documentation/devicetree/bindings/remoteproc/mtk,scp.yaml +141 -4
index 271081df0e46..09102dda4942 100644
@@ -21,6 +21,7 @@ properties:
       - mediatek,mt8188-scp
       - mediatek,mt8192-scp
       - mediatek,mt8195-scp
+      - mediatek,mt8195-scp-dual
 
   reg:
     description:
@@ -31,10 +32,7 @@ properties:
 
   reg-names:
     minItems: 2
-    items:
-      - const: sram
-      - const: cfg
-      - const: l1tcm
+    maxItems: 3
 
   clocks:
     description:
@@ -70,6 +68,81 @@ properties:
 
     unevaluatedProperties: false
 
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 1
+
+  ranges:
+    description:
+      Standard ranges definition providing address translations for
+      local SCP SRAM address spaces to bus addresses.
+
+patternProperties:
+  "^scp@[a-f0-9]+$":
+    type: object
+    description:
+      The MediaTek SCP integrated to SoC might be a multi-core version.
+      The other cores are represented as child nodes of the boot core.
+      There are some integration differences for the IP like the usage of
+      address translator for translating SoC bus addresses into address space
+      for the processor.
+
+      Each SCP core has own cache memory. The SRAM and L1TCM are shared by
+      cores. The power of cache, SRAM and L1TCM power should be enabled
+      before booting SCP cores. The size of cache, SRAM, and L1TCM are varied
+      on differnt SoCs.
+
+      The SCP cores do not use an MMU, but has a set of registers to
+      control the translations between 32-bit CPU addresses into system bus
+      addresses. Cache and memory access settings are provided through a
+      Memory Protection Unit (MPU), programmable only from the SCP.
+
+    properties:
+      compatible:
+        enum:
+          - mediatek,scp-core
+
+      reg:
+        description: The base address and size of SRAM.
+        maxItems: 1
+
+      reg-names:
+        const: sram
+
+      interrupts:
+        maxItems: 1
+
+      firmware-name:
+        $ref: /schemas/types.yaml#/definitions/string
+        description:
+          If present, name (or relative path) of the file within the
+          firmware search path containing the firmware image used when
+          initializing sub cores of multi-core SCP.
+
+      memory-region:
+        maxItems: 1
+
+      cros-ec-rpmsg:
+        $ref: /schemas/mfd/google,cros-ec.yaml
+        description:
+          This subnode represents the rpmsg device. The properties
+          of this node are defined by the individual bindings for
+          the rpmsg devices.
+
+        required:
+          - mediatek,rpmsg-name
+
+        unevaluatedProperties: false
+
+    required:
+      - compatible
+      - reg
+      - reg-names
+
+    additionalProperties: false
+
 required:
   - compatible
   - reg
@@ -99,7 +172,37 @@ allOf:
         reg:
           maxItems: 2
         reg-names:
+          items:
+            - const: sram
+            - const: cfg
+  - if:
+      properties:
+        compatible:
+          enum:
+            - mediatek,mt8192-scp
+            - mediatek,mt8195-scp
+    then:
+      properties:
+        reg:
+          maxItems: 3
+        reg-names:
+          items:
+            - const: sram
+            - const: cfg
+            - const: l1tcm
+  - if:
+      properties:
+        compatible:
+          enum:
+            - mediatek,mt8195-scp-dual
+    then:
+      properties:
+        reg:
           maxItems: 2
+        reg-names:
+          items:
+            - const: cfg
+            - const: l1tcm
 
 additionalProperties: false
 
@@ -121,3 +224,37 @@ examples:
             mediatek,rpmsg-name = "cros-ec-rpmsg";
         };
     };
+
+  - |
+    scp@10500000 {
+        compatible = "mediatek,mt8195-scp-dual";
+        reg = <0x10720000 0xe0000>,
+              <0x10700000 0x8000>;
+        reg-names = "cfg", "l1tcm";
+
+        #address-cells = <1>;
+        #size-cells = <1>;
+        ranges = <0 0x10500000 0x100000>;
+
+        scp@0 {
+            compatible = "mediatek,scp-core";
+            reg = <0x0 0xa0000>;
+            reg-names = "sram";
+
+            cros-ec-rpmsg {
+                compatible = "google,cros-ec-rpmsg";
+                mediatek,rpmsg-name = "cros-ec-rpmsg";
+            };
+        };
+
+        scp@a0000 {
+            compatible = "mediatek,scp-core";
+            reg = <0xa0000 0x20000>;
+            reg-names = "sram";
+
+            cros-ec-rpmsg {
+                compatible = "google,cros-ec-rpmsg";
+                mediatek,rpmsg-name = "cros-ec-rpmsg";
+            };
+        };
+    };
Signature · 1 line
2.18.0
maintainer Reviewed-by on v5 3/12
#5 lore raw

Re: [PATCH v5 03/12] dt-bindings: remoteproc: mediatek: Support MT8195 dual-core SCP

Il 10/02/23 09:59, Tinghan Shen ha scritto:

Quoted 8 lines

Extend the SCP binding to describe the MT8195 dual-core SCP.

Under different applications, the MT8195 SCP can be used as single-core or dual-core. This change keeps the single-core definition and adds new definitions for dual-core use case.

#6 lore raw

PATCH v5 4/12 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 ea6fa1100a00..3778894c96f3 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
@@ -56,6 +57,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
#7 lore raw

PATCH v5 5/12 remoteproc: mediatek: Add MT8195 SCP core 1 operations

In reply to Tinghan Shen

The SCP rproc driver has a set of chip dependent callbacks for boot sequence and IRQ handling. Implement these callbacks for MT8195 SCP core 1.

---
 drivers/remoteproc/mtk_scp.c | 56 ++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
drivers/remoteproc/mtk_scp.c +56 -0
index d421a2ccaa1e..b92274067522 100644
@@ -176,6 +176,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_c1_reset_assert(struct mtk_scp *scp)
+{
+	writel(1, scp->reg_base + MT8195_CORE1_SW_RSTN_SET);
+}
+
+static void mt8195_scp_c1_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;
@@ -212,6 +222,18 @@ static void mt8192_scp_irq_handler(struct mtk_scp *scp)
 	}
 }
 
+static void mt8195_scp_c1_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);
+
+	writel(scp_to_host, scp->reg_base + MT8195_SSHUB2APMCU_IPC_CLR);
+}
+
 static irqreturn_t scp_irq_handler(int irq, void *priv)
 {
 	struct mtk_scp *scp = priv;
@@ -453,6 +475,19 @@ static int mt8195_scp_before_load(struct mtk_scp *scp)
 	return 0;
 }
 
+static int mt8195_scp_c1_before_load(struct mtk_scp *scp)
+{
+	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;
@@ -625,6 +660,15 @@ static void mt8195_scp_stop(struct mtk_scp *scp)
 	writel(0, scp->reg_base + MT8192_CORE0_WDT_CFG);
 }
 
+static void mt8195_scp_c1_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;
@@ -990,6 +1034,18 @@ 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_of_data_c1 = {
+	.scp_clk_get = mt8195_scp_clk_get,
+	.scp_before_load = mt8195_scp_c1_before_load,
+	.scp_irq_handler = mt8195_scp_c1_irq_handler,
+	.scp_reset_assert = mt8195_scp_c1_reset_assert,
+	.scp_reset_deassert = mt8195_scp_c1_reset_deassert,
+	.scp_stop = mt8195_scp_c1_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 },
Signature · 1 line
2.18.0
#8 lore raw

PATCH v5 6/12 remoteproc: mediatek: Extract remoteproc initialization flow

In reply to Tinghan Shen

This is the preparation for probing multi-core SCP. The remoteproc initialization flow is similar on cores and is reuesd to avoid redundant code.

The registers of config and l1tcm are shared for multi-core SCP. Reuse the mapped addresses for all cores.

---
 drivers/remoteproc/mtk_common.h |  7 +++++
 drivers/remoteproc/mtk_scp.c    | 55 +++++++++++++++++++++------------
 2 files changed, 42 insertions(+), 20 deletions(-)
drivers/remoteproc/mtk_common.h +7 -0
index 3778894c96f3..20c1a90be77d 100644
@@ -112,6 +112,13 @@ struct mtk_scp_of_data {
 	size_t ipi_buf_offset;
 };
 
+struct mtk_scp_of_regs {
+	void __iomem *reg_base;
+	void __iomem *l1tcm_base;
+	size_t l1tcm_size;
+	phys_addr_t l1tcm_phys;
+};
+
 struct mtk_scp {
 	struct device *dev;
 	struct rproc *rproc;
drivers/remoteproc/mtk_scp.c +35 -20

85 lines not on this page · raw message

Signature · 1 line
2.18.0
#9 lore raw

Re: [PATCH v5 06/12] remoteproc: mediatek: Extract remoteproc initialization flow

Il 10/02/23 09:59, Tinghan Shen ha scritto:

Quoted 18 lines

This is the preparation for probing multi-core SCP. The remoteproc initialization flow is similar on cores and is reuesd to avoid redundant code.

The registers of config and l1tcm are shared for multi-core SCP. Reuse the mapped addresses for all cores.

---
  drivers/remoteproc/mtk_common.h |  7 +++++
  drivers/remoteproc/mtk_scp.c    | 55 +++++++++++++++++++++------------
  2 files changed, 42 insertions(+), 20 deletions(-)
drivers/remoteproc/mtk_common.h +0 -0
index 3778894c96f3..20c1a90be77d 100644

drivers/remoteproc/mtk_common.h struct mtk_scp_of_data { · line 115

Quoted 4 lines
drivers/remoteproc/mtk_common.h +1 -0
@@ -112,6 +112,13 @@ struct mtk_scp_of_data {
  	size_t ipi_buf_offset;
  };
 
+struct mtk_scp_of_regs {

In v4, I already commented on this one, saying that this structure is used only in mtk_scp.c as a commodity and *only* as a commodity for passing data between two functions, and I already asked to move this structure definition to mtk_scp.c.

Thanks,
Angelo

Quoted 103 lines
drivers/remoteproc/mtk_common.h +6 -0
+	void __iomem *reg_base;
+	void __iomem *l1tcm_base;
+	size_t l1tcm_size;
+	phys_addr_t l1tcm_phys;
+};
+
  struct mtk_scp {
  	struct device *dev;
  	struct rproc *rproc;
drivers/remoteproc/mtk_scp.c +35 -20
index b92274067522..898039879142 100644
@@ -854,7 +854,8 @@ static void scp_remove_rpmsg_subdev(struct mtk_scp *scp)
  	}
  }
 
-static int scp_probe(struct platform_device *pdev)
+static int scp_rproc_init(struct platform_device *pdev,
+			  struct mtk_scp_of_regs *of_regs)
  {
  	struct device *dev = &pdev->dev;
  	struct device_node *np = dev->of_node;
@@ -878,6 +879,11 @@ static int scp_probe(struct platform_device *pdev)
  	scp->data = of_device_get_match_data(dev);
  	platform_set_drvdata(pdev, scp);
 
+	scp->reg_base = of_regs->reg_base;
+	scp->l1tcm_base = of_regs->l1tcm_base;
+	scp->l1tcm_size = of_regs->l1tcm_size;
+	scp->l1tcm_phys = of_regs->l1tcm_phys;
+
  	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sram");
  	scp->sram_base = devm_ioremap_resource(dev, res);
  	if (IS_ERR(scp->sram_base))
@@ -887,24 +893,6 @@ static int scp_probe(struct platform_device *pdev)
  	scp->sram_size = resource_size(res);
  	scp->sram_phys = res->start;
 
-	/* l1tcm is an optional memory region */
-	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "l1tcm");
-	scp->l1tcm_base = devm_ioremap_resource(dev, res);
-	if (IS_ERR(scp->l1tcm_base)) {
-		ret = PTR_ERR(scp->l1tcm_base);
-		if (ret != -EINVAL) {
-			return dev_err_probe(dev, ret, "Failed to map l1tcm memory\n");
-		}
-	} else {
-		scp->l1tcm_size = resource_size(res);
-		scp->l1tcm_phys = res->start;
-	}
-
-	scp->reg_base = devm_platform_ioremap_resource_byname(pdev, "cfg");
-	if (IS_ERR(scp->reg_base))
-		return dev_err_probe(dev, PTR_ERR(scp->reg_base),
-				     "Failed to parse and map cfg memory\n");
-
  	ret = scp->data->scp_clk_get(scp);
  	if (ret)
  		return ret;
@@ -932,7 +920,6 @@ static int scp_probe(struct platform_device *pdev)
  	ret = devm_request_threaded_irq(dev, platform_get_irq(pdev, 0), NULL,
  					scp_irq_handler, IRQF_ONESHOT,
  					pdev->name, scp);
-
  	if (ret) {
  		dev_err(dev, "failed to request irq\n");
  		goto remove_subdev;
@@ -956,6 +943,34 @@ static int scp_probe(struct platform_device *pdev)
  	return ret;
  }
 
+static int scp_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct resource *res;
+	struct mtk_scp_of_regs scp_regs;
+	int ret;
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "cfg");
+	scp_regs.reg_base = devm_ioremap_resource(dev, res);
+	if (IS_ERR(scp_regs.reg_base))
+		return dev_err_probe(dev, PTR_ERR(scp_regs.reg_base),
+				     "Failed to parse and map cfg memory\n");
+
+	/* l1tcm is an optional memory region */
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "l1tcm");
+	scp_regs.l1tcm_base = devm_ioremap_resource(dev, res);
+	if (IS_ERR(scp_regs.l1tcm_base)) {
+		ret = PTR_ERR(scp_regs.l1tcm_base);
+		if (ret != -EINVAL)
+			return dev_err_probe(dev, ret, "Failed to map l1tcm memory\n");
+	} else {
+		scp_regs.l1tcm_size = resource_size(res);
+		scp_regs.l1tcm_phys = res->start;
+	}
+
+	return scp_rproc_init(pdev, &scp_regs);
+}
+
  static int scp_remove(struct platform_device *pdev)
  {
  	struct mtk_scp *scp = platform_get_drvdata(pdev);
#10 lore raw

Re: [PATCH v5 06/12] remoteproc: mediatek: Extract remoteproc initialization flow

Quoted 22 lines · AngeloGioacchino Del Regno

Il 10/02/23 09:59, Tinghan Shen ha scritto:

Quoted 21 lines

This is the preparation for probing multi-core SCP. The remoteproc initialization flow is similar on cores and is reuesd to avoid redundant code.

The registers of config and l1tcm are shared for multi-core SCP. Reuse the mapped addresses for all cores.

---
  drivers/remoteproc/mtk_common.h |  7 +++++
  drivers/remoteproc/mtk_scp.c    | 55 +++++++++++++++++++++------------
  2 files changed, 42 insertions(+), 20 deletions(-)
drivers/remoteproc/mtk_common.h +0 -0
index 3778894c96f3..20c1a90be77d 100644
@@ -112,6 +112,13 @@ struct mtk_scp_of_data {
  	size_t ipi_buf_offset;
  };
 
Quoted 6 lines

drivers/remoteproc/mtk_common.h struct mtk_scp_of_data { · line 115

Quoted 1 line
drivers/remoteproc/mtk_common.h +1 -0
+struct mtk_scp_of_regs {

In v4, I already commented on this one, saying that this structure is used only in mtk_scp.c as a commodity and *only* as a commodity for passing data between two functions, and I already asked to move this structure definition to mtk_scp.c.

I'm sorry. I missed this part.
I'll update this in next version.

Quoted 109 lines

Thanks,
Angelo

Quoted 103 lines
drivers/remoteproc/mtk_common.h +6 -0
+	void __iomem *reg_base;
+	void __iomem *l1tcm_base;
+	size_t l1tcm_size;
+	phys_addr_t l1tcm_phys;
+};
+
  struct mtk_scp {
  	struct device *dev;
  	struct rproc *rproc;
drivers/remoteproc/mtk_scp.c +35 -20
index b92274067522..898039879142 100644
@@ -854,7 +854,8 @@ static void scp_remove_rpmsg_subdev(struct mtk_scp *scp)
  	}
  }
 
-static int scp_probe(struct platform_device *pdev)
+static int scp_rproc_init(struct platform_device *pdev,
+			  struct mtk_scp_of_regs *of_regs)
  {
  	struct device *dev = &pdev->dev;
  	struct device_node *np = dev->of_node;
@@ -878,6 +879,11 @@ static int scp_probe(struct platform_device *pdev)
  	scp->data = of_device_get_match_data(dev);
  	platform_set_drvdata(pdev, scp);
 
+	scp->reg_base = of_regs->reg_base;
+	scp->l1tcm_base = of_regs->l1tcm_base;
+	scp->l1tcm_size = of_regs->l1tcm_size;
+	scp->l1tcm_phys = of_regs->l1tcm_phys;
+
  	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sram");
  	scp->sram_base = devm_ioremap_resource(dev, res);
  	if (IS_ERR(scp->sram_base))
@@ -887,24 +893,6 @@ static int scp_probe(struct platform_device *pdev)
  	scp->sram_size = resource_size(res);
  	scp->sram_phys = res->start;
 
-	/* l1tcm is an optional memory region */
-	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "l1tcm");
-	scp->l1tcm_base = devm_ioremap_resource(dev, res);
-	if (IS_ERR(scp->l1tcm_base)) {
-		ret = PTR_ERR(scp->l1tcm_base);
-		if (ret != -EINVAL) {
-			return dev_err_probe(dev, ret, "Failed to map l1tcm memory\n");
-		}
-	} else {
-		scp->l1tcm_size = resource_size(res);
-		scp->l1tcm_phys = res->start;
-	}
-
-	scp->reg_base = devm_platform_ioremap_resource_byname(pdev, "cfg");
-	if (IS_ERR(scp->reg_base))
-		return dev_err_probe(dev, PTR_ERR(scp->reg_base),
-				     "Failed to parse and map cfg memory\n");
-
  	ret = scp->data->scp_clk_get(scp);
  	if (ret)
  		return ret;
@@ -932,7 +920,6 @@ static int scp_probe(struct platform_device *pdev)
  	ret = devm_request_threaded_irq(dev, platform_get_irq(pdev, 0), NULL,
  					scp_irq_handler, IRQF_ONESHOT,
  					pdev->name, scp);
-
  	if (ret) {
  		dev_err(dev, "failed to request irq\n");
  		goto remove_subdev;
@@ -956,6 +943,34 @@ static int scp_probe(struct platform_device *pdev)
  	return ret;
  }
 
+static int scp_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct resource *res;
+	struct mtk_scp_of_regs scp_regs;
+	int ret;
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "cfg");
+	scp_regs.reg_base = devm_ioremap_resource(dev, res);
+	if (IS_ERR(scp_regs.reg_base))
+		return dev_err_probe(dev, PTR_ERR(scp_regs.reg_base),
+				     "Failed to parse and map cfg memory\n");
+
+	/* l1tcm is an optional memory region */
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "l1tcm");
+	scp_regs.l1tcm_base = devm_ioremap_resource(dev, res);
+	if (IS_ERR(scp_regs.l1tcm_base)) {
+		ret = PTR_ERR(scp_regs.l1tcm_base);
+		if (ret != -EINVAL)
+			return dev_err_probe(dev, ret, "Failed to map l1tcm memory\n");
+	} else {
+		scp_regs.l1tcm_size = resource_size(res);
+		scp_regs.l1tcm_phys = res->start;
+	}
+
+	return scp_rproc_init(pdev, &scp_regs);
+}
+
  static int scp_remove(struct platform_device *pdev)
  {
  	struct mtk_scp *scp = platform_get_drvdata(pdev);
Signature · 2 lines
Best regards,
TingHan
#11 lore raw

PATCH v5 7/12 remoteproc: mediatek: Probe multi-core SCP

In reply to Tinghan Shen

The difference of single-core SCP and multi-core SCP device tree is the presence of child device nodes described SCP cores. The SCP driver populates the platform device and checks the child nodes to identify whether it's a single-core SCP or a multi-core SCP.

The resource structure of the multi-core SCP is a list of remoteproc instances which is different to the single-core SCP. The corresponding resource releasing action is based on the type of SCP.

---
 drivers/remoteproc/mtk_common.h |   7 ++
 drivers/remoteproc/mtk_scp.c    | 177 +++++++++++++++++++++++++++++---
 2 files changed, 169 insertions(+), 15 deletions(-)
drivers/remoteproc/mtk_common.h +7 -0
index 20c1a90be77d..0b2c4bbb55f0 100644
@@ -119,6 +119,10 @@ struct mtk_scp_of_regs {
 	phys_addr_t l1tcm_phys;
 };
 
+struct mtk_scp_cluster {
+	struct list_head cores;
+};
+
 struct mtk_scp {
 	struct device *dev;
 	struct rproc *rproc;
@@ -147,6 +151,9 @@ struct mtk_scp {
 	size_t dram_size;
 
 	struct rproc_subdev *rpmsg_subdev;
+
+	struct list_head elem;
+	struct mtk_scp_cluster *cluster;
 };
 
 /**
drivers/remoteproc/mtk_scp.c +162 -15

229 lines not on this page · raw message

Signature · 1 line
2.18.0
#12 lore raw

PATCH v5 8/12 remoteproc: mediatek: Control SCP core 1 by rproc subdevice

In reply to Tinghan Shen

Register SCP core 1 as a subdevice of core 0 for the boot sequence and watchdog timeout handling. The core 1 has to boot after core 0 because the SCP clock and SRAM power is controlled by SCP core 0. As for watchdog timeout handling, the remoteproc framework helps to stop/start subdevices automatically when SCP driver receives watchdog timeout event.

---
 drivers/remoteproc/mtk_common.h |  8 ++++
 drivers/remoteproc/mtk_scp.c    | 66 +++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+)
drivers/remoteproc/mtk_common.h +8 -0
index 0b2c4bbb55f0..e4ef97f2d3a1 100644
@@ -123,6 +123,13 @@ struct mtk_scp_cluster {
 	struct list_head cores;
 };
 
+struct mtk_scp_core_subdev {
+	struct rproc_subdev subdev;
+	struct mtk_scp *scp;
+};
+
+#define to_core_subdev(d) container_of(d, struct mtk_scp_core_subdev, subdev)
+
 struct mtk_scp {
 	struct device *dev;
 	struct rproc *rproc;
@@ -154,6 +161,7 @@ struct mtk_scp {
 
 	struct list_head elem;
 	struct mtk_scp_cluster *cluster;
+	struct mtk_scp_core_subdev *core_subdev;
 };
 
 /**
drivers/remoteproc/mtk_scp.c +66 -0

84 lines not on this page · raw message

Signature · 1 line
2.18.0
#13 lore raw

PATCH v5 9/12 remoteproc: mediatek: Setup MT8195 SCP core 1 SRAM offset

In reply to Tinghan Shen

Because MT8195 SCP core 0 and core 1 both boot from head of SRAM and have the same viewpoint of SRAM, SCP has a "core 1 SRAM offset" configuration to control the access destination of SCP core 1 to boot core 1 from different SRAM location.

The "core 1 SRAM offset" configuration is composed by a range and an offset. It works like a simple memory mapped mechanism. When SCP core 1 accesses a SRAM address located in the range, the SCP bus adds the configured offset to the address to shift the physical destination address on SCP SRAM. This shifting is transparent to the software running on SCP core 1.

---
 drivers/remoteproc/mtk_scp.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
drivers/remoteproc/mtk_scp.c +27 -0
index f1dfe610dfb1..569e915dfa0f 100644
@@ -477,6 +477,9 @@ static int mt8195_scp_before_load(struct mtk_scp *scp)
 
 static int mt8195_scp_c1_before_load(struct mtk_scp *scp)
 {
+	u32 sec_ctrl;
+	struct mtk_scp *scp_c0;
+
 	scp_sram_power_on(scp->reg_base + MT8195_CPU1_SRAM_PD, 0);
 
 	/* hold SCP in reset while loading FW. */
@@ -485,6 +488,30 @@ static int mt8195_scp_c1_before_load(struct mtk_scp *scp)
 	/* enable MPU for all memory regions */
 	writel(0xff, scp->reg_base + MT8195_CORE1_MEM_ATT_PREDEF);
 
+	/*
+	 * The L2TCM_OFFSET_RANGE and L2TCM_OFFSET shift the destination address
+	 * on SRAM when SCP core 1 accesses SRAM.
+	 *
+	 * This configuration solves booting the SCP core 0 and core 1 from
+	 * different SRAM address because core 0 and core 1 both boot from
+	 * the head of SRAM by default. this must be configured before boot SCP core 1.
+	 *
+	 * The value of L2TCM_OFFSET_RANGE is from the viewpoint of SCP core 1.
+	 * When SCP core 1 issues address within the range (L2TCM_OFFSET_RANGE),
+	 * the address will be added with a fixed offset (L2TCM_OFFSET) on the bus.
+	 * The shift action is tranparent to software.
+	 */
+	writel(0, scp->reg_base + MT8195_L2TCM_OFFSET_RANGE_0_LOW);
+	writel(scp->sram_size, scp->reg_base + MT8195_L2TCM_OFFSET_RANGE_0_HIGH);
+
+	scp_c0 = list_first_entry(&scp->cluster->cores, struct mtk_scp, elem);
+	writel(scp->sram_phys - scp_c0->sram_phys, scp->reg_base + MT8195_L2TCM_OFFSET);
+
+	/* enable 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
#14 lore raw

PATCH v5 10/12 remoteproc: mediatek: Handle MT8195 SCP core 1 watchdog timeout

In reply to Tinghan Shen

The MT8195 SCP core 1 watchdog timeout needs to be handled in the SCP core 0 IRQ handler because the MT8195 SCP core 1 watchdog timeout IRQ is wired on the same IRQ entry for core 0 watchdog timeout. MT8195 SCP has a watchdog status register to identify the watchdog timeout source when IRQ triggered.

---
 drivers/remoteproc/mtk_common.h |  4 ++++
 drivers/remoteproc/mtk_scp.c    | 25 ++++++++++++++++++++++++-
 2 files changed, 28 insertions(+), 1 deletion(-)
drivers/remoteproc/mtk_common.h +4 -0
index e4ef97f2d3a1..ca2395b98d27 100644
@@ -55,6 +55,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 MT8195_CPU1_SRAM_PD			0x1084
drivers/remoteproc/mtk_scp.c +24 -1
index 569e915dfa0f..2b43e23f6de7 100644
@@ -222,6 +222,29 @@ 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);
+	} else {
+		u32 reason = readl(scp->reg_base + MT8195_SYS_STATUS);
+
+		if (reason & MT8195_CORE0_WDT)
+			writel(1, scp->reg_base + MT8192_CORE0_WDT_IRQ);
+
+		if (reason & MT8195_CORE1_WDT)
+			writel(1, scp->reg_base + MT8195_CORE1_WDT_IRQ);
+
+		scp_wdt_handler(scp, reason);
+	}
+
+	writel(scp_to_host, scp->reg_base + MT8192_SCP2APMCU_IPC_CLR);
+}
+
 static void mt8195_scp_c1_irq_handler(struct mtk_scp *scp)
 {
 	u32 scp_to_host;
@@ -1273,7 +1296,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 Reviewed-by on v5 10/12
#15 lore raw

Re: [PATCH v5 10/12] remoteproc: mediatek: Handle MT8195 SCP core 1 watchdog timeout

Il 10/02/23 09:59, Tinghan Shen ha scritto:

Quoted 7 lines

The MT8195 SCP core 1 watchdog timeout needs to be handled in the SCP core 0 IRQ handler because the MT8195 SCP core 1 watchdog timeout IRQ is wired on the same IRQ entry for core 0 watchdog timeout. MT8195 SCP has a watchdog status register to identify the watchdog timeout source when IRQ triggered.

#16 lore raw

PATCH v5 11/12 remoteproc: mediatek: Refine ipi handler error message

In reply to Tinghan Shen

The error message doesn't accurately reflect the cause of the error. The error is due to a handler not being found, not an invalid IPI ID.

---
 drivers/remoteproc/mtk_scp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/remoteproc/mtk_scp.c +1 -1
index 2b43e23f6de7..c8a964c30181 100644
@@ -106,7 +106,7 @@ static void scp_ipi_handler(struct mtk_scp *scp)
 	scp_ipi_lock(scp, id);
 	handler = ipi_desc[id].handler;
 	if (!handler) {
-		dev_err(scp->dev, "No such ipi id = %d\n", id);
+		dev_err(scp->dev, "No handler for ipi id = %d\n", id);
 		scp_ipi_unlock(scp, id);
 		return;
 	}
Signature · 1 line
2.18.0
#17 lore raw

PATCH v5 12/12 arm64: dts: mediatek: mt8195: Add SCP 2nd core

In reply to Tinghan Shen

Rewrite the MT8195 SCP device node as a cluster and add the SCP 2nd core in it.

Since the SCP device node is changed to multi-core structure, enable SCP cluster to enable probing SCP core 0.

---
 .../boot/dts/mediatek/mt8195-cherry.dtsi      |  4 +++
 arch/arm64/boot/dts/mediatek/mt8195.dtsi      | 30 ++++++++++++++-----
 2 files changed, 27 insertions(+), 7 deletions(-)
arch/arm64/boot/dts/mediatek/mt8195-cherry.dtsi +4 -0
index 56749cfe7c33..4f9bc7581adb 100644
@@ -933,6 +933,10 @@
 	interrupts-extended = <&pio 222 IRQ_TYPE_LEVEL_HIGH>;
 };
 
+&scp_cluster {
+	status = "okay";
+};
+
 &scp {
 	status = "okay";
 
arch/arm64/boot/dts/mediatek/mt8195.dtsi +23 -7
index 8f1264d5290b..87e49f5fb7b3 100644
@@ -826,14 +826,30 @@
 			clocks = <&infracfg_ao CLK_INFRA_AO_GCE2>;
 		};
 
-		scp: scp@10500000 {
-			compatible = "mediatek,mt8195-scp";
-			reg = <0 0x10500000 0 0x100000>,
-			      <0 0x10720000 0 0xe0000>,
-			      <0 0x10700000 0 0x8000>;
-			reg-names = "sram", "cfg", "l1tcm";
-			interrupts = <GIC_SPI 462 IRQ_TYPE_LEVEL_HIGH 0>;
+		scp_cluster: scp@10500000 {
+			compatible = "mediatek,mt8195-scp-dual";
+			reg = <0 0x10720000 0 0xe0000>, <0 0x10700000 0 0x8000>;
+			reg-names = "cfg", "l1tcm";
+			#address-cells = <1>;
+			#size-cells = <1>;
+			ranges = <0 0 0x10500000 0x100000>;
 			status = "disabled";
+
+			scp: scp@0 {
+				compatible = "mediatek,scp-core";
+				reg = <0x0 0xa0000>;
+				reg-names = "sram";
+				interrupts = <GIC_SPI 462 IRQ_TYPE_LEVEL_HIGH 0>;
+				status = "disabled";
+			};
+
+			scp_c1: scp@a0000 {
+				compatible = "mediatek,scp-core";
+				reg = <0xa0000 0x20000>;
+				reg-names = "sram";
+				interrupts = <GIC_SPI 463 IRQ_TYPE_LEVEL_HIGH 0>;
+				status = "disabled";
+			};
 		};
 
 		scp_adsp: clock-controller@10720000 {
Signature · 1 line
2.18.0
maintainer Reviewed-by on v5 12/12
#18 lore raw

Re: [PATCH v5 12/12] arm64: dts: mediatek: mt8195: Add SCP 2nd core

Il 10/02/23 09:59, Tinghan Shen ha scritto:

Quoted 42 lines

Rewrite the MT8195 SCP device node as a cluster and add the SCP 2nd core in it.

Since the SCP device node is changed to multi-core structure, enable SCP cluster to enable probing SCP core 0.

---
  .../boot/dts/mediatek/mt8195-cherry.dtsi      |  4 +++
  arch/arm64/boot/dts/mediatek/mt8195.dtsi      | 30 ++++++++++++++-----
  2 files changed, 27 insertions(+), 7 deletions(-)
arch/arm64/boot/dts/mediatek/mt8195-cherry.dtsi +4 -0
index 56749cfe7c33..4f9bc7581adb 100644
@@ -933,6 +933,10 @@
  	interrupts-extended = <&pio 222 IRQ_TYPE_LEVEL_HIGH>;
  };
 
+&scp_cluster {
+	status = "okay";
+};
+
  &scp {
  	status = "okay";
 
arch/arm64/boot/dts/mediatek/mt8195.dtsi +0 -7
index 8f1264d5290b..87e49f5fb7b3 100644
@@ -826,14 +826,30 @@
  			clocks = <&infracfg_ao CLK_INFRA_AO_GCE2>;
  		};
 
-		scp: scp@10500000 {
-			compatible = "mediatek,mt8195-scp";
-			reg = <0 0x10500000 0 0x100000>,
-			      <0 0x10720000 0 0xe0000>,
-			      <0 0x10700000 0 0x8000>;
-			reg-names = "sram", "cfg", "l1tcm";
-			interrupts = <GIC_SPI 462 IRQ_TYPE_LEVEL_HIGH 0>;

arch/arm64/boot/dts/mediatek/mt8195.dtsi line 838

Quoted 10 lines
arch/arm64/boot/dts/mediatek/mt8195.dtsi +9 -0
+		scp_cluster: scp@10500000 {
+			compatible = "mediatek,mt8195-scp-dual";
+			reg = <0 0x10720000 0 0xe0000>, <0 0x10700000 0 0x8000>;
+			reg-names = "cfg", "l1tcm";
+			#address-cells = <1>;
+			#size-cells = <1>;
+			ranges = <0 0 0x10500000 0x100000>;
  			status = "disabled";
+
+			scp: scp@0 {

Minor nit: Please change this to scp_c0:.
Like that, we keep consistency and increase readability, as we're clearly then reading that one node is for core 0, the other is for core 1.

This is fine even on devices using only a single SCP core, because in devicetree we are describing the hardware, not the software implemetation of it - and the MT8195 SoC does, by hardware, have two SCP cores anyway :-)

After which,