pxa_dma.txt 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. PXA/MMP - DMA Slave controller
  2. ==============================
  3. Constraints
  4. -----------
  5. a) Transfers hot queuing
  6. A driver submitting a transfer and issuing it should be granted the transfer
  7. is queued even on a running DMA channel.
  8. This implies that the queuing doesn't wait for the previous transfer end,
  9. and that the descriptor chaining is not only done in the irq/tasklet code
  10. triggered by the end of the transfer.
  11. A transfer which is submitted and issued on a phy doesn't wait for a phy to
  12. stop and restart, but is submitted on a "running channel". The other
  13. drivers, especially mmp_pdma waited for the phy to stop before relaunching
  14. a new transfer.
  15. b) All transfers having asked for confirmation should be signaled
  16. Any issued transfer with DMA_PREP_INTERRUPT should trigger a callback call.
  17. This implies that even if an irq/tasklet is triggered by end of tx1, but
  18. at the time of irq/dma tx2 is already finished, tx1->complete() and
  19. tx2->complete() should be called.
  20. c) Channel running state
  21. A driver should be able to query if a channel is running or not. For the
  22. multimedia case, such as video capture, if a transfer is submitted and then
  23. a check of the DMA channel reports a "stopped channel", the transfer should
  24. not be issued until the next "start of frame interrupt", hence the need to
  25. know if a channel is in running or stopped state.
  26. d) Bandwidth guarantee
  27. The PXA architecture has 4 levels of DMAs priorities : high, normal, low.
  28. The high prorities get twice as much bandwidth as the normal, which get twice
  29. as much as the low priorities.
  30. A driver should be able to request a priority, especially the real-time
  31. ones such as pxa_camera with (big) throughputs.
  32. Design
  33. ------
  34. a) Virtual channels
  35. Same concept as in sa11x0 driver, ie. a driver was assigned a "virtual
  36. channel" linked to the requestor line, and the physical DMA channel is
  37. assigned on the fly when the transfer is issued.
  38. b) Transfer anatomy for a scatter-gather transfer
  39. +------------+-----+---------------+----------------+-----------------+
  40. | desc-sg[0] | ... | desc-sg[last] | status updater | finisher/linker |
  41. +------------+-----+---------------+----------------+-----------------+
  42. This structure is pointed by dma->sg_cpu.
  43. The descriptors are used as follows :
  44. - desc-sg[i]: i-th descriptor, transferring the i-th sg
  45. element to the video buffer scatter gather
  46. - status updater
  47. Transfers a single u32 to a well known dma coherent memory to leave
  48. a trace that this transfer is done. The "well known" is unique per
  49. physical channel, meaning that a read of this value will tell which
  50. is the last finished transfer at that point in time.
  51. - finisher: has ddadr=DADDR_STOP, dcmd=ENDIRQEN
  52. - linker: has ddadr= desc-sg[0] of next transfer, dcmd=0
  53. c) Transfers hot-chaining
  54. Suppose the running chain is :
  55. Buffer 1 Buffer 2
  56. +---------+----+---+ +----+----+----+---+
  57. | d0 | .. | dN | l | | d0 | .. | dN | f |
  58. +---------+----+-|-+ ^----+----+----+---+
  59. | |
  60. +----+
  61. After a call to dmaengine_submit(b3), the chain will look like :
  62. Buffer 1 Buffer 2 Buffer 3
  63. +---------+----+---+ +----+----+----+---+ +----+----+----+---+
  64. | d0 | .. | dN | l | | d0 | .. | dN | l | | d0 | .. | dN | f |
  65. +---------+----+-|-+ ^----+----+----+-|-+ ^----+----+----+---+
  66. | | | |
  67. +----+ +----+
  68. new_link
  69. If while new_link was created the DMA channel stopped, it is _not_
  70. restarted. Hot-chaining doesn't break the assumption that
  71. dma_async_issue_pending() is to be used to ensure the transfer is actually started.
  72. One exception to this rule :
  73. - if Buffer1 and Buffer2 had all their addresses 8 bytes aligned
  74. - and if Buffer3 has at least one address not 4 bytes aligned
  75. - then hot-chaining cannot happen, as the channel must be stopped, the
  76. "align bit" must be set, and the channel restarted As a consequence,
  77. such a transfer tx_submit() will be queued on the submitted queue, and
  78. this specific case if the DMA is already running in aligned mode.
  79. d) Transfers completion updater
  80. Each time a transfer is completed on a channel, an interrupt might be
  81. generated or not, up to the client's request. But in each case, the last
  82. descriptor of a transfer, the "status updater", will write the latest
  83. transfer being completed into the physical channel's completion mark.
  84. This will speed up residue calculation, for large transfers such as video
  85. buffers which hold around 6k descriptors or more. This also allows without
  86. any lock to find out what is the latest completed transfer in a running
  87. DMA chain.
  88. e) Transfers completion, irq and tasklet
  89. When a transfer flagged as "DMA_PREP_INTERRUPT" is finished, the dma irq
  90. is raised. Upon this interrupt, a tasklet is scheduled for the physical
  91. channel.
  92. The tasklet is responsible for :
  93. - reading the physical channel last updater mark
  94. - calling all the transfer callbacks of finished transfers, based on
  95. that mark, and each transfer flags.
  96. If a transfer is completed while this handling is done, a dma irq will
  97. be raised, and the tasklet will be scheduled once again, having a new
  98. updater mark.
  99. f) Residue
  100. Residue granularity will be descriptor based. The issued but not completed
  101. transfers will be scanned for all of their descriptors against the
  102. currently running descriptor.
  103. g) Most complicated case of driver's tx queues
  104. The most tricky situation is when :
  105. - there are not "acked" transfers (tx0)
  106. - a driver submitted an aligned tx1, not chained
  107. - a driver submitted an aligned tx2 => tx2 is cold chained to tx1
  108. - a driver issued tx1+tx2 => channel is running in aligned mode
  109. - a driver submitted an aligned tx3 => tx3 is hot-chained
  110. - a driver submitted an unaligned tx4 => tx4 is put in submitted queue,
  111. not chained
  112. - a driver issued tx4 => tx4 is put in issued queue, not chained
  113. - a driver submitted an aligned tx5 => tx5 is put in submitted queue, not
  114. chained
  115. - a driver submitted an aligned tx6 => tx6 is put in submitted queue,
  116. cold chained to tx5
  117. This translates into (after tx4 is issued) :
  118. - issued queue
  119. +-----+ +-----+ +-----+ +-----+
  120. | tx1 | | tx2 | | tx3 | | tx4 |
  121. +---|-+ ^---|-+ ^-----+ +-----+
  122. | | | |
  123. +---+ +---+
  124. - submitted queue
  125. +-----+ +-----+
  126. | tx5 | | tx6 |
  127. +---|-+ ^-----+
  128. | |
  129. +---+
  130. - completed queue : empty
  131. - allocated queue : tx0
  132. It should be noted that after tx3 is completed, the channel is stopped, and
  133. restarted in "unaligned mode" to handle tx4.
  134. Author: Robert Jarzmik <robert.jarzmik@free.fr>