1 enable object
WDF_DMA_ENABLER_CONFIG dmaConfig;
WdfDeviceSetAlignmentRequirement(DevExt->Device, PCI9656_DTE_ALIGNMENT_16 );
WDF_DMA_ENABLER_CONFIG_INIT(&dmaConfig,
WdfDmaProfileScatterGather64Duplex,
DevExt->MaximumTransferLength);
status = WdfDmaEnablerCreate(DevExt->Device,
&dmaConfig,
WDF_NO_OBJECT_ATTRIBUTES,
&DevExt->DmaEnabler );
if (!NT_SUCCESS (status)) {
. . . //Error-handling code omitted
}
2 common buffer
· WdfCommonBufferGetAlignedVirtualAddress,which returns the system virtual address of the common buffer.内核地址;
· WdfCommonBufferGetAlignedLogicalAddress,which returns the device-bus logical address of the common buffer.
设备总线空间物理地址;
// Allocate common buffer forbuilding writes
DevExt->WriteCommonBufferSize =
sizeof( DMA_TRANSFER_ELEMENT) *DevExt->WriteTransferElements;
status = WdfCommonBufferCreate(DevExt->DmaEnabler,
DevExt->WriteCommonBufferSize,
WDF_NO_OBJECT_ATTRIBUTES,
&DevExt->WriteCommonBuffer );
if (!NT_SUCCESS(status)) {
. . . //Error-handling code omitted
}
DevExt->WriteCommonBufferBase =
WdfCommonBufferGetAlignedVirtualAddress(
DevExt->WriteCommonBuffer);
DevExt->WriteCommonBufferBaseLA=
WdfCommonBufferGetAlignedLogicalAddress(
DevExt->WriteCommonBuffer);
RtlZeroMemory(DevExt->WriteCommonBufferBase, DevExt->WriteCommonBufferSize);
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes,TRANSACTION_CONTEXT);
status = WdfDmaTransactionCreate(DevExt->DmaEnabler,
&attributes,
&DevExt->WriteDmaTransaction);
if(!NT_SUCCESS(status)) {
. . . //Error-handling code omitted
}
These addresses are required to programthe device in theEvtProgramDmacallback function.
3 transaction object
WdfDmaTransactionCreate,