/
/
初始化用于DMA编程的三个对象
NTSTATUS status;
PDEVICE_CONTEXT pDeviceContext;
WDF_DMA_ENABLER_CONFIG dmaConfig
=
{
0
};
WDFDMAENABLER DmaEnabler;
PAGED_CODE();
pDeviceContext
=
GetDeviceContext(Device);
KdPrint((
"自动获取边界大小:[%d]\n"
, WdfDeviceGetAlignmentRequirement(Device)));
/
/
设置DMA数据缓冲区地址边界:
16
字节对齐
WdfDeviceSetAlignmentRequirement(Device, FILE_OCTA_ALIGNMENT);
/
/
创建一个DMA适配器
dmaConfig.Size
=
sizeof(dmaConfig);
WDF_DMA_ENABLER_CONFIG_INIT(&dmaConfig,
WdfDmaProfileScatterGather64Duplex,
MAXNLEN);
status
=
WdfDmaEnablerCreate(Device,
&dmaConfig,
WDF_NO_OBJECT_ATTRIBUTES,
&DmaEnabler);
if
(!NT_SUCCESS(status)) {
if
(status
=
=
STATUS_INVALID_PARAMETER) {
KdPrint((
"检测到无效参数\n"
));
}
else
if
(status
=
=
STATUS_INSUFFICIENT_RESOURCES) {
KdPrint((
"内存不足,无法构造新的 DMA 启用器对象\n"
));
}
else
if
(status
=
=
STATUS_INFO_LENGTH_MISMATCH) {
KdPrint((
"WDF_DMA_ENABLER_CONFIG结构的大小不正确\n"
));
}
else
if
(status
=
=
STATUS_NOT_SUPPORTED) {
KdPrint((
" 驱动程序在早于 Windows 8 的操作系统上请求了 DMA 版本 3\n"
));
}
else
{
KdPrint((
"DMA创建失败:[%d]\n"
,status));
}
return
status;
}