12.5. Set Interrupt Handling in the Kernel PlugIn

  1. When calling WDC_IntEnable() [B.3.41] (after having opened a handle to the Kernel PlugIn driver, as explained in Section 12.4), set the fUseKP function parameter to TRUE to indicate that you wish to enable interrupts in the Kernel PlugIn driver with which the device was opened.
    The generated DriverWizard and the sample pci_diag shared library (xxx_lib.c / pci_lib.c) demonstrate how this should be done — see the generated/sample XXX_IntEnable()/PCI_IntEnable() library function (which is called from the generated/sample xxx_diag/pci_diag user-mode application).

    If you are not using the WDC_xxx API [B.2], in order to enable interrupts in the Kernel PlugIn call WD_IntEnable() or InterruptEnable() (which calls WD_IntEnable()), and pass the handle to the Kernel PlugIn driver that you received from WD_KernelPlugInOpen() (within the hKernelPlugIn field of the WD_KERNEL_PLUGIN structure that was passed to the function). For details regarding these APIs, refer to the WinDriver PCI Low-Level API Reference.

  2. When calling WDC_IntEnable() / InterruptEnable() / WD_IntEnable(), to enable interrupts in the Kernel PlugIn, WinDriver will activate your Kernel PlugIn's KP_IntEnable callback function [B.8.6]. You can implement this function to set the interrupt context that will be passed to the high-IRQL and DPC Kernel PlugIn interrupt handler routines, as well as write to the device to actually enable the interrupts in the hardware, for example, or implement any other code required in order to correctly enable your device's interrupts.
  3. Move the implementation of the user-mode interrupt handler, or the relevant portions of this implementation, to the Kernel PlugIn's interrupt handler functions. High-priority code, such as the code for acknowledging (clearing) level-sensitive interrupts, should be moved to the relevant high-IRQL handler — KP_IntAtIrql [B.8.8] (legacy interrupts) or KP_IntAtIrqlMSI [B.8.10] (MSI/MSI-X) — which runs at high interrupt request level. Deferred processing of the interrupt can be moved to the relevant DPC handler — KP_IntAtDpc [B.8.9] or KP_IntAtDpcMSI [B.8.11] — which will be executed once the high-IRQL handler completes it processing and returns TRUE. You can also modify the code to make it more efficient, due to the advantages of handling the interrupts directly in the kernel, which provides you with greater flexibility (e.g., you can read from a specific register and write back the value that was read, or toggle specific register bits). For a detailed explanation on how to handle interrupts in the kernel using a Kernel PlugIn, refer to Section 11.6.5 of the manual.