Skip to content

Commit 4d130de

Browse files
andy-shevVinod Koul
authored andcommitted
dmaengine: dw: introduce generic filter function
The introduced filter function would be reused in the ACPI and DT cases since in those cases we have to apply mandatory data to the requested channel. Thus, patch moves platform driver to use it in that case. The function unlikely can't be used by users of the driver due to an implicit dependency to the dw_dmac_core module. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
1 parent 8950052 commit 4d130de

3 files changed

Lines changed: 40 additions & 67 deletions

File tree

‎drivers/dma/dw/core.c‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,26 @@ dwc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
919919
return NULL;
920920
}
921921

922+
bool dw_dma_filter(struct dma_chan *chan, void *param)
923+
{
924+
struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
925+
struct dw_dma_slave *dws = param;
926+
927+
if (!dws || dws->dma_dev != chan->device->dev)
928+
return false;
929+
930+
/* We have to copy data since dws can be temporary storage */
931+
932+
dwc->src_id = dws->src_id;
933+
dwc->dst_id = dws->dst_id;
934+
935+
dwc->src_master = dws->src_master;
936+
dwc->dst_master = dws->dst_master;
937+
938+
return true;
939+
}
940+
EXPORT_SYMBOL_GPL(dw_dma_filter);
941+
922942
/*
923943
* Fix sconfig's burst size according to dw_dmac. We need to convert them as:
924944
* 1 -> 0, 4 -> 1, 8 -> 2, 16 -> 3.

‎drivers/dma/dw/internal.h‎

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,6 @@ int dw_dma_resume(struct dw_dma_chip *chip);
4343

4444
#endif /* CONFIG_PM_SLEEP */
4545

46-
/**
47-
* dwc_get_dms - get destination master
48-
* @slave: pointer to the custom slave configuration
49-
*
50-
* Returns destination master in the custom slave configuration if defined, or
51-
* default value otherwise.
52-
*/
53-
static inline unsigned int dwc_get_dms(struct dw_dma_slave *slave)
54-
{
55-
return slave ? slave->dst_master : 0;
56-
}
57-
58-
/**
59-
* dwc_get_sms - get source master
60-
* @slave: pointer to the custom slave configuration
61-
*
62-
* Returns source master in the custom slave configuration if defined, or
63-
* default value otherwise.
64-
*/
65-
static inline unsigned int dwc_get_sms(struct dw_dma_slave *slave)
66-
{
67-
return slave ? slave->src_master : 1;
68-
}
46+
extern bool dw_dma_filter(struct dma_chan *chan, void *param);
6947

7048
#endif /* _DW_DMAC_INTERNAL_H */

‎drivers/dma/dw/platform.c‎

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -25,74 +25,49 @@
2525

2626
#include "internal.h"
2727

28-
struct dw_dma_of_filter_args {
29-
struct dw_dma *dw;
30-
unsigned int req;
31-
unsigned int src;
32-
unsigned int dst;
33-
};
34-
35-
static bool dw_dma_of_filter(struct dma_chan *chan, void *param)
36-
{
37-
struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
38-
struct dw_dma_of_filter_args *fargs = param;
39-
40-
/* Ensure the device matches our channel */
41-
if (chan->device != &fargs->dw->dma)
42-
return false;
43-
44-
dwc->src_id = fargs->req;
45-
dwc->dst_id = fargs->req;
46-
dwc->src_master = fargs->src;
47-
dwc->dst_master = fargs->dst;
48-
49-
return true;
50-
}
51-
5228
static struct dma_chan *dw_dma_of_xlate(struct of_phandle_args *dma_spec,
5329
struct of_dma *ofdma)
5430
{
5531
struct dw_dma *dw = ofdma->of_dma_data;
56-
struct dw_dma_of_filter_args fargs = {
57-
.dw = dw,
32+
struct dw_dma_slave slave = {
33+
.dma_dev = dw->dma.dev,
5834
};
5935
dma_cap_mask_t cap;
6036

6137
if (dma_spec->args_count != 3)
6238
return NULL;
6339

64-
fargs.req = dma_spec->args[0];
65-
fargs.src = dma_spec->args[1];
66-
fargs.dst = dma_spec->args[2];
40+
slave.src_id = dma_spec->args[0];
41+
slave.dst_id = dma_spec->args[0];
42+
slave.src_master = dma_spec->args[1];
43+
slave.dst_master = dma_spec->args[2];
6744

68-
if (WARN_ON(fargs.req >= DW_DMA_MAX_NR_REQUESTS ||
69-
fargs.src >= dw->nr_masters ||
70-
fargs.dst >= dw->nr_masters))
45+
if (WARN_ON(slave.src_id >= DW_DMA_MAX_NR_REQUESTS ||
46+
slave.dst_id >= DW_DMA_MAX_NR_REQUESTS ||
47+
slave.src_master >= dw->nr_masters ||
48+
slave.dst_master >= dw->nr_masters))
7149
return NULL;
7250

7351
dma_cap_zero(cap);
7452
dma_cap_set(DMA_SLAVE, cap);
7553

7654
/* TODO: there should be a simpler way to do this */
77-
return dma_request_channel(cap, dw_dma_of_filter, &fargs);
55+
return dma_request_channel(cap, dw_dma_filter, &slave);
7856
}
7957

8058
#ifdef CONFIG_ACPI
8159
static bool dw_dma_acpi_filter(struct dma_chan *chan, void *param)
8260
{
83-
struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
8461
struct acpi_dma_spec *dma_spec = param;
62+
struct dw_dma_slave slave = {
63+
.dma_dev = dma_spec->dev,
64+
.src_id = dma_spec->slave_id,
65+
.dst_id = dma_spec->slave_id,
66+
.src_master = 1,
67+
.dst_master = 0,
68+
};
8569

86-
if (chan->device->dev != dma_spec->dev ||
87-
chan->chan_id != dma_spec->chan_id)
88-
return false;
89-
90-
dwc->src_id = dma_spec->slave_id;
91-
dwc->dst_id = dma_spec->slave_id;
92-
dwc->src_master = dwc_get_sms(NULL);
93-
dwc->dst_master = dwc_get_dms(NULL);
94-
95-
return true;
70+
return dw_dma_filter(chan, &slave);
9671
}
9772

9873
static void dw_dma_acpi_controller_register(struct dw_dma *dw)

0 commit comments

Comments
 (0)