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