dmad.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /*****************************************************************************
  2. *
  3. * Copyright Andes Technology Corporation 2007-2008
  4. * All Rights Reserved.
  5. *
  6. * Revision History:
  7. *
  8. * Aug.21.2007 Created.
  9. ****************************************************************************/
  10. /*****************************************************************************
  11. *
  12. * FILE NAME VERSION
  13. *
  14. * dmad.h
  15. *
  16. * DESCRIPTION
  17. *
  18. * DMA controller driver internal supplement library.
  19. *
  20. * DATA STRUCTURES
  21. *
  22. * None
  23. *
  24. * DEPENDENCIES
  25. *
  26. * ag101regs.h
  27. * ag101defs.h
  28. *
  29. ****************************************************************************/
  30. #ifndef __DMAD_H__
  31. #define __DMAD_H__
  32. #include <hal.h>
  33. /*****************************************************************************
  34. * Configuration section
  35. ****************************************************************************/
  36. /* Code size control */
  37. #define DMAD_SMALL_FOOTPRINT 0 /* non-zero to disable extra features for small footprint */
  38. /* Debug trace enable switch */
  39. #define DMAD_DEBUG_TRACE 0 /* non-zero to enable debug trace message */
  40. /* DMAD globals section */
  41. enum DMAD_DMAC_CORE { DMAD_DMAC_AHB_CORE, DMAD_DMAC_APB_CORE };
  42. /*
  43. * AHB Channel Request
  44. *
  45. * Notes for developers:
  46. * These should be channel-only properties. Controller-specific properties
  47. * should be separated as other driver structure or driver buildin-hardcode.
  48. * If controller properties are embeded in this union, request for a channel
  49. * may unexpectedly override the controller setting of the request of other
  50. * channels.
  51. */
  52. typedef struct DMAD_AHBCH_REQUEST_STRUCT{
  53. /* controller property (removed! should not exist in this struct) */
  54. // uint8_t big_endian; /* (in) currently only M0 is designed, and transfer endian is default to little */
  55. /* channel property */
  56. uint32_t sync; /* (in) non-zero if src and dst have different clock domain */
  57. uint32_t priority; /* (in) DMAC_CSR_CHPRI_0 (lowest) ~ DMAC_CSR_CHPRI_3 (highest) */
  58. uint32_t hw_handshake; /* (in) non-zero to enable hardware handshake mode */
  59. /* (required when need multiple bursts or in chain mode?) */
  60. uint32_t burst_size; /* (in) DMAC_CSR_SIZE_1 ~ DMAC_CSR_SIZE_256 */
  61. /* source property */
  62. uint32_t src_width; /* (in) DMAC_CSR_WIDTH_8, DMAC_CSR_WIDTH_16, or DMAC_CSR_WIDTH_32 */
  63. uint32_t src_addr_ctrl; /* (in) DMAC_CSR_AD_INC, DMAC_CSR_AD_DEC, or DMAC_CSR_AD_FIX */
  64. uint32_t src_reqn; /* (in) DMAC_REQN_xxx (also used to help determine channel number) */
  65. uint32_t src_index;
  66. /* destination property */
  67. uint32_t dst_width; /* (in) DMAC_CSR_WIDTH_8, DMAC_CSR_WIDTH_16, or DMAC_CSR_WIDTH_32 */
  68. uint32_t dst_addr_ctrl; /* (in) DMAC_CSR_AD_INC, DMAC_CSR_AD_DEC, or DMAC_CSR_AD_FIX */
  69. uint32_t dst_reqn; /* (in) DMAC_REQN_xxx (also used to help determine channel number) */
  70. uint32_t dst_index;
  71. } DMAD_AHBCH_REQUEST;
  72. /*
  73. * APB Channel Request
  74. *
  75. * Notes for developers:
  76. * These should be channel-only properties. Controller-specific properties
  77. * should be separated as other driver structure or driver buildin-hardcode.
  78. * If controller properties are embeded in this union, request for a channel
  79. * may unexpectedly override the controller setting of the request of other
  80. * channels.
  81. */
  82. typedef struct DMAD_APBCH_REQUEST_STRUCT{
  83. /* controller property (removed! should not exist in this struct) */
  84. /* channel property */
  85. uint32_t burst_mode; /* (in) Burst mode (0: no burst 1-, 1: burst 4- data cycles per dma cycle) */
  86. uint32_t data_width; /* (in) APBBR_DATAWIDTH_4(word), APBBR_DATAWIDTH_2(half-word), APBBR_DATAWIDTH_1(byte) */
  87. /* source property */
  88. uint32_t src_addr_ctrl; /* (in) APBBR_ADDRINC_xxx */
  89. uint32_t src_reqn; /* (in) APBBR_REQN_xxx (also used to help determine bus selection) */
  90. uint32_t src_index;
  91. /* destination property */
  92. uint32_t dst_addr_ctrl; /* (in) APBBR_ADDRINC_xxx */
  93. uint32_t dst_reqn; /* (in) APBBR_REQN_xxx (also used to help determine bus selection) */
  94. uint32_t dst_index;
  95. } DMAD_APBCH_REQUEST;
  96. /* Channel Request Descriptor */
  97. typedef struct DMAD_CHANNEL_REQUEST_DESC_STRUCT{
  98. uint32_t controller; /* (in) Use DMA controller in AHB or APB - one of the enum value of DMAD_DMAC_CORE */
  99. uint32_t channel; /* (out) Allocated/granted channel */
  100. void *drq; /* (out) Handle to DMA request queue (ptr to DMAD_DRQ, internal use) */
  101. /*
  102. * Properties for channel-alloc request
  103. * Notes for developers:
  104. * These should be channel-only properties. Controller-specific properties
  105. * should be separated as other driver structure or driver buildin-hardcode.
  106. * If controller properties are embeded in this union, request for a channel
  107. * may unexpectedly override the controller setting of the request of other
  108. * channels.
  109. */
  110. union {
  111. DMAD_AHBCH_REQUEST ahbch_req; /* (in) parameters for AHB DMAC channel request */
  112. DMAD_APBCH_REQUEST apbch_req; /* (in) parameters for APB Bridge embeded DMA conteoller channel request */
  113. };
  114. } DMAD_CHANNEL_REQUEST_DESC;
  115. enum DMAD_DRB_STATE{
  116. DMAD_DRB_STATE_FREE = 0,
  117. DMAD_DRB_STATE_READY,
  118. DMAD_DRB_STATE_SUBMITTED,
  119. DMAD_DRB_STATE_TRANSFERRING,
  120. DMAD_DRB_STATE_COMPLETED,
  121. DMAD_DRB_STATE_ERROR,
  122. DMAD_DRB_STATE_ABORT,
  123. };
  124. /* DMA request block */
  125. typedef struct DMAD_DRB_STRUCT{
  126. uint32_t prev; /* (internal) Linked list previous node */
  127. uint32_t next; /* (internal) Linked list next node */
  128. uint32_t node; /* (internal) Linked list this node */
  129. uint32_t state; /* (out) DRB's current state in the whole submission cycle. */
  130. void *src_addr; /* (in) Source address in this request */
  131. void *dst_addr; /* (in) Destination address in this submission request */
  132. uint32_t req_size; /* (in) AHB DMA (12 bits): 0 ~ 4095, unit is number of "data width" */
  133. /* APB DMA (24 bits): 0 ~ 16M-1, unit is number of "data width * burst size" */
  134. uint32_t transfer_size; /* req_size * data_width*/
  135. hal_semaphore_t *completion_sem;/* (in) Application supplied semaphore to signal completion of this */
  136. /* DMA request block. Specify null to by-pass this mechanism. */
  137. void (*psp)(void*); /* pre-submission programming */
  138. void (*rcp)(void*); /* completion-of-submission programming */
  139. void *data;
  140. uint32_t src_index; /* to indicate it's device or memory */
  141. uint32_t dst_index; /* to indicate it's device or memory */
  142. // uint32_t src_reqn; /* to indicate it's device or memory */
  143. // uint32_t dst_reqn; /* to indicate it's device or memory */
  144. } DMAD_DRB;
  145. enum DMAD_CHDIR
  146. {
  147. DMAD_DIR_A0_TO_A1 = 0,
  148. DMAD_DIR_A1_TO_A0 = 1,
  149. };
  150. /* Debug Trace Mechanism */
  151. #if (DMAD_DEBUG_TRACE)
  152. #define DMAD_TRACE(x) printf x
  153. #define DMAD_STRACE(x) printf x
  154. #else /* DMAD_DEBUG_TRACE */
  155. #define DMAD_TRACE(x)
  156. #define DMAD_STRACE(x)
  157. #endif /* DMAD_DEBUG_TRACE */
  158. /*****************************************************************************
  159. * DMAD Driver Interface
  160. *
  161. * [Structures]
  162. *
  163. * [Functions]
  164. *
  165. *
  166. ****************************************************************************/
  167. extern uint32_t _dmad_channel_alloc(DMAD_CHANNEL_REQUEST_DESC *ch_req, uint8_t init);
  168. extern uint32_t _dmad_channel_free(const DMAD_CHANNEL_REQUEST_DESC *ch_req);
  169. extern uint32_t _dmad_channel_init(const DMAD_CHANNEL_REQUEST_DESC *ch_req);
  170. extern uint32_t _dmad_channel_enable(const DMAD_CHANNEL_REQUEST_DESC *ch_req, uint8_t enable);
  171. extern uint32_t _dmad_alloc_drb(DMAD_CHANNEL_REQUEST_DESC *ch_req, DMAD_DRB **drb);
  172. extern uint32_t _dmad_free_drb(DMAD_CHANNEL_REQUEST_DESC *ch_req, DMAD_DRB *drb);
  173. extern uint32_t _dmad_submit_request(DMAD_CHANNEL_REQUEST_DESC *ch_req, DMAD_DRB *drb);
  174. extern uint32_t _dmad_cancel_request(DMAD_CHANNEL_REQUEST_DESC *ch_req, DMAD_DRB *drb);
  175. extern uint32_t _dmad_wait(DMAD_CHANNEL_REQUEST_DESC *ch_req);
  176. extern uint32_t _dmad_get_reqn(uint32_t dma_controller, uint32_t device);
  177. enum ahp_reqn_index_t {
  178. AHB_NONE,
  179. AHB_CFC,
  180. AHB_SSP,
  181. AHB_UART1TX,
  182. AHB_UART1RX,
  183. AHB_I2SAC97,
  184. AHB_USB,
  185. AHB_EXT0,
  186. AHB_EXT1,
  187. AHB_SSP1TX,
  188. AHB_SSP1RX,
  189. AHB_UART2TX,
  190. AHB_UART2RX,
  191. AHB_UART4TX,
  192. AHB_UART4RX,
  193. AHB_SDC,
  194. AHB_SSP2TX,
  195. AHB_SSP2RX,
  196. AHB_USB_2_0,
  197. AHB_USB_1_1_EP1,
  198. AHB_USB_1_1_EP2,
  199. AHB_USB_1_1_EP3,
  200. AHB_USB_1_1_EP4
  201. };
  202. enum apb_reqn_index_t {
  203. APB_NONE,
  204. APB_CFC,
  205. APB_SSP,
  206. APB_BTUART,
  207. APB_I2SAC97,
  208. APB_STUART,
  209. APB_I2S,
  210. APB_SSP2,
  211. APB_EXT0,
  212. APB_EXT1,
  213. APB_SSP1TX,
  214. APB_SSP1RX,
  215. APB_UART2TX,
  216. APB_UART2RX,
  217. APB_UART4TX,
  218. APB_UART4RX,
  219. APB_SDC,
  220. APB_SSP2TX,
  221. APB_SSP2RX,
  222. APB_USB_2_0,
  223. APB_USB_1_1_EP1,
  224. APB_USB_1_1_EP2,
  225. APB_USB_1_1_EP3,
  226. APB_USB_1_1_EP4,
  227. APB_MAX
  228. };
  229. #endif /* __DMAD_H__ */