9.1.1 DpcForIsr versus CustomDpc Routines
Depending on an NT driver’s design, it can have a single DpcForIsr to complete all interrupt-driven I/O operations, have both a DpcForIsr and a set of operation-specific CustomDpc routines to be queued from its ISR, or have a set of one or more CustomDpc routines.
Most NT device drivers have a single DpcForIsr routine to complete I/O processing for each IRP that requires one or more operations on their respective devices. Using a single DpcForIsr to complete per-request, interrupt-driven I/O operations on a device that does one operation at a time is relatively easy. Such a driver’s ISR need only call IoRequestDpc for each interrupt-driven I/O operation.
Using a single DpcForIsr to complete overlapped, interrupt-driven I/O operations on a device that can do concurrent operations is possible with careful design but can be relatively difficult. In addition to or instead of queueing a DpcForIsr, an NT device driver’s ISR can queue a set of operation-specific, driver-supplied CustomDpc routines by calling KeInsertQueueDpc at the discretion of the driver designer.
For example, consider some of the design challenges for an NT serial driver. As the driver of a full-duplex device, an NT serial driver cannot rely on a one-to-one correspondence between the order in which IRPs are queued to a StartIo routine and the sequence of interrupts from its device in a multitasking, multiprocessor system. Furthermore, such a driver must handle timing out requests and asynchronous user-generated requests to cancel previously requested operations, to purge buffered data, and so forth.
Consequently, an NT serial driver might maintain internal queues for the read, write, purge, and wait operations that user-mode comm applications can request. It also could maintain reference counts or use some other tracking mechanism, such as a set of flags, for the IRPs in its internal queues. Its ISR would call KeInsertQueueDpc with any of a number of driver-allocated and initialized DPC objects, each associated with a driver-supplied CustomDpc routine.
Whether any NT device driver has a single DpcForIsr routine and/or a set of CustomDpc routines depends on the nature of its underlying device, the set of I/O requests it must support, and on the driver designer.