aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/ice4100/sgx535/common/devicemem.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/staging/ice4100/sgx535/common/devicemem.c')
-rwxr-xr-xdrivers/staging/ice4100/sgx535/common/devicemem.c178
1 files changed, 100 insertions, 78 deletions
diff --git a/drivers/staging/ice4100/sgx535/common/devicemem.c b/drivers/staging/ice4100/sgx535/common/devicemem.c
index f7a38e59463..5afd85b4242 100755
--- a/drivers/staging/ice4100/sgx535/common/devicemem.c
+++ b/drivers/staging/ice4100/sgx535/common/devicemem.c
@@ -334,6 +334,38 @@ static PVRSRV_ERROR AllocDeviceMem(void *hDevCookie,
return (PVRSRV_OK);
}
+static PVRSRV_ERROR FreeDeviceMem2(PVRSRV_KERNEL_MEM_INFO *psMemInfo, int bFromAllocator)
+{
+ BM_HANDLE hBuffer;
+
+ if (!psMemInfo)
+ {
+ return PVRSRV_ERROR_INVALID_PARAMS;
+ }
+
+ hBuffer = psMemInfo->sMemBlk.hBuffer;
+
+
+ if (bFromAllocator)
+ BM_Free(hBuffer, psMemInfo->ui32Flags);
+ else
+ BM_FreeExport(hBuffer, psMemInfo->ui32Flags);
+
+
+ if ((psMemInfo->pvSysBackupBuffer) && bFromAllocator)
+ {
+
+ OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, psMemInfo->ui32AllocSize, psMemInfo->pvSysBackupBuffer, NULL);
+ psMemInfo->pvSysBackupBuffer = NULL;
+ }
+
+ if (psMemInfo->ui32RefCount == 0)
+ OSFreeMem(PVRSRV_PAGEABLE_SELECT, sizeof(PVRSRV_KERNEL_MEM_INFO), psMemInfo, NULL);
+
+
+ return(PVRSRV_OK);
+}
+
static PVRSRV_ERROR FreeDeviceMem(PVRSRV_KERNEL_MEM_INFO * psMemInfo)
{
BM_HANDLE hBuffer;
@@ -436,8 +468,6 @@ PVRSRV_ERROR PVRSRVAllocSyncInfoKM(void *hDevCookie,
psKernelSyncInfo->psSyncDataMemInfoKM->psKernelSyncInfo = NULL;
- psKernelSyncInfo->hResItem = NULL;
-
*ppsKernelSyncInfo = psKernelSyncInfo;
return PVRSRV_OK;
@@ -461,29 +491,39 @@ PVRSRV_ERROR PVRSRVFreeSyncInfoKM(PVRSRV_KERNEL_SYNC_INFO * psKernelSyncInfo)
return eError;
}
-static PVRSRV_ERROR FreeDeviceMemCallBack(void *pvParam, u32 ui32Param)
+static void freeWrapped(PVRSRV_KERNEL_MEM_INFO *psMemInfo)
+{
+ void *hOSWrapMem = psMemInfo->sMemBlk.hOSWrapMem;
+
+ if(psMemInfo->sMemBlk.psIntSysPAddr)
+ {
+ OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, sizeof(IMG_SYS_PHYADDR), psMemInfo->sMemBlk.psIntSysPAddr, NULL);
+ psMemInfo->sMemBlk.psIntSysPAddr = NULL;
+ }
+
+ if(hOSWrapMem)
+ {
+ OSReleasePhysPageAddr(hOSWrapMem);
+ }
+}
+
+static PVRSRV_ERROR FreeMemCallBackCommon(PVRSRV_KERNEL_MEM_INFO *psMemInfo, u32 ui32Param, int bFromAllocator)
{
PVRSRV_ERROR eError = PVRSRV_OK;
- PVRSRV_KERNEL_MEM_INFO *psMemInfo = pvParam;
psMemInfo->ui32RefCount--;
- if (psMemInfo->ui32Flags & PVRSRV_MEM_EXPORTED) {
+ if ((psMemInfo->ui32Flags & PVRSRV_MEM_EXPORTED) &&
+ (bFromAllocator == 1)) {
void *hMemInfo = NULL;
- if (psMemInfo->ui32RefCount != 0) {
- PVR_DPF((PVR_DBG_ERROR,
- "FreeDeviceMemCallBack: mappings are open in other processes"));
- return PVRSRV_ERROR_GENERIC;
- }
-
eError = PVRSRVFindHandle(KERNEL_HANDLE_BASE,
&hMemInfo,
psMemInfo,
PVRSRV_HANDLE_TYPE_MEM_INFO);
if (eError != PVRSRV_OK) {
PVR_DPF((PVR_DBG_ERROR,
- "FreeDeviceMemCallBack: can't find exported meminfo in the global handle list"));
+ "FreeMemCallBackCommon: can't find exported meminfo in the global handle list"));
return eError;
}
@@ -492,27 +532,43 @@ static PVRSRV_ERROR FreeDeviceMemCallBack(void *pvParam, u32 ui32Param)
PVRSRV_HANDLE_TYPE_MEM_INFO);
if (eError != PVRSRV_OK) {
PVR_DPF((PVR_DBG_ERROR,
- "FreeDeviceMemCallBack: PVRSRVReleaseHandle failed for exported meminfo"));
+ "FreeMemCallBackCommon: PVRSRVReleaseHandle failed for exported meminfo"));
return eError;
}
}
- PVR_ASSERT(psMemInfo->ui32RefCount == 0);
-
- if (psMemInfo->psKernelSyncInfo) {
- psMemInfo->psKernelSyncInfo->ui32RefCount--;
+ if (psMemInfo->ui32RefCount == 0) {
+ switch(psMemInfo->memType)
+ {
- if (psMemInfo->psKernelSyncInfo->ui32RefCount == 0) {
- eError =
- PVRSRVFreeSyncInfoKM(psMemInfo->psKernelSyncInfo);
+ case PVRSRV_MEMTYPE_WRAPPED:
+ freeWrapped(psMemInfo);
+ case PVRSRV_MEMTYPE_DEVICE:
+ if (psMemInfo->psKernelSyncInfo)
+ {
+ psMemInfo->psKernelSyncInfo->ui32RefCount--;
+ if (psMemInfo->psKernelSyncInfo->ui32RefCount == 0)
+ {
+ eError = PVRSRVFreeSyncInfoKM(psMemInfo->psKernelSyncInfo);
+ }
+ }
+ case PVRSRV_MEMTYPE_DEVICECLASS:
+ break;
+ default:
+ PVR_DPF((PVR_DBG_ERROR, "FreeMemCallBackCommon: Unknown memType"));
+ return PVRSRV_ERROR_GENERIC;
}
}
- if (eError == PVRSRV_OK) {
- eError = FreeDeviceMem(psMemInfo);
- }
+ return FreeDeviceMem2(psMemInfo, bFromAllocator);
+}
- return eError;
+static PVRSRV_ERROR FreeDeviceMemCallBack(void *pvParam,
+ u32 ui32Param)
+{
+ PVRSRV_KERNEL_MEM_INFO *psMemInfo = (PVRSRV_KERNEL_MEM_INFO *)pvParam;
+
+ return FreeMemCallBackCommon(psMemInfo, ui32Param, 1);
}
PVRSRV_ERROR PVRSRVFreeDeviceMemKM(void *hDevCookie,
@@ -600,6 +656,8 @@ PVRSRV_ERROR _PVRSRVAllocDeviceMemKM(void *hDevCookie,
psMemInfo->ui32RefCount++;
+ psMemInfo->memType = PVRSRV_MEMTYPE_DEVICE;
+
return (PVRSRV_OK);
free_mainalloc:
@@ -646,38 +704,9 @@ PVRSRV_ERROR PVRSRVUnwrapExtMemoryKM(PVRSRV_KERNEL_MEM_INFO * psMemInfo)
static PVRSRV_ERROR UnwrapExtMemoryCallBack(void *pvParam, u32 ui32Param)
{
- PVRSRV_ERROR eError = PVRSRV_OK;
PVRSRV_KERNEL_MEM_INFO *psMemInfo = pvParam;
- void *hOSWrapMem;
-
- hOSWrapMem = psMemInfo->sMemBlk.hOSWrapMem;
-
- if (psMemInfo->psKernelSyncInfo) {
- psMemInfo->psKernelSyncInfo->ui32RefCount--;
- if (psMemInfo->psKernelSyncInfo->ui32RefCount == 0) {
- eError =
- PVRSRVFreeSyncInfoKM(psMemInfo->psKernelSyncInfo);
- }
- }
-
- if (psMemInfo->sMemBlk.psIntSysPAddr) {
- OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, sizeof(IMG_SYS_PHYADDR),
- psMemInfo->sMemBlk.psIntSysPAddr, NULL);
- psMemInfo->sMemBlk.psIntSysPAddr = NULL;
- }
- if (eError == PVRSRV_OK) {
-
- psMemInfo->ui32RefCount--;
-
- eError = FreeDeviceMem(psMemInfo);
- }
-
- if (hOSWrapMem) {
- OSReleasePhysPageAddr(hOSWrapMem);
- }
-
- return eError;
+ return FreeMemCallBackCommon(psMemInfo, ui32Param, 1);
}
PVRSRV_ERROR PVRSRVWrapExtMemoryKM(void *hDevCookie,
@@ -839,6 +868,8 @@ PVRSRV_ERROR PVRSRVWrapExtMemoryKM(void *hDevCookie,
psMemInfo->psKernelSyncInfo->ui32RefCount++;
+ psMemInfo->memType = PVRSRV_MEMTYPE_WRAPPED;
+
psMemInfo->ui32RefCount++;
psMemInfo->sMemBlk.hResItem =
@@ -896,7 +927,7 @@ static PVRSRV_ERROR UnmapDeviceMemoryCallBack(void *pvParam, u32 ui32Param)
if (psMapData->psMemInfo->sMemBlk.psIntSysPAddr) {
OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, sizeof(IMG_SYS_PHYADDR),
- psMapData->psMemInfo->sMemBlk.psIntSysPAddr, NULL);
+ psMapData->psMemInfo->sMemBlk.psIntSysPAddr, NULL);
psMapData->psMemInfo->sMemBlk.psIntSysPAddr = NULL;
}
@@ -919,30 +950,10 @@ static PVRSRV_ERROR UnmapDeviceMemoryCallBack(void *pvParam, u32 ui32Param)
return eError;
}
- psMapData->psSrcMemInfo->ui32RefCount--;
-
- if (psMapData->psSrcMemInfo->ui32RefCount == 1 &&
- psMapData->psSrcMemInfo->bPendingFree == 1) {
-
- if (psMapData->psSrcMemInfo->sMemBlk.hResItem != NULL) {
-
- eError =
- ResManFreeResByPtr(psMapData->psSrcMemInfo->sMemBlk.
- hResItem);
- if (eError != PVRSRV_OK) {
- PVR_DPF((PVR_DBG_ERROR,
- "UnmapDeviceMemoryCallBack: Failed to free SRC meminfo"));
- PVR_DBG_BREAK;
- }
- } else {
-
- eError =
- FreeDeviceMemCallBack(psMapData->psSrcMemInfo, 0);
- }
- }
+ eError = FreeMemCallBackCommon(psMapData->psSrcMemInfo, 0, 0);
OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, sizeof(RESMAN_MAP_DEVICE_MEM_DATA),
- psMapData, NULL);
+ psMapData, NULL);
return eError;
}
@@ -1067,8 +1078,14 @@ PVRSRV_ERROR PVRSRVMapDeviceMemoryKM(PVRSRV_PER_PROCESS_DATA * psPerProc,
psMemInfo->pvSysBackupBuffer = NULL;
+ psMemInfo->ui32RefCount++;
+
psSrcMemInfo->ui32RefCount++;
+ BM_Export(psSrcMemInfo->sMemBlk.hBuffer);
+
+ psMemInfo->memType = PVRSRV_MEMTYPE_MAPPED;
+
psMapData->psMemInfo = psMemInfo;
psMapData->psSrcMemInfo = psSrcMemInfo;
@@ -1120,7 +1137,8 @@ static PVRSRV_ERROR UnmapDeviceClassMemoryCallBack(void *pvParam, u32 ui32Param)
{
PVRSRV_KERNEL_MEM_INFO *psMemInfo = pvParam;
- return FreeDeviceMem(psMemInfo);
+ return FreeMemCallBackCommon(psMemInfo, ui32Param, 1);
+
}
PVRSRV_ERROR PVRSRVMapDeviceClassMemoryKM(PVRSRV_PER_PROCESS_DATA * psPerProc,
@@ -1247,6 +1265,10 @@ PVRSRV_ERROR PVRSRVMapDeviceClassMemoryKM(PVRSRV_PER_PROCESS_DATA * psPerProc,
RESMAN_TYPE_DEVICECLASSMEM_MAPPING, psMemInfo, 0,
UnmapDeviceClassMemoryCallBack);
+ psMemInfo->ui32RefCount++;
+
+ psMemInfo->memType = PVRSRV_MEMTYPE_DEVICECLASS;
+
*ppsMemInfo = psMemInfo;
return PVRSRV_OK;