musb_dma.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * MUSB OTG driver DMA controller abstraction
  3. *
  4. * Copyright 2005 Mentor Graphics Corporation
  5. * Copyright (C) 2005-2006 by Texas Instruments
  6. * Copyright (C) 2006-2007 Nokia Corporation
  7. *
  8. * SPDX-License-Identifier: GPL-2.0
  9. */
  10. #ifndef __MUSB_DMA_H__
  11. #define __MUSB_DMA_H__
  12. struct musb_hw_ep;
  13. /*
  14. * DMA Controller Abstraction
  15. *
  16. * DMA Controllers are abstracted to allow use of a variety of different
  17. * implementations of DMA, as allowed by the Inventra USB cores. On the
  18. * host side, usbcore sets up the DMA mappings and flushes caches; on the
  19. * peripheral side, the gadget controller driver does. Responsibilities
  20. * of a DMA controller driver include:
  21. *
  22. * - Handling the details of moving multiple USB packets
  23. * in cooperation with the Inventra USB core, including especially
  24. * the correct RX side treatment of short packets and buffer-full
  25. * states (both of which terminate transfers).
  26. *
  27. * - Knowing the correlation between dma channels and the
  28. * Inventra core's local endpoint resources and data direction.
  29. *
  30. * - Maintaining a list of allocated/available channels.
  31. *
  32. * - Updating channel status on interrupts,
  33. * whether shared with the Inventra core or separate.
  34. */
  35. #define DMA_ADDR_INVALID (~(dma_addr_t)0)
  36. #ifndef CONFIG_USB_MUSB_PIO_ONLY
  37. #define is_dma_capable() (1)
  38. #else
  39. #define is_dma_capable() (0)
  40. #endif
  41. #ifdef CONFIG_USB_TI_CPPI_DMA
  42. #define is_cppi_enabled() 1
  43. #else
  44. #define is_cppi_enabled() 0
  45. #endif
  46. #ifdef CONFIG_USB_TUSB_OMAP_DMA
  47. #define tusb_dma_omap() 1
  48. #else
  49. #define tusb_dma_omap() 0
  50. #endif
  51. /* Anomaly 05000456 - USB Receive Interrupt Is Not Generated in DMA Mode 1
  52. * Only allow DMA mode 1 to be used when the USB will actually generate the
  53. * interrupts we expect.
  54. */
  55. #ifdef CONFIG_BLACKFIN
  56. # undef USE_MODE1
  57. # if !ANOMALY_05000456
  58. # define USE_MODE1
  59. # endif
  60. #endif
  61. /*
  62. * DMA channel status ... updated by the dma controller driver whenever that
  63. * status changes, and protected by the overall controller spinlock.
  64. */
  65. enum dma_channel_status {
  66. /* unallocated */
  67. MUSB_DMA_STATUS_UNKNOWN,
  68. /* allocated ... but not busy, no errors */
  69. MUSB_DMA_STATUS_FREE,
  70. /* busy ... transactions are active */
  71. MUSB_DMA_STATUS_BUSY,
  72. /* transaction(s) aborted due to ... dma or memory bus error */
  73. MUSB_DMA_STATUS_BUS_ABORT,
  74. /* transaction(s) aborted due to ... core error or USB fault */
  75. MUSB_DMA_STATUS_CORE_ABORT
  76. };
  77. struct dma_controller;
  78. /**
  79. * struct dma_channel - A DMA channel.
  80. * @private_data: channel-private data
  81. * @max_len: the maximum number of bytes the channel can move in one
  82. * transaction (typically representing many USB maximum-sized packets)
  83. * @actual_len: how many bytes have been transferred
  84. * @status: current channel status (updated e.g. on interrupt)
  85. * @desired_mode: true if mode 1 is desired; false if mode 0 is desired
  86. *
  87. * channels are associated with an endpoint for the duration of at least
  88. * one usb transfer.
  89. */
  90. struct dma_channel {
  91. void *private_data;
  92. /* FIXME not void* private_data, but a dma_controller * */
  93. size_t max_len;
  94. size_t actual_len;
  95. enum dma_channel_status status;
  96. bool desired_mode;
  97. };
  98. /*
  99. * dma_channel_status - return status of dma channel
  100. * @c: the channel
  101. *
  102. * Returns the software's view of the channel status. If that status is BUSY
  103. * then it's possible that the hardware has completed (or aborted) a transfer,
  104. * so the driver needs to update that status.
  105. */
  106. static inline enum dma_channel_status
  107. dma_channel_status(struct dma_channel *c)
  108. {
  109. return (is_dma_capable() && c) ? c->status : MUSB_DMA_STATUS_UNKNOWN;
  110. }
  111. /**
  112. * struct dma_controller - A DMA Controller.
  113. * @start: call this to start a DMA controller;
  114. * return 0 on success, else negative errno
  115. * @stop: call this to stop a DMA controller
  116. * return 0 on success, else negative errno
  117. * @channel_alloc: call this to allocate a DMA channel
  118. * @channel_release: call this to release a DMA channel
  119. * @channel_abort: call this to abort a pending DMA transaction,
  120. * returning it to FREE (but allocated) state
  121. *
  122. * Controllers manage dma channels.
  123. */
  124. struct dma_controller {
  125. int (*start)(struct dma_controller *);
  126. int (*stop)(struct dma_controller *);
  127. struct dma_channel *(*channel_alloc)(struct dma_controller *,
  128. struct musb_hw_ep *, u8 is_tx);
  129. void (*channel_release)(struct dma_channel *);
  130. int (*channel_program)(struct dma_channel *channel,
  131. u16 maxpacket, u8 mode,
  132. dma_addr_t dma_addr,
  133. u32 length);
  134. int (*channel_abort)(struct dma_channel *);
  135. int (*is_compatible)(struct dma_channel *channel,
  136. u16 maxpacket,
  137. void *buf, u32 length);
  138. };
  139. /* called after channel_program(), may indicate a fault */
  140. extern void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit);
  141. extern struct dma_controller *__init
  142. dma_controller_create(struct musb *, void __iomem *);
  143. extern void dma_controller_destroy(struct dma_controller *);
  144. #endif /* __MUSB_DMA_H__ */