windows server 2003下驱动问题

dsp123 2009-05-14 02:45:30
我用的是Xilinx的ML505这块开发板,Xilinx提供的硬件代码、驱动和应用软件PCI_express_DMA_Freeware_Virtex。
这个驱动要分配一段连续的内存来读写。下面两个函数是在EvtDeviceAdd调用。 EvtDeviceAdd is called by the framework in response to AddDevice call from the PnP manager

DevExt->BufferLogicalAddress = MmAllocateContiguousMemory(DevExt->BufferSize, physicalAddress);

physicalAddress = MmGetPhysicalAddress((PVOID)DevExt->BufferLogicalAddress);

下面的函数是在PCIEIOCtrlCode调用。
case IOCTL_GET_BUFFERADDRESS:
{
phyAddress.HighPart = 0;
phyAddress.LowPart = (ULONG)devExt->BufferPhysicalAddress;

devExt->BufferSystemVirtualAddress = MmMapIoSpace(phyAddress, PCIE_BUFFER_SIZE, MmNonCached);

devExt->BufferMdl = IoAllocateMdl(devExt->BufferSystemVirtualAddress, PCIE_BUFFER_SIZE, FALSE, FALSE, NULL);

MmBuildMdlForNonPagedPool(devExt->BufferMdl);

devExt->BufferUserVirtualAddress = (PVOID)(((ULONG)PAGE_ALIGN(MmMapLockedPages(devExt->BufferMdl, UserMode))) + MmGetMdlByteOffset(devExt->BufferMdl));

}


这个驱动在windows xp下可以正常使用,但是在windows server 2003下就会出现蓝屏,错误的地方是这样一个函数:
MmMapLockedPages(devExt->Buffer2Mdl, UserMode),我用windbg调试,显示:MmUnmapLockedPages called when not at APC_LEVEL or below.

我把usermode改为kernelmode就可以,我还用MmMapLockedPagesSpecifyCache(devExt->BufferMdl, UserMode,MmNonCached,NULL,FALSE,NormalPagePriority)
来代替,也是usermode的问题,为什么一样的函数在xp下可以用,在server下就不能用呢?

但是改为kernelmode后函数返回的地址是内核地址,用户态不能用,所以不知道该怎么办啊。
...全文
112 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yachli 2011-06-24
  • 打赏
  • 举报
回复
我也碰到了此问题,不知后来您怎么解决的
dsp123 2009-06-01
  • 打赏
  • 举报
回复
后来在OSR上查了,MmAllocateContiguousMemory+MmMapLockedPages不是一个很好的方法,在不同的平台上可能会有问题,算了,结贴~~~~
dsp123 2009-05-25
  • 打赏
  • 举报
回复
没有人会吗?
dsp123 2009-05-18
  • 打赏
  • 举报
回复
我还用了另外一种方法:
physicalAddress.LowPart = 0x80000000;
physicalAddress.HighPart = 0x0;

SkipBytes.LowPart=0x00001000;
SkipBytes.LowPart=0x0;
DevExt->BufferMdl = MmAllocatePagesForMdl(LowAddress,
physicalAddress,
SkipBytes,
DevExt->BufferSize);
if(!DevExt->BufferMdl)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
DevExt->BufferPhysicalAddress = MmGetSystemAddressForMdlSafe(
DevExt->BufferMdl,
NormalPagePriority);

DevExt->BufferUserVirtualAddress= MmMapLockedPagesSpecifyCache(DevExt->BufferMdl,
UserMode,
MmNonCached,
NULL,
FALSE,
NormalPagePriority);

还是在MmMapLockedPagesSpecifyCache这个函数处出现蓝屏。
driverstudent 2009-05-15
  • 打赏
  • 举报
回复

mark

21,597

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 驱动开发/核心开发
社区管理员
  • 驱动开发/核心开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