从这一篇开始介绍几个比较重要的源文件和应用程序,并且会对其中一些关键代码进行说明。这些代码流程都是本人亲身测试可行的,但是由于当时调试时杂七杂八的东西加的太多,现在看起来有的地方的代码风马牛不相及,如果完全照搬的话可能行不通的,还是需要各位读者自行理解然后加以改进的。当然如果有问题也欢迎各位读者指出更正,谢谢!
driver.c
/*++
Module Name: driver.c
Abstract:This file contains the driver entry points and callbacks, sucn as DriverEnrty and EvtDeviceAdd function.
Environment: Kernel-mode Driver Framework
Time: 20181015
--*/
#include "driver.h"
/*
#ifdef ALLOC_PRAGMA
#pragma alloc_text (INIT, DriverEntry)
#pragma alloc_text (PAGE, PCIe_EvtDeviceAdd)
#pragma alloc_text (PAGE, PCIe_EvtDriverContextCleanup)
#endif
*/
NTSTATUS InitializeDMA(IN WDFDEVICE Device);
#define MAXNLEN 4096 //DMA传输最大字节长度
NTSTATUS
DriverEntry(
_In_ PDRIVER_OBJECT DriverObject,
_In_ PUNICODE_STRING RegistryPath
)
/*++
Routine Description:
DriverEntry initializes the driver and is the first routine called by the
system after the driver is loaded. DriverEntry specifies the other entry
points in the function driver, such as EvtDevice and DriverUnload.
Parameters Description:
DriverObject - represents the instance of the function driver that is loaded
into memory. DriverEntry must initialize members of DriverObject before it
returns to the caller. DriverObject is allocated by the system before the
driver is loaded, and it is released by the system after the system unloads
the function driver from memory.
RegistryPath - represents the driver specific path in the Registry.
The function driver can use the path to store driver related data between
reboots. The path does not store hardware instance specific data.
Return Value:
STATUS_SUCCESS if successful,
STATUS_UNSUCCESSFUL otherwise.
--*/
{
WDF_DRIVER_CONFIG config;
NTSTATUS status = STATUS_SUCCESS;
WDF_OBJECT_ATTRIBUTES attributes;
KdPrintEx((DPFLTR_IHVAUDIO_ID, DPFLTR_ERROR_LEVEL, "Function 'DriverEntry' begins\n"));
WDF_OBJECT_ATTRIBUTES_INIT(&attributes); //设备属性初始化
WDF_DRIVER_CONFIG_INIT(&config, PCIe_EvtDeviceAdd); //初始化WDF_DRIVER_CONFIG,并提供DeviceAdd函数
//创建驱动对象
status = WdfDriverCreate(DriverObject,
RegistryPath,
&attributes,
&config,
WDF_NO_HANDLE
);
if (!NT_SUCCESS(status)) {
return status;
}
KdPrintEx((DPFLTR_IHVAUDIO_ID, DPFLTR_ERROR_LEVEL, "Function 'DriverEntry' completes successfully and Create wdf driver object\n"));
//attributes.EvtCleanupCallback = PCIe_EvtDriverContextCleanup;
return status
Windows驱动程序开发:DMA传输详解

本文将详细解析driver.c文件中关于WDF(Windows Driver Framework)下的DMA传输驱动程序代码,涵盖DriverEntry、PCIe_EvtDeviceAdd和InitializeDMA等关键回调例程。在DriverEntry中注册PCIe_EvtDeviceAdd例程,初始化设备和驱动对象。PCIe_EvtDeviceAdd用于设备枚举,设置同步模式,创建设备并配置MSI中断。由于WDF MSI中断问题,采用WDM重新实现MSI流程。InitializeDMA为DMA传输准备,创建DMAEnabler、CommonBuffer和DMATransaction对象,设置数据缓冲区对齐和地址。
最低0.47元/天 解锁文章
1219

被折叠的 条评论
为什么被折叠?



