1
2
3
4
5
6
7
8
9#include <common.h>
10
11#include <MCD_dma.h>
12#include <MCD_tasksInit.h>
13#include <MCD_progCheck.h>
14
15
16
17dmaRegs *MCD_dmaBar;
18
19
20
21
22
23extern TaskTableEntry MCD_realTaskTableSrc[NCHANNELS];
24extern TaskTableEntry MCD_modelTaskTableSrc[NUMOFVARIANTS];
25
26
27
28
29
30volatile TaskTableEntry *MCD_taskTable;
31TaskTableEntry *MCD_modelTaskTable;
32
33
34
35
36
37
38static int MCD_chStatus[NCHANNELS] = {
39 MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA,
40 MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA,
41 MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA,
42 MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA, MCD_NO_DMA
43};
44
45
46static void MCD_memcpy(int *dest, int *src, u32 size);
47static void MCD_resmActions(int channel);
48
49
50
51
52
53
54#ifdef MCD_INCLUDE_EU
55extern MCD_bufDesc MCD_singleBufDescs[NCHANNELS];
56#else
57MCD_bufDesc MCD_singleBufDescs[NCHANNELS];
58#endif
59MCD_bufDesc *MCD_relocBuffDesc;
60
61
62#define DBG_CTL_COMP1_TASK (0x00002000)
63#define DBG_CTL_ENABLE (DBG_CTL_AUTO_ARM | \
64 DBG_CTL_BREAK | \
65 DBG_CTL_INT_BREAK | \
66 DBG_CTL_COMP1_TASK)
67#define DBG_CTL_DISABLE (DBG_CTL_AUTO_ARM | \
68 DBG_CTL_INT_BREAK | \
69 DBG_CTL_COMP1_TASK)
70#define DBG_KILL_ALL_STAT (0xFFFFFFFF)
71
72
73#define CSAVE_OFFSET 10
74
75
76#define MCD_BYTE_SWAP_KILLER 0xFFF8888F
77#define MCD_NO_BYTE_SWAP_ATALL 0x00040000
78
79
80#define MAC 0
81#define LUAC 1
82#define CRC 2
83#define LURC 3
84
85
86#define TASK_CHAINNOEU 0
87#define TASK_SINGLENOEU 1
88#ifdef MCD_INCLUDE_EU
89#define TASK_CHAINEU 2
90#define TASK_SINGLEEU 3
91#define TASK_FECRX 4
92#define TASK_FECTX 5
93#else
94#define TASK_CHAINEU 0
95#define TASK_SINGLEEU 1
96#define TASK_FECRX 2
97#define TASK_FECTX 3
98#endif
99
100
101
102
103
104typedef struct MCD_remVariants_struct MCD_remVariant;
105struct MCD_remVariants_struct {
106 int remDestRsdIncr[NCHANNELS];
107 int remSrcRsdIncr[NCHANNELS];
108 s16 remDestIncr[NCHANNELS];
109 s16 remSrcIncr[NCHANNELS];
110 u32 remXferSize[NCHANNELS];
111};
112
113
114MCD_remVariant MCD_remVariants;
115
116
117
118
119
120
121
122
123
124
125
126
127
128extern u32 MCD_funcDescTab0[];
129
130int MCD_initDma(dmaRegs * dmaBarAddr, void *taskTableDest, u32 flags)
131{
132 int i;
133 TaskTableEntry *entryPtr;
134
135
136 MCD_dmaBar = dmaBarAddr;
137
138
139 if ((flags & MCD_RELOC_TASKS) != 0) {
140 int fixedSize;
141 u32 *fixedPtr;
142
143 int varTabsOffset, funcDescTabsOffset, contextSavesOffset;
144 int taskDescTabsOffset;
145 int taskTableSize, varTabsSize, funcDescTabsSize,
146 contextSavesSize;
147 int taskDescTabSize;
148
149 int i;
150
151
152 if (((u32) taskTableDest & 0x000001ff) != 0)
153 return (MCD_TABLE_UNALIGNED);
154
155
156 MCD_taskTable = taskTableDest;
157
158
159
160
161
162
163
164
165
166
167 taskTableSize = NCHANNELS * sizeof(TaskTableEntry);
168
169 varTabsOffset = taskTableSize + (u32) taskTableDest;
170 if ((varTabsOffset & (VAR_TAB_SIZE - 1)) != 0)
171 varTabsOffset =
172 (varTabsOffset + VAR_TAB_SIZE) & (~VAR_TAB_SIZE);
173
174 varTabsSize = NCHANNELS * VAR_TAB_SIZE;
175 funcDescTabsOffset = varTabsOffset + varTabsSize;
176
177 if ((funcDescTabsOffset & (FUNCDESC_TAB_SIZE - 1)) != 0)
178 funcDescTabsOffset =
179 (funcDescTabsOffset +
180 FUNCDESC_TAB_SIZE) & (~FUNCDESC_TAB_SIZE);
181
182 funcDescTabsSize = FUNCDESC_TAB_NUM * FUNCDESC_TAB_SIZE;
183 contextSavesOffset = funcDescTabsOffset + funcDescTabsSize;
184 contextSavesSize = (NCHANNELS * CONTEXT_SAVE_SIZE);
185 fixedSize =
186 taskTableSize + varTabsSize + funcDescTabsSize +
187 contextSavesSize;
188
189
190 fixedPtr = (u32 *) taskTableDest;
191 for (i = 0; i < (fixedSize / 4); i++)
192 fixedPtr[i] = 0;
193
194 entryPtr = (TaskTableEntry *) MCD_taskTable;
195
196 for (i = 0; i < NCHANNELS; i++) {
197
198 entryPtr[i].varTab = (u32) varTabsOffset;
199 entryPtr[i].FDTandFlags =
200 (u32) funcDescTabsOffset | MCD_TT_FLAGS_DEF;
201 entryPtr[i].contextSaveSpace = (u32) contextSavesOffset;
202 varTabsOffset += VAR_TAB_SIZE;
203#ifdef MCD_INCLUDE_EU
204
205
206 funcDescTabsOffset += FUNCDESC_TAB_SIZE;
207#endif
208 contextSavesOffset += CONTEXT_SAVE_SIZE;
209 }
210
211 for (i = 0; i < FUNCDESC_TAB_NUM; i++) {
212 MCD_memcpy((void *)(entryPtr[i].
213 FDTandFlags & ~MCD_TT_FLAGS_MASK),
214 (void *)MCD_funcDescTab0, FUNCDESC_TAB_SIZE);
215 }
216
217
218
219 MCD_modelTaskTable = (TaskTableEntry *) contextSavesOffset;
220
221 MCD_memcpy((void *)MCD_modelTaskTable,
222 (void *)MCD_modelTaskTableSrc,
223 NUMOFVARIANTS * sizeof(TaskTableEntry));
224
225
226 entryPtr = MCD_modelTaskTable;
227 taskDescTabsOffset = (u32) MCD_modelTaskTable +
228 (NUMOFVARIANTS * sizeof(TaskTableEntry));
229
230
231
232 for (i = 0; i < NUMOFVARIANTS; i++) {
233 taskDescTabSize =
234 entryPtr[i].TDTend - entryPtr[i].TDTstart + 4;
235 MCD_memcpy((void *)taskDescTabsOffset,
236 (void *)entryPtr[i].TDTstart,
237 taskDescTabSize);
238 entryPtr[i].TDTstart = (u32) taskDescTabsOffset;
239 taskDescTabsOffset += taskDescTabSize;
240 entryPtr[i].TDTend = (u32) taskDescTabsOffset - 4;
241 }
242#ifdef MCD_INCLUDE_EU
243
244
245 MCD_relocBuffDesc =
246 (MCD_bufDesc *) (entryPtr[NUMOFVARIANTS - 1].TDTend + 4);
247#else
248
249
250 MCD_relocBuffDesc = MCD_singleBufDescs;
251#endif
252 } else {
253
254
255
256 if (((u32) MCD_realTaskTableSrc & 0x000001ff) != 0)
257 return (MCD_TABLE_UNALIGNED);
258
259
260
261
262
263 entryPtr = MCD_realTaskTableSrc;
264 for (i = 0; i < NCHANNELS; i++) {
265 if (((entryPtr[i].varTab & (VAR_TAB_SIZE - 1)) != 0) ||
266 ((entryPtr[i].
267 FDTandFlags & (FUNCDESC_TAB_SIZE - 1)) != 0))
268 return (MCD_TABLE_UNALIGNED);
269 }
270
271 MCD_taskTable = MCD_realTaskTableSrc;
272 MCD_modelTaskTable = MCD_modelTaskTableSrc;
273 MCD_relocBuffDesc = MCD_singleBufDescs;
274 }
275
276
277
278 MCD_dmaBar->taskbar = (u32) MCD_taskTable;
279 for (i = 0; i < NCHANNELS; i++) {
280 MCD_dmaBar->taskControl[i] = 0x0;
281 MCD_chStatus[i] = MCD_NO_DMA;
282 }
283
284
285
286 MCD_dmaBar->debugComp1 = 0;
287 MCD_dmaBar->debugComp2 = 0;
288 MCD_dmaBar->debugControl = DBG_CTL_DISABLE;
289 MCD_dmaBar->debugStatus = DBG_KILL_ALL_STAT;
290
291
292
293 if ((flags & MCD_COMM_PREFETCH_EN) != 0)
294 MCD_dmaBar->ptdControl &= ~PTD_CTL_COMM_PREFETCH;
295 else
296 MCD_dmaBar->ptdControl |= PTD_CTL_COMM_PREFETCH;
297
298 return (MCD_OK);
299}
300
301
302
303
304
305
306
307
308
309int MCD_dmaStatus(int channel)
310{
311 u16 tcrValue;
312
313 if ((channel < 0) || (channel >= NCHANNELS))
314 return (MCD_CHANNEL_INVALID);
315
316 tcrValue = MCD_dmaBar->taskControl[channel];
317 if ((tcrValue & TASK_CTL_EN) == 0) {
318
319 if (MCD_chStatus[channel] == MCD_RUNNING
320 || MCD_chStatus[channel] == MCD_IDLE)
321 MCD_chStatus[channel] = MCD_DONE;
322 } else {
323
324
325 if (MCD_chStatus[channel] == MCD_RUNNING
326 || MCD_chStatus[channel] == MCD_IDLE) {
327 MCD_dmaBar->ptdDebug = PTD_DBG_TSK_VLD_INIT;
328
329
330 if ((MCD_dmaBar->ptdDebug >> channel) & 0x1)
331 MCD_chStatus[channel] = MCD_RUNNING;
332 else
333 MCD_chStatus[channel] = MCD_IDLE;
334
335 }
336 }
337 return MCD_chStatus[channel];
338}
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360int MCD_startDma(int channel, s8 * srcAddr, s16 srcIncr, s8 * destAddr,
361 s16 destIncr, u32 dmaSize, u32 xferSize, u32 initiator,
362 int priority, u32 flags, u32 funcDesc
363#ifdef MCD_NEED_ADDR_TRANS
364 s8 * srcAddrVirt
365#endif
366 )
367{
368 int srcRsdIncr, destRsdIncr;
369 int *cSave;
370 short xferSizeIncr;
371 int tcrCount = 0;
372#ifdef MCD_INCLUDE_EU
373 u32 *realFuncArray;
374#endif
375
376 if ((channel < 0) || (channel >= NCHANNELS))
377 return (MCD_CHANNEL_INVALID);
378
379
380
381
382#ifndef MCD_INCLUDE_EU
383 funcDesc = MCD_FUNC_NOEU1;
384#endif
385
386#ifdef MCD_DEBUG
387 printf("startDma:Setting up params\n");
388#endif
389
390
391
392
393
394
395 MCD_dmaBar->ptdControl |= (u16) 0x8000;
396
397
398#if 1
399
400 srcRsdIncr = srcIncr < 0 ? -1 : (srcIncr > 0 ? 1 : 0);
401 destRsdIncr = destIncr < 0 ? -1 : (destIncr > 0 ? 1 : 0);
402
403 xferSizeIncr = (xferSize & 0xffff) | 0x20000000;
404
405
406 MCD_remVariants.remSrcRsdIncr[channel] = srcRsdIncr;
407 MCD_remVariants.remDestRsdIncr[channel] = destRsdIncr;
408 MCD_remVariants.remDestIncr[channel] = destIncr;
409 MCD_remVariants.remSrcIncr[channel] = srcIncr;
410 MCD_remVariants.remXferSize[channel] = xferSize;
411#endif
412
413 cSave =
414 (int *)(MCD_taskTable[channel].contextSaveSpace) + CSAVE_OFFSET +
415 CURRBD;
416
417#ifdef MCD_INCLUDE_EU
418
419 realFuncArray =
420 (u32 *) (MCD_taskTable[channel].FDTandFlags & 0xffffff00);
421
422
423 realFuncArray[(LURC * 16)] = xferSize == 4 ?
424 funcDesc : xferSize == 2 ?
425 funcDesc & 0xfffff00f : funcDesc & 0xffff000f;
426 realFuncArray[(LURC * 16 + 1)] =
427 (funcDesc & MCD_BYTE_SWAP_KILLER) | MCD_NO_BYTE_SWAP_ATALL;
428#endif
429
430
431
432
433
434 MCD_dmaBar->taskControl[channel] =
435 (initiator << 8) | TASK_CTL_HIPRITSKEN | TASK_CTL_HLDINITNUM;
436
437 while (((MCD_dmaBar->taskControl[channel] & 0x1fff) !=
438 ((initiator << 8) | TASK_CTL_HIPRITSKEN | TASK_CTL_HLDINITNUM))
439 && (tcrCount < 1000)) {
440 tcrCount++;
441
442 MCD_dmaBar->taskControl[channel] =
443 (initiator << 8) | TASK_CTL_HIPRITSKEN |
444 TASK_CTL_HLDINITNUM;
445 }
446
447 MCD_dmaBar->priority[channel] = (u8) priority & PRIORITY_PRI_MASK;
448
449
450 if (channel < 8 && channel >= 0) {
451 MCD_dmaBar->taskSize0 &= ~(0xf << (7 - channel) * 4);
452 MCD_dmaBar->taskSize0 |=
453 (xferSize & 3) << (((7 - channel) * 4) + 2);
454 MCD_dmaBar->taskSize0 |= (xferSize & 3) << ((7 - channel) * 4);
455 } else {
456 MCD_dmaBar->taskSize1 &= ~(0xf << (15 - channel) * 4);
457 MCD_dmaBar->taskSize1 |=
458 (xferSize & 3) << (((15 - channel) * 4) + 2);
459 MCD_dmaBar->taskSize1 |= (xferSize & 3) << ((15 - channel) * 4);
460 }
461
462
463
464 MCD_taskTable[channel].FDTandFlags &= ~MCD_TT_FLAGS_MASK;
465 MCD_taskTable[channel].FDTandFlags |= (MCD_TT_FLAGS_MASK & flags);
466
467 if (flags & MCD_FECTX_DMA) {
468
469 MCD_taskTable[channel].TDTstart =
470 MCD_modelTaskTable[TASK_FECTX].TDTstart;
471 MCD_taskTable[channel].TDTend =
472 MCD_modelTaskTable[TASK_FECTX].TDTend;
473 MCD_startDmaENetXmit((char *)srcAddr, (char *)srcAddr,
474 (char *)destAddr, MCD_taskTable,
475 channel);
476 } else if (flags & MCD_FECRX_DMA) {
477
478 MCD_taskTable[channel].TDTstart =
479 MCD_modelTaskTable[TASK_FECRX].TDTstart;
480 MCD_taskTable[channel].TDTend =
481 MCD_modelTaskTable[TASK_FECRX].TDTend;
482 MCD_startDmaENetRcv((char *)srcAddr, (char *)srcAddr,
483 (char *)destAddr, MCD_taskTable,
484 channel);
485 } else if (flags & MCD_SINGLE_DMA) {
486
487
488
489
490
491 MCD_relocBuffDesc[channel].srcAddr = srcAddr;
492 MCD_relocBuffDesc[channel].destAddr = destAddr;
493
494
495 MCD_relocBuffDesc[channel].lastDestAddr = destAddr;
496
497 MCD_relocBuffDesc[channel].dmaSize = dmaSize;
498 MCD_relocBuffDesc[channel].flags = 0;
499 MCD_relocBuffDesc[channel].csumResult = 0;
500 MCD_relocBuffDesc[channel].next = 0;
501
502
503
504 ((volatile int *)MCD_taskTable[channel].
505 contextSaveSpace)[SRCPTR + CSAVE_OFFSET] = (int)srcAddr;
506 ((volatile int *)MCD_taskTable[channel].
507 contextSaveSpace)[DESTPTR + CSAVE_OFFSET] = (int)destAddr;
508 ((volatile int *)MCD_taskTable[channel].
509 contextSaveSpace)[DCOUNT + CSAVE_OFFSET] = 0;
510 ((volatile int *)MCD_taskTable[channel].
511 contextSaveSpace)[CURRBD + CSAVE_OFFSET] =
512(u32) & (MCD_relocBuffDesc[channel]);
513
514
515 if (funcDesc == MCD_FUNC_NOEU1 || funcDesc == MCD_FUNC_NOEU2) {
516
517 MCD_taskTable[channel].TDTstart =
518 MCD_modelTaskTable[TASK_SINGLENOEU].TDTstart;
519 MCD_taskTable[channel].TDTend =
520 MCD_modelTaskTable[TASK_SINGLENOEU].TDTend;
521 MCD_startDmaSingleNoEu((char *)srcAddr, srcIncr,
522 (char *)destAddr, destIncr,
523 (int)dmaSize, xferSizeIncr,
524 flags, (int *)
525 &(MCD_relocBuffDesc[channel]),
526 cSave, MCD_taskTable, channel);
527 } else {
528
529 MCD_taskTable[channel].TDTstart =
530 MCD_modelTaskTable[TASK_SINGLEEU].TDTstart;
531 MCD_taskTable[channel].TDTend =
532 MCD_modelTaskTable[TASK_SINGLEEU].TDTend;
533 MCD_startDmaSingleEu((char *)srcAddr, srcIncr,
534 (char *)destAddr, destIncr,
535 (int)dmaSize, xferSizeIncr,
536 flags, (int *)
537 &(MCD_relocBuffDesc[channel]),
538 cSave, MCD_taskTable, channel);
539 }
540 } else {
541
542
543#if 1
544
545 ((volatile int *)MCD_taskTable[channel].
546 contextSaveSpace)[SRCPTR + CSAVE_OFFSET]
547 = (int)((MCD_bufDesc *) srcAddr)->srcAddr;
548 ((volatile int *)MCD_taskTable[channel].
549 contextSaveSpace)[DESTPTR + CSAVE_OFFSET]
550 = (int)((MCD_bufDesc *) srcAddr)->destAddr;
551#else
552
553
554 ((volatile int *)MCD_taskTable[channel].
555 contextSaveSpace)[SRCPTR + CSAVE_OFFSET]
556 = (int)((MCD_bufDesc *) srcAddrVirt)->srcAddr;
557 ((volatile int *)MCD_taskTable[channel].
558 contextSaveSpace)[DESTPTR + CSAVE_OFFSET]
559 = (int)((MCD_bufDesc *) srcAddrVirt)->destAddr;
560#endif
561 ((volatile int *)MCD_taskTable[channel].
562 contextSaveSpace)[DCOUNT + CSAVE_OFFSET] = 0;
563 ((volatile int *)MCD_taskTable[channel].
564 contextSaveSpace)[CURRBD + CSAVE_OFFSET] = (u32) srcAddr;
565
566 if (funcDesc == MCD_FUNC_NOEU1 || funcDesc == MCD_FUNC_NOEU2) {
567
568 MCD_taskTable[channel].TDTstart =
569 MCD_modelTaskTable[TASK_CHAINNOEU].TDTstart;
570 MCD_taskTable[channel].TDTend =
571 MCD_modelTaskTable[TASK_CHAINNOEU].TDTend;
572 MCD_startDmaChainNoEu((int *)srcAddr, srcIncr,
573 destIncr, xferSize,
574 xferSizeIncr, cSave,
575 MCD_taskTable, channel);
576 } else {
577
578 MCD_taskTable[channel].TDTstart =
579 MCD_modelTaskTable[TASK_CHAINEU].TDTstart;
580 MCD_taskTable[channel].TDTend =
581 MCD_modelTaskTable[TASK_CHAINEU].TDTend;
582 MCD_startDmaChainEu((int *)srcAddr, srcIncr, destIncr,
583 xferSize, xferSizeIncr, cSave,
584 MCD_taskTable, channel);
585 }
586 }
587 MCD_chStatus[channel] = MCD_IDLE;
588 return (MCD_OK);
589}
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621#define STABTIME 0
622
623int MCD_XferProgrQuery(int channel, MCD_XferProg * progRep)
624{
625 MCD_XferProg prevRep;
626 int again;
627
628 int i;
629 int destDiffBytes;
630
631 int numIterations;
632 int bytesNotXfered;
633 s8 *LWAlignedInitDestAddr, *LWAlignedCurrDestAddr;
634 int subModVal, addModVal;
635
636
637 if ((channel < 0) || (channel >= NCHANNELS))
638 return (MCD_CHANNEL_INVALID);
639
640
641 prevRep.lastSrcAddr =
642 (s8 *) ((volatile int *)MCD_taskTable[channel].
643 contextSaveSpace)[SRCPTR + CSAVE_OFFSET];
644 prevRep.lastDestAddr =
645 (s8 *) ((volatile int *)MCD_taskTable[channel].
646 contextSaveSpace)[DESTPTR + CSAVE_OFFSET];
647 prevRep.dmaSize =
648 ((volatile int *)MCD_taskTable[channel].contextSaveSpace)[DCOUNT +
649 CSAVE_OFFSET];
650 prevRep.currBufDesc =
651 (MCD_bufDesc *) ((volatile int *)MCD_taskTable[channel].
652 contextSaveSpace)[CURRBD + CSAVE_OFFSET];
653
654 do {
655
656 for (i = 0; i < STABTIME; i++) {
657
658
659 i += i >> 2;
660 }
661
662 progRep->lastSrcAddr =
663 (s8 *) ((volatile int *)MCD_taskTable[channel].
664 contextSaveSpace)[SRCPTR + CSAVE_OFFSET];
665 progRep->lastDestAddr =
666 (s8 *) ((volatile int *)MCD_taskTable[channel].
667 contextSaveSpace)[DESTPTR + CSAVE_OFFSET];
668 progRep->dmaSize =
669 ((volatile int *)MCD_taskTable[channel].
670 contextSaveSpace)[DCOUNT + CSAVE_OFFSET];
671 progRep->currBufDesc =
672 (MCD_bufDesc *) ((volatile int *)MCD_taskTable[channel].
673 contextSaveSpace)[CURRBD + CSAVE_OFFSET];
674
675 if (prevRep.lastSrcAddr != progRep->lastSrcAddr
676 || prevRep.lastDestAddr != progRep->lastDestAddr
677 || prevRep.dmaSize != progRep->dmaSize
678 || prevRep.currBufDesc != progRep->currBufDesc) {
679
680
681 prevRep.lastSrcAddr = progRep->lastSrcAddr;
682 prevRep.lastDestAddr = progRep->lastDestAddr;
683 prevRep.dmaSize = progRep->dmaSize;
684 prevRep.currBufDesc = progRep->currBufDesc;
685 again = MCD_TRUE;
686 } else
687 again = MCD_FALSE;
688 } while (again == MCD_TRUE);
689
690
691
692
693 switch (MCD_remVariants.remDestRsdIncr[channel]) {
694 case MINUS1:
695 subModVal =
696 ((int)progRep->
697 lastDestAddr) & ((MCD_remVariants.remXferSize[channel]) -
698 1);
699 addModVal =
700 ((int)progRep->currBufDesc->
701 destAddr) & ((MCD_remVariants.remXferSize[channel]) - 1);
702 LWAlignedInitDestAddr =
703 (progRep->currBufDesc->destAddr) - addModVal;
704 LWAlignedCurrDestAddr = (progRep->lastDestAddr) - subModVal;
705 destDiffBytes = LWAlignedInitDestAddr - LWAlignedCurrDestAddr;
706 bytesNotXfered =
707 (destDiffBytes / MCD_remVariants.remDestIncr[channel]) *
708 (MCD_remVariants.remDestIncr[channel]
709 + MCD_remVariants.remXferSize[channel]);
710 progRep->dmaSize =
711 destDiffBytes - bytesNotXfered + addModVal - subModVal;
712 break;
713 case ZERO:
714 progRep->lastDestAddr = progRep->currBufDesc->destAddr;
715 break;
716 case PLUS1:
717
718
719 subModVal =
720 ((int)progRep->currBufDesc->
721 destAddr) & ((MCD_remVariants.remXferSize[channel]) - 1);
722
723 addModVal =
724 ((int)progRep->
725 lastDestAddr) & ((MCD_remVariants.remXferSize[channel]) -
726 1);
727 LWAlignedInitDestAddr =
728 (progRep->currBufDesc->destAddr) - subModVal;
729 LWAlignedCurrDestAddr = (progRep->lastDestAddr) - addModVal;
730 destDiffBytes = (progRep->lastDestAddr - LWAlignedInitDestAddr);
731 numIterations =
732 (LWAlignedCurrDestAddr -
733 LWAlignedInitDestAddr) /
734 MCD_remVariants.remDestIncr[channel];
735 bytesNotXfered =
736 numIterations * (MCD_remVariants.remDestIncr[channel]
737 - MCD_remVariants.remXferSize[channel]);
738 progRep->dmaSize = destDiffBytes - bytesNotXfered - subModVal;
739 break;
740 default:
741 break;
742 }
743
744
745 switch (MCD_remVariants.remSrcRsdIncr[channel]) {
746 case MINUS1:
747 progRep->lastSrcAddr =
748 progRep->currBufDesc->srcAddr +
749 (MCD_remVariants.remSrcIncr[channel] *
750 (progRep->dmaSize / MCD_remVariants.remXferSize[channel]));
751 break;
752 case ZERO:
753 progRep->lastSrcAddr = progRep->currBufDesc->srcAddr;
754 break;
755 case PLUS1:
756 progRep->lastSrcAddr =
757 progRep->currBufDesc->srcAddr +
758 (MCD_remVariants.remSrcIncr[channel] *
759 (progRep->dmaSize / MCD_remVariants.remXferSize[channel]));
760 break;
761 default:
762 break;
763 }
764
765 return (MCD_OK);
766}
767
768
769
770
771
772
773
774
775
776
777static void MCD_resmActions(int channel)
778{
779 MCD_dmaBar->debugControl = DBG_CTL_DISABLE;
780 MCD_dmaBar->debugStatus = MCD_dmaBar->debugStatus;
781
782
783 MCD_dmaBar->ptdDebug = PTD_DBG_TSK_VLD_INIT;
784
785 if ((MCD_dmaBar->ptdDebug >> channel) & 0x1)
786 MCD_chStatus[channel] = MCD_RUNNING;
787 else
788 MCD_chStatus[channel] = MCD_IDLE;
789}
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805int MCD_killDma(int channel)
806{
807
808
809 if ((channel < 0) || (channel >= NCHANNELS))
810 return (MCD_CHANNEL_INVALID);
811
812 MCD_dmaBar->taskControl[channel] = 0x0;
813 MCD_resumeDma(channel);
814
815
816
817
818
819
820 MCD_chStatus[channel] = MCD_HALTED;
821
822
823
824
825
826
827
828 return (MCD_OK);
829}
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844int MCD_continDma(int channel)
845{
846 if ((channel < 0) || (channel >= NCHANNELS))
847 return (MCD_CHANNEL_INVALID);
848
849 MCD_dmaBar->taskControl[channel] |= TASK_CTL_EN;
850 MCD_chStatus[channel] = MCD_RUNNING;
851
852 return (MCD_OK);
853}
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896int MCD_pauseDma(int channel)
897{
898
899
900 if ((channel < 0) || (channel >= NCHANNELS))
901 return (MCD_CHANNEL_INVALID);
902
903 if (MCD_dmaBar->taskControl[channel] & TASK_CTL_EN) {
904 MCD_dmaBar->debugComp1 = channel;
905 MCD_dmaBar->debugControl =
906 DBG_CTL_ENABLE | (1 << (channel + 16));
907 MCD_chStatus[channel] = MCD_PAUSED;
908
909
910
911
912
913
914
915 }
916 return (MCD_OK);
917}
918
919
920
921
922
923
924
925
926
927
928int MCD_resumeDma(int channel)
929{
930 if ((channel < 0) || (channel >= NCHANNELS))
931 return (MCD_CHANNEL_INVALID);
932
933 if (MCD_dmaBar->taskControl[channel] & TASK_CTL_EN)
934 MCD_resmActions(channel);
935
936 return (MCD_OK);
937}
938
939
940
941
942
943
944
945
946
947
948
949
950
951int MCD_csumQuery(int channel, u32 * csum)
952{
953#ifdef MCD_INCLUDE_EU
954 if ((channel < 0) || (channel >= NCHANNELS))
955 return (MCD_CHANNEL_INVALID);
956
957 *csum = MCD_relocBuffDesc[channel].csumResult;
958 return (MCD_OK);
959#else
960 return (MCD_ERROR);
961#endif
962}
963
964
965
966
967
968
969
970
971int MCD_getCodeSize(void)
972{
973#ifdef MCD_INCLUDE_EU
974 return (0x2b5c);
975#else
976 return (0x173c);
977#endif
978}
979
980
981
982
983
984
985
986
987
988
989char MCD_versionString[] = "Multi-channel DMA API Alpha v0.3 (2004-04-26)";
990#define MCD_REV_MAJOR 0x00
991#define MCD_REV_MINOR 0x03
992
993int MCD_getVersion(char **longVersion)
994{
995 *longVersion = MCD_versionString;
996 return ((MCD_REV_MAJOR << 8) | MCD_REV_MINOR);
997}
998
999
1000
1001
1002
1003
1004
1005static void MCD_memcpy(int *dest, int *src, u32 size)
1006{
1007 u32 i;
1008
1009 for (i = 0; i < size; i += sizeof(int), dest++, src++)
1010 *dest = *src;
1011}
1012