📄 dual_buffer.c
字号:
if (pDBState->pDualPageArena==IMG_NULL)
goto cleanup;
if (DP_HaveHiArena (pDBState->pDualPager))
{
pDBState->pDualPageHiArena =
RA_Create (pDBState->pRAState, "dual page high", 0, 0,
HOST_PAGESIZE(), DP_AllocMany, DP_Free,
pDBState->pDualPager);
if (pDBState->pDualPageHiArena==IMG_NULL)
goto cleanup;
}
}
*ppState = pDBState;
return IMG_TRUE;
cleanup:
if (pDBState!=IMG_NULL)
{
DP_Delete (pDBState->pDualPager);
RA_Delete (pDBState->pDualPageArena);
RA_Delete (pDBState->pDualPageHiArena);
HASH_Delete (pDBState->pDualPageHash);
POOL_Delete (pDBState->pMemBufPool);
DP_Finalise (pDBState->pDPState);
RA_Finalise (pDBState->pRAState);
HASH_Finalise (pDBState->pHashState);
HostFreeMem(PVRSRV_HOST_PAGEABLE_HEAP, pDBState);
}
return IMG_FALSE;
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: DB_Finalise
PURPOSE: To finalise the dual buffer module. All allocated buffers must
be free'd before calling this function.
PARAMETERS: pDBState
RETURNS: None
</function>
------------------------------------------------------------------------------*/
void
DB_Finalise (DB_STATE *pDBState)
{
PVR_DPF ((PVR_DBG_MESSAGE, "DB_Finalise ()"));
PVR_ASSERT (pDBState!=IMG_NULL);
DP_Delete (pDBState->pDualPager);
RA_Delete (pDBState->pDualPageArena);
RA_Delete (pDBState->pDualPageHiArena);
HASH_Delete (pDBState->pDualPageHash);
POOL_Delete (pDBState->pMemBufPool);
DP_Finalise (pDBState->pDPState);
RA_Finalise (pDBState->pRAState);
HASH_Finalise (pDBState->pHashState);
HostFreeMem(PVRSRV_HOST_PAGEABLE_HEAP, pDBState);
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: DB_Alloc
PURPOSE: To allocate a buffer.
PARAMETERS: In: pDBState - dual buffer state (from DB_Initialise())
In: uSize - requested buffer size in bytes.
In: uBufferProps - property flags for the buffer.
In: uDevVAddrAlignment - required device virtual address
alignment, or 0.
Out: DevVAddr - Receives the device virtual address of
the allocated buffer.
RETURNS: Cpu virtual address of the allocated buffer, or 0.
</function>
-----------------------------------------------------------------------------*/
void *
DB_Alloc (DB_STATE *pDBState,
IMG_SIZE_T uSize,
IMG_UINT32 uBufferProps,
IMG_UINT32 uDevVAddrAlignment,
IMG_DEV_VIRTADDR *pDevVAddr)
{
BM_BUF *pBuf;
PVR_DPF ((PVR_DBG_MESSAGE,
"DB_Alloc (size=0x%lx, uBufferProps=%u, dev_align=%u)",
uSize, uBufferProps, uDevVAddrAlignment));
if (DB_AllocBuf (pDBState, uSize, uBufferProps, uDevVAddrAlignment, &pBuf))
{
if (!HASH_Insert (pDBState->pDualPageHash, (IMG_UINTPTR_T) pBuf->CpuVAddr, (IMG_UINTPTR_T)pBuf))
{
PVR_DPF((PVR_DBG_ERROR, "DB_Alloc: ERROR HASH_Insert FAILED"));
DB_FreeBuf (pDBState, &pBuf);
return IMG_NULL;
}
if (pDevVAddr!=IMG_NULL)
*pDevVAddr = pBuf->DevVAddr;
PVR_DPF ((PVR_DBG_MESSAGE,
"..DB_Alloc (); DevVAddr=0x%x", pBuf->DevVAddr.uiAddr));
return pBuf->CpuVAddr;
}
else
{
PVR_DPF((PVR_DBG_ERROR, "DB_Alloc: DB_AllocBuf FAILED"));
}
return IMG_NULL;
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: DB_Free
PURPOSE: Free a buffer previously allocated with DB_alloc().
PARAMETERS: In: pDBState - dual buffer state (from DB_Initialise())
In: CpuVAddr - cpu virtual address of buffer.
RETURNS: None.
</function>
-----------------------------------------------------------------------------*/
void
DB_Free (DB_STATE *pDBState, void *CpuVAddr)
{
BM_BUF *pBuf;
PVR_DPF ((PVR_DBG_MESSAGE, "DB_Free (CpuVAddr=0x%x)", CpuVAddr));
pBuf = (BM_BUF *) HASH_Remove (pDBState->pDualPageHash,
(IMG_UINTPTR_T)CpuVAddr);
PVR_ASSERT (pBuf!=IMG_NULL);
DB_FreeBuf (pDBState, &pBuf);
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: DB_AllocBuf
PURPOSE: Allocate a buffer mapped into both cpu and device virtual
address spaces. Differs from DB_alloc () only in
the nature of the interface.
PARAMETERS: In: pDBState - dual buffer state (from DB_Initialise())
In: uSize - requested buffer size in bytes.
In: uBufferProps - property flags for the buffer.
In: uDevVAddrAlignment - required device virtual address
alignment, or 0.
Out: ppBuf - receives a pointer to a descriptor of the
allocated buffer.
RETURNS: IMG_TRUE - Success
IMG_FALSE - Failed.
</function>
-----------------------------------------------------------------------------*/
IMG_BOOL
DB_AllocBuf (DB_STATE *pDBState,
IMG_SIZE_T uSize,
IMG_UINT32 uFlags,
IMG_UINT32 uAlignment,
BM_BUF **ppBuf)
{
PVR_ASSERT (pDBState != IMG_NULL);
PVR_ASSERT (ppBuf != IMG_NULL);
*ppBuf = POOL_Alloc (pDBState->pMemBufPool);
if (*ppBuf!=IMG_NULL)
{
if (AllocMemory (pDBState, uSize, uFlags, uAlignment, *ppBuf))
return IMG_TRUE;
POOL_Free (pDBState->pMemBufPool, *ppBuf);
PVR_DPF((PVR_DBG_ERROR, "DB_AllocBuf: ERROR AllocMemory FAILED"));
}
else
{
PVR_DPF((PVR_DBG_ERROR, "DB_AllocBuf: ERROR POOL_Alloc FAILED"));
}
return IMG_FALSE;
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: DB_WrapBuf
PURPOSE: Allocate a buffer mapped into both cpu and device virtual
address spaces.
PARAMETERS: In: pDBState - dual buffer state (from DB_Initialise())
In: base - system physical base address
In: uSize - requested buffer size in bytes.
In: uBufferProps - property flags for the buffer.
In: uDevVAddrAlignment - required device virtual address
alignment, or 0.
Out: buf - receives a pointer to a descriptor of the allocated
buffer.
RETURNS: IMG_TRUE - Success
IMG_FALSE - Failed.
</function>
-----------------------------------------------------------------------------*/
IMG_BOOL
DB_WrapBuf (DB_STATE *pDBState,
IMG_SYS_PHYADDR base,
IMG_SIZE_T uSize,
IMG_UINT32 uFlags,
IMG_UINT32 uDevVAddrAlignment,
BM_BUF **ppBuf)
{
PVR_DPF ((PVR_DBG_MESSAGE,
"DB_WrapBuf (base=0x%lx, size=0x%x, flags=%u, align=%u, bm=%p)",
base.uiAddr, uSize, uFlags, uDevVAddrAlignment, (IMG_UINT32)ppBuf));
*ppBuf = POOL_Alloc (pDBState->pMemBufPool);
if (*ppBuf!=IMG_NULL)
{
if (WrapMemory (pDBState, base, uSize, uFlags, uDevVAddrAlignment, *ppBuf))
{
PVR_DPF ((PVR_DBG_MESSAGE,
"..DB_WrapBuf() (dv=0x%x)\n",
(*ppBuf)->DevVAddr.uiAddr));
return IMG_TRUE;
}
POOL_Free (pDBState->pMemBufPool, *ppBuf);
}
return IMG_FALSE;
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: DB_FreeBuf
PURPOSE: Free a buffer previously allocated with DB_AllocBuf().
The buffer is identified by the buffer descriptor bm_buf
returned at allocation. Note the double indirection when
passing the buffer.
PARAMETERS: In: pDBState - dual buffer state (from DB_Initialise())
Out: ppBuf - buffer descriptor to free.
RETURNS: None.
</function>
-----------------------------------------------------------------------------*/
void
DB_FreeBuf (DB_STATE *pDBState, BM_BUF **ppBuf)
{
IMG_UINTPTR_T DevVAddr;
BM_BUF *pBuf;
PVR_ASSERT (ppBuf != IMG_NULL);
pBuf = *ppBuf;
PVR_ASSERT (pBuf != IMG_NULL);
DevVAddr = pBuf->DevVAddr.uiAddr;
#if DEBUG
{
IMG_UINTPTR_T CpuPAddr;
IMG_UINTPTR_T CpuVAddr;
CpuPAddr = pBuf->CpuPAddr.uiAddr;
CpuVAddr = (IMG_UINTPTR_T) pBuf->CpuVAddr;
PVR_DPF ((PVR_DBG_MESSAGE,
"DB_FreeBuf (buf=0x%x, hv=0x%08lx, dv=0x%08lx, hp=0x%08lx)",
pBuf, CpuVAddr, DevVAddr, CpuPAddr));
}
#endif
/* buffer addresses may not be page aligned if the original allocation
was a wrap of unaligned memory, compensate the DevVAddr before
deallocation */
DevVAddr &= ~DEV_PAGE_MASK;
if (pBuf->pArena != IMG_NULL)
RA_Free (pBuf->pArena, DevVAddr, pBuf->pRef);
else
DP_Free (pDBState->pDualPager, DevVAddr, pBuf->pRef);
POOL_Free (pDBState->pMemBufPool, pBuf);
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: DB_ContiguousStatistics
PURPOSE: Retrieve the contiguous buffer arena statistics.
PARAMETERS: In: pDBState - dual buffer state pointer
Out: stats - receives statistics
RETURNS: IMG_TRUE - Success
IMG_FALSE - Failed
</function>
-----------------------------------------------------------------------------*/
IMG_BOOL
DB_ContiguousStatistics (DB_STATE *pDBState,
IMG_UINT32 uFlags,
RA_STATISTICS **ppStats)
{
PVR_ASSERT (pDBState!=IMG_NULL);
return (DP_ContiguousStatistics (pDBState->pDPState, uFlags, ppStats));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -