DESKTOP

Windows 7 : Windows Driver Foundation Architecture (part 3) - Driver Frameworks

10/3/2011 9:05:07 AM

8. WMI Requests (Kernel Mode Drivers Only)

A Windows Management Instrumentation (WMI) request triggers callbacks that the driver registered for any current WMI events. In its WMI callbacks, the driver might call WMI methods on the device object to create and manipulate WMI instances of to change its status as a WMI provider. After the WMI callbacks have returned, the framework completes or forwards the request, as appropriate, on the driver’s behalf. Only the KMDF supports WMI.

To understand how an I/O request flows through a WDF driver, consider the following scenario:

  • A user mode process requests a read from a device.

  • At the time of the request, the device is in a low-power state.

  • The driver has configured a power-managed queue to accept read requests.

The request is processed by the WDF function driver as follows:

  1. The IRP dispatcher inspects the IRP and directs it to the I/O package. The I/O package creates a WDF request object to represent the IRP, adds the WDF request object to the queue, and checks the current device power state. Because the device is in a low-power state, the I/O package calls the Plug and Play/power management package to put the device in the fully powered working state so that it can perform the read operation.

  2. The Plug and Play/power management package returns the device to the working state by taking default actions and calling the appropriate power management callbacks implemented by the driver.

  3. When the device has successfully reentered the working state, the framework dispatches the read request to the driver. If the driver has configured manual dispatching, the driver calls a method on the queue to get a request. Otherwise, the framework dispatches the request either immediately or when the driver has completed the previous request, depending on the queue’s configuration.

  4. If the driver can satisfy the request, it does; if it cannot, it sends the request to an I/O target.


9. Driver Frameworks

The WDF driver model is implemented through the KMDF, which supports Kernel Mode Driver development, and the UMDF, which supports User Mode Driver development. The frameworks provide the basic driver infrastructure and perform the following services for WDF Drivers:

  • Define WDF objects that drivers can instantiate.

  • Manage object lifetimes.

  • Expose a basic set of DDIs that drivers call to manipulate the objects.

  • Provide a common implementation of features that drivers typically require, such as Plug and Play, power management, synchronization, I/O queues, and access to the registry.

  • Manage the flow of I/O requests and Plug and Play and power notifications from the operating system to the driver.

Instead of calling the operating system directly, drivers interact with the appropriate framework for most services. The frameworks manage most of the interactions with the operating system on behalf of the driver. In effect, the frameworks shield driver developers from the details of the operating system.

The frameworks implement the WDF I/O model, object model, and Plug and Play and power management support. Each framework receives I/O requests, calls the driver to handle events according to the driver’s configuration, and applies defaults otherwise. Both frameworks provide intelligent defaults for common operations so that drivers do not require large amounts of potentially buggy “boilerplate” code.

The frameworks support common features required for all device classes. Device-class-specific extensions can also be added. For example, the initial release of the KMDF supports extensions specifically for USB devices. As new features are added to the operating system, and as new device classes are supported, features that are common to all device classes will be added to the base set of DDIs in the frameworks. Extensions will provide features that are required by one or more specific device classes, but not by every device class. The extensions are intended to replace the miniport models common with WDM.

9.1. Kernel Mode Framework

For Kernel Mode Drivers, the KMDF does not replace WDM; instead, it provides a skeletal WDM implementation. In effect, the driver developer configures the skeletal driver to work with a particular device by creating objects and providing event-based callback routines.

The KMDF is a reentrant library that can be shared by multiple drivers. Drivers are dynamically bound with the library at load time, and multiple versions of the library can be used by multiple drivers simultaneously.

The KMDF currently supports creation of the following types of Kernel Mode Drivers:

  • Function drivers for Plug and Play devices.

  • Filter drivers for Plug and Play devices.

  • Bus drivers for Plug and Play device stacks.

  • Control device drivers for legacy (NT 4.0-style) devices that are not part of a Plug and Play stack.

Currently, the KMDF does not support bus filter drivers.

WDF provides certain methods and callbacks specifically for bus drivers, others specifically for function and filter drivers, and still others for control device drivers.

The KMDF identifies a function driver, control device driver, or a bus driver based on the methods that the driver calls and the callbacks that the driver supports. For example, the bus driver for a device typically supports callbacks to enumerate the children of the device and to supply a list of the hardware resources that the device requires. A function driver for a device typically supports callbacks to manage power to its device.

A filter driver explicitly identifies itself as such before creating a device object. The KMDF uses this information when passing I/O requests to the driver. A filter driver registers for only the I/O requests it chooses to filter; the KMDF passes all other requests to the next lower driver. (For a function or bus driver, WDF fails other requests.) By contrast, a WDM filter driver must accept all I/O requests that could be targeted to its device, pass those it does not filter to a lower driver, and act on the remaining subset. A WDM filter driver requires logic to inspect and forward many types of requests; a WDF filter driver has no such code because it receives only the requests it is interested in.

When an application sends an I/O request to a Kernel Mode WDF Driver, the request travels through the components shown in Figure 2.

Figure 2. I/O Flow to Kernel Mode WDF Driver

