/* ARGSUSED - this line tells the compiler to not generate compiler warnings * for unused arguments */ Int smain(Int argc, Char * argv[]) { Int scratchId1 = 0; Int scratchId2 = 0; IALG_Status algStatus; IALG_Fxns * algFxns = &DUMRES_TI_IALG; IRES_Fxns * resFxns = &DUMRES_TI_IRES; DUMRES_TI_Handle algHandle1 = NULL; DUMRES_TI_Handle algHandle2 = NULL; EDMA3_RM_Handle rmHandle = NULL; EDMA3_RM_ResDesc resObj; MEM_Stat stat; Bool retVal; Int i = 0; /* * Create 2 instances of the algorithm using "algFxns" */ algHandle1 = (DUMRES_TI_Handle)DSKT2_createAlg(scratchId1, (IALG_Fxns *)algFxns, NULL,(IALG_Params *)NULL); if (algHandle1 == NULL) { printf("Alg creation failed for algHandle1\n"); return -1; } algHandle2 = (DUMRES_TI_Handle)DSKT2_createAlg(scratchId2, (IALG_Fxns *)algFxns, NULL,(IALG_Params *)NULL); if (algHandle2 == NULL) { printf("Alg creation failed for algHandle2\n"); return -1; } /* Assign resources to the algorithm */ if (IRES_OK != RMAN_assignResources((IALG_Handle)algHandle1, resFxns, scratchId1)) { GT_0trace(ti_sdo_fc_rman_examples_scratchEdma3_GTMask, GT_7CLASS, "Assign Resource Failed \n"); goto AppEnd1; } /* * Activate the Algorithm */ DSKT2_activateAlg(scratchId1, (IALG_Handle)algHandle1); /* * Activate All Resources */ RMAN_activateAllResources((IALG_Handle)algHandle1, resFxns, scratchId1); /* * Use IALG interfaces to do something */ DSKT2_controlAlg((IALG_Handle)algHandle1, (IALG_Cmd)NULL, &algStatus); /* Assign resources to the second algorithm */ if (IRES_OK != RMAN_assignResources((IALG_Handle)algHandle2, resFxns, scratchId2)) { printf("Assign Resource Failed \n"); return -1; } /* * Deactivate All Resources */ RMAN_deactivateAllResources((IALG_Handle)algHandle1, resFxns, scratchId1); /* * Deactivate algorithm */ DSKT2_deactivateAlg(scratchId1, (IALG_Handle)algHandle1); /* * Activate the Algorithm */ DSKT2_activateAlg(scratchId2, (IALG_Handle)algHandle2); /* * Activate All Resources */ RMAN_activateAllResources((IALG_Handle)algHandle2, resFxns, scratchId2); /* * Free resources assigned to this algorihtm */ if (IRES_OK != RMAN_freeResources((IALG_Handle)(algHandle1), resFxns, scratchId1)) { printf("Free Resource Failed \n"); return -1; } /* * Acquire the EDMA3 handle first */ rmHandle = EDMA3_getResourceManager(NULL, -1); if (NULL == rmHandle) { printf("Error obtaining SYSTEM resource Manager Handle \n"); return (-1); } resObj.resId = 151; resObj.type = EDMA3_RM_RES_PARAM_SET; if (EDMA3_RM_SOK != EDMA3_RM_allocResource(rmHandle, &resObj)) { printf("Could not allocate this resource, as it is already owned by " "the algorithm\n"); } resObj.resId = 256; if (EDMA3_RM_SOK != EDMA3_RM_allocResource(rmHandle, &resObj)) { printf("Error, could not allocate resource %d\n" "ERROR for 6467, OK for 6446\n", resObj.resId); } if (EDMA3_RM_SOK != EDMA3_releaseResourceManager(NULL, -1)) { printf("Error releasing system resource manager handle\n"); } /* * Deactivate All Resources */ RMAN_deactivateAllResources((IALG_Handle)algHandle2, resFxns, scratchId2); /* * Deactivate algorithm */ DSKT2_deactivateAlg(scratchId2, (IALG_Handle)algHandle2); /* * Free resources assigned to this algorihtm */ if (IRES_OK != RMAN_freeResources((IALG_Handle)(algHandle2), resFxns, scratchId2)) { printf("Free Resource Failed \n"); return -1; } AppEnd1: /* * Free instance of the algorithm created */ DSKT2_freeAlg(scratchId1, (IALG_Handle)algHandle1); /* * Free instance of the algorithm created */ DSKT2_freeAlg(scratchId2, (IALG_Handle)algHandle2); /* * Unregister the protocol */ if (IRES_OK != RMAN_unregister(&IRESMAN_EDMA3CHAN)) { printf("Unregister Protocol Failed \n"); return -1; } for (i = 0; i < MAXMEMSEGMENTS; i++) { retVal = MEM_stat(i, &stat); if (!retVal) { GT_assert(ti_sdo_fc_rman_examples_scratchEdma3_GTMask, memStat[i].size == 0); } else { if (memStat[i].used != stat.used) { GT_3trace(ti_sdo_fc_rman_examples_scratchEdma3_GTMask, GT_7CLASS, "MEM seg [%d]: orig used = 0x%x, " "curr used = 0x%x", i, memStat[i].used, stat.used); return (-1); } } } RMAN_exit(); return (0); }
/* ARGSUSED - this line tells the compiler not to warn about unused args */ IRES_Handle IRESMAN_EDMA3CHAN_getHandles( IALG_Handle algHandle, IRES_ProtocolArgs * protocolArgs, Int scratchGroupId, IRES_Status * status) { EDMA3_ResDesc resObj; IALG_MemRec protocolMemRecs[IRESMAN_PROTOCOL_EDMA3CHAN_MAX_MEMRECS]; IALG_MemRec constructHandleMemRec; Int numMemRecs; EDMA3_Handle rmHandle; short reqEdma = IRES_EDMA3CHAN_CHAN_NONE; short reqQdma = IRES_EDMA3CHAN_CHAN_NONE; short edma3Chan = IRES_EDMA3CHAN_CHAN_NONE; short qdmaChan = IRES_EDMA3CHAN_CHAN_NONE; short numPaRams = 0; short numTccs = 0; short paRamArray[IRES_EDMA3CHAN_MAXPARAMS] = { EDMA3_RES_ANY }; short tccArray[IRES_EDMA3CHAN_MAXTCCS] = { EDMA3_RES_ANY }; short toFreeTccs = 0; short toFreeParams = 0; short reqParam = IRES_EDMA3CHAN_PARAM_NONE; short reqTcc = IRES_EDMA3CHAN_TCC_NONE; unsigned int cccfg = 0x0; int i = 0; IRESMAN_EDMA3CHAN_ConstructHandleArgs * constructArgs = NULL; IRES_Handle resourceHandle = NULL; /* * Cast the protocolArgs */ IRES_EDMA3CHAN_ProtocolArgs * configArgs = (IRES_EDMA3CHAN_ProtocolArgs *) protocolArgs; GT_assert(CURTRACE, protocolArgs); GT_2trace(CURTRACE, GT_ENTER, "IRESMAN_EDMA3CHAN_getHandles> Enter (protocolArgs=0x%x, " "scratchGroupId=%d)\n", protocolArgs, scratchGroupId); if (_initialized != 1) { GT_0trace(CURTRACE, GT_7CLASS, "IRESMAN_EDMA3CHAN_getHandles> RMAN_register call has not " "happened successfully\n. Please register EDMA3CHAN resource " "with RMAN before assigning resources\n"); *status = IRES_ENORESOURCE; return (NULL); } if (configArgs->mode == IRES_PERSISTENT) { scratchGroupId = -1; } else if (configArgs->mode == IRES_LATEACQUIRE) { //Set to MAX SCRATCH GROUPS scratchGroupId = EDMA3_LATEACQUIREGROUP; GT_0trace(CURTRACE, GT_4CLASS, "IRESMAN_EDMA3CHAN_getHandles> Requested IRES_LATEACQUIRE " "HDVICP resources. Ensure you \"lock\" resources using " "IRES RESUTILS API before using them for correct operation\n"); } rmHandle = EDMA3_getResourceManager(algHandle, scratchGroupId); if (NULL == rmHandle) { *status = IRES_ENORESOURCE; GT_0trace(CURTRACE, GT_7CLASS, "IRESMAN_EDMA3CHAN_getHandles> Error obtaining Low level " "Resource Manager Handle.\n"); GT_0trace(CURTRACE, GT_ENTER, "IRESMAN_EDMA3CHAN_getHandles> Exit (handle=NULL, " "status=IRES_ENORESOURCE)\n"); return (NULL); } if (EDMA3_SOK != EDMA3_getCCRegister( rmHandle , 4, &cccfg)) { *status = IRES_EFAIL; GT_0trace(CURTRACE, GT_7CLASS, "IRESMAN_EDMA3CHAN_getHandles> Error reading EDMA3's CCCFG " "Register.\n"); GT_0trace(CURTRACE, GT_ENTER, "IRESMAN_EDMA3CHAN_getHandles> Exit (handle=NULL, " "status=IRES_EFAIL)\n"); if (EDMA3_SOK != EDMA3_releaseResourceManager(algHandle, scratchGroupId)) { *status = IRES_EFAIL; GT_0trace(CURTRACE, GT_7CLASS, "IRESMAN_EDMA3CHAN_getHandles> Error releasing Low level " "Resource Manager Handle.\n"); } return (NULL); } _dchmapExists = IRES_EDMA3CHAN_EDMA3REGISTERLAYER_CHMAPEXIST(cccfg); if (_dchmapExists) { GT_0trace(CURTRACE, GT_2CLASS, "IRESMAN_EDMA3CHAN_getHandles> DCHMAP exists on device ??\n"); GT_assert(CURTRACE, 0); } numPaRams = configArgs->numPaRams; numTccs = configArgs->numTccs; GT_assert(CURTRACE, numPaRams <= IRES_EDMA3CHAN_MAXPARAMS); GT_assert(CURTRACE, numTccs <= IRES_EDMA3CHAN_MAXTCCS); reqEdma = configArgs->edmaChan; reqQdma = configArgs->qdmaChan; if (configArgs->numPaRams != 0) { reqParam = configArgs->paRamIndex; } if (configArgs->numTccs != 0) { reqTcc = configArgs->tccIndex; } if (IRES_EDMA3CHAN_TCC_NONE == reqTcc) { GT_assert(CURTRACE, numTccs == 0); } if (IRES_EDMA3CHAN_PARAM_NONE == reqParam) { GT_assert(CURTRACE, numPaRams == 0); } if ((reqEdma != IRES_EDMA3CHAN_EDMACHAN_ANY) && (reqEdma != IRES_EDMA3CHAN_CHAN_NONE) && ((reqEdma < 0) || (reqEdma >= 64 ))) { GT_0trace(CURTRACE, GT_6CLASS, "IRESMAN_EDMA3CHAN_getHandles> Bad request for EDMA channel. " "Will not grant request EDMA channel\n"); reqEdma = IRES_EDMA3CHAN_CHAN_NONE; } if ((reqQdma != IRES_EDMA3CHAN_QDMACHAN_ANY) && (reqQdma != IRES_EDMA3CHAN_CHAN_NONE) && ((reqQdma < 0) || (reqQdma >= 8))) { GT_0trace(CURTRACE, GT_6CLASS, "IRESMAN_QDMA3CHAN_getHandles> Bad request for EDMA channel. " "Will not grant request QDMA channel\n"); reqQdma = IRES_EDMA3CHAN_CHAN_NONE; } /* 1. Couple request into Logical EDMA channel request 2. Couple request into Logical QDMA channel request 3. Couple request for multiple (or the rest of the paRams) into contigPaRams request 4. Request rest of the QDMA channels required -> will waste resources 5. Request rest of the TCCs required -> will waste resources */ if ((numPaRams > 0) && (numTccs > 0)) { /* 1. */ if (IRES_EDMA3CHAN_CHAN_NONE != reqEdma) { /* If request is for EDMA N, then PaRam and TCC should be requested of the same number or ANY */ if ((reqEdma != IRES_EDMA3CHAN_EDMACHAN_ANY) && ((IRES_EDMA3CHAN_PARAM_ANY == reqParam) || (reqEdma == reqParam)) && ((IRES_EDMA3CHAN_TCC_ANY == reqTcc) || (reqEdma == reqTcc))) { /* Allocate Logical E Channel N and decrement numTccs and numPaRams and change reqEdma to NONE ? */ resObj.type = EDMA3_RES_DMA_CHANNEL; resObj.resId = reqEdma; tccArray[toFreeTccs] = reqEdma; /* Requesting tcc == edma */ paRamArray[toFreeParams] = reqEdma; if (EDMA3_SOK != EDMA3_allocLogicalChannel(rmHandle, &resObj, (unsigned int *)&paRamArray[toFreeParams], (unsigned int *)&tccArray[toFreeTccs])) { *status = IRES_ENORESOURCE; goto getResmanHandleFail; } edma3Chan = resObj.resId; toFreeParams++; toFreeTccs++; numPaRams--; numTccs--; reqEdma = IRES_EDMA3CHAN_CHAN_NONE; } /* If request is for EDMA ANY and P N or ANY and TCC N or any */ else if ((IRES_EDMA3CHAN_TCC_ANY == reqTcc) || (reqParam == IRES_EDMA3CHAN_PARAM_ANY) || (reqParam == reqTcc)) { /* Allocate logical E Channel #"TCC/PaRAM/ANY" and decrement numTccs and numPaRams */ resObj.type = EDMA3_RES_DMA_CHANNEL; resObj.resId = ((IRES_EDMA3CHAN_PARAM_ANY == reqParam) ? ((IRES_EDMA3CHAN_TCC_ANY == reqTcc) ? EDMA3_RES_ANY : reqTcc) : reqParam); tccArray[toFreeTccs] = resObj.resId; /* Requesting tcc = edma */ paRamArray[toFreeParams] = resObj.resId; if (EDMA3_SOK != EDMA3_allocLogicalChannel(rmHandle, &resObj, (unsigned int *)&paRamArray[toFreeParams], (unsigned int *)&tccArray[toFreeTccs])) { *status = IRES_ENORESOURCE; goto getResmanHandleFail; } edma3Chan = resObj.resId; toFreeParams++; toFreeTccs++; numPaRams--; numTccs--; reqEdma = IRES_EDMA3CHAN_CHAN_NONE; /* If a logical channel was requested, then any other param request cannot have a specific param number */ reqParam = IRES_EDMA3CHAN_PARAM_ANY; reqTcc = IRES_EDMA3CHAN_TCC_ANY; } } /* 2. */ else if (IRES_EDMA3CHAN_CHAN_NONE != reqQdma) { /* If request is for QDMA N or QDMA Any, P should be ANY */ if (IRES_EDMA3CHAN_PARAM_ANY == reqParam) { /* Allocate Logical Q Channel N and decrement numTccs and numPaRams */ resObj.type = EDMA3_RES_QDMA_CHANNEL; resObj.resId = ((IRES_EDMA3CHAN_QDMACHAN_ANY == reqQdma) ? EDMA3_RES_ANY : reqQdma); /* Requesting tcc as required*/ tccArray[toFreeTccs] = (IRES_EDMA3CHAN_TCC_ANY == reqTcc) ? EDMA3_RES_ANY : reqTcc; paRamArray[toFreeParams] = EDMA3_RES_ANY; if (EDMA3_SOK != EDMA3_allocLogicalChannel(rmHandle, &resObj, (unsigned int *)&paRamArray[toFreeParams], (unsigned int *)&tccArray[toFreeTccs])) { *status = IRES_ENORESOURCE; goto getResmanHandleFail; } qdmaChan = resObj.resId; toFreeParams++; toFreeTccs++; numPaRams--; numTccs--; reqQdma = IRES_EDMA3CHAN_CHAN_NONE; /* If a logical channel was requested, then any other param request cannot have a specific param number */ reqParam = IRES_EDMA3CHAN_PARAM_ANY; reqTcc = IRES_EDMA3CHAN_TCC_ANY; } } } /* 3. */ /* Alloc contiguous or Not P */ if (numPaRams > 0) { resObj.type = EDMA3_RES_PARAM_SET; if ((numPaRams > 1) && configArgs->contiguousAllocation) { GT_0trace(CURTRACE, GT_4CLASS, "IRESMAN_EDMA3CHAN_getHandles> Contiguous PaRams " "requested\n"); resObj.resId = (reqParam == IRES_EDMA3CHAN_PARAM_ANY)? EDMA3_RES_ANY: reqParam; if (EDMA3_SOK != EDMA3_allocContiguousResource( rmHandle, &resObj, numPaRams)) { *status = IRES_ENORESOURCE; goto getResmanHandleFail; } else { for (i = 0; i < numPaRams; i++) { paRamArray[i+toFreeParams] = resObj.resId + i; } GT_2trace(CURTRACE, GT_4CLASS, "IRESMAN_EDMA3CHAN_getHandles> Obtained %d PaRams " "starting at %d \n", numPaRams, paRamArray[toFreeParams]); toFreeParams += numPaRams; } numPaRams = 0; } else { GT_0trace(CURTRACE, GT_4CLASS, "IRESMAN_EDMA3CHAN_getHandles> Contiguous PaRams " "NOT required\n"); if (numPaRams == 1) { resObj.resId =(reqParam == IRES_EDMA3CHAN_PARAM_ANY)? EDMA3_RES_ANY: reqParam; } else { /* Multiple non-contig PaRams should always be requested as ANY */ resObj.resId = EDMA3_RES_ANY; } /* * Allocate the PaRams individually */ for (i = 0; i < numPaRams; i++) { if (EDMA3_SOK != EDMA3_allocResource( rmHandle,&resObj)) { *status = IRES_ENORESOURCE; goto getResmanHandleFail; } else { paRamArray[toFreeParams] = resObj.resId; GT_1trace(CURTRACE, GT_4CLASS, "IRESMAN_EDMA3CHAN_getHandles> Obtained Param %d\n" , paRamArray[toFreeParams]); toFreeParams++; resObj.resId = EDMA3_RES_ANY; } } numPaRams = 0; } } /* 4 */ if (IRES_EDMA3CHAN_CHAN_NONE != reqEdma) { resObj.type = EDMA3_RES_DMA_CHANNEL; resObj.resId = ( IRES_EDMA3CHAN_EDMACHAN_ANY == reqEdma) ? EDMA3_RES_ANY: reqEdma; GT_1trace(CURTRACE, GT_2CLASS, "IRESMAN_EDMA3CHAN_getHandles> Requesting individual EDMA " "channel %d, might cause resource wastage !\n", resObj.resId); if (EDMA3_SOK != EDMA3_allocResource( rmHandle,&resObj)) { *status = IRES_ENORESOURCE; goto getResmanHandleFail; } reqEdma = IRES_EDMA3CHAN_CHAN_NONE; edma3Chan = resObj.resId; } if (IRES_EDMA3CHAN_CHAN_NONE != reqQdma) { resObj.type = EDMA3_RES_QDMA_CHANNEL; resObj.resId = (IRES_EDMA3CHAN_QDMACHAN_ANY == reqQdma) ? EDMA3_RES_ANY: reqQdma; GT_1trace(CURTRACE, GT_2CLASS, "IRESMAN_EDMA3CHAN_getHandles> Requesting individual Qdma " "channel %d, might cause resource wastage !\n", resObj.resId); if (EDMA3_SOK != EDMA3_allocResource( rmHandle,&resObj)) { *status = IRES_ENORESOURCE; goto getResmanHandleFail; } reqQdma = IRES_EDMA3CHAN_CHAN_NONE; qdmaChan = resObj.resId; } if (numTccs > 0) { resObj.type = EDMA3_RES_TCC; if ((toFreeTccs > 0) || (numTccs > 1)) { /* If requesting multiple TCCs then use ANY to request */ resObj.resId = EDMA3_RES_ANY; } else { resObj.resId = ((reqTcc == IRES_EDMA3CHAN_TCC_ANY)? EDMA3_RES_ANY:((unsigned int)reqTcc)); } GT_1trace(CURTRACE, GT_2CLASS, "IRESMAN_EDMA3CHAN_getHandles> Requesting %d individual Tcc(s)," "might cause resource wastage !\n", numTccs); for(i = 0 ; i < numTccs; i++) { if (EDMA3_SOK != EDMA3_allocResource( rmHandle, &resObj)) { *status = IRES_ENORESOURCE; goto getResmanHandleFail; } tccArray[toFreeTccs] = resObj.resId; resObj.resId = EDMA3_RES_ANY; GT_1trace(CURTRACE, GT_4CLASS, "IRESMAN_EDMA3CHAN_getHandles> Obtained TCC %d\n", tccArray[toFreeTccs]); toFreeTccs++; } numTccs = 0; } /* Do construct handle stuff here */ /* * To call the Construct handle protocol interface, first construct the * arguments that need to be passed IRES_EDMA3CHAN_ConstructHandleArgs * This has the list of actual params that need to be sent back as handle */ /* * Allocate memory for the constructHandle Arguments */ constructHandleMemRec.size = sizeof(IRESMAN_EDMA3CHAN_ConstructHandleArgs); constructHandleMemRec.alignment = 4; constructHandleMemRec.space = IALG_EXTERNAL; constructHandleMemRec.attrs = IALG_PERSIST; if (FALSE == _allocFxn(&constructHandleMemRec, 1)) { *status = IRES_ENOMEM; GT_1trace(CURTRACE, GT_7CLASS, "IRESMAN_EDMA3CHAN_getHandles> Memory allocation for size 0x%x," " of Persistent External memory failed\n", constructHandleMemRec.size); goto getResmanHandleFail; } GT_assert(CURTRACE, IALG_EXTERNAL == constructHandleMemRec.space); constructArgs = constructHandleMemRec.base; constructArgs->numPaRams = toFreeParams; constructArgs->paRamIndex = paRamArray; constructArgs->edma3Chan = edma3Chan; constructArgs->qdmaChan = qdmaChan; constructArgs->tccIndex = tccArray; constructArgs->numTccs = toFreeTccs; if (scratchGroupId == -1) { constructArgs->persistent = TRUE; } else { constructArgs->persistent = FALSE; } if ( EDMA3_SOK != EDMA3_getBaseAddress(rmHandle, EDMA3_CC_PHY_ADDR, &(constructArgs->edma3CCBaseAddress))) { _freeFxn(&constructHandleMemRec, 1); GT_0trace(CURTRACE, GT_7CLASS, "IRESMAN_EDMA3CHAN_getHandles> Call to obtain base address " "of EDMA3 device failed\n"); *status = IRES_EFAIL; goto getResmanHandleFail; } /* * Get IRES_EDMA3CHAN_RESOURCEPROTOCOL's memory requirements */ numMemRecs = IRESMAN_EDMA3CHAN_CONSTRUCTFXNS.getNumMemRecs ((IRES_ProtocolArgs *) protocolArgs); GT_assert(CURTRACE, numMemRecs <= IRESMAN_PROTOCOL_EDMA3CHAN_MAX_MEMRECS); /* * Get the memory requirements of the protocol in resMemRecs */ IRESMAN_EDMA3CHAN_CONSTRUCTFXNS.getMemRecs((IRES_Handle)NULL, (IRES_ProtocolArgs *) protocolArgs, protocolMemRecs); /* * Allocate that memory */ if (FALSE == _allocFxn(protocolMemRecs, numMemRecs)) { _freeFxn(&constructHandleMemRec, 1); *status = IRES_ENOMEM; GT_1trace(CURTRACE, GT_7CLASS, "IRESMAN_EDMA3CHAN_getHandles> Memory allocation for size 0x%x," " of Persistent External memory failed\n", protocolMemRecs[0].size); goto getResmanHandleFail; } for (i=0; i < numMemRecs; i++) { GT_assert(CURTRACE, protocolMemRecs[i].space == IALG_EXTERNAL); } /* * Construct the resource protocol handle */ resourceHandle = IRESMAN_EDMA3CHAN_CONSTRUCTFXNS.constructHandle( protocolArgs, protocolMemRecs, (IRESMAN_ConstructArgs *)constructArgs, status); GT_assert(CURTRACE, resourceHandle != NULL); /* * Free constructArgs memory, that was just to pass the arguments */ _freeFxn(&constructHandleMemRec, 1); *status = IRES_OK; GT_1trace(CURTRACE, GT_ENTER, "IRESMAN_EDMA3CHAN_getHandles> Exit (handle=0x%x, " "status=IRES_OK)\n", resourceHandle); /* return */ return (resourceHandle); getResmanHandleFail: /* fail code comes here, free resources and leave */ _freeResource(algHandle, scratchGroupId, edma3Chan, qdmaChan, toFreeParams, paRamArray, toFreeTccs, tccArray, configArgs->contiguousAllocation); GT_2trace(CURTRACE, GT_7CLASS, "IRESMAN_EDMA3CHAN_getHandles> Could not allocate requested " "resource of type %d Id %d\n", resObj.type, resObj.resId); if (EDMA3_SOK != EDMA3_releaseResourceManager(algHandle, scratchGroupId)) { *status = IRES_EFAIL; GT_0trace(CURTRACE, GT_7CLASS, "IRESMAN_EDMA3CHAN_getHandles> Error releasing Low " "level Resource Manager Handle.\n"); } *status = IRES_ENORESOURCE; GT_1trace(CURTRACE, GT_ENTER, "IRESMAN_EDMA3CHAN_getHandles> Exit (handle=NULL, status=%d)\n", *status); return (NULL); }
/* * ======== _freeResource ======== * Actually free resources from the EDMA3 Low Level Resource Manager Handle */ static inline IRES_Status _freeResource(IALG_Handle algHandle, Int scratchGroupId, short edma3Chan, short qdmaChan, short numPaRams, short * paRamIndex, short numTccs, short * tccIndex, Bool contigRequest) { EDMA3_ResDesc resObj; IRES_Status status = IRES_OK; EDMA3_Result result = EDMA3_SOK; EDMA3_Handle rmHandle; int i; short toFreeTccs = 0; short toFreeParams = 0; Bool contig = FALSE; /* TODO: Don't need to do anything for scratchGroupId != -1 */ GT_6trace(CURTRACE, GT_ENTER, "_freeResource> Enter " "(algHandle=0x%x, scratchGroupId=%d, edma3Chan=%d, qdmaChan=%d, " "numPaRams=%d, numTccs=0x%x\n)", algHandle, scratchGroupId, edma3Chan, qdmaChan, numPaRams, numTccs); /* * Obtain Resource Manager handle corresponding to this algorithm in this * scratch Group */ rmHandle = EDMA3_getResourceManager(algHandle, scratchGroupId); /* 1. Couple request into Logical EDMA channel request 2. Couple request into Logical QDMA channel request 3. Couple request for multiple (or the rest of the paRams) into contigPaRams request 4. Request rest of the QDMA channels required -> will waste resources 5. Request rest of the TCCs required -> will waste resources */ if ((numPaRams > 0) && (numTccs > 0)) { /* 1. */ if (IRES_EDMA3CHAN_CHAN_NONE != edma3Chan) { /* If free request is for EDMA N, then PaRam and TCC should be of the same number */ /* TODO: Assuming ordering of resources, maybe should search instead */ if ((edma3Chan == tccIndex[toFreeTccs]) && (edma3Chan == paRamIndex[toFreeParams])) { resObj.type = EDMA3_RES_DMA_CHANNEL; resObj.resId = edma3Chan; tccIndex[toFreeTccs] = edma3Chan; /* Requesting tcc == edma */ if (EDMA3_SOK != EDMA3_freeLogicalChannel(rmHandle, &resObj)) { //TODO: Blind release of logical channel, double check //, (unsigned int *)&paRamArray[toFreeParams], // (unsigned int *)&tccIndex[toFreeTccs])) status = IRES_EFAIL; goto freeResourceFail; } toFreeParams++; toFreeTccs++; numPaRams--; numTccs--; edma3Chan = IRES_EDMA3CHAN_CHAN_NONE; } } /* 2. */ else if (IRES_EDMA3CHAN_CHAN_NONE != qdmaChan) { /* If request is for QDMA N or QDMA Any, P should be ANY */ /* TO check: Basically coupling QDMA channel with first PaRam and Tcc */ resObj.type = EDMA3_RES_QDMA_CHANNEL; resObj.resId = qdmaChan; if (EDMA3_SOK != EDMA3_freeLogicalChannel(rmHandle, &resObj)) { //TODO: Blind release of logical channel, double check //, (unsigned int *)&paRamArray[toFreeParams], // (unsigned int *)&tccIndex[toFreeTccs])) status = IRES_EFAIL; goto freeResourceFail; } toFreeParams++; toFreeTccs++; numPaRams--; numTccs--; qdmaChan = IRES_EDMA3CHAN_CHAN_NONE; } } /* 3. */ /* Alloc contiguous or Not P */ if (numPaRams > 0) { resObj.type = EDMA3_RES_PARAM_SET; /* * Check if params are contiguous */ contig = _checkContig(&paRamIndex[toFreeParams], numPaRams); /* * Check if they were requested contiguously */ contig &= contigRequest; if (!contig) { /* * Free the PaRams individually */ for (i = 0; i < numPaRams; i++) { resObj.resId = paRamIndex[toFreeParams]; if (EDMA3_SOK != EDMA3_freeResource( rmHandle,&resObj)) { status = IRES_EFAIL; goto freeResourceFail; } else { toFreeParams++; } } } else { resObj.resId = paRamIndex[toFreeParams]; if (EDMA3_SOK != EDMA3_freeContiguousResource(rmHandle, &resObj, numPaRams)) { status = IRES_EFAIL; goto freeResourceFail; } else { toFreeParams += numPaRams; } numPaRams = 0; } } /* 4 */ if (IRES_EDMA3CHAN_CHAN_NONE != edma3Chan) { resObj.type = EDMA3_RES_DMA_CHANNEL; resObj.resId = edma3Chan; GT_1trace(CURTRACE, GT_2CLASS, "IRESMAN_EDMA3CHAN_getHandles> Freeing individual EDMA " "channel %d, might cause other resources to be freed!\n", resObj.resId); if (EDMA3_SOK != EDMA3_freeResource( rmHandle,&resObj)) { status = IRES_EFAIL; goto freeResourceFail; } edma3Chan = IRES_EDMA3CHAN_CHAN_NONE; } if (IRES_EDMA3CHAN_CHAN_NONE != qdmaChan) { resObj.type = EDMA3_RES_QDMA_CHANNEL; resObj.resId = qdmaChan; GT_1trace(CURTRACE, GT_2CLASS, "IRESMAN_EDMA3CHAN_getHandles> Freeing individual Qdma " "channel %d, might cause other resources to be freed !\n", resObj.resId); if (EDMA3_SOK != EDMA3_freeResource(rmHandle, &resObj)) { status = IRES_EFAIL; goto freeResourceFail; } qdmaChan = IRES_EDMA3CHAN_CHAN_NONE; } if (numTccs > 0) { resObj.type = EDMA3_RES_TCC; GT_1trace(CURTRACE, GT_2CLASS, "IRESMAN_EDMA3CHAN_getHandles> Freeing %d individual Tcc(s)," "might cause other resources to be freed!\n", numTccs); for(i = 0 ; i < numTccs; i++) { resObj.resId = tccIndex[toFreeTccs]; if (EDMA3_SOK != EDMA3_freeResource( rmHandle, &resObj)) { status = IRES_EFAIL; goto freeResourceFail; } GT_1trace(CURTRACE, GT_4CLASS, "IRESMAN_EDMA3CHAN_getHandles> Freed TCC %d\n", tccIndex[toFreeTccs]); toFreeTccs++; } numTccs = 0; } freeResourceFail: result = EDMA3_releaseResourceManager(algHandle, scratchGroupId); if (result != EDMA3_SOK) { status = IRES_EFAIL; } GT_1trace(CURTRACE, GT_ENTER, "_freeResource> Exit " "(status=%d)\n",status); return (status); }
/* ARGSUSED - this line tells the compiler to not generate compiler warnings * for unused arguments */ Int smain(Int argc, String argv[]) { Int scratchId1 = 0; Int scratchId2 = 1; /* IALG_Status algStatus;*/ IALG_Fxns * algFxns = &DUMRES_TI_IALG; IRES_Fxns * resFxns = &DUMRES_TI_IRES; DUMRES_TI_Handle dumHandle1 = NULL; DUMRES_TI_Handle dumHandle2 = NULL; EDMA3_Handle rmHandle = NULL; EDMA3_ResDesc resObj; Bool status = TRUE; IDUMRES_Params params; if (argc > 1) { scratchId1 = atoi(argv[1]); } if (argc > 2) { scratchId2 = atoi(argv[2]); } ALG_init(); /* * Create an instance of the algorithm using "algFxns" */ params.algNum = 1; dumHandle1 = (DUMRES_TI_Handle)ALG_create((IALG_Fxns *)algFxns, (IALG_Handle)NULL, (IALG_Params *)¶ms); if (dumHandle1 == NULL) { printf("Alg1 creation failed \n"); return -1; } params.algNum = 2; dumHandle2 = (DUMRES_TI_Handle)ALG_create((IALG_Fxns *)algFxns, (IALG_Handle)NULL, (IALG_Params *)¶ms); if (dumHandle2 == NULL) { printf("Alg2 creation failed \n"); return -1; } /* Create an instance of an algorithm that implements IALG and IRES_Fxns */ if (IRES_OK != RMAN_assignResources((IALG_Handle)dumHandle1, resFxns,scratchId1)) { printf("Assign Resource Failed \n"); status = FALSE; goto AppEnd1; } /* * Activate the Algorithm */ ALG_activate((IALG_Handle)dumHandle1); /* * Activate All Resources */ RMAN_activateAllResources((IALG_Handle)dumHandle1, resFxns, scratchId1); /* * Use IALG interfaces to do something */ //TODO: DSKT2_controlAlg((IALG_Handle)dumHandle, (IALG_Cmd)NULL, &algStatus); /* Assign resources to the second algorithm */ if (IRES_OK != RMAN_assignResources((IALG_Handle)dumHandle2, resFxns, scratchId2)) { printf("Assign Resource Failed \n"); return -1; } /* * Deactivate All Resources */ RMAN_deactivateAllResources((IALG_Handle)dumHandle1, resFxns, scratchId1); /* * Deactivate algorithm */ ALG_deactivate((IALG_Handle)dumHandle1); /* * Activate the Algorithm */ ALG_activate((IALG_Handle)dumHandle2); /* * Activate All Resources */ RMAN_activateAllResources((IALG_Handle)dumHandle2, resFxns, scratchId2); /* * Free resources assigned to this algorihtm */ if (IRES_OK != RMAN_freeResources((IALG_Handle)(dumHandle1), resFxns, scratchId1)) { printf("Free Resource Failed \n"); return -1; } /* * Acquire the EDMA3 handle first */ rmHandle = EDMA3_getResourceManager((IALG_Handle)NULL, (Int)-1); if (NULL == rmHandle) { printf("Error obtaining SYSTEM resource Manager Handle \n"); return (-1); } resObj.resId = 65; resObj.type = EDMA3_RES_PARAM_SET; if (EDMA3_SOK != EDMA3_allocResource(rmHandle, &resObj)) { printf("Note, could not allocate this resource.\n"); } resObj.resId = 126; if (EDMA3_SOK != EDMA3_allocResource(rmHandle, &resObj)) { printf("Note, could not allocate resource %d\n", resObj.resId); } if (EDMA3_SOK != EDMA3_releaseResourceManager(NULL, -1)) { printf("Note, releasing system resource manager handle\n"); } /* * Deactivate All Resources */ RMAN_deactivateAllResources((IALG_Handle)dumHandle2, resFxns, scratchId2); /* * Deactivate algorithm */ ALG_deactivate((IALG_Handle)dumHandle2); /* * Free resources assigned to this algorihtm */ if (IRES_OK != RMAN_freeResources((IALG_Handle)(dumHandle2), resFxns, scratchId2)) { printf("Free Resource Failed \n"); return -1; } AppEnd1: /* * Free instance of the algorithm created */ ALG_delete((IALG_Handle)dumHandle1); /* * Free instance of the algorithm created */ ALG_delete((IALG_Handle)dumHandle2); RMAN_exit(); if (status) printf("Application exiting normally\n"); return (0); }