WDM power IRP (1)

Source: Internet
Author: User
Tags call back

Xuexi cannot be sent ???

Power Management is an important and difficult part of WDM drivers. It must be handled properly. Otherwise, various exceptions may occur during testing and use. The most serious issue is various bsod related to bug check 0x9f.

Here, we will briefly introduce two types of power IRPs: System-IRPs (system-IRPs) and device-state-related power IRPs (device-IRPs ). The dispatch we registered in the driver entry can accept the above system-IRP and device-IRP. The System-IRP/device-IRP mentioned below all refer to system power IRP/device power IRP.

This section only describes the following four types of power IRPs, including irp_mn_query_power system-IRP, irp_mn_query_power device-IRP, irp_mn_set_power system-IRP, and irp_mn_set_power device-IRP.

The system first sends the system-IRP when converting the power state. After receiving the function driver of the device, a device-IRP is generated, it is also delivered to the power dispatch through the system. The process is to set system-IRP to pending. After the device-IRP processing is complete, set the status of system-IRP Based on the returned status, and then complete the system-IRP. For detailed procedures, refer to the detailed descriptions below.

The four types of power IRPs can be divided into system and device based on different standards. They can also be divided into query, Se, and wakeup. This section only describes query and SET related power IRPs. The difference between query and set is briefly described here. Query is usually used by the system to ask whether a device can enter a certain power state. Set is usually sent after query, which means the system explicitly requires the device to enter a certain power state.

The following describes the processing process of the above IRP Based on the query and set types.

Irp_mn_query_power:

1) The system will issue irp_mn_query_power system-IRP

2a) function driver receives irp_mn_query_power system-IRP

-The function driver sets the I/O completion call back to enable necessary processing when the underlying Bus Driver returns

-The function driver continues to send this IRP to the underlying driver.

-Function Driver returns status_pending

After the underlying bus driver completes processing and complete the system-IRP, the above I/O completion call back a function will be called.

2b) 2a) in I/O completion call back a, the power manager needs to send an irp_mn_query_power system-IRP request based on the irp_mn_query_power device-IRP content mentioned above. When the request PM sends irp_mn_query_power device-IRP, it sets the completion call back B function and returns status_more_processing_required.

2c) function driver receives irp_mn_query_power device-IRP, which can be complete with success (device can be allowed to enter the required status) or fail (device cannot enter the required status ).

After that, the system will call to 2B) The completion call back B mentioned in.

2d) in completion call back B, set the status of irp_mn_query_power system-IRP TO THE STATUS OF irp_mn_query_power device-IRP. Complete irp_mn_query_power system-IRP at the same time.

2c) it is not always that allow/prohibit the system from entering the desired state. In some cases, the system may directly ask the device to enter the desired state without caring for these results through irp_mn_set_power.

Irp_mn_set_power:

3) The system sends irp_mn_set_power system-IRP

4A) function driver receives irp_mn_set_power system-IRP

-The function driver sets the I/O completion call back to enable necessary processing when the underlying Bus Driver returns

-The function driver continues to send this IRP to the underlying driver.

-Function Driver returns status_pending

After the underlying bus driver completes processing and complete the system-IRP, the above I/O completion call back C function will be called.

4b) 4A) in I/O completion call back a, the power manager needs to send an irp_mn_query_power device-IRP request based on the irp_mn_set_power system-IRP content mentioned above. When the request PM sends irp_mn_set_power device-IRP, it sets the completion call back d function and returns status_more_processing_required.

4c) when the function driver receives irp_mn_set_power device-IRP, it is necessary to specify the state of the set power and whether it is power-up or power-down.

4C1) if it is a power-up IRP, the IRP must first be delivered to the underlying bus driver, because the device needs the underlying bus power supply first. In addition, the function driver must wait for all pending IRPs to end before starting the operation. Of course, the function driver cannot directly block the wait because it will affect the system operation. The common practice is:

-The function driver sets the device-IRP to pending and sets the I/O completion call back E. After the underlying bus driver completes processing, it calls the call back. Then, this IRP is sent to the underlying driver and status_pending is returned. At this time, system-IRP and device-IRP are both in pending state.

-After the device-IRP is completed in the bus driver complete, the above I/O completion call back e will be called. At this time, the function driver still needs to wait until the pending IRP ends. Because the completion call back cannot be terminated, it must be handled at passive_level through system work thread. You can set a workitem A and return status_more_processing_required.

-System worker thread calls the preceding workitem A at passive_level. It can wait for all pending IRPs to be returned. The device-IRP will be complete.

4C2) for power-down IRP, the function driver must perform some necessary processing before distributing the device-IRP, because once the bus driver is down, some necessary operations required for resume will become inaccessible.

-The function driver can set workitem B and return sstatus_pending. Perform necessary backup operations in system worker thread passive_level.

-System worker thread calls the preceding workitem B at passive_level. After the backup action is completed, the device-IRP is sent to the underlying driver.

4d) in completion call back d, set the status of irp_mn_query_power system-irp to the status of irp_mn_query_power device-IRP. Complete irp_mn_query_power system-IRP at the same time.

For sample information, see wdkwinddk \ 7600.16385.1 \ SRC \ General \ toaster \ WDM \ func \ featured1.

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.