Skip to contentSkip to conversation

Add support for AHB DMA controller on Milbeaut series

PATCH Superseded [email protected] 3 participants 16 messages Jun 13, 2019 – Sep 6, 2019

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

cover Add support for AHB DMA controller on Milbeaut series

From: Jassi Brar <[email protected]>

The following series adds AHB DMA (HDMAC) controller support on Milbeaut series. This controller is capable of Mem<->MEM and DEV<->MEM transfer. But only DEV<->MEM is currently supported.

Jassi Brar (2):
dt-bindings: milbeaut-hdmac: Add Socionext Milbeaut HDMAC bindings
dmaengine: milbeaut-hdmac: Add HDMAC driver for Milbeaut platforms

 .../bindings/dma/milbeaut-m10v-hdmac.txt           |  54 ++
 drivers/dma/Kconfig                           |  10 +
 drivers/dma/Makefile                          |   1 +
 drivers/dma/milbeaut-hdmac.c                  | 572 ++++++++++++++++++
 4 files changed, 637 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt
 create mode 100644 drivers/dma/milbeaut-hdmac.c
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/2 dt-bindings: milbeaut-m10v-hdmac: Add Socionext Milbeaut HDMAC bindings

From: Jassi Brar <[email protected]>

Document the devicetree bindings for Socionext Milbeaut HDMAC controller. Controller has upto 8 floating channels, that need a predefined slave-id to work from a set of slaves.

---
 .../bindings/dma/milbeaut-m10v-hdmac.txt           | 54 +++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt
Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt new file +51 -0
new file mode 100644
index 000000000000..a104fcb9e73d
@@ -0,0 +1,51 @@
+* Milbeaut AHB DMA Controller
+
+Milbeaut AHB DMA controller has transfer capability bellow.
+ - memory to memory transfer
+ - device to memory transfer
+ - memory to device transfer
+
+Required property:
+- compatible:       Should be  "socionext,milbeaut-m10v-hdmac"
+- reg:              Should contain DMA registers location and length.
+- interrupts:       Should contain all of the per-channel DMA interrupts.
+- #dma-cells:       Should be 1. Specify the ID of the slave.
+- clocks:           Phandle to the clock used by the HDMAC module.
+
+
+Example:
+
+	hdmac1: hdmac@1e110000 {
+		compatible = "socionext,milbeaut-m10v-hdmac";
+		reg = <0x1e110000 0x10000>;
+		interrupts = <0 132 4>,
+			     <0 133 4>,
+			     <0 134 4>,
+			     <0 135 4>,
+			     <0 136 4>,
+			     <0 137 4>,
+			     <0 138 4>,
+			     <0 139 4>;
+		#dma-cells = <1>;
+		clocks = <&dummy_clk>;
+	};
+
+* DMA client
+
+Clients have to specify the DMA requests with phandles in a list.
+
+Required properties:
+- dmas:             List of one or more DMA request specifiers. One DMA request specifier
+                    consists of a phandle to the DMA controller followed by the integer
+                    specifying the request line.
+- dma-names:        List of string identifiers for the DMA requests. For the correct
+                    names, have a look at the specific client driver.
+
+Example:
+
+	sni_spi1: spi@1e800100 {
+		...
+		dmas = <&hdmac1 22>, <&hdmac1 21>;
+		dma-names = "tx", "rx";
+		...
+	};
Signature · 1 line
2.17.1
maintainer
#2 lore raw

Re: [PATCH 1/2] dt-bindings: milbeaut-m10v-hdmac: Add Socionext Milbeaut HDMAC bindings

Quoted 19 lines · On Wed, Jun 12, 2019 at 07:52:37PM -0500, [email protected] wrote:

From: Jassi Brar <[email protected]>

Document the devicetree bindings for Socionext Milbeaut HDMAC controller. Controller has upto 8 floating channels, that need a predefined slave-id to work from a set of slaves.

---
 .../bindings/dma/milbeaut-m10v-hdmac.txt           | 54 +++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt
Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt new file +1 -0
new file mode 100644
index 000000000000..a104fcb9e73d
@@ -0,0 +1,51 @@
+* Milbeaut AHB DMA Controller

Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt line 11

Quoted 10 lines
Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt new file +10 -0
+
+Milbeaut AHB DMA controller has transfer capability bellow.
+ - memory to memory transfer
+ - device to memory transfer
+ - memory to device transfer
+
+Required property:
+- compatible:       Should be  "socionext,milbeaut-m10v-hdmac"
+- reg:              Should contain DMA registers location and length.
+- interrupts:       Should contain all of the per-channel DMA interrupts.

How many?

Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt line 18

Quoted 7 lines
Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt new file +7 -0
+- #dma-cells:       Should be 1. Specify the ID of the slave.
+- clocks:           Phandle to the clock used by the HDMAC module.
+
+
+Example:
+
+	hdmac1: hdmac@1e110000 {

dma-controller@...

Quoted 7 lines
Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt new file +7 -0
+		compatible = "socionext,milbeaut-m10v-hdmac";
+		reg = <0x1e110000 0x10000>;
+		interrupts = <0 132 4>,
+			     <0 133 4>,
+			     <0 134 4>,
+			     <0 135 4>,
+			     <0 136 4>,

Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt line 35

Quoted 10 lines
Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt new file +10 -0
+			     <0 137 4>,
+			     <0 138 4>,
+			     <0 139 4>;
+		#dma-cells = <1>;
+		clocks = <&dummy_clk>;
+	};
+
+* DMA client
+
+Clients have to specify the DMA requests with phandles in a list.

