aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/msi.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pci/msi.c')
-rw-r--r--drivers/pci/msi.c105
1 files changed, 72 insertions, 33 deletions
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 48723d6fa60f..a77e79c8c82e 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -103,9 +103,9 @@ static void set_msi_affinity(unsigned int vector, cpumask_t cpu_mask)
switch (entry->msi_attrib.type) {
case PCI_CAP_ID_MSI:
{
- int pos;
+ int pos = pci_find_capability(entry->dev, PCI_CAP_ID_MSI);
- if (!(pos = pci_find_capability(entry->dev, PCI_CAP_ID_MSI)))
+ if (!pos)
return;
pci_read_config_dword(entry->dev, msi_lower_address_reg(pos),
@@ -347,9 +347,9 @@ static int assign_msi_vector(void)
static int get_new_vector(void)
{
- int vector;
+ int vector = assign_msi_vector();
- if ((vector = assign_msi_vector()) > 0)
+ if (vector > 0)
set_intr_gate(vector, interrupt[vector]);
return vector;
@@ -369,7 +369,8 @@ static int msi_init(void)
return status;
}
- if ((status = msi_cache_init()) < 0) {
+ status = msi_cache_init();
+ if (status < 0) {
pci_msi_enable = 0;
printk(KERN_WARNING "PCI: MSI cache init failed\n");
return status;
@@ -523,10 +524,12 @@ static int msi_capability_init(struct pci_dev *dev)
pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
pci_read_config_word(dev, msi_control_reg(pos), &control);
/* MSI Entry Initialization */
- if (!(entry = alloc_msi_entry()))
+ entry = alloc_msi_entry();
+ if (!entry)
return -ENOMEM;
- if ((vector = get_msi_vector(dev)) < 0) {
+ vector = get_msi_vector(dev);
+ if (vector < 0) {
kmem_cache_free(msi_cachep, entry);
return -EBUSY;
}
@@ -597,7 +600,8 @@ static int msix_capability_init(struct pci_dev *dev,
struct msg_address address;
struct msg_data data;
int vector, pos, i, j, nr_entries, temp = 0;
- u32 phys_addr, table_offset;
+ unsigned long phys_addr;
+ u32 table_offset;
u16 control;
u8 bir;
void __iomem *base;
@@ -606,11 +610,11 @@ static int msix_capability_init(struct pci_dev *dev,
/* Request & Map MSI-X table region */
pci_read_config_word(dev, msi_control_reg(pos), &control);
nr_entries = multi_msix_capable(control);
- pci_read_config_dword(dev, msix_table_offset_reg(pos),
- &table_offset);
+
+ pci_read_config_dword(dev, msix_table_offset_reg(pos), &table_offset);
bir = (u8)(table_offset & PCI_MSIX_FLAGS_BIRMASK);
- phys_addr = pci_resource_start (dev, bir);
- phys_addr += (u32)(table_offset & ~PCI_MSIX_FLAGS_BIRMASK);
+ table_offset &= ~PCI_MSIX_FLAGS_BIRMASK;
+ phys_addr = pci_resource_start (dev, bir) + table_offset;
base = ioremap_nocache(phys_addr, nr_entries * PCI_MSIX_ENTRY_SIZE);
if (base == NULL)
return -ENOMEM;
@@ -620,7 +624,8 @@ static int msix_capability_init(struct pci_dev *dev,
entry = alloc_msi_entry();
if (!entry)
break;
- if ((vector = get_msi_vector(dev)) < 0)
+ vector = get_msi_vector(dev);
+ if (vector < 0)
break;
j = entries[i].entry;
@@ -699,12 +704,17 @@ int pci_enable_msi(struct pci_dev* dev)
if (dev->no_msi)
return status;
+ if (dev->bus->bus_flags & PCI_BUS_FLAGS_NO_MSI)
+ return -EINVAL;
+
temp = dev->irq;
- if ((status = msi_init()) < 0)
+ status = msi_init();
+ if (status < 0)
return status;
- if (!(pos = pci_find_capability(dev, PCI_CAP_ID_MSI)))
+ pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
+ if (!pos)
return -EINVAL;
pci_read_config_word(dev, msi_control_reg(pos), &control);
@@ -728,8 +738,8 @@ int pci_enable_msi(struct pci_dev* dev)
dev->irq = temp;
}
/* 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)) {
+ pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
+ if (pos > 0 && !msi_lookup_vector(dev, PCI_CAP_ID_MSIX)) {
printk(KERN_INFO "PCI: %s: Can't enable MSI. "
"Device already has MSI-X vectors assigned\n",
pci_name(dev));
@@ -755,7 +765,13 @@ void pci_disable_msi(struct pci_dev* dev)
u16 control;
unsigned long flags;
- if (!dev || !(pos = pci_find_capability(dev, PCI_CAP_ID_MSI)))
+ if (!pci_msi_enable)
+ return;
+ if (!dev)
+ return;
+
+ pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
+ if (!pos)
return;
pci_read_config_word(dev, msi_control_reg(pos), &control);
@@ -826,8 +842,10 @@ static int msi_free_vector(struct pci_dev* dev, int vector, int reassign)
* Detect last MSI-X vector to be released.
* Release the MSI-X memory-mapped table.
*/
+#if 0
int pos, nr_entries;
- u32 phys_addr, table_offset;
+ unsigned long phys_addr;
+ u32 table_offset;
u16 control;
u8 bir;
@@ -838,9 +856,12 @@ static int msi_free_vector(struct pci_dev* dev, int vector, int reassign)
pci_read_config_dword(dev, msix_table_offset_reg(pos),
&table_offset);
bir = (u8)(table_offset & PCI_MSIX_FLAGS_BIRMASK);
- phys_addr = pci_resource_start (dev, bir);
- phys_addr += (u32)(table_offset &
- ~PCI_MSIX_FLAGS_BIRMASK);
+ table_offset &= ~PCI_MSIX_FLAGS_BIRMASK;
+ phys_addr = pci_resource_start(dev, bir) + table_offset;
+/*
+ * FIXME! and what did you want to do with phys_addr?
+ */
+#endif
iounmap(base);
}
}
@@ -924,10 +945,12 @@ int pci_enable_msix(struct pci_dev* dev, struct msix_entry *entries, int nvec)
if (!pci_msi_enable || !dev || !entries)
return -EINVAL;
- if ((status = msi_init()) < 0)
+ status = msi_init();
+ if (status < 0)
return status;
- if (!(pos = pci_find_capability(dev, PCI_CAP_ID_MSIX)))
+ pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
+ if (!pos)
return -EINVAL;
pci_read_config_word(dev, msi_control_reg(pos), &control);
@@ -1006,7 +1029,13 @@ void pci_disable_msix(struct pci_dev* dev)
int pos, temp;
u16 control;
- if (!dev || !(pos = pci_find_capability(dev, PCI_CAP_ID_MSIX)))
+ if (!pci_msi_enable)
+ return;
+ if (!dev)
+ return;
+
+ pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
+ if (!pos)
return;
pci_read_config_word(dev, msi_control_reg(pos), &control);
@@ -1066,8 +1095,8 @@ void msi_remove_pci_irq_vectors(struct pci_dev* dev)
return;
temp = dev->irq; /* Save IOAPIC IRQ */
- if ((pos = pci_find_capability(dev, PCI_CAP_ID_MSI)) > 0 &&
- !msi_lookup_vector(dev, PCI_CAP_ID_MSI)) {
+ pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
+ if (pos > 0 && !msi_lookup_vector(dev, PCI_CAP_ID_MSI)) {
spin_lock_irqsave(&msi_lock, flags);
state = msi_desc[dev->irq]->msi_attrib.state;
spin_unlock_irqrestore(&msi_lock, flags);
@@ -1080,8 +1109,8 @@ void msi_remove_pci_irq_vectors(struct pci_dev* dev)
msi_free_vector(dev, dev->irq, 0);
dev->irq = temp; /* Restore IOAPIC IRQ */
}
- if ((pos = pci_find_capability(dev, PCI_CAP_ID_MSIX)) > 0 &&
- !msi_lookup_vector(dev, PCI_CAP_ID_MSIX)) {
+ pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
+ if (pos > 0 && !msi_lookup_vector(dev, PCI_CAP_ID_MSIX)) {
int vector, head, tail = 0, warning = 0;
void __iomem *base = NULL;
@@ -1101,7 +1130,9 @@ void msi_remove_pci_irq_vectors(struct pci_dev* dev)
msi_free_vector(dev, vector, 0);
if (warning) {
/* Force to release the MSI-X memory-mapped table */
- u32 phys_addr, table_offset;
+#if 0
+ unsigned long phys_addr;
+ u32 table_offset;
u16 control;
u8 bir;
@@ -1110,9 +1141,12 @@ void msi_remove_pci_irq_vectors(struct pci_dev* dev)
pci_read_config_dword(dev, msix_table_offset_reg(pos),
&table_offset);
bir = (u8)(table_offset & PCI_MSIX_FLAGS_BIRMASK);
- phys_addr = pci_resource_start (dev, bir);
- phys_addr += (u32)(table_offset &
- ~PCI_MSIX_FLAGS_BIRMASK);
+ table_offset &= ~PCI_MSIX_FLAGS_BIRMASK;
+ phys_addr = pci_resource_start(dev, bir) + table_offset;
+/*
+ * FIXME! and what did you want to do with phys_addr?
+ */
+#endif
iounmap(base);
printk(KERN_WARNING "PCI: %s: msi_remove_pci_irq_vectors() "
"called without free_irq() on all MSI-X vectors\n",
@@ -1123,6 +1157,11 @@ void msi_remove_pci_irq_vectors(struct pci_dev* dev)
}
}
+void pci_no_msi(void)
+{
+ pci_msi_enable = 0;
+}
+
EXPORT_SYMBOL(pci_enable_msi);
EXPORT_SYMBOL(pci_disable_msi);
EXPORT_SYMBOL(pci_enable_msix);