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

📄 mbx.c

📁 Lido PXA270平台开发板的最新BSP,包括源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/*!****************************************************************************
@File			mbx.c

@Title			Device specific routines

@Author			Imagination Technologies

@date   		18 / 9 / 03
 
@Copyright     	Copyright 2003-2004 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		Generic

@Description	Device specific functions

@DoxygenVer		

******************************************************************************/

/******************************************************************************
Modifications :-

$Log: mbx.c $
*****************************************************************************/

#ifdef SUPPORT_XSCALE_PLATFORM
#include <windows.h>
#endif

/* enable inline functions to write to the fast regs */
#define USE_INLINE_FASTREGS

#include "services_headers.h"
#include "buffer_manager.h"
#include "fbmem.h"
#include "mbx.h"
#include "mbx13ddef.h"
#include "mbx12ddef.h"
#include "mbx1defs.h"
#include "sharedutils.h"
#include "regpaths.h"
#ifdef __SH4__
#include "hw.h"
#endif

#if !defined(__KERNEL__)
/* utility */
#define FLOAT_TO_LONG(x) (* ((long *)( & x)))
#endif

#define ui32Float1AsInt		0x3f800000L	// 1.0f
#define ui32Float4096AsInt	0x45800000L	// 4096.0f
#define ui32Float4097AsInt	0x45800800L	// 4097.0f


/* external function prototypes */			
IMG_VOID PVRSRVComplexScene (PVRSRV_DEV_INFO *psDevInfo, PVRSRV_RENDER_CMD_INFO	*psRenderCmd);							
IMG_VOID SetMemInfoDirty(void);
IMG_VOID ProcessLock (PVRSRV_DEV_INFO		*psDevInfo, 
				  	PVRSRV_QUEUE_INFO		*psQueue,
				  	PVRSRV_LOCK_CMD_INFO	*psLockCmd);
IMG_VOID ProcessDummyLock (PVRSRV_DEV_INFO		*psDevInfo, 
				  				PVRSRV_QUEUE_INFO		*psQueue,
								PVRSRV_LOCK_CMD_INFO	*psLockCmd);

PVRSRV_ERROR EnableDevice(PPVRSRV_DEV_INFO psDevInfo);

/* local function prototypes */			
static IMG_VOID Handle3DComplete (PVRSRV_DEV_INFO *psDevInfo);
static IMG_VOID Handle2DSync(PVRSRV_DEV_INFO *psDevInfo);
static IMG_VOID ProcessRender (PVRSRV_DEV_INFO 		*psDevInfo, 
								PVRSRV_QUEUE_INFO		*psQueue,
								PVRSRV_RENDER_CMD_INFO	*psRenderCmd);		

#if defined(SUPPORT_3D_BLIT)

static IMG_VOID ProcessRenderBlt (PVRSRV_DEV_INFO 			*psDevInfo, 
								PVRSRV_QUEUE_INFO			*psQueue,
								PVRSRV_RENDERBLIT_CMD_INFO	*psRenderCmd);

static IMG_VOID ProcessDummyRenderBlt (	PVRSRV_DEV_INFO				*psDevInfo,
					 					PVRSRV_QUEUE_INFO			*psQueue,
										PVRSRV_RENDERBLIT_CMD_INFO	*ps3DBlitCmd);

static IMG_VOID ProcessOverlayRenderBlt (	PVRSRV_DEV_INFO					*psDevInfo,
					 						PVRSRV_QUEUE_INFO				*psQueue,
											PVRSRV_OVL_RENDERBLIT_CMD_INFO	*ps3DBlitCmd);
static IMG_VOID ProcessDummyOverlayRenderBlt (	PVRSRV_DEV_INFO					*psDevInfo,
					 						PVRSRV_QUEUE_INFO				*psQueue,
											PVRSRV_OVL_RENDERBLIT_CMD_INFO	*ps3DBlitCmd);

static PVRSRV_ERROR DevInitBlitMBX(PVRSRV_DEV_INFO	*psDevInfo, PVR3DIF_BLITCTL	**pps3DBlitCtl);

static IMG_VOID DevDeInitBlitMBX(PVRSRV_DEV_INFO *psDevInfo, PVR3DIF_BLITCTL *ps3DBlitCtl);

#endif

static IMG_VOID ProcessBlt (PVRSRV_DEV_INFO		*psDevInfo,
						 		PVRSRV_QUEUE_INFO		*psQueue,
 							 	PVRSRV_BLT_CMD_INFO	*psBltCmd);

