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

msi: Make MSI useable more architectures

The arch hooks arch_setup_msi_irq and arch_teardown_msi_irq are now
responsible for allocating and freeing the linux irq in addition to
setting up the the linux irq to work with the interrupt.

arch_setup_msi_irq now takes a pci_device and a msi_desc and returns
an irq.

With this change in place this code should be useable by all platforms
except those that won't let the OS touch the hardware like ppc RTAS.
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 5b912c10
...@@ -2606,25 +2606,32 @@ static struct irq_chip msi_chip = { ...@@ -2606,25 +2606,32 @@ static struct irq_chip msi_chip = {
.retrigger = ioapic_retrigger_irq, .retrigger = ioapic_retrigger_irq,
}; };
int arch_setup_msi_irq(unsigned int irq, struct pci_dev *dev) int arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc)
{ {
struct msi_msg msg; struct msi_msg msg;
int ret; int irq, ret;
irq = create_irq();
if (irq < 0)
return irq;
set_irq_msi(irq, desc);
ret = msi_compose_msg(dev, irq, &msg); ret = msi_compose_msg(dev, irq, &msg);
if (ret < 0) if (ret < 0) {
destroy_irq(irq);
return ret; return ret;
}
write_msi_msg(irq, &msg); write_msi_msg(irq, &msg);
set_irq_chip_and_handler_name(irq, &msi_chip, handle_edge_irq, set_irq_chip_and_handler_name(irq, &msi_chip, handle_edge_irq,
"edge"); "edge");
return 0; return irq;
} }
void arch_teardown_msi_irq(unsigned int irq) void arch_teardown_msi_irq(unsigned int irq)
{ {
return; destroy_irq(irq);
} }
#endif /* CONFIG_PCI_MSI */ #endif /* CONFIG_PCI_MSI */
......
...@@ -64,12 +64,17 @@ static void ia64_set_msi_irq_affinity(unsigned int irq, cpumask_t cpu_mask) ...@@ -64,12 +64,17 @@ static void ia64_set_msi_irq_affinity(unsigned int irq, cpumask_t cpu_mask)
} }
#endif /* CONFIG_SMP */ #endif /* CONFIG_SMP */
int ia64_setup_msi_irq(unsigned int irq, struct pci_dev *pdev) int ia64_setup_msi_irq(struct pci_dev *pdev, struct msi_desc *desc)
{ {
struct msi_msg msg; struct msi_msg msg;
unsigned long dest_phys_id; unsigned long dest_phys_id;
unsigned int vector; unsigned int irq, vector;
irq = create_irq();
if (irq < 0)
return irq;
set_irq_msi(irq, desc);
dest_phys_id = cpu_physical_id(first_cpu(cpu_online_map)); dest_phys_id = cpu_physical_id(first_cpu(cpu_online_map));
vector = irq; vector = irq;
...@@ -89,12 +94,12 @@ int ia64_setup_msi_irq(unsigned int irq, struct pci_dev *pdev) ...@@ -89,12 +94,12 @@ int ia64_setup_msi_irq(unsigned int irq, struct pci_dev *pdev)
write_msi_msg(irq, &msg); write_msi_msg(irq, &msg);
set_irq_chip_and_handler(irq, &ia64_msi_chip, handle_edge_irq); set_irq_chip_and_handler(irq, &ia64_msi_chip, handle_edge_irq);
return 0; return irq;
} }
void ia64_teardown_msi_irq(unsigned int irq) void ia64_teardown_msi_irq(unsigned int irq)
{ {
return; /* no-op */ destroy_irq(irq);
} }
static void ia64_ack_msi_irq(unsigned int irq) static void ia64_ack_msi_irq(unsigned int irq)
...@@ -126,12 +131,12 @@ static struct irq_chip ia64_msi_chip = { ...@@ -126,12 +131,12 @@ static struct irq_chip ia64_msi_chip = {
}; };
int arch_setup_msi_irq(unsigned int irq, struct pci_dev *pdev) int arch_setup_msi_irq(struct pci_dev *pdev, struct msi_desc *desc)
{ {
if (platform_setup_msi_irq) if (platform_setup_msi_irq)
return platform_setup_msi_irq(irq, pdev); return platform_setup_msi_irq(pdev, desc);
return ia64_setup_msi_irq(irq, pdev); return ia64_setup_msi_irq(pdev, desc);
} }
void arch_teardown_msi_irq(unsigned int irq) void arch_teardown_msi_irq(unsigned int irq)
......
...@@ -59,13 +59,12 @@ void sn_teardown_msi_irq(unsigned int irq) ...@@ -59,13 +59,12 @@ void sn_teardown_msi_irq(unsigned int irq)
sn_intr_free(nasid, widget, sn_irq_info); sn_intr_free(nasid, widget, sn_irq_info);
sn_msi_info[irq].sn_irq_info = NULL; sn_msi_info[irq].sn_irq_info = NULL;
return; destroy_irq(irq);
} }
int sn_setup_msi_irq(unsigned int irq, struct pci_dev *pdev) int sn_setup_msi_irq(struct pci_dev *pdev, struct msi_desc *entry)
{ {
struct msi_msg msg; struct msi_msg msg;
struct msi_desc *entry;
int widget; int widget;
int status; int status;
nasid_t nasid; nasid_t nasid;
...@@ -73,8 +72,8 @@ int sn_setup_msi_irq(unsigned int irq, struct pci_dev *pdev) ...@@ -73,8 +72,8 @@ int sn_setup_msi_irq(unsigned int irq, struct pci_dev *pdev)
struct sn_irq_info *sn_irq_info; struct sn_irq_info *sn_irq_info;
struct pcibus_bussoft *bussoft = SN_PCIDEV_BUSSOFT(pdev); struct pcibus_bussoft *bussoft = SN_PCIDEV_BUSSOFT(pdev);
struct sn_pcibus_provider *provider = SN_PCIDEV_BUSPROVIDER(pdev); struct sn_pcibus_provider *provider = SN_PCIDEV_BUSPROVIDER(pdev);
int irq;
entry = get_irq_msi(irq);
if (!entry->msi_attrib.is_64) if (!entry->msi_attrib.is_64)
return -EINVAL; return -EINVAL;
...@@ -84,6 +83,11 @@ int sn_setup_msi_irq(unsigned int irq, struct pci_dev *pdev) ...@@ -84,6 +83,11 @@ int sn_setup_msi_irq(unsigned int irq, struct pci_dev *pdev)
if (provider == NULL || provider->dma_map_consistent == NULL) if (provider == NULL || provider->dma_map_consistent == NULL)
return -EINVAL; return -EINVAL;
irq = create_irq();
if (irq < 0)
return irq;
set_irq_msi(irq, entry);
/* /*
* Set up the vector plumbing. Let the prom (via sn_intr_alloc) * Set up the vector plumbing. Let the prom (via sn_intr_alloc)
* decide which cpu to direct this msi at by default. * decide which cpu to direct this msi at by default.
...@@ -95,12 +99,15 @@ int sn_setup_msi_irq(unsigned int irq, struct pci_dev *pdev) ...@@ -95,12 +99,15 @@ int sn_setup_msi_irq(unsigned int irq, struct pci_dev *pdev)
SWIN_WIDGETNUM(bussoft->bs_base); SWIN_WIDGETNUM(bussoft->bs_base);
sn_irq_info = kzalloc(sizeof(struct sn_irq_info), GFP_KERNEL); sn_irq_info = kzalloc(sizeof(struct sn_irq_info), GFP_KERNEL);
if (! sn_irq_info) if (! sn_irq_info) {
destroy_irq(irq);
return -ENOMEM; return -ENOMEM;
}
status = sn_intr_alloc(nasid, widget, sn_irq_info, irq, -1, -1); status = sn_intr_alloc(nasid, widget, sn_irq_info, irq, -1, -1);
if (status) { if (status) {
kfree(sn_irq_info); kfree(sn_irq_info);
destroy_irq(irq);
return -ENOMEM; return -ENOMEM;
} }
...@@ -121,6 +128,7 @@ int sn_setup_msi_irq(unsigned int irq, struct pci_dev *pdev) ...@@ -121,6 +128,7 @@ int sn_setup_msi_irq(unsigned int irq, struct pci_dev *pdev)
if (! bus_addr) { if (! bus_addr) {
sn_intr_free(nasid, widget, sn_irq_info); sn_intr_free(nasid, widget, sn_irq_info);
kfree(sn_irq_info); kfree(sn_irq_info);
destroy_irq(irq);
return -ENOMEM; return -ENOMEM;
} }
...@@ -139,7 +147,7 @@ int sn_setup_msi_irq(unsigned int irq, struct pci_dev *pdev) ...@@ -139,7 +147,7 @@ int sn_setup_msi_irq(unsigned int irq, struct pci_dev *pdev)
write_msi_msg(irq, &msg); write_msi_msg(irq, &msg);
set_irq_chip_and_handler(irq, &sn_msi_chip, handle_edge_irq); set_irq_chip_and_handler(irq, &sn_msi_chip, handle_edge_irq);
return 0; return irq;
} }
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
......
...@@ -1956,24 +1956,31 @@ static struct irq_chip msi_chip = { ...@@ -1956,24 +1956,31 @@ static struct irq_chip msi_chip = {
.retrigger = ioapic_retrigger_irq, .retrigger = ioapic_retrigger_irq,
}; };
int arch_setup_msi_irq(unsigned int irq, struct pci_dev *dev) int arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc)
{ {
struct msi_msg msg; struct msi_msg msg;
int ret; int irq, ret;
irq = create_irq();
if (irq < 0)
return irq;
set_irq_msi(irq, desc);
ret = msi_compose_msg(dev, irq, &msg); ret = msi_compose_msg(dev, irq, &msg);
if (ret < 0) if (ret < 0) {
destroy_irq(irq);
return ret; return ret;
}
write_msi_msg(irq, &msg); write_msi_msg(irq, &msg);
set_irq_chip_and_handler_name(irq, &msi_chip, handle_edge_irq, "edge"); set_irq_chip_and_handler_name(irq, &msi_chip, handle_edge_irq, "edge");
return 0; return irq;
} }
void arch_teardown_msi_irq(unsigned int irq) void arch_teardown_msi_irq(unsigned int irq)
{ {
return; destroy_irq(irq);
} }
#endif /* CONFIG_PCI_MSI */ #endif /* CONFIG_PCI_MSI */
......
...@@ -192,37 +192,6 @@ static struct msi_desc* alloc_msi_entry(void) ...@@ -192,37 +192,6 @@ static struct msi_desc* alloc_msi_entry(void)
return entry; return entry;
} }
static int create_msi_irq(void)
{
struct msi_desc *entry;
int irq;
entry = alloc_msi_entry();
if (!entry)
return -ENOMEM;
irq = create_irq();
if (irq < 0) {
kmem_cache_free(msi_cachep, entry);
return -EBUSY;
}
set_irq_msi(irq, entry);
return irq;
}
static void destroy_msi_irq(unsigned int irq)
{
struct msi_desc *entry;
entry = get_irq_msi(irq);
set_irq_chip(irq, NULL);
set_irq_msi(irq, NULL);
destroy_irq(irq);
kmem_cache_free(msi_cachep, entry);
}
static void enable_msi_mode(struct pci_dev *dev, int pos, int type) static void enable_msi_mode(struct pci_dev *dev, int pos, int type)
{ {
u16 control; u16 control;
...@@ -438,7 +407,6 @@ void pci_restore_msi_state(struct pci_dev *dev) ...@@ -438,7 +407,6 @@ void pci_restore_msi_state(struct pci_dev *dev)
**/ **/
static int msi_capability_init(struct pci_dev *dev) static int msi_capability_init(struct pci_dev *dev)
{ {
int status;
struct msi_desc *entry; struct msi_desc *entry;
int pos, irq; int pos, irq;
u16 control; u16 control;
...@@ -446,13 +414,10 @@ static int msi_capability_init(struct pci_dev *dev) ...@@ -446,13 +414,10 @@ static int msi_capability_init(struct pci_dev *dev)
pos = pci_find_capability(dev, PCI_CAP_ID_MSI); pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
pci_read_config_word(dev, msi_control_reg(pos), &control); pci_read_config_word(dev, msi_control_reg(pos), &control);
/* MSI Entry Initialization */ /* MSI Entry Initialization */
irq = create_msi_irq(); entry = alloc_msi_entry();
if (irq < 0) if (!entry)
return irq; return -ENOMEM;
entry = get_irq_msi(irq);
entry->link.head = irq;
entry->link.tail = irq;
entry->msi_attrib.type = PCI_CAP_ID_MSI; entry->msi_attrib.type = PCI_CAP_ID_MSI;
entry->msi_attrib.is_64 = is_64bit_address(control); entry->msi_attrib.is_64 = is_64bit_address(control);
entry->msi_attrib.entry_nr = 0; entry->msi_attrib.entry_nr = 0;
...@@ -478,14 +443,16 @@ static int msi_capability_init(struct pci_dev *dev) ...@@ -478,14 +443,16 @@ static int msi_capability_init(struct pci_dev *dev)
maskbits); maskbits);
} }
/* Configure MSI capability structure */ /* Configure MSI capability structure */
status = arch_setup_msi_irq(irq, dev); irq = arch_setup_msi_irq(dev, entry);
if (status < 0) { if (irq < 0) {
destroy_msi_irq(irq); kmem_cache_free(msi_cachep, entry);
return status; return irq;
} }
entry->link.head = irq;
entry->link.tail = irq;
dev->first_msi_irq = irq; dev->first_msi_irq = irq;
set_irq_msi(irq, entry); set_irq_msi(irq, entry);
/* 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);
...@@ -507,7 +474,6 @@ static int msix_capability_init(struct pci_dev *dev, ...@@ -507,7 +474,6 @@ static int msix_capability_init(struct pci_dev *dev,
struct msix_entry *entries, int nvec) struct msix_entry *entries, int nvec)
{ {
struct msi_desc *head = NULL, *tail = NULL, *entry = NULL; struct msi_desc *head = NULL, *tail = NULL, *entry = NULL;
int status;
int irq, pos, i, j, nr_entries, temp = 0; int irq, pos, i, j, nr_entries, temp = 0;
unsigned long phys_addr; unsigned long phys_addr;
u32 table_offset; u32 table_offset;
...@@ -530,13 +496,11 @@ static int msix_capability_init(struct pci_dev *dev, ...@@ -530,13 +496,11 @@ static int msix_capability_init(struct pci_dev *dev,
/* MSI-X Table Initialization */ /* MSI-X Table Initialization */
for (i = 0; i < nvec; i++) { for (i = 0; i < nvec; i++) {
irq = create_msi_irq(); entry = alloc_msi_entry();
if (irq < 0) if (!entry)
break; break;
entry = get_irq_msi(irq);
j = entries[i].entry; j = entries[i].entry;
entries[i].vector = irq;
entry->msi_attrib.type = PCI_CAP_ID_MSIX; entry->msi_attrib.type = PCI_CAP_ID_MSIX;
entry->msi_attrib.is_64 = 1; entry->msi_attrib.is_64 = 1;
entry->msi_attrib.entry_nr = j; entry->msi_attrib.entry_nr = j;
...@@ -545,6 +509,14 @@ static int msix_capability_init(struct pci_dev *dev, ...@@ -545,6 +509,14 @@ static int msix_capability_init(struct pci_dev *dev,
entry->msi_attrib.pos = pos; entry->msi_attrib.pos = pos;
entry->dev = dev; entry->dev = dev;
entry->mask_base = base; entry->mask_base = base;
/* Configure MSI-X capability structure */
irq = arch_setup_msi_irq(dev, entry);
if (irq < 0) {
kmem_cache_free(msi_cachep, entry);
break;
}
entries[i].vector = irq;
if (!head) { if (!head) {
entry->link.head = irq; entry->link.head = irq;
entry->link.tail = irq; entry->link.tail = irq;
...@@ -557,12 +529,6 @@ static int msix_capability_init(struct pci_dev *dev, ...@@ -557,12 +529,6 @@ static int msix_capability_init(struct pci_dev *dev,
} }
temp = irq; temp = irq;
tail = entry; tail = entry;
/* Configure MSI-X capability structure */
status = arch_setup_msi_irq(irq, dev);
if (status < 0) {
destroy_msi_irq(irq);
break;
}
set_irq_msi(irq, entry); set_irq_msi(irq, entry);
} }
...@@ -706,8 +672,6 @@ static int msi_free_irq(struct pci_dev* dev, int irq) ...@@ -706,8 +672,6 @@ static int msi_free_irq(struct pci_dev* dev, int irq)
int head, entry_nr, type; int head, entry_nr, type;
void __iomem *base; void __iomem *base;
arch_teardown_msi_irq(irq);
entry = get_irq_msi(irq); entry = get_irq_msi(irq);
if (!entry || entry->dev != dev) { if (!entry || entry->dev != dev) {
return -EINVAL; return -EINVAL;
...@@ -718,9 +682,9 @@ static int msi_free_irq(struct pci_dev* dev, int irq) ...@@ -718,9 +682,9 @@ static int msi_free_irq(struct pci_dev* dev, int irq)
base = entry->mask_base; base = entry->mask_base;
get_irq_msi(entry->link.head)->link.tail = entry->link.tail; get_irq_msi(entry->link.head)->link.tail = entry->link.tail;
get_irq_msi(entry->link.tail)->link.head = entry->link.head; get_irq_msi(entry->link.tail)->link.head = entry->link.head;
entry->dev = NULL;
destroy_msi_irq(irq); arch_teardown_msi_irq(irq);
kmem_cache_free(msi_cachep, entry);
if (type == PCI_CAP_ID_MSIX) { if (type == PCI_CAP_ID_MSIX) {
writel(1, base + entry_nr * PCI_MSIX_ENTRY_SIZE + writel(1, base + entry_nr * PCI_MSIX_ENTRY_SIZE +
......
...@@ -21,6 +21,7 @@ struct mm_struct; ...@@ -21,6 +21,7 @@ struct mm_struct;
struct pci_bus; struct pci_bus;
struct task_struct; struct task_struct;
struct pci_dev; struct pci_dev;
struct msi_desc;
typedef void ia64_mv_setup_t (char **); typedef void ia64_mv_setup_t (char **);
typedef void ia64_mv_cpu_init_t (void); typedef void ia64_mv_cpu_init_t (void);
...@@ -79,7 +80,7 @@ typedef unsigned short ia64_mv_readw_relaxed_t (const volatile void __iomem *); ...@@ -79,7 +80,7 @@ typedef unsigned short ia64_mv_readw_relaxed_t (const volatile void __iomem *);
typedef unsigned int ia64_mv_readl_relaxed_t (const volatile void __iomem *); typedef unsigned int ia64_mv_readl_relaxed_t (const volatile void __iomem *);
typedef unsigned long ia64_mv_readq_relaxed_t (const volatile void __iomem *); typedef unsigned long ia64_mv_readq_relaxed_t (const volatile void __iomem *);
typedef int ia64_mv_setup_msi_irq_t (unsigned int irq, struct pci_dev *pdev); typedef int ia64_mv_setup_msi_irq_t (struct pci_dev *pdev, struct msi_desc *);
typedef void ia64_mv_teardown_msi_irq_t (unsigned int irq); typedef void ia64_mv_teardown_msi_irq_t (unsigned int irq);
static inline void static inline void
......
...@@ -41,7 +41,7 @@ struct msi_desc { ...@@ -41,7 +41,7 @@ struct msi_desc {
/* /*
* The arch hook for setup up msi irqs * The arch hook for setup up msi irqs
*/ */
int arch_setup_msi_irq(unsigned int irq, struct pci_dev *dev); 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);
......
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