The Windows Driver Model (WDM) — known at one point as the Win32 Driver Model — is a framework for device drivers introduced by Microsoft with Windows 98 and Windows 2000. It replaced the earlier VxD model used on Windows 95, Windows 3.1, and related systems, as well as the Windows NT Driver Model.
Overview
WDM was announced at WinHEC in 1996 and was initially conceived as the core driver model of Windows NT 5.0 (the release that became Windows 2000). Its principal design goal was to unify the driver models of the Windows 9x and Windows NT product lines by standardizing requirements and reducing the amount of driver code that had to be written separately for each platform.
Under WDM, drivers are organized in layered stacks and communicate with one another through I/O request packets (IRPs). This layered architecture means that each device in a computer is served by a stack of drivers, and drivers within the stack can isolate hardware-independent behavior from hardware-specific behavior.
WDM defines three types of device drivers, although not every driver stack for a given device contains all three types:
- Bus driver: One bus driver exists for each bus on the mainboard. It is primarily responsible for identifying devices connected to that bus and for responding to Plug and Play events. Bus drivers for standard buses (such as PCI, SCSI, USB, and IEEE 1394) are typically provided as part of the operating system.
- Function driver: The principal driver for a device, providing its operational interface and handling operations such as reads and writes. Function drivers are generally written by device vendors and depend on a specific bus driver being present.
- Filter driver: An optional driver that can modify the behavior of a device, for example by intercepting or altering input and output requests. Filter drivers may be installed above the function driver (upper filters) or between the function driver and the bus driver (lower filters).
Function and bus drivers are frequently implemented as driver/minidriver pairs, such as class/miniclass or port/miniport pairs. Class and port drivers are hardware-agnostic and supplied with the operating system, while miniclass and miniport drivers are supplied by hardware vendors and support device-specific operations. WDM also defines architecture and procedures for particular device categories; for example, network devices follow the Network Driver Interface Specification (NDIS).
Device Objects and Driver Stacks
Each driver that processes an I/O request for a device has a corresponding device object loaded into memory. Device objects are created by the operating system from the associated device class and contain structures of type DEVICE_OBJECT, which store pointers to their driver. Within a WDM driver stack, the relevant object types are:
- the physical device object (PDO), at the bottom of the stack, managed by the bus driver;
- the functional device object (FDO), created by the function driver;
- filter device objects, created by filter drivers.
An I/O request packet is passed down the stack by calling IoCallDriver(). An upper filter may receive an IRP from the I/O manager and pass it down if it cannot service the request itself; the function driver processes it next, and the bus driver at the bottom of the stack interacts with the hardware abstraction layer. Execution of an IRP finishes when a driver in the stack returns the request to the I/O manager together with a result and a status flag. The Windows Driver Frameworks (WDF) library wraps WDM interfaces; Kernel-Mode Driver Framework (KMDF) drivers are constructed on top of the same concepts of driver types, driver stacks, device stacks, and IRPs, and KMDF does not replace the need to understand WDM.
Implementation and Compatibility
WDM drivers are implemented as Portable Executable .dll or .sys files. Compliant drivers must follow rules governing design, initialization, Plug and Play, power management, and memory allocation. Drivers that pass Microsoft's quality testing are digitally signed, and the Microsoft Hardware Compatibility Tests and Driver Development Kit include reliability and stress tests.
By conforming to WDM, drivers can be both binary- and source-compatible across Windows 98, Windows 98 Second Edition, Windows Me, Windows 2000, Windows XP, and Windows Server 2003 on x86-based computers. WDM drivers do not run on operating systems earlier than Windows 98 or Windows 2000. WDM drivers are designed to be forward-compatible — a driver written for an earlier version can generally run on a newer version, though it will not be able to take advantage of features introduced later. Compatibility in the reverse direction is not guaranteed: a driver written for Windows XP may or may not load on Windows 2000.
Relationship to Windows Driver Frameworks
WDM was criticized by some driver developers for several reasons, including the difficulty of correctly handling power management events and Plug and Play, the difficulty of implementing I/O cancellation correctly, the volume of boilerplate support code required for each driver, and the absence of support for writing pure user-mode drivers. Concerns were also raised about the quality of documentation and samples provided by Microsoft. In response, Microsoft released the Windows Driver Frameworks (WDF, formerly Windows Driver Foundation) on top of WDM. WDF includes the Kernel-Mode Driver Framework (KMDF) and the User-Mode Driver Framework (UMDF). Windows Vista supports both pure WDM drivers and the newer WDF; KMDF is also available for Windows XP and Windows 2000, and UMDF is available for Windows XP and later.