Suspend/Resume Implementation in KMDF Bus Driver

Hi Experts,
I am developing a Kmdf bus driver for a PCI device.In that i need to implement suspend and resume for such device.When i gone through KMDF event callbacks in MSDN, EvtDeviceQueryRemove/EvtDeviceQueryStop callback functions can be invoked to check whether the specified device can be stopped / removed.But I’m not sure which one is the exact callback function to implement suspend / resume.
Also ,I want to know will there be any ISR’s / IOCTL’s involved during /after the PnP Request to suspend/resume. I assume EvtDeviceD0Exit/EvtDeviceD0Entry can be invoked to achieve suspend/resume.But I’m not very much sure about these callback functions.
So,can anyone clear me,how can i achieve this implementation in KMDF Bus driver.
Thanks in Advance,
Saski

xxxxx@gmail.com wrote:

I am developing a Kmdf bus driver for a PCI device.In that i need to implement suspend and resume for such device.When i gone through KMDF event callbacks in MSDN, EvtDeviceQueryRemove/EvtDeviceQueryStop callback functions can be invoked to check whether the specified device can be stopped / removed.But I’m not sure which one is the exact callback function to implement suspend / resume.

The question is an odd one. PCI does not have the concept of
suspend/resume – that is an operating system concept. When the system
is about to suspend, your driver is not stopped and removed at all.
Instead, you will get a power notification, telling you that the power
state is about to change. This will call EvtDeviceD0Exit. When power
is restored, PnP will call EvtDeviceD0Entry.

Also ,I want to know will there be any ISR’s / IOCTL’s involved during /after the PnP Request to suspend/resume. I assume EvtDeviceD0Exit/EvtDeviceD0Entry can be invoked to achieve suspend/resume.But I’m not very much sure about these callback functions.

It may be just a language issue, but remember that YOU do not invoke
D0Exit and D0Entry. When the system wants to change the power state, IT
will call D0Exit and D0Entry. You need to write those functions to make
sure you are ready. In many cases, for a PCI device, nothing is required.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

I’m quite confused with this concept.SO,Can u clear me is there KMDF callback functions available to enable / disable my PCI device.Or it too depends on the above two D0Entry/D0Exit callback functions.So,whenever I enable my device,the framework will invoke D0Entry and while disabling the device ,it will invoke D0Exit.Is that correct.If not, then how can i implement such enable/disable features in my driver.

xxxxx@gmail.com wrote:

I’m quite confused with this concept. SO,Can u clear me is there KMDF callback functions available to enable / disable my PCI device. Or it too depends on the above two D0Entry/D0Exit callback functions. So,whenever I enable my device,the framework will invoke D0Entry and while disabling the device ,it will invoke D0Exit. Is that correct.If not, then how can i implement such enable/disable features in my driver.

You don’t have to disable your device. PnP will call D0Exit to let you
know that “your device power is about to be removed”. After you return,
PnP will then notify the PCI bus driver, and the bus driver will take
the steps to remove the power. When power is restored, again the PCI
bus driver will perform the actions to start things up again. PnP will
then call your D0Entry to let you know that you just came back to life.

So, in your D0Exit function, all you need to do is save any board state
information that you cannot recreate and will not survive a power
cycle. Many PCI boards do not have any such state, so their D0Exit
functions don’t do very much. Then, in D0Entry, you do whatever you
need to do to initialize your board, and if you saved any state in
D0Exit, you restore it.

The actual process of power off and power on are handled below. All you
need to do is prepare your board for that process, and it is entirely
possible your board needs no preparation.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

I have gone through some KMDF sample driver.In that,While registering the callback functions,it registers for specialfilesupport(WdfDeviceSetSpecialFileSupport). In this function it has the attribute as WdfSpecialFileHibernation.
I have also referred in MSDN sites.Once we use such callback,there is no need of using statemachine callback function.By using state machine callback function ,it is possible to track the state of power , device and pnp.So , Can u tell me, how this callback works and what exactly it does?

When I started to dig deeper about this WdfDeviceSetSpecialFileSupport() callback function, I have a doubt that how the D0Exit callback will be invoked.In power-down sequence,how the framework will be aware that the device is about to enter low-power state.If the device is about to exit D0,how the framework will be aware of it and invoke D0Exit… It’s making me to question everything.Can u clear me.Am a beginner in this KMDF Concept. So cant able to understand deeper.

Special file support only applies to storage devices that host a paging file… If your driver isn’t for such a device, then you don’t have to worry about Special File Support.

Working in the storage stack can be quite tricky when it comes to both power-down and remove. If this is what you’re trying to do, you need to tell us a LOT more about your device and what you’re trying to accomplish so we can help you properly.

Peter
OSR
@OSRDrivers

xxxxx@gmail.com wrote:

When I started to dig deeper about this WdfDeviceSetSpecialFileSupport() callback function, I have a doubt that how the D0Exit callback will be invoked.In power-down sequence,how the framework will be aware that the device is about to enter low-power state.If the device is about to exit D0,how the framework will be aware of it and invoke D0Exit… It’s making me to question everything.Can u clear me.Am a beginner in this KMDF Concept. So cant able to understand deeper.

You still do not understand the basic concepts here. Your driver is not
in control of this. The driver does not decide on its own that the
device will be entering a low power state. It all starts with the
system. When someone in PnP decides that the SYSTEM is going to leave
S0 and go to (for example) S3, it notifies each driver. In response,
the driver responds saying “if the system is going into S3, then I need
to go into D3”. In response to that, PnP will ask the driver to go into
D3, and when KMDF sees that, it calls D0Exit.

You are not making the decisions. You are only RESPONDING to the
actions that the PnP system wants to take.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Thanks Tim.I think now I have better understanding on these callback functions. So,what am lagging now is,while the device powered down from D0 to any low power state( i.e.,D3),Is that possible to retain the kernel allocations like DMA Allocations,ISR handler,Paged/Nonpaged Pool.So that when my device resumes from D3State,it should use the same kernel allocations which is done earlier.If so,how can I do such functionalities and Is there any eventcallback function related with implementation.

You are responsible for your device’s state, the os is responsible for os state. The os restores the relevant state like memory, interrupt handlers etc before asking you to restore the device state. If part of your power down is to disconnect the interrupt (usually it is to disable interrupts in the hw) you would need to connect it again in powering up.

Sent from Outlook Mailhttp: for Windows 10 phone

From: xxxxx@gmail.commailto:xxxxx
Sent: Wednesday, January 13, 2016 4:01 AM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: RE:[ntdev] Suspend/Resume Implementation in KMDF Bus Driver

Thanks Tim.I think now I have better understanding on these callback functions. So,what am lagging now is,while the device powered down from D0 to any low power state( i.e.,D3),Is that possible to retain the kernel allocations like DMA Allocations,ISR handler,Paged/Nonpaged https://na01.safelinks.protection.outlook.com/?url=Pool.So&data=01|01|Doron.Holan%40microsoft.com|ee9442e1a25540a1f84e08d31c113a6b|72f988bf86f141af91ab2d7cd011db47|1&sdata=IQEBAqVGWiO%2F7OJDguk%2B8YeoT8fkch10i3S6jIMBUVk%3D that when my device resumes from D3State,it should use the same kernel allocations which is done earlier.If so,how can I do such functionalities and Is there any eventcallback function related with implementation.


NTDEV is sponsored by OSR

Visit the list online at: https:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at https:

To unsubscribe, visit the List Server section of OSR Online at https:</https:></https:></https:></mailto:xxxxx></mailto:xxxxx></http:>