📄 resman.c
字号:
/*Call the freeing routine*/
if((eRet=psItem->pfnFreeResource(psItem->ui32ProcessID,psItem->pvParam, psItem->ui32Param)) != PVRSRV_OK)
{
PVR_DPF((PVR_DBG_ERROR, "FreeResourceByPtr: ERROR calling FreeResource function"));
}
/*Acquire resource list sync object*/
ACQUIRE_SYNC_OBJ;
/*Free memory for the resource item if we allocated it*/
if((psItem->ui32Flags & RESMAN_FLAGS_CALLER_ALLOCED_BUF) == 0)
{
if(HostFreeMem(PVRSRV_HOST_NON_PAGEABLE_HEAP,psItem) != PVRSRV_OK)
{
PVR_DPF((PVR_DBG_ERROR, "FreeResourceByPtr: ERROR freeing resource list item memory"));
eRet = PVRSRV_ERROR_GENERIC;
}
}
return(eRet);
}
/**************************************************************************
Function Name : FreeResourceByCriteria
Inputs : psProcess - pointer to process struct for the current process
ui32SearchCriteria - indicates which parameters should be used
search for resources to free
ui32ResType - identify what kind of resource to free
pvParam - address of resource to be free
ui32Param - size of resource to be free
ui32AutoFreeLev - auto free level to free
Outputs : None
Returns : PVRSRV_OK on SUccess.
Globals Used : sResList
Description : Frees all resources that match the given criteria for the
current process.
NOTE : this function must be called with the resource
list sync object held
**************************************************************************/
PVRSRV_ERROR FreeResourceByCriteria(PRESMAN_PROCESS psProcess,
IMG_UINT32 ui32SearchCriteria,
IMG_UINT32 ui32ResType,
IMG_PVOID pvParam,
IMG_UINT32 ui32Param,
IMG_UINT32 ui32AutoFreeLev)
{
PRESMAN_ITEM psCurItem;
IMG_BOOL bMatch;
PVRSRV_ERROR eError = PVRSRV_OK;
ResManInit(); /* Ensure ResMan initialised */
/* If autofree level is a criteria ensure that autofree OFF is not the value to match against */
if((ui32SearchCriteria & RESMAN_CRITERIA_AUTOFREE) && ui32AutoFreeLev == RESMAN_AUTOFREE_OFF)
{
PVR_DPF((PVR_DBG_ERROR,"FreeResourceByCriteria: Can't auto free resources that have autofree turned off"));
return PVRSRV_ERROR_INVALID_PARAMS;
}
/*Search resource items starting at after the first dummy item*/
psCurItem = psProcess->psResItemList->psNext;
while(psCurItem->psNext != IMG_NULL)
{
/*Assume this item matchs criteria until we find otherwise*/
bMatch=IMG_TRUE;
/*Check free'ing method*/
if((ui32SearchCriteria & RESMAN_CRITERIA_AUTOFREE) && (psCurItem->ui32Flags & RESMAN_FLAGS_AUTOFREE_MASK) != ui32AutoFreeLev)
{
bMatch = IMG_FALSE;
}
/*Check resource type*/
else if((ui32SearchCriteria & RESMAN_CRITERIA_RESTYPE) && psCurItem->ui32ResType != ui32ResType)
{
bMatch = IMG_FALSE;
}
/*Check address*/
else if((ui32SearchCriteria & RESMAN_CRITERIA_PVOID_PARAM) && psCurItem->pvParam != pvParam)
{
bMatch = IMG_FALSE;
}
/*Check size*/
else if((ui32SearchCriteria & RESMAN_CRITERIA_UI32_PARAM) && psCurItem->ui32Param != ui32Param)
{
bMatch = IMG_FALSE;
}
if(bMatch == IMG_FALSE)
{
/* Move to next item as we did not get a match */
psCurItem = psCurItem->psNext;
}
else
{
/* Free resource as search criteria were met */
eError = FreeResourceByPtr(psCurItem);
if(eError != PVRSRV_OK)
{
return eError;
}
/*
Now because the free routine of this resource may have called
the resource manager we MUST start from the begining of the list again
*/
psCurItem = psProcess->psResItemList->psNext;
if(ui32SearchCriteria & RESMAN_CRITERIA_FREEONCE)
{
return eError;
}
}
}
return eError;
}
/**************************************************************************
Function Name : FindProcess
Inputs : ui32ProcessID - ID of process that we want to find
Outputs : None
Returns : Pointer to process struct if success, else IMG_NULL
Globals Used : sResList
Description : Search the process list for the struct describing
the given process.
NOTE : this function must be called with the resource
list sync object held
**************************************************************************/
PRESMAN_PROCESS FindProcess(IMG_UINT32 ui32ProcessID)
{
PRESMAN_PROCESS psCurProcess=sResList.psProcessList->psNext;
/*Walk the process list*/
while(psCurProcess != IMG_NULL)
{
/*Check if this is the correct process info*/
if(psCurProcess->ui32ProcessID == ui32ProcessID)
{
return(psCurProcess);
}
/*Move to next process*/
psCurProcess = psCurProcess->psNext;
}
return((PRESMAN_PROCESS)IMG_NULL);
}
/**************************************************************************
Function Name : ValidateResList
Inputs : None
Outputs : None
Returns : None
Globals Used : sResList
Description : Walks the resource list check the pointers
NOTE : this function must be called with the resource
list sync object held
**************************************************************************/
#ifdef DEBUG
IMG_VOID ValidateResList(IMG_VOID)
{
PRESMAN_ITEM psCurItem;
PRESMAN_PROCESS psCurProcess = sResList.psProcessList->psNext;
/*Walk the process list*/
while(psCurProcess != IMG_NULL)
{
/*Check current item*/
PVR_ASSERT(psCurProcess->ui32Signature == RESMAN_SIGNATURE);
/*Check last item*/
if(psCurProcess->psPrev != IMG_NULL)
{
PVR_ASSERT(psCurProcess->psPrev->ui32Signature == RESMAN_SIGNATURE);
}
/*Check next item*/
if(psCurProcess->psNext != IMG_NULL)
{
PVR_ASSERT(psCurProcess->psNext->ui32Signature == RESMAN_SIGNATURE);
}
/*Walk the list for this process*/
psCurItem = psCurProcess->psResItemList;
while(psCurItem != IMG_NULL)
{
/*Check current item*/
PVR_ASSERT(psCurItem->ui32Signature == RESMAN_SIGNATURE);
/*Check last item*/
if(psCurItem->psPrev != IMG_NULL)
{
PVR_ASSERT(psCurItem->psPrev->ui32Signature == RESMAN_SIGNATURE);
}
/*Check next item*/
if(psCurItem->psNext != IMG_NULL)
{
PVR_ASSERT(psCurItem->psNext->ui32Signature == RESMAN_SIGNATURE);
}
/*Move to next item*/
psCurItem = psCurItem->psNext;
}
/*Move to next process*/
psCurProcess = psCurProcess->psNext;
}
return;
}
#endif /* DEBUG */
/*****************************************************************************/
/************************* External functions ********************************/
/*****************************************************************************/
/*****************************************************************************
FUNCTION : PVRSRVResManConnect
PURPOSE : Connect or disconnect for the resource manager
PARAMETERS : ui32ProcID Process ID
bConnect IMG_TRUE - connect, IMG_FALSE - disconnect
RETURNS : PVRSRV_NO_ERROR - success
*****************************************************************************/
IMG_EXPORT PVRSRV_ERROR IMG_CALLCONV PVRSRVResManConnect(IMG_UINT32 ui32ProcID, IMG_BOOL bConnect)
{
if(ui32ProcID == PVRSRVRESMAN_PROCESSID_FIND) ui32ProcID = RESMAN_PROCESSID_FIND;
if(bConnect)
{
ResManProcessConnect(ui32ProcID);
}
else
{
ResManProcessDisconnect(ui32ProcID);
}
return(PVRSRV_OK);
}
/*----------------------------------------------------------------------------
<function>
FUNCTION : SetMemInfoDirty
PURPOSE : sets all the mem-infos for all processes registered with resman as dirty
PARAMETERS :
RETURNS :
</function>
------------------------------------------------------------------------------*/
IMG_VOID SetMemInfoDirty(void)
{
RESMAN_ITEM *psResmanItem;
PRESMAN_PROCESS psCurProcess = sResList.psProcessList->psNext;
/* first get the resman process of this process */
/* ui32CurProcessID = HostGetCurrentProcessID();
psProcess = FindProcess(ui32CurProcessID);*/
if(!psCurProcess)
{
/* we were not running any process so do nothing */
return;
}
/*Walk the process list*/
while(psCurProcess != IMG_NULL)
{
psResmanItem = psCurProcess->psResItemList;
/* now cycle through all the resman items and if they are FBMEM then make their MEM_INFO structures invalid */
while(psResmanItem)
{
if(psResmanItem->ui32ResType == RESMAN_TYPE_FRAMBUFMEM)
{
/* make meminfo structure invalid */
*((PVRSRV_MEM_INFO*)psResmanItem->pvParam)->pui32Flags |= PVRSRV_MEMFLG_MEMORY_NOT_AVAILABLE;
}
psResmanItem = psResmanItem->psNext;
}
/*Move to next process*/
psCurProcess = psCurProcess->psNext;
}
}
/*----------------------------------------------------------------------------
<function>
FUNCTION : SaveRestoreBuffers
PURPOSE : Save and restore any surfaces that are marked as PVRSRV_MEMFLG_SAVERESTORE
PARAMETERS : IMG_BOOL bSaveBuffers
RETURNS :
</function>
------------------------------------------------------------------------------*/
IMG_VOID SaveRestoreBuffers(IMG_BOOL bSaveBuffers)
{
RESMAN_ITEM *psResmanItem;
PRESMAN_PROCESS psCurProcess = sResList.psProcessList->psNext;
PVRSRV_MEM_INFO *psMemInfo;
if(!psCurProcess)
{
/* we were not running any process so do nothing */
return;
}
/*Walk the process list*/
while(psCurProcess != IMG_NULL)
{
psResmanItem = psCurProcess->psResItemList;
/* now cycle through all the resman items and if they are FBMEM then make their MEM_INFO structures invalid */
while(psResmanItem)
{
if(psResmanItem->ui32ResType == RESMAN_TYPE_FRAMBUFMEM)
{
psMemInfo = (PVRSRV_MEM_INFO*)psResmanItem->pvParam;
if(*psMemInfo->pui32Flags & PVRSRV_MEMFLG_SAVERESTORE)
{
if(bSaveBuffers)
{
if (HostAllocMem(PVRSRV_HOST_NON_PAGEABLE_HEAP, psMemInfo->ui32AllocSize, &psMemInfo->pvSysBackupBuffer, 0)==PVRSRV_OK)
{
/* Copy from here to there */
HostMemCopy (psMemInfo->pvSysBackupBuffer,psMemInfo->pvLinAddr,psMemInfo->ui32AllocSize);
}
}
else
{
if(psMemInfo->pvSysBackupBuffer)
{
/* If we have a System backup buffer */
/* copy from the sysBackup buffer and then delete it */
HostMemCopy(psMemInfo->pvLinAddr,psMemInfo->pvSysBackupBuffer,psMemInfo->ui32AllocSize);
HostFreeMem(PVRSRV_HOST_NON_PAGEABLE_HEAP, psMemInfo->pvSysBackupBuffer);
psMemInfo->pvSysBackupBuffer=IMG_NULL;
*psMemInfo->pui32Flags &=(~PVRSRV_MEMFLG_MEMORY_NOT_AVAILABLE); /* Clear the dirty flag */
}
}
}
}
psResmanItem = psResmanItem->psNext;
}
/*Move to next process*/
psCurProcess = psCurProcess->psNext;
}
}
/******************************************************************************
End of file (resman.c)
******************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -