提交 032de8e2 编写于 作者: M Michael Ellerman 提交者: Greg Kroah-Hartman

MSI: Give archs the option to free all MSI/Xs at once.

This patch introduces an optional function, arch_teardown_msi_irqs(),
which gives an arch the opportunity to do per-device teardown for
MSI/X. If that's not required, the default version simply calls
arch_teardown_msi_irq() for each msi irq required.

arch_teardown_msi_irqs() is simply passed a pdev, attached to the pdev
is a list of msi_descs, it is up to the arch to free the irq associated
with each of these as appropriate.

For archs that _don't_ implement arch_teardown_msi_irqs(), all msi_descs
with irq == 0 are considered unallocated, and the arch teardown routine
is not called on them.
Signed-off-by: NMichael Ellerman <michael@ellerman.id.au>
Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
上级 9c831334
...@@ -207,7 +207,7 @@ void unmask_msi_irq(unsigned int irq) ...@@ -207,7 +207,7 @@ void unmask_msi_irq(unsigned int irq)
msix_flush_writes(irq); msix_flush_writes(irq);
} }
static int msi_free_irq(struct pci_dev* dev, int irq); static int msi_free_irqs(struct pci_dev* dev);
static struct msi_desc* alloc_msi_entry(void) static struct msi_desc* alloc_msi_entry(void)
...@@ -339,8 +339,7 @@ static int msi_capability_init(struct pci_dev *dev) ...@@ -339,8 +339,7 @@ static int msi_capability_init(struct pci_dev *dev)
/* Configure MSI capability structure */ /* Configure MSI capability structure */
ret = arch_setup_msi_irqs(dev, 1, PCI_CAP_ID_MSI); ret = arch_setup_msi_irqs(dev, 1, PCI_CAP_ID_MSI);
if (ret) { if (ret) {
list_del(&entry->list); msi_free_irqs(dev);
kfree(entry);
return ret; return ret;
} }
...@@ -415,10 +414,11 @@ static int msix_capability_init(struct pci_dev *dev, ...@@ -415,10 +414,11 @@ static int msix_capability_init(struct pci_dev *dev,
list_for_each_entry(entry, &dev->msi_list, list) { list_for_each_entry(entry, &dev->msi_list, list) {
if (entry->irq != 0) { if (entry->irq != 0) {
avail++; avail++;
msi_free_irq(dev, entry->irq);
} }
} }
msi_free_irqs(dev);
/* If we had some success report the number of irqs /* If we had some success report the number of irqs
* we succeeded in setting up. * we succeeded in setting up.
*/ */
...@@ -539,39 +539,33 @@ void pci_disable_msi(struct pci_dev* dev) ...@@ -539,39 +539,33 @@ void pci_disable_msi(struct pci_dev* dev)
} }
default_irq = entry->msi_attrib.default_irq; default_irq = entry->msi_attrib.default_irq;
msi_free_irq(dev, entry->irq); msi_free_irqs(dev);
/* 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;
} }
EXPORT_SYMBOL(pci_disable_msi); EXPORT_SYMBOL(pci_disable_msi);
static int msi_free_irq(struct pci_dev* dev, int irq) static int msi_free_irqs(struct pci_dev* dev)
{ {
struct msi_desc *entry; struct msi_desc *entry, *tmp;
int entry_nr, type;
void __iomem *base;
BUG_ON(irq_has_action(irq));
entry = get_irq_msi(irq); list_for_each_entry(entry, &dev->msi_list, list)
if (!entry || entry->dev != dev) { BUG_ON(irq_has_action(entry->irq));
return -EINVAL;
}
type = entry->msi_attrib.type;
entry_nr = entry->msi_attrib.entry_nr;
base = entry->mask_base;
list_del(&entry->list);
arch_teardown_msi_irq(irq); arch_teardown_msi_irqs(dev);
kfree(entry);
if (type == PCI_CAP_ID_MSIX) { list_for_each_entry_safe(entry, tmp, &dev->msi_list, list) {
writel(1, base + entry_nr * PCI_MSIX_ENTRY_SIZE + if (entry->msi_attrib.type == PCI_CAP_ID_MSIX) {
PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET); if (list_is_last(&entry->list, &dev->msi_list))
iounmap(entry->mask_base);
if (list_empty(&dev->msi_list)) writel(1, entry->mask_base + entry->msi_attrib.entry_nr
iounmap(base); * PCI_MSIX_ENTRY_SIZE
+ PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET);
}
list_del(&entry->list);
kfree(entry);
} }
return 0; return 0;
...@@ -636,10 +630,7 @@ EXPORT_SYMBOL(pci_enable_msix); ...@@ -636,10 +630,7 @@ EXPORT_SYMBOL(pci_enable_msix);
static void msix_free_all_irqs(struct pci_dev *dev) static void msix_free_all_irqs(struct pci_dev *dev)
{ {
struct msi_desc *entry; msi_free_irqs(dev);
list_for_each_entry(entry, &dev->msi_list, list)
msi_free_irq(dev, entry->irq);
} }
void pci_disable_msix(struct pci_dev* dev) void pci_disable_msix(struct pci_dev* dev)
...@@ -669,12 +660,8 @@ void msi_remove_pci_irq_vectors(struct pci_dev* dev) ...@@ -669,12 +660,8 @@ void msi_remove_pci_irq_vectors(struct pci_dev* dev)
if (!pci_msi_enable || !dev) if (!pci_msi_enable || !dev)
return; return;
if (dev->msi_enabled) { if (dev->msi_enabled)
struct msi_desc *entry; msi_free_irqs(dev);
BUG_ON(list_empty(&dev->msi_list));
entry = list_entry(dev->msi_list.next, struct msi_desc, list);
msi_free_irq(dev, entry->irq);
}
if (dev->msix_enabled) if (dev->msix_enabled)
msix_free_all_irqs(dev); msix_free_all_irqs(dev);
...@@ -719,3 +706,19 @@ arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) ...@@ -719,3 +706,19 @@ arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
return 0; return 0;
} }
void __attribute__ ((weak)) arch_teardown_msi_irq(unsigned int irq)
{
return;
}
void __attribute__ ((weak))
arch_teardown_msi_irqs(struct pci_dev *dev)
{
struct msi_desc *entry;
list_for_each_entry(entry, &dev->msi_list, list) {
if (entry->irq != 0)
arch_teardown_msi_irq(entry->irq);
}
}
...@@ -42,6 +42,7 @@ struct msi_desc { ...@@ -42,6 +42,7 @@ struct msi_desc {
int arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc); int arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc);
void arch_teardown_msi_irq(unsigned int irq); void arch_teardown_msi_irq(unsigned int irq);
extern int arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type); extern int arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type);
extern void arch_teardown_msi_irqs(struct pci_dev *dev);
extern int arch_msi_check_device(struct pci_dev* dev, int nvec, int type); extern int arch_msi_check_device(struct pci_dev* dev, int nvec, int type);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册