Writing a DpcForIsr Routine

< BACK  NEXT >
[oR]

A driver's DpcForIsr routine is responsible for determining a final status for the current request, completing the IRP, and starting the next one.

Execution Context

In response to the ISR's call to IoRequestDpc, a driver's DpcForIsr routine (described in Table 8.6) is added to the DPC dispatch queue. When the CPU's IRQL value drops below DISPATCH_LEVEL, the DPC dispatcher calls the DpcForIsr routine. A DpcForIsr routine runs at DISPATCH_LEVEL IRQL, which means it has no access to pagable addresses.

The I/O Manager ignores multiple calls to IoRequestDpc for a given device until the DpcForIsr routine executes. This is normal behavior for all DPC objects. If a driver design is such that it might issue overlapping DPC requests for the same device, then the driver must perform custom queuing of the DPC requests.

What the DpcForIsr Routine Does

Since most of the work happens during interrupt processing, the DpcForIsr routine in a programmed I/O driver doesn't have a lot to do. In particular, this routine should

  1. Set the IRP's I/O status block. Put an appropriate STATUS_XXX code in the Status field and the actual number of bytes transferred in the Information field.

  2. Call IoCompleteRequest to complete the IRP with an appropriate priority boost. Once called, the IRP must not be touched again.

  3. Call IoStartNextPacket to send the next IRP to Start I/O.

Table 8.6. Function Prototype for a DpcForIsr Routine
VOID DpcForIsr IRQL == DISPATCH_LEVEL
Parameter Description
IN PKDPC pDpc DPC object for this call
IN PDEVICE_OBJECT pDevObj Target device for I/O request
IN PIRP pIrp IRP describing this request
IN PVOID pContext Context passed by IoRequestDpc
Return value Void

Priority Increments

The Windows 2000 thread scheduler uses a priority boosting strategy to keep the CPU and I/O devices as busy as possible. As can be seen from the boost values listed in Table 8.7, priority increments are weighted in favor of threads working with interactive devices like the mouse and keyboard.

As part of this strategy, a driver should compensate any thread that waits for an actual device operation by giving a priority boost. Choose an appropriate increment from the table and specify it as an argument to IoCompleteRequest.

Table 8.7. Priority Increment Values
Priority Increment Values
Symbol Boost Use when completing
IO_NO_INCREMENT 0 No device I/O
IO_CD_ROM_INCREMENT 1 CDROM I/O
IO_DISK_INCREMENT 1 Disk I/O
IO_PARALLEL_INCREMENT 1 Parallel port I/O
IO_VIDEO_INCREMENT 1 Video output
IO_MAILSLOT_INCREMENT 2 Mailslot I/O
IO_NAMED_PIPE_INCREMENT 2 Named pipe I/O
IO_NETWORK_INCREMENT 2 Network I/O
IO_SERIAL_INCREMENT 2 Serial port I/O
IO_MOUSE_INCREMENT 6 Pointing device input
IO_KEYBOARD_INCREMENT 6 Keyboard input
IO_SOUND_INCREMENT 8 Sound board I/O

< BACK  NEXT >


The Windows 2000 Device Driver Book(c) A Guide for Programmers
The Windows 2000 Device Driver Book: A Guide for Programmers (2nd Edition)
ISBN: 0130204315
EAN: 2147483647
Year: 2000
Pages: 156

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net