Skip to content

Commit

Permalink
[Decode] Refine bo alloc api for flexiable extention
Browse files Browse the repository at this point in the history
* [Decode] Refine bo alloc api for flexiable extention

Use defined struct params for bo alloction
bo_alloc, bo_alloc_tiled, bo_alloc_userptr as pioneer
Replace all bo_alloc with new mos drm api
Replace all bo_alloc_tiled with new mos drm api
Replace all bo_alloc_userptr with new mos drm api
  • Loading branch information
Jexu authored and intel-mediadev committed Nov 27, 2023
1 parent 5c2ae6a commit f591dc4
Show file tree
Hide file tree
Showing 18 changed files with 524 additions and 457 deletions.
15 changes: 8 additions & 7 deletions media_driver/linux/common/cm/hal/cm_hal_os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,13 +532,14 @@ MOS_STATUS HalCm_AllocateBuffer_Linux(

MosUtilities::MosAtomicIncrement(MosUtilities::m_mosMemAllocCounterGfx);

bo = mos_bo_alloc_userptr(osInterface->pOsContext->bufmgr,
"CM Buffer UP",
(void *)(param->data),
tileformat,
ROUND_UP_TO(size,MOS_PAGE_SIZE),
ROUND_UP_TO(size,MOS_PAGE_SIZE),
0);
struct mos_drm_bo_alloc_userptr alloc_uptr;
alloc_uptr.name = "CM Buffer UP";
alloc_uptr.addr = (void *)(param->data);
alloc_uptr.tiling_mode = tileformat;
alloc_uptr.stride = ROUND_UP_TO(size,MOS_PAGE_SIZE);
alloc_uptr.size = ROUND_UP_TO(size,MOS_PAGE_SIZE);

bo = mos_bo_alloc_userptr(osInterface->pOsContext->bufmgr, &alloc_uptr);

osResource->bMapped = false;
if (bo)
Expand Down
53 changes: 38 additions & 15 deletions media_driver/linux/common/ddi/media_libva_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,14 @@ VAStatus DdiMediaUtil_AllocateSurface(
}
else if( mediaSurface->pSurfDesc->uiVaMemType == VA_SURFACE_ATTRIB_MEM_TYPE_USER_PTR )
{
bo = mos_bo_alloc_userptr( mediaDrvCtx->pDrmBufMgr,
"SysSurface",
(void *)mediaSurface->pSurfDesc->ulBuffer,
mediaSurface->pSurfDesc->uiTile,
pitch,
mediaSurface->pSurfDesc->uiBuffserSize,
0
);
struct mos_drm_bo_alloc_userptr alloc_uptr;
alloc_uptr.name = "SysSurface";
alloc_uptr.addr = (void *)mediaSurface->pSurfDesc->ulBuffer;
alloc_uptr.tiling_mode = mediaSurface->pSurfDesc->uiTile;
alloc_uptr.stride = pitch;
alloc_uptr.size = mediaSurface->pSurfDesc->uiBuffserSize;

bo = mos_bo_alloc_userptr( mediaDrvCtx->pDrmBufMgr, &alloc_uptr);

if (bo != nullptr)
{
Expand Down Expand Up @@ -744,14 +744,27 @@ VAStatus DdiMediaUtil_AllocateSurface(

if ( tileformat == TILING_NONE )
{
bo = mos_bo_alloc(mediaDrvCtx->pDrmBufMgr, "MEDIA", gmmSize, 4096, mem_type);
struct mos_drm_bo_alloc alloc;
alloc.name = "MEDIA";
alloc.size = gmmSize;
alloc.alignment = 4096;
alloc.ext.mem_type = mem_type;

bo = mos_bo_alloc(mediaDrvCtx->pDrmBufMgr, &alloc);
pitch = gmmPitch;
}
else
{
unsigned long ulPitch = 0;
bo = mos_bo_alloc_tiled(mediaDrvCtx->pDrmBufMgr, "MEDIA", gmmPitch, (gmmSize + gmmPitch -1)/gmmPitch, 1, &tileformat, (unsigned long *)&ulPitch, 0, mem_type);
pitch = ulPitch;
struct mos_drm_bo_alloc_tiled alloc_tiled;
alloc_tiled.name = "MEDIA";
alloc_tiled.x = gmmPitch;
alloc_tiled.y = (gmmSize + gmmPitch -1)/gmmPitch;
alloc_tiled.cpp = 1;
alloc_tiled.ext.tiling_mode = tileformat;
alloc_tiled.ext.mem_type = mem_type;

bo = mos_bo_alloc_tiled(mediaDrvCtx->pDrmBufMgr, &alloc_tiled);
pitch = alloc_tiled.pitch;
}

mediaSurface->bMapped = false;
Expand Down Expand Up @@ -847,7 +860,12 @@ VAStatus DdiMediaUtil_AllocateBuffer(

mem_type = MemoryPolicyManager::UpdateMemoryPolicy(&memPolicyPar);

MOS_LINUX_BO *bo = mos_bo_alloc(bufmgr, "Media Buffer", size, 4096, mem_type);
struct mos_drm_bo_alloc alloc;
alloc.name = "Media Buffer";
alloc.size = size;
alloc.alignment = 4096;
alloc.ext.mem_type = mem_type;
MOS_LINUX_BO *bo = mos_bo_alloc(bufmgr, &alloc);

mediaBuffer->bMapped = false;
if (bo)
Expand Down Expand Up @@ -927,7 +945,7 @@ VAStatus DdiMediaUtil_Allocate2DBuffer(
{
DDI_VERBOSEMESSAGE("Gmm Create Resource Failed.");
hRes = VA_STATUS_ERROR_ALLOCATION_FAILED;
goto finish;
return hRes;
}
uint32_t gmmPitch;
uint32_t gmmSize;
Expand All @@ -949,7 +967,12 @@ VAStatus DdiMediaUtil_Allocate2DBuffer(
mem_type = MemoryPolicyManager::UpdateMemoryPolicy(&memPolicyPar);

MOS_LINUX_BO *bo;
bo = mos_bo_alloc(bufmgr, "Media 2D Buffer", gmmSize, 4096, mem_type);
struct mos_drm_bo_alloc alloc;
alloc.name = "Media 2D Buffer";
alloc.size = gmmSize;
alloc.alignment = 4096;
alloc.ext.mem_type = mem_type;
bo = mos_bo_alloc(bufmgr, &alloc);

mediaBuffer->bMapped = false;
if (bo)
Expand Down
44 changes: 25 additions & 19 deletions media_driver/linux/common/os/mos_graphicsresource_specific.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ MOS_STATUS GraphicsResourceSpecific::Allocate(OsContext* osContextPtr, CreatePar
uint32_t bufPitch = GFX_ULONG_CAST(gmmResourceInfoPtr->GetRenderPitch());
uint32_t bufSize = GFX_ULONG_CAST(gmmResourceInfoPtr->GetSizeSurface());
bufHeight = gmmResourceInfoPtr->GetBaseHeight();
unsigned long linuxPitch = 0;
MOS_LINUX_BO* boPtr = nullptr;

char bufName[m_maxBufNameLength];
Expand All @@ -242,32 +241,39 @@ MOS_STATUS GraphicsResourceSpecific::Allocate(OsContext* osContextPtr, CreatePar
MOS_TraceEventExt(EVENT_RESOURCE_ALLOCATE, EVENT_TYPE_START, nullptr, 0, nullptr, 0);
if (nullptr != params.m_pSystemMemory)
{
boPtr = mos_bo_alloc_userptr(pOsContextSpecific->m_bufmgr,
bufName,
params.m_pSystemMemory,
tileFormatLinux,
bufPitch,
bufSize,
0);
struct mos_drm_bo_alloc_userptr alloc_uptr;
alloc_uptr.name = bufName;
alloc_uptr.addr = params.m_pSystemMemory;
alloc_uptr.tiling_mode = tileFormatLinux;
alloc_uptr.stride = bufPitch;
alloc_uptr.size = bufSize;

boPtr = mos_bo_alloc_userptr(pOsContextSpecific->m_bufmgr, &alloc_uptr);
}
// Only Linear and Y TILE supported
else if (tileFormatLinux == TILING_NONE)
{
boPtr = mos_bo_alloc(pOsContextSpecific->m_bufmgr, bufName, bufSize, 4096, mem_type);
struct mos_drm_bo_alloc alloc;
alloc.name = bufName;
alloc.size = bufSize;
alloc.alignment = 4096;
alloc.ext.mem_type = mem_type;
boPtr = mos_bo_alloc(pOsContextSpecific->m_bufmgr, &alloc);
}
else
{
struct mos_drm_bo_alloc_tiled alloc_tiled;
alloc_tiled.name = bufName;
alloc_tiled.x = bufPitch;
alloc_tiled.y = bufSize/bufPitch;
alloc_tiled.cpp = 1;
alloc_tiled.ext.tiling_mode = tileFormatLinux;
alloc_tiled.ext.mem_type = mem_type;

boPtr = mos_bo_alloc_tiled(pOsContextSpecific->m_bufmgr,
bufName,
bufPitch,
bufSize/bufPitch,
1,
&tileFormatLinux,
&linuxPitch,
0,
mem_type);

bufPitch = (uint32_t)linuxPitch;
&alloc_tiled);

bufPitch = (uint32_t)alloc_tiled.pitch;
}

m_mapped = false;
Expand Down
48 changes: 40 additions & 8 deletions media_driver/linux/common/os/mos_os_specific.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ int32_t Linux_GetCommandBuffer(
{
int32_t bResult = false;
MOS_LINUX_BO *cmd_bo = nullptr;
struct mos_drm_bo_alloc alloc;

if ( pOsContext == nullptr ||
pCmdBuffer == nullptr)
Expand All @@ -226,7 +227,11 @@ int32_t Linux_GetCommandBuffer(
}

// Allocate the command buffer from GEM
cmd_bo = mos_bo_alloc(pOsContext->bufmgr,"MOS CmdBuf",iSize,4096, MOS_MEMPOOL_SYSTEMMEMORY); // Align to page boundary
alloc.name = "MOS CmdBuf";
alloc.size = iSize;
alloc.alignment = 4096;
alloc.ext.mem_type = MOS_MEMPOOL_SYSTEMMEMORY;
cmd_bo = mos_bo_alloc(pOsContext->bufmgr, &alloc); // Align to page boundary
if (cmd_bo == nullptr)
{
MOS_OS_ASSERTMESSAGE("Allocation of command buffer failed.");
Expand Down Expand Up @@ -870,6 +875,7 @@ MOS_STATUS Linux_InitGPUStatus(
{
MOS_LINUX_BO *bo = nullptr;
MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
struct mos_drm_bo_alloc alloc;

if (pOsContext == nullptr)
{
Expand All @@ -888,7 +894,11 @@ MOS_STATUS Linux_InitGPUStatus(
}

// Allocate the command buffer from GEM
bo = mos_bo_alloc(pOsContext->bufmgr,"GPU Status Buffer", sizeof(MOS_GPU_STATUS_DATA) * MOS_GPU_CONTEXT_MAX, 4096, MOS_MEMPOOL_SYSTEMMEMORY); // Align to page boundary
alloc.name = "GPU Status Buffer";
alloc.size = sizeof(MOS_GPU_STATUS_DATA) * MOS_GPU_CONTEXT_MAX;
alloc.alignment = 4096;
alloc.ext.mem_type = MOS_MEMPOOL_SYSTEMMEMORY;
bo = mos_bo_alloc(pOsContext->bufmgr, &alloc); // Align to page boundary
if (bo == nullptr)
{
MOS_OS_ASSERTMESSAGE("Allocation of GPU Status Buffer failed.");
Expand Down Expand Up @@ -2216,7 +2226,6 @@ MOS_STATUS Mos_Specific_AllocateResource(
void * ptr;
int32_t iSize = 0;
int32_t iPitch = 0;
unsigned long ulPitch = 0;
MOS_STATUS eStatus;
MOS_LINUX_BO * bo = nullptr;
MOS_TILE_TYPE tileformat;
Expand Down Expand Up @@ -2497,12 +2506,25 @@ MOS_STATUS Mos_Specific_AllocateResource(
// Only Linear and Y TILE supported
if( tileformat_linux == TILING_NONE )
{
bo = mos_bo_alloc(pOsInterface->pOsContext->bufmgr, bufname, iSize, 4096, mem_type);
struct mos_drm_bo_alloc alloc;
alloc.name = bufname;
alloc.size = iSize;
alloc.alignment = 4096;
alloc.ext.mem_type = mem_type;
bo = mos_bo_alloc(pOsInterface->pOsContext->bufmgr, &alloc);
}
else
{
bo = mos_bo_alloc_tiled(pOsInterface->pOsContext->bufmgr, bufname, iPitch, iSize/iPitch, 1, &tileformat_linux, &ulPitch, 0, mem_type);
iPitch = (int32_t)ulPitch;
struct mos_drm_bo_alloc_tiled alloc_tiled;
alloc_tiled.name = bufname;
alloc_tiled.x = iPitch;
alloc_tiled.y = iSize/iPitch;
alloc_tiled.cpp = 1;
alloc_tiled.ext.tiling_mode = tileformat_linux;
alloc_tiled.ext.mem_type = mem_type;

bo = mos_bo_alloc_tiled(pOsInterface->pOsContext->bufmgr, &alloc_tiled);
iPitch = (int32_t)alloc_tiled.pitch;;
}

pOsResource->bMapped = false;
Expand Down Expand Up @@ -4032,7 +4054,12 @@ MOS_LINUX_BO * Mos_GetNopCommandBuffer_Linux(
return nullptr;
}

bo = mos_bo_alloc(pOsInterface->pOsContext->bufmgr, "NOP_CMD_BO", 4096, 4096, MOS_MEMPOOL_SYSTEMMEMORY);
struct mos_drm_bo_alloc alloc;
alloc.name = "NOP_CMD_BO";
alloc.size = 4096;
alloc.alignment = 4096;
alloc.ext.mem_type = MOS_MEMPOOL_SYSTEMMEMORY;
bo = mos_bo_alloc(pOsInterface->pOsContext->bufmgr, &alloc);
if(bo == nullptr)
{
return nullptr;
Expand Down Expand Up @@ -4067,7 +4094,12 @@ MOS_LINUX_BO * Mos_GetBadCommandBuffer_Linux(
return nullptr;
}

bo = mos_bo_alloc(pOsInterface->pOsContext->bufmgr, "BAD_CMD_BO", 4096, 4096, MOS_MEMPOOL_SYSTEMMEMORY);
struct mos_drm_bo_alloc alloc;
alloc.name = "BAD_CMD_BO";
alloc.size = 4096;
alloc.alignment = 4096;
alloc.ext.mem_type = MOS_MEMPOOL_SYSTEMMEMORY;
bo = mos_bo_alloc(pOsInterface->pOsContext->bufmgr, &alloc);
if(bo == nullptr)
{
return nullptr;
Expand Down
37 changes: 20 additions & 17 deletions media_driver/linux/ult/libdrm_mock/mos_bufmgr_api_mock.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,33 +47,36 @@
*/

struct mos_linux_bo *
mos_bo_alloc(struct mos_bufmgr *bufmgr, const char *name,
unsigned long size, unsigned int alignment, int mem_type, unsigned int pat_index, bool cpu_cacheable)
mos_bo_alloc(struct mos_bufmgr *bufmgr,
struct mos_drm_bo_alloc *alloc)
{
return bufmgr->bo_alloc(bufmgr, name, size, alignment, mem_type, pat_index, cpu_cacheable);
if (bufmgr && alloc && bufmgr->bo_alloc)
{
return bufmgr->bo_alloc(bufmgr, alloc);
}
return nullptr;
}

struct mos_linux_bo *
mos_bo_alloc_userptr(struct mos_bufmgr *bufmgr,
const char *name, void *addr,
uint32_t tiling_mode,
uint32_t stride,
unsigned long size,
unsigned long flags)
{
if (bufmgr->bo_alloc_userptr)
return bufmgr->bo_alloc_userptr(bufmgr, name, addr, tiling_mode,
stride, size, flags);
struct mos_drm_bo_alloc_userptr *alloc_uptr)
{
if (bufmgr && alloc_uptr && bufmgr->bo_alloc_userptr)
{
return bufmgr->bo_alloc_userptr(bufmgr, alloc_uptr);
}
return nullptr;
}

struct mos_linux_bo *
mos_bo_alloc_tiled(struct mos_bufmgr *bufmgr, const char *name,
int x, int y, int cpp, uint32_t *tiling_mode,
unsigned long *pitch, unsigned long flags, int mem_type, unsigned int pat_index, bool cpu_cacheable)
mos_bo_alloc_tiled(struct mos_bufmgr *bufmgr,
struct mos_drm_bo_alloc_tiled *alloc_tiled)
{
return bufmgr->bo_alloc_tiled(bufmgr, name, x, y, cpp,
tiling_mode, pitch, flags, mem_type, pat_index, cpu_cacheable);
if (bufmgr && alloc_tiled && bufmgr->bo_alloc_tiled)
{
return bufmgr->bo_alloc_tiled(bufmgr, alloc_tiled);
}
return nullptr;
}

void
Expand Down
Loading

0 comments on commit f591dc4

Please sign in to comment.