ENTERPRISE

Windows 7 : Programming KMDF Hardware Driver - Support Device Interrupts (part 2) - Post-Interrupt Enable and Pre-Interrupt Disable Processing

2/24/2014 12:47:45 AM

4. Code to Enable Interrupts

In the PCIDRV sample, the EvtInterruptEnable callback appears in isrdpc.c. The required code is quite simple, as the following shows:

NTSTATUS
NICEvtInterruptEnable(
IN WDFINTERRUPT Interrupt,
IN WDFDEVICE AssociateDevice
)
{
PFDO_DATA fdoData;
fdoData = FdoGetData(AssociateDevice);
NICEnalbeInterrupt(Interrupt, fdoData);
return STATUS_SUCCESS;
}

NICEnableInterupt is simply a macro that sets the PCI device register to enable interrupts.

5. Code to Disable Interrupts

In the PCIDRV sample, the EvtInterruptDisable callback (also in isrdpc.c) simply calls the internal NICDisableInterrupt macro to set the PCI device register to disable interrupts. The following is the code:

NTSTATUS
NICEvtInterruptDisable(
IN WDFINTERRUPT Interrupt,
IN WDFDEVICE AssociatedDevice
)
{
PFDO_DATA fdoData;

fdoData = FdoGetData(AssociatedDevice);
NICDisableInterrupt(fdoData);
return STATUS_SUCCESS;
}

6. Post-Interrupt Enable and Pre-Interrupt Disable Processing

Some devices cause interrupt storms if they are initialized after their interrupts are enabled. The driver for such a device must therefore be able to perform initialization after the device enters DO but before its interrupt is enabled. Other devices, however, cannot be initialized until the interrupt is enabled. To enable correct operation of both types of devices, KMDF supplies post-interrupt enable and pre-interrupt disable events for which drivers can register.

When powering up a device, KMDF invokes a driver’s callbacks in the following order:

  1. EvtDeviceDOEntry

  2. EvtInterruptEnable

  3. EvtDeviceDOEntryPostInterruptsEnabled

KMDF calls EvtDeviceDOEntry first. Drivers that must initialize their devices before the interrupt is connected (for example, to prevent interrupt storms) should do so in this callback. Next, KMDF calls EvtInterruptEnable. Drivers should enable their interrupts and do little or nothing else in this function because it is called at DIRQL. Finally, KMDF calls EvtDeviceDOEntryPostInterruptsEnabled at PASSIVE_LEVEL. Drivers that must initialize their devices after the interrupt is connected should do so in this callback.

At power-down, KMDF calls the corresponding paired functions in the opposite order:

  1. EvtDeviceDOExitPreInterruptsDisabled

  2. EvtInterruptDisable

  3. EvtDeviceDOEXit

To undo work done by the EvtDeviceDOEntryPostInterruptsEnabled, a driver registers an EvtDeviceDOExitPreInterruptsDisabled function. Like the post-enable function, the pre-disable function does work at PASSIVE_LEVEL in preparation for disabling the interrupt.

A driver must register the post-interrupt enable and pre-interrupt disable callbacks in the WDF_PNPPOWER_EVENT_CALLBACKS structure before creating the device object. The PCIDRV sample fills this structure in its EvtDriverDeviceAdd callback, as follows:

pnpPowerCallbacks.EvtDeviceDOEntryPostInterruptsEnabled =
NICEvtDeviceDOEntryPostInterruptsEnabled;
pnpPowerCallbacks.EvtDeviceDOExitPreInterruptsDisabled =
NICEvtDeviceDOExitPreInterruptsDisabled;

In the current version of the PCIDRV sample, both of these functions are stubs.

Other  
  •  Microsoft Exchange Server 2010 : Managing Data and Database Availability Groups - Content Indexing
  •  Microsoft Exchange Server 2010 : Creating and Managing Database Availability Groups (part 5) - Switching over Servers and Databases
  •  Microsoft Exchange Server 2010 : Creating and Managing Database Availability Groups (part 4) - Configuring Database Availability Group Properties
  •  Microsoft Exchange Server 2010 : Creating and Managing Database Availability Groups (part 3) - Managing Database Availability Group Networks
  •  Microsoft Exchange Server 2010 : Creating and Managing Database Availability Groups (part 2) - Managing Availability Group Membership
  •  Microsoft Exchange Server 2010 : Creating and Managing Database Availability Groups (part 1) - Creating Database Availability Groups
  •  Microsoft Exchange Server 2010 : Navigating the Information Store (part 2) - Improving Availability, Introducing Active Manager
  •  Microsoft Exchange Server 2010 : Navigating the Information Store (part 1) - Using Databases, Understanding Database Structures
  •  Byod – Good Or Bad Or Unknown?
  •  Windows 7 : WORKING WITH THE FIREWALL (part 6) - Using the GPO Technique - Adding a New Application Rule, Removing an Application Rule
  •  
    Most View
    Spring Is Here (Part 2)
    Is 802.11ac Worth Adopting?
    BlackBerry Z10 - A Touchscreen-Based Smartphone (Part 1)
    LG Intuition Review - Skirts The Line Between Smartphone And Tablet (Part 5)
    Fujifilm X-E1 - A Retro Camera That Inspires (Part 4)
    My SQL : Replication for High Availability - Procedures (part 6) - Slave Promotion - A revised method for promoting a slave
    10 Contenders For The 'Ultimate Protector' Crown (Part 3) : Eset Smart Security 6, Kaspersky Internet Security 2013, Zonealarm Internet Security 2013
    HTC Desire C - Does It Have Anything Good?
    Windows Phone 7 : Understanding Matrix Transformations (part 2) - Applying Multiple Transformations
    How To Lock Windows By Image Password
    REVIEW
    - First look: Apple Watch

    - 10 Amazing Tools You Should Be Using with Dropbox
    VIDEO TUTORIAL
    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
    Popular Tags
    Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS
    Top 10
    OPEL MERIVA : Making a grand entrance
    FORD MONDEO 2.0 ECOBOOST : Modern Mondeo
    BMW 650i COUPE : Sexy retooling of BMW's 6-series
    BMW 120d; M135i - Finely tuned
    PHP Tutorials : Storing Images in MySQL with PHP (part 2) - Creating the HTML, Inserting the Image into MySQL
    PHP Tutorials : Storing Images in MySQL with PHP (part 1) - Why store binary files in MySQL using PHP?
    Java Tutorials : Nested For Loop (part 2) - Program to create a Two-Dimensional Array
    Java Tutorials : Nested For Loop (part 1)
    C# Tutorial: Reading and Writing XML Files (part 2) - Reading XML Files
    C# Tutorial: Reading and Writing XML Files (part 1) - Writing XML Files