Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Heiko Carstens | b1b7509 | 2011-01-05 12:47:41 +0100 | [diff] [blame] | 2 | * Copyright IBM Corp. 1999,2010 |
| 3 | * Author(s): Holger Smolinski <Holger.Smolinski@de.ibm.com>, |
| 4 | * Martin Schwidefsky <schwidefsky@de.ibm.com>, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include <linux/kernel_stat.h> |
| 8 | #include <linux/interrupt.h> |
Heiko Carstens | b1b7509 | 2011-01-05 12:47:41 +0100 | [diff] [blame] | 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <asm/s390_ext.h> |
Heiko Carstens | 5a489b9 | 2006-10-06 16:38:35 +0200 | [diff] [blame] | 15 | #include <asm/irq_regs.h> |
Heiko Carstens | b1b7509 | 2011-01-05 12:47:41 +0100 | [diff] [blame] | 16 | #include <asm/cputime.h> |
| 17 | #include <asm/lowcore.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <asm/irq.h> |
Heiko Carstens | a806170 | 2008-04-17 07:46:26 +0200 | [diff] [blame] | 19 | #include "entry.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Heiko Carstens | b1b7509 | 2011-01-05 12:47:41 +0100 | [diff] [blame] | 21 | struct ext_int_info { |
| 22 | struct ext_int_info *next; |
| 23 | ext_int_handler_t handler; |
| 24 | __u16 code; |
| 25 | }; |
| 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. |
| 32 | */ |
Heiko Carstens | b1b7509 | 2011-01-05 12:47:41 +0100 | [diff] [blame] | 33 | static struct ext_int_info *ext_int_hash[256]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Heiko Carstens | 99b2d8d | 2005-07-27 11:45:00 -0700 | [diff] [blame] | 35 | static inline int ext_hash(__u16 code) |
| 36 | { |
| 37 | return (code + (code >> 9)) & 0xff; |
| 38 | } |
| 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | int register_external_interrupt(__u16 code, ext_int_handler_t handler) |
| 41 | { |
Heiko Carstens | b1b7509 | 2011-01-05 12:47:41 +0100 | [diff] [blame] | 42 | struct ext_int_info *p; |
| 43 | int index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Heiko Carstens | b1b7509 | 2011-01-05 12:47:41 +0100 | [diff] [blame] | 45 | p = kmalloc(sizeof(*p), GFP_ATOMIC); |
| 46 | if (!p) |
| 47 | return -ENOMEM; |
| 48 | p->code = code; |
| 49 | p->handler = handler; |
Heiko Carstens | 99b2d8d | 2005-07-27 11:45:00 -0700 | [diff] [blame] | 50 | index = ext_hash(code); |
Heiko Carstens | b1b7509 | 2011-01-05 12:47:41 +0100 | [diff] [blame] | 51 | p->next = ext_int_hash[index]; |
| 52 | ext_int_hash[index] = p; |
| 53 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | } |
Heiko Carstens | b1b7509 | 2011-01-05 12:47:41 +0100 | [diff] [blame] | 55 | EXPORT_SYMBOL(register_external_interrupt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 57 | int unregister_external_interrupt(__u16 code, ext_int_handler_t handler) |
| 58 | { |
Heiko Carstens | b1b7509 | 2011-01-05 12:47:41 +0100 | [diff] [blame] | 59 | struct ext_int_info *p, *q; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | int index; |
| 61 | |
Heiko Carstens | 99b2d8d | 2005-07-27 11:45:00 -0700 | [diff] [blame] | 62 | index = ext_hash(code); |
Heiko Carstens | b1b7509 | 2011-01-05 12:47:41 +0100 | [diff] [blame] | 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; |
| 70 | } |
| 71 | if (!p) |
| 72 | return -ENOENT; |
| 73 | if (q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | q->next = p->next; |
Heiko Carstens | b1b7509 | 2011-01-05 12:47:41 +0100 | [diff] [blame] | 75 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | ext_int_hash[index] = p->next; |
Heiko Carstens | b1b7509 | 2011-01-05 12:47:41 +0100 | [diff] [blame] | 77 | kfree(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | return 0; |
| 79 | } |
Heiko Carstens | b1b7509 | 2011-01-05 12:47:41 +0100 | [diff] [blame] | 80 | EXPORT_SYMBOL(unregister_external_interrupt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
Martin Schwidefsky | f6649a7 | 2010-10-25 16:10:38 +0200 | [diff] [blame] | 82 | void __irq_entry do_extint(struct pt_regs *regs, unsigned int ext_int_code, |
| 83 | unsigned int param32, unsigned long param64) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | { |
Martin Schwidefsky | f6649a7 | 2010-10-25 16:10:38 +0200 | [diff] [blame] | 85 | struct pt_regs *old_regs; |
| 86 | unsigned short code; |
Heiko Carstens | b1b7509 | 2011-01-05 12:47:41 +0100 | [diff] [blame] | 87 | struct ext_int_info *p; |
| 88 | int index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
Martin Schwidefsky | f6649a7 | 2010-10-25 16:10:38 +0200 | [diff] [blame] | 90 | code = (unsigned short) ext_int_code; |
Heiko Carstens | 5a489b9 | 2006-10-06 16:38:35 +0200 | [diff] [blame] | 91 | old_regs = set_irq_regs(regs); |
Martin Schwidefsky | 6377981 | 2010-05-17 10:00:03 +0200 | [diff] [blame] | 92 | s390_idle_check(regs, S390_lowcore.int_clock, |
| 93 | S390_lowcore.async_enter_timer); |
Martin Schwidefsky | 9cfb9b3 | 2008-12-31 15:11:41 +0100 | [diff] [blame] | 94 | irq_enter(); |
Heiko Carstens | 5a62b19 | 2008-04-17 07:46:25 +0200 | [diff] [blame] | 95 | if (S390_lowcore.int_clock >= S390_lowcore.clock_comparator) |
| 96 | /* Serve timer interrupts first. */ |
| 97 | clock_comparator_work(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | kstat_cpu(smp_processor_id()).irqs[EXTERNAL_INTERRUPT]++; |
Martin Schwidefsky | 3c5d92a | 2009-09-29 14:25:16 +0200 | [diff] [blame] | 99 | if (code != 0x1004) |
| 100 | __get_cpu_var(s390_idle).nohz_delay = 1; |
Heiko Carstens | b1b7509 | 2011-01-05 12:47:41 +0100 | [diff] [blame] | 101 | index = ext_hash(code); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | for (p = ext_int_hash[index]; p; p = p->next) { |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 103 | if (likely(p->code == code)) |
Martin Schwidefsky | f6649a7 | 2010-10-25 16:10:38 +0200 | [diff] [blame] | 104 | p->handler(ext_int_code, param32, param64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
| 106 | irq_exit(); |
Heiko Carstens | 9d0a57c | 2006-10-11 15:31:26 +0200 | [diff] [blame] | 107 | set_irq_regs(old_regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | } |
Heiko Carstens | df7997a | 2011-05-26 09:48:23 +0200 | [diff] [blame^] | 109 | |
| 110 | static DEFINE_SPINLOCK(sc_irq_lock); |
| 111 | static int sc_irq_refcount; |
| 112 | |
| 113 | void 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 | } |
| 121 | EXPORT_SYMBOL(service_subclass_irq_register); |
| 122 | |
| 123 | void 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 | } |
| 131 | EXPORT_SYMBOL(service_subclass_irq_unregister); |