Skip to contentSkip to conversation

Tegra GCPDMA: Add dma-channel-mask support

PATCH Superseded Akhil R 2 participants 13 messages Sep 19, 2022 – Sep 23, 2022

Subsystems (4)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Akhil R

author
#0 lore raw

v2 cover Tegra GCPDMA: Add dma-channel-mask support

Read dma-channel-mask from device tree and register only the specified channels. This is useful to reserve some channels for the firmware.

Also update the channel number and interrupts to include all 32 channels. The current driver was using only 31 channels as one channel was reserved for firmware. Now with this change, the driver can align more to the actual hardware.

v1->v2:
* Reversed the operands and used BIT macro in 'if' condition.
* Fixed warning reported-by: kernel test robot <[email protected]>

Akhil R (3):
dt-bindings: dmaengine: Add dma-channel-mask to Tegra GPCDMA
arm64: tegra: Add dma-channel-mask in GPCDMA node
dmaengine: tegra: Add support for dma-channel-mask

 .../bindings/dma/nvidia,tegra186-gpc-dma.yaml |  7 +++-
 arch/arm64/boot/dts/nvidia/tegra186.dtsi      |  4 +-
 arch/arm64/boot/dts/nvidia/tegra194.dtsi      |  4 +-
 arch/arm64/boot/dts/nvidia/tegra234.dtsi      |  4 +-
 drivers/dma/tegra186-gpc-dma.c                | 37 +++++++++++++++----
 5 files changed, 45 insertions(+), 11 deletions(-)
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH v2 1/3 dt-bindings: dmaengine: Add dma-channel-mask to Tegra GPCDMA

Add dma-channel-mask property in Tegra GPCDMA document.

The property would help to specify the channels to be used in kernel and reserve few for the firmware. This was previously achieved by limiting the channel number to 31 in the driver. Now since we can list all 32 channels, update the interrupts property as well to list all 32 interrupts.

---
 .../devicetree/bindings/dma/nvidia,tegra186-gpc-dma.yaml   | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/dma/nvidia,tegra186-gpc-dma.yaml +6 -1
index 7e575296df0c..31724cda074e 100644
@@ -39,7 +39,7 @@ properties:
       Should contain all of the per-channel DMA interrupts in
       ascending order with respect to the DMA channel index.
     minItems: 1
-    maxItems: 31
+    maxItems: 32
 
   resets:
     maxItems: 1
@@ -52,6 +52,9 @@ properties:
 
   dma-coherent: true
 
+  dma-channel-mask:
+    maxItems: 1
+
 required:
   - compatible
   - reg
@@ -60,6 +63,7 @@ required:
   - reset-names
   - "#dma-cells"
   - iommus
+  - dma-channel-mask
 
 additionalProperties: false
 
@@ -108,5 +112,6 @@ examples:
         #dma-cells = <1>;
         iommus = <&smmu TEGRA186_SID_GPCDMA_0>;
         dma-coherent;
+        dma-channel-mask = <0xfffffffe>;
     };
 ...
Signature · 1 line
2.17.1
maintainer Reviewed-by on v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] dt-bindings: dmaengine: Add dma-channel-mask to Tegra GPCDMA

Quoted 45 lines · Akhil R

Add dma-channel-mask property in Tegra GPCDMA document.

The property would help to specify the channels to be used in kernel and reserve few for the firmware. This was previously achieved by limiting the channel number to 31 in the driver. Now since we can list all 32 channels, update the interrupts property as well to list all 32 interrupts.

---
  .../devicetree/bindings/dma/nvidia,tegra186-gpc-dma.yaml   | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/dma/nvidia,tegra186-gpc-dma.yaml +5 -1
index 7e575296df0c..31724cda074e 100644
@@ -39,7 +39,7 @@ properties:
        Should contain all of the per-channel DMA interrupts in
        ascending order with respect to the DMA channel index.
      minItems: 1
-    maxItems: 31
+    maxItems: 32
 
    resets:
      maxItems: 1
@@ -52,6 +52,9 @@ properties:
 
    dma-coherent: true
 
+  dma-channel-mask:
+    maxItems: 1
+
  required:
    - compatible
    - reg
@@ -60,6 +63,7 @@ required:
    - reset-names
    - "#dma-cells"
    - iommus
+  - dma-channel-mask
 
  additionalProperties: false
 

Documentation/devicetree/bindings/dma/nvidia,tegra186-gpc-dma.yaml examples: · line 116

