EvtPrepareHardware: WdfInterruptCreate returns STATUS_INVALID_DEVICE_STATE

Hi,

According to msdn, WdfInterruptCreate() can be called during EvtPrepareHardware starting KMDF 1.11

“Drivers typically call the WdfInterruptCreate method from an EvtDriverDeviceAdd callback function. Starting in KMDF version 1.11, drivers can call WdfInterruptCreate from EvtDevicePrepareHardware. If the driver calls WdfInterruptCreate from EvtDriverDeviceAdd, the InterruptRaw and InterruptTranslated members of the WDF_INTERRUPT_CONFIG structure must be NULL. If the driver calls WdfInterruptCreate from EvtDevicePrepareHardware, these members must both be valid.”

My device has many MSI-X interrupts, which I manage to configure correctly when calling from EvtDriverDeviceAdd. However, when trying to configure from EvtDevicePrepareHardware - the fucnction returns with STATUS_INVALID_DEVICE_STATE

Has anyone got any ideas? Help would be much appreceated

Code:

In EvtPrepareHardware()

for (i = 0; i < WdfCmResourceListGetCount(ResourcesTranslated); i++)
{
desc = WdfCmResourceListGetDescriptor(ResourcesTranslated, i);


switch (desc->Type) {
case CmResourceTypeInterrupt:
DEBUG_P(TRACE_LEVEL_VERBOSE, DBG_PNP, “PrepareHardware() CmResourceTypeInterrupt”);
status = InterruptCreate(pDevExt, WdfCmResourceListGetDescriptor(ResourcesRaw, i), desc);
break;


NTSTATUS InterruptCreate(IN PDEVICE_EXTENSION pDevExt, PCM_PARTIAL_RESOURCE_DESCRIPTOR Raw, PCM_PARTIAL_RESOURCE_DESCRIPTOR Translated)
{

NTSTATUS status = STATUS_SUCCESS;
WDF_INTERRUPT_CONFIG interruptConfig;

DEBUG_P(TRACE_LEVEL_VERBOSE, DBG_PNP, “InterruptCreate() NumInterruptsConfigured = %d”, pDevExt->NumInterruptsConfigured);

WDF_INTERRUPT_CONFIG_INIT(&interruptConfig, SdInterruptMSIIsr, SdEvtInterruptDpc);

// Setup Interrupt enable/disable routine callbacks
interruptConfig.EvtInterruptEnable = InterruptEnable;
interruptConfig.EvtInterruptDisable = InterruptDisable;
interruptConfig.InterruptRaw = Raw;
interruptConfig.InterruptRaw = Translated;

status = WdfInterruptCreate(pDevExt->Device, &interruptConfig, WDF_NO_OBJECT_ATTRIBUTES, &pDevExt->Interrupts[pDevExt->NumInterruptsConfigured]);
if (!NT_SUCCESS(status))
{
DEBUG_P(TRACE_LEVEL_WARNING, DBG_PNP, “InterruptCreate() WdfInterruptCreate failed 0x%x”, status);
}
else
{
pDevExt->NumInterruptsConfigured++;
}

//DEBUG_P(TRACE_LEVEL_INFORMATION, DBG_PNP, “InterruptCreate() created %d interrupts. Exit status = 0x%X”, pDevExt->NumInterruptsConfigured, status);

return status;
}

Thanks

What does !wdfkd.wdflogdump (your driver name) say?

d

Bent from my phone


From: xxxxx@gmail.commailto:xxxxx
Sent: ?10/?28/?2014 1:30 AM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: [ntdev] EvtPrepareHardware: WdfInterruptCreate returns STATUS_INVALID_DEVICE_STATE

Hi,

According to msdn, WdfInterruptCreate() can be called during EvtPrepareHardware starting KMDF 1.11

“Drivers typically call the WdfInterruptCreate method from an EvtDriverDeviceAdd callback function. Starting in KMDF version 1.11, drivers can call WdfInterruptCreate from EvtDevicePrepareHardware. If the driver calls WdfInterruptCreate from EvtDriverDeviceAdd, the InterruptRaw and InterruptTranslated members of the WDF_INTERRUPT_CONFIG structure must be NULL. If the driver calls WdfInterruptCreate from EvtDevicePrepareHardware, these members must both be valid.”

My device has many MSI-X interrupts, which I manage to configure correctly when calling from EvtDriverDeviceAdd. However, when trying to configure from EvtDevicePrepareHardware - the fucnction returns with STATUS_INVALID_DEVICE_STATE

Has anyone got any ideas? Help would be much appreceated

Code:

In EvtPrepareHardware()

for (i = 0; i < WdfCmResourceListGetCount(ResourcesTranslated); i++)
{
desc = WdfCmResourceListGetDescriptor(ResourcesTranslated, i);


switch (desc->Type) {
case CmResourceTypeInterrupt:
DEBUG_P(TRACE_LEVEL_VERBOSE, DBG_PNP, “PrepareHardware() CmResourceTypeInterrupt”);
status = InterruptCreate(pDevExt, WdfCmResourceListGetDescriptor(ResourcesRaw, i), desc);
break;


NTSTATUS InterruptCreate(IN PDEVICE_EXTENSION pDevExt, PCM_PARTIAL_RESOURCE_DESCRIPTOR Raw, PCM_PARTIAL_RESOURCE_DESCRIPTOR Translated)
{

NTSTATUS status = STATUS_SUCCESS;
WDF_INTERRUPT_CONFIG interruptConfig;

DEBUG_P(TRACE_LEVEL_VERBOSE, DBG_PNP, “InterruptCreate() NumInterruptsConfigured = %d”, pDevExt->NumInterruptsConfigured);

WDF_INTERRUPT_CONFIG_INIT(&interruptConfig, SdInterruptMSIIsr, SdEvtInterruptDpc);

// Setup Interrupt enable/disable routine callbacks
interruptConfig.EvtInterruptEnable = InterruptEnable;
interruptConfig.EvtInterruptDisable = InterruptDisable;
interruptConfig.InterruptRaw = Raw;
interruptConfig.InterruptRaw = Translated;

status = WdfInterruptCreate(pDevExt->Device, &interruptConfig, WDF_NO_OBJECT_ATTRIBUTES, &pDevExt->Interrupts[pDevExt->NumInterruptsConfigured]);
if (!NT_SUCCESS(status))
{
DEBUG_P(TRACE_LEVEL_WARNING, DBG_PNP, “InterruptCreate() WdfInterruptCreate failed 0x%x”, status);
}
else
{
pDevExt->NumInterruptsConfigured++;
}

//DEBUG_P(TRACE_LEVEL_INFORMATION, DBG_PNP, “InterruptCreate() created %d interrupts. Exit status = 0x%X”, pDevExt->NumInterruptsConfigured, status);

return status;
}

Thanks


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</mailto:xxxxx></mailto:xxxxx>

Thanks Doron!

I had a silly code mistake:
interruptConfig.InterruptRaw = Raw;
interruptConfig.InterruptRaw = Translated;
(I forgot to assign InterruptTranslated)

Thanks