MCD_dma.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. /*
  2. * Copyright (C) 2004-2007 Freescale Semiconductor, Inc.
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #ifndef _MCD_API_H
  23. #define _MCD_API_H
  24. /* Turn Execution Unit tasks ON (#define) or OFF (#undef) */
  25. #undef MCD_INCLUDE_EU
  26. /* Number of DMA channels */
  27. #define NCHANNELS 16
  28. /* Total number of variants */
  29. #ifdef MCD_INCLUDE_EU
  30. #define NUMOFVARIANTS 6
  31. #else
  32. #define NUMOFVARIANTS 4
  33. #endif
  34. /* Define sizes of the various tables */
  35. #define TASK_TABLE_SIZE (NCHANNELS*32)
  36. #define VAR_TAB_SIZE (128)
  37. #define CONTEXT_SAVE_SIZE (128)
  38. #define FUNCDESC_TAB_SIZE (256)
  39. #ifdef MCD_INCLUDE_EU
  40. #define FUNCDESC_TAB_NUM 16
  41. #else
  42. #define FUNCDESC_TAB_NUM 1
  43. #endif
  44. #ifndef DEFINESONLY
  45. /* Portability typedefs */
  46. #if 1
  47. #include "common.h"
  48. #else
  49. #ifndef s32
  50. typedef int s32;
  51. #endif
  52. #ifndef u32
  53. typedef unsigned int u32;
  54. #endif
  55. #ifndef s16
  56. typedef short s16;
  57. #endif
  58. #ifndef u16
  59. typedef unsigned short u16;
  60. #endif
  61. #ifndef s8
  62. typedef char s8;
  63. #endif
  64. #ifndef u8
  65. typedef unsigned char u8;
  66. #endif
  67. #endif
  68. /*
  69. * These structures represent the internal registers of the
  70. * multi-channel DMA
  71. */
  72. struct dmaRegs_s {
  73. u32 taskbar; /* task table base address */
  74. u32 currPtr;
  75. u32 endPtr;
  76. u32 varTablePtr;
  77. u16 dma_rsvd0;
  78. u16 ptdControl; /* ptd control */
  79. u32 intPending; /* interrupt pending */
  80. u32 intMask; /* interrupt mask */
  81. u16 taskControl[16]; /* task control */
  82. u8 priority[32]; /* priority */
  83. u32 initiatorMux; /* initiator mux control */
  84. u32 taskSize0; /* task size control 0. */
  85. u32 taskSize1; /* task size control 1. */
  86. u32 dma_rsvd1; /* reserved */
  87. u32 dma_rsvd2; /* reserved */
  88. u32 debugComp1; /* debug comparator 1 */
  89. u32 debugComp2; /* debug comparator 2 */
  90. u32 debugControl; /* debug control */
  91. u32 debugStatus; /* debug status */
  92. u32 ptdDebug; /* priority task decode debug */
  93. u32 dma_rsvd3[31]; /* reserved */
  94. };
  95. typedef volatile struct dmaRegs_s dmaRegs;
  96. #endif
  97. /* PTD contrl reg bits */
  98. #define PTD_CTL_TSK_PRI 0x8000
  99. #define PTD_CTL_COMM_PREFETCH 0x0001
  100. /* Task Control reg bits and field masks */
  101. #define TASK_CTL_EN 0x8000
  102. #define TASK_CTL_VALID 0x4000
  103. #define TASK_CTL_ALWAYS 0x2000
  104. #define TASK_CTL_INIT_MASK 0x1f00
  105. #define TASK_CTL_ASTRT 0x0080
  106. #define TASK_CTL_HIPRITSKEN 0x0040
  107. #define TASK_CTL_HLDINITNUM 0x0020
  108. #define TASK_CTL_ASTSKNUM_MASK 0x000f
  109. /* Priority reg bits and field masks */
  110. #define PRIORITY_HLD 0x80
  111. #define PRIORITY_PRI_MASK 0x07
  112. /* Debug Control reg bits and field masks */
  113. #define DBG_CTL_BLOCK_TASKS_MASK 0xffff0000
  114. #define DBG_CTL_AUTO_ARM 0x00008000
  115. #define DBG_CTL_BREAK 0x00004000
  116. #define DBG_CTL_COMP1_TYP_MASK 0x00003800
  117. #define DBG_CTL_COMP2_TYP_MASK 0x00000070
  118. #define DBG_CTL_EXT_BREAK 0x00000004
  119. #define DBG_CTL_INT_BREAK 0x00000002
  120. /*
  121. * PTD Debug reg selector addresses
  122. * This reg must be written with a value to show the contents of
  123. * one of the desired internal register.
  124. */
  125. #define PTD_DBG_REQ 0x00 /* shows the state of 31 initiators */
  126. #define PTD_DBG_TSK_VLD_INIT 0x01 /* shows which 16 tasks are valid and
  127. have initiators asserted */
  128. /* General return values */
  129. #define MCD_OK 0
  130. #define MCD_ERROR -1
  131. #define MCD_TABLE_UNALIGNED -2
  132. #define MCD_CHANNEL_INVALID -3
  133. /* MCD_initDma input flags */
  134. #define MCD_RELOC_TASKS 0x00000001
  135. #define MCD_NO_RELOC_TASKS 0x00000000
  136. #define MCD_COMM_PREFETCH_EN 0x00000002 /* MCF547x/548x ONLY */
  137. /*
  138. * MCD_dmaStatus Status Values for each channel:
  139. * MCD_NO_DMA - No DMA has been requested since reset
  140. * MCD_IDLE - DMA active, but the initiator is currently inactive
  141. * MCD_RUNNING - DMA active, and the initiator is currently active
  142. * MCD_PAUSED - DMA active but it is currently paused
  143. * MCD_HALTED - the most recent DMA has been killed with MCD_killTask()
  144. * MCD_DONE - the most recent DMA has completed
  145. */
  146. #define MCD_NO_DMA 1
  147. #define MCD_IDLE 2
  148. #define MCD_RUNNING 3
  149. #define MCD_PAUSED 4
  150. #define MCD_HALTED 5
  151. #define MCD_DONE 6
  152. /* MCD_startDma parameter defines */
  153. /* Constants for the funcDesc parameter */
  154. /*
  155. * MCD_NO_BYTE_SWAP - to disable byte swapping
  156. * MCD_BYTE_REVERSE - to reverse the bytes of each u32 of the DMAed data
  157. * MCD_U16_REVERSE - to reverse the 16-bit halves of each 32-bit data
  158. * value being DMAed
  159. * MCD_U16_BYTE_REVERSE - to reverse the byte halves of each 16-bit half of
  160. * each 32-bit data value DMAed
  161. * MCD_NO_BIT_REV - do not reverse the bits of each byte DMAed
  162. * MCD_BIT_REV - reverse the bits of each byte DMAed
  163. * MCD_CRC16 - to perform CRC-16 on DMAed data
  164. * MCD_CRCCCITT - to perform CRC-CCITT on DMAed data
  165. * MCD_CRC32 - to perform CRC-32 on DMAed data
  166. * MCD_CSUMINET - to perform internet checksums on DMAed data
  167. * MCD_NO_CSUM - to perform no checksumming
  168. */
  169. #define MCD_NO_BYTE_SWAP 0x00045670
  170. #define MCD_BYTE_REVERSE 0x00076540
  171. #define MCD_U16_REVERSE 0x00067450
  172. #define MCD_U16_BYTE_REVERSE 0x00054760
  173. #define MCD_NO_BIT_REV 0x00000000
  174. #define MCD_BIT_REV 0x00088880
  175. /* CRCing: */
  176. #define MCD_CRC16 0xc0100000
  177. #define MCD_CRCCCITT 0xc0200000
  178. #define MCD_CRC32 0xc0300000
  179. #define MCD_CSUMINET 0xc0400000
  180. #define MCD_NO_CSUM 0xa0000000
  181. #define MCD_FUNC_NOEU1 (MCD_NO_BYTE_SWAP | MCD_NO_BIT_REV | \
  182. MCD_NO_CSUM)
  183. #define MCD_FUNC_NOEU2 (MCD_NO_BYTE_SWAP | MCD_NO_CSUM)
  184. /* Constants for the flags parameter */
  185. #define MCD_TT_FLAGS_RL 0x00000001 /* Read line */
  186. #define MCD_TT_FLAGS_CW 0x00000002 /* Combine Writes */
  187. #define MCD_TT_FLAGS_SP 0x00000004 /* MCF547x/548x ONLY */
  188. #define MCD_TT_FLAGS_MASK 0x000000ff
  189. #define MCD_TT_FLAGS_DEF (MCD_TT_FLAGS_RL | MCD_TT_FLAGS_CW)
  190. #define MCD_SINGLE_DMA 0x00000100 /* Unchained DMA */
  191. #define MCD_CHAIN_DMA /* TBD */
  192. #define MCD_EU_DMA /* TBD */
  193. #define MCD_FECTX_DMA 0x00001000 /* FEC TX ring DMA */
  194. #define MCD_FECRX_DMA 0x00002000 /* FEC RX ring DMA */
  195. /* these flags are valid for MCD_startDma and the chained buffer descriptors */
  196. /*
  197. * MCD_BUF_READY - indicates that this buf is now under the DMA's ctrl
  198. * MCD_WRAP - to tell the FEC Dmas to wrap to the first BD
  199. * MCD_INTERRUPT - to generate an interrupt after completion of the DMA
  200. * MCD_END_FRAME - tell the DMA to end the frame when transferring
  201. * last byte of data in buffer
  202. * MCD_CRC_RESTART - to empty out the accumulated checksum prior to
  203. * performing the DMA
  204. */
  205. #define MCD_BUF_READY 0x80000000
  206. #define MCD_WRAP 0x20000000
  207. #define MCD_INTERRUPT 0x10000000
  208. #define MCD_END_FRAME 0x08000000
  209. #define MCD_CRC_RESTART 0x40000000
  210. /* Defines for the FEC buffer descriptor control/status word*/
  211. #define MCD_FEC_BUF_READY 0x8000
  212. #define MCD_FEC_WRAP 0x2000
  213. #define MCD_FEC_INTERRUPT 0x1000
  214. #define MCD_FEC_END_FRAME 0x0800
  215. /* Defines for general intuitiveness */
  216. #define MCD_TRUE 1
  217. #define MCD_FALSE 0
  218. /* Three different cases for destination and source. */
  219. #define MINUS1 -1
  220. #define ZERO 0
  221. #define PLUS1 1
  222. #ifndef DEFINESONLY
  223. /* Task Table Entry struct*/
  224. typedef struct {
  225. u32 TDTstart; /* task descriptor table start */
  226. u32 TDTend; /* task descriptor table end */
  227. u32 varTab; /* variable table start */
  228. u32 FDTandFlags; /* function descriptor table start & flags */
  229. volatile u32 descAddrAndStatus;
  230. volatile u32 modifiedVarTab;
  231. u32 contextSaveSpace; /* context save space start */
  232. u32 literalBases;
  233. } TaskTableEntry;
  234. /* Chained buffer descriptor:
  235. * flags - flags describing the DMA
  236. * csumResult - checksum performed since last checksum reset
  237. * srcAddr - the address to move data from
  238. * destAddr - the address to move data to
  239. * lastDestAddr - the last address written to
  240. * dmaSize - the no of bytes to xfer independent of the xfer sz
  241. * next - next buffer descriptor in chain
  242. * info - private info about this descriptor; DMA does not affect it
  243. */
  244. typedef volatile struct MCD_bufDesc_struct MCD_bufDesc;
  245. struct MCD_bufDesc_struct {
  246. u32 flags;
  247. u32 csumResult;
  248. s8 *srcAddr;
  249. s8 *destAddr;
  250. s8 *lastDestAddr;
  251. u32 dmaSize;
  252. MCD_bufDesc *next;
  253. u32 info;
  254. };
  255. /* Progress Query struct:
  256. * lastSrcAddr - the most-recent or last, post-increment source address
  257. * lastDestAddr - the most-recent or last, post-increment destination address
  258. * dmaSize - the amount of data transferred for the current buffer
  259. * currBufDesc - pointer to the current buffer descriptor being DMAed
  260. */
  261. typedef volatile struct MCD_XferProg_struct {
  262. s8 *lastSrcAddr;
  263. s8 *lastDestAddr;
  264. u32 dmaSize;
  265. MCD_bufDesc *currBufDesc;
  266. } MCD_XferProg;
  267. /* FEC buffer descriptor */
  268. typedef volatile struct MCD_bufDescFec_struct {
  269. u16 statCtrl;
  270. u16 length;
  271. u32 dataPointer;
  272. } MCD_bufDescFec;
  273. /*************************************************************************/
  274. /* API function Prototypes - see MCD_dmaApi.c for further notes */
  275. /* MCD_startDma starts a particular kind of DMA:
  276. * srcAddr - the channel on which to run the DMA
  277. * srcIncr - the address to move data from, or buffer-descriptor address
  278. * destAddr - the amount to increment the source address per transfer
  279. * destIncr - the address to move data to
  280. * dmaSize - the amount to increment the destination address per transfer
  281. * xferSize - the number bytes in of each data movement (1, 2, or 4)
  282. * initiator - what device initiates the DMA
  283. * priority - priority of the DMA
  284. * flags - flags describing the DMA
  285. * funcDesc - description of byte swapping, bit swapping, and CRC actions
  286. */
  287. int MCD_startDma(int channel, s8 * srcAddr, s16 srcIncr, s8 * destAddr,
  288. s16 destIncr, u32 dmaSize, u32 xferSize, u32 initiator,
  289. int priority, u32 flags, u32 funcDesc);
  290. /*
  291. * MCD_initDma() initializes the DMA API by setting up a pointer to the DMA
  292. * registers, relocating and creating the appropriate task structures, and
  293. * setting up some global settings
  294. */
  295. int MCD_initDma(dmaRegs * sDmaBarAddr, void *taskTableDest, u32 flags);
  296. /* MCD_dmaStatus() returns the status of the DMA on the requested channel. */
  297. int MCD_dmaStatus(int channel);
  298. /* MCD_XferProgrQuery() returns progress of DMA on requested channel */
  299. int MCD_XferProgrQuery(int channel, MCD_XferProg * progRep);
  300. /*
  301. * MCD_killDma() halts the DMA on the requested channel, without any
  302. * intention of resuming the DMA.
  303. */
  304. int MCD_killDma(int channel);
  305. /*
  306. * MCD_continDma() continues a DMA which as stopped due to encountering an
  307. * unready buffer descriptor.
  308. */
  309. int MCD_continDma(int channel);
  310. /*
  311. * MCD_pauseDma() pauses the DMA on the given channel ( if any DMA is
  312. * running on that channel).
  313. */
  314. int MCD_pauseDma(int channel);
  315. /*
  316. * MCD_resumeDma() resumes the DMA on a given channel (if any DMA is
  317. * running on that channel).
  318. */
  319. int MCD_resumeDma(int channel);
  320. /* MCD_csumQuery provides the checksum/CRC after performing a non-chained DMA */
  321. int MCD_csumQuery(int channel, u32 * csum);
  322. /*
  323. * MCD_getCodeSize provides the packed size required by the microcoded task
  324. * and structures.
  325. */
  326. int MCD_getCodeSize(void);
  327. /*
  328. * MCD_getVersion provides a pointer to a version string and returns a
  329. * version number.
  330. */
  331. int MCD_getVersion(char **longVersion);
  332. /* macro for setting a location in the variable table */
  333. #define MCD_SET_VAR(taskTab,idx,value) ((u32 *)(taskTab)->varTab)[idx] = value
  334. /* Note that MCD_SET_VAR() is invoked many times in firing up a DMA function,
  335. so I'm avoiding surrounding it with "do {} while(0)" */
  336. #endif /* DEFINESONLY */
  337. #endif /* _MCD_API_H */