dmaengine patches
Subsystems (4)
Sascha Hauer
maintainerHi,
The following patches are new versions of patches previously posted with the latest comments from Dan integrated. New in this series is a dma driver for the older i.MX SoCs. I decided to implement the dmaengine driver for these SoCs as a user of the old dma driver. This allows us keep both dma drivers in the tree and to convert the users of the dma driver smoothly and one by one to the new driver and remove the old driver afterwards.
Sascha
The following changes since commit 32163f4b2cef28a5aab8b226ffecfc6379a53786:
alpha: fix usp value in multithreaded coredumps (2010-09-25 14:38:13 -0700)
are available in the git repository at:
git://git.pengutronix.de/git/imx/linux-2.6.git sdma-dmaengine
Sascha Hauer (4):
dmaengine: add possibility for cyclic transfers
dmaengine: add wrapper functions for device control functions
dmaengine: Add Freescale i.MX SDMA support
dmaengine: Add Freescale i.MX1/21/27 DMA driver
arch/arm/mach-imx/include/mach/dma-v1.h | 8 +- arch/arm/plat-mxc/include/mach/dma.h | 67 ++ arch/arm/plat-mxc/include/mach/sdma.h | 17 + drivers/dma/Kconfig | 16 + drivers/dma/Makefile | 2 + drivers/dma/dmaengine.c | 2 + drivers/dma/imx-dma.c | 426 ++++++++++ drivers/dma/imx-sdma.c | 1392 +++++++++++++++++++++++++++++++ include/linux/dmaengine.h | 43 +- 9 files changed, 1966 insertions(+), 7 deletions(-) create mode 100644 arch/arm/plat-mxc/include/mach/dma.h create mode 100644 arch/arm/plat-mxc/include/mach/sdma.h create mode 100644 drivers/dma/imx-dma.c create mode 100644 drivers/dma/imx-sdma.c
Sascha Hauer
maintainerPATCH 1/4 dmaengine: add possibility for cyclic transfers
Cyclic transfers are useful for audio where a single buffer divided in periods has to be transfered endlessly until stopped. After being prepared the transfer is started using the dma_async_descriptor->tx_submit function. dma_async_descriptor->callback is called after each period. The transfer is stopped using the DMA_TERMINATE_ALL callback. While being used for cyclic transfers the channel cannot be used for other transfer types.
--- drivers/dma/dmaengine.c | 2 ++ include/linux/dmaengine.h | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletions(-)
drivers/dma/dmaengine.c +2 -0
@@ -692,6 +692,8 @@ int dma_async_device_register(struct dma_device *device) !device->device_prep_dma_interrupt);BUG_ON (dma_has_cap (DMA_SLAVE , device->cap_mask) && !device->device_prep_slave_sg); +BUG_ON (dma_has_cap (DMA_CYCLIC , device->cap_mask) && + !device->device_prep_dma_cyclic);BUG_ON (dma_has_cap (DMA_SLAVE , device->cap_mask) && !device->device_control);
include/linux/dmaengine.h +8 -1
@@ -67,10 +67,11 @@ enum dma_transaction_type {DMA_PRIVATE ,DMA_ASYNC_TX ,DMA_SLAVE , + DMA_CYCLIC, };/* last transaction type for creation of the capabilities mask */ -#define DMA_TX_TYPE_END (DMA_SLAVE + 1) +#define DMA_TX_TYPE_END (DMA_CYCLIC + 1)/**
@@ -422,6 +423,9 @@ struct dma_tx_state {* @device_prep_dma_memset: prepares a memset operation * @device_prep_dma_interrupt: prepares an end of chain interrupt operation * @device_prep_slave_sg: prepares a slave dma operation +* @device_prep_dma_cyclic: prepare a cyclic dma operation suitable for audio. +* The function takes a buffer of size buf_len. The callback function will +* be called after period_len bytes have been transferred. * @device_control: manipulate all pending operations on a channel, returns * zero or error code * @device_tx_status: poll for transaction completion, the optional
@@ -478,6 +482,9 @@ struct dma_device { struct dma_chan *chan, struct scatterlist *sgl, unsigned int sg_len, enum dma_data_direction direction, unsigned long flags); +struct dma_async_tx_descriptor *(*device_prep_dma_cyclic)( +struct dma_chan *chan,dma_addr_t buf_addr,size_t buf_len, +size_t period_len,enum dma_data_direction direction);int (*device_control)(struct dma_chan *chan,enum dma_ctrl_cmd cmd,unsigned long arg);
Signature · 1 line
1.7.2.3
Sascha Hauer
maintainerPATCH 2/4 dmaengine: add wrapper functions for device control functions
In reply to Sascha HauerAdd wrapper functions around the dma_device->device_control function to bring back type safety. Also, add a wrapper function around dma_async_tx_descriptor->tx_submit. This is named dmaengine_submit instead of dmaengine_tx_submit to get rid of the confusing 'tx' in the function name
--- include/linux/dmaengine.h | 34 ++++++++++++++++++++++++++++++++++ 1 files changed, 34 insertions(+), 0 deletions(-)
include/linux/dmaengine.h +34 -0
@@ -494,6 +494,40 @@ struct dma_device {void (*device_issue_pending)(struct dma_chan *chan); }; +static inline int dmaengine_device_control (struct dma_chan *chan, +enum dma_ctrl_cmd cmd, +unsigned long arg) +{ +return chan->device->device_control (chan, cmd, arg); +} + +static inline int dmaengine_slave_config (struct dma_chan *chan, +struct dma_slave_config *config) +{ +return dmaengine_device_control (chan,DMA_SLAVE_CONFIG , + (unsigned long )config); +} + +static inline int dmaengine_terminate_all (struct dma_chan *chan) +{ +return dmaengine_device_control (chan,DMA_TERMINATE_ALL ,0 ); +} + +static inline int dmaengine_pause (struct dma_chan *chan) +{ +return dmaengine_device_control (chan,DMA_PAUSE ,0 ); +} + +static inline int dmaengine_resume (struct dma_chan *chan) +{ +return dmaengine_device_control (chan,DMA_RESUME ,0 ); +} + +static inline int dmaengine_submit (struct dma_async_tx_descriptor *desc) +{ +return desc->tx_submit (desc); +} +static inline bool dmaengine_check_align (u8 align,size_t off1,size_t off2,size_t len) {size_t mask;
Signature · 1 line
1.7.2.3
Sascha Hauer
maintainerPATCH 3/4 dmaengine: Add Freescale i.MX SDMA support
In reply to Sascha HauerThis patch adds support for the Freescale i.MX SDMA engine.
The SDMA engine is a scatter/gather DMA engine which is implemented as a seperate coprocessor. SDMA needs its own firmware which is requested using the standard request_firmware mechanism. The firmware has different entry points for each peripheral type, so drivers have to pass the peripheral type to the DMA engine which in turn picks the correct firmware entry point from a table contained in the firmware image itself.
The original Freescale code also supports support for transfering data to the internal SRAM which needs different entry points to the firmware. Support for this is currently not implemented. Also, support for the ASRC (asymmetric sample rate converter) is skipped.
I took a very simple approach to implement dmaengine support. Only a single descriptor is statically assigned to a each channel. This means that transfers can't be queued up but only a single transfer is in progress. This simplifies implementation a lot and is sufficient for the usual device/memory transfers.
--- arch/arm/mach-imx/include/mach/dma-v1.h | 8 +- arch/arm/plat-mxc/include/mach/dma.h | 67 ++ arch/arm/plat-mxc/include/mach/sdma.h | 17 + drivers/dma/Kconfig | 8 + drivers/dma/Makefile | 1 + drivers/dma/imx-sdma.c | 1392 +++++++++++++++++++++++++++++++ 6 files changed, 1487 insertions(+), 6 deletions(-) create mode 100644 arch/arm/plat-mxc/include/mach/dma.h create mode 100644 arch/arm/plat-mxc/include/mach/sdma.h create mode 100644 drivers/dma/imx-sdma.c
arch/arm/mach-imx/include/mach/dma-v1.h +2 -6
@@ -27,6 +27,8 @@#define imx_has_dma_v1 () (cpu_is_mx1() || cpu_is_mx21() || cpu_is_mx27()) +#include <mach/dma.h> +#define IMX_DMA_CHANNELS 16#define DMA_MODE_READ 0
@@ -96,12 +98,6 @@ int imx_dma_request(int channel, const char *name);void imx_dma_free (int channel); -enum imx_dma_prio { -DMA_PRIO_HIGH =0 , -DMA_PRIO_MEDIUM =1 , -DMA_PRIO_LOW =2 -}; -int imx_dma_request_by_prio (const char *name,enum imx_dma_prio prio);#endif /* __MACH_DMA_V1_H__ */
arch/arm/plat-mxc/include/mach/dma.h new file +67 -0
67 lines not on this page · raw message
arch/arm/plat-mxc/include/mach/sdma.h new file +17 -0
@@ -0,0 +1,17 @@ +#ifndef __MACH_MXC_SDMA_H__ +#define __MACH_MXC_SDMA_H__ + +/** +* struct sdma_platform_data - platform specific data for SDMA engine +* +* @sdma_version The version of this SDMA engine +* @cpu_name used to generate the firmware name +* @to_version CPU Tape out version +*/ +struct sdma_platform_data { +int sdma_version; +char *cpu_name; +int to_version; +}; + +#endif /* __MACH_MXC_SDMA_H__ */
drivers/dma/Kconfig +8 -0
@@ -195,6 +195,14 @@ config PCH_DMA help Enable support for the Topcliff PCH DMA engine. +config IMX_SDMA + tristate "i.MX SDMA support" + depends on ARCH_MX25 || ARCH_MX3 || ARCH_MX5 + select DMA_ENGINE + help + Support the i.MX SDMA engine. This engine is integrated into + Freescale i.MX25/31/35/51 chips. + config DMA_ENGINE bool
drivers/dma/Makefile +1 -0
@@ -25,3 +25,4 @@ obj-$(CONFIG_TIMB_DMA) += timb_dma.o obj-$(CONFIG_STE_DMA40) += ste_dma40.o ste_dma40_ll.o obj-$(CONFIG_PL330_DMA) += pl330.o obj-$(CONFIG_PCH_DMA) += pch_dma.o +obj-$(CONFIG_IMX_SDMA) += imx-sdma.o
drivers/dma/imx-sdma.c new file +1392 -0
1,392 lines not on this page · raw message
Signature · 1 line
1.7.2.3
Dan Williams
AppliedRe: [PATCH 3/4] dmaengine: Add Freescale i.MX SDMA support
Quoted 2 lines · Sascha Hauer
This patch adds support for the Freescale i.MX SDMA engine.
Applied, this set, however...
Quoted 4 lines
(quoted diff) +4
-0+static struct dma_async_tx_descriptor *sdma_prep_slave_sg( + ? ? ? ? ? ? ? struct dma_chan *chan, struct scatterlist *sgl, + ? ? ? ? ? ? ? unsigned int sg_len, enum dma_data_direction direction, + ? ? ? ? ? ? ? unsigned long flags)
Review
Quoted 10 lines
(quoted diff) +10
-0+{ + ? ? ? struct sdma_channel *sdmac = to_sdma_chan(chan); + ? ? ? struct sdma_engine *sdma = sdmac->sdma; + ? ? ? int ret, i, count; + ? ? ? int channel = chan->chan_id; + ? ? ? struct scatterlist *sg; + + ? ? ? if (sdmac->status == DMA_IN_PROGRESS) + ? ? ? ? ? ? ? return NULL; + ? ? ? sdmac->status = DMA_IN_PROGRESS;
...shouldn't this be an atomic test and set operation to ensure a single user at a time?
--
Dan
Sascha Hauer
maintainerPATCH 4/4 dmaengine: Add Freescale i.MX1/21/27 DMA driver
In reply to Sascha HauerThis driver is currently implemented as a user to the old i.MX DMA API. This allows us to convert each user of the old API to the dmaengine API one by one. Once this is done the old DMA driver can be merged into the i.MX dmaengine driver.
--- drivers/dma/Kconfig | 8 + drivers/dma/Makefile | 1 + drivers/dma/imx-dma.c | 426 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 435 insertions(+), 0 deletions(-) create mode 100644 drivers/dma/imx-dma.c
drivers/dma/Kconfig +8 -0
@@ -203,6 +203,14 @@ config IMX_SDMA Support the i.MX SDMA engine. This engine is integrated into Freescale i.MX25/31/35/51 chips. +config IMX_DMA + tristate "i.MX DMA support" + depends on ARCH_MX1 || ARCH_MX21 || MACH_MX27 + select DMA_ENGINE + help + Support the i.MX DMA engine. This engine is integrated into + Freescale i.MX1/21/27 chips. + config DMA_ENGINE bool
drivers/dma/Makefile +1 -0
@@ -26,3 +26,4 @@ obj-$(CONFIG_STE_DMA40) += ste_dma40.o ste_dma40_ll.o obj-$(CONFIG_PL330_DMA) += pl330.o obj-$(CONFIG_PCH_DMA) += pch_dma.o obj-$(CONFIG_IMX_SDMA) += imx-sdma.o +obj-$(CONFIG_IMX_DMA) += imx-dma.o
drivers/dma/imx-dma.c new file +426 -0
426 lines not on this page · raw message
Signature · 1 line
1.7.2.3
PATCH 4/4 dmaengine: Add Freescale i.MX1/21/27 DMA driver
Hi Sascha,
+
Quoted 12 lines
drivers/dma/imx-dma.c new file +11
-0+struct imxdma_channel { +struct imxdma_engine *imxdma; +unsigned int channel; +unsigned int imxdma_channel; + +enum dma_data_direction direction; +enum dma_slave_buswidth word_size; +dma_addr_t bd_phys; +unsigned long flags; +dma_addr_t per_address; +u32 watermark_level;
drivers/dma/imx-dma.c line 51
Quoted 10 lines
drivers/dma/imx-dma.c new file +10
-0+struct dma_chan chan; +spinlock_t lock; +struct dma_async_tx_descriptor desc; +dma_cookie_t last_completed; +enum dma_status status; +int dma_request; +struct scatterlist *sg_list; +}; + +#define MAX_DMA_CHANNELS 8
i.MX27 has 16 DMA channels. Maybe an #ifdef would solve the issue.
Signature · 10 lines
Javier Martin Vista Silicon S.L. CDTUC - FASE C - Oficina S-345 Avda de los Castros s/n 39005- Santander. Cantabria. Spain +34 942 25 32 60 www.vista-silicon.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20101005/646920ac/attachment-0001.html>
Sascha Hauer
maintainerRe: [PATCH 4/4] dmaengine: Add Freescale i.MX1/21/27 DMA driver
Hi Javier,
Quoted 20 lines · javier Martin
Hi Sascha,
+
Quoted 16 lines
drivers/dma/imx-dma.c new file +16
-0+struct imxdma_channel { +struct imxdma_engine *imxdma; +unsigned int channel; +unsigned int imxdma_channel; + +enum dma_data_direction direction; +enum dma_slave_buswidth word_size; +dma_addr_t bd_phys; +unsigned long flags; +dma_addr_t per_address; +u32 watermark_level; +struct dma_chan chan; +spinlock_t lock; +struct dma_async_tx_descriptor desc; +dma_cookie_t last_completed; +enum dma_status status;
Quoted 8 lines
drivers/dma/imx-dma.c line 51
Quoted 6 lines
drivers/dma/imx-dma.c new file +5
-0+int dma_request; +struct scatterlist *sg_list; +}; + +#define MAX_DMA_CHANNELS 8i.MX27 has 16 DMA channels. Maybe an #ifdef would solve the issue.
This is by intention. I want to reserve 8 channels for the old driver and the remaining 8 for the dmaengine driver. This way we can have both in the tree and use both drivers parallel. This can be changed to the real value once the old driver is gone.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Re: [PATCH 4/4] dmaengine: Add Freescale i.MX1/21/27 DMA driver
In reply to Sascha Hauer2010/9/30 Sascha Hauer <[email protected]>:
Quoted 4 lines
This driver is currently implemented as a user to the old i.MX DMA API. This allows us to convert each user of the old API to the dmaengine API one by one. Once this is done the old DMA driver can be merged into the i.MX dmaengine driver.
Seems like a nice path forward so FWIW
Yours,
Linus Walleij
Re: [PATCH 4/4] dmaengine: Add Freescale i.MX1/21/27 DMA driver
In reply to Sascha HauerQuoted 12 lines · Sascha Hauer
This driver is currently implemented as a user to the old i.MX DMA API. This allows us to convert each user of the old API to the dmaengine API one by one. Once this is done the old DMA driver can be merged into the i.MX dmaengine driver.
Signed-off-by Sascha Hauer<[email protected]>--- drivers/dma/Kconfig | 8 + drivers/dma/Makefile | 1 + drivers/dma/imx-dma.c | 426 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 435 insertions(+), 0 deletions(-)create mode 100644
drivers/dma/imx-dma.c
[..]
Quoted 32 lines
drivers/dma/imx-dma.c new file +26
-0@@ -0,0 +1,426 @@ +/* +* drivers/dma/imx-dma.c +* +* This file contains a driver for the Freescale i.MX DMA engine +* found on i.MX1/21/27 +* +* Copyright 2010 Sascha Hauer, Pengutronix<[email protected]> +* +* The code contained herein is licensed under the GNU General Public +* License. You may obtain a copy of the GNU General Public License +* Version 2 or later at the following locations: +* +* http://www.opensource.org/licenses/gpl-license.html +* http://www.gnu.org/copyleft/gpl.html +*/ +#include <linux/init.h> +#include <linux/types.h> +#include <linux/mm.h> +#include <linux/interrupt.h> +#include <linux/spinlock.h> +#include <linux/device.h> +#include <linux/dma-mapping.h> +#include <linux/slab.h> +#include <linux/platform_device.h> +#include <linux/dmaengine.h> +
drivers/dma/imx-dma.c line 36
Quoted 10 lines
drivers/dma/imx-dma.c new file +10
-0+#include <asm/irq.h> +#include <mach/dma-v1.h> +#include <mach/hardware.h> + +struct imxdma_channel { +struct imxdma_engine *imxdma; +unsigned int channel; +unsigned int imxdma_channel; + +enum dma_data_direction direction;
Why does the channel have a direction isn't that a function of the transaction? It's also unused.
drivers/dma/imx-dma.c line 38
Quoted 2 lines
drivers/dma/imx-dma.c new file +2
-0+enum dma_slave_buswidth word_size; +dma_addr_t bd_phys;
unused?
drivers/dma/imx-dma.c line 39
Quoted 1 line
drivers/dma/imx-dma.c new file +1
-0+unsigned long flags;
unused?
Quoted 25 lines
drivers/dma/imx-dma.c new file +25
-0+dma_addr_t per_address; +u32 watermark_level; +struct dma_chan chan; +spinlock_t lock; +struct dma_async_tx_descriptor desc; +dma_cookie_t last_completed; +enum dma_status status; +int dma_request; +struct scatterlist *sg_list; +}; + +#define MAX_DMA_CHANNELS 8 + +struct imxdma_engine { +struct device *dev; +struct dma_device dma_device; +struct imxdma_channel channel[MAX_DMA_CHANNELS ]; +}; + +static struct imxdma_channel *to_imxdma_chan (struct dma_chan *chan) +{ + return container_of(chan, struct imxdma_channel, chan); +} + +static void imxdma_handle (struct imxdma_channel *imxdmac)
drivers/dma/imx-dma.c line 74
Quoted 10 lines
drivers/dma/imx-dma.c new file +10
-0+{ +if (imxdmac->desc.callback) + imxdmac->desc.callback (imxdmac->desc.callback_param); + imxdmac->last_completed = imxdmac->desc.cookie; +} + +static void imxdma_irq_handler (int channel,void *data) +{ +struct imxdma_channel *imxdmac = data; +printk ("%s\n" , __func__);
Debug leftover?
drivers/dma/imx-dma.c line 83
Quoted 9 lines
drivers/dma/imx-dma.c new file +9
-0+ imxdmac->status =DMA_SUCCESS ; +imxdma_handle (imxdmac); +} + +static void imxdma_err_handler (int channel,void *data,int error) +{ +struct imxdma_channel *imxdmac = data; +printk ("%s 0x%08x\n" , __func__, error); +dump_stack ();
If you want to keep this I think it is better as a
WARN(1, "%s 0x%08x\n", __func__, error)
...assuming that errors are rare.
--
Dan
Sascha Hauer
maintainerRe: [PATCH 4/4] dmaengine: Add Freescale i.MX1/21/27 DMA driver
Quoted 8 lines · Dan Williams
drivers/dma/imx-dma.c line 36
Quoted 4 lines
drivers/dma/imx-dma.c new file +4
-0+unsigned int channel; +unsigned int imxdma_channel; + +enum dma_data_direction direction;Why does the channel have a direction isn't that a function of the transaction? It's also unused.
Quoted 8 lines
drivers/dma/imx-dma.c line 38
Quoted 2 lines
drivers/dma/imx-dma.c new file +2
-0+enum dma_slave_buswidth word_size; +dma_addr_t bd_phys;unused?
Quoted 1 line
+ unsigned long flags;
unused?
Sorry, it seems I was a bit too fast posting it. I'll send an updated version.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Sascha Hauer
maintainerPATCH v2 4/4 dmaengine: Add Freescale i.MX1/21/27 DMA driver
In reply to Sascha HauerThis driver is currently implemented as a user to the old i.MX DMA API. This allows us to convert each user of the old API to the dmaengine API one by one. Once this is done the old DMA driver can be merged into the i.MX dmaengine driver.
V2: remove some debug leftovers and unused variables
--- drivers/dma/Kconfig | 8 + drivers/dma/Makefile | 1 + drivers/dma/imx-dma.c | 422 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 431 insertions(+), 0 deletions(-) create mode 100644 drivers/dma/imx-dma.c
drivers/dma/Kconfig +8 -0
@@ -203,6 +203,14 @@ config IMX_SDMA Support the i.MX SDMA engine. This engine is integrated into Freescale i.MX25/31/35/51 chips. +config IMX_DMA + tristate "i.MX DMA support" + depends on ARCH_MX1 || ARCH_MX21 || MACH_MX27 + select DMA_ENGINE + help + Support the i.MX DMA engine. This engine is integrated into + Freescale i.MX1/21/27 chips. + config DMA_ENGINE bool
drivers/dma/Makefile +1 -0
@@ -26,3 +26,4 @@ obj-$(CONFIG_STE_DMA40) += ste_dma40.o ste_dma40_ll.o obj-$(CONFIG_PL330_DMA) += pl330.o obj-$(CONFIG_PCH_DMA) += pch_dma.o obj-$(CONFIG_IMX_SDMA) += imx-sdma.o +obj-$(CONFIG_IMX_DMA) += imx-dma.o
drivers/dma/imx-dma.c new file +422 -0
422 lines not on this page · raw message
Signature · 7 lines
1.7.2.3 -- Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |