Skip to contentSkip to conversation

add zynqmp TCM bindings

PATCH Superseded Tanmay Shah 3 participants 13 messages Dec 15, 2023 – Jan 8, 2024

Subsystems (3)

v8 of 15 Superseded Latest is v15 →

lore
Share & tools
lore
#0 lore raw

v8 cover add zynqmp TCM bindings

Tightly-Coupled Memories(TCMs) are low-latency memory that provides predictable instruction execution and predictable data load/store timing. Each Cortex-R5F processor contains exclusive two 64 KB memory banks on the ATCM and BTCM ports, for a total of 128 KB of memory. In lockstep mode, both 128KB memory is accessible to the cluster.

As per ZynqMP Ultrascale+ Technical Reference Manual UG1085, following is address space of TCM memory. The bindings in this patch series introduces properties to accommodate following address space with address translation between Linux and Cortex-R5 views.

|     |     |     |
| --- | --- | --- |
|      *Mode*        |   *R5 View* | *Linux view* |  Notes               |
| *Split Mode*       | *start addr*| *start addr* |                      |
| R5_0 ATCM (64 KB)  | 0x0000_0000 | 0xFFE0_0000  |                      |
| R5_0 BTCM (64 KB)  | 0x0002_0000 | 0xFFE2_0000  |                      |
| R5_1 ATCM (64 KB)  | 0x0000_0000 | 0xFFE9_0000  | alias of 0xFFE1_0000 |
| R5_1 BTCM (64 KB)  | 0x0002_0000 | 0xFFEB_0000  | alias of 0xFFE3_0000 |
|  ___               |     ___     |    ___       |                      |
| *Lockstep Mode*    |             |              |                      |
| R5_0 ATCM (128 KB) | 0x0000_0000 | 0xFFE0_0000  |                      |
| R5_0 BTCM (128 KB) | 0x0002_0000 | 0xFFE2_0000  |                      |

References:
UG1085 TCM address space:
https://docs.xilinx.com/r/en-US/ug1085-zynq-ultrascale-trm/Tightly-Coupled-Memory-Address-Map

Changes in v8:
- Remove use of pm_domains framework
- Remove checking of pm_domain_id validation to power on/off tcm
- Remove spurious change
- parse power-domains property from device-tree and use EEMI calls to power on/off TCM instead of using pm domains framework

Changes in v7:
- %s/pm_dev1/pm_dev_core0/r
- %s/pm_dev_link1/pm_dev_core0_link/r
- %s/pm_dev2/pm_dev_core1/r
- %s/pm_dev_link2/pm_dev_core1_link/r
- remove pm_domain_id check to move next patch
- add comment about how 1st entry in pm domain list is used
- fix loop when jump to fail_add_pm_domains loop
- move checking of pm_domain_id from previous patch
- fix mem_bank_data memory allocation

Changes in v6:
- Introduce new node entry for r5f cluster split mode dts and keep it disabled by default.
- Keep remoteproc lockstep mode enabled by default to maintian back compatibility.
- Enable split mode only for zcu102 board to demo split mode use
- Remove spurious change
- Handle errors in add_pm_domains function
- Remove redundant code to handle errors from remove_pm_domains
- Missing . at the end of the commit message
- remove redundant initialization of variables
- remove fail_tcm label and relevant code to free memory acquired using devm_* API. As this will be freed when device free it
- add extra check to see if "reg" property is supported or not

Changes in v5:
- maintain Rob's Ack on bindings patch as no changes in bindings
- split previous patch into multiple patches
- Use pm domain framework to turn on/off TCM
- Add support of parsing TCM information from device-tree
- maintain backward compatibility with previous bindings without TCM information available in device-tree

This patch series continues previous effort to upstream ZynqMP TCM bindings:
Previous v4 version link:
https://lore.kernel.org/all/[email protected]/

Previous v3 version link:
https://lore.kernel.org/all/[email protected]/
Radhey Shyam Pandey (1):
dt-bindings: remoteproc: add Tightly Coupled Memory (TCM) bindings

Radhey Shyam Pandey (1):
dt-bindings: remoteproc: add Tightly Coupled Memory (TCM) bindings

Tanmay Shah (2):
dts: zynqmp: add properties for TCM in remoteproc
remoteproc: zynqmp: parse TCM from device tree

 .../remoteproc/xlnx,zynqmp-r5fss.yaml         | 131 +++++++++++++--
 .../boot/dts/xilinx/zynqmp-zcu102-rev1.0.dts  |   8 +
 arch/arm64/boot/dts/xilinx/zynqmp.dtsi        |  60 ++++++-
 drivers/remoteproc/xlnx_r5_remoteproc.c       | 154 +++++++++++++++++-
 4 files changed, 324 insertions(+), 29 deletions(-)

base-commit: 7641890179f913ce73d9dae490b8ab74970fc552

Signature · 1 line
2.25.1
#1 lore raw

PATCH v8 1/3 dt-bindings: remoteproc: add Tightly Coupled Memory (TCM) bindings

From: Radhey Shyam Pandey <[email protected]>

Introduce bindings for TCM memory address space on AMD-xilinx Zynq UltraScale+ platform. It will help in defining TCM in device-tree and make it's access platform agnostic and data-driven.

Tightly-coupled memories(TCMs) are low-latency memory that provides predictable instruction execution and predictable data load/store timing. Each Cortex-R5F processor contains two 64-bit wide 64 KB memory banks on the ATCM and BTCM ports, for a total of 128 KB of memory.

The TCM resources(reg, reg-names and power-domain) are documented for each TCM in the R5 node. The reg and reg-names are made as required properties as we don't want to hardcode TCM addresses for future platforms and for zu+ legacy implementation will ensure that the old dts w/o reg/reg-names works and stable ABI is maintained.

It also extends the examples for TCM split and lockstep modes.

---
 .../remoteproc/xlnx,zynqmp-r5fss.yaml         | 131 +++++++++++++++---
 1 file changed, 113 insertions(+), 18 deletions(-)
Documentation/devicetree/bindings/remoteproc/xlnx,zynqmp-r5fss.yaml +113 -18
index 78aac69f1060..9ecd63ea1b38 100644
@@ -20,6 +20,17 @@ properties:
   compatible:
     const: xlnx,zynqmp-r5fss
 
+  "#address-cells":
+    const: 2
+
+  "#size-cells":
+    const: 2
+
+  ranges:
+    description: |
+      Standard ranges definition providing address translations for
+      local R5F TCM address spaces to bus addresses.
+
   xlnx,cluster-mode:
     $ref: /schemas/types.yaml#/definitions/uint32
     enum: [0, 1, 2]
@@ -37,7 +48,7 @@ properties:
       2: single cpu mode
 
 patternProperties:
-  "^r5f-[a-f0-9]+$":
+  "^r5f@[0-9a-f]+$":
     type: object
     description: |
       The RPU is located in the Low Power Domain of the Processor Subsystem.
@@ -54,8 +65,19 @@ patternProperties:
       compatible:
         const: xlnx,zynqmp-r5f
 
+      reg:
+        items:
+          - description: ATCM internal memory region
+          - description: BTCM internal memory region
+
+      reg-names:
+        items:
+          - const: atcm
+          - const: btcm
+
       power-domains:
-        maxItems: 1
+        minItems: 1
+        maxItems: 3
 
       mboxes:
         minItems: 1
@@ -102,34 +124,107 @@ patternProperties:
     required:
       - compatible
       - power-domains
+      - reg
+      - reg-names
 
     unevaluatedProperties: false
 
 required:
   - compatible
+  - "#address-cells"
+  - "#size-cells"
+  - ranges
 
 additionalProperties: false
 
 examples:
   - |
