首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WDF中的MSI-X中断

WDF中的MSI-X中断
EN

Stack Overflow用户
提问于 2013-04-20 08:55:54
回答 1查看 3.1K关注 0票数 1

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

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

问题是,一旦我有了这个信息,我就不知道如何更改我的代码来专门将中断设置为MSI-X。我执行标准调用来配置WDF_INTERRUPT_CONFIG_INIT结构并调用WdfInterruptCreate,但是创建的中断不是消息通知的,我不知道需要做些什么才能真正实现这一点。

是否有步骤here的WDF版本,或者我应该在这里只执行标准的WDFINTERRUPT创建步骤(http://msdn.microsoft.com/en-ca/library/windows/hardware/ff547345(v=vs.85%29.aspx)?

有没有人有这样做的经验?有人能提供一个源代码示例吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-25 05:09:53

在过去的一周里,我一直在与类似的事情作斗争。我的应用程序稍有不同,因为我试图让普通的MSI中断而不是MSI-X中断工作。但我以几乎相同的方式使用WDF框架。

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

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

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

代码语言:javascript
复制
[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

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

代码语言:javascript
复制
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;
}

就像我说的,希望你现在已经把这一切都弄清楚了,但我想我还是发布一些东西来贡献吧。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16115434

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档