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

📄 mbx.c

📁 Lido PXA270平台开发板的最新BSP,包括源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
 @Return   PVRSRV_ERROR 

******************************************************************************/
PVRSRV_ERROR Enable3DDevice(PVRSRV_DEV_INFO *psDevInfo)
{
	PVRSRV_ERROR		eError = PVRSRV_OK;
	
	/* let's boot the device! */
	eError = psDevInfo->pfnInitDevice (psDevInfo);

	return eError;
}


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

 @Function	Disable3DDevice
 
 @Description 
 
 Enables a 3d device
  
 @Input    psDevInfo 			 : KM devinfo 
 
 @Return   PVRSRV_ERROR 

******************************************************************************/
PVRSRV_ERROR Disable3DDevice(PVRSRV_DEV_INFO *psDevInfo)
{
	PVRSRV_ERROR		eError = PVRSRV_OK;
	
	/* let's disable the device! */
	eError = psDevInfo->pfnDeInitDevice(psDevInfo);

	return eError;
}


#if defined(FIX_HW_PRN_223) || defined(FIX_HW_PRN_251) || defined(FIX_HW_PRN_264_MBXLITE) || defined(FIX_HW_PRN_264_MBX)
/*!
******************************************************************************

 @Function	SetupSpecialObject
 
 @Description 
 
 				setup the special offscreen object to fix complex scene
 				renders when the last tile in the MT has no opaque objects.
 				The object is inserted into the upper half of the BGO reserved
 				EVM 4k page
  
 @Input    psDevInfo 			 : KM devinfo
 @Input    pbyLinBase
 @Input    ui32ObjBase
 @Input    ui32ObjBaseOffset
 
 @Return   none 

******************************************************************************/
IMG_VOID SetupSpecialObject (PPVRSRV_DEV_INFO psDevInfo, 
							IMG_UINT8 *pui8LinBase, 
							IMG_UINT32 ui32ObjBase,
							IMG_UINT32 ui32ObjBaseOffset)
{
	IMG_UINT32	i;
	IMG_UINT32	ui32SpecialObjectPointer;
	IMG_UINT32	*pui32ObjData = (IMG_UINT32*)pui8LinBase;
	
	/* Object is 16 dwords from object pointer */
	ui32SpecialObjectPointer =	MBX1_OBJPTR_STRIPFLAGT0						|
								(1<<MBX1_OBJPTR_STATESIZESHIFT)				|
								((ui32ObjBaseOffset + (16 * sizeof(IMG_UINT32)))>>MBX1_OBJPTR_ADDRESS_GRANSHIFT);


	/*
		Setup the Object Pointer and terminator
	*/
	*pui32ObjData++ = ui32SpecialObjectPointer;
	*pui32ObjData++ = MBX1_OBJPTR_LISTEND;
	
	/* Each object list is 16 dwords (MBX) so pad remainder of list with zero */
	for (i=0; i<14; i++) 
	{
		*pui32ObjData++ = 0;
	}

	/*
		Setup List Pointer
	*/
	psDevInfo->sDeviceSpecific.s3D.ui32SpecialListPtr = (ui32ObjBase+ui32ObjBaseOffset)
												& MBX1_ISPRGNDATA_PTRMASK;
#if defined (FIX_HW_PRN_264_MBX)
	psDevInfo->sDeviceSpecific.s3D.ui32SpecialObjectPointer = ui32SpecialObjectPointer;
#endif
											
	/*
		TSP word (per Obj State) - need this
	*/
	*pui32ObjData++ = MBX1_TSPOBJ_ACMPMODEALWAYS;
	
	/*
		ISP/TSP control words - state data for each poly is placed immediately
		before it.
	*/
#if defined(FIX_HW_PRN_145)
	*pui32ObjData++  = MBX1_ISPTSPCTL_SRCBLENDONE |
						MBX1_ISPTSPCTL_DESTBLENDZERO |
						MBX1_ISPTSPCTL_BLENDOPMODEFOGNONE |
						MBX1_ISPTSPCTL_CKDISABLE |
						MBX1_ISPTSPCTL_DCMPMODEALWAYS |
						MBX1_ISPTSPCTL_DWDISABLE |
						(0 << MBX1_ISPTSPCTL_NUMPASSESSHIFT);
#else
	*pui32ObjData++  = MBX1_ISPTSPCTL_SRCBLENDONE |
						MBX1_ISPTSPCTL_DESTBLENDZERO |
						MBX1_ISPTSPCTL_LOGICALOPDISABLE |
						MBX1_ISPTSPCTL_CKDISABLE |
						MBX1_ISPTSPCTL_DCMPMODEALWAYS |
						MBX1_ISPTSPCTL_DWDISABLE |
						(0 << MBX1_ISPTSPCTL_NUMPASSESSHIFT);
#endif
	/*
		X,Y
	*/
	*pui32ObjData++  = ui32Float4096AsInt;
	*pui32ObjData++  = ui32Float4097AsInt;

	*pui32ObjData++  = ui32Float4096AsInt;
	*pui32ObjData++  = ui32Float4096AsInt;

	*pui32ObjData++  = ui32Float4097AsInt;
	*pui32ObjData++  = ui32Float4096AsInt;

	/*
		Z
	*/
	*pui32ObjData++  = ui32Float1AsInt;
	*pui32ObjData++  = ui32Float1AsInt;	
	*pui32ObjData++  = ui32Float1AsInt;	

	/*
		RHW
	*/
	*pui32ObjData++  = ui32Float1AsInt;
	*pui32ObjData++  = ui32Float1AsInt;
	*pui32ObjData++  = ui32Float1AsInt;

	/*
		Base colour 
	*/
	*pui32ObjData++ = 0x0;
	*pui32ObjData++ = 0x0;
	*pui32ObjData++ = 0x0;
}
#endif

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

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

 @Function	DestroyParameterBufferCallBack
 
 @Description 
 	destroy PB implementation
  
 @Input    ui32ProcessID - process id
 @Input    pvParam - data packet
 @Input    ui32Param - packet size
 
 @Return   PVRSRV_ERROR 

