Okay I found what I looks like an issue.
I tried to use 16KB buffers instead of 64K and tried to set the alignment accordingly.
My code for setting up the DMA/common buffers is as follows:
#define FULLBUFF 16384
//
// evio DMA_TRANSFER_ELEMENTS must be 16Kbyte aligned
//
WdfDeviceSetAlignmentRequirement(DevExt->Device,
16383);
//
// Create a new DMA Enabler instance.
// for Common Buffer
//
{
WDF_DMA_ENABLER_CONFIG dmaConfig;
WDF_DMA_ENABLER_CONFIG_INIT(&dmaConfig,
WdfDmaProfilePacket,
DevExt->MaximumTransferLength);
TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
" - The DMA Profile is WdfDmaProfilePacket");
//
// Opt-in to DMA version 3, which is required by
// WdfDmaTransactionSetSingleTransferRequirement
//
dmaConfig.WdmDmaVersionOverride = 3;
status = WdfDmaEnablerCreate(DevExt->Device,
&dmaConfig,
WDF_NO_OBJECT_ATTRIBUTES,
&DevExt->DmaEnabler);
if (!NT_SUCCESS(status)) {
TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP,
"WdfDmaEnablerCreate failed: %!STATUS!", status);
return status;
}
}
//
// Allocate common buffer for building reads
//
for (i = 0; i < 6; i++)
{
status = WdfCommonBufferCreate(DevExt->DmaEnabler,
FULLBUFF,
WDF_NO_OBJECT_ATTRIBUTES,
&DevExt->ADCBuffers[i].ReadCommonBuffer);
if (!NT_SUCCESS(status)) {
TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP,
"WdfCommonBufferCreate (read) failed %!STATUS!", status);
return status;
}
DevExt->ADCBuffers[i].ReadCommonBufferSize = FULLBUFF;
DevExt->ADCBuffers[i].ReadCommonBufferBase =
WdfCommonBufferGetAlignedVirtualAddress(DevExt->ADCBuffers[i].ReadCommonBuffer);
DevExt->ADCBuffers[i].ReadCommonBufferBaseLA =
WdfCommonBufferGetAlignedLogicalAddress(DevExt->ADCBuffers[i].ReadCommonBuffer);
TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP,
"Alignment is %d", WdfDeviceGetAlignmentRequirement(DevExt->Device));
TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP,
"Low part %d is %x", i, DevExt->ADCBuffers[i].ReadCommonBufferBaseLA.LowPart);
TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP,
"High part %d is %x", i, DevExt->ADCBuffers[i].ReadCommonBufferBaseLA.HighPart);
RtlZeroMemory(DevExt->ADCBuffers[i].ReadCommonBufferBase,
DevExt->ADCBuffers[i].ReadCommonBufferSize);
TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,
"ReadCommonBuffer 0x%p (#0x%I64X), length %I64d",
DevExt->ADCBuffers[i].ReadCommonBufferBase,
DevExt->ADCBuffers[i].ReadCommonBufferBaseLA.QuadPart,
WdfCommonBufferGetLength(DevExt->ADCBuffers[i].ReadCommonBuffer));
}
When I run a trace on this I get.
00000009 evio 4 96 1 9 11\18\2019-15:14:37:413 - The DMA Profile is WdfDmaProfilePacket
00000010 evio 4 96 1 10 11\18\2019-15:14:37:413 Alignment is 16383
00000011 evio 4 96 1 11 11\18\2019-15:14:37:413 Low part 0 is 3f83d000
00000012 evio 4 96 1 12 11\18\2019-15:14:37:413 High part 0 is 0
00000013 evio 4 96 1 13 11\18\2019-15:14:37:413 ReadCommonBuffer 0xFFFFBE829843D000 (#0x3F83D000), length 16384
00000014 evio 4 96 1 14 11\18\2019-15:14:37:413 Alignment is 16383
00000015 evio 4 96 1 15 11\18\2019-15:14:37:413 Low part 1 is 3f8f4000
00000016 evio 4 96 1 16 11\18\2019-15:14:37:413 High part 1 is 0
00000017 evio 4 96 1 17 11\18\2019-15:14:37:413 ReadCommonBuffer 0xFFFFBE82984F4000 (#0x3F8F4000), length 16384
00000018 evio 4 96 1 18 11\18\2019-15:14:37:413 Alignment is 16383
00000019 evio 4 96 1 19 11\18\2019-15:14:37:413 Low part 2 is 3f8a8000
00000020 evio 4 96 1 20 11\18\2019-15:14:37:413 High part 2 is 0
00000021 evio 4 96 1 21 11\18\2019-15:14:37:413 ReadCommonBuffer 0xFFFFBE82984A8000 (#0x3F8A8000), length 16384
00000022 evio 4 96 1 22 11\18\2019-15:14:37:413 Alignment is 16383
00000023 evio 4 96 1 23 11\18\2019-15:14:37:413 Low part 3 is 3f914000
00000024 evio 4 96 1 24 11\18\2019-15:14:37:413 High part 3 is 0
00000025 evio 4 96 1 25 11\18\2019-15:14:37:413 ReadCommonBuffer 0xFFFFBE8298514000 (#0x3F914000), length 16384
00000026 evio 4 96 1 26 11\18\2019-15:14:37:413 Alignment is 16383
00000027 evio 4 96 1 27 11\18\2019-15:14:37:413 Low part 4 is 3f82c000
00000028 evio 4 96 1 28 11\18\2019-15:14:37:413 High part 4 is 0
00000029 evio 4 96 1 29 11\18\2019-15:14:37:413 ReadCommonBuffer 0xFFFFBE829842C000 (#0x3F82C000), length 16384
00000030 evio 4 96 1 30 11\18\2019-15:14:37:413 Alignment is 16383
00000031 evio 4 96 1 31 11\18\2019-15:14:37:413 Low part 5 is 3f8ae000
00000032 evio 4 96 1 32 11\18\2019-15:14:37:413 High part 5 is 0
00000033 evio 4 96 1 33 11\18\2019-15:14:37:413 ReadCommonBuffer 0xFFFFBE82984AE000 (#0x3F8AE000), length 16384
Looking at
Low part 0 is 3f83d000
For example.
That looks to me to be aligned on a 4KB boundary, which if true would explain why I am having issues (not with my hardware but with my code).
For a 16KB aligned boundary shouldn’t the lowest 14 bits of the device address always be zero?
Am I reading something incorrectly, doing something stupid or something else?
Any help would be appreciated.