Skip to contentSkip to conversation

dma: Add Freescale eDMA engine driver support

PATCH In review Jingchang Lu 2 participants 6 messages Sep 5, 2013 – Sep 23, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 3/3 dma: Add Freescale eDMA engine driver support

Add Freescale enhanced direct memory(eDMA) controller support. The eDMA controller deploys DMAMUXs routing DMA request sources(slot) to eDMA channels.
This module can be found on Vybrid and LS-1 SoCs.

---
changes in v5:
config slave_id when dmaengine_slave_config intead of channel request. adding residue calculation and dma pause/resume device control.

changes in v4:
using exact compatible string in binding document.

changes in v3:
handle all pending interrupt one time.
add protect lock on dma transfer complete handling. change desc and tcd alloc flag to GFP_NOWAIT. add sanity check and error messages.

changes in v2:
using generic dma-channels property instead of fsl,dma-channel. rename the binding document to fsl-edma.txt.

 Documentation/devicetree/bindings/dma/fsl-edma.txt |  84 ++
 drivers/dma/Kconfig                                |  10 +
 drivers/dma/Makefile                               |   1 +
 drivers/dma/fsl-edma.c                             | 925 +++++++++++++++++++++
 4 files changed, 1020 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/fsl-edma.txt
 create mode 100644 drivers/dma/fsl-edma.c
Documentation/devicetree/bindings/dma/fsl-edma.txt new file +84 -0
new file mode 100644
index 0000000..60a8cb2
@@ -0,0 +1,84 @@
+* Freescale enhanced Direct Memory Access(eDMA) Controller
+
+The eDMA engine deploys DMAMUXs routing request sources(slot) to
+eDMA controller channels.
+
+* eDMA Controller
+Required properties:
+- compatible :
+  - "fsl,vf610-edma" for eDMA used similar to that on Vybrid vf610 SoC
+- reg : Should contain eDMA registers location and length
+- interrupts : Should contain eDMA interrupt
+- interrupt-names : Should be "edma-tx" for tx interrupt and
+  "edma-err" for err interrupt
+- #dma-cells : Must be <2>.
+  The first cell specifies the DMAMUX ID. Specific request source
+  can only be routed by specific DMAMUXs.
+  the second cell specifies the request source(slot) ID.
+  See include/dt-bindings/dma/<soc>-edma.h for all the supported
+  request source IDs.
+- dma-channels : Number of channels supported by the controller
+- fsl,dma-mux : Phandle of the DMAMUXs deployed by the controller
+
+
+* DMAMUX
+Required properties:
+- reg : Should contain DMAMUX registers location and length
+- fsl,dmamux-id : DMAMUX ID. DMAMUX IDs are unique in each eDMA controller.
+  inside one eDMA controller, specific request source can only be routed by
+  one of its DMAMUXs.
+  However Specific request source may be routed to different eDMA controller,
+  thus all the DMAMUXs sharing a the same request sources have the same ID.
+- clocks : Phandle of the clock used by the DMAMUX
+- clock-names : The clock names
+
+Below is the eDMA controller and DMAMUX association, and DMAMUX IDs assignment
+On Vybrid vf610 SoC, DMAMUX0 and DMAMU3 share the same request source group,
+and DMAMUX1 and DMAMU2 share the same request source group.
+
+eDMA controller		DMAMUXs		DMAMUX ID
+-------------------------------------------------
+eDMA0			DMAMUX0		0
+			DMAMUX1		1
+
+eDMA1			DMAMUX2		1
+			DMAMUX3		0
+
+Examples:
+
+edma0: dma-controller at 40018000 {
+	#dma-cells = <2>;
+	compatible = "fsl,vf610-edma";
+	reg = <0x40018000 0x2000>;
+	interrupts = <0 8 0x04>, <0 9 0x04>;
+	interrupt-names = "edma-tx", "edma-err";
+	dma-channels = <32>;
+	fsl,edma-mux = <&dmamux0>, <&dmamux1>;
+};
+
+dmamux0: dmamux at 40024000 {
+	reg = <0x40024000 0x1000>;
+	fsl,dmamux-id = <0>;
+	clocks = <&clks VF610_CLK_DMAMUX0>;
+	clock-names = "dmamux";
+};
+
+
+* DMA clients
+DMA client drivers that uses the DMA function must use the format described
+in the dma.txt file, using a three-cell specifier for each channel: a phandle
+plus two integer cells as described above.
+
+Examples:
+
+sai2: sai at 40031000 {
+	compatible = "fsl,vf610-sai";
+	reg = <0x40031000 0x1000>;
+	interrupts = <0 86 0x04>;
+	clocks = <&clks VF610_CLK_SAI2>;
+	clock-names = "sai";
+	dma-names = "tx", "rx";
+	dmas = <&edma0 0 VF610_EDMA_MUXID0_SAI2_TX>,
+		<&edma0 0 VF610_EDMA_MUXID0_SAI2_RX>;
+	status = "disabled";
+};
drivers/dma/Kconfig +10 -0
index 526ec77..7d7604d 100644
@@ -317,6 +317,16 @@ config K3_DMA
 	  Support the DMA engine for Hisilicon K3 platform
 	  devices.
 
