Writing a Start IO Routine

< BACK  NEXT >
[oR]

Writing a Start I/O Routine

The remainder of this chapter discusses the development of a programmed I/O driver for a parallel port. For simplicity, this driver ignores many of the details that would have to be considered if writing a commercial driver.

Execution Context

The I/O manager calls the driver's Start I/O routine (described in Table 8.4) either when a Dispatch routine calls IoStartPacket (if the device was idle), or when some other part of the driver calls IoStartNextPacket. In either case, Start I/O runs at DISPATCH_LEVEL IRQL, so it must not do anything that causes a page fault.

What the Start I/O Routine Does

A driver's Start I/O routine is responsible for doing any function code-specific processing needed by the current IRP and then starting the actual device operation. In general terms, a Start I/O routine will do the following:

Table 8.4. Function Prototype for a Start I/O Routine
VOID StartIo IRQL == DISPATCH_LEVEL
Parameter Description
IN PDEVICE_OBJECT pDevObj Target device for this request
IN PIRP pIrp IRP describing this request
Return value Void

  1. Call IoGetCurrentStackLocation to get a pointer to the IRP's stack location.

  2. If a device supports more than one IRP_MJ_XXX function code, examine the I/O stack location's MajorFunction field to determine the operation.

  3. Make working copies of the system buffer pointer and byte counts stored in the IRP. The Device Extension is the best place to keep these items.

  4. Set a flag in the Device Extension, indicating that an interrupt is expected.

  5. Begin the actual device operation.

To guarantee proper synchronization, any of these steps that access data shared with the ISR should be performed inside the SynchCritSection routine rather than in Start I/O itself.

< 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