Skip to content

Commit 0ad7c00

Browse files
nvswarrenVinod Koul
authored andcommitted
dma: add channel request API that supports deferred probe
dma_request_slave_channel() simply returns NULL whenever DMA channel lookup fails. Lookup could fail for two distinct reasons: a) No DMA specification exists for the channel name. This includes situations where no DMA specifications exist at all, or other general lookup problems. b) A DMA specification does exist, yet the driver for that channel is not yet registered. Case (b) should trigger deferred probe in client drivers. However, since they have no way to differentiate the two situations, it cannot. Implement new function dma_request_slave_channel_reason(), which performs identically to dma_request_slave_channel(), except that it returns an error-pointer rather than NULL, which allows callers to detect when deferred probe should occur. Eventually, all drivers should be converted to this new API, the old API removed, and the new API renamed to the more desirable name. This patch doesn't convert the existing API and all drivers in one go, since some drivers call dma_request_slave_channel() then dma_request_channel() if that fails. That would require either modifying dma_request_channel() in the same way, or adding extra error-handling code to all affected drivers, and there are close to 100 drivers using the other API, rather than just the 15-20 or so that use dma_request_slave_channel(), which might be tenable in a single patch. acpi_dma_request_slave_chan_by_name() doesn't currently implement deferred probe. It should, but this will be addressed later. Acked-by: Dan Williams <dan.j.williams@intel.com> Signed-off-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
1 parent 6ce4eac commit 0ad7c00

File tree

3 files changed

+48
-10
lines changed

3 files changed

+48
-10
lines changed

drivers/dma/dmaengine.c

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,8 @@ EXPORT_SYMBOL_GPL(dma_get_slave_channel);
540540
* @mask: capabilities that the channel must satisfy
541541
* @fn: optional callback to disposition available channels
542542
* @fn_param: opaque parameter to pass to dma_filter_fn
543+
*
544+
* Returns pointer to appropriate DMA channel on success or NULL.
543545
*/
544546
struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
545547
dma_filter_fn fn, void *fn_param)
@@ -591,18 +593,43 @@ EXPORT_SYMBOL_GPL(__dma_request_channel);
591593
* dma_request_slave_channel - try to allocate an exclusive slave channel
592594
* @dev: pointer to client device structure
593595
* @name: slave channel name
596+
*
597+
* Returns pointer to appropriate DMA channel on success or an error pointer.
594598
*/
595-
struct dma_chan *dma_request_slave_channel(struct device *dev, const char *name)
599+
struct dma_chan *dma_request_slave_channel_reason(struct device *dev,
600+
const char *name)
596601
{
602+
struct dma_chan *chan;
603+
597604
/* If device-tree is present get slave info from here */
598605
if (dev->of_node)
599606
return of_dma_request_slave_channel(dev->of_node, name);
600607

601608
/* If device was enumerated by ACPI get slave info from here */
602-
if (ACPI_HANDLE(dev))
603-
return acpi_dma_request_slave_chan_by_name(dev, name);
609+
if (ACPI_HANDLE(dev)) {
610+
chan = acpi_dma_request_slave_chan_by_name(dev, name);
611+
if (chan)
612+
return chan;
613+
}
604614

605-
return NULL;
615+
return ERR_PTR(-ENODEV);
616+
}
617+
EXPORT_SYMBOL_GPL(dma_request_slave_channel_reason);
618+
619+
/**
620+
* dma_request_slave_channel - try to allocate an exclusive slave channel
621+
* @dev: pointer to client device structure
622+
* @name: slave channel name
623+
*
624+
* Returns pointer to appropriate DMA channel on success or NULL.
625+
*/
626+
struct dma_chan *dma_request_slave_channel(struct device *dev,
627+
const char *name)
628+
{
629+
struct dma_chan *ch = dma_request_slave_channel_reason(dev, name);
630+
if (IS_ERR(ch))
631+
return NULL;
632+
return ch;
606633
}
607634
EXPORT_SYMBOL_GPL(dma_request_slave_channel);
608635

drivers/dma/of-dma.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ static int of_dma_match_channel(struct device_node *np, const char *name,
143143
* @np: device node to get DMA request from
144144
* @name: name of desired channel
145145
*
146-
* Returns pointer to appropriate dma channel on success or NULL on error.
146+
* Returns pointer to appropriate DMA channel on success or an error pointer.
147147
*/
148148
struct dma_chan *of_dma_request_slave_channel(struct device_node *np,
149149
const char *name)
@@ -152,17 +152,18 @@ struct dma_chan *of_dma_request_slave_channel(struct device_node *np,
152152
struct of_dma *ofdma;
153153
struct dma_chan *chan;
154154
int count, i;
155+
int ret_no_channel = -ENODEV;
155156

156157
if (!np || !name) {
157158
pr_err("%s: not enough information provided\n", __func__);
158-
return NULL;
159+
return ERR_PTR(-ENODEV);
159160
}
160161

161162
count = of_property_count_strings(np, "dma-names");
162163
if (count < 0) {
163164
pr_err("%s: dma-names property of node '%s' missing or empty\n",
164165
__func__, np->full_name);
165-
return NULL;
166+
return ERR_PTR(-ENODEV);
166167
}
167168

168169
for (i = 0; i < count; i++) {
@@ -172,10 +173,12 @@ struct dma_chan *of_dma_request_slave_channel(struct device_node *np,
172173
mutex_lock(&of_dma_lock);
173174
ofdma = of_dma_find_controller(&dma_spec);
174175

175-
if (ofdma)
176+
if (ofdma) {
176177
chan = ofdma->of_dma_xlate(&dma_spec, ofdma);
177-
else
178+
} else {
179+
ret_no_channel = -EPROBE_DEFER;
178180
chan = NULL;
181+
}
179182

180183
mutex_unlock(&of_dma_lock);
181184

@@ -185,7 +188,7 @@ struct dma_chan *of_dma_request_slave_channel(struct device_node *np,
185188
return chan;
186189
}
187190

188-
return NULL;
191+
return ERR_PTR(ret_no_channel);
189192
}
190193

191194
/**

include/linux/dmaengine.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#define LINUX_DMAENGINE_H
2323

2424
#include <linux/device.h>
25+
#include <linux/err.h>
2526
#include <linux/uio.h>
2627
#include <linux/bug.h>
2728
#include <linux/scatterlist.h>
@@ -1040,6 +1041,8 @@ enum dma_status dma_wait_for_async_tx(struct dma_async_tx_descriptor *tx);
10401041
void dma_issue_pending_all(void);
10411042
struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
10421043
dma_filter_fn fn, void *fn_param);
1044+
struct dma_chan *dma_request_slave_channel_reason(struct device *dev,
1045+
const char *name);
10431046
struct dma_chan *dma_request_slave_channel(struct device *dev, const char *name);
10441047
void dma_release_channel(struct dma_chan *chan);
10451048
#else
@@ -1063,6 +1066,11 @@ static inline struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
10631066
{
10641067
return NULL;
10651068
}
1069+
static inline struct dma_chan *dma_request_slave_channel_reason(
1070+
struct device *dev, const char *name)
1071+
{
1072+
return ERR_PTR(-ENODEV);
1073+
}
10661074
static inline struct dma_chan *dma_request_slave_channel(struct device *dev,
10671075
const char *name)
10681076
{

0 commit comments

Comments
 (0)