Kevin O'Connor | c541e1b | 2008-06-21 12:24:14 -0400 | [diff] [blame] | 1 | // Helpers for working with i8259 interrupt controller. |
| 2 | // |
| 3 | // Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net> |
| 4 | // Copyright (C) 2002 MandrakeSoft S.A. |
| 5 | // |
Kevin O'Connor | b1b7c2a | 2009-01-15 20:52:58 -0500 | [diff] [blame] | 6 | // This file may be distributed under the terms of the GNU LGPLv3 license. |
Kevin O'Connor | c541e1b | 2008-06-21 12:24:14 -0400 | [diff] [blame] | 7 | |
Kevin O'Connor | 9521e26 | 2008-07-04 13:04:29 -0400 | [diff] [blame] | 8 | #include "pic.h" // get_pic1_isr |
| 9 | #include "util.h" // dprintf |
| 10 | #include "config.h" // CONFIG_* |
Kevin O'Connor | c541e1b | 2008-06-21 12:24:14 -0400 | [diff] [blame] | 11 | |
| 12 | void |
Kevin O'Connor | 643062f | 2010-01-04 20:48:20 -0500 | [diff] [blame] | 13 | set_pics(u8 irq0, u8 irq8) |
Kevin O'Connor | c541e1b | 2008-06-21 12:24:14 -0400 | [diff] [blame] | 14 | { |
Kevin O'Connor | c541e1b | 2008-06-21 12:24:14 -0400 | [diff] [blame] | 15 | // Send ICW1 (select OCW1 + will send ICW4) |
| 16 | outb(0x11, PORT_PIC1_CMD); |
| 17 | outb(0x11, PORT_PIC2_CMD); |
Kevin O'Connor | 65e6342 | 2008-07-19 14:12:32 -0400 | [diff] [blame] | 18 | // Send ICW2 (base irqs: 0x08-0x0f for irq0-7, 0x70-0x77 for irq8-15) |
Kevin O'Connor | 643062f | 2010-01-04 20:48:20 -0500 | [diff] [blame] | 19 | outb(irq0, PORT_PIC1_DATA); |
| 20 | outb(irq8, PORT_PIC2_DATA); |
Kevin O'Connor | c541e1b | 2008-06-21 12:24:14 -0400 | [diff] [blame] | 21 | // Send ICW3 (cascaded pic ids) |
| 22 | outb(0x04, PORT_PIC1_DATA); |
| 23 | outb(0x02, PORT_PIC2_DATA); |
| 24 | // Send ICW4 (enable 8086 mode) |
| 25 | outb(0x01, PORT_PIC1_DATA); |
| 26 | outb(0x01, PORT_PIC2_DATA); |
| 27 | // Mask all irqs (except cascaded PIC2 irq) |
| 28 | outb(~PIC1_IRQ2, PORT_PIC1_DATA); |
| 29 | outb(~0, PORT_PIC2_DATA); |
| 30 | } |
| 31 | |
Kevin O'Connor | 643062f | 2010-01-04 20:48:20 -0500 | [diff] [blame] | 32 | void |
| 33 | pic_setup(void) |
| 34 | { |
| 35 | dprintf(3, "init pic\n"); |
| 36 | set_pics(0x08, 0x70); |
| 37 | } |
| 38 | |
Kevin O'Connor | c541e1b | 2008-06-21 12:24:14 -0400 | [diff] [blame] | 39 | // Handler for otherwise unused hardware irqs. |
| 40 | void VISIBLE16 |
Kevin O'Connor | ffdc9ee | 2008-12-20 13:10:00 -0500 | [diff] [blame] | 41 | handle_hwpic1(struct bregs *regs) |
Kevin O'Connor | c541e1b | 2008-06-21 12:24:14 -0400 | [diff] [blame] | 42 | { |
Kevin O'Connor | eac894d | 2009-02-05 21:23:39 -0500 | [diff] [blame] | 43 | dprintf(DEBUG_ISR_hwpic1, "handle_hwpic1 irq=%x\n", get_pic1_isr()); |
Kevin O'Connor | ffdc9ee | 2008-12-20 13:10:00 -0500 | [diff] [blame] | 44 | eoi_pic1(); |
| 45 | } |
Kevin O'Connor | c541e1b | 2008-06-21 12:24:14 -0400 | [diff] [blame] | 46 | |
Kevin O'Connor | ffdc9ee | 2008-12-20 13:10:00 -0500 | [diff] [blame] | 47 | void VISIBLE16 |
| 48 | handle_hwpic2(struct bregs *regs) |
| 49 | { |
Kevin O'Connor | eac894d | 2009-02-05 21:23:39 -0500 | [diff] [blame] | 50 | dprintf(DEBUG_ISR_hwpic2, "handle_hwpic2 irq=%x\n", get_pic2_isr()); |
Kevin O'Connor | ffdc9ee | 2008-12-20 13:10:00 -0500 | [diff] [blame] | 51 | eoi_pic2(); |
Kevin O'Connor | c541e1b | 2008-06-21 12:24:14 -0400 | [diff] [blame] | 52 | } |