Skip to content

Commit

Permalink
PCI: PM: Avoid forcing PCI_D0 for wakeup reasons inconsistently
Browse files Browse the repository at this point in the history
It is inconsistent to return PCI_D0 from pci_target_state() instead
of the original target state if 'wakeup' is true and the device
cannot signal PME from D0.

This only happens when the device cannot signal PME from the original
target state and any shallower power states (including D0) and that
case is effectively equivalent to the one in which PME singaling is
not supported at all.  Since the original target state is returned in
the latter case, make the function do that in the former one too.

Link: https://lore.kernel.org/linux-pm/3149540.aeNJFYEL58@kreacher/
Fixes: 666ff6f ("PCI/PM: Avoid using device_may_wakeup() for runtime PM")
Reported-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reported-by: Utkarsh H Patel <utkarsh.h.patel@intel.com>
Reported-by: Koba Ko <koba.ko@canonical.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
  • Loading branch information
rafaeljw committed Aug 4, 2021
1 parent 14858dc commit da9f215
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions drivers/pci/pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -2595,16 +2595,20 @@ static pci_power_t pci_target_state(struct pci_dev *dev, bool wakeup)
if (dev->current_state == PCI_D3cold)
target_state = PCI_D3cold;

if (wakeup) {
if (wakeup && dev->pme_support) {
pci_power_t state = target_state;

/*
* Find the deepest state from which the device can generate
* PME#.
*/
if (dev->pme_support) {
while (target_state
&& !(dev->pme_support & (1 << target_state)))
target_state--;
}
while (state && !(dev->pme_support & (1 << state)))
state--;

if (state)
return state;
else if (dev->pme_support & 1)
return PCI_D0;
}

return target_state;
Expand Down

0 comments on commit da9f215

Please sign in to comment.