+config FSL_EDMA
+	tristate "Freescale eDMA engine support"
+	depends on OF
+	select DMA_ENGINE
+	select DMA_VIRTUAL_CHANNELS
+	help
+	  Support the Freescale eDMA engine with DMAMUXs managing route
+	  between request sources(slot) and eDMA engine channels.
+	  This module can be found on Freescale Vybrid and LS-1 SoCs.
+
 config DMA_ENGINE
 	bool
 
drivers/dma/Makefile +1 -0
index cb5a77a..bb50311 100644
@@ -41,3 +41,4 @@ obj-$(CONFIG_MMP_PDMA) += mmp_pdma.o
 obj-$(CONFIG_DMA_JZ4740) += dma-jz4740.o
 obj-$(CONFIG_K3_DMA) += k3dma.o
 obj-$(CONFIG_TI_CPPI41) += cppi41.o
+obj-$(CONFIG_FSL_EDMA) += fsl-edma.o
drivers/dma/fsl-edma.c new file +925 -0

925 lines not on this page · raw message

Signature · 1 line
1.8.0
#1 lore raw
Quoted 113 lines · Jingchang Lu

Add Freescale enhanced direct memory(eDMA) controller support. The eDMA controller deploys DMAMUXs routing DMA request sources(slot) to eDMA channels.
This module can be found on Vybrid and LS-1 SoCs.

---
changes in v5:
config slave_id when dmaengine_slave_config intead of channel request. adding residue calculation and dma pause/resume device control.

changes in v4:
using exact compatible string in binding document.

changes in v3:
handle all pending interrupt one time.
add protect lock on dma transfer complete handling. change desc and tcd alloc flag to GFP_NOWAIT. add sanity check and error messages.

changes in v2:
using generic dma-channels property instead of fsl,dma-channel. rename the binding document to fsl-edma.txt.

 Documentation/devicetree/bindings/dma/fsl-edma.txt |  84 ++
 drivers/dma/Kconfig                                |  10 +
 drivers/dma/Makefile                               |   1 +
 drivers/dma/fsl-edma.c                             | 925 +++++++++++++++++++++
 4 files changed, 1020 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/fsl-edma.txt
 create mode 100644 drivers/dma/fsl-edma.c
