dw_dmac: don't exceed AHB master number in dwc_get_data_width
PATCH v2 1/1 dw_dmac: don't exceed AHB master number in dwc_get_data_width
The driver's default assumes that hardware has two AHB masters which might be not true. In such rare cases we have not to exceed a number of the AHB masters present in the hardware. Thus, the AHB master with highest possible number will be used to retrieve the data witdh value.
The patch also changes the logic a bit when the master parameter of the dwc_get_data_width() is out of range. Now the function will return a value related to the first AHB master.
--- drivers/dma/dw_dmac.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-)
drivers/dma/dw_dmac.c +20 -13
@@ -46,13 +46,29 @@ static inline unsigned int dwc_get_sms(struct dw_dma_slave *slave)return slave ? slave->src_master :1 ; } +#define SRC_MASTER 0 +#define DST_MASTER 1 + +static inline unsigned int dwc_get_master (struct dma_chan *chan,int master) +{ +struct dw_dma *dw =to_dw_dma (chan->device); +struct dw_dma_slave *dws = chan->private; +unsigned int m =0 ; + +if (master ==SRC_MASTER ) + m =dwc_get_sms (dws); +else if (master ==DST_MASTER ) + m =dwc_get_dms (dws); + + return min_t(unsigned int, dw->nr_masters - 1, m); +} +#define DWC_DEFAULT_CTLLO (_chan) ({ \ - struct dw_dma_slave *__slave = (_chan->private); \ struct dw_dma_chan *_dwc = to_dw_dma_chan(_chan); \ struct dma_slave_config *_sconfig = &_dwc->dma_sconfig; \ bool _is_slave = is_slave_direction(_dwc->direction); \ - int _dms = dwc_get_dms(__slave); \ - int _sms = dwc_get_sms(__slave); \ + int _dms = dwc_get_master(_chan, DST_MASTER); \ + int _sms = dwc_get_master(_chan, SRC_MASTER); \ u8 _smsize = _is_slave ? _sconfig->src_maxburst : \ DW_DMA_MSIZE_16; \ u8 _dmsize = _is_slave ? _sconfig->dst_maxburst : \
@@ -73,20 +89,11 @@ static inline unsigned int dwc_get_sms(struct dw_dma_slave *slave)*/ #define NR_DESCS_PER_CHANNEL 64 -#define SRC_MASTER 0 -#define DST_MASTER 1 -static inline unsigned int dwc_get_data_width (struct dma_chan *chan,int master) {struct dw_dma *dw =to_dw_dma (chan->device); -struct dw_dma_slave *dws = chan->private; -if (master ==SRC_MASTER ) -return dw->data_width[dwc_get_sms (dws)]; -else if (master ==DST_MASTER ) -return dw->data_width[dwc_get_dms (dws)]; - -return 0 ; +return dw->data_width[dwc_get_master (chan, master)]; }/*----------------------------------------------------------------------*/
Signature · 1 line
1.7.10.4
Looks fine now, just some minor issues.
- I believe there should be a space between "PATCH" and "v2" in subject.
- Changelog missing v1->v2, place it after three dash "-" and before file name present below.
Quoted 4 lines · Andy Shevchenko
The driver's default assumes that hardware has two AHB masters which might be not true. In such rare cases we have not to exceed a number of the AHB masters present in the hardware. Thus, the AHB master with highest possible number will be used to retrieve the data witdh value.
I would write it as:
The driver assumes that hardware has two AHB masters which might not be always true. In such cases we must not exceed number of the AHB masters present in the hardware. In the proposed scheme in this patch, we would choose the master with highest possible number whenever we exceed max AHB masters.
Quoted 3 lines
The patch also changes the logic a bit when the master parameter of the
dwc_get_data_width()is out of range. Now the function will return a value related to the first AHB master.
This para is not required, i believe.
Quoted 11 lines
Signed-off-by Andy Shevchenko <[email protected]>--- drivers/dma/dw_dmac.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-)drivers/dma/dw_dmac.c +0
-0@@ -46,13 +46,29 @@ static inline unsigned int dwc_get_sms(struct dw_dma_slave *slave)return slave ? slave->src_master :1 ;
drivers/dma/dw_dmac.c static inline unsigned int dwc_get_sms(struct dw_dma_slave *slave) · line 56
Quoted 10 lines
drivers/dma/dw_dmac.c +8
-0} +#define SRC_MASTER 0 +#define DST_MASTER 1 + +static inline unsigned int dwc_get_master (struct dma_chan *chan,int master) +{ +struct dw_dma *dw =to_dw_dma (chan->device); +struct dw_dma_slave *dws = chan->private; +unsigned int m =0 ;
no need to initialize m.
Quoted 31 lines
drivers/dma/dw_dmac.c +11
-6+ +if (master ==SRC_MASTER ) + m =dwc_get_sms (dws); +else if (master ==DST_MASTER ) + m =dwc_get_dms (dws); + + return min_t(unsigned int, dw->nr_masters - 1, m); +} +#define DWC_DEFAULT_CTLLO (_chan) ({ \ - struct dw_dma_slave *__slave = (_chan->private); \ struct dw_dma_chan *_dwc = to_dw_dma_chan(_chan); \ struct dma_slave_config *_sconfig = &_dwc->dma_sconfig; \ bool _is_slave = is_slave_direction(_dwc->direction); \ - int _dms = dwc_get_dms(__slave); \ - int _sms = dwc_get_sms(__slave); \ + int _dms = dwc_get_master(_chan, DST_MASTER); \ + int _sms = dwc_get_master(_chan, SRC_MASTER); \ u8 _smsize = _is_slave ? _sconfig->src_maxburst : \ DW_DMA_MSIZE_16; \ u8 _dmsize = _is_slave ? _sconfig->dst_maxburst : \@@ -73,20 +89,11 @@ static inline unsigned int dwc_get_sms(struct dw_dma_slave *slave)*/ #define NR_DESCS_PER_CHANNEL 64 -#define SRC_MASTER 0 -#define DST_MASTER 1 -static inline unsigned int dwc_get_data_width (struct dma_chan *chan,int master) {struct dw_dma *dw =to_dw_dma (chan->device);
drivers/dma/dw_dmac.c static inline unsigned int dwc_get_sms(struct dw_dma_slave *slave) · line 97
Quoted 10 lines
drivers/dma/dw_dmac.c +1
-7-struct dw_dma_slave *dws = chan->private; -if (master ==SRC_MASTER ) -return dw->data_width[dwc_get_sms (dws)]; -else if (master ==DST_MASTER ) -return dw->data_width[dwc_get_dms (dws)]; - -return 0 ; +return dw->data_width[dwc_get_master (chan, master)]; }
After fixing these,