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

📄 hostfunc.c

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

@Title			environment related functions

@Author			Imagination Technologies

@date   		23rd May 2002
 
@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	environment related functions

@DoxygenVer		

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

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

$Log: hostfunc.c $
*****************************************************************************/

#include <windows.h>
#include <ceddk.h>

#ifdef SUPPORT_PCI
	#include <giisr.h>		/* Generic ISR handler DLL interface */
	#include <devload.h>
#endif

#include "img_types.h"
#include "services_headers.h"

#include "jdisplaydefs.h"	/* FIXME: should include this here */
#include "mbx1defs.h"		/* FIXME: should include this here */
#include "heapman.h"


/* Display driver Settings */
#define POWERVR_REG_ROOT 	   			"Drivers\\Display\\PowerVR"
/* HAL Settings */
#define POWERVR_CHIP_KEY				"\\MBX1\\"
#define PVRHAL_REGSETTINGS_ROOT 		POWERVR_CHIP_KEY "HWSettings\\HAL"
#define PVRHAL_REGCOMMONAPPHINT_ROOT 	POWERVR_CHIP_KEY "Global\\D3D"
#define PVRHAL_REGAPPHINT_ROOT 			POWERVR_CHIP_KEY "Game Settings\\D3D\\"
#define PVRHAL_REGLASTAPP_ROOT			POWERVR_CHIP_KEY "LastApp\\"
#define PVRHAL_REGDDAPPHINT_ROOT 		POWERVR_CHIP_KEY "Game Settings\\DDraw\\"

#define IST_PRIORITY    20

/*!
 ************************************************************
 	IRQ translation buffer
 ***********************************************************/
typedef struct t_HAL_TRANSLATE_IRQ_BUFFER {

  ULONG ulInterruptNumber;/*!< interrupt number */
  ULONG ulInterruptVector;/*!< interrupt vector */

} HAL_TRANSLATE_IRQ_BUFFER;


IMG_UINT32 GetRegistryConfig (IMG_BOOL * bInstallIsr,     /* OUT - TRUE if ISR Handler found in registry */
								LPWSTR pszwIsrDll,      /* OUT - Name of ISR Handler dll */
								LPWSTR pszwIsrHandler);  /* OUT - Name of ISR Handler routine */
								
static PVRSRV_ERROR InitPCIInterrupts(SYS_DATA *psSysData, PVRSRV_DEV_INFO *psDevInfo);

#ifdef ADJUSTWRITECOMBINING


static PVRSRV_ERROR AddWCEntry(PVOID pvAddress,IMG_UINT32 ui32MapSize);
static PVRSRV_ERROR RemoveWCEntry(PVOID pvAddress);

static WRITE_COMBINED_MEM_TAG  	g_sWCList ={NULL,0,NULL};
static IMG_BOOL					g_bWriteCombining=FALSE;		// Don't by default as we will start up in refclock
#endif
static HANDLE hPageableHeap = NULL;

#ifdef LOCAL_MEMORY_SELF_REFRESH
extern void LockLocalMemoryFunction(void);
extern void UnLockLocalMemoryFunction(void);
#endif
/*----------------------------------------------------------------------------
	Public functions

 HostMapDeviceMemIntoUserSpace
 HostUnmapDeviceMemFromUserSpace
 HostCheckFreeBlock ???
 
 HostPageableByteAlloc
 HostPageableByteFree
 HostNonPageableByteAlloc
 HostNonPageableByteFree
 
 HostMapLinToCPUPhys
 HostGetCurrentProcessID
 
 HostAllocUserModeMem
 HostFreeUserModeMem
 
 HostMemSet
 HostMapPhysToLin
 HostUnMapPhysToLin
 
 HostCreateMutex
 HostDestroyMutex
 HostAcquireMutex
 HostReleaseMutex

------------------------------------------------------------------------------*/


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

 @Function		systemisr_wrapper
 
 @Description	wraps ISR
	
 @Input    psSysData - sys data

 @Return   none

******************************************************************************/
static void systemisr_wrapper(SYS_DATA *psSysData)
{
	PVRSRV_DEV_INFO *psDevInfo = psSysData->psDevInfoList;
	ENV_DATA *psEnvData = (ENV_DATA*)psSysData->pvEnvSpecificData;
	PVR_DPF((PVR_DBG_WARNING,"Inside system ISR, psSysData = 0x%x\n",psSysData));
	
	while(TRUE)
	{
		/*********************************************************************/
		
		WaitForSingleObject(psEnvData->hISRThreadEventHandle, INFINITE);

		SysGlobalDisableInterrupts();

		psDevInfo = psSysData->psDevInfoList;

		while(psDevInfo)
		{
			if(psDevInfo->pfnDeviceISR != NULL)
			{
				(*psDevInfo->pfnDeviceISR)(psDevInfo);		
			}
			psDevInfo = psDevInfo->psNext;
		}
		
		InterruptDone(psEnvData->ui32TransIRQ);

		SysGlobalEnableInterrupts();
	}
}


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

 @Function		InitInterrupts
 
 @Description	This function sets up the thread that will respond to hardware 
				interrupts, and configures the card to generate interrupts on the
				events we need.
	
 @Input    ui32Irq - sys data
 @Input    pszISRName
 @Input    pvData
 @Input    pfnSystemISR_Wrapper
 
 @Return   PVRSRV_ERROR

******************************************************************************/
static PVRSRV_ERROR InitInterrupts(IMG_UINT32 ui32Irq, 
									const IMG_CHAR *pszISRName, 
									IMG_PVOID pvData, 
									IMG_PVOID pfnSystemISR_Wrapper)
{
	PVRSRV_ERROR eError = PVRSRV_OK;
	SYS_DATA *psSysData = (SYS_DATA *)pvData;
	ENV_DATA *psEnvData = (ENV_DATA*)psSysData->pvEnvSpecificData;
	/* FIXME: just use the first device for now */
	PVRSRV_DEV_INFO *psDevInfo = psSysData->psDevInfoList;

#ifdef SUPPORT_PCI
		eError = InitPCIInterrupts(psSysData, psDevInfo);
#else
		psEnvData->ui32TransIRQ  = ui32Irq;
#endif
	
	/* Do Platform interrupt specific intialisation */
	if(eError != PVRSRV_OK)
	{
		PVR_DPF((PVR_DBG_ERROR,"InitializeInterrupts: Platform Specific Thread Initialisation Failed."));
		return eError;
	}

	/* Create IST management event objects */
	
	if((psEnvData->hISRThreadEventHandle = CreateEvent(NULL, FALSE, FALSE, NULL)) == NULL)
	{
		PVR_DPF((PVR_DBG_ERROR,"InitializeInterrupts: Unable to create event for IST."));
		return PVRSRV_ERROR_GENERIC;
	}

	/*
		Initialise Interrupt (system function)
		Converts event to interrupt event, enables interrupt. 
		Must happen before IST created/started.
	*/
	if(InterruptInitialize(psEnvData->ui32TransIRQ, psEnvData->hISRThreadEventHandle, NULL, 0) == FALSE)
	{
		PVR_DPF((PVR_DBG_ERROR,"InitializeInterrupts: Unable to initialise interrupt."));
		return PVRSRV_ERROR_GENERIC;
	}

	/* Create and start IST */
	if((psEnvData->hISTThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)pfnSystemISR_Wrapper,psSysData,0,NULL)) == NULL)
	{
		PVR_DPF((PVR_DBG_ERROR,"InitializeInterrupts: Unable to create thread for IST."));
		return(FALSE);
	}

	/* This causes IST to run & block on the IstEvent, waiting for first interrupt. */
	CeSetThreadPriority(psEnvData->hISTThread, IST_PRIORITY);

	return eError;
}



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

 @Function		DeInitInterrupts
 
 @Description	This function sets up the thread that will respond to hardware 
				interrupts, and configures the card to generate interrupts on the
				events we need.
	
 @Input    pvData
 
 @Return   PVRSRV_ERROR

******************************************************************************/
static PVRSRV_ERROR DeInitInterrupts (IMG_PVOID pvData)
{
	SYS_DATA *psSysData = (SYS_DATA *)pvData;
	ENV_DATA *psEnvData = (ENV_DATA*)psSysData->pvEnvSpecificData;
	PVRSRV_ERROR eError = PVRSRV_OK;

#ifdef SUPPORT_PCI
	if (!FreeIntChainHandler(psEnvData->hISRHandle))
	{
		PVR_DPF((PVR_DBG_ERROR,"DeInitInterrupts: Couldn't uninstall ISR handler."));
		eError = PVRSRV_ERROR_GENERIC;		
	}
#endif /* SUPPORT_PCI */

	if (TerminateThread(psEnvData->hISTThread, 0) == 0)
	{
		PVR_DPF((PVR_DBG_ERROR,"DeInitInterrupts: Unable to terminate IST thread."));
		eError = PVRSRV_ERROR_GENERIC;
	}

	if (CloseHandle(psEnvData->hISRThreadEventHandle) == 0)
	{
		PVR_DPF((PVR_DBG_ERROR,"DeInitInterrupts: Unable to close event for IST."));
		eError = PVRSRV_ERROR_GENERIC;
	}

	if (CloseHandle(psEnvData->hISTThread) == 0)
	{
		PVR_DPF((PVR_DBG_ERROR,"DeInitInterrupts: Unable to close event for IST."));
		eError = PVRSRV_ERROR_GENERIC;
	}

	return eError;
}

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

 @Function		HostInstallISR
 
 @Description	Installs an ISR
	
 @Input    ui32Irq - IRQ number
 @Input    pszISRName - ISR name
 @Input    pvData - pointer to pass
 @Input    bIsSystemISR - 

 @Return   error status 