Documentation/devicetree/bindings/dma/fsl-edma.txt new file +74 -0
new file mode 100644
index 0000000..60a8cb2
@@ -0,0 +1,84 @@
+* Freescale enhanced Direct Memory Access(eDMA) Controller
+
+The eDMA engine deploys DMAMUXs routing request sources(slot) to
+eDMA controller channels.
+
+* eDMA Controller
+Required properties:
+- compatible :
+  - "fsl,vf610-edma" for eDMA used similar to that on Vybrid vf610 SoC
+- reg : Should contain eDMA registers location and length
+- interrupts : Should contain eDMA interrupt
+- interrupt-names : Should be "edma-tx" for tx interrupt and
+  "edma-err" for err interrupt
+- #dma-cells : Must be <2>.
+  The first cell specifies the DMAMUX ID. Specific request source
+  can only be routed by specific DMAMUXs.
+  the second cell specifies the request source(slot) ID.
+  See include/dt-bindings/dma/<soc>-edma.h for all the supported
+  request source IDs.
+- dma-channels : Number of channels supported by the controller
+- fsl,dma-mux : Phandle of the DMAMUXs deployed by the controller
+
+
+* DMAMUX
+Required properties:
+- reg : Should contain DMAMUX registers location and length
+- fsl,dmamux-id : DMAMUX ID. DMAMUX IDs are unique in each eDMA controller.
+  inside one eDMA controller, specific request source can only be routed by
+  one of its DMAMUXs.
+  However Specific request source may be routed to different eDMA controller,
+  thus all the DMAMUXs sharing a the same request sources have the same ID.
+- clocks : Phandle of the clock used by the DMAMUX
+- clock-names : The clock names
+
+Below is the eDMA controller and DMAMUX association, and DMAMUX IDs assignment
+On Vybrid vf610 SoC, DMAMUX0 and DMAMU3 share the same request source group,
+and DMAMUX1 and DMAMU2 share the same request source group.
+
+eDMA controller		DMAMUXs		DMAMUX ID
+-------------------------------------------------
+eDMA0			DMAMUX0		0
+			DMAMUX1		1
+
+eDMA1			DMAMUX2		1
+			DMAMUX3		0
+
+Examples:
+
+edma0: dma-controller at 40018000 {
+	#dma-cells = <2>;
+	compatible = "fsl,vf610-edma";
+	reg = <0x40018000 0x2000>;
+	interrupts = <0 8 0x04>, <0 9 0x04>;
+	interrupt-names = "edma-tx", "edma-err";
+	dma-channels = <32>;
+	fsl,edma-mux = <&dmamux0>, <&dmamux1>;
+};
+
+dmamux0: dmamux at 40024000 {
+	reg = <0x40024000 0x1000>;
+	fsl,dmamux-id = <0>;
+	clocks = <&clks VF610_CLK_DMAMUX0>;
+	clock-names = "dmamux";
+};
+
+
+* DMA clients
+DMA client drivers that uses the DMA function must use the format described
+in the dma.txt file, using a three-cell specifier for each channel: a phandle
+plus two integer cells as described above.
+
+Examples:
+
+sai2: sai at 40031000 {

Documentation/devicetree/bindings/dma/fsl-edma.txt line 84

Quoted 10 lines
Documentation/devicetree/bindings/dma/fsl-edma.txt new file +10 -0
+	compatible = "fsl,vf610-sai";
+	reg = <0x40031000 0x1000>;
+	interrupts = <0 86 0x04>;
+	clocks = <&clks VF610_CLK_SAI2>;
+	clock-names = "sai";
+	dma-names = "tx", "rx";
+	dmas = <&edma0 0 VF610_EDMA_MUXID0_SAI2_TX>,
+		<&edma0 0 VF610_EDMA_MUXID0_SAI2_RX>;
+	status = "disabled";
+};

I need ACK from DT maintainers on the above parts

Documentation/devicetree/bindings/dma/fsl-edma.txt

Quoted 10 lines
Documentation/devicetree/bindings/dma/fsl-edma.txt new file +10 -0
+static int fsl_edma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
+		unsigned long arg)
+{
+	struct fsl_edma_chan *fsl_chan = to_fsl_edma_chan(chan);
+	struct dma_slave_config *cfg = (void *)arg;
+
+	switch (cmd) {
+	case DMA_TERMINATE_ALL:
+		fsl_edma_disable_request(fsl_chan);
+		fsl_chan->edesc = NULL;

you need to hold the lock here to prevent race here!

Quoted 11 lines
Documentation/devicetree/bindings/dma/fsl-edma.txt new file +11 -0
+		vchan_free_chan_resources(&fsl_chan->vchan);
+		return 0;
+
+	case DMA_SLAVE_CONFIG:
+		fsl_chan->fsc.dir = cfg->direction;
+		if (cfg->direction == DMA_DEV_TO_MEM) {
+			fsl_chan->fsc.dev_addr = cfg->src_addr;
+			fsl_chan->fsc.addr_width = cfg->src_addr_width;
+			fsl_chan->fsc.burst = cfg->src_maxburst;
+			fsl_chan->fsc.attr = fsl_edma_get_tcd_attr(cfg->src_addr_width);
+		} else if (cfg->direction == DMA_MEM_TO_DEV) {

Documentation/devicetree/bindings/dma/fsl-edma.txt

Quoted 10 lines
Documentation/devicetree/bindings/dma/fsl-edma.txt new file +10 -0
+			fsl_chan->fsc.dev_addr = cfg->dst_addr;
+			fsl_chan->fsc.addr_width = cfg->dst_addr_width;
+			fsl_chan->fsc.burst = cfg->dst_maxburst;
+			fsl_chan->fsc.attr = fsl_edma_get_tcd_attr(cfg->dst_addr_width);
+		} else {
+			return -EINVAL;
+		}
+
+		if (!cfg->slave_id) {
+			return -EINVAL;

should you check for this first, you wrote the channel with config above and now returning error?

Documentation/devicetree/bindings/dma/fsl-edma.txt

Quoted 9 lines
Documentation/devicetree/bindings/dma/fsl-edma.txt new file +9 -0
+		} else if (fsl_chan->fsc.slave_id != cfg->slave_id) {
+			fsl_edmamux_disable_chan(fsl_chan);
+			fsl_edmamux_enable_chan(fsl_chan, cfg->slave_id);
+		}
+		return 0;
+
+	case DMA_PAUSE:
+		if (fsl_chan->edesc)
+			fsl_edma_disable_request(fsl_chan);

racy here too...

Documentation/devicetree/bindings/dma/fsl-edma.txt

Quoted 5 lines
Documentation/devicetree/bindings/dma/fsl-edma.txt new file +5 -0
+		return 0;
+
+	case DMA_RESUME:
+		if (fsl_chan->edesc)
+			fsl_edma_enable_request(fsl_chan);

ditto

Quoted 18 lines
Documentation/devicetree/bindings/dma/fsl-edma.txt new file +17 -0
+		return 0;
+
+	default:
+		return -ENXIO;
+	}
+}
+
 
