📄 dual_page.c
字号:
PARAMETERS: In: pH - dual page handle, not the void type is dictated by
the generic nature of the resource allocator interface.
In: uSize - requested size in bytes
Out: pActualSize - received the actual size allocated in bytes
which may be >= requested size
Out: ppRef - receives the arbitrary user reference associated
with the underlying storage.
In: uFlags - bit mask of allocation flags
Out: base - receives a pointer to the allocated storage.
RETURNS: IMG_TRUE - success
IMG_FALSE - failed
</function>
-----------------------------------------------------------------------------*/
IMG_BOOL
DP_AllocMany (void *pH,
IMG_SIZE_T uSize,
IMG_SIZE_T *pActualSize,
void **ppRef,
IMG_UINT32 uFlags,
IMG_UINTPTR_T *pBase)
{
PVR_DPF ((PVR_DBG_MESSAGE, "DP_AllocMany (size=0x%x)", uSize));
// if (uSize < 0x10000)
// uSize <<= 3;
return DP_Alloc (pH, uSize, pActualSize, ppRef, uFlags, 0, pBase);
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: DP_Alloc
PURPOSE: Allocate a block of pages mapped in both cpu and device
virtual address spaces.
PARAMETERS: In: pH - dual page handle, note the void type is dictated by
the generic nature of the resource allocator interface.
In: uSize - requested size in bytes
Out: pActualSize - received the actual size allocated in bytes
which may be >= requested size
Out: ppRef - receives the arbitrary user reference associated
with the underlying storage.
In: uFlags - bit mask of allocation flags.
In: uDevVAddrAlignment - required alignment of device virtual
address, or 0.
Out: pDevVAddr - receives a pointer to the allocated storage.
RETURNS: IMG_TRUE - success
IMG_FALSE - failed
</function>
-----------------------------------------------------------------------------*/
IMG_BOOL
DP_Alloc (void *pH,
IMG_SIZE_T uRequestSize,
IMG_SIZE_T *pActualSize,
void **ppRef,
IMG_UINT32 uFlags,
IMG_UINT32 uDevVAddrAlignment,
IMG_UINTPTR_T *pDevVAddr)
{
DP_MAPPING *pMapping;
DP_PAGER *pPager = pH;
IMG_BOOL bResult;
IMG_SIZE_T uSize;
PVR_DPF ((PVR_DBG_MESSAGE,
"DP_Alloc (pPager=0x%x, uRequestSize=0x%x, uFlags=0x%x, uAlign=0x%x)",
pPager, uRequestSize, uFlags, uDevVAddrAlignment));
PVR_ASSERT (ppRef != IMG_NULL);
PVR_ASSERT (pPager != IMG_NULL);
PVR_ASSERT (pPager->pDPState != IMG_NULL);
uSize = HOST_PAGEALIGN (uRequestSize);
PVR_ASSERT (uSize >= uRequestSize);
pMapping = POOL_Alloc (pPager->pDPState->pMappingPool);
if (pMapping == IMG_NULL) goto fail_pool_alloc;
pMapping->CpuVAddr = 0;
pMapping->DevVAddr.uiAddr = 0;
pMapping->CpuPAddr.uiAddr = 0;
pMapping->uSize = uSize;
pMapping->eCpuMemoryOrigin = hm_none;
pMapping->pPager = pPager;
bResult = CpuMemoryAlloc (pPager, pMapping, pActualSize, uFlags,
uDevVAddrAlignment);
if (!bResult) goto fail_cpu_mem_alloc;
bResult = DevMemoryAlloc (pPager, pMapping, pActualSize, uFlags,
uDevVAddrAlignment, pDevVAddr);
if (!bResult) goto fail_dev_mem_alloc;
PVR_ASSERT (uDevVAddrAlignment>1?(pMapping->DevVAddr.uiAddr%uDevVAddrAlignment)==0:1);
PVR_DPF ((PVR_DBG_MESSAGE, "...DP_Alloc () = IMG_TRUE"));
*ppRef = pMapping;
return IMG_TRUE;
// DevMemoryFree (pMapping);
fail_dev_mem_alloc:
PVR_DPF ((PVR_DBG_WARNING, "...DP_Alloc () failed dev mem alloc"));
CpuMemoryFree (pPager, pMapping);
fail_cpu_mem_alloc:
PVR_DPF ((PVR_DBG_WARNING, "...DP_Alloc () failed cpu mem alloc"));
POOL_Free (pPager->pDPState->pMappingPool, pMapping);
fail_pool_alloc:
PVR_DPF ((PVR_DBG_WARNING, "...DP_Alloc () failed pool alloc"));
return IMG_FALSE;
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: DP_Wrap
PURPOSE: Allocate a block of pages mapped in both cpu and device
virtual address spaces.
PARAMETERS: In: pH - dual page handle, not the void type is dictated by
the generic nature of the resource allocator interface.
In: base - system physical address base
In: uSize - requested size in bytes
Out: pActualSize - received the actual size allocated in bytes
which may be >= requested size
Out: ppRef - receives the arbitrary user reference associated
with the underlying storage.
In: uFlags - bit mask of allocation flags.
In: uDevVAddrAlignment - required alignment of device virtual
address, or 0.
Out: pDevVAddr - receives a pointer to the allocated storage.
RETURNS: IMG_TRUE - Success
IMG_FALSE - Failed
</function>
-----------------------------------------------------------------------------*/
IMG_BOOL
DP_Wrap (void *h,
IMG_SYS_PHYADDR base,
IMG_SIZE_T uSize,
IMG_SIZE_T *pActualSize,
void **ref,
IMG_UINT32 uFlags,
IMG_UINT32 uDevVAddrAlignment,
IMG_UINTPTR_T *pDevVAddr)
{
DP_MAPPING *pMapping;
DP_PAGER *pPager = h;
int bResult;
IMG_CPU_PHYADDR CpuPAddr;
PVR_DPF ((PVR_DBG_MESSAGE,
"DP_Wrap(h=0x%x, base=0x%x, size=0x%x, pActualSize=0x%x, ref=0x%x, flags=%u, align=%u)",
h, base.uiAddr, uSize, pActualSize, ref, uFlags,
uDevVAddrAlignment));
PVR_ASSERT (pPager!=IMG_NULL);
PVR_ASSERT (pPager->pDPState!=IMG_NULL);
PVR_ASSERT (ref!=IMG_NULL);
pMapping = POOL_Alloc (pPager->pDPState->pMappingPool);
if (pMapping==IMG_NULL)
{
return IMG_FALSE;
}
uSize = HOST_PAGEALIGN (uSize);
if (pActualSize!=IMG_NULL)
*pActualSize = uSize;
pMapping->DevVAddr.uiAddr = 0;
pMapping->CpuVAddr = 0;
pMapping->CpuPAddr.uiAddr = 0;
pMapping->uSize = uSize;
pMapping->eCpuMemoryOrigin = hm_none;
pMapping->pPager = pPager;
CpuPAddr = ENV_SysPAddrToCpuPAddr (base);
bResult = CpuMemoryWrap (pMapping, CpuPAddr);
if (!bResult) goto fail_cleanup;
bResult = DevMemoryAlloc (pPager,
pMapping,
pActualSize,
uFlags,
uDevVAddrAlignment,
pDevVAddr);
if (!bResult) goto fail_cleanup;
*ref = pMapping;
return IMG_TRUE;
fail_cleanup:
DevMemoryFree (pMapping);
CpuMemoryFree (pPager, pMapping);
POOL_Free (pPager->pDPState->pMappingPool, pMapping);
return IMG_FALSE;
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: DP_Free
PURPOSE: Free a block of pages previously allocated via DP_Alloc
or DP_AllocMany.
PARAMETERS: In: h - dual page handle, not the void type is dictated by
the generic nature of the resource allocator interface.
In: base - base address of blocks to free.
In : ref - arbitrary user reference associated with the
underlying storage provided by DP_Alloc or
DP_AllocMany.
RETURNS: None
</function>
------------------------------------------------------------------------------*/
void
DP_Free (void *h, IMG_UINTPTR_T _base, void *ref)
{
DP_PAGER *pPager = h;
DP_MAPPING *pMapping;
pMapping = ref;
UNREFERENCED_PARAMETER (_base);
PVR_DPF ((PVR_DBG_MESSAGE,
"DP_Free (h=0x%x, base=0x%x, ref=0x%x)", h, _base, ref));
PVR_ASSERT (pMapping != IMG_NULL);
PVR_ASSERT (pPager != IMG_NULL);
PVR_ASSERT (pPager->pDPState != IMG_NULL);
CpuMemoryFree (pPager, pMapping);
DevMemoryFree (pMapping);
POOL_Free (pPager->pDPState->pMappingPool, pMapping);
PVR_DPF ((PVR_DBG_MESSAGE,
"..DP_Free (h=0x%x, base=0x%x, ref=0x%x)", h, _base, ref));
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: DP_HaveHiArena
PURPOSE: Test if we have a high arena.
PARAMETERS: In: pPager - dual page pager to test.
RETURNS: IMG_TRUE - high arena present
IMG_FALSE - no high arena.
</function>
-----------------------------------------------------------------------------*/
IMG_BOOL
DP_HaveHiArena (DP_PAGER *pPager)
{
return MMU_HaveHiArena (pPager->pMMU);
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: DP_ContiguousStatistics
PURPOSE: Retrieve the contiguous buffer arena statistics.
PARAMETERS: In: pDPState - dual page state (from DP_Initialise)
In: uFlags - allocation flags for which statistics are
required.
Out: ppStats - receives statistics
RETURNS: IMG_TRUE - Success
IMG_FALSE - Failure
</function>
-----------------------------------------------------------------------------*/
IMG_BOOL
DP_ContiguousStatistics (DP_STATE *pDPState,
IMG_UINT32 uFlags,
RA_STATISTICS **ppStats)
{
if (pDPState->pContiguousPool!=IMG_NULL
&& (uFlags & BP_POOL_MASK) < pDPState->uContiguousPoolCount)
{
RA_Statistics (pDPState->pContiguousPool[uFlags & BP_POOL_MASK].pSysPhysArena,
ppStats);
return IMG_TRUE;
}
return IMG_FALSE;
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: DP_AllocContiguous
PURPOSE: Allocate from the contiguous arena.
PARAMETERS: In: pPager - dual page pager to allocate from.
In: uPoolNr - pool to allocate from.
In: uSize - Size in bytes of required region.
Out: pActualSize - Receives actual size in bytes if non null.
In: uDevVAddrAlignment - Device v address alignment required.
Out: pCPUVAddr - Receives cpu virtual address.
Out: pCPUPAddr - Receives cpu physical address.
RETURNS: IMG_TRUE - Success.
IMG_FALSE - Failure.
</function>
-----------------------------------------------------------------------------*/
IMG_BOOL
DP_AllocContiguous (DP_PAGER *pPager,
IMG_UINT32 uPoolNr,
IMG_SIZE_T uSize,
IMG_SIZE_T *pActualSize,
IMG_UINT32 uDevVAddrAlignment,
IMG_CPU_VIRTADDR *pCPUVAddr,
IMG_CPU_PHYADDR *pCPUPAddr)
{
IMG_SYS_PHYADDR SysPAddr;
PVR_DPF ((PVR_DBG_MESSAGE,
"DP_AllocContiguous (size=0x%lx, align=0x%lx)",
uSize, uDevVAddrAlignment));
*pCPUVAddr = IMG_NULL;
pCPUPAddr->uiAddr = 0;
if (!RA_Alloc (pPager->pDPState->pContiguousPool[uPoolNr].pSysPhysArena,
uSize,
pActualSize,
IMG_NULL,
0,
uDevVAddrAlignment,
0,
&SysPAddr.uiAddr))
return IMG_FALSE;
*pCPUPAddr = ENV_SysPAddrToCpuPAddr (SysPAddr);
*pCPUVAddr = (IMG_CPU_VIRTADDR) ((IMG_UINTPTR_T) pPager->pDPState->pContiguousPool[uPoolNr].CpuVAddr + SysPAddr.uiAddr - pPager->pDPState->pContiguousPool[uPoolNr].descriptor->BaseSysPAddr.uiAddr);
PVR_DPF((PVR_DBG_MESSAGE, "..DP_AllocContiguous () cpu_vaddr=0x%08x cpu_paddr=0x%08x",
*pCPUVAddr, pCPUPAddr->uiAddr));
return IMG_TRUE;
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: DP_FreeContiguous
PURPOSE: Free allocation from the contiguous arena.
PARAMETERS: In: pPager - dual page pager to allocate from.
In: uPoolNr - pool to deallocate to.
In: CpuVAddr - CPU virtual address of allocated region.
RETURNS: None
</function>
-----------------------------------------------------------------------------*/
void
DP_FreeContiguous (DP_PAGER *pPager,
IMG_UINT32 uPoolNr,
IMG_CPU_PHYADDR cpuPAddr)
{
PVR_DPF((PVR_DBG_MESSAGE,
"DP_FreeContiguous (pPager=0x%x, uPoolNr=%d, cpuPAddr=0x%0x)",
pPager, uPoolNr, cpuPAddr.uiAddr));
RA_Free (pPager->pDPState->pContiguousPool[uPoolNr].pSysPhysArena,
ENV_CpuPAddrToSysPAddr (cpuPAddr).uiAddr,
IMG_NULL);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -