Skip to contentSkip to conversation

dmaengine: sf-pdma: add platform DMA support for HiFive Unleashed A00

PATCH Superseded Green Wan 2 participants 3 messages Sep 20, 2019 – Sep 26, 2019 1 message not in the archive

Subsystems (3)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Green Wan

author
#0 lore raw

PATCH v3 3/3 dmaengine: sf-pdma: add platform DMA support for HiFive Unleashed A00

Add 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

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)
   ------               ------
---
 MAINTAINERS                   |   1 +
 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 | 623 ++++++++++++++++++++++++++++++++++
 drivers/dma/sf-pdma/sf-pdma.h | 124 +++++++
 7 files changed, 758 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
MAINTAINERS +1 -0
index d0caa09a479e..c5f0662c9106 100644
@@ -14594,6 +14594,7 @@ 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
drivers/dma/Kconfig +2 -0
index 413efef5fbb6..f05a928f5a3d 100644
@@ -667,6 +667,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
index 5bddf6f8790f..77a552d970ae 100644
@@ -29,6 +29,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
new file mode 100644
index 000000000000..0e01a5728a79
@@ -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
new file mode 100644
index 000000000000..764552ab8d0a
@@ -0,0 +1 @@
+obj-$(CONFIG_SF_PDMA)   += sf-pdma.o
drivers/dma/sf-pdma/sf-pdma.c new file +623 -0

623 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
maintainer
#1 lore raw

Hi Green,

On 20-09-19, 17:01, Green Wan wrote:

Please make sure threading is *not* broken in your patch series. Atm they are all over place in my mailbox!

Quoted 2 lines

Link tag is used for discussion for the patch, please drop first one and add second one as a documentation for hardware

MAINTAINERS F: drivers/media/mmc/siano/ · line 14598

Quoted 10 lines
MAINTAINERS +1 -0
index d0caa09a479e..c5f0662c9106 100644
@@ -14594,6 +14594,7 @@ 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

What is this generated against, only one line?

MAINTAINERS F: drivers/media/mmc/siano/

Quoted 4 lines
MAINTAINERS +4 -0
+static void sf_pdma_fill_desc(struct sf_pdma_chan *chan,
+			      u64 dst,
+			      u64 src,
+			      u64 size)

Please align these to precceeding line open brace!

Quoted 28 lines
MAINTAINERS +28 -0
+{
+	struct pdma_regs *regs = &chan->regs;
+
+	writel(PDMA_FULL_SPEED, regs->xfer_type);
+	writeq(size, regs->xfer_size);
+	writeq(dst, regs->dst_addr);
+	writeq(src, regs->src_addr);
+}
+
+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 *
+	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__);

MAINTAINERS

Quoted 10 lines
MAINTAINERS +10 -0
+		return NULL;
+	}
+
+	desc = sf_pdma_alloc_desc(chan);
+	if (!desc)
+		return NULL;
+
+	desc->in_use = true;
+	desc->dirn = DMA_MEM_TO_MEM;
+	desc->async_tx = vchan_tx_prep(&chan->vchan, &desc->vdesc, flags);

No error checking?

MAINTAINERS

Quoted 13 lines
MAINTAINERS +13 -0
+
+	spin_lock_irqsave(&chan->lock, flags);
+	chan->desc = desc;
+	sf_pdma_fill_desc(desc->chan, dest, src, len);
+	spin_unlock_irqrestore(&chan->lock, flags);
+
+	return desc->async_tx;
+}
+
+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,

This is slave dma right, why are you unmapping? Also where is the mapping call?

MAINTAINERS

Quoted 13 lines
MAINTAINERS +13 -0
+				   chan->dma_dev_addr,
+				   chan->dma_dev_size,
+				   chan->dma_dir, 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 unprep?

Quoted 15 lines
MAINTAINERS +15 -0
+static enum dma_status
+sf_pdma_tx_status(struct dma_chan *dchan,
+		  dma_cookie_t cookie,
+		  struct dma_tx_state *txstate)
+{
+	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;
+	}

MAINTAINERS

Quoted 10 lines
MAINTAINERS +10 -0
+
+	spin_unlock_irqrestore(&chan->lock, flags);
+
+	status = dma_cookie_status(dchan, cookie, txstate);
+
+	if (status == DMA_COMPLETE)
+		return status;
+
+	if (!txstate)
+		return chan->status;

why not return status? Is that expected to be different than status?

MAINTAINERS

Quoted 5 lines
MAINTAINERS +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);

whay about irqs and tasklets, they are still enabled and can trigger!

Signature · 1 line
~Vinod

A message that is not in the archive (sent off-list or not yet received): CAJivOr4qZ7s20cME5=Fdw6G2-2JQGjO2ZT-ar2oHk3aad0R1gg@mail.gmail.com

maintainer
#3 lore raw
Quoted 8 lines · Green Wan

Hi Vinod,

Thanks for the comments. Check my reply below.

Quoted 2 lines · Vinod Koul

Hi Green,

Quoted 7 lines
Quoted 6 lines · Green Wan

Please make sure threading is *not* broken in your patch series. Atm they are all over place in my mailbox!

K, I'll check. Just simply git send to the list retrieved from "

get_maintainer.pl".

Well I guess you used each patch on git-send, you should pass on the whole series so that it threads as well

To test: you can send to yourself and check if threading is fine or not.

Quoted 13 lines
Quoted 13 lines

MAINTAINERS F: drivers/media/mmc/siano/ · line 14598

Quoted 10 lines
MAINTAINERS +1 -0
index d0caa09a479e..c5f0662c9106 100644
@@ -14594,6 +14594,7 @@ 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

What is this generated against, only one line?

Quoted 3 lines
Quoted 1 line

against patch v3 1/3. I split the maintainer modification into patch 1/3

and 3/3 to make "checkpatch.pl --strict" zero warning for both of them. And to give info more specifically, I can add

Ah, Can you please add these changes in a separate patch at the end please

Quoted 17 lines
Quoted 7 lines
Quoted 7 lines
MAINTAINERS +7 -0
+                                chan->dma_dev_addr,
+                                chan->dma_dev_size,
+                                chan->dma_dir, 0);
+     chan->dma_dir = DMA_NONE;
+}
+
+static int sf_pdma_slave_config(struct dma_chan *dchan,
Quoted 9 lines

MAINTAINERS

Quoted 6 lines
MAINTAINERS +6 -0
+                             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 unprep?

Quoted 1 line

I think the original idea from ./drivers/dma/fsl-edma* is to make sure the

We should fix that too!

Quoted 29 lines
Quoted 19 lines
Quoted 19 lines
MAINTAINERS +19 -0
+static enum dma_status
+sf_pdma_tx_status(struct dma_chan *dchan,
+               dma_cookie_t cookie,
+               struct dma_tx_state *txstate)
+{
+     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;
+     }
+
+     spin_unlock_irqrestore(&chan->lock, flags);
+
+     status = dma_cookie_status(dchan, cookie, txstate);
Quoted 10 lines

MAINTAINERS

Quoted 6 lines
MAINTAINERS +6 -0
+
+     if (status == DMA_COMPLETE)
+             return status;
+
+     if (!txstate)
+             return chan->status;

why not return status? Is that expected to be different than status?

Quoted 4 lines

Depends on the value set by dma_cookie_status(). At the moment, the value of chan->status should be DMA_IN_PROGRESS till changed by sf_pdma_desc_residue() or set to DMA_ERROR by err ISR. The value could be different between status and chan->status.

In case !txstate there is no sf_pdma_desc_residue() so it doesnt make sense to me to have return different things here!

Signature · 1 line
~Vinod