pci: Stamp out pci_find_* usage in fakephp
[safe/jmp/linux-2.6] / drivers / pci / pci.c
index d252045..a544997 100644 (file)
@@ -19,6 +19,7 @@
 #include <asm/dma.h>   /* isa_dma_bridge_buggy */
 #include "pci.h"
 
+unsigned int pci_pm_d3_delay = 10;
 
 /**
  * pci_bus_max_busnr - returns maximum PCI bus number of given bus' children
@@ -164,7 +165,6 @@ int pci_bus_find_capability(struct pci_bus *bus, unsigned int devfn, int cap)
        return __pci_bus_find_cap(bus, devfn, hdr_type & 0x7f, cap);
 }
 
-#if 0
 /**
  * pci_find_ext_capability - Find an extended capability
  * @dev: PCI device to query
@@ -212,7 +212,7 @@ int pci_find_ext_capability(struct pci_dev *dev, int cap)
 
        return 0;
 }
-#endif  /*  0  */
+EXPORT_SYMBOL_GPL(pci_find_ext_capability);
 
 /**
  * pci_find_parent_resource - return resource region of parent bus of given region
@@ -314,6 +314,14 @@ pci_set_power_state(struct pci_dev *dev, pci_power_t state)
        } else if (dev->current_state == state)
                return 0;        /* we're already there */
 
+       /*
+        * If the device or the parent bridge can't support PCI PM, ignore
+        * the request if we're doing anything besides putting it into D0
+        * (which would only happen on boot).
+        */
+       if ((state == PCI_D1 || state == PCI_D2) && pci_no_d1d2(dev))
+               return 0;
+
        /* find PCI PM capability in list */
        pm = pci_find_capability(dev, PCI_CAP_ID_PM);
        
@@ -364,13 +372,13 @@ pci_set_power_state(struct pci_dev *dev, pci_power_t state)
        /* Mandatory power management transition delays */
        /* see PCI PM 1.1 5.6.1 table 18 */
        if (state == PCI_D3hot || dev->current_state == PCI_D3hot)
-               msleep(10);
+               msleep(pci_pm_d3_delay);
        else if (state == PCI_D2 || dev->current_state == PCI_D2)
                udelay(200);
 
        /*
         * Give firmware a chance to be called, such as ACPI _PRx, _PSx
-        * Firmware method after natice method ?
+        * Firmware method after native method ?
         */
        if (platform_pci_set_power_state)
                platform_pci_set_power_state(dev, state);
@@ -424,10 +432,12 @@ pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state)
        case PM_EVENT_ON:
                return PCI_D0;
        case PM_EVENT_FREEZE:
+       case PM_EVENT_PRETHAW:
+               /* REVISIT both freeze and pre-thaw "should" use D0 */
        case PM_EVENT_SUSPEND:
                return PCI_D3hot;
        default:
-               printk("They asked me for state %d\n", state.event);
+               printk("Unrecognized suspend event %d\n", state.event);
                BUG();
        }
        return PCI_D0;
@@ -435,6 +445,51 @@ 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 = kzalloc(sizeof(*save_state) + sizeof(u16) * 4, GFP_KERNEL);
+       if (!save_state) {
+               dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n");
+               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++]);
+       pci_add_saved_cap(dev, save_state);
+       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++]);
+       pci_remove_saved_cap(save_state);
+       kfree(save_state);
+}
+
 /**
  * pci_save_state - save the PCI configuration space of a device before suspending
  * @dev: - PCI device that we're dealing with
@@ -450,6 +505,8 @@ 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;
        return 0;
 }
 
@@ -463,7 +520,14 @@ pci_restore_state(struct pci_dev *dev)
        int i;
        int val;
 
-       for (i = 0; i < 16; i++) {
+       /* PCI Express register must be restored first */
+       pci_restore_pcie_state(dev);
+
+       /*
+        * The Base Address register should be programmed before the command
+        * register(s)
+        */
+       for (i = 15; i >= 0; i--) {
                pci_read_config_dword(dev, i * 4, &val);
                if (val != dev->saved_config_space[i]) {
                        printk(KERN_DEBUG "PM: Writing back config space on "
@@ -514,7 +578,12 @@ pci_enable_device_bars(struct pci_dev *dev, int bars)
 int
 pci_enable_device(struct pci_dev *dev)
 {
-       int err = pci_enable_device_bars(dev, (1 << PCI_NUM_RESOURCES) - 1);
+       int err;
+
+       if (dev->is_enabled)
+               return 0;
+
+       err = pci_enable_device_bars(dev, (1 << PCI_NUM_RESOURCES) - 1);
        if (err)
                return err;
        pci_fixup_device(pci_fixup_enable, dev);
@@ -543,7 +612,14 @@ void
 pci_disable_device(struct pci_dev *dev)
 {
        u16 pci_command;
-       
+
+       if (dev->msi_enabled)
+               disable_msi_mode(dev, pci_find_capability(dev, PCI_CAP_ID_MSI),
+                       PCI_CAP_ID_MSI);
+       if (dev->msix_enabled)
+               disable_msi_mode(dev, pci_find_capability(dev, PCI_CAP_ID_MSI),
+                       PCI_CAP_ID_MSIX);
+
        pci_read_config_word(dev, PCI_COMMAND, &pci_command);
        if (pci_command & PCI_COMMAND_MASTER) {
                pci_command &= ~PCI_COMMAND_MASTER;
@@ -676,10 +752,12 @@ int pci_request_region(struct pci_dev *pdev, int bar, const char *res_name)
        return 0;
 
 err_out:
-       printk (KERN_WARNING "PCI: Unable to reserve %s region #%d:%lx@%lx for device %s\n",
+       printk (KERN_WARNING "PCI: Unable to reserve %s region #%d:%llx@%llx "
+               "for device %s\n",
                pci_resource_flags(pdev, bar) & IORESOURCE_IO ? "I/O" : "mem",
                bar + 1, /* PCI BAR # */
-               pci_resource_len(pdev, bar), pci_resource_start(pdev, bar),
+               (unsigned long long)pci_resource_len(pdev, bar),
+               (unsigned long long)pci_resource_start(pdev, bar),
                pci_name(pdev));
        return -EBUSY;
 }
@@ -927,13 +1005,12 @@ static int __devinit pci_setup(char *str)
                }
                str = k;
        }
-       return 1;
+       return 0;
 }
+early_param("pci", pci_setup);
 
 device_initcall(pci_init);
 
-__setup("pci=", pci_setup);
-
 #if defined(CONFIG_ISA) || defined(CONFIG_EISA)
 /* FIXME: Some boxes have multiple ISA bridges! */
 struct pci_dev *isa_bridge;