-    remoteproc {
-        compatible = "xlnx,zynqmp-r5fss";
-        xlnx,cluster-mode = <1>;
-
-        r5f-0 {
-            compatible = "xlnx,zynqmp-r5f";
-            power-domains = <&zynqmp_firmware 0x7>;
-            memory-region = <&rproc_0_fw_image>, <&rpu0vdev0buffer>, <&rpu0vdev0vring0>, <&rpu0vdev0vring1>;
-            mboxes = <&ipi_mailbox_rpu0 0>, <&ipi_mailbox_rpu0 1>;
-            mbox-names = "tx", "rx";
+    #include <dt-bindings/power/xlnx-zynqmp-power.h>
+
+    //Split mode configuration
+    soc {
+        #address-cells = <2>;
+        #size-cells = <2>;
+
+        remoteproc@ffe00000 {
+            compatible = "xlnx,zynqmp-r5fss";
+            xlnx,cluster-mode = <0>;
+
+            #address-cells = <2>;
+            #size-cells = <2>;
+            ranges = <0x0 0x0 0x0 0xffe00000 0x0 0x10000>,
+                     <0x0 0x20000 0x0 0xffe20000 0x0 0x10000>,
+                     <0x1 0x0 0x0 0xffe90000 0x0 0x10000>,
+                     <0x1 0x20000 0x0 0xffeb0000 0x0 0x10000>;
+
+            r5f@0 {
+                compatible = "xlnx,zynqmp-r5f";
+                reg = <0x0 0x0 0x0 0x10000>, <0x0 0x20000 0x0 0x10000>;
+                reg-names = "atcm", "btcm";
+                power-domains = <&zynqmp_firmware PD_RPU_0>,
+                                <&zynqmp_firmware PD_R5_0_ATCM>,
+                                <&zynqmp_firmware PD_R5_0_BTCM>;
+                memory-region = <&rproc_0_fw_image>, <&rpu0vdev0buffer>,
+                                <&rpu0vdev0vring0>, <&rpu0vdev0vring1>;
+                mboxes = <&ipi_mailbox_rpu0 0>, <&ipi_mailbox_rpu0 1>;
+                mbox-names = "tx", "rx";
+            };
+
+            r5f@1 {
+                compatible = "xlnx,zynqmp-r5f";
+                reg = <0x1 0x0 0x0 0x10000>, <0x1 0x20000 0x0 0x10000>;
+                reg-names = "atcm", "btcm";
+                power-domains = <&zynqmp_firmware PD_RPU_1>,
+                                <&zynqmp_firmware PD_R5_1_ATCM>,
+                                <&zynqmp_firmware PD_R5_1_BTCM>;
+                memory-region = <&rproc_1_fw_image>, <&rpu1vdev0buffer>,
+                                <&rpu1vdev0vring0>, <&rpu1vdev0vring1>;
+                mboxes = <&ipi_mailbox_rpu1 0>, <&ipi_mailbox_rpu1 1>;
+                mbox-names = "tx", "rx";
+            };
         };
+    };
 
-        r5f-1 {
-            compatible = "xlnx,zynqmp-r5f";
-            power-domains = <&zynqmp_firmware 0x8>;
-            memory-region = <&rproc_1_fw_image>, <&rpu1vdev0buffer>, <&rpu1vdev0vring0>, <&rpu1vdev0vring1>;
-            mboxes = <&ipi_mailbox_rpu1 0>, <&ipi_mailbox_rpu1 1>;
-            mbox-names = "tx", "rx";
+  - |
+    //Lockstep configuration
+    soc {
+        #address-cells = <2>;
+        #size-cells = <2>;
+
+        remoteproc@ffe00000 {
+            compatible = "xlnx,zynqmp-r5fss";
+            xlnx,cluster-mode = <1>;
+
+            #address-cells = <2>;
+            #size-cells = <2>;
+            ranges = <0x0 0x0 0x0 0xffe00000 0x0 0x20000>,
+                     <0x0 0x20000 0x0 0xffe20000 0x0 0x20000>;
+
+            r5f@0 {
+                compatible = "xlnx,zynqmp-r5f";
+                reg = <0x0 0x0 0x0 0x20000>, <0x0 0x20000 0x0 0x20000>;
+                reg-names = "atcm", "btcm";
+                power-domains = <&zynqmp_firmware PD_RPU_0>,
+                                <&zynqmp_firmware PD_R5_0_ATCM>,
+                                <&zynqmp_firmware PD_R5_0_BTCM>;
+                memory-region = <&rproc_0_fw_image>, <&rpu0vdev0buffer>,
+                                <&rpu0vdev0vring0>, <&rpu0vdev0vring1>;
+                mboxes = <&ipi_mailbox_rpu0 0>, <&ipi_mailbox_rpu0 1>;
+                mbox-names = "tx", "rx";
+            };
+
+            r5f@1 {
+                compatible = "xlnx,zynqmp-r5f";
+                reg = <0x1 0x0 0x0 0x10000>, <0x1 0x20000 0x0 0x10000>;
+                reg-names = "atcm", "btcm";
+                power-domains = <&zynqmp_firmware PD_RPU_1>,
+                                <&zynqmp_firmware PD_R5_1_ATCM>,
+                                <&zynqmp_firmware PD_R5_1_BTCM>;
+                memory-region = <&rproc_1_fw_image>, <&rpu1vdev0buffer>,
+                                <&rpu1vdev0vring0>, <&rpu1vdev0vring1>;
+                mboxes = <&ipi_mailbox_rpu1 0>, <&ipi_mailbox_rpu1 1>;
+                mbox-names = "tx", "rx";
+            };
         };
     };
 ...
Signature · 1 line
2.25.1
#2 lore raw

PATCH v8 2/3 dts: zynqmp: add properties for TCM in remoteproc

In reply to Tanmay Shah

Add properties as per new bindings in zynqmp remoteproc node to represent TCM address and size.

This patch also adds alternative remoteproc node to represent remoteproc cluster in split mode. By default lockstep mode is enabled and users should disable it before using split mode dts. Both device-tree nodes can't be used simultaneously one of them must be disabled. For zcu102-1.0 and zcu102-1.1 board remoteproc split mode dts node is enabled and lockstep mode dts is disabled.

---
 .../boot/dts/xilinx/zynqmp-zcu102-rev1.0.dts  |  8 +++
 arch/arm64/boot/dts/xilinx/zynqmp.dtsi        | 60 +++++++++++++++++--
 2 files changed, 63 insertions(+), 5 deletions(-)
arch/arm64/boot/dts/xilinx/zynqmp-zcu102-rev1.0.dts +8 -0
index c8f71a1aec89..495ca94b45db 100644
@@ -14,6 +14,14 @@ / {
 	compatible = "xlnx,zynqmp-zcu102-rev1.0", "xlnx,zynqmp-zcu102", "xlnx,zynqmp";
 };
 
+&rproc_split {
+	status = "okay";
+};
+
+&rproc_lockstep {
+	status = "disabled";
+};
+
 &eeprom {
 	#address-cells = <1>;
 	#size-cells = <1>;
arch/arm64/boot/dts/xilinx/zynqmp.dtsi +55 -5

74 lines not on this page · raw message

Signature · 1 line
2.25.1
maintainer Acked-by on v8 2/3
#3 lore raw

Re: [PATCH v8 2/3] dts: zynqmp: add properties for TCM in remoteproc

Quoted 105 lines · Tanmay Shah

Add properties as per new bindings in zynqmp remoteproc node to represent TCM address and size.

This patch also adds alternative remoteproc node to represent remoteproc cluster in split mode. By default lockstep mode is enabled and users should disable it before using split mode dts. Both device-tree nodes can't be used simultaneously one of them must be disabled. For zcu102-1.0 and zcu102-1.1 board remoteproc split mode dts node is enabled and lockstep mode dts is disabled.

---
  .../boot/dts/xilinx/zynqmp-zcu102-rev1.0.dts  |  8 +++
  arch/arm64/boot/dts/xilinx/zynqmp.dtsi        | 60 +++++++++++++++++--
  2 files changed, 63 insertions(+), 5 deletions(-)
arch/arm64/boot/dts/xilinx/zynqmp-zcu102-rev1.0.dts +8 -0
index c8f71a1aec89..495ca94b45db 100644
@@ -14,6 +14,14 @@ / {
  	compatible = "xlnx,zynqmp-zcu102-rev1.0", "xlnx,zynqmp-zcu102", "xlnx,zynqmp";
  };
 
+&rproc_split {
+	status = "okay";
+};
+
+&rproc_lockstep {
+	status = "disabled";
+};
+
  &eeprom {
  	#address-cells = <1>;
  	#size-cells = <1>;
arch/arm64/boot/dts/xilinx/zynqmp.dtsi +50 -4
index b61fc99cd911..602e6aba7ac5 100644
@@ -247,19 +247,69 @@ fpga_full: fpga-full {
  		ranges;
  	};
 
-	remoteproc {
+	rproc_lockstep: remoteproc@ffe00000 {
  		compatible = "xlnx,zynqmp-r5fss";
  		xlnx,cluster-mode = <1>;
 
-		r5f-0 {
+		#address-cells = <2>;
+		#size-cells = <2>;
+
+		ranges = <0x0 0x0 0x0 0xffe00000 0x0 0x20000>,
+			 <0x0 0x20000 0x0 0xffe20000 0x0 0x20000>,
+			 <0x1 0x0 0x0 0xffe90000 0x0 0x10000>,
+			 <0x1 0x20000 0x0 0xffeb0000 0x0 0x10000>;
+
+		r5f@0 {
+			compatible = "xlnx,zynqmp-r5f";
+			reg = <0x0 0x0 0x0 0x20000>, <0x0 0x20000 0x0 0x20000>;
+			reg-names = "atcm", "btcm";
+			power-domains = <&zynqmp_firmware PD_RPU_0>,
+					<&zynqmp_firmware PD_R5_0_ATCM>,
+					<&zynqmp_firmware PD_R5_0_BTCM>;
+			memory-region = <&rproc_0_fw_image>;
+		};
+
+		r5f@1 {
+			compatible = "xlnx,zynqmp-r5f";
+			reg = <0x1 0x0 0x0 0x10000>, <0x1 0x20000 0x0 0x10000>;
+			reg-names = "atcm", "btcm";
+			power-domains = <&zynqmp_firmware PD_RPU_1>,
+					<&zynqmp_firmware PD_R5_1_ATCM>,
+					<&zynqmp_firmware PD_R5_1_BTCM>;
+			memory-region = <&rproc_1_fw_image>;
+		};
+	};
+
+	rproc_split: remoteproc-split@ffe00000 {
+		status = "disabled";
+		compatible = "xlnx,zynqmp-r5fss";
+		xlnx,cluster-mode = <0>;
+
+		#address-cells = <2>;
+		#size-cells = <2>;
+
+		ranges = <0x0 0x0 0x0 0xffe00000 0x0 0x10000>,
+			 <0x0 0x20000 0x0 0xffe20000 0x0 0x10000>,
+			 <0x1 0x0 0x0 0xffe90000 0x0 0x10000>,
+			 <0x1 0x20000 0x0 0xffeb0000 0x0 0x10000>;
+
+		r5f@0 {
  			compatible = "xlnx,zynqmp-r5f";
-			power-domains = <&zynqmp_firmware PD_RPU_0>;
+			reg = <0x0 0x0 0x0 0x10000>, <0x0 0x20000 0x0 0x10000>;
+			reg-names = "atcm", "btcm";
+			power-domains = <&zynqmp_firmware PD_RPU_0>,
+					<&zynqmp_firmware PD_R5_0_ATCM>,
+					<&zynqmp_firmware PD_R5_0_BTCM>;
  			memory-region = <&rproc_0_fw_image>;
  		};
 
-		r5f-1 {
+		r5f@1 {

arch/arm64/boot/dts/xilinx/zynqmp.dtsi fpga_full: fpga-full { · line 315

Quoted 10 lines
arch/arm64/boot/dts/xilinx/zynqmp.dtsi +5 -1
  			compatible = "xlnx,zynqmp-r5f";
-			power-domains = <&zynqmp_firmware PD_RPU_1>;
+			reg = <0x1 0x0 0x0 0x10000>, <0x1 0x20000 0x0 0x10000>;
+			reg-names = "atcm", "btcm";
+			power-domains = <&zynqmp_firmware PD_RPU_1>,
+					<&zynqmp_firmware PD_R5_1_ATCM>,
+					<&zynqmp_firmware PD_R5_1_BTCM>;
  			memory-region = <&rproc_1_fw_image>;
  		};
  	};

Let me know if you want me to take this via my tree.

Thanks,
Michal

#4 lore raw

Re: [PATCH v8 2/3] dts: zynqmp: add properties for TCM in remoteproc

Quoted 120 lines · Michal Simek
Quoted 105 lines · Tanmay Shah

Add properties as per new bindings in zynqmp remoteproc node to represent TCM address and size.

This patch also adds alternative remoteproc node to represent remoteproc cluster in split mode. By default lockstep mode is enabled and users should disable it before using split mode dts. Both device-tree nodes can't be used simultaneously one of them must be disabled. For zcu102-1.0 and zcu102-1.1 board remoteproc split mode dts node is enabled and lockstep mode dts is disabled.

---
  .../boot/dts/xilinx/zynqmp-zcu102-rev1.0.dts  |  8 +++
  arch/arm64/boot/dts/xilinx/zynqmp.dtsi        | 60 +++++++++++++++++--
  2 files changed, 63 insertions(+), 5 deletions(-)
arch/arm64/boot/dts/xilinx/zynqmp-zcu102-rev1.0.dts +8 -0
index c8f71a1aec89..495ca94b45db 100644
@@ -14,6 +14,14 @@ / {
  	compatible = "xlnx,zynqmp-zcu102-rev1.0", "xlnx,zynqmp-zcu102", "xlnx,zynqmp";
  };
 
+&rproc_split {
+	status = "okay";
+};
+
+&rproc_lockstep {
+	status = "disabled";
+};
+
  &eeprom {
  	#address-cells = <1>;
  	#size-cells = <1>;
arch/arm64/boot/dts/xilinx/zynqmp.dtsi +50 -4
index b61fc99cd911..602e6aba7ac5 100644
@@ -247,19 +247,69 @@ fpga_full: fpga-full {
  		ranges;
  	};
 
-	remoteproc {
+	rproc_lockstep: remoteproc@ffe00000 {
  		compatible = "xlnx,zynqmp-r5fss";
  		xlnx,cluster-mode = <1>;
 
-		r5f-0 {
+		#address-cells = <2>;
+		#size-cells = <2>;
+
+		ranges = <0x0 0x0 0x0 0xffe00000 0x0 0x20000>,
+			 <0x0 0x20000 0x0 0xffe20000 0x0 0x20000>,
+			 <0x1 0x0 0x0 0xffe90000 0x0 0x10000>,
+			 <0x1 0x20000 0x0 0xffeb0000 0x0 0x10000>;
+
+		r5f@0 {
+			compatible = "xlnx,zynqmp-r5f";
+			reg = <0x0 0x0 0x0 0x20000>, <0x0 0x20000 0x0 0x20000>;
+			reg-names = "atcm", "btcm";
+			power-domains = <&zynqmp_firmware PD_RPU_0>,
+					<&zynqmp_firmware PD_R5_0_ATCM>,
+					<&zynqmp_firmware PD_R5_0_BTCM>;
+			memory-region = <&rproc_0_fw_image>;
+		};
+
+		r5f@1 {
+			compatible = "xlnx,zynqmp-r5f";
+			reg = <0x1 0x0 0x0 0x10000>, <0x1 0x20000 0x0 0x10000>;
+			reg-names = "atcm", "btcm";
+			power-domains = <&zynqmp_firmware PD_RPU_1>,
+					<&zynqmp_firmware PD_R5_1_ATCM>,
+					<&zynqmp_firmware PD_R5_1_BTCM>;
+			memory-region = <&rproc_1_fw_image>;
+		};
+	};
+
+	rproc_split: remoteproc-split@ffe00000 {
+		status = "disabled";
+		compatible = "xlnx,zynqmp-r5fss";
+		xlnx,cluster-mode = <0>;
+
+		#address-cells = <2>;
+		#size-cells = <2>;
+
+		ranges = <0x0 0x0 0x0 0xffe00000 0x0 0x10000>,
+			 <0x0 0x20000 0x0 0xffe20000 0x0 0x10000>,
+			 <0x1 0x0 0x0 0xffe90000 0x0 0x10000>,
+			 <0x1 0x20000 0x0 0xffeb0000 0x0 0x10000>;
+
+		r5f@0 {
  			compatible = "xlnx,zynqmp-r5f";
-			power-domains = <&zynqmp_firmware PD_RPU_0>;
+			reg = <0x0 0x0 0x0 0x10000>, <0x0 0x20000 0x0 0x10000>;
+			reg-names = "atcm", "btcm";
+			power-domains = <&zynqmp_firmware PD_RPU_0>,
+					<&zynqmp_firmware PD_R5_0_ATCM>,
+					<&zynqmp_firmware PD_R5_0_BTCM>;
  			memory-region = <&rproc_0_fw_image>;
  		};
 
-		r5f-1 {
+		r5f@1 {

arch/arm64/boot/dts/xilinx/zynqmp.dtsi fpga_full: fpga-full { · line 315

Quoted 10 lines
arch/arm64/boot/dts/xilinx/zynqmp.dtsi +5 -1
  			compatible = "xlnx,zynqmp-r5f";
-			power-domains = <&zynqmp_firmware PD_RPU_1>;
+			reg = <0x1 0x0 0x0 0x10000>, <0x1 0x20000 0x0 0x10000>;
+			reg-names = "atcm", "btcm";
+			power-domains = <&zynqmp_firmware PD_RPU_1>,
+					<&zynqmp_firmware PD_R5_1_ATCM>,
+					<&zynqmp_firmware PD_R5_1_BTCM>;
  			memory-region = <&rproc_1_fw_image>;
  		};
  	};
Quoted 1 line

Let me know if you want me to take this via my tree.

Hi Michal,

Thanks for reviews. I will ping you once driver changes are approved.

Or Mathieu can take this in remoteproc tree, either way is fine.

But I would like to wait till driver changes are approved.

Tanmay

Quoted 3 lines

Thanks,
Michal

maintainer
#5 lore raw

Re: [PATCH v8 2/3] dts: zynqmp: add properties for TCM in remoteproc

Quoted 123 lines · Tanmay Shah
Quoted 120 lines · Michal Simek
Quoted 105 lines · Tanmay Shah

Add properties as per new bindings in zynqmp remoteproc node to represent TCM address and size.

This patch also adds alternative remoteproc node to represent remoteproc cluster in split mode. By default lockstep mode is enabled and users should disable it before using split mode dts. Both device-tree nodes can't be used simultaneously one of them must be disabled. For zcu102-1.0 and zcu102-1.1 board remoteproc split mode dts node is enabled and lockstep mode dts is disabled.

---
  .../boot/dts/xilinx/zynqmp-zcu102-rev1.0.dts  |  8 +++
  arch/arm64/boot/dts/xilinx/zynqmp.dtsi        | 60 +++++++++++++++++--
  2 files changed, 63 insertions(+), 5 deletions(-)
arch/arm64/boot/dts/xilinx/zynqmp-zcu102-rev1.0.dts +8 -0
index c8f71a1aec89..495ca94b45db 100644
@@ -14,6 +14,14 @@ / {
    compatible = "xlnx,zynqmp-zcu102-rev1.0", "xlnx,zynqmp-zcu102", "xlnx,zynqmp";
  };
 
+&rproc_split {
+   status = "okay";
+};
+
+&rproc_lockstep {
+   status = "disabled";
+};
+
  &eeprom {
    #address-cells = <1>;
    #size-cells = <1>;
arch/arm64/boot/dts/xilinx/zynqmp.dtsi +50 -4
index b61fc99cd911..602e6aba7ac5 100644
@@ -247,19 +247,69 @@ fpga_full: fpga-full {
            ranges;
    };
 
-   remoteproc {
+   rproc_lockstep: remoteproc@ffe00000 {
            compatible = "xlnx,zynqmp-r5fss";
            xlnx,cluster-mode = <1>;
 
-           r5f-0 {
+           #address-cells = <2>;
+           #size-cells = <2>;
+
+           ranges = <0x0 0x0 0x0 0xffe00000 0x0 0x20000>,
+                    <0x0 0x20000 0x0 0xffe20000 0x0 0x20000>,
+                    <0x1 0x0 0x0 0xffe90000 0x0 0x10000>,
+                    <0x1 0x20000 0x0 0xffeb0000 0x0 0x10000>;
+
+           r5f@0 {
+                   compatible = "xlnx,zynqmp-r5f";
+                   reg = <0x0 0x0 0x0 0x20000>, <0x0 0x20000 0x0 0x20000>;
+                   reg-names = "atcm", "btcm";
+                   power-domains = <&zynqmp_firmware PD_RPU_0>,
+                                   <&zynqmp_firmware PD_R5_0_ATCM>,
+                                   <&zynqmp_firmware PD_R5_0_BTCM>;
+                   memory-region = <&rproc_0_fw_image>;
+           };
+
+           r5f@1 {
+                   compatible = "xlnx,zynqmp-r5f";
+                   reg = <0x1 0x0 0x0 0x10000>, <0x1 0x20000 0x0 0x10000>;
+                   reg-names = "atcm", "btcm";
+                   power-domains = <&zynqmp_firmware PD_RPU_1>,
+                                   <&zynqmp_firmware PD_R5_1_ATCM>,
+                                   <&zynqmp_firmware PD_R5_1_BTCM>;
+                   memory-region = <&rproc_1_fw_image>;
+           };
+   };
+
+   rproc_split: remoteproc-split@ffe00000 {
+           status = "disabled";
+           compatible = "xlnx,zynqmp-r5fss";
+           xlnx,cluster-mode = <0>;
+
+           #address-cells = <2>;
+           #size-cells = <2>;
+
+           ranges = <0x0 0x0 0x0 0xffe00000 0x0 0x10000>,
+                    <0x0 0x20000 0x0 0xffe20000 0x0 0x10000>,
+                    <0x1 0x0 0x0 0xffe90000 0x0 0x10000>,
+                    <0x1 0x20000 0x0 0xffeb0000 0x0 0x10000>;
+
+           r5f@0 {
                    compatible = "xlnx,zynqmp-r5f";
-                   power-domains = <&zynqmp_firmware PD_RPU_0>;
+                   reg = <0x0 0x0 0x0 0x10000>, <0x0 0x20000 0x0 0x10000>;
+                   reg-names = "atcm", "btcm";
+                   power-domains = <&zynqmp_firmware PD_RPU_0>,
+                                   <&zynqmp_firmware PD_R5_0_ATCM>,
+                                   <&zynqmp_firmware PD_R5_0_BTCM>;
                    memory-region = <&rproc_0_fw_image>;
            };
 
-           r5f-1 {
+           r5f@1 {

arch/arm64/boot/dts/xilinx/zynqmp.dtsi fpga_full: fpga-full { · line 315

Quoted 10 lines
arch/arm64/boot/dts/xilinx/zynqmp.dtsi +5 -1
                    compatible = "xlnx,zynqmp-r5f";
-                   power-domains = <&zynqmp_firmware PD_RPU_1>;
+                   reg = <0x1 0x0 0x0 0x10000>, <0x1 0x20000 0x0 0x10000>;
+                   reg-names = "atcm", "btcm";
+                   power-domains = <&zynqmp_firmware PD_RPU_1>,
+                                   <&zynqmp_firmware PD_R5_1_ATCM>,
+                                   <&zynqmp_firmware PD_R5_1_BTCM>;
                    memory-region = <&rproc_1_fw_image>;
            };
    };
Quoted 5 lines
Quoted 1 line

Let me know if you want me to take this via my tree.

Hi Michal,

Thanks for reviews. I will ping you once driver changes are approved.

I'll pick this up with the rest of the driver. It will be easier that way.

Quoted 10 lines

Or Mathieu can take this in remoteproc tree, either way is fine.

But I would like to wait till driver changes are approved.

Tanmay

Quoted 3 lines

Thanks,
Michal

maintainer
#6 lore raw

Re: [PATCH v8 2/3] dts: zynqmp: add properties for TCM in remoteproc

In reply to Tanmay Shah

Hi Tanmay,

Quoted 47 lines · Tanmay Shah

Add properties as per new bindings in zynqmp remoteproc node to represent TCM address and size.

This patch also adds alternative remoteproc node to represent remoteproc cluster in split mode. By default lockstep mode is enabled and users should disable it before using split mode dts. Both device-tree nodes can't be used simultaneously one of them must be disabled. For zcu102-1.0 and zcu102-1.1 board remoteproc split mode dts node is enabled and lockstep mode dts is disabled.

---
 .../boot/dts/xilinx/zynqmp-zcu102-rev1.0.dts  |  8 +++
 arch/arm64/boot/dts/xilinx/zynqmp.dtsi        | 60 +++++++++++++++++--
 2 files changed, 63 insertions(+), 5 deletions(-)
arch/arm64/boot/dts/xilinx/zynqmp-zcu102-rev1.0.dts +8 -0
index c8f71a1aec89..495ca94b45db 100644
@@ -14,6 +14,14 @@ / {
 	compatible = "xlnx,zynqmp-zcu102-rev1.0", "xlnx,zynqmp-zcu102", "xlnx,zynqmp";
 };
 
+&rproc_split {
+	status = "okay";
+};
+
+&rproc_lockstep {
+	status = "disabled";
+};
+
 &eeprom {
 	#address-cells = <1>;
 	#size-cells = <1>;
arch/arm64/boot/dts/xilinx/zynqmp.dtsi +1 -1
index b61fc99cd911..602e6aba7ac5 100644
@@ -247,19 +247,69 @@ fpga_full: fpga-full {
 		ranges;
 	};
 
-	remoteproc {
+	rproc_lockstep: remoteproc@ffe00000 {
 		compatible = "xlnx,zynqmp-r5fss";

arch/arm64/boot/dts/xilinx/zynqmp.dtsi fpga_full: fpga-full { · line 260

Quoted 10 lines
arch/arm64/boot/dts/xilinx/zynqmp.dtsi +7 -1
 		xlnx,cluster-mode = <1>;
 
-		r5f-0 {
+		#address-cells = <2>;
+		#size-cells = <2>;
+
+		ranges = <0x0 0x0 0x0 0xffe00000 0x0 0x20000>,
+			 <0x0 0x20000 0x0 0xffe20000 0x0 0x20000>,
+			 <0x1 0x0 0x0 0xffe90000 0x0 0x10000>,
+			 <0x1 0x20000 0x0 0xffeb0000 0x0 0x10000>;

As far as I can tell, in lockstep mode the last two entries are not needed. This is also contrasting with that is in the bindings, which is quite confusing.

Quoted 61 lines
arch/arm64/boot/dts/xilinx/zynqmp.dtsi +47 -3
+
+		r5f@0 {
+			compatible = "xlnx,zynqmp-r5f";
+			reg = <0x0 0x0 0x0 0x20000>, <0x0 0x20000 0x0 0x20000>;
+			reg-names = "atcm", "btcm";
+			power-domains = <&zynqmp_firmware PD_RPU_0>,
+					<&zynqmp_firmware PD_R5_0_ATCM>,
+					<&zynqmp_firmware PD_R5_0_BTCM>;
+			memory-region = <&rproc_0_fw_image>;
+		};
+
+		r5f@1 {
+			compatible = "xlnx,zynqmp-r5f";
+			reg = <0x1 0x0 0x0 0x10000>, <0x1 0x20000 0x0 0x10000>;
+			reg-names = "atcm", "btcm";
+			power-domains = <&zynqmp_firmware PD_RPU_1>,
+					<&zynqmp_firmware PD_R5_1_ATCM>,
+					<&zynqmp_firmware PD_R5_1_BTCM>;
+			memory-region = <&rproc_1_fw_image>;
+		};
+	};
+
+	rproc_split: remoteproc-split@ffe00000 {
+		status = "disabled";
+		compatible = "xlnx,zynqmp-r5fss";
+		xlnx,cluster-mode = <0>;
+
+		#address-cells = <2>;
+		#size-cells = <2>;
+
+		ranges = <0x0 0x0 0x0 0xffe00000 0x0 0x10000>,
+			 <0x0 0x20000 0x0 0xffe20000 0x0 0x10000>,
+			 <0x1 0x0 0x0 0xffe90000 0x0 0x10000>,
+			 <0x1 0x20000 0x0 0xffeb0000 0x0 0x10000>;
+
+		r5f@0 {
 			compatible = "xlnx,zynqmp-r5f";
-			power-domains = <&zynqmp_firmware PD_RPU_0>;
+			reg = <0x0 0x0 0x0 0x10000>, <0x0 0x20000 0x0 0x10000>;
+			reg-names = "atcm", "btcm";
+			power-domains = <&zynqmp_firmware PD_RPU_0>,
+					<&zynqmp_firmware PD_R5_0_ATCM>,
+					<&zynqmp_firmware PD_R5_0_BTCM>;
 			memory-region = <&rproc_0_fw_image>;
 		};
 
-		r5f-1 {
+		r5f@1 {
 			compatible = "xlnx,zynqmp-r5f";
-			power-domains = <&zynqmp_firmware PD_RPU_1>;
+			reg = <0x1 0x0 0x0 0x10000>, <0x1 0x20000 0x0 0x10000>;
+			reg-names = "atcm", "btcm";
+			power-domains = <&zynqmp_firmware PD_RPU_1>,
+					<&zynqmp_firmware PD_R5_1_ATCM>,
+					<&zynqmp_firmware PD_R5_1_BTCM>;
 			memory-region = <&rproc_1_fw_image>;
 		};
 	};
Signature · 1 line
2.25.1
#7 lore raw

Re: [PATCH v8 2/3] dts: zynqmp: add properties for TCM in remoteproc

Quoted 52 lines · Mathieu Poirier

Hi Tanmay,

Quoted 49 lines · Tanmay Shah

Add properties as per new bindings in zynqmp remoteproc node to represent TCM address and size.

This patch also adds alternative remoteproc node to represent remoteproc cluster in split mode. By default lockstep mode is enabled and users should disable it before using split mode dts. Both device-tree nodes can't be used simultaneously one of them must be disabled. For zcu102-1.0 and zcu102-1.1 board remoteproc split mode dts node is enabled and lockstep mode dts is disabled.

---
 .../boot/dts/xilinx/zynqmp-zcu102-rev1.0.dts  |  8 +++
 arch/arm64/boot/dts/xilinx/zynqmp.dtsi        | 60 +++++++++++++++++--
 2 files changed, 63 insertions(+), 5 deletions(-)
arch/arm64/boot/dts/xilinx/zynqmp-zcu102-rev1.0.dts +8 -0
index c8f71a1aec89..495ca94b45db 100644
@@ -14,6 +14,14 @@ / {
 	compatible = "xlnx,zynqmp-zcu102-rev1.0", "xlnx,zynqmp-zcu102", "xlnx,zynqmp";
 };
 
+&rproc_split {
+	status = "okay";
+};
+
+&rproc_lockstep {
+	status = "disabled";
+};
+
 &eeprom {
 	#address-cells = <1>;
 	#size-cells = <1>;
arch/arm64/boot/dts/xilinx/zynqmp.dtsi +1 -1
index b61fc99cd911..602e6aba7ac5 100644
@@ -247,19 +247,69 @@ fpga_full: fpga-full {
 		ranges;
 	};
 
-	remoteproc {
+	rproc_lockstep: remoteproc@ffe00000 {
 		compatible = "xlnx,zynqmp-r5fss";
 		xlnx,cluster-mode = <1>;
 
Quoted 11 lines

arch/arm64/boot/dts/xilinx/zynqmp.dtsi fpga_full: fpga-full { · line 260

Quoted 8 lines
arch/arm64/boot/dts/xilinx/zynqmp.dtsi +7 -1
-		r5f-0 {
+		#address-cells = <2>;
+		#size-cells = <2>;
+
+		ranges = <0x0 0x0 0x0 0xffe00000 0x0 0x20000>,
+			 <0x0 0x20000 0x0 0xffe20000 0x0 0x20000>,
+			 <0x1 0x0 0x0 0xffe90000 0x0 0x10000>,
+			 <0x1 0x20000 0x0 0xffeb0000 0x0 0x10000>;

As far as I can tell, in lockstep mode the last two entries are not needed. This is also contrasting with that is in the bindings, which is quite confusing.

Hi Mathieu,

Yes I agree. I think it should be same as of bindings example.

However, I will have to test and make sure no impact on driver. I will fix it in next revision.

Meanwhile, are you going to review driver changes as well or do you want to wait for next revision ?

Tanmay

Quoted 61 lines
Quoted 61 lines
arch/arm64/boot/dts/xilinx/zynqmp.dtsi +47 -3
+
+		r5f@0 {
+			compatible = "xlnx,zynqmp-r5f";
+			reg = <0x0 0x0 0x0 0x20000>, <0x0 0x20000 0x0 0x20000>;
+			reg-names = "atcm", "btcm";
+			power-domains = <&zynqmp_firmware PD_RPU_0>,
+					<&zynqmp_firmware PD_R5_0_ATCM>,
+					<&zynqmp_firmware PD_R5_0_BTCM>;
+			memory-region = <&rproc_0_fw_image>;
+		};
+
+		r5f@1 {
+			compatible = "xlnx,zynqmp-r5f";
+			reg = <0x1 0x0 0x0 0x10000>, <0x1 0x20000 0x0 0x10000>;
+			reg-names = "atcm", "btcm";
+			power-domains = <&zynqmp_firmware PD_RPU_1>,
+					<&zynqmp_firmware PD_R5_1_ATCM>,
+					<&zynqmp_firmware PD_R5_1_BTCM>;
+			memory-region = <&rproc_1_fw_image>;
+		};
+	};
+
+	rproc_split: remoteproc-split@ffe00000 {
+		status = "disabled";
+		compatible = "xlnx,zynqmp-r5fss";
+		xlnx,cluster-mode = <0>;
+
+		#address-cells = <2>;
+		#size-cells = <2>;
+
+		ranges = <0x0 0x0 0x0 0xffe00000 0x0 0x10000>,
+			 <0x0 0x20000 0x0 0xffe20000 0x0 0x10000>,
+			 <0x1 0x0 0x0 0xffe90000 0x0 0x10000>,
+			 <0x1 0x20000 0x0 0xffeb0000 0x0 0x10000>;
+
+		r5f@0 {
 			compatible = "xlnx,zynqmp-r5f";
-			power-domains = <&zynqmp_firmware PD_RPU_0>;
+			reg = <0x0 0x0 0x0 0x10000>, <0x0 0x20000 0x0 0x10000>;
+			reg-names = "atcm", "btcm";
+			power-domains = <&zynqmp_firmware PD_RPU_0>,
+					<&zynqmp_firmware PD_R5_0_ATCM>,
+					<&zynqmp_firmware PD_R5_0_BTCM>;
 			memory-region = <&rproc_0_fw_image>;
 		};
 
-		r5f-1 {
+		r5f@1 {
 			compatible = "xlnx,zynqmp-r5f";
-			power-domains = <&zynqmp_firmware PD_RPU_1>;
+			reg = <0x1 0x0 0x0 0x10000>, <0x1 0x20000 0x0 0x10000>;
+			reg-names = "atcm", "btcm";
+			power-domains = <&zynqmp_firmware PD_RPU_1>,
+					<&zynqmp_firmware PD_R5_1_ATCM>,
+					<&zynqmp_firmware PD_R5_1_BTCM>;
 			memory-region = <&rproc_1_fw_image>;
 		};
 	};
Signature · 1 line
2.25.1
#8 lore raw

PATCH v8 3/3 remoteproc: zynqmp: parse TCM from device tree

In reply to Tanmay Shah

ZynqMP TCM information is fixed in driver. Now ZynqMP TCM information is available in device-tree. Parse TCM information in driver as per new bindings.

---

Changes in v8:
- parse power-domains property from device-tree and use EEMI calls to power on/off TCM instead of using pm domains framework
- Remove checking of pm_domain_id validation to power on/off tcm
- Remove spurious change

Changes in v7:
- move checking of pm_domain_id from previous patch
- fix mem_bank_data memory allocation

 drivers/remoteproc/xlnx_r5_remoteproc.c | 154 +++++++++++++++++++++++-
 1 file changed, 148 insertions(+), 6 deletions(-)
drivers/remoteproc/xlnx_r5_remoteproc.c +148 -6
index 4395edea9a64..36d73dcd93f0 100644
@@ -74,8 +74,8 @@ struct mbox_info {
 };
 
 /*
- * Hardcoded TCM bank values. This will be removed once TCM bindings are
- * accepted for system-dt specifications and upstreamed in linux kernel
+ * Hardcoded TCM bank values. This will stay in driver to maintain backward
+ * compatibility with device-tree that does not have TCM information.
  */
 static const struct mem_bank_data zynqmp_tcm_banks_split[] = {
 	{0xffe00000UL, 0x0, 0x10000UL, PD_R5_0_ATCM, "atcm0"}, /* TCM 64KB each */
@@ -878,6 +878,139 @@ static struct zynqmp_r5_core *zynqmp_r5_add_rproc_core(struct device *cdev)
 	return ERR_PTR(ret);
 }
 
+static int zynqmp_r5_get_tcm_node_from_dt(struct zynqmp_r5_cluster *cluster)
+{
+	struct of_phandle_args out_args;
+	int tcm_reg_per_r5, tcm_pd_idx;
+	struct zynqmp_r5_core *r5_core;
+	int i, j, tcm_bank_count, ret;
+	struct platform_device *cpdev;
+	struct mem_bank_data *tcm;
+	struct device_node *np;
+	struct resource *res;
+	u64 abs_addr, size;
+	struct device *dev;
+
+	for (i = 0; i < cluster->core_count; i++) {
+		r5_core = cluster->r5_cores[i];
+		dev = r5_core->dev;
+		np = of_node_get(dev_of_node(dev));
+		tcm_pd_idx = 1;
+
+		/* we have address cell 2 and size cell as 2 */
+		tcm_reg_per_r5 = of_property_count_elems_of_size(np, "reg",
+								 4 * sizeof(u32));
+		if (tcm_reg_per_r5 <= 0) {
+			dev_err(dev, "can't get reg property err %d\n", tcm_reg_per_r5);
+			return -EINVAL;
+		}
+
+		/*
+		 * In lockstep mode, r5 core 0 will use r5 core 1 TCM
+		 * power domains as well. so allocate twice of per core TCM
+		 */
+		if (cluster->mode == LOCKSTEP_MODE)
+			tcm_bank_count = tcm_reg_per_r5 * 2;
+		else
+			tcm_bank_count = tcm_reg_per_r5;
+
+		r5_core->tcm_banks = devm_kcalloc(dev, tcm_bank_count,
+						  sizeof(struct mem_bank_data *),
+						  GFP_KERNEL);
+		if (!r5_core->tcm_banks)
+			ret = -ENOMEM;
+
+		r5_core->tcm_bank_count = tcm_bank_count;
+		for (j = 0; j < tcm_bank_count; j++) {
+			tcm = devm_kzalloc(dev, sizeof(struct mem_bank_data),
+					   GFP_KERNEL);
+			if (!tcm)
+				return -ENOMEM;
+
+			r5_core->tcm_banks[j] = tcm;
+
+			/*
+			 * In lockstep mode, get second core's TCM power domains id
+			 * after first core TCM parsing is done as
+			 */
+			if (j == tcm_reg_per_r5) {
+				/* dec first core node */
+				of_node_put(np);
+
+				/* get second core node */
+				np = of_get_next_child(cluster->dev->of_node, np);
+
+				/*
+				 * reset index of power-domains property list
+				 * for second core
+				 */
+				tcm_pd_idx = 1;
+			}
+
+			/* get power-domains id of tcm */
+			ret = of_parse_phandle_with_args(np, "power-domains",
+							 "#power-domain-cells",
+							 tcm_pd_idx,
+							 &out_args);
+			if (ret) {
+				dev_err(r5_core->dev,
+					"failed to get tcm %d pm domain, ret %d\n",
+					j, ret);
+				of_node_put(out_args.np);
+				return ret;
+			}
+			tcm->pm_domain_id = out_args.args[0];
+			of_node_put(out_args.np);
+			tcm_pd_idx++;
+
+			/*
+			 * In lockstep mode, we only need second core's power domain
+			 * ids. Other information from second core isn't needed so
+			 * ignore it. This forms table as zynqmp_tcm_banks_lockstep
+			 */
+			if (j >= tcm_reg_per_r5)
+				continue;
+
+			/* get tcm address without translation */
+			ret = of_property_read_reg(np, j, &abs_addr, &size);
+			if (ret) {
+				of_node_put(np);
+				dev_err(dev, "failed to get reg property\n");
+				return ret;
+			}
+
+			/*
+			 * remote processor can address only 32 bits
+			 * so convert 64-bits into 32-bits. This will discard
+			 * any unwanted upper 32-bits.
+			 */
+			tcm->da = (u32)abs_addr;
+			tcm->size = (u32)size;
+
+			cpdev = to_platform_device(dev);
+			res = platform_get_resource(cpdev, IORESOURCE_MEM, j);
+			if (!res) {
+				of_node_put(np);
+				dev_err(dev, "failed to get tcm resource\n");
+				return -EINVAL;
+			}
+
+			tcm->addr = (u32)res->start;
+			tcm->bank_name = (char *)res->name;
+			res = devm_request_mem_region(dev, tcm->addr, tcm->size,
+						      tcm->bank_name);
+			if (!res) {
+				dev_err(dev, "failed to request tcm resource\n");
+				of_node_put(np);
+				return -EINVAL;
+			}
+		}
+	}
+
+	of_node_put(np);
+	return 0;
+}
+
 /**
  * zynqmp_r5_get_tcm_node()
  * Ideally this function should parse tcm node and store information
@@ -956,10 +1089,19 @@ static int zynqmp_r5_core_init(struct zynqmp_r5_cluster *cluster,
 	struct zynqmp_r5_core *r5_core;
 	int ret, i;
 
-	ret = zynqmp_r5_get_tcm_node(cluster);
-	if (ret < 0) {
-		dev_err(dev, "can't get tcm node, err %d\n", ret);
-		return ret;
+	r5_core = cluster->r5_cores[0];
+	if (of_find_property(r5_core->np, "reg", NULL)) {
+		ret = zynqmp_r5_get_tcm_node_from_dt(cluster);
+		if (ret) {
+			dev_err(dev, "can't get tcm node from dt, err %d\n", ret);
+			return ret;
+		}
+	} else {
+		ret = zynqmp_r5_get_tcm_node(cluster);
+		if (ret < 0) {
+			dev_err(dev, "can't get tcm node, err %d\n", ret);
+			return ret;
+		}
 	}
 
 	for (i = 0; i < cluster->core_count; i++) {
Signature · 1 line
2.25.1
maintainer
#9 lore raw

Re: [PATCH v8 3/3] remoteproc: zynqmp: parse TCM from device tree

Quoted 1 line · Tanmay Shah

ZynqMP TCM information is fixed in driver. Now ZynqMP TCM information

s/"is fixed in driver"/"was fixed in driver"

Quoted 58 lines

is available in device-tree. Parse TCM information in driver as per new bindings.

---

Changes in v8:
- parse power-domains property from device-tree and use EEMI calls to power on/off TCM instead of using pm domains framework
- Remove checking of pm_domain_id validation to power on/off tcm
- Remove spurious change

Changes in v7:
- move checking of pm_domain_id from previous patch
- fix mem_bank_data memory allocation

 drivers/remoteproc/xlnx_r5_remoteproc.c | 154 +++++++++++++++++++++++-
 1 file changed, 148 insertions(+), 6 deletions(-)
drivers/remoteproc/xlnx_r5_remoteproc.c +22 -2
index 4395edea9a64..36d73dcd93f0 100644
@@ -74,8 +74,8 @@ struct mbox_info {
 };
 
 /*
- * Hardcoded TCM bank values. This will be removed once TCM bindings are
- * accepted for system-dt specifications and upstreamed in linux kernel
+ * Hardcoded TCM bank values. This will stay in driver to maintain backward
+ * compatibility with device-tree that does not have TCM information.
  */
 static const struct mem_bank_data zynqmp_tcm_banks_split[] = {
 	{0xffe00000UL, 0x0, 0x10000UL, PD_R5_0_ATCM, "atcm0"}, /* TCM 64KB each */
@@ -878,6 +878,139 @@ static struct zynqmp_r5_core *zynqmp_r5_add_rproc_core(struct device *cdev)
 	return ERR_PTR(ret);
 }
 
+static int zynqmp_r5_get_tcm_node_from_dt(struct zynqmp_r5_cluster *cluster)
+{
+	struct of_phandle_args out_args;
+	int tcm_reg_per_r5, tcm_pd_idx;
+	struct zynqmp_r5_core *r5_core;
+	int i, j, tcm_bank_count, ret;
+	struct platform_device *cpdev;
+	struct mem_bank_data *tcm;
+	struct device_node *np;
+	struct resource *res;
+	u64 abs_addr, size;
+	struct device *dev;
+
+	for (i = 0; i < cluster->core_count; i++) {
+		r5_core = cluster->r5_cores[i];
+		dev = r5_core->dev;
+		np = of_node_get(dev_of_node(dev));
+		tcm_pd_idx = 1;
+
+		/* we have address cell 2 and size cell as 2 */

drivers/remoteproc/xlnx_r5_remoteproc.c static struct zynqmp_r5_core *zynqmp_r5_add_rproc_core(struct device *cdev) · line 910

Quoted 10 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +10 -0
+		tcm_reg_per_r5 = of_property_count_elems_of_size(np, "reg",
+								 4 * sizeof(u32));
+		if (tcm_reg_per_r5 <= 0) {
+			dev_err(dev, "can't get reg property err %d\n", tcm_reg_per_r5);
+			return -EINVAL;
+		}
+
+		/*
+		 * In lockstep mode, r5 core 0 will use r5 core 1 TCM
+		 * power domains as well. so allocate twice of per core TCM

Twice of what? Please use proper english in your multi line comments, i.e a capital letter for the first word and a dot at the end.

Quoted 14 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +14 -0
+		 */
+		if (cluster->mode == LOCKSTEP_MODE)
+			tcm_bank_count = tcm_reg_per_r5 * 2;
+		else
+			tcm_bank_count = tcm_reg_per_r5;
+
+		r5_core->tcm_banks = devm_kcalloc(dev, tcm_bank_count,
+						  sizeof(struct mem_bank_data *),
+						  GFP_KERNEL);
+		if (!r5_core->tcm_banks)
+			ret = -ENOMEM;
+
+		r5_core->tcm_bank_count = tcm_bank_count;
+		for (j = 0; j < tcm_bank_count; j++) {

drivers/remoteproc/xlnx_r5_remoteproc.c static struct zynqmp_r5_core *zynqmp_r5_add_rproc_core(struct device *cdev) · line 934

Quoted 10 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +10 -0
+			tcm = devm_kzalloc(dev, sizeof(struct mem_bank_data),
+					   GFP_KERNEL);
+			if (!tcm)
+				return -ENOMEM;
+
+			r5_core->tcm_banks[j] = tcm;
+
+			/*
+			 * In lockstep mode, get second core's TCM power domains id
+			 * after first core TCM parsing is done as

There seems to be words missing at the end of the sentence, and there is no dot.

Quoted 15 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +15 -0
+			 */
+			if (j == tcm_reg_per_r5) {
+				/* dec first core node */
+				of_node_put(np);
+
+				/* get second core node */
+				np = of_get_next_child(cluster->dev->of_node, np);
+
+				/*
+				 * reset index of power-domains property list
+				 * for second core
+				 */
+				tcm_pd_idx = 1;
+			}
+

drivers/remoteproc/xlnx_r5_remoteproc.c static struct zynqmp_r5_core *zynqmp_r5_add_rproc_core(struct device *cdev) · line 959

Quoted 10 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +10 -0
+			/* get power-domains id of tcm */
+			ret = of_parse_phandle_with_args(np, "power-domains",
+							 "#power-domain-cells",
+							 tcm_pd_idx,
+							 &out_args);
+			if (ret) {
+				dev_err(r5_core->dev,
+					"failed to get tcm %d pm domain, ret %d\n",
+					j, ret);
+				of_node_put(out_args.np);

I'm pretty sure this isn't needed in error conditions since @out_args would not have been assigned.

drivers/remoteproc/xlnx_r5_remoteproc.c static struct zynqmp_r5_core *zynqmp_r5_add_rproc_core(struct device *cdev) · line 969

Quoted 10 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +10 -0
+				return ret;
+			}
+			tcm->pm_domain_id = out_args.args[0];
+			of_node_put(out_args.np);
+			tcm_pd_idx++;
+
+			/*
+			 * In lockstep mode, we only need second core's power domain
+			 * ids. Other information from second core isn't needed so
+			 * ignore it. This forms table as zynqmp_tcm_banks_lockstep

I don't understand the last sentence of this comment and it is missing a dot at the end. Comments should be enlightening, the ones I found in this patch are sowing confusion.

drivers/remoteproc/xlnx_r5_remoteproc.c static struct zynqmp_r5_core *zynqmp_r5_add_rproc_core(struct device *cdev) · line 973

Quoted 4 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +4 -0
+			 */
+			if (j >= tcm_reg_per_r5)
+				contiue;
+

This condition and the one above (j == tcm_reg_per_r5) is brittle and almost guaranteed to cause maintenance problems in the future.

I understand your will to reuse as much code as possible but this is one of the rare cases where duplicating code is probably better. Please introduce two new functions, i.e zynqmp_r5_get_tcm_node_from_dt_split() and zynqmp_r5_get_tcm_node_from_dt_lockstep(), and do all the necessary processing based on the use case.

Thanks,
Mathieu

Quoted 70 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +53 -4
+			/* get tcm address without translation */
+			ret = of_property_read_reg(np, j, &abs_addr, &size);
+			if (ret) {
+				of_node_put(np);
+				dev_err(dev, "failed to get reg property\n");
+				return ret;
+			}
+
+			/*
+			 * remote processor can address only 32 bits
+			 * so convert 64-bits into 32-bits. This will discard
+			 * any unwanted upper 32-bits.
+			 */
+			tcm->da = (u32)abs_addr;
+			tcm->size = (u32)size;
+
+			cpdev = to_platform_device(dev);
+			res = platform_get_resource(cpdev, IORESOURCE_MEM, j);
+			if (!res) {
+				of_node_put(np);
+				dev_err(dev, "failed to get tcm resource\n");
+				return -EINVAL;
+			}
+
+			tcm->addr = (u32)res->start;
+			tcm->bank_name = (char *)res->name;
+			res = devm_request_mem_region(dev, tcm->addr, tcm->size,
+						      tcm->bank_name);
+			if (!res) {
+				dev_err(dev, "failed to request tcm resource\n");
+				of_node_put(np);
+				return -EINVAL;
+			}
+		}
+	}
+
+	of_node_put(np);
+	return 0;
+}
+
 /**
  * zynqmp_r5_get_tcm_node()
  * Ideally this function should parse tcm node and store information
@@ -956,10 +1089,19 @@ static int zynqmp_r5_core_init(struct zynqmp_r5_cluster *cluster,
 	struct zynqmp_r5_core *r5_core;
 	int ret, i;
 
-	ret = zynqmp_r5_get_tcm_node(cluster);
-	if (ret < 0) {
-		dev_err(dev, "can't get tcm node, err %d\n", ret);
-		return ret;
+	r5_core = cluster->r5_cores[0];
+	if (of_find_property(r5_core->np, "reg", NULL)) {
+		ret = zynqmp_r5_get_tcm_node_from_dt(cluster);
+		if (ret) {
+			dev_err(dev, "can't get tcm node from dt, err %d\n", ret);
+			return ret;
+		}
+	} else {
+		ret = zynqmp_r5_get_tcm_node(cluster);
+		if (ret < 0) {
+			dev_err(dev, "can't get tcm node, err %d\n", ret);
+			return ret;
+		}
 	}
 
 	for (i = 0; i < cluster->core_count; i++) {
Signature · 1 line
2.25.1
#10 lore raw

Re: [PATCH v8 3/3] remoteproc: zynqmp: parse TCM from device tree

Quoted 156 lines · Mathieu Poirier
Quoted 1 line · Tanmay Shah

ZynqMP TCM information is fixed in driver. Now ZynqMP TCM information

s/"is fixed in driver"/"was fixed in driver"

Quoted 58 lines

is available in device-tree. Parse TCM information in driver as per new bindings.

---

Changes in v8:
- parse power-domains property from device-tree and use EEMI calls to power on/off TCM instead of using pm domains framework
- Remove checking of pm_domain_id validation to power on/off tcm
- Remove spurious change

Changes in v7:
- move checking of pm_domain_id from previous patch
- fix mem_bank_data memory allocation

 drivers/remoteproc/xlnx_r5_remoteproc.c | 154 +++++++++++++++++++++++-
 1 file changed, 148 insertions(+), 6 deletions(-)
drivers/remoteproc/xlnx_r5_remoteproc.c +22 -2
index 4395edea9a64..36d73dcd93f0 100644
@@ -74,8 +74,8 @@ struct mbox_info {
 };
 
 /*
- * Hardcoded TCM bank values. This will be removed once TCM bindings are
- * accepted for system-dt specifications and upstreamed in linux kernel
+ * Hardcoded TCM bank values. This will stay in driver to maintain backward
+ * compatibility with device-tree that does not have TCM information.
  */
 static const struct mem_bank_data zynqmp_tcm_banks_split[] = {
 	{0xffe00000UL, 0x0, 0x10000UL, PD_R5_0_ATCM, "atcm0"}, /* TCM 64KB each */
@@ -878,6 +878,139 @@ static struct zynqmp_r5_core *zynqmp_r5_add_rproc_core(struct device *cdev)
 	return ERR_PTR(ret);
 }
 
+static int zynqmp_r5_get_tcm_node_from_dt(struct zynqmp_r5_cluster *cluster)
+{
+	struct of_phandle_args out_args;
+	int tcm_reg_per_r5, tcm_pd_idx;
+	struct zynqmp_r5_core *r5_core;
+	int i, j, tcm_bank_count, ret;
+	struct platform_device *cpdev;
+	struct mem_bank_data *tcm;
+	struct device_node *np;
+	struct resource *res;
+	u64 abs_addr, size;
+	struct device *dev;
+
+	for (i = 0; i < cluster->core_count; i++) {
+		r5_core = cluster->r5_cores[i];
+		dev = r5_core->dev;
+		np = of_node_get(dev_of_node(dev));
+		tcm_pd_idx = 1;
+
+		/* we have address cell 2 and size cell as 2 */

drivers/remoteproc/xlnx_r5_remoteproc.c static struct zynqmp_r5_core *zynqmp_r5_add_rproc_core(struct device *cdev) · line 910

Quoted 10 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +10 -0
+		tcm_reg_per_r5 = of_property_count_elems_of_size(np, "reg",
+								 4 * sizeof(u32));
+		if (tcm_reg_per_r5 <= 0) {
+			dev_err(dev, "can't get reg property err %d\n", tcm_reg_per_r5);
+			return -EINVAL;
+		}
+
+		/*
+		 * In lockstep mode, r5 core 0 will use r5 core 1 TCM
+		 * power domains as well. so allocate twice of per core TCM

Twice of what? Please use proper english in your multi line comments, i.e a capital letter for the first word and a dot at the end.

Quoted 14 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +14 -0
+		 */
+		if (cluster->mode == LOCKSTEP_MODE)
+			tcm_bank_count = tcm_reg_per_r5 * 2;
+		else
+			tcm_bank_count = tcm_reg_per_r5;
+
+		r5_core->tcm_banks = devm_kcalloc(dev, tcm_bank_count,
+						  sizeof(struct mem_bank_data *),
+						  GFP_KERNEL);
+		if (!r5_core->tcm_banks)
+			ret = -ENOMEM;
+
+		r5_core->tcm_bank_count = tcm_bank_count;
+		for (j = 0; j < tcm_bank_count; j++) {

drivers/remoteproc/xlnx_r5_remoteproc.c static struct zynqmp_r5_core *zynqmp_r5_add_rproc_core(struct device *cdev) · line 934

Quoted 10 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +10 -0
+			tcm = devm_kzalloc(dev, sizeof(struct mem_bank_data),
+					   GFP_KERNEL);
+			if (!tcm)
+				return -ENOMEM;
+
+			r5_core->tcm_banks[j] = tcm;
+
+			/*
+			 * In lockstep mode, get second core's TCM power domains id
+			 * after first core TCM parsing is done as

There seems to be words missing at the end of the sentence, and there is no dot.

Quoted 15 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +15 -0
+			 */
+			if (j == tcm_reg_per_r5) {
+				/* dec first core node */
+				of_node_put(np);
+
+				/* get second core node */
+				np = of_get_next_child(cluster->dev->of_node, np);
+
+				/*
+				 * reset index of power-domains property list
+				 * for second core
+				 */
+				tcm_pd_idx = 1;
+			}
+

drivers/remoteproc/xlnx_r5_remoteproc.c static struct zynqmp_r5_core *zynqmp_r5_add_rproc_core(struct device *cdev) · line 959

Quoted 10 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +10 -0
+			/* get power-domains id of tcm */
+			ret = of_parse_phandle_with_args(np, "power-domains",
+							 "#power-domain-cells",
+							 tcm_pd_idx,
+							 &out_args);
+			if (ret) {
+				dev_err(r5_core->dev,
+					"failed to get tcm %d pm domain, ret %d\n",
+					j, ret);
+				of_node_put(out_args.np);

I'm pretty sure this isn't needed in error conditions since @out_args would not have been assigned.

drivers/remoteproc/xlnx_r5_remoteproc.c static struct zynqmp_r5_core *zynqmp_r5_add_rproc_core(struct device *cdev) · line 969

Quoted 10 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +10 -0
+				return ret;
+			}
+			tcm->pm_domain_id = out_args.args[0];
+			of_node_put(out_args.np);
+			tcm_pd_idx++;
+
+			/*
+			 * In lockstep mode, we only need second core's power domain
+			 * ids. Other information from second core isn't needed so
+			 * ignore it. This forms table as zynqmp_tcm_banks_lockstep

I don't understand the last sentence of this comment and it is missing a dot at the end. Comments should be enlightening, the ones I found in this patch are sowing confusion.

drivers/remoteproc/xlnx_r5_remoteproc.c static struct zynqmp_r5_core *zynqmp_r5_add_rproc_core(struct device *cdev) · line 973

Quoted 4 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +4 -0
+			 */
+			if (j >= tcm_reg_per_r5)
+				contiue;
+

This condition and the one above (j == tcm_reg_per_r5) is brittle and almost guaranteed to cause maintenance problems in the future.

Quoted 5 lines

I understand your will to reuse as much code as possible but this is one of the rare cases where duplicating code is probably better. Please introduce two new functions, i.e zynqmp_r5_get_tcm_node_from_dt_split() and zynqmp_r5_get_tcm_node_from_dt_lockstep(), and do all the necessary processing based on the use case.

Ack will fix the documentation and tcm parsing as suggested.

Quoted 73 lines

Thanks,
Mathieu

Quoted 70 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +53 -4
+			/* get tcm address without translation */
+			ret = of_property_read_reg(np, j, &abs_addr, &size);
+			if (ret) {
+				of_node_put(np);
+				dev_err(dev, "failed to get reg property\n");
+				return ret;
+			}
+
+			/*
+			 * remote processor can address only 32 bits
+			 * so convert 64-bits into 32-bits. This will discard
+			 * any unwanted upper 32-bits.
+			 */
+			tcm->da = (u32)abs_addr;
+			tcm->size = (u32)size;
+
+			cpdev = to_platform_device(dev);
+			res = platform_get_resource(cpdev, IORESOURCE_MEM, j);
+			if (!res) {
+				of_node_put(np);
+				dev_err(dev, "failed to get tcm resource\n");
+				return -EINVAL;
+			}
+
+			tcm->addr = (u32)res->start;
+			tcm->bank_name = (char *)res->name;
+			res = devm_request_mem_region(dev, tcm->addr, tcm->size,
+						      tcm->bank_name);
+			if (!res) {
+				dev_err(dev, "failed to request tcm resource\n");
+				of_node_put(np);
+				return -EINVAL;
+			}
+		}
+	}
+
+	of_node_put(np);
+	return 0;
+}
+
 /**
  * zynqmp_r5_get_tcm_node()
  * Ideally this function should parse tcm node and store information
@@ -956,10 +1089,19 @@ static int zynqmp_r5_core_init(struct zynqmp_r5_cluster *cluster,
 	struct zynqmp_r5_core *r5_core;
 	int ret, i;
 
-	ret = zynqmp_r5_get_tcm_node(cluster);
-	if (ret < 0) {
-		dev_err(dev, "can't get tcm node, err %d\n", ret);
-		return ret;
+	r5_core = cluster->r5_cores[0];
+	if (of_find_property(r5_core->np, "reg", NULL)) {
+		ret = zynqmp_r5_get_tcm_node_from_dt(cluster);
+		if (ret) {
+			dev_err(dev, "can't get tcm node from dt, err %d\n", ret);
+			return ret;
+		}
+	} else {
+		ret = zynqmp_r5_get_tcm_node(cluster);
+		if (ret < 0) {
+			dev_err(dev, "can't get tcm node, err %d\n", ret);
+			return ret;
+		}
 	}
 
 	for (i = 0; i < cluster->core_count; i++) {
Signature · 1 line
2.25.1
#11 lore raw

Re: [PATCH v8 3/3] remoteproc: zynqmp: parse TCM from device tree

In reply to Mathieu Poirier
Quoted 156 lines · Mathieu Poirier
Quoted 1 line · Tanmay Shah

ZynqMP TCM information is fixed in driver. Now ZynqMP TCM information

s/"is fixed in driver"/"was fixed in driver"

Quoted 58 lines

is available in device-tree. Parse TCM information in driver as per new bindings.

---

Changes in v8:
- parse power-domains property from device-tree and use EEMI calls to power on/off TCM instead of using pm domains framework
- Remove checking of pm_domain_id validation to power on/off tcm
- Remove spurious change

Changes in v7:
- move checking of pm_domain_id from previous patch
- fix mem_bank_data memory allocation

 drivers/remoteproc/xlnx_r5_remoteproc.c | 154 +++++++++++++++++++++++-
 1 file changed, 148 insertions(+), 6 deletions(-)
drivers/remoteproc/xlnx_r5_remoteproc.c +22 -2
index 4395edea9a64..36d73dcd93f0 100644
@@ -74,8 +74,8 @@ struct mbox_info {
 };
 
 /*
- * Hardcoded TCM bank values. This will be removed once TCM bindings are
- * accepted for system-dt specifications and upstreamed in linux kernel
+ * Hardcoded TCM bank values. This will stay in driver to maintain backward
+ * compatibility with device-tree that does not have TCM information.
  */
 static const struct mem_bank_data zynqmp_tcm_banks_split[] = {
 	{0xffe00000UL, 0x0, 0x10000UL, PD_R5_0_ATCM, "atcm0"}, /* TCM 64KB each */
@@ -878,6 +878,139 @@ static struct zynqmp_r5_core *zynqmp_r5_add_rproc_core(struct device *cdev)
 	return ERR_PTR(ret);
 }
 
+static int zynqmp_r5_get_tcm_node_from_dt(struct zynqmp_r5_cluster *cluster)
+{
+	struct of_phandle_args out_args;
+	int tcm_reg_per_r5, tcm_pd_idx;
+	struct zynqmp_r5_core *r5_core;
+	int i, j, tcm_bank_count, ret;
+	struct platform_device *cpdev;
+	struct mem_bank_data *tcm;
+	struct device_node *np;
+	struct resource *res;
+	u64 abs_addr, size;
+	struct device *dev;
+
+	for (i = 0; i < cluster->core_count; i++) {
+		r5_core = cluster->r5_cores[i];
+		dev = r5_core->dev;
+		np = of_node_get(dev_of_node(dev));
+		tcm_pd_idx = 1;
+
+		/* we have address cell 2 and size cell as 2 */

drivers/remoteproc/xlnx_r5_remoteproc.c static struct zynqmp_r5_core *zynqmp_r5_add_rproc_core(struct device *cdev) · line 910

Quoted 10 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +10 -0
+		tcm_reg_per_r5 = of_property_count_elems_of_size(np, "reg",
+								 4 * sizeof(u32));
+		if (tcm_reg_per_r5 <= 0) {
+			dev_err(dev, "can't get reg property err %d\n", tcm_reg_per_r5);
+			return -EINVAL;
+		}
+
+		/*
+		 * In lockstep mode, r5 core 0 will use r5 core 1 TCM
+		 * power domains as well. so allocate twice of per core TCM

Twice of what? Please use proper english in your multi line comments, i.e a capital letter for the first word and a dot at the end.

Quoted 14 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +14 -0
+		 */
+		if (cluster->mode == LOCKSTEP_MODE)
+			tcm_bank_count = tcm_reg_per_r5 * 2;
+		else
+			tcm_bank_count = tcm_reg_per_r5;
+
+		r5_core->tcm_banks = devm_kcalloc(dev, tcm_bank_count,
+						  sizeof(struct mem_bank_data *),
+						  GFP_KERNEL);
+		if (!r5_core->tcm_banks)
+			ret = -ENOMEM;
+
+		r5_core->tcm_bank_count = tcm_bank_count;
+		for (j = 0; j < tcm_bank_count; j++) {

drivers/remoteproc/xlnx_r5_remoteproc.c static struct zynqmp_r5_core *zynqmp_r5_add_rproc_core(struct device *cdev) · line 934

Quoted 10 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +10 -0
+			tcm = devm_kzalloc(dev, sizeof(struct mem_bank_data),
+					   GFP_KERNEL);
+			if (!tcm)
+				return -ENOMEM;
+
+			r5_core->tcm_banks[j] = tcm;
+
+			/*
+			 * In lockstep mode, get second core's TCM power domains id
+			 * after first core TCM parsing is done as

There seems to be words missing at the end of the sentence, and there is no dot.

Quoted 15 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +15 -0
+			 */
+			if (j == tcm_reg_per_r5) {
+				/* dec first core node */
+				of_node_put(np);
+
+				/* get second core node */
+				np = of_get_next_child(cluster->dev->of_node, np);
+
+				/*
+				 * reset index of power-domains property list
+				 * for second core
+				 */
+				tcm_pd_idx = 1;
+			}
+

drivers/remoteproc/xlnx_r5_remoteproc.c static struct zynqmp_r5_core *zynqmp_r5_add_rproc_core(struct device *cdev) · line 959

Quoted 10 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +10 -0
+			/* get power-domains id of tcm */
+			ret = of_parse_phandle_with_args(np, "power-domains",
+							 "#power-domain-cells",
+							 tcm_pd_idx,
+							 &out_args);
+			if (ret) {
+				dev_err(r5_core->dev,
+					"failed to get tcm %d pm domain, ret %d\n",
+					j, ret);
+				of_node_put(out_args.np);

I'm pretty sure this isn't needed in error conditions since @out_args would not have been assigned.

drivers/remoteproc/xlnx_r5_remoteproc.c static struct zynqmp_r5_core *zynqmp_r5_add_rproc_core(struct device *cdev) · line 969

Quoted 10 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +10 -0
+				return ret;
+			}
+			tcm->pm_domain_id = out_args.args[0];
+			of_node_put(out_args.np);
+			tcm_pd_idx++;
+
+			/*
+			 * In lockstep mode, we only need second core's power domain
+			 * ids. Other information from second core isn't needed so
+			 * ignore it. This forms table as zynqmp_tcm_banks_lockstep

I don't understand the last sentence of this comment and it is missing a dot at the end. Comments should be enlightening, the ones I found in this patch are sowing confusion.

drivers/remoteproc/xlnx_r5_remoteproc.c static struct zynqmp_r5_core *zynqmp_r5_add_rproc_core(struct device *cdev) · line 973

Quoted 4 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +4 -0
+			 */
+			if (j >= tcm_reg_per_r5)
+				contiue;
+

This condition and the one above (j == tcm_reg_per_r5) is brittle and almost guaranteed to cause maintenance problems in the future.

Quoted 5 lines

I understand your will to reuse as much code as possible but this is one of the rare cases where duplicating code is probably better. Please introduce two new functions, i.e zynqmp_r5_get_tcm_node_from_dt_split() and zynqmp_r5_get_tcm_node_from_dt_lockstep(), and do all the necessary processing based on the use case.

Hi Mathieu,

I tried to implement this and it still looks hacky, as in lockstep mode unnecessary TCM is being allocated just to store power-domains.

Instead, I am taking another cleaner approach where, TCM is parsed in uniform way in both modes from device-tree during

zynqmp_r5_core_init. However, during  "add_tcm_carveout_lockstep_mode" call, I will simply parse second core's TCM power-domains

from device-tree and turn it on.

I will implement this and send v9 after successful testing. I wanted to give you heads up on this approach. I hope it is fine.

Thanks,
Tanmay

Quoted 74 lines

Thanks,
Mathieu

Quoted 70 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +53 -4
+			/* get tcm address without translation */
+			ret = of_property_read_reg(np, j, &abs_addr, &size);
+			if (ret) {
+				of_node_put(np);
+				dev_err(dev, "failed to get reg property\n");
+				return ret;
+			}
+
+			/*
+			 * remote processor can address only 32 bits
+			 * so convert 64-bits into 32-bits. This will discard
+			 * any unwanted upper 32-bits.
+			 */
+			tcm->da = (u32)abs_addr;
+			tcm->size = (u32)size;
+
+			cpdev = to_platform_device(dev);
+			res = platform_get_resource(cpdev, IORESOURCE_MEM, j);
+			if (!res) {
+				of_node_put(np);
+				dev_err(dev, "failed to get tcm resource\n");
+				return -EINVAL;
+			}
+
+			tcm->addr = (u32)res->start;
+			tcm->bank_name = (char *)res->name;
+			res = devm_request_mem_region(dev, tcm->addr, tcm->size,
+						      tcm->bank_name);
+			if (!res) {
+				dev_err(dev, "failed to request tcm resource\n");
+				of_node_put(np);
+				return -EINVAL;
+			}
+		}
+	}
+
+	of_node_put(np);
+	return 0;
+}
+
 /**
  * zynqmp_r5_get_tcm_node()
  * Ideally this function should parse tcm node and store information
@@ -956,10 +1089,19 @@ static int zynqmp_r5_core_init(struct zynqmp_r5_cluster *cluster,
 	struct zynqmp_r5_core *r5_core;
 	int ret, i;
 
-	ret = zynqmp_r5_get_tcm_node(cluster);
-	if (ret < 0) {
-		dev_err(dev, "can't get tcm node, err %d\n", ret);
-		return ret;
+	r5_core = cluster->r5_cores[0];
+	if (of_find_property(r5_core->np, "reg", NULL)) {
+		ret = zynqmp_r5_get_tcm_node_from_dt(cluster);
+		if (ret) {
+			dev_err(dev, "can't get tcm node from dt, err %d\n", ret);
+			return ret;
+		}
+	} else {
+		ret = zynqmp_r5_get_tcm_node(cluster);
+		if (ret < 0) {
+			dev_err(dev, "can't get tcm node, err %d\n", ret);
+			return ret;
+		}
 	}
 
 	for (i = 0; i < cluster->core_count; i++) {
Signature · 1 line
2.25.1
maintainer
#12 lore raw

Re: [PATCH v8 3/3] remoteproc: zynqmp: parse TCM from device tree

Quoted 169 lines · Tanmay Shah
Quoted 153 lines · Mathieu Poirier
Quoted 1 line · Tanmay Shah

ZynqMP TCM information is fixed in driver. Now ZynqMP TCM information

s/"is fixed in driver"/"was fixed in driver"

Quoted 58 lines

is available in device-tree. Parse TCM information in driver as per new bindings.

---

Changes in v8:
- parse power-domains property from device-tree and use EEMI calls to power on/off TCM instead of using pm domains framework
- Remove checking of pm_domain_id validation to power on/off tcm
- Remove spurious change

Changes in v7:
- move checking of pm_domain_id from previous patch
- fix mem_bank_data memory allocation

 drivers/remoteproc/xlnx_r5_remoteproc.c | 154 +++++++++++++++++++++++-
 1 file changed, 148 insertions(+), 6 deletions(-)
drivers/remoteproc/xlnx_r5_remoteproc.c +22 -2
index 4395edea9a64..36d73dcd93f0 100644
@@ -74,8 +74,8 @@ struct mbox_info {
 };
 
 /*
- * Hardcoded TCM bank values. This will be removed once TCM bindings are
- * accepted for system-dt specifications and upstreamed in linux kernel
+ * Hardcoded TCM bank values. This will stay in driver to maintain backward
+ * compatibility with device-tree that does not have TCM information.
  */
 static const struct mem_bank_data zynqmp_tcm_banks_split[] = {
    {0xffe00000UL, 0x0, 0x10000UL, PD_R5_0_ATCM, "atcm0"}, /* TCM 64KB each */
@@ -878,6 +878,139 @@ static struct zynqmp_r5_core *zynqmp_r5_add_rproc_core(struct device *cdev)
    return ERR_PTR(ret);
 }
 
+static int zynqmp_r5_get_tcm_node_from_dt(struct zynqmp_r5_cluster *cluster)
+{
+   struct of_phandle_args out_args;
+   int tcm_reg_per_r5, tcm_pd_idx;
+   struct zynqmp_r5_core *r5_core;
+   int i, j, tcm_bank_count, ret;
+   struct platform_device *cpdev;
+   struct mem_bank_data *tcm;
+   struct device_node *np;
+   struct resource *res;
+   u64 abs_addr, size;
+   struct device *dev;
+
+   for (i = 0; i < cluster->core_count; i++) {
+           r5_core = cluster->r5_cores[i];
+           dev = r5_core->dev;
+           np = of_node_get(dev_of_node(dev));
+           tcm_pd_idx = 1;
+
+           /* we have address cell 2 and size cell as 2 */

drivers/remoteproc/xlnx_r5_remoteproc.c static struct zynqmp_r5_core *zynqmp_r5_add_rproc_core(struct device *cdev) · line 910

Quoted 10 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +10 -0
+           tcm_reg_per_r5 = of_property_count_elems_of_size(np, "reg",
+                                                            4 * sizeof(u32));
+           if (tcm_reg_per_r5 <= 0) {
+                   dev_err(dev, "can't get reg property err %d\n", tcm_reg_per_r5);
+                   return -EINVAL;
+           }
+
+           /*
+            * In lockstep mode, r5 core 0 will use r5 core 1 TCM
+            * power domains as well. so allocate twice of per core TCM

Twice of what? Please use proper english in your multi line comments, i.e a capital letter for the first word and a dot at the end.

Quoted 14 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +14 -0
+            */
+           if (cluster->mode == LOCKSTEP_MODE)
+                   tcm_bank_count = tcm_reg_per_r5 * 2;
+           else
+                   tcm_bank_count = tcm_reg_per_r5;
+
+           r5_core->tcm_banks = devm_kcalloc(dev, tcm_bank_count,
+                                             sizeof(struct mem_bank_data *),
+                                             GFP_KERNEL);
+           if (!r5_core->tcm_banks)
+                   ret = -ENOMEM;
+
+           r5_core->tcm_bank_count = tcm_bank_count;
+           for (j = 0; j < tcm_bank_count; j++) {

drivers/remoteproc/xlnx_r5_remoteproc.c static struct zynqmp_r5_core *zynqmp_r5_add_rproc_core(struct device *cdev) · line 934

Quoted 10 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +10 -0
+                   tcm = devm_kzalloc(dev, sizeof(struct mem_bank_data),
+                                      GFP_KERNEL);
+                   if (!tcm)
+                           return -ENOMEM;
+
+                   r5_core->tcm_banks[j] = tcm;
+
+                   /*
+                    * In lockstep mode, get second core's TCM power domains id
+                    * after first core TCM parsing is done as

There seems to be words missing at the end of the sentence, and there is no dot.

Quoted 15 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +15 -0
+                    */
+                   if (j == tcm_reg_per_r5) {
+                           /* dec first core node */
+                           of_node_put(np);
+
+                           /* get second core node */
+                           np = of_get_next_child(cluster->dev->of_node, np);
+
+                           /*
+                            * reset index of power-domains property list
+                            * for second core
+                            */
+                           tcm_pd_idx = 1;
+                   }
+

drivers/remoteproc/xlnx_r5_remoteproc.c static struct zynqmp_r5_core *zynqmp_r5_add_rproc_core(struct device *cdev) · line 959

Quoted 10 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +10 -0
+                   /* get power-domains id of tcm */
+                   ret = of_parse_phandle_with_args(np, "power-domains",
+                                                    "#power-domain-cells",
+                                                    tcm_pd_idx,
+                                                    &out_args);
+                   if (ret) {
+                           dev_err(r5_core->dev,
+                                   "failed to get tcm %d pm domain, ret %d\n",
+                                   j, ret);
+                           of_node_put(out_args.np);

I'm pretty sure this isn't needed in error conditions since @out_args would not have been assigned.

drivers/remoteproc/xlnx_r5_remoteproc.c static struct zynqmp_r5_core *zynqmp_r5_add_rproc_core(struct device *cdev) · line 969

Quoted 10 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +10 -0
+                           return ret;
+                   }
+                   tcm->pm_domain_id = out_args.args[0];
+                   of_node_put(out_args.np);
+                   tcm_pd_idx++;
+
+                   /*
+                    * In lockstep mode, we only need second core's power domain
+                    * ids. Other information from second core isn't needed so
+                    * ignore it. This forms table as zynqmp_tcm_banks_lockstep

I don't understand the last sentence of this comment and it is missing a dot at the end. Comments should be enlightening, the ones I found in this patch are sowing confusion.

drivers/remoteproc/xlnx_r5_remoteproc.c static struct zynqmp_r5_core *zynqmp_r5_add_rproc_core(struct device *cdev) · line 973

Quoted 4 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +4 -0
+                    */
+                   if (j >= tcm_reg_per_r5)
+                           contiue;
+
Quoted 8 lines

This condition and the one above (j == tcm_reg_per_r5) is brittle and almost guaranteed to cause maintenance problems in the future.

I understand your will to reuse as much code as possible but this is one of the rare cases where duplicating code is probably better. Please introduce two new functions, i.e zynqmp_r5_get_tcm_node_from_dt_split() and zynqmp_r5_get_tcm_node_from_dt_lockstep(), and do all the necessary processing based on the use case.

Hi Mathieu,

I tried to implement this and it still looks hacky, as in lockstep mode unnecessary TCM is being allocated just to store power-domains.

Quoted 8 lines

Instead, I am taking another cleaner approach where, TCM is parsed in uniform way in both modes from device-tree during

zynqmp_r5_core_init. However, during "add_tcm_carveout_lockstep_mode" call, I will simply parse second core's TCM power-domains

from device-tree and turn it on.

I will implement this and send v9 after successful testing. I wanted to give you heads up on this approach. I hope it is fine.

Thanks for letting me know - now I don't have to pull out what's left of hair on my head to figure out what is going on.

Quoted 78 lines

Thanks,
Tanmay

Quoted 74 lines

Thanks,
Mathieu

Quoted 70 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +53 -5
+                   /* get tcm address without translation */
+                   ret = of_property_read_reg(np, j, &abs_addr, &size);
+                   if (ret) {
+                           of_node_put(np);
+                           dev_err(dev, "failed to get reg property\n");
+                           return ret;
+                   }
+
+                   /*
+                    * remote processor can address only 32 bits
+                    * so convert 64-bits into 32-bits. This will discard
+                    * any unwanted upper 32-bits.
+                    */
+                   tcm->da = (u32)abs_addr;
+                   tcm->size = (u32)size;
+
+                   cpdev = to_platform_device(dev);
+                   res = platform_get_resource(cpdev, IORESOURCE_MEM, j);
+                   if (!res) {
+                           of_node_put(np);
+                           dev_err(dev, "failed to get tcm resource\n");
+                           return -EINVAL;
+                   }
+
+                   tcm->addr = (u32)res->start;
+                   tcm->bank_name = (char *)res->name;
+                   res = devm_request_mem_region(dev, tcm->addr, tcm->size,
+                                                 tcm->bank_name);
+                   if (!res) {
+                           dev_err(dev, "failed to request tcm resource\n");
+                           of_node_put(np);
+                           return -EINVAL;
+                   }
+           }
+   }
+
+   of_node_put(np);
+   return 0;
+}
+
 /**
  * zynqmp_r5_get_tcm_node()
  * Ideally this function should parse tcm node and store information
@@ -956,10 +1089,19 @@ static int zynqmp_r5_core_init(struct zynqmp_r5_cluster *cluster,
    struct zynqmp_r5_core *r5_core;
    int ret, i;
 
-   ret = zynqmp_r5_get_tcm_node(cluster);
-   if (ret < 0) {
-           dev_err(dev, "can't get tcm node, err %d\n", ret);
-           return ret;
+   r5_core = cluster->r5_cores[0];
+   if (of_find_property(r5_core->np, "reg", NULL)) {
+           ret = zynqmp_r5_get_tcm_node_from_dt(cluster);
+           if (ret) {
+                   dev_err(dev, "can't get tcm node from dt, err %d\n", ret);
+                   return ret;
+           }
+   } else {
+           ret = zynqmp_r5_get_tcm_node(cluster);
+           if (ret < 0) {
+                   dev_err(dev, "can't get tcm node, err %d\n", ret);
+                   return ret;
+           }
    }
 
    for (i = 0; i < cluster->core_count; i++) {
--

2.25.1