?? tmif.c
字號:
/*----------------------------------------------------------------------------
COPYRIGHT (c) 1998 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
// 010828 Wim de Haan Changed code to remove compiler warnings:
// Line 1175: '-' : incompatible types - from 'void *'
// to 'unsigned char *'
// Line 1175: '=' : 'void *' differs in levels of
// indirection from 'int '
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// SYSTEM INCLUDE FILES
//////////////////////////////////////////////////////////////////////////////
#include "wdm.h"
//////////////////////////////////////////////////////////////////////////////
// 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 )
{
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 )
{
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:
Irp->IoStatus.Information = 0;
Irp->IoStatus.Status = STATUS_DEVICE_BUSY;
IoCompleteRequest (Irp, IO_NO_INCREMENT);
return STATUS_DEVICE_BUSY;
}
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--;
Irp->IoStatus.Information = 0;
Irp->IoStatus.Status = STATUS_SUCCESS;
IoCompleteRequest (Irp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
tmmanCloseExit1:
Irp->IoStatus.Information = 0;
Irp->IoStatus.Status = STATUS_DEVICE_BUSY;
IoCompleteRequest (Irp, IO_NO_INCREMENT);
return STATUS_DEVICE_BUSY;
}
NTSTATUS tmmanDeviceControl(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp )
{
PIO_STACK_LOCATION IOStackLocation;
PVOID IOParameters = Irp->AssociatedIrp.SystemBuffer;
ULONG ReturnInformation = 0;
IOStackLocation = IoGetCurrentIrpStackLocation ( Irp );
// assume that IO Manager will be calling us only with IRP_MJ_DEVICE_CONTROL
switch ( IOStackLocation->Parameters.DeviceIoControl.IoControlCode )
{
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;
TMManDeviceObject* TMManDevice;
ReturnInformation = sizeof ( tmifDSPOpen );
if ( TMIF->DSPNumber >= TMManGlobal->MaximumDevices )
{
TMIF->Status = statusDSPNumberOutofRange;
break;
}
if ( ! TMManGlobal->DeviceList[TMIF->DSPNumber] )
{
TMIF->Status = statusDSPNumberOutofRange;
break;
}
TMManDevice =
(TMManDeviceObject*)TMManGlobal->DeviceList[TMIF->DSPNumber];
// currently we are treating stops and removes the same way.
if ( ( TMManDevice->Stopped ) || ( TMManDevice->Removed ) )
{
TMIF->Status = statusHardwareUnavailable;
break;
}
InterlockedIncrement ( &TMManDevice->References );
if ( 1 == TMManDevice->References )
{
KeClearEvent ( &TMManDevice->RemoveEvent );
KeClearEvent ( &TMManDevice->StopEvent );
}
TMIF->DSPHandle = (UInt32)TMManGlobal->DeviceList[TMIF->DSPNumber];
TMIF->Status = statusSuccess;
}
break;
case constIOCTLtmmanDSPClose : // vxd callable
{
tmifGenericFunction* TMIF =
(tmifGenericFunction*)IOParameters;
TMManDeviceObject* TMManDevice = (TMManDeviceObject*)TMIF->Handle;
ReturnInformation = sizeof ( tmifGenericFunction );
if ( ! TMManDevice )
{
TMIF->Status = statusHardwareUnavailable;
break;
}
InterlockedDecrement ( &TMManDevice->References );
if ( 0 == TMManDevice->References )
{
KeSetEvent ( &TMManDevice->RemoveEvent,
IO_NO_INCREMENT,
FALSE );
KeSetEvent ( &TMManDevice->StopEvent,
IO_NO_INCREMENT,
FALSE );
}
TMIF->Status = statusSuccess;
}
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,
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -