Writing a Common Buffer Bus Master DMA Driver

< BACK  NEXT >
[oR]

In common-buffer bus master DMA, the device transfers data to or from a contiguous nonpaged pool buffer, using a DMA controller that is part of the device itself. Frequently, this kind of hardware treats the common buffer as a mailbox for exchanging control and status messages with the driver.

How Common-Buffer Bus Master DMA Works

The exact operation of a common-buffer bus master driver will depend on the physical device. The description that follows is based on the typical architecture. It assumes the device uses one mailbox for commands and another to return status information. Figure 12.7 illustrates this arrangement.

Figure 12.7. Common buffer implementation of message exchange
graphics/12fig07.gif
IRP_MN_START_DEVICE HANDLER

This handler must now perform the following tasks:

  1. Invoke IoGetDmaAdapter to locate the Adapter object associated with the device.

  2. Use AllocateCommonBuffer to get a block of contiguous, nonpaged memory that both the driver and the device can access.

  3. Store the virtual address of the common buffer in the Device Extension for subsequent use.

START I/O ROUTINE

To send a command to the device, the Start I/O routine performs the following:

  1. Builds a command structure in the common buffer, using the virtual address stored in the Device Extension.

  2. If needed (CacheEnabled parameter set to TRUE), KeFlushIoBuffers is invoked to force data from the CPU's cache out to physical memory.

  3. Finally, Start I/O sets a bit in the device control register to notify the device that there is a command waiting for it. In essence, this is equivalent to starting the device.

In response to the notification bit being set, the device begins processing the command in the common buffer.

INTERRUPT SERVICE ROUTINE

When the device has finished processing the command in the common buffer, it puts a message in the status mailbox and generates an interrupt. In response to this interrupt, the driver's Interrupt Service Routine does the following:

  1. Copies the contents of the status mailbox into various fields of the Device Extension.

  2. If necessary, the ISR sets another bit in the device control register to acknowledge that it has read the status message.

  3. Calls IoRequestDpc to continue processing the request at a lower IRQL.

IRP_MN_STOP_DEVICE HANDLER

When the device is stopped, a driver should quiet the device. The Stop handler calls FreeCommonBuffer to release the memory associated with the buffer.

< 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