blob: 207bc511a6e31949e9394e8d7ecf4335d15eb4cb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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#include <linux/interrupt.h>
16
17#include <asm/lowcore.h>
18#include <asm/s390_ext.h>
19#include <asm/irq.h>
20
21/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 * 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 */
27ext_int_info_t *ext_int_hash[256] = { 0, };
28
Heiko Carstens99b2d8d2005-07-27 11:45:00 -070029static inline int ext_hash(__u16 code)
30{
31 return (code + (code >> 9)) & 0xff;
32}
33
Linus Torvalds1da177e2005-04-16 15:20:36 -070034int register_external_interrupt(__u16 code, ext_int_handler_t handler)
35{
36 ext_int_info_t *p;
37 int index;
38
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;
Heiko Carstens99b2d8d2005-07-27 11:45:00 -070044 index = ext_hash(code);
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 p->next = ext_int_hash[index];
46 ext_int_hash[index] = p;
47 return 0;
48}
49
50int register_early_external_interrupt(__u16 code, ext_int_handler_t handler,
51 ext_int_info_t *p)
52{
53 int index;
54
55 if (p == NULL)
56 return -EINVAL;
57 p->code = code;
58 p->handler = handler;
Heiko Carstens99b2d8d2005-07-27 11:45:00 -070059 index = ext_hash(code);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 p->next = ext_int_hash[index];
61 ext_int_hash[index] = p;
62 return 0;
63}
64
65int unregister_external_interrupt(__u16 code, ext_int_handler_t handler)
66{
67 ext_int_info_t *p, *q;
68 int index;
69
Heiko Carstens99b2d8d2005-07-27 11:45:00 -070070 index = ext_hash(code);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 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;
78 }
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;
87}
88
89int unregister_early_external_interrupt(__u16 code, ext_int_handler_t handler,
90 ext_int_info_t *p)
91{
92 ext_int_info_t *q;
93 int index;
94
95 if (p == NULL || p->code != code || p->handler != handler)
96 return -EINVAL;
Heiko Carstens99b2d8d2005-07-27 11:45:00 -070097 index = ext_hash(code);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 q = ext_int_hash[index];
99 if (p != q) {
100 while (q != NULL) {
101 if (q->next == p)
102 break;
103 q = q->next;
104 }
105 if (q == NULL)
106 return -ENOENT;
107 q->next = p->next;
108 } else
109 ext_int_hash[index] = p->next;
110 return 0;
111}
112
113void do_extint(struct pt_regs *regs, unsigned short code)
114{
115 ext_int_info_t *p;
116 int index;
117
118 irq_enter();
119 asm volatile ("mc 0,0");
120 if (S390_lowcore.int_clock >= S390_lowcore.jiffy_timer)
121 /**
122 * Make sure that the i/o interrupt did not "overtake"
123 * the last HZ timer interrupt.
124 */
125 account_ticks(regs);
126 kstat_cpu(smp_processor_id()).irqs[EXTERNAL_INTERRUPT]++;
Heiko Carstens99b2d8d2005-07-27 11:45:00 -0700127 index = ext_hash(code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 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);
132 }
133 }
134 irq_exit();
135}
136
137EXPORT_SYMBOL(register_external_interrupt);
138EXPORT_SYMBOL(unregister_external_interrupt);
139