Windows Driver Development-1

Source: Internet
Author: User

The previous article, "Windows Driver Development-Basic 2", has introduced the Windows approximate framework. So what's the difference between using WDF?

We know that in WDF, Kmdf is a must. And Kmdf is architected on WDM.


WDM Driver Model

    In the WDM driver model, there are at least two drivers per hardware device. One of the drivers we call a function driver is usually the one you think of as the hardware device driver.    It understands all the details that make the hardware work, is responsible for initializing I/O operations, has the responsibility to handle the interrupt events that are caused by the I/O operation, and is responsible for providing the user with a device-appropriate control mode. Another driver we call the bus driver. It is responsible for managing the hardware-to-computer connection.    For example, the PCI bus driver detects a device plugged into a PCI slot and determines the resource usage of the device, and it can also control the current switch of the PCI slot where the device resides. Some devices have more than two drivers. We use the term filter driver (filter driver) to describe them. Some filter drivers are only monitored when the feature driver performs I/O operations. In most cases, hardware or software vendors use filter drivers to modify the behavior of existing feature drivers. The upper filter drivers see the IRP before the feature driver, and they have the opportunity to provide the user with additional features that the feature driver does not know at all. Sometimes, a top-level driver can fix bugs or flaws in a feature driver or hardware. The low-level filter driver sees the IRP when the feature driver sends an IRP to the bus driver.    In some cases, such as when a USB device is plugged into a USB bus, the low-level filter driver can modify the bus operation flow to be performed by the function driver. WDM feature drivers typically consist of two separate execution files. A file is a class driver that knows how to handle the WDM protocol used by the operating system (some protocols are quite complex) and how to manage the basic characteristics of the entire device class. The USB camera class driver is an example. Another file, called the mini-driver (MiniDriver), contains the vendor-specific feature routines that the class driver uses to manage device instances.    The class driver and the mini-driver are combined to become a full-featured driver. You can think of a complete driver as a container that contains many routines that invoke routines in this container to perform various operations on the IRP when the operating system encounters an IRP. Figure 5-1 shows this concept. Some routines, such as DriverEntry and AddDevice, and dispatch functions corresponding to several IRP will appear in each of these containers. Drivers that need to queue to an IRP generally have a startio routine. The driver performing the DMA transfer should have a Adaptercontrol routine. Most devices that can generate hardware interrupts have an interrupt for their driversA service routine (ISR) and a deferred procedure call (DPC) routine. Drivers typically have several dispatch functions that support different types of IRP, of which three dispatch functions are required. Therefore, one of the tasks of WDM driver developers is to select the required routines for this container.

WDM Routines

A basic WDF driver: DriverEntry and Evtdeviceadd

(C:/WINDDK/7600.16385.1/SRC/USB/OSRUSBFX2)

/*++step1:this step shows how to create a simplest functional driver.       It is only registers DriverEntry and Evtdeviceadd callback.       Framework provides default behaviour for everything else. This allows the install and uninstall this driver.--*/#include "ntddk.h" #include "wdf.h" #include "prototypes.h" Ntstatu Sdriverentry (in Pdriver_object driverobject, in punicode_string registrypath) {wdf_driver_config conf    Ig    NTSTATUS status;    Kdprint (("DriverEntry of Step1\n"));    Wdf_driver_config_init (&config, Evtdeviceadd); Status = Wdfdrivercreate (DriverObject, Registrypath, Wdf_no_object_attribute    S, &config, Wdf_no_handle); if (!    Nt_success (status) {Kdprint ("Wdfdrivercreate failed 0x%x\n", status)); } return status; Ntstatusevtdeviceadd (in Wdfdriver Driver, in Pwdfdevice_iniT deviceinit) {NTSTATUS status;        Wdfdevice device;    Unreferenced_parameter (Driver);    Status = Wdfdevicecreate (&deviceinit, Wdf_no_object_attributes, &device); if (!        Nt_success (status) {Kdprint ("Wdfdevicecreate failed 0x%x\n", status));    return status; } return status;



Windows Driver Development-1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.