Skip to content

Commit

Permalink
xen/irq: Cleanup the find_unbound_irq
Browse files Browse the repository at this point in the history
The "find_unbound_irq" is a bit unusual - it allocates
virtual IRQ (event channels) in reverse order. This means
starting at the "top" of the available IRQs (nr_irqs) down
to the GSI/MSI IRQs (nr_irqs_gsi). Lets document this and
also make the variables easier to understand.

Signed-off-by: Konrad Rzeszutek Wilk <[email protected]>
  • Loading branch information
konradwilk committed Dec 9, 2010
1 parent cf7d7e5 commit d1b758e
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions drivers/xen/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,15 +405,21 @@ static int find_unbound_irq(void)
{
struct irq_data *data;
int irq, res;
int start = get_nr_hw_irqs();
int bottom = get_nr_hw_irqs();
int top = nr_irqs-1;

if (start == nr_irqs)
if (bottom == nr_irqs)
goto no_irqs;

/* nr_irqs is a magic value. Must not use it.*/
for (irq = nr_irqs-1; irq > start; irq--) {
/* This loop starts from the top of IRQ space and goes down.
* We need this b/c if we have a PCI device in a Xen PV guest
* we do not have an IO-APIC (though the backend might have them)
* mapped in. To not have a collision of physical IRQs with the Xen
* event channels start at the top of the IRQ space for virtual IRQs.
*/
for (irq = top; irq > bottom; irq--) {
data = irq_get_irq_data(irq);
/* only 0->15 have init'd desc; handle irq > 16 */
/* only 15->0 have init'd desc; handle irq > 16 */
if (!data)
break;
if (data->chip == &no_irq_chip)
Expand All @@ -424,7 +430,7 @@ static int find_unbound_irq(void)
return irq;
}

if (irq == start)
if (irq == bottom)
goto no_irqs;

res = irq_alloc_desc_at(irq, -1);
Expand Down

0 comments on commit d1b758e

Please sign in to comment.