Commit 63a7b17e authored by Jiang Liu's avatar Jiang Liu Committed by Thomas Gleixner

PCI/MSI: Simplify PCI MSI code by initializing msi_desc.nvec_used earlier

Simplify PCI MSI code by initializing msi_desc.nvec_used and
msi_desc.msi_attrib.multiple when creating MSI descriptors.

Also remove redundant checks in IRQ remapping drivers, PCI MSI core
already guarantees these.
Signed-off-by: default avatarJiang Liu <jiang.liu@linux.intel.com>
Acked-by: default avatarBjorn Helgaas <bhelgaas@google.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Grant Likely <grant.likely@linaro.org>
Cc: Marc Zyngier <marc.zyngier@arm.com>
Cc: Yingjoe Chen <yingjoe.chen@mediatek.com>
Cc: Yijing Wang <wangyijing@huawei.com>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent 3f3cecae
......@@ -56,19 +56,13 @@ static int do_setup_msi_irqs(struct pci_dev *dev, int nvec)
unsigned int irq;
struct msi_desc *msidesc;
WARN_ON(!list_is_singular(&dev->msi_list));
msidesc = list_entry(dev->msi_list.next, struct msi_desc, list);
WARN_ON(msidesc->irq);
WARN_ON(msidesc->msi_attrib.multiple);
WARN_ON(msidesc->nvec_used);
irq = irq_alloc_hwirqs(nvec, dev_to_node(&dev->dev));
if (irq == 0)
return -ENOSPC;
nvec_pow2 = __roundup_pow_of_two(nvec);
msidesc->nvec_used = nvec;
msidesc->msi_attrib.multiple = ilog2(nvec_pow2);
for (sub_handle = 0; sub_handle < nvec; sub_handle++) {
if (!sub_handle) {
index = msi_alloc_remapped_irq(dev, irq, nvec_pow2);
......@@ -96,8 +90,6 @@ static int do_setup_msi_irqs(struct pci_dev *dev, int nvec)
* IRQs from tearing down again in default_teardown_msi_irqs()
*/
msidesc->irq = 0;
msidesc->nvec_used = 0;
msidesc->msi_attrib.multiple = 0;
return ret;
}
......
......@@ -101,19 +101,13 @@ int __weak arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
*/
void default_teardown_msi_irqs(struct pci_dev *dev)
{
int i;
struct msi_desc *entry;
list_for_each_entry(entry, &dev->msi_list, list) {
int i, nvec;
if (entry->irq == 0)
continue;
if (entry->nvec_used)
nvec = entry->nvec_used;
else
nvec = 1 << entry->msi_attrib.multiple;
for (i = 0; i < nvec; i++)
arch_teardown_msi_irq(entry->irq + i);
}
list_for_each_entry(entry, &dev->msi_list, list)
if (entry->irq)
for (i = 0; i < entry->nvec_used; i++)
arch_teardown_msi_irq(entry->irq + i);
}
void __weak arch_teardown_msi_irqs(struct pci_dev *dev)
......@@ -363,19 +357,12 @@ static void free_msi_irqs(struct pci_dev *dev)
struct msi_desc *entry, *tmp;
struct attribute **msi_attrs;
struct device_attribute *dev_attr;
int count = 0;
int i, count = 0;
list_for_each_entry(entry, &dev->msi_list, list) {
int i, nvec;
if (!entry->irq)
continue;
if (entry->nvec_used)
nvec = entry->nvec_used;
else
nvec = 1 << entry->msi_attrib.multiple;
for (i = 0; i < nvec; i++)
BUG_ON(irq_has_action(entry->irq + i));
}
list_for_each_entry(entry, &dev->msi_list, list)
if (entry->irq)
for (i = 0; i < entry->nvec_used; i++)
BUG_ON(irq_has_action(entry->irq + i));
arch_teardown_msi_irqs(dev);
......@@ -566,7 +553,7 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
return ret;
}
static struct msi_desc *msi_setup_entry(struct pci_dev *dev)
static struct msi_desc *msi_setup_entry(struct pci_dev *dev, int nvec)
{
u16 control;
struct msi_desc *entry;
......@@ -584,6 +571,8 @@ static struct msi_desc *msi_setup_entry(struct pci_dev *dev)
entry->msi_attrib.maskbit = !!(control & PCI_MSI_FLAGS_MASKBIT);
entry->msi_attrib.default_irq = dev->irq; /* Save IOAPIC IRQ */
entry->msi_attrib.multi_cap = (control & PCI_MSI_FLAGS_QMASK) >> 1;
entry->msi_attrib.multiple = ilog2(__roundup_pow_of_two(nvec));
entry->nvec_used = nvec;
if (control & PCI_MSI_FLAGS_64BIT)
entry->mask_pos = dev->msi_cap + PCI_MSI_MASK_64;
......@@ -616,7 +605,7 @@ static int msi_capability_init(struct pci_dev *dev, int nvec)
msi_set_enable(dev, 0); /* Disable MSI during set up */
entry = msi_setup_entry(dev);
entry = msi_setup_entry(dev, nvec);
if (!entry)
return -ENOMEM;
......@@ -687,6 +676,7 @@ static int msix_setup_entries(struct pci_dev *dev, void __iomem *base,
entry->msi_attrib.entry_nr = entries[i].entry;
entry->msi_attrib.default_irq = dev->irq;
entry->mask_base = base;
entry->nvec_used = 1;
list_add_tail(&entry->list, &dev->msi_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