Wdm Driver Concept

来源:互联网 发布:最近的网络红歌2017 编辑:程序博客网 时间:2024/05/21 21:34

Bus Drivers

A bus driver services a bus controller, adapter, or bridge (see the Possible Driver Layers figure). Microsoft provides bus drivers for most common buses, such as PCI, PnpISA, SCSI, and USB. Other bus drivers can be provided by IHVs or OEMs. Bus drivers are required drivers; there is one bus driver for each type of bus on a machine. A bus driver can service more than one bus if there is more than one bus of the same type on the machine.

The primary responsibilities of a bus driver are to:

·                  Enumerate the devices on its bus.

·                  Respond to Plug and Play IRPs and power management IRPs.

·                  Multiplex access to the bus (for some buses).

·                  Generically administer the devices on its bus.

During enumeration, a bus driver identifies the devices on its bus and creates device objects for them. (For information about device objects, see Device Objects and Device Stacks.) The method a bus driver uses to identify connected devices depends on the particular bus.

A bus driver performs certain operations on behalf of the devices on its bus, including accessing device registers to physically change the power state of a device. For example, when the device goes to sleep, the bus driver sets device registers to put the device in the proper device power state.

Note, however, that a bus driver does not handle read and write requests for the devices on its bus. Read and write requests to a device are handled by the device's function driver. Only if the device is being used in raw mode does the parent bus driver handle reads and writes for the device.

A bus driver acts as the function driver for its controller, adapter, or bridge, and therefore manages device power policy for these components.

A bus driver can be implemented as a driver/minidriver pair, the way a SCSI port/miniport driver pair drives a SCSI host bus adapter (HBA). In such driver pairs, the minidriver is linked to the second driver, which is a DLL.

Function Drivers

A function driver is the main driver for a device. A function driver is typically written by the device vendor and is required (unless the device is being used in raw mode). The PnP manager loads at most one function driver for a device. A function driver can service one or more devices.

A function driver provides the operational interface for its device. Typically the function driver handles reads and writes to the device and manages device power policy.

The function driver for a device can be implemented as a driver/minidriver pair, such as a port/miniport driver pair or a class/miniclass driver pair. In such driver pairs, the minidriver is linked to the second driver, which is a DLL.

If a device is being driven in raw mode, it has no function driver and no upper or lower-level filter drivers. All raw-mode I/O is done by the bus driver and optional bus filter drivers.

Types of WDM Device Objects

There are three kinds of WDM device objects:

1. Physical Device Object (PDO) − represents a device on a bus to a bus driver.

2. Functional Device Object (FDO) − represents a device to a function driver.

3. Filter Device Object (filter DO) − represents a device to a filter driver.

The three kinds of device objects are all of the type DEVICE_OBJECT, but are used differently and can have different device extensions.

A driver adds itself to the stack of drivers that handle I/O for a device by creating a device object (IoCreateDevice) and attaching it to the device stack (IoAttachDeviceToDeviceStack). IoAttachDeviceToDeviceStack determines the current top of the device stack and attaches the new device object to the top of the device stack.