dmaengine.txt 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. DMA Engine API Guide
  2. ====================
  3. Vinod Koul <vinod dot koul at intel.com>
  4. NOTE: For DMA Engine usage in async_tx please see:
  5. Documentation/crypto/async-tx-api.txt
  6. Below is a guide to device driver writers on how to use the Slave-DMA API of the
  7. DMA Engine. This is applicable only for slave DMA usage only.
  8. The slave DMA usage consists of following steps
  9. 1. Allocate a DMA slave channel
  10. 2. Set slave and controller specific parameters
  11. 3. Get a descriptor for transaction
  12. 4. Submit the transaction and wait for callback notification
  13. 1. Allocate a DMA slave channel
  14. Channel allocation is slightly different in the slave DMA context, client
  15. drivers typically need a channel from a particular DMA controller only and even
  16. in some cases a specific channel is desired. To request a channel
  17. dma_request_channel() API is used.
  18. Interface:
  19. struct dma_chan *dma_request_channel(dma_cap_mask_t mask,
  20. dma_filter_fn filter_fn,
  21. void *filter_param);
  22. where dma_filter_fn is defined as:
  23. typedef bool (*dma_filter_fn)(struct dma_chan *chan, void *filter_param);
  24. When the optional 'filter_fn' parameter is set to NULL dma_request_channel
  25. simply returns the first channel that satisfies the capability mask. Otherwise,
  26. when the mask parameter is insufficient for specifying the necessary channel,
  27. the filter_fn routine can be used to disposition the available channels in the
  28. system. The filter_fn routine is called once for each free channel in the
  29. system. Upon seeing a suitable channel filter_fn returns DMA_ACK which flags
  30. that channel to be the return value from dma_request_channel. A channel
  31. allocated via this interface is exclusive to the caller, until
  32. dma_release_channel() is called.
  33. 2. Set slave and controller specific parameters
  34. Next step is always to pass some specific information to the DMA driver. Most of
  35. the generic information which a slave DMA can use is in struct dma_slave_config.
  36. It allows the clients to specify DMA direction, DMA addresses, bus widths, DMA
  37. burst lengths etc. If some DMA controllers have more parameters to be sent then
  38. they should try to embed struct dma_slave_config in their controller specific
  39. structure. That gives flexibility to client to pass more parameters, if
  40. required.
  41. Interface:
  42. int dmaengine_slave_config(struct dma_chan *chan,
  43. struct dma_slave_config *config)
  44. 3. Get a descriptor for transaction
  45. For slave usage the various modes of slave transfers supported by the
  46. DMA-engine are:
  47. slave_sg - DMA a list of scatter gather buffers from/to a peripheral
  48. dma_cyclic - Perform a cyclic DMA operation from/to a peripheral till the
  49. operation is explicitly stopped.
  50. The non NULL return of this transfer API represents a "descriptor" for the given
  51. transaction.
  52. Interface:
  53. struct dma_async_tx_descriptor *(*chan->device->device_prep_dma_sg)(
  54. struct dma_chan *chan,
  55. struct scatterlist *dst_sg, unsigned int dst_nents,
  56. struct scatterlist *src_sg, unsigned int src_nents,
  57. unsigned long flags);
  58. struct dma_async_tx_descriptor *(*chan->device->device_prep_dma_cyclic)(
  59. struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
  60. size_t period_len, enum dma_data_direction direction);
  61. 4. Submit the transaction and wait for callback notification
  62. To schedule the transaction to be scheduled by dma device, the "descriptor"
  63. returned in above (3) needs to be submitted.
  64. To tell the dma driver that a transaction is ready to be serviced, the
  65. descriptor->submit() callback needs to be invoked. This chains the descriptor to
  66. the pending queue.
  67. The transactions in the pending queue can be activated by calling the
  68. issue_pending API. If channel is idle then the first transaction in queue is
  69. started and subsequent ones queued up.
  70. On completion of the DMA operation the next in queue is submitted and a tasklet
  71. triggered. The tasklet would then call the client driver completion callback
  72. routine for notification, if set.
  73. Interface:
  74. void dma_async_issue_pending(struct dma_chan *chan);
  75. ==============================================================================
  76. Additional usage notes for dma driver writers
  77. 1/ Although DMA engine specifies that completion callback routines cannot submit
  78. any new operations, but typically for slave DMA subsequent transaction may not
  79. be available for submit prior to callback routine being called. This requirement
  80. is not a requirement for DMA-slave devices. But they should take care to drop
  81. the spin-lock they might be holding before calling the callback routine