udma.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /* Customer ID=11656; Build=0x5f626; Copyright (c) 2005-2014 by Cadence Design Systems, Inc. ALL RIGHTS RESERVED.
  2. * These coded instructions, statements, and computer programs are the
  3. * copyrighted works and confidential proprietary information of
  4. * Cadence Design Systems, Inc. They may not be modified, copied, reproduced,
  5. * distributed, or disclosed to third parties in any manner, medium, or form,
  6. * in whole or in part, without the prior written consent of Cadence Design
  7. * Systems Inc.
  8. */
  9. #ifndef __UDMA_H__
  10. #define __UDMA_H__
  11. #include <stdint.h>
  12. #include <stddef.h>
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. /* Size of the uDMA descriptor */
  17. #define UDMA_DESC_STRUCT_SIZE 32
  18. /* Request attribute is a bit vector passed to the udma functions - udma_copy,
  19. * udma_2d_copy, udma_add_descs.
  20. * Bit 0 : 1 - trigger an interrupt when done, else do nothing
  21. * Bit 1 : 0 - retry the failed request; abort after programmer specified
  22. * number of retries. Defaults to abort with no retries.
  23. * 1 - abort the failed request (after retries) and all pending requests
  24. */
  25. #define UDMA_DONE_INTERRUPT 0x1
  26. #define UDMA_ERROR_ABORT 0x0
  27. #define UDMA_ERROR_ABORT_ALL 0x2
  28. /* Enum representing various udma error conditions, udma status, and
  29. * return values
  30. */
  31. typedef enum {
  32. UDMA_OK = 0,
  33. UDMA_ERROR_QUEUE_FULL = 1,
  34. UDMA_ERROR_BAD_DESC = 2,
  35. UDMA_ERROR_DRAM_CROSSING = 3,
  36. UDMA_ERROR_PIF_ADDR_BUS = 4,
  37. UDMA_ERROR_PIF_DATA_BUS = 5,
  38. UDMA_REQ_PENDING = 6,
  39. UDMA_REQ_DONE = 7,
  40. UDMA_ERROR_BAD_REQUEST = 8,
  41. UDMA_ERROR_INVALID_ARG = 11,
  42. UDMA_ERROR_INIT = 12,
  43. UDMA_ERROR_INTERNAL = -1
  44. } udma_status_t;
  45. #ifndef __UDMA_INTERNAL_H__
  46. /* Opaque structure describing a uDMA descriptor */
  47. struct udma_desc_struct {
  48. char _[UDMA_DESC_STRUCT_SIZE];
  49. } __attribute__ ((aligned (UDMA_DESC_STRUCT_SIZE)));
  50. #endif
  51. typedef struct udma_desc_struct udma_desc_t;
  52. /* Initialize the udma control structure, the uDMA registers with
  53. * the descriptor queue addresses, and the uDMA sync and error interrupt
  54. * handler. This function needs to be invoked prior to using the uDMA.
  55. *
  56. * xmp_udma_sync_intr : Processor interrupt number to flag udma done
  57. * xmp_udma_error_intr : Processor interrupt number to flag udma error
  58. *
  59. * Returns UDMA_ERROR_INIT if there was an error during initialization else
  60. * returns UDMA_OK.
  61. */
  62. extern udma_status_t
  63. udma_init(uint32_t xmp_udma_sync_intr, uint32_t xmp_udma_error_intr);
  64. /* Performs a copy of a linear block of size bytes from the src
  65. * to the dest address. If the call returns UDMA_OK, status is set to
  66. * UDMA_REQ_PENDING or UDMA_REQ_DONE. If there is a dma error, the error code,
  67. * which could be one of UDMA_ERROR_BAD_DESC, UDMA_ERROR_DRAM_CROSSING,
  68. * UDMA_ERROR_PIF_ADDR_BUS, UDMA_ERROR_PIF_DATA_BUS is returned in the status.
  69. * Status is set to UDMA_REQ_DONE if the dma completes normally.
  70. * On completion, the callback function is invoked with the callback_data
  71. * and status as parameters. Note, the callback is always invoked even if
  72. * there is a dma error.
  73. *
  74. * src : src address of the copy
  75. * dest : dest address of the copy
  76. * size : number of bytes to copy
  77. * callback_data : optional data to be passed to callback_func
  78. * callback_func : optional callback after copy is done
  79. * request_attr : attribute defining how to process this request
  80. * (see description of the request attribute in top of udma.h)
  81. * status : track status of the copy; this gets also passed
  82. * as the second argument to the callback_func
  83. *
  84. * Returns UDMA_ERROR_QUEUE_FULL if no more requests can be added, else
  85. * returns UDMA_OK.
  86. */
  87. extern udma_status_t
  88. udma_copy(void *dest,
  89. void *src,
  90. size_t size,
  91. void *callback_data,
  92. void (*callback_func)(void *, udma_status_t *status),
  93. uint32_t request_attr,
  94. udma_status_t *status);
  95. /* Performs a copy of a 2D block of data from the src to the dest
  96. * address. If the call returns UDMA_OK, status is set to UDMA_REQ_PENDING or
  97. * UDMA_REQ_DONE. If there is a dma error, the error code,
  98. * which could be one of UDMA_ERROR_BAD_DESC, UDMA_ERROR_DRAM_CROSSING,
  99. * UDMA_ERROR_PIF_ADDR_BUS, UDMA_ERROR_PIF_DATA_BUS is returned in the status.
  100. * Status is set to UDMA_REQ_DONE if the dma completes normally.
  101. * On completion, the callback function is invoked with the callback_data
  102. * and status as parameters. Note, the callback is always invoked even if
  103. * there is a dma error.
  104. *
  105. * src : src address of the copy
  106. * dest : dest address of the copy
  107. * row_size : number of bytes per row to copy
  108. * num_rows : number of rows to copy
  109. * src_pitch : src pitch
  110. * dest_pitch : dest pitch
  111. * callback_data : optional data to be passed to callback_func
  112. * callback_func : optional callback after copy is done
  113. * request_attr : attribute defining how to process this request
  114. * (see description of the request attribute in top of udma.h)
  115. * status : track status of the copy; this gets also passed
  116. * as the second argument to the callback_func
  117. *
  118. * Returns UDMA_ERROR_QUEUE_FULL if no more requests can be added, else
  119. * returns UDMA_OK.
  120. */
  121. extern udma_status_t
  122. udma_2d_copy(void *dest,
  123. void *src,
  124. size_t row_size,
  125. uint32_t num_rows,
  126. uint32_t src_pitch,
  127. uint32_t dest_pitch,
  128. void *callback_data,
  129. void (*callback_func)(void *, udma_status_t *status),
  130. uint32_t request_attr,
  131. udma_status_t *status);
  132. /* Process requests that are done. Any callbacks associated
  133. * with the completed requests gets invoked. If there are any errors,
  134. * the error request is (and any pending request based on the request attribute)
  135. * cancelled and the error code is returned in the status associated with
  136. * all such cancelled requests. Callbacks associated with the cancelled
  137. * requests are also invoked. If all requests terminate normally, the status
  138. * of the completed requests are set to UDMA_REQ_DONE.
  139. *
  140. * Returns void
  141. */
  142. extern void
  143. udma_process_requests();
  144. /* Sets the udma max PIF block size
  145. *
  146. * max_block_size : max block size to be set
  147. *
  148. * Returns UDMA_ERROR_INVALID_ARG if block_size is > 3, else returns UDMA_OK
  149. */
  150. udma_status_t
  151. udma_set_max_block_size(uint32_t block_size);
  152. /* Sets the udma max outstanding PIF requests
  153. *
  154. * max_outstanding : max outstanding PIF requests
  155. *
  156. * Returns UDMA_ERROR_INVALID_ARG if max_outstanding is not between 1 and 16
  157. * else returns UDMA_OK
  158. */
  159. udma_status_t
  160. udma_set_max_outstanding(uint32_t max_outstanding);
  161. /* Initialize a uDMA descriptor using the copy parameters. The descriptor
  162. * is then queued separately using udma_add_desc
  163. *
  164. * src : src address of the copy
  165. * dest : dest address of the copy
  166. * row_size : number of bytes per row to copy
  167. * num_rows : number of rows to copy
  168. * src_pitch : src pitch
  169. * dest_pitch : dest pitch
  170. * notify_with_interrupt : If 1, interrupt when dma is done with this descriptor
  171. * if 0, do nothing, else undefined
  172. *
  173. * Returns void
  174. */
  175. extern void
  176. udma_set_desc(void *src,
  177. void *dest,
  178. size_t row_size,
  179. uint32_t num_rows,
  180. uint32_t src_pitch,
  181. uint32_t dest_pitch,
  182. uint32_t notify_with_interrupt,
  183. udma_desc_t *desc);
  184. /* Add multiple uDMA descriptors to the descriptor queue. If the call returns
  185. * UDMA_OK, the status is set to UDMA_REQ_PENDING or UDMA_REQ_DONE.
  186. * If there is a dma error, the error code, which could be one of
  187. * UDMA_ERROR_BAD_DESC, UDMA_ERROR_DRAM_CROSSING, UDMA_ERROR_PIF_ADDR_BUS,
  188. * UDMA_ERROR_PIF_DATA_BUS is returned in the status. Status is set
  189. * to UDMA_REQ_DONE, if the dma completes normally.
  190. * On completion, the callback function is invoked with the callback_data
  191. * and status as parameters. Note, the callback is always invoked even if
  192. * there is a dma error.
  193. *
  194. * desc : descriptors to be added
  195. * num_desc : number of descriptors to be added
  196. * callback_data : optional data to be passed to callback_func
  197. * callback_func : optional callback after copy is done
  198. * request_attr : attribute defining how to process this request
  199. * (see description of the request attribute in top of udma.h)
  200. * Note, bit 0 (for enabling interrupt) is ignored in this call.
  201. * To interrupt on dma completion, set the
  202. * notify_with_interrupt parameter when creating descriptors
  203. * using udma_set_desc.
  204. * status : track status of the copy; this gets also passed
  205. * as the second argument to the callback_func
  206. *
  207. * Returns UDMA_ERROR_QUEUE_FULL if no more descriptors can be added,
  208. * UDMA_ERROR_INVALID_ARG if num_descs == 0, else return UDMA_OK
  209. */
  210. udma_status_t
  211. udma_add_descs(udma_desc_t *descs,
  212. uint32_t num_descs,
  213. void *callback_data,
  214. void (*callback_func)(void *, udma_status_t *status),
  215. uint32_t request_attr,
  216. udma_status_t *status);
  217. /* Wait for udma copy request to complete. Could spin wait or goto waiti
  218. * based on the sleep_wait parameter. Once the request is done, the callback
  219. * associated with this request and any prior completed requests are handled.
  220. * Error code, if any, is returned in the status s, else s is set to
  221. * UDMA_REQ_DONE.
  222. *
  223. * s : status to wait for
  224. * sleep_wait : sleep wait if true, else spin waits
  225. *
  226. * Returns void
  227. */
  228. extern void
  229. udma_wait_request(volatile udma_status_t *s, uint32_t sleep_wait);
  230. /* Inlined function to set the src, dest address of the descriptor
  231. *
  232. * src : src address of the uDMA
  233. * dest : dest address of the uDMA
  234. * desc : descriptor to be modified
  235. *
  236. * Returns void
  237. */
  238. void static inline
  239. udma_set_desc_addrs(void *src, void *dest, udma_desc_t *desc) {
  240. uint32_t *d = (uint32_t *)desc;
  241. *d = (uintptr_t)src;
  242. *(d+1) = (uintptr_t)dest;
  243. }
  244. /* Sets the number of retries for a failed dma request
  245. *
  246. * max_retries : max number of retries
  247. *
  248. * Sets the max number of retries for a failed dma request. The default is 0,
  249. * i.e, no retries
  250. */
  251. void
  252. udma_set_max_retries(uint32_t max_retries);
  253. #ifdef __cplusplus
  254. }
  255. #endif
  256. #endif /* __UDMA_H__ */