The Wayback Machine - https://web.archive.org/web/20040829073441/http://www.microsoft.com:80/whdc/archive/wdm.mspx
*
Microsoft.com Home|Site Map
Windows*
Search Microsoft.com for:
Windows Hardware and Driver Central*
|WHDC Site Map
Search WHDC for

WinHEC 2004: Overview

WDM: Introduction to Windows Driver Model

Updated: May 22, 2002
*
On This Page
Types of WDM DriversTypes of WDM Drivers
Possible Driver LayersPossible Driver Layers
Bus DriversBus Drivers
Function DriversFunction Drivers
Filter DriversFilter Drivers
WDM VersionsWDM Versions
WDM Differences in Plug and PlayWDM Differences in Plug and Play

To allow driver developers to write device drivers that are source-code compatible across all Microsoft� Windows� operating systems, the Windows Driver Model (WDM) was introduced. Kernel-mode drivers that follow WDM rules are called WDM drivers. All WDM drivers must:

Include Wdm.h, not Ntddk.h. (Note that Wdm.h is a subset of ntddk.h.)

Be designed as a bus driver, a function driver, or a filter driver, as described in Types of WDM Drivers.

Create device objects as described in WDM Device Objects and Device Stacks.

Support Plug and Play.

Support Power Management.

Support Windows Management Instrumentation (WMI)

Although the Windows DDK emphasizes development of WDM drivers for kernel mode, information pertinent to kernel-mode drivers that do not follow WDM rules is also provided in the DDK. This allows you to maintain existing non-WDM drivers and to write new drivers that interface with these existing drivers.

When to Write a WDM Driver.
If you are writing new kernel-mode drivers, they should be WDM drivers unless you are writing a driver that will be inserted into a stack of non-WDM drivers. Please read the documentation for device type-specific Microsoft-supplied drivers, contained in this DDK documentation, to determine how new drivers must interface with Microsoft-supplied drivers.

All new driver stacks should consist of WDM drivers.

Cross-Platform Support.
There are cross-platform issues to consider, whether you are developing WDM or non-WDM drivers. For more information, see "Writing Drivers for Multiple Platforms and Operating Systems" in the current Windows�DDK.

Types of WDM Drivers

There are three kinds of WDM drivers:

Bus drivers, which drive an I/O bus and provide per-slot functionality that is device-independent.

Function drivers, which drive an individual device.

Filter drivers, which filter I/O requests for a device, a class of devices, or a bus.

In this context, a bus is any device to which other physical, logical, or virtual devices are attached; a bus includes traditional buses such as SCSI and PCI, as well as parallel ports, serial ports, and i8042 ports.

It is important for driver writers to understand the different kinds of WDM drivers and to know which kind of driver they are writing. For example, whether or not a driver handles each Plug and Play IRP and how to handle such IRPs depends on what kind of driver is being written (bus driver, function driver, or filter driver).

The following figure shows the relationship between the bus driver, function driver, and filter drivers for a device.

WDM drivers

Possible Driver Layers

Each device typically has a bus driver for the parent I/O bus, a function driver for the device, and zero or more filter drivers for the device. A driver design that requires many filter drivers does not yield optimal performance.

The drivers in the previous figure are the following:

A bus driver services a bus controller, adapter, or bridge. Bus drivers are required drivers; there is one bus driver for each type of bus on a machine. Microsoft provides bus drivers for most common buses. IHVs and OEMs can provide other bus drivers.

A bus filter driver typically adds value to a bus and is supplied by Microsoft or a system OEM. There can be any number of bus filter drivers for a bus.

Lower-level filter drivers typically modify the behavior of device hardware. They are optional and are typically supplied by IHVs. There can be any number of lower-level filter drivers for a device.

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).

Upper-level filter drivers typically provide added-value features for a device. They are optional and are typically provided by IHVs.

The following describe the general types of drivers in detail.

Bus Drivers

A bus driver services a bus controller, adapter, or bridge. Microsoft provides bus drivers for most common buses, such as PCI, 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. 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.

Filter Drivers

Filter drivers are optional drivers that add value to or modify the behavior of a device. A filter driver can service one or more devices.