Quoted 6 lines
Documentation/devicetree/bindings/dma/nvidia,tegra186-gpc-dma.yaml +1 -0
@@ -108,5 +112,6 @@ examples:
          #dma-cells = <1>;
          iommus = <&smmu TEGRA186_SID_GPCDMA_0>;
          dma-coherent;
+        dma-channel-mask = <0xfffffffe>;
      };
...

Thanks!
Jon

Signature · 1 line
nvpublic
author
#3 lore raw

PATCH v2 2/3 arm64: tegra: Add dma-channel-mask in GPCDMA node

In reply to Akhil R

Add dma-channel-mask property in Tegra GPCDMA device tree node.

The property would help to specify the channels to be used in kernel and reserve few for the firmware. This was previously achieved by limiting the channel number to 31 in the driver. Now since we can list all 32 channels, update the interrupts property as well to list all 32 interrupts.

---
 arch/arm64/boot/dts/nvidia/tegra186.dtsi | 4 +++-
 arch/arm64/boot/dts/nvidia/tegra194.dtsi | 4 +++-
 arch/arm64/boot/dts/nvidia/tegra234.dtsi | 4 +++-
 3 files changed, 9 insertions(+), 3 deletions(-)
arch/arm64/boot/dts/nvidia/tegra186.dtsi +3 -1
index 3580fbf99091..13a84e34e094 100644
@@ -78,7 +78,8 @@
 		reg = <0x0 0x2600000 0x0 0x210000>;
 		resets = <&bpmp TEGRA186_RESET_GPCDMA>;
 		reset-names = "gpcdma";
-		interrupts = <GIC_SPI 76 IRQ_TYPE_LEVEL_HIGH>,
+		interrupts = <GIC_SPI 75 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 76 IRQ_TYPE_LEVEL_HIGH>,
 			     <GIC_SPI 77 IRQ_TYPE_LEVEL_HIGH>,
 			     <GIC_SPI 78 IRQ_TYPE_LEVEL_HIGH>,
 			     <GIC_SPI 79 IRQ_TYPE_LEVEL_HIGH>,
@@ -112,6 +113,7 @@
 		#dma-cells = <1>;
 		iommus = <&smmu TEGRA186_SID_GPCDMA_0>;
 		dma-coherent;
+		dma-channel-mask = <0xfffffffe>;
 		status = "okay";
 	};
 
arch/arm64/boot/dts/nvidia/tegra194.dtsi +3 -1
index 9176c4b27133..593fbf22b34f 100644
@@ -142,7 +142,8 @@
 			reg = <0x2600000 0x210000>;
 			resets = <&bpmp TEGRA194_RESET_GPCDMA>;
 			reset-names = "gpcdma";
-			interrupts = <GIC_SPI 76 IRQ_TYPE_LEVEL_HIGH>,
+			interrupts = <GIC_SPI 75 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 76 IRQ_TYPE_LEVEL_HIGH>,
 				     <GIC_SPI 77 IRQ_TYPE_LEVEL_HIGH>,
 				     <GIC_SPI 78 IRQ_TYPE_LEVEL_HIGH>,
 				     <GIC_SPI 79 IRQ_TYPE_LEVEL_HIGH>,
@@ -176,6 +177,7 @@
 			#dma-cells = <1>;
 			iommus = <&smmu TEGRA194_SID_GPCDMA_0>;
 			dma-coherent;
+			dma-channel-mask = <0xfffffffe>;
 			status = "okay";
 		};
 
arch/arm64/boot/dts/nvidia/tegra234.dtsi +3 -1
index 5852e765ad90..afd90b72cdea 100644
@@ -28,7 +28,8 @@
 			reg = <0x2600000 0x210000>;
 			resets = <&bpmp TEGRA234_RESET_GPCDMA>;
 			reset-names = "gpcdma";
-			interrupts = <GIC_SPI 76 IRQ_TYPE_LEVEL_HIGH>,
+			interrupts = <GIC_SPI 75 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 76 IRQ_TYPE_LEVEL_HIGH>,
 				     <GIC_SPI 77 IRQ_TYPE_LEVEL_HIGH>,
 				     <GIC_SPI 78 IRQ_TYPE_LEVEL_HIGH>,
 				     <GIC_SPI 79 IRQ_TYPE_LEVEL_HIGH>,
@@ -61,6 +62,7 @@
 				     <GIC_SPI 106 IRQ_TYPE_LEVEL_HIGH>;
 			#dma-cells = <1>;
 			iommus = <&smmu_niso0 TEGRA234_SID_GPCDMA>;
