/*! ****************************************************************************** @Function RESOURCE_ListEmpty ******************************************************************************/ IMG_RESULT RESOURCE_ListEmpty( LST_T * psList, IMG_BOOL bReleaseItems, RESOURCE_pfnFreeItem pfnFreeItem, IMG_VOID * pvFreeCbParam ) { RESOURCE_sListElem * psListElem = IMG_NULL; IMG_UINT32 ui32Result; /* Check input params. */ IMG_ASSERT(IMG_NULL != psList); if (psList == IMG_NULL) { ui32Result = IMG_ERROR_INVALID_PARAMETERS; goto error; } /* Remove all the buffer list elements from the image buffer list. */ psListElem = LST_removeHead(psList); while (IMG_NULL != psListElem) { if (bReleaseItems) { RESOURCE_ItemRelease(psListElem->pui32RefCount); } else { /* Return and free. */ RESOURCE_ItemReturn(psListElem->pui32RefCount); if (psListElem->pui32RefCount == IMG_NULL || *psListElem->pui32RefCount == 0) { if (pfnFreeItem) { pfnFreeItem(psListElem->pvItem, pvFreeCbParam); } else { IMG_FREE(psListElem->pvItem); } psListElem->pvItem = IMG_NULL; } } /* Free the buffer list element. */ IMG_FREE(psListElem); psListElem = IMG_NULL; /* Get the next element from the list. */ psListElem = LST_removeHead(psList); } return IMG_SUCCESS; error: return ui32Result; }
/*! ****************************************************************************** @Function perflog_CleanFile @Description Truncates performance file to zero length. @Input pFileHandler : file to be cleand @Return IMG_SUCCESS in case when file has been cleand successfully, error code otherwise ******************************************************************************/ static IMG_RESULT perflog_CleanFile(perflog_FileHandler *pFileHandler) { perflog_Buffer *psBuffer; if(pFileHandler == IMG_NULL) { REPORT(REPORT_MODULE_PERFLOG, REPORT_ERR, "Performance logger cannot clean file: invalid parameters"); return IMG_ERROR_INVALID_PARAMETERS; } SYSOSKM_LockMutex(pFileHandler->hMutexHandle); //removes all buffers psBuffer = LST_removeHead(&pFileHandler->sBufferList); while(psBuffer) { perflog_DestroyBuffer(psBuffer); psBuffer = LST_removeHead(&pFileHandler->sBufferList); } SYSOSKM_UnlockMutex(pFileHandler->hMutexHandle); return IMG_SUCCESS; }
/*! ****************************************************************************** @Function POOL_PoolSetFreeCallback ******************************************************************************/ IMG_RESULT POOL_PoolSetFreeCallback( IMG_HANDLE hPoolHandle, POOL_pfnFree pfnFree ) { POOL_sResPool * psResPool = hPoolHandle; POOL_sResource * psResource; IMG_UINT32 ui32Result; IMG_ASSERT(gInitialised); IMG_ASSERT(psResPool != IMG_NULL); if (!gInitialised || psResPool == IMG_NULL) { ui32Result = IMG_ERROR_INVALID_PARAMETERS; goto error_nolock; } /* Lock the pool...*/ SYSOSKM_LockMutex(psResPool->hMutexHandle); psResPool->pfnFree = pfnFree; /* If free callback set...*/ if (psResPool->pfnFree != IMG_NULL) { /* Move resources from free to active list...*/ psResource = (POOL_sResource *)LST_removeHead(&psResPool->sFreeResList); while (psResource != IMG_NULL) { /* Add to active list...*/ LST_add(&psResPool->sActResList, psResource); psResource->ui32RefCnt++; /* Unlock the pool...*/ SYSOSKM_UnlockMutex(psResPool->hMutexHandle); /* Call the free callback...*/ psResPool->pfnFree(psResource->ui32ResId, psResource->pvParam); /* Lock the pool...*/ SYSOSKM_LockMutex(psResPool->hMutexHandle); /* Get next free resource...*/ psResource = (POOL_sResource *)LST_removeHead(&psResPool->sFreeResList); } } /* Unlock the pool...*/ SYSOSKM_UnlockMutex(psResPool->hMutexHandle); /* Return IMG_SUCCESS...*/ return IMG_SUCCESS; error_nolock: return ui32Result; }
/*! ****************************************************************************** @Function VDECDDUTILS_FreeStrUnit ******************************************************************************/ IMG_RESULT VDECDDUTILS_FreeStrUnit( VDECDD_sStrUnit * psStrUnit ) { BSPP_sBitStrSeg * psBitStrSeg; /* Loop over bit stream segments...*/ psBitStrSeg = (BSPP_sBitStrSeg *)LST_removeHead(&psStrUnit->sBitStrSegList); while (psBitStrSeg != IMG_NULL) { /* Free segment. */ IMG_FREE(psBitStrSeg); /* Get next segment. */ psBitStrSeg = (BSPP_sBitStrSeg *)LST_removeHead(&psStrUnit->sBitStrSegList); } /* Free the sequence header...*/ if (psStrUnit->psSequHdrInfo != IMG_NULL) { psStrUnit->psSequHdrInfo->ui32RefCount--; if (psStrUnit->psSequHdrInfo->ui32RefCount == 0) { IMG_FREE(psStrUnit->psSequHdrInfo); psStrUnit->psSequHdrInfo = IMG_NULL; } } /* Free the picture header... */ if (psStrUnit->psPictHdrInfo != IMG_NULL) { if (psStrUnit->psPictHdrInfo->sPictSgmData.pvData) { IMG_FREE(psStrUnit->psPictHdrInfo->sPictSgmData.pvData); psStrUnit->psPictHdrInfo->sPictSgmData.pvData = IMG_NULL; } IMG_FREE(psStrUnit->psPictHdrInfo); psStrUnit->psPictHdrInfo = IMG_NULL; } /* Free stream unit. */ IMG_FREE(psStrUnit); psStrUnit = IMG_NULL; /* Return success...*/ return IMG_SUCCESS; }
/*! ****************************************************************************** @Function VDECDDUTILS_CreateStrUnit @Description this function allocate a structure for a complete data unit ******************************************************************************/ IMG_RESULT VDECDDUTILS_CreateStrUnit( VDECDD_sStrUnit ** ppsStrUnit, LST_T * sBSList ) { VDECDD_sStrUnit * psStrUnit; BSPP_sBitStrSeg * psBitStrSeg; VDEC_MALLOC(psStrUnit); IMG_ASSERT(psStrUnit != IMG_NULL); if (psStrUnit == IMG_NULL) { return IMG_ERROR_OUT_OF_MEMORY; } VDEC_BZERO(psStrUnit); if (sBSList != IMG_NULL) { // copy BS list to this list LST_init(&psStrUnit->sBitStrSegList); for ( psBitStrSeg = LST_first( sBSList); psBitStrSeg != NULL; psBitStrSeg = LST_first(sBSList) ) { psBitStrSeg = LST_removeHead(sBSList); LST_add(&psStrUnit->sBitStrSegList,psBitStrSeg); } } *ppsStrUnit = psStrUnit; return IMG_SUCCESS; }
/*! ****************************************************************************** @Function RESOURCE_ListRemoveHead ******************************************************************************/ IMG_VOID * RESOURCE_ListRemoveHead( LST_T * psList ) { RESOURCE_sListElem * psListElem = IMG_NULL; IMG_VOID * pvItem = IMG_NULL; /* Check input params. */ IMG_ASSERT(IMG_NULL != psList); if (psList == IMG_NULL) { goto error; } /* Peek the head item of the list. */ psListElem = LST_removeHead(psList); if (psListElem) { pvItem = psListElem->pvItem; /* Free the list element. */ IMG_FREE(psListElem); psListElem = IMG_NULL; } error: return pvItem; }
/*! ****************************************************************************** @Function VDECDDUTILS_CreateStrUnitOld @Description this function allocate a structure for a complete data unit ******************************************************************************/ IMG_RESULT VDECDDUTILS_CreateStrUnitOld( VDECDD_sStrUnit ** ppsStrUnit, BSPP_sSequHdrInfo * psSeqInfo, BSPP_sPictHdrInfo * psPicInfo, LST_T * sBSList ) { VDECDD_sStrUnit * psStrUnit; BSPP_sBitStrSeg * psBitStrSeg; VDEC_MALLOC(psStrUnit); IMG_ASSERT(psStrUnit != IMG_NULL); if (psStrUnit == IMG_NULL) { return IMG_ERROR_OUT_OF_MEMORY; } VDEC_BZERO(psStrUnit); if (sBSList != IMG_NULL) { // copy BS list to this list LST_init(&psStrUnit->sBitStrSegList); for ( psBitStrSeg = LST_first( sBSList); psBitStrSeg != NULL; psBitStrSeg = LST_first(sBSList) ) { psBitStrSeg = LST_removeHead(sBSList); LST_add(&psStrUnit->sBitStrSegList,psBitStrSeg); } } if(psSeqInfo !=IMG_NULL) { psStrUnit->psSequHdrInfo = psSeqInfo; psStrUnit->psSequHdrInfo->ui32RefCount = 1; } psStrUnit->psPictHdrInfo = psPicInfo; *ppsStrUnit = psStrUnit; return IMG_SUCCESS; }
/*! ****************************************************************************** @Function POOL_PoolDestroy ******************************************************************************/ IMG_RESULT POOL_PoolDestroy( IMG_HANDLE hPoolHandle ) { POOL_sResPool * psResPool = hPoolHandle; POOL_sResource * psResource; POOL_sResource * psCloneResource; IMG_UINT32 ui32Result; IMG_ASSERT(gInitialised); IMG_ASSERT(psResPool != IMG_NULL); if (!gInitialised || psResPool == IMG_NULL) { ui32Result = IMG_ERROR_INVALID_PARAMETERS; goto error_nolock; } /* Lock the pool...*/ SYSOSKM_LockMutex(psResPool->hMutexHandle); /* Disable interrupts. */ SYSOSKM_DisableInt(); /* Remove the pool from the active list...*/ LST_remove(&gsPoolList, psResPool); /* Enable interrupts. */ SYSOSKM_EnableInt(); /* Destroy any resources in the free list...*/ psResource = (POOL_sResource *)LST_removeHead(&psResPool->sFreeResList); while (psResource != IMG_NULL) { psResource->pfnDestructor(psResource->pvParam); IMG_FREE(psResource); psResource = (POOL_sResource *)LST_removeHead(&psResPool->sFreeResList); } /* Destroy any resources in the active list...*/ psResource = (POOL_sResource *)LST_removeHead(&psResPool->sActResList); while (psResource != IMG_NULL) { psCloneResource = (POOL_sResource *)LST_removeHead(&psResource->sCloneResList); while (psCloneResource != IMG_NULL) { /* If we created a copy of the resources pvParam then free it...*/ if (psCloneResource->pvParam != IMG_NULL) { IMG_FREE(psCloneResource->pvParam ); } IMG_FREE(psCloneResource); psCloneResource = (POOL_sResource *)LST_removeHead(&psResource->sCloneResList); } /* Call the resource destructor...*/ psResource->pfnDestructor(psResource->pvParam); IMG_FREE(psResource); psResource = (POOL_sResource *)LST_removeHead(&psResPool->sActResList); } /* Destroy the context for the Id generator...*/ if (psResPool->hIdGenHandle != IMG_NULL) { ui32Result = IDGEN_DestroyContext(psResPool->hIdGenHandle); IMG_ASSERT(ui32Result == IMG_SUCCESS); } /* Unlock the pool...*/ SYSOSKM_UnlockMutex(psResPool->hMutexHandle); /* Destroy mutex...*/ SYSOSKM_DestroyMutex(psResPool->hMutexHandle); /* Free the pool structure */ IMG_FREE(psResPool); return IMG_SUCCESS; error_nolock: return ui32Result; }
/* ****************************************************************************** @Function MTXIO_ProcessMTXMsgs ******************************************************************************/ IMG_RESULT MTXIO_ProcessMTXMsgs( MTXIO_sContext * psContext, MSVDX_sMsgQueue * psMsgQStatus ) { IMG_UINT32 ui32ReadIdx, ui32WriteIdx, ui32BufferSize; IMG_UINT32 ui32FirstWord, ui32MessageSize; IMG_UINT32 * pui32FirstWord; VDECFW_eMessageID eMessageID; MSVDXIO_sHISRMsg * psMessage; /* we can only read messages from the Completion buffer */ MSVDX_eCommsArea eArea = MTXIO_AREA_COMPLETION; #if !defined(SECURE_MEDIA_SUPPORT) && !defined(VXD_BRIDGING) IMG_CHAR szPdumpComment[100]; #endif // Initialise the output flags. IMG_ASSERT(psMsgQStatus); psMsgQStatus->bEmpty = IMG_FALSE; psMsgQStatus->bQueued = IMG_FALSE; IMG_ASSERT(!LST_empty(&psMsgQStatus->sFreeMsgList)); IMG_ASSERT(LST_empty(&psMsgQStatus->sNewMsgList)); ui32ReadIdx = mtxio_commsAreaGet( psContext, eArea, MTXIO_FIELD_RD_INDEX ); ui32WriteIdx = mtxio_commsAreaGet( psContext, eArea, MTXIO_FIELD_WRT_INDEX ); ui32BufferSize = mtxio_commsAreaGet( psContext, eArea, MTXIO_FIELD_SIZE ); /* While there are messages to read and somewhere to put them. */ while (ui32ReadIdx != ui32WriteIdx && LST_first(&psMsgQStatus->sFreeMsgList)) { #if !defined(SECURE_MEDIA_SUPPORT) && !defined(VXD_BRIDGING) /* reproduce message reading in a pdump script */ MSVDXIO_PDUMPComment(psContext->hMsvdxIoCtx, psContext->asComms[eArea].eMemSpace, "MTXIO_ProcessMTXMsgs : Wait for COMPLETION area FW message"); MSVDXIO_Poll(psContext->hMsvdxIoCtx, psContext->asComms[eArea].eMemSpace, gaui32VlrOffset[eArea] + psContext->asComms[eArea].ui32WrtIndexOffset, ui32ReadIdx, 0xffffffff, MSVDXIO_POLL_NOT_EQUAL); #endif /* read the first word of the message */ mtxio_commsReadWords(psContext, eArea, psContext->asComms[eArea].ui32BufOffset + (ui32ReadIdx<<2), 1, &ui32FirstWord, IMG_TRUE); /* get the message size in words and ID */ pui32FirstWord = &ui32FirstWord; ui32MessageSize = (MEMIO_READ_FIELD(pui32FirstWord, V2_PADMSG_SIZE) + 3) / 4; eMessageID = MEMIO_READ_FIELD(pui32FirstWord, V2_PADMSG_MID); /* sanity check - message fits in buffer and does not go past write pointer */ IMG_ASSERT( ui32MessageSize < ui32BufferSize ); IMG_ASSERT( (ui32ReadIdx > ui32WriteIdx) || ((ui32ReadIdx + ui32MessageSize) <= ui32WriteIdx) ); /* sanity check - message is of the MTX -> Host type */ IMG_ASSERT( eMessageID >= VDECFW_MSGID_BE_PADDING ); #if !defined(SECURE_MEDIA_SUPPORT) && !defined(VXD_BRIDGING) snprintf(szPdumpComment, 99, "MTXIO_ProcessMTXMsgs: %s message received", eMessageID == VDECFW_MSGID_BE_PADDING ? "PADDING" : eMessageID == VDECFW_MSGID_PIC_DECODED ? "PIC DECODED" : eMessageID == VDECFW_MSGID_PIC_CRCS ? "CRC" : eMessageID == VDECFW_MSGID_PIC_PERFORMANCE ? "PERFORMANCE" : "UNKNOWN"); szPdumpComment[99] = 0; MSVDXIO_PDUMPComment(psContext->hMsvdxIoCtx, psContext->asComms[eArea].eMemSpace, szPdumpComment); #endif /* consume if the message is a padding message */ if ( VDECFW_MSGID_BE_PADDING == eMessageID ) { /* sanity check - message does infact pad to the end of the buffer */ IMG_ASSERT( ui32ReadIdx > ui32WriteIdx ); IMG_ASSERT( (ui32ReadIdx + ui32MessageSize) == ui32BufferSize ); ui32ReadIdx = 0; mtxio_commsAreaSet( psContext, eArea, MTXIO_FIELD_RD_INDEX, ui32ReadIdx ); continue; } psMessage = LST_removeHead(&psMsgQStatus->sFreeMsgList); IMG_ASSERT(psMessage); /* copy message into internal buffer and get new read index */ ui32ReadIdx = mtxio_copyMessageData(psContext, eArea, ui32ReadIdx, psMsgQStatus->ui32WriteIdx, psMsgQStatus->ui32ReadIdx, ui32MessageSize, ui32BufferSize, psMessage, psMsgQStatus->aui32MsgBuf); psMsgQStatus->ui32WriteIdx = psMessage->ui32NewRdIndex; /* Add the message to the HISR active list */ LST_add(&psMsgQStatus->sNewMsgList, psMessage); /* update the read index */ mtxio_commsAreaSet( psContext, eArea, MTXIO_FIELD_RD_INDEX, ui32ReadIdx ); psMsgQStatus->bQueued = IMG_TRUE; #if !defined(SECURE_MEDIA_SUPPORT) && !defined(VXD_BRIDGING) MSVDXIO_PDUMPComment(psContext->hMsvdxIoCtx, psContext->asComms[eArea].eMemSpace, "MTXIO_ProcessMTXMsgs: FW message receive complete"); #endif } /* report success or otherwise */ psMsgQStatus->bEmpty = ((ui32ReadIdx == ui32WriteIdx) ? IMG_TRUE: IMG_FALSE); return IMG_SUCCESS; }