dmaengine: introduce is_slave_xfer helper
v2 cover dmaengine: introduce is_slave_xfer helper
There is a common practice to distinguish slave type transfers by checking direction of the channel. This series introduces the check helper and its usage across the drivers.
Since v1:
- append commit messages to the all patches
- update description for the patches against dw_dmac and at_hdmac
- apply all current Reviewed-by and Acked-by tags
Andy Shevchenko (6):
dmaengine: introduce is_slave_xfer function
dma: at_hdmac: check direction properly for cyclic transfers
dma: dw_dmac: check direction properly in dw_dma_cyclic_prep
dma: ep93xx_dma: reuse is_slave_xfer helper
dma: ipu_idmac: reuse is_slave_xfer helper
dma: ste_dma40: reuse is_slave_xfer helper
drivers/dma/at_hdmac.c | 10 +++++----- drivers/dma/dw_dmac.c | 5 +++-- drivers/dma/ep93xx_dma.c | 3 +-- drivers/dma/ipu/ipu_idmac.c | 2 +- drivers/dma/ste_dma40.c | 2 +- include/linux/dmaengine.h | 5 +++++ 6 files changed, 16 insertions(+), 11 deletions(-)
Signature · 1 line
1.7.10.4
PATCH v2 1/6 dmaengine: introduce is_slave_xfer function
This function helps to distinguish the slave type of transfer by checking the direction parameter.
--- include/linux/dmaengine.h | 5 +++++ 1 file changed, 5 insertions(+)
include/linux/dmaengine.h +5 -0
@@ -618,6 +618,11 @@ static inline int dmaengine_slave_config(struct dma_chan *chan, (unsigned long)config); } +static inline bool is_slave_xfer (enum dma_transfer_direction direction) +{ +return (direction ==DMA_MEM_TO_DEV ) || (direction ==DMA_DEV_TO_MEM ); +} +static inline struct dma_async_tx_descriptor *dmaengine_prep_slave_single (struct dma_chan *chan,dma_addr_t buf,size_t len,enum dma_transfer_direction dir,unsigned long flags)
Signature · 1 line
1.7.10.4
Re: [PATCHv2 1/6] dmaengine: introduce is_slave_xfer function
Quoted 2 lines · Andy Shevchenko
This function helps to distinguish the slave type of transfer by checking the direction parameter.
Looks like a good idea.
Yours,
Linus Walleij
PATCH v2 2/6 dma: at_hdmac: check direction properly for cyclic transfers
In reply to Andy Shevchenkodma_transfer_direction is a normal enum. It means we can't usually use the values as bit fields. Let's adjust this check and move it above the usage of the direction parameter, due to the nature of the following usage of it.
--- drivers/dma/at_hdmac.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/dma/at_hdmac.c +5 -5
@@ -778,7 +778,7 @@ err:*/ static int atc_dma_cyclic_check_values (unsigned int reg_width,dma_addr_t buf_addr, -size_t period_len,enum dma_transfer_direction direction) +size_t period_len) {if (period_len > (ATC_BTSIZE_MAX << reg_width)) goto err_out;
@@ -786,8 +786,6 @@ atc_dma_cyclic_check_values(unsigned int reg_width, dma_addr_t buf_addr, goto err_out;if (unlikely (buf_addr & ((1 << reg_width) -1 ))) goto err_out; -if (unlikely (!(direction & (DMA_DEV_TO_MEM |DMA_MEM_TO_DEV )))) - goto err_out;return 0 ;
@@ -886,14 +884,16 @@ atc_prep_dma_cyclic(struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,return NULL ; } +if (unlikely (!is_slave_xfer (direction))) + goto err_out; +if (sconfig->direction ==DMA_MEM_TO_DEV ) reg_width =convert_buswidth (sconfig->dst_addr_width);else reg_width =convert_buswidth (sconfig->src_addr_width);/* Check for too big/unaligned periods and unaligned DMA buffer */ -if (atc_dma_cyclic_check_values (reg_width, buf_addr, - period_len, direction)) +if (atc_dma_cyclic_check_values (reg_width, buf_addr, period_len)) goto err_out;/* build cyclic linked list */
Signature · 1 line
1.7.10.4
PATCH v2 3/6 dma: dw_dmac: check direction properly in dw_dma_cyclic_prep
In reply to Andy Shevchenkodma_transfer_direction is a normal enum. It means we can't usually use the values as bit fields. Let's adjust this check and move it above the usage of the direction parameter, due to the nature of the following usage of it.
--- drivers/dma/dw_dmac.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/dma/dw_dmac.c +3 -2
@@ -1336,6 +1336,9 @@ struct dw_cyclic_desc *dw_dma_cyclic_prep(struct dma_chan *chan, retval =ERR_PTR (-EINVAL ); +if (unlikely (!is_slave_xfer (direction))) + goto out_err; +if (direction ==DMA_MEM_TO_DEV ) reg_width =__ffs (sconfig->dst_addr_width);else
@@ -1350,8 +1353,6 @@ struct dw_cyclic_desc *dw_dma_cyclic_prep(struct dma_chan *chan, goto out_err;if (unlikely (buf_addr & ((1 << reg_width) -1 ))) goto out_err; -if (unlikely (!(direction & (DMA_MEM_TO_DEV |DMA_DEV_TO_MEM )))) - goto out_err; retval =ERR_PTR (-ENOMEM );
Signature · 1 line
1.7.10.4
PATCH v2 4/6 dma: ep93xx_dma: reuse is_slave_xfer helper
In reply to Andy ShevchenkoThe is_slave_xfer helps to check if the transfer type is slave.
--- drivers/dma/ep93xx_dma.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/dma/ep93xx_dma.c +1 -2
@@ -903,8 +903,7 @@ static int ep93xx_dma_alloc_chan_resources(struct dma_chan *chan)switch (data->port) {case EP93XX_DMA_SSP :case EP93XX_DMA_IDE : -if (data->direction !=DMA_MEM_TO_DEV && - data->direction !=DMA_DEV_TO_MEM ) +if (!is_slave_xfer (data->direction))return -EINVAL ;break ;default :
Signature · 1 line
1.7.10.4
PATCH v2 5/6 dma: ipu_idmac: reuse is_slave_xfer helper
In reply to Andy ShevchenkoThe is_slave_xfer helps to check if the transfer type is slave.
--- drivers/dma/ipu/ipu_idmac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/ipu/ipu_idmac.c +1 -1
@@ -1347,7 +1347,7 @@ static struct dma_async_tx_descriptor *idmac_prep_slave_sg(struct dma_chan *chan chan->chan_id != IDMAC_IC_7)return NULL ; -if (direction !=DMA_DEV_TO_MEM && direction !=DMA_MEM_TO_DEV ) { +if (!is_slave_xfer (direction)) {dev_err (chan->device->dev,"Invalid DMA direction %d!\n" , direction);return NULL ; }
Signature · 1 line
1.7.10.4
PATCH v2 6/6 dma: ste_dma40: reuse is_slave_xfer helper
In reply to Andy ShevchenkoThe is_slave_xfer helps to check if the transfer type is slave.
--- drivers/dma/ste_dma40.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/ste_dma40.c +1 -1
@@ -2337,7 +2337,7 @@ static struct dma_async_tx_descriptor *d40_prep_slave_sg(struct dma_chan *chan, unsigned long dma_flags, void *context) { -if (direction !=DMA_DEV_TO_MEM && direction !=DMA_MEM_TO_DEV ) +if (!is_slave_xfer (direction))return NULL ;return d40_prep_sg (chan, sgl, sgl, sg_len, direction, dma_flags);
Signature · 1 line
1.7.10.4
Re: [PATCHv2 6/6] dma: ste_dma40: reuse is_slave_xfer helper
Quoted 5 lines · Andy Shevchenko
The
is_slave_xferhelps to check if the transfer type is slave.Signed-off-by Andy Shevchenko <[email protected]>Reviewed-by Viresh Kumar <[email protected]>Cc Linus Walleij <[email protected]>
Yours,
Linus Walleij