⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 memmgr.c

📁 Lido PXA270平台开发板的最新BSP,包括源代码
💻 C
字号:
/**************************************************************************
 * Name         : memmgr.c
 * Author       : BCB
 * Created      : 13/06/2003
 *
 * Copyright    : 2003 by Imagination Technologies Limited. All rights reserved.
 *              : No part of this software, either material or conceptual 
 *              : may be copied or distributed, transmitted, transcribed,
 *              : stored in a retrieval system or translated into any 
 *              : human or computer language in any form by any means,
 *              : electronic, mechanical, manual or other-wise, or 
 *              : disclosed to third parties without the express written
 *              : permission of Imagination Technologies Limited, Unit 8, HomePark
 *              : Industrial Estate, King's Langley, Hertfordshire,
 *              : WD4 8LZ, U.K.
 *
 * Platform     : ANSI
 *
 * $Date: 2003/11/10 17:22:02 $ $Revision: 1.1 $
 * $Log: memmgr.c $
 **************************************************************************/
#define MODULE_ID MODID_MEMMGR

/* Exclude from builds with Services */
#ifndef SERVICES_PRESENT

#include "context.h"

/***********************************************************************************
 Function Name      : CreatePhysAddrGenerator
 Inputs             : gc
 Outputs            : -
 Returns            : -
 Description        : Creates a physical address generator in a context
************************************************************************************/

IMG_VOID CreatePhysAddrGenerator(GLESContext *gc)
{
	PHYSMEMENTRY *psFreeMem = GLESCalloc(NULL, sizeof(PHYSMEMENTRY));

	gc->sHWContext.sPhysMemMgr.ui32FBBase = 0;
	gc->sHWContext.sPhysMemMgr.ui32FBSize = (32 * 1024 * 1024);

	psFreeMem->ui32Size = gc->sHWContext.sPhysMemMgr.ui32FBSize;
	psFreeMem->ui32StartAddr = gc->sHWContext.sPhysMemMgr.ui32FBBase;
	
	gc->sHWContext.sPhysMemMgr.psFreeMem = psFreeMem;

}

/***********************************************************************************
 Function Name      : DestroyPhysAddrGenerator
 Inputs             : gc
 Outputs            : -
 Returns            : -
 Description        : Destroys a physical address generator in a context
************************************************************************************/

IMG_VOID DestroyPhysAddrGenerator(GLESContext *gc)
{
	PHYSMEMENTRY *psEntry = gc->sHWContext.sPhysMemMgr.psFreeMem;
	PHYSMEMENTRY *psNext = psEntry;

	while(psNext)
	{
		psNext = psEntry->psNext;
		GLESFree(gc, psEntry);
		psEntry = psNext;
	}
}

/***********************************************************************************
 Function Name      : GetPhysAddr
 Inputs             : gc, ui32Size, ui32Align
 Outputs            : pui32Addr
 Returns            : Success
 Description        : Gets a physical address range from the generator
************************************************************************************/


IMG_BOOL GetPhysAddr(GLESContext *gc, IMG_UINT32 ui32Size, IMG_UINT32 ui32Align, IMG_UINT32 *pui32Addr)
{
	PHYSMEMENTRY *psEntry = gc->sHWContext.sPhysMemMgr.psFreeMem;
	PHYSMEMENTRY *psTemp;
	IMG_UINT32 ui32Adjust;

	while(psEntry)
	{
		ui32Adjust = psEntry->ui32StartAddr & (ui32Align - 1);
		
		if(ui32Adjust)
			ui32Adjust = ui32Align - ui32Adjust;

		if(psEntry->ui32Size == ui32Size)
		{
			if(!ui32Adjust)
			{
				*pui32Addr = psEntry->ui32StartAddr;
				psEntry->psPrev->psNext = psEntry->psNext;
				psEntry->psNext->psPrev = psEntry->psPrev;

				GLESFree(gc, psEntry);
				return IMG_TRUE;
			}
		}
		else if(psEntry->ui32Size > ui32Size + ui32Adjust)
		{
			*pui32Addr = psEntry->ui32StartAddr + ui32Adjust;

			if(ui32Adjust)
			{
				psTemp = GLESCalloc(gc, sizeof(PHYSMEMENTRY));
				psTemp->ui32Size = psEntry->ui32Size - (ui32Adjust + ui32Size);
				psTemp->ui32StartAddr = psEntry->ui32StartAddr + ui32Size + ui32Adjust;
				psTemp->psPrev = psEntry;
				psTemp->psNext = psEntry->psNext;
				
				if(psEntry->psNext)
				{
					psEntry->psNext->psPrev = psTemp;
				}
				psEntry->psNext = psTemp;
				
				psEntry->ui32Size = ui32Adjust;
			}
			else
			{
				psEntry->ui32Size -= ui32Size;
				psEntry->ui32StartAddr += ui32Size;
			}

			return IMG_TRUE;
		}

		psEntry = psEntry->psNext;
	}

	return IMG_FALSE;

}

/***********************************************************************************
 Function Name      : ReturnPhysAddr
 Inputs             : gc, ui32Size, ui32Addr
 Outputs            : -
 Returns            : -
 Description        : Returns a physical address range to the generator.
************************************************************************************/


IMG_VOID ReturnPhysAddr(GLESContext *gc, IMG_UINT32 ui32Size, IMG_UINT32 ui32Addr)
{
	PHYSMEMENTRY *psEntry = gc->sHWContext.sPhysMemMgr.psFreeMem;

	while(psEntry)
	{
		if(ui32Addr < psEntry->ui32StartAddr)
		{
			if(ui32Addr + ui32Size == psEntry->ui32StartAddr)
			{
				psEntry->ui32StartAddr -= ui32Size;
				psEntry->ui32Size += ui32Size;

				if(psEntry->psPrev)
				{
					if(psEntry->ui32StartAddr == (psEntry->psPrev->ui32StartAddr+psEntry->psPrev->ui32Size))
					{
						psEntry->psPrev->ui32Size += psEntry->ui32Size;
						psEntry->psPrev->psNext = psEntry->psNext;
						
						if(psEntry->psNext)
						{
							psEntry->psNext->psPrev = psEntry->psPrev;
						}
						GLESFree(gc, psEntry);
					}
				}
				return;
			}
			else if(psEntry->psPrev && (ui32Addr == (psEntry->psPrev->ui32StartAddr+psEntry->psPrev->ui32Size)))
			{
				psEntry->psPrev->ui32Size += ui32Size;
				return;
			}
			else
			{
				PHYSMEMENTRY *psTemp;
		
				psTemp = GLESCalloc(gc, sizeof(PHYSMEMENTRY));

				psTemp->ui32StartAddr = ui32Addr;
				psTemp->ui32Size = ui32Size;
				
				if(psEntry->psPrev)
					psEntry->psPrev->psNext = psTemp;

				psTemp->psPrev = psEntry->psPrev;
				psEntry->psPrev = psTemp;
				psTemp->psNext = psEntry;

				return;
			}

		}


		psEntry = psEntry->psNext;
	}

}

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -