plan 9 kernel history: overview | file list | diff list

1998/0910/pc/i8259.c (diff list | history)

1998/0320/sys/src/9/pc/i8259.c:27,461998/0910/sys/src/9/pc/i8259.c:27,47 (short | long | prev | next)
XXX bug fix?: add i8259lock. Change Vector* to Irq*.
rsc Fri Mar 4 12:44:25 2005
1997/0327    
 
static int int0mask;			/* interrupts enabled for first 8259 */ 
static int int1mask;			/* interrupts enabled for second 8259 */ 
1998/0910    
static int elcr;			/* mask of level-triggered interrupts */ 
static Lock i8259lock; 
1997/0327    
 
int elcr;				/* mask of level-triggered interrupts */ 
                 
void 
i8259init(void) 
{ 
	int elcr1; 
 
1998/0910    
	ilock(&i8259lock); 
1997/0327    
	int0mask = 0xFF; 
	int1mask = 0xFF; 
 
	/* 
	 *  Set up the first 8259 interrupt processor. 
	 *  Make 8259 interrupts start at CPU vector Int0vec. 
1998/0910    
	 *  Make 8259 interrupts start at CPU vector VectorPIC. 
1997/0327    
	 *  Set the 8259 as master with edge triggered 
	 *  input with fully nested interrupts. 
	 */ 
1998/0320/sys/src/9/pc/i8259.c:91,1491998/0910/sys/src/9/pc/i8259.c:92,158
1997/0327    
			elcr = (inb(Elcr2)<<8)|elcr1; 
	} 
	outb(Elcr1, elcr1); 
1998/0910    
	iunlock(&i8259lock); 
1997/0521    
//	if(elcr) 
//		print("ELCR: %4.4uX\n", elcr); 
1997/0327    
} 
 
int 
i8259isr(int v) 
1998/0910    
i8259isr(int vno) 
1997/0327    
{ 
	int isr; 
 
1998/0910    
	if(vno < VectorPIC || vno > VectorPIC+MaxIrqPIC) 
		return 0; 
 
1997/0327    
	/* 
	 *  tell the 8259 that we're done with the 
	 *  highest level interrupt (interrupts are still 
	 *  off at this point) 
	 */ 
	isr = 0; 
	if(v >= VectorPIC && v <= MaxVectorPIC){ 
		isr = inb(Int0ctl); 
		outb(Int0ctl, EOI); 
		if(v >= VectorPIC+8){ 
			isr |= inb(Int1ctl)<<8; 
			outb(Int1ctl, EOI); 
		} 
1998/0910    
	ilock(&i8259lock); 
	isr = inb(Int0ctl); 
	outb(Int0ctl, EOI); 
	if(vno >= VectorPIC+8){ 
		isr |= inb(Int1ctl)<<8; 
		outb(Int1ctl, EOI); 
1997/0327    
	} 
1998/0910    
	iunlock(&i8259lock); 
1997/0327    
 
	return isr & (1<<(v-VectorPIC)); 
1998/0910    
	return isr & (1<<(vno-VectorPIC)); 
1997/0327    
} 
 
int 
i8259enable(int v, int, Irqctl* irqctl) 
1998/0910    
i8259enable(Vctl* v) 
1997/0327    
{ 
1998/0320    
	if(v < VectorPIC || v > MaxVectorPIC){ 
		print("i8259enable: vector %d out of range\n", v); 
		return -1; 
	} 
1997/0327    
	v -= VectorPIC; 
1998/0910    
	int irq; 
1997/0327    
 
	/* 
	 *  enable corresponding interrupt in 8259 
1998/0910    
	 * Given an IRQ, enable the corresponding interrupt in the i8259 
	 * and return the vector to be used. The i8259 is set to use a fixed 
	 * range of vectors starting at VectorPIC. 
1997/0327    
	 */ 
	if(v < 8){ 
		int0mask &= ~(1<<v); 
1998/0910    
	irq = v->irq; 
	if(irq < 0 || irq > MaxIrqPIC){ 
		print("i8259enable: irq %d out of range\n", irq); 
		return -1; 
	} 
 
	ilock(&i8259lock); 
	if(irq < 8){ 
		int0mask &= ~(1<<irq); 
1997/0327    
		outb(Int0aux, int0mask); 
	} 
	else{ 
		int1mask &= ~(1<<(v-8)); 
1998/0910    
		int1mask &= ~(1<<(irq-8)); 
1997/0327    
		outb(Int1aux, int1mask); 
	} 
 
	if(elcr & (1<<v)) 
		irqctl->eoi = i8259isr; 
1998/0910    
	if(elcr & (1<<irq)) 
		v->eoi = i8259isr; 
1997/0327    
	else 
		irqctl->isr = i8259isr; 
	irqctl->isintr = 1; 
1998/0910    
		v->isr = i8259isr; 
	iunlock(&i8259lock); 
1997/0327    
 
	return v; 
1998/0910    
	return VectorPIC+irq; 
1997/0327    
} 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)