Windows driver development and windows driver development

Source: Internet
Author: User

Windows driver development and windows driver development

The previous article "Windows driver development-basics 2" has introduced the windows framework. What are the differences between WDF?

We know that in WDF, KMDF is required. KMDF is based on WDM.


WDM Driver Model

In the WDM driver model, each hardware device has at least two drivers. One of the drivers is called a function driver, which is usually the hardware device driver you think. It understands all the details of hardware work, initializes I/O operations, and handles the interruptions caused by the completion of I/O operations, it is the responsibility to provide users with a suitable device control method. Another driver is called the bus driver. It manages the connection between hardware and computers. For example, the PCI bus driver detects the device inserted into the PCI slot and determines the resource usage of the device. It can also control the current switch of the PCI slot where the device is located. Some devices have more than two drivers. We use the filter driver to describe them. Some filter drivers only monitor when functional drivers perform I/O operations. In most cases, hardware or software vendors use the filter driver to modify the behavior of existing functional drivers. The upper-layer filter drivers see IRPs before the feature drivers. They have the opportunity to provide additional features to users, but the feature drivers do not know at all. Sometimes, an upper-layer driver can fix functional drivers or hardware faults or defects. The low-layer filter driver sees the IRP when the function driver sends an IRP to the bus driver. In some cases, for example, when a USB device is inserted into a USB bus, the low-layer filter driver can modify the bus operation flow to be executed by the function driver. The WDM driver is usually composed of two separated execution files. A file is a class driver that understands how to handle the WDM protocol used by the operating system (some protocols are quite complex) and how to manage the basic features of the entire device class. A usb camera driver is an example. Another file is called minidriver, which contains vendor-specific feature routines used by the class driver to manage device instances. Class drivers and mini drivers are combined to become a complete functional driver. A complete driver can be seen as a container, which contains many routines. When an IRP is encountered by the operating system, it calls the routines in the container to execute various operations on the IRP. Figure 5-1 shows this concept. Some routines, such as DriverEntry and AddDevice, and dispatch functions corresponding to several IRPs will appear in each of these containers. Drivers that need to queue for IRP generally have a StartIo routine. The driver that executes DMA transmission should have an AdapterControl routine. For most devices that can generate hardware interruptions, their drivers have an interruption service routine (ISR) and a delay process call (DPC) routine. Drivers generally have several dispatch functions that support different types of IRPs. Three of them are required. Therefore, a task of the WDM driver developer is to select the required routine for this container.

WDM routine

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 only registers DriverEntry and EvtDeviceAdd callback.       Framework provides default behaviour for everything else.       This allows you to install and uninstall this driver.--*/#include "ntddk.h"#include "wdf.h"#include "prototypes.h"NTSTATUSDriverEntry(    IN PDRIVER_OBJECT  DriverObject,    IN PUNICODE_STRING RegistryPath    ){    WDF_DRIVER_CONFIG       config;    NTSTATUS                status;    KdPrint(("DriverEntry of Step1\n"));    WDF_DRIVER_CONFIG_INIT(&config, EvtDeviceAdd);    status = WdfDriverCreate(DriverObject,                        RegistryPath,                        WDF_NO_OBJECT_ATTRIBUTES,                         &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;}



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.