Introduction to Plug and Play and Power Management in the Windows Driver Foundation 694430060 陳怡碩.

Slides:



Advertisements
Similar presentations
Accessing I/O Devices Processor Memory BUS I/O Device 1 I/O Device 2.
Advertisements

WDM 드라이버의 기본 구조 What is WDM?
Lectures on File Management
Linux Device Driver Report I/O Request Flow in WDF Kernel- Mode Drivers.
Process Description and Control
Process Description and Control Module 1.0. Major Requirements of an Operating System Interleave the execution of several processes to maximize processor.
Architectural Support for OS March 29, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
IO Request Flow in WDF Kernel-Mode Drivers
1 Process Description and Control Chapter 3. 2 Process Management—Fundamental task of an OS The OS is responsible for: Allocation of resources to processes.
CSCE 351: Operating System Kernels
Chapter 13 Embedded Systems
OS Spring’03 Introduction Operating Systems Spring 2003.
Chapter 11 Operating Systems
I/O Request Flaw in WDF Kernel-Mode Driver
1 I/O Management in Representative Operating Systems.
1 Threads Chapter 4 Reading: 4.1,4.4, Process Characteristics l Unit of resource ownership - process is allocated: n a virtual address space to.
Check Disk. Disk Defragmenter Using Disk Defragmenter Effectively Run Disk Defragmenter when the computer will receive the least usage. Educate users.
Exception and Interrupt Handling
Hands-On Microsoft Windows Server 2008
WINDOWS SERVICES. Introduction You often need programs that run continuously in the background Examples: – servers –Print spooler You often need.
MICROPROCESSOR INPUT/OUTPUT
1 Lecture 20: I/O n I/O hardware n I/O structure n communication with controllers n device interrupts n device drivers n streams.
ATA Miniport Nuts and Bolts
1-1 Embedded Network Interface (ENI) API Concepts Shared RAM vs. FIFO modes ENI API’s.
Lecture 2 Process Concepts, Performance Measures and Evaluation Techniques.
Chapter 3 Process Description and Control
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
A Comparative Study of the Linux and Windows Device Driver Architectures with a focus on IEEE1394 (high speed serial bus) drivers Melekam Tsegaye
Windows 2000 System Mechanisms Computing Department, Lancaster University, UK.
CE Operating Systems Lecture 11 Windows – Object manager and process management.
NT Kernel CS Spring Overview Interrupts and Exceptions: Trap Handler Interrupt Request Levels and IRT DPC’s, and APC’s System Service Dispatching.
Operating Systems Lecture November 2015© Copyright Virtual University of Pakistan 2 Agenda for Today Review of previous lecture Hardware (I/O, memory,
WHDC PowerPoint Template Notes & Handouts
Chapter 2 Processes and Threads Introduction 2.2 Processes A Process is the execution of a Program More specifically… – A process is a program.
1 Kyung Hee University Statecharts Spring Kyung Hee University Specifying Objects’ Behaviour  Interaction diagrams show message-passing behaviour.
Updates and Common Questions Asked by Simulation Developers Peter Shier Architect Windows Devices and Storage Technologies
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
System Components ● There are three main protected modules of the System  The Hardware Abstraction Layer ● A virtual machine to configure all devices.
How to Develop a KMDF Driver. Outline WDF Object model DDI Organization Object context memory Object lifetime WDF Request Flow Through the Driver Request.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
Lecture 4 Mechanisms & Kernel for NOSs. Mechanisms for Network Operating Systems  Network operating systems provide three basic mechanisms that support.
Customer and Partner Connections Design and Develop Assess and Certify.
Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze Unit OS3: Concurrency 3.3. Advanced Windows Synchronization.
Operating Systems (CS 340 D) Dr. Abeer Mahmoud Princess Nora University Faculty of Computer & Information Systems Computer science Department.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
1 Process Description and Control Chapter 3. 2 Process A program in execution An instance of a program running on a computer The entity that can be assigned.
Time Management.  Time management is concerned with OS facilities and services which measure real time.  These services include:  Keeping track of.
Embedded Computer - Definition When a microcomputer is part of a larger product, it is said to be an embedded computer. The embedded computer retrieves.
Active-HDL Server Farm Course 11. All materials updated on: September 30, 2004 Outline 1.Introduction 2.Advantages 3.Requirements 4.Installation 5.Architecture.
CHAPTER 6 Threads, Handlers, and Programmatic Movement.
1 Chapter 2: Operating-System Structures Services Interface provided to users & programmers –System calls (programmer access) –User level access to system.
Advanced Operating Systems CS6025 Spring 2016 Processes and Threads (Chapter 2)
Memory Management.
Operating Systems (CS 340 D)
OPERATING SYSTEMS CS3502 Fall 2017
Computer Architecture
Structure of Processes
Computer-System Architecture
TDC 311 Process Scheduling.
Process Description and Control
Process Description and Control
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Threads Chapter 4.
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Process Description and Control
Operating Systems Lecture 3.
Process Description and Control
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

Introduction to Plug and Play and Power Management in the Windows Driver Foundation 694430060 陳怡碩

Abstract The Windows Driver Foundation (WDF) defines a new model for developing device drivers for the Microsoft® Windows® family of operating systems This paper provides an introduction to how drivers implement Plug and Play and Power Management features using the kernel-mode driver framework that is part of WDF

Introduction(一) The Windows Driver Foundation comprises two parts: kernel-mode driver framework user-mode driver framework The major goal of the Windows Driver Foundation (WDF) : Easy to develop The freedom necessary to support

Introduction(二) Kernel mode goal provided by its implementation of Plug and Play (PnP) . power management.

A Brief Review of WDF Concepts(一) Execution of a framework-based driver begins at DriverEntry A WDF driver initializes and instantiates its WDFDRIVER object. A framework-based driver initializes and instantiates a WDFDEVICE object a framework-based driver is called is EvtDeviceAdd.

A Brief Review of WDF Concepts(二) A driver also declares its I/O request queuing model, and the queues it will use, within its EvtDeviceAdd routine A framework-based driver that supports hardware that is capable of interrupting initializes its WDFINTERRUPT object.

Implementing PnP & Power Management(一) Windows Driver Foundation implements a fully integrated model for PnP and power management Unlike WDM, PnP and power management are not implemented separately in a WDF driver Advantages: Presents a single, streamlined set of interfaces Eliminates the need for redundant driver code

Implementing PnP & Power Management(二) example driver types A description of the type of driver and the PnP and power management features that the driver implements. A description of the framework functions that need to be called or event callbacks that the driver needs to implement to support the desired PnP and power management features. Example code showing the implementation of those features. The framework takes in response to various example PnP and power events for this driver type.

Power Policy in WDF Drivers The device power state (D state) closely reflects the system’s power state (S state) The management of D states for a device is called “power policy” A driver other than a function driver can indicate to WDF that it is the power policy owner for its device by issuing a function call during initialization

Software-Only Drivers A software-only driver is a driver that does not control any hardware A software-only driver can be either a root-enumerated function driver or a filter driver

Implementing Framework-Based Software-Only Drivers Software-only WDF drivers demonstrate the dramatic difference between the framework and WDM Software-only drivers typically utilize the default PnP and power management handling provided by the framework Any arriving PnP or power events are automatically managed by the framework

WDFQUEUE Handling for Software-Only Drivers By default, the framework implements power management for all WDFQUEUE objects When a WDFQUEUE is power managed, requests are dispatched from the queue to the driver’s I/O processing callback events only when the device’s hardware is available Software-only drivers do not access any device hardware. Therefore, software-only drivers, especially filter drivers, should typically disable power management for all their queues.

Example PnP and Power Code for a Software-Only Driver A basic EvtDeviceAdd function for a software-only driver This function contains two PnP or power management features : Support for the optional WDFDEVICE cleanup event The driver’s disabling power management support for its one WDFQUEUE P.6-P.9

Framework Actions for a Software-Only Driver In the software-only driver, almost all PnP/PM operations are handled by the framework. The framework will automatically grant operation system requests that arrive at the driver fort PM operations Driver doesn’t control any hardware, it doesn’t need to provide any additional event handler callbacks

Hardware Function Drivers The framework handles most of the PnP/PM tasks for hardware function drivers in the same way that it handles those tasks for software-only drivers.

Implementing Hardware Function Drivers (一) That is, the driver must determine what I/O ports, memory mapped addresses Interrupts are used to communicate with its device, store that information for later use, and map any memory-based resources into kernel virtual address space

Implementing Hardware Function Drivers (二) A driver that supports hardware must initialize its device to a known state every time the device transitions to D0, including during system startup Most drivers that support hardware must manage interrupts from their devices, including enabling and disabling device interrupts when requested by the framework The framework will automatically stop dispatching I/O requests from those queues to the driver whenever its device’s hardware is not accessible

Hardware Resource Identification and Tear-Down During initialization, the framework calls a driver’s EvtPrepareHardware callback with the collection of hardware resources that have been assigned to the device When a device relinquishes its hardware resources, the framework calls EvtReleaseHardware to request the driver to tear down any software state that was previously established in EvtPrepareHardware

Device Power-Up Initialization and Power-Down Tear-Down Each time a device enters D0, the framework calls the driver for that device at its EvtDeviceD0Entry event callback The driver’s EvtDeviceD0Entry is called after the driver’s EvtPrepareHardware function has been called Each time a device is about to leave D0, the framework calls the device’s driver at its EvtDeviceD0Exit event callback

Interrupt Support A driver that supports interrupts from its device will create a WDFINTERRUPT object during EvtDeviceAdd processing The driver specifies interrupt enable and interrupt disable event callback functions by filling in the EvtInterruptEnable and EvtInterruptDisable members

WDFQUEUE Management in Hardware Function Drivers (一) WDFQUEUE objects are power managed by default by the framework when a WDFQUEUE is power managed by the framework, requests are dispatched from that queue to the driver’s I/O processing callback events only when the device’s hardware is accessible and powered to D0

WDFQUEUE Management in Hardware Function Drivers (二) The driver therefore sorts requests into two : WDFQUEUE:A power-managed WDFQUEUE for read and write requests WDFQUEUE:A non–power-managed WDFQUEUE for device control requests

Example PnP and Power Code for a Hardware Function Driver EvtPrepareHardware and EvtReleaseHardware callbacks EvtDeviceD0Entry and EvtDeviceD0Exit callbacks Interrupt handling, including creating a WDFINTERRUPT object and support for EvtInterruptEnable and EvtInterruptDisable callbacks P.12 ~ P.17

Framework Actions for a Simple Hardware Function Driver (一) Almost all of PnP and power management is done for this driver by the framework Whenever a set of hardware resources is assigned to a device, its driver’s EvtPrepareHardware function is called NTSTATUS EvtPrepareHardware(WDFDEVICE Device WDFCOLLECTION Resources, WDFCOLLECTION ResourcesTranslated)

Framework Actions for a Simple Hardware Function Driver (二) Each time a device is about to enter D0, the framework calls the driver’s EvtDeviceD0Entry function NTSTATUS EvtDeviceD0Entry(WDFDEVICE Device,WDF_POWER_DEVICE_STATE PreviousState)

Framework Actions for a Simple Hardware Function Driver (三) The value for the parameter which represents the previous state is an enum, taken from the following list : typedef enum _WDF_POWER_DEVICE_STATE { WdfPowerDeviceUnspecified = 0, WdfPowerDeviceD0, WdfPowerDeviceD1, WdfPowerDeviceD2, WdfPowerDeviceD3, WdfPowerDeviceStateD3Final, WdfPowerDevicePrepareForHibernation, WdfPowerDeviceMaximum } WDF_POWER_DEVICE_STATE,*PWDF_POWER_DEVICE_STATE;

Framework Actions for a Simple Hardware Function Driver (四) If the EvtDeviceD0Entry callback returns success, the framework next connects the driver’s ISR to device interrupts and enables interrupts on the device by calling the driver’s EvtInterruptEnable function BOOLEAN EvtInterruptEnable(WDFINTERRUPT Interrupt, WDFDEVICE Device) After it returns from EvtInterruptEnable, the device is ready for use.

Device Startup and Initialization 1. EvtDevicePrepareHardware is called by the framework. 2. EvtDeviceD0Entry is called by the framework. 3. The framework connects the device’s ISR to interrupts from the device. 4. EvtInterruptEnable is called by the framework at DIRQL. 5. EvtDeviceD0EntryPostInterruptsEnabled is called by the framework at IRQL PASSIVE_LEVEL. 6. The framework releases any WDFQUEUEs that are power managed.

Remove a Device 1. The framework holds all power-managed WDFQUEUEs. 2. EvtDeviceD0ExitPreInterruptsDisabled is called by the framework at IRQL PASSIVE_LEVEL. 3. EvtInterruptDisable is called by the framework at DIRQL. 4. The framework disconnects the driver’s ISR from the device. 5. EvtDeviceD0Exit is called by the framework. 6. EvtDeviceReleaseHardware is called by the framework.

Driver writers might be particularly interested in two target states that the framework can pass into a driver’s EvtDeviceD0Exit event callback: WdfPowerDevicePrepareForHibernation WdfPowerDeviceStateD3Final

Hardware Function Drivers with Idle Support The framework handles most of the complex work involved in implementing PnP and power management

Implementing Device Power-Down Idle Support (一) A framework driver indicates that it will support idle within its EvtDeviceAdd function Whether device power-down on idle support is enabled for the device The amount of time without receiving an I/O request before the device is considered idle The device power state to which the device should be transitioned when it is idled

Implementing Device Power-Down Idle Support (二) It’s controlled by the field Enabled and the default is WdfDefault The driver sets this value into the IdleTimeout field The driver sets this value in the DxState field

Implementing Device Power-Down Idle Support (三) Wether the user can control idle policy or not is determined by the setting of the UserControlOfIdleSettings field IdleAllowUserControl (the default) IdleDoNotAllowUserControl

Implementing Device Power-Down Idle Support (四) Device idle policy can be changed at any time by the driver, after its initial call to WdfDeviceUpdateS0IdleSettings in its EvtDeviceAdd function A driver can also indicate to the framework that a device has entered or exited a state in which the device may not be idled by using the WdfDevicePowerReference and WdfDevicePowerDereference functions

Implementing Device Power-Down Idle Support (五) After IdleTimeout milliseconds pass and no I/O requests are active on the device, the framework transitions the device to the lower-power state the driver indicated in its last call to WdfDeviceUpdateS0IdleSettings

Implementing Device Power-Down Idle Support (六) The framework returns the device to D0 whenever one of the following occurs : A new I/O request arrives at any of the device’s power-managed queues The driver calls WdfDevicePowerReference The driver disables idle support by calling WdfDeviceUpdateS0IdleSettings

Choosing Appropriate Idle Times and Idle States A framework-based driver can avoid its devices prematurely entering the idle state by increasing the IdleTimeout value and calling WdfDeviceUpdateS0IdleSettings each time the device becomes non-idle

Example PnP and Power Code for Supporting Device Idle This driver adds support for device idle by initializing WDF_DEVICE_POWER_POLICY_IDLE_SETTINGS structure and calling WdfDeviceUpdateS0IdleSettings P.22 -P.26

Framework Actions Supporting Device Idle The framework keeps a count of I/O activity on all power-managed WDFQUEUEs owned by each WDFDEVICE While the device is idling in its low-powered state, the framework will automatically transition the device back into D0 whenever the count of I/O activity on any of the device’s power-managed queues becomes non-zero