/*++ Copyright (c) 1999 Eugene A. Klimov. All rights Reserved Copyright (c) 2003 Aleksandrov O.E. All rights Reserved Copyright (c) 1999 …ўЈҐ­Ё© Ђ. Љ«Ё¬®ў. All rights Reserved Copyright (c) 2003 Ђ«ҐЄc ­¤а®ў Ћ.…. All rights Reserved Module Name: mi1201.h Abstract: Include file for MI1201-AGM Port I/O Driver ******************************************************** ORIGINATED from Copyright (c) 1990-2000 Microsoft Corporation, All Rights Reserved Module Name: genport.h Abstract: Include file for Generic Port I/O Example Driver Author: Robert R. Howell January 6, 1993 Environment: Kernel mode Revision History: Eliyas Yakub Dec 29, 1998 Converted to Windows 2000 --*/ #include #include "mi1201ioctl.h" // Get IOCTL interface definitions #include "FuncMi1201.h" // Описание данных для Модификации драйвера //#if !defined(__GENPORT_H__) !!!my //#define __GENPORT_H__ !!!my #if !defined(__MI1201_H__) #define __MI1201_H__ #define PORTIO_TAG 'MI12' typedef struct _LastPortInfo { ULONG PortType; // последняя операция ULONG Port; // последний порт с которым проводились операция } tLastPortInfo, *ptLastPortInfo; //typedef struct _TranslatedPortInfo { // ULONG Port; // последний порт с которым проводились операция // ULONG PortMemoryType; // тип порта //} tTranslatedPortInfo, *ptTranslatedPortInfo; typedef PORT_DATA tTranslatedPortInfo; typedef tTranslatedPortInfo *ptTranslatedPortInfo; typedef struct _LastReadWriteInfo { tLastPortInfo Initial; // исходный порт tTranslatedPortInfo Translated; // транслированный порт FAST_MUTEX LockMutex; // запрет одновременного доступа } tLastReadWriteInfo, *ptLastReadWriteInfo; typedef struct _tWaitData { ULONG ULFiller; // на всякий случай } tWaitData, *ptWaitData; // структура данных для драйвера МИ-1201 АГМ typedef struct _LOCAL_DEVICE_INFO { PDEVICE_OBJECT DeviceObject; // The Gpd device object. PDEVICE_OBJECT NextLowerDriver; // The top of the stack IO_REMOVE_LOCK RemoveLock; BOOLEAN Started; BOOLEAN Removed; BOOLEAN Filler[1]; // bug fix ??? BOOLEAN AbortStateBeforeRemoving; KEVENT AbortEvent; // запрос на немедленное завершение операций tTransPortInfoArray TranslatedPortRangesInfo; // информация по ТРАНСЛИРОВАННЫМ диапазонам портов (максимально cMaxRangeNumber диапазонов) tInitialPortInfoArray InitialPortRangesInfo; // информация по ИСХОДНЫМ (ФИЗИЧЕСКИМ) диапазонам портов (максимально cMaxRangeNumber диапазонов) tLastReadWriteInfo LastRead; // данные по последней операции чтения tLastReadWriteInfo LastWrite; // данные по последней операции записи tWaitData WaitData; ULONG ULFiller[2]; // на всякий случай } LOCAL_DEVICE_INFO, *PLOCAL_DEVICE_INFO; // driver local data structure specific to each device object /* typedef struct _LOCAL_DEVICE_INFO { PVOID PortBase; // base port address ULONG PortCount; // Count of I/O addresses used. ULONG PortMemoryType; // HalTranslateBusAddress MemoryType PDEVICE_OBJECT DeviceObject; // The Gpd device object. PDEVICE_OBJECT NextLowerDriver; // The top of the stack BOOLEAN Started; BOOLEAN Removed; BOOLEAN PortWasMapped; // If TRUE, we have to unmap on unload BOOLEAN Filler[1]; //bug fix IO_REMOVE_LOCK RemoveLock; } LOCAL_DEVICE_INFO, *PLOCAL_DEVICE_INFO; */ #if DBG #define DebugPrint(_x_) \ DbgPrint ("MI1201:"); \ DbgPrint _x_; #define TRAP() DbgBreakPoint() //-------------- #define DebugPrint1(_x_) \ DbgPrint _x_; #define myTRAP() _asm {int 3} #else #define DebugPrint(_x_) #define TRAP() //-------------- #define DebugPrint1(_x_) #define myTRAP() #endif typedef struct _TestAlingment { // для выяснения выравнивания UCHAR Char; ULONG Long; UCHAR Char1; } tTestAlingment, *ptTestAlingment; // Определение типа для функционального параметра typedef ULONG (fReadPort)(IN PULONG Port); typedef fReadPort *pfReadPort; // Определение типа для функционального параметра typedef VOID (fWritePort)(IN PULONG Port, IN ULONG Data); typedef fWritePort *pfWritePort; typedef VOID (fWritePortBuffer)(IN PULONG Port, IN PULONG Buffer, IN ULONG Count); typedef fWritePortBuffer *pfWritePortBuffer; typedef VOID (fReadPortBuffer)(IN PULONG Port, IN PULONG Buffer, IN ULONG Count); typedef fReadPortBuffer *pfReadPortBuffer; /********************* function prototypes ***********************************/ // NTSTATUS DriverEntry( IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath ); NTSTATUS GpdDispatch( IN PDEVICE_OBJECT pDO, IN PIRP pIrp ); NTSTATUS GpdIoctlReadPort( IN PLOCAL_DEVICE_INFO pLDI, IN PIRP pIrp, IN PIO_STACK_LOCATION IrpStack, IN ULONG IoctlCode ); NTSTATUS GpdIoctlWritePort( IN PLOCAL_DEVICE_INFO pLDI, IN PIRP pIrp, IN PIO_STACK_LOCATION IrpStack, IN ULONG IoctlCode ); VOID GpdUnload( IN PDRIVER_OBJECT DriverObject ); NTSTATUS GpdAddDevice( IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject ); NTSTATUS GpdDispatchPnp ( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ); NTSTATUS GpdStartDevice ( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ); NTSTATUS GpdDispatchPower( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ); NTSTATUS GpdDispatchSystemControl( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ); PCHAR PnPMinorFunctionString ( UCHAR MinorFunction ); //---------------------------------------------------------------------- NTSTATUS TranslatePort( IN ULONG nPort, IN ULONG nPortType, IN PLOCAL_DEVICE_INFO pLDI, IN OUT ptLastReadWriteInfo pInfo, OUT ptTranslatedPortInfo pTranslatedPort ); NTSTATUS myUnmapIoSpaces( IN OUT tTransPortInfo *PortInfo ); UCHAR GetPortSize(ULONG PortType); NTSTATUS GpdIoctlWritePortBuffer( IN PLOCAL_DEVICE_INFO pLDI, IN PIRP pIrp, IN PIO_STACK_LOCATION IrpStack ); NTSTATUS GpdIoctlReadPortBuffer( IN PLOCAL_DEVICE_INFO pLDI, IN PIRP pIrp, IN PIO_STACK_LOCATION IrpStack ); NTSTATUS MI1201IoctlAbort( IN PLOCAL_DEVICE_INFO pLDI, IN PIRP pIrp, IN PIO_STACK_LOCATION IrpStack ); BOOLEAN AbortState( IN PLOCAL_DEVICE_INFO pLDI ); BOOLEAN AbortSet( IN PLOCAL_DEVICE_INFO pLDI, IN BOOLEAN Abort ); // READ_PORT---------------------------------------- ULONG myREAD_PORT_UCHAR(PULONG Port); ULONG myREAD_PORT_USHORT(PULONG Port); ULONG myREAD_REGISTER_UCHAR(PULONG Port); ULONG myREAD_REGISTER_USHORT(PULONG Port); // WRITE_PORT---------------------------------------- VOID myWRITE_PORT_UCHAR(IN PULONG Port, IN ULONG Data); VOID myWRITE_PORT_USHORT(IN PULONG Port, IN ULONG Data); VOID myWRITE_REGISTER_UCHAR(IN PULONG Port, IN ULONG Data); VOID myWRITE_REGISTER_USHORT(IN PULONG Port, IN ULONG Data); // READ_PORT_BUFFER---------------------------------------- VOID myREAD_PORT_BUFFER_UCHAR(IN PULONG Port, IN PULONG Buffer, IN ULONG Count); VOID myREAD_PORT_BUFFER_USHORT(IN PULONG Port, IN PULONG Buffer, IN ULONG Count); VOID myREAD_REGISTER_BUFFER_UCHAR(IN PULONG Port, IN PULONG Buffer, IN ULONG Count); VOID myREAD_REGISTER_BUFFER_USHORT(IN PULONG Port, IN PULONG Buffer, IN ULONG Count); // WRITE_PORT_BUFFER---------------------------------------- VOID myWRITE_PORT_BUFFER_UCHAR(IN PULONG Port, IN PULONG Buffer, IN ULONG Count); VOID myWRITE_PORT_BUFFER_USHORT(IN PULONG Port, IN PULONG Buffer, IN ULONG Count); VOID myWRITE_REGISTER_BUFFER_UCHAR(IN PULONG Port, IN PULONG Buffer, IN ULONG Count); VOID myWRITE_REGISTER_BUFFER_USHORT(IN PULONG Port, IN PULONG Buffer, IN ULONG Count); // ---------------------------------------- NTSTATUS WaitOnPort( IN pfReadPort pFuncReadPort, IN PGENPORT_WAIT_INPUT_BUFFER pWaitData, IN OUT PGENPORT_WAIT_OUTPUT_BUFFER pResultData, IN PKEVENT pAbortEvent ); NTSTATUS GpdIoctlWaitPort( IN PLOCAL_DEVICE_INFO pLDI, IN PIRP pIrp, IN PIO_STACK_LOCATION IrpStack ); NTSTATUS GetAppropriateWritePortFunction( IN PPORT_DATA pPort, OUT pfWritePort *pFuncWritePort ); NTSTATUS GetAppropriateReadPortFunction( IN PPORT_DATA pPort, OUT pfReadPort *pFuncReadPort ); NTSTATUS WaitOnPortEx( IN PGENPORT_GENPORT_WRITE_AND_WAIT_WAIT_DATA pWaitData, IN OUT PGENPORT_WAIT_OUTPUT_BUFFER pResultData, IN PKEVENT pAbortEvent ); NTSTATUS WriteAndWaitOnPort( IN PGENPORT_WRITE_AND_WAIT_INPUT_BUFFER pWriteAndWaitData, OUT PGENPORT_WAIT_OUTPUT_BUFFER pResultData, IN PKEVENT pAbortEvent ); NTSTATUS GpdIoctlWriteAndWaitPort( IN PLOCAL_DEVICE_INFO pLDI, IN PIRP pIrp, IN PIO_STACK_LOCATION IrpStack ); NTSTATUS TranslatePortEx( IN PPORT_DATA pPort, IN PLOCAL_DEVICE_INFO pLDI, IN OUT ptLastReadWriteInfo pInfo, OUT PPORT_DATA pTranslatedPort ); NTSTATUS GpdIoctlCheckMultifunctionInputBuffer( IN PLOCAL_DEVICE_INFO pLDI, IN PIRP pIrp, IN PIO_STACK_LOCATION IrpStack ); NTSTATUS CheckMultifunctionIrpBuffer( IN PGENPORT_MULTIFUNCTION_IO_INPUT_BUFFER pBuffer, IN ULONG uBufferSize, OUT PGENPORT_MULTIFUNCTION_IO_ERROR_DESCRIPTION pErrorDesc, OUT PULONG pOutputBufferSize, IN PLOCAL_DEVICE_INFO pLDI ); NTSTATUS GetAppropriateReadPortBufferFunction( IN PPORT_DATA pPort, OUT pfReadPortBuffer *pFuncReadPort ); NTSTATUS GetAppropriateWritePortBufferFunction( IN PPORT_DATA pPort, OUT pfWritePortBuffer *pFuncWritePort ); NTSTATUS GpdIoctlProcessMultifunctionInputBuffer( IN PLOCAL_DEVICE_INFO pLDI, IN PIRP pIrp, IN PIO_STACK_LOCATION IrpStack ); NTSTATUS ProcessMultifunctionIrpBuffer( IN PGENPORT_MULTIFUNCTION_IO_INPUT_BUFFER pBuffer, OUT PGENPORT_MULTIFUNCTION_IO_OUTPUT_BUFFER pOutputBuffer, IN PLOCAL_DEVICE_INFO pLDI ); #endif