Skip to content

Commit 8010dad

Browse files
nvswarrenVinod Koul
authored andcommitted
dma: add dma_get_any_slave_channel(), for use in of_xlate()
mmp_pdma.c implements a custom of_xlate() function that is 95% identical to what Tegra will need. Create a function to implement the common part, so everyone doesn't just cut/paste the implementation. Cc: Dan Williams <dan.j.williams@intel.com> Cc: Vinod Koul <vinod.koul@intel.com> Cc: Lars-Peter Clausen <lars@metafoo.de> Cc: dmaengine@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
1 parent 6ce4eac commit 8010dad

File tree

3 files changed

+36
-23
lines changed

3 files changed

+36
-23
lines changed

drivers/dma/dmaengine.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,34 @@ struct dma_chan *dma_get_slave_channel(struct dma_chan *chan)
535535
}
536536
EXPORT_SYMBOL_GPL(dma_get_slave_channel);
537537

538+
struct dma_chan *dma_get_any_slave_channel(struct dma_device *device)
539+
{
540+
dma_cap_mask_t mask;
541+
struct dma_chan *chan;
542+
int err;
543+
544+
dma_cap_zero(mask);
545+
dma_cap_set(DMA_SLAVE, mask);
546+
547+
/* lock against __dma_request_channel */
548+
mutex_lock(&dma_list_mutex);
549+
550+
chan = private_candidate(&mask, device, NULL, NULL);
551+
if (chan) {
552+
err = dma_chan_get(chan);
553+
if (err) {
554+
pr_debug("%s: failed to get %s: (%d)\n",
555+
__func__, dma_chan_name(chan), err);
556+
chan = NULL;
557+
}
558+
}
559+
560+
mutex_unlock(&dma_list_mutex);
561+
562+
return chan;
563+
}
564+
EXPORT_SYMBOL_GPL(dma_get_any_slave_channel);
565+
538566
/**
539567
* __dma_request_channel - try to allocate an exclusive channel
540568
* @mask: capabilities that the channel must satisfy

drivers/dma/mmp_pdma.c

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -893,33 +893,17 @@ static struct dma_chan *mmp_pdma_dma_xlate(struct of_phandle_args *dma_spec,
893893
struct of_dma *ofdma)
894894
{
895895
struct mmp_pdma_device *d = ofdma->of_dma_data;
896-
struct dma_chan *chan, *candidate;
896+
struct dma_chan *chan;
897+
struct mmp_pdma_chan *c;
897898

898-
retry:
899-
candidate = NULL;
900-
901-
/* walk the list of channels registered with the current instance and
902-
* find one that is currently unused */
903-
list_for_each_entry(chan, &d->device.channels, device_node)
904-
if (chan->client_count == 0) {
905-
candidate = chan;
906-
break;
907-
}
908-
909-
if (!candidate)
899+
chan = dma_get_any_slave_channel(&d->device);
900+
if (!chan)
910901
return NULL;
911902

912-
/* dma_get_slave_channel will return NULL if we lost a race between
913-
* the lookup and the reservation */
914-
chan = dma_get_slave_channel(candidate);
915-
916-
if (chan) {
917-
struct mmp_pdma_chan *c = to_mmp_pdma_chan(chan);
918-
c->drcmr = dma_spec->args[0];
919-
return chan;
920-
}
903+
c = to_mmp_pdma_chan(chan);
904+
c->drcmr = dma_spec->args[0];
921905

922-
goto retry;
906+
return chan;
923907
}
924908

925909
static int mmp_pdma_probe(struct platform_device *op)

include/linux/dmaengine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,7 @@ int dma_async_device_register(struct dma_device *device);
10791079
void dma_async_device_unregister(struct dma_device *device);
10801080
void dma_run_dependencies(struct dma_async_tx_descriptor *tx);
10811081
struct dma_chan *dma_get_slave_channel(struct dma_chan *chan);
1082+
struct dma_chan *dma_get_any_slave_channel(struct dma_device *device);
10821083
struct dma_chan *net_dma_find_channel(void);
10831084
#define dma_request_channel(mask, x, y) __dma_request_channel(&(mask), x, y)
10841085
#define dma_request_slave_channel_compat(mask, x, y, dev, name) \

0 commit comments

Comments
 (0)