Skip to content

Commit d8fa080

Browse files
fancervinodkoul
authored andcommitted
dmaengine: dw: Simplify max-burst calculation procedure
In order to have a more coherent DW AHB DMA slave configuration method - dwc_config() - let's simplify the source and destination channel max-burst calculation procedure: 1. Create the max-burst verification method as it has been just done for the memory and peripheral address widths. Thus the dwc_config() method will turn to a set of the verification methods execution. 2. Since both the generic DW AHB DMA and Intel iDMA 32-bit engines support the power-of-2 bursts only, then the specified by the client driver max-burst values can be converted to being power-of-2 right in the max-burst verification method. 3. Since max-burst encoded value is required on the CTL_LO fields calculation stage, the encode_maxburst() callback can be easily dropped from the dw_dma structure meanwhile the encoding procedure will be executed right in the CTL_LO register value calculation. Thus the update will provide the next positive effects: the internal DMA-slave config structure will contain only the real DMA-transfer config values, which will be encoded to the DMA-controller register fields only when it's required on the buffer mapping; the redundant encode_maxburst() callback will be dropped simplifying the internal HW-abstraction API; dwc_config() will look more readable executing the verification functions one-by-one. Signed-off-by: Serge Semin <[email protected]> Acked-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 3acb301 commit d8fa080

File tree

4 files changed

+29
-20
lines changed

4 files changed

+29
-20
lines changed

drivers/dma/dw/core.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,23 @@ bool dw_dma_filter(struct dma_chan *chan, void *param)
779779
}
780780
EXPORT_SYMBOL_GPL(dw_dma_filter);
781781

782+
static int dwc_verify_maxburst(struct dma_chan *chan)
783+
{
784+
struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
785+
786+
dwc->dma_sconfig.src_maxburst =
787+
clamp(dwc->dma_sconfig.src_maxburst, 1U, dwc->max_burst);
788+
dwc->dma_sconfig.dst_maxburst =
789+
clamp(dwc->dma_sconfig.dst_maxburst, 1U, dwc->max_burst);
790+
791+
dwc->dma_sconfig.src_maxburst =
792+
rounddown_pow_of_two(dwc->dma_sconfig.src_maxburst);
793+
dwc->dma_sconfig.dst_maxburst =
794+
rounddown_pow_of_two(dwc->dma_sconfig.dst_maxburst);
795+
796+
return 0;
797+
}
798+
782799
static int dwc_verify_p_buswidth(struct dma_chan *chan)
783800
{
784801
struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
@@ -838,7 +855,7 @@ static int dwc_verify_m_buswidth(struct dma_chan *chan)
838855
dwc->dma_sconfig.src_addr_width = mem_width;
839856
} else if (dwc->dma_sconfig.direction == DMA_DEV_TO_MEM) {
840857
reg_width = dwc->dma_sconfig.src_addr_width;
841-
reg_burst = rounddown_pow_of_two(dwc->dma_sconfig.src_maxburst);
858+
reg_burst = dwc->dma_sconfig.src_maxburst;
842859

843860
dwc->dma_sconfig.dst_addr_width = min(mem_width, reg_width * reg_burst);
844861
}
@@ -849,15 +866,13 @@ static int dwc_verify_m_buswidth(struct dma_chan *chan)
849866
static int dwc_config(struct dma_chan *chan, struct dma_slave_config *sconfig)
850867
{
851868
struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
852-
struct dw_dma *dw = to_dw_dma(chan->device);
853869
int ret;
854870

855871
memcpy(&dwc->dma_sconfig, sconfig, sizeof(*sconfig));
856872

857-
dwc->dma_sconfig.src_maxburst =
858-
clamp(dwc->dma_sconfig.src_maxburst, 1U, dwc->max_burst);
859-
dwc->dma_sconfig.dst_maxburst =
860-
clamp(dwc->dma_sconfig.dst_maxburst, 1U, dwc->max_burst);
873+
ret = dwc_verify_maxburst(chan);
874+
if (ret)
875+
return ret;
861876

862877
ret = dwc_verify_p_buswidth(chan);
863878
if (ret)
@@ -867,9 +882,6 @@ static int dwc_config(struct dma_chan *chan, struct dma_slave_config *sconfig)
867882
if (ret)
868883
return ret;
869884

870-
dw->encode_maxburst(dwc, &dwc->dma_sconfig.src_maxburst);
871-
dw->encode_maxburst(dwc, &dwc->dma_sconfig.dst_maxburst);
872-
873885
return 0;
874886
}
875887

drivers/dma/dw/dw.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ static size_t dw_dma_block2bytes(struct dw_dma_chan *dwc, u32 block, u32 width)
6464
return DWC_CTLH_BLOCK_TS(block) << width;
6565
}
6666

