struct _tag_DrvMapApp_Reg{
PHYSICAL_ADDRESS DevBaseAddr; //物理地址或者逻辑地址(设备访问需要)
PVOID DrvBaseAddr; //内核态虚拟地址(驱动程序访问需要)
PVOID AppBaseAddr; //用户态虚拟地址(应用程序访问需要)
unsigned long int length;
int isBusy;
PMDL pMdl;
WDFDMAENABLER dmaEnable;
WDFCOMMONBUFFER commonBuffer;
WDFDMATRANSACTION DmaTransaction;
WDFINTERRUPT Interrupt;
WDFREQUEST Request;
}DrvMapAppReg1;
ULONG Counter_i; // 资源计数器,记录WDF框架分配给设备的资源个数,counter for WdfCmResourceListGetCount
(ResourceListTranslated)
ULONG OffsetAddressFromApp; // get offset address that is given by application 偏移地址(由应用程序传递过来)
} DEVICE_CONTEXT, *PDEVICE_CONTEXT;
4.EvtDeviceAdd函数中
#define DMA_SIZE (900*1024)
5.在EvtIoDeviceControl例程中:
类型定义
typedef struct _tag_DMA_MEMORY{
void * addr; //注意环境切换 win32 or x64 指针变量的长度不一样
unsigned long length;
}DMA_MEMORY_Header, *PDMA_MEMORY_Header;
case PCIeCardDrv_IOCTL_GET_THREAD_ADDR:
//outBuffer返回进程需要使用DMA空间的首地址和长度,在switch之前已经获取
KdrPrint("EvtIoDeviceControl: I am GET_THREAD_ADDR!\n");
MapSharedMemory2App(pDevContext, (PDMA_MEMORY_Header)outBuffer);
WdfRequestCompleteWithInformation(Request, status, OutputBufferLength);
if (!NT_SUCCESS(status)){
goto Exit;
}
break;