Nothing specific to this binding here and the client side is already documented, so drop this section.

Quoted 19 lines
Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt new file +16 -0
+
+Required properties:
+- dmas:             List of one or more DMA request specifiers. One DMA request specifier
+                    consists of a phandle to the DMA controller followed by the integer
+                    specifying the request line.
+- dma-names:        List of string identifiers for the DMA requests. For the correct
+                    names, have a look at the specific client driver.
+
+Example:
+
+	sni_spi1: spi@1e800100 {
+		...
+		dmas = <&hdmac1 22>, <&hdmac1 21>;
+		dma-names = "tx", "rx";
+		...
+	};
Signature · 1 line
2.17.1
author
#3 lore raw

Re: [PATCH 1/2] dt-bindings: milbeaut-m10v-hdmac: Add Socionext Milbeaut HDMAC bindings

Quoted 25 lines · Rob Herring
Quoted 23 lines · On Wed, Jun 12, 2019 at 07:52:37PM -0500, [email protected] wrote:

From: Jassi Brar <[email protected]>

Document the devicetree bindings for Socionext Milbeaut HDMAC controller. Controller has upto 8 floating channels, that need a predefined slave-id to work from a set of slaves.

---
 .../bindings/dma/milbeaut-m10v-hdmac.txt           | 54 +++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt
Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt new file +5 -0
new file mode 100644
index 000000000000..a104fcb9e73d
@@ -0,0 +1,51 @@
+* Milbeaut AHB DMA Controller
+
+Milbeaut AHB DMA controller has transfer capability bellow.
+ - memory to memory transfer
+ - device to memory transfer
Quoted 9 lines

Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt line 11

Quoted 6 lines
Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt new file +6 -0
+ - memory to device transfer
+
+Required property:
+- compatible:       Should be  "socionext,milbeaut-m10v-hdmac"
+- reg:              Should contain DMA registers location and length.
+- interrupts:       Should contain all of the per-channel DMA interrupts.

How many?

Each channel has an IRQ line. And the number of channels is configurable. So instead of having some explicit property like 'dma-channels', we infer that from the number of irqs registered.

Quoted 10 lines

Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt line 18

Quoted 7 lines
Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt new file +7 -0
+- #dma-cells:       Should be 1. Specify the ID of the slave.
+- clocks:           Phandle to the clock used by the HDMAC module.
+
+
+Example:
+
+     hdmac1: hdmac@1e110000 {

dma-controller@...

OK

Quoted 12 lines
Quoted 12 lines
Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt new file +12 -0
+             compatible = "socionext,milbeaut-m10v-hdmac";
+             reg = <0x1e110000 0x10000>;
+             interrupts = <0 132 4>,
+                          <0 133 4>,
+                          <0 134 4>,
+                          <0 135 4>,
+                          <0 136 4>,
+                          <0 137 4>,
+                          <0 138 4>,
+                          <0 139 4>;
+             #dma-cells = <1>;
+             clocks = <&dummy_clk>;
Quoted 9 lines

Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt line 35

Quoted 5 lines
Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt new file +5 -0
+     };
+
+* DMA client
+
+Clients have to specify the DMA requests with phandles in a list.

Nothing specific to this binding here and the client side is already documented, so drop this section.

OK.

Thanks

maintainer
#4 lore raw

Re: [PATCH 1/2] dt-bindings: milbeaut-m10v-hdmac: Add Socionext Milbeaut HDMAC bindings

Quoted 36 lines · Jassi Brar
Quoted 25 lines · Rob Herring
Quoted 23 lines · On Wed, Jun 12, 2019 at 07:52:37PM -0500, [email protected] wrote:

From: Jassi Brar <[email protected]>

Document the devicetree bindings for Socionext Milbeaut HDMAC controller. Controller has upto 8 floating channels, that need a predefined slave-id to work from a set of slaves.

---
 .../bindings/dma/milbeaut-m10v-hdmac.txt           | 54 +++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt
Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt new file +5 -0
new file mode 100644
index 000000000000..a104fcb9e73d
@@ -0,0 +1,51 @@
+* Milbeaut AHB DMA Controller
+
+Milbeaut AHB DMA controller has transfer capability bellow.
+ - memory to memory transfer
+ - device to memory transfer
Quoted 9 lines

Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt line 11

Quoted 6 lines
Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt new file +6 -0
+ - memory to device transfer
+
+Required property:
+- compatible:       Should be  "socionext,milbeaut-m10v-hdmac"
+- reg:              Should contain DMA registers location and length.
+- interrupts:       Should contain all of the per-channel DMA interrupts.

How many?

Quoted 3 lines

Each channel has an IRQ line. And the number of channels is configurable. So instead of having some explicit property like 'dma-channels', we infer that from the number of irqs registered.

Yes, I get that. There's still a range that's valid and you need to define those constraints. If there's a variable number of channels, then that implies different SoCs which should also mean different compatible strings.

Rob

#5 lore raw

PATCH 2/2 dmaengine: milbeaut-hdmac: Add HDMAC driver for Milbeaut platforms

In reply to [email protected]

From: Jassi Brar <[email protected]>

Driver for Socionext Milbeaut HDMAC controller. The controller has upto 8 floating channels, that need a predefined slave-id to work from a set of slaves.