67-
static void dw_dma_encode_maxburst(struct dw_dma_chan *dwc, u32 *maxburst)
67+
static inline u8 dw_dma_encode_maxburst(u32 maxburst)
6868
{
6969
/*
7070
* Fix burst size according to dw_dmac. We need to convert them as:
7171
* 1 -> 0, 4 -> 1, 8 -> 2, 16 -> 3.
7272
*/
73-
*maxburst = *maxburst > 1 ? fls(*maxburst) - 2 : 0;
73+
return maxburst > 1 ? fls(maxburst) - 2 : 0;
7474
}
7575

7676
static u32 dw_dma_prepare_ctllo(struct dw_dma_chan *dwc)
@@ -82,11 +82,11 @@ static u32 dw_dma_prepare_ctllo(struct dw_dma_chan *dwc)
8282
if (dwc->direction == DMA_MEM_TO_DEV) {
8383
sms = dwc->dws.m_master;
8484
dms = dwc->dws.p_master;
85-
dmsize = sconfig->dst_maxburst;
85+
dmsize = dw_dma_encode_maxburst(sconfig->dst_maxburst);
8686
} else if (dwc->direction == DMA_DEV_TO_MEM) {
8787
sms = dwc->dws.p_master;
8888
dms = dwc->dws.m_master;
89-
smsize = sconfig->src_maxburst;
89+
smsize = dw_dma_encode_maxburst(sconfig->src_maxburst);
9090
} else /* DMA_MEM_TO_MEM */ {
9191
sms = dwc->dws.m_master;
9292
dms = dwc->dws.m_master;
@@ -125,7 +125,6 @@ int dw_dma_probe(struct dw_dma_chip *chip)
125125
dw->suspend_chan = dw_dma_suspend_chan;
126126
dw->resume_chan = dw_dma_resume_chan;
127127
dw->prepare_ctllo = dw_dma_prepare_ctllo;
128-
dw->encode_maxburst = dw_dma_encode_maxburst;
129128
dw->bytes2block = dw_dma_bytes2block;
130129
dw->block2bytes = dw_dma_block2bytes;
131130

drivers/dma/dw/idma32.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ static size_t idma32_block2bytes(struct dw_dma_chan *dwc, u32 block, u32 width)
199199
return IDMA32C_CTLH_BLOCK_TS(block);
200200
}
201201

202-
static void idma32_encode_maxburst(struct dw_dma_chan *dwc, u32 *maxburst)
202+
static inline u8 idma32_encode_maxburst(u32 maxburst)
203203
{
204-
*maxburst = *maxburst > 1 ? fls(*maxburst) - 1 : 0;
204+
return maxburst > 1 ? fls(maxburst) - 1 : 0;
205205
}
206206

207207
static u32 idma32_prepare_ctllo(struct dw_dma_chan *dwc)
@@ -210,9 +210,9 @@ static u32 idma32_prepare_ctllo(struct dw_dma_chan *dwc)
210210
u8 smsize = 0, dmsize = 0;
211211

212212
if (dwc->direction == DMA_MEM_TO_DEV)
213-
dmsize = sconfig->dst_maxburst;
213+
dmsize = idma32_encode_maxburst(sconfig->dst_maxburst);
214214
else if (dwc->direction == DMA_DEV_TO_MEM)
215-
smsize = sconfig->src_maxburst;
215+
smsize = idma32_encode_maxburst(sconfig->src_maxburst);
216216

217217
return DWC_CTLL_LLP_D_EN | DWC_CTLL_LLP_S_EN |
218218
DWC_CTLL_DST_MSIZE(dmsize) | DWC_CTLL_SRC_MSIZE(smsize);
@@ -274,7 +274,6 @@ int idma32_dma_probe(struct dw_dma_chip *chip)
274274
dw->suspend_chan = idma32_suspend_chan;
275275
dw->resume_chan = idma32_resume_chan;
276276
dw->prepare_ctllo = idma32_prepare_ctllo;
277-
dw->encode_maxburst = idma32_encode_maxburst;
278277
dw->bytes2block = idma32_bytes2block;
279278
dw->block2bytes = idma32_block2bytes;
280279

drivers/dma/dw/regs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ struct dw_dma {
327327
void (*suspend_chan)(struct dw_dma_chan *dwc, bool drain);
328328
void (*resume_chan)(struct dw_dma_chan *dwc, bool drain);
329329
u32 (*prepare_ctllo)(struct dw_dma_chan *dwc);
330-
void (*encode_maxburst)(struct dw_dma_chan *dwc, u32 *maxburst);
331330
u32 (*bytes2block)(struct dw_dma_chan *dwc, size_t bytes,
332331
unsigned int width, size_t *len);
333332
size_t (*block2bytes)(struct dw_dma_chan *dwc, u32 block, u32 width);

0 commit comments

Comments
 (0)