diff mbox series

[v3,8/9] PCI/PM: Avoid redundant current_state update

Message ID 1844408.CQOukoFCf9@kreacher (mailing list archive)
State Accepted
Commit 1e3d471e5cb10c7eb8f2b62f06dbd3bf3b515df7
Delegated to: Bjorn Helgaas
Headers show
Series PCI/PM: Improvements related to device transitions into D0 | expand

Commit Message

Rafael J. Wysocki April 14, 2022, 1:18 p.m. UTC
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Notice that if pci_power_up() returns success early, without updating
the given device's PCI_PM_CTRL register, because it has verified that
the power state of the device is D0 already at that point, the
pci_update_current_state() invocation in pci_pm_default_resume_early()
is redundant.

Avoid that redundant call by making pci_power_up() return 1 when it
has updated the device's PCI_PM_CTRL register and checking its return
value in pci_pm_default_resume_early().

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---

v2 -> v3:
   * Added R-by from Mika.

---
 drivers/pci/pci-driver.c |    5 +++--
 drivers/pci/pci.c        |   10 ++++++++--
 2 files changed, 11 insertions(+), 4 deletions(-)
diff mbox series

Patch

Index: linux-pm/drivers/pci/pci-driver.c
===================================================================
--- linux-pm.orig/drivers/pci/pci-driver.c
+++ linux-pm/drivers/pci/pci-driver.c
@@ -553,8 +553,9 @@  static void pci_pm_default_resume(struct
 
 static void pci_pm_default_resume_early(struct pci_dev *pci_dev)
 {
-	pci_power_up(pci_dev);
-	pci_update_current_state(pci_dev, PCI_D0);
+	if (pci_power_up(pci_dev))
+		pci_update_current_state(pci_dev, PCI_D0);
+
 	pci_restore_state(pci_dev);
 	pci_pme_restore(pci_dev);
 }
Index: linux-pm/drivers/pci/pci.c
===================================================================
--- linux-pm.orig/drivers/pci/pci.c
+++ linux-pm/drivers/pci/pci.c
@@ -1189,6 +1189,12 @@  static int pci_dev_wait(struct pci_dev *
 /**
  * pci_power_up - Put the given device into D0
  * @dev: PCI device to power up
+ *
+ * Use the platform firmware and the PCI_PM_CTRL register to put @dev into D0.
+ *
+ * Return 0 if invoking the platform firmware was sufficient to put @dev into D0
+ * (and so the PCI_PM_CTRL register was not updated), or 1 if it was necessary to
+ * update the PCI_PM_CTRL register, or -ENODEV if the device was not accessible.
  */
 int pci_power_up(struct pci_dev *dev)
 {
@@ -1244,7 +1250,7 @@  int pci_power_up(struct pci_dev *dev)
 		udelay(PCI_PM_D2_DELAY);
 
 	dev->current_state = PCI_D0;
-	return 0;
+	return 1;
 
 fail:
 	pci_err(dev, "Unable to change power state to D0, device inaccessible\n");
@@ -1294,7 +1300,7 @@  static int pci_set_full_power_state(stru
 	int ret;
 
 	ret = pci_power_up(dev);
-	if (ret)
+	if (ret < 0)
 		return ret;
 
 	if (!dev->pm_cap)