How to add Modern standby to WDM driver architecture?

Hello everyone,

Firstly, I'm not sure if this question is appropriate for this forum, and if it's not, I will delete it. I'm a newcomer to Windows PCIe to Serial port driver development and I have a question about whether the WDM driver architecture can support modern standby functionality.

If it's feasible, how can it be implemented specifically? Do you have any relevant information or examples? I've searched the internet, but it seems that most of the information is about the WDF driver framework.

From what I know:
To support modern standby, both the hardware SoC and the driver need to support modern standby. However, I'd like to discuss first how to implement it in the driver.
Since modern standby involves entering S0idle, which is different from traditional sleep mode entering S3, in WDF, you can call WdfDeviceAssignS0IdleSettings() and put the device into the D3 state. But in WDM, I don't know what Windows function to call to enter S0idle and put the device into the D3 state.

I hope experienced seniors can share their experiences.

Thank you all.

There's a reason for that. If you do it in WDM, you will do it wrong.

I don't know what Windows function to call to enter S0idle

YOU don't make a call to enter S0Idle. The operating makes that decision, typically based on whether the devices are all ready for it. Your device should go into D3 as soon as it is not doing anything. If the devices are all in D3, then the system can shift into S0Idle.

Thank you for your reply.

To provide some additional context about my current platforms, I have two computers. Computer A supports Modern Standby (confirmed by running powercfg /a in Command Prompt), while computer B supports only traditional sleep mode. Initially, I used a WDM driver for traditional sleep mode on computer B. It seems that if I want to support Modern Standby on computer A, I'll have to convert the WDM driver to the WDF framework. This seems like a big work.

Is it the correct approach to convert from WDM to WDF?

Another question, I've found a Windows API called PoRegisterPowerSettingCallback and tried it on computer A. When I press the sleep button on computer A, it enters MyPowerSettingCallback() and prints a message. My idea is to put the device into D3 in the callback function, but will the system still remain in the S0 power state? I'm not sure if my idea is correct.

POWER_SETTING_CALLBACK MyPowerSettingCallback;
NTSTATUS RegisterPowerSettingCallback(PDEVICE_OBJECT DeviceObject)
{
    NTSTATUS status;

    status = PoRegisterPowerSettingCallback(
        (PDEVICE_OBJECT) DeviceObject,
        &GUID_MONITOR_POWER_ON,
        MyPowerSettingCallback,
        NULL,
        NULL
    );

    return status;
}

NTSTATUS
MyPowerSettingCallback(
    LPCGUID SettingGuid,
    PVOID Value,
    ULONG ValueLength,
    PVOID Context
)
{
    // Function body
    SerialDbgPrintEx(SERTRACECALLS, "PowerSettingCallback\n");

    return STATUS_SUCCESS;
}

NTSTATUS
DriverEntry(
           IN PDRIVER_OBJECT DriverObject,
           IN PUNICODE_STRING RegistryPath
           )

{
   ......

   status = RegisterPowerSettingCallback(DriverObject->DeviceObject);
   if (!NT_SUCCESS(status)) {
       SerialDbgPrintEx(SERTRACECALLS, "register RegisterPowerSettingCallback fail \n");
       return status;
   }

   .....
}

Thank you.

Supporting modern standby in a WDM device driver can be complicated. But, I’ve got to ask: What bigger goal are you trying to accomplish? The entire system, from the ACPI BIOS (specific setting are required, for example, in the FADT) to the peripheral device drivers ALL need to support modern standby.

So, simply adding PoFx support to one driver isn’t going to help.

Tell us your larger goal, and we’ll see if we can help.

Also… is this a work project or are you a hobbyist that’s playing around.

This is one of my work projects, but it's currently in the evaluation phase, so I need to understand whether modern standby can be implemented in WDM.

I recently studied the information about modern standby on Microsoft's official website. I know that supporting modern standby requires support from the CPU, BIOS, hardware, and firmware. This represents a significant change for sleep mode.

For my part, I only need to ensure that my device (a PCIe bridge) supports modern standby. I already have a system that supports modern standby available for use.

The problem I'm currently facing is how to take the first step if WDM can implement modern standby. You mentioned PoFx, which I found references to on the Microsoft website, but I didn't find practical examples, so I'm not quite sure how to proceed.

I'm not very familiar with Windows drivers, so some of my questions might seem a bit naive. Please bear with me.

The answer to this is "Yes" -- absolutely it can. NOT every driver in the system is a WDF driver.

I only need to ensure that my device (a PCIe bridge) supports modern standby

Hmmm... Off the top of my head, I'd say it'll be harder implementing a driver for a PCIe Bridge and integrating it into the system properly than it'll be to implement Modern Standby in the driver for that Bridge. But, you probably know more about the practical aspects of that than I do.

... every driver in the system is a WDF driver.

By which Mr Viscarola meant "WDM driver".

As long as you've implemented the standards, shouldn't a PCIe bridge be essentially invisible? Why is a driver required?

1 Like

Well, no... aside from the stupid typo (now corrected) in my post, I was very clumsily attempting to reference the fact that implementing Modern Standby in WDF is waaay simple compared to doing it in WDM.

I should have ended my post after "Absolutely it can." :grin:

This is what happens when I answer a complex question while I'm on lunch break from teaching a WDF Seminar.

Aside from that... "What Mr. Robers said" :slight_smile:

Blockquote
As long as you've implemented the standards, shouldn't a PCIe bridge be essentially invisible? Why is a driver required?

Our company's products are external PCIe devices, so they require a driver