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

📄 mpegcommon.c

📁 Lido PXA270平台开发板的最新BSP,包括源代码
💻 C
字号:
/*******************************************************************************
* Name         : mpegcommon.c
* Title        : Device specific routines
* Author       : Dave Bartlett
* Created      : 18 / 10 /03
*
* 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.
*
* Description  : Device specific functions
*
* Platform     : Generic
*
*******************************************************************************/

#include "services_headers.h"
#include "sharedutils.h"
#include "m24va.h"

/*----------------------------------------------------------------------------
<function>
    FUNCTION   : InitMpegDeviceInfo
    PURPOSE    : Allocates and sets up the display device devinfo
    PARAMETERS : PPVRSRV_DEV psDevInfo
    			 PVRSRV_DEVICE_IDENTIFIER *psDevId)
    RETURNS    : IMG_ERROR
</function>
------------------------------------------------------------------------------*/
PVRSRV_ERROR InitMpegDeviceInfo(PVRSRV_DEV_INFO **ppsDevInfo, 
								PVRSRV_DEVICE_IDENTIFIER *psDevId)
{
	PVRSRV_ERROR		eError = PVRSRV_OK;
	PVRSRV_DEV_INFO		*psDevInfo;
	DEVICEMPEG			*psDevice;
	PVRSRV_DEV_LOCATION *psDevLocation;
	IMG_VOID			*pvLinBase;

	/******************************************** Allocate device control block */

	if(HostAllocMem( PVRSRV_HOST_NON_PAGEABLE_HEAP, 
					 sizeof(PVRSRV_DEV_INFO), 
					 (IMG_VOID **)&psDevInfo, 0) != PVRSRV_OK)	
	{
		PVR_DPF((PVR_DBG_ERROR,"InitMpegDeviceInfo : Failed to alloc memory for DevInfo"));
		return (PVRSRV_ERROR_OUT_OF_MEMORY);
	}

	HostMemSet(psDevInfo, 0, sizeof(PVRSRV_DEV_INFO));
	
	/* copy psDevId into new psDevInfo */
	psDevInfo->sDevId = *psDevId;
	psDevice = &psDevInfo->sDeviceSpecific.sMpeg;
	
	/************************************************ Create Device mutex's */

	eError = HostCreateResource(&psDevice->hDeviceResource);

	if(eError != PVRSRV_OK)
	{
		PVR_DPF((PVR_DBG_ERROR,"InitMpegDeviceInfo: Failed to create mutex !"));

		return(PVRSRV_ERROR_INIT_FAILURE);
	}

	/***************************************************** Map in registers */

	SysFindLocation(psDevInfo);
		
	psDevLocation = &psDevInfo->sDevLocation;		/* save pointer de-refs */
	
	/* Map Regs */
	pvLinBase = HostMapPhysToLin(ENV_SysPAddrToCpuPAddr(psDevLocation->sRegsPhysBase),
								 psDevLocation->ui32RegSize,
								 CACHETYPE_UNCACHED | EXTRA_CACHETYPE_SHARED);

	if(pvLinBase == (IMG_CPU_VIRTADDR)0)
	{
		PVR_DPF((PVR_DBG_ERROR,"InitMpegDeviceInfo : Failed to map in regs\n"));
		return PVRSRV_ERROR_BAD_MAPPING;
	}
	psDevLocation->pvRegsBaseKM = pvLinBase;


	/**************************************************** Map in slave ports */

	pvLinBase = HostMapPhysToLin(psDevLocation->sDeviceSpecific.sM24VA.sSPPhysicalBase,
								 psDevLocation->sDeviceSpecific.sM24VA.ui32SPSize,
								 CACHETYPE_WRITECOMBINED | EXTRA_CACHETYPE_SHARED);
	if (pvLinBase == (IMG_CPU_VIRTADDR)0)
	{
		PVR_DPF((PVR_DBG_ERROR,"InitDisplayDeviceInfo : Failed to map in FB memory"));
		return PVRSRV_ERROR_BAD_MAPPING;
	}

	psDevLocation->sDeviceSpecific.sM24VA.pvSPLinearBase = pvLinBase;
	psDevLocation->sDeviceSpecific.sM24VA.pvSPCmd		 = (IMG_UINT32*)((IMG_UINT32)pvLinBase + M24VA_SP_CMD_OFFSET);
	psDevLocation->sDeviceSpecific.sM24VA.pvSPIDCT		 = (IMG_UINT32*)((IMG_UINT32)pvLinBase + M24VA_SP_IDCT_OFFSET);
	
#ifdef SUPPORT_POWER_STATE
	psDevInfo->pfnSetPowerState 		= DevPowerStateM24VA;
#endif			

	/* return the new devinfo */
	*ppsDevInfo = psDevInfo;

	return(eError);
}

