blob: 87b5c532abf1faf132e85bf4158869c1677493f1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Heiko Carstensb1b75092011-01-05 12:47:41 +01002 * Copyright IBM Corp. 1999,2010
3 * Author(s): Holger Smolinski <Holger.Smolinski@de.ibm.com>,
4 * Martin Schwidefsky <schwidefsky@de.ibm.com>,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
6
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <linux/kernel_stat.h>
8#include <linux/interrupt.h>
Heiko Carstensb1b75092011-01-05 12:47:41 +01009#include <linux/module.h>
10#include <linux/kernel.h>
11#include <linux/ftrace.h>
12#include <linux/errno.h>
13#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <asm/s390_ext.h>
Heiko Carstens5a489b92006-10-06 16:38:35 +020015#include <asm/irq_regs.h>
Heiko Carstensb1b75092011-01-05 12:47:41 +010016#include <asm/cputime.h>
17#include <asm/lowcore.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <asm/irq.h>
Heiko Carstensa8061702008-04-17 07:46:26 +020019#include "entry.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Heiko Carstensb1b75092011-01-05 12:47:41 +010021struct ext_int_info {
22 struct ext_int_info *next;
23 ext_int_handler_t handler;
24 __u16 code;
25};
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 * 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.
32 */
Heiko Carstensb1b75092011-01-05 12:47:41 +010033static struct ext_int_info *ext_int_hash[256];
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Heiko Carstens99b2d8d2005-07-27 11:45:00 -070035static inline int ext_hash(__u16 code)
36{
37 return (code + (code >> 9)) & 0xff;
38}
39
Linus Torvalds1da177e2005-04-16 15:20:36 -070040int register_external_interrupt(__u16 code, ext_int_handler_t handler)
41{
Heiko Carstensb1b75092011-01-05 12:47:41 +010042 struct ext_int_info *p;
43 int index;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Heiko Carstensb1b75092011-01-05 12:47:41 +010045 p = kmalloc(sizeof(*p), GFP_ATOMIC);
46 if (!p)
47 return -ENOMEM;
48 p->code = code;
49 p->handler = handler;
Heiko Carstens99b2d8d2005-07-27 11:45:00 -070050 index = ext_hash(code);
Heiko Carstensb1b75092011-01-05 12:47:41 +010051 p->next = ext_int_hash[index];
52 ext_int_hash[index] = p;
53 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054}
Heiko Carstensb1b75092011-01-05 12:47:41 +010055EXPORT_SYMBOL(register_external_interrupt);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57int unregister_external_interrupt(__u16 code, ext_int_handler_t handler)
58{
Heiko Carstensb1b75092011-01-05 12:47:41 +010059 struct ext_int_info *p, *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 int index;
61
Heiko Carstens99b2d8d2005-07-27 11:45:00 -070062 index = ext_hash(code);
Heiko Carstensb1b75092011-01-05 12:47:41 +010063 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;
70 }
71 if (!p)
72 return -ENOENT;
73 if (q)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 q->next = p->next;
Heiko Carstensb1b75092011-01-05 12:47:41 +010075 else
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 ext_int_hash[index] = p->next;
Heiko Carstensb1b75092011-01-05 12:47:41 +010077 kfree(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 return 0;
79}
Heiko Carstensb1b75092011-01-05 12:47:41 +010080EXPORT_SYMBOL(unregister_external_interrupt);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Martin Schwidefskyf6649a72010-10-25 16:10:38 +020082void __irq_entry do_extint(struct pt_regs *regs, unsigned int ext_int_code,
83 unsigned int param32, unsigned long param64)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
Martin Schwidefskyf6649a72010-10-25 16:10:38 +020085 struct pt_regs *old_regs;
86 unsigned short code;
Heiko Carstensb1b75092011-01-05 12:47:41 +010087 struct ext_int_info *p;
88 int index;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Martin Schwidefskyf6649a72010-10-25 16:10:38 +020090 code = (unsigned short) ext_int_code;
Heiko Carstens5a489b92006-10-06 16:38:35 +020091 old_regs = set_irq_regs(regs);
Martin Schwidefsky63779812010-05-17 10:00:03 +020092 s390_idle_check(regs, S390_lowcore.int_clock,
93 S390_lowcore.async_enter_timer);
Martin Schwidefsky9cfb9b32008-12-31 15:11:41 +010094 irq_enter();
Heiko Carstens5a62b192008-04-17 07:46:25 +020095 if (S390_lowcore.int_clock >= S390_lowcore.clock_comparator)
96 /* Serve timer interrupts first. */
97 clock_comparator_work();
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 kstat_cpu(smp_processor_id()).irqs[EXTERNAL_INTERRUPT]++;
Martin Schwidefsky3c5d92a2009-09-29 14:25:16 +020099 if (code != 0x1004)
100 __get_cpu_var(s390_idle).nohz_delay = 1;
Heiko Carstensb1b75092011-01-05 12:47:41 +0100101 index = ext_hash(code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 for (p = ext_int_hash[index]; p; p = p->next) {
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100103 if (likely(p->code == code))
Martin Schwidefskyf6649a72010-10-25 16:10:38 +0200104 p->handler(ext_int_code, param32, param64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 }
106 irq_exit();
Heiko Carstens9d0a57c2006-10-11 15:31:26 +0200107 set_irq_regs(old_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108}
Heiko Carstensdf7997a2011-05-26 09:48:23 +0200109
110static DEFINE_SPINLOCK(sc_irq_lock);
111static int sc_irq_refcount;
112
113void service_subclass_irq_register(void)
114{
115 spin_lock(&sc_irq_lock);
116 if (!sc_irq_refcount)
117 ctl_set_bit(0, 9);
118 sc_irq_refcount++;
119 spin_unlock(&sc_irq_lock);
120}
121EXPORT_SYMBOL(service_subclass_irq_register);
122
123void service_subclass_irq_unregister(void)
124{
125 spin_lock(&sc_irq_lock);
126 sc_irq_refcount--;
127 if (!sc_irq_refcount)
128 ctl_clear_bit(0, 9);
129 spin_unlock(&sc_irq_lock);
130}
131EXPORT_SYMBOL(service_subclass_irq_unregister);