[Help] Covert I/O mapped to memory Mapped I/o

Hi all,

I am getting confused after searching google groups on MmMapIoSpace. I
hope that someone can help this .For your reference i will copy the full source code.

FileName : MicroATE.C

#include "MicroATE.h"

NTSTATUS DriverEntry(IN PDRIVER_OBJECT pDriverObject,IN PUNICODE_STRING strRegistryPath)
{
UNREFERENCED_PARAMETER (strRegistryPath);

DebugPrint (("Driver Entry\n"));

pDriverObject->MajorFunction[IRP_MJ_CREATE] = Create;
pDriverObject->MajorFunction[IRP_MJ_CLOSE] = Close;
pDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = Dispatch;
pDriverObject->MajorFunction[IRP_MJ_PNP] = DispatchPnP;
pDriverObject->DriverExtension->AddDevice = AddDevice;
pDriverObject->DriverUnload = Unload;
return STATUS_SUCCESS;
}

NTSTATUS AddDevice(IN PDRIVER_OBJECT pDriverObject,IN PDEVICE_OBJECT pPhysicalDeviceObject)
{
NTSTATUS status = STATUS_SUCCESS;
PDEVICE_OBJECT deviceObject = NULL;
PLOCAL_DEVICE_INFO deviceInfo;
UNICODE_STRING ntDeviceName;
UNICODE_STRING win32DeviceName;

DebugPrint(("AddDevice1\n"));

PAGED_CODE();
RtlInitUnicodeString(&ntDeviceName, GPD_DEVICE_NAME);
RtlInitUnicodeString(&win32DeviceName, DOS_DEVICE_NAME);

// Create a device object.
status = IoCreateDevice (pDriverObject,
sizeof (LOCAL_DEVICE_INFO),
&ntDeviceName,
MICROATE_TYPE,
0,
FALSE,
&deviceObject);
if (!NT_SUCCESS (status)) {
return status;
}

status = IoCreateSymbolicLink( &win32DeviceName, &ntDeviceName );
if (!NT_SUCCESS(status)) {
IoDeleteDevice(deviceObject);
return status;
}
deviceInfo = (PLOCAL_DEVICE_INFO) deviceObject->DeviceExtension;
deviceInfo->DeviceObject = deviceObject;
deviceInfo->PhysicalDeviceObject = pPhysicalDeviceObject;
deviceInfo->NextLowerDriver = IoAttachDeviceToDeviceStack (
deviceObject, pPhysicalDeviceObject);
if(NULL == deviceInfo->NextLowerDriver) {
IoDeleteSymbolicLink(&win32DeviceName);
IoDeleteDevice(deviceObject);
return STATUS_NO_SUCH_DEVICE;
}

deviceObject->Flags &= ~DO_DEVICE_INITIALIZING;

IoInitializeDpcRequest(deviceInfo->DeviceObject, DpcForIsr);

deviceObject->Flags |= DO_BUFFERED_IO;

return STATUS_SUCCESS;
}


VOID Unload(IN PDRIVER_OBJECT pDriverObject )
{
DebugPrint(("Unload\n"));
}


NTSTATUS CompleteRequest(IN PIRP pIrp,IN NTSTATUS pStatus)
{
pIrp->IoStatus.Status = pStatus;
IoCompleteRequest(pIrp, IO_NO_INCREMENT);
return pStatus;
}

NTSTATUS Create(IN PDEVICE_OBJECT pDeviceObject,IN PIRP pIrp)
{
NTSTATUS status;
PLOCAL_DEVICE_INFO deviceInfo;
deviceInfo = (PLOCAL_DEVICE_INFO)pDeviceObject->DeviceExtension;

DebugPrint(("Create PCI Device Driver Hari \n"));

if(!deviceInfo->Started){
status = STATUS_DEVICE_NOT_READY;
return CompleteRequest(pIrp, status);
}
status = STATUS_SUCCESS;
pIrp->IoStatus.Information = 0;
status = CompleteRequest(pIrp, status);

m_nISREnabled = 0x0000;
m_nInterruptBitStatus = 0x0000;
m_nClearInterruptStatus = 0x0001;

return status;
}

