1 // Helpers for working with i8259 interrupt controller.
3 // Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
4 // Copyright (C) 2002 MandrakeSoft S.A.
6 // This file may be distributed under the terms of the GNU LGPLv3 license.
10 #include "ioport.h" // PORT_PIC*
11 #include "biosvar.h" // SET_IVT
14 #define PIC1_IRQ0 (1<<0)
15 #define PIC1_IRQ1 (1<<1)
16 #define PIC1_IRQ2 (1<<2)
17 #define PIC1_IRQ5 (1<<5)
18 #define PIC1_IRQ6 (1<<6)
20 #define PIC2_IRQ8 (1<<0)
21 #define PIC2_IRQ12 (1<<4)
22 #define PIC2_IRQ13 (1<<5)
23 #define PIC2_IRQ14 (1<<6)
28 // Send eoi (select OCW2 + eoi)
29 outb(0x20, PORT_PIC1_CMD);
35 // Send eoi (select OCW2 + eoi)
36 outb(0x20, PORT_PIC2_CMD);
43 outb(inb(PORT_PIC1_DATA) & ~irq, PORT_PIC1_DATA);
49 outb(inb(PORT_PIC2_DATA) & ~irq, PORT_PIC2_DATA);
55 outb(inb(PORT_PIC1_DATA) | irq, PORT_PIC1_DATA);
61 outb(inb(PORT_PIC2_DATA) | irq, PORT_PIC2_DATA);
67 // 0x0b == select OCW1 + read ISR
68 outb(0x0b, PORT_PIC1_CMD);
69 return inb(PORT_PIC1_CMD);
75 // 0x0b == select OCW1 + read ISR
76 outb(0x0b, PORT_PIC2_CMD);
77 return inb(PORT_PIC2_CMD);
81 enable_hwirq(int hwirq, struct segoff_s func)
85 unmask_pic1(1 << hwirq);
86 vector = 0x08 + hwirq;
88 unmask_pic2(1 << (hwirq - 8));
89 vector = 0x70 + hwirq - 8;
91 SET_IVT(vector, func);
94 void set_pics(u8 irq0, u8 irq8);