+			dma-channel-mask = <0xfffffffe>;
 			dma-coherent;
 		};
 
Signature · 1 line
2.17.1
maintainer Reviewed-by on v2 2/3
#4 lore raw

Re: [PATCH v2 2/3] arm64: tegra: Add dma-channel-mask in GPCDMA node

Quoted 74 lines · Akhil R

Add dma-channel-mask property in Tegra GPCDMA device tree node.

The property would help to specify the channels to be used in kernel and reserve few for the firmware. This was previously achieved by limiting the channel number to 31 in the driver. Now since we can list all 32 channels, update the interrupts property as well to list all 32 interrupts.

---
  arch/arm64/boot/dts/nvidia/tegra186.dtsi | 4 +++-
  arch/arm64/boot/dts/nvidia/tegra194.dtsi | 4 +++-
  arch/arm64/boot/dts/nvidia/tegra234.dtsi | 4 +++-
  3 files changed, 9 insertions(+), 3 deletions(-)
arch/arm64/boot/dts/nvidia/tegra186.dtsi +3 -1
index 3580fbf99091..13a84e34e094 100644
@@ -78,7 +78,8 @@
  		reg = <0x0 0x2600000 0x0 0x210000>;
  		resets = <&bpmp TEGRA186_RESET_GPCDMA>;
  		reset-names = "gpcdma";
-		interrupts = <GIC_SPI 76 IRQ_TYPE_LEVEL_HIGH>,
+		interrupts = <GIC_SPI 75 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 76 IRQ_TYPE_LEVEL_HIGH>,
  			     <GIC_SPI 77 IRQ_TYPE_LEVEL_HIGH>,
  			     <GIC_SPI 78 IRQ_TYPE_LEVEL_HIGH>,
  			     <GIC_SPI 79 IRQ_TYPE_LEVEL_HIGH>,
@@ -112,6 +113,7 @@
  		#dma-cells = <1>;
  		iommus = <&smmu TEGRA186_SID_GPCDMA_0>;
  		dma-coherent;
+		dma-channel-mask = <0xfffffffe>;
  		status = "okay";
  	};
 
arch/arm64/boot/dts/nvidia/tegra194.dtsi +3 -1
index 9176c4b27133..593fbf22b34f 100644
@@ -142,7 +142,8 @@
  			reg = <0x2600000 0x210000>;
  			resets = <&bpmp TEGRA194_RESET_GPCDMA>;
  			reset-names = "gpcdma";
-			interrupts = <GIC_SPI 76 IRQ_TYPE_LEVEL_HIGH>,
+			interrupts = <GIC_SPI 75 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 76 IRQ_TYPE_LEVEL_HIGH>,
  				     <GIC_SPI 77 IRQ_TYPE_LEVEL_HIGH>,
  				     <GIC_SPI 78 IRQ_TYPE_LEVEL_HIGH>,
  				     <GIC_SPI 79 IRQ_TYPE_LEVEL_HIGH>,
@@ -176,6 +177,7 @@
  			#dma-cells = <1>;
  			iommus = <&smmu TEGRA194_SID_GPCDMA_0>;
  			dma-coherent;
+			dma-channel-mask = <0xfffffffe>;
  			status = "okay";
  		};
 
arch/arm64/boot/dts/nvidia/tegra234.dtsi +2 -1
index 5852e765ad90..afd90b72cdea 100644
@@ -28,7 +28,8 @@
  			reg = <0x2600000 0x210000>;
  			resets = <&bpmp TEGRA234_RESET_GPCDMA>;
  			reset-names = "gpcdma";
-			interrupts = <GIC_SPI 76 IRQ_TYPE_LEVEL_HIGH>,
+			interrupts = <GIC_SPI 75 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 76 IRQ_TYPE_LEVEL_HIGH>,
  				     <GIC_SPI 77 IRQ_TYPE_LEVEL_HIGH>,
  				     <GIC_SPI 78 IRQ_TYPE_LEVEL_HIGH>,
  				     <GIC_SPI 79 IRQ_TYPE_LEVEL_HIGH>,

arch/arm64/boot/dts/nvidia/tegra234.dtsi line 68

Quoted 7 lines
arch/arm64/boot/dts/nvidia/tegra234.dtsi +1 -0
@@ -61,6 +62,7 @@
  				     <GIC_SPI 106 IRQ_TYPE_LEVEL_HIGH>;
  			#dma-cells = <1>;
  			iommus = <&smmu_niso0 TEGRA234_SID_GPCDMA>;
+			dma-channel-mask = <0xfffffffe>;
  			dma-coherent;
  		};
 