/*----------------------------------------------------------------------------
<function>
    FUNCTION   : DeInitMpegDeviceInfo
    PURPOSE    : DeAllocates devinfo and associated sub structures
    PARAMETERS : PPVRSRV_DEV psDevInfo
    RETURNS    : IMG_ERROR
</function>
------------------------------------------------------------------------------*/
PVRSRV_ERROR DeInitMpegDeviceInfo(PVRSRV_DEV_INFO *psDevInfo)
{
	PVRSRV_DEV_LOCATION *psDevLocation	= &psDevInfo->sDevLocation;
	PVRSRV_ERROR		eError			= PVRSRV_OK;

	eError = HostDestroyResource(&psDevInfo->sDeviceSpecific.sMpeg.hDeviceResource);
	if (eError != PVRSRV_OK)
	{
		return eError;
	}

	/* UnMap Regs */
	HostUnMapPhysToLin(psDevLocation->pvRegsBaseKM, psDevLocation->ui32RegSize);

	/* Unmap slave ports */
	HostUnMapPhysToLin(psDevLocation->sDeviceSpecific.sM24VA.pvSPLinearBase, 
					   psDevLocation->sDeviceSpecific.sM24VA.ui32SPSize);
	
	/* DeAllocate devinfo */
	HostFreeMem(PVRSRV_HOST_NON_PAGEABLE_HEAP, psDevInfo);
	
	return(eError);
}

/*----------------------------------------------------------------------------
<function>
    FUNCTION   : EnableDisplayDevice
    PURPOSE    : Enables a display device
    PARAMETERS : PPVRSRV_DEV psDevInfo
    RETURNS    : IMG_ERROR
</function>
------------------------------------------------------------------------------*/
PVRSRV_ERROR EnableMpegDevice(PVRSRV_DEV_INFO *psDevInfo)
{
	PVRSRV_ERROR	eError = PVRSRV_OK;

	/* let's boot the device! */
	if(psDevInfo->pfnInitDevice)
	{
		eError = psDevInfo->pfnInitDevice(psDevInfo);
	}

	return(eError);
}

/*----------------------------------------------------------------------------
<function>
    FUNCTION   : DisableMpegDevice
    PURPOSE    : Disables a Display device
    PARAMETERS : PPVRSRV_DEV psDevInfo
    RETURNS    : IMG_ERROR
</function>
------------------------------------------------------------------------------*/
PVRSRV_ERROR DisableMpegDevice(PVRSRV_DEV_INFO *psDevInfo)
{
	PVRSRV_ERROR	eError = PVRSRV_OK;
	
	/* let's disable the device! */
	if(psDevInfo->pfnDeInitDevice)
	{
		eError = psDevInfo->pfnDeInitDevice(psDevInfo);
	}

	return(eError);
}


#ifdef SUPPORT_POWER_STATE
/*!
******************************************************************************

 @Function	DevPowerStateMPEG
 
 @Description 
 
 does necessary preparation before power state transition
 
 @Input	   psDevInfo : 

 @Input	   ePVRState : 

 @Input	   ui32Flags : 

 @Return   none :

******************************************************************************/
PVRSRV_ERROR  DevPowerStateM24VA(PVRSRV_DEV_INFO *psDevInfo, PVR_POWER_STATE ePVRState, IMG_UINT32 ui32Flags)
{
	PVRSRV_ERROR		eError;
	SYS_DATA			*psSysData;
	DEVICEMPEG			*psMPEG = &psDevInfo->sDeviceSpecific.sMpeg;
	IMG_PVOID			 pvRegsBase = psDevInfo->sDevLocation.pvRegsBaseKM;
	
	if(SysAcquireData(&psSysData) != PVRSRV_OK)
	{
		return PVRSRV_ERROR_GENERIC;
	}

	/* we want to acquire the mutex on the pre state of anything except coming out of D3
	
	and we want to release it on the post of anything except going into D3
	*/
	
	if(ui32Flags == (PVRSRV_SEVERE_LOSS_OF_CONTEXT | PVRSRV_PRE_STATE_CHANGE_MASK))		  /*Pre state change */
	{	
	    if((ePVRState != psDevInfo->ePowerState) && (psDevInfo->ePowerState!=PVRSRV_POWER_STATE_D3 ))
		{
			/******************************************************** Going down */

			/* If we are in a D3 state then everything is idle or disabled */
			if(psDevInfo->ePowerState == PVRSRV_POWER_STATE_D3)
			{
				return PVRSRV_ERROR_GENERIC;
			}

			/* Acquire MPEG h/w to stop any subsequent accesses */
			eError = HostLockResource(&psMPEG->hDeviceResource, IMG_TRUE);
			if (eError != PVRSRV_OK)
			{
				return eError;
			}
			
			/* Wait for 1ms for device to become idle */	
			HostWaitus(MAX_HW_TIME_US);
		}
	}
	else if((ui32Flags & PVRSRV_PRE_STATE_CHANGE_MASK) == 0)	  /*Post state change */
	{
		if((ePVRState != psDevInfo->ePowerState) && (ePVRState != PVRSRV_POWER_STATE_D3))
		{
		/******************************************************** Going up */


			/* Power state transition complete, release MPEG */
			eError = HostUnlockResource(&psMPEG->hDeviceResource);
			if (eError != PVRSRV_OK)
			{
				return eError;
			}
		}
		/* Update our power state. */
		psDevInfo->ePowerState=ePVRState;

	}

	return PVRSRV_OK;
}

#endif

⌨️ 快捷键说明

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