Commit 5a39837f authored by Linus Torvalds's avatar Linus Torvalds

Merge branches 'stable/irq.fairness' and 'stable/irq.ween_of_nr_irqs' of...

Merge branches 'stable/irq.fairness' and 'stable/irq.ween_of_nr_irqs' of git://git.kernel.org/pub/scm/linux/kernel/git/konrad/xen

* 'stable/irq.fairness' of git://git.kernel.org/pub/scm/linux/kernel/git/konrad/xen:
  xen: events: Remove redundant clear of l2i at end of round-robin loop
  xen: events: Make round-robin scan fairer by snapshotting each l2 word once only
  xen: events: Clean up round-robin evtchn scan.
  xen: events: Make last processed event channel a per-cpu variable.
  xen: events: Process event channels notifications in round-robin order.

* 'stable/irq.ween_of_nr_irqs' of git://git.kernel.org/pub/scm/linux/kernel/git/konrad/xen:
  xen: events: Fix compile error if CONFIG_SMP is not defined.
  xen: events: correct locking in xen_irq_from_pirq
  xen: events: propagate irq allocation failure instead of panicking
  xen: events: do not workaround too-small nr_irqs
  xen: events: remove use of nr_irqs as upper bound on number of pirqs
  xen: events: dynamically allocate irq info structures
  xen: events: maintain a list of Xen interrupts
  xen: events: push setup of irq<->{evtchn,ipi,virq,pirq} maps into irq_info init functions
  xen: events: turn irq_info constructors into initialiser functions
  xen: events: use per-cpu variable for cpu_evtchn_mask
  xen: events: refactor GSI pirq bindings functions
  xen: events: rename restore_cpu_pirqs -> restore_pirqs
  xen: events: remove unused public functions
  xen: events: fix xen_map_pirq_gsi error return
  xen: events: simplify comment
  xen: events: separate two unrelated halves of if condition

Fix up trivial conflicts in drivers/xen/events.c
...@@ -50,7 +50,7 @@ static int acpi_register_gsi_xen_hvm(struct device *dev, u32 gsi, ...@@ -50,7 +50,7 @@ static int acpi_register_gsi_xen_hvm(struct device *dev, u32 gsi,
name = "ioapic-level"; name = "ioapic-level";
} }
irq = xen_map_pirq_gsi(map_irq.pirq, gsi, shareable, name); irq = xen_bind_pirq_gsi_to_irq(gsi, map_irq.pirq, shareable, name);
printk(KERN_DEBUG "xen: --> irq=%d, pirq=%d\n", irq, map_irq.pirq); printk(KERN_DEBUG "xen: --> irq=%d, pirq=%d\n", irq, map_irq.pirq);
...@@ -237,6 +237,7 @@ static int xen_pcifront_enable_irq(struct pci_dev *dev) ...@@ -237,6 +237,7 @@ static int xen_pcifront_enable_irq(struct pci_dev *dev)
{ {
int rc; int rc;
int share = 1; int share = 1;
int pirq;
u8 gsi; u8 gsi;
rc = pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &gsi); rc = pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &gsi);
...@@ -246,13 +247,21 @@ static int xen_pcifront_enable_irq(struct pci_dev *dev) ...@@ -246,13 +247,21 @@ static int xen_pcifront_enable_irq(struct pci_dev *dev)
return rc; return rc;
} }
rc = xen_allocate_pirq_gsi(gsi);
if (rc < 0) {
dev_warn(&dev->dev, "Xen PCI: failed to allocate a PIRQ for GSI%d: %d\n",
gsi, rc);
return rc;
}
pirq = rc;
if (gsi < NR_IRQS_LEGACY) if (gsi < NR_IRQS_LEGACY)
share = 0; share = 0;
rc = xen_allocate_pirq(gsi, share, "pcifront"); rc = xen_bind_pirq_gsi_to_irq(gsi, pirq, share, "pcifront");
if (rc < 0) { if (rc < 0) {
dev_warn(&dev->dev, "Xen PCI: failed to register GSI%d: %d\n", dev_warn(&dev->dev, "Xen PCI: failed to bind GSI%d (PIRQ%d) to IRQ: %d\n",
gsi, rc); gsi, pirq, rc);
return rc; return rc;
} }
...@@ -309,7 +318,7 @@ int __init pci_xen_hvm_init(void) ...@@ -309,7 +318,7 @@ int __init pci_xen_hvm_init(void)
#ifdef CONFIG_XEN_DOM0 #ifdef CONFIG_XEN_DOM0
static int xen_register_pirq(u32 gsi, int triggering) static int xen_register_pirq(u32 gsi, int triggering)
{ {
int rc, irq; int rc, pirq, irq = -1;
struct physdev_map_pirq map_irq; struct physdev_map_pirq map_irq;
int shareable = 0; int shareable = 0;
char *name; char *name;
...@@ -325,17 +334,20 @@ static int xen_register_pirq(u32 gsi, int triggering) ...@@ -325,17 +334,20 @@ static int xen_register_pirq(u32 gsi, int triggering)
name = "ioapic-level"; name = "ioapic-level";
} }
irq = xen_allocate_pirq(gsi, shareable, name); pirq = xen_allocate_pirq_gsi(gsi);
if (pirq < 0)
printk(KERN_DEBUG "xen: --> irq=%d\n", irq); goto out;
irq = xen_bind_pirq_gsi_to_irq(gsi, pirq, shareable, name);
if (irq < 0) if (irq < 0)
goto out; goto out;
printk(KERN_DEBUG "xen: --> pirq=%d -> irq=%d\n", pirq, irq);
map_irq.domid = DOMID_SELF; map_irq.domid = DOMID_SELF;
map_irq.type = MAP_PIRQ_TYPE_GSI; map_irq.type = MAP_PIRQ_TYPE_GSI;
map_irq.index = gsi; map_irq.index = gsi;
map_irq.pirq = irq; map_irq.pirq = pirq;
rc = HYPERVISOR_physdev_op(PHYSDEVOP_map_pirq, &map_irq); rc = HYPERVISOR_physdev_op(PHYSDEVOP_map_pirq, &map_irq);
if (rc) { if (rc) {
...@@ -422,13 +434,18 @@ static int __init pci_xen_initial_domain(void) ...@@ -422,13 +434,18 @@ static int __init pci_xen_initial_domain(void)
void __init xen_setup_pirqs(void) void __init xen_setup_pirqs(void)
{ {
int irq; int pirq, irq;
pci_xen_initial_domain(); pci_xen_initial_domain();
if (0 == nr_ioapics) { if (0 == nr_ioapics) {
for (irq = 0; irq < NR_IRQS_LEGACY; irq++) for (irq = 0; irq < NR_IRQS_LEGACY; irq++) {
xen_allocate_pirq(irq, 0, "xt-pic"); pirq = xen_allocate_pirq_gsi(irq);
if (WARN(pirq < 0,
"Could not allocate PIRQ for legacy interrupt\n"))
break;
irq = xen_bind_pirq_gsi_to_irq(irq, pirq, 0, "xt-pic");
}
return; return;
} }
......
...@@ -56,6 +56,8 @@ ...@@ -56,6 +56,8 @@
*/ */
static DEFINE_SPINLOCK(irq_mapping_update_lock); static DEFINE_SPINLOCK(irq_mapping_update_lock);
static LIST_HEAD(xen_irq_list_head);
/* IRQ <-> VIRQ mapping. */ /* IRQ <-> VIRQ mapping. */
static DEFINE_PER_CPU(int [NR_VIRQS], virq_to_irq) = {[0 ... NR_VIRQS-1] = -1}; static DEFINE_PER_CPU(int [NR_VIRQS], virq_to_irq) = {[0 ... NR_VIRQS-1] = -1};
...@@ -85,7 +87,9 @@ enum xen_irq_type { ...@@ -85,7 +87,9 @@ enum xen_irq_type {
*/ */
struct irq_info struct irq_info
{ {
struct list_head list;
enum xen_irq_type type; /* type */ enum xen_irq_type type; /* type */
unsigned irq;
unsigned short evtchn; /* event channel */ unsigned short evtchn; /* event channel */
unsigned short cpu; /* cpu bound */ unsigned short cpu; /* cpu bound */
...@@ -103,23 +107,10 @@ struct irq_info ...@@ -103,23 +107,10 @@ struct irq_info
#define PIRQ_NEEDS_EOI (1 << 0) #define PIRQ_NEEDS_EOI (1 << 0)
#define PIRQ_SHAREABLE (1 << 1) #define PIRQ_SHAREABLE (1 << 1)
static struct irq_info *irq_info;
static int *pirq_to_irq;
static int *evtchn_to_irq; static int *evtchn_to_irq;
struct cpu_evtchn_s {
unsigned long bits[NR_EVENT_CHANNELS/BITS_PER_LONG];
};
static __initdata struct cpu_evtchn_s init_evtchn_mask = { static DEFINE_PER_CPU(unsigned long [NR_EVENT_CHANNELS/BITS_PER_LONG],
.bits[0 ... (NR_EVENT_CHANNELS/BITS_PER_LONG)-1] = ~0ul, cpu_evtchn_mask);
};
static struct cpu_evtchn_s __refdata *cpu_evtchn_mask_p = &init_evtchn_mask;
static inline unsigned long *cpu_evtchn_mask(int cpu)
{
return cpu_evtchn_mask_p[cpu].bits;
}
/* Xen will never allocate port zero for any purpose. */ /* Xen will never allocate port zero for any purpose. */
#define VALID_EVTCHN(chn) ((chn) != 0) #define VALID_EVTCHN(chn) ((chn) != 0)
...@@ -128,46 +119,86 @@ static struct irq_chip xen_dynamic_chip; ...@@ -128,46 +119,86 @@ static struct irq_chip xen_dynamic_chip;
static struct irq_chip xen_percpu_chip; static struct irq_chip xen_percpu_chip;
static struct irq_chip xen_pirq_chip; static struct irq_chip xen_pirq_chip;
/* Constructor for packed IRQ information. */ /* Get info for IRQ */
static struct irq_info mk_unbound_info(void) static struct irq_info *info_for_irq(unsigned irq)
{
return get_irq_data(irq);
}
/* Constructors for packed IRQ information. */
static void xen_irq_info_common_init(struct irq_info *info,
unsigned irq,
enum xen_irq_type type,
unsigned short evtchn,
unsigned short cpu)
{ {
return (struct irq_info) { .type = IRQT_UNBOUND };
BUG_ON(info->type != IRQT_UNBOUND && info->type != type);
info->type = type;
info->irq = irq;
info->evtchn = evtchn;
info->cpu = cpu;
evtchn_to_irq[evtchn] = irq;
} }
static struct irq_info mk_evtchn_info(unsigned short evtchn) static void xen_irq_info_evtchn_init(unsigned irq,
unsigned short evtchn)
{ {
return (struct irq_info) { .type = IRQT_EVTCHN, .evtchn = evtchn, struct irq_info *info = info_for_irq(irq);
.cpu = 0 };
xen_irq_info_common_init(info, irq, IRQT_EVTCHN, evtchn, 0);
} }
static struct irq_info mk_ipi_info(unsigned short evtchn, enum ipi_vector ipi) static void xen_irq_info_ipi_init(unsigned cpu,
unsigned irq,
unsigned short evtchn,
enum ipi_vector ipi)
{ {
return (struct irq_info) { .type = IRQT_IPI, .evtchn = evtchn, struct irq_info *info = info_for_irq(irq);
.cpu = 0, .u.ipi = ipi };
xen_irq_info_common_init(info, irq, IRQT_IPI, evtchn, 0);
info->u.ipi = ipi;
per_cpu(ipi_to_irq, cpu)[ipi] = irq;
} }
static struct irq_info mk_virq_info(unsigned short evtchn, unsigned short virq) static void xen_irq_info_virq_init(unsigned cpu,
unsigned irq,
unsigned short evtchn,
unsigned short virq)
{ {
return (struct irq_info) { .type = IRQT_VIRQ, .evtchn = evtchn, struct irq_info *info = info_for_irq(irq);
.cpu = 0, .u.virq = virq };
xen_irq_info_common_init(info, irq, IRQT_VIRQ, evtchn, 0);
info->u.virq = virq;
per_cpu(virq_to_irq, cpu)[virq] = irq;
} }
static struct irq_info mk_pirq_info(unsigned short evtchn, unsigned short pirq, static void xen_irq_info_pirq_init(unsigned irq,
unsigned short gsi, unsigned short vector) unsigned short evtchn,
unsigned short pirq,
unsigned short gsi,
unsigned short vector,
unsigned char flags)
{ {
return (struct irq_info) { .type = IRQT_PIRQ, .evtchn = evtchn, struct irq_info *info = info_for_irq(irq);
.cpu = 0,
.u.pirq = { .pirq = pirq, .gsi = gsi, .vector = vector } }; xen_irq_info_common_init(info, irq, IRQT_PIRQ, evtchn, 0);
info->u.pirq.pirq = pirq;
info->u.pirq.gsi = gsi;
info->u.pirq.vector = vector;
info->u.pirq.flags = flags;
} }
/* /*
* Accessors for packed IRQ information. * Accessors for packed IRQ information.
*/ */
static struct irq_info *info_for_irq(unsigned irq)
{
return &irq_info[irq];
}
static unsigned int evtchn_from_irq(unsigned irq) static unsigned int evtchn_from_irq(unsigned irq)
{ {
if (unlikely(WARN(irq < 0 || irq >= nr_irqs, "Invalid irq %d!\n", irq))) if (unlikely(WARN(irq < 0 || irq >= nr_irqs, "Invalid irq %d!\n", irq)))
...@@ -212,26 +243,6 @@ static unsigned pirq_from_irq(unsigned irq) ...@@ -212,26 +243,6 @@ static unsigned pirq_from_irq(unsigned irq)
return info->u.pirq.pirq; return info->u.pirq.pirq;
} }
static unsigned gsi_from_irq(unsigned irq)
{
struct irq_info *info = info_for_irq(irq);
BUG_ON(info == NULL);
BUG_ON(info->type != IRQT_PIRQ);
return info->u.pirq.gsi;
}
static unsigned vector_from_irq(unsigned irq)
{
struct irq_info *info = info_for_irq(irq);
BUG_ON(info == NULL);
BUG_ON(info->type != IRQT_PIRQ);
return info->u.pirq.vector;
}
static enum xen_irq_type type_from_irq(unsigned irq) static enum xen_irq_type type_from_irq(unsigned irq)
{ {
return info_for_irq(irq)->type; return info_for_irq(irq)->type;
...@@ -267,7 +278,7 @@ static inline unsigned long active_evtchns(unsigned int cpu, ...@@ -267,7 +278,7 @@ static inline unsigned long active_evtchns(unsigned int cpu,
unsigned int idx) unsigned int idx)
{ {
return (sh->evtchn_pending[idx] & return (sh->evtchn_pending[idx] &
cpu_evtchn_mask(cpu)[idx] & per_cpu(cpu_evtchn_mask, cpu)[idx] &
~sh->evtchn_mask[idx]); ~sh->evtchn_mask[idx]);
} }
...@@ -280,28 +291,28 @@ static void bind_evtchn_to_cpu(unsigned int chn, unsigned int cpu) ...@@ -280,28 +291,28 @@ static void bind_evtchn_to_cpu(unsigned int chn, unsigned int cpu)
cpumask_copy(irq_to_desc(irq)->irq_data.affinity, cpumask_of(cpu)); cpumask_copy(irq_to_desc(irq)->irq_data.affinity, cpumask_of(cpu));
#endif #endif
clear_bit(chn, cpu_evtchn_mask(cpu_from_irq(irq))); clear_bit(chn, per_cpu(cpu_evtchn_mask, cpu_from_irq(irq)));
set_bit(chn, cpu_evtchn_mask(cpu)); set_bit(chn, per_cpu(cpu_evtchn_mask, cpu));
irq_info[irq].cpu = cpu; info_for_irq(irq)->cpu = cpu;
} }
static void init_evtchn_cpu_bindings(void) static void init_evtchn_cpu_bindings(void)
{ {
int i; int i;
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
struct irq_desc *desc; struct irq_info *info;
/* By default all event channels notify CPU#0. */ /* By default all event channels notify CPU#0. */
for_each_irq_desc(i, desc) { list_for_each_entry(info, &xen_irq_list_head, list) {
struct irq_desc *desc = irq_to_desc(info->irq);
cpumask_copy(desc->irq_data.affinity, cpumask_of(0)); cpumask_copy(desc->irq_data.affinity, cpumask_of(0));
} }
#endif #endif
for_each_possible_cpu(i) for_each_possible_cpu(i)
memset(cpu_evtchn_mask(i), memset(per_cpu(cpu_evtchn_mask, i),
(i == 0) ? ~0 : 0, sizeof(struct cpu_evtchn_s)); (i == 0) ? ~0 : 0, sizeof(*per_cpu(cpu_evtchn_mask, i)));
} }
static inline void clear_evtchn(int port) static inline void clear_evtchn(int port)
...@@ -376,7 +387,28 @@ static void unmask_evtchn(int port) ...@@ -376,7 +387,28 @@ static void unmask_evtchn(int port)
put_cpu(); put_cpu();
} }
static int xen_allocate_irq_dynamic(void) static void xen_irq_init(unsigned irq)
{
struct irq_info *info;
struct irq_desc *desc = irq_to_desc(irq);
#ifdef CONFIG_SMP
/* By default all event channels notify CPU#0. */
cpumask_copy(desc->irq_data.affinity, cpumask_of(0));
#endif
info = kzalloc(sizeof(*info), GFP_KERNEL);
if (info == NULL)
panic("Unable to allocate metadata for IRQ%d\n", irq);
info->type = IRQT_UNBOUND;
set_irq_data(irq, info);
list_add_tail(&info->list, &xen_irq_list_head);
}
static int __must_check xen_allocate_irq_dynamic(void)
{ {
int first = 0; int first = 0;
int irq; int irq;
...@@ -393,22 +425,14 @@ static int xen_allocate_irq_dynamic(void) ...@@ -393,22 +425,14 @@ static int xen_allocate_irq_dynamic(void)
first = get_nr_irqs_gsi(); first = get_nr_irqs_gsi();
#endif #endif
retry:
irq = irq_alloc_desc_from(first, -1); irq = irq_alloc_desc_from(first, -1);
if (irq == -ENOMEM && first > NR_IRQS_LEGACY) { xen_irq_init(irq);
printk(KERN_ERR "Out of dynamic IRQ space and eating into GSI space. You should increase nr_irqs\n");
first = max(NR_IRQS_LEGACY, first - NR_IRQS_LEGACY);
goto retry;
}
if (irq < 0)
panic("No available IRQ to bind to: increase nr_irqs!\n");
return irq; return irq;
} }
static int xen_allocate_irq_gsi(unsigned gsi) static int __must_check xen_allocate_irq_gsi(unsigned gsi)
{ {
int irq; int irq;
...@@ -423,17 +447,25 @@ static int xen_allocate_irq_gsi(unsigned gsi) ...@@ -423,17 +447,25 @@ static int xen_allocate_irq_gsi(unsigned gsi)
/* Legacy IRQ descriptors are already allocated by the arch. */ /* Legacy IRQ descriptors are already allocated by the arch. */
if (gsi < NR_IRQS_LEGACY) if (gsi < NR_IRQS_LEGACY)
return gsi; irq = gsi;
else
irq = irq_alloc_desc_at(gsi, -1);
irq = irq_alloc_desc_at(gsi, -1); xen_irq_init(irq);
if (irq < 0)
panic("Unable to allocate to IRQ%d (%d)\n", gsi, irq);
return irq; return irq;
} }
static void xen_free_irq(unsigned irq) static void xen_free_irq(unsigned irq)
{ {
struct irq_info *info = get_irq_data(irq);
list_del(&info->list);
set_irq_data(irq, NULL);
kfree(info);
/* Legacy IRQ descriptors are managed by the arch. */ /* Legacy IRQ descriptors are managed by the arch. */
if (irq < NR_IRQS_LEGACY) if (irq < NR_IRQS_LEGACY)
return; return;
...@@ -563,51 +595,39 @@ static void ack_pirq(struct irq_data *data) ...@@ -563,51 +595,39 @@ static void ack_pirq(struct irq_data *data)
static int find_irq_by_gsi(unsigned gsi) static int find_irq_by_gsi(unsigned gsi)
{ {
int irq; struct irq_info *info;
for (irq = 0; irq < nr_irqs; irq++) { list_for_each_entry(info, &xen_irq_list_head, list) {
struct irq_info *info = info_for_irq(irq); if (info->type != IRQT_PIRQ)
if (info == NULL || info->type != IRQT_PIRQ)
continue; continue;
if (gsi_from_irq(irq) == gsi) if (info->u.pirq.gsi == gsi)
return irq; return info->irq;
} }
return -1; return -1;
} }
int xen_allocate_pirq(unsigned gsi, int shareable, char *name) int xen_allocate_pirq_gsi(unsigned gsi)
{ {
return xen_map_pirq_gsi(gsi, gsi, shareable, name); return gsi;
} }
/* xen_map_pirq_gsi might allocate irqs from the top down, as a /*
* consequence don't assume that the irq number returned has a low value * Do not make any assumptions regarding the relationship between the
* or can be used as a pirq number unless you know otherwise. * IRQ number returned here and the Xen pirq argument.
*
* One notable exception is when xen_map_pirq_gsi is called passing an
* hardware gsi as argument, in that case the irq number returned
* matches the gsi number passed as second argument.
* *
* Note: We don't assign an event channel until the irq actually started * Note: We don't assign an event channel until the irq actually started
* up. Return an existing irq if we've already got one for the gsi. * up. Return an existing irq if we've already got one for the gsi.
*/ */
int xen_map_pirq_gsi(unsigned pirq, unsigned gsi, int shareable, char *name) int xen_bind_pirq_gsi_to_irq(unsigned gsi,
unsigned pirq, int shareable, char *name)
{ {
int irq = 0; int irq = -1;
struct physdev_irq irq_op; struct physdev_irq irq_op;
spin_lock(&irq_mapping_update_lock); spin_lock(&irq_mapping_update_lock);
if ((pirq > nr_irqs) || (gsi > nr_irqs)) {
printk(KERN_WARNING "xen_map_pirq_gsi: %s %s is incorrect!\n",
pirq > nr_irqs ? "pirq" :"",
gsi > nr_irqs ? "gsi" : "");
goto out;
}
irq = find_irq_by_gsi(gsi); irq = find_irq_by_gsi(gsi);
if (irq != -1) { if (irq != -1) {
printk(KERN_INFO "xen_map_pirq_gsi: returning irq %d for gsi %u\n", printk(KERN_INFO "xen_map_pirq_gsi: returning irq %d for gsi %u\n",
...@@ -616,6 +636,8 @@ int xen_map_pirq_gsi(unsigned pirq, unsigned gsi, int shareable, char *name) ...@@ -616,6 +636,8 @@ int xen_map_pirq_gsi(unsigned pirq, unsigned gsi, int shareable, char *name)
} }
irq = xen_allocate_irq_gsi(gsi); irq = xen_allocate_irq_gsi(gsi);
if (irq < 0)
goto out;
set_irq_chip_and_handler_name(irq, &xen_pirq_chip, set_irq_chip_and_handler_name(irq, &xen_pirq_chip,
handle_level_irq, name); handle_level_irq, name);
...@@ -633,9 +655,8 @@ int xen_map_pirq_gsi(unsigned pirq, unsigned gsi, int shareable, char *name) ...@@ -633,9 +655,8 @@ int xen_map_pirq_gsi(unsigned pirq, unsigned gsi, int shareable, char *name)
goto out; goto out;
} }
irq_info[irq] = mk_pirq_info(0, pirq, gsi, irq_op.vector); xen_irq_info_pirq_init(irq, 0, pirq, gsi, irq_op.vector,
irq_info[irq].u.pirq.flags |= shareable ? PIRQ_SHAREABLE : 0; shareable ? PIRQ_SHAREABLE : 0);
pirq_to_irq[pirq] = irq;
out: out:
spin_unlock(&irq_mapping_update_lock); spin_unlock(&irq_mapping_update_lock);
...@@ -672,8 +693,7 @@ int xen_bind_pirq_msi_to_irq(struct pci_dev *dev, struct msi_desc *msidesc, ...@@ -672,8 +693,7 @@ int xen_bind_pirq_msi_to_irq(struct pci_dev *dev, struct msi_desc *msidesc,
set_irq_chip_and_handler_name(irq, &xen_pirq_chip, set_irq_chip_and_handler_name(irq, &xen_pirq_chip,
handle_level_irq, name); handle_level_irq, name);
irq_info[irq] = mk_pirq_info(0, pirq, 0, vector); xen_irq_info_pirq_init(irq, 0, pirq, 0, vector, 0);
pirq_to_irq[pirq] = irq;
ret = irq_set_msi_desc(irq, msidesc); ret = irq_set_msi_desc(irq, msidesc);
if (ret < 0) if (ret < 0)
goto error_irq; goto error_irq;
...@@ -709,9 +729,6 @@ int xen_destroy_irq(int irq) ...@@ -709,9 +729,6 @@ int xen_destroy_irq(int irq)
goto out; goto out;
} }
} }
pirq_to_irq[info->u.pirq.pirq] = -1;
irq_info[irq] = mk_unbound_info();
xen_free_irq(irq); xen_free_irq(irq);
...@@ -720,19 +737,26 @@ int xen_destroy_irq(int irq) ...@@ -720,19 +737,26 @@ int xen_destroy_irq(int irq)
return rc; return rc;
} }
int xen_vector_from_irq(unsigned irq) int xen_irq_from_pirq(unsigned pirq)
{ {
return vector_from_irq(irq); int irq;
}
int xen_gsi_from_irq(unsigned irq) struct irq_info *info;
{
return gsi_from_irq(irq);
}
int xen_irq_from_pirq(unsigned pirq) spin_lock(&irq_mapping_update_lock);
{
return pirq_to_irq[pirq]; list_for_each_entry(info, &xen_irq_list_head, list) {
if (info == NULL || info->type != IRQT_PIRQ)
continue;
irq = info->irq;
if (info->u.pirq.pirq == pirq)
goto out;
}
irq = -1;
out:
spin_unlock(&irq_mapping_update_lock);
return irq;
} }
int bind_evtchn_to_irq(unsigned int evtchn) int bind_evtchn_to_irq(unsigned int evtchn)
...@@ -745,14 +769,16 @@ int bind_evtchn_to_irq(unsigned int evtchn) ...@@ -745,14 +769,16 @@ int bind_evtchn_to_irq(unsigned int evtchn)
if (irq == -1) { if (irq == -1) {
irq = xen_allocate_irq_dynamic(); irq = xen_allocate_irq_dynamic();
if (irq == -1)
goto out;
set_irq_chip_and_handler_name(irq, &xen_dynamic_chip, set_irq_chip_and_handler_name(irq, &xen_dynamic_chip,
handle_fasteoi_irq, "event"); handle_fasteoi_irq, "event");
evtchn_to_irq[evtchn] = irq; xen_irq_info_evtchn_init(irq, evtchn);
irq_info[irq] = mk_evtchn_info(evtchn);
} }
out:
spin_unlock(&irq_mapping_update_lock); spin_unlock(&irq_mapping_update_lock);
return irq; return irq;
...@@ -782,9 +808,7 @@ static int bind_ipi_to_irq(unsigned int ipi, unsigned int cpu) ...@@ -782,9 +808,7 @@ static int bind_ipi_to_irq(unsigned int ipi, unsigned int cpu)
BUG(); BUG();
evtchn = bind_ipi.port; evtchn = bind_ipi.port;
evtchn_to_irq[evtchn] = irq; xen_irq_info_ipi_init(cpu, irq, evtchn, ipi);
irq_info[irq] = mk_ipi_info(evtchn, ipi);
per_cpu(ipi_to_irq, cpu)[ipi] = irq;
bind_evtchn_to_cpu(evtchn, cpu); bind_evtchn_to_cpu(evtchn, cpu);
} }
...@@ -821,6 +845,8 @@ int bind_virq_to_irq(unsigned int virq, unsigned int cpu) ...@@ -821,6 +845,8 @@ int bind_virq_to_irq(unsigned int virq, unsigned int cpu)
if (irq == -1) { if (irq == -1) {
irq = xen_allocate_irq_dynamic(); irq = xen_allocate_irq_dynamic();
if (irq == -1)
goto out;
set_irq_chip_and_handler_name(irq, &xen_percpu_chip, set_irq_chip_and_handler_name(irq, &xen_percpu_chip,
handle_percpu_irq, "virq"); handle_percpu_irq, "virq");
...@@ -832,14 +858,12 @@ int bind_virq_to_irq(unsigned int virq, unsigned int cpu) ...@@ -832,14 +858,12 @@ int bind_virq_to_irq(unsigned int virq, unsigned int cpu)
BUG(); BUG();
evtchn = bind_virq.port; evtchn = bind_virq.port;
evtchn_to_irq[evtchn] = irq; xen_irq_info_virq_init(cpu, irq, evtchn, virq);
irq_info[irq] = mk_virq_info(evtchn, virq);
per_cpu(virq_to_irq, cpu)[virq] = irq;
bind_evtchn_to_cpu(evtchn, cpu); bind_evtchn_to_cpu(evtchn, cpu);
} }
out:
spin_unlock(&irq_mapping_update_lock); spin_unlock(&irq_mapping_update_lock);
return irq; return irq;
...@@ -876,11 +900,9 @@ static void unbind_from_irq(unsigned int irq) ...@@ -876,11 +900,9 @@ static void unbind_from_irq(unsigned int irq)
evtchn_to_irq[evtchn] = -1; evtchn_to_irq[evtchn] = -1;
} }
if (irq_info[irq].type != IRQT_UNBOUND) { BUG_ON(info_for_irq(irq)->type == IRQT_UNBOUND);
irq_info[irq] = mk_unbound_info();
xen_free_irq(irq); xen_free_irq(irq);
}
spin_unlock(&irq_mapping_update_lock); spin_unlock(&irq_mapping_update_lock);
} }
...@@ -894,6 +916,8 @@ int bind_evtchn_to_irqhandler(unsigned int evtchn, ...@@ -894,6 +916,8 @@ int bind_evtchn_to_irqhandler(unsigned int evtchn,
int retval; int retval;
irq = bind_evtchn_to_irq(evtchn); irq = bind_evtchn_to_irq(evtchn);
if (irq < 0)
return irq;
retval = request_irq(irq, handler, irqflags, devname, dev_id); retval = request_irq(irq, handler, irqflags, devname, dev_id);
if (retval != 0) { if (retval != 0) {
unbind_from_irq(irq); unbind_from_irq(irq);
...@@ -935,6 +959,8 @@ int bind_virq_to_irqhandler(unsigned int virq, unsigned int cpu, ...@@ -935,6 +959,8 @@ int bind_virq_to_irqhandler(unsigned int virq, unsigned int cpu,
int retval; int retval;
irq = bind_virq_to_irq(virq, cpu); irq = bind_virq_to_irq(virq, cpu);
if (irq < 0)
return irq;
retval = request_irq(irq, handler, irqflags, devname, dev_id); retval = request_irq(irq, handler, irqflags, devname, dev_id);
if (retval != 0) { if (retval != 0) {
unbind_from_irq(irq); unbind_from_irq(irq);
...@@ -986,7 +1012,7 @@ irqreturn_t xen_debug_interrupt(int irq, void *dev_id) ...@@ -986,7 +1012,7 @@ irqreturn_t xen_debug_interrupt(int irq, void *dev_id)
{ {
struct shared_info *sh = HYPERVISOR_shared_info; struct shared_info *sh = HYPERVISOR_shared_info;
int cpu = smp_processor_id(); int cpu = smp_processor_id();
unsigned long *cpu_evtchn = cpu_evtchn_mask(cpu); unsigned long *cpu_evtchn = per_cpu(cpu_evtchn_mask, cpu);
int i; int i;
unsigned long flags; unsigned long flags;
static DEFINE_SPINLOCK(debug_lock); static DEFINE_SPINLOCK(debug_lock);
...@@ -1064,6 +1090,13 @@ irqreturn_t xen_debug_interrupt(int irq, void *dev_id) ...@@ -1064,6 +1090,13 @@ irqreturn_t xen_debug_interrupt(int irq, void *dev_id)
} }
static DEFINE_PER_CPU(unsigned, xed_nesting_count); static DEFINE_PER_CPU(unsigned, xed_nesting_count);
static DEFINE_PER_CPU(unsigned int, current_word_idx);
static DEFINE_PER_CPU(unsigned int, current_bit_idx);
/*
* Mask out the i least significant bits of w
*/
#define MASK_LSBS(w, i) (w & ((~0UL) << i))
/* /*
* Search the CPUs pending events bitmasks. For each one found, map * Search the CPUs pending events bitmasks. For each one found, map
...@@ -1076,6 +1109,9 @@ static DEFINE_PER_CPU(unsigned, xed_nesting_count); ...@@ -1076,6 +1109,9 @@ static DEFINE_PER_CPU(unsigned, xed_nesting_count);
*/ */
static void __xen_evtchn_do_upcall(void) static void __xen_evtchn_do_upcall(void)
{ {
int start_word_idx, start_bit_idx;
int word_idx, bit_idx;
int i;
int cpu = get_cpu(); int cpu = get_cpu();
struct shared_info *s = HYPERVISOR_shared_info; struct shared_info *s = HYPERVISOR_shared_info;
struct vcpu_info *vcpu_info = __this_cpu_read(xen_vcpu); struct vcpu_info *vcpu_info = __this_cpu_read(xen_vcpu);
...@@ -1094,17 +1130,57 @@ static void __xen_evtchn_do_upcall(void) ...@@ -1094,17 +1130,57 @@ static void __xen_evtchn_do_upcall(void)
wmb(); wmb();
#endif #endif
pending_words = xchg(&vcpu_info->evtchn_pending_sel, 0); pending_words = xchg(&vcpu_info->evtchn_pending_sel, 0);
while (pending_words != 0) {
start_word_idx = __this_cpu_read(current_word_idx);
start_bit_idx = __this_cpu_read(current_bit_idx);
word_idx = start_word_idx;
for (i = 0; pending_words != 0; i++) {
unsigned long pending_bits; unsigned long pending_bits;
int word_idx = __ffs(pending_words); unsigned long words;
pending_words &= ~(1UL << word_idx);
while ((pending_bits = active_evtchns(cpu, s, word_idx)) != 0) { words = MASK_LSBS(pending_words, word_idx);
int bit_idx = __ffs(pending_bits);
int port = (word_idx * BITS_PER_LONG) + bit_idx; /*
int irq = evtchn_to_irq[port]; * If we masked out all events, wrap to beginning.
*/
if (words == 0) {
word_idx = 0;
bit_idx = 0;
continue;
}
word_idx = __ffs(words);
pending_bits = active_evtchns(cpu, s, word_idx);
bit_idx = 0; /* usually scan entire word from start */
if (word_idx == start_word_idx) {
/* We scan the starting word in two parts */
if (i == 0)
/* 1st time: start in the middle */
bit_idx = start_bit_idx;
else
/* 2nd time: mask bits done already */
bit_idx &= (1UL << start_bit_idx) - 1;
}
do {
unsigned long bits;
int port, irq;
struct irq_desc *desc; struct irq_desc *desc;
bits = MASK_LSBS(pending_bits, bit_idx);
/* If we masked out all events, move on. */
if (bits == 0)
break;
bit_idx = __ffs(bits);
/* Process port. */
port = (word_idx * BITS_PER_LONG) + bit_idx;
irq = evtchn_to_irq[port];
mask_evtchn(port); mask_evtchn(port);
clear_evtchn(port); clear_evtchn(port);
...@@ -1113,7 +1189,21 @@ static void __xen_evtchn_do_upcall(void) ...@@ -1113,7 +1189,21 @@ static void __xen_evtchn_do_upcall(void)
if (desc) if (desc)
generic_handle_irq_desc(irq, desc); generic_handle_irq_desc(irq, desc);
} }
}
bit_idx = (bit_idx + 1) % BITS_PER_LONG;
/* Next caller starts at last processed + 1 */
__this_cpu_write(current_word_idx,
bit_idx ? word_idx :
(word_idx+1) % BITS_PER_LONG);
__this_cpu_write(current_bit_idx, bit_idx);
} while (bit_idx != 0);
/* Scan start_l1i twice; all others once. */
if ((word_idx != start_word_idx) || (i != 0))
pending_words &= ~(1UL << word_idx);
word_idx = (word_idx + 1) % BITS_PER_LONG;
} }
BUG_ON(!irqs_disabled()); BUG_ON(!irqs_disabled());
...@@ -1163,8 +1253,7 @@ void rebind_evtchn_irq(int evtchn, int irq) ...@@ -1163,8 +1253,7 @@ void rebind_evtchn_irq(int evtchn, int irq)
so there should be a proper type */ so there should be a proper type */
BUG_ON(info->type == IRQT_UNBOUND); BUG_ON(info->type == IRQT_UNBOUND);
evtchn_to_irq[evtchn] = irq; xen_irq_info_evtchn_init(irq, evtchn);
irq_info[irq] = mk_evtchn_info(evtchn);
spin_unlock(&irq_mapping_update_lock); spin_unlock(&irq_mapping_update_lock);
...@@ -1181,10 +1270,14 @@ static int rebind_irq_to_cpu(unsigned irq, unsigned tcpu) ...@@ -1181,10 +1270,14 @@ static int rebind_irq_to_cpu(unsigned irq, unsigned tcpu)
struct evtchn_bind_vcpu bind_vcpu; struct evtchn_bind_vcpu bind_vcpu;
int evtchn = evtchn_from_irq(irq); int evtchn = evtchn_from_irq(irq);
/* events delivered via platform PCI interrupts are always if (!VALID_EVTCHN(evtchn))
* routed to vcpu 0 */ return -1;
if (!VALID_EVTCHN(evtchn) ||
(xen_hvm_domain() && !xen_have_vector_callback)) /*
* Events delivered via platform PCI interrupts are always
* routed to vcpu 0 and hence cannot be rebound.
*/
if (xen_hvm_domain() && !xen_have_vector_callback)
return -1; return -1;
/* Send future instances of this interrupt to other vcpu. */ /* Send future instances of this interrupt to other vcpu. */
...@@ -1271,19 +1364,22 @@ static int retrigger_dynirq(struct irq_data *data) ...@@ -1271,19 +1364,22 @@ static int retrigger_dynirq(struct irq_data *data)
return ret; return ret;
} }
static void restore_cpu_pirqs(void) static void restore_pirqs(void)
{ {
int pirq, rc, irq, gsi; int pirq, rc, irq, gsi;
struct physdev_map_pirq map_irq; struct physdev_map_pirq map_irq;
struct irq_info *info;
for (pirq = 0; pirq < nr_irqs; pirq++) { list_for_each_entry(info, &xen_irq_list_head, list) {
irq = pirq_to_irq[pirq]; if (info->type != IRQT_PIRQ)
if (irq == -1)
continue; continue;
pirq = info->u.pirq.pirq;
gsi = info->u.pirq.gsi;
irq = info->irq;
/* save/restore of PT devices doesn't work, so at this point the /* save/restore of PT devices doesn't work, so at this point the
* only devices present are GSI based emulated devices */ * only devices present are GSI based emulated devices */
gsi = gsi_from_irq(irq);
if (!gsi) if (!gsi)
continue; continue;
...@@ -1296,8 +1392,7 @@ static void restore_cpu_pirqs(void) ...@@ -1296,8 +1392,7 @@ static void restore_cpu_pirqs(void)
if (rc) { if (rc) {
printk(KERN_WARNING "xen map irq failed gsi=%d irq=%d pirq=%d rc=%d\n", printk(KERN_WARNING "xen map irq failed gsi=%d irq=%d pirq=%d rc=%d\n",
gsi, irq, pirq, rc); gsi, irq, pirq, rc);
irq_info[irq] = mk_unbound_info(); xen_free_irq(irq);
pirq_to_irq[pirq] = -1;
continue; continue;
} }
...@@ -1327,8 +1422,7 @@ static void restore_cpu_virqs(unsigned int cpu) ...@@ -1327,8 +1422,7 @@ static void restore_cpu_virqs(unsigned int cpu)
evtchn = bind_virq.port; evtchn = bind_virq.port;
/* Record the new mapping. */ /* Record the new mapping. */
evtchn_to_irq[evtchn] = irq; xen_irq_info_virq_init(cpu, irq, evtchn, virq);
irq_info[irq] = mk_virq_info(evtchn, virq);
bind_evtchn_to_cpu(evtchn, cpu); bind_evtchn_to_cpu(evtchn, cpu);
} }
} }
...@@ -1352,8 +1446,7 @@ static void restore_cpu_ipis(unsigned int cpu) ...@@ -1352,8 +1446,7 @@ static void restore_cpu_ipis(unsigned int cpu)
evtchn = bind_ipi.port; evtchn = bind_ipi.port;
/* Record the new mapping. */ /* Record the new mapping. */
evtchn_to_irq[evtchn] = irq; xen_irq_info_ipi_init(cpu, irq, evtchn, ipi);
irq_info[irq] = mk_ipi_info(evtchn, ipi);
bind_evtchn_to_cpu(evtchn, cpu); bind_evtchn_to_cpu(evtchn, cpu);
} }
} }
...@@ -1413,7 +1506,8 @@ void xen_poll_irq(int irq) ...@@ -1413,7 +1506,8 @@ void xen_poll_irq(int irq)
void xen_irq_resume(void) void xen_irq_resume(void)
{ {
unsigned int cpu, irq, evtchn; unsigned int cpu, evtchn;
struct irq_info *info;
init_evtchn_cpu_bindings(); init_evtchn_cpu_bindings();
...@@ -1422,8 +1516,8 @@ void xen_irq_resume(void) ...@@ -1422,8 +1516,8 @@ void xen_irq_resume(void)
mask_evtchn(evtchn); mask_evtchn(evtchn);
/* No IRQ <-> event-channel mappings. */ /* No IRQ <-> event-channel mappings. */
for (irq = 0; irq < nr_irqs; irq++) list_for_each_entry(info, &xen_irq_list_head, list)
irq_info[irq].evtchn = 0; /* zap event-channel binding */ info->evtchn = 0; /* zap event-channel binding */
for (evtchn = 0; evtchn < NR_EVENT_CHANNELS; evtchn++) for (evtchn = 0; evtchn < NR_EVENT_CHANNELS; evtchn++)
evtchn_to_irq[evtchn] = -1; evtchn_to_irq[evtchn] = -1;
...@@ -1433,7 +1527,7 @@ void xen_irq_resume(void) ...@@ -1433,7 +1527,7 @@ void xen_irq_resume(void)
restore_cpu_ipis(cpu); restore_cpu_ipis(cpu);
} }
restore_cpu_pirqs(); restore_pirqs();
} }
static struct irq_chip xen_dynamic_chip __read_mostly = { static struct irq_chip xen_dynamic_chip __read_mostly = {
...@@ -1519,17 +1613,6 @@ void __init xen_init_IRQ(void) ...@@ -1519,17 +1613,6 @@ void __init xen_init_IRQ(void)
{ {
int i; int i;
cpu_evtchn_mask_p = kcalloc(nr_cpu_ids, sizeof(struct cpu_evtchn_s),
GFP_KERNEL);
irq_info = kcalloc(nr_irqs, sizeof(*irq_info), GFP_KERNEL);
/* We are using nr_irqs as the maximum number of pirq available but
* that number is actually chosen by Xen and we don't know exactly
* what it is. Be careful choosing high pirq numbers. */
pirq_to_irq = kcalloc(nr_irqs, sizeof(*pirq_to_irq), GFP_KERNEL);
for (i = 0; i < nr_irqs; i++)
pirq_to_irq[i] = -1;
evtchn_to_irq = kcalloc(NR_EVENT_CHANNELS, sizeof(*evtchn_to_irq), evtchn_to_irq = kcalloc(NR_EVENT_CHANNELS, sizeof(*evtchn_to_irq),
GFP_KERNEL); GFP_KERNEL);
for (i = 0; i < NR_EVENT_CHANNELS; i++) for (i = 0; i < NR_EVENT_CHANNELS; i++)
......
...@@ -47,9 +47,9 @@ static inline void notify_remote_via_evtchn(int port) ...@@ -47,9 +47,9 @@ static inline void notify_remote_via_evtchn(int port)
(void)HYPERVISOR_event_channel_op(EVTCHNOP_send, &send); (void)HYPERVISOR_event_channel_op(EVTCHNOP_send, &send);
} }
extern void notify_remote_via_irq(int irq); void notify_remote_via_irq(int irq);
extern void xen_irq_resume(void); void xen_irq_resume(void);
/* Clear an irq's pending state, in preparation for polling on it */ /* Clear an irq's pending state, in preparation for polling on it */
void xen_clear_irq_pending(int irq); void xen_clear_irq_pending(int irq);
...@@ -68,20 +68,22 @@ void xen_poll_irq_timeout(int irq, u64 timeout); ...@@ -68,20 +68,22 @@ void xen_poll_irq_timeout(int irq, u64 timeout);
unsigned irq_from_evtchn(unsigned int evtchn); unsigned irq_from_evtchn(unsigned int evtchn);
/* Xen HVM evtchn vector callback */ /* Xen HVM evtchn vector callback */
extern void xen_hvm_callback_vector(void); void xen_hvm_callback_vector(void);
extern int xen_have_vector_callback; extern int xen_have_vector_callback;
int xen_set_callback_via(uint64_t via); int xen_set_callback_via(uint64_t via);
void xen_evtchn_do_upcall(struct pt_regs *regs); void xen_evtchn_do_upcall(struct pt_regs *regs);
void xen_hvm_evtchn_do_upcall(void); void xen_hvm_evtchn_do_upcall(void);
/* Allocate an irq for a physical interrupt, given a gsi. "Legacy" /* Allocate a pirq for a physical interrupt, given a gsi. */
* GSIs are identity mapped; others are dynamically allocated as int xen_allocate_pirq_gsi(unsigned gsi);
* usual. */ /* Bind a pirq for a physical interrupt to an irq. */
int xen_allocate_pirq(unsigned gsi, int shareable, char *name); int xen_bind_pirq_gsi_to_irq(unsigned gsi,
int xen_map_pirq_gsi(unsigned pirq, unsigned gsi, int shareable, char *name); unsigned pirq, int shareable, char *name);
#ifdef CONFIG_PCI_MSI #ifdef CONFIG_PCI_MSI
/* Allocate a pirq for a MSI style physical interrupt. */
int xen_allocate_pirq_msi(struct pci_dev *dev, struct msi_desc *msidesc); int xen_allocate_pirq_msi(struct pci_dev *dev, struct msi_desc *msidesc);
/* Bind an PSI pirq to an irq. */
int xen_bind_pirq_msi_to_irq(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, int vector, const char *name); int pirq, int vector, const char *name);
#endif #endif
...@@ -89,12 +91,6 @@ int xen_bind_pirq_msi_to_irq(struct pci_dev *dev, struct msi_desc *msidesc, ...@@ -89,12 +91,6 @@ int xen_bind_pirq_msi_to_irq(struct pci_dev *dev, struct msi_desc *msidesc,
/* De-allocates the above mentioned physical interrupt. */ /* De-allocates the above mentioned physical interrupt. */
int xen_destroy_irq(int irq); int xen_destroy_irq(int irq);
/* Return vector allocated to pirq */
int xen_vector_from_irq(unsigned pirq);
/* Return gsi allocated to pirq */
int xen_gsi_from_irq(unsigned pirq);
/* Return irq from pirq */ /* Return irq from pirq */
int xen_irq_from_pirq(unsigned pirq); int xen_irq_from_pirq(unsigned pirq);
......
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