Add NVIDIA Tegra GPC-DMA driver
v15 cover Add NVIDIA Tegra GPC-DMA driver
Add support for NVIDIA Tegra general purpose DMA driver for Tegra186 and Tegra194 platform.
v14 -> v15:
* Removed late suspend.
* Removed unneeded prototype
* Updated kfree to free tdc->vc instead of tdc->dma_desc.
* Updated Kconfig to use ARCH_TEGRA instead of specific chips.
v14 - https://lkml.org/lkml/2021/12/6/370
Akhil R (4):
dt-bindings: dmaengine: Add doc for tegra gpcdma
dmaengine: tegra: Add tegra gpcdma driver
arm64: defconfig: tegra: Enable GPCDMA
arm64: tegra: Add GPCDMA node for tegra186 and tegra194
.../bindings/dma/nvidia,tegra186-gpc-dma.yaml | 110 ++ arch/arm64/boot/dts/nvidia/tegra186.dtsi | 42 + arch/arm64/boot/dts/nvidia/tegra194.dtsi | 43 + arch/arm64/configs/defconfig | 1 + drivers/dma/Kconfig | 11 + drivers/dma/Makefile | 1 + drivers/dma/tegra186-gpc-dma.c | 1281 ++++++++++++++++++++ 7 files changed, 1489 insertions(+) create mode 100644 Documentation/devicetree/bindings/dma/nvidia,tegra186-gpc-dma.yaml create mode 100644 drivers/dma/tegra186-gpc-dma.c
Signature · 1 line
2.7.4
PATCH v15 1/4 dt-bindings: dmaengine: Add doc for tegra gpcdma
Add DT binding document for Nvidia Tegra GPCDMA controller.
--- .../bindings/dma/nvidia,tegra186-gpc-dma.yaml | 110 +++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 Documentation/devicetree/bindings/dma/nvidia,tegra186-gpc-dma.yaml
Documentation/devicetree/bindings/dma/nvidia,tegra186-gpc-dma.yaml new file +110 -0
@@ -0,0 +1,110 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/dma/nvidia,tegra186-gpc-dma.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: NVIDIA Tegra GPC DMA Controller Device Tree Bindings + +description: | + The Tegra General Purpose Central (GPC) DMA controller is used for faster + data transfers between memory to memory, memory to device and device to + memory. + +maintainers: + - Jon Hunter <[email protected]> + - Rajesh Gumasta <[email protected]> + +allOf: + - $ref: "dma-controller.yaml#" + +properties: + compatible: + oneOf: + - const: nvidia,tegra186-gpcdma + - items: + - const: nvidia,tegra194-gpcdma + - const: nvidia,tegra186-gpcdma + + "#dma-cells": + const: 1 + + reg: + maxItems: 1 + + interrupts: + description: + Should contain all of the per-channel DMA interrupts in + ascending order with respect to the DMA channel index. + minItems: 1 + maxItems: 31 + + resets: + maxItems: 1 + + reset-names: + const: gpcdma + + iommus: + maxItems: 1 + + dma-coherent: true + +required: + - compatible + - reg + - interrupts + - resets + - reset-names + - "#dma-cells" + - iommus + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/memory/tegra186-mc.h> + #include <dt-bindings/reset/tegra186-reset.h> + + dma-controller@2600000 { + compatible = "nvidia,tegra186-gpcdma"; + reg = <0x2600000 0x210000>; + resets = <&bpmp TEGRA186_RESET_GPCDMA>; + reset-names = "gpcdma"; + interrupts = <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>, + <GIC_SPI 80 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 81 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 82 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 83 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 84 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 85 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 86 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 87 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 88 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 89 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 90 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 91 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 92 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 93 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 94 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 95 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 96 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 97 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 98 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 99 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 100 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 101 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 102 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 103 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 104 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 105 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 106 IRQ_TYPE_LEVEL_HIGH>; + #dma-cells = <1>; + iommus = <&smmu TEGRA186_SID_GPCDMA_0>; + dma-coherent; + }; +...
Signature · 1 line
2.7.4
PATCH v15 2/4 dmaengine: tegra: Add tegra gpcdma driver
In reply to Akhil RAdding GPC DMA controller driver for Tegra186 and Tegra194. The driver supports dma transfers between memory to memory, IO peripheral to memory and memory to IO peripheral.
--- drivers/dma/Kconfig | 11 + drivers/dma/Makefile | 1 + drivers/dma/tegra186-gpc-dma.c | 1281 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1293 insertions(+) create mode 100644 drivers/dma/tegra186-gpc-dma.c
drivers/dma/Kconfig +11 -0
@@ -629,6 +629,17 @@ config TXX9_DMAC Support the TXx9 SoC internal DMA controller. This can be integrated in chips such as the Toshiba TX4927/38/39. +config TEGRA186_GPC_DMA + tristate "NVIDIA Tegra GPC DMA support" + depends on ARCH_TEGRA || COMPILE_TEST + select DMA_ENGINE + help + Support for the NVIDIA Tegra General Purpose Central DMA controller. + The DMA controller has multiple DMA channels which can be configured + for different peripherals like UART, SPI, etc which are on APB bus. + This DMA controller transfers data from memory to peripheral FIFO + or vice versa. It also supports memory to memory data transfer. + config TEGRA20_APB_DMA tristate "NVIDIA Tegra20 APB DMA support" depends on ARCH_TEGRA || COMPILE_TEST
drivers/dma/Makefile +1 -0
@@ -72,6 +72,7 @@ obj-$(CONFIG_STM32_MDMA) += stm32-mdma.o obj-$(CONFIG_SPRD_DMA) += sprd-dma.o obj-$(CONFIG_S3C24XX_DMAC) += s3c24xx-dma.o obj-$(CONFIG_TXX9_DMAC) += txx9dmac.o +obj-$(CONFIG_TEGRA186_GPC_DMA) += tegra186-gpc-dma.o obj-$(CONFIG_TEGRA20_APB_DMA) += tegra20-apb-dma.o obj-$(CONFIG_TEGRA210_ADMA) += tegra210-adma.o obj-$(CONFIG_TIMB_DMA) += timb_dma.o
drivers/dma/tegra186-gpc-dma.c new file +1281 -0
1,281 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH v15 2/4] dmaengine: tegra: Add tegra gpcdma driver
16.12.2021 20:11, Akhil R пишет:
Quoted 35 lines
drivers/dma/tegra186-gpc-dma.c new file +35
-0+static int tegra_dma_terminate_all (struct dma_chan *dc) +{ +struct tegra_dma_channel *tdc =to_tegra_dma_chan (dc); +unsigned long wcount =0 ; +unsigned long status; +unsigned long flags; +int err; + +raw_spin_lock_irqsave (&tdc->lock, flags); + +if (!tdc->dma_desc) { +raw_spin_unlock_irqrestore (&tdc->lock, flags); +return 0 ; + } + +if (!tdc->busy) + goto skip_dma_stop; + +if (tdc->tdma->chip_data->hw_support_pause) + err =tegra_dma_pause (tdc); +else + err =tegra_dma_stop_client (tdc); + +if (err) { +raw_spin_unlock_irqrestore (&tdc->lock, flags); +return err; + } + + status =tdc_read (tdc,TEGRA_GPCDMA_CHAN_STATUS ); +if (status &TEGRA_GPCDMA_STATUS_ISE_EOC ) { +dev_dbg (tdc2dev (tdc),"%s():handling isr\n" , __func__); +tegra_dma_xfer_complete (tdc); + status =tdc_read (tdc,TEGRA_GPCDMA_CHAN_STATUS ); + } +
drivers/dma/tegra186-gpc-dma.c line 621
Quoted 10 lines
drivers/dma/tegra186-gpc-dma.c new file +10
-0+ wcount =tdc_read (tdc,TEGRA_GPCDMA_CHAN_XFER_COUNT ); +tegra_dma_stop (tdc); + + tdc->dma_desc->bytes_transferred += + tdc->dma_desc->bytes_requested - (wcount *4 ); + +skip_dma_stop: +tegra_dma_sid_free (tdc); +vchan_free_chan_resources (&tdc->vc); +kfree (&tdc->vc);
You really going to kfree the head of tegra_dma_channel here? Once again, this code was 100% untested :/
You're not allowed to free channel from the dma_terminate_all() callback. This callback terminates submitted descs, that's it.
https://elixir.bootlin.com/linux/v5.16-rc5/source/include/linux/dmaengine.h#L1105
https://elixir.bootlin.com/linux/v5.16-rc5/source/drivers/i2c/busses/i2c-tegra.c#L962
RE: [PATCH v15 2/4] dmaengine: tegra: Add tegra gpcdma driver
Quoted 40 lines
16.12.2021 20:11, Akhil R пишет:
Quoted 39 lines
drivers/dma/tegra186-gpc-dma.c new file +39
-0+static int tegra_dma_terminate_all (struct dma_chan *dc) { +struct tegra_dma_channel *tdc =to_tegra_dma_chan (dc); +unsigned long wcount =0 ; +unsigned long status; +unsigned long flags; +int err; + +raw_spin_lock_irqsave (&tdc->lock, flags); + +if (!tdc->dma_desc) { +raw_spin_unlock_irqrestore (&tdc->lock, flags); +return 0 ; + } + +if (!tdc->busy) + goto skip_dma_stop; + +if (tdc->tdma->chip_data->hw_support_pause) + err =tegra_dma_pause (tdc); +else + err =tegra_dma_stop_client (tdc); + +if (err) { +raw_spin_unlock_irqrestore (&tdc->lock, flags); +return err; + } + + status =tdc_read (tdc,TEGRA_GPCDMA_CHAN_STATUS ); +if (status &TEGRA_GPCDMA_STATUS_ISE_EOC ) { +dev_dbg (tdc2dev (tdc),"%s():handling isr\n" , __func__); +tegra_dma_xfer_complete (tdc); + status =tdc_read (tdc,TEGRA_GPCDMA_CHAN_STATUS ); + } + + wcount =tdc_read (tdc,TEGRA_GPCDMA_CHAN_XFER_COUNT ); +tegra_dma_stop (tdc); + + tdc->dma_desc->bytes_transferred += + tdc->dma_desc->bytes_requested - (wcount *4 );
Quoted 8 lines
drivers/dma/tegra186-gpc-dma.c line 621
Quoted 5 lines
drivers/dma/tegra186-gpc-dma.c new file +5
-0+ +skip_dma_stop: +tegra_dma_sid_free (tdc); +vchan_free_chan_resources (&tdc->vc); +kfree (&tdc->vc);You really going to kfree the head of
tegra_dma_channelhere? Once again, this code was 100% untested :/
I did validate this using DMATEST which did not show any error.
https://www.kernel.org/doc/html/latest/driver-api/dmaengine/dmatest.html
Do you suggest something better?
Quoted 3 lines
You're not allowed to free channel from the
dma_terminate_all()callback. This callback terminates submitted descs, that's it.
Sorry, I am relatively new to DMA framework (probably you get it from the patch version no. :)). I read your previous comment as to use tdc->vc instead of dma_desc. I would learn a bit more and update with a change. Thanks for the inputs.
Thanks,
Akhil
--
nvpublic
Re: [PATCH v15 2/4] dmaengine: tegra: Add tegra gpcdma driver
20.12.2021 18:23, Akhil R пишет:
Quoted 52 lines
Quoted 40 lines
16.12.2021 20:11, Akhil R пишет:
Quoted 39 lines
drivers/dma/tegra186-gpc-dma.c new file +39
-0+static int tegra_dma_terminate_all (struct dma_chan *dc) { +struct tegra_dma_channel *tdc =to_tegra_dma_chan (dc); +unsigned long wcount =0 ; +unsigned long status; +unsigned long flags; +int err; + +raw_spin_lock_irqsave (&tdc->lock, flags); + +if (!tdc->dma_desc) { +raw_spin_unlock_irqrestore (&tdc->lock, flags); +return 0 ; + } + +if (!tdc->busy) + goto skip_dma_stop; + +if (tdc->tdma->chip_data->hw_support_pause) + err =tegra_dma_pause (tdc); +else + err =tegra_dma_stop_client (tdc); + +if (err) { +raw_spin_unlock_irqrestore (&tdc->lock, flags); +return err; + } + + status =tdc_read (tdc,TEGRA_GPCDMA_CHAN_STATUS ); +if (status &TEGRA_GPCDMA_STATUS_ISE_EOC ) { +dev_dbg (tdc2dev (tdc),"%s():handling isr\n" , __func__); +tegra_dma_xfer_complete (tdc); + status =tdc_read (tdc,TEGRA_GPCDMA_CHAN_STATUS ); + } + + wcount =tdc_read (tdc,TEGRA_GPCDMA_CHAN_XFER_COUNT ); +tegra_dma_stop (tdc); + + tdc->dma_desc->bytes_transferred += + tdc->dma_desc->bytes_requested - (wcount *4 );Quoted 8 lines
drivers/dma/tegra186-gpc-dma.c line 621
Quoted 5 lines
drivers/dma/tegra186-gpc-dma.c new file +5
-0+ +skip_dma_stop: +tegra_dma_sid_free (tdc); +vchan_free_chan_resources (&tdc->vc); +kfree (&tdc->vc);You really going to kfree the head of
tegra_dma_channelhere? Once again, this code was 100% untested :/I did validate this using DMATEST which did not show any error.
https://www.kernel.org/doc/html/latest/driver-api/dmaengine/dmatest.html
Do you suggest something better?
Quoted 6 lines
Quoted 3 lines
You're not allowed to free channel from the
dma_terminate_all()callback. This callback terminates submitted descs, that's it.Sorry, I am relatively new to DMA framework (probably you get it from the patch version no. :)). I read your previous comment as to use
tdc->vcinstead ofdma_desc. I would learn a bit more and update with a change. Thanks for the inputs.
Looks like DMATEST doesn't try to terminate in a middle of transfer and then check that further transfers work. You may try to extend DMATEST or simulate I2C error to test it, you should also test it with enabled KASAN.
PATCH v15 3/4 arm64: defconfig: tegra: Enable GPCDMA
In reply to Akhil REnable TEGRA_GPC_DMA in defconfig for Tegra186 and Tegra196 gpc dma controller driver
--- arch/arm64/configs/defconfig | 1 + 1 file changed, 1 insertion(+)
arch/arm64/configs/defconfig +1 -0
@@ -944,6 +944,7 @@ CONFIG_MV_XOR=y CONFIG_MV_XOR_V2=y CONFIG_OWL_DMA=y CONFIG_PL330_DMA=y +CONFIG_TEGRA186_GPC_DMA=m CONFIG_TEGRA20_APB_DMA=y CONFIG_TEGRA210_ADMA=m CONFIG_QCOM_BAM_DMA=y
Signature · 1 line
2.7.4
PATCH v15 4/4 arm64: tegra: Add GPCDMA node for tegra186 and tegra194
In reply to Akhil RAdd device tree node for GPCDMA controller on Tegra186 target and Tegra194 target.
--- arch/arm64/boot/dts/nvidia/tegra186.dtsi | 42 +++++++++++++++++++++++++++++++ arch/arm64/boot/dts/nvidia/tegra194.dtsi | 43 ++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+)
arch/arm64/boot/dts/nvidia/tegra186.dtsi +42 -0
@@ -73,6 +73,48 @@ snps,rxpbl = <8>; }; + dma-controller@2600000 { + compatible = "nvidia,tegra186-gpcdma"; + reg = <0x0 0x2600000 0x0 0x210000>; + resets = <&bpmp TEGRA186_RESET_GPCDMA>; + reset-names = "gpcdma"; + interrupts = <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>, + <GIC_SPI 80 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 81 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 82 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 83 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 84 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 85 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 86 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 87 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 88 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 89 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 90 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 91 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 92 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 93 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 94 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 95 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 96 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 97 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 98 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 99 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 100 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 101 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 102 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 103 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 104 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 105 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 106 IRQ_TYPE_LEVEL_HIGH>; + #dma-cells = <1>; + iommus = <&smmu TEGRA186_SID_GPCDMA_0>; + dma-coherent; + status = "okay"; + }; + aconnect@2900000 { compatible = "nvidia,tegra186-aconnect", "nvidia,tegra210-aconnect";
arch/arm64/boot/dts/nvidia/tegra194.dtsi +43 -0
49 lines not on this page · raw message
Signature · 1 line
2.7.4