NTSTATUS Close(IN PDEVICE_OBJECT pDeviceObject,IN PIRP pIrp)
{
NTSTATUS status;
PLOCAL_DEVICE_INFO deviceInfo;
deviceInfo = (PLOCAL_DEVICE_INFO)pDeviceObject->DeviceExtension;

DebugPrint(("Close\n"));

status = STATUS_SUCCESS;
pIrp->IoStatus.Information = 0;
status = CompleteRequest(pIrp, status);
return status;
}

NTSTATUS DefaultPnpHandler(IN PDEVICE_OBJECT pDeviceObject,IN PIRP pIrp)
{
PLOCAL_DEVICE_INFO deviceInfo;
IoSkipCurrentIrpStackLocation(pIrp);
deviceInfo = (PLOCAL_DEVICE_INFO)pDeviceObject->DeviceExtension;
DebugPrint(("Default PnP Handler\n"));
return IoCallDriver(deviceInfo->NextLowerDriver, pIrp);
}

NTSTATUS ForwardAndWait(IN PDEVICE_OBJECT pDeviceObject,IN PIRP pIrp)
{
KEVENT event;
PLOCAL_DEVICE_INFO deviceInfo;
KeInitializeEvent(&event, NotificationEvent, FALSE);
IoCopyCurrentIrpStackLocationToNext(pIrp);
IoSetCompletionRoutine(pIrp, (PIO_COMPLETION_ROUTINE)CompletionRoutine, (PVOID) &event, TRUE, TRUE, TRUE);
deviceInfo = (PLOCAL_DEVICE_INFO)pDeviceObject->DeviceExtension;
IoCallDriver(deviceInfo->NextLowerDriver, pIrp);
KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
DebugPrint(("ForwardAndWait\n"));
return pIrp->IoStatus.Status;
}

NTSTATUS CompletionRoutine(IN PDEVICE_OBJECT pDeviceObject,IN PIRP pIrp,IN PKEVENT pEvent)
{
if (pIrp->PendingReturned) {
IoMarkIrpPending(pIrp);
}
KeSetEvent(pEvent, 0, FALSE);
DebugPrint(("Completion Routine\n"));
return STATUS_MORE_PROCESSING_REQUIRED;
}

VOID DpcForIsr(IN PKDPC pDpc,IN PDEVICE_OBJECT pDeviceObject,IN PIRP pIrp,IN PLOCAL_DEVICE_INFO deviceInfo)
{
NTSTATUS status = STATUS_SUCCESS;
unsigned short temp = 0;

DebugPrint (("DpcForIsr\n"));

ASSERT(KeGetCurrentIrql() >= DISPATCH_LEVEL);
deviceInfo = (PLOCAL_DEVICE_INFO)pDeviceObject->DeviceExtension;

if(deviceInfo->EventObject != NULL){
KeSetEvent((KEVENT*)deviceInfo->EventObject, 0, FALSE);
DebugPrint(("KEventObject after setting (%x)\n", (deviceInfo->EventObject)));
}
temp = _inpw(m_nInterruptStatusReg);
_outpw(m_nInterruptStatusReg, temp);
_outpw(m_nInterruptEnableReg, 1);
}

BOOLEAN ISR(IN PKINTERRUPT InterruptObject,IN PLOCAL_DEVICE_INFO deviceInfo)
{
DebugPrint(("ISR Entry\n"));
if( m_nISREnabled == 0x100 ){
unsigned short checkBit = 0 , statusBit = 0;

m_nISREnabled = 0;
DebugPrint (("Enter into ISR function \n"));
checkBit = _inpw(m_nInterruptStatusReg);
statusBit = checkBit;
_outpw(m_nInterruptStatusReg, 0xff);
m_nInterruptBitStatus ^= statusBit;
//DebugPrint( ("data %x", m_nInterruptBitStatus) );
//IoRequestDpc(deviceInfo->DeviceObject, NULL, deviceInfo);
_outpw(m_nInterruptEnableReg, 0);
return TRUE;
}
else{
DebugPrint (("ISR Return \n"));
return FALSE;
}
}

NTSTATUS DispatchPnP (IN PDEVICE_OBJECT pDeviceObject,IN PIRP pIrp)
{
PIO_STACK_LOCATION irpStack;
NTSTATUS status = STATUS_SUCCESS;
UNICODE_STRING win32DeviceName;
PLOCAL_DEVICE_INFO deviceInfo;

PAGED_CODE();
DebugPrint(("DispatchPnP \n"));

deviceInfo = (PLOCAL_DEVICE_INFO) pDeviceObject->DeviceExtension;
irpStack = IoGetCurrentIrpStackLocation(pIrp);

if (!NT_SUCCESS (status)) {
status = CompleteRequest(pIrp, status);
return status;
}

switch (irpStack->MinorFunction) {
case IRP_MN_START_DEVICE:
DebugPrint(("DispatchPnP_StartDevice \n"));
pIrp->IoStatus.Status = STATUS_SUCCESS;
status = ForwardAndWait(pDeviceObject, pIrp);
if (!NT_SUCCESS(status))
return CompleteRequest(pIrp, status);
status = StartDevice(pDeviceObject, pIrp);
if(NT_SUCCESS(status)) {
deviceInfo->Started = TRUE;
deviceInfo->Removed = FALSE;
}
CompleteRequest(pIrp, status);
break;

case IRP_MN_QUERY_STOP_DEVICE:
DebugPrint(("DispatchPnP_QueryStopDevice\n"));
status = STATUS_SUCCESS;
status = CompleteRequest(pIrp, status);
break;

case IRP_MN_QUERY_REMOVE_DEVICE:
DebugPrint(("DispatchPnP_QueryRemoveDevice \n"));
pIrp->IoStatus.Status = STATUS_SUCCESS;
status = DefaultPnpHandler(pDeviceObject, pIrp);
break;

case IRP_MN_SURPRISE_REMOVAL:
DebugPrint(("DispatchPnP_SurpriseRemoval \n"));
deviceInfo->Removed = TRUE;
deviceInfo->Started = FALSE;
RtlInitUnicodeString(&win32DeviceName, DOS_DEVICE_NAME);
IoDeleteSymbolicLink(&win32DeviceName);
pIrp->IoStatus.Status = STATUS_SUCCESS;
status = DefaultPnpHandler(pDeviceObject, pIrp);
break;

case IRP_MN_REMOVE_DEVICE:
DebugPrint(("DispatchPnP_RemoveDevice\n"));
if(!deviceInfo->Removed) {
deviceInfo->Removed = TRUE;
deviceInfo->Started = FALSE;
RtlInitUnicodeString(&win32DeviceName, DOS_DEVICE_NAME);
IoDeleteSymbolicLink(&win32DeviceName);
}
pIrp->IoStatus.Status = STATUS_SUCCESS;
status = DefaultPnpHandler(pDeviceObject, pIrp);
IoDetachDevice(deviceInfo->NextLowerDriver);
IoDeleteDevice(pDeviceObject);
break;

case IRP_MN_STOP_DEVICE:
DebugPrint(("DispatchPnP_StopDevice \n"));
pIrp->IoStatus.Status = STATUS_SUCCESS;
deviceInfo = (PLOCAL_DEVICE_INFO)pDeviceObject->DeviceExtension;
return DefaultPnpHandler(pDeviceObject, pIrp);
break;
case IRP_MN_CANCEL_REMOVE_DEVICE:
// No action required in this case. Just pass it down.
case IRP_MN_CANCEL_STOP_DEVICE:
//No action required in this case.
pIrp->IoStatus.Status = STATUS_SUCCESS;
default:
status = DefaultPnpHandler(pDeviceObject, pIrp);
break;
}
return status;
}

NTSTATUS StartDevice (IN PDEVICE_OBJECT pDeviceObject,IN PIRP pIrp)
{
NTSTATUS status = STATUS_SUCCESS;
PCM_PARTIAL_RESOURCE_DESCRIPTOR resourceTrans;
PCM_PARTIAL_RESOURCE_LIST partialResourceListTranslated;
PIO_STACK_LOCATION stack;
ULONG i;
PLOCAL_DEVICE_INFO deviceInfo;
DebugPrint(("Start Device\n"));
deviceInfo = (PLOCAL_DEVICE_INFO)pDeviceObject->DeviceExtension;
stack = IoGetCurrentIrpStackLocation(pIrp);
PAGED_CODE();
if (deviceInfo->Removed) {
return STATUS_DELETE_PENDING;
}
if (NULL == stack->Parameters.StartDevice.AllocatedResourcesTranslated) {

return STATUS_INSUFFICIENT_RESOURCES;
}

partialResourceListTranslated =
&stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList;
resourceTrans = &partialResourceListTranslated->PartialDescriptors[0];
for (i = 0; i < partialResourceListTranslated->Count; i++, resourceTrans++) {
switch (resourceTrans->Type) {
case CmResourceTypePort:
deviceInfo->PortWasMapped = TRUE;
deviceInfo->PortBase = (PVOID)resourceTrans->u.Port.Start.LowPart;
deviceInfo->PortCount = resourceTrans->u.Port.Length;
DebugPrint(("Resource Translated Port: (%x) Length: (%d)\n",
resourceTrans->u.Port.Start.LowPart,
resourceTrans->u.Port.Length));
break;
case CmResourceTypeMemory:

deviceInfo->PortWasMapped = TRUE;
deviceInfo->PortBase = MmMapIoSpace(membase,
resourceTrans->u.Port.Length, MmNonCached);
ASSERT(deviceInfo->PortBase != 0);

// membase = resourceTrans->u.Memory.Start;
// deviceInfo->nbytes = resourceTrans->u.Memory.Length;
break;
case CmResourceTypeInterrupt:
DebugPrint(("Main Interrupt"));
deviceInfo->InterruptLevel = resourceTrans->u.Interrupt.Level;
deviceInfo->InterruptVector = resourceTrans->u.Interrupt.Vector;
deviceInfo->InterruptAffinity = resourceTrans->u.Interrupt.Affinity;
if(resourceTrans->Flags == CM_RESOURCE_INTERRUPT_LATCHED) {
DebugPrint(("Interrupt resource type is latched\n"));
deviceInfo->InterruptMode = Latched;
}else{
DebugPrint(("Interrupt resource type is level sensitive\n"));
deviceInfo->InterruptMode = LevelSensitive;
}
deviceInfo->irqShare = resourceTrans->ShareDisposition == CmResourceShareShared;
status = IoConnectInterrupt(&deviceInfo->InterruptObject,
(PKSERVICE_ROUTINE)ISR,
deviceInfo,
NULL,
(UCHAR)deviceInfo->InterruptVector,
(UCHAR)deviceInfo->InterruptLevel,
(UCHAR)deviceInfo->InterruptLevel,
deviceInfo->InterruptMode,
deviceInfo->irqShare,
deviceInfo->InterruptAffinity,
FALSE);
if (!NT_SUCCESS(status)){
DebugPrint(("IoConnectInterrupt fails \n"));
return status;
}
break;


default:
DebugPrint((" resource type \n"));
break;
} //end of switch
// deviceInfo->membase = (PUCHAR) MmMapIoSpace(membase,deviceInfo->nbytes,MmNonCached);
// if (!deviceInfo->membase)
// return STATUS_NO_MEMORY;
} // end of for
deviceInfo->InterfaceType = PCIBus;
return status;
}

NTSTATUS Dispatch(IN PDEVICE_OBJECT pDeviceObject,IN PIRP pIrp)
{
PLOCAL_DEVICE_INFO deviceInfo;
PIO_STACK_LOCATION IrpStack;
NTSTATUS status;

unsigned long timeout = -10000;
unsigned short commandReg, sequenceReg;
unsigned short address = 0;
unsigned long data = 0;
PVOID inOutBuffer;
ULONG inBufferLength;
ULONG outBufferLength;

DebugPrint (("Dispatching Messages\n"));
PAGED_CODE();
pIrp->IoStatus.Information = 0;
deviceInfo = (PLOCAL_DEVICE_INFO)pDeviceObject->DeviceExtension; // Get local info struct
if(!deviceInfo->Started) {
status = STATUS_DEVICE_NOT_READY;
status = CompleteRequest(pIrp, status);
DebugPrint (("Return\n"));
return status;
}
commandReg = (unsigned short)deviceInfo->PortBase;
sequenceReg = commandReg + 4;
m_nInterruptStatusReg = commandReg + 2;
m_nInterruptEnableReg = commandReg + 8;
m_nCommandReg = commandReg;
m_nSequenceReg = sequenceReg;

IrpStack = IoGetCurrentIrpStackLocation(pIrp);
inOutBuffer = pIrp->AssociatedIrp.SystemBuffer;
inBufferLength = IrpStack->Parameters.DeviceIoControl.InputBufferLength;
outBufferLength = IrpStack->Parameters.DeviceIoControl.OutputBufferLength;
DebugPrint (("Before \n"));
switch (IrpStack->MajorFunction)
{

case IRP_MJ_DEVICE_CONTROL:
// Dispatch on IOCTL
switch (IrpStack->Parameters.DeviceIoControl.IoControlCode)
{

case IOCTL_ADD:
address = *(PUSHORT)inOutBuffer;
DebugPrint(("My Function Add : (%x), %x\n", address, inOutBuffer));
case IOCTL_READWORD:
address = *(PUSHORT)inOutBuffer;
DebugPrint(("ReadAddress2 (%x)\n", address));
_outpw( commandReg, *(PUSHORT)inOutBuffer );
*(PULONG)inOutBuffer = _inpd( sequenceReg );
data = *(PULONG)inOutBuffer;
DebugPrint(("ReadData2 (%x)\n", data));
pIrp->IoStatus.Information = sizeof(ULONG);
status = STATUS_SUCCESS;
break;
case IOCTL_WRITEDWORD: // Write a DWORD of data to machine port
{
address = ((PORT_INPUT*)inOutBuffer)->m_nAddress;
data = ((PORT_INPUT*)inOutBuffer)->m_nData;
//DebugPrint(("WriteAddress1 (%x)\n", address));
//DebugPrint(("WriteData1 (%x)\n", data));
_outpw( commandReg, ((PORT_INPUT*)inOutBuffer)->m_nAddress );
_outpd( sequenceReg, (ULONG)(((PORT_INPUT*)inOutBuffer)->m_nData ) );
status = STATUS_SUCCESS;
break;
}
case IOCTL_READDWORD: // Read a DWORD of data from machine port
{
address = *(PUSHORT)inOutBuffer;
DebugPrint(("ReadAddress1 (%x)\n", address));
_outpw( commandReg, *(PUSHORT)inOutBuffer );
*(PULONG)inOutBuffer = _inpd( sequenceReg );
data = *(PULONG)inOutBuffer;
DebugPrint(("ReadData1 (%x)\n", data));
pIrp->IoStatus.Information = sizeof(ULONG);
status = STATUS_SUCCESS;
break;
}
case IOCTL_WRITEIREGWORD: // Write a WORD to interface card port.
{
USHORT address = commandReg + ((PORT_INPUT*)inOutBuffer)->m_nAddress;
USHORT data = (USHORT)((PORT_INPUT*)inOutBuffer)->m_nData;
DebugPrint(("WriteREGWord (%x)\n", address));
DebugPrint(("WriteREGWord (%x)\n", data));
_outpw( address, data );
status = STATUS_SUCCESS;
break;
}
case IOCTL_READIREGWORD: // Read a WORD from interface card port.
{
USHORT address = commandReg + (*((PUSHORT)inOutBuffer));
*(PUSHORT)inOutBuffer = _inpw( address );
pIrp->IoStatus.Information = sizeof(USHORT);
status = STATUS_SUCCESS;
break;
}
case IOCTL_WRITEIREGDWORD: // Write a DWORD to interface card port.
{
USHORT address = commandReg + ((PORT_INPUT*)inOutBuffer)->m_nAddress;
ULONG data = (ULONG)((PORT_INPUT*)inOutBuffer)->m_nData;
_outpd( address, data );
// DebugPrint(("WriteIRegAddress (%x)\n", address));
// DebugPrint(("WriteIRegData(%x)\n", data));
status = STATUS_SUCCESS;
break;
}
case IOCTL_READIREGDWORD: // Read a DWORD from interface card port.
{
USHORT address = commandReg + (*(PUSHORT)inOutBuffer);
*(PULONG)inOutBuffer = _inpd( address );
data = *(PULONG)inOutBuffer;
// DebugPrint(("Address (%x)\n", address));
// DebugPrint(("ReadIRegData (%x)\n", data));
pIrp->IoStatus.Information = sizeof(ULONG);
status = STATUS_SUCCESS;
break;
}
case IOCTL_READWRITE:
{
READWRITE_INPUT* objInput = (READWRITE_INPUT*)inOutBuffer;
unsigned int write, readIndex, count, totalBytes;
int writeAddress = 0;
int WriteAddressData = 0, readAddressData = 0;
totalBytes = objInput->m_nNoOfBytes;
//DebugPrint(("totalBytes: (%d) \n", (ULONG)totalBytes ));
write = 1;
readIndex = 0;
for( count = 0; count < totalBytes; count++) {
//DebugPrint(("count =(%d)\n", count ));
writeAddress = objInput->m_pWriteDataPtr[count];
if((count % 2) == 0){
if( (writeAddress & 0x8000) == 0x8000 ){
//DebugPrint(("Enter into read option" ));
write = 0;
writeAddress = (writeAddress & 0xFFF);
}
//DebugPrint(("WriteAddress =(%x)\n", (ULONG)writeAddress ));
_outpw(commandReg, writeAddress);
}
else {
if( write == 0 ){
//DebugPrint(("Enter into Read Receive RAM" ));
readAddressData = _inpd(sequenceReg);
//DebugPrint((" readAddressData: (%x)\n", (ULONG)readAddressData ));
objInput->m_pReadDataPtr[readIndex] = readAddressData;
readIndex++;
write = 1;
}
else{
WriteAddressData = objInput->m_pWriteDataPtr[count];
//DebugPrint(("WriteAddressData = (%x)\n", (ULONG)WriteAddressData ));
_outpd(sequenceReg, WriteAddressData);
}
}
}
status = STATUS_SUCCESS;
break;
}
case IOCTL_READWRITE_AUTOINCR:
{
short nRead = 0;
unsigned int nAddress = 0, nCount = 0, nData = 0, nNoOfDataItems = 0;
READWRITE_INPUT *pInputBuffer = (READWRITE_INPUT*)inOutBuffer;

nNoOfDataItems = pInputBuffer->m_nNoOfBytes;
//[[ Check whether Read or Write
nRead = ( pInputBuffer->m_pWriteDataPtr[ 0 ] & 0x00800000 ) ? 1 : 0;
//----------------------------]]
//[[ Write the Address Selection Register to H/W
nAddress = pInputBuffer->m_pWriteDataPtr[ 0 ] & 0x000FFFFF;
_outpw( commandReg, nAddress );
//--------------------------------------------]]
//[[ Write the Start Address ( Tick ) to H/W
nData = pInputBuffer->m_pWriteDataPtr[ 1 ] & 0x000FFFFF;
_outpd( sequenceReg, nData );
//----------------------------------------]]
//[[ Write the Memory Bank Address to H/W
nAddress = pInputBuffer->m_pWriteDataPtr[ 3 ] & 0x000FFFFF;
_outpw( commandReg, nAddress );
//-------------------------------------]]

for( nCount = 0; nCount < nNoOfDataItems; nCount++ ) {
if( nRead == 1 ){ // Read operation...
nData = _inpd( sequenceReg );
pInputBuffer->m_pReadDataPtr[ nCount ] = nData;
}
else{ // Write operation...
nData = pInputBuffer->m_pWriteDataPtr[ nCount + 4 ];
_outpd( sequenceReg, nData );
}
}

status = STATUS_SUCCESS;
break;
}
case IOCTL_ENABLEINTERRUPT:
{
unsigned short temp = 0;
unsigned short data = 0;

m_nISREnabled = 0;
m_nInterruptBitStatus = 0;
_outpw(m_nInterruptEnableReg, 0);
//DebugPrint( ("Flag: %d\n", m_nClearInterruptStatus) );
if( m_nClearInterruptStatus == 0x0001 ){
//DebugPrint( ("Clearing Status at 502H\n") );
_outpw(m_nInterruptStatusReg, 0xff);
m_nClearInterruptStatus = 0x0000;
}
data = _inpw(m_nInterruptStatusReg);
if( ( data & 0x04 ) != 0 ){
//DebugPrint( ("Status at 502H: %x\n", data&0x04) );
m_nInterruptBitStatus = (data & 0xff);
m_nClearInterruptStatus = 0x0001;
}
*(PUSHORT)inOutBuffer = (data & 0xff);
pIrp->IoStatus.Information = sizeof(USHORT);
status = STATUS_SUCCESS;
break;
}
case IOCTL_CLEARINTERRUPT:
{
_outpw(m_nInterruptStatusReg, 0xff);
m_nInterruptBitStatus = 0;
status = STATUS_SUCCESS;
break;
}
case IOCTL_READ_FOOTSWITCH_STATUS:
{
unsigned short nData = 0;

nData = _inpw( m_nInterruptStatusReg );
if( ( nData & 0x00FF ) != 0x0000 )
_outpw( m_nInterruptStatusReg, 0xFFFF );
*(PUSHORT)inOutBuffer = ( nData & 0xFF );
pIrp->IoStatus.Information = sizeof(USHORT);
status = STATUS_SUCCESS;
break;
}
default:
status = STATUS_INVALID_PARAMETER;

}
break;
default:
status = STATUS_NOT_IMPLEMENTED;
break;
}
status = CompleteRequest(pIrp, status);
return status;
}


FileName : MicroATE.h


#include "ntddk.h"
#include "IoStruct.h"
#include "QtIoctl.h"

#ifndef __MicroATE_H__
#define __MicroATE_H__

//#define GPD_DEVICE_NAME L"\\Device\\MicroATE"
//#define GPD_DEVICE_NAME L"\\Device\\PXIQT25"
#define GPD_DEVICE_NAME L"\\Device\\PXIICM"

//#define DOS_DEVICE_NAME L"\\DosDevices\\MicroATE"
//#define DOS_DEVICE_NAME L"\\DosDevices\\PXIQT25"
#define DOS_DEVICE_NAME L"\\DosDevices\\PXIICM"

#define MICROATE_TYPE 40000

#if DBG
#define DebugPrint(_x_) \
DbgPrint ("QmaxPCI:"); \
DbgPrint _x_;

#define TRAP() DbgBreakPoint()

#else
#define DebugPrint(_x_)
#define TRAP()
#endif
PHYSICAL_ADDRESS membase;
typedef struct _LOCAL_DEVICE_INFO{
PDEVICE_OBJECT DeviceObject;
PDEVICE_OBJECT PhysicalDeviceObject;
PDEVICE_OBJECT NextLowerDriver;

BOOLEAN Started;
BOOLEAN Removed;
PVOID PortBase; // base port address
ULONG PortCount; // Count of I/O addresses used.
BOOLEAN PortWasMapped;
INTERFACE_TYPE InterfaceType;
PUCHAR membase;
ULONG nbytes;
PKINTERRUPT InterruptObject;
PVOID EventObject;

ULONG InterruptLevel;
ULONG InterruptVector;
ULONG InterruptAffinity;
ULONG InterruptMode;
BOOLEAN irqShare;
BOOLEAN MappedPorts;

CM_RESOURCE_LIST TranslatedResourceList;

}LOCAL_DEVICE_INFO, *PLOCAL_DEVICE_INFO;

