dmaengine: sf-pdma: Add platform dma driver
Subsystems (5)
v4 cover dmaengine: sf-pdma: Add platform dma driver
Add PDMA driver support for SiFive HiFive Unleashed RevA00 board. Mainly follows DMAengine controller doc[1] to implement and take other DMA drivers as reference. Such as
- drivers/dma/fsl-edma.c
- drivers/dma/dw-edma/
- drivers/dma/pxa-dma.c
Using DMA test client[2] to test. Detailed datasheet is doc[3]. Driver supports:
- 4 physical DMA channels, share same DONE and error interrupt handler.
- Support MEM_TO_MEM
- Tested by DMA test client
- patches include DT Bindgins document and dts for fu450-c000 SoC. Separate dts patch for easier review and apply to different branch or SoC platform.
- retry 1 time if DMA error occurs.
[Reference Doc]
[1] ./Documentation/driver-api/dmaengine/provider.rst
[2] ./Documentation/driver-api/dmaengine/dmatest.rst
[3] https://static.dev.sifive.com/FU540-C000-v1.0.pdf
[Simple steps to test of DMA Test client]
$ echo 1 > /sys/module/dmatest/parameters/iterations $ echo dma0chan0 > /sys/module/dmatest/parameters/channel $ echo dma0chan1 > /sys/module/dmatest/parameters/channel $ echo dma0chan2 > /sys/module/dmatest/parameters/channel $ echo dma0chan3 > /sys/module/dmatest/parameters/channel $ echo 1 > /sys/module/dmatest/parameters/run
[Expected test result]
[ 267.563323] dmatest: dma0chan0-copy0: summary 45629 tests, 0 failures 38769.01 iops 309661 KB/s (0) [ 267.572427] dmatest: dma0chan1-copy0: summary 45863 tests, 0 failures 40286.85 iops 321643 KB/s (0) [ 267.581392] dmatest: dma0chan2-copy0: summary 45975 tests, 0 failures 41178.48 iops 328740 KB/s (0) [ 267.590542] dmatest: dma0chan3-copy0: summary 44768 tests, 0 failures 38560.29 iops 307726 KB/s (0)
Green Wan (4):
dt-bindings: dmaengine: sf-pdma: add bindins for SiFive PDMA
riscv: dts: add support for PDMA device of HiFive Unleashed Rev A00
dmaengine: sf-pdma: add platform DMA support for HiFive Unleashed A00
MAINTAINERS: Add Green as SiFive PDMA driver maintainer
.../bindings/dma/sifive,fu540-c000-pdma.yaml | 55 ++ MAINTAINERS | 6 + arch/riscv/boot/dts/sifive/fu540-c000.dtsi | 7 + drivers/dma/Kconfig | 2 + drivers/dma/Makefile | 1 + drivers/dma/sf-pdma/Kconfig | 6 + drivers/dma/sf-pdma/Makefile | 1 + drivers/dma/sf-pdma/sf-pdma.c | 601 ++++++++++++++++++ drivers/dma/sf-pdma/sf-pdma.h | 124 ++++ 9 files changed, 803 insertions(+) create mode 100644 Documentation/devicetree/bindings/dma/sifive,fu540-c000-pdma.yaml create mode 100644 drivers/dma/sf-pdma/Kconfig create mode 100644 drivers/dma/sf-pdma/Makefile create mode 100644 drivers/dma/sf-pdma/sf-pdma.c create mode 100644 drivers/dma/sf-pdma/sf-pdma.h
Signature · 1 line
2.17.1
PATCH v4 1/4 dt-bindings: dmaengine: sf-pdma: add bindins for SiFive PDMA
Add DT bindings document for Platform DMA(PDMA) driver of board, HiFive Unleashed Rev A00.
--- .../bindings/dma/sifive,fu540-c000-pdma.yaml | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Documentation/devicetree/bindings/dma/sifive,fu540-c000-pdma.yaml
Documentation/devicetree/bindings/dma/sifive,fu540-c000-pdma.yaml new file +55 -0
@@ -0,0 +1,55 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/dma/sifive,fu540-c000-pdma.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: SiFive Unleashed Rev C000 Platform DMA + +maintainers: + - Green Wan <[email protected]> + - Palmer Debbelt <[email protected]> + - Paul Walmsley <[email protected]> + +description: | + Platform DMA is a DMA engine of SiFive Unleashed. It supports 4 + channels. Each channel has 2 interrupts. One is for DMA done and + the other is for DME error. + + In different SoC, DMA could be attached to different IRQ line. + DT file need to be changed to meet the difference. For technical + doc, + + https://static.dev.sifive.com/FU540-C000-v1.0.pdf + +properties: + compatible: + items: + - const: sifive,fu540-c000-pdma + + reg: + maxItems: 1 + + interrupts: + minItems: 1 + maxItems: 8 + + '#dma-cells': + const: 1 + +required: + - compatible + - reg + - interrupts + - '#dma-cells' + +examples: + - | + dma@3000000 { + compatible = "sifive,fu540-c000-pdma"; + reg = <0x0 0x3000000 0x0 0x8000>; + interrupts = <23 24 25 26 27 28 29 30>; + #dma-cells = <1>; + }; + +...
Signature · 1 line
2.17.1
Re: [PATCH v4 1/4] dt-bindings: dmaengine: sf-pdma: add bindins for SiFive PDMA
Quoted 9 lines · Green Wan
Add DT bindings document for Platform DMA(PDMA) driver of board, HiFive Unleashed Rev A00.
Signed-off-by Green Wan <[email protected]>--- .../bindings/dma/sifive,fu540-c000-pdma.yaml | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Documentation/devicetree/bindings/dma/sifive,fu540-c000-pdma.yaml
PATCH v4 2/4 riscv: dts: add support for PDMA device of HiFive Unleashed Rev A00
In reply to Green WanAdd PDMA support to (arch/riscv/boot/dts/sifive/fu540-c000.dtsi)
--- arch/riscv/boot/dts/sifive/fu540-c000.dtsi | 7 +++++++ 1 file changed, 7 insertions(+)
arch/riscv/boot/dts/sifive/fu540-c000.dtsi +7 -0
@@ -162,6 +162,13 @@ clocks = <&prci PRCI_CLK_TLCLK>; status = "disabled"; }; + dma: dma@3000000 { + compatible = "sifive,fu540-c000-pdma"; + reg = <0x0 0x3000000 0x0 0x8000>; + interrupt-parent = <&plic0>; + interrupts = <23 24 25 26 27 28 29 30>; + #dma-cells = <1>; + }; uart1: serial@10011000 { compatible = "sifive,fu540-c000-uart", "sifive,uart0"; reg = <0x0 0x10011000 0x0 0x1000>;
Signature · 1 line
2.17.1
PATCH v4 3/4 dmaengine: sf-pdma: add platform DMA support for HiFive Unleashed A00
In reply to Green WanAdd PDMA driver, sf-pdma, to enable DMA engine on HiFive Unleashed Rev A00 board.
- Implement dmaengine APIs, support MEM_TO_MEM async copy.
- Tested by DMA Test client
- Supports 4 channels DMA, each channel has 1 done and 1 err interrupt connected to platform-level interrupt controller (PLIC).
- Depends on DMA_ENGINE and DMA_VIRTUAL_CHANNELS
The datasheet is here:
https://static.dev.sifive.com/FU540-C000-v1.0.pdf
Follow the DMAengine controller doc, "./Documentation/driver-api/dmaengine/provider.rst" to implement DMA engine. And use the dma test client in doc, "./Documentation/driver-api/dmaengine/dmatest.rst", to test.
Each DMA channel has separate HW regs and support done and error ISRs. 4 channels share 1 done and 1 err ISRs. There's no expander/arbitrator in DMA HW.
------ ------ | |--< done 23 >--|ch 0| | |--< err 24 >--| | (dma0chan0) | | ------ | | ------ | |--< done 25 >--|ch 1| | |--< err 26 >--| | (dma0chan1) |PLIC| ------ | | ------ | |--< done 27 >--|ch 2| | |--< err 28 >--| | (dma0chan2) | | ------ | | ------ | |--< done 29 >--|ch 3| | |--< err 30 >--| | (dma0chan3) ------ ------
--- drivers/dma/Kconfig | 2 + drivers/dma/Makefile | 1 + drivers/dma/sf-pdma/Kconfig | 6 + drivers/dma/sf-pdma/Makefile | 1 + drivers/dma/sf-pdma/sf-pdma.c | 601 ++++++++++++++++++++++++++++++++++ drivers/dma/sf-pdma/sf-pdma.h | 124 +++++++ 6 files changed, 735 insertions(+) create mode 100644 drivers/dma/sf-pdma/Kconfig create mode 100644 drivers/dma/sf-pdma/Makefile create mode 100644 drivers/dma/sf-pdma/sf-pdma.c create mode 100644 drivers/dma/sf-pdma/sf-pdma.h
drivers/dma/Kconfig +2 -0
@@ -661,6 +661,8 @@ source "drivers/dma/qcom/Kconfig" source "drivers/dma/dw/Kconfig" +source "drivers/dma/sf-pdma/Kconfig" + source "drivers/dma/dw-edma/Kconfig" source "drivers/dma/hsu/Kconfig"
drivers/dma/Makefile +1 -0
@@ -28,6 +28,7 @@ obj-$(CONFIG_DMA_SUN4I) += sun4i-dma.o obj-$(CONFIG_DMA_SUN6I) += sun6i-dma.o obj-$(CONFIG_DW_AXI_DMAC) += dw-axi-dmac/ obj-$(CONFIG_DW_DMAC_CORE) += dw/ +obj-$(CONFIG_SF_PDMA) += sf-pdma/ obj-$(CONFIG_DW_EDMA) += dw-edma/ obj-$(CONFIG_EP93XX_DMA) += ep93xx_dma.o obj-$(CONFIG_FSL_DMA) += fsldma.o
drivers/dma/sf-pdma/Kconfig new file +6 -0
@@ -0,0 +1,6 @@ +config SF_PDMA + bool "Sifive PDMA controller driver" + select DMA_ENGINE + select DMA_VIRTUAL_CHANNELS + help + Support the SiFive PDMA controller.
drivers/dma/sf-pdma/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_SF_PDMA) += sf-pdma.o
drivers/dma/sf-pdma/sf-pdma.c new file +601 -0
601 lines not on this page · raw message
drivers/dma/sf-pdma/sf-pdma.h new file +124 -0
124 lines not on this page · raw message
Signature · 1 line
2.17.1
kbuild test robot
build bot[RFC PATCH] dmaengine: sf-pdma: sf_pdma_disclaim_chan() can be static
Fixes: 31c3b98b5a01 ("dmaengine: sf-pdma: add platform DMA support for HiFive Unleashed A00")
--- sf-pdma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/dma/sf-pdma/sf-pdma.c +2 -2
@@ -97,14 +97,14 @@ static void sf_pdma_fill_desc(struct sf_pdma_chan *chan,writeq (src, regs->src_addr); } -void sf_pdma_disclaim_chan (struct sf_pdma_chan *chan) +static void sf_pdma_disclaim_chan (struct sf_pdma_chan *chan) {struct pdma_regs *regs = &chan->regs;writel (PDMA_CLEAR_CTRL , regs->ctrl); } -struct dma_async_tx_descriptor * +static struct dma_async_tx_descriptor * sf_pdma_prep_dma_memcpy(struct dma_chan *dchan, dma_addr_t dest, dma_addr_t src,
kbuild test robot
build botRe: [PATCH v4 3/4] dmaengine: sf-pdma: add platform DMA support for HiFive Unleashed A00
In reply to Green WanThank you for the patch! Perhaps something to improve:
Hi Green,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on linus/master]
[cannot apply to v5.4-rc2 next-20191011]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Green-Wan/dmaengine-sf-pdma-Add-platform-dma-driver/20191003-172343
reproduce:
# apt-get install sparse
# sparse version: v0.6.1-rc1-43-g0ccb3b4-dirty
make ARCH=x86_64 allmodconfig
make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'If you fix the issue, kindly add following tag
sparse warnings: (new ones prefixed by >>)
>> drivers/dma/sf-pdma/sf-pdma.c:100:6: sparse: sparse: symbol 'sf_pdma_disclaim_chan' was not declared. Should it be static? >> drivers/dma/sf-pdma/sf-pdma.c:107:32: sparse: sparse: symbol 'sf_pdma_prep_dma_memcpy' was not declared. Should it be static?
Please review and possibly fold the followup patch.
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Vinod Koul
maintainerRe: [PATCH v4 3/4] dmaengine: sf-pdma: add platform DMA support for HiFive Unleashed A00
In reply to Green Wandrivers/dma/Kconfig source "drivers/dma/qcom/Kconfig" · line 664
Quoted 9 lines · Green Wan
drivers/dma/Kconfig +1
-0@@ -661,6 +661,8 @@ source "drivers/dma/qcom/Kconfig" source "drivers/dma/dw/Kconfig" +source "drivers/dma/sf-pdma/Kconfig"
Please keep this in sorted order
drivers/dma/Makefile obj-$(CONFIG_DMA_SUN4I) += sun4i-dma.o · line 31
Quoted 13 lines
drivers/dma/Kconfig +1
-0+ source "drivers/dma/dw-edma/Kconfig" source "drivers/dma/hsu/Kconfig"drivers/dma/Makefile +1
-0@@ -28,6 +28,7 @@ obj-$(CONFIG_DMA_SUN4I) += sun4i-dma.o obj-$(CONFIG_DMA_SUN6I) += sun6i-dma.o obj-$(CONFIG_DW_AXI_DMAC) += dw-axi-dmac/ obj-$(CONFIG_DW_DMAC_CORE) += dw/ +obj-$(CONFIG_SF_PDMA) += sf-pdma/
here as well!
drivers/dma/sf-pdma/Kconfig line 2
Quoted 11 lines
drivers/dma/Makefile +0
-0obj-$(CONFIG_DW_EDMA) += dw-edma/ obj-$(CONFIG_EP93XX_DMA) += ep93xx_dma.o obj-$(CONFIG_FSL_DMA) += fsldma.odrivers/dma/sf-pdma/Kconfig new file +2
-0@@ -0,0 +1,6 @@ +config SF_PDMA + bool "Sifive PDMA controller driver"
why not a module?
Quoted 4 lines
drivers/dma/sf-pdma/Kconfig new file +4
-0+#include <linux/module.h> +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/pm_runtime.h>
drivers/dma/sf-pdma/Kconfig
Quoted 10 lines
drivers/dma/sf-pdma/Kconfig new file +10
-0+#include <linux/dmaengine.h> +#include <linux/err.h> +#include <linux/interrupt.h> +#include <linux/dma-mapping.h> +#include <linux/irq.h> +#include <linux/of.h> +#include <linux/of_device.h> +#include <linux/of_address.h> +#include <linux/of_irq.h> +#include <linux/of_dma.h>
do you need all the headers?
Quoted 1 line
+#include <
linux/time64.h>
why is this required?
drivers/dma/sf-pdma/Kconfig
Quoted 6 lines
drivers/dma/sf-pdma/Kconfig new file +6
-0+ +#include "sf-pdma.h" +#include "../dmaengine.h" +#include "../virt-dma.h" + +#define SIFIVE_PDMA_NAME "sf-pdma"
this is used only once! can you use it directly to help readability!
drivers/dma/sf-pdma/Kconfig
Quoted 13 lines
drivers/dma/sf-pdma/Kconfig new file +13
-0+ +#ifndef readq +static inline unsigned long long readq(void __iomem *addr) +{ + return readl(addr) | (((unsigned long long)readl(addr + 4)) << 32LL); +} +#endif + +#ifndef writeq +static inline void writeq(unsigned long long v, void __iomem *addr) +{ + writel(v & 0xffffffff, addr); + writel(v >> 32, addr + 4);
why not use upper/lower_32_bits?
drivers/dma/sf-pdma/Kconfig
Quoted 4 lines
drivers/dma/sf-pdma/Kconfig new file +4
-0+static void sf_pdma_fill_desc(struct sf_pdma_chan *chan, + u64 dst, + u64 src, + u64 size)
these can fit in a line!
drivers/dma/sf-pdma/Kconfig
Quoted 12 lines
drivers/dma/sf-pdma/Kconfig new file +12
-0+struct dma_async_tx_descriptor * + sf_pdma_prep_dma_memcpy(struct dma_chan *dchan, + dma_addr_t dest, + dma_addr_t src, + size_t len, + unsigned long flags) +{ + struct sf_pdma_chan *chan = to_sf_pdma_chan(dchan); + struct sf_pdma_desc *desc; + + if (!chan || !len || !dest || !src) { + pr_debug("%s: Please check dma len, dest, src!\n", __func__);
why pr_debug() and not dev_debug(), bonus you get the device name in each print!
and this should be an error print!
drivers/dma/sf-pdma/Kconfig
Quoted 7 lines
drivers/dma/sf-pdma/Kconfig new file +7
-0+static void sf_pdma_unprep_slave_dma(struct sf_pdma_chan *chan) +{ + if (chan->dma_dir != DMA_NONE) + dma_unmap_resource(chan->vchan.chan.device->dev, + chan->dma_dev_addr, + chan->dma_dev_size, + chan->dma_dir, 0);
this does not seem correct to me, in slave cases the client is supposed to take care of mapping and unmapping, why is this being done here?
drivers/dma/sf-pdma/Kconfig
Quoted 10 lines
drivers/dma/sf-pdma/Kconfig new file +10
-0+ chan->dma_dir = DMA_NONE; +} + +static int sf_pdma_slave_config(struct dma_chan *dchan, + struct dma_slave_config *cfg) +{ + struct sf_pdma_chan *chan = to_sf_pdma_chan(dchan); + + memcpy(&chan->cfg, cfg, sizeof(*cfg)); + sf_pdma_unprep_slave_dma(chan);
why unmap!
Quoted 4 lines
drivers/dma/sf-pdma/Kconfig new file +4
-0+static enum dma_status +sf_pdma_tx_status(struct dma_chan *dchan, + dma_cookie_t cookie, + struct dma_tx_state *txstate)
drivers/dma/sf-pdma/Kconfig
Quoted 10 lines
drivers/dma/sf-pdma/Kconfig new file +10
-0+{ + struct sf_pdma_chan *chan = to_sf_pdma_chan(dchan); + enum dma_status status; + unsigned long flags; + + spin_lock_irqsave(&chan->lock, flags); + if (chan->xfer_err) { + chan->status = DMA_ERROR; + spin_unlock_irqrestore(&chan->lock, flags); + return chan->status;
well this is not correct! The status is queried for a descriptor and we might have that succeeded so returning error of a channel for descriptor does not make sense!
drivers/dma/sf-pdma/Kconfig
Quoted 9 lines
drivers/dma/sf-pdma/Kconfig new file +9
-0+static irqreturn_t sf_pdma_done_isr(int irq, void *dev_id) +{ + struct sf_pdma_chan *chan = dev_id; + struct pdma_regs *regs = &chan->regs; + unsigned long flags; + + spin_lock_irqsave(&chan->lock, flags); + writel((readl(regs->ctrl)) & ~PDMA_DONE_STATUS_MASK, regs->ctrl); + spin_unlock_irqrestore(&chan->lock, flags);
why not submit next transaction here? This is DMA so we do care about utilizing it!
Quoted 9 lines
drivers/dma/sf-pdma/Kconfig new file +9
-0+static int sf_pdma_irq_init(struct platform_device *pdev, struct sf_pdma *pdma) +{ + int irq, r, i; + struct sf_pdma_chan *chan; + + for (i = 0; i < pdma->n_chans; i++) { + chan = &pdma->chans[i]; + + irq = platform_get_irq(pdev, i * 2);
drivers/dma/sf-pdma/Kconfig
Quoted 10 lines
drivers/dma/sf-pdma/Kconfig new file +10
-0+ if (irq < 0) { + dev_err(&pdev->dev, "Can't get pdma done irq.\n"); + return irq; + } + + r = devm_request_irq(&pdev->dev, irq, sf_pdma_done_isr, 0, + dev_name(&pdev->dev), (void *)chan); + if (r) { + dev_err(&pdev->dev, "Fail to attach done ISR: %d\n", r); + return -1;
-1 :(
Quoted 34 lines
drivers/dma/sf-pdma/Kconfig new file +34
-0+static int sf_pdma_probe(struct platform_device *pdev) +{ + struct sf_pdma *pdma; + struct sf_pdma_chan *chan; + struct resource *res; + int len, chans; + int ret; + + chans = PDMA_NR_CH; + len = sizeof(*pdma) + sizeof(*chan) * chans; + pdma = devm_kzalloc(&pdev->dev, len, GFP_KERNEL); + if (!pdma) + return -ENOMEM; + + pdma->n_chans = chans; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + pdma->membase = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(pdma->membase)) + goto ERR_MEMBASE; + + ret = sf_pdma_irq_init(pdev, pdma); + if (ret) + goto ERR_INITIRQ; + + sf_pdma_setup_chans(pdma); + + pdma->dma_dev.dev = &pdev->dev; + dma_cap_set(DMA_MEMCPY, pdma->dma_dev.cap_mask); + + ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); + if (ret) + pr_warn("*** Failed to set DMA mask. Fall back to default.\n"); +
drivers/dma/sf-pdma/Kconfig
Quoted 10 lines
drivers/dma/sf-pdma/Kconfig new file +10
-0+ /* Setup DMA APIs */ + pdma->dma_dev.device_alloc_chan_resources = + sf_pdma_alloc_chan_resources; + pdma->dma_dev.device_free_chan_resources = + sf_pdma_free_chan_resources; + pdma->dma_dev.device_tx_status = sf_pdma_tx_status; + pdma->dma_dev.device_prep_dma_memcpy = sf_pdma_prep_dma_memcpy; + pdma->dma_dev.device_config = sf_pdma_slave_config; + pdma->dma_dev.device_terminate_all = sf_pdma_terminate_all; + pdma->dma_dev.device_issue_pending = sf_pdma_issue_pending;
please set the capabilities of the controller, width, direction, granularity etc!
drivers/dma/sf-pdma/Kconfig
Quoted 5 lines
drivers/dma/sf-pdma/Kconfig new file +5
-0+static int sf_pdma_remove(struct platform_device *pdev) +{ + struct sf_pdma *pdma = platform_get_drvdata(pdev); + + dma_async_device_unregister(&pdma->dma_dev);
since you used devm_irq_() you have irq which is running, tasklets which maybe schedule and can be scheduled again including the vchan one!
Signature · 1 line
~Vinod
PATCH v4 4/4 MAINTAINERS: Add Green as SiFive PDMA driver maintainer
In reply to Green WanUpdate MAINTAINERS for SiFive PDMA driver.
--- MAINTAINERS | 6 ++++++ 1 file changed, 6 insertions(+)
MAINTAINERS +6 -0
@@ -14779,6 +14779,12 @@ F: drivers/media/usb/siano/ F: drivers/media/usb/siano/ F: drivers/media/mmc/siano/ +SIFIVE PDMA DRIVER +M: Green Wan <[email protected]> +S: Maintained +F: drivers/dma/sf-pdma/ +F: Documentation/devicetree/bindings/dma/sifive,fu540-c000-pdma.yaml + SIFIVE DRIVERS M: Palmer Dabbelt <[email protected]> M: Paul Walmsley <[email protected]>
Signature · 1 line
2.17.1