upgrade to fedora-2.6.12-1.1398.FC4 + vserver 2.0.rc7
[linux-2.6.git] / drivers / pci / msi.c
index 726a966..30206ac 100644 (file)
 #include <asm/io.h>
 #include <asm/smp.h>
 
+#include "pci.h"
 #include "msi.h"
 
-static spinlock_t msi_lock = SPIN_LOCK_UNLOCKED;
+static DEFINE_SPINLOCK(msi_lock);
 static struct msi_desc* msi_desc[NR_IRQS] = { [0 ... NR_IRQS-1] = NULL };
 static kmem_cache_t* msi_cachep;
 
@@ -66,7 +67,7 @@ static void msi_set_mask_bit(unsigned int vector, int flag)
                int             pos;
                u32             mask_bits;
 
-               pos = (int)entry->mask_base;
+               pos = (long)entry->mask_base;
                pci_read_config_dword(entry->dev, pos, &mask_bits);
                mask_bits &= ~(1);
                mask_bits |= flag;
@@ -372,21 +373,27 @@ static int msi_init(void)
        if (!status)
                return status;
 
+       if (pci_msi_quirk) {
+               pci_msi_enable = 0;
+               printk(KERN_WARNING "PCI: MSI quirk detected. MSI disabled.\n");
+               status = -EINVAL;
+               return status;
+       }
+
        if ((status = msi_cache_init()) < 0) {
                pci_msi_enable = 0;
-               printk(KERN_INFO "WARNING: MSI INIT FAILURE\n");
+               printk(KERN_WARNING "PCI: MSI cache init failed\n");
                return status;
        }
        last_alloc_vector = assign_irq_vector(AUTO_ASSIGN);
        if (last_alloc_vector < 0) {
                pci_msi_enable = 0;
-               printk(KERN_INFO "WARNING: ALL VECTORS ARE BUSY\n");
+               printk(KERN_WARNING "PCI: No interrupt vectors available for MSI\n");
                status = -EBUSY;
                return status;
        }
        vector_irq[last_alloc_vector] = 0;
        nr_released_vectors++;
-       printk(KERN_INFO "MSI INIT SUCCESS\n");
 
        return status;
 }
@@ -515,7 +522,7 @@ void pci_scan_msi_device(struct pci_dev *dev)
  * msi_capability_init - configure device's MSI capability structure
  * @dev: pointer to the pci_dev data structure of MSI device function
  *
- * Setup the MSI capability structure of device funtion with a single
+ * Setup the MSI capability structure of device function with a single
  * MSI vector, regardless of device function is capable of handling
  * multiple messages. A return of zero indicates the successful setup
  * of an entry zero with the new MSI vector or non-zero for otherwise.
@@ -548,7 +555,7 @@ static int msi_capability_init(struct pci_dev *dev)
        dev->irq = vector;
        entry->dev = dev;
        if (is_mask_bit_support(control)) {
-               entry->mask_base = (void __iomem *)msi_mask_bits_reg(pos,
+               entry->mask_base = (void __iomem *)(long)msi_mask_bits_reg(pos,
                                is_64bit_address(control));
        }
        /* Replace with MSI handler */
@@ -592,7 +599,7 @@ static int msi_capability_init(struct pci_dev *dev)
  * msix_capability_init - configure device's MSI-X capability
  * @dev: pointer to the pci_dev data structure of MSI-X device function
  *
- * Setup the MSI-X capability structure of device funtion with a
+ * Setup the MSI-X capability structure of device function with a
  * single MSI-X vector. A return of zero indicates the successful setup of
  * requested MSI-X entries with allocated vectors or non-zero for otherwise.
  **/
@@ -617,15 +624,10 @@ static int msix_capability_init(struct pci_dev *dev,
        bir = (u8)(table_offset & PCI_MSIX_FLAGS_BIRMASK);
        phys_addr = pci_resource_start (dev, bir);
        phys_addr += (u32)(table_offset & ~PCI_MSIX_FLAGS_BIRMASK);
-       if (!request_mem_region(phys_addr,
-               nr_entries * PCI_MSIX_ENTRY_SIZE,
-               "MSI-X vector table"))
-               return -ENOMEM;
        base = ioremap_nocache(phys_addr, nr_entries * PCI_MSIX_ENTRY_SIZE);
-       if (base == NULL) {
-               release_mem_region(phys_addr, nr_entries * PCI_MSIX_ENTRY_SIZE);
+       if (base == NULL)
                return -ENOMEM;
-       }
+
        /* MSI-X Table Initialization */
        for (i = 0; i < nvec; i++) {
                entry = alloc_msi_entry();
@@ -701,12 +703,14 @@ static int msix_capability_init(struct pci_dev *dev,
  **/
 int pci_enable_msi(struct pci_dev* dev)
 {
-       int pos, temp = dev->irq, status = -EINVAL;
+       int pos, temp, status = -EINVAL;
        u16 control;
 
        if (!pci_msi_enable || !dev)
                return status;
 
+       temp = dev->irq;
+
        if ((status = msi_init()) < 0)
                return status;
 
@@ -736,7 +740,9 @@ int pci_enable_msi(struct pci_dev* dev)
        /* Check whether driver already requested for MSI-X vectors */
        if ((pos = pci_find_capability(dev, PCI_CAP_ID_MSIX)) > 0 &&
                !msi_lookup_vector(dev, PCI_CAP_ID_MSIX)) {
-                       printk(KERN_INFO "Can't enable MSI. Device already had MSI-X vectors assigned\n");
+                       printk(KERN_INFO "PCI: %s: Can't enable MSI.  "
+                              "Device already has MSI-X vectors assigned\n",
+                              pci_name(dev));
                        dev->irq = temp;
                        return -EINVAL;
        }
@@ -774,9 +780,9 @@ void pci_disable_msi(struct pci_dev* dev)
        }
        if (entry->msi_attrib.state) {
                spin_unlock_irqrestore(&msi_lock, flags);
-               printk(KERN_DEBUG "Driver[%d:%d:%d] unloaded wo doing free_irq on vector->%d\n",
-               dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn),
-               dev->irq);
+               printk(KERN_WARNING "PCI: %s: pci_disable_msi() called without "
+                      "free_irq() on MSI vector %d\n",
+                      pci_name(dev), dev->irq);
                BUG_ON(entry->msi_attrib.state > 0);
        } else {
                vector_irq[dev->irq] = 0; /* free it */
@@ -858,8 +864,6 @@ static int msi_free_vector(struct pci_dev* dev, int vector, int reassign)
                        phys_addr += (u32)(table_offset &
                                ~PCI_MSIX_FLAGS_BIRMASK);
                        iounmap(base);
-                       release_mem_region(phys_addr,
-                               nr_entries * PCI_MSIX_ENTRY_SIZE);
                }
        }
 
@@ -982,7 +986,9 @@ int pci_enable_msix(struct pci_dev* dev, struct msix_entry *entries, int nvec)
        /* Check whether driver already requested for MSI vector */
        if (pci_find_capability(dev, PCI_CAP_ID_MSI) > 0 &&
                !msi_lookup_vector(dev, PCI_CAP_ID_MSI)) {
-               printk(KERN_INFO "Can't enable MSI-X. Device already had MSI vector assigned\n");
+               printk(KERN_INFO "PCI: %s: Can't enable MSI-X.  "
+                      "Device already has an MSI vector assigned\n",
+                      pci_name(dev));
                dev->irq = temp;
                return -EINVAL;
        }
@@ -1050,9 +1056,9 @@ void pci_disable_msix(struct pci_dev* dev)
                spin_unlock_irqrestore(&msi_lock, flags);
                if (warning) {
                        dev->irq = temp;
-                       printk(KERN_DEBUG "Driver[%d:%d:%d] unloaded wo doing free_irq on all vectors\n",
-                       dev->bus->number, PCI_SLOT(dev->devfn),
-                       PCI_FUNC(dev->devfn));
+                       printk(KERN_WARNING "PCI: %s: pci_disable_msix() called without "
+                              "free_irq() on all MSI-X vectors\n",
+                              pci_name(dev));
                        BUG_ON(warning > 0);
                } else {
                        dev->irq = temp;
@@ -1068,7 +1074,7 @@ void pci_disable_msix(struct pci_dev* dev)
  * msi_remove_pci_irq_vectors - reclaim MSI(X) vectors to unused state
  * @dev: pointer to the pci_dev data structure of MSI(X) device function
  *
- * Being called during hotplug remove, from which the device funciton
+ * Being called during hotplug remove, from which the device function
  * is hot-removed. All previous assigned MSI/MSI-X vectors, if
  * allocated for this device function, are reclaimed to unused state,
  * which may be used later on.
@@ -1088,9 +1094,9 @@ void msi_remove_pci_irq_vectors(struct pci_dev* dev)
                state = msi_desc[dev->irq]->msi_attrib.state;
                spin_unlock_irqrestore(&msi_lock, flags);
                if (state) {
-                       printk(KERN_DEBUG "Driver[%d:%d:%d] unloaded wo doing free_irq on vector->%d\n",
-                       dev->bus->number, PCI_SLOT(dev->devfn),
-                       PCI_FUNC(dev->devfn), dev->irq);
+                       printk(KERN_WARNING "PCI: %s: msi_remove_pci_irq_vectors() "
+                              "called without free_irq() on MSI vector %d\n",
+                              pci_name(dev), dev->irq);
                        BUG_ON(state > 0);
                } else /* Release MSI vector assigned to this device */
                        msi_free_vector(dev, dev->irq, 0);
@@ -1130,11 +1136,9 @@ void msi_remove_pci_irq_vectors(struct pci_dev* dev)
                        phys_addr += (u32)(table_offset &
                                ~PCI_MSIX_FLAGS_BIRMASK);
                        iounmap(base);
-                       release_mem_region(phys_addr, PCI_MSIX_ENTRY_SIZE *
-                               multi_msix_capable(control));
-                       printk(KERN_DEBUG "Driver[%d:%d:%d] unloaded wo doing free_irq on all vectors\n",
-                               dev->bus->number, PCI_SLOT(dev->devfn),
-                               PCI_FUNC(dev->devfn));
+                       printk(KERN_WARNING "PCI: %s: msi_remove_pci_irq_vectors() "
+                              "called without free_irq() on all MSI-X vectors\n",
+                              pci_name(dev));
                        BUG_ON(warning > 0);
                }
                dev->irq = temp;                /* Restore IOAPIC IRQ */