From patchwork Tue Aug 20 18:24:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ott X-Patchwork-Id: 2847270 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id EB802BF546 for ; Tue, 20 Aug 2013 18:24:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AF6DC20524 for ; Tue, 20 Aug 2013 18:24:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2B29520512 for ; Tue, 20 Aug 2013 18:24:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751290Ab3HTSYb (ORCPT ); Tue, 20 Aug 2013 14:24:31 -0400 Received: from e06smtp12.uk.ibm.com ([195.75.94.108]:52381 "EHLO e06smtp12.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751238Ab3HTSYb (ORCPT ); Tue, 20 Aug 2013 14:24:31 -0400 Received: from /spool/local by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 20 Aug 2013 19:18:16 +0100 Received: from d06dlp01.portsmouth.uk.ibm.com (9.149.20.13) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 20 Aug 2013 19:18:14 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 9BBFF17D8058 for ; Tue, 20 Aug 2013 19:26:21 +0100 (BST) Received: from d06av02.portsmouth.uk.ibm.com (d06av02.portsmouth.uk.ibm.com [9.149.37.228]) by b06cxnps3074.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r7KIOEVD54132888 for ; Tue, 20 Aug 2013 18:24:14 GMT Received: from d06av02.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id r7KIOPvr013343 for ; Tue, 20 Aug 2013 12:24:26 -0600 Received: from icon-9-164-140-223.megacenter.de.ibm.com (icon-9-164-140-223.megacenter.de.ibm.com [9.164.140.223]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id r7KIOOtZ013328 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 20 Aug 2013 12:24:25 -0600 Date: Tue, 20 Aug 2013 20:24:24 +0200 (CEST) From: Sebastian Ott X-X-Sender: sebott@c4eb To: Bjorn Helgaas cc: "linux-pci@vger.kernel.org" Subject: Re: [PATCH] PCI: add hibernation hooks In-Reply-To: Message-ID: References: User-Agent: Alpine 2.03 (LFD 1266 2009-07-14) Organization: =?ISO-8859-15?Q?=22IBM_Deutschland_Research_&_Development_GmbH_=2F_Vorsitzende_des_Aufsichtsrats=3A_Martina_Koederitz_Gesch=E4ftsf=FChrung=3A_Dirk_Wittkopp_Sitz_der_Gesellschaft=3A_B=F6blingen_=2F_Registergericht?= =?ISO-8859-15?Q?=3A_Amtsgericht_Stuttgart=2C_HRB_243294=22?= MIME-Version: 1.0 X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13082018-8372-0000-0000-000006F1107E Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Tue, 20 Aug 2013, Bjorn Helgaas wrote: > On Tue, Aug 20, 2013 at 8:41 AM, Sebastian Ott > wrote: > > Hello Bjorn, > > > > I'm currently trying to implement hibernate support for pci on s390. To access > > the config space of a pci function on s390 the function has to be enabled first. > > So I need some kind of callback to achieve this before the pci core or the device > > driver tries to access the function after a resume from hibernate. > > > > Would you be OK with the following patch? > > I think doing something like this is fine. > > What would it look like if we provided empty weak definitions of the > eight functions you need to hook: pcibios_pm_freeze(), > pcibios_pm_freeze_noirq(), etc.? Then the callers wouldn't have to do > a test before making the call. Not sure which would be better, but it > might be more obvious that this is a build-time binding rather than a > dynamic binding. > > Should we check return values from the arch code? OK. I did one additional change - since we are not dependant on dev_pm_ops we can call these functions with a pci_dev *. Regards, Sebastian --- PCI: add hibernation hooks Platforms may want to provide architecture-specific functionality when a PCI device is doing a hibernate transition. Add weak symbols pcibios_pm_* that architectures can override to do so. Signed-off-by: Sebastian Ott --- drivers/pci/pci-driver.c | 46 ++++++++++++++++++++++++++++++++++++++-------- include/linux/pci.h | 11 +++++++++++ 2 files changed, 49 insertions(+), 8 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -763,6 +763,20 @@ static int pci_pm_resume(struct device * #ifdef CONFIG_HIBERNATE_CALLBACKS + +/* + * provide arch specific hooks when a pci device is doing + * a hibernate transition + */ +int __weak pcibios_pm_freeze(struct pci_dev *pdev) { return 0; } +int __weak pcibios_pm_freeze_noirq(struct pci_dev *pdev) { return 0; } +int __weak pcibios_pm_thaw(struct pci_dev *pdev) { return 0; } +int __weak pcibios_pm_thaw_noirq(struct pci_dev *pdev) { return 0; } +int __weak pcibios_pm_poweroff(struct pci_dev *pdev) { return 0; } +int __weak pcibios_pm_poweroff_noirq(struct pci_dev *pdev) { return 0; } +int __weak pcibios_pm_restore(struct pci_dev *pdev) { return 0; } +int __weak pcibios_pm_restore_noirq(struct pci_dev *pdev) { return 0; } + static int pci_pm_freeze(struct device *dev) { struct pci_dev *pci_dev = to_pci_dev(dev); @@ -786,7 +800,7 @@ static int pci_pm_freeze(struct device * return error; } - return 0; + return pcibios_pm_freeze(pci_dev); } static int pci_pm_freeze_noirq(struct device *dev) @@ -811,14 +825,18 @@ static int pci_pm_freeze_noirq(struct de pci_pm_set_unknown_state(pci_dev); - return 0; + return pcibios_pm_freeze_noirq(pci_dev); } static int pci_pm_thaw_noirq(struct device *dev) { struct pci_dev *pci_dev = to_pci_dev(dev); struct device_driver *drv = dev->driver; - int error = 0; + int error; + + error = pcibios_pm_thaw_noirq(pci_dev); + if (error) + return error; if (pci_has_legacy_pm_support(pci_dev)) return pci_legacy_resume_early(dev); @@ -835,7 +853,11 @@ static int pci_pm_thaw(struct device *de { struct pci_dev *pci_dev = to_pci_dev(dev); const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; - int error = 0; + int error; + + error = pcibios_pm_thaw(pci_dev); + if (error) + return error; if (pci_has_legacy_pm_support(pci_dev)) return pci_legacy_resume(dev); @@ -878,7 +900,7 @@ static int pci_pm_poweroff(struct device Fixup: pci_fixup_device(pci_fixup_suspend, pci_dev); - return 0; + return pcibios_pm_poweroff(pci_dev); } static int pci_pm_poweroff_noirq(struct device *dev) @@ -911,14 +933,18 @@ static int pci_pm_poweroff_noirq(struct if (pci_dev->class == PCI_CLASS_SERIAL_USB_EHCI) pci_write_config_word(pci_dev, PCI_COMMAND, 0); - return 0; + return pcibios_pm_poweroff_noirq(pci_dev); } static int pci_pm_restore_noirq(struct device *dev) { struct pci_dev *pci_dev = to_pci_dev(dev); struct device_driver *drv = dev->driver; - int error = 0; + int error; + + error = pcibios_pm_restore_noirq(pci_dev); + if (error) + return error; pci_pm_default_resume_early(pci_dev); @@ -935,7 +961,11 @@ static int pci_pm_restore(struct device { struct pci_dev *pci_dev = to_pci_dev(dev); const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; - int error = 0; + int error; + + error = pcibios_pm_restore(pci_dev); + if (error) + return error; /* * This is necessary for the hibernation error path in which restore is --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1648,6 +1648,17 @@ int pcibios_set_pcie_reset_state(struct int pcibios_add_device(struct pci_dev *dev); void pcibios_release_device(struct pci_dev *dev); +#ifdef CONFIG_HIBERNATE_CALLBACKS +int pcibios_pm_freeze(struct pci_dev *pdev); +int pcibios_pm_freeze_noirq(struct pci_dev *pdev); +int pcibios_pm_thaw(struct pci_dev *pdev); +int pcibios_pm_thaw_noirq(struct pci_dev *pdev); +int pcibios_pm_poweroff(struct pci_dev *pdev); +int pcibios_pm_poweroff_noirq(struct pci_dev *pdev); +int pcibios_pm_restore(struct pci_dev *pdev); +int pcibios_pm_restore_noirq(struct pci_dev *pdev); +#endif + #ifdef CONFIG_PCI_MMCONFIG void __init pci_mmcfg_early_init(void); void __init pci_mmcfg_late_init(void);