******************************************************************************/
static PVRSRV_ERROR DestroyParameterBufferCallBack(IMG_UINT32	ui32ProcessID, 
												   IMG_PVOID	pvParam, 
												   IMG_UINT32	ui32Param)
{
	PVRSRV_DEV_INFO *psDevInfo; 
	PVR3DIF_PARAMBUFFER *psParamBuff;
	DEVICE3D *ps3D;
	
	psDevInfo = (PVRSRV_DEV_INFO*)pvParam;
	ps3D = &psDevInfo->sDeviceSpecific.s3D;
	psParamBuff= (PVR3DIF_PARAMBUFFER *)ps3D->hParamBuffer;

	/* The ps3DCtlList being empty is insufficient to guarantee we can remove the PB, as the removal of RTs
	 * is non-atomic wrt the subsequent destruction of the PB. 
	 * We therefore use a refcount to ensure correct behaviour.
	 */
	ps3D->ui32ParamBufferRefCount--;

	/*
		Only destroy the parameter buffer if all render targets have been removed and refcount is 0.
	*/
	if(psParamBuff && (ps3D->ui32ParamBufferRefCount == 0) && (psParamBuff->ps3DCtlList == IMG_NULL))
	{
		/* Free the parameter space */
		if (psParamBuff->pvParamLinBaseKM)
		{
			FreeStaticFBMem(psDevInfo, psParamBuff->pvParamLinBaseKM);
		}
		
		/* Free PageTable mem. */
		if (psParamBuff->pvPageTableLinBaseKM)
		{
			FreeStaticFBMem(psDevInfo, psParamBuff->pvPageTableLinBaseKM);
		}

#ifdef SUPPORT_POWER_STATE
		HostFreeMem(PVRSRV_HOST_NON_PAGEABLE_HEAP, psParamBuff->pvBGOPageShadow);
#endif

		/* Free actual PBDesc. */
		HostFreeMem(PVRSRV_HOST_NON_PAGEABLE_HEAP, psParamBuff);	
		
		psDevInfo->sDeviceSpecific.s3D.hParamBuffer = IMG_NULL;

#if defined(SUPPORT_3D_BLIT)
		/* De-initialise 3D blitting */
		DevDeInitBlitMBX(psDevInfo, (PVR3DIF_BLITCTL *) psDevInfo->sDeviceSpecific.s3D.h3DBlitCtl);
#endif		
		/* 
			Gate the 3D and TA cores 
		*/
		SysCoreDisable(psDevInfo, DEV_CGCORE_MBX_TA, IMG_TRUE);
		SysCoreDisable(psDevInfo, DEV_CGCORE_MBX_3D, IMG_TRUE);
	}

	return(PVRSRV_OK);
}	


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

 @Function	PVRSRVCreateParameterBuffer
 
 @Description 
 Must be called prior to adding render targets.
 If the parameter buffer does not exist - it is created.
 References are counted.
 
 @Input    psDevData : 

 @Input    ui32ParamBuffSize : 

 @Return   PVRSRV_ERROR  : 

