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 17, 2019

Subsystems (3)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Green Wan

author
#0 lore raw

PATCH 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 | 609 ++++++++++++++++++++++++++++++++++
 drivers/dma/sf-pdma/sf-pdma.h | 124 +++++++
 7 files changed, 744 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 +609 -0

609 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
#1 lore raw
I love your patch! Yet something to improve:

Hi Green,

I love your patch! Yet something to improve:

[auto build test ERROR on linus/master]
[cannot apply to v5.3 next-20190916]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Green-Wan/dmaengine-sf-pdma-Add-platform-dma-driver/20190917-142826
config: i386-allmodconfig (attached as .config)
compiler: gcc-7 (Debian 7.4.0-11) 7.4.0 reproduce:

        # save the attached .config to linux build tree
        make ARCH=i386 

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

drivers/dma/sf-pdma/sf-pdma.c: In function 'sf_pdma_fill_desc':

>> drivers/dma/sf-pdma/sf-pdma.c:80:2: error: implicit declaration of function 'writeq'; did you mean 'writel'? [-Werror=implicit-function-declaration]
     writeq(size, regs->xfer_size);
     ^~~~~~
     writel
   drivers/dma/sf-pdma/sf-pdma.c: In function 'sf_pdma_desc_residue':
>> drivers/dma/sf-pdma/sf-pdma.c:188:12: error: implicit declaration of function 'readq'; did you mean 'readl'? [-Werror=implicit-function-declaration]
     residue = readq(regs->residue);
               ^~~~~
               readl
   drivers/dma/sf-pdma/sf-pdma.c: In function 'sf_pdma_free_desc':
   drivers/dma/sf-pdma/sf-pdma.c:308:16: warning: unused variable 'flags' [-Wunused-variable]
     unsigned long flags;
                   ^~~~~

cc1: some warnings being treated as errors

vim +80 drivers/dma/sf-pdma/sf-pdma.c

    71	
    72	static void sf_pdma_fill_desc(struct sf_pdma_chan *chan,
    73				      u64 dst,
    74				      u64 src,
    75				      u64 size)
    76	{
    77		struct pdma_regs *regs = &chan->regs;
    78	
    79		writel(PDMA_FULL_SPEED, regs->xfer_type);
  > 80		writeq(size, regs->xfer_size);
    81		writeq(dst, regs->dst_addr);
    82		writeq(src, regs->src_addr);
    83	}
    84	
    85	void sf_pdma_disclaim_chan(struct sf_pdma_chan *chan)
    86	{
    87		struct pdma_regs *regs = &chan->regs;
    88	
    89		writel(PDMA_CLEAR_CTRL, regs->ctrl);
    90	}
    91	
    92	struct dma_async_tx_descriptor *
    93		sf_pdma_prep_dma_memcpy(struct dma_chan *dchan,
    94					dma_addr_t dest,
    95					dma_addr_t src,
    96					size_t len,
    97					unsigned long flags)
    98	{
    99		struct sf_pdma_chan *chan = to_sf_pdma_chan(dchan);
   100		struct sf_pdma_desc *desc;
   101	
   102		if (!chan || !len || !dest || !src) {
   103			pr_debug("%s: Please check dma len, dest, src!\n", __func__);
   104			return NULL;
   105		}
   106	
   107		desc = sf_pdma_alloc_desc(chan);
   108		if (!desc)
   109			return NULL;
   110	
   111		desc->in_use = true;
   112		desc->dirn = DMA_MEM_TO_MEM;
   113		desc->async_tx = vchan_tx_prep(&chan->vchan, &desc->vdesc, flags);
   114	
   115		spin_lock_irqsave(&chan->lock, flags);
   116		chan->desc = desc;
   117		sf_pdma_fill_desc(desc->chan, dest, src, len);
   118		spin_unlock_irqrestore(&chan->lock, flags);
   119	
   120		return desc->async_tx;
   121	}
   122	
   123	static void sf_pdma_unprep_slave_dma(struct sf_pdma_chan *chan)
   124	{
   125		if (chan->dma_dir != DMA_NONE)
   126			dma_unmap_resource(chan->vchan.chan.device->dev,
   127					   chan->dma_dev_addr,
   128					   chan->dma_dev_size,
   129					   chan->dma_dir, 0);
   130		chan->dma_dir = DMA_NONE;
   131	}
   132	
   133	static int sf_pdma_slave_config(struct dma_chan *dchan,
   134					struct dma_slave_config *cfg)
   135	{
   136		struct sf_pdma_chan *chan = to_sf_pdma_chan(dchan);
   137	
   138		memcpy(&chan->cfg, cfg, sizeof(*cfg));
   139		sf_pdma_unprep_slave_dma(chan);
   140	
   141		return 0;
   142	}
   143	
   144	static int sf_pdma_alloc_chan_resources(struct dma_chan *dchan)
   145	{
   146		struct sf_pdma_chan *chan = to_sf_pdma_chan(dchan);
   147		struct pdma_regs *regs = &chan->regs;
   148	
   149		dma_cookie_init(dchan);
   150		writel(PDMA_CLAIM_MASK, regs->ctrl);
   151	
   152		return 0;
   153	}
   154	
   155	static void sf_pdma_disable_request(struct sf_pdma_chan *chan)
   156	{
   157		struct pdma_regs *regs = &chan->regs;
   158	
   159		writel(readl(regs->ctrl) & ~PDMA_RUN_MASK, regs->ctrl);
   160	}
   161	
   162	static void sf_pdma_free_chan_resources(struct dma_chan *dchan)
   163	{
   164		struct sf_pdma_chan *chan = to_sf_pdma_chan(dchan);
   165		unsigned long flags;
   166		LIST_HEAD(head);
   167	
   168		spin_lock_irqsave(&chan->vchan.lock, flags);
   169		sf_pdma_disable_request(chan);
   170		kfree(chan->desc);
   171		chan->desc = NULL;
   172		vchan_get_all_descriptors(&chan->vchan, &head);
   173		sf_pdma_unprep_slave_dma(chan);
   174		vchan_dma_desc_free_list(&chan->vchan, &head);
   175		sf_pdma_disclaim_chan(chan);
   176		spin_unlock_irqrestore(&chan->vchan.lock, flags);
   177	}
   178	
   179	static size_t sf_pdma_desc_residue(struct sf_pdma_chan *chan,
   180					   dma_cookie_t cookie)
   181	{
   182		struct virt_dma_desc *vd = NULL;
   183		struct sf_pdma_desc *desc;
   184		struct pdma_regs *regs = &chan->regs;
   185		unsigned long flags;
   186		u64 residue;
   187	
 > 188		residue = readq(regs->residue);

189
190 chan->status = residue ? DMA_IN_PROGRESS : DMA_COMPLETE;
191
192 spin_lock_irqsave(&chan->vchan.lock, flags);
193 vd = vchan_find_desc(&chan->vchan, cookie);
194 if (!vd)
195 goto out;
196
197 desc = to_sf_pdma_desc(vd);
198
199 spin_unlock_irqrestore(&chan->vchan.lock, flags);
200
201 if (desc && chan->status == DMA_COMPLETE)
202 vchan_tx_desc_free(desc->async_tx);
203
204 return residue;
205
206 out:
207 spin_unlock_irqrestore(&chan->vchan.lock, flags);
208 return residue;
209 }
210

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#2 lore raw
In reply to Green Wan
I love your patch! Yet something to improve:

Hi Green,

I love your patch! Yet something to improve:

[auto build test ERROR on linus/master]
[cannot apply to v5.3 next-20190916]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Green-Wan/dmaengine-sf-pdma-Add-platform-dma-driver/20190917-142826
config: arm-allmodconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (GCC) 7.4.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=arm

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

drivers/dma/sf-pdma/sf-pdma.c: In function 'sf_pdma_fill_desc':
drivers/dma/sf-pdma/sf-pdma.c:80:2: error: implicit declaration of function 'writeq'; did you mean 'writel'? [-Werror=implicit-function-declaration]

     writeq(size, regs->xfer_size);
     ^~~~~~
     writel
   drivers/dma/sf-pdma/sf-pdma.c: In function 'sf_pdma_desc_residue':
>> drivers/dma/sf-pdma/sf-pdma.c:188:12: error: implicit declaration of function 'readq'; did you mean 'readb'? [-Werror=implicit-function-declaration]
     residue = readq(regs->residue);
               ^~~~~
               readb
   drivers/dma/sf-pdma/sf-pdma.c: In function 'sf_pdma_free_desc':
   drivers/dma/sf-pdma/sf-pdma.c:308:16: warning: unused variable 'flags' [-Wunused-variable]
     unsigned long flags;
                   ^~~~~

cc1: some warnings being treated as errors

