summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'jacinto6/sgx_src/eurasia_km/services4/srvkm/common/devicemem.c')
-rw-r--r--jacinto6/sgx_src/eurasia_km/services4/srvkm/common/devicemem.c637
1 files changed, 352 insertions, 285 deletions
diff --git a/jacinto6/sgx_src/eurasia_km/services4/srvkm/common/devicemem.c b/jacinto6/sgx_src/eurasia_km/services4/srvkm/common/devicemem.c
index d28136f..f6d4463 100644
--- a/jacinto6/sgx_src/eurasia_km/services4/srvkm/common/devicemem.c
+++ b/jacinto6/sgx_src/eurasia_km/services4/srvkm/common/devicemem.c
@@ -49,21 +49,24 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
49#include "osfunc.h" 49#include "osfunc.h"
50#include "devicemem.h" 50#include "devicemem.h"
51 51
52#if defined(SUPPORT_DRM_GEM)
53#include "dmabuf.h"
54#endif
55
56#if defined(SUPPORT_ION) 52#if defined(SUPPORT_ION)
57#include "ion.h" 53#include "ion.h"
58#include "env_perproc.h" 54#include "env_perproc.h"
55#include "ion_sync.h"
56
57/* Start size of the g_IonSyncHash hash table */
58#define ION_SYNC_HASH_SIZE 20
59HASH_TABLE *g_psIonSyncHash = IMG_NULL;
59#endif 60#endif
60 61
61#if defined(SUPPORT_DRM_GEM) || defined(SUPPORT_ION) 62#if defined(SUPPORT_DMABUF)
62#include "external_sync.h" 63#include "dmabuf.h"
64#include "dmabuf_sync.h"
65#include "pvr_linux_fence.h"
63 66
64/* Start size of the g_ExternalSyncHash hash table */ 67/* Start size of the g_DmaBufSyncHash hash table */
65#define EXTERNAL_SYNC_HASH_SIZE 20 68#define DMABUF_SYNC_HASH_SIZE 20
66HASH_TABLE *g_psExternalSyncHash = IMG_NULL; 69HASH_TABLE *g_psDmaBufSyncHash = IMG_NULL;
67#endif 70#endif
68 71
69#include "lists.h" 72#include "lists.h"
@@ -114,8 +117,8 @@ typedef struct _PVRSRV_DC_MAPINFO_
114 117
115static IMG_UINT32 g_ui32SyncUID = 0; 118static IMG_UINT32 g_ui32SyncUID = 0;
116#if defined (MEM_TRACK_INFO_DEBUG) 119#if defined (MEM_TRACK_INFO_DEBUG)
117PVRSRV_MEM_TRACK_INFO *g_psMemTrackInfoHead = NULL; 120PVRSRV_MEM_TRACK_INFO *g_psMemTrackInfoHead = IMG_NULL;
118PVRSRV_MEM_TRACK_INFO *g_psMemTrackInfoTail = NULL; 121PVRSRV_MEM_TRACK_INFO *g_psMemTrackInfoTail = IMG_NULL;
119IMG_UINT32 g_ui32NumOfOpsRecorded = 0; 122IMG_UINT32 g_ui32NumOfOpsRecorded = 0;
120#endif 123#endif
121 124
@@ -182,7 +185,7 @@ IMG_EXPORT
182IMG_VOID IMG_CALLCONV PVRSRVPrintMemTrackInfo(IMG_UINT32 ui32FaultAddr) 185IMG_VOID IMG_CALLCONV PVRSRVPrintMemTrackInfo(IMG_UINT32 ui32FaultAddr)
183{ 186{
184 PVRSRV_MEM_TRACK_INFO *psMemTrackInfo; 187 PVRSRV_MEM_TRACK_INFO *psMemTrackInfo;
185 const IMG_CHAR *apszMemOpNames[] = {"UNKNOWN", "DEVICE", "DEVICECLASS", "WRAPPED", "MAPPED", "ION", "ALLOC", "FREE"}; 188 static const IMG_CHAR * const apszMemOpNames[] = {"UNKNOWN", "DEVICE", "DEVICECLASS", "WRAPPED", "MAPPED", "ION", "DMA-BUF" "ALLOC", "FREE"};
186 psMemTrackInfo = g_psMemTrackInfoHead; 189 psMemTrackInfo = g_psMemTrackInfoHead;
187 190
188 PVR_DPF((PVR_DBG_MESSAGE,"PVRSRVMemTrackInfo: Dumping mem tracking info\n")); 191 PVR_DPF((PVR_DBG_MESSAGE,"PVRSRVMemTrackInfo: Dumping mem tracking info\n"));
@@ -619,6 +622,9 @@ static PVRSRV_ERROR AllocDeviceMem(IMG_HANDLE hDevCookie,
619 ui32NumVirtChunks, 622 ui32NumVirtChunks,
620 ui32NumPhysChunks, 623 ui32NumPhysChunks,
621 pabMapChunk, 624 pabMapChunk,
625 #if defined (PVRSRV_DEVMEM_TIME_STATS)
626 &psMemInfo->ui32TimeToDevMap,
627 #endif
622 &hBuffer); 628 &hBuffer);
623 629
624 if (!bBMError) 630 if (!bBMError)
@@ -679,7 +685,12 @@ static PVRSRV_ERROR FreeDeviceMem2(PVRSRV_KERNEL_MEM_INFO *psMemInfo, PVRSRV_FRE
679 switch(eCallbackOrigin) 685 switch(eCallbackOrigin)
680 { 686 {
681 case PVRSRV_FREE_CALLBACK_ORIGIN_ALLOCATOR: 687 case PVRSRV_FREE_CALLBACK_ORIGIN_ALLOCATOR:
682 BM_Free(hBuffer, psMemInfo->ui32Flags); 688 BM_Free(hBuffer,
689 psMemInfo->ui32Flags
690 #if defined(PVRSRV_DEVMEM_TIME_STATS)
691 ,psMemInfo->pui32TimeToDevUnmap
692 #endif
693 );
683 break; 694 break;
684 case PVRSRV_FREE_CALLBACK_ORIGIN_IMPORTER: 695 case PVRSRV_FREE_CALLBACK_ORIGIN_IMPORTER:
685 BM_FreeExport(hBuffer, psMemInfo->ui32Flags); 696 BM_FreeExport(hBuffer, psMemInfo->ui32Flags);
@@ -712,7 +723,11 @@ static PVRSRV_ERROR FreeDeviceMem(PVRSRV_KERNEL_MEM_INFO *psMemInfo)
712 723
713 hBuffer = psMemInfo->sMemBlk.hBuffer; 724 hBuffer = psMemInfo->sMemBlk.hBuffer;
714 725
715 BM_Free(hBuffer, psMemInfo->ui32Flags); 726 BM_Free(hBuffer, psMemInfo->ui32Flags
727 #if defined(PVRSRV_DEVMEM_TIME_STATS)
728 , IMG_NULL
729 #endif
730 );
716 731
717 if(psMemInfo->pvSysBackupBuffer) 732 if(psMemInfo->pvSysBackupBuffer)
718 { 733 {
@@ -814,6 +829,10 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVAllocSyncInfoKM(IMG_HANDLE hDevCookie,
814 psSyncData->ui32LastReadOpDumpVal = 0; 829 psSyncData->ui32LastReadOpDumpVal = 0;
815 psSyncData->ui64LastWrite = 0; 830 psSyncData->ui64LastWrite = 0;
816 831
832#if defined(SUPPORT_DMABUF)
833 psKernelSyncInfo->hFenceContext = IMG_NULL;
834#endif
835
817#if defined(SUPPORT_PER_SYNC_DEBUG) 836#if defined(SUPPORT_PER_SYNC_DEBUG)
818 psKernelSyncInfo->ui32OperationMask = 0; 837 psKernelSyncInfo->ui32OperationMask = 0;
819 memset(psKernelSyncInfo->aui32OpInfo, 0, sizeof(psKernelSyncInfo->aui32OpInfo)); 838 memset(psKernelSyncInfo->aui32OpInfo, 0, sizeof(psKernelSyncInfo->aui32OpInfo));
@@ -963,21 +982,21 @@ static IMG_VOID freeExternal(PVRSRV_KERNEL_MEM_INFO *psMemInfo)
963 OSReleasePhysPageAddr(hOSWrapMem); 982 OSReleasePhysPageAddr(hOSWrapMem);
964 } 983 }
965 } 984 }
966#if defined(SUPPORT_DRM_GEM) 985#if defined(SUPPORT_ION)
967 else if (psMemInfo->memType == PVRSRV_MEMTYPE_DMABUF) 986 else if (psMemInfo->memType == PVRSRV_MEMTYPE_ION)
968 { 987 {
969 if (hOSWrapMem) 988 if (hOSWrapMem)
970 { 989 {
971 DmabufUnimportBufferAndReleasePhysAddr(hOSWrapMem); 990 IonUnimportBufferAndReleasePhysAddr(hOSWrapMem);
972 } 991 }
973 } 992 }
974#endif 993#endif
975#if defined(SUPPORT_ION) 994#if defined(SUPPORT_DMABUF)
976 else if (psMemInfo->memType == PVRSRV_MEMTYPE_ION) 995 else if (psMemInfo->memType == PVRSRV_MEMTYPE_DMABUF)
977 { 996 {
978 if (hOSWrapMem) 997 if (hOSWrapMem)
979 { 998 {
980 IonUnimportBufferAndReleasePhysAddr(hOSWrapMem); 999 DmaBufUnimportAndReleasePhysAddr(hOSWrapMem);
981 } 1000 }
982 } 1001 }
983#endif 1002#endif
@@ -1071,14 +1090,21 @@ PVRSRV_ERROR FreeMemCallBackCommon(PVRSRV_KERNEL_MEM_INFO *psMemInfo,
1071 freeExternal(psMemInfo); 1090 freeExternal(psMemInfo);
1072 case PVRSRV_MEMTYPE_DEVICE: 1091 case PVRSRV_MEMTYPE_DEVICE:
1073 case PVRSRV_MEMTYPE_DEVICECLASS: 1092 case PVRSRV_MEMTYPE_DEVICECLASS:
1074#if defined(SUPPORT_DRM_GEM) || defined(SUPPORT_ION) 1093#if defined(SUPPORT_ION)
1075 if (psMemInfo->hExternalSyncInfo) 1094 if (psMemInfo->hIonSyncInfo)
1076 { 1095 {
1077 /* 1096 /*
1078 For syncs attached to Ion imported buffers we handle 1097 For syncs attached to Ion imported buffers we handle
1079 things a little differently 1098 things a little differently
1080 */ 1099 */
1081 PVRSRVExternalBufferSyncInfoDecRef(psMemInfo->hExternalSyncInfo, psMemInfo); 1100 PVRSRVIonBufferSyncInfoDecRef(psMemInfo->hIonSyncInfo, psMemInfo);
1101 }
1102 else
1103#endif
1104#if defined(SUPPORT_DMABUF)
1105 if (psMemInfo->hDmaBufSyncInfo)
1106 {
1107 PVRSRVDmaBufSyncInfoDecRef(psMemInfo->hDmaBufSyncInfo, psMemInfo);
1082 } 1108 }
1083 else 1109 else
1084#endif 1110#endif
@@ -1090,7 +1116,7 @@ PVRSRV_ERROR FreeMemCallBackCommon(PVRSRV_KERNEL_MEM_INFO *psMemInfo,
1090 } 1116 }
1091 break; 1117 break;
1092 default: 1118 default:
1093 PVR_DPF((PVR_DBG_ERROR, "FreeMemCallBackCommon: Unknown memType: %d", psMemInfo->memType)); 1119 PVR_DPF((PVR_DBG_ERROR, "FreeMemCallBackCommon: Unknown memType"));
1094 eError = PVRSRV_ERROR_INVALID_MEMINFO; 1120 eError = PVRSRV_ERROR_INVALID_MEMINFO;
1095 } 1121 }
1096 } 1122 }
@@ -1393,24 +1419,35 @@ free_mainalloc:
1393 return eError; 1419 return eError;
1394} 1420}
1395 1421
1396#if defined(SUPPORT_DRM_GEM) || defined(SUPPORT_ION) 1422#if defined(SUPPORT_ION)
1397PVRSRV_ERROR PVRSRVExternalBufferSyncAcquire(IMG_HANDLE hUnique, 1423static PVRSRV_ERROR IonUnmapCallback(IMG_PVOID pvParam,
1424 IMG_UINT32 ui32Param,
1425 IMG_BOOL bDummy)
1426{
1427 PVRSRV_KERNEL_MEM_INFO *psMemInfo = (PVRSRV_KERNEL_MEM_INFO *)pvParam;
1428
1429 PVR_UNREFERENCED_PARAMETER(bDummy);
1430
1431 return FreeMemCallBackCommon(psMemInfo, ui32Param, PVRSRV_FREE_CALLBACK_ORIGIN_ALLOCATOR);
1432}
1433
1434PVRSRV_ERROR PVRSRVIonBufferSyncAcquire(IMG_HANDLE hUnique,
1398 IMG_HANDLE hDevCookie, 1435 IMG_HANDLE hDevCookie,
1399 IMG_HANDLE hDevMemContext, 1436 IMG_HANDLE hDevMemContext,
1400 PVRSRV_EXTERNAL_SYNC_INFO **ppsExternalSyncInfo) 1437 PVRSRV_ION_SYNC_INFO **ppsIonSyncInfo)
1401{ 1438{
1402 PVRSRV_EXTERNAL_SYNC_INFO *psExternalSyncInfo; 1439 PVRSRV_ION_SYNC_INFO *psIonSyncInfo;
1403 PVRSRV_ERROR eError; 1440 PVRSRV_ERROR eError;
1404 IMG_BOOL bRet; 1441 IMG_BOOL bRet;
1405 1442
1406 /* Check the hash to see if we already have a sync for this buffer */ 1443 /* Check the hash to see if we already have a sync for this buffer */
1407 psExternalSyncInfo = (PVRSRV_EXTERNAL_SYNC_INFO *) HASH_Retrieve(g_psExternalSyncHash, (IMG_UINTPTR_T) hUnique); 1444 psIonSyncInfo = (PVRSRV_ION_SYNC_INFO *) HASH_Retrieve(g_psIonSyncHash, (IMG_UINTPTR_T) hUnique);
1408 if (psExternalSyncInfo == 0) 1445 if (psIonSyncInfo == 0)
1409 { 1446 {
1410 /* This buffer is new to us, create the syncinfo for it */ 1447 /* This buffer is new to us, create the syncinfo for it */
1411 eError = OSAllocMem(PVRSRV_PAGEABLE_SELECT, 1448 eError = OSAllocMem(PVRSRV_PAGEABLE_SELECT,
1412 sizeof(PVRSRV_EXTERNAL_SYNC_INFO), 1449 sizeof(PVRSRV_ION_SYNC_INFO),
1413 (IMG_VOID **)&psExternalSyncInfo, IMG_NULL, 1450 (IMG_VOID **)&psIonSyncInfo, IMG_NULL,
1414 "Ion Synchronization Info"); 1451 "Ion Synchronization Info");
1415 if (eError != PVRSRV_OK) 1452 if (eError != PVRSRV_OK)
1416 { 1453 {
@@ -1419,109 +1456,96 @@ PVRSRV_ERROR PVRSRVExternalBufferSyncAcquire(IMG_HANDLE hUnique,
1419 1456
1420 eError = PVRSRVAllocSyncInfoKM(hDevCookie, 1457 eError = PVRSRVAllocSyncInfoKM(hDevCookie,
1421 hDevMemContext, 1458 hDevMemContext,
1422 &psExternalSyncInfo->psSyncInfo); 1459 &psIonSyncInfo->psSyncInfo);
1423 if (eError != PVRSRV_OK) 1460 if (eError != PVRSRV_OK)
1424 { 1461 {
1425 OSFreeMem(PVRSRV_PAGEABLE_SELECT, 1462 OSFreeMem(PVRSRV_PAGEABLE_SELECT,
1426 sizeof(PVRSRV_EXTERNAL_SYNC_INFO), 1463 sizeof(PVRSRV_ION_SYNC_INFO),
1427 psExternalSyncInfo, 1464 psIonSyncInfo,
1428 IMG_NULL); 1465 IMG_NULL);
1429 1466
1430 return eError; 1467 return eError;
1431 } 1468 }
1432#if defined(SUPPORT_MEMINFO_IDS) 1469#if defined(SUPPORT_MEMINFO_IDS)
1433 psExternalSyncInfo->ui64Stamp = ++g_ui64MemInfoID; 1470 psIonSyncInfo->ui64Stamp = ++g_ui64MemInfoID;
1434#else 1471#else
1435 psExternalSyncInfo->ui64Stamp = 0; 1472 psIonSyncInfo->ui64Stamp = 0;
1436#endif 1473#endif
1437 bRet = HASH_Insert(g_psExternalSyncHash, (IMG_UINTPTR_T) hUnique, (IMG_UINTPTR_T) psExternalSyncInfo); 1474 bRet = HASH_Insert(g_psIonSyncHash, (IMG_UINTPTR_T) hUnique, (IMG_UINTPTR_T) psIonSyncInfo);
1438 if (!bRet) 1475 if (!bRet)
1439 { 1476 {
1440 eError = PVRSRV_ERROR_OUT_OF_MEMORY; 1477 eError = PVRSRV_ERROR_OUT_OF_MEMORY;
1441 1478
1442 PVRSRVKernelSyncInfoDecRef(psExternalSyncInfo->psSyncInfo, IMG_NULL); 1479 PVRSRVKernelSyncInfoDecRef(psIonSyncInfo->psSyncInfo, IMG_NULL);
1443 OSFreeMem(PVRSRV_PAGEABLE_SELECT, 1480 OSFreeMem(PVRSRV_PAGEABLE_SELECT,
1444 sizeof(PVRSRV_EXTERNAL_SYNC_INFO), 1481 sizeof(PVRSRV_ION_SYNC_INFO),
1445 psExternalSyncInfo, 1482 psIonSyncInfo,
1446 IMG_NULL); 1483 IMG_NULL);
1447 1484
1448 return eError; 1485 return eError;
1449 } 1486 }
1450 1487
1451 psExternalSyncInfo->ui32RefCount = 0; 1488 psIonSyncInfo->ui32RefCount = 0;
1452 psExternalSyncInfo->hUnique = hUnique; 1489 psIonSyncInfo->hUnique = hUnique;
1453 } 1490 }
1454 1491
1455 psExternalSyncInfo->ui32RefCount++; 1492 psIonSyncInfo->ui32RefCount++;
1456 *ppsExternalSyncInfo = psExternalSyncInfo; 1493 *ppsIonSyncInfo = psIonSyncInfo;
1457 return PVRSRV_OK; 1494 return PVRSRV_OK;
1458} 1495}
1459 1496
1460IMG_VOID PVRSRVExternalBufferSyncRelease(PVRSRV_EXTERNAL_SYNC_INFO *psExternalSyncInfo) 1497IMG_VOID PVRSRVIonBufferSyncRelease(PVRSRV_ION_SYNC_INFO *psIonSyncInfo)
1461{ 1498{
1462 psExternalSyncInfo->ui32RefCount--; 1499 psIonSyncInfo->ui32RefCount--;
1463 1500
1464 if (psExternalSyncInfo->ui32RefCount == 0) 1501 if (psIonSyncInfo->ui32RefCount == 0)
1465 { 1502 {
1466 PVRSRV_EXTERNAL_SYNC_INFO *psLookup; 1503 PVRSRV_ION_SYNC_INFO *psLookup;
1467 /* 1504 /*
1468 If we're holding the last reference to the syncinfo 1505 If we're holding the last reference to the syncinfo
1469 then free it 1506 then free it
1470 */ 1507 */
1471 psLookup = (PVRSRV_EXTERNAL_SYNC_INFO *) HASH_Remove(g_psExternalSyncHash, (IMG_UINTPTR_T) psExternalSyncInfo->hUnique); 1508 psLookup = (PVRSRV_ION_SYNC_INFO *) HASH_Remove(g_psIonSyncHash, (IMG_UINTPTR_T) psIonSyncInfo->hUnique);
1472 PVR_ASSERT(psLookup == psExternalSyncInfo); 1509 PVR_ASSERT(psLookup == psIonSyncInfo);
1473 PVRSRVKernelSyncInfoDecRef(psExternalSyncInfo->psSyncInfo, IMG_NULL); 1510 PVRSRVKernelSyncInfoDecRef(psIonSyncInfo->psSyncInfo, IMG_NULL);
1474 OSFreeMem(PVRSRV_PAGEABLE_SELECT, 1511 OSFreeMem(PVRSRV_PAGEABLE_SELECT,
1475 sizeof(PVRSRV_EXTERNAL_SYNC_INFO), 1512 sizeof(PVRSRV_ION_SYNC_INFO),
1476 psExternalSyncInfo, 1513 psIonSyncInfo,
1477 IMG_NULL); 1514 IMG_NULL);
1478 } 1515 }
1479} 1516}
1480#endif //defined(SUPPORT_DRM_GEM) || defined(SUPPORT_ION)
1481
1482#if defined(SUPPORT_DRM_GEM)
1483static PVRSRV_ERROR DmabufUnmapCallback(IMG_PVOID pvParam,
1484 IMG_UINT32 ui32Param,
1485 IMG_BOOL bDummy)
1486{
1487 PVRSRV_KERNEL_MEM_INFO *psMemInfo = (PVRSRV_KERNEL_MEM_INFO *)pvParam;
1488
1489 PVR_UNREFERENCED_PARAMETER(bDummy);
1490
1491 return FreeMemCallBackCommon(psMemInfo, ui32Param, PVRSRV_FREE_CALLBACK_ORIGIN_ALLOCATOR);
1492}
1493 1517
1494/*! 1518/*!
1495****************************************************************************** 1519******************************************************************************
1496 1520
1497 @Function PVRSRVMapDmabufKM 1521 @Function PVRSRVMapIonHandleKM
1498 1522
1499 @Description 1523 @Description
1500 1524
1501 Map a DMABUF buffer into the specified device memory context 1525 Map an ION buffer into the specified device memory context
1502 1526
1503 @Input psPerProc : PerProcess data 1527 @Input psPerProc : PerProcess data
1504 @Input hDevCookie : Device node cookie 1528 @Input hDevCookie : Device node cookie
1505 @Input hDevMemHeap : Heap dmabuf handles are mapped into 1529 @Input hDevMemHeap : Heap ion handles are mapped into
1506 @Input ui32NumBuffers : Number of dmabuf handles to map. (If one handle is being 1530 @Input ui32NumBuffers : Number of ion handles to map. (If one handle is being
1507 mapped, this should be 1, not 0.) 1531 mapped, this should be 1, not 0.)
1508 @Input phDmabuf : Array of ui32NumBuffers dmabuf handles (fds) 1532 @Input phIon : Array of ui32NumBuffers ion handles (fds)
1509 @Input ui32Flags : Mapping flags 1533 @Input ui32Flags : Mapping flags
1510 @Input ui32ChunkCount : If ui32NumBuffers is 1, this is the number of 1534 @Input ui32ChunkCount : If ui32NumBuffers is 1, this is the number of
1511 "chunks" specified to be mapped into device-virtual 1535 "chunks" specified to be mapped into device-virtual
1512 address space. If ui32NumBuffers > 1, it is ignored. 1536 address space. If ui32NumBuffers > 1, it is ignored.
1513 @Input pauiOffset : Array of offsets in device-virtual address space to map 1537 @Input pauiOffset : Array of offsets in device-virtual address space to map
1514 "chunks" of physical from the dmabuf allocation. 1538 "chunks" of physical from the ion allocation.
1515 @Input pauiSize : Array of sizes in bytes of device-virtual address space to 1539 @Input pauiSize : Array of sizes in bytes of device-virtual address space to
1516 map "chunks" of physical from the dmabuf allocation. 1540 map "chunks" of physical from the ion allocation.
1517 @Input puiDmabufBufferSize : Size in bytes of resulting device-virtual mapping. 1541 @Input puiIonBufferSize : Size in bytes of resulting device-virtual mapping.
1518 @Output ppsKernelMemInfo: Output kernel meminfo if successful 1542 @Output ppsKernelMemInfo: Output kernel meminfo if successful
1519 1543
1520 @Return PVRSRV_ERROR : 1544 @Return PVRSRV_ERROR :
1521 1545
1522******************************************************************************/ 1546******************************************************************************/
1523IMG_EXPORT 1547IMG_EXPORT
1524PVRSRV_ERROR PVRSRVMapDmabufKM(PVRSRV_PER_PROCESS_DATA *psPerProc, 1548PVRSRV_ERROR PVRSRVMapIonHandleKM(PVRSRV_PER_PROCESS_DATA *psPerProc,
1525 IMG_HANDLE hDevCookie, 1549 IMG_HANDLE hDevCookie,
1526 IMG_HANDLE hDevMemHeap, 1550 IMG_HANDLE hDevMemHeap,
1527 IMG_UINT32 ui32NumFDs, 1551 IMG_UINT32 ui32NumFDs,
@@ -1530,10 +1554,11 @@ PVRSRV_ERROR PVRSRVMapDmabufKM(PVRSRV_PER_PROCESS_DATA *psPerProc,
1530 IMG_UINT32 ui32ChunkCount, 1554 IMG_UINT32 ui32ChunkCount,
1531 IMG_SIZE_T *pauiOffset, 1555 IMG_SIZE_T *pauiOffset,
1532 IMG_SIZE_T *pauiSize, 1556 IMG_SIZE_T *pauiSize,
1533 IMG_SIZE_T *puiDmabufBufferSize, 1557 IMG_SIZE_T *puiIonBufferSize,
1534 PVRSRV_KERNEL_MEM_INFO **ppsKernelMemInfo, 1558 PVRSRV_KERNEL_MEM_INFO **ppsKernelMemInfo,
1535 IMG_UINT64 *pui64Stamp) 1559 IMG_UINT64 *pui64Stamp)
1536{ 1560{
1561 PVRSRV_ENV_PER_PROCESS_DATA *psPerProcEnv = PVRSRVProcessPrivateData(psPerProc);
1537 PVRSRV_DEVICE_NODE *psDeviceNode; 1562 PVRSRV_DEVICE_NODE *psDeviceNode;
1538 PVRSRV_KERNEL_MEM_INFO *psNewKernelMemInfo; 1563 PVRSRV_KERNEL_MEM_INFO *psNewKernelMemInfo;
1539 IMG_SYS_PHYADDR *pasSysPhysAddr; 1564 IMG_SYS_PHYADDR *pasSysPhysAddr;
@@ -1550,7 +1575,8 @@ PVRSRV_ERROR PVRSRVMapDmabufKM(PVRSRV_PER_PROCESS_DATA *psPerProc,
1550 IMG_BOOL bAllocSync = (ui32Flags & PVRSRV_MEM_NO_SYNCOBJ)?IMG_FALSE:IMG_TRUE; 1575 IMG_BOOL bAllocSync = (ui32Flags & PVRSRV_MEM_NO_SYNCOBJ)?IMG_FALSE:IMG_TRUE;
1551 1576
1552 if ((hDevCookie == IMG_NULL) || (ui32ChunkCount == 0) 1577 if ((hDevCookie == IMG_NULL) || (ui32ChunkCount == 0)
1553 || (hDevMemHeap == IMG_NULL) || (ppsKernelMemInfo == IMG_NULL)) 1578 || (hDevMemHeap == IMG_NULL) || (ppsKernelMemInfo == IMG_NULL)
1579 || (psPerProcEnv == IMG_NULL))
1554 { 1580 {
1555 PVR_DPF((PVR_DBG_ERROR, "%s: Invalid params", __FUNCTION__)); 1581 PVR_DPF((PVR_DBG_ERROR, "%s: Invalid params", __FUNCTION__));
1556 return PVRSRV_ERROR_INVALID_PARAMS; 1582 return PVRSRV_ERROR_INVALID_PARAMS;
@@ -1584,8 +1610,9 @@ PVRSRV_ERROR PVRSRVMapDmabufKM(PVRSRV_PER_PROCESS_DATA *psPerProc,
1584 } 1610 }
1585 OSMemSet(psNewKernelMemInfo, 0, sizeof(PVRSRV_KERNEL_MEM_INFO)); 1611 OSMemSet(psNewKernelMemInfo, 0, sizeof(PVRSRV_KERNEL_MEM_INFO));
1586 1612
1587 /* Import the DMABUF buffer into our dmabuf_client and DMA map it */ 1613 /* Import the ION buffer into our ion_client and DMA map it */
1588 eError = DmabufImportBufferAndAcquirePhysAddr(ui32NumFDs, 1614 eError = IonImportBufferAndAcquirePhysAddr(psPerProcEnv->psIONClient,
1615 ui32NumFDs,
1589 pi32BufferFDs, 1616 pi32BufferFDs,
1590 &ui32PageCount, 1617 &ui32PageCount,
1591 &pasSysPhysAddr, 1618 &pasSysPhysAddr,
@@ -1594,31 +1621,31 @@ PVRSRV_ERROR PVRSRVMapDmabufKM(PVRSRV_PER_PROCESS_DATA *psPerProc,
1594 &hUnique); 1621 &hUnique);
1595 if (eError != PVRSRV_OK) 1622 if (eError != PVRSRV_OK)
1596 { 1623 {
1597 PVR_DPF((PVR_DBG_ERROR, "%s: Failed to get dmabuf buffer/buffer phys addr", __FUNCTION__)); 1624 PVR_DPF((PVR_DBG_ERROR, "%s: Failed to get ion buffer/buffer phys addr", __FUNCTION__));
1598 goto exitFailedImport; 1625 goto exitFailedImport;
1599 } 1626 }
1600 1627
1601 /* 1628 /*
1602 Make sure the number of pages detected by the dmabuf import are at least 1629 Make sure the number of pages detected by the ion import are at least
1603 the size of the total chunked region 1630 the size of the total chunked region
1604 */ 1631 */
1605 if(ui32PageCount * PAGE_SIZE < uiMapSize) 1632 if(ui32PageCount * PAGE_SIZE < uiMapSize)
1606 { 1633 {
1607 PVR_DPF((PVR_DBG_ERROR, "%s: dmabuf allocator returned fewer page addresses " 1634 PVR_DPF((PVR_DBG_ERROR, "%s: ion allocator returned fewer page addresses "
1608 "than specified chunk size(s)", __FUNCTION__)); 1635 "than specified chunk size(s)", __FUNCTION__));
1609 eError = PVRSRV_ERROR_INVALID_PARAMS; 1636 eError = PVRSRV_ERROR_INVALID_PARAMS;
1610 goto exitFailedAdjustedAlloc; 1637 goto exitFailedAdjustedAlloc;
1611 } 1638 }
1612 1639
1613 /* 1640 /*
1614 An Dmabuf buffer might have a number of "chunks" in it which need to be 1641 An Ion buffer might have a number of "chunks" in it which need to be
1615 mapped virtually continuous so we need to create a new array of 1642 mapped virtually continuous so we need to create a new array of
1616 addresses based on this chunk data for the actual wrap 1643 addresses based on this chunk data for the actual wrap
1617 */ 1644 */
1618 if(OSAllocMem(PVRSRV_PAGEABLE_SELECT, 1645 if(OSAllocMem(PVRSRV_PAGEABLE_SELECT,
1619 sizeof(IMG_SYS_PHYADDR) * (uiMapSize/HOST_PAGESIZE()), 1646 sizeof(IMG_SYS_PHYADDR) * (uiMapSize/HOST_PAGESIZE()),
1620 (IMG_VOID **)&pasAdjustedSysPhysAddr, IMG_NULL, 1647 (IMG_VOID **)&pasAdjustedSysPhysAddr, IMG_NULL,
1621 "Dmabuf adjusted system address array") != PVRSRV_OK) 1648 "Ion adjusted system address array") != PVRSRV_OK)
1622 { 1649 {
1623 PVR_DPF((PVR_DBG_ERROR,"%s: Failed to alloc memory for adjusted array", __FUNCTION__)); 1650 PVR_DPF((PVR_DBG_ERROR,"%s: Failed to alloc memory for adjusted array", __FUNCTION__));
1624 goto exitFailedAdjustedAlloc; 1651 goto exitFailedAdjustedAlloc;
@@ -1644,7 +1671,7 @@ PVRSRV_ERROR PVRSRVMapDmabufKM(PVRSRV_PER_PROCESS_DATA *psPerProc,
1644 &ui32Flags, /* This function clobbers our bits in ui32Flags */ 1671 &ui32Flags, /* This function clobbers our bits in ui32Flags */
1645 &hBuffer)) 1672 &hBuffer))
1646 { 1673 {
1647 PVR_DPF((PVR_DBG_ERROR, "%s: Failed to wrap dmabuf buffer", __FUNCTION__)); 1674 PVR_DPF((PVR_DBG_ERROR, "%s: Failed to wrap ion buffer", __FUNCTION__));
1648 eError = PVRSRV_ERROR_OUT_OF_MEMORY; 1675 eError = PVRSRV_ERROR_OUT_OF_MEMORY;
1649 goto exitFailedWrap; 1676 goto exitFailedWrap;
1650 } 1677 }
@@ -1660,7 +1687,7 @@ PVRSRV_ERROR PVRSRVMapDmabufKM(PVRSRV_PER_PROCESS_DATA *psPerProc,
1660 psNewKernelMemInfo->ui32Flags = ui32Flags; 1687 psNewKernelMemInfo->ui32Flags = ui32Flags;
1661 psNewKernelMemInfo->sDevVAddr = psMemBlock->sDevVirtAddr; 1688 psNewKernelMemInfo->sDevVAddr = psMemBlock->sDevVirtAddr;
1662 psNewKernelMemInfo->uAllocSize = uiMapSize; 1689 psNewKernelMemInfo->uAllocSize = uiMapSize;
1663 psNewKernelMemInfo->memType = PVRSRV_MEMTYPE_DMABUF; 1690 psNewKernelMemInfo->memType = PVRSRV_MEMTYPE_ION;
1664 PVRSRVKernelMemInfoIncRef(psNewKernelMemInfo); 1691 PVRSRVKernelMemInfoIncRef(psNewKernelMemInfo);
1665 1692
1666 /* Clear the Backup buffer pointer as we do not have one at this point. We only allocate this as we are going up/down */ 1693 /* Clear the Backup buffer pointer as we do not have one at this point. We only allocate this as we are going up/down */
@@ -1672,63 +1699,67 @@ PVRSRV_ERROR PVRSRVMapDmabufKM(PVRSRV_PER_PROCESS_DATA *psPerProc,
1672 } 1699 }
1673 else 1700 else
1674 { 1701 {
1675 PVRSRV_EXTERNAL_SYNC_INFO *psExternalSyncInfo; 1702 PVRSRV_ION_SYNC_INFO *psIonSyncInfo;
1676 BM_HEAP *psBMHeap; 1703 BM_HEAP *psBMHeap;
1677 IMG_HANDLE hDevMemContext; 1704 IMG_HANDLE hDevMemContext;
1678 1705
1679 psBMHeap = (BM_HEAP*)hDevMemHeap; 1706 psBMHeap = (BM_HEAP*)hDevMemHeap;
1680 hDevMemContext = (IMG_HANDLE)psBMHeap->pBMContext; 1707 hDevMemContext = (IMG_HANDLE)psBMHeap->pBMContext;
1681 1708
1682 eError = PVRSRVExternalBufferSyncInfoIncRef(hUnique, 1709 eError = PVRSRVIonBufferSyncInfoIncRef(hUnique,
1683 hDevCookie, 1710 hDevCookie,
1684 hDevMemContext, 1711 hDevMemContext,
1685 &psExternalSyncInfo, 1712 &psIonSyncInfo,
1686 psNewKernelMemInfo); 1713 psNewKernelMemInfo);
1687 if(eError != PVRSRV_OK) 1714 if(eError != PVRSRV_OK)
1688 { 1715 {
1689 goto exitFailedSync; 1716 goto exitFailedSync;
1690 } 1717 }
1691 psNewKernelMemInfo->hExternalSyncInfo = psExternalSyncInfo; 1718 psNewKernelMemInfo->hIonSyncInfo = psIonSyncInfo;
1692 psNewKernelMemInfo->psKernelSyncInfo = ExternalBufferSyncGetKernelSyncInfo(psExternalSyncInfo); 1719 psNewKernelMemInfo->psKernelSyncInfo = IonBufferSyncGetKernelSyncInfo(psIonSyncInfo);
1693 *pui64Stamp = ExternalBufferSyncGetStamp(psExternalSyncInfo); 1720 *pui64Stamp = IonBufferSyncGetStamp(psIonSyncInfo);
1694 } 1721 }
1695 1722
1696 /* register with the resman */ 1723 /* register with the resman */
1697 psNewKernelMemInfo->sMemBlk.hResItem = ResManRegisterRes(psPerProc->hResManContext, 1724 psNewKernelMemInfo->sMemBlk.hResItem = ResManRegisterRes(psPerProc->hResManContext,
1698 RESMAN_TYPE_DEVICEMEM_DMABUF, 1725 RESMAN_TYPE_DEVICEMEM_ION,
1699 psNewKernelMemInfo, 1726 psNewKernelMemInfo,
1700 0, 1727 0,
1701 &DmabufUnmapCallback); 1728 &IonUnmapCallback);
1702 if (psNewKernelMemInfo->sMemBlk.hResItem == IMG_NULL) 1729 if (psNewKernelMemInfo->sMemBlk.hResItem == IMG_NULL)
1703 { 1730 {
1704 eError = PVRSRV_ERROR_OUT_OF_MEMORY; 1731 eError = PVRSRV_ERROR_OUT_OF_MEMORY;
1705 goto exitFailedResman; 1732 goto exitFailedResman;
1706 } 1733 }
1707 1734
1708 psNewKernelMemInfo->memType = PVRSRV_MEMTYPE_DMABUF; 1735 psNewKernelMemInfo->memType = PVRSRV_MEMTYPE_ION;
1709 1736
1710 /* 1737 /*
1711 As the user doesn't tell us the size, just the "chunk" information 1738 As the user doesn't tell us the size, just the "chunk" information
1712 return actual size of the Dmabuf buffer so we can mmap it. 1739 return actual size of the Ion buffer so we can mmap it.
1713 */ 1740 */
1714 *puiDmabufBufferSize = ui32PageCount * HOST_PAGESIZE(); 1741 *puiIonBufferSize = ui32PageCount * HOST_PAGESIZE();
1715 *ppsKernelMemInfo = psNewKernelMemInfo; 1742 *ppsKernelMemInfo = psNewKernelMemInfo;
1716 return PVRSRV_OK; 1743 return PVRSRV_OK;
1717 1744
1718exitFailedResman: 1745exitFailedResman:
1719 if (psNewKernelMemInfo->psKernelSyncInfo) 1746 if (psNewKernelMemInfo->psKernelSyncInfo)
1720 { 1747 {
1721 PVRSRVExternalBufferSyncInfoDecRef(psNewKernelMemInfo->hExternalSyncInfo, psNewKernelMemInfo); 1748 PVRSRVIonBufferSyncInfoDecRef(psNewKernelMemInfo->hIonSyncInfo, psNewKernelMemInfo);
1722 } 1749 }
1723exitFailedSync: 1750exitFailedSync:
1724 BM_Free(hBuffer, ui32Flags); 1751 BM_Free(hBuffer, ui32Flags
1752 #if defined (PVRSRV_DEVMEM_TIME_STATS)
1753 , IMG_NULL
1754 #endif
1755 );
1725exitFailedWrap: 1756exitFailedWrap:
1726 OSFreeMem(PVRSRV_PAGEABLE_SELECT, 1757 OSFreeMem(PVRSRV_PAGEABLE_SELECT,
1727 sizeof(IMG_SYS_PHYADDR) * uiAdjustOffset, 1758 sizeof(IMG_SYS_PHYADDR) * uiAdjustOffset,
1728 pasAdjustedSysPhysAddr, 1759 pasAdjustedSysPhysAddr,
1729 IMG_NULL); 1760 IMG_NULL);
1730exitFailedAdjustedAlloc: 1761exitFailedAdjustedAlloc:
1731 DmabufUnimportBufferAndReleasePhysAddr(hPriv); 1762 IonUnimportBufferAndReleasePhysAddr(hPriv);
1732exitFailedImport: 1763exitFailedImport:
1733 OSFreeMem(PVRSRV_PAGEABLE_SELECT, 1764 OSFreeMem(PVRSRV_PAGEABLE_SELECT,
1734 sizeof(PVRSRV_KERNEL_MEM_INFO), 1765 sizeof(PVRSRV_KERNEL_MEM_INFO),
@@ -1741,11 +1772,11 @@ exitFailedImport:
1741/*! 1772/*!
1742****************************************************************************** 1773******************************************************************************
1743 1774
1744 @Function PVRSRVUnmapDmabufKM 1775 @Function PVRSRVUnmapIonHandleKM
1745 1776
1746 @Description 1777 @Description
1747 1778
1748 Frees a dmabuf buffer mapped with PVRSRVMapDmabufKM, including the mem_info structure 1779 Frees an ion buffer mapped with PVRSRVMapIonHandleKM, including the mem_info structure
1749 1780
1750 @Input psMemInfo : 1781 @Input psMemInfo :
1751 1782
@@ -1753,7 +1784,7 @@ exitFailedImport:
1753 1784
1754******************************************************************************/ 1785******************************************************************************/
1755IMG_EXPORT 1786IMG_EXPORT
1756PVRSRV_ERROR IMG_CALLCONV PVRSRVUnmapDmabufKM(PVRSRV_KERNEL_MEM_INFO *psMemInfo) 1787PVRSRV_ERROR IMG_CALLCONV PVRSRVUnmapIonHandleKM(PVRSRV_KERNEL_MEM_INFO *psMemInfo)
1757{ 1788{
1758 if (!psMemInfo) 1789 if (!psMemInfo)
1759 { 1790 {
@@ -1762,10 +1793,10 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVUnmapDmabufKM(PVRSRV_KERNEL_MEM_INFO *psMemInfo)
1762 1793
1763 return ResManFreeResByPtr(psMemInfo->sMemBlk.hResItem, CLEANUP_WITH_POLL); 1794 return ResManFreeResByPtr(psMemInfo->sMemBlk.hResItem, CLEANUP_WITH_POLL);
1764} 1795}
1765#endif /* SUPPORT_DRM_GEM */ 1796#endif /* SUPPORT_ION */
1766 1797
1767#if defined(SUPPORT_ION) 1798#if defined(SUPPORT_DMABUF)
1768static PVRSRV_ERROR IonUnmapCallback(IMG_PVOID pvParam, 1799static PVRSRV_ERROR DmaBufUnmapCallback(IMG_PVOID pvParam,
1769 IMG_UINT32 ui32Param, 1800 IMG_UINT32 ui32Param,
1770 IMG_BOOL bDummy) 1801 IMG_BOOL bDummy)
1771{ 1802{
@@ -1776,91 +1807,168 @@ static PVRSRV_ERROR IonUnmapCallback(IMG_PVOID pvParam,
1776 return FreeMemCallBackCommon(psMemInfo, ui32Param, PVRSRV_FREE_CALLBACK_ORIGIN_ALLOCATOR); 1807 return FreeMemCallBackCommon(psMemInfo, ui32Param, PVRSRV_FREE_CALLBACK_ORIGIN_ALLOCATOR);
1777} 1808}
1778 1809
1810PVRSRV_ERROR PVRSRVDmaBufSyncAcquire(IMG_HANDLE hUnique,
1811 IMG_HANDLE hPriv,
1812 IMG_HANDLE hDevCookie,
1813 IMG_HANDLE hDevMemContext,
1814 PVRSRV_DMABUF_SYNC_INFO **ppsDmaBufSyncInfo)
1815{
1816 PVRSRV_DMABUF_SYNC_INFO *psDmaBufSyncInfo;
1817 PVRSRV_ERROR eError;
1818 IMG_BOOL bRet;
1819
1820 /*
1821 * If the import has a unique handle, check the hash to see if we
1822 * already have a sync for the buffer.
1823 */
1824 psDmaBufSyncInfo = hUnique ? (PVRSRV_DMABUF_SYNC_INFO *) HASH_Retrieve(g_psDmaBufSyncHash, (IMG_UINTPTR_T)hUnique) : NULL;
1825 if (!psDmaBufSyncInfo)
1826 {
1827 /* Create the syncinfo for the import */
1828 eError = OSAllocMem(PVRSRV_PAGEABLE_SELECT,
1829 sizeof(PVRSRV_DMABUF_SYNC_INFO),
1830 (IMG_VOID **)&psDmaBufSyncInfo, IMG_NULL,
1831 "DMA-BUF Synchronization Info");
1832 if (eError != PVRSRV_OK)
1833 {
1834 goto ErrorAllocDmaBufSyncInfo;
1835 }
1836
1837 eError = PVRSRVAllocSyncInfoKM(hDevCookie,
1838 hDevMemContext,
1839 &psDmaBufSyncInfo->psSyncInfo);
1840 if (eError != PVRSRV_OK)
1841 {
1842 goto ErrorAllocSyncInfo;
1843 }
1844#if defined(SUPPORT_MEMINFO_IDS)
1845 psDmaBufSyncInfo->ui64Stamp = ++g_ui64MemInfoID;
1846#else
1847 psDmaBufSyncInfo->ui64Stamp = 0;
1848#endif
1849 psDmaBufSyncInfo->ui32RefCount = 0;
1850 psDmaBufSyncInfo->hUnique = hUnique;
1851
1852 psDmaBufSyncInfo->psSyncInfo->hFenceContext = PVRLinuxFenceContextCreate(psDmaBufSyncInfo->psSyncInfo, hPriv);
1853 if (!psDmaBufSyncInfo->psSyncInfo->hFenceContext)
1854 {
1855 eError = PVRSRV_ERROR_OUT_OF_MEMORY;
1856 goto ErrorCreateFenceContext;
1857 }
1858
1859 if (hUnique)
1860 {
1861 bRet = HASH_Insert(g_psDmaBufSyncHash, (IMG_UINTPTR_T)hUnique, (IMG_UINTPTR_T) psDmaBufSyncInfo);
1862 if (!bRet)
1863 {
1864 eError = PVRSRV_ERROR_OUT_OF_MEMORY;
1865 goto ErrorHashInsert;
1866 }
1867 }
1868 }
1869
1870 psDmaBufSyncInfo->ui32RefCount++;
1871 *ppsDmaBufSyncInfo = psDmaBufSyncInfo;
1872 return PVRSRV_OK;
1873
1874ErrorHashInsert:
1875 PVRLinuxFenceContextDestroy(psDmaBufSyncInfo->psSyncInfo->hFenceContext);
1876ErrorCreateFenceContext:
1877 PVRSRVKernelSyncInfoDecRef(psDmaBufSyncInfo->psSyncInfo, IMG_NULL);
1878ErrorAllocSyncInfo:
1879 OSFreeMem(PVRSRV_PAGEABLE_SELECT,
1880 sizeof(PVRSRV_DMABUF_SYNC_INFO),
1881 psDmaBufSyncInfo,
1882 IMG_NULL);
1883ErrorAllocDmaBufSyncInfo:
1884 return eError;
1885}
1886
1887IMG_VOID PVRSRVDmaBufSyncRelease(PVRSRV_DMABUF_SYNC_INFO *psDmaBufSyncInfo)
1888{
1889 psDmaBufSyncInfo->ui32RefCount--;
1890
1891 if (psDmaBufSyncInfo->ui32RefCount == 0)
1892 {
1893 /*
1894 If we're holding the last reference to the syncinfo
1895 then free it
1896 */
1897 if (psDmaBufSyncInfo->hUnique)
1898 {
1899 PVRSRV_DMABUF_SYNC_INFO *psLookup = (PVRSRV_DMABUF_SYNC_INFO *) HASH_Remove(g_psDmaBufSyncHash, (IMG_UINTPTR_T) psDmaBufSyncInfo->hUnique);
1900 (void)psLookup;
1901 PVR_ASSERT(psLookup == psDmaBufSyncInfo);
1902 }
1903 PVRLinuxFenceContextDestroy(psDmaBufSyncInfo->psSyncInfo->hFenceContext);
1904 PVRSRVKernelSyncInfoDecRef(psDmaBufSyncInfo->psSyncInfo, IMG_NULL);
1905 OSFreeMem(PVRSRV_PAGEABLE_SELECT,
1906 sizeof(PVRSRV_DMABUF_SYNC_INFO),
1907 psDmaBufSyncInfo,
1908 IMG_NULL);
1909 }
1910}
1911
1779/*! 1912/*!
1780****************************************************************************** 1913******************************************************************************
1781 1914
1782 @Function PVRSRVMapIonHandleKM 1915 @Function PVRSRVMapDmaBufKM
1783 1916
1784 @Description 1917 @Description
1785 1918
1786 Map an ION buffer into the specified device memory context 1919 Map a dma_buf into the specified device memory context
1787 1920
1788 @Input psPerProc : PerProcess data 1921 @Input psPerProc : PerProcess data.
1789 @Input hDevCookie : Device node cookie 1922 @Input hDevCookie : Device node cookie.
1790 @Input hDevMemHeap : Heap ion handles are mapped into 1923 @Input hDevMemHeap : Heap the buffers are mapped into.
1791 @Input ui32NumBuffers : Number of ion handles to map. (If one handle is being 1924 @Input ui32NumFDs : Number of DMA Buf FDs.
1792 mapped, this should be 1, not 0.) 1925 @Input pi32DmaBufFD : Array of DMA Buf FDs.
1793 @Input phIon : Array of ui32NumBuffers ion handles (fds) 1926 @Input puiDmaBufOffset : Array of offsets into each DMA Buf.
1794 @Input ui32Flags : Mapping flags 1927 @Input puiSize : Array of sizes of each DMA Buf chunk.
1795 @Input ui32ChunkCount : If ui32NumBuffers is 1, this is the number of 1928 @Input ui32Flags : Mapping flags.
1796 "chunks" specified to be mapped into device-virtual 1929 @Input puiDmaBufSize : Size in bytes of resulting device-virtual mapping.
1797 address space. If ui32NumBuffers > 1, it is ignored. 1930 @Output ppsKernelMemInfo: Output kernel meminfo if successful.
1798 @Input pauiOffset : Array of offsets in device-virtual address space to map 1931 @Output puiMemInfoOffset : Array of offsets of each chunk in the meminfo.
1799 "chunks" of physical from the ion allocation.
1800 @Input pauiSize : Array of sizes in bytes of device-virtual address space to
1801 map "chunks" of physical from the ion allocation.
1802 @Input puiIonBufferSize : Size in bytes of resulting device-virtual mapping.
1803 @Output ppsKernelMemInfo: Output kernel meminfo if successful
1804 1932
1805 @Return PVRSRV_ERROR : 1933 @Return PVRSRV_ERROR :
1806 1934
1807******************************************************************************/ 1935******************************************************************************/
1808IMG_EXPORT 1936IMG_EXPORT
1809PVRSRV_ERROR PVRSRVMapIonHandleKM(PVRSRV_PER_PROCESS_DATA *psPerProc, 1937PVRSRV_ERROR PVRSRVMapDmaBufKM(PVRSRV_PER_PROCESS_DATA *psPerProc,
1810 IMG_HANDLE hDevCookie, 1938 IMG_HANDLE hDevCookie,
1811 IMG_HANDLE hDevMemHeap, 1939 IMG_HANDLE hDevMemHeap,
1812 IMG_UINT32 ui32NumFDs,
1813 IMG_INT32 *pi32BufferFDs,
1814 IMG_UINT32 ui32Flags, 1940 IMG_UINT32 ui32Flags,
1815 IMG_UINT32 ui32ChunkCount, 1941 IMG_UINT32 ui32NumFDs,
1816 IMG_SIZE_T *pauiOffset, 1942 IMG_INT32 *pi32DmaBufFD,
1817 IMG_SIZE_T *pauiSize, 1943 IMG_SIZE_T *puiDmaBufOffset,
1818 IMG_SIZE_T *puiIonBufferSize, 1944 IMG_SIZE_T *puiDmaBufSize,
1819 PVRSRV_KERNEL_MEM_INFO **ppsKernelMemInfo, 1945 PVRSRV_KERNEL_MEM_INFO **ppsKernelMemInfo,
1946 IMG_SIZE_T *puiSize,
1947 IMG_SIZE_T *puiMemInfoOffset,
1820 IMG_UINT64 *pui64Stamp) 1948 IMG_UINT64 *pui64Stamp)
1821{ 1949{
1822 PVRSRV_ENV_PER_PROCESS_DATA *psPerProcEnv = PVRSRVProcessPrivateData(psPerProc);
1823 PVRSRV_DEVICE_NODE *psDeviceNode; 1950 PVRSRV_DEVICE_NODE *psDeviceNode;
1824 PVRSRV_KERNEL_MEM_INFO *psNewKernelMemInfo; 1951 PVRSRV_KERNEL_MEM_INFO *psNewKernelMemInfo;
1825 IMG_SYS_PHYADDR *pasSysPhysAddr; 1952 IMG_SYS_PHYADDR *pasSysPhysAddr;
1826 IMG_SYS_PHYADDR *pasAdjustedSysPhysAddr;
1827 PVRSRV_MEMBLK *psMemBlock; 1953 PVRSRV_MEMBLK *psMemBlock;
1828 PVRSRV_ERROR eError; 1954 PVRSRV_ERROR eError;
1829 IMG_HANDLE hPriv; 1955 IMG_HANDLE hPriv;
1830 IMG_HANDLE hUnique; 1956 IMG_HANDLE hUnique;
1831 BM_HANDLE hBuffer; 1957 BM_HANDLE hBuffer;
1832 IMG_SIZE_T uiMapSize = 0; 1958 IMG_SIZE_T uiMapSize = 0;
1833 IMG_SIZE_T uiAdjustOffset = 0;
1834 IMG_UINT32 ui32PageCount; 1959 IMG_UINT32 ui32PageCount;
1835 IMG_UINT32 i; 1960 IMG_BOOL bAllocSync = (ui32Flags & PVRSRV_MEM_NO_SYNCOBJ) ? IMG_FALSE : IMG_TRUE;
1836 IMG_BOOL bAllocSync = (ui32Flags & PVRSRV_MEM_NO_SYNCOBJ)?IMG_FALSE:IMG_TRUE;
1837 1961
1838 if ((hDevCookie == IMG_NULL) || (ui32ChunkCount == 0) 1962 if ((hDevCookie == IMG_NULL) || (hDevMemHeap == IMG_NULL)
1839 || (hDevMemHeap == IMG_NULL) || (ppsKernelMemInfo == IMG_NULL)) 1963 || (ppsKernelMemInfo == IMG_NULL))
1840 { 1964 {
1841 PVR_DPF((PVR_DBG_ERROR, "%s: Invalid params", __FUNCTION__)); 1965 PVR_DPF((PVR_DBG_ERROR, "%s: Invalid params", __FUNCTION__));
1842 return PVRSRV_ERROR_INVALID_PARAMS; 1966 return PVRSRV_ERROR_INVALID_PARAMS;
1843 } 1967 }
1844 1968
1845 for (i=0;i<ui32ChunkCount;i++)
1846 {
1847 if ((pauiOffset[i] & HOST_PAGEMASK) != 0)
1848 {
1849 PVR_DPF((PVR_DBG_ERROR,"%s: Chunk offset is not page aligned", __FUNCTION__));
1850 return PVRSRV_ERROR_INVALID_PARAMS;
1851 }
1852
1853 if ((pauiSize[i] & HOST_PAGEMASK) != 0)
1854 {
1855 PVR_DPF((PVR_DBG_ERROR,"%s: Chunk size is not page aligned", __FUNCTION__));
1856 return PVRSRV_ERROR_INVALID_PARAMS;
1857 }
1858 uiMapSize += pauiSize[i];
1859 }
1860
1861 psDeviceNode = (PVRSRV_DEVICE_NODE *)hDevCookie; 1969 psDeviceNode = (PVRSRV_DEVICE_NODE *)hDevCookie;
1862 1970
1863 if(OSAllocMem(PVRSRV_PAGEABLE_SELECT, 1971 if (OSAllocMem(PVRSRV_PAGEABLE_SELECT,
1864 sizeof(PVRSRV_KERNEL_MEM_INFO), 1972 sizeof(PVRSRV_KERNEL_MEM_INFO),
1865 (IMG_VOID **)&psNewKernelMemInfo, IMG_NULL, 1973 (IMG_VOID **)&psNewKernelMemInfo, IMG_NULL,
1866 "Kernel Memory Info") != PVRSRV_OK) 1974 "Kernel Memory Info") != PVRSRV_OK)
@@ -1870,68 +1978,36 @@ PVRSRV_ERROR PVRSRVMapIonHandleKM(PVRSRV_PER_PROCESS_DATA *psPerProc,
1870 } 1978 }
1871 OSMemSet(psNewKernelMemInfo, 0, sizeof(PVRSRV_KERNEL_MEM_INFO)); 1979 OSMemSet(psNewKernelMemInfo, 0, sizeof(PVRSRV_KERNEL_MEM_INFO));
1872 1980
1873 /* Import the ION buffer into our ion_client and DMA map it */ 1981 /* Import the DMA Buffer */
1874 eError = IonImportBufferAndAcquirePhysAddr(psPerProcEnv->psIONClient, 1982 eError = DmaBufImportAndAcquirePhysAddr(ui32NumFDs,
1875 ui32NumFDs, 1983 pi32DmaBufFD,
1876 pi32BufferFDs, 1984 puiDmaBufOffset,
1985 puiDmaBufSize,
1877 &ui32PageCount, 1986 &ui32PageCount,
1878 &pasSysPhysAddr, 1987 &pasSysPhysAddr,
1988 puiMemInfoOffset,
1879 &psNewKernelMemInfo->pvLinAddrKM, 1989 &psNewKernelMemInfo->pvLinAddrKM,
1880 &hPriv, 1990 &hPriv,
1881 &hUnique); 1991 &hUnique);
1882 if (eError != PVRSRV_OK) 1992 if (eError != PVRSRV_OK)
1883 { 1993 {
1884 PVR_DPF((PVR_DBG_ERROR, "%s: Failed to get ion buffer/buffer phys addr", __FUNCTION__)); 1994 PVR_DPF((PVR_DBG_ERROR, "%s: Failed to get dma-buf phys addr", __FUNCTION__));
1885 goto exitFailedImport; 1995 goto exitFailedImport;
1886 } 1996 }
1887 1997
1888 /* 1998 uiMapSize = ui32PageCount * HOST_PAGESIZE();
1889 Make sure the number of pages detected by the ion import are at least
1890 the size of the total chunked region
1891 */
1892 if(ui32PageCount * PAGE_SIZE < uiMapSize)
1893 {
1894 PVR_DPF((PVR_DBG_ERROR, "%s: ion allocator returned fewer page addresses "
1895 "than specified chunk size(s)", __FUNCTION__));
1896 eError = PVRSRV_ERROR_INVALID_PARAMS;
1897 goto exitFailedAdjustedAlloc;
1898 }
1899
1900 /*
1901 An Ion buffer might have a number of "chunks" in it which need to be
1902 mapped virtually continuous so we need to create a new array of
1903 addresses based on this chunk data for the actual wrap
1904 */
1905 if(OSAllocMem(PVRSRV_PAGEABLE_SELECT,
1906 sizeof(IMG_SYS_PHYADDR) * (uiMapSize/HOST_PAGESIZE()),
1907 (IMG_VOID **)&pasAdjustedSysPhysAddr, IMG_NULL,
1908 "Ion adjusted system address array") != PVRSRV_OK)
1909 {
1910 PVR_DPF((PVR_DBG_ERROR,"%s: Failed to alloc memory for adjusted array", __FUNCTION__));
1911 goto exitFailedAdjustedAlloc;
1912 }
1913 OSMemSet(pasAdjustedSysPhysAddr, 0, sizeof(IMG_SYS_PHYADDR) * (uiMapSize/HOST_PAGESIZE()));
1914
1915 for (i=0;i<ui32ChunkCount;i++)
1916 {
1917 OSMemCopy(&pasAdjustedSysPhysAddr[uiAdjustOffset],
1918 &pasSysPhysAddr[pauiOffset[i]/HOST_PAGESIZE()],
1919 (pauiSize[i]/HOST_PAGESIZE()) * sizeof(IMG_SYS_PHYADDR));
1920
1921 uiAdjustOffset += pauiSize[i]/HOST_PAGESIZE();
1922 }
1923 1999
1924 /* Wrap the returned addresses into our memory context */ 2000 /* Wrap the returned addresses into our memory context */
1925 if (!BM_Wrap(hDevMemHeap, 2001 if (!BM_Wrap(hDevMemHeap,
1926 uiMapSize, 2002 uiMapSize,
1927 0, 2003 0,
1928 IMG_FALSE, 2004 IMG_FALSE,
1929 pasAdjustedSysPhysAddr, 2005 pasSysPhysAddr,
1930 IMG_NULL, 2006 IMG_NULL,
1931 &ui32Flags, /* This function clobbers our bits in ui32Flags */ 2007 &ui32Flags, /* This function clobbers our bits in ui32Flags */
1932 &hBuffer)) 2008 &hBuffer))
1933 { 2009 {
1934 PVR_DPF((PVR_DBG_ERROR, "%s: Failed to wrap ion buffer", __FUNCTION__)); 2010 PVR_DPF((PVR_DBG_ERROR, "%s: Failed to wrap dma-buf", __FUNCTION__));
1935 eError = PVRSRV_ERROR_OUT_OF_MEMORY; 2011 eError = PVRSRV_ERROR_OUT_OF_MEMORY;
1936 goto exitFailedWrap; 2012 goto exitFailedWrap;
1937 } 2013 }
@@ -1942,80 +2018,75 @@ PVRSRV_ERROR PVRSRVMapIonHandleKM(PVRSRV_PER_PROCESS_DATA *psPerProc,
1942 psMemBlock->hOSMemHandle = BM_HandleToOSMemHandle(hBuffer); 2018 psMemBlock->hOSMemHandle = BM_HandleToOSMemHandle(hBuffer);
1943 psMemBlock->hBuffer = (IMG_HANDLE) hBuffer; 2019 psMemBlock->hBuffer = (IMG_HANDLE) hBuffer;
1944 psMemBlock->hOSWrapMem = hPriv; /* Saves creating a new element as we know hOSWrapMem will not be used */ 2020 psMemBlock->hOSWrapMem = hPriv; /* Saves creating a new element as we know hOSWrapMem will not be used */
1945 psMemBlock->psIntSysPAddr = pasAdjustedSysPhysAddr; 2021 psMemBlock->psIntSysPAddr = pasSysPhysAddr;
1946 2022
1947 psNewKernelMemInfo->ui32Flags = ui32Flags; 2023 psNewKernelMemInfo->ui32Flags = ui32Flags;
1948 psNewKernelMemInfo->sDevVAddr = psMemBlock->sDevVirtAddr; 2024 psNewKernelMemInfo->sDevVAddr = psMemBlock->sDevVirtAddr;
1949 psNewKernelMemInfo->uAllocSize = uiMapSize; 2025 psNewKernelMemInfo->uAllocSize = uiMapSize;
1950 psNewKernelMemInfo->memType = PVRSRV_MEMTYPE_ION; 2026 psNewKernelMemInfo->memType = PVRSRV_MEMTYPE_DMABUF;
1951 PVRSRVKernelMemInfoIncRef(psNewKernelMemInfo); 2027 PVRSRVKernelMemInfoIncRef(psNewKernelMemInfo);
1952 2028
1953 /* Clear the Backup buffer pointer as we do not have one at this point. We only allocate this as we are going up/down */
1954 psNewKernelMemInfo->pvSysBackupBuffer = IMG_NULL;
1955
1956 if (!bAllocSync) 2029 if (!bAllocSync)
1957 { 2030 {
1958 psNewKernelMemInfo->psKernelSyncInfo = IMG_NULL; 2031 psNewKernelMemInfo->psKernelSyncInfo = IMG_NULL;
1959 } 2032 }
1960 else 2033 else
1961 { 2034 {
1962 PVRSRV_EXTERNAL_SYNC_INFO *psExternalSyncInfo; 2035 PVRSRV_DMABUF_SYNC_INFO *psDmaBufSyncInfo;
1963 BM_HEAP *psBMHeap; 2036 BM_HEAP *psBMHeap;
1964 IMG_HANDLE hDevMemContext; 2037 IMG_HANDLE hDevMemContext;
1965 2038
1966 psBMHeap = (BM_HEAP*)hDevMemHeap; 2039 psBMHeap = (BM_HEAP*)hDevMemHeap;
1967 hDevMemContext = (IMG_HANDLE)psBMHeap->pBMContext; 2040 hDevMemContext = (IMG_HANDLE)psBMHeap->pBMContext;
1968 2041
1969 eError = PVRSRVExternalBufferSyncInfoIncRef(hUnique, 2042 eError = PVRSRVDmaBufSyncInfoIncRef(hUnique,
2043 hPriv,
1970 hDevCookie, 2044 hDevCookie,
1971 hDevMemContext, 2045 hDevMemContext,
1972 &psExternalSyncInfo, 2046 &psDmaBufSyncInfo,
1973 psNewKernelMemInfo); 2047 psNewKernelMemInfo);
1974 if(eError != PVRSRV_OK) 2048 if(eError != PVRSRV_OK)
1975 { 2049 {
1976 goto exitFailedSync; 2050 goto exitFailedSync;
1977 } 2051 }
1978 psNewKernelMemInfo->hExternalSyncInfo = psExternalSyncInfo; 2052 psNewKernelMemInfo->hDmaBufSyncInfo = psDmaBufSyncInfo;
1979 psNewKernelMemInfo->psKernelSyncInfo = ExternalBufferSyncGetKernelSyncInfo(psExternalSyncInfo); 2053 psNewKernelMemInfo->psKernelSyncInfo = psDmaBufSyncInfo->psSyncInfo;
1980 *pui64Stamp = ExternalBufferSyncGetStamp(psExternalSyncInfo); 2054 *pui64Stamp = DmaBufSyncGetStamp(psDmaBufSyncInfo);
1981 } 2055 }
1982 2056
1983 /* register with the resman */ 2057 /* register with the resman */
1984 psNewKernelMemInfo->sMemBlk.hResItem = ResManRegisterRes(psPerProc->hResManContext, 2058 psNewKernelMemInfo->sMemBlk.hResItem = ResManRegisterRes(psPerProc->hResManContext,
1985 RESMAN_TYPE_DEVICEMEM_ION, 2059 RESMAN_TYPE_DEVICEMEM_DMABUF,
1986 psNewKernelMemInfo, 2060 psNewKernelMemInfo,
1987 0, 2061 0,
1988 &IonUnmapCallback); 2062 &DmaBufUnmapCallback);
1989 if (psNewKernelMemInfo->sMemBlk.hResItem == IMG_NULL) 2063 if (psNewKernelMemInfo->sMemBlk.hResItem == IMG_NULL)
1990 { 2064 {
1991 eError = PVRSRV_ERROR_OUT_OF_MEMORY; 2065 eError = PVRSRV_ERROR_OUT_OF_MEMORY;
1992 goto exitFailedResman; 2066 goto exitFailedResman;
1993 } 2067 }
1994 2068
1995 psNewKernelMemInfo->memType = PVRSRV_MEMTYPE_ION; 2069 psNewKernelMemInfo->memType = PVRSRV_MEMTYPE_DMABUF;
1996 2070
1997 /* 2071 /* Return actual size of the imported memory so we can mmap it */
1998 As the user doesn't tell us the size, just the "chunk" information 2072 *puiSize = uiMapSize;
1999 return actual size of the Ion buffer so we can mmap it.
2000 */
2001 *puiIonBufferSize = ui32PageCount * HOST_PAGESIZE();
2002 *ppsKernelMemInfo = psNewKernelMemInfo; 2073 *ppsKernelMemInfo = psNewKernelMemInfo;
2003 return PVRSRV_OK; 2074 return PVRSRV_OK;
2004 2075
2005exitFailedResman: 2076exitFailedResman:
2006 if (psNewKernelMemInfo->psKernelSyncInfo) 2077 if (psNewKernelMemInfo->psKernelSyncInfo)
2007 { 2078 {
2008 PVRSRVExternalBufferSyncInfoDecRef(psNewKernelMemInfo->hExternalSyncInfo, psNewKernelMemInfo); 2079 PVRSRVDmaBufSyncInfoDecRef(psNewKernelMemInfo->hDmaBufSyncInfo, psNewKernelMemInfo);
2009 } 2080 }
2010exitFailedSync: 2081exitFailedSync:
2011 BM_Free(hBuffer, ui32Flags); 2082 BM_Free(hBuffer, ui32Flags
2083 #if defined (PVRSRV_DEVMEM_TIME_STATS)
2084 , IMG_NULL
2085 #endif
2086 );
2087
2012exitFailedWrap: 2088exitFailedWrap:
2013 OSFreeMem(PVRSRV_PAGEABLE_SELECT, 2089 DmaBufUnimportAndReleasePhysAddr(hPriv);
2014 sizeof(IMG_SYS_PHYADDR) * uiAdjustOffset,
2015 pasAdjustedSysPhysAddr,
2016 IMG_NULL);
2017exitFailedAdjustedAlloc:
2018 IonUnimportBufferAndReleasePhysAddr(hPriv);
2019exitFailedImport: 2090exitFailedImport:
2020 OSFreeMem(PVRSRV_PAGEABLE_SELECT, 2091 OSFreeMem(PVRSRV_PAGEABLE_SELECT,
2021 sizeof(PVRSRV_KERNEL_MEM_INFO), 2092 sizeof(PVRSRV_KERNEL_MEM_INFO),
@@ -2028,11 +2099,11 @@ exitFailedImport:
2028/*! 2099/*!
2029****************************************************************************** 2100******************************************************************************
2030 2101
2031 @Function PVRSRVUnmapIonHandleKM 2102 @Function PVRSRVUnmapDmaBufKM
2032 2103
2033 @Description 2104 @Description
2034 2105
2035 Frees an ion buffer mapped with PVRSRVMapIonHandleKM, including the mem_info structure 2106 Releases a dma_buf mapped with PVRSRVMapDmaBufKM, including the mem_info structure
2036 2107
2037 @Input psMemInfo : 2108 @Input psMemInfo :
2038 2109
@@ -2040,7 +2111,7 @@ exitFailedImport:
2040 2111
2041******************************************************************************/ 2112******************************************************************************/
2042IMG_EXPORT 2113IMG_EXPORT
2043PVRSRV_ERROR IMG_CALLCONV PVRSRVUnmapIonHandleKM(PVRSRV_KERNEL_MEM_INFO *psMemInfo) 2114PVRSRV_ERROR IMG_CALLCONV PVRSRVUnmapDmaBufKM(PVRSRV_KERNEL_MEM_INFO *psMemInfo)
2044{ 2115{
2045 if (!psMemInfo) 2116 if (!psMemInfo)
2046 { 2117 {
@@ -2049,7 +2120,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVUnmapIonHandleKM(PVRSRV_KERNEL_MEM_INFO *psMemIn
2049 2120
2050 return ResManFreeResByPtr(psMemInfo->sMemBlk.hResItem, CLEANUP_WITH_POLL); 2121 return ResManFreeResByPtr(psMemInfo->sMemBlk.hResItem, CLEANUP_WITH_POLL);
2051} 2122}
2052#endif /* SUPPORT_ION */ 2123#endif /* SUPPORT_DMABUF */
2053 2124
2054/*! 2125/*!
2055****************************************************************************** 2126******************************************************************************
@@ -2294,7 +2365,7 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVWrapExtMemoryKM(IMG_HANDLE hDevCookie,
2294 } 2365 }
2295 else 2366 else
2296 { 2367 {
2297 PVR_DPF((PVR_DBG_ERROR, "PVRSRVWrapExtMemoryKM: invalid parameter, no address specificed")); 2368 PVR_DPF((PVR_DBG_ERROR, "PVRSRVWrapExtMemoryKM: invalid parameter, no address specified"));
2298 } 2369 }
2299 return PVRSRV_ERROR_INVALID_PARAMS; 2370 return PVRSRV_ERROR_INVALID_PARAMS;
2300 } 2371 }
@@ -2404,7 +2475,9 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVWrapExtMemoryKM(IMG_HANDLE hDevCookie,
2404 &psMemInfo->psKernelSyncInfo); 2475 &psMemInfo->psKernelSyncInfo);
2405 if(eError != PVRSRV_OK) 2476 if(eError != PVRSRV_OK)
2406 { 2477 {
2407 goto ErrorExitPhase4; 2478 FreeDeviceMem(psMemInfo);
2479 /* FreeDeviceMem will free the meminfo so jump straight to ErrorExitPhase2 */
2480 goto ErrorExitPhase2;
2408 } 2481 }
2409 2482
2410 /* increment the refcount */ 2483 /* increment the refcount */
@@ -2447,27 +2520,12 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVWrapExtMemoryKM(IMG_HANDLE hDevCookie,
2447 return PVRSRV_OK; 2520 return PVRSRV_OK;
2448 2521
2449 /* error handling: */ 2522 /* error handling: */
2450
2451ErrorExitPhase4:
2452 if(psMemInfo)
2453 {
2454 FreeDeviceMem(psMemInfo);
2455 /*
2456 FreeDeviceMem will free the meminfo so set
2457 it to NULL to avoid double free below
2458 */
2459 psMemInfo = IMG_NULL;
2460 }
2461
2462ErrorExitPhase3: 2523ErrorExitPhase3:
2463 if(psMemInfo) 2524 OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, sizeof(PVRSRV_KERNEL_MEM_INFO), psMemInfo, IMG_NULL);
2464 { 2525 /*not nulling pointer, out of scope*/
2465 OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, sizeof(PVRSRV_KERNEL_MEM_INFO), psMemInfo, IMG_NULL);
2466 /*not nulling pointer, out of scope*/
2467 }
2468 2526
2469ErrorExitPhase2: 2527ErrorExitPhase2:
2470 if(psIntSysPAddr) 2528 if(hOSWrapMem)
2471 { 2529 {
2472 OSReleasePhysPageAddr(hOSWrapMem); 2530 OSReleasePhysPageAddr(hOSWrapMem);
2473 } 2531 }
@@ -3116,7 +3174,15 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVMapDeviceClassMemoryKM(PVRSRV_PER_PROCESS_DATA *
3116 if (eError != PVRSRV_OK) 3174 if (eError != PVRSRV_OK)
3117 { 3175 {
3118 PVR_DPF((PVR_DBG_ERROR,"PVRSRVMapDeviceClassMemoryKM: AllocMemTilingRange failed")); 3176 PVR_DPF((PVR_DBG_ERROR,"PVRSRVMapDeviceClassMemoryKM: AllocMemTilingRange failed"));
3119 goto ErrorExitPhase3; 3177
3178 if (psMemInfo->psKernelSyncInfo)
3179 {
3180 PVRSRVKernelSyncInfoDecRef(psMemInfo->psKernelSyncInfo, psMemInfo);
3181 }
3182 FreeDeviceMem(psMemInfo);
3183
3184 /* FreeDeviceMem will free the meminfo so jump straight to the final exit */
3185 goto ErrorExitPhase1;
3120 } 3186 }
3121 } 3187 }
3122#endif 3188#endif
@@ -3178,36 +3244,11 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVMapDeviceClassMemoryKM(PVRSRV_PER_PROCESS_DATA *
3178#endif 3244#endif
3179 return PVRSRV_OK; 3245 return PVRSRV_OK;
3180 3246
3181#if defined(SUPPORT_MEMORY_TILING)
3182ErrorExitPhase3:
3183 if(psMemInfo)
3184 {
3185 if (psMemInfo->psKernelSyncInfo)
3186 {
3187 PVRSRVKernelSyncInfoDecRef(psMemInfo->psKernelSyncInfo, psMemInfo);
3188 }
3189
3190 FreeDeviceMem(psMemInfo);
3191 /*
3192 FreeDeviceMem will free the meminfo so set
3193 it to NULL to avoid double free below
3194 */
3195 psMemInfo = IMG_NULL;
3196 }
3197#endif
3198
3199ErrorExitPhase2: 3247ErrorExitPhase2:
3200 if(psMemInfo) 3248 OSFreeMem(PVRSRV_PAGEABLE_SELECT, sizeof(PVRSRV_KERNEL_MEM_INFO), psMemInfo, IMG_NULL);
3201 {
3202 OSFreeMem(PVRSRV_PAGEABLE_SELECT, sizeof(PVRSRV_KERNEL_MEM_INFO), psMemInfo, IMG_NULL);
3203 }
3204 3249
3205ErrorExitPhase1: 3250ErrorExitPhase1:
3206 if(psDCMapInfo) 3251 OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, sizeof(PVRSRV_DC_MAPINFO), psDCMapInfo, IMG_NULL);
3207 {
3208 OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, sizeof(PVRSRV_KERNEL_MEM_INFO), psDCMapInfo, IMG_NULL);
3209 }
3210
3211 return eError; 3252 return eError;
3212} 3253}
3213 3254
@@ -3241,27 +3282,53 @@ PVRSRV_ERROR IMG_CALLCONV PVRSRVInitDeviceMem(IMG_VOID)
3241{ 3282{
3242 PVRSRV_ERROR eError = PVRSRV_OK; 3283 PVRSRV_ERROR eError = PVRSRV_OK;
3243 3284
3244#if defined(SUPPORT_ION) || defined(SUPPORT_DRM_GEM) 3285#if defined(SUPPORT_ION)
3245 /* 3286 /*
3246 For Ion and GEM buffers we need to store which ones we know about so 3287 For Ion buffers we need to store which ones we know about so
3247 we don't give the same buffer a different sync 3288 we don't give the same buffer a different sync
3248 */ 3289 */
3249 PVR_DPF((PVR_DBG_ERROR,"PVRSRVInitDeviceMem: Creating external hash")); 3290 g_psIonSyncHash = HASH_Create(ION_SYNC_HASH_SIZE);
3250 g_psExternalSyncHash = HASH_Create(EXTERNAL_SYNC_HASH_SIZE); 3291 if (!g_psIonSyncHash)
3251 if (g_psExternalSyncHash == IMG_NULL) 3292 {
3293 eError = PVRSRV_ERROR_OUT_OF_MEMORY;
3294 goto Error;
3295 }
3296#endif
3297#if defined(SUPPORT_DMABUF)
3298 g_psDmaBufSyncHash = HASH_Create(DMABUF_SYNC_HASH_SIZE);
3299 if (!g_psDmaBufSyncHash)
3252 { 3300 {
3253 PVR_DPF((PVR_DBG_ERROR,"PVRSRVInitDeviceMem: Creating external hash failed"));
3254 eError = PVRSRV_ERROR_OUT_OF_MEMORY; 3301 eError = PVRSRV_ERROR_OUT_OF_MEMORY;
3302 goto Error;
3255 } 3303 }
3256#endif 3304#endif
3257 3305
3306#if defined(SUPPORT_ION) || defined(SUPPORT_DMABUF)
3307 return PVRSRV_OK;
3308Error:
3309#endif
3310#if defined(SUPPORT_DMABUF)
3311 if (g_psDmaBufSyncHash)
3312 {
3313 HASH_Delete(g_psDmaBufSyncHash);
3314 }
3315#endif
3316#if defined(SUPPORT_ION)
3317 if (g_psIonSyncHash)
3318 {
3319 HASH_Delete(g_psIonSyncHash);
3320 }
3321#endif
3258 return eError; 3322 return eError;
3259} 3323}
3260 3324
3261IMG_VOID IMG_CALLCONV PVRSRVDeInitDeviceMem(IMG_VOID) 3325IMG_VOID IMG_CALLCONV PVRSRVDeInitDeviceMem(IMG_VOID)
3262{ 3326{
3263#if defined(SUPPORT_ION) || defined(SUPPORT_DRM_GEM) 3327#if defined(SUPPORT_DMABUF)
3264 HASH_Delete(g_psExternalSyncHash); 3328 HASH_Delete(g_psDmaBufSyncHash);
3329#endif
3330#if defined(SUPPORT_ION)
3331 HASH_Delete(g_psIonSyncHash);
3265#endif 3332#endif
3266} 3333}
3267 3334