static IMG_VOID ProcessDummyRender (PVRSRV_DEV_INFO 		*psDevInfo, 
								PVRSRV_QUEUE_INFO		*psQueue,
								PVRSRV_RENDER_CMD_INFO	*psRenderCmd);

static IMG_VOID ProcessDummyBlt (PVRSRV_DEV_INFO		*psDevInfo,
					 			PVRSRV_QUEUE_INFO		*psQueue,
 					 			PVRSRV_BLT_CMD_INFO	*psBltCmd);

static IMG_VOID SetupHWRegs(PVRSRV_DEV_INFO *psDevInfo, IMG_UINT32 ui32Offset);

static PVRSRV_ERROR Setup3DCtl(	PVRSRV_DEV_INFO		*psDevInfo,
								PVR3DIF_PARAMBUFFER	*psParamBuff,
								PVR3DIF_3DCTL		*ps3DCtl,
								IMG_UINT32			ui32AAFlags);

static IMG_VOID InitHWBackgroundObj(IMG_UINT32 *pui32BGObj);

static IMG_VOID CalcHWBGO3DCtl (DEVICE3D *ps3D, PVR3DIF_3DCTL *ps3DCtl, IMG_UINT32 ui32AAFlags);

static PVRSRV_ERROR CalcTileDimensions (PVRSRV_DEV_INFO *psDevInfo,
										PVR3DIF_3DCTL *ps3DCtl,
										IMG_UINT32 ui32Width, 
										IMG_UINT32 ui32Height);
#ifdef WINCE_PERF
struct 
{
	LARGE_INTEGER i64TotalTime;
	LARGE_INTEGER i64FrameStartTime;
	LARGE_INTEGER i64FrameStopTime;
	LARGE_INTEGER i64MaxTime;
	LARGE_INTEGER i64MinTime;
	IMG_UINT32	  u32CallCount;
} PROFILE_DATA;

__inline IMG_VOID INIT_RENDER_TIMER()
{
	PROFILE_DATA.i64MaxTime.QuadPart = 0;
	PROFILE_DATA.u32CallCount = 0;
	PROFILE_DATA.i64TotalTime.QuadPart = 0;
	PROFILE_DATA.i64MinTime.QuadPart = 10000000;
}

__inline IMG_VOID START_RENDER_TIMER()
{
	QueryPerformanceCounter(&PROFILE_DATA.i64FrameStartTime);
	PROFILE_DATA.u32CallCount++;
}
__inline IMG_VOID STOP_RENDER_TIMER()
{
	LARGE_INTEGER i64Time;
	QueryPerformanceCounter(&PROFILE_DATA.i64FrameStopTime);
	i64Time.QuadPart = PROFILE_DATA.i64FrameStopTime.QuadPart - PROFILE_DATA.i64FrameStartTime.QuadPart;
	PROFILE_DATA.i64TotalTime.QuadPart += i64Time.QuadPart;
	if(i64Time.QuadPart > PROFILE_DATA.i64MaxTime.QuadPart)
	{
		PROFILE_DATA.i64MaxTime.QuadPart = i64Time.QuadPart;
	}
	if(i64Time.QuadPart < PROFILE_DATA.i64MinTime.QuadPart)
	{
		PROFILE_DATA.i64MinTime.QuadPart = i64Time.QuadPart;
	}
}
__inline IMG_VOID PRINT_RENDER_DATA()
{
	/* Open profile file */
	FILE *pFile = _tfopen(TEXT("release\\Z-3DBlitprofile.txt"),TEXT("w+"));
	IMG_FLOAT fAvgRender, fMaxRender, fMinRender;
	LARGE_INTEGER i64Freq;

	QueryPerformanceFrequency(&i64Freq);
	fAvgRender = (((IMG_FLOAT) PROFILE_DATA.i64TotalTime.QuadPart / (IMG_FLOAT) PROFILE_DATA.u32CallCount) / (IMG_FLOAT) i64Freq.QuadPart);
	fMaxRender = ((IMG_FLOAT) PROFILE_DATA.i64MaxTime.QuadPart  / (IMG_FLOAT) i64Freq.QuadPart);
	fMinRender = ((IMG_FLOAT) PROFILE_DATA.i64MinTime.QuadPart  / (IMG_FLOAT) i64Freq.QuadPart);
	_ftprintf(pFile, TEXT("** Average Render Time = %f"),fAvgRender);
	_ftprintf(pFile, TEXT("\n"));
	_ftprintf(pFile, TEXT("** Max Render Time = %f"),fMaxRender);
	_ftprintf(pFile, TEXT("\n"));
	_ftprintf(pFile, TEXT("** Min Render Time = %f"),fMinRender);
	_ftprintf(pFile, TEXT("\n"));

	/* Close file */
	fclose(pFile);
}
#else
#define INIT_RENDER_TIMER()
#define START_RENDER_TIMER()
#define STOP_RENDER_TIMER()
#define PRINT_RENDER_DATA()
#endif