Thanks!
Jon

Signature · 1 line
nvpublic
author
#5 lore raw

PATCH v2 3/3 dmaengine: tegra: Add support for dma-channel-mask

In reply to Akhil R

Add support for dma-channel-mask so that only the specified channels are used. This helps to reserve some channels for the firmware.

This was initially achieved by limiting the channel number to 31 in the driver and adjusting the register address to skip channel0 which was reserved for a firmware. Now, with this change, the driver can align more to the actual hardware which has 32 channels.

---
 drivers/dma/tegra186-gpc-dma.c | 37 +++++++++++++++++++++++++++-------
 1 file changed, 30 insertions(+), 7 deletions(-)
drivers/dma/tegra186-gpc-dma.c +30 -7
index fa9bda4a2bc6..1d1180db6d4e 100644
@@ -161,7 +161,10 @@
 #define TEGRA_GPCDMA_BURST_COMPLETION_TIMEOUT	5000 /* 5 msec */
 
 /* Channel base address offset from GPCDMA base address */
-#define TEGRA_GPCDMA_CHANNEL_BASE_ADD_OFFSET	0x20000
+#define TEGRA_GPCDMA_CHANNEL_BASE_ADDR_OFFSET	0x10000
+
+/* Default channel mask reserving channel0 */
+#define TEGRA_GPCDMA_DEFAULT_CHANNEL_MASK	0xfffffffe
 
 struct tegra_dma;
 struct tegra_dma_channel;
