From 2e1fcabe9ee43afebf096cc0044fff06b5867b06 Mon Sep 17 00:00:00 2001 From: aiju Date: Mon, 16 May 2011 01:28:41 +0000 Subject: [PATCH 1/2] improved interrupt vector allocation code --- sys/src/9/pc/mp.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/sys/src/9/pc/mp.c b/sys/src/9/pc/mp.c index 77ac729ec..9aff6ebe5 100644 --- a/sys/src/9/pc/mp.c +++ b/sys/src/9/pc/mp.c @@ -705,6 +705,24 @@ mpintrcpu(void) return mpapic[i].apicno; } +/* hardcoded VectorAPIC and stuff. bad. */ +static int +allocvector(void) +{ + static int round = 0, num = 1; + static Lock l; + int vno; + + lock(&l); + if(num >= 24) { + if(++round >= 8) round = 0; + num = 1; + } + vno = 64 + num++ * 8 + round; + unlock(&l); + return vno; +} + static int mpintrenablex(Vctl* v, int tbdf) { @@ -806,13 +824,7 @@ mpintrenablex(Vctl* v, int tbdf) * vector regardless of whether the devices on that pin use * the same IRQ as devices on another pin. */ - vno = VectorAPIC + (incref(&mpvnoref)-1)*8; -//print("%s vector %d (imask)\n", v->name, vno); - if(vno > MaxVectorAPIC){ - print("mpintrenable: vno %d, irq %d, tbdf %uX\n", - vno, v->irq, tbdf); - return -1; - } + vno = allocvector(); hi = mpintrcpu()<<24; lo = mpintrinit(bus, aintr->intr, vno, v->irq); //print("lo 0x%uX: busno %d intr %d vno %d irq %d elcr 0x%uX\n", @@ -869,11 +881,7 @@ msiintrenable(Vctl *v) break; } - vno = VectorAPIC + (incref(&mpvnoref)-1)*8; - if(vno > MaxVectorAPIC) { - print("msiintrenable: vno %d\n", vno); - return -1; - } + vno = allocvector(); cpu = mpintrcpu(); pcicfgw32(pci, cap + MSIAddr, (0xFEE << 20) | (cpu << 12)); pcicfgw32(pci, cap + MSIAddr + 4, 0); From 78a02732e32e2fd9e886b920f5ea63f52bd3c0b9 Mon Sep 17 00:00:00 2001 From: aiju Date: Mon, 16 May 2011 01:39:59 +0000 Subject: [PATCH 2/2] removed stale variable --- sys/src/9/pc/mp.c | 1 - 1 file changed, 1 deletion(-) diff --git a/sys/src/9/pc/mp.c b/sys/src/9/pc/mp.c index 9aff6ebe5..5bf687dd0 100644 --- a/sys/src/9/pc/mp.c +++ b/sys/src/9/pc/mp.c @@ -17,7 +17,6 @@ static int mpeisabus = -1; extern int i8259elcr; /* mask of level-triggered interrupts */ static Apic mpapic[MaxAPICNO+1]; static int machno2apicno[MaxAPICNO+1]; /* inverse map: machno -> APIC ID */ -static Ref mpvnoref; /* unique vector assignment */ static int mpmachno = 1; static Lock mpphysidlock; static int mpphysid;