0396-dmaengine-bcm2835-limit-max-length-based-on-channel-.patch 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. From 690414c3621a694fc4ace6775ae3c11e64da2895 Mon Sep 17 00:00:00 2001
  2. From: Martin Sperl <kernel@martin.sperl.org>
  3. Date: Wed, 16 Mar 2016 12:25:00 -0700
  4. Subject: [PATCH] dmaengine: bcm2835: limit max length based on channel type
  5. The bcm2835 dma system has 2 basic types of dma-channels:
  6. * "normal" channels
  7. * "light" channels
  8. Lite channels are limited in several aspects:
  9. * internal data-structure is 128 bit (not 256)
  10. * does not support BCM2835_DMA_TDMODE (2D)
  11. * DMA length register is limited to 16 bit.
  12. so 0-65535 (not 0-65536 as mentioned in the official datasheet)
  13. * BCM2835_DMA_S/D_IGNORE are not supported
  14. The detection of the type of mode is implemented by looking at
  15. the LITE bit in the DEBUG register for each channel.
  16. This allows automatic detection.
  17. Based on this the maximum block size is set to (64K - 4) or to 1G
  18. and this limit is honored during generation of control block
  19. chains. The effect is that when a LITE channel is used more
  20. control blocks are used to do the same transfer (compared
  21. to a normal channel).
  22. As there are several sources/target DREQS that are 32 bit wide
  23. we need to have the transfer to be a multiple of 4 as this would
  24. break the transfer otherwise.
  25. This is why the limit of (64K - 4) was chosen over the
  26. alternative of (64K - 4K).
  27. Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
  28. Reviewed-by: Eric Anholt <eric@anholt.net>
  29. Signed-off-by: Eric Anholt <eric@anholt.net>
  30. Signed-off-by: Vinod Koul <vinod.koul@intel.com>
  31. ---
  32. drivers/dma/bcm2835-dma.c | 29 ++++++++++++++++++++++++++---
  33. 1 file changed, 26 insertions(+), 3 deletions(-)
  34. --- a/drivers/dma/bcm2835-dma.c
  35. +++ b/drivers/dma/bcm2835-dma.c
  36. @@ -81,6 +81,8 @@ struct bcm2835_chan {
  37. void __iomem *chan_base;
  38. int irq_number;
  39. +
  40. + bool is_lite_channel;
  41. };
  42. struct bcm2835_desc {
  43. @@ -169,6 +171,16 @@ struct bcm2835_desc {
  44. #define BCM2835_DMA_CHAN(n) ((n) << 8) /* Base address */
  45. #define BCM2835_DMA_CHANIO(base, n) ((base) + BCM2835_DMA_CHAN(n))
  46. +/* the max dma length for different channels */
  47. +#define MAX_DMA_LEN SZ_1G
  48. +#define MAX_LITE_DMA_LEN (SZ_64K - 4)
  49. +
  50. +static inline size_t bcm2835_dma_max_frame_length(struct bcm2835_chan *c)
  51. +{
  52. + /* lite and normal channels have different max frame length */
  53. + return c->is_lite_channel ? MAX_LITE_DMA_LEN : MAX_DMA_LEN;
  54. +}
  55. +
  56. /* how many frames of max_len size do we need to transfer len bytes */
  57. static inline size_t bcm2835_dma_frames_for_length(size_t len,
  58. size_t max_len)
  59. @@ -217,8 +229,10 @@ static void bcm2835_dma_create_cb_set_le
  60. size_t *total_len,
  61. u32 finalextrainfo)
  62. {
  63. - /* set the length */
  64. - control_block->length = len;
  65. + size_t max_len = bcm2835_dma_max_frame_length(chan);
  66. +
  67. + /* set the length taking lite-channel limitations into account */
  68. + control_block->length = min_t(u32, len, max_len);
  69. /* finished if we have no period_length */
  70. if (!period_len)
  71. @@ -544,6 +558,7 @@ static struct dma_async_tx_descriptor *b
  72. dma_addr_t src, dst;
  73. u32 info = BCM2835_DMA_WAIT_RESP;
  74. u32 extra = BCM2835_DMA_INT_EN;
  75. + size_t max_len = bcm2835_dma_max_frame_length(c);
  76. size_t frames;
  77. /* Grab configuration */
  78. @@ -586,7 +601,10 @@ static struct dma_async_tx_descriptor *b
  79. }
  80. /* calculate number of frames */
  81. - frames = DIV_ROUND_UP(buf_len, period_len);
  82. + frames = /* number of periods */
  83. + DIV_ROUND_UP(buf_len, period_len) *
  84. + /* number of frames per period */
  85. + bcm2835_dma_frames_for_length(period_len, max_len);
  86. /*
  87. * allocate the CB chain
  88. @@ -685,6 +703,11 @@ static int bcm2835_dma_chan_init(struct
  89. c->ch = chan_id;
  90. c->irq_number = irq;
  91. + /* check in DEBUG register if this is a LITE channel */
  92. + if (readl(c->chan_base + BCM2835_DMA_DEBUG) &
  93. + BCM2835_DMA_DEBUG_LITE)
  94. + c->is_lite_channel = true;
  95. +
  96. return 0;
  97. }