mirror of
https://github.com/torvalds/linux.git
synced 2024-11-11 06:31:49 +00:00
xen: events: separate MSI PIRQ allocation from PIRQ binding to IRQ
Split the binding aspect of xen_allocate_pirq_msi out into a new xen_bind_pirq_to_irq function. In xen_hvm_setup_msi_irq when allocating a pirq write the MSI message to signal the PIRQ as soon as the pirq is obtained. There is no way to free the pirq back so if the subsequent binding to an IRQ fails we want to ensure that we will reuse the PIRQ next time rather than leak it. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
This commit is contained in:
parent
5cad61a6ba
commit
bf480d952b
@ -86,7 +86,7 @@ static void xen_msi_compose_msg(struct pci_dev *pdev, unsigned int pirq,
|
||||
|
||||
static int xen_hvm_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
|
||||
{
|
||||
int irq, pirq, ret = 0;
|
||||
int irq, pirq;
|
||||
struct msi_desc *msidesc;
|
||||
struct msi_msg msg;
|
||||
|
||||
@ -94,39 +94,32 @@ static int xen_hvm_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
|
||||
__read_msi_msg(msidesc, &msg);
|
||||
pirq = MSI_ADDR_EXT_DEST_ID(msg.address_hi) |
|
||||
((msg.address_lo >> MSI_ADDR_DEST_ID_SHIFT) & 0xff);
|
||||
if (xen_irq_from_pirq(pirq) >= 0 && msg.data == XEN_PIRQ_MSI_DATA) {
|
||||
irq = xen_allocate_pirq_msi((type == PCI_CAP_ID_MSIX) ?
|
||||
"msi-x" : "msi", &pirq, 0);
|
||||
if (irq < 0)
|
||||
if (msg.data != XEN_PIRQ_MSI_DATA ||
|
||||
xen_irq_from_pirq(pirq) < 0) {
|
||||
pirq = xen_allocate_pirq_msi(dev, msidesc);
|
||||
if (pirq < 0)
|
||||
goto error;
|
||||
ret = set_irq_msi(irq, msidesc);
|
||||
if (ret < 0)
|
||||
goto error_while;
|
||||
printk(KERN_DEBUG "xen: msi already setup: msi --> irq=%d"
|
||||
" pirq=%d\n", irq, pirq);
|
||||
return 0;
|
||||
xen_msi_compose_msg(dev, pirq, &msg);
|
||||
__write_msi_msg(msidesc, &msg);
|
||||
dev_dbg(&dev->dev, "xen: msi bound to pirq=%d\n", pirq);
|
||||
} else {
|
||||
dev_dbg(&dev->dev,
|
||||
"xen: msi already bound to pirq=%d\n", pirq);
|
||||
}
|
||||
irq = xen_allocate_pirq_msi((type == PCI_CAP_ID_MSIX) ?
|
||||
"msi-x" : "msi", &pirq, 1);
|
||||
if (irq < 0 || pirq < 0)
|
||||
irq = xen_bind_pirq_msi_to_irq(dev, msidesc, pirq,
|
||||
(type == PCI_CAP_ID_MSIX) ?
|
||||
"msi-x" : "msi");
|
||||
if (irq < 0)
|
||||
goto error;
|
||||
printk(KERN_DEBUG "xen: msi --> irq=%d, pirq=%d\n", irq, pirq);
|
||||
xen_msi_compose_msg(dev, pirq, &msg);
|
||||
ret = set_irq_msi(irq, msidesc);
|
||||
if (ret < 0)
|
||||
goto error_while;
|
||||
write_msi_msg(irq, &msg);
|
||||
dev_dbg(&dev->dev,
|
||||
"xen: msi --> pirq=%d --> irq=%d\n", pirq, irq);
|
||||
}
|
||||
return 0;
|
||||
|
||||
error_while:
|
||||
unbind_from_irqhandler(irq, NULL);
|
||||
error:
|
||||
if (ret == -ENODEV)
|
||||
dev_err(&dev->dev, "Xen PCI frontend has not registered" \
|
||||
" MSI/MSI-X support!\n");
|
||||
|
||||
return ret;
|
||||
dev_err(&dev->dev,
|
||||
"Xen PCI frontend has not registered MSI/MSI-X support!\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -152,28 +145,19 @@ static int xen_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
|
||||
goto error;
|
||||
i = 0;
|
||||
list_for_each_entry(msidesc, &dev->msi_list, list) {
|
||||
irq = xen_allocate_pirq_msi(
|
||||
(type == PCI_CAP_ID_MSIX) ?
|
||||
"pcifront-msi-x" : "pcifront-msi",
|
||||
&v[i], 0);
|
||||
if (irq < 0) {
|
||||
ret = -1;
|
||||
irq = xen_bind_pirq_msi_to_irq(dev, msidesc, v[i],
|
||||
(type == PCI_CAP_ID_MSIX) ?
|
||||
"pcifront-msi-x" :
|
||||
"pcifront-msi");
|
||||
if (irq < 0)
|
||||
goto free;
|
||||
}
|
||||
ret = set_irq_msi(irq, msidesc);
|
||||
if (ret)
|
||||
goto error_while;
|
||||
i++;
|
||||
}
|
||||
kfree(v);
|
||||
return 0;
|
||||
|
||||
error_while:
|
||||
unbind_from_irqhandler(irq, NULL);
|
||||
error:
|
||||
if (ret == -ENODEV)
|
||||
dev_err(&dev->dev, "Xen PCI frontend has not registered" \
|
||||
" MSI/MSI-X support!\n");
|
||||
dev_err(&dev->dev, "Xen PCI frontend has not registered MSI/MSI-X support!\n");
|
||||
free:
|
||||
kfree(v);
|
||||
return ret;
|
||||
|
@ -647,12 +647,12 @@ out:
|
||||
#include <linux/msi.h>
|
||||
#include "../pci/msi.h"
|
||||
|
||||
static int find_unbound_pirq(int type)
|
||||
int xen_allocate_pirq_msi(struct pci_dev *dev, struct msi_desc *msidesc)
|
||||
{
|
||||
int rc;
|
||||
struct physdev_get_free_pirq op_get_free_pirq;
|
||||
|
||||
op_get_free_pirq.type = type;
|
||||
op_get_free_pirq.type = MAP_PIRQ_TYPE_MSI;
|
||||
rc = HYPERVISOR_physdev_op(PHYSDEVOP_get_free_pirq, &op_get_free_pirq);
|
||||
|
||||
WARN_ONCE(rc == -ENOSYS,
|
||||
@ -661,9 +661,10 @@ static int find_unbound_pirq(int type)
|
||||
return rc ? -1 : op_get_free_pirq.pirq;
|
||||
}
|
||||
|
||||
int xen_allocate_pirq_msi(char *name, int *pirq, int alloc_pirq)
|
||||
int xen_bind_pirq_msi_to_irq(struct pci_dev *dev, struct msi_desc *msidesc,
|
||||
int pirq, const char *name)
|
||||
{
|
||||
int irq;
|
||||
int irq, ret;
|
||||
|
||||
spin_lock(&irq_mapping_update_lock);
|
||||
|
||||
@ -671,24 +672,21 @@ int xen_allocate_pirq_msi(char *name, int *pirq, int alloc_pirq)
|
||||
if (irq == -1)
|
||||
goto out;
|
||||
|
||||
if (alloc_pirq) {
|
||||
*pirq = find_unbound_pirq(MAP_PIRQ_TYPE_MSI);
|
||||
if (*pirq == -1) {
|
||||
xen_free_irq(irq);
|
||||
irq = -1;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
set_irq_chip_and_handler_name(irq, &xen_pirq_chip,
|
||||
handle_level_irq, name);
|
||||
|
||||
irq_info[irq] = mk_pirq_info(0, *pirq, 0, 0);
|
||||
pirq_to_irq[*pirq] = irq;
|
||||
|
||||
irq_info[irq] = mk_pirq_info(0, pirq, 0, 0);
|
||||
pirq_to_irq[pirq] = irq;
|
||||
ret = set_irq_msi(irq, msidesc);
|
||||
if (ret < 0)
|
||||
goto error_irq;
|
||||
out:
|
||||
spin_unlock(&irq_mapping_update_lock);
|
||||
return irq;
|
||||
error_irq:
|
||||
spin_unlock(&irq_mapping_update_lock);
|
||||
xen_free_irq(irq);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int xen_create_msi_irq(struct pci_dev *dev, struct msi_desc *msidesc, int type)
|
||||
|
@ -75,7 +75,9 @@ int xen_allocate_pirq(unsigned gsi, int shareable, char *name);
|
||||
int xen_map_pirq_gsi(unsigned pirq, unsigned gsi, int shareable, char *name);
|
||||
|
||||
#ifdef CONFIG_PCI_MSI
|
||||
int xen_allocate_pirq_msi(char *name, int *pirq, int alloc_pirq);
|
||||
int xen_allocate_pirq_msi(struct pci_dev *dev, struct msi_desc *msidesc);
|
||||
int xen_bind_pirq_msi_to_irq(struct pci_dev *dev, struct msi_desc *msidesc,
|
||||
int pirq, const char *name);
|
||||
int xen_create_msi_irq(struct pci_dev *dev, struct msi_desc *msidesc, int type);
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user