diff mbox

PCI: add hibernation hooks

Message ID alpine.LFD.2.03.1308202016210.1620@linux.vnet.ibm.com
State Accepted
Headers show

Commit Message

Sebastian Ott Aug. 20, 2013, 6:24 p.m. UTC
On Tue, 20 Aug 2013, Bjorn Helgaas wrote:
> On Tue, Aug 20, 2013 at 8:41 AM, Sebastian Ott
> <sebott@linux.vnet.ibm.com> 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 <sebott@linux.vnet.ibm.com>
---
 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
diff mbox

Patch

--- 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);