Bus Filter Drivers. Bus filter drivers typically add value to a bus and are supplied by Microsoft or a system OEM. Bus filter drivers are optional. There can be any number of bus filter drivers for a bus.

A bus filter driver could, for example, implement proprietary enhancements to standard bus hardware.

For devices described by an ACPI BIOS, the Power Manager inserts a Microsoft-supplied ACPI filter (bus filter driver) above the bus driver for each such device. The ACPI filter carries out device power policy and powers on and off devices. The ACPI filter is transparent to other drivers and is not present on non-ACPI machines.

Lower-Level Filter Drivers. Lower-level filter drivers typically modify the behavior of device hardware. They are typically supplied by IHVs and are optional. There can be any number of lower-level filter drivers for a device.

A lower-level device filter driver monitors and/or modifies I/O requests to a particular device. Typically, such filters redefine hardware behavior to match expected specifications.

A lower-level class filter driver monitors and/or modifies I/O requests for a class of devices. For example, a lower-level class filter driver for mouse devices could provide acceleration, performing a nonlinear conversion of mouse movement data.

Upper-Level Filter Drivers. Upper-level filter drivers typically provide added-value features for a device. Such drivers are usually provided by IHVs and are optional. There can be any number of upper-level filter drivers for a device.

An upper-level device filter driver adds value for a particular device. For example, an upper-level device filter driver for a keyboard could enforce additional security checks.

An upper-level class filter driver adds value for all devices of a particular class.

WDM Versions

Although Windows�XP, Windows�2000, Windows�98, and Windows�Me all support WDM, incremental changes to WDM have resulted in later-released operating systems supporting additional WDM features that earlier releases do not support. Later versions of WDM generally support all the features available in earlier versions of WDM; that is, each new version of WDM is a superset of the previous WDM version. When possible, a cross-system driver should conform to the lowest WDM version on any operating system.

A cross-system WDM driver should use the IoIsWdmVersionAvailable routine to determine which version of WDM is supported by the system on which it is running. The reference page for IoIsWdmVersionAvailable provides a list of WDM version numbers.

The simplest way to ensure cross-system compatibility is to write a driver that uses only those features supported by the lowest version of WDM. However, this is not always possible. In some situations, drivers require additional code to take advantage of features available in later versions of WDM or to compensate for differences between Windows operating systems.

WDM Differences in Driver Support Routines. The DDK reference page for each driver support routine indicates if the routine is restricted to specific versions of WDM, or if its behavior is different on different operating system versions. Before using any driver support routine in a cross-system driver, be sure to understand any version-specific restrictions or behaviors.

WDM Differences in Plug and Play

The Plug and Play feature IRP_MN_SURPRISE_REMOVAL is supported only in Windows�2000 and later versions of the operating system (WDM version 1.10 and later).

In addition, the following features work differently on Windows�98/Me from Windows�2000 and later versions of the operating system:

IRP_MN_STOP_DEVICE and IRP_MN_REMOVE_DEVICE

IRP_MN_QUERY_REMOVE_DEVICE

WDM Differences in Power Management. The following power management features differ in operation on Windows�98/Me and Windows�2000 and later versions of the operating system:

PoSetPowerState

PoRequestPowerIrp

PoRegisterDeviceForIdleDetection

IRP_MN_QUERY_POWER

IRP_MN_SET_POWER

Completing power IRPs. Drivers on Windows�98/Me must complete power IRPs at IRQL = PASSIVE_LEVEL, while drivers on Windows 2000 and later versions of the operating system can complete such IRPs at IRQL = PASSIVE_LEVEL or IRQL = DISPATCH_LEVEL.

DO_POWER_PAGABLE flag in DEVICE_OBJECT

WDM Differences in Kernel-Mode Driver Operation. Kernel-mode WDM drivers for Windows�98/Me must follow certain guidelines for using floating-point operations, MMX, 3DNOW!, or Intel's SSE extensions.

Windows�98/Me provides a fixed number of worker threads that might not be adequate for some drivers. For more information about this and other Windows�98/Me-specific WDM issues, see "Cross-Platform Issues for WDM Drivers" in the current Windows�DDK.



�2004 Microsoft Corporation. All rights reserved.�Terms of Use |Trademarks |Privacy Statement
Microsoft