ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / s390 / kernel / s390_ext.c
1 /*
2  *  arch/s390/kernel/s390_ext.c
3  *
4  *  S390 version
5  *    Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
6  *    Author(s): Holger Smolinski (Holger.Smolinski@de.ibm.com),
7  *               Martin Schwidefsky (schwidefsky@de.ibm.com)
8  */
9
10 #include <linux/module.h>
11 #include <linux/kernel.h>
12 #include <linux/slab.h>
13 #include <linux/errno.h>
14 #include <linux/kernel_stat.h>
15
16 #include <asm/lowcore.h>
17 #include <asm/s390_ext.h>
18 #include <asm/irq.h>
19
20 /*
21  * Simple hash strategy: index = code & 0xff;
22  * ext_int_hash[index] is the start of the list for all external interrupts
23  * that hash to this index. With the current set of external interrupts 
24  * (0x1202 external call, 0x1004 cpu timer, 0x2401 hwc console, 0x4000
25  * iucv and 0x2603 pfault) this is always the first element. 
26  */
27 ext_int_info_t *ext_int_hash[256] = { 0, };
28
29 int register_external_interrupt(__u16 code, ext_int_handler_t handler)
30 {
31         ext_int_info_t *p;
32         int index;
33
34         p = (ext_int_info_t *) kmalloc(sizeof(ext_int_info_t), GFP_ATOMIC);
35         if (p == NULL)
36                 return -ENOMEM;
37         p->code = code;
38         p->handler = handler;
39         index = code & 0xff;
40         p->next = ext_int_hash[index];
41         ext_int_hash[index] = p;
42         return 0;
43 }
44
45 int register_early_external_interrupt(__u16 code, ext_int_handler_t handler,
46                                       ext_int_info_t *p)
47 {
48         int index;
49
50         if (p == NULL)
51                 return -EINVAL;
52         p->code = code;
53         p->handler = handler;
54         index = code & 0xff;
55         p->next = ext_int_hash[index];
56         ext_int_hash[index] = p;
57         return 0;
58 }
59
60 int unregister_external_interrupt(__u16 code, ext_int_handler_t handler)
61 {
62         ext_int_info_t *p, *q;
63         int index;
64
65         index = code & 0xff;
66         q = NULL;
67         p = ext_int_hash[index];
68         while (p != NULL) {
69                 if (p->code == code && p->handler == handler)
70                         break;
71                 q = p;
72                 p = p->next;
73         }
74         if (p == NULL)
75                 return -ENOENT;
76         if (q != NULL)
77                 q->next = p->next;
78         else
79                 ext_int_hash[index] = p->next;
80         kfree(p);
81         return 0;
82 }
83
84 int unregister_early_external_interrupt(__u16 code, ext_int_handler_t handler,
85                                         ext_int_info_t *p)
86 {
87         ext_int_info_t *q;
88         int index;
89
90         if (p == NULL || p->code != code || p->handler != handler)
91                 return -EINVAL;
92         index = code & 0xff;
93         q = ext_int_hash[index];
94         if (p != q) {
95                 while (q != NULL) {
96                         if (q->next == p)
97                                 break;
98                         q = q->next;
99                 }
100                 if (q == NULL)
101                         return -ENOENT;
102                 q->next = p->next;
103         } else
104                 ext_int_hash[index] = p->next;
105         return 0;
106 }
107
108 void do_extint(struct pt_regs *regs, unsigned short code)
109 {
110         ext_int_info_t *p;
111         int index;
112
113         irq_enter();
114         asm volatile ("mc 0,0");
115         if (S390_lowcore.int_clock >= S390_lowcore.jiffy_timer)
116                 account_ticks(regs);
117         kstat_cpu(smp_processor_id()).irqs[EXTERNAL_INTERRUPT]++;
118         index = code & 0xff;
119         for (p = ext_int_hash[index]; p; p = p->next) {
120                 if (likely(p->code == code)) {
121                         if (likely(p->handler))
122                                 p->handler(regs, code);
123                 }
124         }
125         irq_exit();
126 }
127
128 EXPORT_SYMBOL(register_external_interrupt);
129 EXPORT_SYMBOL(unregister_external_interrupt);
130