blob: c75af3e665d08efffc93db87f4ad5099689cdf14 [file] [log] [blame]
Kevin O'Connorf54c1502008-06-14 15:56:16 -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'Connorff3651a2008-06-18 07:45:38 -04007#ifndef __PIC_H
8#define __PIC_H
Kevin O'Connorf54c1502008-06-14 15:56:16 -04009
10#include "ioport.h" // PORT_PIC*
Kevin O'Connorcc9e1bf2010-07-28 21:31:38 -040011#include "biosvar.h" // SET_IVT
Kevin O'Connorf54c1502008-06-14 15:56:16 -040012
13// PORT_PIC1 bitdefs
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)
19// PORT_PIC2 bitdefs
20#define PIC2_IRQ8 (1<<0)
21#define PIC2_IRQ12 (1<<4)
22#define PIC2_IRQ13 (1<<5)
23#define PIC2_IRQ14 (1<<6)
24
25static inline void
Kevin O'Connor1ca05b02010-01-03 17:43:37 -050026eoi_pic1(void)
Kevin O'Connorf54c1502008-06-14 15:56:16 -040027{
28 // Send eoi (select OCW2 + eoi)
29 outb(0x20, PORT_PIC1_CMD);
30}
31
32static inline void
Kevin O'Connor1ca05b02010-01-03 17:43:37 -050033eoi_pic2(void)
Kevin O'Connorf54c1502008-06-14 15:56:16 -040034{
35 // Send eoi (select OCW2 + eoi)
36 outb(0x20, PORT_PIC2_CMD);
37 eoi_pic1();
38}
39
40static inline void
41unmask_pic1(u8 irq)
42{
43 outb(inb(PORT_PIC1_DATA) & ~irq, PORT_PIC1_DATA);
44}
45
46static inline void
47unmask_pic2(u8 irq)
48{
49 outb(inb(PORT_PIC2_DATA) & ~irq, PORT_PIC2_DATA);
50}
51
Kevin O'Connorc541e1b2008-06-21 12:24:14 -040052static inline void
53mask_pic1(u8 irq)
54{
55 outb(inb(PORT_PIC1_DATA) | irq, PORT_PIC1_DATA);
56}
57
58static inline void
59mask_pic2(u8 irq)
60{
61 outb(inb(PORT_PIC2_DATA) | irq, PORT_PIC2_DATA);
62}
63
Kevin O'Connorf54c1502008-06-14 15:56:16 -040064static inline u8
Kevin O'Connor1ca05b02010-01-03 17:43:37 -050065get_pic1_isr(void)
Kevin O'Connorf54c1502008-06-14 15:56:16 -040066{
67 // 0x0b == select OCW1 + read ISR
68 outb(0x0b, PORT_PIC1_CMD);
69 return inb(PORT_PIC1_CMD);
70}
71
Kevin O'Connorc541e1b2008-06-21 12:24:14 -040072static inline u8
Kevin O'Connor1ca05b02010-01-03 17:43:37 -050073get_pic2_isr(void)
Kevin O'Connorf54c1502008-06-14 15:56:16 -040074{
Kevin O'Connorc541e1b2008-06-21 12:24:14 -040075 // 0x0b == select OCW1 + read ISR
76 outb(0x0b, PORT_PIC2_CMD);
77 return inb(PORT_PIC2_CMD);
Kevin O'Connorf54c1502008-06-14 15:56:16 -040078}
Kevin O'Connorff3651a2008-06-18 07:45:38 -040079
Kevin O'Connord21c0892008-11-26 17:02:43 -050080static inline void
Kevin O'Connorcc9e1bf2010-07-28 21:31:38 -040081enable_hwirq(int hwirq, struct segoff_s func)
Kevin O'Connord21c0892008-11-26 17:02:43 -050082{
83 int vector;
84 if (hwirq < 8) {
85 unmask_pic1(1 << hwirq);
86 vector = 0x08 + hwirq;
87 } else {
88 unmask_pic2(1 << (hwirq - 8));
89 vector = 0x70 + hwirq - 8;
90 }
Kevin O'Connorcc9e1bf2010-07-28 21:31:38 -040091 SET_IVT(vector, func);
Kevin O'Connord21c0892008-11-26 17:02:43 -050092}
93
Kevin O'Connor643062f2010-01-04 20:48:20 -050094void set_pics(u8 irq0, u8 irq8);
Kevin O'Connor1ca05b02010-01-03 17:43:37 -050095void pic_setup(void);
Kevin O'Connorc541e1b2008-06-21 12:24:14 -040096
Kevin O'Connorff3651a2008-06-18 07:45:38 -040097#endif // pic.h