******************************************************************************/
IMG_EXPORT PVRSRV_ERROR PVRSRVCreateParameterBuffer(PVRSRV_DEV_DATA *psDevData, IMG_UINT32 ui32ParamBuffSize)
{
	PVRSRV_DEV_INFO *psDevInfo = psDevData->psDevInfoKM;
	DEVICE3D *psDevice = &psDevInfo->sDeviceSpecific.s3D;
	PVRSRV_ERROR eError = PVRSRV_OK;
	PVR3DIF_PARAMBUFFER 	*psParamBuffer = IMG_NULL;
	IMG_VOID				*pvParamLinBase = IMG_NULL;
	IMG_VOID				*pvPageTableLinBase = IMG_NULL;

	/* If we haven't got one means we haven't setup our primary PB yet.. */
	if	(!psDevice->hParamBuffer)
	{
		IMG_DEV_VIRTADDR			ParamDevVAddr; 
		IMG_DEV_VIRTADDR			PageTableDevVAddr; 
		IMG_UINT32					ui32NumBlocks;
		
		if(ui32ParamBuffSize < MBX1_TA_EVM_PAGETBL_GRAN)
		{
			PVR_DPF((PVR_DBG_ERROR,"Cannot run 3D with less than 1 page of parameter memory"));
			return PVRSRV_ERROR_INVALID_PARAMS;
		}

		eError = PVRSRV_ERROR_OUT_OF_MEMORY;
		
		pvParamLinBase		= 0;
		pvPageTableLinBase = 0;
		
		if(HostAllocMem( PVRSRV_HOST_NON_PAGEABLE_HEAP, 
						 sizeof(PVR3DIF_PARAMBUFFER), 
						 (IMG_VOID **)&psParamBuffer, 0) != PVRSRV_OK)
		{
			PVR_DPF((PVR_DBG_ERROR,"PVRSRVCreateParameterBuffer: Failed to alloc host mem for ParamBuffer struct !"));
			goto ErrorExit;
		}
		
		/* Init host to zero */
		HostMemSet(psParamBuffer, 0, sizeof(PVR3DIF_PARAMBUFFER));
		
		/* round to space to page size */
		ui32ParamBuffSize = (ui32ParamBuffSize + MBX1_TA_EVM_PAGETBL_GRAN - 1) & ~(MBX1_TA_EVM_PAGETBL_GRAN-1);
			/*
			Add an extra page for BGO
		*/
		ui32ParamBuffSize += MBX1_TA_EVM_PAGETBL_GRAN;
		
		if(ui32ParamBuffSize > MBX1_ADDRRANGE_PARAMDATA)
		{
			PVR_DPF((PVR_DBG_WARNING,"Cannot allocate more than 8Mb less 1 page for BG obj data"));
			ui32ParamBuffSize = MBX1_ADDRRANGE_PARAMDATA;
		}

		/* Allocate frame buffer object memory as required.. */
		eError = AllocStaticFBMem(	psDevInfo,
									0,
									ui32ParamBuffSize,
									MBX1_ADDRGRAN_OBJBASE,
									&pvParamLinBase,
									&ParamDevVAddr);
		if (eError != PVRSRV_OK)
		{
			PVR_DPF((PVR_DBG_ERROR,"Failed to allocate FB object area !"));
			goto ErrorExit;
		}

#ifdef SUPPORT_POWER_STATE
		/* Allocate a shadow page for the background object */
		if(HostAllocMem( PVRSRV_HOST_NON_PAGEABLE_HEAP, 
						 MBX1_TA_EVM_PAGETBL_GRAN, 
						 (IMG_VOID **)&psParamBuffer->pvBGOPageShadow, 0) != PVRSRV_OK)
		{
			PVR_DPF((PVR_DBG_ERROR,"PVRSRVCreateParameterBuffer: Failed to alloc shadow page for BGO !"));
			goto ErrorExit;
		}
#endif
		
			
#if defined(FIX_HW_PRN_223) || defined(FIX_HW_PRN_251) || defined(FIX_HW_PRN_264_MBXLITE) || defined(FIX_HW_PRN_264_MBX)
		/*
		Setup special Object pointer and Object Data
		setup halfway through spare page (lower half used by BGO)
		*/
		SetupSpecialObject (psDevInfo,
			(IMG_UINT8 *)pvParamLinBase+MBX1_TA_EVM_PAGETBL_GRAN/2,
			ParamDevVAddr.uiAddr,											/* Object Base */
			MBX1_TA_EVM_PAGETBL_GRAN/2);									/* Offset from Object Base */
#endif
		
		InitHWBackgroundObj(pvParamLinBase);

		/* Allocate FB memory for page table. */ 
		eError = AllocStaticFBMem(	psDevInfo,
									0,
									MBX1_FREEPAGELIST_MAX_ENTRIES * MBX1_FREEPAGELIST_ENTRY_SIZE,
									MBX1_ADDRGRAN_FREEPAGELIST,
									&pvPageTableLinBase,
									&PageTableDevVAddr);

		if (eError != PVRSRV_OK)
		{
			PVR_DPF((PVR_DBG_ERROR,"ERROR - Failed to alloc host mem for TA/Render HW control structures !"));
			goto ErrorExit;
		}
		
		/* Calc number of blocks. */
		ui32NumBlocks = ui32ParamBuffSize / MBX1_TA_EVM_PAGETBL_GRAN;
		
		/* Reserve the first page for the HW background object data */
		ui32NumBlocks--;
		
		/* Save the info in PBDESC */
		psParamBuffer->ui32TotalPBSize		= ui32ParamBuffSize;
		psParamBuffer->ui32NumBlocks		= ui32NumBlocks;
		psParamBuffer->ParamDevVAddr		= ParamDevVAddr;
		psParamBuffer->pvParamLinBaseKM		= pvParamLinBase;
		psParamBuffer->PageTableDevVAddr	= PageTableDevVAddr;
		psParamBuffer->pvPageTableLinBaseKM	= pvPageTableLinBase;
		psParamBuffer->ps3DCtlList			= IMG_NULL;
		
		/* Set pointer in parent structure. */
		psDevice->hParamBuffer = (IMG_HANDLE)psParamBuffer;

		/* 
			Ungate the 3D
		*/
		if (SysCoreEnable(psDevInfo, DEV_CGCORE_MBX_TA, IMG_TRUE) != PVRSRV_OK)
		{
			PVR_DPF((PVR_DBG_ERROR,"PVRSRVCreateParameterBuffer: failed to ungate TA"));
			goto ErrorExit;
		}
		if (SysCoreEnable(psDevInfo, DEV_CGCORE_MBX_3D, IMG_TRUE) != PVRSRV_OK)
		{
			PVR_DPF((PVR_DBG_ERROR,"PVRSRVCreateParameterBuffer: failed to ungate 3d"));
			goto ErrorExit;
		}
		
		/* 
		Setup the HW regs, leaving the first page for the HW 
		backgroud object data
		*/
		SetupHWRegs(psDevInfo, MBX1_TA_EVM_PAGETBL_GRAN);

#if defined(SUPPORT_3D_BLIT)
		/* Initialise 3D blitting */
		DevInitBlitMBX(psDevData->psDevInfoKM, (PVR3DIF_BLITCTL **) &psDevInfo->sDeviceSpecific.s3D.h3DBlitCtl);
#endif
	}
	else
	{
		psParamBuffer = (PVR3DIF_PARAMBUFFER *)psDevice->hParamBuffer;
	}

	psDevice->ui32ParamBufferRefCount++;

	/* Require resource manager to track resource */
	if (ResManRegisterRes((	PRESMAN_ITEM)IMG_NULL, 
		                    RESMAN_TYPE_PARAMBUFF, 
							psDevData->psDevInfoKM,
							0, 
							DestroyParameterBufferCallBack, 
							RESMAN_AUTOFREE_LEV1) == IMG_NULL)
	{
		PVR_DPF((PVR_DBG_ERROR,"PVRSRVCreateParameterBuffer: Failed to register resource"));
		goto ErrorExit;
	}
	
	/* return success */
	return (PVRSRV_OK);
		
	/* handle failure case */
ErrorExit:
		
	/* free up anything that managed to get allocated.. */
	if (pvPageTableLinBase)
	{
		FreeStaticFBMem(psDevInfo, pvPageTableLinBase);
	}
		
	if (pvParamLinBase)
	{
		FreeStaticFBMem(psDevInfo, pvParamLinBase);
	}


#ifdef SUPPORT_POWER_STATE

	if(psParamBuffer->pvBGOPageShadow)
	{
		HostFreeMem(PVRSRV_HOST_NON_PAGEABLE_HEAP, psParamBuffer->pvBGOPageShadow);
	}

#endif
		
	if (psParamBuffer)
	{
		HostFreeMem(PVRSRV_HOST_NON_PAGEABLE_HEAP, psParamBuffer);	
	}
		
	return (eError);
}

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

 @Function	PVRSRVDestroyParameterBuffer
 

⌨️ 快捷键说明

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