pnfs-obj: objlayoutdriver module skeleton
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / s390 / kernel / s390_ext.c
blob185029919c4d98fe38440547cf47c1730b8c5a11
1 /*
2 * Copyright IBM Corp. 1999,2010
3 * Author(s): Holger Smolinski <Holger.Smolinski@de.ibm.com>,
4 * Martin Schwidefsky <schwidefsky@de.ibm.com>,
5 */
7 #include <linux/kernel_stat.h>
8 #include <linux/interrupt.h>
9 #include <linux/module.h>
10 #include <linux/kernel.h>
11 #include <linux/ftrace.h>
12 #include <linux/errno.h>
13 #include <linux/slab.h>
14 #include <asm/s390_ext.h>
15 #include <asm/irq_regs.h>
16 #include <asm/cputime.h>
17 #include <asm/lowcore.h>
18 #include <asm/irq.h>
19 #include "entry.h"
21 struct ext_int_info {
22 struct ext_int_info *next;
23 ext_int_handler_t handler;
24 __u16 code;
28 * ext_int_hash[index] is the start of the list for all external interrupts
29 * that hash to this index. With the current set of external interrupts
30 * (0x1202 external call, 0x1004 cpu timer, 0x2401 hwc console, 0x4000
31 * iucv and 0x2603 pfault) this is always the first element.
33 static struct ext_int_info *ext_int_hash[256];
35 static inline int ext_hash(__u16 code)
37 return (code + (code >> 9)) & 0xff;
40 int register_external_interrupt(__u16 code, ext_int_handler_t handler)
42 struct ext_int_info *p;
43 int index;
45 p = kmalloc(sizeof(*p), GFP_ATOMIC);
46 if (!p)
47 return -ENOMEM;
48 p->code = code;
49 p->handler = handler;
50 index = ext_hash(code);
51 p->next = ext_int_hash[index];
52 ext_int_hash[index] = p;
53 return 0;
55 EXPORT_SYMBOL(register_external_interrupt);
57 int unregister_external_interrupt(__u16 code, ext_int_handler_t handler)
59 struct ext_int_info *p, *q;
60 int index;
62 index = ext_hash(code);
63 q = NULL;
64 p = ext_int_hash[index];
65 while (p) {
66 if (p->code == code && p->handler == handler)
67 break;
68 q = p;
69 p = p->next;
71 if (!p)
72 return -ENOENT;
73 if (q)
74 q->next = p->next;
75 else
76 ext_int_hash[index] = p->next;
77 kfree(p);
78 return 0;
80 EXPORT_SYMBOL(unregister_external_interrupt);
82 void __irq_entry do_extint(struct pt_regs *regs, unsigned int ext_int_code,
83 unsigned int param32, unsigned long param64)
85 struct pt_regs *old_regs;
86 unsigned short code;
87 struct ext_int_info *p;
88 int index;
90 code = (unsigned short) ext_int_code;
91 old_regs = set_irq_regs(regs);
92 s390_idle_check(regs, S390_lowcore.int_clock,
93 S390_lowcore.async_enter_timer);
94 irq_enter();
95 if (S390_lowcore.int_clock >= S390_lowcore.clock_comparator)
96 /* Serve timer interrupts first. */
97 clock_comparator_work();
98 kstat_cpu(smp_processor_id()).irqs[EXTERNAL_INTERRUPT]++;
99 if (code != 0x1004)
100 __get_cpu_var(s390_idle).nohz_delay = 1;
101 index = ext_hash(code);
102 for (p = ext_int_hash[index]; p; p = p->next) {
103 if (likely(p->code == code))
104 p->handler(ext_int_code, param32, param64);
106 irq_exit();
107 set_irq_regs(old_regs);