---
 drivers/dma/Kconfig          |  10 +
 drivers/dma/Makefile         |   1 +
 drivers/dma/milbeaut-hdmac.c | 572 +++++++++++++++++++++++++++++++++++
 3 files changed, 583 insertions(+)
 create mode 100644 drivers/dma/milbeaut-hdmac.c
drivers/dma/Kconfig +10 -0
index 703275cc29de..15a1d5263ca1 100644
@@ -347,6 +347,16 @@ config MCF_EDMA
 	  minimal intervention from a host processor.
 	  This module can be found on Freescale ColdFire mcf5441x SoCs.
 
+config MILBEAUT_HDMAC
+	tristate "Milbeaut AHB DMA support"
+	depends on ARCH_MILBEAUT || COMPILE_TEST
+	depends on OF
+	select DMA_ENGINE
+	select DMA_VIRTUAL_CHANNELS
+	help
+	  Say yes here to support the Socionext Milbeaut
+	  HDMAC device.
+
 config MMP_PDMA
 	bool "MMP PDMA support"
 	depends on ARCH_MMP || ARCH_PXA || COMPILE_TEST
drivers/dma/Makefile +1 -0
index 6126e1c3a875..d0a9f46726e8 100644
@@ -45,6 +45,7 @@ obj-$(CONFIG_INTEL_IOP_ADMA) += iop-adma.o
 obj-$(CONFIG_INTEL_MIC_X100_DMA) += mic_x100_dma.o
 obj-$(CONFIG_K3_DMA) += k3dma.o
 obj-$(CONFIG_LPC18XX_DMAMUX) += lpc18xx-dmamux.o
+obj-$(CONFIG_MILBEAUT_HDMAC) += milbeaut-hdmac.o
 obj-$(CONFIG_MMP_PDMA) += mmp_pdma.o
 obj-$(CONFIG_MMP_TDMA) += mmp_tdma.o
 obj-$(CONFIG_MOXART_DMA) += moxart-dma.o
drivers/dma/milbeaut-hdmac.c new file +572 -0

572 lines not on this page · raw message

Signature · 1 line
2.17.1
maintainer
#6 lore raw

Re: [PATCH 2/2] dmaengine: milbeaut-hdmac: Add HDMAC driver for Milbeaut platforms

drivers/dma/milbeaut-hdmac.c line 15

Quoted 10 lines · On 12-06-19, 19:52, [email protected] wrote:
drivers/dma/milbeaut-hdmac.c new file +10 -0
+#include <linux/bits.h>
+#include <linux/clk.h>
+#include <linux/dma-mapping.h>
+#include <linux/dmaengine.h>
+#include <linux/interrupt.h>
+#include <linux/iopoll.h>
+#include <linux/list.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_dma.h>

Do we need both, IIRC of_dma.h does include of.h!

drivers/dma/milbeaut-hdmac.c line 120

