0088-bcm2835-dma-Fix-up-convert-to-DMA-pool.patch 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. From 5bb7ea036f5dfa3e3e3e1c674cb3f06e8204743e Mon Sep 17 00:00:00 2001
  2. From: Matthias Reichl <hias@horus.com>
  3. Date: Mon, 16 Nov 2015 14:05:35 +0000
  4. Subject: [PATCH 088/381] bcm2835-dma: Fix up convert to DMA pool
  5. ---
  6. drivers/dma/bcm2835-dma.c | 36 ++++++++++++++++++++++++++----------
  7. 1 file changed, 26 insertions(+), 10 deletions(-)
  8. --- a/drivers/dma/bcm2835-dma.c
  9. +++ b/drivers/dma/bcm2835-dma.c
  10. @@ -488,6 +488,17 @@ static struct dma_async_tx_descriptor *b
  11. c->cyclic = true;
  12. return vchan_tx_prep(&c->vc, &d->vd, flags);
  13. +error_cb:
  14. + i--;
  15. + for (; i >= 0; i--) {
  16. + struct bcm2835_cb_entry *cb_entry = &d->cb_list[i];
  17. +
  18. + dma_pool_free(c->cb_pool, cb_entry->cb, cb_entry->paddr);
  19. + }
  20. +
  21. + kfree(d->cb_list);
  22. + kfree(d);
  23. + return NULL;
  24. }
  25. static struct dma_async_tx_descriptor *
  26. @@ -534,6 +545,7 @@ bcm2835_dma_prep_slave_sg(struct dma_cha
  27. if (!d)
  28. return NULL;
  29. + d->c = c;
  30. d->dir = direction;
  31. if (c->ch >= 8) /* LITE channel */
  32. @@ -553,15 +565,21 @@ bcm2835_dma_prep_slave_sg(struct dma_cha
  33. d->frames += len / max_size + 1;
  34. }
  35. - /* Allocate memory for control blocks */
  36. - d->control_block_size = d->frames * sizeof(struct bcm2835_dma_cb);
  37. - d->control_block_base = dma_zalloc_coherent(chan->device->dev,
  38. - d->control_block_size, &d->control_block_base_phys,
  39. - GFP_NOWAIT);
  40. - if (!d->control_block_base) {
  41. + d->cb_list = kcalloc(d->frames, sizeof(*d->cb_list), GFP_KERNEL);
  42. + if (!d->cb_list) {
  43. kfree(d);
  44. return NULL;
  45. }
  46. + /* Allocate memory for control blocks */
  47. + for (i = 0; i < d->frames; i++) {
  48. + struct bcm2835_cb_entry *cb_entry = &d->cb_list[i];
  49. +
  50. + cb_entry->cb = dma_pool_zalloc(c->cb_pool, GFP_ATOMIC,
  51. + &cb_entry->paddr);
  52. +
  53. + if (!cb_entry->cb)
  54. + goto error_cb;
  55. + }
  56. /*
  57. * Iterate over all SG entries, create a control block
  58. @@ -578,7 +596,7 @@ bcm2835_dma_prep_slave_sg(struct dma_cha
  59. for (j = 0; j < len; j += max_size) {
  60. struct bcm2835_dma_cb *control_block =
  61. - &d->control_block_base[i + split_cnt];
  62. + d->cb_list[i + split_cnt].cb;
  63. /* Setup addresses */
  64. if (d->dir == DMA_DEV_TO_MEM) {
  65. @@ -620,9 +638,7 @@ bcm2835_dma_prep_slave_sg(struct dma_cha
  66. if (i < sg_len - 1 || len - j > max_size) {
  67. /* Next block is the next frame. */
  68. control_block->next =
  69. - d->control_block_base_phys +
  70. - sizeof(struct bcm2835_dma_cb) *
  71. - (i + split_cnt + 1);
  72. + d->cb_list[i + split_cnt + 1].paddr;
  73. } else {
  74. /* Next block is empty. */
  75. control_block->next = 0;