/*!
******************************************************************************

 @Function	ConvertToFloatFormatAndDivide
 
 @Description 
 
 Converts the supplied integer to floating representation which is then divided
 by 65536.  E.g. to convert 0.125 to floating point format, pass in the integer
 8192  (0.125 x 65536)

 Only works for positive integers.


 @Input    ui32Value 			: Positive integer to convert

 @Return   IMG_INT32			: Floating point format representation

******************************************************************************/
IMG_INT32 ConvertToFloatFormatAndDivide(IMG_INT32 i32Value)
{
    IMG_INT32 i32Exponent, i32Fp;
    
    i32Fp = 0;
    
    if (i32Value)
    {
        if (i32Value<0)
        {
			PVR_DPF((PVR_DBG_ERROR,"ConvertToFloatFormatAndDivide: Input is negative"));
        }
        
        /* Normalise i32Value by left-shifting until its most significant 1
                   has shifted into the sign bit (bit 31).  For i32Value==1
                   this will
                   take 31 steps, numbered 0..30, hence the exponent is
                   decremented
                   from an initial value of 127+30 */
        for (i32Exponent=157;(i32Value<<=1)>0;)
        {
            i32Exponent--;
        }
        
		/* Divide by 65536 */
		i32Exponent -= 16;

        /* Shift the significant 23bits of the fractional part, bits 8..30,
           down to bits 0..22 and mask out the sign bit/extension. */
        i32Fp |= (i32Value>>8) & 0x7fffff;
        
        i32Fp |= i32Exponent << 23;
    }
    
    return i32Fp;
}


/*!
******************************************************************************

 @Function	PVRSRVAcquire2DFifoSpaceISR
 
 @Description 
 
 USER AND KERNEL MODE FUNCTION 
 Attempts to acquire space in the SlavePort FIFO. Called from 
 display driver, 3D driver and ISRs

 This provides flow control for the slaveports. 

 On return, the number of bytes that can be written is returned in pui32BytesObtained.

 @Input    psDevInfo 			: UM devdata
 
 @Input    psHWInfo 			: HW Info

 @Output   *pui32BytesObtained	: free bytes in FIFO

 @Return   PVRSRV_ERROR			: 

******************************************************************************/
IMG_EXPORT
PVRSRV_ERROR IMG_CALLCONV PVRSRVAcquire2DFifoSpaceISR (PVRSRV_DEV_INFO	*psDevInfo,
													IMG_VOID		*pvRegsBase,
												   	IMG_UINT32	   	*pui32BytesObtained)
{
	PVRSRV_ERROR		eError;	
	DEVICE3D 			*ps3D = &psDevInfo->sDeviceSpecific.s3D;
	PVRSRV_MUTEX_HANDLE	*phMutex = &ps3D->hMutexTAFifoSpace;
	IMG_UINT32			ui32ReserveBytes;
	IMG_UINT32			ui32FifoBytes;
	
	eError = HostAcquireMutex (phMutex, IMG_FALSE); 
	if (eError != PVRSRV_OK)
	{
		PVR_DPF((PVR_DBG_ERROR,"PVRSRVAcquire2DFifoSpaceISR: failed to acquire the FIFO resource"));
		return eError;
	}

#ifdef DEBUG
	/* check appropriate resources have previously been acquired */
	if (HostIsResourceLocked(&ps3D->h2DSlaveportResource) == IMG_FALSE)
	{
		PVR_DPF((PVR_DBG_ERROR,"PVRSRVAcquire2DFifoSpaceISR: 2D slaveport is not locked"));
		eError = PVRSRV_ERROR_GENERIC;
		goto ErrorHandler; /* we need to release FIFO mutex */
	}
#endif /*DEBUG*/

	/* set up temporary for reserveTA */
	ui32ReserveBytes = ps3D->ui32BytesReservedTA;

	/* read fifo space from HW */
	//FIXME: make this inline
	ui32FifoBytes = (MBX1_SP_FIFO_DWSIZE - MBX_EXTRACT_FIFO_COUNT(ReadHWReg(pvRegsBase, MBX1_GLOBREG_INT_STATUS))) << 2;

	/* set bytes available for 3D port */
	//FIXME: should we include reserve on 2D port in case other 2DFifo functions use cached value?
	//ps3D->ui32BytesFreeTAFifo = ui32FifoBytes;

	/* Minus reserve if possible */
	if (ui32FifoBytes < ui32ReserveBytes)
	{
		ui32FifoBytes = 0;
	}
	else
	{
		ui32FifoBytes -= ui32ReserveBytes;
	} 

	/* set reserve for 2D port */
	ps3D->ui32BytesReserved2d = ui32FifoBytes;
		
	/* return the bytes available to 3d port */
	*pui32BytesObtained = ui32FifoBytes;

#if DEBUG
ErrorHandler:
#endif /*DEBUG*/

	if (HostReleaseMutex(phMutex) != PVRSRV_OK)
	{
		PVR_DPF((PVR_DBG_ERROR,"PVRSRVAcquire2DFifoSpaceISR: HostReleaseMutex failed"));
	}

	return eError;
}



