Re: [ntdev] GetScatterGatherList seems not worked

I’m dreadfully sorry, I’m too anxious to explain my question yesterday.
I mean that the scatter gather list which get from GetScatterGatherList, seems not work.
I translate the SGList to my own link list, then write the list head to my device’s Dma engine.
Observing from the device, it has transfered data to the physical address discribed in the list correctly, and with no error TLP.
By add KdPrint for logging, I can confirm the address I read form SgList is the same as the device received, so i think this bug must be in my driver code.
In order to prove my point, I hava allocated a new WDFCommonBuffer and put the common buffer address as the first element of my link list.
After enable the device, I can see the common buffer has been filled with correct data by WinDbg.
So, I guess the SgList that I geted form the GetScatterGatherList, has the wrong physical adress. But I have no idea to prove and solve it.--------------------------------

----- ԭʼ?ʼ? -----
???ˣ?Phil Selmer
?ռ??ˣ?“Windows System Software Devs Interest List”
???⣺Re: [ntdev] GetScatterGatherList seems not worked
???ڣ?2016??10??22?? 19??57??

Have you tried WdfDmaEnablerCreate and then using WdfDmaEnablerWdmGetDmaAdapter? What is preventing you from using the WDF DMA? I had a complex DMA setup that I was able to port to KMDF from WDM. Check out the PLX9x5x sample for insight.

- Phil

On Sat, Oct 22, 2016 at 7:29 AM, lizzoe wrote:

Hello,
I want to use Direct I/O to implement DMA on my own driver, but it seems doesn’t work. Here’s my steps(For some reasons, I can not choose the way of WDF’s Dmatransaction):
1, allocate DMA adaptor during the driver init. DEVICE_DESCRIPTION dd; RtlZeroMemory(&dd, sizeof(dd)); dd.Version = DEVICE_DESCRIPTION_VERSION2; dd.Master = TRUE; dd.ScatterGather = TRUE; dd.InterfaceType = PCIBus; dd.MaximumLength = MAXIMUM_TRANSFER_LENGTH; dd.Dma64BitAddresses = TRUE;
ULONG NumberOfMapRegisters = 100;
adapter = IoGetDmaAdapter(WdfDeviceWdmGetPhysicalDevice(DevExt->Device), &dd, &NumberOfMapRegisters);
KdPrint((“DMA Adapter can afford %d Map Registers”, NumberOfMapRegisters));
if (!adapter) { TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP, “WdfDmaEnablerCreate failed: %!STATUS!”, status); return STATUS_NDIS_ADAPTER_NOT_FOUND; }
DevExt->DmaChannel[i].DmaAdaptor = adapter;
2, Make a DeviceIOContorl with Direct I/O #define PCIe_IOCTL_CREATE_DMA_CHANNEL CTL_CODE(FILE_DEVICE_UNKNOWN, 0x804, METHOD_DIRECT_FROM_HARDWARE, FILE_ANY_ACCESS)
3, In EvtIoDeviceControl routine PDEVICE_OBJECT pDevice = WdfDeviceWdmGetPhysicalDevice(DevExt->Device); status = WdfRequestRetrieveInputWdmMdl(Request, &mdl); virtualAddress = MmGetMdlVirtualAddress(mdl); length = MmGetMdlByteCount(mdl); status = adapter->DmaOperations->GetScatterGatherList( adapter, pDevice, mdl, virtualAddress, length, SGListExcution, DevExt, TRUE );4, In SGListExcution, get the SGList to my device’s DMA engine dteVA = (PDMA_TRANSFER_ELEMENT)devExt->ReadCommonBufferBase; dteLA = (devExt->ReadCommonBufferBaseLA.QuadPart + sizeof(DMA_TRANSFER_ELEMENT)); for (i = 0; i < SgList->NumberOfElements; i++) {
dteVA->LogicalAddr = SgList->Elements[i].Address.QuadPart; dteVA->Length = SgList->Elements[i].Length;
KdPrint((“[Element %d]LogicalAddr: %llx, Length:%llu”, i, dteVA->LogicalAddr, dteVA->Length));
// Reserved dteVA->Status = 0xFFFF; dteVA->VirturalAddr = 0;
offset += SgList->Elements[i].Length;
// // If at end of SgList, then set LastElement bit in final NTE. // if (i == SgList->NumberOfElements - 1) { dteVA->NextDescAddr = 0; break; } else { dteVA->NextDescAddr = dteLA; }

//Adjust the next DMA_TRANSFER_ELEMEMT
dteVA++; dteLA += sizeof(DMA_TRANSFER_ELEMENT);
KdPrint((“dteVA is %llx, dteLA is %llx”, dteVA, dteLA)); } After doing this, I enable my device to write data to the physical address. But there’s no data found after the divice finish writing. my user space buffer is still nothing.
I don’t know in which part the problem occurs?
Thank you


NTDEV is sponsored by OSR

Visit the list online at:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at

To unsubscribe, visit the List Server section of OSR Online at


NTDEV is sponsored by OSR

Visit the list online at:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at

To unsubscribe, visit the List Server section of OSR Online at