/* * ======== MemMgr_Alloc_skel ======== */ Int32 MemMgr_Alloc_skel(UInt32 size, UInt32 *data) { MemAllocBlock *blockPtr; int numBlocks; // int i; void *ptr; UInt16 remoteProcId; // printf("--> MemMgr_Alloc_skel(size: %d, data: 0x%x)\n", // (int)size, (unsigned int)data); /* setup a call frame */ remoteProcId = (UInt16)data[0]; numBlocks = (int)data[1]; // printf("numBlocks: %d\n", numBlocks); blockPtr = (MemAllocBlock *)&data[2]; // printf("blockPtr: 0x%x\n", (unsigned int)blockPtr); #if 0 for (i = 0; i < numBlocks; i++) { if ((blockPtr + i)->pixelFormat == PIXEL_FMT_PAGE) { printf("blocks[%d].mode: %d\n", i, (blockPtr + i)->pixelFormat); printf("blocks[%d].len: %d\n", i, (blockPtr + i)->dim.len); } else { printf("blocks[%d].mode: %d\n", i, (blockPtr + i)->pixelFormat); printf("blocks[%d].width: %d\n", i, (blockPtr + i)->dim.area.width); printf("blocks[%d].height: %d\n", i, (blockPtr + i)->dim.area.height); } } #endif /* invoke the requested api */ ptr = MemMgr_Alloc(blockPtr, numBlocks); #if 0 for (i = 0; i < numBlocks; i++) { printf("blocks[%d].stride: %d\n", i, (blockPtr + i)->stride); printf("blocks[%d].ptr: 0x%x\n", i, (unsigned int)((blockPtr + i)->ptr)); printf("blocks[%d].reserved: 0x%x\n", i, (unsigned int)((blockPtr + i)->reserved)); } #endif // printf("<-- MemMgr_Alloc_skel, 0x%x\n", (unsigned int)ptr); return((Int32)ptr); }
/* Function to allocate memory from the SyslinkMemMgr */ Ptr SyslinkMemMgr_TilerMemory_alloc(SyslinkMemMgr_TilerMemory_Object *obj, SyslinkMemMgr_AllocParams *allocParams) { Ptr buf = NULL; #if defined (SYSLINK_USE_TILER) SyslinkMemMgr_AllocParams *instAllocParams = (SyslinkMemMgr_AllocParams *)allocParams; /* TBD: This function should be able to allocate multiple blocks*/ MemAllocBlock memAllocBlk; /* Memset is neccessary before MemMgr_Alloc RCM server raises assertions otherwise*/ MEMSET(&memAllocBlk, 0, sizeof(memAllocBlk)); if (instAllocParams->block[0].pixelFormat < ((1 << (sizeof(pixel_fmt_t) * 8)) -1)) { memAllocBlk.pixelFormat = (pixel_fmt_t)instAllocParams->block[0].pixelFormat; } else { obj= NULL; System_printf("\nThe pixelFormat value for SyslinkMemMgr_AllocParams is too big\n"); } memAllocBlk.dim.area.width = instAllocParams->block[0].dim.area.width; memAllocBlk.dim.area.height = instAllocParams->block[0].dim.area.height; if (obj != NULL) { buf = MemMgr_Alloc(&memAllocBlk, instAllocParams->tilerBlocks); if(buf == NULL){ System_printf("\nTiler MemMgr_Alloc failed\n"); } else { instAllocParams->block[0].stride = memAllocBlk.stride; } } #endif /* #if defined (SYSLINK_USE_TILER) */ return (buf); }
/*========================================================*/ OMX_ERRORTYPE SampleTest_AllocateBuffers(SampleCompTestCtxt * pContext, OMX_PARAM_PORTDEFINITIONTYPE * pPortDef) { OMX_ERRORTYPE eError = OMX_ErrorNone; OMX_U8 *pBuffer = NULL; BufferList *pBufferList; BufferList *pTemp; OMX_BUFFERHEADERTYPE *pBufferHdr; OMX_U32 i = 100; OMX_COMPONENTTYPE *pComp; #ifdef OMX_SAMPLE_TILER_TEST MemAllocBlock *pBlock = NULL; OMX_U32 nNumBlocks = 1; /*For i/p port allocate 2D packed buffer, for o/p port allocate 1D buffer. Ideally client should get this from GetParams but this is just a sample test so values are hardcoded*/ if (pPortDef->nPortIndex == OMX_SAMPLE_INPUT_PORT) { nNumBlocks = 2; pBlock = TIMM_OSAL_Malloc(sizeof(MemAllocBlock) * nNumBlocks, 0, 0, 0); TIMM_OSAL_Memset(pBlock, 0, sizeof(MemAllocBlock) * nNumBlocks); pBlock[0].dim.area.width = OMX_SAMPLE_IN_2DYWIDTH; pBlock[0].dim.area.height = OMX_SAMPLE_IN_2DYHEIGHT; pBlock[0].pixelFormat = PIXEL_FMT_8BIT; pBlock[1].dim.area.width = OMX_SAMPLE_IN_2DUVWIDTH; pBlock[1].dim.area.height = OMX_SAMPLE_IN_2DUVHEIGHT; pBlock[1].pixelFormat = PIXEL_FMT_16BIT; } else { nNumBlocks = 1; pBlock = TIMM_OSAL_Malloc(sizeof(MemAllocBlock) * nNumBlocks, 0, 0, 0); TIMM_OSAL_Memset(pBlock, 0, sizeof(MemAllocBlock) * nNumBlocks); pBlock[0].dim.len = OMX_SAMPLE_BUFFER_SIZE; pBlock[0].pixelFormat = PIXEL_FMT_PAGE; } #endif for (i = 0; i < pPortDef->nBufferCountActual; i++) { pBufferList = (BufferList *) TIMM_OSAL_Malloc(sizeof(BufferList), TIMM_OSAL_TRUE, 0, TIMMOSAL_MEM_SEGMENT_INT); if (!pBufferList) { OMX_TEST_SET_ERROR_BAIL (OMX_ErrorInsufficientResources, "malloc failed \n"); } if (pContext->bClientAllocBuf) { #ifdef OMX_SAMPLE_TILER_TEST /*For i/p port allocate 2D packed buffer, for o/p port allocate 1D buffer. Ideally client should get this from GetParams but this is just a sample test so values are hardcoded*/ pBuffer = MemMgr_Alloc(pBlock, nNumBlocks); printf("\nMemMgr allocated buffer = 0x%x\n", pBuffer); #else pBuffer = (OMX_U8 *) TIMM_OSAL_MallocaBuffer(pPortDef-> nBufferSize, pPortDef->bBuffersContiguous, pPortDef->nBufferAlignment); #endif if (!pBufferList) { OMX_TEST_SET_ERROR_BAIL (OMX_ErrorInsufficientResources, "malloc failed \n"); } printf("\nCalling UseBuf on port %d\n", pPortDef->nPortIndex); eError = OMX_UseBuffer(pContext->hComp, &pBufferHdr, pPortDef->nPortIndex, 0, pPortDef->nBufferSize, pBuffer); OMX_TEST_BAIL_IF_ERROR(eError); } else { pComp = (OMX_COMPONENTTYPE *) pContext->hComp; printf("\nCalling allocate buffer\n"); eError = OMX_AllocateBuffer(pContext->hComp, &pBufferHdr, pPortDef->nPortIndex, 0, pPortDef->nBufferSize); OMX_TEST_BAIL_IF_ERROR(eError); } printf("\npBufferHdr->nOutputPortIndex = %d\n", pBufferHdr->nOutputPortIndex); printf("\npBufferHdr->nInputPortIndex = %d\n", pBufferHdr->nInputPortIndex); pBufferList->pNextBuf = NULL; pBufferList->pBufHdr = pBufferHdr; pBufferList->pOrigBufHdr = pBufferHdr; if (pPortDef->eDir == OMX_DirInput) { printf("\npBufferHdr->nOutputPortIndex = %d\n", pBufferHdr->nOutputPortIndex); printf("\npBufferHdr->nInputPortIndex = %d\n", pBufferHdr->nInputPortIndex); pBufferHdr->nOutputPortIndex = OMX_NOPORT; if (pContext->pInBufferList == NULL) { pContext->pInBufferList = pBufferList; } else { pTemp = pContext->pInBufferList; while (pTemp->pNextBuf) pTemp = pTemp->pNextBuf; pTemp->pNextBuf = pBufferList; } } else { pBufferHdr->nInputPortIndex = OMX_NOPORT; printf("\npBufferHdr->nOutputPortIndex = %d\n", pBufferHdr->nOutputPortIndex); printf("\npBufferHdr->nInputPortIndex = %d\n", pBufferHdr->nInputPortIndex); if (pContext->pOutBufferList == NULL) { pContext->pOutBufferList = pBufferList; } else { pTemp = pContext->pOutBufferList; while (pTemp->pNextBuf) pTemp = pTemp->pNextBuf; pTemp->pNextBuf = pBufferList; } } } OMX_TEST_BAIL: #ifdef OMX_SAMPLE_TILER_TEST if (pBlock != NULL) TIMM_OSAL_Free(pBlock); #endif if (eError != OMX_ErrorNone) { if (pBufferList) { TIMM_OSAL_Free(pBufferList); } } return eError; }
/*! * @brief Allocate memory for remote processor application * * This function is called by remote processor application to * Allocate a buffer. * * @param dataSize Size of the marshalled data packet * @param data Marshalled data packet * * @sa SysLinkMemUtils_free */ Int32 SysLinkMemUtils_alloc (UInt32 dataSize, UInt32 * data) { AllocArgs * args = (AllocArgs *)data; Int i; MemAllocBlock * memBlock = NULL; Ptr allocedPtr = NULL; UInt32 retAddr = 0; UInt32 size = 0; Int32 status = PROCMGR_SUCCESS; SyslinkMemUtils_MpuAddrToMap mpuAddrList [1]; GT_2trace (curTrace, GT_ENTER, "SysLinkMemUtils_alloc", dataSize, data); memBlock = Memory_calloc (NULL, sizeof (MemAllocBlock) * args->numBuffers, 0); if (!memBlock) { status = PROCMGR_E_MEMORY; #if !defined(SYSLINK_BUILD_OPTIMIZE) GT_setFailureReason (curTrace, GT_4CLASS, (Char *)__func__, status, "Error allocating memBlock"); #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */ } else { for (i = 0; i < args->numBuffers; i++) { memBlock [i].pixelFormat = args->params [i].pixelFormat; memBlock [i].dim.area.width = args->params [i].width; memBlock [i].dim.area.height = args->params [i].height; memBlock [i].dim.len = args->params [i].length; } } if (status == PROCMGR_SUCCESS) { /* Allocation */ allocedPtr = MemMgr_Alloc (memBlock, args->numBuffers); if (!allocedPtr) { status = PROCMGR_E_MEMORY; #if !defined(SYSLINK_BUILD_OPTIMIZE) GT_setFailureReason (curTrace, GT_4CLASS, (Char *)__func__, status, "Error MemMgr buffer"); #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */ } } if (status == PROCMGR_SUCCESS) { for (i = 0; i < args->numBuffers; i++) { args->params [i].stride = memBlock [i].stride; args->params [i].ptr = memBlock [i].ptr; } size = _SysLinkMemUtils_bufferSize (memBlock, args->numBuffers); mpuAddrList [0].mpuAddr = (UInt32)allocedPtr; mpuAddrList [0].size = size; status = SysLinkMemUtils_map (mpuAddrList, 1, &retAddr, ProcMgr_MapType_Tiler, PROC_SYSM3); #if !defined(SYSLINK_BUILD_OPTIMIZE) if (status != PROCMGR_SUCCESS) { GT_setFailureReason (curTrace, GT_4CLASS, (Char *)__func__, status, "Error in SysLinkMemUtils_map"); } #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */ } if (status == PROCMGR_SUCCESS) { status = _SysLinkMemUtils_insertMapElement ((Ptr)retAddr, allocedPtr, size); #if !defined(SYSLINK_BUILD_OPTIMIZE) if (status != PROCMGR_SUCCESS) { GT_setFailureReason (curTrace, GT_4CLASS, (Char *)__func__, status, "Error in SysLinkMemUtils_InsertMapElement"); } #endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */ } if (status != PROCMGR_SUCCESS) { if (retAddr) { SysLinkMemUtils_unmap (retAddr, PROC_SYSM3); } if (allocedPtr) { MemMgr_Free (allocedPtr); } } if (memBlock) Memory_free (NULL, memBlock, 1); GT_1trace (curTrace, GT_LEAVE, "SysLinkMemUtils_alloc", retAddr); return retAddr; }
* CE functions. */ void * dce_alloc(int sz) { /* TODO: for now, allocate in tiler paged mode (1d) container.. until DMM * is enabled on ducati, this would make the physical address the same as * the virtual address on ducati, which simplifies some things. Maybe * later use ducati heap instead.. */ MemAllocBlock block = { .pixelFormat = PIXEL_FMT_PAGE, .dim = { .len = sz + sizeof(MemHeader), } }; MemHeader *h = MemMgr_Alloc(&block, 1); h->size = sz; h->ducati_addr = TilerMem_VirtToPhys(H2P(h)); memset(H2P(h), 0, sz); return H2P(h); } /** * Free a block allocated by dce_alloc() */ void dce_free(void *ptr) { MemMgr_Free(P2H(ptr));