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

📄 ave2k.h

📁 driver wdk
💻 H
字号:
// File Name:
//		xxdriver.h
//
// Contents:
//		Constants, structures, and function
//		declarations specific to this driver.
//
#ifndef _AVE2K_DRIVER
#define _AVE2K_DRIVER

//
// Header files
//
#include <ntddk.h>
#include "hardware.h"
#include "ave2kif.h"
#include "AudioStream.h"

#if _WIN32_WINNT==0x0500
#include "debugprint.h"
#endif
//
// Various constants
//
#define	AVE2K_NT_DEVICE_NAME		L"\\Device\\Ave2k"
#define	AVE2K_WIN32_DEVICE_NAME	L"\\DosDevices\\AVE2K"
#define	AVE2K_DRIVER_NAME			L"AVE2K"

#define	AVE2K_MAXIMUM_DEVICES	64
#define	AVE2K_MAX_NAME_LENGTH	50

#define RPSBUFFERSIZE 160          //maximum number of RPS command

#define CLIPPINGDMABUFFERSIZE 64

//constant determining using direct I/O or buffered I/O
#define USING_DIRECT_IO     1

//++
// Description:
//		Driver-defined structure used to hold 
//		miscellaneous device information.
//
// Access:
//		Allocated from NON-PAGED POOL
//		Available at any IRQL
//--
	typedef struct{	
		ULONG  Length;    //Allocated buffer length
		PHYSICAL_ADDRESS  LogicalAddress;
		PUCHAR BaseAddress;

		ULONG DMAAddress; //Physical address of DMA 
}DATACOMMONBUFFER;

#define LOGOSIZE 6146
typedef struct {
	UCHAR Logo[LOGOSIZE];
}LOGO;

typedef struct _DEVICE_EXTENSION 
{
	PDEVICE_OBJECT DeviceObject; // Back pointer
#if _WIN32_WINNT==0x0500
	PDEVICE_OBJECT PDO; // The PDO to which the FDO is attached.
	//pnp support
	PDEVICE_OBJECT NextLowerDriver;     // The top of the stack
	BOOLEAN        Started;             //indicate the device has been started 
    BOOLEAN        Removed;            //indicate the device has been removed 
    ULONG          UsageCount;          //indicate how many outstandIO is served
    KEVENT         RemoveEvent; // an event to sync outstandIO to zero.
   
	BOOLEAN        Occupyed;           //indicate the device has been opened by an application  
#endif
	ULONG NtDeviceNumber;	// Zero-based device num	

#if _WIN32_WINNT==0x0500
	BOOLEAN             PortWasMapped;  // If TRUE, we have to unmap on unload
#endif
	PUCHAR PortBase;		// First control register
	ULONG PortSpan;
	
	PKINTERRUPT pInterrupt;	// Interrupt object

	ULONG cMapRegs;			// Count of mapping regs

	UCHAR	DeviceStatus;	// Most recent status

	OVERLAY_WINDOW OverlayWindow; //Size and status of overlay window

#if _WIN32_WINNT==0x0400
	PADAPTER_OBJECT pAdapter;     //Adapter object for the bus master DMA
#else
	PDMA_ADAPTER pAdapter;     //Adapter object for the bus master DMA
#endif

	//Audio stream buffer 
	DATACOMMONBUFFER DataCommonBuffer1;
	AUDIODESPLIST AudioBufferList1;
	AUDIODESP DespBuffer1[NUMOFAUDIODESCRIPTOR];
	BOOLEAN DataReceiving[2];

	//Common buffer of second data channel, using audio channel 1
    DATACOMMONBUFFER DataCommonBuffer2;
	AUDIODESPLIST AudioBufferList2;
	AUDIODESP DespBuffer2[NUMOFAUDIODESCRIPTOR];
	//BOOLEAN DataReceiving2;

	DATACOMMONBUFFER BitmapCommonBuffer;

	//RPS support data structure
	struct {
		ULONG RPSBuffer[RPSBUFFERSIZE];
		ULONG PhysicalAddress;
	}RPS[2];

	//PCI bus parameters
	ULONG BusNumber;
	ULONG SlotNumber;
	ULONG PhyPortBase;

    //Callers of MmGetSystemAddressForMdl must be running at IRQL <= DISPATCH_LEVEL,
	//so data buffer associated with IRP must be mapped in StartIo function
	PVOID ReadIrpDataBuffer;

	//Clipping control
	ULONG outformat;  //HPS output format and clipping control
	struct{
		ULONG ClipDmaBuffer[CLIPPINGDMABUFFERSIZE];
	}Clips[2];

	//Vide and audio data rate control
	USHORT VideoDataRate[2];
	
	USHORT AudioDataRate[2];

	//Data filter
	ULONG DataFilter[2];

	//Video scaler parameters
	int VideoType[2];
	int nPreVideoType[2];
	ULONG NIP; //pixels per line
	ULONG NIL; //number of lines
	//ULONG NIP2; //pixels per line
	ULONG NIL2; //number of lines
	ULONG lNumOfRect[2];

	USHORT BoardVersion;
	USHORT VolumeControl;
	USHORT Double;
	USHORT VideoSourceSelect;
	USHORT Compress;
	USHORT ExtraFunctions;
	ULONG SerialsNo;
	DISPLAY_PARAMETER DisplayParameter;
	//ULONG PacketLost;
	//ULONG PacketLost2;
	AVE2K_STATISTICS Stat[2];
	KSPIN_LOCK ReadLock;
	KSPIN_LOCK ReadLock2;

	UCHAR Export;
	UCHAR Export2;
	USHORT AlarmConfig;
	//Alternate channel related datas
	KDEVICE_QUEUE AlternateIrpQueue;
	KDPC AlternateDpc;
	PIRP CurrentAlternateIrp;
	PVOID CurrentAlternateIrpBuffer;
	
	//IER register shadow
	ULONG IERValue;
	ULONG FrameRate;
	KSPIN_LOCK DebiLock;
	KSPIN_LOCK RPSLock;
	ULONG ExStat[2];
	ULONG nErrorRecover[2];
	//ULONG nEat[2];
	ULONG nStillStuff[2];
	ULONG nStuffLimit[2];
	ULONG TestCount[2];
	ULONG nTotalCount[2];
	KEVENT EventVDone;
	int Recovering[2];
	int bBitmapCaptureLock;
	LOGO Logo[2];
	int bLogoEnable[2];
	USHORT nOnFrame[2];
	USHORT nOffFrame[2];
	BOOLEAN bMode2[2];
	BOOLEAN bFirstVideo;
	BOOLEAN bBitmapOK;
	int bFrmAdjMode2;
	//for date time OSD
	KDPC OSDDpc;
	KTIMER OSDTimer;
	int nOSDMode;
	int nOSDUpdate;
	int nDay;
	int nSpaceChar;
	unsigned char pChannelName[50];
	int nReplace;
	int nTimeBias;
	int nOSDHorOff;
	int nOSDVerOff;
	int nOSDTextRow;
	int nOSDCorner;
	BOOLEAN bOSDMaskEnable;
	int nOSDMaskLeft;
	int nOSDMaskTop;
	int nOSDMaskRight;
	int nOSDMaskBottom;
	int nOSDMaskGridTop;
	int nOSDMaskGridBottom;
	int nOSDMaskGridLeft;
	int nOSDMaskGridRight;
	int nAudioThres;
	int bDataTSLRunnning;
	int lMaxLevel;
	//int bAudioDetected;
	int nMaxAudio;
	int bOSDBorder;
	KTIMER AudioTimer;
	KDPC AudioDpc;
	
} DEVICE_EXTENSION, *PDEVICE_EXTENSION;

#define ERR_NONE	0
#define ERR_RESYNC	1
#define ERR_RESTART 2
#define ERR_SHIFT	3
#define ERR_RELOAD	4

#define SUBVENDOR_THAKRAL 0x5468 //"Th"
#define SUBSYS_AVE2KREVA1	0x2000
#define SUBSYS_AVE2KREVA2	0x2001
#define SUBSYS_AVE2KREVA21	0x0003
#define SUBSYS_AVE2KDREVB2	0x2002
#define SUBSYS_AVE2KMREVC2	0x2003
#define SUBSYS_AVE2KREVD1Q	0x2004//XQ
#define SUBSYS_AVE2KREVD1D	0x2005//XD Pro
#define SUBSYS_AVE2KREVD1S	0x2006//XS Pro

//BoardVerisons
//REVA0 is REVA1 without EEPROM or EEPROM not Initialzed
enum {REVA0=0, REVA1, REVA2, REVB2, REVC2, REVD1}; 
enum {VOL_NONE=0, VOL_X9221, VOL_X9241, VOL_M62429, VOL_ANASWTCH};

#if _WIN32_WINNT==0x0400
//++
// Description:
//		Temporary struct used during driver 
//		initialization to hold config data about a
//		single device.
//
// Access:
//		Allocated from PAGED POOL
//		Available ONLY at IRQL PASSIVE_LEVEL
//--
typedef struct _DEVICE_BLOCK 
{
	//PCI parameters
	ULONG BusNumber;
	ULONG SlotNumber;

	//
	// Original values pulled from the PCI configuration space
	//
	PHYSICAL_ADDRESS OriginalPortBase;     //Base address of SAA7146A registers
	PULONG PortBase;
	ULONG PortSpan;	

    //Interrupt parameters
	ULONG OriginalVector;
	ULONG SystemVector;
	KIRQL Dirql;
	ULONG Level;
	KAFFINITY Affinity;
	KINTERRUPT_MODE InterruptMode;
	USHORT BoardVersion;
} DEVICE_BLOCK, *PDEVICE_BLOCK;


//++
// Description:
//		Temporary struct used during driver 
//		initialization to hold hardware 
//		configuration data about all devices.
//
// Access:
//		Allocated from PAGED POOL
//		Available ONLY at IRQL PASSIVE_LEVEL
//--
typedef struct _DEVICE_CONFIG
{
	//
	// Number of devices in the array
	//
	ULONG	Count;
	//
	// One array-element for each device
	//
	DEVICE_BLOCK Device[ AVE2K_MAXIMUM_DEVICES ];
} DEVICE_CONFIG, *PDEVICE_CONFIG;
#endif

//
// Prototypes for globally defined functions...
//
//
// init.c
//
NTSTATUS
DriverEntry(
	IN PDRIVER_OBJECT DriverObject,
	IN PUNICODE_STRING RegistryPath
	);

//
// unload.c
//
VOID
Ave2kDriverUnload(
	IN PDRIVER_OBJECT DriverObject
	);

VOID
Ave2kReleaseHardware(
	IN PDRIVER_OBJECT DriverObject
	);

//
// init.c
//
#if _WIN32_WINNT==0x0400
NTSTATUS
Ave2kGetHardwareInfo(
	IN PDRIVER_OBJECT DriverObject,
	IN PUNICODE_STRING RegistryPath,
	OUT PDEVICE_CONFIG ConfigList
	);
#else
NTSTATUS
Ave2kGetVGAHardwareInfo();
#endif

#if _WIN32_WINNT==0x0400
NTSTATUS
Ave2kReportHardwareUsage(
	IN PDRIVER_OBJECT DriverObject,
	IN PDEVICE_CONFIG ConfigList
	);
#endif
//
// dispatch.c
//
NTSTATUS
Ave2kDispatchOpenClose(
	IN PDEVICE_OBJECT pDO,
	IN PIRP Irp
	);

NTSTATUS 
Ave2kDispatchWrite(
	IN PDEVICE_OBJECT pDO,
	IN PIRP Irp
	);

NTSTATUS 
Ave2kDispatchRead(
	IN PDEVICE_OBJECT pDO,
	IN PIRP Irp
	);

NTSTATUS
Ave2kDispatchCleanup(
	IN PDEVICE_OBJECT DeviceObject,
	IN PIRP Irp
	);
//
// transfer.c
//
VOID
Ave2kStartIo(
	IN PDEVICE_OBJECT DeviceObject,
	IN PIRP Irp
	);

BOOLEAN
Ave2kIsr(
	IN PKINTERRUPT Interrupt,
	IN PVOID ServiceContext
	);

VOID
Ave2kDpcForIsr(
    IN PKDPC Dpc,
    IN PVOID DeferredContext,
    IN PVOID SystemArgument1,
    IN PVOID SystemArgument2
	);

//called on behalf of DeviceIoControl
NTSTATUS
Ave2kDispatchDeviceIoControl(
	IN PDEVICE_OBJECT pDO,
	IN PIRP Irp
	);

//Cancel.c
//++
// Function:
//		Ave2kCancelIrp
//
// Description:
//		This function gets called to cancel
//		an IRP that's somewhere between the
//		Device Queue and the beginning
//		of processing in the Start I/O routine.
//
// Arguments:
//		Pointer to the Device object
//		Pointer to the target IRP
//
// Return Value:
//		(None)
//
// Synchronization:
//		This routine is called at DISPATCH_LEVEL
//		IRQL, holding the Cancel spin lock.
//
//--
VOID
Ave2kCancelIrp(
	IN PDEVICE_OBJECT DeviceObject,
	IN PIRP Irp
	);

//++
// Function:
//		Ave2kCancelChannel2Irp
//
// Description:
//		This function gets called to cancel
//		an IRP of Channel2
//
// Arguments:
//		Pointer to the Device object
//		Pointer to the target IRP
//
// Return Value:
//		(None)
//
// Synchronization:
//		This routine is called at DISPATCH_LEVEL
//		IRQL, holding the Cancel spin lock.
//
//--
VOID
Ave2kCancelChannel2Irp(
	IN PDEVICE_OBJECT DeviceObject,
	IN PIRP Irp
	);

//
// Make sure device interrupts are OFF
//
BOOLEAN Ave2kDisableInterrupts(PDEVICE_EXTENSION pDevExt);

//Set Value of IER of SAA7146
BOOLEAN Ave2kSetInterrupts(PDEVICE_EXTENSION pDevExt);
//I had to move this function protype from audiostream.h to here 
//because audiostream.h was included before definition of PDEVICE_EXTENSION
BOOLEAN AudioDespListRead(PDEVICE_EXTENSION pDE, ULONG BufLen, int nChannel);

BOOLEAN ErrorRecover(PDEVICE_EXTENSION pDE, int nChannel);

#if _WIN32_WINNT==0x0500
NTSTATUS
Ave2kAddDevice(
    IN PDRIVER_OBJECT DriverObject,
    IN PDEVICE_OBJECT PhysicalDeviceObject
    );


NTSTATUS
Ave2kDispatchPnp (
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp
    );

NTSTATUS
Ave2kStartDevice (
    IN PDEVICE_OBJECT    DeviceObject,
    IN PIRP             Irp
    );

NTSTATUS
Ave2kDispatchPower(
    IN PDEVICE_OBJECT    DeviceObject,
    IN PIRP              Irp
    );
NTSTATUS 
Ave2kDispatchSystemControl(
    IN PDEVICE_OBJECT    DeviceObject,
    IN PIRP              Irp
    );

NTSTATUS 
Ave2kCompletionRoutine(
    IN PDEVICE_OBJECT   DeviceObject,
    IN PIRP             Irp,
    IN PVOID            Context
    );

LONG
Ave2kIoIncrement(
    IN  PDEVICE_EXTENSION   DeviceExtension
    );   

LONG
Ave2kIoDecrement(
    IN  PDEVICE_EXTENSION   DeviceExtension
    );   
#endif

#endif	// _AVE2K_DRIVER

⌨️ 快捷键说明

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