The Windows Driver Model (WDM)
The Windows Driver Model (WDM) is the foundational driver architecture for Windows operating systems. It provides a standardized framework for developing device drivers, ensuring compatibility and stability across various hardware components.
Core Concepts
WDM is built around several key concepts:
- Device Objects: Represent physical or logical devices. Drivers interact with the system through device objects.
- Driver Objects: Represent a specific driver and its capabilities.
- Functional Device Objects (FDOs): Represent a single, functional instance of a device.
- Physical Device Objects (PDOs): Represent the physical device itself, as seen by the bus.
- Filter Device Objects (FDOs): Optional objects inserted into the device stack to intercept or modify I/O requests.
- I/O Request Packets (IRPs): Structures used to pass I/O requests from the operating system to the driver and between drivers in a stack.
Driver Stacks
WDM drivers are organized in a hierarchical structure called a device stack. Each device object in the stack represents a layer of functionality. A typical stack might include:
- Bus Driver: Handles the bus itself (e.g., PCI, USB).
- Filter Driver (optional): Intercepts or modifies I/O.
- Function Driver: Provides the primary functionality for the device.
- Lower Filter Driver (optional): Further filtering.
- Raw PDO (optional): For devices that don't fit the standard model.
I/O requests (IRPs) travel down the stack to the function driver and then potentially back up, allowing each layer to process the request.
IRP Processing
Drivers process IRPs by implementing specific dispatch routines. When an IRP arrives for a particular I/O function (e.g., IRP_MJ_READ, IRP_MJ_WRITE), the system calls the corresponding dispatch routine in the driver.
// Example of a dispatch routine signature
NTSTATUS DriverDispatchRead(
PDEVICE_OBJECT DeviceObject,
PIRP Irp
) {
// Process the read request
// ...
return STATUS_SUCCESS;
}
Drivers can complete an IRP, pass it down to the next driver in the stack, or return it to the system.
Key WDM Components
- I/O Manager: Manages the I/O system, including IRP creation, queuing, and delivery.
- Plug and Play Manager: Handles device enumeration, configuration, and resource allocation.
- Power Manager: Manages device power states.
- WMI (Windows Management Instrumentation): Provides a standardized interface for managing system and device information.
Understanding the Driver Stack
The hierarchical nature of the driver stack is crucial for modularity and extensibility. It allows for independent development and debugging of different driver layers.
Evolution to WDF
While WDM is the foundation, Microsoft has introduced the Windows Driver Frameworks (WDF), which includes Kernel-Mode Driver Framework (KMDF) and User-Mode Driver Framework (UMDF). WDF simplifies driver development by abstracting many of the complexities of WDM, offering a more object-oriented approach.
Migrating to WDF
For new driver development, it is highly recommended to use WDF (KMDF or UMDF) as it significantly reduces development effort and improves driver quality compared to direct WDM programming.
This section provides a high-level overview of the Windows Driver Model. For detailed information on specific components and programming interfaces, please refer to the API Reference and related documentation.