WDF中的MSI-X中断

时间:2013-04-20 00:55:54

标签: windows driver interrupt kmdf wdf

我在使用WDF / KMDF编写的Windows总线驱动程序中实现MSI-X中断时遇到了很多麻烦。 我已经阅读了MSDN documentation,并且那里没有太多有用的信息。我的理解是它应该只是“工作”。

我已更改驱动程序的INF文件以添加相应的注册表项,并确认它们在安装时设置正常。我正在查询PCI配置空间并确定是否支持MSI-X中断。

问题是,一旦我掌握了这些信息,我就不知道如何更改我的代码以专门设置中断为MSI-X。我执行标准调用来配置WDF_INTERRUPT_CONFIG_INIT stuct并调用WdfInterruptCreate,但是创建的中断没有消息信号,我不知道需要做些什么来实际实现这一点。

是否有步骤here的WDF版本,或者我应该执行标准的WDFINTERRUPT创建步骤here

有没有人有这方面的经验?任何人都可以提供源代码示例吗?

1 个答案:

答案 0 :(得分:2)

上周我一直在努力寻找类似的东西。我的应用程序略有不同,因为我试图获得普通的MSI中断而不是MSI-X中断。但是我以几乎相同的方式使用WDF框架。

我意识到你在2013年4月左右发布了原始问题,但没有更新。你解决了原来的问题吗?如果是这样,我希望看到你自己的解决方案。

在我的WDF驱动程序中,我映射传入的硬件资源列表并使用WdfCmResourceListGetDescriptor()函数解析它以检查WDFCMRESLIST列表中的每个PCM_PARTIAL_RESOURCE_DESCRIPTOR项。我能够获得单个CmResourceTypeInterrupt描述符,但它总是用于传统中断而不是MSI中断。我的设备支持MSI。我不明白为什么MSI描述符不在资源列表中,即使在你所描述的.inf文件中设置额外的注册表项之后也是如此。

事实证明我的.inf文件中有拼写错误。我忘了在设备安装部分附加“.HW”后缀。添加此后缀允许总线管理器修改设备中的pcie配置地址并创建相应的MSI中断资源描述符,该描述符必须由驱动程序挂钩。

[Standard.NT$ARCH$]
%tdvr.DeviceDesc%=tdvr_Device, PCI\VEN_104C&DEV_B800 

[tdvr_Device.NT]
CopyFiles=Drivers_Dir

[tdvr_Device.NT.HW]
AddReg=MSI_Interrupts

[Drivers_Dir]
tdvr.sys

;http://msdn.microsoft.com/en-us/library/windows/hardware/ff544246(v=vs.85).aspx
;To receive message-signaled interrupts (MSIs), a driver's INF file must enable MSIs in the 
;registry during installation. Use the Interrupt Management\MessageSignaledInterruptProperties 
;subkey of the device's hardware key to enable MSI support.

[MSI_Interrupts]
HKR,Interrupt Management,,0x00000010
HKR,Interrupt Management\MessageSignaledInterruptProperties,,0x00000010
HKR,Interrupt Management\MessageSignaledInterruptProperties,MSISupported,0x00010001,1

当在资源列表中找到MSI中断资源描述符时(例如在evtMapHWResources回调中),该描述符用作WdfInterruptCreate()函数的输入。这里的“tdvr”前缀是我自己的驱动程序命名约定。

NTSTATUS
tdvrConfigureInterrupts(
    _Inout_ PDEVICE_CONTEXT deviceContext,
    _In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR interruptDescRaw,
    _In_ PCM_PARTIAL_RESOURCE_DESCRIPTOR interruptDescTranslated
    )
{
    NTSTATUS status;
    PAGED_CODE();
    FuncEntry();

    // What kind of interrupt has been provided?
    if (CM_RESOURCE_INTERRUPT_MESSAGE & interruptDescTranslated->Flags)
    {
        TraceInterrupt(TRACE_LEVEL_INFORMATION, 
            "Message Interrupt level 0x%0x, Vector 0x%0x, MessageCount %u\n"
            ,interruptDescTranslated->u.MessageInterrupt.Translated.Level
            ,interruptDescTranslated->u.MessageInterrupt.Translated.Vector
            ,interruptDescTranslated->u.MessageInterrupt.Raw.MessageCount
            );
    }
    else
    {
        TraceInterrupt(TRACE_LEVEL_INFORMATION,
            "Legacy Interrupt level: 0x%0x, Vector: 0x%0x\n"
            ,interruptDescTranslated->u.Interrupt.Level
            ,interruptDescTranslated->u.Interrupt.Vector
            );
    }

    //
    // Create WDFINTERRUPT object.
    //
    WDF_INTERRUPT_CONFIG interruptConfig;
    WDF_INTERRUPT_CONFIG_INIT(
        &interruptConfig,
        tdvrEvtInterruptIsr,
        tdvrEvtInterruptDpc
        );

    // Each interrupt has some context data
    WDF_OBJECT_ATTRIBUTES interruptAttributes;
    WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(
        &interruptAttributes,
        INTERRUPT_CONTEXT
        );

    //
    // These first two callbacks will be called at DIRQL.  Their job is to
    // enable and disable interrupts.
    //
    interruptConfig.EvtInterruptEnable  = tdvrEvtInterruptEnable;
    interruptConfig.EvtInterruptDisable = tdvrEvtInterruptDisable;

    // If the driver calls WdfInterruptCreate from EvtDriverDeviceAdd, the InterruptRaw and
    // InterruptTranslated members of the WDF_INTERRUPT_CONFIG structure must be NULL. 
    // the driver calls WdfInterruptCreate from EvtDevicePrepareHardware, these members must both be valid.
    interruptConfig.InterruptTranslated = interruptDescTranslated;
    interruptConfig.InterruptRaw = interruptDescRaw;

    // Our driver must call WdfInterruptCreate once for each interrupt vector that its device requires. 
    // If the device supports message-signaled interrupts (MSI), the driver must create an interrupt object 
    // for each message that the device can support.
    status = WdfInterruptCreate(
        deviceContext->WdfDevice,
        &interruptConfig,
        &interruptAttributes,
        &deviceContext->WdfInterrupt
        );

    if (!NT_SUCCESS(status))
    {
        TraceInterrupt(TRACE_LEVEL_ERROR, "WdfInterruptCreate FAILED: %!STATUS!\n", status);
    }
    else
    {
        PINTERRUPT_CONTEXT interruptContext = InterruptGetContext(deviceContext->WdfInterrupt);
        // do whatever with context info
    }

    FuncExit();
    return status;
}

就像我现在所说的那样,你们已经想到了这一切,但我想我会发布一些东西来做出贡献。