+static enum dma_status fsl_edma_tx_status(struct dma_chan *chan,
+		dma_cookie_t cookie, struct dma_tx_state *txstate)
+{
+	struct fsl_edma_chan *fsl_chan = to_fsl_edma_chan(chan);
+	struct virt_dma_desc *vdesc;
+	enum dma_status status;
+	unsigned long flags;
+
+	if (fsl_chan->status == DMA_ERROR)
+		status = DMA_ERROR;

Documentation/devicetree/bindings/dma/fsl-edma.txt

Quoted 10 lines
Documentation/devicetree/bindings/dma/fsl-edma.txt new file +10 -0
+	else
+		status = dma_cookie_status(chan, cookie, txstate);
+
+	if (status == DMA_SUCCESS || !txstate)
+		return status;
+
+	spin_lock_irqsave(&fsl_chan->vchan.lock, flags);
+	vdesc = vchan_find_desc(&fsl_chan->vchan, cookie);
+	if (fsl_chan->edesc && cookie == fsl_chan->edesc->vdesc.tx.cookie)
+		txstate->residue = fsl_edma_desc_residue(fsl_chan, vdesc, 1);

why not use true/false for the last bool arg?

Documentation/devicetree/bindings/dma/fsl-edma.txt

Quoted 10 lines
Documentation/devicetree/bindings/dma/fsl-edma.txt new file +9 -0
+	else if (vdesc)
+		txstate->residue = fsl_edma_desc_residue(fsl_chan, vdesc, 0);
+	else
+		txstate->residue = 0;
+
+	spin_unlock_irqrestore(&fsl_chan->vchan.lock, flags);
+
+	return status;
+}

~Vinod

#2 lore raw
Quoted 11 lines

-----Original Message-----
From: Vinod Koul [mailto:vinod.koul at intel.com]
Sent: Tuesday, September 17, 2013 12:54 PM
To: Lu Jingchang-B35083
Cc: djbw at fb.com; shawn.guo at linaro.org; linux-kernel at vger.kernel.org; linux-arm-kernel at lists.infradead.org; devicetree at vger.kernel.org; Wang Huan-B18965
Subject: Re: [PATCH 3/3] dma: Add Freescale eDMA engine driver support

Quoted 1 line

I need ACK from DT maintainers on the above parts

Should I cc this to one of the DT maintainers? Thanks.

Quoted 13 lines
Quoted 2 lines

