]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/pdk.git/blob - packages/ti/drv/udma/dmautils/src/dmautils_autoincrement_3d.c
udma-lld: add to PDK
[processor-sdk/pdk.git] / packages / ti / drv / udma / dmautils / src / dmautils_autoincrement_3d.c
1 /*
2  *  Copyright (c) Texas Instruments Incorporated 2018
3  *
4  *  Redistribution and use in source and binary forms, with or without
5  *  modification, are permitted provided that the following conditions
6  *  are met:
7  *
8  *    Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *
11  *    Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the
14  *    distribution.
15  *
16  *    Neither the name of Texas Instruments Incorporated nor the names of
17  *    its contributors may be used to endorse or promote products derived
18  *    from this software without specific prior written permission.
19  *
20  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
34 /*
35  *******************************************************************************
36  *
37  *  DMA utility functions
38  *
39  *******************************************************************************
40 */
42 /**
43  *****************************************************************************
44  * \file  dmautils_autoincrement_3d.c
45  *
46  * \brief*  This file contains function implementation for dma util functions for
47  *  configuring DMA on J7 device for autoincrement 3D usecase.
48  *
49  *
50  *****************************************************************************
51  */
53 /* ========================================================================== */
54 /*                             Include Files                                  */
55 /* ========================================================================== */
56 #include <string.h>
57 #include <math.h>
58 #include <stdint.h>
60 #include "ti/drv/udma/udma.h"
61 #include "ti/drv/udma/dmautils/src/dmautils_autoincrement_3d_priv.h"
62 #include "ti/drv/udma/dmautils/include/dmautils_autoincrement_3d.h"
64 #if defined (HOST_EMULATION)
65   #if defined (__C7100__)
66     #include <c7x_host_emulation.h>
67   #endif
68 #else
69   #if defined (__C7100__)
70     #include <c7x.h>
71   #endif
72 #endif
75 /* If its a Loki Build then force the mode to be in hostemulation as Loki doesnt support DRU */
76 #if defined (LOKI_BUILD)
77 #define HOST_EMULATION (1U)
78 #endif
80 #define DMAUTILS_ALIGN_CEIL(VAL, ALIGN) ((((VAL) + (ALIGN) - 1)/(ALIGN)) * (ALIGN) )
83 #ifdef HOST_EMULATION
84 #include "stdlib.h"
86 void hostEmulation_updateTriggerCount(struct Udma_DrvObj * udmaDrvHandle,
87                                                                               volatile uint64_t *pSwTrigReg)
88 {
89   uint32_t i;
90   CSL_DRU_t *druRegs = udmaDrvHandle->utcInfo[0].druRegs;
91   uintptr_t origPtr = (uintptr_t)pSwTrigReg;
92   uintptr_t currPtr;
94   for ( i = 0; i < udmaDrvHandle->utcInfo[0].numCh; i++)
95   {
96     currPtr = (uintptr_t)&druRegs->CHRT[i].CHRT_SWTRIG;
97     if ( currPtr == origPtr)
98     {
99       /* Use reserved space for tracking number of triggers submitted for a given channel */
100       druRegs->CHRT[i].Resv_256[0]++;
101       break;
102     }
103   }
106 void hostEmulation_druChSubmitAtomicTr(CSL_DRU_t *pRegs,
107                                            uint32_t chId,
108                                            void *  vdata)
110   CSL_UdmapTR * tr = (CSL_UdmapTR *)vdata;
111   CSL_UdmapTR * origTransferRecord   = ( CSL_UdmapTR *)&pRegs->CHATOMIC[chId];
112   CSL_UdmapTR * nextTransferRecord  = (CSL_UdmapTR *)&pRegs->CHATOMIC[chId].DEBUG[0];
113   CSL_UdmapTR * nextTransferRecord1 = (CSL_UdmapTR *)&pRegs->CHATOMIC[chId].DEBUG[1];
114   CSL_UdmapTR * nextTransferRecord2 = (CSL_UdmapTR *)&pRegs->CHATOMIC[chId].DEBUG[2];
116   /* Use reserved space for tracking number of triggers submitted for a given channel */
117   pRegs->CHRT[chId].Resv_256[0] = 0;
119   *origTransferRecord  = *tr;
120   *nextTransferRecord = *tr;
121   *nextTransferRecord1 = *tr;
122   *nextTransferRecord2 = *tr;
126 uint64_t hostEmulation_addressUpdate( uint64_t base, int32_t offset, uint64_t addrMask )
128   uint64_t newAddr;
130   newAddr = base + offset;
132   if ( addrMask != 0 )
133   {
134     newAddr = ( base & addrMask ) | ( newAddr & ~addrMask );
135   }
137   return newAddr;
140 void hostEmulation_circMask( uint32_t cbk0, uint32_t cbk1, uint64_t * circMask0, uint64_t * circMask1  )
142   uint32_t blockSize0 = cbk0 + 9U; /* power-of-2 of block size in bytes */
143   uint32_t blockSize1 = cbk0 + cbk1 + 10U; /* power-of-2 of block size in bytes */
145   if ( blockSize1 > 31U )
146   {
147     blockSize1 = 32U; /* clamp to 4GB maximum size */
148   }
149   *circMask0 = (~0ULL) << blockSize0;
150   *circMask1 = (~0ULL) << blockSize1;
153 static void hostEmulation_triggerDMA(struct Udma_DrvObj * udmaDrvHandle)
155   uint32_t chId;
156   CSL_DRU_t * druRegs;
157   CSL_UdmapCfg  * udmapRegs;
158   CSL_ringacc_cfgRegs * ringAccCfgRegs;
161   druRegs             = udmaDrvHandle->utcInfo[0].druRegs;
162   ringAccCfgRegs  = udmaDrvHandle->raRegs.pCfgRegs;
163   udmapRegs        = &udmaDrvHandle->udmapRegs;
166   for ( chId = 0; chId < 32; chId++)//:TODO: Remove hard coded value of 32
167   {
168     if ( (druRegs->CHRT[chId].CHRT_SWTRIG & CSL_DRU_CHRT_SWTRIG_GLOBAL_TRIGGER0_MASK) == 1U)
169     {
170       uint8_t *srcPtr;
171       uint8_t *dstPtr;
172       uint32_t triggerType;
173       uint32_t circDir;
174       uint32_t icnt0;
175       uint32_t CBK0, CBK1;
176       uint32_t AM0, AM1, AM2, AM3;
177       uint64_t srcAM0, srcAM1, srcAM2, srcAM3;
178       uint64_t dstAM0, dstAM1, dstAM2, dstAM3;
179       uint64_t circMask0;
180       uint64_t circMask1;
181       uint32_t AMODE;
182       uint32_t loopCnt1Reset, loopCnt2Reset;
183       uint8_t * interimBuffer = NULL;
184       uint32_t srcLoopExitCondition = 0;
185       uint32_t dstLoopExitCondition = 0;
186       uint32_t totalSrcCnt, totalDstCnt;
187       /* Clear the sw trigger so that next trigger can happen */
190       druRegs->CHRT[chId].Resv_256[0]--;
191       /* Use reserved space for tracking number of triggers submitted for a given channel */
192       if ( druRegs->CHRT[chId].Resv_256[0] == 0 )
193       {
194         druRegs->CHRT[chId].CHRT_SWTRIG  = druRegs->CHRT[chId].CHRT_SWTRIG & (uint64_t)(~CSL_DRU_CHRT_SWTRIG_GLOBAL_TRIGGER0_MASK);
195       }
197       CSL_UdmapTR * origTransferRecord  = (CSL_UdmapTR *)(void *) &druRegs->CHATOMIC[chId];
198       CSL_UdmapTR * nextTransferRecord = (CSL_UdmapTR *)(void *) &druRegs->CHATOMIC[chId].DEBUG[0];
199       CSL_UdmapTR * nextTransferRecord1 = (CSL_UdmapTR *)(void *) &druRegs->CHATOMIC[chId].DEBUG[1];
200       CSL_UdmapTR * nextTransferRecord2 = (CSL_UdmapTR *)(void *) &druRegs->CHATOMIC[chId].DEBUG[2];
202       /* Do the actual transfer */
204       triggerType = CSL_FEXT(origTransferRecord->flags, UDMAP_TR_FLAGS_TRIGGER0_TYPE);
205       AMODE = CSL_FEXT(origTransferRecord->fmtflags, UDMAP_TR_FMTFLAGS_AMODE);
207       if ( AMODE == CSL_UDMAP_TR_FMTFLAGS_AMODE_CIRCULAR)
208       {
209         circDir        = CSL_FEXT(origTransferRecord->fmtflags, UDMAP_TR_FMTFLAGS_DIR);
210         CBK0         = CSL_FEXT(origTransferRecord->fmtflags, UDMAP_TR_FMTFLAGS_AMODE_SPECIFIC_CBK0);
211         CBK1         = CSL_FEXT(origTransferRecord->fmtflags, UDMAP_TR_FMTFLAGS_AMODE_SPECIFIC_CBK1);
212         AM0           = CSL_FEXT(origTransferRecord->fmtflags, UDMAP_TR_FMTFLAGS_AMODE_SPECIFIC_AM0);
213         AM1           = CSL_FEXT(origTransferRecord->fmtflags, UDMAP_TR_FMTFLAGS_AMODE_SPECIFIC_AM1);
214         AM2           = CSL_FEXT(origTransferRecord->fmtflags, UDMAP_TR_FMTFLAGS_AMODE_SPECIFIC_AM2);
215         AM3           = CSL_FEXT(origTransferRecord->fmtflags, UDMAP_TR_FMTFLAGS_AMODE_SPECIFIC_AM3);
216         hostEmulation_circMask(CBK0, CBK1, &circMask0, &circMask1);
217       }
218       else
219       {
220         /* Linear Addressing */
221         circMask0 = (~0ULL);
222         circMask1 = (~0ULL);
223         AM0 = 0;
224         AM1 = 0;
225         AM2 = 0;
226         AM3 = 0;
227         circDir = 0;
228       }
230       if ( circDir == CSL_UDMAP_TR_FMTFLAGS_DIR_DST_USES_AMODE)
231       {
232         dstAM0 = (AM0 == 0 ) ? 0 : ( (AM0 == 1) ? circMask0 : circMask1  );/* Circular update */
233         srcAM0 = 0;/* Linear Update */
235         dstAM1 = (AM1 == 0 ) ? 0 : ( (AM1 == 1) ? circMask0 : circMask1  );/* Circular update */
236         srcAM1 = 0;/* Linear Update */
238         dstAM2 = (AM2 == 0 ) ? 0 : ( (AM2 == 1) ? circMask0 : circMask1  );/* Circular update */
239         srcAM2 = 0;/* Linear Update */
241         dstAM3 = (AM3 == 0 ) ? 0 : ( (AM3 == 1) ? circMask0 : circMask1  );/* Circular update */
242         srcAM3 = 0;/* Linear Update */
243       }
244       else
245       {
246         dstAM0 = 0;/* Linear Update */
247         srcAM0 = (AM0 == 0 ) ? 0 : ( (AM0 == 1) ? circMask0 : circMask1  );
249         dstAM1 = 0;/* Linear Update */
250         srcAM1 = (AM1 == 0 ) ? 0 : ( (AM1 == 1) ? circMask0 : circMask1  );
252         dstAM2 = 0;/* Linear Update */
253         srcAM2 = (AM2 == 0 ) ? 0 : ( (AM2 == 1) ? circMask0 : circMask1  );
255         dstAM3 = 0;/* Linear Update */
256         srcAM3 = (AM3 == 0 ) ? 0 : ( (AM3 == 1) ? circMask0 : circMask1  );
258       }
260       loopCnt1Reset = 0;
261       loopCnt2Reset = 0;
263       /* allocate worst case, actual buffer used will depend on trugerType */
264       interimBuffer = (uint8_t *)malloc(origTransferRecord->icnt0 * origTransferRecord->icnt1 * origTransferRecord->icnt2 *
265                                         origTransferRecord->icnt3);
266       dstPtr = interimBuffer;
268       totalSrcCnt = nextTransferRecord->icnt0 * nextTransferRecord->icnt1 * nextTransferRecord->icnt2 * nextTransferRecord->icnt3;
269       totalDstCnt = nextTransferRecord->dicnt0 * nextTransferRecord->dicnt1 * nextTransferRecord->dicnt2 * nextTransferRecord->dicnt3;
271       srcLoopExitCondition  = ( totalSrcCnt < totalDstCnt )? totalSrcCnt : totalDstCnt;
272       dstLoopExitCondition  = srcLoopExitCondition;
273       /* Set the minimum value of icnt3 for both src and dst as TR completes whenever anyone of them  is exauhsted */
274       /* Transfer source data to a intermediate linear buffer */
276       while (1)
277       {
278         srcPtr = (uint8_t *)nextTransferRecord->addr;
279 /*        dstPtr = interimBuffer +
280                     (origTransferRecord->icnt1 - nextTransferRecord->icnt1) * origTransferRecord->icnt0 +
281                     (origTransferRecord->icnt2 - nextTransferRecord->icnt2) * origTransferRecord->icnt0 * origTransferRecord->icnt1;*/
283         for (icnt0 = 0; icnt0 < nextTransferRecord->icnt0; icnt0++)
284         {
285           *dstPtr = *srcPtr;
286             srcPtr = (uint8_t *)hostEmulation_addressUpdate((uint64_t)srcPtr, 1, srcAM0);
287             dstPtr++;
288         }
289         nextTransferRecord->icnt1--;
290         nextTransferRecord->addr   = hostEmulation_addressUpdate(nextTransferRecord->addr ,  nextTransferRecord->dim1,   srcAM1);
292         if ( nextTransferRecord->icnt1 == 0)
293         {
294           loopCnt1Reset = 1;
295           nextTransferRecord->icnt2--;
296           nextTransferRecord->icnt1 = origTransferRecord->icnt1;
298           nextTransferRecord->addr   = hostEmulation_addressUpdate(nextTransferRecord1->addr ,  nextTransferRecord->dim2,   srcAM2);
300           nextTransferRecord1->addr   = nextTransferRecord->addr;
301         }
303         if ( nextTransferRecord->icnt2 == 0)
304         {
305           loopCnt2Reset= 1;
306           nextTransferRecord->icnt3--;
307           nextTransferRecord->icnt2 = origTransferRecord->icnt2;
309           nextTransferRecord->addr   = hostEmulation_addressUpdate(nextTransferRecord2->addr,  nextTransferRecord->dim3,   srcAM3);
311           nextTransferRecord1->addr   = nextTransferRecord->addr;
312           nextTransferRecord2->addr   = nextTransferRecord->addr;
313         }
315         if ( nextTransferRecord->icnt3 == 0)
316         {
317           CSL_REG64_FINS(&druRegs->CHRT[chId].CHRT_CTL, DRU_CHRT_CTL_ENABLE, 0);
318           break;
319         }
322         if ( triggerType == CSL_UDMAP_TR_FLAGS_TRIGGER_TYPE_ICNT1_DEC )
323         {
324           break;
325         }
326         else if ( triggerType == CSL_UDMAP_TR_FLAGS_TRIGGER_TYPE_ICNT2_DEC )
327         {
328           if ( loopCnt1Reset == 1)
329           {
330             nextTransferRecord1->addr   = nextTransferRecord->addr;
331             break;
332           }
333         }
334         else if ( triggerType == CSL_UDMAP_TR_FLAGS_TRIGGER_TYPE_ICNT3_DEC )
335         {
336           if ( loopCnt2Reset == 1)
337           {
338             nextTransferRecord2->addr   = nextTransferRecord->addr;
339             break;
340           }
341         }
342         else
343         {
344           /*Indicates 4D sync,  Just continue */
345         }
346         srcLoopExitCondition--;
347         if ( srcLoopExitCondition == 0)
348         {
349           nextTransferRecord->icnt3 = 0;
350           CSL_REG64_FINS(&druRegs->CHRT[chId].CHRT_CTL, DRU_CHRT_CTL_ENABLE, 0);
351           break;
352         }
353       }
355       loopCnt1Reset = 0;
356       loopCnt2Reset = 0;
358      srcPtr = interimBuffer;
359       /* Now copy the intermediate data to the destination buffer */
360      while (1)
361       {
362         dstPtr = (uint8_t *)nextTransferRecord->daddr;
364         for (icnt0 = 0; icnt0 < nextTransferRecord->dicnt0; icnt0++)
365         {
366           *dstPtr = *srcPtr;
367            *srcPtr++;
368             dstPtr = (uint8_t *)hostEmulation_addressUpdate((uint64_t)dstPtr, 1, dstAM0);
369         }
371         nextTransferRecord->dicnt1--;
373         nextTransferRecord->daddr = hostEmulation_addressUpdate(nextTransferRecord->daddr, nextTransferRecord->ddim1, dstAM1);
375         if ( nextTransferRecord->dicnt1 == 0)
376         {
377           loopCnt1Reset = 1;
378           nextTransferRecord->dicnt2--;
379           nextTransferRecord->dicnt1 = origTransferRecord->dicnt1;
381           nextTransferRecord->daddr = hostEmulation_addressUpdate(nextTransferRecord1->daddr, nextTransferRecord->ddim2, dstAM2);
382           nextTransferRecord1->daddr = nextTransferRecord->daddr;
383         }
385         if ( nextTransferRecord->dicnt2 == 0)
386         {
387           loopCnt2Reset= 1;
388           nextTransferRecord->dicnt3--;
389           nextTransferRecord->dicnt2 = origTransferRecord->dicnt2;
391           nextTransferRecord->daddr = hostEmulation_addressUpdate(nextTransferRecord2->daddr, nextTransferRecord->ddim3, dstAM3);
393           nextTransferRecord1->daddr = nextTransferRecord->daddr;
394           nextTransferRecord2->daddr = nextTransferRecord->daddr;
395         }
397         if ( nextTransferRecord->dicnt3 == 0)
398         {
399           CSL_REG64_FINS(&druRegs->CHRT[chId].CHRT_CTL, DRU_CHRT_CTL_ENABLE, 0);
400           break;
401         }
403         if ( triggerType == CSL_UDMAP_TR_FLAGS_TRIGGER_TYPE_ICNT1_DEC )
404         {
405           break;
406         }
407         else if ( triggerType == CSL_UDMAP_TR_FLAGS_TRIGGER_TYPE_ICNT2_DEC )
408         {
409           if ( loopCnt1Reset == 1)
410           {
411             break;
412           }
413         }
414         else if ( triggerType == CSL_UDMAP_TR_FLAGS_TRIGGER_TYPE_ICNT3_DEC )
415         {
416           if ( loopCnt2Reset == 1)
417           {
418             break;
419           }
420         }
422         dstLoopExitCondition--;
423         if ( dstLoopExitCondition == 0)
424         {
425           nextTransferRecord->dicnt3 = 0;
426           CSL_REG64_FINS(&druRegs->CHRT[chId].CHRT_CTL, DRU_CHRT_CTL_ENABLE, 0);
427           break;
428         }
429       }
431       if (( nextTransferRecord->icnt3 == 0 ) || ( nextTransferRecord->dicnt3 == 0 ))
432       {
433         /* this indicates that TR is received from PSIL */
434         if ( (druRegs->CHNRT[chId].CFG & CSL_DRU_CHNRT_CFG_CHAN_TYPE_OWNER_MASK) != 0 )
435         {
436            CSL_UdmapCppi5TRPD * trDescriptor;
437            uint64_t * ringPtr;
438            uint64_t currTr;
439            uint64_t numTr;
440            CSL_UdmapTR           *pTr;
441            /* Get Ring Memory Pointer */
442           ringPtr = (uint64_t *) ((uint64_t)((uint64_t)ringAccCfgRegs->RING[udmapRegs->txChanCnt + chId].BA_HI << 32) |
443                                             ringAccCfgRegs->RING[udmapRegs->txChanCnt + chId].BA_LO);
445            trDescriptor = (CSL_UdmapCppi5TRPD *) (*ringPtr);
447            numTr = CSL_udmapCppi5GetPktLen(trDescriptor);
448            /* Use this field to track the TR, For the target build this would be handled by hardware */
449            /* In real hardware this will not be like this it is done just for host emulation*/
450            currTr =  druRegs->CHATOMIC[chId].DEBUG[1].NEXT_TR_WORD0_1;
452             if ( currTr < numTr)
453             {
454                currTr++;
455                pTr = (CSL_UdmapTR *)( (uint8_t *)trDescriptor + sizeof(CSL_UdmapTR) * currTr);
457                /* Update both original and next transfer record by reading the TR from the TR descriptor */
458               hostEmulation_druChSubmitAtomicTr(druRegs, chId, (void *) pTr);
460                druRegs->CHATOMIC[chId].DEBUG[1].NEXT_TR_WORD0_1 = currTr;
462             }
463         }
464       }
465       if ( interimBuffer != NULL)
466       {
467         free(interimBuffer);
468       }
469     }
470   }
472 #endif
475 static int32_t DmaUtilsAutoInc3d_getTotalBlockCount(uint8_t * trMem, uint32_t numTr)
477     uint32_t i;
478     CSL_UdmapTR * pTr;
479     uint32_t isRingBasedFlowReq = 0;
480     uint32_t numTotBlks = 0;
481     uint32_t triggerType;
482     uint32_t srcCounts;
483     uint32_t dstCounts;
485     pTr = ( CSL_UdmapTR * )trMem;
487     if ( numTr > DMAUTILS_MAX_NUM_TR_DIRECT_TR_MODE)
488     {
489       isRingBasedFlowReq = 1U;
490     }
492     if (  isRingBasedFlowReq == 1U )
493     {
494       /* Setup TR descriptor */
495       pTr = (CSL_UdmapTR *)(trMem + sizeof(CSL_UdmapTR));
496     }
498     for ( i = 0; i < numTr; i++)
499     {
500         triggerType = CSL_FEXT(pTr[i].flags, UDMAP_TR_FLAGS_TRIGGER0_TYPE );
501         if ( triggerType == CSL_UDMAP_TR_FLAGS_TRIGGER_TYPE_ICNT1_DEC )
502         {
503             srcCounts = pTr[i].icnt1 * pTr[i].icnt2 * pTr[i].icnt3;
504             dstCounts = pTr[i].dicnt1 * pTr[i].dicnt2 * pTr[i].dicnt3;
505         }
506         else if ( triggerType == CSL_UDMAP_TR_FLAGS_TRIGGER_TYPE_ICNT2_DEC )
507         {
508             srcCounts = pTr[i].icnt2 * pTr[i].icnt3;
509             dstCounts = pTr[i].dicnt2 * pTr[i].dicnt3;
510         }
511         else if ( triggerType == CSL_UDMAP_TR_FLAGS_TRIGGER_TYPE_ICNT3_DEC )
512         {
513             srcCounts = pTr[i].icnt3;
514             dstCounts = pTr[i].dicnt3;
515         }
516         else
517         {
518             srcCounts = 1U;
519             dstCounts = 1U;
520         }
522         /* Always pick the minmum of the src and dst count as once any one is exhausted TR is compete */
523         numTotBlks += ( srcCounts > dstCounts) ? dstCounts : srcCounts;
524     }
526     return numTotBlks;
532 static void DmaUtilsAutoInc3d_setupTr(CSL_UdmapTR * tr,
533                                                                         DmaUtilsAutoInc3d_TransferProp * transferProp);
535 static void DmaUtilsAutoInc3d_setupTr(CSL_UdmapTR * tr,
536                                                                         DmaUtilsAutoInc3d_TransferProp * transferProp)
539     uint32_t triggerBoundary;
540     uint32_t waitBoundary;
541     uint32_t fmtflags = 0;
543     switch (transferProp->syncType)
544     {
545         case DMAUTILSAUTOINC3D_SYNC_1D :
546         {
547           triggerBoundary = CSL_UDMAP_TR_FLAGS_TRIGGER_TYPE_ICNT1_DEC;
548           waitBoundary     = CSL_UDMAP_TR_FLAGS_EVENT_SIZE_ICNT1_DEC;
549           break;
550         }
551         case DMAUTILSAUTOINC3D_SYNC_2D :
552         {
553           triggerBoundary = CSL_UDMAP_TR_FLAGS_TRIGGER_TYPE_ICNT2_DEC;
554           waitBoundary     = CSL_UDMAP_TR_FLAGS_EVENT_SIZE_ICNT2_DEC;
555           break;
556         }
557         case DMAUTILSAUTOINC3D_SYNC_3D:
558         {
559           triggerBoundary = CSL_UDMAP_TR_FLAGS_TRIGGER_TYPE_ICNT3_DEC;
560           waitBoundary     = CSL_UDMAP_TR_FLAGS_EVENT_SIZE_ICNT3_DEC;
561           break;
562         }
563         case DMAUTILSAUTOINC3D_SYNC_4D:
564         {
565           triggerBoundary = CSL_UDMAP_TR_FLAGS_TRIGGER_TYPE_ALL;
566           waitBoundary     = CSL_UDMAP_TR_FLAGS_EVENT_SIZE_COMPLETION;
567           break;
568         }
569         default :
570         {
571           triggerBoundary = CSL_UDMAP_TR_FLAGS_TRIGGER_TYPE_ICNT2_DEC;
572           waitBoundary     = CSL_UDMAP_TR_FLAGS_EVENT_SIZE_ICNT2_DEC;
573           break;
574         }
575     }
577     /* Configure circularity parameters if required */
578     if ( ( transferProp->circProp.circSize1 != 0 ) ||
579             ( transferProp->circProp.circSize2 != 0 ) )
580     {
581         int32_t CBK0;
582         int32_t CBK1;
583         uint32_t circSize1 = transferProp->circProp.circSize1;
584         uint32_t circSize2 = transferProp->circProp.circSize2;
585         uint32_t circDir;
587         if ( transferProp->circProp.circDir == DMAUTILSAUTOINC3D_CIRCDIR_SRC )
588         {
589           circDir = CSL_UDMAP_TR_FMTFLAGS_DIR_SRC_USES_AMODE;
590         }
591         else
592         {
593           circDir = CSL_UDMAP_TR_FMTFLAGS_DIR_DST_USES_AMODE;
594         }
596         CBK0 = log2((double) circSize1) - 9;
597         CBK1 = log2((double)circSize2)  - 1U -CBK0;
599         if ( CBK1 < 0 )
600         {
601            CBK1 = 0;
602         }
604         fmtflags = CSL_FMK(UDMAP_TR_FMTFLAGS_AMODE, CSL_UDMAP_TR_FMTFLAGS_AMODE_CIRCULAR) |
605                                CSL_FMK(UDMAP_TR_FMTFLAGS_DIR, circDir) |
606                                CSL_FMK(UDMAP_TR_FMTFLAGS_ELYPE, CSL_UDMAP_TR_FMTFLAGS_ELYPE_1) |
607                                CSL_FMK(UDMAP_TR_FMTFLAGS_DFMT, CSL_UDMAP_TR_FMTFLAGS_DFMT_NO_CHANGE ) |
608                                CSL_FMK(UDMAP_TR_FMTFLAGS_SECTR, CSL_UDMAP_TR_FMTFLAGS_SECTR_NONE ) |
609                                CSL_FMK(UDMAP_TR_FMTFLAGS_AMODE_SPECIFIC_CBK0, CBK0 ) |
610                                CSL_FMK(UDMAP_TR_FMTFLAGS_AMODE_SPECIFIC_CBK1, CBK1 ) |
611                                CSL_FMK(UDMAP_TR_FMTFLAGS_AMODE_SPECIFIC_AM0, transferProp->circProp.addrModeIcnt0) |
612                                CSL_FMK(UDMAP_TR_FMTFLAGS_AMODE_SPECIFIC_AM1, transferProp->circProp.addrModeIcnt1) |
613                                CSL_FMK(UDMAP_TR_FMTFLAGS_AMODE_SPECIFIC_AM2, transferProp->circProp.addrModeIcnt2) |
614                                CSL_FMK(UDMAP_TR_FMTFLAGS_AMODE_SPECIFIC_AM3, transferProp->circProp.addrModeIcnt3);
616     }
617      /* Setup TR */
618     tr->flags     = CSL_FMK(UDMAP_TR_FLAGS_TYPE, CSL_UDMAP_TR_FLAGS_TYPE_4D_BLOCK_MOVE_REPACKING)             |
619                CSL_FMK(UDMAP_TR_FLAGS_STATIC, FALSE)                                           |
620                CSL_FMK(UDMAP_TR_FLAGS_EOL, FALSE)                                              |   /* NA */
621                CSL_FMK(UDMAP_TR_FLAGS_EVENT_SIZE, waitBoundary)    |
622                CSL_FMK(UDMAP_TR_FLAGS_TRIGGER0, CSL_UDMAP_TR_FLAGS_TRIGGER_GLOBAL0)          |/*Set the trigger to local trigger*/
623                CSL_FMK(UDMAP_TR_FLAGS_TRIGGER0_TYPE, triggerBoundary)      |/* This is to transfer a 2D block for each trigger*/
624                CSL_FMK(UDMAP_TR_FLAGS_TRIGGER1, CSL_UDMAP_TR_FLAGS_TRIGGER_NONE)               |
625                CSL_FMK(UDMAP_TR_FLAGS_TRIGGER1_TYPE, CSL_UDMAP_TR_FLAGS_TRIGGER_TYPE_ALL)      |
626                CSL_FMK(UDMAP_TR_FLAGS_CMD_ID, 0)                                           |   /* This will come back in TR response */
627                CSL_FMK(UDMAP_TR_FLAGS_SA_INDIRECT, 0U)                                         |
628                CSL_FMK(UDMAP_TR_FLAGS_DA_INDIRECT, 0U)                                         |
629                CSL_FMK(UDMAP_TR_FLAGS_EOP, 1U);
631     tr->addr        = (uintptr_t)transferProp->ioPointers.srcPtr;
632     tr->icnt0        = transferProp->transferDim.sicnt0;
633     tr->icnt1        = transferProp->transferDim.sicnt1;
634     tr->icnt2        = transferProp->transferDim.sicnt2;
635     tr->icnt3        = transferProp->transferDim.sicnt3;
636     tr->dim1        = transferProp->transferDim.sdim1;
637     tr->dim2        = transferProp->transferDim.sdim2;
638     tr->dim3        = transferProp->transferDim.sdim3;
639     tr->fmtflags    = fmtflags;
640     tr->daddr       = (uintptr_t) transferProp->ioPointers.dstPtr;
641     tr->dicnt0       = transferProp->transferDim.dicnt0;
642     tr->dicnt1       = transferProp->transferDim.dicnt1;
643     tr->dicnt2       = transferProp->transferDim.dicnt2;
644     tr->dicnt3       = transferProp->transferDim.dicnt3;
645     tr->ddim1      =  transferProp->transferDim.ddim1;
646     tr->ddim2      =  transferProp->transferDim.ddim2;
647     tr->ddim3      =  transferProp->transferDim.ddim3;
650 static void DmaUtilsAutoInc3d_printf(void * autoIncrementContext, int traceLevel, const char *format, ...);
651 static void DmaUtilsAutoInc3d_printf(void * autoIncrementContext, int traceLevel, const char *format, ...)
653   DmaUtilsAutoInc3d_Context * dmautilsContext = (DmaUtilsAutoInc3d_Context *)autoIncrementContext;
654   va_list args;
656   if ( dmautilsContext->initParams.DmaUtilsVprintf != NULL )
657   {
658       if ( traceLevel < dmautilsContext->initParams.traceLogLevel)
659       {
660           va_start(args, format);
661           dmautilsContext->initParams.DmaUtilsVprintf(format, args);
662           va_end(args);
663       }
664   }
667 static void  DmaUtilsAutoInc3d_initializeContext(void * autoIncrementContext);
668 static void  DmaUtilsAutoInc3d_initializeContext(void * autoIncrementContext)
670     DmaUtilsAutoInc3d_Context * autoIncHandle = (DmaUtilsAutoInc3d_Context *)autoIncrementContext;
672     memset(autoIncHandle, 0, sizeof(DmaUtilsAutoInc3d_Context));
674 //:TODO: This needs to be done at appropriate place
675 #ifdef HOST_EMULATION
677 #endif
678     return ;
682 int32_t DmaUtilsAutoInc3d_getContextSize(int32_t numChannels)
684     int32_t contextSize = 0;
686     contextSize += DMAUTILS_ALIGN_CEIL(sizeof(DmaUtilsAutoInc3d_ChannelContext), 128) * numChannels;
688     contextSize += DMAUTILS_ALIGN_CEIL(sizeof(DmaUtilsAutoInc3d_Context), 128);
690     return contextSize;
693 static int32_t DmaUtilsAutoInc3d_setupContext(void * autoIncrementContext, DmaUtilsAutoInc3d_InitParam * initParams);
694 static int32_t DmaUtilsAutoInc3d_setupContext(void * autoIncrementContext, DmaUtilsAutoInc3d_InitParam * initParams)
696     int32_t     retVal = UDMA_SOK;
697     int32_t memLocation = 0;
698     uint8_t * memPointer;
699     int32_t i;
700     DmaUtilsAutoInc3d_Context * dmaUtilsContext;
702     memPointer  = (uint8_t *)autoIncrementContext;
703     dmaUtilsContext = (DmaUtilsAutoInc3d_Context *)memPointer;
704     memLocation += DMAUTILS_ALIGN_CEIL(sizeof(DmaUtilsAutoInc3d_Context), 128);
706     dmaUtilsContext->initParams = *initParams;
708     for ( i = 0; i < initParams->numChannels; i++)
709     {
710       dmaUtilsContext->channelContext[i] = (DmaUtilsAutoInc3d_ChannelContext *) (memPointer + memLocation);
711       memLocation += DMAUTILS_ALIGN_CEIL(sizeof (DmaUtilsAutoInc3d_ChannelContext), 128);
712     }
714     if ( memLocation > initParams->contextSize)
715     {
716         DmaUtilsAutoInc3d_printf(autoIncrementContext, 0, " DmaUtilsAutoInc3d_setupContext : Failed \n");
717         retVal = UDMA_EINVALID_PARAMS;
718     }
720     return retVal;
723 int32_t DmaUtilsAutoInc3d_init(void * autoIncrementContext , DmaUtilsAutoInc3d_InitParam * initParams, DmaUtilsAutoInc3d_ChannelInitParam chInitParams[])
725   uint32_t size;
726   int32_t     retVal = UDMA_SOK;
727   int32_t i;
728   uint32_t                chType;
729   uint32_t                eventId;
730   Udma_ChPrms       chPrms;
731   Udma_ChUtcPrms  utcPrms;
732   DmaUtilsAutoInc3d_Context              * dmautilsContext;
733   DmaUtilsAutoInc3d_ChannelContext * channelContext;
734   Udma_ChHandle channelHandle;
736   if ( initParams == NULL)
737   {
738     retVal = UDMA_EBADARGS;
739     goto Exit;
740   }
742   if ( autoIncrementContext == NULL)
743   {
744     retVal = UDMA_EBADARGS;
745     goto Exit;
746   }
748   size = DmaUtilsAutoInc3d_getContextSize(initParams->numChannels);
750   if ( size != initParams->contextSize )
751   {
752     retVal = UDMA_EINVALID_PARAMS;
753     goto Exit;
754   }
755   /* Reset internal variables of autoincrement context */
756   DmaUtilsAutoInc3d_initializeContext(autoIncrementContext);
758   dmautilsContext = (DmaUtilsAutoInc3d_Context *)autoIncrementContext;
760   retVal = DmaUtilsAutoInc3d_setupContext(autoIncrementContext, initParams);
761   if   (UDMA_SOK != retVal)
762   {
763     goto Exit;
764   }
766   /* Initialize the channel params to default */
767    chType = UDMA_CH_TYPE_UTC;
768    UdmaChPrms_init(&chPrms, chType);
769    chPrms.utcId = UDMA_UTC_ID_MSMC_DRU0;
771   UdmaChUtcPrms_init(&utcPrms);
773   for ( i = 0; i < initParams->numChannels; i++)
774   {
775       channelContext = dmautilsContext->channelContext[i];
777       if ( chInitParams[i].druOwner == DMAUTILSAUTOINC3D_DRUOWNER_DIRECT_TR )
778       {
779           chPrms.fqRingPrms.ringMem      = NULL;
780           chPrms.cqRingPrms.ringMem     = NULL;
781           chPrms.tdCqRingPrms.ringMem = NULL;
782           chPrms.fqRingPrms.elemCnt     = 0U;
783           chPrms.cqRingPrms.elemCnt     = 0U;
784           chPrms.tdCqRingPrms.elemCnt  = 0U;
786           utcPrms.druOwner = CSL_DRU_OWNER_DIRECT_TR;
787       }
788       else
789       {
790           chPrms.fqRingPrms.ringMem     = &channelContext->ringMem;
791           chPrms.cqRingPrms.ringMem    = &channelContext->responseRingMem;
792           chPrms.tdCqRingPrms.ringMem = NULL;
793           chPrms.fqRingPrms.ringMemSize = sizeof(uint64_t);
794           chPrms.cqRingPrms.ringMemSize = sizeof(uint64_t);
795           chPrms.tdCqRingPrms.ringMemSize = 0;
796           chPrms.fqRingPrms.elemCnt      = 1U;/* We have only one element per ring */
797           chPrms.cqRingPrms.elemCnt     = 1U;/* We have only one element per ring */
798           chPrms.tdCqRingPrms.elemCnt  = 0U;/* We have only one element per ring */
800           utcPrms.druOwner = CSL_DRU_OWNER_UDMAC_TR;
801       }
803       channelHandle = &(channelContext->chHandle);
805       retVal = Udma_chOpen(initParams->udmaDrvHandle, channelHandle, chType, &chPrms);
806       if(UDMA_SOK != retVal)
807       {
808           DmaUtilsAutoInc3d_printf(autoIncrementContext, 0, "Udma_chOpen : Failed \n");
809          goto Exit;
810       }
812       /* Config UTC channel */
813       utcPrms.druQueueId  =chInitParams[i].dmaQueNo;
815       retVal = Udma_chConfigUtc(channelHandle, &utcPrms);
816       if(UDMA_SOK != retVal)
817       {
818           DmaUtilsAutoInc3d_printf(autoIncrementContext, 0, "Udma_chConfigUtc : Failed \n");
819           goto Exit;
820       }
822       /* Enable The channel */
823       retVal = Udma_chEnable(channelHandle);
824       if(UDMA_SOK != retVal)
825       {
826           DmaUtilsAutoInc3d_printf(autoIncrementContext, 0, "Udma_chEnable : Failed \n");
827           goto Exit;
828       }
830       eventId = Udma_chGetNum(channelHandle);
832       channelContext->swTriggerPointer = Udma_druGetTriggerRegAddr(channelHandle);
833       //:TODO: Currently it is assumed that DRU local events are routed to 32 event of c7x. This needs to be done cleanly
834       channelContext->waitWord =  ((uint64_t)1U << (32 + eventId) );
835   }
837 Exit:
838     return retVal;
841 int32_t DmaUtilsAutoInc3d_getTrMemReq(int32_t numTRs)
843     int32_t isRingBasedFlowReq = 0;
844     int32_t trMemReq = 0;
846     if ( numTRs > DMAUTILS_MAX_NUM_TR_DIRECT_TR_MODE)
847     {
848       isRingBasedFlowReq = 1;
849     }
851     if ( isRingBasedFlowReq )
852     {
853          //:TODO: Check how to make sure align required
854          /* This indicates ring accelerator mode and hence will need memory for TR descriptor */
855         trMemReq = sizeof(CSL_UdmapCppi5TRPD) + /* Number of Bytes for TR descriptor */
856                                sizeof(CSL_UdmapTR) + /* Padding required to bring start of TR request to natural alignment for memory fetch efficiency */
857                                numTRs * sizeof(CSL_UdmapTR) + /* Memory for Transfer Records */
858                                numTRs * sizeof(uint32_t);/* Memory for Transfer Response Records */
859     }
860     else
861     {
862       trMemReq = numTRs * sizeof(CSL_UdmapTR);
863     }
865     return trMemReq;
869 int32_t DmaUtilsAutoInc3d_prepareTr(DmaUtilsAutoInc3d_TrPrepareParam * trPrepParam ,  DmaUtilsAutoInc3d_TransferProp transferProp[])
871     int32_t size;
872     int32_t     retVal = UDMA_SOK;
873     int32_t isRingBasedFlowReq = 0;
874     CSL_UdmapTR * pTrArray;
875     int32_t i;
877     if ( trPrepParam == NULL )
878     {
879       retVal = UDMA_EBADARGS;
880       goto Exit;
881     }
883     size = DmaUtilsAutoInc3d_getTrMemReq(trPrepParam->numTRs);
885     if ( trPrepParam->trMemSize < size )
886     {
887       retVal = UDMA_EINVALID_PARAMS;
888       goto Exit;
889     }
891     if ( trPrepParam->trMem == NULL )
892     {
893       retVal = UDMA_EBADARGS;
894       goto Exit;
895     }
897     if ( trPrepParam->numTRs > DMAUTILS_MAX_NUM_TR_DIRECT_TR_MODE)
898     {
899         isRingBasedFlowReq = 1;
900     }
902     pTrArray = (CSL_UdmapTR *)trPrepParam->trMem;
904     if ( isRingBasedFlowReq == 1 )
905     {
906       /* This needs to be updated with correct value during configure */
907       uint32_t cqRingNum = 0;
908       /* Setup TR descriptor */
910       CSL_UdmapCppi5TRPD * pTrpd = (CSL_UdmapCppi5TRPD *)trPrepParam->trMem;
911       CSL_UdmapTR           *pTr = (CSL_UdmapTR *)(trPrepParam->trMem + sizeof(CSL_UdmapTR));
913       UdmaUtils_makeTrpd(pTrpd, UDMA_TR_TYPE_9, trPrepParam->numTRs, cqRingNum);
914       pTrArray = pTr;
916     }
918     for ( i = 0; i < trPrepParam->numTRs ; i++)
919     {
920           DmaUtilsAutoInc3d_setupTr(&pTrArray[i], &transferProp[i]);
921     }
924 Exit:
926     return retVal;
931 int32_t DmaUtilsAutoInc3d_configure(void * autoIncrementContext, int32_t channelId, uint8_t * trMem, int32_t numTr)
933     int32_t     retVal = UDMA_SOK;
934     DmaUtilsAutoInc3d_Context              * dmautilsContext;
935     DmaUtilsAutoInc3d_ChannelContext * channelContext;
936     uint32_t isRingBasedFlowReq =0;
937     Udma_ChHandle channelHandle;
939     uint32_t i;
941 #ifdef HOST_EMULATION
942     uint32_t druChannelNum;
943 #endif
944     if ( autoIncrementContext == NULL)
945     {
946       retVal = UDMA_EBADARGS;
947       DmaUtilsAutoInc3d_printf(autoIncrementContext, 0, "DmaUtilsAutoInc3d_configure : Failed :autoIncrementContext == NULL \n");
948       goto Exit;
949     }
951     if ( trMem == NULL )
952     {
953       retVal = UDMA_EBADARGS;
954       DmaUtilsAutoInc3d_printf(autoIncrementContext, 0, "DmaUtilsAutoInc3d_configure : Failed : trMem == NULL \n");
955       goto Exit;
956     }
958     dmautilsContext = (DmaUtilsAutoInc3d_Context *)autoIncrementContext;
960     channelContext = dmautilsContext->channelContext[channelId];
961     channelHandle = &channelContext->chHandle;
963     if ( numTr > DMAUTILS_MAX_NUM_TR_DIRECT_TR_MODE)
964     {
965         isRingBasedFlowReq = 1U;
966     }
968     if ( isRingBasedFlowReq  == 0U)
969     {
971         CSL_UdmapTR * tr;
973         tr = ( CSL_UdmapTR *)trMem;
975         /* Submit the TR using atomic write */
976         //:TODO: currently host emulation doesn't handle multiple TR in direct TR mode
977         for ( i = 0; i < numTr; i++)
978         {
979 #ifndef HOST_EMULATION
980               Udma_chDruSubmitTr(channelHandle, tr + i);
981 #else
982               druChannelNum = Udma_chGetNum(channelHandle);
983               hostEmulation_druChSubmitAtomicTr(dmautilsContext->initParams.udmaDrvHandle->utcInfo[UDMA_UTC_ID_MSMC_DRU0].druRegs,
984                                                                                 druChannelNum , (void *)tr);
985 #endif
986         }
987     }
988     else
989     {
990       uint32_t cqRingNum = Udma_chGetCqRingNum(channelHandle);
992       CSL_UdmapCppi5TRPD * pTrpd = (CSL_UdmapCppi5TRPD *)trMem;
994       /* Update the cq ring number as it was not set correctly during descriptor preperation */
995       CSL_udmapCppi5SetReturnPolicy(
996               pTrpd,
997               CSL_UDMAP_CPPI5_PD_DESCINFO_DTYPE_VAL_TR,
998               CSL_UDMAP_CPPI5_PD_PKTINFO2_RETPOLICY_VAL_ENTIRE_PKT,
999               CSL_UDMAP_CPPI5_PD_PKTINFO2_EARLYRET_VAL_NO,
1000               CSL_UDMAP_CPPI5_PD_PKTINFO2_RETPUSHPOLICY_VAL_TO_TAIL,
1001               cqRingNum);
1003       Udma_ringQueueRaw(Udma_chGetFqRingHandle(channelHandle),
1004               (uint64_t)trMem);
1006 #ifdef HOST_EMULATION
1007       CSL_UdmapTR           *pTr = (CSL_UdmapTR *)(trMem + sizeof(CSL_UdmapTR));
1009       druChannelNum = (channelHandle->extChNum - channelHandle->utcInfo->startCh);
1010       hostEmulation_druChSubmitAtomicTr(dmautilsContext->initParams.udmaDrvHandle->utcInfo[UDMA_UTC_ID_MSMC_DRU0].druRegs,
1011                                                                         druChannelNum,
1012                                                                         (void *)pTr);
1014       /* Use this field to track the TR, For the target build this would be handled by hardware */
1015       /* In real hardware this will not be like this it is done just for host emulation*/
1016       dmautilsContext->initParams.udmaDrvHandle->utcInfo[UDMA_UTC_ID_MSMC_DRU0].druRegs->CHATOMIC[druChannelNum].DEBUG[1].NEXT_TR_WORD0_1 = 1;
1018 #endif
1019     }
1021     dmautilsContext->blkIdx[channelId] = DmaUtilsAutoInc3d_getTotalBlockCount(trMem, numTr);
1022 Exit :
1024     return retVal;
1029 int32_t DmaUtilsAutoInc3d_trigger(void * autoIncrementContext, int32_t channelId)
1031     DmaUtilsAutoInc3d_Context              * dmautilsContext;
1033     dmautilsContext = (DmaUtilsAutoInc3d_Context *)autoIncrementContext;
1035     CSL_druChSetGlobalTrigger0Raw(dmautilsContext->channelContext[channelId]->swTriggerPointer);//:TODO: This should be replaced by something else as we are not suppose to directly use these registers
1036 #ifdef HOST_EMULATION
1037     hostEmulation_updateTriggerCount(dmautilsContext->initParams.udmaDrvHandle,
1038                                                      dmautilsContext->channelContext[channelId]->swTriggerPointer);
1039 #endif
1041     dmautilsContext->blkIdx[channelId]--;
1043     return dmautilsContext->blkIdx[channelId];
1048 void  DmaUtilsAutoInc3d_wait(void * autoIncrementContext, int32_t channelId)
1050     DmaUtilsAutoInc3d_Context              * dmautilsContext;
1052     dmautilsContext = (DmaUtilsAutoInc3d_Context *)autoIncrementContext;
1054 #ifndef HOST_EMULATION
1055     volatile uint64_t eflRegisterVal;
1056     uint64_t waitWord;
1058     waitWord = dmautilsContext->channelContext[channelId]->waitWord;
1059     eflRegisterVal = __get_indexed(__EFR,0);
1060     while((eflRegisterVal & waitWord ) != waitWord )
1061     {
1062       eflRegisterVal = __get_indexed(__EFR,0);
1063     }
1064     __set_indexed(__EFCLR,0, waitWord);
1065 #else
1066     /* Do the actual Transfer for host emulation*/
1067     hostEmulation_triggerDMA(dmautilsContext->initParams.udmaDrvHandle);
1068 #endif
1070     return;
1074 int32_t DmaUtilsAutoInc3d_deconfigure(void * autoIncrementContext, int32_t channelId, uint8_t * trMem, int32_t numTr)
1076     int32_t     retVal = UDMA_SOK;
1077     DmaUtilsAutoInc3d_Context              * dmautilsContext;
1078     DmaUtilsAutoInc3d_ChannelContext * channelContext;
1079     uint32_t isRingBasedFlowReq =0;
1080     Udma_ChHandle channelHandle;
1081 #ifdef HOST_EMULATION
1082     uint32_t druChannelNum;
1083 #endif
1084     if ( autoIncrementContext == NULL)
1085     {
1086       retVal = UDMA_EBADARGS;
1087       DmaUtilsAutoInc3d_printf(autoIncrementContext, 0, "DmaUtilsAutoInc3d_configure : Failed :autoIncrementContext == NULL \n");
1088       goto Exit;
1089     }
1091     if ( trMem == NULL )
1092     {
1093       retVal = UDMA_EBADARGS;
1094       DmaUtilsAutoInc3d_printf(autoIncrementContext, 0, "DmaUtilsAutoInc3d_configure : Failed : trMem == NULL \n");
1095       goto Exit;
1096     }
1098     dmautilsContext = ( DmaUtilsAutoInc3d_Context *)autoIncrementContext;
1100     channelContext = dmautilsContext->channelContext[channelId];
1101     channelHandle = &channelContext->chHandle;
1104     /* disable  The channel */
1105     if ( numTr > DMAUTILS_MAX_NUM_TR_DIRECT_TR_MODE)
1106     {
1107         isRingBasedFlowReq = 1U;
1108     }
1110     if ( isRingBasedFlowReq  == 1 )
1111     {
1112        uint64_t    pDesc = 0;
1113       retVal = Udma_ringDequeueRaw(Udma_chGetCqRingHandle(channelHandle), &pDesc);
1114       if(UDMA_SOK != retVal)
1115       {
1116           DmaUtilsAutoInc3d_printf(autoIncrementContext, 0, "DmaUtilsAutoInc3d_deconfigure : Failed : Udma_ringDequeueRaw\n");
1117           retVal = UDMA_EFAIL;
1118           goto Exit;
1119       }
1120     }
1122 Exit:
1123     return retVal;
1128 int32_t DmaUtilsAutoInc3d_deinit(void * autoIncrementContext)
1130     int32_t     retVal = UDMA_SOK;
1131     DmaUtilsAutoInc3d_Context              * dmautilsContext;
1132     DmaUtilsAutoInc3d_ChannelContext * channelContext;
1133     Udma_ChHandle channelHandle;
1134     int32_t i;
1135     if ( autoIncrementContext == NULL)
1136     {
1137         retVal = UDMA_EBADARGS;
1138         DmaUtilsAutoInc3d_printf(autoIncrementContext, 0, "DmaUtilsAutoInc3d_configure : Failed :autoIncrementContext == NULL \n");
1139         goto Exit;
1140     }
1142     dmautilsContext = ( DmaUtilsAutoInc3d_Context *)autoIncrementContext;
1143     for ( i = 0; i < dmautilsContext->initParams.numChannels; i++)
1144      {
1145          channelContext = dmautilsContext->channelContext[i];
1146          channelHandle = &(channelContext->chHandle);
1148 #if !HOST_EMULATION
1149          /* Avoid calling chDisable API for host emulation as it depends on some of the hardware sequence
1150          which are not emulated in host emulation */
1151          retVal = Udma_chDisable(channelHandle, UDMA_DEFAULT_CH_DISABLE_TIMEOUT);
1152 #endif
1153          if(UDMA_SOK != retVal)
1154          {
1155              DmaUtilsAutoInc3d_printf(autoIncrementContext, 0, "DmaUtilsAutoInc3d_deconfigure : Failed : Udma_chDisable\n");
1156              retVal = UDMA_EFAIL;
1157              goto Exit;
1158          }
1160          retVal = Udma_chClose(channelHandle);
1161          if(UDMA_SOK != retVal)
1162          {
1163              DmaUtilsAutoInc3d_printf(autoIncrementContext, 0, "DmaUtilsAutoInc3d_deinit : Udma_chClose : Failed \n");
1164             goto Exit;
1165          }
1166     }
1167 Exit:
1169     return retVal;