Hi guys,
I write driver for PCI device with scatter gather dma
I have almost all done, but when I tried driver on 64bit, it didnt work.
I am attaching two techniques which I tried.
Goal is allocate some memory in lower 32bit range, because my device doesnt support 64bit addresing.
Problem is in second technique when I want to write to the buffer from driver. Unfortunately I need to store some values in thi s buffer of my PCIE device. It cause BSOD.
First technique works well, but allocated address is bellow 4GB only on 32 bit systems. So it fails on 64bit systems.
Thank you in advance, Ondrej
//first technique - good
sgDescVA = MmAllocateNonCachedMemory(sgDescLength);
RtlZeroMemory(sgDescVA,sgDescLength);
deviceData->ScatterGatherDescMdl = IoAllocateMdl(sgDescVA,sgDescLength,FALSE,FALSE,NULL);
MmBuildMdlForNonPagedPool(deviceData->ScatterGatherDescMdl);
sgDescVA = MmGetMdlVirtualAddress(deviceData->ScatterGatherDescMdl);
//writing to the buffer, no problems
RtlZeroMemory(sgDescVA,sgDescLength); //OK
//second technique - bad
lowAddr.QuadPart = 0;
highAddr.QuadPart = 0xFFFFFFFF; //4GB
sgDescVA = MmAllocateMappingAddress(sgDescLength,‘tag2’);
deviceData->ScatterGatherDescMdl = MmAllocatePagesForMdl(lowAddr, highAddr, lowAddr, sgDescLength);
__try
{
//doesnt works with/without MmProbeAndLockPages, I tried both alternatives
//MmProbeAndLockPages(deviceData->ScatterGatherDescMdl, KernelMode, IoModifyAccess);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
//there I tried both MmMapLockedPagesWithReservedMapping and MmMapLockedPagesSpecifyCache
//a
sgDescVA = MmMapLockedPagesWithReservedMapping(sgDescVA,‘tag2’, deviceData->ScatterGatherDescMdl,MmNonCached);
//b
//sgDescVA = MmMapLockedPagesSpecifyCache(deviceData->ScatterGatherDescMdl, KernelMode, MmNonCached, sgDescVA, FALSE, NormalPagePriority);
//test
sgDescVA = MmGetMdlVirtualAddress(deviceData->ScatterGatherDescMdl);
//riting to the buffer, it cause bsod
RtlZeroMemory(sgDescVA,sgDescLength); //cause BSOD everytime