******************************************************************************/
PVRSRV_ERROR HostInstallISR(IMG_UINT32 ui32Irq, const IMG_CHAR *pszISRName, IMG_VOID *pvData, IMG_BOOL bIsSystemISR)
{
	PVRSRV_ERROR eError;
	
	eError = InitInterrupts(ui32Irq, pszISRName, pvData, systemisr_wrapper);
	if(eError != PVRSRV_OK)
	{
		PVR_DPF((PVR_DBG_ERROR,"Couldn't install system ISR on IRQ %d\n",ui32Irq));
		return PVRSRV_ERROR_GENERIC;
	}	

	return PVRSRV_OK;
}

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

 @Function		HostUnInstallISR
 
 @Description	uninstalls an ISR
	
 @Input    ui32Irq - IRQ number
 @Input    pvData - pointer to pass

 @Return   error status 

******************************************************************************/
PVRSRV_ERROR HostUnInstallISR(IMG_UINT32 ui32Irq, IMG_VOID *pvData)
{
	PVRSRV_ERROR eError;

	PVR_DPF((PVR_DBG_WARNING,"Uninstalling ISR on IRQ %d with cookie %x\n",ui32Irq,pvData));

	eError = DeInitInterrupts(pvData);
	if(eError != PVRSRV_OK)
	{
		PVR_DPF((PVR_DBG_ERROR,"Couldn't install system ISR on IRQ %d\n",ui32Irq));
		return PVRSRV_ERROR_GENERIC;
	}	

	return PVRSRV_OK;
}


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

 @Function		HostMemCopy
 
 @Description	Copies memory around
	
 @Input    pvDst - pointer to dst
 @Output   pvSrc - pointer to src
 @Input    ui32Size - bytes to copy

 @Return  none

******************************************************************************/
IMG_VOID HostMemCopy(IMG_VOID *pvDst, IMG_VOID *pvSrc, IMG_UINT32 ui32Size)
{
	memcpy(pvDst, pvSrc, ui32Size);
}


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

 @Function		HostGetPageSize
 
 @Description	gets page size
	
 @Return   		page size

******************************************************************************/
IMG_UINT32 HostGetPageSize(IMG_VOID)
{
	return PAGE_SIZE;
}


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

 @Function		HostUnmapFrmBufMemFromUserSpace
 
 @Description	Unmaps region of frame buffer memory from the user memory address
               : range that was allocated with HostMapFrmBufMemIntoUserSpace
	
 @Input			ui32DevCookie
 @Input			pvUserAddr
 @Input			ui32MappingSize
 @Input			pvProcess
 
 @Return   		none

******************************************************************************/
IMG_VOID HostUnmapFrmBufMemFromUserSpace (IMG_UINT32 ui32DevCookie, 
										  IMG_VOID *pvUserAddr, 
										  IMG_UINT32 ui32MappingSize,
										  IMG_VOID *pvProcess)
{
	UNREFERENCED_PARAMETER (ui32DevCookie);
	UNREFERENCED_PARAMETER (pvProcess);

	HostUnMapPhysToLin(pvUserAddr, ui32MappingSize);
	return;
}



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

 @Function		HostCheckFreeBlock
 
 @Description	Check the given free block of memory has been corrupted
               : This is done by checking that evey byte of the buffer is 0xE2
	
 @Input			pvStart
 @Input			ui32Size
 
 @Return   		

******************************************************************************/
IMG_UINT32 HostCheckFreeBlock(IMG_VOID *pvStart, IMG_UINT32 ui32Size)
{
	#if 0
	IMG_UINT32	dwRet=0;
	IMG_UINT32	dwDWORDCo=ui32Size/4;

	if (ui32Size == 0)
	{
		return (0);
	}

	__asm
	{
		mov		edi, pvStart
		mov		ecx, dwDWORDCo
		mov		eax, DBG_MEMORY_DEALLOC_INITIALIZER + (DBG_MEMORY_DEALLOC_INITIALIZER << 8) + (DBG_MEMORY_DEALLOC_INITIALIZER << 16) + (DBG_MEMORY_DEALLOC_INITIALIZER << 24)
		repe	scasd
		jz		BlockOk
		mov		ecx, edi
		sub		ecx, 4
BlockOk:
		mov		dwRet, ecx
	}
	return (dwRet);
	#else
	UNREFERENCED_PARAMETER (pvStart);
	UNREFERENCED_PARAMETER (ui32Size);
	return 0;
	#endif
}


⌨️ 快捷键说明

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