Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

PCI/PM: Rearrange pci_set_power_state()

The part of pci_set_power_state() related to transitions into
low-power states is unnecessary convoluted, so clearly divide it
into the D3cold special case and the general case covering all of
the other states.

Also fix a potential issue with calling pci_bus_set_current_state()
to set the current state of all devices on the subordinate bus to
D3cold without checking if the power state of the parent bridge has
really changed to D3cold.

Link: https://lore.kernel.org/r/2139440.Mh6RI2rZIc@kreacher
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>

authored by

Rafael J. Wysocki and committed by
Bjorn Helgaas
3cc2a2b2 0aacdc95

+17 -11
+17 -11
drivers/pci/pci.c
··· 1446 1446 if (state >= PCI_D3hot && (dev->dev_flags & PCI_DEV_FLAGS_NO_D3)) 1447 1447 return 0; 1448 1448 1449 - /* 1450 - * To put device in D3cold, we put device into D3hot in native 1451 - * way, then put device into D3cold with platform ops 1452 - */ 1453 - error = pci_set_low_power_state(dev, state > PCI_D3hot ? 1454 - PCI_D3hot : state); 1449 + if (state == PCI_D3cold) { 1450 + /* 1451 + * To put the device in D3cold, put it into D3hot in the native 1452 + * way, then put it into D3cold using platform ops. 1453 + */ 1454 + error = pci_set_low_power_state(dev, PCI_D3hot); 1455 1455 1456 - if (pci_platform_power_transition(dev, state)) 1457 - return error; 1456 + if (pci_platform_power_transition(dev, PCI_D3cold)) 1457 + return error; 1458 1458 1459 - /* Powering off a bridge may power off the whole hierarchy */ 1460 - if (state == PCI_D3cold) 1461 - pci_bus_set_current_state(dev->subordinate, PCI_D3cold); 1459 + /* Powering off a bridge may power off the whole hierarchy */ 1460 + if (dev->current_state == PCI_D3cold) 1461 + pci_bus_set_current_state(dev->subordinate, PCI_D3cold); 1462 + } else { 1463 + error = pci_set_low_power_state(dev, state); 1464 + 1465 + if (pci_platform_power_transition(dev, state)) 1466 + return error; 1467 + } 1462 1468 1463 1469 return 0; 1464 1470 }