DMA: shdma: 40-bit address prototype
PATCH 2/7 DMA: shdma: 40-bit address prototype
From: Magnus Damm <[email protected]>
Hack up 40-bit address support via the FIXSAR and FIXDAR addresses provided by the SYS-DMAC hardware in R-Car Gen2.
The data sheet says that auto increment overflow from SAR to FIXSAR and DAR to FIXDAR does not happen, so based on that limit size of DMA transactions that try to cross the 32-bit boundary.
Not for upstream merge.
---
drivers/dma/sh/shdma.h | 4 +-- drivers/dma/sh/shdmac.c | 48 +++++++++++++++++++++++++++++++++++++++++------ include/linux/sh_dma.h | 2 + 3 files changed, 46 insertions(+), 8 deletions(-)
drivers/dma/sh/shdma.h +2 -2
@@ -46,8 +46,8 @@ struct sh_dmae_device { };struct sh_dmae_regs { -u32 sar;/* SAR / source address */ -u32 dar;/* DAR / destination address */ +dma_addr_t sar;/* SAR / source address */ +dma_addr_t dar;/* DAR / destination address */ u32 tcr;/* TCR / transfer count */ };
drivers/dma/sh/shdmac.c +42 -6
85 lines not on this page · raw message
include/linux/sh_dma.h +2 -0
@@ -70,6 +70,7 @@ struct sh_dmae_channel {* @chclr_present: DMAC has one or several CHCLR registers * @chclr_bitwise: channel CHCLR registers are bitwise * @slave_only: DMAC cannot be used for MEMCPY +* @fourty_bits_addr: Hardware support dealing with 40 bit addresses */ struct sh_dmae_pdata {const struct sh_dmae_slave_config *slave;
@@ -92,6 +93,7 @@ struct sh_dmae_pdata { unsigned int chclr_present:1; unsigned int chclr_bitwise:1; unsigned int slave_only:1; + unsigned int fourty_bits_addr:1; };/* DMAOR definitions */
Hi Magnus,
drivers/dma/sh/shdmac.c 2014-06-10 23:08:46.000000000 +0900 static int sh_dmae_desc_setup(struct shd · line 394
Quoted 7 lines · Magnus Damm
drivers/dma/sh/shdmac.c 2014-06-10 23:08:46.000000000 +0900 renamed from drivers/dma/sh/shdmac.c +2
-0@@ -382,12 +392,30 @@ static int sh_dmae_desc_setup(struct shd +#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT + /* unsure if crossing 32-bit boundary really works, disable for now */
As you mentioned at the top, the datasheet says it doesn't.
drivers/dma/sh/shdmac.c 2014-06-10 23:08:46.000000000 +0900 static int sh_dmae_desc_setup(struct shd · line 400
Quoted 6 lines
drivers/dma/sh/shdmac.c 2014-06-10 23:08:46.000000000 +0900 renamed from drivers/dma/sh/shdmac.c +6
-0+ if (shdev->pdata->fourty_bits_addr) { + dma_addr_t limit = 0xffffffff; + dma_addr_t src_masked = src & limit; + dma_addr_t dst_masked = dst & limit; + + if ((src_masked < limit) && ((src_masked + *len) > limit))
"src_masked < limit" fails to catch the case "src_masked = 0xffffffff". "(src_masked + *len) > limit)" incorrectly catches the case "(src_masked + *len) = 0x*00000000".
I think you want to check for
if ((src >> 32) != ((src + *len - 1) >> 32))
?
drivers/dma/sh/shdmac.c 2014-06-10 23:08:46.000000000 +0900 static int sh_dmae_desc_setup(struct shd · line 404
Quoted 4 lines
drivers/dma/sh/shdmac.c 2014-06-10 23:08:46.000000000 +0900 renamed from drivers/dma/sh/shdmac.c +4
-0+ *len = limit - src_masked; + + if ((dst_masked < limit) && ((dst_masked + *len) > limit)) + *len = limit - dst_masked;
Idem ditto.
drivers/dma/sh/shdmac.c 2014-06-10 23:08:46.000000000 +0900 static int sh_dmae_desc_setup(struct shd · line 406
Quoted 2 lines
drivers/dma/sh/shdmac.c 2014-06-10 23:08:46.000000000 +0900 renamed from drivers/dma/sh/shdmac.c +2
-0+ } +#endif
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Hi Geert,
Quoted 28 lines · Geert Uytterhoeven
Hi Magnus,
drivers/dma/sh/shdmac.c 2014-06-10 23:08:46.000000000 +0900 static int sh_dmae_desc_setup(struct shd · line 394
Quoted 7 lines · Magnus Damm
drivers/dma/sh/shdmac.c 2014-06-10 23:08:46.000000000 +0900 renamed from drivers/dma/sh/shdmac.c +2
-0@@ -382,12 +392,30 @@ static int sh_dmae_desc_setup(struct shd +#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT + /* unsure if crossing 32-bit boundary really works, disable for now */As you mentioned at the top, the datasheet says it doesn't.
drivers/dma/sh/shdmac.c 2014-06-10 23:08:46.000000000 +0900 static int sh_dmae_desc_setup(struct shd · line 400
Quoted 6 lines
drivers/dma/sh/shdmac.c 2014-06-10 23:08:46.000000000 +0900 renamed from drivers/dma/sh/shdmac.c +6
-0+ if (shdev->pdata->fourty_bits_addr) { + dma_addr_t limit = 0xffffffff; + dma_addr_t src_masked = src & limit; + dma_addr_t dst_masked = dst & limit; + + if ((src_masked < limit) && ((src_masked + *len) > limit))"
src_masked< limit" fails to catch the case "src_masked=0xffffffff". "(src_masked+ *len) > limit)" incorrectly catches the case "(src_masked+ *len) = 0x*00000000".I think you want to check for
if ((src >> 32) != ((src + *len - 1) >> 32))
Quoted 8 lines
?
drivers/dma/sh/shdmac.c 2014-06-10 23:08:46.000000000 +0900 static int sh_dmae_desc_setup(struct shd · line 404
Quoted 4 lines
drivers/dma/sh/shdmac.c 2014-06-10 23:08:46.000000000 +0900 renamed from drivers/dma/sh/shdmac.c +4
-0+ *len = limit - src_masked; + + if ((dst_masked < limit) && ((dst_masked + *len) > limit)) + *len = limit - dst_masked;Idem ditto.
Thanks for checking my code. Indeed, the code is incorrect.
How about the following replacement?
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
/* disable transfer across 32-bit boundary */
if (shdev->pdata->fourty_bits_addr) {
dma_addr_t four_gigs = 1ULL << 32;
if ((src >> 32) != ((src + *len - 1) >> 32))
*len = four_gigs - (src & (four_gigs - 1));if ((dst >> 32) != ((dst + *len - 1) >> 32))
*len = four_gigs - (dst & (four_gigs - 1)); }
#endif
Thanks,
/ magnus
Hi Magnus,
Quoted 28 lines · Magnus Damm
Quoted 10 lines
Quoted 1 line
+ if ((
src_masked< limit) && ((src_masked+ *len) > limit))"
src_masked< limit" fails to catch the case "src_masked=0xffffffff". "(src_masked+ *len) > limit)" incorrectly catches the case "(src_masked+ *len) = 0x*00000000".I think you want to check for
if ((src >> 32) != ((src + *len - 1) >> 32))Quoted 8 lines
?
drivers/dma/sh/shdmac.c static int sh_dmae_desc_setup(struct shd · line 415
Quoted 4 lines
drivers/dma/sh/shdmac.c +4
-0+ *len = limit - src_masked; + +if ((dst_masked < limit) && ((dst_masked + *len) > limit)) + *len = limit - dst_masked;Idem ditto.
Thanks for checking my code. Indeed, the code is incorrect.
How about the following replacement?
#ifdef
CONFIG_ARCH_DMA_ADDR_T_64BIT
/* disable transfer across 32-bit boundary */
if (shdev->pdata->fourty_bits_addr) {
dma_addr_tfour_gigs= 1ULL << 32;
Quoted 7 lines
if ((src >> 32) != ((src + *len - 1) >> 32)) *len = four_gigs - (src & (four_gigs - 1));if ((dst >> 32) != ((dst + *len - 1) >> 32))
*len = four_gigs - (dst & (four_gigs - 1)); }#endif
Thanks, that looks correct to me.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds