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

📄 tmif.c

📁 PNX系列设备驱动 PNX系列设备驱动
💻 C
📖 第 1 页 / 共 3 页
字号:
/*---------------------------------------------------------------------------- 
COPYRIGHT (c) 1997 by Philips Semiconductors

THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED AND COPIED IN 
ACCORDANCE WITH THE TERMS AND CONDITIONS OF SUCH A LICENSE AND WITH THE 
INCLUSION OF THE THIS COPY RIGHT NOTICE. THIS SOFTWARE OR ANY OTHER COPIES 
OF THIS SOFTWARE MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER
PERSON. THE OWNERSHIP AND TITLE OF THIS SOFTWARE IS NOT TRANSFERRED. 

THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT ANY PRIOR NOTICE
AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY Philips Semiconductor. 

PHILIPS ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF THIS SOFTWARE
ON PLATFORMS OTHER THAN THE ONE ON WHICH THIS SOFTWARE IS FURNISHED.
----------------------------------------------------------------------------*/

//////////////////////////////////////////////////////////////////////////////
//	HISTORY
//
//	960405	Tilakraj Roy 	Created
//	960710	Tilakraj Roy	Started adding code for tmman inteface 
//	961008	Tilakraj Roy	Added code for shared memory allocaiton interfaces.
//	961010	Tilakraj Roy	Added code for image loading, running & stopping
//	970806	Tilakraj Roy	Ported to Workstation V4.0
//
//////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
//				SYSTEM INCLUDE FILES
//////////////////////////////////////////////////////////////////////////////

#if (defined TMMAN_WINNT) || ( defined TMMAN_WIN98 )
#include "ntddk.h"
#endif

//////////////////////////////////////////////////////////////////////////////
//				DRIVER INCLUDE FILES
//////////////////////////////////////////////////////////////////////////////

#include "tmmanapi.h"
#include "tmmanlib.h"
#include "platform.h"
#include "verinfo.h"
#include "tmif.h"

//////////////////////////////////////////////////////////////////////////////
//				MANIFEST CONSTANTS
//////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
//				TYPEDEFS
//////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
//				PROTOTYPES
//////////////////////////////////////////////////////////////////////////////

TMStatus	tmmanKernelModeNegotiateVersion ( tmmanVersion* Version );

//////////////////////////////////////////////////////////////////////////////
//				IMPLEMENTATION
//////////////////////////////////////////////////////////////////////////////

NTSTATUS tmmanOpen(
    IN PDEVICE_OBJECT pdo,
    IN PIRP Irp )
{
	NTSTATUS			NTStatus;
	UInt32				ClientIdx, DeviceIdx;
	ClientObject*		Client;
	PVOID			Process;

	Process = PsGetCurrentProcess();
	
	DPF(1,("tmman:tmmanOpen:Process[%x]:\n", Process ));

	// search for an empty slot.
	DPF(1,("tmman:tmmanOpen:ClientList:"));
	for ( ClientIdx = 0 ; ClientIdx < TMManGlobal->MaximumClients ; ClientIdx ++ )
	{
		if ( TMManGlobal->ClientList[ClientIdx] )
		{
			DPF(1,("[#%x:%x]", 
				ClientIdx, ((ClientObject*)TMManGlobal->ClientList[ClientIdx])->Process ));
			continue;
		}
		else
		{
			break;
		}
	}

	DPF(1,("\n"));

	if ( ClientIdx == TMManGlobal->MaximumClients )
	{
		DPF(0,("tmman:tmmanOpen:NoMoreClientsFree\n"));
		goto tmmanOpenExit1;
	}
		
	TMManGlobal->ClientList[ClientIdx] = memAllocate (  
		sizeof ( ClientObject ) + sizeof ( ClientDeviceObject ) * ( TMManGlobal->DeviceCount - 1 ) ); 

	if ( TMManGlobal->ClientList[ClientIdx] == Null )
	{
		DPF(0,("tmman:tmmanOpen:memAllocate:FAIL\n"));
		goto tmmanOpenExit1;	
	}
	
	Client = TMManGlobal->ClientList[ClientIdx];
	Client->Process = Process;
	Client->DeviceCount = TMManGlobal->DeviceCount;

	// initialize the per device data structures
	// BUGCHECK - we have to go by Client->DeviceCount since devices could have
	// gone away Workstation 5.0 problem.
	for ( DeviceIdx = 0 ; DeviceIdx < TMManGlobal->DeviceCount ; DeviceIdx++ )
	{
		TMManDeviceObject* TMManDevice = TMManGlobal->DeviceList[DeviceIdx];
		UInt32	Dummy, Length;
		UInt32	AddrKernel;
		
		Client->Device[DeviceIdx].Device = TMManDevice;

		halGetMMIOInfo (
			TMManDevice->HalHandle,
			(Pointer*)&Dummy,
			(Pointer*)&AddrKernel,
			&Length );

		// map mmio so that it can be acessed from user mode
		 if ( ( Client->Device[DeviceIdx].MMIOAddrUser = 
			sectionMapPhysicalAddress ( 
			AddrKernel, 
			Length,
			&Client->Device[DeviceIdx].MMIOHandleUser ) ) == NULL )
		{
			DPF(0,("tmman:tmmanOpen:sectionMapPhysicalAddress:MMIO:FAIL\n" ));
			goto	tmmanOpenExit2;
		}

		if ( TMManGlobal->MapSDRAM )
		{
			// if MapSDRAM is turned ON then MmMapMMIOSpace would have
			// been called already
			halGetSDRAMInfo (
				TMManDevice->HalHandle,
				(Pointer*)&Dummy,
				(Pointer*)&AddrKernel,
				&Length );

			if ( ( Client->Device[DeviceIdx].SDRAMAddrUser = 
				sectionMapPhysicalAddress ( 
				AddrKernel, 
				Length,
				&Client->Device[DeviceIdx].SDRAMHandleUser ) ) == NULL )
			{
				DPF(0,("tmman:tmmanOpen:sectionMapPhysicalAddress:SDRAM:FAIL\n" ));

				sectionUnmapPhysicalAddress ( 
					Client->Device[DeviceIdx].MMIOAddrUser,
					Client->Device[DeviceIdx].MMIOHandleUser );

				goto	tmmanOpenExit2;
			}
		}

		if ( ( Client->Device[DeviceIdx].MemoryAddrUser = 
			sectionMapPhysicalAddress ( 
			(UInt32)TMManDevice->MemoryBlock, 
			TMManDevice->MemoryBlockSize,
			&Client->Device[DeviceIdx].MemoryHandleUser ) ) == NULL )
		{
			DPF(0,("tmman:tmmanOpen:sectionMapPhysicalAddress:MEMORY:FAIL\n" ));

			if ( TMManGlobal->MapSDRAM )
			{
			
				sectionUnmapPhysicalAddress ( 
					Client->Device[DeviceIdx].SDRAMAddrUser,
					Client->Device[DeviceIdx].SDRAMHandleUser );
			}

			sectionUnmapPhysicalAddress ( 
				Client->Device[DeviceIdx].MMIOAddrUser,
				Client->Device[DeviceIdx].MMIOHandleUser );
			goto	tmmanOpenExit2;
		}

	}

	TMManGlobal->ClientCount++;
	
	Irp->IoStatus.Information = 0;
	Irp->IoStatus.Status = STATUS_SUCCESS;
	IoCompleteRequest (Irp, IO_NO_INCREMENT);
	return STATUS_SUCCESS;

tmmanOpenExit2:

	for ( /* use the current DeviceIdx */ ; DeviceIdx > 0 ; DeviceIdx-- )
	{
		sectionUnmapPhysicalAddress ( 
			Client->Device[DeviceIdx - 1].MemoryAddrUser,
			Client->Device[DeviceIdx - 1].MemoryHandleUser );

		if ( TMManGlobal->MapSDRAM )
		{

			sectionUnmapPhysicalAddress ( 
				Client->Device[DeviceIdx - 1].SDRAMAddrUser,
				Client->Device[DeviceIdx - 1].SDRAMHandleUser );
		}

		sectionUnmapPhysicalAddress ( 
			Client->Device[DeviceIdx - 1].MMIOAddrUser,
			Client->Device[DeviceIdx - 1].MMIOHandleUser );
	}

	memFree ( TMManGlobal->ClientList[ClientIdx] );

tmmanOpenExit1:
#if (defined TMMAN_WINNT) || ( defined TMMAN_WIN98 )
	Irp->IoStatus.Information = 0;
	Irp->IoStatus.Status = STATUS_DEVICE_BUSY;
	IoCompleteRequest (Irp, IO_NO_INCREMENT);
	return STATUS_DEVICE_BUSY;
#endif

}

NTSTATUS tmmanClose(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp )
{
	UInt32				ClientIdx, DeviceIdx;
	ClientObject*		Client;
	PVOID			Process;

	Process = PsGetCurrentProcess();
	
	DPF(1,("tmman:tmmanClose:Process[%x]\n", Process ));

	for ( ClientIdx = 0 ; ClientIdx < TMManGlobal->MaximumClients ; ClientIdx ++ )
	{
		if ( !TMManGlobal->ClientList[ClientIdx] )
			continue;

		if ( ((ClientObject*)TMManGlobal->ClientList[ClientIdx])->Process != Process )
			continue;
		break;
	}

	if ( ClientIdx == TMManGlobal->MaximumClients )
	{
		DPF(0,("tmman:tmmanClose:PANIC:InvalidHandle:Process[%x]\n", Process ));
		goto tmmanCloseExit1;
	}
	// assume one open handle per process context		
	// if we have more than slot of a single process than
	// we are smoking something we are not supposed to
	// since tmman32.dll is the only one who calls CreateProcess
	// during ATTACH_PROCESS
	
	Client = TMManGlobal->ClientList[ClientIdx];

	

	// initialize the per device data structures
	// BUGCHECK - we have to go by Client->DeviceCount 
	for ( DeviceIdx = 0 ; DeviceIdx < TMManGlobal->DeviceCount ; DeviceIdx++ )
	{
		TMManDeviceObject* TMManDevice = TMManGlobal->DeviceList[DeviceIdx];

		memoryManagerDestroyMemoryByClient (
			TMManDevice->MemoryManagerHandle, 
			(UInt32)Process );

		messageManagerDestroyMessageByClient (
			TMManDevice->MessageManagerHandle, 
			(UInt32)Process );

		eventManagerDestroyEventByClient (
			TMManDevice->EventManagerHandle, 
			(UInt32)Process );

		sgbufferManagerDestroySGBufferByClient (
			TMManDevice->SGBufferManagerHandle, 
			(UInt32)Process );

		sectionUnmapPhysicalAddress ( 
			Client->Device[DeviceIdx].MMIOAddrUser, 
			Client->Device[DeviceIdx].MMIOHandleUser );
		if ( TMManGlobal->MapSDRAM )
		{

			sectionUnmapPhysicalAddress ( 
				Client->Device[DeviceIdx].SDRAMAddrUser,
				Client->Device[DeviceIdx].SDRAMHandleUser );
		}

		sectionUnmapPhysicalAddress ( 
			Client->Device[DeviceIdx].MemoryAddrUser,
			Client->Device[DeviceIdx].MemoryHandleUser );
		
	
	}

	memFree ( TMManGlobal->ClientList[ClientIdx] );

	TMManGlobal->ClientList[ClientIdx] = NULL;
	
	TMManGlobal->ClientCount--;
#if (defined TMMAN_WINNT) || ( defined TMMAN_WIN98 )
	Irp->IoStatus.Information = 0;
	Irp->IoStatus.Status = STATUS_SUCCESS;
	IoCompleteRequest (Irp, IO_NO_INCREMENT);
	return STATUS_SUCCESS;
#endif

tmmanCloseExit1:
#if (defined TMMAN_WINNT) || ( defined TMMAN_WIN98 )
	Irp->IoStatus.Information = 0;
	Irp->IoStatus.Status = STATUS_DEVICE_BUSY;
	IoCompleteRequest (Irp, IO_NO_INCREMENT);
	return STATUS_DEVICE_BUSY;
#endif

}

NTSTATUS tmmanDeviceControl(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp )
{
#if (defined TMMAN_WINNT) || ( defined TMMAN_WIN98 )
    NTSTATUS Status;
	PIO_STACK_LOCATION  IOStackLocation;
	PVOID	IOParameters = Irp->AssociatedIrp.SystemBuffer;
	ULONG	ReturnInformation = 0;
 
    
	IOStackLocation = IoGetCurrentIrpStackLocation ( Irp );
#endif

    // assume that IO Manager will be calling us only with IRP_MJ_DEVICE_CONTROL

#if (defined TMMAN_WINNT) || ( defined TMMAN_WIN98 )
	switch ( IOStackLocation->Parameters.DeviceIoControl.IoControlCode )
#endif
	{

		case constIOCTLtmmanNegotiateVersion : // vxd callable
		{
			tmifNegotiateVersion* TMIF = 	
				(tmifNegotiateVersion*)IOParameters;

			TMIF->Status = tmmanKernelModeNegotiateVersion ( &TMIF->Version );
			ReturnInformation = sizeof ( tmifNegotiateVersion );
		}
		break;

		case constIOCTLtmmanDSPOpen : // vxd callable
		{
			tmifDSPOpen* TMIF = 	
				(tmifDSPOpen*)IOParameters;
			if ( TMIF->DSPNumber < TMManGlobal->DeviceCount )
			{
				TMIF->DSPHandle = (UInt32)TMManGlobal->DeviceList[TMIF->DSPNumber];
				TMIF->Status = statusSuccess;

			}
			else
			{
				TMIF->Status = statusDSPNumberOutofRange;
			}
			ReturnInformation = sizeof ( tmifDSPOpen );
			
		}
		break;

		case constIOCTLtmmanDSPClose : // vxd callable
		{
			tmifGenericFunction* TMIF = 	
				(tmifGenericFunction*)IOParameters;

			TMIF->Status = statusSuccess;
			ReturnInformation = sizeof ( tmifGenericFunction );

		}
		break;

		case constIOCTLtmmanDSPGetNum : // vxd callable
		{
			tmifDSPNum* TMIF = 	
				(tmifDSPNum*)IOParameters;
		
			TMIF->DSPCount = TMManGlobal->DeviceCount;
			TMIF->Status = statusSuccess;
			ReturnInformation = sizeof ( tmifDSPNum );

		}
		break;

		case	constIOCTLtmmanDSPInfo : // vxd callable
		{
			tmifDSPInfo*	TMIF =
				(tmifDSPInfo*)IOParameters;


			TMManDeviceObject* TMManDevice = (TMManDeviceObject*)TMIF->DSPHandle;
			UInt32	ClientIdx;
			UInt32	Dummy;
			PVOID			Process;
			ClientObject*		Client;

			Process = PsGetCurrentProcess();

			for ( ClientIdx = 0 ; ClientIdx < TMManGlobal->MaximumClients ; ClientIdx ++ )
			{
				if ( !TMManGlobal->ClientList[ClientIdx] )
					continue;

				if ( ((ClientObject*)TMManGlobal->ClientList[ClientIdx])->Process != Process )
					continue;
				break;
			}

			if ( ClientIdx == TMManGlobal->MaximumClients )
			{
				DPF(0,("tmman:tmmanDeviceControl:PANIC:tmmanDSPInfo:InvalidHandle:Process[%x]\n", 
					Process));
				TMIF->Status = statusInvalidHandle;
				ReturnInformation = sizeof ( tmifDSPInfo );
				break;
			}

			Client = TMManGlobal->ClientList[ClientIdx];
			
			TMIF->Info.MMIO.MappedAddress = 
				(UInt32)Client->Device[TMManDevice->DSPNumber].MMIOAddrUser;

			TMIF->Info.SDRAM.MappedAddress = 
				(UInt32)Client->Device[TMManDevice->DSPNumber].SDRAMAddrUser;

			halGetMMIOInfo (
				TMManDevice->HalHandle,
				(Pointer*)&TMIF->Info.MMIO.PhysicalAddress,
				(Pointer*)&Dummy,
				&TMIF->Info.MMIO.Size );
	

			halGetSDRAMInfo (
				TMManDevice->HalHandle,
				(Pointer*)&TMIF->Info.SDRAM.PhysicalAddress,
				(Pointer*)&Dummy,
				&TMIF->Info.SDRAM.Size );


			halGetTMPCIInfo ( 
				TMManDevice->HalHandle,
				&TMIF->Info.TMDeviceVendorID,
				&TMIF->Info.TMSubSystemID,
				&TMIF->Info.TMClassRevisionID );

			halGetBridgePCIInfo ( 
				TMManDevice->HalHandle,
				&TMIF->Info.BridgeDeviceVendorID,
				&TMIF->Info.BridgeSubsystemID,
				&TMIF->Info.BridgeClassRevisionID );

			TMIF->Info.DSPNumber = TMManDevice->DSPNumber;
			TMIF->Status = statusSuccess;
			ReturnInformation = sizeof ( tmifDSPInfo );

		}
		break;


		case	constIOCTLtmmanDSPLoad :
		{
			tmifDSPLoad*	TMIF =

⌨️ 快捷键说明

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