@@ -246,6 +249,7 @@ struct tegra_dma {
 	const struct tegra_dma_chip_data *chip_data;
 	unsigned long sid_m2d_reserved;
 	unsigned long sid_d2m_reserved;
+	u32 chan_mask;
 	void __iomem *base_addr;
 	struct device *dev;
 	struct dma_device dma_dev;
@@ -1288,7 +1292,7 @@ static struct dma_chan *tegra_dma_of_xlate(struct of_phandle_args *dma_spec,
 }
 
 static const struct tegra_dma_chip_data tegra186_dma_chip_data = {
-	.nr_channels = 31,
+	.nr_channels = 32,
 	.channel_reg_size = SZ_64K,
 	.max_dma_count = SZ_1G,
 	.hw_support_pause = false,
@@ -1296,7 +1300,7 @@ static const struct tegra_dma_chip_data tegra186_dma_chip_data = {
 };
 
 static const struct tegra_dma_chip_data tegra194_dma_chip_data = {
-	.nr_channels = 31,
+	.nr_channels = 32,
 	.channel_reg_size = SZ_64K,
 	.max_dma_count = SZ_1G,
 	.hw_support_pause = true,
@@ -1304,7 +1308,7 @@ static const struct tegra_dma_chip_data tegra194_dma_chip_data = {
 };
 
 static const struct tegra_dma_chip_data tegra234_dma_chip_data = {
-	.nr_channels = 31,
+	.nr_channels = 32,
 	.channel_reg_size = SZ_64K,
 	.max_dma_count = SZ_1G,
 	.hw_support_pause = true,
@@ -1380,15 +1384,28 @@ static int tegra_dma_probe(struct platform_device *pdev)
 	}
 	stream_id = iommu_spec->ids[0] & 0xffff;
 
+	ret = device_property_read_u32(&pdev->dev, "dma-channel-mask",
+				       &tdma->chan_mask);
+	if (ret) {
+		dev_warn(&pdev->dev,
+			 "Missing dma-channel-mask property, using default channel mask %#x\n",
+			 TEGRA_GPCDMA_DEFAULT_CHANNEL_MASK);
+		tdma->chan_mask = TEGRA_GPCDMA_DEFAULT_CHANNEL_MASK;
+	}
+
 	INIT_LIST_HEAD(&tdma->dma_dev.channels);
 	for (i = 0; i < cdata->nr_channels; i++) {
 		struct tegra_dma_channel *tdc = &tdma->channels[i];
 
+		/* Check for channel mask */
+		if (!(tdma->chan_mask & BIT(i)))
+			continue;
+
 		tdc->irq = platform_get_irq(pdev, i);
 		if (tdc->irq < 0)
 			return tdc->irq;
 
-		tdc->chan_base_offset = TEGRA_GPCDMA_CHANNEL_BASE_ADD_OFFSET +
+		tdc->chan_base_offset = TEGRA_GPCDMA_CHANNEL_BASE_ADDR_OFFSET +
 					i * cdata->channel_reg_size;
 		snprintf(tdc->name, sizeof(tdc->name), "gpcdma.%d", i);
 		tdc->tdma = tdma;
@@ -1449,8 +1466,8 @@ static int tegra_dma_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	dev_info(&pdev->dev, "GPC DMA driver register %d channels\n",
-		 cdata->nr_channels);
+	dev_info(&pdev->dev, "GPC DMA driver register %lu channels\n",
+		 hweight_long(tdma->chan_mask));
 
 	return 0;
 }
@@ -1473,6 +1490,9 @@ static int __maybe_unused tegra_dma_pm_suspend(struct device *dev)
 	for (i = 0; i < tdma->chip_data->nr_channels; i++) {
 		struct tegra_dma_channel *tdc = &tdma->channels[i];
 
+		if (!(tdma->chan_mask & BIT(i)))
+			continue;
+
 		if (tdc->dma_desc) {
 			dev_err(tdma->dev, "channel %u busy\n", i);
 			return -EBUSY;
@@ -1492,6 +1512,9 @@ static int __maybe_unused tegra_dma_pm_resume(struct device *dev)
 	for (i = 0; i < tdma->chip_data->nr_channels; i++) {
 		struct tegra_dma_channel *tdc = &tdma->channels[i];
 
+		if (!(tdma->chan_mask & BIT(i)))
+			continue;
+
 		tegra_dma_program_sid(tdc, tdc->stream_id);
 	}
 
Signature · 1 line
2.17.1
maintainer
#6 lore raw

Re: [PATCH v2 3/3] dmaengine: tegra: Add support for dma-channel-mask

Quoted 18 lines · Akhil R

Add support for dma-channel-mask so that only the specified channels are used. This helps to reserve some channels for the firmware.

This was initially achieved by limiting the channel number to 31 in the driver and adjusting the register address to skip channel0 which was reserved for a firmware. Now, with this change, the driver can align more to the actual hardware which has 32 channels.

---
  drivers/dma/tegra186-gpc-dma.c | 37 +++++++++++++++++++++++++++-------
  1 file changed, 30 insertions(+), 7 deletions(-)
drivers/dma/tegra186-gpc-dma.c +0 -0
index fa9bda4a2bc6..1d1180db6d4e 100644

drivers/dma/tegra186-gpc-dma.c line 164

Quoted 5 lines
drivers/dma/tegra186-gpc-dma.c +1 -1
@@ -161,7 +161,10 @@
  #define TEGRA_GPCDMA_BURST_COMPLETION_TIMEOUT	5000 /* 5 msec */
 
  /* Channel base address offset from GPCDMA base address */
-#define TEGRA_GPCDMA_CHANNEL_BASE_ADD_OFFSET	0x20000
+#define TEGRA_GPCDMA_CHANNEL_BASE_ADDR_OFFSET	0x10000

Why did this value change? There is no mention in the commit message. If this was incorrect before, then this needs to be a separate patch and tagged with the appropriate fixes tag so that this can be picked up for stable.

Thanks
Jon

Signature · 1 line
nvpublic
author
#7 lore raw

RE: [PATCH v2 3/3] dmaengine: tegra: Add support for dma-channel-mask

Quoted 23 lines · Akhil R

drivers/dma/tegra186-gpc-

Quoted 14 lines

Add support for dma-channel-mask so that only the specified channels are used. This helps to reserve some channels for the firmware.

This was initially achieved by limiting the channel number to 31 in the driver and adjusting the register address to skip channel0 which was reserved for a firmware. Now, with this change, the driver can align more to the actual hardware which has 32 channels.

---
  drivers/dma/tegra186-gpc-dma.c | 37 +++++++++++++++++++++++++++-------
  1 file changed, 30 insertions(+), 7 deletions(-)
drivers/dma/tegra186-gpc- renamed from drivers/dma/tegra186-gpc-dma.c +0 -0

dma.c

drivers/dma/tegra186-gpc-dma.c line 161

Quoted 5 lines

index fa9bda4a2bc6..1d1180db6d4e 100644

drivers/dma/tegra186-gpc-dma.c +0 -0
@@ -161,7 +161,10 @@
  #define TEGRA_GPCDMA_BURST_COMPLETION_TIMEOUT	5000 /* 5

msec */

Quoted 1 line
Quoted 8 lines

drivers/dma/tegra186-gpc-dma.c line 164

Quoted 3 lines

/* Channel base address offset from GPCDMA base address */

drivers/dma/tegra186-gpc-dma.c +1 -1
-#define TEGRA_GPCDMA_CHANNEL_BASE_ADD_OFFSET	0x20000
+#define TEGRA_GPCDMA_CHANNEL_BASE_ADDR_OFFSET	0x10000

Why did this value change? There is no mention in the commit message. If this was incorrect before, then this needs to be a separate patch and tagged with the appropriate fixes tag so that this can be picked up for stable.

This is mentioned in the commit message.

"... and adjusting the register address to skip channel0 ..."

Probably it is not very clear that it directs to this change. Shall I update the commit message to have a clearer context?

Regards,
Akhil

maintainer
#8 lore raw

Re: [PATCH v2 3/3] dmaengine: tegra: Add support for dma-channel-mask

Quoted 31 lines · Akhil R
Quoted 23 lines · Akhil R

drivers/dma/tegra186-gpc-

Quoted 14 lines

Add support for dma-channel-mask so that only the specified channels are used. This helps to reserve some channels for the firmware.

This was initially achieved by limiting the channel number to 31 in the driver and adjusting the register address to skip channel0 which was reserved for a firmware. Now, with this change, the driver can align more to the actual hardware which has 32 channels.

---
   drivers/dma/tegra186-gpc-dma.c | 37 +++++++++++++++++++++++++++-------
   1 file changed, 30 insertions(+), 7 deletions(-)
drivers/dma/tegra186-gpc- renamed from drivers/dma/tegra186-gpc-dma.c +0 -0

dma.c

drivers/dma/tegra186-gpc-dma.c line 161

Quoted 5 lines

index fa9bda4a2bc6..1d1180db6d4e 100644

drivers/dma/tegra186-gpc-dma.c +0 -0
@@ -161,7 +161,10 @@
   #define TEGRA_GPCDMA_BURST_COMPLETION_TIMEOUT	5000 /* 5

msec */

Quoted 1 line
Quoted 8 lines

drivers/dma/tegra186-gpc-dma.c line 164

Quoted 3 lines
   /* Channel base address offset from GPCDMA base address */
drivers/dma/tegra186-gpc-dma.c +1 -1
-#define TEGRA_GPCDMA_CHANNEL_BASE_ADD_OFFSET	0x20000
+#define TEGRA_GPCDMA_CHANNEL_BASE_ADDR_OFFSET	0x10000

Why did this value change? There is no mention in the commit message. If this was incorrect before, then this needs to be a separate patch and tagged with the appropriate fixes tag so that this can be picked up for stable.

Quoted 6 lines

This is mentioned in the commit message.

"... and adjusting the register address to skip channel0 ..."

Probably it is not very clear that it directs to this change. Shall I update the commit message to have a clearer context?

Ah OK. I was wondering how this worked with 'channel_reg_size' but looking closer I see channel_reg_size is always SZ_64K. I wonder why we even bother having this parameter and don't use SZ_64K directly?

Anyway, for now this is fine.

Jon

Signature · 1 line
nvpublic
author
#9 lore raw

RE: [PATCH v2 3/3] dmaengine: tegra: Add support for dma-channel-mask

Quoted 35 lines · Akhil R
Quoted 4 lines
Quoted 4 lines · Akhil R
Quoted 3 lines

Add support for dma-channel-mask so that only the specified channels are used. This helps to reserve some channels for the firmware.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

This was initially achieved by limiting the channel number to 31 in the driver and adjusting the register address to skip channel0 which was reserved for a firmware. Now, with this change, the driver can align more to the actual hardware which has 32 channels.

---
   drivers/dma/tegra186-gpc-dma.c | 37 +++++++++++++++++++++++++++---

----

Quoted 21 lines
Quoted 11 lines

drivers/dma/tegra186-gpc-

Quoted 3 lines
   1 file changed, 30 insertions(+), 7 deletions(-)
drivers/dma/tegra186-gpc- renamed from drivers/dma/tegra186-gpc-dma.c +0 -0

dma.c

drivers/dma/tegra186-gpc-dma.c line 161

Quoted 5 lines

index fa9bda4a2bc6..1d1180db6d4e 100644

drivers/dma/tegra186-gpc-dma.c +0 -0
@@ -161,7 +161,10 @@
   #define TEGRA_GPCDMA_BURST_COMPLETION_TIMEOUT	5000 /* 5

msec */

Quoted 1 line
Quoted 8 lines

drivers/dma/tegra186-gpc-dma.c line 164

Quoted 3 lines
   /* Channel base address offset from GPCDMA base address */
drivers/dma/tegra186-gpc-dma.c +1 -1
-#define TEGRA_GPCDMA_CHANNEL_BASE_ADD_OFFSET	0x20000
+#define TEGRA_GPCDMA_CHANNEL_BASE_ADDR_OFFSET	0x10000

Why did this value change? There is no mention in the commit message. If this was incorrect before, then this needs to be a separate patch and tagged with the appropriate fixes tag so that this can be picked up for stable.

This is mentioned in the commit message.

Quoted 8 lines
Quoted 4 lines

"... and adjusting the register address to skip channel0 ..."

Probably it is not very clear that it directs to this change. Shall I update the commit message to have a clearer context?

Ah OK. I was wondering how this worked with 'channel_reg_size' but looking closer I see channel_reg_size is always SZ_64K. I wonder why we even bother having this parameter and don't use SZ_64K directly?

There is an offset from the base address which the per channel registers start. Although this offset value happens to match with the channel_reg_size, this is not actually the per channel register size.

Quoted 3 lines

Anyway, for now this is fine.

Thanks for the review.

Regards,
Akhil

maintainer
#10 lore raw

Re: [PATCH v2 3/3] dmaengine: tegra: Add support for dma-channel-mask

On 23/09/2022 12:09, Akhil R wrote:

...

Quoted 6 lines
Quoted 3 lines

Ah OK. I was wondering how this worked with 'channel_reg_size' but looking closer I see channel_reg_size is always SZ_64K. I wonder why we even bother having this parameter and don't use SZ_64K directly?

There is an offset from the base address which the per channel registers start. Although this offset value happens to match with the channel_reg_size, this is not actually the per channel register size.

Yes I see that, but I mean why do we even bother having this channel_reg_size parameter? Does not look like we need this (currently). All we need is ...

tdc->chan_base_offset = TEGRA_GPCDMA_CHANNEL_BASE_ADDR_OFFSET +

                         (i * SZ_64K);

Jon

Signature · 1 line
nvpublic
author
#11 lore raw

RE: [PATCH v2 3/3] dmaengine: tegra: Add support for dma-channel-mask

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

Ah OK. I was wondering how this worked with 'channel_reg_size' but looking closer I see channel_reg_size is always SZ_64K. I wonder why we even bother having this parameter and don't use SZ_64K directly?

There is an offset from the base address which the per channel registers start. Although this offset value happens to match with the channel_reg_size, this is not actually the per channel register size.

Quoted 7 lines

Yes I see that, but I mean why do we even bother having this channel_reg_size parameter? Does not look like we need this (currently). All we need is ...

  tdc->chan_base_offset = TEGRA_GPCDMA_CHANNEL_BASE_ADDR_OFFSET +
                          (i * SZ_64K);

Ah. Ok. Got it now. Would add this as an improvement in another patch.

Thanks,
Akhil

maintainer Reviewed-by on v2 3/3
#12 lore raw

Re: [PATCH v2 3/3] dmaengine: tegra: Add support for dma-channel-mask

In reply to Akhil R
Quoted 116 lines · Akhil R

Add support for dma-channel-mask so that only the specified channels are used. This helps to reserve some channels for the firmware.

This was initially achieved by limiting the channel number to 31 in the driver and adjusting the register address to skip channel0 which was reserved for a firmware. Now, with this change, the driver can align more to the actual hardware which has 32 channels.

---
  drivers/dma/tegra186-gpc-dma.c | 37 +++++++++++++++++++++++++++-------
  1 file changed, 30 insertions(+), 7 deletions(-)
drivers/dma/tegra186-gpc-dma.c +27 -7
index fa9bda4a2bc6..1d1180db6d4e 100644
@@ -161,7 +161,10 @@
  #define TEGRA_GPCDMA_BURST_COMPLETION_TIMEOUT	5000 /* 5 msec */
 
  /* Channel base address offset from GPCDMA base address */
-#define TEGRA_GPCDMA_CHANNEL_BASE_ADD_OFFSET	0x20000
+#define TEGRA_GPCDMA_CHANNEL_BASE_ADDR_OFFSET	0x10000
+
+/* Default channel mask reserving channel0 */
+#define TEGRA_GPCDMA_DEFAULT_CHANNEL_MASK	0xfffffffe
 
  struct tegra_dma;
  struct tegra_dma_channel;
@@ -246,6 +249,7 @@ struct tegra_dma {
  	const struct tegra_dma_chip_data *chip_data;
  	unsigned long sid_m2d_reserved;
  	unsigned long sid_d2m_reserved;
+	u32 chan_mask;
  	void __iomem *base_addr;
  	struct device *dev;
  	struct dma_device dma_dev;
@@ -1288,7 +1292,7 @@ static struct dma_chan *tegra_dma_of_xlate(struct of_phandle_args *dma_spec,
  }
 
  static const struct tegra_dma_chip_data tegra186_dma_chip_data = {
-	.nr_channels = 31,
+	.nr_channels = 32,
  	.channel_reg_size = SZ_64K,
  	.max_dma_count = SZ_1G,
  	.hw_support_pause = false,
@@ -1296,7 +1300,7 @@ static const struct tegra_dma_chip_data tegra186_dma_chip_data = {
  };
 
  static const struct tegra_dma_chip_data tegra194_dma_chip_data = {
-	.nr_channels = 31,
+	.nr_channels = 32,
  	.channel_reg_size = SZ_64K,
  	.max_dma_count = SZ_1G,
  	.hw_support_pause = true,
@@ -1304,7 +1308,7 @@ static const struct tegra_dma_chip_data tegra194_dma_chip_data = {
  };
 
  static const struct tegra_dma_chip_data tegra234_dma_chip_data = {
-	.nr_channels = 31,
+	.nr_channels = 32,
  	.channel_reg_size = SZ_64K,
  	.max_dma_count = SZ_1G,
  	.hw_support_pause = true,
@@ -1380,15 +1384,28 @@ static int tegra_dma_probe(struct platform_device *pdev)
  	}
  	stream_id = iommu_spec->ids[0] & 0xffff;
 
+	ret = device_property_read_u32(&pdev->dev, "dma-channel-mask",
+				       &tdma->chan_mask);
+	if (ret) {
+		dev_warn(&pdev->dev,
+			 "Missing dma-channel-mask property, using default channel mask %#x\n",
+			 TEGRA_GPCDMA_DEFAULT_CHANNEL_MASK);
+		tdma->chan_mask = TEGRA_GPCDMA_DEFAULT_CHANNEL_MASK;
+	}
+
  	INIT_LIST_HEAD(&tdma->dma_dev.channels);
  	for (i = 0; i < cdata->nr_channels; i++) {
  		struct tegra_dma_channel *tdc = &tdma->channels[i];
 
+		/* Check for channel mask */
+		if (!(tdma->chan_mask & BIT(i)))
+			continue;
+
  		tdc->irq = platform_get_irq(pdev, i);
  		if (tdc->irq < 0)
  			return tdc->irq;
 
-		tdc->chan_base_offset = TEGRA_GPCDMA_CHANNEL_BASE_ADD_OFFSET +
+		tdc->chan_base_offset = TEGRA_GPCDMA_CHANNEL_BASE_ADDR_OFFSET +
  					i * cdata->channel_reg_size;
  		snprintf(tdc->name, sizeof(tdc->name), "gpcdma.%d", i);
  		tdc->tdma = tdma;
@@ -1449,8 +1466,8 @@ static int tegra_dma_probe(struct platform_device *pdev)
  		return ret;
  	}
 
-	dev_info(&pdev->dev, "GPC DMA driver register %d channels\n",
-		 cdata->nr_channels);
+	dev_info(&pdev->dev, "GPC DMA driver register %lu channels\n",
+		 hweight_long(tdma->chan_mask));
 
  	return 0;
  }
@@ -1473,6 +1490,9 @@ static int __maybe_unused tegra_dma_pm_suspend(struct device *dev)
  	for (i = 0; i < tdma->chip_data->nr_channels; i++) {
  		struct tegra_dma_channel *tdc = &tdma->channels[i];
 
+		if (!(tdma->chan_mask & BIT(i)))
+			continue;
+
  		if (tdc->dma_desc) {
  			dev_err(tdma->dev, "channel %u busy\n", i);
  			return -EBUSY;

drivers/dma/tegra186-gpc-dma.c static int __maybe_unused tegra_dma_pm_resume(struct device *dev) · line 1520

Quoted 9 lines
drivers/dma/tegra186-gpc-dma.c +3 -0
@@ -1492,6 +1512,9 @@ static int __maybe_unused tegra_dma_pm_resume(struct device *dev)
  	for (i = 0; i < tdma->chip_data->nr_channels; i++) {
  		struct tegra_dma_channel *tdc = &tdma->channels[i];
 
+		if (!(tdma->chan_mask & BIT(i)))
+			continue;
+
  		tegra_dma_program_sid(tdc, tdc->stream_id);
  	}
 

Thanks!
Jon

Signature · 1 line
nvpublic