linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Linux PCI <linux-pci@vger.kernel.org>
Cc: Linux PM <linux-pm@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Bjorn Helgaas <helgaas@kernel.org>,
	Mika Westerberg <mika.westerberg@linux.intel.com>
Subject: [PATCH v3 5/9] PCI/PM: Move pci_set_low_power_state() next to its caller
Date: Thu, 14 Apr 2022 15:14:10 +0200	[thread overview]
Message-ID: <3124866.5fSG56mABF@kreacher> (raw)
In-Reply-To: <5838942.lOV4Wx5bFT@kreacher>

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Because pci_set_power_state() is the only caller of
pci_set_low_power_state(), move the latter next to the former.

No functional impact.

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

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

---
 drivers/pci/pci.c |  160 +++++++++++++++++++++++++++---------------------------
 1 file changed, 80 insertions(+), 80 deletions(-)

Index: linux-pm/drivers/pci/pci.c
===================================================================
--- linux-pm.orig/drivers/pci/pci.c
+++ linux-pm/drivers/pci/pci.c
@@ -1068,86 +1068,6 @@ static inline bool platform_pci_bridge_d
 }
 
 /**
- * pci_set_low_power_state - Program the given device into a low-power state
- * @dev: PCI device to handle.
- * @state: PCI power state (D1, D2, D3hot) to put the device into.
- *
- * RETURN VALUE:
- * -EINVAL if the requested state is invalid.
- * -EIO if device does not support PCI PM or its PM capabilities register has a
- * wrong version, or device doesn't support the requested state.
- * 0 if device already is in the requested state.
- * 0 if device's power state has been successfully changed.
- */
-static int pci_set_low_power_state(struct pci_dev *dev, pci_power_t state)
-{
-	u16 pmcsr;
-
-	/* Check if we're already there */
-	if (dev->current_state == state)
-		return 0;
-
-	if (!dev->pm_cap)
-		return -EIO;
-
-	if (state < PCI_D1 || state > PCI_D3hot)
-		return -EINVAL;
-
-	/*
-	 * Validate transition: We can enter D0 from any state, but if
-	 * we're already in a low-power state, we can only go deeper.  E.g.,
-	 * we can go from D1 to D3, but we can't go directly from D3 to D1;
-	 * we'd have to go from D3 to D0, then to D1.
-	 */
-	if (dev->current_state <= PCI_D3cold && dev->current_state > state) {
-		pci_err(dev, "invalid power transition (from %s to %s)\n",
-			pci_power_name(dev->current_state),
-			pci_power_name(state));
-		return -EINVAL;
-	}
-
-	/* Check if this device supports the desired state */
-	if ((state == PCI_D1 && !dev->d1_support)
-	   || (state == PCI_D2 && !dev->d2_support))
-		return -EIO;
-
-	pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
-	if (PCI_POSSIBLE_ERROR(pmcsr)) {
-		pci_err(dev, "can't change power state from %s to %s (config space inaccessible)\n",
-			pci_power_name(dev->current_state),
-			pci_power_name(state));
-		return -EIO;
-	}
-
-	pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
-	pmcsr |= state;
-
-	/* Enter specified state */
-	pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, pmcsr);
-
-	/*
-	 * Mandatory power management transition delays; see PCI PM 1.1
-	 * 5.6.1 table 18
-	 */
-	if (state == PCI_D3hot)
-		pci_dev_d3_sleep(dev);
-	else if (state == PCI_D2)
-		udelay(PCI_PM_D2_DELAY);
-
-	pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
-	dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK);
-	if (dev->current_state != state)
-		pci_info_ratelimited(dev, "refused to change power state from %s to %s\n",
-			 pci_power_name(dev->current_state),
-			 pci_power_name(state));
-
-	if (dev->bus->self)
-		pcie_aspm_pm_state_change(dev->bus->self);
-
-	return 0;
-}
-
-/**
  * pci_update_current_state - Read power state of given device and cache it
  * @dev: PCI device to handle.
  * @state: State to cache in case the device doesn't have the PM capability
@@ -1405,6 +1325,86 @@ static int pci_set_full_power_state(stru
 
 	if (dev->bus->self)
 		pcie_aspm_pm_state_change(dev->bus->self);
+
+	return 0;
+}
+
+/**
+ * pci_set_low_power_state - Program the given device into a low-power state
+ * @dev: PCI device to handle.
+ * @state: PCI power state (D1, D2, D3hot) to put the device into.
+ *
+ * RETURN VALUE:
+ * -EINVAL if the requested state is invalid.
+ * -EIO if device does not support PCI PM or its PM capabilities register has a
+ * wrong version, or device doesn't support the requested state.
+ * 0 if device already is in the requested state.
+ * 0 if device's power state has been successfully changed.
+ */
+static int pci_set_low_power_state(struct pci_dev *dev, pci_power_t state)
+{
+	u16 pmcsr;
+
+	/* Check if we're already there */
+	if (dev->current_state == state)
+		return 0;
+
+	if (!dev->pm_cap)
+		return -EIO;
+
+	if (state < PCI_D1 || state > PCI_D3hot)
+		return -EINVAL;
+
+	/*
+	 * Validate transition: We can enter D0 from any state, but if
+	 * we're already in a low-power state, we can only go deeper.  E.g.,
+	 * we can go from D1 to D3, but we can't go directly from D3 to D1;
+	 * we'd have to go from D3 to D0, then to D1.
+	 */
+	if (dev->current_state <= PCI_D3cold && dev->current_state > state) {
+		pci_err(dev, "invalid power transition (from %s to %s)\n",
+			pci_power_name(dev->current_state),
+			pci_power_name(state));
+		return -EINVAL;
+	}
+
+	/* Check if this device supports the desired state */
+	if ((state == PCI_D1 && !dev->d1_support)
+	   || (state == PCI_D2 && !dev->d2_support))
+		return -EIO;
+
+	pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
+	if (PCI_POSSIBLE_ERROR(pmcsr)) {
+		pci_err(dev, "can't change power state from %s to %s (config space inaccessible)\n",
+			pci_power_name(dev->current_state),
+			pci_power_name(state));
+		return -EIO;
+	}
+
+	pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
+	pmcsr |= state;
+
+	/* Enter specified state */
+	pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, pmcsr);
+
+	/*
+	 * Mandatory power management transition delays; see PCI PM 1.1
+	 * 5.6.1 table 18
+	 */
+	if (state == PCI_D3hot)
+		pci_dev_d3_sleep(dev);
+	else if (state == PCI_D2)
+		udelay(PCI_PM_D2_DELAY);
+
+	pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
+	dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK);
+	if (dev->current_state != state)
+		pci_info_ratelimited(dev, "refused to change power state from %s to %s\n",
+			 pci_power_name(dev->current_state),
+			 pci_power_name(state));
+
+	if (dev->bus->self)
+		pcie_aspm_pm_state_change(dev->bus->self);
 
 	return 0;
 }




  parent reply	other threads:[~2022-04-14 13:32 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-09 13:03 [PATCH v1 0/7] PCI/PM: Improvements related to device transitions into D0 Rafael J. Wysocki
2022-04-09 13:05 ` [PATCH v1 1/7] PCI/PM: Resume subordinate bus in bus type callbacks Rafael J. Wysocki
2022-04-09 13:06 ` [PATCH v1 2/7] PCI/PM: Drop the runtime_d3cold PCI device flag Rafael J. Wysocki
2022-04-09 13:08 ` [PATCH v1 3/7] PCI/PM: Rearrange pci_update_current_state() Rafael J. Wysocki
2022-04-09 13:22 ` [PATCH v1 4/7] PCI/PM: Rework changing power states of PCI devices Rafael J. Wysocki
2022-04-09 13:23 ` [PATCH v1 5/7] PCI/PM: Move pci_set_low_power_state() next to its caller Rafael J. Wysocki
2022-04-09 13:26 ` [PATCH v1 6/7] PCI/PM: Clean up pci_set_low_power_state() Rafael J. Wysocki
2022-04-09 13:28 ` [PATCH v1 7/7] PCI/PM: Rearrange pci_set_power_state() Rafael J. Wysocki
2022-04-11 14:17 ` [PATCH v2 0/9] PCI/PM: Improvements related to device transitions into D0 Rafael J. Wysocki
2022-04-11 14:19   ` [PATCH v2 1/9] PCI/PM: Resume subordinate bus in bus type callbacks Rafael J. Wysocki
2022-04-11 14:20   ` [PATCH v2 2/9] PCI/PM: Drop the runtime_d3cold device flag Rafael J. Wysocki
2022-04-11 14:21   ` [PATCH v2 3/9] PCI/PM: Rearrange pci_update_current_state() Rafael J. Wysocki
2022-04-12  9:42     ` Mika Westerberg
2022-04-12 10:56       ` Rafael J. Wysocki
2022-04-11 14:25   ` [PATCH v2 4/9] PCI/PM: Rework changing power states of PCI devices Rafael J. Wysocki
2022-04-12 10:00     ` Mika Westerberg
2022-04-12 11:31       ` Rafael J. Wysocki
2022-04-12 11:38         ` Mika Westerberg
2022-04-11 14:27   ` [PATCH v2 5/9] PCI/PM: Move pci_set_low_power_state() next to its caller Rafael J. Wysocki
2022-04-11 14:28   ` [PATCH v2 6/9] PCI/PM: Clean up pci_set_low_power_state() Rafael J. Wysocki
2022-04-11 14:30   ` [PATCH v2 7/9] PCI/PM: Rearrange pci_set_power_state() Rafael J. Wysocki
2022-04-11 14:31   ` [PATCH v2 8/9] PCI/PM: Avoid redundant current_state update Rafael J. Wysocki
2022-04-11 14:33   ` [PATCH v2 9/9] PCI/PM: Replace pci_set_power_state() in pci_pm_thaw_noirq() Rafael J. Wysocki
2022-04-11 14:33   ` [PATCH v2 0/9] PCI/PM: Improvements related to device transitions into D0 Rafael J. Wysocki
2022-04-12 10:08   ` Mika Westerberg
2022-04-12 11:34     ` Rafael J. Wysocki
2022-04-14 13:00   ` [PATCH v3 " Rafael J. Wysocki
2022-04-14 13:04     ` [PATCH v3 1/9] PCI/PM: Resume subordinate bus in bus type callbacks Rafael J. Wysocki
2022-04-14 13:04     ` [PATCH v3 2/9] PCI/PM: Drop the runtime_d3cold device flag Rafael J. Wysocki
2022-04-14 13:07     ` [PATCH v3 3/9] PCI/PM: Rearrange pci_update_current_state() Rafael J. Wysocki
2022-04-14 13:11     ` [PATCH v3 4/9] PCI/PM: Rework changing power states of PCI devices Rafael J. Wysocki
2022-05-03 17:59       ` Nathan Chancellor
2022-05-04 12:59         ` Rafael J. Wysocki
2022-05-04 15:54           ` Anders Roxell
2022-05-04 16:36           ` Nathan Chancellor
2022-05-04 18:00             ` Rafael J. Wysocki
2022-05-04 19:35               ` Nathan Chancellor
2022-05-05 11:58                 ` Rafael J. Wysocki
2022-05-04 16:54         ` Bjorn Helgaas
2022-05-04 17:15           ` Rafael J. Wysocki
2022-04-14 13:14     ` Rafael J. Wysocki [this message]
2022-04-14 13:15     ` [PATCH v3 6/9] PCI/PM: Clean up pci_set_low_power_state() Rafael J. Wysocki
2022-04-14 13:17     ` [PATCH v3 7/9] PCI/PM: Rearrange pci_set_power_state() Rafael J. Wysocki
2022-04-14 13:18     ` [PATCH v3 8/9] PCI/PM: Avoid redundant current_state update Rafael J. Wysocki
2022-04-14 13:19     ` [PATCH v3 9/9] PCI/PM: Replace pci_set_power_state() in pci_pm_thaw_noirq() Rafael J. Wysocki
2022-04-20 16:25     ` [PATCH v3 0/9] PCI/PM: Improvements related to device transitions into D0 Bjorn Helgaas
2022-04-20 16:28       ` Rafael J. Wysocki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3124866.5fSG56mABF@kreacher \
    --to=rjw@rjwysocki.net \
    --cc=helgaas@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).