As the figure shows, the following components are involved in handling an I/O request to a Kernel Mode WDF Driver:

  • Application— The application is a user mode process that issues I/O requests through the Win32 API.

  • Win32 API— In response to the application’s I/O request, the Win32 API calls I/O routines in the Windows kernel.

  • Windows kernel— The I/O manager in the Windows kernel creates an IRP to represent the request and presents it to the target driver by calling the driver at a designated entry point. For Kernel Mode WDF Drivers, the KMDF registers the entry points, in effect intercepting the request on behalf of the driver.

  • KMDF— The KMDF.

9.2. User Mode Framework

The UMDF implements a subset of the KMDF functionality, including support for Plug and Play, power management, and asynchronous I/O. Drivers that run in user mode have access only to the user address space and therefore pose low risk to system stability. User Mode Drivers cannot handle interrupts, perform DMA, or use kernel mode resources such as nonpaged pool.

Using the UMDF, developers can create drivers for any protocol or serial-bus based device. Although these drivers run in user mode, they use the standard Plug and Play installation mechanism and the same I/O model as Kernel Mode WDF Drivers. Figure 3 shows the components involved in transmitting an I/O request from an application to a User Mode WDF Driver.

Figure 3. I/O Flow to User Mode WDF Driver

Figure 3 includes the following components, described according to the typical flow of an I/O request:

  • Application— The application is a user mode process that issues I/O requests through the Win32 API.

  • Win32 API— In response to the application’s I/O request, the Win32 API calls I/O routines in the Windows kernel.

Other  
  •  Windows 7 : Using Advanced Security Options (part 2) - Configuring Windows Defender
  •  Windows 7 : Using Advanced Security Options (part 1) - Configuring the Action Center & Performing a Manual Scan
  •  Windows 7 : Configuring User Account Control
  •  Windows 7 : Managing and Applying LGPOs (part 3) - Using Local Policies
  •  Windows 7 : Managing and Applying LGPOs (part 2) - Using Account Policies
  •  Windows 7 : Managing and Applying LGPOs (part 1) - Configuring Local Security Policies
  •  Windows 7 : Managing Security
  •  Windows 7 : Creating and Managing Groups
  •  Windows 7 : Managing User Properties
  •  Windows 7 : Working with User Accounts (part 2)
  •  Windows 7 : Working with User Accounts (part 1)
  •  Windows Server : Designing a Software Update Infrastructure (part 2)
  •  Windows Server : Designing a Software Update Infrastructure (part 1)
  •  Securing Windows Server 2008 in the Branch Office
  •  Windows 7 : Configuring Network Connectivity - Configuring DirectAccess
  •  Windows 7 : Configuring Network Connectivity - Understanding BranchCache
  •  Windows 7 : Configuring Remote Management
  •  Configuring Windows 7 on a Network
  •  Windows Server : Branch Office Deployment - Branch Office Services (part 2)
  •  Windows Server : Branch Office Deployment - Branch Office Services (part 1)
  •  
    Top 10
    A New Lick Of CSS For Old Websites
    The Terminator, Apple And Six Months Into Your Future
    Make Great Movies On Your Mobile
    In Car Android : Easy access, The Car Home app
    Get The Most From Your Android's Browser
    Inkjet All In One Shootout - Going With Ink (Part 3) - Specifications - Brother MFC – J825DW, Canon Pixma MX897, Epson workforce pro WP – 4521, HP Officejet 6700 premium
    Inkjet All In One Shootout - Going With Ink (Part 2) - Performance - Brother MFC – J825DW, Canon Pixma MX897, Epson workforce pro WP – 4521, HP Officejet 6700 premium
    Inkjet All In One Shootout - Going With Ink (Part 1) - Design & Handling - Brother MFC – J825DW, Canon Pixma MX897, Epson workforce pro WP – 4521, HP Officejet 6700 premium
    Ipad : Using iTap VNC
    Linking PCs with a Network : Connecting to and Sharing Files with Other PCs on Your Network, Sharing a Printer on the Network
    Most View
    Kingcom Joypad C72 Tablet Review
    Zalman CNPS20LQ - A Liquid-Cooler That Makes Waves (Part 1)
    Macbook Air: Another choice of Ultrabook?
    Biggest tips guide ever! (Part 5) - PC Problems
    iClone 5 Pro
    Sharepoint 2007: Create a New List Item
    Implementing Security in Windows 7 : Protect an Account with a Password
    iPhone 3D Programming : Adding Depth and Realism - Shaders Demystified
    iPhone 3D Programming : Adding Depth and Realism - Surface Normals (part 1)
    IIS 7.0 : Managing Administration Extensions
    10 Valuable TVs For Your Living Room
    Combinations and Permutations with F#
    Exploiting SQL Injection : Enumerating the Database Schema (part 2) - MySQL
    Advanced ASP.NET : Data Caching (part 2) - Caching to Provide Multiple Views
    MSI Z77A-GD55 - Military Precision Meets Ivy Bridge
    Windows 7 : Using Shared Resources - UNC Paths & Accessing Remote Resources
    Active Directory Domain Services 2008 : Delegate Permissions for WMI Filters
    Programming .NET Security : Cryptography Explained (part 1) - Confidentiality
    The Hacked Man (Part 1) - Facebook : Rummaging a digital rubbish bin
    Introducing Windows Phone 7 Photo Features (part 1) - Using a Chooser to Take Photos