add zynqmp TCM bindings
v5 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 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 depends on following pending patch:
https://lore.kernel.org/all/[email protected]/
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
Tanmay Shah (3):
dts: zynqmp: add properties for TCM in remoteproc
remoteproc: zynqmp: add pm domains support
remoteproc: zynqmp: parse TCM from device tree
.../remoteproc/xlnx,zynqmp-r5fss.yaml | 131 ++++++- arch/arm64/boot/dts/xilinx/zynqmp.dtsi | 28 +- drivers/remoteproc/xlnx_r5_remoteproc.c | 346 ++++++++++++++++-- 3 files changed, 454 insertions(+), 51 deletions(-)
base-commit: 1a93ced18d7b81be39beba26b1c168ef21c8d0ad
prerequisite-patch-id: fe44cda02ab56ead54bea998952f27c8b7fc5ff0
Signature · 1 line
2.25.1
PATCH v5 1/4 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
@@ -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
PATCH v5 2/4 dts: zynqmp: add properties for TCM in remoteproc
In reply to Tanmay ShahAdd properties as per new bindings in zynqmp remoteproc node to represent TCM address and size. This patch configures RPU in split mode and adds TCM information accordingly.
--- arch/arm64/boot/dts/xilinx/zynqmp.dtsi | 28 ++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)
arch/arm64/boot/dts/xilinx/zynqmp.dtsi +22 -6
@@ -247,19 +247,35 @@ fpga_full: fpga-full { ranges; }; - remoteproc { + remoteproc@ffe00000 { compatible = "xlnx,zynqmp-r5fss"; - xlnx,cluster-mode = <1>; + xlnx,cluster-mode = <0>; - r5f-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
Mathieu Poirier
maintainerRe: [PATCH v5 2/4] dts: zynqmp: add properties for TCM in remoteproc
Quoted 4 lines · Tanmay Shah
Add properties as per new bindings in zynqmp remoteproc node to represent TCM address and size. This patch configures RPU in split mode and adds TCM information accordingly.
Why is this changed from lockstep to split mode? What about all the people out there that are expecting a lockstep mode?
Quoted 54 lines
Signed-off-by Tanmay Shah <[email protected]>--- arch/arm64/boot/dts/xilinx/zynqmp.dtsi | 28 ++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)arch/arm64/boot/dts/xilinx/zynqmp.dtsi +22
-6@@ -247,19 +247,35 @@ fpga_full: fpga-full { ranges; }; - remoteproc { + remoteproc@ffe00000 { compatible = "xlnx,zynqmp-r5fss"; - xlnx,cluster-mode = <1>; + xlnx,cluster-mode = <0>; - r5f-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
Re: [PATCH v5 2/4] dts: zynqmp: add properties for TCM in remoteproc
Hi Mathieu,
Thanks for the reviews. Please find my comments below.
Quoted 8 lines · Mathieu Poirier
Quoted 4 lines · Tanmay Shah
Add properties as per new bindings in zynqmp remoteproc node to represent TCM address and size. This patch configures RPU in split mode and adds TCM information accordingly.
Why is this changed from lockstep to split mode? What about all the people out there that are expecting a lockstep mode?
I agree, this should have been in split mode in the first place as we would like to demonstrate use of both
RPUs with two separate demo firmwares which is the best use of the
hardware and the most preferred use of zynqmp platform by people. That motivates to change
this to split mode.
Now changing this may not be problem for lot of people with following reasons.
The firmwares that are only using first 64KB of TCM memory, they can easily run in split mode as well.
Also rpmsg vring information isn't available in device-tree yet, so I am hoping that firmware that
are using upstream device-tree are not that big yet.
If we change this to split mode before introducing rpmsg related nodes, I bet it will affect very less number of people.
For lockstep mode the example is available in dt-bindings document.
So, if people need lockstep mode for any reason, all they need to change is xlnx,cluster-mode property from 0 to 1 and TCM nodes
from bindings document.
If you think it's crucial to mention all above, I can send new patch with all above info in commit message.
Quoted 55 lines
Quoted 55 lines
Signed-off-by Tanmay Shah <[email protected]>--- arch/arm64/boot/dts/xilinx/zynqmp.dtsi | 28 ++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)arch/arm64/boot/dts/xilinx/zynqmp.dtsi +22
-6@@ -247,19 +247,35 @@ fpga_full: fpga-full { ranges; }; - remoteproc { + remoteproc@ffe00000 { compatible = "xlnx,zynqmp-r5fss"; - xlnx,cluster-mode = <1>; + xlnx,cluster-mode = <0>; - r5f-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
Re: [PATCH v5 2/4] dts: zynqmp: add properties for TCM in remoteproc
Quoted 34 lines · Tanmay Shah
Hi Mathieu,
Thanks for the reviews. Please find my comments below.
Quoted 8 lines · Mathieu Poirier
Quoted 4 lines · Tanmay Shah
Add properties as per new bindings in zynqmp remoteproc node to represent TCM address and size. This patch configures RPU in split mode and adds TCM information accordingly.
Why is this changed from lockstep to split mode? What about all the people out there that are expecting a lockstep mode?
I agree, this should have been in split mode in the first place as we would like to demonstrate use of both
RPUs with two separate demo firmwares which is the best use of the
hardware and the most preferred use of zynqmp platform by people. That motivates to change
this to split mode.
Now changing this may not be problem for lot of people with following reasons.
The firmwares that are only using first 64KB of TCM memory, they can easily run in split mode as well.
Also rpmsg vring information isn't available in device-tree yet, so I am hoping that firmware that
are using upstream device-tree are not that big yet.
If we change this to split mode before introducing rpmsg related nodes, I bet it will affect very less number of people.
Quoted 8 lines
For lockstep mode the example is available in dt-bindings document.
So, if people need lockstep mode for any reason, all they need to change is xlnx,cluster-mode property from 0 to 1 and TCM nodes
from bindings document.
If you think it's crucial to mention all above, I can send new patch with all above info in commit message.
Something to add to this. So, let's say if we don't change it now, what would be good time to change it?
As I am hopping to use RPU1 as well with upstream device-tree. Please let me know some suggestion to work this.
Thanks and again as always appreciate complete reviews,
Tanmay
Quoted 57 lines
Quoted 57 lines
Quoted 57 lines
Signed-off-by Tanmay Shah <[email protected]>--- arch/arm64/boot/dts/xilinx/zynqmp.dtsi | 28 ++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)arch/arm64/boot/dts/xilinx/zynqmp.dtsi +22
-6@@ -247,19 +247,35 @@ fpga_full: fpga-full { ranges; }; - remoteproc { + remoteproc@ffe00000 { compatible = "xlnx,zynqmp-r5fss"; - xlnx,cluster-mode = <1>; + xlnx,cluster-mode = <0>; - r5f-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
Mathieu Poirier
maintainerRe: [PATCH v5 2/4] dts: zynqmp: add properties for TCM in remoteproc
Quoted 32 lines · Tanmay Shah
Quoted 29 lines · Tanmay Shah
Hi Mathieu,
Thanks for the reviews. Please find my comments below.
Quoted 8 lines · Mathieu Poirier
Quoted 4 lines · Tanmay Shah
Add properties as per new bindings in zynqmp remoteproc node to represent TCM address and size. This patch configures RPU in split mode and adds TCM information accordingly.
Why is this changed from lockstep to split mode? What about all the people out there that are expecting a lockstep mode?
I agree, this should have been in split mode in the first place as we would like to demonstrate use of both
RPUs with two separate demo firmwares which is the best use of the
hardware and the most preferred use of zynqmp platform by people. That motivates to change
this to split mode.
Now changing this may not be problem for lot of people with following reasons.
The firmwares that are only using first 64KB of TCM memory, they can easily run in split mode as well.
Also rpmsg vring information isn't available in device-tree yet, so I am hoping that firmware that
Quoted 7 lines
Quoted 7 lines
are using upstream device-tree are not that big yet.
If we change this to split mode before introducing rpmsg related nodes, I bet it will affect very less number of people.
For lockstep mode the example is available in dt-bindings document.
I could use the same argument for the split mode, i.e default is lockstep and there is an example in the dt-bindings document for split mode.
Quoted 9 lines
Quoted 6 lines
So, if people need lockstep mode for any reason, all they need to change is xlnx,cluster-mode property from 0 to 1 and TCM nodes
from bindings document.
If you think it's crucial to mention all above, I can send new patch with all above info in commit message.
Something to add to this. So, let's say if we don't change it now, what would be good time to change it?
The best way to go about this is to introduce another DT that is tailored for split mode. That way people can choose to boot their device in a specific mode using the DT. If you decide to go this way, look at how ST has split their DT for different boards - search for "m4_rproc" under " arch/arm/boot/dts/st".
Quoted 64 lines
As I am hopping to use RPU1 as well with upstream device-tree. Please let me know some suggestion to work this.
Thanks and again as always appreciate complete reviews,
Tanmay
Quoted 57 lines
Quoted 57 lines
Quoted 57 lines
Signed-off-by Tanmay Shah <[email protected]>--- arch/arm64/boot/dts/xilinx/zynqmp.dtsi | 28 ++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)arch/arm64/boot/dts/xilinx/zynqmp.dtsi +22
-7@@ -247,19 +247,35 @@ fpga_full: fpga-full { ranges; }; - remoteproc { + remoteproc@ffe00000 { compatible = "xlnx,zynqmp-r5fss"; - xlnx,cluster-mode = <1>; + xlnx,cluster-mode = <0>; - r5f-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>; }; }; --2.25.1
Re: [PATCH v5 2/4] dts: zynqmp: add properties for TCM in remoteproc
Quoted 52 lines · Mathieu Poirier
Quoted 32 lines · Tanmay Shah
Quoted 29 lines · Tanmay Shah
Hi Mathieu,
Thanks for the reviews. Please find my comments below.
Quoted 8 lines · Mathieu Poirier
Quoted 4 lines · Tanmay Shah
Add properties as per new bindings in zynqmp remoteproc node to represent TCM address and size. This patch configures RPU in split mode and adds TCM information accordingly.
Why is this changed from lockstep to split mode? What about all the people out there that are expecting a lockstep mode?
I agree, this should have been in split mode in the first place as we would like to demonstrate use of both
RPUs with two separate demo firmwares which is the best use of the
hardware and the most preferred use of zynqmp platform by people. That motivates to change
this to split mode.
Now changing this may not be problem for lot of people with following reasons.
The firmwares that are only using first 64KB of TCM memory, they can easily run in split mode as well.
Also rpmsg vring information isn't available in device-tree yet, so I am hoping that firmware that
Quoted 7 lines
Quoted 7 lines
are using upstream device-tree are not that big yet.
If we change this to split mode before introducing rpmsg related nodes, I bet it will affect very less number of people.
For lockstep mode the example is available in dt-bindings document.
I could use the same argument for the split mode, i.e default is lockstep and there is an example in the dt-bindings document for split mode.
Quoted 7 lines
Quoted 6 lines
So, if people need lockstep mode for any reason, all they need to change is xlnx,cluster-mode property from 0 to 1 and TCM nodes
from bindings document.
If you think it's crucial to mention all above, I can send new patch with all above info in commit message.
Quoted 8 lines
Quoted 2 lines
Something to add to this. So, let's say if we don't change it now, what would be good time to change it?
The best way to go about this is to introduce another DT that is tailored for split mode. That way people can choose to boot their device in a specific mode using the DT. If you decide to go this way, look at how ST has split their DT for different boards - search for "
m4_rproc" under "arch/arm/boot/dts/st".
Thanks for the suggestion. I looked at the example and I think it will work.
I have following idea.
So, if I understand this correctly, we introduce two separate nodes in device-tree.
SOC dtsi file: zynqmp.dtsi
remoteproc_lockstep: remoteproc@... {
. . .
status = "disabled";
};
remoteproc_split: remoteproc@... {
. . .
status = "disabled";
};
And then in board dts enable whatever mode is needed for that board:
*zcu102*.dts
&remoteproc_split {
status = "okay";
};
This sounds like good idea, I hope this is what you mean.
Please let me know if I am missing something.
Quoted 65 lines
Quoted 65 lines
As I am hopping to use RPU1 as well with upstream device-tree. Please let me know some suggestion to work this.
Thanks and again as always appreciate complete reviews,
Tanmay
Quoted 57 lines
Quoted 57 lines
Quoted 57 lines
Signed-off-by Tanmay Shah <[email protected]>--- arch/arm64/boot/dts/xilinx/zynqmp.dtsi | 28 ++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)arch/arm64/boot/dts/xilinx/zynqmp.dtsi +22
-7@@ -247,19 +247,35 @@ fpga_full: fpga-full { ranges; }; - remoteproc { + remoteproc@ffe00000 { compatible = "xlnx,zynqmp-r5fss"; - xlnx,cluster-mode = <1>; + xlnx,cluster-mode = <0>; - r5f-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>; }; }; --2.25.1
Mathieu Poirier
maintainerRe: [PATCH v5 2/4] dts: zynqmp: add properties for TCM in remoteproc
Quoted 69 lines · Tanmay Shah
Quoted 52 lines · Mathieu Poirier
Quoted 32 lines · Tanmay Shah
Quoted 29 lines · Tanmay Shah
Hi Mathieu,
Thanks for the reviews. Please find my comments below.
Quoted 8 lines · Mathieu Poirier
Quoted 4 lines · Tanmay Shah
Add properties as per new bindings in zynqmp remoteproc node to represent TCM address and size. This patch configures RPU in split mode and adds TCM information accordingly.
Why is this changed from lockstep to split mode? What about all the people out there that are expecting a lockstep mode?
I agree, this should have been in split mode in the first place as we would like to demonstrate use of both
RPUs with two separate demo firmwares which is the best use of the
hardware and the most preferred use of zynqmp platform by people. That motivates to change
this to split mode.
Now changing this may not be problem for lot of people with following reasons.
The firmwares that are only using first 64KB of TCM memory, they can easily run in split mode as well.
Also rpmsg vring information isn't available in device-tree yet, so I am hoping that firmware that
Quoted 7 lines
Quoted 7 lines
are using upstream device-tree are not that big yet.
If we change this to split mode before introducing rpmsg related nodes, I bet it will affect very less number of people.
For lockstep mode the example is available in dt-bindings document.
I could use the same argument for the split mode, i.e default is lockstep and there is an example in the dt-bindings document for split mode.
Quoted 7 lines
Quoted 6 lines
So, if people need lockstep mode for any reason, all they need to change is xlnx,cluster-mode property from 0 to 1 and TCM nodes
from bindings document.
If you think it's crucial to mention all above, I can send new patch with all above info in commit message.
Quoted 8 lines
Quoted 2 lines
Something to add to this. So, let's say if we don't change it now, what would be good time to change it?
The best way to go about this is to introduce another DT that is tailored for split mode. That way people can choose to boot their device in a specific mode using the DT. If you decide to go this way, look at how ST has split their DT for different boards - search for "
m4_rproc" under "arch/arm/boot/dts/st".Thanks for the suggestion. I looked at the example and I think it will work.
I have following idea.
So, if I understand this correctly, we introduce two separate nodes in device-tree.
Quoted 7 lines
SOC dtsi file:
zynqmp.dtsi
remoteproc_lockstep: remoteproc@... {. . .
status = "disabled";
I don't think you need the "status"
Quoted 15 lines
};
remoteproc_split: remoteproc@... {. . .
status = "disabled";
};
And then in board dts enable whatever mode is needed for that board:
Quoted 7 lines
*zcu102*.dts
&remoteproc_split{status = "okay";
};
Exactly. Again, I don't think the "status" is needed.
Quoted 71 lines
This sounds like good idea, I hope this is what you mean.
Please let me know if I am missing something.
Quoted 65 lines
Quoted 65 lines
As I am hopping to use RPU1 as well with upstream device-tree. Please let me know some suggestion to work this.
Thanks and again as always appreciate complete reviews,
Tanmay
Quoted 57 lines
Quoted 57 lines
Quoted 57 lines
Signed-off-by Tanmay Shah <[email protected]>--- arch/arm64/boot/dts/xilinx/zynqmp.dtsi | 28 ++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)arch/arm64/boot/dts/xilinx/zynqmp.dtsi +22
-7@@ -247,19 +247,35 @@ fpga_full: fpga-full { ranges; }; - remoteproc { + remoteproc@ffe00000 { compatible = "xlnx,zynqmp-r5fss"; - xlnx,cluster-mode = <1>; + xlnx,cluster-mode = <0>; - r5f-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>; }; }; --2.25.1
Re: [PATCH v5 2/4] dts: zynqmp: add properties for TCM in remoteproc
Quoted 97 lines · Mathieu Poirier
Quoted 69 lines · Tanmay Shah
Quoted 52 lines · Mathieu Poirier
Quoted 32 lines · Tanmay Shah
Quoted 29 lines · Tanmay Shah
Hi Mathieu,
Thanks for the reviews. Please find my comments below.
Quoted 8 lines · Mathieu Poirier
Quoted 4 lines · Tanmay Shah
Add properties as per new bindings in zynqmp remoteproc node to represent TCM address and size. This patch configures RPU in split mode and adds TCM information accordingly.
Why is this changed from lockstep to split mode? What about all the people out there that are expecting a lockstep mode?
I agree, this should have been in split mode in the first place as we would like to demonstrate use of both
RPUs with two separate demo firmwares which is the best use of the
hardware and the most preferred use of zynqmp platform by people. That motivates to change
this to split mode.
Now changing this may not be problem for lot of people with following reasons.
The firmwares that are only using first 64KB of TCM memory, they can easily run in split mode as well.
Also rpmsg vring information isn't available in device-tree yet, so I am hoping that firmware that
Quoted 7 lines
Quoted 7 lines
are using upstream device-tree are not that big yet.
If we change this to split mode before introducing rpmsg related nodes, I bet it will affect very less number of people.
For lockstep mode the example is available in dt-bindings document.
I could use the same argument for the split mode, i.e default is lockstep and there is an example in the dt-bindings document for split mode.
Quoted 7 lines
Quoted 6 lines
So, if people need lockstep mode for any reason, all they need to change is xlnx,cluster-mode property from 0 to 1 and TCM nodes
from bindings document.
If you think it's crucial to mention all above, I can send new patch with all above info in commit message.
Quoted 8 lines
Quoted 2 lines
Something to add to this. So, let's say if we don't change it now, what would be good time to change it?
The best way to go about this is to introduce another DT that is tailored for split mode. That way people can choose to boot their device in a specific mode using the DT. If you decide to go this way, look at how ST has split their DT for different boards - search for "
m4_rproc" under "arch/arm/boot/dts/st".Thanks for the suggestion. I looked at the example and I think it will work.
I have following idea.
So, if I understand this correctly, we introduce two separate nodes in device-tree.
Quoted 7 lines
SOC dtsi file:
zynqmp.dtsi
remoteproc_lockstep: remoteproc@... {. . .
status = "disabled";
I don't think you need the "status"
Quoted 17 lines
};
remoteproc_split: remoteproc@... {. . .
status = "disabled";
};
And then in board dts enable whatever mode is needed for that board:
*zcu102*.dts
Quoted 7 lines
Quoted 5 lines
&remoteproc_split{status = "okay";
};
Exactly. Again, I don't think the "status" is needed.
Thanks for the suggestion. Yes I think if we don't include status then both nodes are enabled by default, and people can
disable in board dts what they don't want.
Instead I keep status disabled, for one of the node, (for split probably as lockstep is already enabled) and people
can choose what they wnt.
Thanks,
Tanmay
Quoted 72 lines
Quoted 72 lines
This sounds like good idea, I hope this is what you mean.
Please let me know if I am missing something.
Quoted 65 lines
Quoted 65 lines
As I am hopping to use RPU1 as well with upstream device-tree. Please let me know some suggestion to work this.
Thanks and again as always appreciate complete reviews,
Tanmay
Quoted 57 lines
Quoted 57 lines
Quoted 57 lines
Signed-off-by Tanmay Shah <[email protected]>--- arch/arm64/boot/dts/xilinx/zynqmp.dtsi | 28 ++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)arch/arm64/boot/dts/xilinx/zynqmp.dtsi +22
-7@@ -247,19 +247,35 @@ fpga_full: fpga-full { ranges; }; - remoteproc { + remoteproc@ffe00000 { compatible = "xlnx,zynqmp-r5fss"; - xlnx,cluster-mode = <1>; + xlnx,cluster-mode = <0>; - r5f-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>; }; }; --2.25.1
PATCH v5 3/4 remoteproc: zynqmp: add pm domains support
In reply to Tanmay ShahUse TCM pm domains extracted from device-tree to power on/off TCM using general pm domain framework
--- drivers/remoteproc/xlnx_r5_remoteproc.c | 224 ++++++++++++++++++++++-- 1 file changed, 205 insertions(+), 19 deletions(-)
drivers/remoteproc/xlnx_r5_remoteproc.c +205 -19
@@ -16,6 +16,7 @@#include <linux/of_reserved_mem.h> #include <linux/platform_device.h> #include <linux/remoteproc.h> +#include <linux/pm_domain.h> #include "remoteproc_internal.h"
@@ -102,6 +103,12 @@ static const struct mem_bank_data zynqmp_tcm_banks_lockstep[] = {* @rproc: rproc handle * @pm_domain_id: RPU CPU power domain id * @ipi: pointer to mailbox information +* @num_pm_dev: number of tcm pm domain devices for this core +* @pm_dev1: pm domain virtual devices for power domain framework +* @pm_dev_link1: pm domain device links after registration +* @pm_dev2: used only in lockstep mode. second core's pm domain virtual devices +* @pm_dev_link2: used only in lockstep mode. second core's pm device links after +* registration */ struct zynqmp_r5_core {struct device *dev;
@@ -111,6 +118,11 @@ struct zynqmp_r5_core {struct rproc *rproc;u32 pm_domain_id;struct mbox_info *ipi; +int num_pm_dev; +struct device **pm_dev1; +struct device_link **pm_dev_link1; +struct device **pm_dev2; +struct device_link **pm_dev_link2; };/**
@@ -575,12 +587,21 @@ static int add_tcm_carveout_split_mode(struct rproc *rproc) bank_size = r5_core->tcm_banks[i]->size; pm_domain_id = r5_core->tcm_banks[i]->pm_domain_id; - ret =zynqmp_pm_request_node (pm_domain_id, -ZYNQMP_PM_CAPABILITY_ACCESS ,0 , -ZYNQMP_PM_REQUEST_ACK_BLOCKING ); -if (ret <0 ) { -dev_err (dev,"failed to turn on TCM 0x%x" , pm_domain_id); - goto release_tcm_split; +/* +* If TCM information is available in device-tree then +* in that case, pm domain framework will power on/off TCM. +* In that case pm_domain_id is set to 0. If hardcode +* bindings from driver is used, then only this driver will +* use pm_domain_id. +*/ +if (pm_domain_id) { + ret =zynqmp_pm_request_node (pm_domain_id, +ZYNQMP_PM_CAPABILITY_ACCESS ,0 , +ZYNQMP_PM_REQUEST_ACK_BLOCKING ); +if (ret <0 ) { +dev_err (dev,"failed to turn on TCM 0x%x" , pm_domain_id); + goto release_tcm_split; + } } dev_dbg(dev, "TCM carveout split mode %s addr=%llx, da=0x%x, size=0x%lx",
@@ -646,13 +667,16 @@ static int add_tcm_carveout_lockstep_mode(struct rproc *rproc)for (i =0 ; i < num_banks; i++) { pm_domain_id = r5_core->tcm_banks[i]->pm_domain_id; -/* Turn on each TCM bank individually */ - ret =zynqmp_pm_request_node (pm_domain_id, -ZYNQMP_PM_CAPABILITY_ACCESS ,0 , -ZYNQMP_PM_REQUEST_ACK_BLOCKING ); -if (ret <0 ) { -dev_err (dev,"failed to turn on TCM 0x%x" , pm_domain_id); - goto release_tcm_lockstep; +if (pm_domain_id) { +/* Turn on each TCM bank individually */ + ret =zynqmp_pm_request_node (pm_domain_id, +ZYNQMP_PM_CAPABILITY_ACCESS ,0 , +ZYNQMP_PM_REQUEST_ACK_BLOCKING ); +if (ret <0 ) { +dev_err (dev,"failed to turn on TCM 0x%x" , + pm_domain_id); + goto release_tcm_lockstep; + } } bank_size = r5_core->tcm_banks[i]->size;
@@ -687,8 +711,10 @@ static int add_tcm_carveout_lockstep_mode(struct rproc *rproc)/* If failed, Turn off all TCM banks turned on before */ for (i--; i >=0 ; i--) { pm_domain_id = r5_core->tcm_banks[i]->pm_domain_id; -zynqmp_pm_release_node (pm_domain_id); +if (pm_domain_id) +zynqmp_pm_release_node (pm_domain_id); } +return ret; }
@@ -758,6 +784,153 @@ static int zynqmp_r5_parse_fw(struct rproc *rproc, const struct firmware *fw)return ret; } +static void zynqmp_r5_remove_pm_domains (struct rproc *rproc) +{ +struct zynqmp_r5_core *r5_core = rproc->priv; +struct device *dev = r5_core->dev; +struct zynqmp_r5_cluster *cluster; +int i; + + cluster =platform_get_drvdata (to_platform_device (dev->parent)); + +for (i =0 ; i < r5_core->num_pm_dev; i++) { +if (r5_core->pm_dev_link1 && r5_core->pm_dev_link1[i]) +device_link_del (r5_core->pm_dev_link1[i]); +if (r5_core->pm_dev1 && !IS_ERR_OR_NULL (r5_core->pm_dev1[i])) +dev_pm_domain_detach (r5_core->pm_dev1[i], false); + } + +kfree (r5_core->pm_dev1); + r5_core->pm_dev1 =NULL ; +kfree (r5_core->pm_dev_link1); + r5_core->pm_dev_link1 =NULL ; + +if (cluster->mode ==SPLIT_MODE ) { + r5_core->num_pm_dev =0 ; +return ; + } + +for (i =0 ; i < r5_core->num_pm_dev; i++) { +if (r5_core->pm_dev_link2 && r5_core->pm_dev_link2[i]) +device_link_del (r5_core->pm_dev_link2[i]); +if (r5_core->pm_dev2 && !IS_ERR_OR_NULL (r5_core->pm_dev2[i])) +dev_pm_domain_detach (r5_core->pm_dev2[i], false); + } + +kfree (r5_core->pm_dev2); + r5_core->pm_dev2 =NULL ; +kfree (r5_core->pm_dev_link2); + r5_core->pm_dev_link2 =NULL ; + r5_core->num_pm_dev =0 ; +} + +static int zynqmp_r5_add_pm_domains (struct rproc *rproc) +{ +struct zynqmp_r5_core *r5_core = rproc->priv; +struct device *dev = r5_core->dev, *dev2; +struct zynqmp_r5_cluster *cluster; +struct platform_device *pdev; +struct device_node *np; +int i, num_pm_dev, ret; + + cluster =platform_get_drvdata (to_platform_device (dev->parent)); + +/* get number of power-domains */ + num_pm_dev =of_count_phandle_with_args (r5_core->np,"power-domains" , +"#power-domain-cells" ); + +if (num_pm_dev <=0 ) +return -EINVAL ; + + r5_core->pm_dev1 =kcalloc (num_pm_dev, +sizeof (struct device *), +GFP_KERNEL ); +if (!r5_core->pm_dev1) + ret = -ENOMEM ; + + r5_core->pm_dev_link1 =kcalloc (num_pm_dev, +sizeof (struct device_link *), +GFP_KERNEL ); +if (!r5_core->pm_dev_link1) +return -ENOMEM ; + + r5_core->num_pm_dev = num_pm_dev; + +/* for zynqmp we only add TCM power domains and not core's power domain */ +for (i =1 ; i < r5_core->num_pm_dev; i++) { + r5_core->pm_dev1[i] =dev_pm_domain_attach_by_id (dev, i); +if (IS_ERR (r5_core->pm_dev1[i])) { +dev_dbg (dev,"failed to attach pm domain %d\n" , i); +return PTR_ERR (r5_core->pm_dev1[i]); + } +if (!r5_core->pm_dev1[i]) { +dev_dbg (dev,"can't attach to pm domain %d\n" , i); +return -EINVAL ; + } + + r5_core->pm_dev_link1[i] =device_link_add (dev, r5_core->pm_dev1[i], +DL_FLAG_STATELESS | +DL_FLAG_RPM_ACTIVE | +DL_FLAG_PM_RUNTIME ); +if (!r5_core->pm_dev_link1[i]) { +dev_pm_domain_detach (r5_core->pm_dev1[i], true); + r5_core->pm_dev1[i] =NULL ; +return -EINVAL ; + } + } + +if (cluster->mode ==SPLIT_MODE ) +return 0 ; + + r5_core->pm_dev2 =kcalloc (num_pm_dev, +sizeof (struct device *), +GFP_KERNEL ); +if (!r5_core->pm_dev2) +return -ENOMEM ; + + r5_core->pm_dev_link2 =kcalloc (num_pm_dev, +sizeof (struct device_link *), +GFP_KERNEL ); +if (!r5_core->pm_dev_link2) +return -ENOMEM ; + +/* get second core's device to detach its power-domains */ + np =of_get_next_child (cluster->dev->of_node,of_node_get (dev->of_node)); + + pdev =of_find_device_by_node (np); +if (!pdev) { +dev_err (cluster->dev,"core1 platform device not available\n" ); +return -EINVAL ; + } + + dev2 = &pdev->dev; + +/* for zynqmp we only add TCM power domains and not core's power domain */ +for (i =1 ; i < r5_core->num_pm_dev; i++) { + r5_core->pm_dev2[i] =dev_pm_domain_attach_by_id (dev2, i); +if (IS_ERR (r5_core->pm_dev2[i])) { +dev_dbg (dev,"can't attach to pm domain %d\n" , i); +return PTR_ERR (r5_core->pm_dev2[i]); + } +if (!r5_core->pm_dev2[i]) { +dev_dbg (dev,"can't attach to pm domain %d\n" , i); +return -EINVAL ; + } + + r5_core->pm_dev_link2[i] =device_link_add (dev, r5_core->pm_dev2[i], +DL_FLAG_STATELESS | +DL_FLAG_RPM_ACTIVE | +DL_FLAG_PM_RUNTIME ); +if (!r5_core->pm_dev_link2[i]) { +dev_pm_domain_detach (r5_core->pm_dev2[i], true); + r5_core->pm_dev2[i] =NULL ; +return -ENODEV ; + } + } + +return 0 ; +} +/** * zynqmp_r5_rproc_prepare() * adds carveouts for TCM bank and reserved memory regions
@@ -770,19 +943,30 @@ static int zynqmp_r5_rproc_prepare(struct rproc *rproc) {int ret; + ret =zynqmp_r5_add_pm_domains (rproc); +if (ret) { +dev_err (&rproc->dev,"failed to add pm domains\n" ); + goto fail_prepare; + } + ret =add_tcm_banks (rproc);if (ret) {dev_err (&rproc->dev,"failed to get TCM banks, err %d\n" , ret); -return ret; + goto fail_prepare; } ret =add_mem_regions_carveout (rproc);if (ret) {dev_err (&rproc->dev,"failed to get reserve mem regions %d\n" , ret); -return ret; + goto fail_prepare; }return 0 ; + +fail_prepare: +zynqmp_r5_remove_pm_domains (rproc); + +return ret; }/**
@@ -801,11 +985,13 @@ static int zynqmp_r5_rproc_unprepare(struct rproc *rproc) r5_core = rproc->priv; +zynqmp_r5_remove_pm_domains (rproc); +for (i =0 ; i < r5_core->tcm_bank_count; i++) { pm_domain_id = r5_core->tcm_banks[i]->pm_domain_id; -if (zynqmp_pm_release_node (pm_domain_id)) -dev_warn (r5_core->dev, -"can't turn off TCM bank 0x%x" , pm_domain_id); +if (pm_domain_id &&zynqmp_pm_release_node (pm_domain_id)) +dev_dbg (r5_core->dev, +"can't turn off TCM bank 0x%x" , pm_domain_id); }return 0 ;
Signature · 1 line
2.25.1
Mathieu Poirier
maintainerRe: [PATCH v5 3/4] remoteproc: zynqmp: add pm domains support
Quoted 98 lines · Tanmay Shah
Use TCM pm domains extracted from device-tree to power on/off TCM using general pm domain framework
Signed-off-by Tanmay Shah <[email protected]>--- drivers/remoteproc/xlnx_r5_remoteproc.c | 224 ++++++++++++++++++++++-- 1 file changed, 205 insertions(+), 19 deletions(-)drivers/remoteproc/xlnx_r5_remoteproc.c +37
-13@@ -16,6 +16,7 @@#include <linux/of_reserved_mem.h> #include <linux/platform_device.h> #include <linux/remoteproc.h> +#include <linux/pm_domain.h> #include "remoteproc_internal.h" @@ -102,6 +103,12 @@ static const struct mem_bank_data zynqmp_tcm_banks_lockstep[] = {* @rproc: rproc handle * @pm_domain_id: RPU CPU power domain id * @ipi: pointer to mailbox information +* @num_pm_dev: number of tcm pm domain devices for this core +* @pm_dev1: pm domain virtual devices for power domain framework +* @pm_dev_link1: pm domain device links after registration +* @pm_dev2: used only in lockstep mode. second core's pm domain virtual devices +* @pm_dev_link2: used only in lockstep mode. second core's pm device links after +* registration */ struct zynqmp_r5_core {struct device *dev;@@ -111,6 +118,11 @@ struct zynqmp_r5_core {struct rproc *rproc;u32 pm_domain_id;struct mbox_info *ipi; +int num_pm_dev; +struct device **pm_dev1; +struct device_link **pm_dev_link1; +struct device **pm_dev2; +struct device_link **pm_dev_link2; };/** @@ -575,12 +587,21 @@ static int add_tcm_carveout_split_mode(struct rproc *rproc) bank_size = r5_core->tcm_banks[i]->size; pm_domain_id = r5_core->tcm_banks[i]->pm_domain_id; - ret =zynqmp_pm_request_node (pm_domain_id, -ZYNQMP_PM_CAPABILITY_ACCESS ,0 , -ZYNQMP_PM_REQUEST_ACK_BLOCKING ); -if (ret <0 ) { -dev_err (dev,"failed to turn on TCM 0x%x" , pm_domain_id); - goto release_tcm_split; +/* +* If TCM information is available in device-tree then +* in that case, pm domain framework will power on/off TCM. +* In that case pm_domain_id is set to 0. If hardcode +* bindings from driver is used, then only this driver will +* use pm_domain_id. +*/ +if (pm_domain_id) { + ret =zynqmp_pm_request_node (pm_domain_id, +ZYNQMP_PM_CAPABILITY_ACCESS ,0 , +ZYNQMP_PM_REQUEST_ACK_BLOCKING ); +if (ret <0 ) { +dev_err (dev,"failed to turn on TCM 0x%x" , pm_domain_id); + goto release_tcm_split; + } } dev_dbg(dev, "TCM carveout split mode %s addr=%llx, da=0x%x, size=0x%lx",@@ -646,13 +667,16 @@ static int add_tcm_carveout_lockstep_mode(struct rproc *rproc)for (i =0 ; i < num_banks; i++) { pm_domain_id = r5_core->tcm_banks[i]->pm_domain_id; -/* Turn on each TCM bank individually */ - ret =zynqmp_pm_request_node (pm_domain_id, -ZYNQMP_PM_CAPABILITY_ACCESS ,0 , -ZYNQMP_PM_REQUEST_ACK_BLOCKING ); -if (ret <0 ) { -dev_err (dev,"failed to turn on TCM 0x%x" , pm_domain_id); - goto release_tcm_lockstep; +if (pm_domain_id) { +/* Turn on each TCM bank individually */ + ret =zynqmp_pm_request_node (pm_domain_id, +ZYNQMP_PM_CAPABILITY_ACCESS ,0 , +ZYNQMP_PM_REQUEST_ACK_BLOCKING ); +if (ret <0 ) { +dev_err (dev,"failed to turn on TCM 0x%x" , + pm_domain_id); + goto release_tcm_lockstep; + } } bank_size = r5_core->tcm_banks[i]->size;
drivers/remoteproc/xlnx_r5_remoteproc.c static int add_tcm_carveout_lockstep_mode(struct rproc *rproc) · line 717
Quoted 8 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +3
-1@@ -687,8 +711,10 @@ static int add_tcm_carveout_lockstep_mode(struct rproc *rproc)/* If failed, Turn off all TCM banks turned on before */ for (i--; i >=0 ; i--) { pm_domain_id = r5_core->tcm_banks[i]->pm_domain_id; -zynqmp_pm_release_node (pm_domain_id); +if (pm_domain_id) +zynqmp_pm_release_node (pm_domain_id); } +
Spurious change
Quoted 13 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +6
-0return ret; }@@ -758,6 +784,153 @@ static int zynqmp_r5_parse_fw(struct rproc *rproc, const struct firmware *fw)return ret; } +static void zynqmp_r5_remove_pm_domains (struct rproc *rproc) +{ +struct zynqmp_r5_core *r5_core = rproc->priv; +struct device *dev = r5_core->dev; +struct zynqmp_r5_cluster *cluster; +int i;
drivers/remoteproc/xlnx_r5_remoteproc.c static int zynqmp_r5_parse_fw(struct rproc *rproc, const struct firmware *fw) · line 802
Quoted 10 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +10
-0+ + cluster =platform_get_drvdata (to_platform_device (dev->parent)); + +for (i =0 ; i < r5_core->num_pm_dev; i++) { +if (r5_core->pm_dev_link1 && r5_core->pm_dev_link1[i]) +device_link_del (r5_core->pm_dev_link1[i]); +if (r5_core->pm_dev1 && !IS_ERR_OR_NULL (r5_core->pm_dev1[i])) +dev_pm_domain_detach (r5_core->pm_dev1[i], false); + } +
A global function such as this one should not have to deal with error conditions. Those should be dealt with in the allocation function where cleanup is done on error conditions. See my comment below in zynqmp_r5_add_pm_domains().
Quoted 22 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +22
-0+kfree (r5_core->pm_dev1); + r5_core->pm_dev1 =NULL ; +kfree (r5_core->pm_dev_link1); + r5_core->pm_dev_link1 =NULL ; + +if (cluster->mode ==SPLIT_MODE ) { + r5_core->num_pm_dev =0 ; +return ; + } + +for (i =0 ; i < r5_core->num_pm_dev; i++) { +if (r5_core->pm_dev_link2 && r5_core->pm_dev_link2[i]) +device_link_del (r5_core->pm_dev_link2[i]); +if (r5_core->pm_dev2 && !IS_ERR_OR_NULL (r5_core->pm_dev2[i])) +dev_pm_domain_detach (r5_core->pm_dev2[i], false); + } + +kfree (r5_core->pm_dev2); + r5_core->pm_dev2 =NULL ; +kfree (r5_core->pm_dev_link2); + r5_core->pm_dev_link2 =NULL ; + r5_core->num_pm_dev =0 ;
drivers/remoteproc/xlnx_r5_remoteproc.c static int zynqmp_r5_parse_fw(struct rproc *rproc, const struct firmware *fw) · line 834
Quoted 10 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +10
-0+} + +static int zynqmp_r5_add_pm_domains (struct rproc *rproc) +{ +struct zynqmp_r5_core *r5_core = rproc->priv; +struct device *dev = r5_core->dev, *dev2; +struct zynqmp_r5_cluster *cluster; +struct platform_device *pdev; +struct device_node *np; +int i, num_pm_dev, ret;
I'm not sure 'ret' is needed - see below.
drivers/remoteproc/xlnx_r5_remoteproc.c static int zynqmp_r5_parse_fw(struct rproc *rproc, const struct firmware *fw) · line 836
Quoted 2 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +2
-0+ + cluster =platform_get_drvdata (to_platform_device (dev->parent));
Why not use dev_get_drvdata() as it is done elsewhere in this driver?
drivers/remoteproc/xlnx_r5_remoteproc.c static int zynqmp_r5_parse_fw(struct rproc *rproc, const struct firmware *fw) · line 849
Quoted 13 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +13
-0+ +/* get number of power-domains */ + num_pm_dev =of_count_phandle_with_args (r5_core->np,"power-domains" , +"#power-domain-cells" ); + +if (num_pm_dev <=0 ) +return -EINVAL ; + + r5_core->pm_dev1 =kcalloc (num_pm_dev, +sizeof (struct device *), +GFP_KERNEL ); +if (!r5_core->pm_dev1) + ret = -ENOMEM ;
What's the goal of the assignment? Did you mean to return an error instead?
drivers/remoteproc/xlnx_r5_remoteproc.c static int zynqmp_r5_parse_fw(struct rproc *rproc, const struct firmware *fw) · line 855
Quoted 6 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +6
-0+ + r5_core->pm_dev_link1 =kcalloc (num_pm_dev, +sizeof (struct device_link *), +GFP_KERNEL ); +if (!r5_core->pm_dev_link1) +return -ENOMEM ;
In case of error, always cleanup the work done in the current function. That way cleanup functions such as zynqmp_r5_remove_pm_domains() are simple and easy to read.
Quoted 134 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +96
-5+ + r5_core->num_pm_dev = num_pm_dev; + +/* for zynqmp we only add TCM power domains and not core's power domain */ +for (i =1 ; i < r5_core->num_pm_dev; i++) { + r5_core->pm_dev1[i] =dev_pm_domain_attach_by_id (dev, i); +if (IS_ERR (r5_core->pm_dev1[i])) { +dev_dbg (dev,"failed to attach pm domain %d\n" , i); +return PTR_ERR (r5_core->pm_dev1[i]); + } +if (!r5_core->pm_dev1[i]) { +dev_dbg (dev,"can't attach to pm domain %d\n" , i); +return -EINVAL ; + } + + r5_core->pm_dev_link1[i] =device_link_add (dev, r5_core->pm_dev1[i], +DL_FLAG_STATELESS | +DL_FLAG_RPM_ACTIVE | +DL_FLAG_PM_RUNTIME ); +if (!r5_core->pm_dev_link1[i]) { +dev_pm_domain_detach (r5_core->pm_dev1[i], true); + r5_core->pm_dev1[i] =NULL ; +return -EINVAL ; + } + } + +if (cluster->mode ==SPLIT_MODE ) +return 0 ; + + r5_core->pm_dev2 =kcalloc (num_pm_dev, +sizeof (struct device *), +GFP_KERNEL ); +if (!r5_core->pm_dev2) +return -ENOMEM ; + + r5_core->pm_dev_link2 =kcalloc (num_pm_dev, +sizeof (struct device_link *), +GFP_KERNEL ); +if (!r5_core->pm_dev_link2) +return -ENOMEM ; + +/* get second core's device to detach its power-domains */ + np =of_get_next_child (cluster->dev->of_node,of_node_get (dev->of_node)); + + pdev =of_find_device_by_node (np); +if (!pdev) { +dev_err (cluster->dev,"core1 platform device not available\n" ); +return -EINVAL ; + } + + dev2 = &pdev->dev; + +/* for zynqmp we only add TCM power domains and not core's power domain */ +for (i =1 ; i < r5_core->num_pm_dev; i++) { + r5_core->pm_dev2[i] =dev_pm_domain_attach_by_id (dev2, i); +if (IS_ERR (r5_core->pm_dev2[i])) { +dev_dbg (dev,"can't attach to pm domain %d\n" , i); +return PTR_ERR (r5_core->pm_dev2[i]); + } +if (!r5_core->pm_dev2[i]) { +dev_dbg (dev,"can't attach to pm domain %d\n" , i); +return -EINVAL ; + } + + r5_core->pm_dev_link2[i] =device_link_add (dev, r5_core->pm_dev2[i], +DL_FLAG_STATELESS | +DL_FLAG_RPM_ACTIVE | +DL_FLAG_PM_RUNTIME ); +if (!r5_core->pm_dev_link2[i]) { +dev_pm_domain_detach (r5_core->pm_dev2[i], true); + r5_core->pm_dev2[i] =NULL ; +return -ENODEV ; + } + } + +return 0 ; +} +/** * zynqmp_r5_rproc_prepare() * adds carveouts for TCM bank and reserved memory regions @@ -770,19 +943,30 @@ static int zynqmp_r5_rproc_prepare(struct rproc *rproc) {int ret; + ret =zynqmp_r5_add_pm_domains (rproc); +if (ret) { +dev_err (&rproc->dev,"failed to add pm domains\n" ); + goto fail_prepare; + } + ret =add_tcm_banks (rproc);if (ret) {dev_err (&rproc->dev,"failed to get TCM banks, err %d\n" , ret); -return ret; + goto fail_prepare; } ret =add_mem_regions_carveout (rproc);if (ret) {dev_err (&rproc->dev,"failed to get reserve mem regions %d\n" , ret); -return ret; + goto fail_prepare; }return 0 ; + +fail_prepare: +zynqmp_r5_remove_pm_domains (rproc); + +return ret; }/** @@ -801,11 +985,13 @@ static int zynqmp_r5_rproc_unprepare(struct rproc *rproc) r5_core = rproc->priv; +zynqmp_r5_remove_pm_domains (rproc); +for (i =0 ; i < r5_core->tcm_bank_count; i++) { pm_domain_id = r5_core->tcm_banks[i]->pm_domain_id; -if (zynqmp_pm_release_node (pm_domain_id)) -dev_warn (r5_core->dev, -"can't turn off TCM bank 0x%x" , pm_domain_id); +if (pm_domain_id &&zynqmp_pm_release_node (pm_domain_id)) +dev_dbg (r5_core->dev, +"can't turn off TCM bank 0x%x" , pm_domain_id); }return 0 ;Signature · 1 line
2.25.1
Re: [PATCH v5 3/4] remoteproc: zynqmp: add pm domains support
Hello Mathiew,
Thanks for reviews.
Quoted 97 lines · Mathieu Poirier
Quoted 96 lines · Tanmay Shah
Use TCM pm domains extracted from device-tree to power on/off TCM using general pm domain framework
Signed-off-by Tanmay Shah <[email protected]>--- drivers/remoteproc/xlnx_r5_remoteproc.c | 224 ++++++++++++++++++++++-- 1 file changed, 205 insertions(+), 19 deletions(-)drivers/remoteproc/xlnx_r5_remoteproc.c +37
-13@@ -16,6 +16,7 @@#include <linux/of_reserved_mem.h> #include <linux/platform_device.h> #include <linux/remoteproc.h> +#include <linux/pm_domain.h> #include "remoteproc_internal.h" @@ -102,6 +103,12 @@ static const struct mem_bank_data zynqmp_tcm_banks_lockstep[] = {* @rproc: rproc handle * @pm_domain_id: RPU CPU power domain id * @ipi: pointer to mailbox information +* @num_pm_dev: number of tcm pm domain devices for this core +* @pm_dev1: pm domain virtual devices for power domain framework +* @pm_dev_link1: pm domain device links after registration +* @pm_dev2: used only in lockstep mode. second core's pm domain virtual devices +* @pm_dev_link2: used only in lockstep mode. second core's pm device links after +* registration */ struct zynqmp_r5_core {struct device *dev;@@ -111,6 +118,11 @@ struct zynqmp_r5_core {struct rproc *rproc;u32 pm_domain_id;struct mbox_info *ipi; +int num_pm_dev; +struct device **pm_dev1; +struct device_link **pm_dev_link1; +struct device **pm_dev2; +struct device_link **pm_dev_link2; };/** @@ -575,12 +587,21 @@ static int add_tcm_carveout_split_mode(struct rproc *rproc) bank_size = r5_core->tcm_banks[i]->size; pm_domain_id = r5_core->tcm_banks[i]->pm_domain_id; - ret =zynqmp_pm_request_node (pm_domain_id, -ZYNQMP_PM_CAPABILITY_ACCESS ,0 , -ZYNQMP_PM_REQUEST_ACK_BLOCKING ); -if (ret <0 ) { -dev_err (dev,"failed to turn on TCM 0x%x" , pm_domain_id); - goto release_tcm_split; +/* +* If TCM information is available in device-tree then +* in that case, pm domain framework will power on/off TCM. +* In that case pm_domain_id is set to 0. If hardcode +* bindings from driver is used, then only this driver will +* use pm_domain_id. +*/ +if (pm_domain_id) { + ret =zynqmp_pm_request_node (pm_domain_id, +ZYNQMP_PM_CAPABILITY_ACCESS ,0 , +ZYNQMP_PM_REQUEST_ACK_BLOCKING ); +if (ret <0 ) { +dev_err (dev,"failed to turn on TCM 0x%x" , pm_domain_id); + goto release_tcm_split; + } } dev_dbg(dev, "TCM carveout split mode %s addr=%llx, da=0x%x, size=0x%lx",@@ -646,13 +667,16 @@ static int add_tcm_carveout_lockstep_mode(struct rproc *rproc)for (i =0 ; i < num_banks; i++) { pm_domain_id = r5_core->tcm_banks[i]->pm_domain_id; -/* Turn on each TCM bank individually */ - ret =zynqmp_pm_request_node (pm_domain_id, -ZYNQMP_PM_CAPABILITY_ACCESS ,0 , -ZYNQMP_PM_REQUEST_ACK_BLOCKING ); -if (ret <0 ) { -dev_err (dev,"failed to turn on TCM 0x%x" , pm_domain_id); - goto release_tcm_lockstep; +if (pm_domain_id) { +/* Turn on each TCM bank individually */ + ret =zynqmp_pm_request_node (pm_domain_id, +ZYNQMP_PM_CAPABILITY_ACCESS ,0 , +ZYNQMP_PM_REQUEST_ACK_BLOCKING ); +if (ret <0 ) { +dev_err (dev,"failed to turn on TCM 0x%x" , + pm_domain_id); + goto release_tcm_lockstep; + } }
Quoted 12 lines
drivers/remoteproc/xlnx_r5_remoteproc.c static int add_tcm_carveout_lockstep_mode(struct rproc *rproc) · line 717
Quoted 10 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +3
-1bank_size = r5_core->tcm_banks[i]->size;@@ -687,8 +711,10 @@ static int add_tcm_carveout_lockstep_mode(struct rproc *rproc)/* If failed, Turn off all TCM banks turned on before */ for (i--; i >=0 ; i--) { pm_domain_id = r5_core->tcm_banks[i]->pm_domain_id; -zynqmp_pm_release_node (pm_domain_id); +if (pm_domain_id) +zynqmp_pm_release_node (pm_domain_id); } +Spurious change
Ack, will remove it.
Quoted 21 lines
Quoted 21 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +13
-0return ret; }@@ -758,6 +784,153 @@ static int zynqmp_r5_parse_fw(struct rproc *rproc, const struct firmware *fw)return ret; } +static void zynqmp_r5_remove_pm_domains (struct rproc *rproc) +{ +struct zynqmp_r5_core *r5_core = rproc->priv; +struct device *dev = r5_core->dev; +struct zynqmp_r5_cluster *cluster; +int i; + + cluster =platform_get_drvdata (to_platform_device (dev->parent)); + +for (i =0 ; i < r5_core->num_pm_dev; i++) { +if (r5_core->pm_dev_link1 && r5_core->pm_dev_link1[i]) +device_link_del (r5_core->pm_dev_link1[i]); +if (r5_core->pm_dev1 && !IS_ERR_OR_NULL (r5_core->pm_dev1[i]))
Quoted 8 lines
drivers/remoteproc/xlnx_r5_remoteproc.c static int zynqmp_r5_parse_fw(struct rproc *rproc, const struct firmware *fw) · line 802
Quoted 3 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +3
-0+dev_pm_domain_detach (r5_core->pm_dev1[i], false); + } +A global function such as this one should not have to deal with error conditions. Those should be dealt with in the allocation function where cleanup is done on error conditions. See my comment below in
zynqmp_r5_add_pm_domains().
Ack, I won't use IS_ERR_OR_NULL here. Instead will make sure that if this function is called,
all the pm domains are acquired successfully.
Quoted 26 lines
Quoted 26 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +26
-0+kfree (r5_core->pm_dev1); + r5_core->pm_dev1 =NULL ; +kfree (r5_core->pm_dev_link1); + r5_core->pm_dev_link1 =NULL ; + +if (cluster->mode ==SPLIT_MODE ) { + r5_core->num_pm_dev =0 ; +return ; + } + +for (i =0 ; i < r5_core->num_pm_dev; i++) { +if (r5_core->pm_dev_link2 && r5_core->pm_dev_link2[i]) +device_link_del (r5_core->pm_dev_link2[i]); +if (r5_core->pm_dev2 && !IS_ERR_OR_NULL (r5_core->pm_dev2[i])) +dev_pm_domain_detach (r5_core->pm_dev2[i], false); + } + +kfree (r5_core->pm_dev2); + r5_core->pm_dev2 =NULL ; +kfree (r5_core->pm_dev_link2); + r5_core->pm_dev_link2 =NULL ; + r5_core->num_pm_dev =0 ; +} + +static int zynqmp_r5_add_pm_domains (struct rproc *rproc) +{
Quoted 8 lines
drivers/remoteproc/xlnx_r5_remoteproc.c static int zynqmp_r5_parse_fw(struct rproc *rproc, const struct firmware *fw) · line 834
Quoted 6 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +6
-0+struct zynqmp_r5_core *r5_core = rproc->priv; +struct device *dev = r5_core->dev, *dev2; +struct zynqmp_r5_cluster *cluster; +struct platform_device *pdev; +struct device_node *np; +int i, num_pm_dev, ret;I'm not sure 'ret' is needed - see below.
You are right. It's not needed. will fix it.
Quoted 6 lines
drivers/remoteproc/xlnx_r5_remoteproc.c static int zynqmp_r5_parse_fw(struct rproc *rproc, const struct firmware *fw) · line 836
Quoted 3 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +2
-0+ + cluster =platform_get_drvdata (to_platform_device (dev->parent));Why not use
dev_get_drvdata()as it is done elsewhere in this driver?
Quoted 15 lines
drivers/remoteproc/xlnx_r5_remoteproc.c static int zynqmp_r5_parse_fw(struct rproc *rproc, const struct firmware *fw) · line 849
Quoted 13 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +13
-0+ +/* get number of power-domains */ + num_pm_dev =of_count_phandle_with_args (r5_core->np,"power-domains" , +"#power-domain-cells" ); + +if (num_pm_dev <=0 ) +return -EINVAL ; + + r5_core->pm_dev1 =kcalloc (num_pm_dev, +sizeof (struct device *), +GFP_KERNEL ); +if (!r5_core->pm_dev1) + ret = -ENOMEM ;What's the goal of the assignment? Did you mean to return an error instead?
Ack, it should have been return. I implemented multiple ways to return errors, and missed to fix this before sending the patch.
Quoted 11 lines
drivers/remoteproc/xlnx_r5_remoteproc.c static int zynqmp_r5_parse_fw(struct rproc *rproc, const struct firmware *fw) · line 855
Quoted 7 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +6
-0+ + r5_core->pm_dev_link1 =kcalloc (num_pm_dev, +sizeof (struct device_link *), +GFP_KERNEL ); +if (!r5_core->pm_dev_link1) +return -ENOMEM ;In case of error, always cleanup the work done in the current function. That way cleanup functions such as
zynqmp_r5_remove_pm_domains()are simple and easy to read.
Ack. I will make sure that if we fail here for any reason, all the memory allocated is freed
here. Also any acquired devices and pm domains should be detached and released in this function
only upon failure in between.
Thanks,
Tanmay
Quoted 135 lines
Quoted 135 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +96
-5+ + r5_core->num_pm_dev = num_pm_dev; + +/* for zynqmp we only add TCM power domains and not core's power domain */ +for (i =1 ; i < r5_core->num_pm_dev; i++) { + r5_core->pm_dev1[i] =dev_pm_domain_attach_by_id (dev, i); +if (IS_ERR (r5_core->pm_dev1[i])) { +dev_dbg (dev,"failed to attach pm domain %d\n" , i); +return PTR_ERR (r5_core->pm_dev1[i]); + } +if (!r5_core->pm_dev1[i]) { +dev_dbg (dev,"can't attach to pm domain %d\n" , i); +return -EINVAL ; + } + + r5_core->pm_dev_link1[i] =device_link_add (dev, r5_core->pm_dev1[i], +DL_FLAG_STATELESS | +DL_FLAG_RPM_ACTIVE | +DL_FLAG_PM_RUNTIME ); +if (!r5_core->pm_dev_link1[i]) { +dev_pm_domain_detach (r5_core->pm_dev1[i], true); + r5_core->pm_dev1[i] =NULL ; +return -EINVAL ; + } + } + +if (cluster->mode ==SPLIT_MODE ) +return 0 ; + + r5_core->pm_dev2 =kcalloc (num_pm_dev, +sizeof (struct device *), +GFP_KERNEL ); +if (!r5_core->pm_dev2) +return -ENOMEM ; + + r5_core->pm_dev_link2 =kcalloc (num_pm_dev, +sizeof (struct device_link *), +GFP_KERNEL ); +if (!r5_core->pm_dev_link2) +return -ENOMEM ; + +/* get second core's device to detach its power-domains */ + np =of_get_next_child (cluster->dev->of_node,of_node_get (dev->of_node)); + + pdev =of_find_device_by_node (np); +if (!pdev) { +dev_err (cluster->dev,"core1 platform device not available\n" ); +return -EINVAL ; + } + + dev2 = &pdev->dev; + +/* for zynqmp we only add TCM power domains and not core's power domain */ +for (i =1 ; i < r5_core->num_pm_dev; i++) { + r5_core->pm_dev2[i] =dev_pm_domain_attach_by_id (dev2, i); +if (IS_ERR (r5_core->pm_dev2[i])) { +dev_dbg (dev,"can't attach to pm domain %d\n" , i); +return PTR_ERR (r5_core->pm_dev2[i]); + } +if (!r5_core->pm_dev2[i]) { +dev_dbg (dev,"can't attach to pm domain %d\n" , i); +return -EINVAL ; + } + + r5_core->pm_dev_link2[i] =device_link_add (dev, r5_core->pm_dev2[i], +DL_FLAG_STATELESS | +DL_FLAG_RPM_ACTIVE | +DL_FLAG_PM_RUNTIME ); +if (!r5_core->pm_dev_link2[i]) { +dev_pm_domain_detach (r5_core->pm_dev2[i], true); + r5_core->pm_dev2[i] =NULL ; +return -ENODEV ; + } + } + +return 0 ; +} +/** * zynqmp_r5_rproc_prepare() * adds carveouts for TCM bank and reserved memory regions @@ -770,19 +943,30 @@ static int zynqmp_r5_rproc_prepare(struct rproc *rproc) {int ret; + ret =zynqmp_r5_add_pm_domains (rproc); +if (ret) { +dev_err (&rproc->dev,"failed to add pm domains\n" ); + goto fail_prepare; + } + ret =add_tcm_banks (rproc);if (ret) {dev_err (&rproc->dev,"failed to get TCM banks, err %d\n" , ret); -return ret; + goto fail_prepare; } ret =add_mem_regions_carveout (rproc);if (ret) {dev_err (&rproc->dev,"failed to get reserve mem regions %d\n" , ret); -return ret; + goto fail_prepare; }return 0 ; + +fail_prepare: +zynqmp_r5_remove_pm_domains (rproc); + +return ret; }/** @@ -801,11 +985,13 @@ static int zynqmp_r5_rproc_unprepare(struct rproc *rproc) r5_core = rproc->priv; +zynqmp_r5_remove_pm_domains (rproc); +for (i =0 ; i < r5_core->tcm_bank_count; i++) { pm_domain_id = r5_core->tcm_banks[i]->pm_domain_id; -if (zynqmp_pm_release_node (pm_domain_id)) -dev_warn (r5_core->dev, -"can't turn off TCM bank 0x%x" , pm_domain_id); +if (pm_domain_id &&zynqmp_pm_release_node (pm_domain_id)) +dev_dbg (r5_core->dev, +"can't turn off TCM bank 0x%x" , pm_domain_id); }return 0 ;Signature · 1 line
2.25.1
PATCH v5 4/4 remoteproc: zynqmp: parse TCM from device tree
In reply to Tanmay ShahZynqMP TCM information is fixed in driver. Now ZynqMP TCM information is available in device-tree. Parse TCM information in driver as per new bindings
--- drivers/remoteproc/xlnx_r5_remoteproc.c | 122 ++++++++++++++++++++++-- 1 file changed, 114 insertions(+), 8 deletions(-)
drivers/remoteproc/xlnx_r5_remoteproc.c +114 -8
@@ -75,8 +75,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 */
@@ -613,7 +613,8 @@ static int add_tcm_carveout_split_mode(struct rproc *rproc) bank_name);if (!rproc_mem) { ret = -ENOMEM ; -zynqmp_pm_release_node (pm_domain_id); +if (pm_domain_id) +zynqmp_pm_release_node (pm_domain_id); goto release_tcm_split; }
@@ -626,7 +627,8 @@ static int add_tcm_carveout_split_mode(struct rproc *rproc)/* If failed, Turn off all TCM banks turned on before */ for (i--; i >=0 ; i--) { pm_domain_id = r5_core->tcm_banks[i]->pm_domain_id; -zynqmp_pm_release_node (pm_domain_id); +if (pm_domain_id) +zynqmp_pm_release_node (pm_domain_id); }return ret; }
@@ -1064,6 +1066,107 @@ 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) +{ +int i, j, tcm_bank_count, ret = -EINVAL ; +struct zynqmp_r5_core *r5_core; +struct platform_device *cpdev; +struct resource *res =NULL ; +u64 abs_addr =0 , size =0 ; +struct mem_bank_data *tcm; +struct device_node *np; +struct device *dev; + +for (i =0 ; i < cluster->core_count; i++) { + r5_core = cluster->r5_cores[i]; + dev = r5_core->dev; + np =dev_of_node (dev); + +/* we have address cell 2 and size cell as 2 */ + ret =of_property_count_elems_of_size (np,"reg" , +4 *sizeof (u32)); +if (ret ==0 ) { + ret = -EINVAL ; + goto fail_tcm; + } +if (ret <0 ) + goto fail_tcm; + + tcm_bank_count = ret; + + r5_core->tcm_banks =devm_kcalloc (dev, tcm_bank_count, +sizeof (struct mem_bank_data *), +GFP_KERNEL ); +if (!r5_core->tcm_banks) { + ret = -ENOMEM ; + goto fail_tcm; + } + + 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) { + ret = -ENOMEM ; + goto fail_tcm; + } + + r5_core->tcm_banks[j] = tcm; + +/* get tcm address without translation */ + ret =of_property_read_reg (np, j, &abs_addr, &size); +if (ret) { +dev_err (dev,"failed to get reg property\n" ); + goto fail_tcm; + } + +/* +* 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) { +dev_err (dev,"failed to get tcm resource\n" ); + ret = -EINVAL ; + goto fail_tcm; + } + + 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" ); + ret = -EINVAL ; + goto fail_tcm; + } + } + } + +return 0 ; + +fail_tcm: +while (i >=0 ) { + r5_core = cluster->r5_cores[i]; +for (j =0 ; j < r5_core->tcm_bank_count; j++) { +if (!r5_core->tcm_banks || !r5_core->tcm_banks[j]) +continue ; + tcm = r5_core->tcm_banks[j]; +devm_kfree (r5_core->dev, tcm); + } +devm_kfree (r5_core->dev, r5_core->tcm_banks); + r5_core->tcm_banks =NULL ; + i--; + } + +return ret; +} +/** * zynqmp_r5_get_tcm_node() * Ideally this function should parse tcm node and store information
@@ -1142,10 +1245,13 @@ 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; + ret =zynqmp_r5_get_tcm_node_from_dt (cluster); +if (ret) { + 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
Mathieu Poirier
maintainerRe: [PATCH v5 4/4] remoteproc: zynqmp: parse TCM from device tree
Quoted 3 lines · 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
Missing '.' at the end of the sentence.
Quoted 45 lines
Signed-off-by Tanmay Shah <[email protected]>--- drivers/remoteproc/xlnx_r5_remoteproc.c | 122 ++++++++++++++++++++++-- 1 file changed, 114 insertions(+), 8 deletions(-)drivers/remoteproc/xlnx_r5_remoteproc.c +6
-4@@ -75,8 +75,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 */ @@ -613,7 +613,8 @@ static int add_tcm_carveout_split_mode(struct rproc *rproc) bank_name);if (!rproc_mem) { ret = -ENOMEM ; -zynqmp_pm_release_node (pm_domain_id); +if (pm_domain_id) +zynqmp_pm_release_node (pm_domain_id); goto release_tcm_split; }@@ -626,7 +627,8 @@ static int add_tcm_carveout_split_mode(struct rproc *rproc)/* If failed, Turn off all TCM banks turned on before */ for (i--; i >=0 ; i--) { pm_domain_id = r5_core->tcm_banks[i]->pm_domain_id; -zynqmp_pm_release_node (pm_domain_id); +if (pm_domain_id) +zynqmp_pm_release_node (pm_domain_id); }return ret; }@@ -1064,6 +1066,107 @@ static struct zynqmp_r5_core *zynqmp_r5_add_rproc_core(struct device *cdev)return ERR_PTR (ret); }
drivers/remoteproc/xlnx_r5_remoteproc.c static struct zynqmp_r5_core *zynqmp_r5_add_rproc_core(struct device *cdev) · line 1078
Quoted 10 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +9
-0+static int zynqmp_r5_get_tcm_node_from_dt (struct zynqmp_r5_cluster *cluster) +{ +int i, j, tcm_bank_count, ret = -EINVAL ; +struct platform_device *cpdev; +struct resource *res =NULL ; +u64 abs_addr =0 , size =0 ; +struct mem_bank_data *tcm; +struct device_node *np; +struct device *dev;
As far as I can tell, none of the above initialization is needed. I have commented on that before.
Quoted 5 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +5
-0+ +for (i =0 ; i < cluster->core_count; i++) { + r5_core = cluster->r5_cores[i]; + dev = r5_core->dev; + np =dev_of_node (dev);
drivers/remoteproc/xlnx_r5_remoteproc.c static struct zynqmp_r5_core *zynqmp_r5_add_rproc_core(struct device *cdev) · line 1093
Quoted 10 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +10
-0+ +/* we have address cell 2 and size cell as 2 */ + ret =of_property_count_elems_of_size (np,"reg" , +4 *sizeof (u32)); +if (ret ==0 ) { + ret = -EINVAL ; + goto fail_tcm; + } +if (ret <0 ) + goto fail_tcm;
if (ret <= 0) {
ret = -EINVAL;
goto fail_tcm;
}Quoted 62 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +62
-0+ + tcm_bank_count = ret; + + r5_core->tcm_banks =devm_kcalloc (dev, tcm_bank_count, +sizeof (struct mem_bank_data *), +GFP_KERNEL ); +if (!r5_core->tcm_banks) { + ret = -ENOMEM ; + goto fail_tcm; + } + + 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) { + ret = -ENOMEM ; + goto fail_tcm; + } + + r5_core->tcm_banks[j] = tcm; + +/* get tcm address without translation */ + ret =of_property_read_reg (np, j, &abs_addr, &size); +if (ret) { +dev_err (dev,"failed to get reg property\n" ); + goto fail_tcm; + } + +/* +* 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) { +dev_err (dev,"failed to get tcm resource\n" ); + ret = -EINVAL ; + goto fail_tcm; + } + + 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" ); + ret = -EINVAL ; + goto fail_tcm; + } + } + } + +return 0 ; + +fail_tcm: +while (i >=0 ) { + r5_core = cluster->r5_cores[i];
drivers/remoteproc/xlnx_r5_remoteproc.c static struct zynqmp_r5_core *zynqmp_r5_add_rproc_core(struct device *cdev) · line 1165
Quoted 10 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +10
-0+for (j =0 ; j < r5_core->tcm_bank_count; j++) { +if (!r5_core->tcm_banks || !r5_core->tcm_banks[j]) +continue ; + tcm = r5_core->tcm_banks[j]; +devm_kfree (r5_core->dev, tcm); + } +devm_kfree (r5_core->dev, r5_core->tcm_banks); + r5_core->tcm_banks =NULL ; + i--; + }
Given the devm_xyz() API used in this function, is the above needed?
Thanks,
Mathieu
Quoted 28 lines
drivers/remoteproc/xlnx_r5_remoteproc.c +11
-4+ +return ret; +} +/** * zynqmp_r5_get_tcm_node() * Ideally this function should parse tcm node and store information @@ -1142,10 +1245,13 @@ 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; + ret =zynqmp_r5_get_tcm_node_from_dt (cluster); +if (ret) { + 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