gfx: pvr: add an interface for inc/dec meminfo ref count
authorAnder Conselvan de Oliveira <ander.conselvan.de.oliveira@intel.com>
Wed, 15 Feb 2012 13:02:23 +0000 (15:02 +0200)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Tue, 3 Jul 2012 09:29:55 +0000 (12:29 +0300)
The drm part of the pvr driver stores pointers to mem infos but those
may be freed by the clients. If the reference counts aren't increased
properly, those mem infos may be freed while the kernel still
references them.

Signed-off-by: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira@intel.com>
Reviewed-by: Imre Deak <imre.deak@intel.com>
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
drivers/staging/mrst/pvr/services4/include/servicesint.h
drivers/staging/mrst/pvr/services4/srvkm/common/buffer_manager.c
drivers/staging/mrst/pvr/services4/srvkm/common/devicemem.c
drivers/staging/mrst/pvr/services4/srvkm/include/buffer_manager.h

index d3755f4..31699dc 100644 (file)
@@ -282,6 +282,12 @@ PVRSRVMapMemInfoMem(const PVRSRV_CONNECTION *psConnection,
                     IMG_HANDLE hKernelMemInfo,
                     PVRSRV_CLIENT_MEM_INFO **ppsClientMemInfo);
 
+IMG_IMPORT
+IMG_VOID PVRSRVRefDeviceMemKM(PVRSRV_KERNEL_MEM_INFO *psMemInfo);
+
+IMG_IMPORT
+IMG_VOID PVRSRVUnrefDeviceMemKM(PVRSRV_KERNEL_MEM_INFO *psMemInfo);
+
 #if defined(PVRSRV_RESOURCE_PROFILING)
 PVRSRV_KERNEL_MEM_INFO* PVRSRVGetMapMemInfo(IMG_VOID *psMap);
 #endif
index 326e958..e8f23d0 100644 (file)
@@ -1490,6 +1490,14 @@ BM_FreeExport(BM_HANDLE hBuf,
 }
 
 IMG_VOID
+BM_Reference(BM_HANDLE hBuf)
+{
+       BM_BUF *pBuf = (BM_BUF *)hBuf;
+
+       pBuf->ui32RefCount++;
+}
+
+IMG_VOID
 BM_Free (BM_HANDLE hBuf,
                IMG_UINT32 ui32Flags)
 {
index e3999b6..0d80713 100644 (file)
@@ -1316,6 +1316,31 @@ ErrorExit:
 }
 
 
+void PVRSRVRefDeviceMemKM(PVRSRV_KERNEL_MEM_INFO *psMemInfo)
+{
+       if (!psMemInfo)
+               return;
+
+       /* Reference count is ignored on PVRSRV_MEMTYPE_MAPPED and may be busted
+        * on other memory types too, so don't try to support all cases.
+        */
+       if (psMemInfo->memType != PVRSRV_MEMTYPE_DEVICE) {
+               PVR_DPF((PVR_DBG_ERROR, "PVRSRVRefDeviceMemKM: only PVRSRV_MEMTYPE_DEVICE is supported"));
+               return;
+       }
+
+       psMemInfo->ui32RefCount++;
+       BM_Reference(psMemInfo->sMemBlk.hBuffer);
+}
+
+void PVRSRVUnrefDeviceMemKM(PVRSRV_KERNEL_MEM_INFO *psMemInfo)
+{
+       if (!psMemInfo || psMemInfo->memType != PVRSRV_MEMTYPE_DEVICE)
+               return;
+
+       FreeMemCallBackCommon(psMemInfo, 0, IMG_TRUE);
+}
+
 IMG_EXPORT
 PVRSRV_ERROR IMG_CALLCONV PVRSRVUnmapDeviceClassMemoryKM(PVRSRV_KERNEL_MEM_INFO *psMemInfo)
 {
index 0a8e0ad..c6ec4bd 100644 (file)
@@ -204,6 +204,8 @@ IMG_VOID BM_Export(BM_HANDLE hBuf);
 
 IMG_VOID BM_FreeExport(BM_HANDLE hBuf, IMG_UINT32 ui32Flags);
 
+IMG_VOID BM_Reference(BM_HANDLE hBuf);
+
 #if defined(__cplusplus)
 }
 #endif