Skip to content

Commit 7bb587f

Browse files
zhangfeigaoVinod Koul
authored andcommitted
dmaengine: add interface of dma_get_slave_channel
Suggested by Arnd, add dma_get_slave_channel interface Dma host driver could get specific channel specificied by request line, rather than filter. host example: static struct dma_chan *xx_of_dma_simple_xlate(struct of_phandle_args *dma_spec, struct of_dma *ofdma) { struct xx_dma_dev *d = ofdma->of_dma_data; unsigned int request = dma_spec->args[0]; if (request > d->dma_requests) return NULL; return dma_get_slave_channel(&(d->chans[request].vc.chan)); } probe: of_dma_controller_register((&op->dev)->of_node, xx_of_dma_simple_xlate, d); Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org> Acked-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
1 parent c095ba7 commit 7bb587f

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

‎drivers/dma/dmaengine.c‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,32 @@ static struct dma_chan *private_candidate(const dma_cap_mask_t *mask,
503503
return NULL;
504504
}
505505

506+
/**
507+
* dma_request_channel - try to get specific channel exclusively
508+
* @chan: target channel
509+
*/
510+
struct dma_chan *dma_get_slave_channel(struct dma_chan *chan)
511+
{
512+
int err = -EBUSY;
513+
514+
/* lock against __dma_request_channel */
515+
mutex_lock(&dma_list_mutex);
516+
517+
if (chan->client_count == 0)
518+
err = dma_chan_get(chan);
519+
else
520+
chan = NULL;
521+
522+
mutex_unlock(&dma_list_mutex);
523+
524+
if (err)
525+
pr_debug("%s: failed to get %s: (%d)\n",
526+
__func__, dma_chan_name(chan), err);
527+
528+
return chan;
529+
}
530+
EXPORT_SYMBOL_GPL(dma_get_slave_channel);
531+
506532
/**
507533
* dma_request_channel - try to allocate an exclusive channel
508534
* @mask: capabilities that the channel must satisfy

‎include/linux/dmaengine.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,7 @@ int dma_async_device_register(struct dma_device *device);
995995
void dma_async_device_unregister(struct dma_device *device);
996996
void dma_run_dependencies(struct dma_async_tx_descriptor *tx);
997997
struct dma_chan *dma_find_channel(enum dma_transaction_type tx_type);
998+
struct dma_chan *dma_get_slave_channel(struct dma_chan *chan);
998999
struct dma_chan *net_dma_find_channel(void);
9991000
#define dma_request_channel(mask, x, y) __dma_request_channel(&(mask), x, y)
10001001
#define dma_request_slave_channel_compat(mask, x, y, dev, name) \

0 commit comments

Comments
 (0)