MCD_dmaApi.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026
  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. /*Main C file for multi-channel DMA API. */
  23. #include <common.h>
  24. #ifdef CONFIG_FSLDMAFEC
  25. #include <MCD_dma.h>
  26. #include <MCD_tasksInit.h>
  27. #include <MCD_progCheck.h>
  28. /********************************************************************/
  29. /* This is an API-internal pointer to the DMA's registers */
  30. dmaRegs *MCD_dmaBar;
  31. /*
  32. * These are the real and model task tables as generated by the
  33. * build process
  34. */
  35. extern TaskTableEntry MCD_realTaskTableSrc[NCHANNELS];
  36. extern TaskTableEntry MCD_modelTaskTableSrc[NUMOFVARIANTS];
  37. /*
  38. * However, this (usually) gets relocated to on-chip SRAM, at which
  39. * point we access them as these tables
  40. */
  41. volatile TaskTableEntry *MCD_taskTable;
  42. TaskTableEntry *MCD_modelTaskTable;
  43. /*
  44. * MCD_chStatus[] is an array of status indicators for remembering
  45. * whether a DMA has ever been attempted on each channel, pausing
  46. * status, etc.
  47. */
  48. static int MCD_chStatus[NCHANNELS] = {
  49. MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA,
  50. MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA,
  51. MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA,
  52. MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA
  53. };
  54. /* Prototypes for local functions */
  55. static void MCD_memcpy(int *dest, int *src, u32 size);
  56. static void MCD_resmActions(int channel);
  57. /*
  58. * Buffer descriptors used for storage of progress info for single Dmas
  59. * Also used as storage for the DMA for CRCs for single DMAs
  60. * Otherwise, the DMA does not parse these buffer descriptors
  61. */
  62. #ifdef MCD_INCLUDE_EU
  63. extern MCD_bufDesc MCD_singleBufDescs[NCHANNELS];
  64. #else
  65. MCD_bufDesc MCD_singleBufDescs[NCHANNELS];
  66. #endif
  67. MCD_bufDesc *MCD_relocBuffDesc;
  68. /* Defines for the debug control register's functions */
  69. #define DBG_CTL_COMP1_TASK (0x00002000)
  70. #define DBG_CTL_ENABLE (DBG_CTL_AUTO_ARM | \
  71. DBG_CTL_BREAK | \
  72. DBG_CTL_INT_BREAK | \
  73. DBG_CTL_COMP1_TASK)
  74. #define DBG_CTL_DISABLE (DBG_CTL_AUTO_ARM | \
  75. DBG_CTL_INT_BREAK | \
  76. DBG_CTL_COMP1_TASK)
  77. #define DBG_KILL_ALL_STAT (0xFFFFFFFF)
  78. /* Offset to context save area where progress info is stored */
  79. #define CSAVE_OFFSET 10
  80. /* Defines for Byte Swapping */
  81. #define MCD_BYTE_SWAP_KILLER 0xFFF8888F
  82. #define MCD_NO_BYTE_SWAP_ATALL 0x00040000
  83. /* Execution Unit Identifiers */
  84. #define MAC 0 /* legacy - not used */
  85. #define LUAC 1 /* legacy - not used */
  86. #define CRC 2 /* legacy - not used */
  87. #define LURC 3 /* Logic Unit with CRC */
  88. /* Task Identifiers */
  89. #define TASK_CHAINNOEU 0
  90. #define TASK_SINGLENOEU 1
  91. #ifdef MCD_INCLUDE_EU
  92. #define TASK_CHAINEU 2
  93. #define TASK_SINGLEEU 3
  94. #define TASK_FECRX 4
  95. #define TASK_FECTX 5
  96. #else
  97. #define TASK_CHAINEU 0
  98. #define TASK_SINGLEEU 1
  99. #define TASK_FECRX 2
  100. #define TASK_FECTX 3
  101. #endif
  102. /*
  103. * Structure to remember which variant is on which channel
  104. * TBD- need this?
  105. */
  106. typedef struct MCD_remVariants_struct MCD_remVariant;
  107. struct MCD_remVariants_struct {
  108. int remDestRsdIncr[NCHANNELS]; /* -1,0,1 */
  109. int remSrcRsdIncr[NCHANNELS]; /* -1,0,1 */
  110. s16 remDestIncr[NCHANNELS]; /* DestIncr */
  111. s16 remSrcIncr[NCHANNELS]; /* srcIncr */
  112. u32 remXferSize[NCHANNELS]; /* xferSize */
  113. };
  114. /* Structure to remember the startDma parameters for each channel */
  115. MCD_remVariant MCD_remVariants;
  116. /********************************************************************/
  117. /* Function: MCD_initDma
  118. * Purpose: Initializes the DMA API by setting up a pointer to the DMA
  119. * registers, relocating and creating the appropriate task
  120. * structures, and setting up some global settings
  121. * Arguments:
  122. * dmaBarAddr - pointer to the multichannel DMA registers
  123. * taskTableDest - location to move DMA task code and structs to
  124. * flags - operational parameters
  125. * Return Value:
  126. * MCD_TABLE_UNALIGNED if taskTableDest is not 512-byte aligned
  127. * MCD_OK otherwise
  128. */
  129. extern u32 MCD_funcDescTab0[];
  130. int MCD_initDma(dmaRegs * dmaBarAddr, void *taskTableDest, u32 flags)
  131. {
  132. int i;
  133. TaskTableEntry *entryPtr;
  134. /* setup the local pointer to register set */
  135. MCD_dmaBar = dmaBarAddr;
  136. /* do we need to move/create a task table */
  137. if ((flags & MCD_RELOC_TASKS) != 0) {
  138. int fixedSize;
  139. u32 *fixedPtr;
  140. /*int *tablePtr = taskTableDest;TBD */
  141. int varTabsOffset, funcDescTabsOffset, contextSavesOffset;
  142. int taskDescTabsOffset;
  143. int taskTableSize, varTabsSize, funcDescTabsSize,
  144. contextSavesSize;
  145. int taskDescTabSize;
  146. int i;
  147. /* check if physical address is aligned on 512 byte boundary */
  148. if (((u32) taskTableDest & 0x000001ff) != 0)
  149. return (MCD_TABLE_UNALIGNED);
  150. /* set up local pointer to task Table */
  151. MCD_taskTable = taskTableDest;
  152. /*
  153. * Create a task table:
  154. * - compute aligned base offsets for variable tables and
  155. * function descriptor tables, then
  156. * - loop through the task table and setup the pointers
  157. * - copy over model task table with the the actual task
  158. * descriptor tables
  159. */
  160. taskTableSize = NCHANNELS * sizeof(TaskTableEntry);
  161. /* align variable tables to size */
  162. varTabsOffset = taskTableSize + (u32) taskTableDest;
  163. if ((varTabsOffset & (VAR_TAB_SIZE - 1)) != 0)
  164. varTabsOffset =
  165. (varTabsOffset + VAR_TAB_SIZE) & (~VAR_TAB_SIZE);
  166. /* align function descriptor tables */
  167. varTabsSize = NCHANNELS * VAR_TAB_SIZE;
  168. funcDescTabsOffset = varTabsOffset + varTabsSize;
  169. if ((funcDescTabsOffset & (FUNCDESC_TAB_SIZE - 1)) != 0)
  170. funcDescTabsOffset =
  171. (funcDescTabsOffset +
  172. FUNCDESC_TAB_SIZE) & (~FUNCDESC_TAB_SIZE);
  173. funcDescTabsSize = FUNCDESC_TAB_NUM * FUNCDESC_TAB_SIZE;
  174. contextSavesOffset = funcDescTabsOffset + funcDescTabsSize;
  175. contextSavesSize = (NCHANNELS * CONTEXT_SAVE_SIZE);
  176. fixedSize =
  177. taskTableSize + varTabsSize + funcDescTabsSize +
  178. contextSavesSize;
  179. /* zero the thing out */
  180. fixedPtr = (u32 *) taskTableDest;
  181. for (i = 0; i < (fixedSize / 4); i++)
  182. fixedPtr[i] = 0;
  183. entryPtr = (TaskTableEntry *) MCD_taskTable;
  184. /* set up fixed pointers */
  185. for (i = 0; i < NCHANNELS; i++) {
  186. /* update ptr to local value */
  187. entryPtr[i].varTab = (u32) varTabsOffset;
  188. entryPtr[i].FDTandFlags =
  189. (u32) funcDescTabsOffset | MCD_TT_FLAGS_DEF;
  190. entryPtr[i].contextSaveSpace = (u32) contextSavesOffset;
  191. varTabsOffset += VAR_TAB_SIZE;
  192. #ifdef MCD_INCLUDE_EU
  193. /* if not there is only one, just point to the
  194. same one */
  195. funcDescTabsOffset += FUNCDESC_TAB_SIZE;
  196. #endif
  197. contextSavesOffset += CONTEXT_SAVE_SIZE;
  198. }
  199. /* copy over the function descriptor table */
  200. for (i = 0; i < FUNCDESC_TAB_NUM; i++) {
  201. MCD_memcpy((void *)(entryPtr[i].
  202. FDTandFlags & ~MCD_TT_FLAGS_MASK),
  203. (void *)MCD_funcDescTab0, FUNCDESC_TAB_SIZE);
  204. }
  205. /* copy model task table to where the context saves stuff
  206. leaves off */
  207. MCD_modelTaskTable = (TaskTableEntry *) contextSavesOffset;
  208. MCD_memcpy((void *)MCD_modelTaskTable,
  209. (void *)MCD_modelTaskTableSrc,
  210. NUMOFVARIANTS * sizeof(TaskTableEntry));
  211. /* point to local version of model task table */
  212. entryPtr = MCD_modelTaskTable;
  213. taskDescTabsOffset = (u32) MCD_modelTaskTable +
  214. (NUMOFVARIANTS * sizeof(TaskTableEntry));
  215. /* copy actual task code and update TDT ptrs in local
  216. model task table */
  217. for (i = 0; i < NUMOFVARIANTS; i++) {
  218. taskDescTabSize =
  219. entryPtr[i].TDTend - entryPtr[i].TDTstart + 4;
  220. MCD_memcpy((void *)taskDescTabsOffset,
  221. (void *)entryPtr[i].TDTstart,
  222. taskDescTabSize);
  223. entryPtr[i].TDTstart = (u32) taskDescTabsOffset;
  224. taskDescTabsOffset += taskDescTabSize;
  225. entryPtr[i].TDTend = (u32) taskDescTabsOffset - 4;
  226. }
  227. #ifdef MCD_INCLUDE_EU
  228. /* Tack single DMA BDs onto end of code so API controls
  229. where they are since DMA might write to them */
  230. MCD_relocBuffDesc =
  231. (MCD_bufDesc *) (entryPtr[NUMOFVARIANTS - 1].TDTend + 4);
  232. #else
  233. /* DMA does not touch them so they can be wherever and we
  234. don't need to waste SRAM on them */
  235. MCD_relocBuffDesc = MCD_singleBufDescs;
  236. #endif
  237. } else {
  238. /* point the would-be relocated task tables and the
  239. buffer descriptors to the ones the linker generated */
  240. if (((u32) MCD_realTaskTableSrc & 0x000001ff) != 0)
  241. return (MCD_TABLE_UNALIGNED);
  242. /* need to add code to make sure that every thing else is
  243. aligned properly TBD. this is problematic if we init
  244. more than once or after running tasks, need to add
  245. variable to see if we have aleady init'd */
  246. entryPtr = MCD_realTaskTableSrc;
  247. for (i = 0; i < NCHANNELS; i++) {
  248. if (((entryPtr[i].varTab & (VAR_TAB_SIZE - 1)) != 0) ||
  249. ((entryPtr[i].
  250. FDTandFlags & (FUNCDESC_TAB_SIZE - 1)) != 0))
  251. return (MCD_TABLE_UNALIGNED);
  252. }
  253. MCD_taskTable = MCD_realTaskTableSrc;
  254. MCD_modelTaskTable = MCD_modelTaskTableSrc;
  255. MCD_relocBuffDesc = MCD_singleBufDescs;
  256. }
  257. /* Make all channels as totally inactive, and remember them as such: */
  258. MCD_dmaBar->taskbar = (u32) MCD_taskTable;
  259. for (i = 0; i < NCHANNELS; i++) {
  260. MCD_dmaBar->taskControl[i] = 0x0;
  261. MCD_chStatus[i] = MCD_NO_DMA;
  262. }
  263. /* Set up pausing mechanism to inactive state: */
  264. /* no particular values yet for either comparator registers */
  265. MCD_dmaBar->debugComp1 = 0;
  266. MCD_dmaBar->debugComp2 = 0;
  267. MCD_dmaBar->debugControl = DBG_CTL_DISABLE;
  268. MCD_dmaBar->debugStatus = DBG_KILL_ALL_STAT;
  269. /* enable or disable commbus prefetch, really need an ifdef or
  270. something to keep from trying to set this in the 8220 */
  271. if ((flags & MCD_COMM_PREFETCH_EN) != 0)
  272. MCD_dmaBar->ptdControl &= ~PTD_CTL_COMM_PREFETCH;
  273. else
  274. MCD_dmaBar->ptdControl |= PTD_CTL_COMM_PREFETCH;
  275. return (MCD_OK);
  276. }
  277. /*********************** End of MCD_initDma() ***********************/
  278. /********************************************************************/
  279. /* Function: MCD_dmaStatus
  280. * Purpose: Returns the status of the DMA on the requested channel
  281. * Arguments: channel - channel number
  282. * Returns: Predefined status indicators
  283. */
  284. int MCD_dmaStatus(int channel)
  285. {
  286. u16 tcrValue;
  287. if ((channel < 0) || (channel >= NCHANNELS))
  288. return (MCD_CHANNEL_INVALID);
  289. tcrValue = MCD_dmaBar->taskControl[channel];
  290. if ((tcrValue & TASK_CTL_EN) == 0) { /* nothing running */
  291. /* if last reported with task enabled */
  292. if (MCD_chStatus[channel] == MCD_RUNNING
  293. || MCD_chStatus[channel] == MCD_IDLE)
  294. MCD_chStatus[channel] = MCD_DONE;
  295. } else { /* something is running */
  296. /* There are three possibilities: paused, running or idle. */
  297. if (MCD_chStatus[channel] == MCD_RUNNING
  298. || MCD_chStatus[channel] == MCD_IDLE) {
  299. MCD_dmaBar->ptdDebug = PTD_DBG_TSK_VLD_INIT;
  300. /* This register is selected to know which initiator is
  301. actually asserted. */
  302. if ((MCD_dmaBar->ptdDebug >> channel) & 0x1)
  303. MCD_chStatus[channel] = MCD_RUNNING;
  304. else
  305. MCD_chStatus[channel] = MCD_IDLE;
  306. /* do not change the status if it is already paused. */
  307. }
  308. }
  309. return MCD_chStatus[channel];
  310. }
  311. /******************** End of MCD_dmaStatus() ************************/
  312. /********************************************************************/
  313. /* Function: MCD_startDma
  314. * Ppurpose: Starts a particular kind of DMA
  315. * Arguments:
  316. * srcAddr - the channel on which to run the DMA
  317. * srcIncr - the address to move data from, or buffer-descriptor address
  318. * destAddr - the amount to increment the source address per transfer
  319. * destIncr - the address to move data to
  320. * dmaSize - the amount to increment the destination address per transfer
  321. * xferSize - the number bytes in of each data movement (1, 2, or 4)
  322. * initiator - what device initiates the DMA
  323. * priority - priority of the DMA
  324. * flags - flags describing the DMA
  325. * funcDesc - description of byte swapping, bit swapping, and CRC actions
  326. * srcAddrVirt - virtual buffer descriptor address TBD
  327. * Returns: MCD_CHANNEL_INVALID if channel is invalid, else MCD_OK
  328. */
  329. int MCD_startDma(int channel, s8 * srcAddr, s16 srcIncr, s8 * destAddr,
  330. s16 destIncr, u32 dmaSize, u32 xferSize, u32 initiator,
  331. int priority, u32 flags, u32 funcDesc
  332. #ifdef MCD_NEED_ADDR_TRANS
  333. s8 * srcAddrVirt
  334. #endif
  335. )
  336. {
  337. int srcRsdIncr, destRsdIncr;
  338. int *cSave;
  339. short xferSizeIncr;
  340. int tcrCount = 0;
  341. #ifdef MCD_INCLUDE_EU
  342. u32 *realFuncArray;
  343. #endif
  344. if ((channel < 0) || (channel >= NCHANNELS))
  345. return (MCD_CHANNEL_INVALID);
  346. /* tbd - need to determine the proper response to a bad funcDesc when
  347. not including EU functions, for now, assign a benign funcDesc, but
  348. maybe should return an error */
  349. #ifndef MCD_INCLUDE_EU
  350. funcDesc = MCD_FUNC_NOEU1;
  351. #endif
  352. #ifdef MCD_DEBUG
  353. printf("startDma:Setting up params\n");
  354. #endif
  355. /* Set us up for task-wise priority. We don't technically need to do
  356. this on every start, but since the register involved is in the same
  357. longword as other registers that users are in control of, setting
  358. it more than once is probably preferable. That since the
  359. documentation doesn't seem to be completely consistent about the
  360. nature of the PTD control register. */
  361. MCD_dmaBar->ptdControl |= (u16) 0x8000;
  362. /* Not sure what we need to keep here rtm TBD */
  363. #if 1
  364. /* Calculate additional parameters to the regular DMA calls. */
  365. srcRsdIncr = srcIncr < 0 ? -1 : (srcIncr > 0 ? 1 : 0);
  366. destRsdIncr = destIncr < 0 ? -1 : (destIncr > 0 ? 1 : 0);
  367. xferSizeIncr = (xferSize & 0xffff) | 0x20000000;
  368. /* Remember for each channel which variant is running. */
  369. MCD_remVariants.remSrcRsdIncr[channel] = srcRsdIncr;
  370. MCD_remVariants.remDestRsdIncr[channel] = destRsdIncr;
  371. MCD_remVariants.remDestIncr[channel] = destIncr;
  372. MCD_remVariants.remSrcIncr[channel] = srcIncr;
  373. MCD_remVariants.remXferSize[channel] = xferSize;
  374. #endif
  375. cSave =
  376. (int *)(MCD_taskTable[channel].contextSaveSpace) + CSAVE_OFFSET +
  377. CURRBD;
  378. #ifdef MCD_INCLUDE_EU
  379. /* may move this to EU specific calls */
  380. realFuncArray =
  381. (u32 *) (MCD_taskTable[channel].FDTandFlags & 0xffffff00);
  382. /* Modify the LURC's normal and byte-residue-loop functions according
  383. to parameter. */
  384. realFuncArray[(LURC * 16)] = xferSize == 4 ?
  385. funcDesc : xferSize == 2 ?
  386. funcDesc & 0xfffff00f : funcDesc & 0xffff000f;
  387. realFuncArray[(LURC * 16 + 1)] =
  388. (funcDesc & MCD_BYTE_SWAP_KILLER) | MCD_NO_BYTE_SWAP_ATALL;
  389. #endif
  390. /* Write the initiator field in the TCR, and also set the
  391. initiator-hold bit. Note that,due to a hardware quirk, this could
  392. collide with an MDE access to the initiator-register file, so we
  393. have to verify that the write reads back correctly. */
  394. MCD_dmaBar->taskControl[channel] =
  395. (initiator << 8) | TASK_CTL_HIPRITSKEN | TASK_CTL_HLDINITNUM;
  396. while (((MCD_dmaBar->taskControl[channel] & 0x1fff) !=
  397. ((initiator << 8) | TASK_CTL_HIPRITSKEN | TASK_CTL_HLDINITNUM))
  398. && (tcrCount < 1000)) {
  399. tcrCount++;
  400. /*MCD_dmaBar->ptd_tcr[channel] = (initiator << 8) | 0x0020; */
  401. MCD_dmaBar->taskControl[channel] =
  402. (initiator << 8) | TASK_CTL_HIPRITSKEN |
  403. TASK_CTL_HLDINITNUM;
  404. }
  405. MCD_dmaBar->priority[channel] = (u8) priority & PRIORITY_PRI_MASK;
  406. /* should be albe to handle this stuff with only one write to ts reg
  407. - tbd */
  408. if (channel < 8 && channel >= 0) {
  409. MCD_dmaBar->taskSize0 &= ~(0xf << (7 - channel) * 4);
  410. MCD_dmaBar->taskSize0 |=
  411. (xferSize & 3) << (((7 - channel) * 4) + 2);
  412. MCD_dmaBar->taskSize0 |= (xferSize & 3) << ((7 - channel) * 4);
  413. } else {
  414. MCD_dmaBar->taskSize1 &= ~(0xf << (15 - channel) * 4);
  415. MCD_dmaBar->taskSize1 |=
  416. (xferSize & 3) << (((15 - channel) * 4) + 2);
  417. MCD_dmaBar->taskSize1 |= (xferSize & 3) << ((15 - channel) * 4);
  418. }
  419. /* setup task table flags/options which mostly control the line
  420. buffers */
  421. MCD_taskTable[channel].FDTandFlags &= ~MCD_TT_FLAGS_MASK;
  422. MCD_taskTable[channel].FDTandFlags |= (MCD_TT_FLAGS_MASK & flags);
  423. if (flags & MCD_FECTX_DMA) {
  424. /* TDTStart and TDTEnd */
  425. MCD_taskTable[channel].TDTstart =
  426. MCD_modelTaskTable[TASK_FECTX].TDTstart;
  427. MCD_taskTable[channel].TDTend =
  428. MCD_modelTaskTable[TASK_FECTX].TDTend;
  429. MCD_startDmaENetXmit(srcAddr, srcAddr, destAddr, MCD_taskTable,
  430. channel);
  431. } else if (flags & MCD_FECRX_DMA) {
  432. /* TDTStart and TDTEnd */
  433. MCD_taskTable[channel].TDTstart =
  434. MCD_modelTaskTable[TASK_FECRX].TDTstart;
  435. MCD_taskTable[channel].TDTend =
  436. MCD_modelTaskTable[TASK_FECRX].TDTend;
  437. MCD_startDmaENetRcv(srcAddr, srcAddr, destAddr, MCD_taskTable,
  438. channel);
  439. } else if (flags & MCD_SINGLE_DMA) {
  440. /* this buffer descriptor is used for storing off initial
  441. parameters for later progress query calculation and for the
  442. DMA to write the resulting checksum. The DMA does not use
  443. this to determine how to operate, that info is passed with
  444. the init routine */
  445. MCD_relocBuffDesc[channel].srcAddr = srcAddr;
  446. MCD_relocBuffDesc[channel].destAddr = destAddr;
  447. /* definitely not its final value */
  448. MCD_relocBuffDesc[channel].lastDestAddr = destAddr;
  449. MCD_relocBuffDesc[channel].dmaSize = dmaSize;
  450. MCD_relocBuffDesc[channel].flags = 0; /* not used */
  451. MCD_relocBuffDesc[channel].csumResult = 0; /* not used */
  452. MCD_relocBuffDesc[channel].next = 0; /* not used */
  453. /* Initialize the progress-querying stuff to show no
  454. progress: */
  455. ((volatile int *)MCD_taskTable[channel].
  456. contextSaveSpace)[SRCPTR + CSAVE_OFFSET] = (int)srcAddr;
  457. ((volatile int *)MCD_taskTable[channel].
  458. contextSaveSpace)[DESTPTR + CSAVE_OFFSET] = (int)destAddr;
  459. ((volatile int *)MCD_taskTable[channel].
  460. contextSaveSpace)[DCOUNT + CSAVE_OFFSET] = 0;
  461. ((volatile int *)MCD_taskTable[channel].
  462. contextSaveSpace)[CURRBD + CSAVE_OFFSET] =
  463. (u32) & (MCD_relocBuffDesc[channel]);
  464. /* tbd - need to keep the user from trying to call the EU
  465. routine when MCD_INCLUDE_EU is not defined */
  466. if (funcDesc == MCD_FUNC_NOEU1 || funcDesc == MCD_FUNC_NOEU2) {
  467. /* TDTStart and TDTEnd */
  468. MCD_taskTable[channel].TDTstart =
  469. MCD_modelTaskTable[TASK_SINGLENOEU].TDTstart;
  470. MCD_taskTable[channel].TDTend =
  471. MCD_modelTaskTable[TASK_SINGLENOEU].TDTend;
  472. MCD_startDmaSingleNoEu(srcAddr, srcIncr, destAddr,
  473. destIncr, dmaSize, xferSizeIncr,
  474. flags, (int *)
  475. &(MCD_relocBuffDesc[channel]),
  476. cSave, MCD_taskTable, channel);
  477. } else {
  478. /* TDTStart and TDTEnd */
  479. MCD_taskTable[channel].TDTstart =
  480. MCD_modelTaskTable[TASK_SINGLEEU].TDTstart;
  481. MCD_taskTable[channel].TDTend =
  482. MCD_modelTaskTable[TASK_SINGLEEU].TDTend;
  483. MCD_startDmaSingleEu(srcAddr, srcIncr, destAddr,
  484. destIncr, dmaSize, xferSizeIncr,
  485. flags, (int *)
  486. &(MCD_relocBuffDesc[channel]),
  487. cSave, MCD_taskTable, channel);
  488. }
  489. } else { /* chained DMAS */
  490. /* Initialize the progress-querying stuff to show no
  491. progress: */
  492. #if 1
  493. /* (!defined(MCD_NEED_ADDR_TRANS)) */
  494. ((volatile int *)MCD_taskTable[channel].
  495. contextSaveSpace)[SRCPTR + CSAVE_OFFSET]
  496. = (int)((MCD_bufDesc *) srcAddr)->srcAddr;
  497. ((volatile int *)MCD_taskTable[channel].
  498. contextSaveSpace)[DESTPTR + CSAVE_OFFSET]
  499. = (int)((MCD_bufDesc *) srcAddr)->destAddr;
  500. #else
  501. /* if using address translation, need the virtual addr of the
  502. first buffdesc */
  503. ((volatile int *)MCD_taskTable[channel].
  504. contextSaveSpace)[SRCPTR + CSAVE_OFFSET]
  505. = (int)((MCD_bufDesc *) srcAddrVirt)->srcAddr;
  506. ((volatile int *)MCD_taskTable[channel].
  507. contextSaveSpace)[DESTPTR + CSAVE_OFFSET]
  508. = (int)((MCD_bufDesc *) srcAddrVirt)->destAddr;
  509. #endif
  510. ((volatile int *)MCD_taskTable[channel].
  511. contextSaveSpace)[DCOUNT + CSAVE_OFFSET] = 0;
  512. ((volatile int *)MCD_taskTable[channel].
  513. contextSaveSpace)[CURRBD + CSAVE_OFFSET] = (u32) srcAddr;
  514. if (funcDesc == MCD_FUNC_NOEU1 || funcDesc == MCD_FUNC_NOEU2) {
  515. /*TDTStart and TDTEnd */
  516. MCD_taskTable[channel].TDTstart =
  517. MCD_modelTaskTable[TASK_CHAINNOEU].TDTstart;
  518. MCD_taskTable[channel].TDTend =
  519. MCD_modelTaskTable[TASK_CHAINNOEU].TDTend;
  520. MCD_startDmaChainNoEu((int *)srcAddr, srcIncr,
  521. destIncr, xferSize,
  522. xferSizeIncr, cSave,
  523. MCD_taskTable, channel);
  524. } else {
  525. /*TDTStart and TDTEnd */
  526. MCD_taskTable[channel].TDTstart =
  527. MCD_modelTaskTable[TASK_CHAINEU].TDTstart;
  528. MCD_taskTable[channel].TDTend =
  529. MCD_modelTaskTable[TASK_CHAINEU].TDTend;
  530. MCD_startDmaChainEu((int *)srcAddr, srcIncr, destIncr,
  531. xferSize, xferSizeIncr, cSave,
  532. MCD_taskTable, channel);
  533. }
  534. }
  535. MCD_chStatus[channel] = MCD_IDLE;
  536. return (MCD_OK);
  537. }
  538. /************************ End of MCD_startDma() *********************/
  539. /********************************************************************/
  540. /* Function: MCD_XferProgrQuery
  541. * Purpose: Returns progress of DMA on requested channel
  542. * Arguments: channel - channel to retrieve progress for
  543. * progRep - pointer to user supplied MCD_XferProg struct
  544. * Returns: MCD_CHANNEL_INVALID if channel is invalid, else MCD_OK
  545. *
  546. * Notes:
  547. * MCD_XferProgrQuery() upon completing or after aborting a DMA, or
  548. * while the DMA is in progress, this function returns the first
  549. * DMA-destination address not (or not yet) used in the DMA. When
  550. * encountering a non-ready buffer descriptor, the information for
  551. * the last completed descriptor is returned.
  552. *
  553. * MCD_XferProgQuery() has to avoid the possibility of getting
  554. * partially-updated information in the event that we should happen
  555. * to query DMA progress just as the DMA is updating it. It does that
  556. * by taking advantage of the fact context is not saved frequently for
  557. * the most part. We therefore read it at least twice until we get the
  558. * same information twice in a row.
  559. *
  560. * Because a small, but not insignificant, amount of time is required
  561. * to write out the progress-query information, especially upon
  562. * completion of the DMA, it would be wise to guarantee some time lag
  563. * between successive readings of the progress-query information.
  564. */
  565. /* How many iterations of the loop below to execute to stabilize values */
  566. #define STABTIME 0
  567. int MCD_XferProgrQuery(int channel, MCD_XferProg * progRep)
  568. {
  569. MCD_XferProg prevRep;
  570. int again; /* true if we are to try again to ge
  571. consistent results */
  572. int i; /* used as a time-waste counter */
  573. int destDiffBytes; /* Total no of bytes that we think actually
  574. got xfered. */
  575. int numIterations; /* number of iterations */
  576. int bytesNotXfered; /* bytes that did not get xfered. */
  577. s8 *LWAlignedInitDestAddr, *LWAlignedCurrDestAddr;
  578. int subModVal, addModVal; /* Mode values to added and subtracted
  579. from the final destAddr */
  580. if ((channel < 0) || (channel >= NCHANNELS))
  581. return (MCD_CHANNEL_INVALID);
  582. /* Read a trial value for the progress-reporting values */
  583. prevRep.lastSrcAddr =
  584. (s8 *) ((volatile int *)MCD_taskTable[channel].
  585. contextSaveSpace)[SRCPTR + CSAVE_OFFSET];
  586. prevRep.lastDestAddr =
  587. (s8 *) ((volatile int *)MCD_taskTable[channel].
  588. contextSaveSpace)[DESTPTR + CSAVE_OFFSET];
  589. prevRep.dmaSize =
  590. ((volatile int *)MCD_taskTable[channel].contextSaveSpace)[DCOUNT +
  591. CSAVE_OFFSET];
  592. prevRep.currBufDesc =
  593. (MCD_bufDesc *) ((volatile int *)MCD_taskTable[channel].
  594. contextSaveSpace)[CURRBD + CSAVE_OFFSET];
  595. /* Repeatedly reread those values until they match previous values: */
  596. do {
  597. /* Waste a little bit of time to ensure stability: */
  598. for (i = 0; i < STABTIME; i++) {
  599. /* make sure this loop does something so that it
  600. doesn't get optimized out */
  601. i += i >> 2;
  602. }
  603. /* Check them again: */
  604. progRep->lastSrcAddr =
  605. (s8 *) ((volatile int *)MCD_taskTable[channel].
  606. contextSaveSpace)[SRCPTR + CSAVE_OFFSET];
  607. progRep->lastDestAddr =
  608. (s8 *) ((volatile int *)MCD_taskTable[channel].
  609. contextSaveSpace)[DESTPTR + CSAVE_OFFSET];
  610. progRep->dmaSize =
  611. ((volatile int *)MCD_taskTable[channel].
  612. contextSaveSpace)[DCOUNT + CSAVE_OFFSET];
  613. progRep->currBufDesc =
  614. (MCD_bufDesc *) ((volatile int *)MCD_taskTable[channel].
  615. contextSaveSpace)[CURRBD + CSAVE_OFFSET];
  616. /* See if they match: */
  617. if (prevRep.lastSrcAddr != progRep->lastSrcAddr
  618. || prevRep.lastDestAddr != progRep->lastDestAddr
  619. || prevRep.dmaSize != progRep->dmaSize
  620. || prevRep.currBufDesc != progRep->currBufDesc) {
  621. /* If they don't match, remember previous values and
  622. try again: */
  623. prevRep.lastSrcAddr = progRep->lastSrcAddr;
  624. prevRep.lastDestAddr = progRep->lastDestAddr;
  625. prevRep.dmaSize = progRep->dmaSize;
  626. prevRep.currBufDesc = progRep->currBufDesc;
  627. again = MCD_TRUE;
  628. } else
  629. again = MCD_FALSE;
  630. } while (again == MCD_TRUE);
  631. /* Update the dCount, srcAddr and destAddr */
  632. /* To calculate dmaCount, we consider destination address. C
  633. overs M1,P1,Z for destination */
  634. switch (MCD_remVariants.remDestRsdIncr[channel]) {
  635. case MINUS1:
  636. subModVal =
  637. ((int)progRep->
  638. lastDestAddr) & ((MCD_remVariants.remXferSize[channel]) -
  639. 1);
  640. addModVal =
  641. ((int)progRep->currBufDesc->
  642. destAddr) & ((MCD_remVariants.remXferSize[channel]) - 1);
  643. LWAlignedInitDestAddr =
  644. (progRep->currBufDesc->destAddr) - addModVal;
  645. LWAlignedCurrDestAddr = (progRep->lastDestAddr) - subModVal;
  646. destDiffBytes = LWAlignedInitDestAddr - LWAlignedCurrDestAddr;
  647. bytesNotXfered =
  648. (destDiffBytes / MCD_remVariants.remDestIncr[channel]) *
  649. (MCD_remVariants.remDestIncr[channel]
  650. + MCD_remVariants.remXferSize[channel]);
  651. progRep->dmaSize =
  652. destDiffBytes - bytesNotXfered + addModVal - subModVal;
  653. break;
  654. case ZERO:
  655. progRep->lastDestAddr = progRep->currBufDesc->destAddr;
  656. break;
  657. case PLUS1:
  658. /* This value has to be subtracted from the final
  659. calculated dCount. */
  660. subModVal =
  661. ((int)progRep->currBufDesc->
  662. destAddr) & ((MCD_remVariants.remXferSize[channel]) - 1);
  663. /* These bytes are already in lastDestAddr. */
  664. addModVal =
  665. ((int)progRep->
  666. lastDestAddr) & ((MCD_remVariants.remXferSize[channel]) -
  667. 1);
  668. LWAlignedInitDestAddr =
  669. (progRep->currBufDesc->destAddr) - subModVal;
  670. LWAlignedCurrDestAddr = (progRep->lastDestAddr) - addModVal;
  671. destDiffBytes = (progRep->lastDestAddr - LWAlignedInitDestAddr);
  672. numIterations =
  673. (LWAlignedCurrDestAddr -
  674. LWAlignedInitDestAddr) /
  675. MCD_remVariants.remDestIncr[channel];
  676. bytesNotXfered =
  677. numIterations * (MCD_remVariants.remDestIncr[channel]
  678. - MCD_remVariants.remXferSize[channel]);
  679. progRep->dmaSize = destDiffBytes - bytesNotXfered - subModVal;
  680. break;
  681. default:
  682. break;
  683. }
  684. /* This covers M1,P1,Z for source */
  685. switch (MCD_remVariants.remSrcRsdIncr[channel]) {
  686. case MINUS1:
  687. progRep->lastSrcAddr =
  688. progRep->currBufDesc->srcAddr +
  689. (MCD_remVariants.remSrcIncr[channel] *
  690. (progRep->dmaSize / MCD_remVariants.remXferSize[channel]));
  691. break;
  692. case ZERO:
  693. progRep->lastSrcAddr = progRep->currBufDesc->srcAddr;
  694. break;
  695. case PLUS1:
  696. progRep->lastSrcAddr =
  697. progRep->currBufDesc->srcAddr +
  698. (MCD_remVariants.remSrcIncr[channel] *
  699. (progRep->dmaSize / MCD_remVariants.remXferSize[channel]));
  700. break;
  701. default:
  702. break;
  703. }
  704. return (MCD_OK);
  705. }
  706. /******************* End of MCD_XferProgrQuery() ********************/
  707. /********************************************************************/
  708. /* MCD_resmActions() does the majority of the actions of a DMA resume.
  709. * It is called from MCD_killDma() and MCD_resumeDma(). It has to be
  710. * a separate function because the kill function has to negate the task
  711. * enable before resuming it, but the resume function has to do nothing
  712. * if there is no DMA on that channel (i.e., if the enable bit is 0).
  713. */
  714. static void MCD_resmActions(int channel)
  715. {
  716. MCD_dmaBar->debugControl = DBG_CTL_DISABLE;
  717. MCD_dmaBar->debugStatus = MCD_dmaBar->debugStatus;
  718. /* This register is selected to know which initiator is
  719. actually asserted. */
  720. MCD_dmaBar->ptdDebug = PTD_DBG_TSK_VLD_INIT;
  721. if ((MCD_dmaBar->ptdDebug >> channel) & 0x1)
  722. MCD_chStatus[channel] = MCD_RUNNING;
  723. else
  724. MCD_chStatus[channel] = MCD_IDLE;
  725. }
  726. /********************* End of MCD_resmActions() *********************/
  727. /********************************************************************/
  728. /* Function: MCD_killDma
  729. * Purpose: Halt the DMA on the requested channel, without any
  730. * intention of resuming the DMA.
  731. * Arguments: channel - requested channel
  732. * Returns: MCD_CHANNEL_INVALID if channel is invalid, else MCD_OK
  733. *
  734. * Notes:
  735. * A DMA may be killed from any state, including paused state, and it
  736. * always goes to the MCD_HALTED state even if it is killed while in
  737. * the MCD_NO_DMA or MCD_IDLE states.
  738. */
  739. int MCD_killDma(int channel)
  740. {
  741. /* MCD_XferProg progRep; */
  742. if ((channel < 0) || (channel >= NCHANNELS))
  743. return (MCD_CHANNEL_INVALID);
  744. MCD_dmaBar->taskControl[channel] = 0x0;
  745. MCD_resumeDma(channel);
  746. /*
  747. * This must be after the write to the TCR so that the task doesn't
  748. * start up again momentarily, and before the status assignment so
  749. * as to override whatever MCD_resumeDma() may do to the channel
  750. * status.
  751. */
  752. MCD_chStatus[channel] = MCD_HALTED;
  753. /*
  754. * Update the current buffer descriptor's lastDestAddr field
  755. *
  756. * MCD_XferProgrQuery (channel, &progRep);
  757. * progRep.currBufDesc->lastDestAddr = progRep.lastDestAddr;
  758. */
  759. return (MCD_OK);
  760. }
  761. /************************ End of MCD_killDma() **********************/
  762. /********************************************************************/
  763. /* Function: MCD_continDma
  764. * Purpose: Continue a DMA which as stopped due to encountering an
  765. * unready buffer descriptor.
  766. * Arguments: channel - channel to continue the DMA on
  767. * Returns: MCD_CHANNEL_INVALID if channel is invalid, else MCD_OK
  768. *
  769. * Notes:
  770. * This routine does not check to see if there is a task which can
  771. * be continued. Also this routine should not be used with single DMAs.
  772. */
  773. int MCD_continDma(int channel)
  774. {
  775. if ((channel < 0) || (channel >= NCHANNELS))
  776. return (MCD_CHANNEL_INVALID);
  777. MCD_dmaBar->taskControl[channel] |= TASK_CTL_EN;
  778. MCD_chStatus[channel] = MCD_RUNNING;
  779. return (MCD_OK);
  780. }
  781. /********************** End of MCD_continDma() **********************/
  782. /*********************************************************************
  783. * MCD_pauseDma() and MCD_resumeDma() below use the DMA's debug unit
  784. * to freeze a task and resume it. We freeze a task by breakpointing
  785. * on the stated task. That is, not any specific place in the task,
  786. * but any time that task executes. In particular, when that task
  787. * executes, we want to freeze that task and only that task.
  788. *
  789. * The bits of the debug control register influence interrupts vs.
  790. * breakpoints as follows:
  791. * - Bits 14 and 0 enable or disable debug functions. If enabled, you
  792. * will get the interrupt but you may or may not get a breakpoint.
  793. * - Bits 2 and 1 decide whether you also get a breakpoint in addition
  794. * to an interrupt.
  795. *
  796. * The debug unit can do these actions in response to either internally
  797. * detected breakpoint conditions from the comparators, or in response
  798. * to the external breakpoint pin, or both.
  799. * - Bits 14 and 1 perform the above-described functions for
  800. * internally-generated conditions, i.e., the debug comparators.
  801. * - Bits 0 and 2 perform the above-described functions for external
  802. * conditions, i.e., the breakpoint external pin.
  803. *
  804. * Note that, although you "always" get the interrupt when you turn
  805. * the debug functions, the interrupt can nevertheless, if desired, be
  806. * masked by the corresponding bit in the PTD's IMR. Note also that
  807. * this means that bits 14 and 0 must enable debug functions before
  808. * bits 1 and 2, respectively, have any effect.
  809. *
  810. * NOTE: It's extremely important to not pause more than one DMA channel
  811. * at a time.
  812. ********************************************************************/
  813. /********************************************************************/
  814. /* Function: MCD_pauseDma
  815. * Purpose: Pauses the DMA on a given channel (if any DMA is running
  816. * on that channel).
  817. * Arguments: channel
  818. * Returns: MCD_CHANNEL_INVALID if channel is invalid, else MCD_OK
  819. */
  820. int MCD_pauseDma(int channel)
  821. {
  822. /* MCD_XferProg progRep; */
  823. if ((channel < 0) || (channel >= NCHANNELS))
  824. return (MCD_CHANNEL_INVALID);
  825. if (MCD_dmaBar->taskControl[channel] & TASK_CTL_EN) {
  826. MCD_dmaBar->debugComp1 = channel;
  827. MCD_dmaBar->debugControl =
  828. DBG_CTL_ENABLE | (1 << (channel + 16));
  829. MCD_chStatus[channel] = MCD_PAUSED;
  830. /*
  831. * Update the current buffer descriptor's lastDestAddr field
  832. *
  833. * MCD_XferProgrQuery (channel, &progRep);
  834. * progRep.currBufDesc->lastDestAddr = progRep.lastDestAddr;
  835. */
  836. }
  837. return (MCD_OK);
  838. }
  839. /************************* End of MCD_pauseDma() ********************/
  840. /********************************************************************/
  841. /* Function: MCD_resumeDma
  842. * Purpose: Resumes the DMA on a given channel (if any DMA is
  843. * running on that channel).
  844. * Arguments: channel - channel on which to resume DMA
  845. * Returns: MCD_CHANNEL_INVALID if channel is invalid, else MCD_OK
  846. */
  847. int MCD_resumeDma(int channel)
  848. {
  849. if ((channel < 0) || (channel >= NCHANNELS))
  850. return (MCD_CHANNEL_INVALID);
  851. if (MCD_dmaBar->taskControl[channel] & TASK_CTL_EN)
  852. MCD_resmActions(channel);
  853. return (MCD_OK);
  854. }
  855. /************************ End of MCD_resumeDma() ********************/
  856. /********************************************************************/
  857. /* Function: MCD_csumQuery
  858. * Purpose: Provide the checksum after performing a non-chained DMA
  859. * Arguments: channel - channel to report on
  860. * csum - pointer to where to write the checksum/CRC
  861. * Returns: MCD_ERROR if the channel is invalid, else MCD_OK
  862. *
  863. * Notes:
  864. *
  865. */
  866. int MCD_csumQuery(int channel, u32 * csum)
  867. {
  868. #ifdef MCD_INCLUDE_EU
  869. if ((channel < 0) || (channel >= NCHANNELS))
  870. return (MCD_CHANNEL_INVALID);
  871. *csum = MCD_relocBuffDesc[channel].csumResult;
  872. return (MCD_OK);
  873. #else
  874. return (MCD_ERROR);
  875. #endif
  876. }
  877. /*********************** End of MCD_resumeDma() *********************/
  878. /********************************************************************/
  879. /* Function: MCD_getCodeSize
  880. * Purpose: Provide the size requirements of the microcoded tasks
  881. * Returns: Size in bytes
  882. */
  883. int MCD_getCodeSize(void)
  884. {
  885. #ifdef MCD_INCLUDE_EU
  886. return (0x2b5c);
  887. #else
  888. return (0x173c);
  889. #endif
  890. }
  891. /********************** End of MCD_getCodeSize() ********************/
  892. /********************************************************************/
  893. /* Function: MCD_getVersion
  894. * Purpose: Provide the version string and number
  895. * Arguments: longVersion - user supplied pointer to a pointer to a char
  896. * which points to the version string
  897. * Returns: Version number and version string (by reference)
  898. */
  899. char MCD_versionString[] = "Multi-channel DMA API Alpha v0.3 (2004-04-26)";
  900. #define MCD_REV_MAJOR 0x00
  901. #define MCD_REV_MINOR 0x03
  902. int MCD_getVersion(char **longVersion)
  903. {
  904. *longVersion = MCD_versionString;
  905. return ((MCD_REV_MAJOR << 8) | MCD_REV_MINOR);
  906. }
  907. /********************** End of MCD_getVersion() *********************/
  908. /********************************************************************/
  909. /* Private version of memcpy()
  910. * Note that everything this is used for is longword-aligned.
  911. */
  912. static void MCD_memcpy(int *dest, int *src, u32 size)
  913. {
  914. u32 i;
  915. for (i = 0; i < size; i += sizeof(int), dest++, src++)
  916. *dest = *src;
  917. }
  918. #endif /* CONFIG_FSLDMAFEC */