unsigned short m_nCommandReg, m_nSequenceReg, m_nInterruptStatusReg, m_nInterruptEnableReg;
unsigned short m_nInterruptBitStatus = 0x0000, m_nISREnabled = 0x0000, m_nClearInterruptStatus = 0x0001;

NTSTATUS
DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING strRegistryPath
);

NTSTATUS
AddDevice(
IN PDRIVER_OBJECT pDriveObject,
IN PDEVICE_OBJECT pPhysicalDeviceObject
);

VOID
Unload(
IN PDRIVER_OBJECT pDriverObject
);

NTSTATUS
CompleteRequest(
IN PIRP pIrp,
IN NTSTATUS pStatus
);

NTSTATUS
Create(
IN PDEVICE_OBJECT pDeviceObject,
IN PIRP pIrp
);

NTSTATUS
Close(
IN PDEVICE_OBJECT pDeviceObject,
IN PIRP pIrp
);

NTSTATUS
DefaultPnpHandler(
IN PDEVICE_OBJECT pDeviceObject,
IN PIRP pIrp
);

NTSTATUS
ForwardAndWait(
IN PDEVICE_OBJECT pDeviceObject,
IN PIRP pIrp
);

NTSTATUS
CompletionRoutine(
IN PDEVICE_OBJECT pDeviceObject,
IN PIRP pIrp,
IN PKEVENT pEvent
);

VOID
DpcForIsr(
IN PKDPC pDpc,
IN PDEVICE_OBJECT pDeviceObject,
IN PIRP pIrp,
IN PLOCAL_DEVICE_INFO deviceInfo
);

BOOLEAN
ISR(
IN PKINTERRUPT InterruptObject,
IN PLOCAL_DEVICE_INFO deviceInfo
);

NTSTATUS
DispatchPnP (
IN PDEVICE_OBJECT pDeviceObject,
IN PIRP pIrp
);

NTSTATUS
StartDevice (
IN PDEVICE_OBJECT pDeviceObject,
IN PIRP pIrp
);

NTSTATUS
Dispatch(
IN PDEVICE_OBJECT pDeviceObject,
IN PIRP pIrp
);

#endif


Am I doing the right thing? If not, please correct me. Thanks.

Regards,
Rajesh Kumar.G
 

Back
Top