00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00035 #include <arch/drivers/i8259.h>
00036 #include <cpu.h>
00037 #include <arch/types.h>
00038 #include <arch/asm.h>
00039 #include <arch.h>
00040 #include <print.h>
00041 #include <interrupt.h>
00042
00043
00044
00045
00046
00047
00048 static void pic_spurious(int n, istate_t *istate);
00049
00050 void i8259_init(void)
00051 {
00052
00053 outb(PIC_PIC0PORT1, PIC_ICW1 | PIC_NEEDICW4);
00054
00055
00056 outb(PIC_PIC0PORT2, IVT_IRQBASE);
00057
00058
00059 outb(PIC_PIC0PORT2, 1 << IRQ_PIC1);
00060
00061
00062 outb(PIC_PIC0PORT2, 1);
00063
00064
00065 outb(PIC_PIC1PORT1, PIC_ICW1 | PIC_NEEDICW4);
00066
00067
00068 outb(PIC_PIC1PORT2, IVT_IRQBASE + 8);
00069
00070
00071 outb(PIC_PIC1PORT2, IRQ_PIC1);
00072
00073
00074 outb(PIC_PIC1PORT2, 1);
00075
00076
00077
00078
00079 exc_register(VECTOR_PIC_SPUR, "pic_spurious", (iroutine) pic_spurious);
00080
00081
00082
00083
00084
00085 enable_irqs_function = pic_enable_irqs;
00086 disable_irqs_function = pic_disable_irqs;
00087 eoi_function = pic_eoi;
00088
00089 pic_disable_irqs(0xffff);
00090 pic_enable_irqs(1<<IRQ_PIC1);
00091 }
00092
00093 void pic_enable_irqs(__u16 irqmask)
00094 {
00095 __u8 x;
00096
00097 if (irqmask & 0xff) {
00098 x = inb(PIC_PIC0PORT2);
00099 outb(PIC_PIC0PORT2, x & (~(irqmask & 0xff)));
00100 }
00101 if (irqmask >> 8) {
00102 x = inb(PIC_PIC1PORT2);
00103 outb(PIC_PIC1PORT2, x & (~(irqmask >> 8)));
00104 }
00105 }
00106
00107 void pic_disable_irqs(__u16 irqmask)
00108 {
00109 __u8 x;
00110
00111 if (irqmask & 0xff) {
00112 x = inb(PIC_PIC0PORT2);
00113 outb(PIC_PIC0PORT2, x | (irqmask & 0xff));
00114 }
00115 if (irqmask >> 8) {
00116 x = inb(PIC_PIC1PORT2);
00117 outb(PIC_PIC1PORT2, x | (irqmask >> 8));
00118 }
00119 }
00120
00121 void pic_eoi(void)
00122 {
00123 outb(0x20,0x20);
00124 outb(0xa0,0x20);
00125 }
00126
00127 void pic_spurious(int n, istate_t *istate)
00128 {
00129 #ifdef CONFIG_DEBUG
00130 printf("cpu%d: PIC spurious interrupt\n", CPU->id);
00131 #endif
00132 }
00133