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 v1 1/2] PCI: PM: Avoid leaving devices in D0-uninitialized in pci_power_up()
Date: Mon, 04 Apr 2022 17:41:13 +0200 [thread overview]
Message-ID: <3623886.MHq7AAxBmi@kreacher> (raw)
In-Reply-To: <4198163.ejJDZkT8p0@kreacher>
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
In theory, pci_power_up() may leave a device in D0-uninitialized
during a transition from D3cold to D0.
Say, a PCIe device depending on some ACPI power resources is put into
D3cold, so the power resources in question are all turned off. Then,
pci_power_up() is called to put it into D0.
It first calls pci_platform_power_transition() which invokes
platform_pci_set_power_state() to turn on the ACPI power resources
depended on by the device and, if that is successful, it calls
pci_update_current_state() to update the current_state field of
the PCI device object. If the device's configuration space is
accessible at this point, which is the case if
platform_pci_set_power_state() leaves it in D0-uninitialized (and
there's nothing to prevent it from doing so), current_state will be
set to PCI_D0 and the pci_raw_set_power_state() called subsequently
will notice that the device is in D0 already and do nothing.
However, that is not correct, because it may be still necessary to
restore the device's BARs at this point.
To address this issue, set current_state temporarily to PCI_D3hot
in the cases in which pci_raw_set_power_state() may need to do more
than just changing the power state of the device.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/pci/pci.c | 10 ++++++++++
1 file changed, 10 insertions(+)
Index: linux-pm/drivers/pci/pci.c
===================================================================
--- linux-pm.orig/drivers/pci/pci.c
+++ linux-pm/drivers/pci/pci.c
@@ -1309,6 +1309,8 @@ static int pci_dev_wait(struct pci_dev *
*/
int pci_power_up(struct pci_dev *dev)
{
+ pci_power_t old_state = dev->current_state;
+
pci_platform_power_transition(dev, PCI_D0);
/*
@@ -1325,6 +1327,14 @@ int pci_power_up(struct pci_dev *dev)
pci_resume_bus(dev->subordinate);
}
+ /*
+ * For transitions from D3hot or deeper and initial power-up, force
+ * PCI_PM_CTRL register write, D3*->D0 transition delay and BARS
+ * restoration.
+ */
+ if (old_state >= PCI_D3hot)
+ dev->current_state = PCI_D3hot;
+
return pci_raw_set_power_state(dev, PCI_D0);
}
next prev parent reply other threads:[~2022-04-04 15:42 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-04 15:38 [PATCH v1 0/2]: PCI: PM: Improvements related to D3cold -> D0 transitions Rafael J. Wysocki
2022-04-04 15:41 ` Rafael J. Wysocki [this message]
2022-04-05 9:53 ` [PATCH v1 1/2] PCI: PM: Avoid leaving devices in D0-uninitialized in pci_power_up() Mika Westerberg
2022-04-07 19:01 ` Rafael J. Wysocki
2022-04-08 12:43 ` Mika Westerberg
2022-04-04 15:42 ` [PATCH v1 2/2] PCI: PM: Resume bus after putting the bridge into D0 entirely Rafael J. Wysocki
2022-04-05 9:54 ` Mika Westerberg
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=3623886.MHq7AAxBmi@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