vim +188 drivers/dma/sf-pdma/sf-pdma.c

    71	
    72	static void sf_pdma_fill_desc(struct sf_pdma_chan *chan,
    73				      u64 dst,
    74				      u64 src,
    75				      u64 size)
    76	{
    77		struct pdma_regs *regs = &chan->regs;
    78	
    79		writel(PDMA_FULL_SPEED, regs->xfer_type);
  > 80		writeq(size, regs->xfer_size);
    81		writeq(dst, regs->dst_addr);
    82		writeq(src, regs->src_addr);
    83	}
    84	
    85	void sf_pdma_disclaim_chan(struct sf_pdma_chan *chan)
    86	{
    87		struct pdma_regs *regs = &chan->regs;
    88	
    89		writel(PDMA_CLEAR_CTRL, regs->ctrl);
    90	}
    91	
    92	struct dma_async_tx_descriptor *
    93		sf_pdma_prep_dma_memcpy(struct dma_chan *dchan,
    94					dma_addr_t dest,
    95					dma_addr_t src,
    96					size_t len,
    97					unsigned long flags)
    98	{
    99		struct sf_pdma_chan *chan = to_sf_pdma_chan(dchan);
   100		struct sf_pdma_desc *desc;
   101	
   102		if (!chan || !len || !dest || !src) {
   103			pr_debug("%s: Please check dma len, dest, src!\n", __func__);
   104			return NULL;
   105		}
   106	
   107		desc = sf_pdma_alloc_desc(chan);
   108		if (!desc)
   109			return NULL;
   110	
   111		desc->in_use = true;
   112		desc->dirn = DMA_MEM_TO_MEM;
   113		desc->async_tx = vchan_tx_prep(&chan->vchan, &desc->vdesc, flags);
   114	
   115		spin_lock_irqsave(&chan->lock, flags);
   116		chan->desc = desc;
   117		sf_pdma_fill_desc(desc->chan, dest, src, len);
   118		spin_unlock_irqrestore(&chan->lock, flags);
   119	
   120		return desc->async_tx;
   121	}
   122	
   123	static void sf_pdma_unprep_slave_dma(struct sf_pdma_chan *chan)
   124	{
   125		if (chan->dma_dir != DMA_NONE)
   126			dma_unmap_resource(chan->vchan.chan.device->dev,
   127					   chan->dma_dev_addr,
   128					   chan->dma_dev_size,
   129					   chan->dma_dir, 0);
   130		chan->dma_dir = DMA_NONE;
   131	}
   132	
   133	static int sf_pdma_slave_config(struct dma_chan *dchan,
   134					struct dma_slave_config *cfg)
   135	{
   136		struct sf_pdma_chan *chan = to_sf_pdma_chan(dchan);
   137	
   138		memcpy(&chan->cfg, cfg, sizeof(*cfg));
   139		sf_pdma_unprep_slave_dma(chan);
   140	
   141		return 0;
   142	}
   143	
   144	static int sf_pdma_alloc_chan_resources(struct dma_chan *dchan)
   145	{
   146		struct sf_pdma_chan *chan = to_sf_pdma_chan(dchan);
   147		struct pdma_regs *regs = &chan->regs;
   148	
   149		dma_cookie_init(dchan);
   150		writel(PDMA_CLAIM_MASK, regs->ctrl);
   151	
   152		return 0;
   153	}
   154	
   155	static void sf_pdma_disable_request(struct sf_pdma_chan *chan)
   156	{
   157		struct pdma_regs *regs = &chan->regs;
   158	
   159		writel(readl(regs->ctrl) & ~PDMA_RUN_MASK, regs->ctrl);
   160	}
   161	
   162	static void sf_pdma_free_chan_resources(struct dma_chan *dchan)
   163	{
   164		struct sf_pdma_chan *chan = to_sf_pdma_chan(dchan);
   165		unsigned long flags;
   166		LIST_HEAD(head);
   167	
   168		spin_lock_irqsave(&chan->vchan.lock, flags);
   169		sf_pdma_disable_request(chan);
   170		kfree(chan->desc);
   171		chan->desc = NULL;
   172		vchan_get_all_descriptors(&chan->vchan, &head);
   173		sf_pdma_unprep_slave_dma(chan);
   174		vchan_dma_desc_free_list(&chan->vchan, &head);
   175		sf_pdma_disclaim_chan(chan);
   176		spin_unlock_irqrestore(&chan->vchan.lock, flags);
   177	}
   178	
   179	static size_t sf_pdma_desc_residue(struct sf_pdma_chan *chan,
   180					   dma_cookie_t cookie)
   181	{
   182		struct virt_dma_desc *vd = NULL;
   183		struct sf_pdma_desc *desc;
   184		struct pdma_regs *regs = &chan->regs;
   185		unsigned long flags;
   186		u64 residue;
   187	
 > 188		residue = readq(regs->residue);

189
190 chan->status = residue ? DMA_IN_PROGRESS : DMA_COMPLETE;
191
192 spin_lock_irqsave(&chan->vchan.lock, flags);
193 vd = vchan_find_desc(&chan->vchan, cookie);
194 if (!vd)
195 goto out;
196
197 desc = to_sf_pdma_desc(vd);
198
199 spin_unlock_irqrestore(&chan->vchan.lock, flags);
200
201 if (desc && chan->status == DMA_COMPLETE)
202 vchan_tx_desc_free(desc->async_tx);
203
204 return residue;
205
206 out:
207 spin_unlock_irqrestore(&chan->vchan.lock, flags);
208 return residue;
209 }
210

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv