Commit fb1b55d6 authored by Gavin Shan's avatar Gavin Shan Committed by Michael Ellerman

powerpc/powernv: Use MSI bitmap to manage IRQs

As Michael Ellerman mentioned, arch/powerpc/sysdev/msi_bitmap.c
already implemented bitmap to manage (alloc/free) MSI interrupts.
The patch intends to use that mechanism to manage MSI interrupts
for PowerNV platform.
Signed-off-by: default avatarGavin Shan <shangw@linux.vnet.ibm.com>
Signed-off-by: default avatarMichael Ellerman <michael@ellerman.id.au>
parent 2a3563b0
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <asm/prom.h> #include <asm/prom.h>
#include <asm/pci-bridge.h> #include <asm/pci-bridge.h>
#include <asm/machdep.h> #include <asm/machdep.h>
#include <asm/msi_bitmap.h>
#include <asm/ppc-pci.h> #include <asm/ppc-pci.h>
#include <asm/opal.h> #include <asm/opal.h>
#include <asm/iommu.h> #include <asm/iommu.h>
...@@ -647,7 +648,7 @@ static int pnv_pci_ioda_msi_setup(struct pnv_phb *phb, struct pci_dev *dev, ...@@ -647,7 +648,7 @@ static int pnv_pci_ioda_msi_setup(struct pnv_phb *phb, struct pci_dev *dev,
static void pnv_pci_init_ioda_msis(struct pnv_phb *phb) static void pnv_pci_init_ioda_msis(struct pnv_phb *phb)
{ {
unsigned int bmap_size; unsigned int count;
const __be32 *prop = of_get_property(phb->hose->dn, const __be32 *prop = of_get_property(phb->hose->dn,
"ibm,opal-msi-ranges", NULL); "ibm,opal-msi-ranges", NULL);
if (!prop) { if (!prop) {
...@@ -658,18 +659,17 @@ static void pnv_pci_init_ioda_msis(struct pnv_phb *phb) ...@@ -658,18 +659,17 @@ static void pnv_pci_init_ioda_msis(struct pnv_phb *phb)
return; return;
phb->msi_base = be32_to_cpup(prop); phb->msi_base = be32_to_cpup(prop);
phb->msi_count = be32_to_cpup(prop + 1); count = be32_to_cpup(prop + 1);
bmap_size = BITS_TO_LONGS(phb->msi_count) * sizeof(unsigned long); if (msi_bitmap_alloc(&phb->msi_bmp, count, phb->hose->dn)) {
phb->msi_map = zalloc_maybe_bootmem(bmap_size, GFP_KERNEL);
if (!phb->msi_map) {
pr_err("PCI %d: Failed to allocate MSI bitmap !\n", pr_err("PCI %d: Failed to allocate MSI bitmap !\n",
phb->hose->global_number); phb->hose->global_number);
return; return;
} }
phb->msi_setup = pnv_pci_ioda_msi_setup; phb->msi_setup = pnv_pci_ioda_msi_setup;
phb->msi32_support = 1; phb->msi32_support = 1;
pr_info(" Allocated bitmap for %d MSIs (base IRQ 0x%x)\n", pr_info(" Allocated bitmap for %d MSIs (base IRQ 0x%x)\n",
phb->msi_count, phb->msi_base); count, phb->msi_base);
} }
#else #else
static void pnv_pci_init_ioda_msis(struct pnv_phb *phb) { } static void pnv_pci_init_ioda_msis(struct pnv_phb *phb) { }
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <asm/prom.h> #include <asm/prom.h>
#include <asm/pci-bridge.h> #include <asm/pci-bridge.h>
#include <asm/machdep.h> #include <asm/machdep.h>
#include <asm/msi_bitmap.h>
#include <asm/ppc-pci.h> #include <asm/ppc-pci.h>
#include <asm/opal.h> #include <asm/opal.h>
#include <asm/iommu.h> #include <asm/iommu.h>
...@@ -55,7 +56,7 @@ static int pnv_pci_p5ioc2_msi_setup(struct pnv_phb *phb, struct pci_dev *dev, ...@@ -55,7 +56,7 @@ static int pnv_pci_p5ioc2_msi_setup(struct pnv_phb *phb, struct pci_dev *dev,
static void pnv_pci_init_p5ioc2_msis(struct pnv_phb *phb) static void pnv_pci_init_p5ioc2_msis(struct pnv_phb *phb)
{ {
unsigned int bmap_size; unsigned int count;
const __be32 *prop = of_get_property(phb->hose->dn, const __be32 *prop = of_get_property(phb->hose->dn,
"ibm,opal-msi-ranges", NULL); "ibm,opal-msi-ranges", NULL);
if (!prop) if (!prop)
...@@ -67,10 +68,8 @@ static void pnv_pci_init_p5ioc2_msis(struct pnv_phb *phb) ...@@ -67,10 +68,8 @@ static void pnv_pci_init_p5ioc2_msis(struct pnv_phb *phb)
if (of_device_is_compatible(phb->hose->dn, "ibm,p5ioc2-pcix")) if (of_device_is_compatible(phb->hose->dn, "ibm,p5ioc2-pcix"))
return; return;
phb->msi_base = be32_to_cpup(prop); phb->msi_base = be32_to_cpup(prop);
phb->msi_count = be32_to_cpup(prop + 1); count = be32_to_cpup(prop + 1);
bmap_size = BITS_TO_LONGS(phb->msi_count) * sizeof(unsigned long); if (msi_bitmap_alloc(&phb->msi_bmp, count, phb->hose->dn)) {
phb->msi_map = zalloc_maybe_bootmem(bmap_size, GFP_KERNEL);
if (!phb->msi_map) {
pr_err("PCI %d: Failed to allocate MSI bitmap !\n", pr_err("PCI %d: Failed to allocate MSI bitmap !\n",
phb->hose->global_number); phb->hose->global_number);
return; return;
...@@ -78,7 +77,7 @@ static void pnv_pci_init_p5ioc2_msis(struct pnv_phb *phb) ...@@ -78,7 +77,7 @@ static void pnv_pci_init_p5ioc2_msis(struct pnv_phb *phb)
phb->msi_setup = pnv_pci_p5ioc2_msi_setup; phb->msi_setup = pnv_pci_p5ioc2_msi_setup;
phb->msi32_support = 0; phb->msi32_support = 0;
pr_info(" Allocated bitmap for %d MSIs (base IRQ 0x%x)\n", pr_info(" Allocated bitmap for %d MSIs (base IRQ 0x%x)\n",
phb->msi_count, phb->msi_base); count, phb->msi_base);
} }
#else #else
static void pnv_pci_init_p5ioc2_msis(struct pnv_phb *phb) { } static void pnv_pci_init_p5ioc2_msis(struct pnv_phb *phb) { }
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <asm/prom.h> #include <asm/prom.h>
#include <asm/pci-bridge.h> #include <asm/pci-bridge.h>
#include <asm/machdep.h> #include <asm/machdep.h>
#include <asm/msi_bitmap.h>
#include <asm/ppc-pci.h> #include <asm/ppc-pci.h>
#include <asm/opal.h> #include <asm/opal.h>
#include <asm/iommu.h> #include <asm/iommu.h>
...@@ -47,43 +48,7 @@ static int pnv_msi_check_device(struct pci_dev* pdev, int nvec, int type) ...@@ -47,43 +48,7 @@ static int pnv_msi_check_device(struct pci_dev* pdev, int nvec, int type)
struct pci_controller *hose = pci_bus_to_host(pdev->bus); struct pci_controller *hose = pci_bus_to_host(pdev->bus);
struct pnv_phb *phb = hose->private_data; struct pnv_phb *phb = hose->private_data;
return (phb && phb->msi_map) ? 0 : -ENODEV; return (phb && phb->msi_bmp.bitmap) ? 0 : -ENODEV;
}
static unsigned int pnv_get_one_msi(struct pnv_phb *phb)
{
unsigned long flags;
unsigned int id, rc;
spin_lock_irqsave(&phb->lock, flags);
id = find_next_zero_bit(phb->msi_map, phb->msi_count, phb->msi_next);
if (id >= phb->msi_count && phb->msi_next)
id = find_next_zero_bit(phb->msi_map, phb->msi_count, 0);
if (id >= phb->msi_count) {
rc = 0;
goto out;
}
__set_bit(id, phb->msi_map);
rc = id + phb->msi_base;
out:
spin_unlock_irqrestore(&phb->lock, flags);
return rc;
}
static void pnv_put_msi(struct pnv_phb *phb, unsigned int hwirq)
{
unsigned long flags;
unsigned int id;
if (WARN_ON(hwirq < phb->msi_base ||
hwirq >= (phb->msi_base + phb->msi_count)))
return;
id = hwirq - phb->msi_base;
spin_lock_irqsave(&phb->lock, flags);
__clear_bit(id, phb->msi_map);
spin_unlock_irqrestore(&phb->lock, flags);
} }
static int pnv_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type) static int pnv_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type)
...@@ -92,7 +57,8 @@ static int pnv_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type) ...@@ -92,7 +57,8 @@ static int pnv_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type)
struct pnv_phb *phb = hose->private_data; struct pnv_phb *phb = hose->private_data;
struct msi_desc *entry; struct msi_desc *entry;
struct msi_msg msg; struct msi_msg msg;
unsigned int hwirq, virq; int hwirq;
unsigned int virq;
int rc; int rc;
if (WARN_ON(!phb)) if (WARN_ON(!phb))
...@@ -104,25 +70,25 @@ static int pnv_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type) ...@@ -104,25 +70,25 @@ static int pnv_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type)
pci_name(pdev)); pci_name(pdev));
return -ENXIO; return -ENXIO;
} }
hwirq = pnv_get_one_msi(phb); hwirq = msi_bitmap_alloc_hwirqs(&phb->msi_bmp, 1);
if (!hwirq) { if (hwirq < 0) {
pr_warn("%s: Failed to find a free MSI\n", pr_warn("%s: Failed to find a free MSI\n",
pci_name(pdev)); pci_name(pdev));
return -ENOSPC; return -ENOSPC;
} }
virq = irq_create_mapping(NULL, hwirq); virq = irq_create_mapping(NULL, phb->msi_base + hwirq);
if (virq == NO_IRQ) { if (virq == NO_IRQ) {
pr_warn("%s: Failed to map MSI to linux irq\n", pr_warn("%s: Failed to map MSI to linux irq\n",
pci_name(pdev)); pci_name(pdev));
pnv_put_msi(phb, hwirq); msi_bitmap_free_hwirqs(&phb->msi_bmp, hwirq, 1);
return -ENOMEM; return -ENOMEM;
} }
rc = phb->msi_setup(phb, pdev, hwirq, entry->msi_attrib.is_64, rc = phb->msi_setup(phb, pdev, phb->msi_base + hwirq,
&msg); entry->msi_attrib.is_64, &msg);
if (rc) { if (rc) {
pr_warn("%s: Failed to setup MSI\n", pci_name(pdev)); pr_warn("%s: Failed to setup MSI\n", pci_name(pdev));
irq_dispose_mapping(virq); irq_dispose_mapping(virq);
pnv_put_msi(phb, hwirq); msi_bitmap_free_hwirqs(&phb->msi_bmp, hwirq, 1);
return rc; return rc;
} }
irq_set_msi_desc(virq, entry); irq_set_msi_desc(virq, entry);
...@@ -144,7 +110,8 @@ static void pnv_teardown_msi_irqs(struct pci_dev *pdev) ...@@ -144,7 +110,8 @@ static void pnv_teardown_msi_irqs(struct pci_dev *pdev)
if (entry->irq == NO_IRQ) if (entry->irq == NO_IRQ)
continue; continue;
irq_set_msi_desc(entry->irq, NULL); irq_set_msi_desc(entry->irq, NULL);
pnv_put_msi(phb, virq_to_hw(entry->irq)); msi_bitmap_free_hwirqs(&phb->msi_bmp,
virq_to_hw(entry->irq) - phb->msi_base, 1);
irq_dispose_mapping(entry->irq); irq_dispose_mapping(entry->irq);
} }
} }
......
...@@ -73,11 +73,9 @@ struct pnv_phb { ...@@ -73,11 +73,9 @@ struct pnv_phb {
spinlock_t lock; spinlock_t lock;
#ifdef CONFIG_PCI_MSI #ifdef CONFIG_PCI_MSI
unsigned long *msi_map;
unsigned int msi_base; unsigned int msi_base;
unsigned int msi_count;
unsigned int msi_next;
unsigned int msi32_support; unsigned int msi32_support;
struct msi_bitmap msi_bmp;
#endif #endif
int (*msi_setup)(struct pnv_phb *phb, struct pci_dev *dev, int (*msi_setup)(struct pnv_phb *phb, struct pci_dev *dev,
unsigned int hwirq, unsigned int is_64, unsigned int hwirq, unsigned int is_64,
......
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