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

📄 comemdrv.h

📁 一个主设备驱动程序绝对可用
💻 H
字号:
//////////////////////////////////////////////////////////////////////
//
// File:      comemdrv.h
// $Archive: /ComemL/Host/ComemLif/comemdrv.h $
//
// Purpose:
//   this header file contains the IOCTL definitions, structures,
//   and status codes used to communicate with the COMEM device
//   driver.
//  
// Copyright (c) 2002 SEED, Inc.  May not be reproduced without
// permission.  See the license agreement for more details.
//
//////////////////////////////////////////////////////////////////////

#ifndef __comemdrv_h__
#define __comemdrv_h__

//////////////////////////////////////////////////////////////////////
//
// miscellaneous defines
//
//////////////////////////////////////////////////////////////////////

#define COMEM_Major		1
#define COMEM_Minor		0
#define COMEM_DeviceID		UNDEFINED_DEVICE_ID    /* this is only needed if we publish API entries for Win16 apps */
#define COMEM_Init_Order	UNDEFINED_INIT_ORDER

#define PCI_ENUM_FUNC_GET_DEVICE_INFO   0
#define PCI_ENUM_FUNC_SET_DEVICE_INFO   1


//////////////////////////////////////////////////////////////////////
// Define generic types -- the user may not include win.h
//////////////////////////////////////////////////////////////////////
#ifndef NULL
#define NULL ((void *) 0)
#endif 

#ifndef _UCHAR_DEFINED
#define _UCHAR_DEFINED
typedef unsigned char UCHAR;
#endif // !_UCHAR_DEFINED

#ifndef _USHORT_DEFINED
#define _USHORT_DEFINED
typedef unsigned short USHORT;
#endif // !_USHORT_DEFINED

#ifndef _WORD_DEFINED
#define _WORD_DEFINED
typedef unsigned short WORD;
#endif // !_WORD_DEFINED

#ifndef _DWORD_DEFINED
#define _DWORD_DEFINED
typedef unsigned long DWORD;
#endif // !_DWORD_DEFINED

#ifndef _ULONG_DEFINED
#define _ULONG_DEFINED
typedef unsigned long ULONG;
#endif // !_ULONG_DEFINED

#define MAX_FRAGMENTS 16               // Maximum number of fragments permitted in memory map
#define COMEM_MAX_DEVICES 16           // Max number of co-memory devices in a system
#define COMEM_MAX_BARS   1             // Number of Base Address Registers in the PCI config space of co-mem
#ifndef PAGE_SIZE
#define PAGE_SIZE 4096                 // Page size in a Windows system
#define VendorId  0x12be
#define DeviceId  0x3042
#endif

#ifndef NO_ERROR
#define NO_ERROR           					(0)
#endif

#define ERROR_INVALID_REGION 				(-1)
#define ERROR_INVALID_ADDIN_ADDR 			(-2)
#define ERROR_OVERLAID_REGION 				(-3)
#define ERROR_BAD_PAGE_TABLE				(-4)
#define ERROR_MEMORY_ALLOC  				(-5)
#define ERROR_ALLOC_EXISTS					(-6)
#define ERROR_NO_DRIVER    					(-7)
#define ERROR_INVALID_COMEM_ID				(-8)
#define ERROR_DEVICE_NOT_FOUND				(-9)
#define ERROR_UNKNOWN 						(-10)

#define FILE_DEVICE_COMEM  FILE_DEVICE_UNKNOWN
#define COMEM_IOCTL_INDEX  0x801				// Base value for IOCTLs used here

//////////////////////////////////////////////////////////////////////
//
// IOCTL defines
//
//////////////////////////////////////////////////////////////////////
#define IOCTL_COMEM_GETSTATUS                   CTL_CODE(FILE_DEVICE_COMEM ,   \
                                                         COMEM_IOCTL_INDEX+0,  \
                                                         METHOD_BUFFERED,      \
                                                         FILE_ANY_ACCESS)