+static int fsl_edma_control(struct dma_chan *chan, enum dma_ctrl_cmd

cmd,

drivers/dma/fsl-edma.c line 275

Quoted 9 lines
drivers/dma/fsl-edma.c new file +9 -0
+		unsigned long arg)
+{
+	struct fsl_edma_chan *fsl_chan = to_fsl_edma_chan(chan);
+	struct dma_slave_config *cfg = (void *)arg;
+
+	switch (cmd) {
+	case DMA_TERMINATE_ALL:
+		fsl_edma_disable_request(fsl_chan);
+		fsl_chan->edesc = NULL;

you need to hold the lock here to prevent race here!

Thanks, I will fix this in the next version of the patch.

Quoted 19 lines
Quoted 19 lines
drivers/dma/fsl-edma.c new file +10 -0
+		vchan_free_chan_resources(&fsl_chan->vchan);
+		return 0;
+
+	case DMA_SLAVE_CONFIG:
+		fsl_chan->fsc.dir = cfg->direction;
+		if (cfg->direction == DMA_DEV_TO_MEM) {
+			fsl_chan->fsc.dev_addr = cfg->src_addr;
+			fsl_chan->fsc.addr_width = cfg->src_addr_width;
+			fsl_chan->fsc.burst = cfg->src_maxburst;
+			fsl_chan->fsc.attr = fsl_edma_get_tcd_attr(cfg-

src_addr_width);

drivers/dma/fsl-edma.c new file +5 -0
+		} else if (cfg->direction == DMA_MEM_TO_DEV) {
+			fsl_chan->fsc.dev_addr = cfg->dst_addr;
+			fsl_chan->fsc.addr_width = cfg->dst_addr_width;
+			fsl_chan->fsc.burst = cfg->dst_maxburst;
+			fsl_chan->fsc.attr = fsl_edma_get_tcd_attr(cfg-

dst_addr_width);

(quoted diff) +1 -0
+		} else {
Quoted 8 lines

drivers/dma/fsl-edma.c line 296

Quoted 5 lines
drivers/dma/fsl-edma.c new file +5 -0
+			return -EINVAL;
+		}
+
+		if (!cfg->slave_id) {
+			return -EINVAL;

should you check for this first, you wrote the channel with config above and now
returning error?

Yes, the slave id should be checked first, thanks!

Quoted 5 lines

drivers/dma/fsl-edma.c line 376

Quoted 4 lines
drivers/dma/fsl-edma.c new file +4 -0
+	spin_lock_irqsave(&fsl_chan->vchan.lock, flags);
+	vdesc = vchan_find_desc(&fsl_chan->vchan, cookie);
+	if (fsl_chan->edesc && cookie == fsl_chan->edesc->vdesc.tx.cookie)
+		txstate->residue = fsl_edma_desc_residue(fsl_chan, vdesc, 1);

why not use true/false for the last bool arg?

Thanks, I will use true/false instead.

Best Regards,
Jingchang

#3 lore raw
In reply to Vinod Koul
Quoted 8 lines

-----Original Message-----
From: Vinod Koul [mailto:vinod.koul at intel.com]
Sent: Tuesday, September 17, 2013 12:54 PM
To: Lu Jingchang-B35083
Cc: djbw at fb.com; shawn.guo at linaro.org; linux-kernel at vger.kernel.org; linux-arm-kernel at lists.infradead.org; devicetree at vger.kernel.org; Wang Huan-B18965
Subject: Re: [PATCH 3/3] dma: Add Freescale eDMA engine driver support

Quoted 4 lines

drivers/dma/fsl-edma.c line 305

Quoted 3 lines
drivers/dma/fsl-edma.c new file +3 -0
+	case DMA_PAUSE:
+		if (fsl_chan->edesc)
+			fsl_edma_disable_request(fsl_chan);

racy here too...

It only set the channel HW register, no list is handled, is lock needed here? Thanks!

Best Regards,
Jingchang

#4 lore raw
Quoted 6 lines · On Tue, Sep 17, 2013 at 08:08:46AM +0000, Lu Jingchang-B35083 wrote:
Quoted 4 lines

drivers/dma/fsl-edma.c line 305

Quoted 3 lines
drivers/dma/fsl-edma.c new file +3 -0
+	case DMA_PAUSE:
+		if (fsl_chan->edesc)
+			fsl_edma_disable_request(fsl_chan);

racy here too...

It only set the channel HW register, no list is handled, is lock needed here? Thanks!

well thats the point while you are terminating the current trasnaction can complete and then start another one. You want to try and prevent these case also. Here you are neither locking the HW access nor the the list, so its juts waiting to crash!

~Vinod

#5 lore raw
Quoted 16 lines

-----Original Message-----
From: Vinod Koul [mailto:vinod.koul at intel.com]
Sent: Monday, September 23, 2013 12:26 PM
To: Lu Jingchang-B35083
Cc: djbw at fb.com; shawn.guo at linaro.org; linux-kernel at vger.kernel.org; linux-arm-kernel at lists.infradead.org; devicetree at vger.kernel.org
Subject: Re: [PATCH 3/3] dma: Add Freescale eDMA engine driver support

Quoted 6 lines · On Tue, Sep 17, 2013 at 08:08:46AM +0000, Lu Jingchang-B35083 wrote:
Quoted 4 lines

drivers/dma/fsl-edma.c line 305

Quoted 3 lines
drivers/dma/fsl-edma.c new file +3 -0
+	case DMA_PAUSE:
+		if (fsl_chan->edesc)
+			fsl_edma_disable_request(fsl_chan);

racy here too...

It only set the channel HW register, no list is handled, is lock needed here? Thanks!

Quoted 7 lines

well thats the point while you are terminating the current trasnaction can
complete and then start another one. You want to try and prevent these case
also. Here you are neither locking the HW access nor the the list, so its juts
waiting to crash!

Thanks! I have sent out the new v6 patch last week with holding lock here, Could you please help review it?

Best Regards,
Jingchang