Linux 2.6.18.8
[linux-2.6/suspend2-2.6.18.git] / arch / s390 / kernel / s390_ext.c
blobc1b383537fec2cbb3c0f4431c6a7faa80b83a73f
1 /*
2 * arch/s390/kernel/s390_ext.c
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 */
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 #include <linux/interrupt.h>
17 #include <asm/lowcore.h>
18 #include <asm/s390_ext.h>
19 #include <asm/irq.h>
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.
27 ext_int_info_t *ext_int_hash[256] = { NULL, };
29 static inline int ext_hash(__u16 code)
31 return (code + (code >> 9)) & 0xff;
34 int register_external_interrupt(__u16 code, ext_int_handler_t handler)
36 ext_int_info_t *p;
37 int index;
39 p = (ext_int_info_t *) kmalloc(sizeof(ext_int_info_t), GFP_ATOMIC);
40 if (p == NULL)
41 return -ENOMEM;
42 p->code = code;
43 p->handler = handler;
44 index = ext_hash(code);
45 p->next = ext_int_hash[index];
46 ext_int_hash[index] = p;
47 return 0;
50 int register_early_external_interrupt(__u16 code, ext_int_handler_t handler,
51 ext_int_info_t *p)
53 int index;
55 if (p == NULL)
56 return -EINVAL;
57 p->code = code;
58 p->handler = handler;
59 index = ext_hash(code);
60 p->next = ext_int_hash[index];
61 ext_int_hash[index] = p;
62 return 0;
65 int unregister_external_interrupt(__u16 code, ext_int_handler_t handler)
67 ext_int_info_t *p, *q;
68 int index;
70 index = ext_hash(code);
71 q = NULL;
72 p = ext_int_hash[index];
73 while (p != NULL) {
74 if (p->code == code && p->handler == handler)
75 break;
76 q = p;
77 p = p->next;
79 if (p == NULL)
80 return -ENOENT;
81 if (q != NULL)
82 q->next = p->next;
83 else
84 ext_int_hash[index] = p->next;
85 kfree(p);
86 return 0;
89 int unregister_early_external_interrupt(__u16 code, ext_int_handler_t handler,
90 ext_int_info_t *p)
92 ext_int_info_t *q;
93 int index;
95 if (p == NULL || p->code != code || p->handler != handler)
96 return -EINVAL;
97 index = ext_hash(code);
98 q = ext_int_hash[index];
99 if (p != q) {
100 while (q != NULL) {
101 if (q->next == p)
102 break;
103 q = q->next;
105 if (q == NULL)
106 return -ENOENT;
107 q->next = p->next;
108 } else
109 ext_int_hash[index] = p->next;
110 return 0;
113 void do_extint(struct pt_regs *regs, unsigned short code)
115 ext_int_info_t *p;
116 int index;
118 irq_enter();
119 asm volatile ("mc 0,0");
120 if (S390_lowcore.int_clock >= S390_lowcore.jiffy_timer)
122 * Make sure that the i/o interrupt did not "overtake"
123 * the last HZ timer interrupt.
125 account_ticks(regs);
126 kstat_cpu(smp_processor_id()).irqs[EXTERNAL_INTERRUPT]++;
127 index = ext_hash(code);
128 for (p = ext_int_hash[index]; p; p = p->next) {
129 if (likely(p->code == code)) {
130 if (likely(p->handler))
131 p->handler(regs, code);
134 irq_exit();
137 EXPORT_SYMBOL(register_external_interrupt);
138 EXPORT_SYMBOL(unregister_external_interrupt);