]> xenbits.xensource.com Git - legacy/linux-2.6.18-xen.git/commitdiff
backport: allocate cap save buffers for PCIe/PCI-X.
authorKeir Fraser <keir.fraser@citrix.com>
Wed, 18 Mar 2009 11:45:30 +0000 (11:45 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Wed, 18 Mar 2009 11:45:30 +0000 (11:45 +0000)
Changeset 819:e8a9f8910a3f doesn't backport all the necessary code.
This patch adds the missing part. It is also backported from upstream
Linux kernel and the git commit is:

commit 63f4898ace2788a89ed685672aab092e1c3e50e6
Author: Rafael J. Wysocki <rjw@sisk.pl>
Date:   Sun Dec 7 22:02:58 2008 +0100

    PCI: handle PCI state saving with interrupts disabled

    Since interrupts will soon be disabled at PCI resume time, we need
    to
    pre-allocate memory to save/restore PCI config space (or use
    GFP_ATOMIC=, but this is safer).

Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: "Rafael J. Wysocki" <rjw@sisk.pl>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
Signed-off-by: Dexuan Cui <dexuan.cui@intel.com>=
drivers/pci/pci.c
drivers/pci/pci.h
drivers/pci/probe.c

index 49da9adcde555c069d7630dc6b23ce3bcce66186..ee7b2be82210cedca31e146edd557d5b556fddd5 100644 (file)
@@ -705,6 +705,51 @@ int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable)
        return 0;
 }
 
+/**
+ * pci_add_save_buffer - allocate buffer for saving given capability registers
+ * @dev: the PCI device
+ * @cap: the capability to allocate the buffer for
+ * @size: requested size of the buffer
+ */
+static int pci_add_cap_save_buffer(
+       struct pci_dev *dev, char cap, unsigned int size)
+{
+       int pos;
+       struct pci_cap_saved_state *save_state;
+
+       pos = pci_find_capability(dev, cap);
+       if (pos <= 0)
+               return 0;
+
+       save_state = kzalloc(sizeof(*save_state) + size, GFP_KERNEL);
+       if (!save_state)
+               return -ENOMEM;
+
+       save_state->cap_nr = cap;
+       pci_add_saved_cap(dev, save_state);
+
+       return 0;
+}
+
+/**
+ * pci_allocate_cap_save_buffers - allocate buffers for saving capabilities
+ * @dev: the PCI device
+ */
+void pci_allocate_cap_save_buffers(struct pci_dev *dev)
+{
+       int error;
+
+       error = pci_add_cap_save_buffer(dev, PCI_CAP_ID_EXP, 4 * sizeof(u16));
+       if (error)
+               dev_err(&dev->dev,
+                       "unable to preallocate PCI Express save buffer\n");
+
+       error = pci_add_cap_save_buffer(dev, PCI_CAP_ID_PCIX, sizeof(u16));
+       if (error)
+               dev_err(&dev->dev,
+                       "unable to preallocate PCI-X save buffer\n");
+}
+
 /**
  * pci_enable_ari - enable ARI forwarding if hardware support it
  * @dev: the PCI device
index c3e06ef74a0e7738b1dee52b8d5360cd2b433561..b470b103615aa294c2bce0af475478a3007ebf70 100644 (file)
@@ -15,6 +15,8 @@ extern int pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
 extern int (*platform_pci_choose_state)(struct pci_dev *dev, pm_message_t state);
 extern int (*platform_pci_set_power_state)(struct pci_dev *dev, pci_power_t state);
 
+extern void pci_allocate_cap_save_buffers(struct pci_dev *dev);
+
 extern int pci_user_read_config_byte(struct pci_dev *dev, int where, u8 *val);
 extern int pci_user_read_config_word(struct pci_dev *dev, int where, u16 *val);
 extern int pci_user_read_config_dword(struct pci_dev *dev, int where, u32 *val);
index de7bfb709ac084d429f498bd578e5d6251445627..4cb5c5ac4e4fa61bdd7c88f5d82edc323b9d71b5 100644 (file)
@@ -892,6 +892,9 @@ void __devinit pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
        /* Fix up broken headers */
        pci_fixup_device(pci_fixup_header, dev);
 
+       /* Buffers for saving PCIe and PCI-X capabilities */
+       pci_allocate_cap_save_buffers(dev);
        /* Alternative Routing-ID Forwarding */
        pci_enable_ari(dev);