Commit ded86d8d authored by Eric W. Biederman's avatar Eric W. Biederman Committed by Greg Kroah-Hartman

msi: Kill msi_lookup_irq

The function msi_lookup_irq was horrible.  As a side effect of running
it changed dev->irq, and then the callers would need to change it
back.  In addition it does a global scan through all of the irqs,
which seems to be the sole justification of the msi_lock.

To remove the neede for msi_lookup_irq I added first_msi_irq to struct
pci_dev.  Then depending on the context I replaced msi_lookup_irq with
dev->first_msi_irq, dev->msi_enabled, or dev->msix_enabled.

msi_enabled and msix_enabled were already present in pci_dev for other
reasons.
Signed-off-by: default avatarEric W. Biederman <ebiederm@xmission.com>
Acked-by: default avatarIngo Molnar <mingo@elte.hu>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 8fed4b65
...@@ -272,28 +272,6 @@ void disable_msi_mode(struct pci_dev *dev, int pos, int type) ...@@ -272,28 +272,6 @@ void disable_msi_mode(struct pci_dev *dev, int pos, int type)
pci_intx(dev, 1); /* enable intx */ pci_intx(dev, 1); /* enable intx */
} }
static int msi_lookup_irq(struct pci_dev *dev, int type)
{
int irq;
unsigned long flags;
spin_lock_irqsave(&msi_lock, flags);
for (irq = 0; irq < NR_IRQS; irq++) {
if (!msi_desc[irq] || msi_desc[irq]->dev != dev ||
msi_desc[irq]->msi_attrib.type != type ||
msi_desc[irq]->msi_attrib.default_irq != dev->irq)
continue;
spin_unlock_irqrestore(&msi_lock, flags);
/* This pre-assigned MSI irq for this device
already exists. Override dev->irq with this irq */
dev->irq = irq;
return 0;
}
spin_unlock_irqrestore(&msi_lock, flags);
return -EACCES;
}
#ifdef CONFIG_PM #ifdef CONFIG_PM
static int __pci_save_msi_state(struct pci_dev *dev) static int __pci_save_msi_state(struct pci_dev *dev)
{ {
...@@ -364,11 +342,13 @@ static void __pci_restore_msi_state(struct pci_dev *dev) ...@@ -364,11 +342,13 @@ static void __pci_restore_msi_state(struct pci_dev *dev)
static int __pci_save_msix_state(struct pci_dev *dev) static int __pci_save_msix_state(struct pci_dev *dev)
{ {
int pos; int pos;
int temp;
int irq, head, tail = 0; int irq, head, tail = 0;
u16 control; u16 control;
struct pci_cap_saved_state *save_state; struct pci_cap_saved_state *save_state;
if (!dev->msix_enabled)
return 0;
pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
if (pos <= 0 || dev->no_msi) if (pos <= 0 || dev->no_msi)
return 0; return 0;
...@@ -386,13 +366,7 @@ static int __pci_save_msix_state(struct pci_dev *dev) ...@@ -386,13 +366,7 @@ static int __pci_save_msix_state(struct pci_dev *dev)
*((u16 *)&save_state->data[0]) = control; *((u16 *)&save_state->data[0]) = control;
/* save the table */ /* save the table */
temp = dev->irq; irq = head = dev->first_msi_irq;
if (msi_lookup_irq(dev, PCI_CAP_ID_MSIX)) {
kfree(save_state);
return -EINVAL;
}
irq = head = dev->irq;
while (head != tail) { while (head != tail) {
struct msi_desc *entry; struct msi_desc *entry;
...@@ -402,7 +376,6 @@ static int __pci_save_msix_state(struct pci_dev *dev) ...@@ -402,7 +376,6 @@ static int __pci_save_msix_state(struct pci_dev *dev)
tail = msi_desc[irq]->link.tail; tail = msi_desc[irq]->link.tail;
irq = tail; irq = tail;
} }
dev->irq = temp;
save_state->cap_nr = PCI_CAP_ID_MSIX; save_state->cap_nr = PCI_CAP_ID_MSIX;
pci_add_saved_cap(dev, save_state); pci_add_saved_cap(dev, save_state);
...@@ -428,9 +401,11 @@ static void __pci_restore_msix_state(struct pci_dev *dev) ...@@ -428,9 +401,11 @@ static void __pci_restore_msix_state(struct pci_dev *dev)
int pos; int pos;
int irq, head, tail = 0; int irq, head, tail = 0;
struct msi_desc *entry; struct msi_desc *entry;
int temp;
struct pci_cap_saved_state *save_state; struct pci_cap_saved_state *save_state;
if (!dev->msix_enabled)
return;
save_state = pci_find_saved_cap(dev, PCI_CAP_ID_MSIX); save_state = pci_find_saved_cap(dev, PCI_CAP_ID_MSIX);
if (!save_state) if (!save_state)
return; return;
...@@ -443,10 +418,7 @@ static void __pci_restore_msix_state(struct pci_dev *dev) ...@@ -443,10 +418,7 @@ static void __pci_restore_msix_state(struct pci_dev *dev)
return; return;
/* route the table */ /* route the table */
temp = dev->irq; irq = head = dev->first_msi_irq;
if (msi_lookup_irq(dev, PCI_CAP_ID_MSIX))
return;
irq = head = dev->irq;
while (head != tail) { while (head != tail) {
entry = msi_desc[irq]; entry = msi_desc[irq];
write_msi_msg(irq, &entry->msg_save); write_msi_msg(irq, &entry->msg_save);
...@@ -454,7 +426,6 @@ static void __pci_restore_msix_state(struct pci_dev *dev) ...@@ -454,7 +426,6 @@ static void __pci_restore_msix_state(struct pci_dev *dev)
tail = msi_desc[irq]->link.tail; tail = msi_desc[irq]->link.tail;
irq = tail; irq = tail;
} }
dev->irq = temp;
pci_write_config_word(dev, msi_control_reg(pos), save); pci_write_config_word(dev, msi_control_reg(pos), save);
enable_msi_mode(dev, pos, PCI_CAP_ID_MSIX); enable_msi_mode(dev, pos, PCI_CAP_ID_MSIX);
...@@ -524,6 +495,7 @@ static int msi_capability_init(struct pci_dev *dev) ...@@ -524,6 +495,7 @@ static int msi_capability_init(struct pci_dev *dev)
return status; return status;
} }
dev->first_msi_irq = irq;
attach_msi_entry(entry, irq); attach_msi_entry(entry, irq);
/* Set MSI enabled bits */ /* Set MSI enabled bits */
enable_msi_mode(dev, pos, PCI_CAP_ID_MSI); enable_msi_mode(dev, pos, PCI_CAP_ID_MSI);
...@@ -620,6 +592,7 @@ static int msix_capability_init(struct pci_dev *dev, ...@@ -620,6 +592,7 @@ static int msix_capability_init(struct pci_dev *dev,
avail = -EBUSY; avail = -EBUSY;
return avail; return avail;
} }
dev->first_msi_irq = entries[0].vector;
/* Set MSI-X enabled bits */ /* Set MSI-X enabled bits */
enable_msi_mode(dev, pos, PCI_CAP_ID_MSIX); enable_msi_mode(dev, pos, PCI_CAP_ID_MSIX);
...@@ -667,13 +640,11 @@ int pci_msi_supported(struct pci_dev * dev) ...@@ -667,13 +640,11 @@ int pci_msi_supported(struct pci_dev * dev)
**/ **/
int pci_enable_msi(struct pci_dev* dev) int pci_enable_msi(struct pci_dev* dev)
{ {
int pos, temp, status; int pos, status;
if (pci_msi_supported(dev) < 0) if (pci_msi_supported(dev) < 0)
return -EINVAL; return -EINVAL;
temp = dev->irq;
status = msi_init(); status = msi_init();
if (status < 0) if (status < 0)
return status; return status;
...@@ -682,15 +653,14 @@ int pci_enable_msi(struct pci_dev* dev) ...@@ -682,15 +653,14 @@ int pci_enable_msi(struct pci_dev* dev)
if (!pos) if (!pos)
return -EINVAL; return -EINVAL;
WARN_ON(!msi_lookup_irq(dev, PCI_CAP_ID_MSI)); WARN_ON(!!dev->msi_enabled);
/* Check whether driver already requested for MSI-X irqs */ /* Check whether driver already requested for MSI-X irqs */
pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
if (pos > 0 && !msi_lookup_irq(dev, PCI_CAP_ID_MSIX)) { if (pos > 0 && dev->msix_enabled) {
printk(KERN_INFO "PCI: %s: Can't enable MSI. " printk(KERN_INFO "PCI: %s: Can't enable MSI. "
"Device already has MSI-X irq assigned\n", "Device already has MSI-X enabled\n",
pci_name(dev)); pci_name(dev));
dev->irq = temp;
return -EINVAL; return -EINVAL;
} }
status = msi_capability_init(dev); status = msi_capability_init(dev);
...@@ -709,6 +679,9 @@ void pci_disable_msi(struct pci_dev* dev) ...@@ -709,6 +679,9 @@ void pci_disable_msi(struct pci_dev* dev)
if (!dev) if (!dev)
return; return;
if (!dev->msi_enabled)
return;
pos = pci_find_capability(dev, PCI_CAP_ID_MSI); pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
if (!pos) if (!pos)
return; return;
...@@ -717,28 +690,30 @@ void pci_disable_msi(struct pci_dev* dev) ...@@ -717,28 +690,30 @@ void pci_disable_msi(struct pci_dev* dev)
if (!(control & PCI_MSI_FLAGS_ENABLE)) if (!(control & PCI_MSI_FLAGS_ENABLE))
return; return;
disable_msi_mode(dev, pos, PCI_CAP_ID_MSI); disable_msi_mode(dev, pos, PCI_CAP_ID_MSI);
spin_lock_irqsave(&msi_lock, flags); spin_lock_irqsave(&msi_lock, flags);
entry = msi_desc[dev->irq]; entry = msi_desc[dev->first_msi_irq];
if (!entry || !entry->dev || entry->msi_attrib.type != PCI_CAP_ID_MSI) { if (!entry || !entry->dev || entry->msi_attrib.type != PCI_CAP_ID_MSI) {
spin_unlock_irqrestore(&msi_lock, flags); spin_unlock_irqrestore(&msi_lock, flags);
return; return;
} }
if (irq_has_action(dev->irq)) { if (irq_has_action(dev->first_msi_irq)) {
spin_unlock_irqrestore(&msi_lock, flags); spin_unlock_irqrestore(&msi_lock, flags);
printk(KERN_WARNING "PCI: %s: pci_disable_msi() called without " printk(KERN_WARNING "PCI: %s: pci_disable_msi() called without "
"free_irq() on MSI irq %d\n", "free_irq() on MSI irq %d\n",
pci_name(dev), dev->irq); pci_name(dev), dev->first_msi_irq);
BUG_ON(irq_has_action(dev->irq)); BUG_ON(irq_has_action(dev->first_msi_irq));
} else { } else {
default_irq = entry->msi_attrib.default_irq; default_irq = entry->msi_attrib.default_irq;
spin_unlock_irqrestore(&msi_lock, flags); spin_unlock_irqrestore(&msi_lock, flags);
msi_free_irq(dev, dev->irq); msi_free_irq(dev, dev->first_msi_irq);
/* Restore dev->irq to its default pin-assertion irq */ /* Restore dev->irq to its default pin-assertion irq */
dev->irq = default_irq; dev->irq = default_irq;
} }
dev->first_msi_irq = 0;
} }
static int msi_free_irq(struct pci_dev* dev, int irq) static int msi_free_irq(struct pci_dev* dev, int irq)
...@@ -797,7 +772,7 @@ static int msi_free_irq(struct pci_dev* dev, int irq) ...@@ -797,7 +772,7 @@ static int msi_free_irq(struct pci_dev* dev, int irq)
int pci_enable_msix(struct pci_dev* dev, struct msix_entry *entries, int nvec) int pci_enable_msix(struct pci_dev* dev, struct msix_entry *entries, int nvec)
{ {
int status, pos, nr_entries; int status, pos, nr_entries;
int i, j, temp; int i, j;
u16 control; u16 control;
if (!entries || pci_msi_supported(dev) < 0) if (!entries || pci_msi_supported(dev) < 0)
...@@ -825,16 +800,14 @@ int pci_enable_msix(struct pci_dev* dev, struct msix_entry *entries, int nvec) ...@@ -825,16 +800,14 @@ int pci_enable_msix(struct pci_dev* dev, struct msix_entry *entries, int nvec)
return -EINVAL; /* duplicate entry */ return -EINVAL; /* duplicate entry */
} }
} }
temp = dev->irq; WARN_ON(!!dev->msix_enabled);
WARN_ON(!msi_lookup_irq(dev, PCI_CAP_ID_MSIX));
/* Check whether driver already requested for MSI irq */ /* Check whether driver already requested for MSI irq */
if (pci_find_capability(dev, PCI_CAP_ID_MSI) > 0 && if (pci_find_capability(dev, PCI_CAP_ID_MSI) > 0 &&
!msi_lookup_irq(dev, PCI_CAP_ID_MSI)) { dev->msi_enabled) {
printk(KERN_INFO "PCI: %s: Can't enable MSI-X. " printk(KERN_INFO "PCI: %s: Can't enable MSI-X. "
"Device already has an MSI irq assigned\n", "Device already has an MSI irq assigned\n",
pci_name(dev)); pci_name(dev));
dev->irq = temp;
return -EINVAL; return -EINVAL;
} }
status = msix_capability_init(dev, entries, nvec); status = msix_capability_init(dev, entries, nvec);
...@@ -843,7 +816,9 @@ int pci_enable_msix(struct pci_dev* dev, struct msix_entry *entries, int nvec) ...@@ -843,7 +816,9 @@ int pci_enable_msix(struct pci_dev* dev, struct msix_entry *entries, int nvec)
void pci_disable_msix(struct pci_dev* dev) void pci_disable_msix(struct pci_dev* dev)
{ {
int pos, temp; int irq, head, tail = 0, warning = 0;
unsigned long flags;
int pos;
u16 control; u16 control;
if (!pci_msi_enable) if (!pci_msi_enable)
...@@ -851,6 +826,9 @@ void pci_disable_msix(struct pci_dev* dev) ...@@ -851,6 +826,9 @@ void pci_disable_msix(struct pci_dev* dev)
if (!dev) if (!dev)
return; return;
if (!dev->msix_enabled)
return;
pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
if (!pos) if (!pos)
return; return;
...@@ -861,13 +839,7 @@ void pci_disable_msix(struct pci_dev* dev) ...@@ -861,13 +839,7 @@ void pci_disable_msix(struct pci_dev* dev)
disable_msi_mode(dev, pos, PCI_CAP_ID_MSIX); disable_msi_mode(dev, pos, PCI_CAP_ID_MSIX);
temp = dev->irq; irq = head = dev->first_msi_irq;
if (!msi_lookup_irq(dev, PCI_CAP_ID_MSIX)) {
int irq, head, tail = 0, warning = 0;
unsigned long flags;
irq = head = dev->irq;
dev->irq = temp; /* Restore pin IRQ */
while (head != tail) { while (head != tail) {
spin_lock_irqsave(&msi_lock, flags); spin_lock_irqsave(&msi_lock, flags);
tail = msi_desc[irq]->link.tail; tail = msi_desc[irq]->link.tail;
...@@ -885,7 +857,7 @@ void pci_disable_msix(struct pci_dev* dev) ...@@ -885,7 +857,7 @@ void pci_disable_msix(struct pci_dev* dev)
pci_name(dev)); pci_name(dev));
BUG_ON(warning > 0); BUG_ON(warning > 0);
} }
} dev->first_msi_irq = 0;
} }
/** /**
...@@ -899,30 +871,28 @@ void pci_disable_msix(struct pci_dev* dev) ...@@ -899,30 +871,28 @@ void pci_disable_msix(struct pci_dev* dev)
**/ **/
void msi_remove_pci_irq_vectors(struct pci_dev* dev) void msi_remove_pci_irq_vectors(struct pci_dev* dev)
{ {
int pos, temp; int pos;
unsigned long flags; unsigned long flags;
if (!pci_msi_enable || !dev) if (!pci_msi_enable || !dev)
return; return;
temp = dev->irq; /* Save IOAPIC IRQ */
pos = pci_find_capability(dev, PCI_CAP_ID_MSI); pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
if (pos > 0 && !msi_lookup_irq(dev, PCI_CAP_ID_MSI)) { if (pos > 0 && dev->msi_enabled) {
if (irq_has_action(dev->irq)) { if (irq_has_action(dev->first_msi_irq)) {
printk(KERN_WARNING "PCI: %s: msi_remove_pci_irq_vectors() " printk(KERN_WARNING "PCI: %s: msi_remove_pci_irq_vectors() "
"called without free_irq() on MSI irq %d\n", "called without free_irq() on MSI irq %d\n",
pci_name(dev), dev->irq); pci_name(dev), dev->first_msi_irq);
BUG_ON(irq_has_action(dev->irq)); BUG_ON(irq_has_action(dev->first_msi_irq));
} else /* Release MSI irq assigned to this device */ } else /* Release MSI irq assigned to this device */
msi_free_irq(dev, dev->irq); msi_free_irq(dev, dev->first_msi_irq);
dev->irq = temp; /* Restore IOAPIC IRQ */
} }
pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
if (pos > 0 && !msi_lookup_irq(dev, PCI_CAP_ID_MSIX)) { if (pos > 0 && dev->msix_enabled) {
int irq, head, tail = 0, warning = 0; int irq, head, tail = 0, warning = 0;
void __iomem *base = NULL; void __iomem *base = NULL;
irq = head = dev->irq; irq = head = dev->first_msi_irq;
while (head != tail) { while (head != tail) {
spin_lock_irqsave(&msi_lock, flags); spin_lock_irqsave(&msi_lock, flags);
tail = msi_desc[irq]->link.tail; tail = msi_desc[irq]->link.tail;
...@@ -942,7 +912,6 @@ void msi_remove_pci_irq_vectors(struct pci_dev* dev) ...@@ -942,7 +912,6 @@ void msi_remove_pci_irq_vectors(struct pci_dev* dev)
pci_name(dev)); pci_name(dev));
BUG_ON(warning > 0); BUG_ON(warning > 0);
} }
dev->irq = temp; /* Restore IOAPIC IRQ */
} }
} }
......
...@@ -174,6 +174,9 @@ struct pci_dev { ...@@ -174,6 +174,9 @@ struct pci_dev {
struct bin_attribute *rom_attr; /* attribute descriptor for sysfs ROM entry */ struct bin_attribute *rom_attr; /* attribute descriptor for sysfs ROM entry */
int rom_attr_enabled; /* has display of the rom attribute been enabled? */ int rom_attr_enabled; /* has display of the rom attribute been enabled? */
struct bin_attribute *res_attr[DEVICE_COUNT_RESOURCE]; /* sysfs file for resources */ struct bin_attribute *res_attr[DEVICE_COUNT_RESOURCE]; /* sysfs file for resources */
#ifdef CONFIG_PCI_MSI
unsigned int first_msi_irq;
#endif
}; };
#define pci_dev_g(n) list_entry(n, struct pci_dev, global_list) #define pci_dev_g(n) list_entry(n, struct pci_dev, global_list)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment