INT CmDevice_RT::Initialize(CmDriverContext * pDriverContext) { INT result = CreateAuxDevice(pDriverContext); if (result != CM_SUCCESS) { CM_ASSERT(0); return result; } m_pSurfaceMgr = NULL; result = CmSurfaceManager::Create(this, m_HalMaxValues, m_HalMaxValuesEx, m_pSurfaceMgr); if (result != CM_SUCCESS) { CM_ASSERT(0); return result; } result = CreateQueue_Internel(); if (result != CM_SUCCESS) { CM_ASSERT(0); return result; } return result; }
INT CmDevice_RT::GetMaxValueFromCaps(CM_HAL_MAX_VALUES & MaxValues, CM_HAL_MAX_VALUES_EX & MaxValuesEx) { DXVA_CM_QUERY_CAPS queryCaps; UINT querySize = sizeof(DXVA_CM_QUERY_CAPS); CmSafeMemSet(&queryCaps, 0, sizeof(DXVA_CM_QUERY_CAPS)); queryCaps.Type = DXVA_CM_MAX_VALUES; INT hr = GetCapsInternal(&queryCaps, &querySize); if (FAILED(hr)) { CM_ASSERT(0); return CM_FAILURE; } MaxValues = queryCaps.MaxValues; MaxValues.iMaxArgsPerKernel = (queryCaps.MaxValues.iMaxArgsPerKernel > CM_MAX_ARGS_PER_KERNEL) ? (CM_MAX_ARGS_PER_KERNEL) : queryCaps.MaxValues.iMaxArgsPerKernel; CmSafeMemSet(&queryCaps, 0, sizeof(DXVA_CM_QUERY_CAPS)); queryCaps.Type = DXVA_CM_MAX_VALUES_EX; hr = GetCapsInternal(&queryCaps, &querySize); if (FAILED(hr)) { CM_ASSERT(0); return CM_FAILURE; } MaxValuesEx = queryCaps.MaxValuesEx; return CM_SUCCESS; }
INT CmDevice_RT::LoadJITDll(void) { int result = 0; if (NULL == m_hJITDll) { m_hJITDll = dlopen(GetJitterName(), RTLD_LAZY); if (NULL == m_hJITDll) { result = CM_JITDLL_LOAD_FAILURE; CM_ASSERT(0); return result; } if (NULL == m_fJITCompile) { m_fJITCompile = (pJITCompile) GetProcAddress(m_hJITDll, JITCOMPILE_FUNCTION_STR); m_fFreeBlock = (pFreeBlock) GetProcAddress(m_hJITDll, FREEBLOCK_FUNCTION_STR); m_fJITVersion = (pJITVersion) GetProcAddress(m_hJITDll, JITVERSION_FUNCTION_STR); } if ((NULL == m_fJITCompile) || (NULL == m_fFreeBlock) || (NULL == m_fJITVersion)) { result = CM_JITDLL_LOAD_FAILURE; CM_ASSERT(0); return result; } } return result; }
INT CmDevice::GetFreeBlockFnt(pFreeBlock & fFreeBlock) { if (m_fFreeBlock) { fFreeBlock = m_fFreeBlock; } else { if (!m_hJITDll) { if (sizeof(void *) == 4) { m_hJITDll = dlopen("igfxcmjit32.so", RTLD_LAZY); } else { m_hJITDll = dlopen("igfxcmjit64.so", RTLD_LAZY); } if (NULL == m_hJITDll) { CM_ASSERT(0); return CM_JITDLL_LOAD_FAILURE; } } m_fFreeBlock = (pFreeBlock) GetProcAddress(m_hJITDll, FREEBLOCK_FUNCTION_STR); if (NULL == m_fFreeBlock) { CM_ASSERT(0); return CM_JITDLL_LOAD_FAILURE; } fFreeBlock = m_fFreeBlock; } return CM_SUCCESS; }
INT CmDevice::GetJITVersionFnt(pJITVersion & fJITVersion) { if (m_fJITVersion) { fJITVersion = m_fJITVersion; } else { if (!m_hJITDll) { if (sizeof(void *) == 4) { m_hJITDll = dlopen("igfxcmjit32.so", RTLD_LAZY); } else { m_hJITDll = dlopen("igfxcmjit64.so", RTLD_LAZY); } if (NULL == m_hJITDll) { CM_ASSERT(0); return CM_JITDLL_LOAD_FAILURE; } } m_fJITVersion = (pJITVersion) GetProcAddress(m_hJITDll, JITVERSION_FUNCTION_STR); if (NULL == m_fJITVersion) { CM_ASSERT(0); return CM_JITDLL_LOAD_FAILURE; } fJITVersion = m_fJITVersion; } return CM_SUCCESS; }
CM_RT_API INT CmDevice_RT::DestroyTask(CmTask * &pTask) { CLock locker(m_CriticalSection_Task); if (pTask == NULL) { return CM_FAILURE; } CmTask_RT* pTask_RT = static_cast< CmTask_RT* >(pTask); if ( pTask_RT == NULL ) { return CM_FAILURE; } UINT index = pTask_RT->GetIndexInTaskArray(); if (pTask == (CmTask_RT *) m_TaskArray.GetElement(index)) { INT status = CmTask_RT::Destroy(pTask_RT); if (status == CM_SUCCESS) { m_TaskArray.SetElement(index, NULL); pTask = NULL; return CM_SUCCESS; } else { CM_ASSERT(0); return status; } } else { CM_ASSERT(0); return CM_FAILURE; } }
CM_RT_API INT CmDevice_RT::DestroyThreadSpace(CmThreadSpace * &pTS) { if (pTS == NULL) { return CM_FAILURE; } UINT indexTs = pTS->GetIndexInTsArray(); CLock locker(m_CriticalSection_ThreadSpace); if (pTS == m_ThreadSpaceArray.GetElement(indexTs)) { INT status = CmThreadSpace::Destroy(pTS); if (status == CM_SUCCESS) { m_ThreadSpaceArray.SetElement(indexTs, NULL); pTS = NULL; return CM_SUCCESS; } else { CM_ASSERT(0); return status; } } else { CM_ASSERT(0); return CM_FAILURE; } }
INT CmDevice_RT::SetCapsInternal(CM_DEVICE_CAP_NAME capName, size_t capValueSize, void *pCapValue) { CM_RETURN_CODE hr = CM_SUCCESS; DXVA_CM_SET_CAPS setCaps; UINT maxValue; size_t size = sizeof(maxValue); CmSafeMemSet(&setCaps, 0, sizeof(setCaps)); switch (capName) { case CAP_HW_THREAD_COUNT: if (capValueSize != sizeof(UINT)) { CM_ASSERT(0); return CM_INVALID_HARDWARE_THREAD_NUMBER; } if (*(UINT *) pCapValue <= 0) { CM_ASSERT(0); return CM_INVALID_HARDWARE_THREAD_NUMBER; } GetCaps(CAP_HW_THREAD_COUNT, size, &maxValue); if (*(UINT *) pCapValue > maxValue) { CM_ASSERT(0); return CM_INVALID_HARDWARE_THREAD_NUMBER; } setCaps.Type = DXVA_CM_MAX_HW_THREADS; setCaps.MaxValue = *(UINT *) pCapValue; break; case CAP_L3_CONFIG: if (capValueSize != sizeof(L3_CONFIG_REGISTER_VALUES)){ CM_ASSERT(0); return CM_INVALIDE_L3_CONFIGURATION; } else { L3_CONFIG_REGISTER_VALUES *l3_c = (L3_CONFIG_REGISTER_VALUES *)pCapValue; setCaps.L3_SQCREG1 = l3_c->SQCREG1_VALUE; setCaps.L3_CNTLREG2 = l3_c->CNTLREG2_VALUE; setCaps.L3_CNTLREG3 = l3_c->CNTLREG3_VALUE; setCaps.L3_CNTLREG = l3_c->CNTLREG_VALUE; setCaps.Type = DXVA_CM_MAX_HW_L3_CONFIG; } break; default: return CM_FAILURE; } PCM_CONTEXT pCmData = (PCM_CONTEXT) this->GetAccelData(); CHK_GENOSSTATUS_RETURN_CMERROR(pCmData->pCmHalState-> pfnSetCaps(pCmData->pCmHalState, (PCM_HAL_MAX_SET_CAPS_PARAM) & setCaps)); finish: return hr; }
INT CmDevice_RT::Create(CmDriverContext * pDriverContext, CmDevice_RT * &pDevice, UINT DevCreateOption) { INT result = CM_FAILURE; if (pDevice != NULL) { pDevice->Acquire(); return CM_SUCCESS; } pDevice = new(std::nothrow) CmDevice_RT(DevCreateOption); if (pDevice) { pDevice->Acquire(); result = pDevice->Initialize(pDriverContext); if (result != CM_SUCCESS) { CM_ASSERT(0); CmDevice_RT::Destroy(pDevice); pDevice = NULL; } } else { CM_ASSERT(0); result = CM_OUT_OF_HOST_MEMORY; } return result; }
t_cm_error cm_bindInterfaceTrace( const t_interface_require_description *itfRequire, const t_interface_provide_description *itfProvide, t_elfdescription *elfhandleTrace) { t_interface_require *require = &itfRequire->client->Template->requires[itfRequire->requireIndex]; t_interface_require_description bcitfRequire; t_interface_provide_description bcitfProvide; t_trace_bf_info *bfInfo; t_cm_error error; LOG_INTERNAL(1, "\n##### Bind Synchronous Trace %s/%x.%s -> %s/%x.%s #####\n", itfRequire->client->pathname, itfRequire->client, itfRequire->origName, itfProvide->server->pathname, itfProvide->server, itfProvide->origName); /* Allocate aynchronous binding factory information */ bfInfo = (t_trace_bf_info*)OSAL_Alloc(sizeof(t_trace_bf_info)); if(bfInfo == 0) return CM_NO_MORE_MEMORY; /* * Instantiate related trace on dsp */ { char traceTemplateName[4 + MAX_INTERFACE_TYPE_NAME_LENGTH + 1]; cm_StringCopy(traceTemplateName,"_tr.", sizeof(traceTemplateName)); cm_StringConcatenate(traceTemplateName, require->interface->type, MAX_INTERFACE_TYPE_NAME_LENGTH); if ((error = cm_instantiateComponent( traceTemplateName, itfRequire->client->domainId, itfProvide->server->priority, traceDup, elfhandleTrace, &bfInfo->traceInstance)) != CM_OK) { OSAL_Free(bfInfo); return (error == CM_COMPONENT_NOT_FOUND)?CM_BINDING_COMPONENT_NOT_FOUND : error; } } /* Bind event to server interface (Error must not occure) */ CM_ASSERT(cm_getRequiredInterface(bfInfo->traceInstance, "target", &bcitfRequire) == CM_OK); cm_bindLowLevelInterface(&bcitfRequire, itfProvide, BF_SYNCHRONOUS, NULL); /* Get the event interface (Error must not occure) */ CM_ASSERT(cm_getProvidedInterface(bfInfo->traceInstance, "target", &bcitfProvide) == CM_OK); /* Bind client to event (Error must not occure) */ cm_bindLowLevelInterface(itfRequire, &bcitfProvide, BF_TRACE, bfInfo); cm_TRC_traceBinding(TRACE_BIND_COMMAND_BIND_SYNCHRONOUS, itfRequire->client, itfProvide->server, itfRequire->client->Template->requires[itfRequire->requireIndex].name, itfProvide->server->Template->provides[itfProvide->provideIndex].name); return CM_OK; }
INT CmQueue::Enqueue_RT(CmKernel * pKernelArray[], const UINT uiKernelCount, const UINT uiTotalThreadCount, CmEvent * &pEvent, const CmThreadSpace * pTS, UINT64 uiSyncBitmap, PCM_HAL_POWER_OPTION_PARAM pPowerOption) { if (pKernelArray == NULL) { CM_ASSERTMESSAGE("Kernel array is NULL."); return CM_INVALID_ARG_VALUE; } if (uiKernelCount == 0) { CM_ASSERTMESSAGE("There are no valid kernels."); return CM_INVALID_ARG_VALUE; } BOOL bIsEventVisible = (pEvent == CM_NO_EVENT) ? FALSE : TRUE; CmTaskInternal *pTask = NULL; INT result = CmTaskInternal::Create(uiKernelCount, uiTotalThreadCount, pKernelArray, pTS, m_pDevice, uiSyncBitmap, pTask); if (result != CM_SUCCESS) { CM_ASSERT(0); return result; } m_CriticalSection_Queue.Acquire(); if (!m_EnqueuedTasks.Push(pTask)) { m_CriticalSection_Queue.Release(); CM_ASSERT(0); return CM_FAILURE; } INT taskDriverId = -1; result = CreateEvent(pTask, bIsEventVisible, taskDriverId, pEvent); if (result != CM_SUCCESS) { m_CriticalSection_Queue.Release(); CM_ASSERT(0); return result; } pTask->SetPowerOption(pPowerOption); UpdateSurfaceStateOnPush(pTask); result = FlushTaskWithoutSync(); m_CriticalSection_Queue.Release(); return result; }
INT CmQueue::Enqueue_RT(CmKernel * pKernelArray[], const UINT uiKernelCount, const UINT uiTotalThreadCount, CmEvent * &pEvent, const CmThreadGroupSpace * pTGS, UINT64 uiSyncBitmap, CM_HAL_PREEMPTION_MODE preemptionMode) { if (pKernelArray == NULL) { CM_ASSERTMESSAGE("Kernel array is NULL."); return CM_INVALID_ARG_VALUE; } if (uiKernelCount == 0) { CM_ASSERTMESSAGE("There are no valid kernels."); return CM_INVALID_ARG_VALUE; } CmTaskInternal *pTask = NULL; INT result = CmTaskInternal::Create(uiKernelCount, uiTotalThreadCount, pKernelArray, pTGS, m_pDevice, uiSyncBitmap, pTask); if (result != CM_SUCCESS) { CM_ASSERT(0); return result; } m_CriticalSection_Queue.Acquire(); pTask->SetPreemptionMode(preemptionMode); if (!m_EnqueuedTasks.Push(pTask)) { m_CriticalSection_Queue.Release(); CM_ASSERT(0); return CM_FAILURE; } INT taskDriverId = -1; result = CreateEvent(pTask, !(pEvent == CM_NO_EVENT), taskDriverId, pEvent); if (result != CM_SUCCESS) { m_CriticalSection_Queue.Release(); CM_ASSERT(0); return result; } UpdateSurfaceStateOnPush(pTask); result = FlushTaskWithoutSync(); m_CriticalSection_Queue.Release(); return result; }
INT CmEvent::Query(void) { CM_RETURN_CODE hr = CM_SUCCESS; if ((m_Status != CM_STATUS_FLUSHED) && (m_Status != CM_STATUS_STARTED)) { return CM_FAILURE; } CM_ASSERT(m_TaskDriverId > -1); CM_HAL_QUERY_TASK_PARAM param; param.iTaskId = m_TaskDriverId; PCM_CONTEXT pCmData = (PCM_CONTEXT) m_pDevice->GetAccelData(); CHK_GENOSSTATUS_RETURN_CMERROR(pCmData->pCmHalState-> pfnQueryTask(pCmData->pCmHalState, ¶m)); if (param.status == CM_TASK_FINISHED) { CmQueue *pQueue = NULL; m_Time = param.iTaskDuration; m_Status = CM_STATUS_FINISHED; m_GlobalCMSubmitTime = param.iTaskGlobalCMSubmitTime; m_CMSubmitTimeStamp = param.iTaskCMSubmitTimeStamp; m_HWStartTimeStamp = param.iTaskHWStartTimeStamp; m_HWEndTimeStamp = param.iTaskHWEndTimeStamp; m_CompleteTime = param.iTaskCompleteTime; m_pDevice->GetQueue(pQueue); if (!pQueue) { CM_ASSERT(0); return CM_FAILURE; } if (m_OsData) { drm_intel_bo_unreference((drm_intel_bo *) m_OsData); } m_GlobalCMSubmitTime = param.iTaskGlobalCMSubmitTime; m_CMSubmitTimeStamp = param.iTaskCMSubmitTimeStamp; m_HWStartTimeStamp = param.iTaskHWStartTimeStamp; m_HWEndTimeStamp = param.iTaskHWEndTimeStamp; m_CompleteTime = param.iTaskCompleteTime; } else if (param.status == CM_TASK_IN_PROGRESS) { m_Status = CM_STATUS_STARTED; } finish: return hr; }
INT CmSurfaceManager::DestroySurface(CmBuffer_RT * &pSurface1D, SURFACE_DESTROY_KIND destroyKind) { UINT handle = 0; INT result = CM_SUCCESS; if (!pSurface1D) { return CM_FAILURE; } SurfaceIndex *pIndex = NULL; pSurface1D->GetIndex(pIndex); CM_ASSERT(pIndex); UINT index = pIndex->get_data(); CM_ASSERT(m_SurfaceArray[index] == pSurface1D); if (destroyKind == FORCE_DESTROY) { pSurface1D->WaitForReferenceFree(); } else { if (m_pCmDevice->IsSurfaceReuseEnabled() && !pSurface1D->IsUpSurface()) { result = UPDATE_STATE_FOR_REUSE_DESTROY(destroyKind, index); } else { result = UPDATE_STATE_FOR_DELAYED_DESTROY(destroyKind, index); } if (result != CM_SUCCESS) { return result; } } result = pSurface1D->GetHandle(handle); if (result != CM_SUCCESS) { return result; } result = FreeBuffer(handle); if (result != CM_SUCCESS) { return result; } CmSurface *pSurface = pSurface1D; CmSurface::Destroy(pSurface); UPDATE_STATE_FOR_REAL_DESTROY(index, CM_ENUM_CLASS_TYPE_CMBUFFER_RT); return CM_SUCCESS; }
INT CmSurfaceManager::UPDATE_STATE_FOR_REAL_DESTROY(UINT i, CM_ENUM_CLASS_TYPE kind) { m_SurfaceReleased[i] = FALSE; m_SurfaceCached[i] = FALSE; m_SurfaceArray[i] = NULL; m_SurfaceDestroyID[i]++; m_SurfaceSizes[i] = 0; switch (kind) { case CM_ENUM_CLASS_TYPE_CMBUFFER_RT: m_bufferCount--; break; case CM_ENUM_CLASS_TYPE_CMSURFACE2D: m_2DSurfaceCount--; break; case CM_ENUM_CLASS_TYPE_CMSURFACE2DUP: m_2DUPSurfaceCount--; break; default: CM_ASSERT(0); break; } return CM_SUCCESS; }
INT CmSurfaceManager::GetPixelBytesAndHeight(UINT width, UINT height, CM_SURFACE_FORMAT format, UINT & sizePerPixel, UINT & updatedHeight) { updatedHeight = height; switch (format) { case CM_SURFACE_FORMAT_X8R8G8B8: case CM_SURFACE_FORMAT_A8R8G8B8: case CM_SURFACE_FORMAT_R32F: sizePerPixel = 4; break; case CM_SURFACE_FORMAT_V8U8: case CM_SURFACE_FORMAT_UYVY: case CM_SURFACE_FORMAT_YUY2: case CM_SURFACE_FORMAT_R16_UINT: sizePerPixel = 2; break; case CM_SURFACE_FORMAT_A8: case CM_SURFACE_FORMAT_P8: case CM_SURFACE_FORMAT_R8_UINT: sizePerPixel = 1; break; case CM_SURFACE_FORMAT_NV12: sizePerPixel = 1; updatedHeight += (updatedHeight + 1) / 2; break; case CM_SURFACE_FORMAT_411P: case CM_SURFACE_FORMAT_422H: case CM_SURFACE_FORMAT_444P: sizePerPixel = 1; updatedHeight = height * 3; break; case CM_SURFACE_FORMAT_IMC3: sizePerPixel = 1; updatedHeight = height * 2; break; case CM_SURFACE_FORMAT_422V: sizePerPixel = 1; updatedHeight = height * 2; break; case CM_SURFACE_FORMAT_YV12: sizePerPixel = 1; updatedHeight += updatedHeight / 2; break; default: CM_ASSERT(0); return CM_SURFACE_FORMAT_NOT_SUPPORTED; } return CM_SUCCESS; }
CM_RT_API INT CmDevice_RT::DestroyThreadGroupSpace(CmThreadGroupSpace * &pTGS) { if (pTGS == NULL) { return CM_FAILURE; } UINT indexTGs = static_cast<CmThreadGroupSpace_RT*>(pTGS)->GetIndexInTGsArray(); CLock locker(m_CriticalSection_ThreadGroupSpace); if (pTGS == static_cast < CmThreadGroupSpace * >(m_ThreadGroupSpaceArray.GetElement(indexTGs))) { INT status = CmThreadGroupSpace_RT::Destroy(pTGS); if (status == CM_SUCCESS) { m_ThreadGroupSpaceArray.SetElement(indexTGs, NULL); pTGS = NULL; return CM_SUCCESS; } } else { CM_ASSERT(0); return CM_FAILURE; } return CM_FAILURE; }
CM_RT_API INT CmDevice_RT::GetGenPlatform(UINT & platform) { if (m_Platform != IGFX_UNKNOWN_CORE) { platform = m_Platform; return CM_SUCCESS; } platform = IGFX_UNKNOWN_CORE; INT hr = 0; DXVA_CM_QUERY_CAPS queryCaps; UINT querySize = sizeof(DXVA_CM_QUERY_CAPS); CmSafeMemSet(&queryCaps, 0, sizeof(queryCaps)); queryCaps.Type = DXVA_CM_QUERY_GPU; hr = GetCapsInternal(&queryCaps, &querySize); if (FAILED(hr)) { CM_ASSERT(0); return CM_FAILURE; } if (queryCaps.iVersion) { platform = queryCaps.iVersion; } return CM_SUCCESS; }
INT CmSurfaceManager::UPDATE_STATE_FOR_REUSE_DESTROY(SURFACE_DESTROY_KIND destroyKind, UINT i) { switch (destroyKind) { case DELAYED_DESTROY: if (m_SurfaceCached[i]) { return CM_SURFACE_CACHED; } if (!m_SurfaceReleased[i] || m_SurfaceState[i]) { return CM_SURFACE_IN_USE; } break; case APP_DESTROY: m_SurfaceReleased[i] = TRUE; if (m_SurfaceReleased[i] && !m_SurfaceCached[i]) { m_SurfaceCached[i] = TRUE; } return CM_SURFACE_CACHED; case GC_DESTROY: if (!m_SurfaceReleased[i] || m_SurfaceState[i]) { return CM_SURFACE_IN_USE; } break; default: CM_ASSERT(0); return CM_FAILURE; } return CM_SUCCESS; }
INT CmSurface2DUP::Create(UINT index, UINT handle, UINT width, UINT height, CM_SURFACE_FORMAT format, CmSurfaceManager * pSurfaceManager, CmSurface2DUP * &pSurface) { INT result = CM_SUCCESS; pSurface = new(std::nothrow) CmSurface2DUP(handle, width, height, format, pSurfaceManager); if (pSurface) { result = pSurface->Initialize(index); if (result != CM_SUCCESS) { CmSurface *pBaseSurface = pSurface; CmSurface::Destroy(pBaseSurface); } } else { CM_ASSERT(0); result = CM_OUT_OF_HOST_MEMORY; } return result; }
CM_RT_API INT CmDevice_RT::CreateKernel(CmProgram * pProgram, const char *kernelName, CmKernel * &pKernel, const char *options) { if (pProgram == NULL) { CM_ASSERT(0); return CM_INVALID_ARG_VALUE; } CLock locker(m_CriticalSection_Program_Kernel); UINT freeSlotInKernelArray = m_KernelArray.GetFirstFreeIndex(); CmKernel_RT *pKernel_RT=NULL; CmProgram_RT* pProgram_RT = static_cast<CmProgram_RT*>(pProgram); INT result = CmKernel_RT::Create(this, pProgram_RT, kernelName, freeSlotInKernelArray, m_KernelCount, pKernel_RT, options); if (result == CM_SUCCESS) { m_KernelArray.SetElement(freeSlotInKernelArray, pKernel_RT); m_KernelCount++; pKernel = static_cast< CmKernel * >(pKernel_RT); } return result; }
CM_RT_API INT CmDevice_RT::LoadProgram(void *pCommonISACode, const UINT size, CmProgram * &pProgram, const char *options) { INT result; if ((pCommonISACode == NULL) || (size == 0)) { CM_ASSERT(0); return CM_INVALID_COMMON_ISA; } CLock locker(m_CriticalSection_Program_Kernel); UINT firstfreeslot = m_ProgramArray.GetFirstFreeIndex(); CmProgram_RT *pProgram_RT = NULL; result = CmProgram_RT::Create(this, pCommonISACode, size, NULL, 0, pProgram_RT, options, firstfreeslot); if (result == CM_SUCCESS) { m_ProgramArray.SetElement(firstfreeslot, pProgram_RT); m_ProgramCount++; pProgram = (static_cast<CmProgram *>(pProgram_RT)); } return result; }
INT CmQueue::CleanQueue(void) { INT status = CM_SUCCESS; m_CriticalSection_Queue.Acquire(); if (!m_EnqueuedTasks.IsEmpty()) { FlushTaskWithoutSync(TRUE); } CM_ASSERT(m_EnqueuedTasks.IsEmpty()); m_EnqueuedTasks.DeleteFreePool(); struct timeval start; gettimeofday(&start, NULL); UINT64 timeout_usec; timeout_usec = CM_MAX_TIMEOUT * m_FlushedTasks.GetCount() * 1000000; while (!m_FlushedTasks.IsEmpty() && status != CM_EXCEED_MAX_TIMEOUT) { QueryFlushedTasks(); struct timeval current; gettimeofday(¤t, NULL); UINT64 timeuse_usec; timeuse_usec = 1000000 * (current.tv_sec - start.tv_sec) + current.tv_usec - start.tv_usec; if (timeuse_usec > timeout_usec) status = CM_EXCEED_MAX_TIMEOUT; } m_FlushedTasks.DeleteFreePool(); m_CriticalSection_Queue.Release(); return status; }
INT CmQueue::UpdateSurfaceStateOnPush(CmTaskInternal * pTask) { INT *pSurfState = NULL; BOOL *surfArray = NULL; CmSurfaceManager *pSurfaceMgr = NULL; UINT freeSurfNum = 0; m_pDevice->GetSurfaceManager(pSurfaceMgr); if (!pSurfaceMgr) { CM_ASSERT(0); return CM_FAILURE; } CSync *pSurfaceLock = m_pDevice->GetSurfaceCreationLock(); pSurfaceLock->Acquire(); UINT poolSize = pSurfaceMgr->GetSurfacePoolSize(); pSurfaceMgr->GetSurfaceState(pSurfState); pTask->GetTaskSurfaces(surfArray); for (UINT i = 0; i < poolSize; i++) { if (surfArray[i]) { pSurfState[i]++; } } pSurfaceMgr->DestroySurfaceInPool(freeSurfNum, DELAYED_DESTROY); pSurfaceLock->Release(); return CM_SUCCESS; }
PUBLIC void cm_PWR_DisableMemory( t_nmf_core_id coreId, t_dsp_memory_type_id dspMemType, t_cm_physical_address address, t_cm_size size) { switch(dspMemType) { case INTERNAL_XRAM24: case INTERNAL_XRAM16: case INTERNAL_YRAM24: case INTERNAL_YRAM16: _pwrMPCMemoryCountT[coreId]--; break; case SDRAM_EXT24: case SDRAM_EXT16: case SDRAM_CODE: case LOCKED_CODE: OSAL_DisablePwrRessource( CM_OSAL_POWER_SDRAM, address, size); break; case ESRAM_EXT24: case ESRAM_EXT16: case ESRAM_CODE: OSAL_DisablePwrRessource( CM_OSAL_POWER_ESRAM, address, size); break; default: CM_ASSERT(0); } }
void cm_unbindInterfaceAsynchronous( const t_interface_require_description *itfRequire, t_async_bf_info *bfInfo) { t_interface_require_description eventitfRequire; LOG_INTERNAL(1, "\n##### UnBind asynchronous %s/%x.%s #####\n", itfRequire->client->pathname, itfRequire->client, itfRequire->origName, 0, 0, 0); cm_TRC_traceBinding(TRACE_BIND_COMMAND_UNBIND_ASYNCHRONOUS, itfRequire->client, NULL, itfRequire->client->Template->requires[itfRequire->requireIndex].name, NULL); /* Unbind Client from Event Binding Component */ cm_bindLowLevelInterfaceToConst(itfRequire, 0x0, NULL); /* Unbind explicitly Event from Server Binding Component */ /* This is mandatory to fix the providedItfUsedCount of the server */ CM_ASSERT(cm_getRequiredInterface(bfInfo->eventInstance, "target", &eventitfRequire) == CM_OK); cm_registerLowLevelInterfaceToConst(&eventitfRequire, NULL); /* Destroy Event fifo */ dspevent_destroyDspEventFifo(bfInfo->dspfifoHandle); /* Destroy Event Binding Component */ cm_destroyInstance(bfInfo->eventInstance, DESTROY_WITHOUT_CHECK); /* Free BF info */ OSAL_Free(bfInfo); }
CmKernel *CmTask::GetKernelPointer(UINT index) { if (index >= m_KernelCount) { CM_ASSERT(0); return NULL; } return m_pKernelArray[index]; }
CM_RT_API INT CmQueue::EnqueueWithGroup(CmTask * pTask, CmEvent * &pEvent, const CmThreadGroupSpace * pTGS) { INT result; if (pTask == NULL) { CM_ASSERTMESSAGE("Kernel array is NULL."); return CM_INVALID_ARG_VALUE; } UINT count = 0; count = pTask->GetKernelCount(); if (count == 0) { CM_ASSERTMESSAGE("There are no valid kernels."); return CM_FAILURE; } typedef CmKernel *pCmKernel; CmKernel **pTmp = new(std::nothrow) pCmKernel[count + 1]; if (pTmp == NULL) { CM_ASSERT(0); return CM_OUT_OF_HOST_MEMORY; } UINT totalThreadNumber = 0; for (UINT i = 0; i < count; i++) { UINT singleThreadNumber = 0; pTmp[i] = pTask->GetKernelPointer(i); if (pTmp[i]->IsThreadArgExisted()) { CM_ASSERTMESSAGE ("No thread Args allowed when using group space"); CmSafeDeleteArray(pTmp); return CM_THREAD_ARG_NOT_ALLOWED; } pTmp[i]->GetThreadCount(singleThreadNumber); totalThreadNumber += singleThreadNumber; } pTmp[count] = NULL; result = Enqueue_RT(pTmp, count, totalThreadNumber, pEvent, pTGS, pTask->GetSyncBitmap(), pTask->GetPreemptionMode()); if (pEvent) { pEvent->SetKernelNames(pTask, NULL, const_cast < CmThreadGroupSpace * >(pTGS)); } CmSafeDeleteArray(pTmp); return result; }
INT CmSurfaceManager::DestroySurfaceInPool(UINT & freeSurfNum, SURFACE_DESTROY_KIND destroyKind) { CmSurface *pSurface = NULL; CmBuffer_RT *pSurf1D = NULL; CmSurface2D *pSurf2D = NULL; CmSurface2DUP *pSurf2DUP = NULL; INT status = CM_FAILURE; UINT index = m_pCmDevice->ValidSurfaceIndexStart(); freeSurfNum = 0; while (index < m_SurfaceArraySize) { pSurface = m_SurfaceArray[index]; if (!pSurface) { index++; continue; } status = CM_FAILURE; switch (pSurface->Type()) { case CM_ENUM_CLASS_TYPE_CMSURFACE2D: pSurf2D = static_cast < CmSurface2D * >(pSurface); if (pSurf2D) { status = DestroySurface(pSurf2D, destroyKind); } break; case CM_ENUM_CLASS_TYPE_CMBUFFER_RT: pSurf1D = static_cast < CmBuffer_RT * >(pSurface); if (pSurf1D) { status = DestroySurface(pSurf1D, destroyKind); } break; case CM_ENUM_CLASS_TYPE_CMSURFACE2DUP: pSurf2DUP = static_cast < CmSurface2DUP * >(pSurface); if (pSurf2DUP) { status = DestroySurface(pSurf2DUP, destroyKind); } break; default: CM_ASSERT(0); break; } if (status == CM_SUCCESS) { freeSurfNum++; } index++; } return CM_SUCCESS; }
CM_RT_API INT CmDevice_RT::DestroyKernel(CmKernel * &pKernel) { if (pKernel == NULL) { return CM_FAILURE; } CLock locker(m_CriticalSection_Program_Kernel); CmKernel_RT *pKernel_RT=static_cast<CmKernel_RT*>(pKernel); UINT indexInKernelArrary = pKernel_RT->GetKernelIndex(); CmProgram_RT *pProgram_RT = NULL; if (pKernel_RT == m_KernelArray.GetElement(indexInKernelArrary)) { pKernel_RT->GetCmProgram(pProgram_RT); if (pProgram_RT == NULL) { CM_ASSERT(0); return CM_FAILURE; } UINT indexInProgramArray = pProgram_RT->GetProgramIndex(); if (pProgram_RT == m_ProgramArray.GetElement(indexInProgramArray)) { CmKernel_RT::Destroy(pKernel_RT, pProgram_RT); if (pKernel_RT == NULL) { m_KernelArray.SetElement(indexInKernelArrary, NULL); } if (pProgram_RT == NULL) { m_ProgramArray.SetElement(indexInProgramArray, NULL); } return CM_SUCCESS; } else { CM_ASSERT(0); return CM_FAILURE; } } else { CM_ASSERT(0); return CM_FAILURE; } return CM_SUCCESS; }