#define IOCTL_COMEM_GETVERSION                  CTL_CODE(FILE_DEVICE_COMEM ,   \
                                                         COMEM_IOCTL_INDEX+1,  \
                                                         METHOD_BUFFERED,      \
                                                         FILE_ANY_ACCESS)

#define IOCTL_COMEM_GETPCICFG                   CTL_CODE(FILE_DEVICE_COMEM ,   \
                                                         COMEM_IOCTL_INDEX+2,  \
                                                         METHOD_BUFFERED,      \
                                                         FILE_ANY_ACCESS)

#define IOCTL_COMEM_SETPCICFG                   CTL_CODE(FILE_DEVICE_COMEM ,   \
                                                         COMEM_IOCTL_INDEX+3,  \
                                                         METHOD_BUFFERED,      \
                                                         FILE_ANY_ACCESS)
#define IOCTL_COMEM_CREATEBARPTR                CTL_CODE(FILE_DEVICE_COMEM ,   \
                                                         COMEM_IOCTL_INDEX+9,  \
                                                         METHOD_BUFFERED,      \
                                                         FILE_ANY_ACCESS)

#define IOCTL_COMEM_DESTROYBARPTR               CTL_CODE(FILE_DEVICE_COMEM,    \
                                                         COMEM_IOCTL_INDEX+10, \
                                                         METHOD_BUFFERED,      \
                                                         FILE_ANY_ACCESS)

#define IOCTL_COMEM_ALLOCCONTIGMEM              CTL_CODE(FILE_DEVICE_COMEM,    \
                                                         COMEM_IOCTL_INDEX+11, \
                                                         METHOD_BUFFERED,      \
                                                         FILE_ANY_ACCESS)

#define IOCTL_COMEM_DEALLOCCONTIGMEM            CTL_CODE(FILE_DEVICE_COMEM ,   \
                                                         COMEM_IOCTL_INDEX+12, \
                                                         METHOD_BUFFERED,      \
                                                         FILE_ANY_ACCESS)
#define IOCTL_COMEM_INTERRUPSET                 CTL_CODE(FILE_DEVICE_COMEM ,   \
                                                         COMEM_IOCTL_INDEX+13, \
                                                         METHOD_BUFFERED,      \
                                                         FILE_ANY_ACCESS)


//////////////////////////////////////////////////////////////////////
//
// structures
//
//////////////////////////////////////////////////////////////////////
// Structure passed into IOCTL_COMEM_GETSTATUS
typedef struct  {
		DWORD comemID;		// A structure must have at least one member
		}GetStatusIn;

// Structure passed out of IOCTL_COMEM_GETSTATUS
typedef struct {
		DWORD status;           // Currently not used -- return 0 for no error
      DWORD referenceCount;   // Number of handles currently open for this device
		} GetStatusOut;

// Structure passed into IOCTL_COMEM_GETPCICFG
typedef struct 
{
   DWORD ComemId;
} GetPciCfgIn;

// Structure returned by IOCTL_COMEM_GETPCICFG
typedef struct GetPciCfgOut_t
{
    USHORT  VendorID;
    USHORT  DeviceID;
    USHORT  Command; 
    USHORT  Status;
    UCHAR   RevisionID;
    UCHAR   ProgIf;    
    UCHAR   SubClass;  
    UCHAR   BaseClass; 
    UCHAR   CacheLineSize;
    UCHAR   LatencyTimer; 
    UCHAR   HeaderType;   
    UCHAR   BIST;          
    ULONG   BaseAddresses[6];
	 ULONG	CardBusCISPtr;
    USHORT	SubsystemVendorID;
	 USHORT	SubsystemID;
	 ULONG	ROMBaseAddress;
    ULONG   Reserved2[2];
    UCHAR   InterruptLine; 
    UCHAR   InterruptPin;  
    UCHAR   MinimumGrant;  
    UCHAR   MaximumLatency;
    DWORD   status;
} GetPciCfgOut;

typedef struct _pci_config_header_0_t
{
    USHORT  VendorID;
    USHORT  DeviceID;
    USHORT  Command; 
    USHORT  Status;
    UCHAR   RevisionID;
    UCHAR   ProgIf;    
    UCHAR   SubClass;  
    UCHAR   BaseClass; 
    UCHAR   CacheLineSize;
    UCHAR   LatencyTimer; 
    UCHAR   HeaderType;   
    UCHAR   BIST;          
    ULONG   BaseAddresses[6];
	 ULONG	CardBusCISPtr;
    USHORT	SubsystemVendorID;
	 USHORT	SubsystemID;
	 ULONG	ROMBaseAddress;
    ULONG   Reserved2[2];
    UCHAR   InterruptLine; 
    UCHAR   InterruptPin;  
    UCHAR   MinimumGrant;  
    UCHAR   MaximumLatency;
} PCI_CONFIG_HEADER_0;

// Structure passed into by IOCTL_COMEM_SETPCICFG
typedef struct _SetPciCfgIn
{
    USHORT  VendorID;
    USHORT  DeviceID;
    USHORT  Command; 
    USHORT  Status;
    UCHAR   RevisionID;
    UCHAR   ProgIf;    
    UCHAR   SubClass;  
    UCHAR   BaseClass; 
    UCHAR   CacheLineSize;
    UCHAR   LatencyTimer; 
    UCHAR   HeaderType;   
    UCHAR   BIST;          
    ULONG   BaseAddresses[6];
	 ULONG	CardBusCISPtr;
    USHORT	SubsystemVendorID;
	 USHORT	SubsystemID;
	 ULONG	ROMBaseAddress;
    ULONG   Reserved2[2];
    UCHAR   InterruptLine; 
    UCHAR   InterruptPin;  
    UCHAR   MinimumGrant;  
    UCHAR   MaximumLatency;
    DWORD ComemID;
} SetPciCfgIn;

// Output structure to IOCTL_COMEM_DESTROYBARPTR
typedef struct
{
   DWORD status;
} AllocMemoryOut, DeallocMemoryOut, SetPciCfgOut, 
   DestroyLinPtrOut, DestroyBarPtrOut;

// Input structure for IOCTL_COMEM_CREATEBARPTR
typedef struct 
{
   DWORD comemID;
} CreateLinPtrIn, DestroyLinPtrIn, 
   DeallocMemoryIn, 
   CreateBarPtrIn, DestroyBarPtrIn;


// Structure used in internal allocation routines
// Output structure returned by IOCTL_COMEM_CREATELINPTR
typedef struct 
{
  struct AllocMemoryAllSubStruct
     {
     DWORD linearAddr;
     DWORD physAddr;
     DWORD size;
     } data[MAX_FRAGMENTS];
     DWORD status;
}  CreateLinPtrOut, AllocBlockAll;

typedef struct
{
	DWORD linBAR[COMEM_MAX_BARS];    // Addresses of comem in user space
	DWORD linPage;
	DWORD physPage;
    DWORD status;
} CreateBarPtrOut;

// input structure to IOCTL_COMEM_ALLOCCONTIGMEM
typedef struct 
{
   DWORD comemID;
   DWORD size;		// # of 4K pages (to be used later, currently defaults to 4)
} AllocContigMemIn;
// output structure to IOCTL_COMEM_ALLOCCONTIGMEM
typedef struct 
{
   DWORD linearAddr;
   DWORD physAddr;
   DWORD status;
} AllocContigMemOut;

// input structure to IOCTL_COMEM_DEALLOCCONTIGMEM 
typedef struct 
{
   DWORD comemID;
   DWORD linearAddr;
   DWORD physAddr;
} DeallocContigMemIn;

// output structure to IOCTL_COMEM_DEALLOCCONTIGMEM 
typedef struct 
{
   DWORD status;
} DeallocContigMemOut;

// input structure to IOCTL_COMEM_INTERRUPSET 
typedef struct 
{
   DWORD comemID;
   DWORD interrupset;
} InterruptSetIn;

#endif

⌨️ 快捷键说明

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