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

📄 halservcalls.c

📁 Lido PXA270平台开发板的最新BSP,包括源代码
💻 C
字号:
/******************************************************************************
<module>
* Name         : halservcalls.c
* Title        : services calls wrappers
* Author(s)    : Imagination Technologies
* Created      : 26 May 2004
*
* Copyright    : 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.
*
* Description  : services calls wrappers
*
* Platform     : Windows CE
*
 $Log: halservcalls.c $
********************************************************************************/
#include "ddraw_headers.h"

/*****************************************************************************
<function>
 FUNCTION	:	PVRHALAllocDeviceMem	
    
 PURPOSE	:	Pass through function, ensuring any processes obtaining device 
				mem are connected to the resource manager

 RETURNS	:	PVRSRV_ERROR
<function/>
*****************************************************************************/

PVRSRV_ERROR PVRHALAllocDeviceMem (PVRSRV_DEV_DATA	*psDevData,
								   IMG_UINT32		ui32Flags,
								   IMG_UINT32		ui32Size,
								   IMG_UINT32		ui32Alignment,
								   PVRSRV_MEM_INFO  **ppsMemInfo)
{
	PVRHALConnectResMan(FALSE, TRUE);

	return PVRSRVAllocDeviceMem(psDevData,
								ui32Flags | PVRSRV_MEMFLG_SAVERESTORE, 
								ui32Size, 
								ui32Alignment, 
								ppsMemInfo);
}

/*****************************************************************************
<function>
 FUNCTION	:	PVRHALFreeDeviceMem	
    
 PURPOSE	:	Pass through function, ensuring any processes releasing device 
				mem are disconnected from the resource manager at the appropriate 
				time

 RETURNS	:	PVRSRV_ERROR
<function/>
*****************************************************************************/

PVRSRV_ERROR PVRHALFreeDeviceMem (PVRSRV_DEV_DATA *psDevData,
								  PVRSRV_MEM_INFO *psMemInfo)
{
	PVRSRV_ERROR	eError;

	eError = PVRSRVFreeDeviceMem(psDevData, psMemInfo);
	PVRHALConnectResMan(FALSE, FALSE);
	return eError;
}

/*****************************************************************************
<function>
 FUNCTION	:	PVRHALConnectResMan	
    
 PURPOSE	:	The aim of this function is to manage connections to the
				resource manager. Each calling process should only ever
				have a single connection, so that if a process is blown away
				the Resource manager can de-allocate it's resources. To do this 
				we reference count calls to connect by each process. The exception
				to this is the Process which inialises the Hal (see below).

 PARAMETERS	:	bInitial	-	Denotes Hal initialisation
				bConnect	-	Denotes connection\disconnection
 RETURNS	:	None
<function/>
*****************************************************************************/
VOID PVRHALConnectResMan(BOOL bInitial, BOOL bConnect)
{
	HANDLE				hProcID;
	RESMAN_CONNECTION*	psRMConnection;
	
	hProcID			= GetOwnerProcess();

	if(bInitial)
	{
		if(bConnect)
		{
	
			/*
				Connect HAL to resource manager. We connect twice because the owner process
				may die before the Hal is destroyed, and Resman would automatically release
				our resources. Adding an extra reference guards against this case.
			*/
			PVR_DPF((PVR_DBG_MESSAGE,"HAL Connecting to Res man - process ID %u", hProcID));

			psRMConnection = (RESMAN_CONNECTION*) AllocSharedMem(sizeof(RESMAN_CONNECTION));

			psRMConnection->hProcID			= hProcID;
			psRMConnection->dwConnected		+= 2;
			psRMConnection->psNext			= NULL;

			/*
				Perform the connections
			*/
			PVRSRVResManConnect((IMG_UINT32) psRMConnection->hProcID, TRUE);
			PVRSRVResManConnect((IMG_UINT32) psRMConnection->hProcID, TRUE);
			gpsDriverData->psResManConnections = psRMConnection;
		}
		else
		{
			/*
				We need to free the first connection in the list, as this is the HAL
				Connection.  Current hProcID may be invalid at this point as the original process
				that initalised the hal may not exist.
			*/
			PVR_DPF((PVR_DBG_MESSAGE,"HAL DISConnecting from Res man - process ID %u", gpsDriverData->psResManConnections->hProcID));

			ASSERT(gpsDriverData->psResManConnections->psNext == NULL);

			PVRSRVResManConnect((IMG_UINT32) gpsDriverData->psResManConnections->hProcID, FALSE);
			PVRSRVResManConnect((IMG_UINT32) gpsDriverData->psResManConnections->hProcID, FALSE);

			FreeSharedMem(gpsDriverData->psResManConnections);
			gpsDriverData->psResManConnections = NULL;
		}
	}
	else
	{
		RESMAN_CONNECTION*	psRMPrevConnection = NULL;
		/*
			Find matching connection struct
		*/
		psRMPrevConnection = psRMConnection = gpsDriverData->psResManConnections;
		while(psRMConnection)
		{
			if(psRMConnection->hProcID == hProcID) break;
			psRMPrevConnection = psRMConnection;
			psRMConnection = psRMConnection->psNext;
		}

		if(bConnect)
		{
			if(psRMConnection == NULL)
			{
				/*
					New connection
				*/
				ASSERT(psRMPrevConnection != NULL);
				
				psRMConnection = (RESMAN_CONNECTION*) AllocSharedMem(sizeof(RESMAN_CONNECTION));

				psRMConnection->dwConnected = 1;
				psRMConnection->hProcID		= hProcID;
				psRMConnection->psNext		= NULL;

				PVRSRVResManConnect((IMG_UINT32) psRMConnection->hProcID, TRUE);

				psRMPrevConnection->psNext = psRMConnection;
			}
			else
			{
				psRMConnection->dwConnected++;
			}

			PVR_DPF((PVR_DBG_MESSAGE,"Resource Connecting to Res man - process ID %u - connection count - %u", hProcID, psRMConnection->dwConnected));
		}
		else
		{
			if(psRMConnection == NULL)
			{	
				DPF("PVRHALConnectResMan: Can't disconnect an unconnected process");
				return;
			}
			else
			{
				PVR_DPF((PVR_DBG_MESSAGE,"Resource Disconnecting from Res man - process ID %u - connection count - %u", hProcID, psRMConnection->dwConnected-1));
				if(--psRMConnection->dwConnected == 0)
				{
					PVRSRVResManConnect((IMG_UINT32) psRMConnection->hProcID, FALSE);
					psRMPrevConnection->psNext = psRMConnection->psNext;
					FreeSharedMem(psRMConnection);
				}
			}
		}
	}
}
/*****************************************************************************
  End of file (halservcalls.c)
*****************************************************************************/

⌨️ 快捷键说明

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