/*!
******************************************************************************

 @Function	PVRSRVAcquire3DFifoSpaceISR
 
 @Description 
 
 USER AND KERNEL MODE FUNCTION 
 Attempts to acquire space in the SlavePort FIFO. Called from 
 display driver, 3D driver and ISRs

 This provides flow control for the slaveports. 

 On return, the number of bytes that can be written is returned in pui32BytesObtained.

 @Input    psDevInfo 			: UM devdata
 
 @Input    psHWInfo 			: HW Info

 @Output   *pui32BytesObtained	: free bytes in FIFO

 @Return   PVRSRV_ERROR			: 

******************************************************************************/
IMG_EXPORT
PVRSRV_ERROR IMG_CALLCONV PVRSRVAcquire3DFifoSpaceISR (PVRSRV_DEV_INFO	*psDevInfo,
													IMG_VOID		*pvRegsBase,
												   	IMG_UINT32	   	*pui32BytesObtained)
{
	PVRSRV_ERROR		eError;	
	DEVICE3D 			*ps3D = &psDevInfo->sDeviceSpecific.s3D;
	PVRSRV_MUTEX_HANDLE	*phMutex = &ps3D->hMutexTAFifoSpace;
	IMG_UINT32			ui32ReserveBytes;
	IMG_UINT32			ui32FifoBytes;
	
	eError = HostAcquireMutex (phMutex, IMG_FALSE); 
	if (eError != PVRSRV_OK)
	{
		PVR_DPF((PVR_DBG_ERROR,"PVRSRVAcquire3DFifoSpaceISR: failed to acquire the FIFO resource"));
		return eError;
	}

#ifdef DEBUG
	/* check appropriate resources have previously been acquired */
	if (HostIsResourceLocked(&ps3D->hTAResource) == IMG_FALSE)
	{
		PVR_DPF((PVR_DBG_ERROR,"PVRSRVAcquire3DFifoSpaceISR: TA and/or TA slaveport is not locked"));
		eError = PVRSRV_ERROR_GENERIC;
		goto ErrorHandler; /* we need to release FIFO mutex */
	}
#endif

	/* set up temporary for reserve2d */
	ui32ReserveBytes = ps3D->ui32BytesReserved2d;

	/* read fifo space from HW */
	//FIXME: make this inline
	ui32FifoBytes = (MBX1_SP_FIFO_DWSIZE - MBX_EXTRACT_FIFO_COUNT(ReadHWReg(pvRegsBase, MBX1_GLOBREG_INT_STATUS))) << 2;

	/* set bytes available for 2D port */
	//FIXME: should we include reserve on 3D port in case other 3DFifo functions use cached value?
	//ps3D->ui32BytesFreeTAFifo = ui32FifoBytes;

	/* Minus reserve if possible */
	if (ui32FifoBytes < ui32ReserveBytes)
	{
		ui32FifoBytes = 0;
	}
	else
	{
		ui32FifoBytes -= ui32ReserveBytes;
	} 

	/* set reserve for 3D port */
	ps3D->ui32BytesReservedTA = ui32FifoBytes;
		
	/* return the bytes available to 3d port */
	*pui32BytesObtained = ui32FifoBytes;

#if DEBUG
ErrorHandler:
#endif /*DEBUG*/

	if (HostReleaseMutex(phMutex) != PVRSRV_OK)
	{
		PVR_DPF((PVR_DBG_ERROR,"PVRSRVAcquire3DFifoSpaceISR: HostReleaseMutex failed"));
	}

	return eError;
}

/*!
******************************************************************************

 @Function	GetHWTextureSize
 
 @Description 
 
 Returns pixel size as MBX TSP HW size definition
  
 @Input    ui32TexSize 			 : pixel size 
 
 @Return   IMG_UINT32 

⌨️ 快捷键说明

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