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

📄 tmif.c

📁 PNX系列设备驱动 PNX系列设备驱动
💻 C
📖 第 1 页 / 共 3 页
字号:
				TMManDevice->EventManagerHandle,
				PsGetCurrentProcess(), // client listhead struct
				TMIF->Name,
				TMIF->SynchObject,
				TMIF->SynchFlags,
				&TMIF->EventHandle );
			ReturnInformation = sizeof ( tmifEventCreate );
		}
		break;


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

			TMIF->Status = eventDestroy (
				TMIF->Handle );
			ReturnInformation = sizeof ( tmifGenericFunction );

		}
		break;

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

			TMIF->Status = eventSignal (
					TMIF->Handle );
			ReturnInformation = sizeof ( tmifGenericFunction );
		}
		break;

		//---------------------------------------------------------------------
		//	Debugging 
		//---------------------------------------------------------------------
		case constIOCTLtmmanGetDebugDPBuffers : //vxd callable
		{
			tmifDebugBuffers*	TMIF =
				(tmifDebugBuffers*)IOParameters;
			TMManDeviceObject* TMManDevice = (TMManDeviceObject*)TMIF->DSPHandle;
			UInt32	ClientIdx, DeviceIdx;
			UInt32			Dummy;
			Bool			Status;
			UInt32			SDRAMKernelBaseAddress;


			Status = debugDPBuffers (
				TMManDevice->HalHandle,
				&TMIF->FirstHalfPtr, 
				&TMIF->FirstHalfSize, 
				&TMIF->SecondHalfPtr, 
				&TMIF->SecondHalfSize );

			ReturnInformation = sizeof ( tmifDebugBuffers );

			if ( Status == True )
			{
				TMIF->Status = statusSuccess;
			}
			else
			{
				// we have nothing so exit out
				TMIF->Status = statusDebugNoDebugInformation;
				break;
			}

			halGetSDRAMInfo (
				TMManDevice->HalHandle,
				(Pointer*)&Dummy,
				(Pointer*)&SDRAMKernelBaseAddress,
				&Dummy );

			if ( TMIF->FirstHalfPtr )
			{
				TMIF->FirstHalfPtr = TMIF->FirstHalfPtr - SDRAMKernelBaseAddress;
			}

			if ( TMIF->SecondHalfPtr )
			{
				TMIF->SecondHalfPtr = TMIF->SecondHalfPtr - SDRAMKernelBaseAddress;
			}
		}
		break;

		case constIOCTLtmmanGetDebugTargetBuffers : //vxd callable
		{
			tmifDebugBuffers*	TMIF =
				(tmifDebugBuffers*)IOParameters;
			TMManDeviceObject* TMManDevice = (TMManDeviceObject*)TMIF->DSPHandle;
			UInt32	ClientIdx, DeviceIdx;
			UInt32			Dummy;
			Bool			Status;
			UInt32			SDRAMKernelBaseAddress;
			
			Status = debugTargetBuffers (
				TMManDevice->HalHandle,
				&TMIF->FirstHalfPtr, 
				&TMIF->FirstHalfSize, 
				&TMIF->SecondHalfPtr, 
				&TMIF->SecondHalfSize );

			ReturnInformation = sizeof ( tmifDebugBuffers );

			if ( Status == True )
			{
				TMIF->Status = statusSuccess;
			}
			else
			{
				// we have nothing so exit out
				TMIF->Status = statusDebugNoDebugInformation;
				break;
			}

			halGetSDRAMInfo (
				TMManDevice->HalHandle,
				(Pointer*)&Dummy,
				(Pointer*)&SDRAMKernelBaseAddress,
				&Dummy );

			if ( TMIF->FirstHalfPtr )
			{
				TMIF->FirstHalfPtr = TMIF->FirstHalfPtr - SDRAMKernelBaseAddress;
			}

			if ( TMIF->SecondHalfPtr )
			{
				TMIF->SecondHalfPtr = TMIF->SecondHalfPtr - SDRAMKernelBaseAddress;
			}
		}
		break;

		case constIOCTLtmmanGetDebugHostBuffers : //vxd callable
		{
			tmifDebugBuffers*	TMIF =
				(tmifDebugBuffers*)IOParameters;
			Bool	Status;

			Status = debugHostBuffers (
				&TMIF->FirstHalfPtr, 
				&TMIF->FirstHalfSize, 
				&TMIF->SecondHalfPtr, 
				&TMIF->SecondHalfSize );

			TMIF->Status = 
				( Status == True ) ? statusSuccess : statusDebugNoDebugInformation;
			ReturnInformation = sizeof ( tmifDebugBuffers );

		}
		break;

		case constIOCTLtmmanDebugPrintf : //vxd callable
		{
			//appliction stuff is printed only if level 31 is enabled.
			DPF(31,( IOParameters ));
		}
		break;

		//---------------------------------------------------------------------
		//	Shared Memory
		//---------------------------------------------------------------------
		case constIOCTLtmmanSharedMemoryCreate : //vxd callable
		{
			tmifSharedMemoryCreate*	TMIF =
				(tmifSharedMemoryCreate*)IOParameters;
			TMManDeviceObject* TMManDevice = (TMManDeviceObject*)TMIF->DSPHandle;
			UInt32			ClientIdx, DeviceIdx;
			UInt8*			KernelMemoryAddress;

			TMIF->Status = memoryCreate(
				TMManDevice->MemoryManagerHandle,
				PsGetCurrentProcess(), // client listhead struct
				TMIF->Name, 
				TMIF->Size, 
				&KernelMemoryAddress,
				&TMIF->SharedMemoryHandle);


			if ( TMIF->Status == statusSuccess )
			{
				TMIF->Address =	KernelMemoryAddress - TMManDevice->MemoryBlock;
			}

			ReturnInformation = sizeof ( tmifSharedMemoryCreate );

		}
		break;

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

			TMIF->Status = memoryDestroy(
				TMIF->Handle );
			ReturnInformation = sizeof ( tmifGenericFunction );

		}
		break;

		case constIOCTLtmmanSharedMemoryGetAddress : // vxd callable
		{
			tmifSharedMemoryAddress*	TMIF =
				(tmifSharedMemoryAddress*)IOParameters;

			PHYSICAL_ADDRESS	PhysicalAddress;
			UInt32				KernelMemoryAddress;
			UInt32				HalHandle;

			TMIF->Status = memoryGetAddress (
				TMIF->SharedMemoryHandle,
				&KernelMemoryAddress );

			if ( TMIF->Status == statusSuccess )
			{
				PhysicalAddress = MmGetPhysicalAddress((PVOID)KernelMemoryAddress);

				memoryGetHalHandle ( 
					TMIF->SharedMemoryHandle,
					&HalHandle );

				TMIF->PhysicalAddress = halTranslateTargetPhysicalAddress ( 
					HalHandle, 
					PhysicalAddress.LowPart );
			}

			ReturnInformation = sizeof ( tmifSharedMemoryAddress );

		}
		break;



		//---------------------------------------------------------------------
		//	DMA Buffer Locking
		//---------------------------------------------------------------------
		case constIOCTLtmmanSGBufferCreate :
		{
			tmifSGBufferCreate*	TMIF =
				(tmifSGBufferCreate*)IOParameters;


			TMManDeviceObject* TMManDevice = (TMManDeviceObject*)TMIF->DSPHandle;

			TMIF->Status = sgbufferCreate (
				TMManDevice->SGBufferManagerHandle,
				PsGetCurrentProcess(), // client listhead struct
				TMIF->Name,
				TMIF->MappedAddress,
				TMIF->Size,
				TMIF->Flags,
				&TMIF->SGBufferHandle );

			ReturnInformation = sizeof ( tmifSGBufferCreate );


		}
		break;

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

			TMIF->Status = sgbufferDestroy ( TMIF->Handle );

			ReturnInformation = sizeof ( tmifGenericFunction );

		}
		break;

		//---------------------------------------------------------------------
		//	Misclaneous Memory Mapping Functions
		//---------------------------------------------------------------------

		// the following 2 DEVIOCTLS are protected in user 
		// mode by a Global Mutex.
		case constIOCTLtmmanXlateAdapterAddress1 : // vxd callable
		{
			tmifGenericFunction*	TMIF =
				(tmifGenericFunction*)IOParameters;
			PHYSICAL_ADDRESS		AdapterPhysicalAddress;

			AdapterPhysicalAddress = MmGetPhysicalAddress ( 
				MmGetSystemAddressForMdl ( Irp->MdlAddress ) );

			//store the tranalted address in a temporary global variable
			TMManGlobal->XlatedAddress = AdapterPhysicalAddress.LowPart;

			// nothing to be returned as the output buffer is METHOD_OUT_DIRECT.
			ReturnInformation = MmGetMdlByteCount ( Irp->MdlAddress );

		}
		break;

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

			// retrieved the stored address
			TMIF->Handle = TMManGlobal->XlatedAddress;
			TMIF->Status = statusSuccess;

			ReturnInformation = sizeof ( tmifGenericFunction );

		}
		break;

		// the following 2 DEVIOCTLS are protected in user 
		// mode by a Global Mutex.
		case constIOCTLtmmanMapSDRAM : // vxd callable
		{
			tmifGenericFunction*	TMIF =
				(tmifGenericFunction*)IOParameters;

			UInt32				ClientIdx;
			UInt32				Dummy;
			PVOID				Process;
			ClientObject*		Client;
			UInt32				Length;
			UInt32				AddrKernel;
			
			TMManDeviceObject* TMManDevice = (TMManDeviceObject*)TMIF->Handle;
			TMIF->Status = statusSuccess;
			ReturnInformation = sizeof ( tmifGenericFunction );

			// if this flag is set then SDRAM is already mapped
			// so ignore this call
			if ( TMManGlobal->MapSDRAM )
				break;

			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;
				break;
			}

			Client = TMManGlobal->ClientList[ClientIdx];
			
			if ( halMapSDRAM ( TMManDevice->HalHandle ) != TRUE )
			{
				TMIF->Status = statusMemoryUnavailable;
				DPF(0,("tmman:tmmanOpen:halMapAdapterMemory:SDRAM:FAIL\n" ));
				break;
			}

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

			if ( ( Client->Device[TMManDevice->DSPNumber].SDRAMAddrUser = 
				sectionMapPhysicalAddress ( 
				AddrKernel, 
				Length,
				&Client->Device[TMManDevice->DSPNumber].SDRAMHandleUser ) ) == NULL )
			{
				TMIF->Status = statusOutOfVirtualAddresses;
				DPF(0,("tmman:tmmanOpen:sectionMapPhysicalAddress:SDRAM:FAIL\n" ));
				halUnmapSDRAM( TMManDevice->HalHandle );
				break;
			}




		}
		break;

		case constIOCTLtmmanUnmapSDRAM : // vxd callable
		{
			tmifGenericFunction*	TMIF =
				(tmifGenericFunction*)IOParameters;
			PVOID				Process;
			ClientObject*		Client;
			UInt32				Length;
			UInt32				ClientIdx;
			TMManDeviceObject* TMManDevice = (TMManDeviceObject*)TMIF->Handle;

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

			if ( TMManGlobal->MapSDRAM )
				break;

			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:tmmanClose:PANIC:InvalidHandle:Process[%x]\n", Process ));
				TMIF->Status = statusInvalidHandle;
				break;
			}

			Client = TMManGlobal->ClientList[ClientIdx];

			sectionUnmapPhysicalAddress ( 
				Client->Device[TMManDevice->DSPNumber].SDRAMAddrUser,
				Client->Device[TMManDevice->DSPNumber].SDRAMHandleUser );

			halUnmapSDRAM ( TMManDevice->HalHandle );

		}
		break;

		
		default :
		return 1;
	}

