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