pxa_dma.rst 6.6 KB

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