This source file includes following definitions.
- disable_irq
- enable_irq
- do_bottom_half
- get_irq_list
- do_IRQ
- do_fast_IRQ
- irqaction
- request_irq
- free_irq
- math_error_irq
- no_action
- init_IRQ
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 #include <linux/ptrace.h>
26 #include <linux/errno.h>
27 #include <linux/kernel_stat.h>
28 #include <linux/signal.h>
29 #include <linux/sched.h>
30 #include <linux/interrupt.h>
31
32 #include <asm/system.h>
33 #include <asm/io.h>
34 #include <asm/irq.h>
35
36 #define CR0_NE 32
37
38 static unsigned char cache_21 = 0xff;
39 static unsigned char cache_A1 = 0xff;
40
41 unsigned long intr_count = 0;
42 unsigned long bh_active = 0;
43 unsigned long bh_mask = 0xFFFFFFFF;
44 struct bh_struct bh_base[32];
45
46 void disable_irq(unsigned int irq_nr)
47 {
48 unsigned long flags;
49 unsigned char mask;
50
51 mask = 1 << (irq_nr & 7);
52 save_flags(flags);
53 if (irq_nr < 8) {
54 cli();
55 cache_21 |= mask;
56 outb(cache_21,0x21);
57 restore_flags(flags);
58 return;
59 }
60 cli();
61 cache_A1 |= mask;
62 outb(cache_A1,0xA1);
63 restore_flags(flags);
64 }
65
66 void enable_irq(unsigned int irq_nr)
67 {
68 unsigned long flags;
69 unsigned char mask;
70
71 mask = ~(1 << (irq_nr & 7));
72 save_flags(flags);
73 if (irq_nr < 8) {
74 cli();
75 cache_21 &= mask;
76 outb(cache_21,0x21);
77 restore_flags(flags);
78 return;
79 }
80 cli();
81 cache_A1 &= mask;
82 outb(cache_A1,0xA1);
83 restore_flags(flags);
84 }
85
86
87
88
89
90
91 asmlinkage void do_bottom_half(void)
92 {
93 unsigned long active;
94 unsigned long mask, left;
95 struct bh_struct *bh;
96
97 bh = bh_base;
98 active = bh_active & bh_mask;
99 for (mask = 1, left = ~0 ; left & active ; bh++,mask += mask,left += left) {
100 if (mask & active) {
101 void (*fn)(void *);
102 bh_active &= ~mask;
103 fn = bh->routine;
104 if (!fn)
105 goto bad_bh;
106 fn(bh->data);
107 }
108 }
109 return;
110 bad_bh:
111 printk ("irq.c:bad bottom half entry\n");
112 }
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129 BUILD_IRQ(FIRST,0,0x01)
130 BUILD_IRQ(FIRST,1,0x02)
131 BUILD_IRQ(FIRST,2,0x04)
132 BUILD_IRQ(FIRST,3,0x08)
133 BUILD_IRQ(FIRST,4,0x10)
134 BUILD_IRQ(FIRST,5,0x20)
135 BUILD_IRQ(FIRST,6,0x40)
136 BUILD_IRQ(FIRST,7,0x80)
137 BUILD_IRQ(SECOND,8,0x01)
138 BUILD_IRQ(SECOND,9,0x02)
139 BUILD_IRQ(SECOND,10,0x04)
140 BUILD_IRQ(SECOND,11,0x08)
141 BUILD_IRQ(SECOND,12,0x10)
142 BUILD_IRQ(SECOND,13,0x20)
143 BUILD_IRQ(SECOND,14,0x40)
144 BUILD_IRQ(SECOND,15,0x80)
145
146
147
148
149
150 static void (*interrupt[16])(void) = {
151 IRQ0_interrupt, IRQ1_interrupt, IRQ2_interrupt, IRQ3_interrupt,
152 IRQ4_interrupt, IRQ5_interrupt, IRQ6_interrupt, IRQ7_interrupt,
153 IRQ8_interrupt, IRQ9_interrupt, IRQ10_interrupt, IRQ11_interrupt,
154 IRQ12_interrupt, IRQ13_interrupt, IRQ14_interrupt, IRQ15_interrupt
155 };
156
157 static void (*fast_interrupt[16])(void) = {
158 fast_IRQ0_interrupt, fast_IRQ1_interrupt,
159 fast_IRQ2_interrupt, fast_IRQ3_interrupt,
160 fast_IRQ4_interrupt, fast_IRQ5_interrupt,
161 fast_IRQ6_interrupt, fast_IRQ7_interrupt,
162 fast_IRQ8_interrupt, fast_IRQ9_interrupt,
163 fast_IRQ10_interrupt, fast_IRQ11_interrupt,
164 fast_IRQ12_interrupt, fast_IRQ13_interrupt,
165 fast_IRQ14_interrupt, fast_IRQ15_interrupt
166 };
167
168 static void (*bad_interrupt[16])(void) = {
169 bad_IRQ0_interrupt, bad_IRQ1_interrupt,
170 bad_IRQ2_interrupt, bad_IRQ3_interrupt,
171 bad_IRQ4_interrupt, bad_IRQ5_interrupt,
172 bad_IRQ6_interrupt, bad_IRQ7_interrupt,
173 bad_IRQ8_interrupt, bad_IRQ9_interrupt,
174 bad_IRQ10_interrupt, bad_IRQ11_interrupt,
175 bad_IRQ12_interrupt, bad_IRQ13_interrupt,
176 bad_IRQ14_interrupt, bad_IRQ15_interrupt
177 };
178
179
180
181
182 static struct sigaction irq_sigaction[16] = {
183 { NULL, 0, 0, NULL }, { NULL, 0, 0, NULL },
184 { NULL, 0, 0, NULL }, { NULL, 0, 0, NULL },
185 { NULL, 0, 0, NULL }, { NULL, 0, 0, NULL },
186 { NULL, 0, 0, NULL }, { NULL, 0, 0, NULL },
187 { NULL, 0, 0, NULL }, { NULL, 0, 0, NULL },
188 { NULL, 0, 0, NULL }, { NULL, 0, 0, NULL },
189 { NULL, 0, 0, NULL }, { NULL, 0, 0, NULL },
190 { NULL, 0, 0, NULL }, { NULL, 0, 0, NULL }
191 };
192
193 int get_irq_list(char *buf)
194 {
195 int i, len = 0;
196 struct sigaction * sa = irq_sigaction;
197
198 for (i = 0 ; i < 16 ; i++, sa++) {
199 if (!sa->sa_handler)
200 continue;
201 len += sprintf(buf+len, "%2d: %8d %c %s\n",
202 i, kstat.interrupts[i],
203 (sa->sa_flags & SA_INTERRUPT) ? '+' : ' ',
204 (char *) sa->sa_mask);
205 }
206 return len;
207 }
208
209
210
211
212
213
214
215
216 asmlinkage void do_IRQ(int irq, struct pt_regs * regs)
217 {
218 struct sigaction * sa = irq + irq_sigaction;
219
220 kstat.interrupts[irq]++;
221 sa->sa_handler((int) regs);
222 }
223
224
225
226
227
228
229 asmlinkage void do_fast_IRQ(int irq)
230 {
231 struct sigaction * sa = irq + irq_sigaction;
232
233 kstat.interrupts[irq]++;
234 sa->sa_handler(irq);
235 }
236
237
238
239
240
241 static int irqaction(unsigned int irq, struct sigaction * new_sa)
242 {
243 struct sigaction * sa;
244 unsigned long flags;
245
246 if (irq > 15)
247 return -EINVAL;
248 sa = irq + irq_sigaction;
249 if (sa->sa_handler)
250 return -EBUSY;
251 if (!new_sa->sa_handler)
252 return -EINVAL;
253 save_flags(flags);
254 cli();
255 *sa = *new_sa;
256 if (sa->sa_flags & SA_INTERRUPT)
257 set_intr_gate(0x20+irq,fast_interrupt[irq]);
258 else
259 set_intr_gate(0x20+irq,interrupt[irq]);
260 if (irq < 8) {
261 cache_21 &= ~(1<<irq);
262 outb(cache_21,0x21);
263 } else {
264 cache_21 &= ~(1<<2);
265 cache_A1 &= ~(1<<(irq-8));
266 outb(cache_21,0x21);
267 outb(cache_A1,0xA1);
268 }
269 restore_flags(flags);
270 return 0;
271 }
272
273 int request_irq(unsigned int irq, void (*handler)(int),
274 unsigned long flags, const char * devname)
275 {
276 struct sigaction sa;
277
278 sa.sa_handler = handler;
279 sa.sa_flags = flags;
280 sa.sa_mask = (unsigned long) devname;
281 sa.sa_restorer = NULL;
282 return irqaction(irq,&sa);
283 }
284
285 void free_irq(unsigned int irq)
286 {
287 struct sigaction * sa = irq + irq_sigaction;
288 unsigned long flags;
289
290 if (irq > 15) {
291 printk("Trying to free IRQ%d\n",irq);
292 return;
293 }
294 if (!sa->sa_handler) {
295 printk("Trying to free free IRQ%d\n",irq);
296 return;
297 }
298 save_flags(flags);
299 cli();
300 if (irq < 8) {
301 cache_21 |= 1 << irq;
302 outb(cache_21,0x21);
303 } else {
304 cache_A1 |= 1 << (irq-8);
305 outb(cache_A1,0xA1);
306 }
307 set_intr_gate(0x20+irq,bad_interrupt[irq]);
308 sa->sa_handler = NULL;
309 sa->sa_flags = 0;
310 sa->sa_mask = 0;
311 sa->sa_restorer = NULL;
312 restore_flags(flags);
313 }
314
315
316
317
318
319
320
321
322
323
324
325
326 static void math_error_irq(int cpl)
327 {
328 outb(0,0xF0);
329 if (ignore_irq13 || !hard_math)
330 return;
331 math_error();
332 }
333
334 static void no_action(int cpl) { }
335
336 void init_IRQ(void)
337 {
338 int i;
339
340 for (i = 0; i < 16 ; i++)
341 set_intr_gate(0x20+i,bad_interrupt[i]);
342 if (request_irq(2, no_action, SA_INTERRUPT, "cascade"))
343 printk("Unable to get IRQ2 for cascade\n");
344 if (request_irq(13,math_error_irq, 0, "math error"))
345 printk("Unable to get IRQ13 for math-error handler\n");
346
347
348 for (i = 0; i < 32; i++) {
349 bh_base[i].routine = NULL;
350 bh_base[i].data = NULL;
351 }
352 bh_active = 0;
353 intr_count = 0;
354 }