From patchwork Tue Nov 5 10:13:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 11227477 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 29F29112B for ; Tue, 5 Nov 2019 10:32:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1314521D71 for ; Tue, 5 Nov 2019 10:32:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388723AbfKEKcb (ORCPT ); Tue, 5 Nov 2019 05:32:31 -0500 Received: from cloudserver094114.home.pl ([79.96.170.134]:44576 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388703AbfKEKca (ORCPT ); Tue, 5 Nov 2019 05:32:30 -0500 Received: from 79.184.254.83.ipv4.supernova.orange.pl (79.184.254.83) (HELO kreacher.localnet) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.292) id 0ec36c7f3c6dcade; Tue, 5 Nov 2019 11:32:28 +0100 From: "Rafael J. Wysocki" To: Bjorn Helgaas Cc: LKML , Linux PCI , Linux PM , Mika Westerberg Subject: [PATCH 1/5] PCI: PM: Move power state update away from pci_power_up() Date: Tue, 05 Nov 2019 11:13:43 +0100 Message-ID: <37482337.udjOGdOKNb@kreacher> In-Reply-To: <2771503.n70vfTtcVb@kreacher> References: <2771503.n70vfTtcVb@kreacher> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Rafael J. Wysocki Move the invocation of pci_update_current_state() from pci_power_up() to pci_pm_default_resume_early(), which is the only caller of that function. Preparatory change, no functional impact. Signed-off-by: Rafael J. Wysocki --- drivers/pci/pci-driver.c | 1 + drivers/pci/pci.c | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) Index: linux-pm/drivers/pci/pci-driver.c =================================================================== --- linux-pm.orig/drivers/pci/pci-driver.c +++ linux-pm/drivers/pci/pci-driver.c @@ -524,6 +524,7 @@ static int pci_restore_standard_config(s 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); 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 @@ -1148,7 +1148,6 @@ void pci_power_up(struct pci_dev *dev) { __pci_start_power_transition(dev, PCI_D0); pci_raw_set_power_state(dev, PCI_D0); - pci_update_current_state(dev, PCI_D0); } /** From patchwork Tue Nov 5 10:27:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 11227471 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4F1E516B1 for ; Tue, 5 Nov 2019 10:32:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 37E3D21E6F for ; Tue, 5 Nov 2019 10:32:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388729AbfKEKcb (ORCPT ); Tue, 5 Nov 2019 05:32:31 -0500 Received: from cloudserver094114.home.pl ([79.96.170.134]:63627 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388583AbfKEKca (ORCPT ); Tue, 5 Nov 2019 05:32:30 -0500 Received: from 79.184.254.83.ipv4.supernova.orange.pl (79.184.254.83) (HELO kreacher.localnet) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.292) id 647da8bd74dd8b11; Tue, 5 Nov 2019 11:32:27 +0100 From: "Rafael J. Wysocki" To: Bjorn Helgaas Cc: LKML , Linux PCI , Linux PM , Mika Westerberg Subject: [PATCH 2/5] PCI: PM: Use pci_power_up() in pci_set_power_state() Date: Tue, 05 Nov 2019 11:27:49 +0100 Message-ID: <2520019.OZ1nXS5aSj@kreacher> In-Reply-To: <2771503.n70vfTtcVb@kreacher> References: <2771503.n70vfTtcVb@kreacher> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Rafael J. Wysocki Make it explicitly clear that the code to put devices into D0 in pci_set_power_state() and in pci_pm_default_resume_early() is the same by making the latter use pci_power_up() for transitions into D0. Code rearrangement, no intentional functional impact. Signed-off-by: Rafael J. Wysocki --- This is on top of https://patchwork.kernel.org/patch/11223673/ --- drivers/pci/pci.c | 25 +++++++++++++------------ drivers/pci/pci.h | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) Index: linux-pm/drivers/pci/pci.c =================================================================== --- linux-pm.orig/drivers/pci/pci.c +++ linux-pm/drivers/pci/pci.c @@ -1033,6 +1033,16 @@ static void __pci_start_power_transition } /** + * pci_power_up - Put the given device into D0 + * @dev: PCI device to power up + */ +int pci_power_up(struct pci_dev *dev) +{ + __pci_start_power_transition(dev, PCI_D0); + return pci_raw_set_power_state(dev, PCI_D0); +} + +/** * __pci_dev_set_current_state - Set current state of a PCI device * @dev: Device to handle * @data: pointer to state to be set @@ -1117,6 +1127,9 @@ int pci_set_power_state(struct pci_dev * if (dev->current_state == state) return 0; + if (state == PCI_D0) + return pci_power_up(dev); + /* * This device is quirked not to be put into D3, so don't put it in * D3 @@ -1124,8 +1137,6 @@ int pci_set_power_state(struct pci_dev * if (state >= PCI_D3hot && (dev->dev_flags & PCI_DEV_FLAGS_NO_D3)) return 0; - __pci_start_power_transition(dev, state); - /* * To put device in D3cold, we put device into D3hot in native * way, then put device into D3cold with platform ops @@ -1141,16 +1152,6 @@ int pci_set_power_state(struct pci_dev * EXPORT_SYMBOL(pci_set_power_state); /** - * pci_power_up - Put the given device into D0 forcibly - * @dev: PCI device to power up - */ -void pci_power_up(struct pci_dev *dev) -{ - __pci_start_power_transition(dev, PCI_D0); - pci_raw_set_power_state(dev, PCI_D0); -} - -/** * 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-pm/drivers/pci/pci.h =================================================================== --- linux-pm.orig/drivers/pci/pci.h +++ linux-pm/drivers/pci/pci.h @@ -85,7 +85,7 @@ struct pci_platform_pm_ops { int pci_set_platform_pm(const struct pci_platform_pm_ops *ops); void pci_update_current_state(struct pci_dev *dev, pci_power_t state); void pci_refresh_power_state(struct pci_dev *dev); -void pci_power_up(struct pci_dev *dev); +int pci_power_up(struct pci_dev *dev); void pci_disable_enabled_device(struct pci_dev *dev); int pci_finish_runtime_suspend(struct pci_dev *dev); void pcie_clear_root_pme_status(struct pci_dev *dev); From patchwork Tue Nov 5 10:29:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 11227481 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 00BD716B1 for ; Tue, 5 Nov 2019 10:32:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DC4A621A4A for ; Tue, 5 Nov 2019 10:32:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388707AbfKEKc3 (ORCPT ); Tue, 5 Nov 2019 05:32:29 -0500 Received: from cloudserver094114.home.pl ([79.96.170.134]:43855 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388700AbfKEKc3 (ORCPT ); Tue, 5 Nov 2019 05:32:29 -0500 Received: from 79.184.254.83.ipv4.supernova.orange.pl (79.184.254.83) (HELO kreacher.localnet) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.292) id 6bc7cd40211169eb; Tue, 5 Nov 2019 11:32:27 +0100 From: "Rafael J. Wysocki" To: Bjorn Helgaas Cc: LKML , Linux PCI , Linux PM , Mika Westerberg Subject: [PATCH 3/5] PCI: PM: Fold __pci_start_power_transition() into its caller Date: Tue, 05 Nov 2019 11:29:16 +0100 Message-ID: <3458080.lsoDbfkST9@kreacher> In-Reply-To: <2771503.n70vfTtcVb@kreacher> References: <2771503.n70vfTtcVb@kreacher> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Rafael J. Wysocki Because pci_power_up() has become the only caller of __pci_start_power_transition(), there is no need for the latter to be a separate function any more, so fold it into the former, drop a redundant check and reduce the number of lines of code somewhat. Code rearrangement, no intentional functional impact. Signed-off-by: Rafael J. Wysocki --- drivers/pci/pci.c | 48 ++++++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 30 deletions(-) Index: linux-pm/drivers/pci/pci.c =================================================================== --- linux-pm.orig/drivers/pci/pci.c +++ linux-pm/drivers/pci/pci.c @@ -1003,42 +1003,30 @@ void pci_wakeup_bus(struct pci_bus *bus) } /** - * __pci_start_power_transition - Start power transition of a PCI device - * @dev: PCI device to handle. - * @state: State to put the device into. + * pci_power_up - Put the given device into D0 + * @dev: PCI device to power up */ -static void __pci_start_power_transition(struct pci_dev *dev, pci_power_t state) +int pci_power_up(struct pci_dev *dev) { - if (state == PCI_D0) { - pci_platform_power_transition(dev, PCI_D0); + pci_platform_power_transition(dev, PCI_D0); + + /* + * Mandatory power management transition delays, see PCI Express Base + * Specification Revision 2.0 Section 6.6.1: Conventional Reset. Do not + * delay for devices powered on/off by corresponding bridge, because + * have already delayed for the bridge. + */ + if (dev->runtime_d3cold) { + if (dev->d3cold_delay && !dev->imm_ready) + msleep(dev->d3cold_delay); /* - * Mandatory power management transition delays, see - * PCI Express Base Specification Revision 2.0 Section - * 6.6.1: Conventional Reset. Do not delay for - * devices powered on/off by corresponding bridge, - * because have already delayed for the bridge. + * When powering on a bridge from D3cold, the whole hierarchy + * may be powered on into D0uninitialized state, resume them to + * give them a chance to suspend again */ - if (dev->runtime_d3cold) { - if (dev->d3cold_delay && !dev->imm_ready) - msleep(dev->d3cold_delay); - /* - * When powering on a bridge from D3cold, the - * whole hierarchy may be powered on into - * D0uninitialized state, resume them to give - * them a chance to suspend again - */ - pci_wakeup_bus(dev->subordinate); - } + pci_wakeup_bus(dev->subordinate); } -} -/** - * pci_power_up - Put the given device into D0 - * @dev: PCI device to power up - */ -int pci_power_up(struct pci_dev *dev) -{ - __pci_start_power_transition(dev, PCI_D0); return pci_raw_set_power_state(dev, PCI_D0); } From patchwork Tue Nov 5 10:30:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 11227465 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3F3B9112B for ; Tue, 5 Nov 2019 10:32:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 292CF222C6 for ; Tue, 5 Nov 2019 10:32:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388465AbfKEKc0 (ORCPT ); Tue, 5 Nov 2019 05:32:26 -0500 Received: from cloudserver094114.home.pl ([79.96.170.134]:44247 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388583AbfKEKcY (ORCPT ); Tue, 5 Nov 2019 05:32:24 -0500 Received: from 79.184.254.83.ipv4.supernova.orange.pl (79.184.254.83) (HELO kreacher.localnet) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.292) id 31dc8ebde46860d1; Tue, 5 Nov 2019 11:32:21 +0100 From: "Rafael J. Wysocki" To: Bjorn Helgaas Cc: LKML , Linux PCI , Linux PM , Mika Westerberg , Alex Deucher , amd-gfx@lists.freedesktop.org Subject: [PATCH 4/5] PCI: PM: Avoid exporting __pci_complete_power_transition() Date: Tue, 05 Nov 2019 11:30:36 +0100 Message-ID: <1731661.ykamz2Tiuf@kreacher> In-Reply-To: <2771503.n70vfTtcVb@kreacher> References: <2771503.n70vfTtcVb@kreacher> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Rafael J. Wysocki Notice that radeon_set_suspend(), which is the only caller of __pci_complete_power_transition() outside of pci.c, really only cares about the pci_platform_power_transition() invoked by it, so export the latter instead of it, update the radeon driver to call pci_platform_power_transition() directly and make __pci_complete_power_transition() static. Code rearrangement, no intentional functional impact. Signed-off-by: Rafael J. Wysocki --- drivers/pci/pci.c | 6 +++--- drivers/video/fbdev/aty/radeon_pm.c | 2 +- include/linux/pci.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) Index: linux-pm/drivers/pci/pci.c =================================================================== --- linux-pm.orig/drivers/pci/pci.c +++ linux-pm/drivers/pci/pci.c @@ -963,7 +963,7 @@ void pci_refresh_power_state(struct pci_ * @dev: PCI device to handle. * @state: State to put the device into. */ -static int pci_platform_power_transition(struct pci_dev *dev, pci_power_t state) +int pci_platform_power_transition(struct pci_dev *dev, pci_power_t state) { int error; @@ -979,6 +979,7 @@ static int pci_platform_power_transition return error; } +EXPORT_SYMBOL_GPL(pci_platform_power_transition); /** * pci_wakeup - Wake up a PCI device @@ -1061,7 +1062,7 @@ void pci_bus_set_current_state(struct pc * * This function should not be called directly by device drivers. */ -int __pci_complete_power_transition(struct pci_dev *dev, pci_power_t state) +static int __pci_complete_power_transition(struct pci_dev *dev, pci_power_t state) { int ret; @@ -1073,7 +1074,6 @@ int __pci_complete_power_transition(stru pci_bus_set_current_state(dev->subordinate, PCI_D3cold); return ret; } -EXPORT_SYMBOL_GPL(__pci_complete_power_transition); /** * pci_set_power_state - Set the power state of a PCI device Index: linux-pm/drivers/video/fbdev/aty/radeon_pm.c =================================================================== --- linux-pm.orig/drivers/video/fbdev/aty/radeon_pm.c +++ linux-pm/drivers/video/fbdev/aty/radeon_pm.c @@ -2593,7 +2593,7 @@ static void radeon_set_suspend(struct ra * calling pci_set_power_state() */ radeonfb_whack_power_state(rinfo, PCI_D2); - __pci_complete_power_transition(rinfo->pdev, PCI_D2); + pci_platform_power_transition(rinfo->pdev, PCI_D2); } else { printk(KERN_DEBUG "radeonfb (%s): switching to D0 state...\n", pci_name(rinfo->pdev)); Index: linux-pm/include/linux/pci.h =================================================================== --- linux-pm.orig/include/linux/pci.h +++ linux-pm/include/linux/pci.h @@ -1232,7 +1232,7 @@ struct pci_cap_saved_state *pci_find_sav int pci_add_cap_save_buffer(struct pci_dev *dev, char cap, unsigned int size); int pci_add_ext_cap_save_buffer(struct pci_dev *dev, u16 cap, unsigned int size); -int __pci_complete_power_transition(struct pci_dev *dev, pci_power_t state); +int pci_platform_power_transition(struct pci_dev *dev, pci_power_t state); int pci_set_power_state(struct pci_dev *dev, pci_power_t state); pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state); bool pci_pme_capable(struct pci_dev *dev, pci_power_t state); From patchwork Tue Nov 5 10:32:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 11227483 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B6B9916B1 for ; Tue, 5 Nov 2019 10:32:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9523321E6F for ; Tue, 5 Nov 2019 10:32:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388663AbfKEKcX (ORCPT ); Tue, 5 Nov 2019 05:32:23 -0500 Received: from cloudserver094114.home.pl ([79.96.170.134]:63694 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388465AbfKEKcX (ORCPT ); Tue, 5 Nov 2019 05:32:23 -0500 Received: from 79.184.254.83.ipv4.supernova.orange.pl (79.184.254.83) (HELO kreacher.localnet) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.292) id fa89029b01134efa; Tue, 5 Nov 2019 11:32:21 +0100 From: "Rafael J. Wysocki" To: Bjorn Helgaas Cc: LKML , Linux PCI , Linux PM , Mika Westerberg Subject: [PATCH 5/5] PCI: PM: Fold __pci_complete_power_transition() into its caller Date: Tue, 05 Nov 2019 11:32:02 +0100 Message-ID: <1769241.yKxyosiRnQ@kreacher> In-Reply-To: <2771503.n70vfTtcVb@kreacher> References: <2771503.n70vfTtcVb@kreacher> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Rafael J. Wysocki Because pci_set_power_state() has become the only caller of __pci_complete_power_transition(), there is no need for the latter to be a separate function any more, so fold it into the former, drop a redundant check and reduce the number of lines of code somewhat. Code rearrangement, no intentional functional impact. Signed-off-by: Rafael J. Wysocki --- drivers/pci/pci.c | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) Index: linux-pm/drivers/pci/pci.c =================================================================== --- linux-pm.orig/drivers/pci/pci.c +++ linux-pm/drivers/pci/pci.c @@ -1056,26 +1056,6 @@ void pci_bus_set_current_state(struct pc } /** - * __pci_complete_power_transition - Complete power transition of a PCI device - * @dev: PCI device to handle. - * @state: State to put the device into. - * - * This function should not be called directly by device drivers. - */ -static int __pci_complete_power_transition(struct pci_dev *dev, pci_power_t state) -{ - int ret; - - if (state <= PCI_D0) - return -EINVAL; - ret = pci_platform_power_transition(dev, state); - /* Power off the bridge may power off the whole hierarchy */ - if (!ret && state == PCI_D3cold) - pci_bus_set_current_state(dev->subordinate, PCI_D3cold); - return ret; -} - -/** * 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. @@ -1094,7 +1074,7 @@ static int __pci_complete_power_transiti */ int pci_set_power_state(struct pci_dev *dev, pci_power_t state) { - int error; + int error, ret; /* Bound the state we're entering */ if (state > PCI_D3cold) @@ -1132,10 +1112,12 @@ int pci_set_power_state(struct pci_dev * error = pci_raw_set_power_state(dev, state > PCI_D3hot ? PCI_D3hot : state); - if (!__pci_complete_power_transition(dev, state)) - error = 0; + ret = pci_platform_power_transition(dev, state); + /* Powering off a bridge may power off the whole hierarchy */ + if (!ret && state == PCI_D3cold) + pci_bus_set_current_state(dev->subordinate, PCI_D3cold); - return error; + return ret ? error : 0; } EXPORT_SYMBOL(pci_set_power_state);