Exemplo n.º 1
0
IMG_BOOL RA_Alloc(struct RA_ARENA *pArena, size_t uRequestSize,
		  struct BM_MAPPING **ppsMapping, u32 uFlags, u32 uAlignment,
		  u32 *base)
{
	IMG_BOOL bResult;
	size_t uSize = uRequestSize;

	PVR_ASSERT(pArena != NULL);

	if (pArena == NULL) {
		PVR_DPF(PVR_DBG_ERROR,
			 "RA_Alloc: invalid parameter - pArena");
		return IMG_FALSE;
	}

	PVR_DPF(PVR_DBG_MESSAGE, "RA_Alloc: "
		 "arena='%s', size=0x%x(0x%x), alignment=0x%x",
		 pArena->name, uSize, uRequestSize, uAlignment);

	bResult = _AttemptAllocAligned(pArena, uSize, ppsMapping, uFlags,
				       uAlignment, base);
	if (!bResult) {
		struct BM_MAPPING *psImportMapping;
		u32 import_base;
		size_t uImportSize = uSize;

		if (uAlignment > pArena->uQuantum)
			uImportSize += (uAlignment - 1);

		uImportSize =
		    ((uImportSize + pArena->uQuantum - 1) /
		     pArena->uQuantum) * pArena->uQuantum;

		bResult =
		    pArena->pImportAlloc(pArena->pImportHandle, uImportSize,
					 &uImportSize, &psImportMapping, uFlags,
					 &import_base);
		if (bResult) {
			struct BT *pBT;
			pBT = _InsertResourceSpan(pArena, import_base,
						uImportSize);

			if (pBT == NULL) {
				pArena->pImportFree(pArena->pImportHandle,
						    import_base,
						    psImportMapping);
				PVR_DPF(PVR_DBG_MESSAGE, "RA_Alloc: "
					 "name='%s', size=0x%x failed!",
					 pArena->name, uSize);

				return IMG_FALSE;
			}
			pBT->psMapping = psImportMapping;
#ifdef RA_STATS
			pArena->sStatistics.uFreeSegmentCount++;
			pArena->sStatistics.uFreeResourceCount += uImportSize;
			pArena->sStatistics.uImportCount++;
			pArena->sStatistics.uSpanCount++;
#endif
			bResult = _AttemptAllocAligned(pArena, uSize,
						 ppsMapping, uFlags, uAlignment,
						 base);
			if (!bResult)
				PVR_DPF(PVR_DBG_MESSAGE, "RA_Alloc: "
					 "name='%s' uAlignment failed!",
					 pArena->name);
		}
	}
#ifdef RA_STATS
	if (bResult)
		pArena->sStatistics.uCumulativeAllocs++;
#endif

	PVR_DPF(PVR_DBG_MESSAGE,
		 "RA_Alloc: name='%s', size=0x%x, *base=0x%x = %d",
		 pArena->name, uSize, *base, bResult);

	return bResult;
}
Exemplo n.º 2
0
IMG_BOOL
RA_Alloc (RA_ARENA *pArena,
		  IMG_SIZE_T uRequestSize,
		  IMG_SIZE_T *pActualSize,
		  BM_MAPPING **ppsMapping,
		  IMG_UINT32 uFlags,
		  IMG_UINT32 uAlignment,
		  IMG_UINT32 uAlignmentOffset,
		  IMG_UINTPTR_T *base)
{
	IMG_BOOL bResult;
	IMG_SIZE_T uSize = uRequestSize;

	PVR_ASSERT (pArena!=IMG_NULL);

	if (pArena == IMG_NULL)
	{
		PVR_DPF ((PVR_DBG_ERROR,"RA_Alloc: invalid parameter - pArena"));
		return IMG_FALSE;
	}

#if defined(VALIDATE_ARENA_TEST)
	ValidateArena(pArena);
#endif

#ifdef USE_BM_FREESPACE_CHECK
	CheckBMFreespace();
#endif

	if (pActualSize != IMG_NULL)
	{
		*pActualSize = uSize;
	}

	PVR_DPF ((PVR_DBG_MESSAGE,
			  "RA_Alloc: arena='%s', size=0x%x(0x%x), alignment=0x%x, offset=0x%x",
		   pArena->name, uSize, uRequestSize, uAlignment, uAlignmentOffset));

	

	bResult = _AttemptAllocAligned (pArena, uSize, ppsMapping, uFlags,
									uAlignment, uAlignmentOffset, base);
	if (!bResult)
	{
		BM_MAPPING *psImportMapping;
		IMG_UINTPTR_T import_base;
		IMG_SIZE_T uImportSize = uSize;

		


		if (uAlignment > pArena->uQuantum)
		{
			uImportSize += (uAlignment - 1);
		}

		
		uImportSize = ((uImportSize + pArena->uQuantum - 1)/pArena->uQuantum)*pArena->uQuantum;

		bResult =
			pArena->pImportAlloc (pArena->pImportHandle, uImportSize, &uImportSize,
								 &psImportMapping, uFlags, &import_base);
		if (bResult)
		{
			BT *pBT;
			pBT = _InsertResourceSpan (pArena, import_base, uImportSize);
			
			if (pBT == IMG_NULL)
			{
				
				pArena->pImportFree(pArena->pImportHandle, import_base,
									psImportMapping);
				PVR_DPF ((PVR_DBG_MESSAGE,
						  "RA_Alloc: name='%s', size=0x%x failed!",
						  pArena->name, uSize));
				
				return IMG_FALSE;
			}
			pBT->psMapping = psImportMapping;
#ifdef RA_STATS
			pArena->sStatistics.uFreeSegmentCount++;
			pArena->sStatistics.uFreeResourceCount += uImportSize;
			pArena->sStatistics.uImportCount++;
			pArena->sStatistics.uSpanCount++;
#endif
			bResult = _AttemptAllocAligned(pArena, uSize, ppsMapping, uFlags,
										   uAlignment, uAlignmentOffset,
										   base);
			if (!bResult)
			{
				PVR_DPF ((PVR_DBG_MESSAGE,
						  "RA_Alloc: name='%s' uAlignment failed!",
						  pArena->name));
			}
		}
	}
#ifdef RA_STATS
	if (bResult)
		pArena->sStatistics.uCumulativeAllocs++;
#endif

	PVR_DPF ((PVR_DBG_MESSAGE,
			  "RA_Alloc: name='%s', size=0x%x, *base=0x%x = %d",
			  pArena->name, uSize, *base, bResult));

	

#if defined(VALIDATE_ARENA_TEST)
	ValidateArena(pArena);
#endif

	return bResult;
}