1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33#include <common.h>
34#include <asm/io.h>
35#include <asm/i8259.h>
36#include <asm/ibmpc.h>
37#include <asm/interrupt.h>
38
39#if CONFIG_SYS_NUM_IRQS != 16
40#error "CONFIG_SYS_NUM_IRQS must equal 16 if CONFIG_SYS_NUM_IRQS is defined"
41#endif
42
43int interrupt_init(void)
44{
45 u8 i;
46
47 disable_interrupts();
48
49
50 outb(0xff, MASTER_PIC + IMR);
51 outb(0xff, SLAVE_PIC + IMR);
52
53
54
55
56 outb(ICW1_SEL|ICW1_EICW4, MASTER_PIC + ICW1);
57 outb(0x20, MASTER_PIC + ICW2);
58 outb(IR2, MASTER_PIC + ICW3);
59 outb(ICW4_PM, MASTER_PIC + ICW4);
60
61 for (i = 0; i < 8; i++)
62 outb(OCW2_SEOI | i, MASTER_PIC + OCW2);
63
64
65
66
67 outb(ICW1_SEL|ICW1_EICW4, SLAVE_PIC + ICW1);
68 outb(0x28, SLAVE_PIC + ICW2);
69 outb(0x02, SLAVE_PIC + ICW3);
70 outb(ICW4_PM, SLAVE_PIC + ICW4);
71
72 for (i = 0; i < 8; i++)
73 outb(OCW2_SEOI | i, SLAVE_PIC + OCW2);
74
75
76
77
78
79 unmask_irq(2);
80
81 enable_interrupts();
82
83 return 0;
84}
85
86void mask_irq(int irq)
87{
88 int imr_port;
89
90 if (irq >= CONFIG_SYS_NUM_IRQS)
91 return;
92
93 if (irq > 7)
94 imr_port = SLAVE_PIC + IMR;
95 else
96 imr_port = MASTER_PIC + IMR;
97
98 outb(inb(imr_port) | (1 << (irq & 7)), imr_port);
99}
100
101void unmask_irq(int irq)
102{
103 int imr_port;
104
105 if (irq >= CONFIG_SYS_NUM_IRQS)
106 return;
107
108 if (irq > 7)
109 imr_port = SLAVE_PIC + IMR;
110 else
111 imr_port = MASTER_PIC + IMR;
112
113 outb(inb(imr_port) & ~(1 << (irq & 7)), imr_port);
114}
115
116void specific_eoi(int irq)
117{
118 if (irq >= CONFIG_SYS_NUM_IRQS)
119 return;
120
121 if (irq > 7) {
122
123
124
125
126
127 outb(OCW2_SEOI | (irq & 7), SLAVE_PIC + OCW2);
128 irq = SEOI_IR2;
129 }
130
131 outb(OCW2_SEOI | irq, MASTER_PIC + OCW2);
132}
133