]> xenbits.xensource.com Git - legacy/linux-2.6.18-xen.git/commitdiff
Save/restore PCIe/PCI-X states across S3.
authorKeir Fraser <keir.fraser@citrix.com>
Fri, 13 Mar 2009 10:08:22 +0000 (10:08 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Fri, 13 Mar 2009 10:08:22 +0000 (10:08 +0000)
This patch is backported from upstream Linux kernel.

commit b56a5a23bfecd9cac9187164a9d5f22d287c48b9
Author: Michael S. Tsirkin <mst@mellanox.co.il>
Date:   Mon Aug 21 16:22:22 2006 +0300

    PCI: Restore PCI Express capability registers after PM event

    Restore PCI Express capability registers after PM event.
    This includes maxumum MTU for PCI express and other vital data.

Signed-off-by: Michael S. Tsirkin <mst@mellanox.co.il>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
commit cc692a5f1e9816671b77da77c6d6c463156ba1c7
Author: Stephen Hemminger <shemminger@osdl.org>
Date:   Wed Nov 8 16:17:15 2006 -0800

    PCI: save/restore PCI-X state

    Shouldn't PCI-X state be saved/restored?  No device really needs
    this
    right now. qla24xx (fc HBA) and mthca (infiniband) don't do
    suspend,
    and sky2 resets its tweaks when links are brought up.

Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Dexuan Cui <dexuan.cui@intel.com>
drivers/pci/pci.c

index 0361192725d414b1d64ff4ca4bdd0b5d2a20595a..27294502d9ad8abb40f26aed781a23e077dda9a9 100644 (file)
@@ -428,6 +428,86 @@ pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state)
 
 EXPORT_SYMBOL(pci_choose_state);
 
+static int pci_save_pcie_state(struct pci_dev *dev)
+{
+       int pos, i = 0;
+       struct pci_cap_saved_state *save_state;
+       u16 *cap;
+
+       pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
+       if (pos <= 0)
+               return 0;
+
+       save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP);
+       if (!save_state) {
+               dev_err(&dev->dev, "buffer not found in %s\n", __FUNCTION__);
+               return -ENOMEM;
+       }
+       cap = (u16 *)&save_state->data[0];
+
+       pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &cap[i++]);
+       pci_read_config_word(dev, pos + PCI_EXP_LNKCTL, &cap[i++]);
+       pci_read_config_word(dev, pos + PCI_EXP_SLTCTL, &cap[i++]);
+       pci_read_config_word(dev, pos + PCI_EXP_RTCTL, &cap[i++]);
+
+       return 0;
+}
+
+static void pci_restore_pcie_state(struct pci_dev *dev)
+{
+       int i = 0, pos;
+       struct pci_cap_saved_state *save_state;
+       u16 *cap;
+
+       save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP);
+       pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
+       if (!save_state || pos <= 0)
+               return;
+       cap = (u16 *)&save_state->data[0];
+
+       pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, cap[i++]);
+       pci_write_config_word(dev, pos + PCI_EXP_LNKCTL, cap[i++]);
+       pci_write_config_word(dev, pos + PCI_EXP_SLTCTL, cap[i++]);
+       pci_write_config_word(dev, pos + PCI_EXP_RTCTL, cap[i++]);
+}
+
+
+static int pci_save_pcix_state(struct pci_dev *dev)
+{
+       int pos;
+       struct pci_cap_saved_state *save_state;
+
+       pos = pci_find_capability(dev, PCI_CAP_ID_PCIX);
+       if (pos <= 0)
+               return 0;
+
+       save_state = pci_find_saved_cap(dev, PCI_CAP_ID_PCIX);
+       if (!save_state) {
+               dev_err(&dev->dev, "buffer not found in %s\n", __FUNCTION__);
+               return -ENOMEM;
+       }
+
+       pci_read_config_word(dev, pos + PCI_X_CMD, (u16 *)save_state->data);
+
+       return 0;
+}
+
+static void pci_restore_pcix_state(struct pci_dev *dev)
+{
+       int i = 0, pos;
+       struct pci_cap_saved_state *save_state;
+       u16 *cap;
+
+       save_state = pci_find_saved_cap(dev, PCI_CAP_ID_PCIX);
+       pos = pci_find_capability(dev, PCI_CAP_ID_PCIX);
+       if (!save_state || pos <= 0)
+               return;
+       cap = (u16 *)&save_state->data[0];
+
+       pci_write_config_word(dev, pos + PCI_X_CMD, cap[i++]);
+}
+
+
 /**
  * pci_save_state - save the PCI configuration space of a device before suspending
  * @dev: - PCI device that we're dealing with
@@ -443,6 +523,11 @@ pci_save_state(struct pci_dev *dev)
                return i;
        if ((i = pci_save_msix_state(dev)) != 0)
                return i;
+       if ((i = pci_save_pcie_state(dev)) != 0)
+               return i;
+       if ((i = pci_save_pcix_state(dev)) != 0)
+               return i;
+
        return 0;
 }
 
@@ -456,6 +541,9 @@ pci_restore_state(struct pci_dev *dev)
        int i;
        int val;
 
+       /* PCI Express register must be restored first */
+       pci_restore_pcie_state(dev);
+
        /*
         * The Base Address register should be programmed before the command
         * register(s)
@@ -471,6 +559,7 @@ pci_restore_state(struct pci_dev *dev)
                                dev->saved_config_space[i]);
                }
        }
+       pci_restore_pcix_state(dev);
        pci_restore_msi_state(dev);
        pci_restore_msix_state(dev);
        return 0;