blob: 8992a8b576f79292a469cb63b6bea8b96058ffd5 [file] [log] [blame]
Kevin O'Connorc541e1b2008-06-21 12:24:14 -04001// 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'Connorb1b7c2a2009-01-15 20:52:58 -05006// This file may be distributed under the terms of the GNU LGPLv3 license.
Kevin O'Connorc541e1b2008-06-21 12:24:14 -04007
Kevin O'Connor9521e262008-07-04 13:04:29 -04008#include "pic.h" // get_pic1_isr
9#include "util.h" // dprintf
10#include "config.h" // CONFIG_*
Kevin O'Connorc541e1b2008-06-21 12:24:14 -040011
12void
Kevin O'Connor643062f2010-01-04 20:48:20 -050013set_pics(u8 irq0, u8 irq8)
Kevin O'Connorc541e1b2008-06-21 12:24:14 -040014{
Kevin O'Connorc541e1b2008-06-21 12:24:14 -040015 // Send ICW1 (select OCW1 + will send ICW4)
16 outb(0x11, PORT_PIC1_CMD);
17 outb(0x11, PORT_PIC2_CMD);
Kevin O'Connor65e63422008-07-19 14:12:32 -040018 // Send ICW2 (base irqs: 0x08-0x0f for irq0-7, 0x70-0x77 for irq8-15)
Kevin O'Connor643062f2010-01-04 20:48:20 -050019 outb(irq0, PORT_PIC1_DATA);
20 outb(irq8, PORT_PIC2_DATA);
Kevin O'Connorc541e1b2008-06-21 12:24:14 -040021 // 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'Connor643062f2010-01-04 20:48:20 -050032void
33pic_setup(void)
34{
35 dprintf(3, "init pic\n");
36 set_pics(0x08, 0x70);
37}
38
Kevin O'Connorc541e1b2008-06-21 12:24:14 -040039// Handler for otherwise unused hardware irqs.
40void VISIBLE16
Kevin O'Connorffdc9ee2008-12-20 13:10:00 -050041handle_hwpic1(struct bregs *regs)
Kevin O'Connorc541e1b2008-06-21 12:24:14 -040042{
Kevin O'Connoreac894d2009-02-05 21:23:39 -050043 dprintf(DEBUG_ISR_hwpic1, "handle_hwpic1 irq=%x\n", get_pic1_isr());
Kevin O'Connorffdc9ee2008-12-20 13:10:00 -050044 eoi_pic1();
45}
Kevin O'Connorc541e1b2008-06-21 12:24:14 -040046
Kevin O'Connorffdc9ee2008-12-20 13:10:00 -050047void VISIBLE16
48handle_hwpic2(struct bregs *regs)
49{
Kevin O'Connoreac894d2009-02-05 21:23:39 -050050 dprintf(DEBUG_ISR_hwpic2, "handle_hwpic2 irq=%x\n", get_pic2_isr());
Kevin O'Connorffdc9ee2008-12-20 13:10:00 -050051 eoi_pic2();
Kevin O'Connorc541e1b2008-06-21 12:24:14 -040052}