Graphics: Add a path to allocate memory without mapping into GPU
authorgwang23 <gang.a.wang@intel.com>
Wed, 19 Oct 2011 08:52:10 +0000 (16:52 +0800)
committerbuildbot <buildbot@intel.com>
Fri, 23 Dec 2011 16:44:12 +0000 (08:44 -0800)
BZ: 17008

For 9134 issue, the GPU address space is used out. add a path to allocate
memory without mapping into GPU to refine the usage of the GPU address
space.

Change-Id: Ibeffde0907238f7e232224d2f59b7db3051ccfb9
Signed-off-by: gwang23 <gang.a.wang@intel.com>
Reviewed-on: http://android.intel.com:8080/22084
Reviewed-by: Xu, Randy <randy.xu@intel.com>
Tested-by: Xu, Randy <randy.xu@intel.com>
Reviewed-by: buildbot <buildbot@intel.com>
Tested-by: buildbot <buildbot@intel.com>
Signed-off-by: Tong Bo <box.tong@intel.com>
Reviewed-on: http://android.intel.com:8080/27740

drivers/staging/mrst/pvr/include4/services.h
drivers/staging/mrst/pvr/services4/srvkm/common/buffer_manager.c

index 43051d3..4e6d05f 100755 (executable)
@@ -56,6 +56,7 @@ extern "C" {
 #define PVRSRV_MEM_RAM_BACKED_ALLOCATION       (1U<<9)
 #define PVRSRV_MEM_NO_RESMAN                           (1U<<10)
 #define PVRSRV_MEM_EXPORTED                                    (1U<<11)
+#define PVRSRV_MEM_NO_GPU_ADDR                         (1U<<20)
 
 
 #define PVRSRV_HAP_CACHED                                      (1U<<12)
index 9860c31..328b03b 100755 (executable)
@@ -101,19 +101,45 @@ AllocMemory (BM_CONTEXT                   *pBMContext,
                }
 
                
-               if (!RA_Alloc(pArena,
-                                         uSize,
-                                         IMG_NULL,
-                                         (IMG_VOID*) &pMapping,
-                                         uFlags,
-                                         uDevVAddrAlignment,
-                                         0,
-                                         pvPrivData,
-                                         ui32PrivDataLength,
-                                         (IMG_UINTPTR_T *)&(pBuf->DevVAddr.uiAddr)))
-               {
-                       PVR_DPF((PVR_DBG_ERROR, "AllocMemory: RA_Alloc(0x%x) FAILED", uSize));
-                       return IMG_FALSE;
+               if(uFlags & PVRSRV_MEM_NO_GPU_ADDR)
+               {
+                       IMG_SIZE_T uImportSize = uSize;
+                       IMG_BOOL result = IMG_TRUE;
+                       IMG_UINT32 uQuantum = MAX(HOST_PAGESIZE(), psBMHeap->sDevArena.ui32DataPageSize);
+
+                       if (uDevVAddrAlignment > uQuantum)
+                       {
+                               uImportSize += (uDevVAddrAlignment - 1);
+                       }
+
+                       uImportSize = ((uImportSize + uQuantum - 1)/uQuantum)*uQuantum;
+
+                       result = BM_ImportMemory(psBMHeap, uImportSize, &uImportSize, &pMapping, uFlags,
+                                                pvPrivData, ui32PrivDataLength, &pBuf->DevVAddr.uiAddr);
+                       if(result == IMG_FALSE)
+                       {
+                               PVR_DPF((PVR_DBG_ERROR, "AllocMemory: RA_Alloc(0x%x) FAILED", uSize));
+                               return IMG_FALSE;
+                       }
+                       PVR_ASSERT(pBuf->DevVAddr.uiAddr == 0)
+                       PVR_ASSERT(pMapping->DevVAddr.uiAddr == 0)
+               }
+               else
+               {
+                       if (!RA_Alloc(pArena,
+                                                 uSize,
+                                                 IMG_NULL,
+                                                 (IMG_VOID*) &pMapping,
+                                                 uFlags,
+                                                 uDevVAddrAlignment,
+                                                 0,
+                                                 pvPrivData,
+                                                 ui32PrivDataLength,
+                                                 (IMG_UINTPTR_T *)&(pBuf->DevVAddr.uiAddr)))
+                       {
+                               PVR_DPF((PVR_DBG_ERROR, "AllocMemory: RA_Alloc(0x%x) FAILED", uSize));
+                               return IMG_FALSE;
+                       }
                }
 
                uOffset = pBuf->DevVAddr.uiAddr - pMapping->DevVAddr.uiAddr;
@@ -595,7 +621,16 @@ FreeBuf (BM_BUF *pBuf, IMG_UINT32 ui32Flags, IMG_BOOL bFromAllocator)
 
 
                                PVR_ASSERT(pBuf->ui32ExportCount == 0)
-                               RA_Free (pBuf->pMapping->pArena, pBuf->DevVAddr.uiAddr, IMG_FALSE);
+
+                               if(ui32Flags & PVRSRV_MEM_NO_GPU_ADDR)
+                               {
+                                       PVR_ASSERT(pBuf->DevVAddr.uiAddr == 0)
+                                       BM_FreeMemory(pBuf->pMapping->pBMHeap, pBuf->DevVAddr.uiAddr, pBuf->pMapping);
+                               }
+                               else
+                               {
+                                       RA_Free (pBuf->pMapping->pArena, pBuf->DevVAddr.uiAddr, IMG_FALSE);
+                               }
                        }
                }
                else
@@ -2304,18 +2339,21 @@ BM_ImportMemory (IMG_VOID *pH,
        }
 
        
-       bResult = DevMemoryAlloc (pBMContext,
-                                                               pMapping,
-                                                               IMG_NULL,
-                                                               uFlags,
-                                                               (IMG_UINT32)uDevVAddrAlignment,
-                                                               &pMapping->DevVAddr);
-       if (!bResult)
+       if(!(uFlags & PVRSRV_MEM_NO_GPU_ADDR))
        {
-               PVR_DPF((PVR_DBG_ERROR,
-                               "BM_ImportMemory: DevMemoryAlloc(0x%x) failed",
-                               pMapping->uSize));
-               goto fail_dev_mem_alloc;
+               bResult = DevMemoryAlloc (pBMContext,
+                                                                       pMapping,
+                                                                       IMG_NULL,
+                                                                       uFlags,
+                                                                       (IMG_UINT32)uDevVAddrAlignment,
+                                                                       &pMapping->DevVAddr);
+               if (!bResult)
+               {
+                       PVR_DPF((PVR_DBG_ERROR,
+                                       "BM_ImportMemory: DevMemoryAlloc(0x%x) failed",
+                                       pMapping->uSize));
+                       goto fail_dev_mem_alloc;
+               }
        }
 
        
@@ -2401,7 +2439,10 @@ BM_FreeMemory (IMG_VOID *h, IMG_UINTPTR_T _base, BM_MAPPING *psMapping)
                return;
        }
 
-       DevMemoryFree (psMapping);
+       if(!(psMapping->ui32Flags & PVRSRV_MEM_NO_GPU_ADDR))
+       {
+               DevMemoryFree (psMapping);
+       }
 
        
        if((psMapping->ui32Flags & PVRSRV_MEM_INTERLEAVED) != 0)