linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Abhishek Sahu <abhsahu@nvidia.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>
Subject: Re: [PATCH] PCI: Fix the ACPI power state during runtime resume
Date: Fri, 4 Feb 2022 17:32:19 -0600	[thread overview]
Message-ID: <20220204233219.GA228585@bhelgaas> (raw)
In-Reply-To: <20220124122107.12148-1-abhsahu@nvidia.com>

[+cc Rafael, hoping for your review :)

Wonder if we should add something like this to MAINTAINERS so you get
cc'd on power-related things:

diff --git a/MAINTAINERS b/MAINTAINERS
index ea3e6c914384..3d9a211cad5d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -15422,6 +15422,7 @@ F:	include/linux/pm.h
 F:	include/linux/pm_*
 F:	include/linux/powercap.h
 F:	kernel/configs/nopm.config
+K:	pci_[a-z_]*power[a-z_]*\(
 
 DYNAMIC THERMAL POWER MANAGEMENT (DTPM)
 M:	Daniel Lezcano <daniel.lezcano@kernel.org>
]

On Mon, Jan 24, 2022 at 05:51:07PM +0530, Abhishek Sahu wrote:
> Consider the following sequence during PCI device runtime
> suspend/resume:
> 
> 1. PCI device goes into runtime suspended state. The PCI state
>    will be changed to PCI_D0 and then pci_platform_power_transition()
>    will be called which changes the ACPI state to ACPI_STATE_D3_HOT.
> 
> 2. Parent bridge goes into runtime suspended state. If parent
>    bridge supports D3cold, then it will change the power state of all its
>    children to D3cold state and the power will be removed.
> 
> 3. During wake-up time, the bridge will be runtime resumed first
>    and pci_power_up() will be called for the bridge. Now, the power
>    supply will be resumed.
> 
> 4. pci_resume_bus() will be called which will internally invoke
>    pci_restore_standard_config(). pci_update_current_state()
>    will read PCI_PM_CTRL register and the current_state will be
>    updated to D0.
> 
> In the above process, at step 4, the ACPI device state will still be
> ACPI_STATE_D3_HOT since pci_platform_power_transition() is not being
> invoked. We need call the pci_platform_power_transition() with state
> D0 to change the ACPI state to ACPI_STATE_D0.
> 
> This patch calls pci_power_up() if current power state is D0 inside
> pci_restore_standard_config(). This pci_power_up() will change the
> ACPI state to ACPI_STATE_D0.
> 
> Following are the steps to confirm:
> 
> Enable the debug prints in acpi_pci_set_power_state()
> 
> 0000:01:00.0 is PCI device and 0000:00:01.0 is parent bridge device
> 
> Before:
> 
> 0000:01:00.0: power state changed by ACPI to D3hot
> 0000:00:01.0: power state changed by ACPI to D3cold
> 0000:00:01.0: power state changed by ACPI to D0
> 
> After:
> 
> 0000:01:00.0: power state changed by ACPI to D3hot
> 0000:00:01.0: power state changed by ACPI to D3cold
> 0000:00:01.0: power state changed by ACPI to D0
> 0000:01:00.0: power state changed by ACPI to D0
> 
> So with this patch, the PCI device ACPI state is also being
> changed to D0.
> 
> Signed-off-by: Abhishek Sahu <abhsahu@nvidia.com>
> ---
>  drivers/pci/pci-driver.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
> index 588588cfda48..64e0cca12f16 100644
> --- a/drivers/pci/pci-driver.c
> +++ b/drivers/pci/pci-driver.c
> @@ -521,14 +521,22 @@ static void pci_device_shutdown(struct device *dev)
>   */
>  static int pci_restore_standard_config(struct pci_dev *pci_dev)
>  {
> +	int error = 0;
>  	pci_update_current_state(pci_dev, PCI_UNKNOWN);
>  
>  	if (pci_dev->current_state != PCI_D0) {
> -		int error = pci_set_power_state(pci_dev, PCI_D0);
> -		if (error)
> -			return error;
> +		error = pci_set_power_state(pci_dev, PCI_D0);
> +	} else {
> +		/*
> +		 * The platform power state can still be non-D0, so this is
> +		 * required to change the platform power state to D0.
> +		 */
> +		error = pci_power_up(pci_dev);
>  	}
>  
> +	if (error)
> +		return error;
> +
>  	pci_restore_state(pci_dev);
>  	pci_pme_restore(pci_dev);
>  	return 0;
> -- 
> 2.17.1
> 

  reply	other threads:[~2022-02-04 23:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-24 12:21 [PATCH] PCI: Fix the ACPI power state during runtime resume Abhishek Sahu
2022-02-04 23:32 ` Bjorn Helgaas [this message]
2022-02-07 18:58   ` Rafael J. Wysocki
2022-02-07 20:13     ` Bjorn Helgaas
2022-02-08 10:30     ` Abhishek Sahu
2022-04-05 16:36       ` Abhishek Sahu
2022-04-05 16:50         ` Rafael J. Wysocki
2022-04-06  5:32           ` Abhishek Sahu
2022-04-06 12:06             ` Rafael J. Wysocki
2022-04-06 18:43               ` Abhishek Sahu
2022-04-06 18:49                 ` 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=20220204233219.GA228585@bhelgaas \
    --to=helgaas@kernel.org \
    --cc=abhsahu@nvidia.com \
    --cc=bhelgaas@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    /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).