From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: ACPI Devel Maling List <linux-acpi@vger.kernel.org>
Cc: Alan Stern <stern@rowland.harvard.edu>,
Andi Kleen <andi@firstfloor.org>,
Jesse Barnes <jbarnes@virtuousgeek.org>,
pm list <linux-pm@lists.linux-foundation.org>,
Zhang Rui <rui.zhang@intel.com>,
Zhao Yakui <yakui.zhao@intel.com>, Pavel Machek <pavel@suse.cz>
Subject: [PATCH 4/9] PCI: Rework pci_set_power_state function (rev. 3)
Date: Wed, 2 Jul 2008 00:05:41 +0200 [thread overview]
Message-ID: <200807020005.42448.rjw@sisk.pl> (raw)
In-Reply-To: <200807012356.26669.rjw@sisk.pl>
From: Rafael J. Wysocki <rjw@sisk.pl>
PCI: Rework pci_set_power_state function (rev. 3)
Rework pci_set_power_state() so that the platform callback is
invoked before the native mechanism, if necessary. Also, make
the function check if the device is power manageable by the
platform before invoking the platform callback.
This may matter if the device dependent on additional power
resources controlled by the platform is being put into D0, in which
case those power resources must be turned on before we attempt to
handle the device itself.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Pavel Machek <pavel@suse.cz>
---
drivers/pci/pci-acpi.c | 16 +++--
drivers/pci/pci.c | 152 +++++++++++++++++++++++++++++++++----------------
2 files changed, 115 insertions(+), 53 deletions(-)
Index: linux-next/drivers/pci/pci.c
===================================================================
--- linux-next.orig/drivers/pci/pci.c
+++ linux-next/drivers/pci/pci.c
@@ -404,67 +404,56 @@ static inline pci_power_t platform_pci_c
}
/**
- * pci_set_power_state - Set the power state of a PCI device
- * @dev: PCI device to be suspended
- * @state: PCI power state (D0, D1, D2, D3hot, D3cold) we're entering
- *
- * Transition a device to a new power state, using the Power Management
- * Capabilities in the device's config space.
- *
- * RETURN VALUE:
- * -EINVAL if trying to enter a lower state than we're already in.
- * 0 if we're already in the requested state.
- * -EIO if device does not support PCI PM.
- * 0 if we can successfully change the power state.
+ * pci_raw_set_power_state - Use PCI PM registers to set the power state of
+ * given PCI device
+ * @dev: PCI device to handle.
+ * @pm: PCI PM capability offset of the device.
+ * @state: PCI power state (D0, 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.
*/
-int
-pci_set_power_state(struct pci_dev *dev, pci_power_t state)
+static int
+pci_raw_set_power_state(struct pci_dev *dev, int pm, pci_power_t state)
{
- int pm, need_restore = 0;
u16 pmcsr, pmc;
+ bool need_restore = false;
- /* bound the state we're entering */
- if (state > PCI_D3hot)
- state = PCI_D3hot;
-
- /*
- * If the device or the parent bridge can't support PCI PM, ignore
- * the request if we're doing anything besides putting it into D0
- * (which would only happen on boot).
- */
- if ((state == PCI_D1 || state == PCI_D2) && pci_no_d1d2(dev))
- return 0;
-
- /* find PCI PM capability in list */
- pm = pci_find_capability(dev, PCI_CAP_ID_PM);
-
- /* abort if the device doesn't support PM capabilities */
if (!pm)
return -EIO;
+ if (state < PCI_D0 || state > PCI_D3hot)
+ return -EINVAL;
+
/* Validate current state:
* Can enter D0 from any state, but if we can only go deeper
* to sleep if we're already in a low power state
*/
- if (state != PCI_D0 && dev->current_state > state) {
+ if (dev->current_state == state) {
+ /* we're already there */
+ return 0;
+ } else if (state != PCI_D0 && dev->current_state <= PCI_D3cold
+ && dev->current_state > state) {
dev_err(&dev->dev, "invalid power transition "
"(from state %d to %d)\n", dev->current_state, state);
return -EINVAL;
- } else if (dev->current_state == state)
- return 0; /* we're already there */
+ }
+ pci_read_config_word(dev, pm + PCI_PM_PMC, &pmc);
- pci_read_config_word(dev,pm + PCI_PM_PMC,&pmc);
if ((pmc & PCI_PM_CAP_VER_MASK) > 3) {
- dev_printk(KERN_DEBUG, &dev->dev, "unsupported PM cap regs "
- "version (%u)\n", pmc & PCI_PM_CAP_VER_MASK);
+ dev_err(&dev->dev, "unsupported PM cap regs version (%u)\n",
+ pmc & PCI_PM_CAP_VER_MASK);
return -EIO;
}
/* check if this device supports the desired state */
- if (state == PCI_D1 && !(pmc & PCI_PM_CAP_D1))
- return -EIO;
- else if (state == PCI_D2 && !(pmc & PCI_PM_CAP_D2))
+ if ((state == PCI_D1 && !(pmc & PCI_PM_CAP_D1))
+ || (state == PCI_D2 && !(pmc & PCI_PM_CAP_D2)))
return -EIO;
pci_read_config_word(dev, pm + PCI_PM_CTRL, &pmcsr);
@@ -483,7 +472,7 @@ pci_set_power_state(struct pci_dev *dev,
case PCI_UNKNOWN: /* Boot-up */
if ((pmcsr & PCI_PM_CTRL_STATE_MASK) == PCI_D3hot
&& !(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET))
- need_restore = 1;
+ need_restore = true;
/* Fall-through: force to D0 */
default:
pmcsr = 0;
@@ -500,12 +489,6 @@ pci_set_power_state(struct pci_dev *dev,
else if (state == PCI_D2 || dev->current_state == PCI_D2)
udelay(200);
- /*
- * Give firmware a chance to be called, such as ACPI _PRx, _PSx
- * Firmware method after native method ?
- */
- platform_pci_set_power_state(dev, state);
-
dev->current_state = state;
/* According to section 5.4.1 of the "PCI BUS POWER MANAGEMENT
@@ -530,6 +513,81 @@ pci_set_power_state(struct pci_dev *dev,
}
/**
+ * pci_update_current_state - Read PCI power state of given device from its
+ * PCI PM registers and cache it
+ * @dev: PCI device to handle.
+ * @pm: PCI PM capability offset of the device.
+ */
+static void pci_update_current_state(struct pci_dev *dev, int pm)
+{
+ if (pm) {
+ u16 pmcsr;
+
+ pci_read_config_word(dev, pm + PCI_PM_CTRL, &pmcsr);
+ dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK);
+ }
+}
+
+/**
+ * pci_set_power_state - Set the power state of a PCI device
+ * @dev: PCI device to handle.
+ * @state: PCI power state (D0, D1, D2, D3hot) to put the device into.
+ *
+ * Transition a device to a new power state, using the platform formware and/or
+ * the device's PCI PM registers.
+ *
+ * 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.
+ */
+int pci_set_power_state(struct pci_dev *dev, pci_power_t state)
+{
+ int pm, error;
+
+ /* bound the state we're entering */
+ if (state > PCI_D3hot)
+ state = PCI_D3hot;
+ else if (state < PCI_D0)
+ state = PCI_D0;
+ else if ((state == PCI_D1 || state == PCI_D2) && pci_no_d1d2(dev))
+ /*
+ * If the device or the parent bridge do not support PCI PM,
+ * ignore the request if we're doing anything other than putting
+ * it into D0 (which would only happen on boot).
+ */
+ return 0;
+
+ /* Find PCI PM capability in the list */
+ pm = pci_find_capability(dev, PCI_CAP_ID_PM);
+
+ if (state == PCI_D0 && platform_pci_power_manageable(dev)) {
+ /*
+ * Allow the platform to change the state, for example via ACPI
+ * _PR0, _PS0 and some such, but do not trust it.
+ */
+ int ret = platform_pci_set_power_state(dev, PCI_D0);
+ if (!ret)
+ pci_update_current_state(dev, pm);
+ }
+
+ error = pci_raw_set_power_state(dev, pm, state);
+
+ if (state > PCI_D0 && platform_pci_power_manageable(dev)) {
+ /* Allow the platform to finalize the transition */
+ int ret = platform_pci_set_power_state(dev, state);
+ if (!ret) {
+ pci_update_current_state(dev, pm);
+ error = 0;
+ }
+ }
+
+ return error;
+}
+
+/**
* pci_choose_state - Choose the power state of a PCI device
* @dev: PCI device to be suspended
* @state: target sleep state for the whole system. This is the value
Index: linux-next/drivers/pci/pci-acpi.c
===================================================================
--- linux-next.orig/drivers/pci/pci-acpi.c
+++ linux-next/drivers/pci/pci-acpi.c
@@ -277,12 +277,11 @@ static int acpi_pci_set_power_state(stru
[PCI_D3hot] = ACPI_STATE_D3,
[PCI_D3cold] = ACPI_STATE_D3
};
+ int error = -EINVAL;
- if (!handle)
- return -ENODEV;
/* If the ACPI device has _EJ0, ignore the device */
- if (ACPI_SUCCESS(acpi_get_handle(handle, "_EJ0", &tmp)))
- return 0;
+ if (!handle || ACPI_SUCCESS(acpi_get_handle(handle, "_EJ0", &tmp)))
+ return -ENODEV;
switch (state) {
case PCI_D0:
@@ -290,9 +289,14 @@ static int acpi_pci_set_power_state(stru
case PCI_D2:
case PCI_D3hot:
case PCI_D3cold:
- return acpi_bus_set_power(handle, state_conv[state]);
+ error = acpi_bus_set_power(handle, state_conv[state]);
}
- return -EINVAL;
+
+ if (!error)
+ printk(KERN_INFO "PCI: Power state of %s changed by ACPI\n",
+ pci_name(dev));
+
+ return error;
}
static struct pci_platform_pm_ops acpi_pci_platform_pm = {
next prev parent reply other threads:[~2008-07-01 22:14 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-01 21:56 [PATCH 0/9] PCI PM: Handling of PCI devices wake-up functionality (rev. 3) Rafael J. Wysocki
2008-07-01 22:00 ` [PATCH 1/9] PCI ACPI: Remove acpi_platform_enable_wakeup Rafael J. Wysocki
2008-07-01 22:03 ` [PATCH 2/9] ACPI: Introduce acpi_bus_power_manageable function Rafael J. Wysocki
2008-07-01 22:04 ` [PATCH 3/9] PCI: Introduce platform_pci_power_manageable function Rafael J. Wysocki
2008-07-01 22:05 ` Rafael J. Wysocki [this message]
2008-07-01 22:06 ` [PATCH 5/9] ACPI: Introduce acpi_device_sleep_wake function Rafael J. Wysocki
2008-07-01 22:07 ` [PATCH 6/9] ACPI: Introduce new device wakeup flag 'prepared' Rafael J. Wysocki
2008-07-01 22:08 ` [PATCH 7/9] PCI ACPI: Rework PCI handling of wake-up (rev. 4) Rafael J. Wysocki
2008-07-02 7:30 ` Zhao Yakui
2008-07-02 10:16 ` Rafael J. Wysocki
2008-07-01 22:09 ` [PATCH 8/9] PCI PM: Introduce pci_prepare_to_sleep and pci_back_from_sleep Rafael J. Wysocki
2008-07-01 22:10 ` [PATCH 9/9] PCI: Simplify PCI device PM code (rev. 4) Rafael J. Wysocki
2008-07-03 12:04 ` [PATCH 0/9] PCI PM: Handling of PCI devices wake-up functionality (rev. 3) Rafael J. Wysocki
2008-07-07 1:30 ` [PATCH 0/8] PCI PM: Handling of PCI devices wake-up functionality (rev. 4) Rafael J. Wysocki
2008-07-07 1:30 ` [PATCH 1/8] ACPI: Introduce acpi_bus_power_manageable function Rafael J. Wysocki
2008-07-07 1:32 ` [PATCH 2/8] PCI: Introduce platform_pci_power_manageable function Rafael J. Wysocki
2008-07-07 1:32 ` [PATCH 3/8] PCI: Rework pci_set_power_state function (rev. 4) Rafael J. Wysocki
2008-07-07 1:33 ` [PATCH 4/8] ACPI: Introduce acpi_device_sleep_wake function Rafael J. Wysocki
2008-07-07 1:34 ` [PATCH 5/8] ACPI: Introduce new device wakeup flag 'prepared' Rafael J. Wysocki
2008-07-07 14:08 ` Pavel Machek
2008-07-07 1:34 ` [PATCH 6/8] PCI ACPI: Rework PCI handling of wake-up (rev. 5) Rafael J. Wysocki
2008-07-11 20:30 ` Pavel Machek
2008-07-07 1:35 ` [PATCH 7/8] PCI PM: Introduce pci_prepare_to_sleep and pci_back_from_sleep Rafael J. Wysocki
2008-07-11 20:31 ` Pavel Machek
2008-07-07 1:36 ` [PATCH 8/8] PCI: Simplify PCI device PM code (rev. 4) Rafael J. Wysocki
2008-07-11 20:37 ` Pavel Machek
2008-07-11 20:45 ` Rafael J. Wysocki
2008-07-11 20:49 ` Pavel Machek
2008-07-08 0:49 ` [PATCH 0/8] PCI PM: Handling of PCI devices wake-up functionality " Jesse Barnes
2008-07-08 14:42 ` Rafael J. Wysocki
2008-07-13 20:45 ` PCI PM: Fix pci_prepare_to_sleep Rafael J. Wysocki
2008-07-14 21:27 ` Jesse Barnes
2008-07-14 21:40 ` 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=200807020005.42448.rjw@sisk.pl \
--to=rjw@sisk.pl \
--cc=andi@firstfloor.org \
--cc=jbarnes@virtuousgeek.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-pm@lists.linux-foundation.org \
--cc=pavel@suse.cz \
--cc=rui.zhang@intel.com \
--cc=stern@rowland.harvard.edu \
--cc=yakui.zhao@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).