aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/ice4100/sgx535/common/buffer_manager.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/staging/ice4100/sgx535/common/buffer_manager.c')
-rwxr-xr-xdrivers/staging/ice4100/sgx535/common/buffer_manager.c122
1 files changed, 75 insertions, 47 deletions
diff --git a/drivers/staging/ice4100/sgx535/common/buffer_manager.c b/drivers/staging/ice4100/sgx535/common/buffer_manager.c
index af3f72437d9..cfbb9712def 100755
--- a/drivers/staging/ice4100/sgx535/common/buffer_manager.c
+++ b/drivers/staging/ice4100/sgx535/common/buffer_manager.c
@@ -490,7 +490,7 @@ ZeroBuf(BM_BUF * pBuf, BM_MAPPING * pMapping, u32 ui32Bytes, u32 ui32Flags)
return 1;
}
-static void FreeBuf(BM_BUF * pBuf, u32 ui32Flags)
+static void FreeBuf(BM_BUF * pBuf, u32 ui32Flags, int bFromAllocator)
{
BM_MAPPING *pMapping;
@@ -503,67 +503,80 @@ static void FreeBuf(BM_BUF * pBuf, u32 ui32Flags)
if (ui32Flags & PVRSRV_MEM_USER_SUPPLIED_DEVVADDR) {
- if (ui32Flags & PVRSRV_MEM_RAM_BACKED_ALLOCATION) {
+ if ((pBuf->ui32ExportCount == 0) && (pBuf->ui32RefCount == 0)) {
- PVR_DPF((PVR_DBG_ERROR,
- "FreeBuf: combination of DevVAddr management and RAM backing mode unsupported"));
- } else {
+ if(ui32Flags & PVRSRV_MEM_RAM_BACKED_ALLOCATION) {
+ PVR_DPF((PVR_DBG_ERROR,
+ "FreeBuf: combination of DevVAddr management and RAM backing mode unsupported"));
+ } else {
- OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, sizeof(BM_MAPPING),
- pMapping, NULL);
- pBuf->pMapping = NULL;
+ OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, sizeof(BM_MAPPING),
+ pMapping, NULL);
+ pBuf->pMapping = NULL;
+ }
}
} else {
if (pBuf->hOSMemHandle != pMapping->hOSMemHandle) {
- OSReleaseSubMemHandle(pBuf->hOSMemHandle, ui32Flags);
+ if ((pBuf->ui32ExportCount == 0) && (pBuf->ui32RefCount == 0)) {
+ OSReleaseSubMemHandle(pBuf->hOSMemHandle, ui32Flags);
+ }
}
if (ui32Flags & PVRSRV_MEM_RAM_BACKED_ALLOCATION) {
- RA_Free(pBuf->pMapping->pArena, pBuf->DevVAddr.uiAddr,
- 0);
+ if ((pBuf->ui32ExportCount == 0) && (pBuf->ui32RefCount == 0)) {
+ PVR_ASSERT(pBuf->ui32ExportCount == 0);
+
+ RA_Free(pBuf->pMapping->pArena, pBuf->DevVAddr.uiAddr, 0);
+ }
} else {
- switch (pMapping->eCpuMemoryOrigin) {
- case hm_wrapped:
- OSUnReservePhys(pMapping->CpuVAddr,
- pMapping->uSize, ui32Flags,
- pMapping->hOSMemHandle);
- break;
- case hm_wrapped_virtaddr:
- OSUnRegisterMem(pMapping->CpuVAddr,
- pMapping->uSize, ui32Flags,
- pMapping->hOSMemHandle);
- break;
- case hm_wrapped_scatter:
- OSUnReserveDiscontigPhys(pMapping->CpuVAddr,
- pMapping->uSize,
- ui32Flags,
- pMapping->
- hOSMemHandle);
- break;
- case hm_wrapped_scatter_virtaddr:
- OSUnRegisterDiscontigMem(pMapping->CpuVAddr,
- pMapping->uSize,
- ui32Flags,
- pMapping->
- hOSMemHandle);
- break;
- default:
- break;
+ if ((pBuf->ui32ExportCount == 0) && (pBuf->ui32RefCount == 0)) {
+ switch (pMapping->eCpuMemoryOrigin) {
+ case hm_wrapped:
+ OSUnReservePhys(pMapping->CpuVAddr,
+ pMapping->uSize, ui32Flags,
+ pMapping->hOSMemHandle);
+ break;
+ case hm_wrapped_virtaddr:
+ OSUnRegisterMem(pMapping->CpuVAddr,
+ pMapping->uSize, ui32Flags,
+ pMapping->hOSMemHandle);
+ break;
+ case hm_wrapped_scatter:
+ OSUnReserveDiscontigPhys(pMapping->CpuVAddr,
+ pMapping->uSize,
+ ui32Flags,
+ pMapping->
+ hOSMemHandle);
+ break;
+ case hm_wrapped_scatter_virtaddr:
+ OSUnRegisterDiscontigMem(pMapping->CpuVAddr,
+ pMapping->uSize,
+ ui32Flags,
+ pMapping->
+ hOSMemHandle);
+ break;
+ default:
+ break;
+ }
}
- DevMemoryFree(pMapping);
+ if (bFromAllocator)
+ DevMemoryFree(pMapping);
- OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, sizeof(BM_MAPPING),
- pMapping, NULL);
- pBuf->pMapping = NULL;
+ if ((pBuf->ui32ExportCount == 0) && (pBuf->ui32RefCount == 0)) {
+ OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, sizeof(BM_MAPPING),
+ pMapping, NULL);
+ pBuf->pMapping = NULL;
+ }
+ }
+ if ((pBuf->ui32ExportCount == 0) && (pBuf->ui32RefCount == 0)) {
+ OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, sizeof(BM_BUF), pBuf, NULL);
}
}
-
- OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, sizeof(BM_BUF), pBuf, NULL);
-
}
+
PVRSRV_ERROR BM_DestroyContext_AnyCb(BM_HEAP * psBMHeap)
{
if (psBMHeap->ui32Attribs
@@ -1226,7 +1239,7 @@ BM_Wrap(void *hDevMemHeap,
if (!HASH_Insert
(psBMContext->pBufferHash, (u32) sHashAddress.uiAddr,
(u32) pBuf)) {
- FreeBuf(pBuf, uFlags);
+ FreeBuf(pBuf, uFlags, 1);
PVR_DPF((PVR_DBG_ERROR, "BM_Wrap: HASH_Insert FAILED"));
return 0;
}
@@ -1248,6 +1261,21 @@ BM_Wrap(void *hDevMemHeap,
return 1;
}
+void BM_Export (BM_HANDLE hBuf)
+{
+ BM_BUF *pBuf = (BM_BUF *)hBuf;
+
+ pBuf->ui32ExportCount++;
+}
+
+void BM_FreeExport (BM_HANDLE hBuf, u32 ui32Flags)
+{
+ BM_BUF *pBuf = (BM_BUF *)hBuf;
+
+ pBuf->ui32ExportCount--;
+ FreeBuf (pBuf, ui32Flags, 0);
+}
+
void BM_Free(BM_HANDLE hBuf, u32 ui32Flags)
{
BM_BUF *pBuf = (BM_BUF *) hBuf;
@@ -1275,7 +1303,7 @@ void BM_Free(BM_HANDLE hBuf, u32 ui32Flags)
HASH_Remove(pBuf->pMapping->pBMHeap->pBMContext->
pBufferHash, (u32) sHashAddr.uiAddr);
}
- FreeBuf(pBuf, ui32Flags);
+ FreeBuf(pBuf, ui32Flags, 1);
}
}