#if (defined TMMAN_WINNT) || ( defined TMMAN_WIN98 )
	Irp->IoStatus.Information = ReturnInformation;
	Irp->IoStatus.Status = STATUS_SUCCESS;
	IoCompleteRequest ( Irp, IO_NO_INCREMENT );
	return STATUS_SUCCESS;
#endif

}


//
//		Interface implementations
//		Have to put in code for resources and version.h


TMStatus	tmmanKernelModeNegotiateVersion ( 
	tmmanVersion* Version )
{
	TMStatus	Status = statusSuccess;

	if ( Version->Major != verGetFileMajorVersion() )
	{
		DPF(0,("tmman:tmmanKernelModeNegotiateVersion:MajorVersion:FAIL\n"));
		Status = statusMajorVersionError;
		goto tmifNegotiateVersionExit1;
	}

	if ( Version->Minor != verGetFileMinorVersion()  )
	{
		DPF(0,("tmman:tmmanKernelModeNegotiateVersion:MinorVersion:FAIL\n"));
		Status = statusMinorVersionError;
		goto tmifNegotiateVersionExit1;
	}

tmifNegotiateVersionExit1 :
	Version->Major = verGetFileMajorVersion();
	Version->Minor = verGetFileMinorVersion();
	Version->Build = verGetFileBuildVersion();
	return Status;
}



⌨️ 快捷键说明

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