This source file includes following definitions.
- disable_irq
- enable_irq
- get_irq_list
- get_smp_prof_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/malloc.h>
27 #include <linux/random.h>
28
29 #include <asm/system.h>
30 #include <asm/io.h>
31 #include <asm/irq.h>
32 #include <asm/bitops.h>
33 #include <asm/smp.h>
34
35 #define CR0_NE 32
36
37 static unsigned char cache_21 = 0xff;
38 static unsigned char cache_A1 = 0xff;
39
40 #ifdef __SMP_PROF__
41 static unsigned int int_count[NR_CPUS][NR_IRQS] = {{0},};
42 #endif
43
44 void disable_irq(unsigned int irq_nr)
45 {
46 unsigned long flags;
47 unsigned char mask;
48
49 mask = 1 << (irq_nr & 7);
50 save_flags(flags);
51 if (irq_nr < 8) {
52 cli();
53 cache_21 |= mask;
54 outb(cache_21,0x21);
55 restore_flags(flags);
56 return;
57 }
58 cli();
59 cache_A1 |= mask;
60 outb(cache_A1,0xA1);
61 restore_flags(flags);
62 }
63
64 void enable_irq(unsigned int irq_nr)
65 {
66 unsigned long flags;
67 unsigned char mask;
68
69 mask = ~(1 << (irq_nr & 7));
70 save_flags(flags);
71 if (irq_nr < 8) {
72 cli();
73 cache_21 &= mask;
74 outb(cache_21,0x21);
75 restore_flags(flags);
76 return;
77 }
78 cli();
79 cache_A1 &= mask;
80 outb(cache_A1,0xA1);
81 restore_flags(flags);
82 }
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107 BUILD_TIMER_IRQ(FIRST,0,0x01)
108 BUILD_IRQ(FIRST,1,0x02)
109 BUILD_IRQ(FIRST,2,0x04)
110 BUILD_IRQ(FIRST,3,0x08)
111 BUILD_IRQ(FIRST,4,0x10)
112 BUILD_IRQ(FIRST,5,0x20)
113 BUILD_IRQ(FIRST,6,0x40)
114 BUILD_IRQ(FIRST,7,0x80)
115 BUILD_IRQ(SECOND,8,0x01)
116 BUILD_IRQ(SECOND,9,0x02)
117 BUILD_IRQ(SECOND,10,0x04)
118 BUILD_IRQ(SECOND,11,0x08)
119 BUILD_IRQ(SECOND,12,0x10)
120 #ifdef __SMP__
121 BUILD_MSGIRQ(SECOND,13,0x20)
122 #else
123 BUILD_IRQ(SECOND,13,0x20)
124 #endif
125 BUILD_IRQ(SECOND,14,0x40)
126 BUILD_IRQ(SECOND,15,0x80)
127 #ifdef __SMP__
128 BUILD_RESCHEDIRQ(16)
129 #endif
130
131
132
133
134
135 static void (*interrupt[17])(void) = {
136 IRQ0_interrupt, IRQ1_interrupt, IRQ2_interrupt, IRQ3_interrupt,
137 IRQ4_interrupt, IRQ5_interrupt, IRQ6_interrupt, IRQ7_interrupt,
138 IRQ8_interrupt, IRQ9_interrupt, IRQ10_interrupt, IRQ11_interrupt,
139 IRQ12_interrupt, IRQ13_interrupt, IRQ14_interrupt, IRQ15_interrupt
140 #ifdef __SMP__
141 ,IRQ16_interrupt
142 #endif
143 };
144
145 static void (*fast_interrupt[16])(void) = {
146 fast_IRQ0_interrupt, fast_IRQ1_interrupt,
147 fast_IRQ2_interrupt, fast_IRQ3_interrupt,
148 fast_IRQ4_interrupt, fast_IRQ5_interrupt,
149 fast_IRQ6_interrupt, fast_IRQ7_interrupt,
150 fast_IRQ8_interrupt, fast_IRQ9_interrupt,
151 fast_IRQ10_interrupt, fast_IRQ11_interrupt,
152 fast_IRQ12_interrupt, fast_IRQ13_interrupt,
153 fast_IRQ14_interrupt, fast_IRQ15_interrupt
154 };
155
156 static void (*bad_interrupt[16])(void) = {
157 bad_IRQ0_interrupt, bad_IRQ1_interrupt,
158 bad_IRQ2_interrupt, bad_IRQ3_interrupt,
159 bad_IRQ4_interrupt, bad_IRQ5_interrupt,
160 bad_IRQ6_interrupt, bad_IRQ7_interrupt,
161 bad_IRQ8_interrupt, bad_IRQ9_interrupt,
162 bad_IRQ10_interrupt, bad_IRQ11_interrupt,
163 bad_IRQ12_interrupt, bad_IRQ13_interrupt,
164 bad_IRQ14_interrupt, bad_IRQ15_interrupt
165 };
166
167
168
169
170 static struct irqaction timer_irq = { NULL, 0, 0, NULL, NULL, NULL};
171 static struct irqaction cascade_irq = { NULL, 0, 0, NULL, NULL, NULL};
172 static struct irqaction math_irq = { NULL, 0, 0, NULL, NULL, NULL};
173
174 static struct irqaction *irq_action[16] = {
175 NULL, NULL, NULL, NULL, NULL, NULL , NULL, NULL,
176 NULL, NULL, NULL, NULL, NULL, NULL , NULL, NULL
177 };
178
179 int get_irq_list(char *buf)
180 {
181 int i, len = 0;
182 struct irqaction * action;
183
184 for (i = 0 ; i < 16 ; i++) {
185 action = *(i + irq_action);
186 if (!action)
187 continue;
188 len += sprintf(buf+len, "%2d: %8d %c %s",
189 i, kstat.interrupts[i],
190 (action->flags & SA_INTERRUPT) ? '+' : ' ',
191 action->name);
192 for (action=action->next; action; action = action->next) {
193 len += sprintf(buf+len, ",%s %s",
194 (action->flags & SA_INTERRUPT) ? " +" : "",
195 action->name);
196 }
197 len += sprintf(buf+len, "\n");
198 }
199
200
201
202 #ifdef __SMP_PROF__
203 len+=sprintf(buf+len, "IPI: %8lu received\n",
204 ipi_count);
205 #endif
206 return len;
207 }
208
209 #ifdef __SMP_PROF__
210
211 int get_smp_prof_list(char *buf) {
212 int i,j, len = 0;
213 struct irqaction * action;
214 unsigned long sum_spins = 0;
215 unsigned long sum_spins_syscall = 0;
216 unsigned long sum_spins_sys_idle = 0;
217 unsigned long sum_smp_idle_count = 0;
218
219 for (i=0;i<=smp_num_cpus;i++) {
220 sum_spins+=smp_spins[i];
221 sum_spins_syscall+=smp_spins_syscall[i];
222 sum_spins_sys_idle+=smp_spins_sys_idle[i];
223 sum_smp_idle_count+=smp_idle_count[i];
224 }
225
226 len += sprintf(buf+len,"CPUS: %10i \n",
227 0==smp_num_cpus?1:smp_num_cpus);
228 len += sprintf(buf+len," SUM ");
229 for (i=0;i<smp_num_cpus;i++)
230 len += sprintf(buf+len," P%1d ",i);
231 len += sprintf(buf+len,"\n");
232 for (i = 0 ; i < NR_IRQS ; i++) {
233 action = *(i + irq_action);
234 if (!action->handler)
235 continue;
236 len += sprintf(buf+len, "%3d: %10d ",
237 i, kstat.interrupts[i]);
238 for (j=0;j<smp_num_cpus;j++)
239 len+=sprintf(buf+len, "%10d ",int_count[j][i]);
240 len += sprintf(buf+len, "%c %s\n",
241 (action->flags & SA_INTERRUPT) ? '+' : ' ',
242 action->name);
243 for (action=action->next; action; action = action->next) {
244 len += sprintf(buf+len, ",%s %s",
245 (action->flags & SA_INTERRUPT) ? " +" : "",
246 action->name);
247 }
248 }
249 len+=sprintf(buf+len, "LCK: %10lu",
250 sum_spins);
251 for (i=0;i<smp_num_cpus;i++)
252 len+=sprintf(buf+len," %10lu",smp_spins[i]);
253 len +=sprintf(buf+len," spins from int\n");
254
255 len+=sprintf(buf+len, "LCK: %10lu",
256 sum_spins_syscall);
257 for (i=0;i<smp_num_cpus;i++)
258 len+=sprintf(buf+len," %10lu",smp_spins_syscall[i]);
259 len +=sprintf(buf+len," spins from syscall\n");
260
261 len+=sprintf(buf+len, "LCK: %10lu",
262 sum_spins_sys_idle);
263 for (i=0;i<smp_num_cpus;i++)
264 len+=sprintf(buf+len," %10lu",smp_spins_sys_idle[i]);
265 len +=sprintf(buf+len," spins from sysidle\n");
266 len+=sprintf(buf+len,"IDLE %10lu",sum_smp_idle_count);
267 for (i=0;i<smp_num_cpus;i++)
268 len+=sprintf(buf+len," %10lu",smp_idle_count[i]);
269 len +=sprintf(buf+len," idle ticks\n");
270
271 len+=sprintf(buf+len, "IPI: %10lu received\n",
272 ipi_count);
273
274 return len;
275 }
276 #endif
277
278
279
280
281
282
283
284
285
286
287 asmlinkage void do_IRQ(int irq, struct pt_regs * regs)
288 {
289 struct irqaction * action = *(irq + irq_action);
290
291 #ifdef __SMP__
292 if(smp_threads_ready && active_kernel_processor!=smp_processor_id())
293 panic("IRQ %d: active processor set wrongly(%d not %d).\n", irq, active_kernel_processor, smp_processor_id());
294 #endif
295
296 kstat.interrupts[irq]++;
297 #ifdef __SMP_PROF__
298 int_count[smp_processor_id()][irq]++;
299 #endif
300 while (action) {
301 if (action->flags & SA_SAMPLE_RANDOM) {
302 add_interrupt_randomness(irq);
303 }
304 action->handler(irq, action->dev_id, regs);
305 action = action->next;
306 }
307 }
308
309
310
311
312
313
314 asmlinkage void do_fast_IRQ(int irq)
315 {
316 struct irqaction * action = *(irq + irq_action);
317 #ifdef __SMP__
318
319 if(smp_threads_ready && active_kernel_processor!=smp_processor_id() && irq!=13)
320 panic("fast_IRQ %d: active processor set wrongly(%d not %d).\n", irq, active_kernel_processor, smp_processor_id());
321 #endif
322
323 kstat.interrupts[irq]++;
324 #ifdef __SMP_PROF__
325 int_count[smp_processor_id()][irq]++;
326 #endif
327 while (action) {
328 if (action->flags & SA_SAMPLE_RANDOM)
329 add_interrupt_randomness(irq);
330 action->handler(irq, action->dev_id, NULL);
331 action = action->next;
332 }
333 }
334
335 #define SA_PROBE SA_ONESHOT
336
337 int request_irq(unsigned int irq,
338 void (*handler)(int, void *, struct pt_regs *),
339 unsigned long irqflags,
340 const char * devname,
341 void *dev_id)
342 {
343 struct irqaction * action, *tmp = NULL;
344 unsigned long flags;
345
346 if (irq > 15)
347 return -EINVAL;
348 if (!handler)
349 return -EINVAL;
350 action = *(irq + irq_action);
351 if (action) {
352 if ((action->flags & SA_SHIRQ) && (irqflags & SA_SHIRQ)) {
353 for (tmp = action; tmp->next; tmp = tmp->next);
354 } else {
355 return -EBUSY;
356 }
357 if ((action->flags & SA_INTERRUPT) ^ (irqflags & SA_INTERRUPT)) {
358 printk("Attempt to mix fast and slow interrupts on IRQ%d denied\n", irq);
359 return -EBUSY;
360 }
361 }
362 if (irqflags & SA_SAMPLE_RANDOM)
363 rand_initialize_irq(irq);
364 save_flags(flags);
365 cli();
366 if (irq == 2)
367 action = &cascade_irq;
368 else if (irq == 13)
369 action = &math_irq;
370 else if (irq == TIMER_IRQ)
371 action = &timer_irq;
372 else
373 action = (struct irqaction *)kmalloc(sizeof(struct irqaction), GFP_KERNEL);
374
375 if (!action) {
376 restore_flags(flags);
377 return -ENOMEM;
378 }
379
380 action->handler = handler;
381 action->flags = irqflags;
382 action->mask = 0;
383 action->name = devname;
384 action->next = NULL;
385 action->dev_id = dev_id;
386
387 if (tmp) {
388 tmp->next = action;
389 } else {
390 *(irq + irq_action) = action;
391 if (!(action->flags & SA_PROBE)) {
392 if (action->flags & SA_INTERRUPT)
393 set_intr_gate(0x20+irq,fast_interrupt[irq]);
394 else
395 set_intr_gate(0x20+irq,interrupt[irq]);
396 }
397 if (irq < 8) {
398 cache_21 &= ~(1<<irq);
399 outb(cache_21,0x21);
400 } else {
401 cache_21 &= ~(1<<2);
402 cache_A1 &= ~(1<<(irq-8));
403 outb(cache_21,0x21);
404 outb(cache_A1,0xA1);
405 }
406 }
407
408 restore_flags(flags);
409 return 0;
410 }
411
412 void free_irq(unsigned int irq, void *dev_id)
413 {
414 struct irqaction * action = *(irq + irq_action);
415 struct irqaction * tmp = NULL;
416 unsigned long flags;
417
418 if (irq > 15) {
419 printk("Trying to free IRQ%d\n",irq);
420 return;
421 }
422 if (!action->handler) {
423 printk("Trying to free free IRQ%d\n",irq);
424 return;
425 }
426 if (dev_id) {
427 for (; action; action = action->next) {
428 if (action->dev_id == dev_id) break;
429 tmp = action;
430 }
431 if (!action) {
432 printk("Trying to free free shared IRQ%d\n",irq);
433 return;
434 }
435 } else if (action->flags & SA_SHIRQ) {
436 printk("Trying to free shared IRQ%d with NULL device ID\n", irq);
437 return;
438 }
439 save_flags(flags);
440 cli();
441 if (action && tmp) {
442 tmp->next = action->next;
443 } else {
444 *(irq + irq_action) = action->next;
445 }
446
447 if ((irq == 2) || (irq == 13) | (irq == TIMER_IRQ))
448 memset(action, 0, sizeof(struct irqaction));
449 else
450 kfree_s(action, sizeof(struct irqaction));
451
452 if (!(*(irq + irq_action))) {
453 if (irq < 8) {
454 cache_21 |= 1 << irq;
455 outb(cache_21,0x21);
456 } else {
457 cache_A1 |= 1 << (irq-8);
458 outb(cache_A1,0xA1);
459 }
460 set_intr_gate(0x20+irq,bad_interrupt[irq]);
461 }
462
463 restore_flags(flags);
464 }
465
466 #ifndef __SMP__
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481 static void math_error_irq(int cpl, void *dev_id, struct pt_regs *regs)
482 {
483 outb(0,0xF0);
484 if (ignore_irq13 || !hard_math)
485 return;
486 math_error();
487 }
488
489 #endif
490
491 static void no_action(int cpl, void *dev_id, struct pt_regs *regs) { }
492
493 unsigned long probe_irq_on (void)
494 {
495 unsigned int i, irqs = 0, irqmask;
496 unsigned long delay;
497
498
499 for (i = 15; i > 0; i--) {
500 if (!request_irq(i, no_action, SA_PROBE, "probe", NULL)) {
501 enable_irq(i);
502 irqs |= (1 << i);
503 }
504 }
505
506
507 for (delay = jiffies + 2; delay > jiffies; );
508
509
510 irqmask = (((unsigned int)cache_A1)<<8) | (unsigned int)cache_21;
511 for (i = 15; i > 0; i--) {
512 if (irqs & (1 << i) & irqmask) {
513 irqs ^= (1 << i);
514 free_irq(i, NULL);
515 }
516 }
517 #ifdef DEBUG
518 printk("probe_irq_on: irqs=0x%04x irqmask=0x%04x\n", irqs, irqmask);
519 #endif
520 return irqs;
521 }
522
523 int probe_irq_off (unsigned long irqs)
524 {
525 unsigned int i, irqmask;
526
527 irqmask = (((unsigned int)cache_A1)<<8) | (unsigned int)cache_21;
528 for (i = 15; i > 0; i--) {
529 if (irqs & (1 << i)) {
530 free_irq(i, NULL);
531 }
532 }
533 #ifdef DEBUG
534 printk("probe_irq_off: irqs=0x%04x irqmask=0x%04x\n", irqs, irqmask);
535 #endif
536 irqs &= irqmask;
537 if (!irqs)
538 return 0;
539 i = ffz(~irqs);
540 if (irqs != (irqs & (1 << i)))
541 i = -i;
542 return i;
543 }
544
545 void init_IRQ(void)
546 {
547 int i;
548 static unsigned char smptrap=0;
549 if(smptrap)
550 return;
551 smptrap=1;
552
553
554 outb_p(0x34,0x43);
555 outb_p(LATCH & 0xff , 0x40);
556 outb(LATCH >> 8 , 0x40);
557 for (i = 0; i < 16 ; i++)
558 set_intr_gate(0x20+i,bad_interrupt[i]);
559
560
561 #ifdef __SMP__
562 set_intr_gate(0x20+i, interrupt[i]);
563 #endif
564 if (request_irq(2, no_action, SA_INTERRUPT, "cascade", NULL))
565 printk("Unable to get IRQ2 for cascade.\n");
566 #ifndef __SMP__
567 if (request_irq(13, math_error_irq, 0, "math error", NULL))
568 printk("Unable to get IRQ13 for math-error handler.\n");
569 #else
570 if (request_irq(13, smp_message_irq, SA_INTERRUPT, "IPI", NULL))
571 printk("Unable to get IRQ13 for IPI.\n");
572 #endif
573 request_region(0x20,0x20,"pic1");
574 request_region(0xa0,0x20,"pic2");
575 }