/***************************************************************************** * 函 数 名 : bsp_sfree * * 功能描述 : BSP 动态内存释放(加spin lock保护,多核场景使用) * * 输入参数 : pMem: 动态内存指针 * 输出参数 : 无 * 返 回 值 : 无 *****************************************************************************/ void bsp_sfree(void* pMem) { u32 u32Size; u32 u32Flags; if(0 == *g_mem_init_mark) { return; } /* Invalid Cache */ if (!MEM_IS_AXI_ADDR(pMem)) { MEM_INVALID_CACHE(MEM_GET_ALLOC_ADDR(pMem), MEM_MGR_SIZE_FOR_CACHE); } #ifdef __BSP_MEM_DEBUG__ /* 检查当前内存是否有效 */ if (bsp_ptr_invalid(pMem) || MEM_FREE == MEM_ITEM_STATUS(pMem) || MEM_ITEM_FLAGS(pMem) == MEM_NORM_DDR_POOL) { printk("warning! ptr:0x%x, invalid mem block, or may free twice, or wrong mem flags line:%d\n", (unsigned int)pMem, __LINE__); return; } #endif u32Size = MEM_ITEM_SIZE(pMem); u32Flags = MEM_ITEM_FLAGS(pMem); bsp_memory_free(u32Flags, pMem, u32Size); return; }
/***************************************************************************** * 函 数 名 : bsp_sfree * * 功能描述 : BSP 动态内存释放(加spin lock保护,多核场景使用) * * 输入参数 : pMem: 动态内存指针 * 输出参数 : 无 * 返 回 值 : 无 *****************************************************************************/ void bsp_sfree(void* pMem) { u32 u32Size; u32 u32Flags; if(0 == *g_mem_init_mark) { return; } #ifdef __BSP_MEM_DEBUG__ if (bsp_ptr_invalid(pMem)) { bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_MEM, "warning! ptr:0x%x, invalid mem block line:%d\n", pMem, __LINE__); return; } #endif /* Invalid Cache */ if (!MEM_IS_AXI_ADDR(pMem)) { MEM_INVALID_CACHE(MEM_GET_ALLOC_ADDR(pMem), MEM_MGR_SIZE_FOR_CACHE); } #ifdef __BSP_MEM_DEBUG__ /* 检查当前内存是否有效 */ if (MEM_FREE == MEM_ITEM_STATUS(pMem)) { bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_MEM, "warning! ptr:0x%x, may free twice, or wrong mem status line:%d\n", (unsigned int)pMem, __LINE__); return; } #endif u32Size = MEM_ITEM_SIZE(pMem); u32Flags = MEM_ITEM_FLAGS(pMem); bsp_memory_free(u32Flags, pMem, u32Size); return; }
STATIC s32 bsp_mem_dump_block(u32 u32Addr) { BSP_BOOL bBlockInvalid = FALSE; bBlockInvalid = bBlockInvalid; if (NULL == (void *)u32Addr) { bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_MEM,"can't dump the block, the input ptr is NULL\n"); return BSP_ERROR; } if (MEM_MAGIC_NUM != MEM_ITEM_MAGIC(u32Addr)) { bBlockInvalid = TRUE; bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_MEM,"The Block:0x%x may Invalid!\n", u32Addr); } /* 为确保正确,统一刷下Cache */ MEM_INVALID_CACHE(MEM_GET_ALLOC_ADDR(u32Addr), MEM_MGR_SIZE_FOR_CACHE); bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_MEM,"================================\n"); bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_MEM,"dump mem block info:\n"); bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_MEM,"================================\n"); bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_MEM,"usr ptr: 0x%x\n", u32Addr); bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_MEM,"alloc ptr: 0x%x\n", (u32)MEM_GET_ALLOC_ADDR(u32Addr)); bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_MEM,"magic num: 0x%x\n", MEM_ITEM_MAGIC(u32Addr)); bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_MEM,"block size: %d\n", MEM_ITEM_SIZE(u32Addr)); bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_MEM,"mem flags: 0x%x\n", MEM_ITEM_FLAGS(u32Addr)); bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_MEM,"mem item next: 0x%x\n", MEM_ITEM_NEXT(u32Addr)); #ifdef __BSP_MEM_DEBUG__ bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_MEM,"used file name: %s\n", (bBlockInvalid) ? ("invalid") : (BSP_CHAR*)MEM_ITEM_FILE_NAME(u32Addr)); bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_MEM,"used line: %d\n", MEM_ITEM_LINE(u32Addr)); bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_MEM,"mem status: %s\n", (MEM_ITEM_STATUS(u32Addr)) ? ("ALLOC") : ("FREE")); #endif bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_MEM,"================================\n"); return BSP_OK; }