Quoted 6 lines
drivers/dma/milbeaut-hdmac.c new file +6 -0
+/* mc->vc.lock must be held by caller */
+static void milbeaut_chan_start(struct milbeaut_hdmac_chan *mc,
+				struct milbeaut_hdmac_desc *md)
+{
+	struct scatterlist *sg;
+	u32  cb, ca, src_addr, dest_addr, len;
           ^^

double space

drivers/dma/milbeaut-hdmac.c line 182

Quoted 12 lines
drivers/dma/milbeaut-hdmac.c new file +12 -0
+static irqreturn_t milbeaut_hdmac_interrupt(int irq, void *dev_id)
+{
+	struct milbeaut_hdmac_chan *mc = dev_id;
+	struct milbeaut_hdmac_desc *md;
+	irqreturn_t ret = IRQ_HANDLED;
+	u32 val;
+
+	spin_lock(&mc->vc.lock);
+
+	/* Ack and Disable irqs */
+	val = readl_relaxed(mc->reg_ch_base + MLB_HDMAC_DMACB);
+	val &= ~(FIELD_PREP(MLB_HDMAC_SS, 0x7));
                                         ^^^^

Magic ..?

drivers/dma/milbeaut-hdmac.c line 235

Quoted 10 lines
drivers/dma/milbeaut-hdmac.c new file +10 -0
+static int milbeaut_hdmac_chan_pause(struct dma_chan *chan)
+{
+	struct virt_dma_chan *vc = to_virt_chan(chan);
+	struct milbeaut_hdmac_chan *mc = to_milbeaut_hdmac_chan(vc);
+	u32 val;
+
+	spin_lock(&mc->vc.lock);
+	val = readl_relaxed(mc->reg_ch_base + MLB_HDMAC_DMACA);
+	val |= MLB_HDMAC_PB;
+	writel_relaxed(val, mc->reg_ch_base + MLB_HDMAC_DMACA);

We really should have an updatel() and friends in kernel, feel free to add in your driver though!

Quoted 13 lines
drivers/dma/milbeaut-hdmac.c new file +13 -0
+static int milbeaut_hdmac_chan_init(struct platform_device *pdev,
+				    struct milbeaut_hdmac_device *mdev,
+				    int chan_id)
+{
+	struct device *dev = &pdev->dev;
+	struct milbeaut_hdmac_chan *mc = &mdev->channels[chan_id];
+	char *irq_name;
+	int irq, ret;
+
+	irq = platform_get_irq(pdev, chan_id);
+	if (irq < 0) {
+		dev_err(&pdev->dev, "failed to get IRQ number for ch%d\n",
+			chan_id);

drivers/dma/milbeaut-hdmac.c line 436

Quoted 10 lines
drivers/dma/milbeaut-hdmac.c new file +10 -0
+		return irq;
+	}
+
+	irq_name = devm_kasprintf(dev, GFP_KERNEL, "milbeaut-hdmac-%d",
+				  chan_id);
+	if (!irq_name)
+		return -ENOMEM;
+
+	ret = devm_request_irq(dev, irq, milbeaut_hdmac_interrupt,
+			       IRQF_SHARED, irq_name, mc);

I tend to dislike using devm_request_irq(), we have no control over when the irq is freed and what is a spirious irq is running while we are unrolling, so IMHO it make sense to free up and ensure all tasklets are quiesced when remove returns

drivers/dma/milbeaut-hdmac.c line 443

Quoted 7 lines
drivers/dma/milbeaut-hdmac.c new file +7 -0
+	if (ret)
+		return ret;
+
+	mc->mdev = mdev;
+	mc->reg_ch_base = mdev->reg_base + MLB_HDMAC_CH_STRIDE * (chan_id + 1);
+	mc->vc.desc_free = milbeaut_hdmac_desc_free;
+	vchan_init(&mc->vc, &mdev->ddev);

who kills the vc->task?

Quoted 13 lines
drivers/dma/milbeaut-hdmac.c new file +13 -0
+static int milbeaut_hdmac_remove(struct platform_device *pdev)
+{
+	struct milbeaut_hdmac_device *mdev = platform_get_drvdata(pdev);
+	struct dma_chan *chan;
+	int ret;
+
+	/*
+	 * Before reaching here, almost all descriptors have been freed by the
+	 * ->device_free_chan_resources() hook. However, each channel might
+	 * be still holding one descriptor that was on-flight at that moment.
+	 * Terminate it to make sure this hardware is no longer running. Then,
+	 * free the channel resources once again to avoid memory leak.
+	 */

drivers/dma/milbeaut-hdmac.c line 550

Quoted 10 lines
drivers/dma/milbeaut-hdmac.c new file +10 -0
+	list_for_each_entry(chan, &mdev->ddev.channels, device_node) {
+		ret = dmaengine_terminate_sync(chan);
+		if (ret)
+			return ret;
+		milbeaut_hdmac_free_chan_resources(chan);
+	}
+
+	of_dma_controller_free(pdev->dev.of_node);
+	dma_async_device_unregister(&mdev->ddev);
+	clk_disable_unprepare(mdev->clk);

And as suspected we have active tasklets and irq at this time :(

Signature · 1 line
~Vinod
author
#7 lore raw

Re: [PATCH 2/2] dmaengine: milbeaut-hdmac: Add HDMAC driver for Milbeaut platforms

Quoted 16 lines · Vinod Koul

drivers/dma/milbeaut-hdmac.c line 15

Quoted 10 lines · On 12-06-19, 19:52, [email protected] wrote:
drivers/dma/milbeaut-hdmac.c new file +10 -0
+#include <linux/bits.h>
+#include <linux/clk.h>
+#include <linux/dma-mapping.h>
+#include <linux/dmaengine.h>
+#include <linux/interrupt.h>
+#include <linux/iopoll.h>
+#include <linux/list.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_dma.h>

Do we need both, IIRC of_dma.h does include of.h!

OK

Quoted 9 lines

drivers/dma/milbeaut-hdmac.c line 120

Quoted 6 lines
drivers/dma/milbeaut-hdmac.c new file +6 -0
+/* mc->vc.lock must be held by caller */
+static void milbeaut_chan_start(struct milbeaut_hdmac_chan *mc,
+                             struct milbeaut_hdmac_desc *md)
+{
+     struct scatterlist *sg;
+     u32  cb, ca, src_addr, dest_addr, len;
           ^^

double space

OK

Quoted 13 lines

drivers/dma/milbeaut-hdmac.c line 182

Quoted 12 lines
drivers/dma/milbeaut-hdmac.c new file +12 -0
+static irqreturn_t milbeaut_hdmac_interrupt(int irq, void *dev_id)
+{
+     struct milbeaut_hdmac_chan *mc = dev_id;
+     struct milbeaut_hdmac_desc *md;
+     irqreturn_t ret = IRQ_HANDLED;
+     u32 val;
+
+     spin_lock(&mc->vc.lock);
+
+     /* Ack and Disable irqs */
+     val = readl_relaxed(mc->reg_ch_base + MLB_HDMAC_DMACB);
+     val &= ~(FIELD_PREP(MLB_HDMAC_SS, 0x7));
                                         ^^^^
Quoted 2 lines

Magic ..?

OK, will define a macro for 7

Quoted 5 lines
Quoted 5 lines
drivers/dma/milbeaut-hdmac.c new file +5 -0
+static int milbeaut_hdmac_chan_pause(struct dma_chan *chan)
+{
+     struct virt_dma_chan *vc = to_virt_chan(chan);
+     struct milbeaut_hdmac_chan *mc = to_milbeaut_hdmac_chan(vc);
+     u32 val;
Quoted 9 lines

drivers/dma/milbeaut-hdmac.c line 235

Quoted 5 lines
drivers/dma/milbeaut-hdmac.c new file +5 -0
+
+     spin_lock(&mc->vc.lock);
+     val = readl_relaxed(mc->reg_ch_base + MLB_HDMAC_DMACA);
+     val |= MLB_HDMAC_PB;
+     writel_relaxed(val, mc->reg_ch_base + MLB_HDMAC_DMACA);

We really should have an updatel() and friends in kernel, feel free to add in your driver though!

I'll pass on that for now.

Quoted 20 lines
Quoted 20 lines
drivers/dma/milbeaut-hdmac.c new file +20 -0
+static int milbeaut_hdmac_chan_init(struct platform_device *pdev,
+                                 struct milbeaut_hdmac_device *mdev,
+                                 int chan_id)
+{
+     struct device *dev = &pdev->dev;
+     struct milbeaut_hdmac_chan *mc = &mdev->channels[chan_id];
+     char *irq_name;
+     int irq, ret;
+
+     irq = platform_get_irq(pdev, chan_id);
+     if (irq < 0) {
+             dev_err(&pdev->dev, "failed to get IRQ number for ch%d\n",
+                     chan_id);
+             return irq;
+     }
+
+     irq_name = devm_kasprintf(dev, GFP_KERNEL, "milbeaut-hdmac-%d",
+                               chan_id);
+     if (!irq_name)
+             return -ENOMEM;
Quoted 9 lines

drivers/dma/milbeaut-hdmac.c line 436

Quoted 3 lines
drivers/dma/milbeaut-hdmac.c new file +3 -0
+
+     ret = devm_request_irq(dev, irq, milbeaut_hdmac_interrupt,
+                            IRQF_SHARED, irq_name, mc);

I tend to dislike using devm_request_irq(), we have no control over when the irq is freed and what is a spirious irq is running while we are unrolling, so IMHO it make sense to free up and ensure all tasklets are quiesced when remove returns

If the code is written clean and tight we need not be so paranoid.

Quoted 10 lines

drivers/dma/milbeaut-hdmac.c line 443

Quoted 7 lines
drivers/dma/milbeaut-hdmac.c new file +7 -0
+     if (ret)
+             return ret;
+
+     mc->mdev = mdev;
+     mc->reg_ch_base = mdev->reg_base + MLB_HDMAC_CH_STRIDE * (chan_id + 1);
+     mc->vc.desc_free = milbeaut_hdmac_desc_free;
+     vchan_init(&mc->vc, &mdev->ddev);

who kills the vc->task?

vchan_synchronize() called from milbeaut_hdmac_synchronize()

Quoted 17 lines
Quoted 17 lines
drivers/dma/milbeaut-hdmac.c new file +17 -0
+static int milbeaut_hdmac_remove(struct platform_device *pdev)
+{
+     struct milbeaut_hdmac_device *mdev = platform_get_drvdata(pdev);
+     struct dma_chan *chan;
+     int ret;
+
+     /*
+      * Before reaching here, almost all descriptors have been freed by the
+      * ->device_free_chan_resources() hook. However, each channel might
+      * be still holding one descriptor that was on-flight at that moment.
+      * Terminate it to make sure this hardware is no longer running. Then,
+      * free the channel resources once again to avoid memory leak.
+      */
+     list_for_each_entry(chan, &mdev->ddev.channels, device_node) {
+             ret = dmaengine_terminate_sync(chan);
+             if (ret)
+                     return ret;
Quoted 9 lines

drivers/dma/milbeaut-hdmac.c line 550

Quoted 6 lines
drivers/dma/milbeaut-hdmac.c new file +6 -0
+             milbeaut_hdmac_free_chan_resources(chan);
+     }
+
+     of_dma_controller_free(pdev->dev.of_node);
+     dma_async_device_unregister(&mdev->ddev);
+     clk_disable_unprepare(mdev->clk);

And as suspected we have active tasklets and irq at this time :(

Not sure how is that....

thanks.

maintainer
#8 lore raw

Re: [PATCH 2/2] dmaengine: milbeaut-hdmac: Add HDMAC driver for Milbeaut platforms

Quoted 102 lines · Jassi Brar
Quoted 16 lines · Vinod Koul

drivers/dma/milbeaut-hdmac.c line 15

Quoted 10 lines · On 12-06-19, 19:52, [email protected] wrote:
drivers/dma/milbeaut-hdmac.c new file +10 -0
+#include <linux/bits.h>
+#include <linux/clk.h>
+#include <linux/dma-mapping.h>
+#include <linux/dmaengine.h>
+#include <linux/interrupt.h>
+#include <linux/iopoll.h>
+#include <linux/list.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_dma.h>

Do we need both, IIRC of_dma.h does include of.h!

OK

Quoted 9 lines

drivers/dma/milbeaut-hdmac.c line 120

Quoted 6 lines
drivers/dma/milbeaut-hdmac.c new file +6 -0
+/* mc->vc.lock must be held by caller */
+static void milbeaut_chan_start(struct milbeaut_hdmac_chan *mc,
+                             struct milbeaut_hdmac_desc *md)
+{
+     struct scatterlist *sg;
+     u32  cb, ca, src_addr, dest_addr, len;
           ^^

double space

OK

Quoted 13 lines

drivers/dma/milbeaut-hdmac.c line 182

Quoted 12 lines
drivers/dma/milbeaut-hdmac.c new file +12 -0
+static irqreturn_t milbeaut_hdmac_interrupt(int irq, void *dev_id)
+{
+     struct milbeaut_hdmac_chan *mc = dev_id;
+     struct milbeaut_hdmac_desc *md;
+     irqreturn_t ret = IRQ_HANDLED;
+     u32 val;
+
+     spin_lock(&mc->vc.lock);
+
+     /* Ack and Disable irqs */
+     val = readl_relaxed(mc->reg_ch_base + MLB_HDMAC_DMACB);
+     val &= ~(FIELD_PREP(MLB_HDMAC_SS, 0x7));
                                         ^^^^
Quoted 2 lines

Magic ..?

OK, will define a macro for 7

Quoted 5 lines
Quoted 5 lines
drivers/dma/milbeaut-hdmac.c new file +5 -0
+static int milbeaut_hdmac_chan_pause(struct dma_chan *chan)
+{
+     struct virt_dma_chan *vc = to_virt_chan(chan);
+     struct milbeaut_hdmac_chan *mc = to_milbeaut_hdmac_chan(vc);
+     u32 val;
Quoted 9 lines

drivers/dma/milbeaut-hdmac.c line 235

Quoted 5 lines
drivers/dma/milbeaut-hdmac.c new file +5 -0
+
+     spin_lock(&mc->vc.lock);
+     val = readl_relaxed(mc->reg_ch_base + MLB_HDMAC_DMACA);
+     val |= MLB_HDMAC_PB;
+     writel_relaxed(val, mc->reg_ch_base + MLB_HDMAC_DMACA);

We really should have an updatel() and friends in kernel, feel free to add in your driver though!

I'll pass on that for now.

Quoted 20 lines
Quoted 20 lines
drivers/dma/milbeaut-hdmac.c new file +20 -0
+static int milbeaut_hdmac_chan_init(struct platform_device *pdev,
+                                 struct milbeaut_hdmac_device *mdev,
+                                 int chan_id)
+{
+     struct device *dev = &pdev->dev;
+     struct milbeaut_hdmac_chan *mc = &mdev->channels[chan_id];
+     char *irq_name;
+     int irq, ret;
+
+     irq = platform_get_irq(pdev, chan_id);
+     if (irq < 0) {
+             dev_err(&pdev->dev, "failed to get IRQ number for ch%d\n",
+                     chan_id);
+             return irq;
+     }
+
+     irq_name = devm_kasprintf(dev, GFP_KERNEL, "milbeaut-hdmac-%d",
+                               chan_id);
+     if (!irq_name)
+             return -ENOMEM;
Quoted 9 lines

drivers/dma/milbeaut-hdmac.c line 436

Quoted 3 lines
drivers/dma/milbeaut-hdmac.c new file +3 -0
+
+     ret = devm_request_irq(dev, irq, milbeaut_hdmac_interrupt,
+                            IRQF_SHARED, irq_name, mc);

I tend to dislike using devm_request_irq(), we have no control over when the irq is freed and what is a spirious irq is running while we are unrolling, so IMHO it make sense to free up and ensure all tasklets are quiesced when remove returns

If the code is written clean and tight we need not be so paranoid.

Quoted 8 lines
Quoted 7 lines
drivers/dma/milbeaut-hdmac.c new file +7 -0
+     if (ret)
+             return ret;
+
+     mc->mdev = mdev;
+     mc->reg_ch_base = mdev->reg_base + MLB_HDMAC_CH_STRIDE * (chan_id + 1);
+     mc->vc.desc_free = milbeaut_hdmac_desc_free;
+     vchan_init(&mc->vc, &mdev->ddev);
Quoted 3 lines
Quoted 2 lines

who kills the vc->task?

vchan_synchronize() called from milbeaut_hdmac_synchronize()

But that can be skipped by called, from driver pov we need to ensure that it is killed

Quoted 26 lines
Quoted 17 lines
Quoted 17 lines
drivers/dma/milbeaut-hdmac.c new file +17 -0
+static int milbeaut_hdmac_remove(struct platform_device *pdev)
+{
+     struct milbeaut_hdmac_device *mdev = platform_get_drvdata(pdev);
+     struct dma_chan *chan;
+     int ret;
+
+     /*
+      * Before reaching here, almost all descriptors have been freed by the
+      * ->device_free_chan_resources() hook. However, each channel might
+      * be still holding one descriptor that was on-flight at that moment.
+      * Terminate it to make sure this hardware is no longer running. Then,
+      * free the channel resources once again to avoid memory leak.
+      */
+     list_for_each_entry(chan, &mdev->ddev.channels, device_node) {
+             ret = dmaengine_terminate_sync(chan);
+             if (ret)
+                     return ret;
Quoted 9 lines

drivers/dma/milbeaut-hdmac.c line 550

Quoted 6 lines
drivers/dma/milbeaut-hdmac.c new file +6 -0
+             milbeaut_hdmac_free_chan_resources(chan);
+     }
+
+     of_dma_controller_free(pdev->dev.of_node);
+     dma_async_device_unregister(&mdev->ddev);
+     clk_disable_unprepare(mdev->clk);

And as suspected we have active tasklets and irq at this time :(

Quoted 1 line

Not sure how is that....

Since you use devm variants, and driver tasklet is not killed, irq can be fired (spurious as well) and can run irq and schedule a tasklet. How do you prevent that?

Thanks

Signature · 1 line
~Vinod
#9 lore raw

v2 cover Add support for AHB DMA controller on Milbeaut series

In reply to [email protected]

From: Jassi Brar <[email protected]>

Changes since v1:
1) Drop uncessary headers from driver
2) Some Cosmetic changes.
3) Define macro for magic numbers
4) Specify constraints on number of channels/irq in DT bindings

Jassi Brar (2):
dt-bindings: milbeaut-m10v-hdmac: Add Socionext Milbeaut HDMAC
bindings
dmaengine: milbeaut-hdmac: Add HDMAC driver for Milbeaut platforms

 .../bindings/dma/milbeaut-m10v-hdmac.txt      |  32 +
 drivers/dma/Kconfig                           |  10 +
 drivers/dma/Makefile                          |   1 +
 drivers/dma/milbeaut-hdmac.c                  | 571 ++++++++++++++++++
 4 files changed, 614 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt
 create mode 100644 drivers/dma/milbeaut-hdmac.c
Signature · 1 line
2.17.1
#10 lore raw

PATCH v2 1/2 dt-bindings: milbeaut-m10v-hdmac: Add Socionext Milbeaut HDMAC bindings

From: Jassi Brar <[email protected]>

Document the devicetree bindings for Socionext Milbeaut HDMAC controller. Controller has upto 8 floating channels, that need a predefined slave-id to work from a set of slaves.

---
 .../bindings/dma/milbeaut-m10v-hdmac.txt      | 32 +++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt
Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt new file +32 -0
new file mode 100644
index 000000000000..f0960724f1c7
@@ -0,0 +1,32 @@
+* Milbeaut AHB DMA Controller
+
+Milbeaut AHB DMA controller has transfer capability bellow.
+ - device to memory transfer
+ - memory to device transfer
+
+Required property:
+- compatible:       Should be  "socionext,milbeaut-m10v-hdmac"
+- reg:              Should contain DMA registers location and length.
+- interrupts:       Should contain all of the per-channel DMA interrupts.
+                     Number of channels is configurable - 2, 4 or 8, so
+                     the number of interrupts specfied should be {2,4,8}.
+- #dma-cells:       Should be 1. Specify the ID of the slave.
+- clocks:           Phandle to the clock used by the HDMAC module.
+
+
+Example:
+
+	hdmac1: dma-controller@1e110000 {
+		compatible = "socionext,milbeaut-m10v-hdmac";
+		reg = <0x1e110000 0x10000>;
+		interrupts = <0 132 4>,
+			     <0 133 4>,
+			     <0 134 4>,
+			     <0 135 4>,
+			     <0 136 4>,
+			     <0 137 4>,
+			     <0 138 4>,
+			     <0 139 4>;
+		#dma-cells = <1>;
+		clocks = <&dummy_clk>;
+	};
Signature · 1 line
2.17.1
maintainer Reviewed-by on v2 1/2
#11 lore raw

Re: [PATCH v2 1/2] dt-bindings: milbeaut-m10v-hdmac: Add Socionext Milbeaut HDMAC bindings

Quoted 6 lines · On Sun, 18 Aug 2019 00:17:54 -0500, [email protected] wrote:

From: Jassi Brar <[email protected]>

Document the devicetree bindings for Socionext Milbeaut HDMAC controller. Controller has upto 8 floating channels, that need a predefined slave-id to work from a set of slaves.

Quoted 6 lines
---
 .../bindings/dma/milbeaut-m10v-hdmac.txt      | 32 +++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt
maintainer
#12 lore raw

Re: [PATCH v2 1/2] dt-bindings: milbeaut-m10v-hdmac: Add Socionext Milbeaut HDMAC bindings

In reply to [email protected]
Quoted 18 lines · On 18-08-19, 00:17, [email protected] wrote:

From: Jassi Brar <[email protected]>

Document the devicetree bindings for Socionext Milbeaut HDMAC controller. Controller has upto 8 floating channels, that need a predefined slave-id to work from a set of slaves.

---
 .../bindings/dma/milbeaut-m10v-hdmac.txt      | 32 +++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt
Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt new file +0 -0
new file mode 100644
index 000000000000..f0960724f1c7

Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt line 3

Quoted 3 lines
Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt new file +3 -0
@@ -0,0 +1,32 @@
+* Milbeaut AHB DMA Controller
+
+Milbeaut AHB DMA controller has transfer capability bellow.

s/bellow/below:

Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt line 12

Quoted 9 lines
Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt new file +9 -0
+ - device to memory transfer
+ - memory to device transfer
+
+Required property:
+- compatible:       Should be  "socionext,milbeaut-m10v-hdmac"
+- reg:              Should contain DMA registers location and length.
+- interrupts:       Should contain all of the per-channel DMA interrupts.
+                     Number of channels is configurable - 2, 4 or 8, so
+                     the number of interrupts specfied should be {2,4,8}.

s/specfied/specified

Signature · 1 line
~Vinod
author
#13 lore raw

Re: [PATCH v2 1/2] dt-bindings: milbeaut-m10v-hdmac: Add Socionext Milbeaut HDMAC bindings

Quoted 26 lines · Vinod Koul
Quoted 18 lines · On 18-08-19, 00:17, [email protected] wrote:

From: Jassi Brar <[email protected]>

Document the devicetree bindings for Socionext Milbeaut HDMAC controller. Controller has upto 8 floating channels, that need a predefined slave-id to work from a set of slaves.

---
 .../bindings/dma/milbeaut-m10v-hdmac.txt      | 32 +++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt
Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt new file +0 -0
new file mode 100644
index 000000000000..f0960724f1c7

Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt line 3

Quoted 3 lines
Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt new file +3 -0
@@ -0,0 +1,32 @@
+* Milbeaut AHB DMA Controller
+
+Milbeaut AHB DMA controller has transfer capability bellow.

s/bellow/below:

Quoted 12 lines

Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt line 12

Quoted 9 lines
Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt new file +9 -0
+ - device to memory transfer
+ - memory to device transfer
+
+Required property:
+- compatible:       Should be  "socionext,milbeaut-m10v-hdmac"
+- reg:              Should contain DMA registers location and length.
+- interrupts:       Should contain all of the per-channel DMA interrupts.
+                     Number of channels is configurable - 2, 4 or 8, so
+                     the number of interrupts specfied should be {2,4,8}.

s/specfied/specified

Hi Vinod,
Do you want me to spin yet another revision for the two types in text?

thnx

maintainer
#14 lore raw

Re: [PATCH v2 1/2] dt-bindings: milbeaut-m10v-hdmac: Add Socionext Milbeaut HDMAC bindings

Quoted 39 lines · Jassi Brar
Quoted 26 lines · Vinod Koul
Quoted 18 lines · On 18-08-19, 00:17, [email protected] wrote:

From: Jassi Brar <[email protected]>

Document the devicetree bindings for Socionext Milbeaut HDMAC controller. Controller has upto 8 floating channels, that need a predefined slave-id to work from a set of slaves.

---
 .../bindings/dma/milbeaut-m10v-hdmac.txt      | 32 +++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt
Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt new file +0 -0
new file mode 100644
index 000000000000..f0960724f1c7

Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt line 3

Quoted 3 lines
Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt new file +3 -0
@@ -0,0 +1,32 @@
+* Milbeaut AHB DMA Controller
+
+Milbeaut AHB DMA controller has transfer capability bellow.

s/bellow/below:

Quoted 12 lines

Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt line 12

Quoted 9 lines
Documentation/devicetree/bindings/dma/milbeaut-m10v-hdmac.txt new file +9 -0
+ - device to memory transfer
+ - memory to device transfer
+
+Required property:
+- compatible:       Should be  "socionext,milbeaut-m10v-hdmac"
+- reg:              Should contain DMA registers location and length.
+- interrupts:       Should contain all of the per-channel DMA interrupts.
+                     Number of channels is configurable - 2, 4 or 8, so
+                     the number of interrupts specfied should be {2,4,8}.

s/specfied/specified

Quoted 2 lines

Hi Vinod,
Do you want me to spin yet another revision for the two types in text?

Yes that would be easier for me

Thanks

Signature · 1 line
~Vinod
#15 lore raw

PATCH v2 2/2 dmaengine: milbeaut-hdmac: Add HDMAC driver for Milbeaut platforms

In reply to [email protected]

From: Jassi Brar <[email protected]>

Driver for Socionext Milbeaut HDMAC controller. The controller has upto 8 floating channels, that need a predefined slave-id to work from a set of slaves.

---
 drivers/dma/Kconfig          |  10 +
 drivers/dma/Makefile         |   1 +
 drivers/dma/milbeaut-hdmac.c | 571 +++++++++++++++++++++++++++++++++++
 3 files changed, 582 insertions(+)
 create mode 100644 drivers/dma/milbeaut-hdmac.c
drivers/dma/Kconfig +10 -0
index 03fa0c58cef3..66979f27f0f3 100644
@@ -348,6 +348,16 @@ config MCF_EDMA
 	  minimal intervention from a host processor.
 	  This module can be found on Freescale ColdFire mcf5441x SoCs.
 
+config MILBEAUT_HDMAC
+	tristate "Milbeaut AHB DMA support"
+	depends on ARCH_MILBEAUT || COMPILE_TEST
+	depends on OF
+	select DMA_ENGINE
+	select DMA_VIRTUAL_CHANNELS
+	help
+	  Say yes here to support the Socionext Milbeaut
+	  HDMAC device.
+
 config MMP_PDMA
 	bool "MMP PDMA support"
 	depends on ARCH_MMP || ARCH_PXA || COMPILE_TEST
drivers/dma/Makefile +1 -0
index 5bddf6f8790f..e4aed0730dea 100644
@@ -46,6 +46,7 @@ obj-$(CONFIG_INTEL_IOP_ADMA) += iop-adma.o
 obj-$(CONFIG_INTEL_MIC_X100_DMA) += mic_x100_dma.o
 obj-$(CONFIG_K3_DMA) += k3dma.o
 obj-$(CONFIG_LPC18XX_DMAMUX) += lpc18xx-dmamux.o
+obj-$(CONFIG_MILBEAUT_HDMAC) += milbeaut-hdmac.o
 obj-$(CONFIG_MMP_PDMA) += mmp_pdma.o
 obj-$(CONFIG_MMP_TDMA) += mmp_tdma.o
 obj-$(CONFIG_MOXART_DMA) += moxart-dma.o
drivers/dma/milbeaut-hdmac.c new file +571 -0

571 lines not on this page · raw message

Signature · 1 line
2.17.1