Skip to contentSkip to conversation

Potential issue with pci_prepare_to_sleep if there's no platform support for D3cold transition

DISCUSSION Heiner Kallweit 3 participants 5 messages Apr 21, 2025 – Apr 23, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

If there's no platform support for transition to D3cold, then pci_set_power_state(dev, D3cold) still returns 0, even though power state is transitioned to D3hot only. We called pci_enable_wake(dev, D3cold, wakeup) before, therefore PME for D3hot may not be enabled. Is this a bug?

Background:
In __pci_set_power_state we have the following:

error = pci_set_low_power_state(dev, PCI_D3hot, locked); if (pci_platform_power_transition(dev, PCI_D3cold))

	return error;

The acpi_pci_set_power_state() stub returns -ENODEV. Therefore, if error=0, __pci_set_power_state() will return 0 if pci_platform_power_transition() fails.

#1 lore raw

[cc += Rafael, linux-acpi]

Quoted 9 lines · Heiner Kallweit

If there's no platform support for transition to D3cold, then pci_set_power_state(dev, D3cold) still returns 0, even though power state is transitioned to D3hot only. We called pci_enable_wake(dev, D3cold, wakeup) before, therefore PME for D3hot may not be enabled. Is this a bug?

Background:
In __pci_set_power_state we have the following:

Quoted 7 lines

error = pci_set_low_power_state(dev, PCI_D3hot, locked); if (pci_platform_power_transition(dev, PCI_D3cold))

	return error;

The acpi_pci_set_power_state() stub returns -ENODEV. Therefore, if error=0, __pci_set_power_state() will return 0 if pci_platform_power_transition() fails.

pci_prepare_to_sleep() calls pci_target_state() right at the top.

If wakeup is supported and enabled, pci_target_state() is supposed to find the deepest power state supporting wakeup. If D3cold doesn't support wakeup, D3hot or a shallower state is returned.

Hence I don't quite understand how the scenario you're describing could occur in practice. Are you seeing actual issues and have tracked them down to incorrect handling in pci_prepare_to_sleep()?

Thanks,

Lukas

#2 lore raw
Quoted 9 lines · Lukas Wunner

[cc += Rafael, linux-acpi]

Quoted 5 lines · Heiner Kallweit

If there's no platform support for transition to D3cold, then pci_set_power_state(dev, D3cold) still returns 0, even though power state is transitioned to D3hot only. We called pci_enable_wake(dev, D3cold, wakeup) before, therefore PME for D3hot may not be enabled. Is this a bug?

On platforms using ACPI, no it isn't.

Internally, pci_enable_wake() evaluates _DSW and it doesn't distinguish between D3hot and D3cold as per the spec.

Quoted 20 lines
Quoted 10 lines

Background:
In __pci_set_power_state we have the following:

error = pci_set_low_power_state(dev, PCI_D3hot, locked); if (pci_platform_power_transition(dev, PCI_D3cold))

      return error;

The acpi_pci_set_power_state() stub returns -ENODEV. Therefore, if error=0, __pci_set_power_state() will return 0 if pci_platform_power_transition() fails.

pci_prepare_to_sleep() calls pci_target_state() right at the top.

If wakeup is supported and enabled, pci_target_state() is supposed to find the deepest power state supporting wakeup. If D3cold doesn't support wakeup, D3hot or a shallower state is returned.

Hence I don't quite understand how the scenario you're describing could occur in practice. Are you seeing actual issues and have tracked them down to incorrect handling in pci_prepare_to_sleep()?

#3 lore raw
Quoted 12 lines · Rafael J. Wysocki
Quoted 9 lines · Lukas Wunner

[cc += Rafael, linux-acpi]

Quoted 5 lines · Heiner Kallweit

If there's no platform support for transition to D3cold, then pci_set_power_state(dev, D3cold) still returns 0, even though power state is transitioned to D3hot only. We called pci_enable_wake(dev, D3cold, wakeup) before, therefore PME for D3hot may not be enabled. Is this a bug?

Quoted 25 lines

On platforms using ACPI, no it isn't.

Internally, pci_enable_wake() evaluates _DSW and it doesn't distinguish between D3hot and D3cold as per the spec.

Quoted 20 lines
Quoted 10 lines

Background:
In __pci_set_power_state we have the following:

error = pci_set_low_power_state(dev, PCI_D3hot, locked); if (pci_platform_power_transition(dev, PCI_D3cold))

      return error;

The acpi_pci_set_power_state() stub returns -ENODEV. Therefore, if error=0, __pci_set_power_state() will return 0 if pci_platform_power_transition() fails.

pci_prepare_to_sleep() calls pci_target_state() right at the top.

If wakeup is supported and enabled, pci_target_state() is supposed to find the deepest power state supporting wakeup. If D3cold doesn't support wakeup, D3hot or a shallower state is returned.

Hence I don't quite understand how the scenario you're describing could occur in practice. Are you seeing actual issues and have tracked them down to incorrect handling in pci_prepare_to_sleep()?

On non-ACPI systems pci_target_state() just looks at the device capabilities. The described scenario can happen if device supports wake from D3cold, but platform has no means to switch a device to D3cold. I'm thinking of e.g. RTL8125 on ARM. Typically I don't expect an issue because boot-up default on these devices is to have PME wake from all states enabled. So it's more of a theoretical exercise at the moment.

#4 lore raw
Quoted 40 lines · Heiner Kallweit
Quoted 12 lines · Rafael J. Wysocki
Quoted 9 lines · Lukas Wunner

[cc += Rafael, linux-acpi]

Quoted 5 lines · Heiner Kallweit

If there's no platform support for transition to D3cold, then pci_set_power_state(dev, D3cold) still returns 0, even though power state is transitioned to D3hot only. We called pci_enable_wake(dev, D3cold, wakeup) before, therefore PME for D3hot may not be enabled. Is this a bug?

Quoted 25 lines

On platforms using ACPI, no it isn't.

Internally, pci_enable_wake() evaluates _DSW and it doesn't distinguish between D3hot and D3cold as per the spec.

Quoted 20 lines
Quoted 10 lines

Background:
In __pci_set_power_state we have the following:

error = pci_set_low_power_state(dev, PCI_D3hot, locked); if (pci_platform_power_transition(dev, PCI_D3cold))

      return error;

The acpi_pci_set_power_state() stub returns -ENODEV. Therefore, if error=0, __pci_set_power_state() will return 0 if pci_platform_power_transition() fails.

pci_prepare_to_sleep() calls pci_target_state() right at the top.

If wakeup is supported and enabled, pci_target_state() is supposed to find the deepest power state supporting wakeup. If D3cold doesn't support wakeup, D3hot or a shallower state is returned.

Hence I don't quite understand how the scenario you're describing could occur in practice. Are you seeing actual issues and have tracked them down to incorrect handling in pci_prepare_to_sleep()?

Quoted 7 lines

On non-ACPI systems pci_target_state() just looks at the device capabilities. The described scenario can happen if device supports wake from D3cold, but platform has no means to switch a device to D3cold. I'm thinking of e.g. RTL8125 on ARM. Typically I don't expect an issue because boot-up default on these devices is to have PME wake from all states enabled. So it's more of a theoretical exercise at the moment.

I just see that pci_target_state() won't return D3cold for non-ACPI systems. Therefore sorry for the noise.