| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 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> | 
| Heiko Carstens | 88dbd20 | 2009-06-12 10:26:46 +0200 | [diff] [blame] | 13 | #include <linux/ftrace.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/errno.h> | 
 | 15 | #include <linux/kernel_stat.h> | 
 | 16 | #include <linux/interrupt.h> | 
| Martin Schwidefsky | 76d4e00 | 2009-06-12 10:26:21 +0200 | [diff] [blame] | 17 | #include <asm/cputime.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <asm/lowcore.h> | 
 | 19 | #include <asm/s390_ext.h> | 
| Heiko Carstens | 5a489b9 | 2006-10-06 16:38:35 +0200 | [diff] [blame] | 20 | #include <asm/irq_regs.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <asm/irq.h> | 
| Heiko Carstens | a806170 | 2008-04-17 07:46:26 +0200 | [diff] [blame] | 22 | #include "entry.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 |  | 
 | 24 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 |  * ext_int_hash[index] is the start of the list for all external interrupts | 
 | 26 |  * that hash to this index. With the current set of external interrupts  | 
 | 27 |  * (0x1202 external call, 0x1004 cpu timer, 0x2401 hwc console, 0x4000 | 
 | 28 |  * iucv and 0x2603 pfault) this is always the first element.  | 
 | 29 |  */ | 
| Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 30 | ext_int_info_t *ext_int_hash[256] = { NULL, }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 |  | 
| Heiko Carstens | 99b2d8d | 2005-07-27 11:45:00 -0700 | [diff] [blame] | 32 | static inline int ext_hash(__u16 code) | 
 | 33 | { | 
 | 34 | 	return (code + (code >> 9)) & 0xff; | 
 | 35 | } | 
 | 36 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | int register_external_interrupt(__u16 code, ext_int_handler_t handler) | 
 | 38 | { | 
 | 39 |         ext_int_info_t *p; | 
 | 40 |         int index; | 
 | 41 |  | 
| Robert P. J. Day | 5cbded5 | 2006-12-13 00:35:56 -0800 | [diff] [blame] | 42 | 	p = kmalloc(sizeof(ext_int_info_t), GFP_ATOMIC); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 |         if (p == NULL) | 
 | 44 |                 return -ENOMEM; | 
 | 45 |         p->code = code; | 
 | 46 |         p->handler = handler; | 
| Heiko Carstens | 99b2d8d | 2005-07-27 11:45:00 -0700 | [diff] [blame] | 47 | 	index = ext_hash(code); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 |         p->next = ext_int_hash[index]; | 
 | 49 |         ext_int_hash[index] = p; | 
 | 50 |         return 0; | 
 | 51 | } | 
 | 52 |  | 
 | 53 | int register_early_external_interrupt(__u16 code, ext_int_handler_t handler, | 
 | 54 | 				      ext_int_info_t *p) | 
 | 55 | { | 
 | 56 |         int index; | 
 | 57 |  | 
 | 58 |         if (p == NULL) | 
 | 59 |                 return -EINVAL; | 
 | 60 |         p->code = code; | 
 | 61 |         p->handler = handler; | 
| Heiko Carstens | 99b2d8d | 2005-07-27 11:45:00 -0700 | [diff] [blame] | 62 | 	index = ext_hash(code); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 |         p->next = ext_int_hash[index]; | 
 | 64 |         ext_int_hash[index] = p; | 
 | 65 |         return 0; | 
 | 66 | } | 
 | 67 |  | 
 | 68 | int unregister_external_interrupt(__u16 code, ext_int_handler_t handler) | 
 | 69 | { | 
 | 70 |         ext_int_info_t *p, *q; | 
 | 71 |         int index; | 
 | 72 |  | 
| Heiko Carstens | 99b2d8d | 2005-07-27 11:45:00 -0700 | [diff] [blame] | 73 | 	index = ext_hash(code); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 |         q = NULL; | 
 | 75 |         p = ext_int_hash[index]; | 
 | 76 |         while (p != NULL) { | 
 | 77 |                 if (p->code == code && p->handler == handler) | 
 | 78 |                         break; | 
 | 79 |                 q = p; | 
 | 80 |                 p = p->next; | 
 | 81 |         } | 
 | 82 |         if (p == NULL) | 
 | 83 |                 return -ENOENT; | 
 | 84 |         if (q != NULL) | 
 | 85 |                 q->next = p->next; | 
 | 86 |         else | 
 | 87 |                 ext_int_hash[index] = p->next; | 
 | 88 | 	kfree(p); | 
 | 89 |         return 0; | 
 | 90 | } | 
 | 91 |  | 
 | 92 | int unregister_early_external_interrupt(__u16 code, ext_int_handler_t handler, | 
 | 93 | 					ext_int_info_t *p) | 
 | 94 | { | 
 | 95 | 	ext_int_info_t *q; | 
 | 96 | 	int index; | 
 | 97 |  | 
 | 98 | 	if (p == NULL || p->code != code || p->handler != handler) | 
 | 99 | 		return -EINVAL; | 
| Heiko Carstens | 99b2d8d | 2005-07-27 11:45:00 -0700 | [diff] [blame] | 100 | 	index = ext_hash(code); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | 	q = ext_int_hash[index]; | 
 | 102 | 	if (p != q) { | 
 | 103 | 		while (q != NULL) { | 
 | 104 | 			if (q->next == p) | 
 | 105 | 				break; | 
 | 106 | 			q = q->next; | 
 | 107 | 		} | 
 | 108 | 		if (q == NULL) | 
 | 109 | 			return -ENOENT; | 
 | 110 | 		q->next = p->next; | 
 | 111 | 	} else | 
 | 112 | 		ext_int_hash[index] = p->next; | 
 | 113 | 	return 0; | 
 | 114 | } | 
 | 115 |  | 
| Heiko Carstens | 88dbd20 | 2009-06-12 10:26:46 +0200 | [diff] [blame] | 116 | void __irq_entry do_extint(struct pt_regs *regs, unsigned short code) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | { | 
 | 118 |         ext_int_info_t *p; | 
 | 119 |         int index; | 
| Heiko Carstens | 5a489b9 | 2006-10-06 16:38:35 +0200 | [diff] [blame] | 120 | 	struct pt_regs *old_regs; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 |  | 
| Heiko Carstens | 5a489b9 | 2006-10-06 16:38:35 +0200 | [diff] [blame] | 122 | 	old_regs = set_irq_regs(regs); | 
| Heiko Carstens | 43ca5c3 | 2008-04-17 07:46:23 +0200 | [diff] [blame] | 123 | 	s390_idle_check(); | 
| Martin Schwidefsky | 9cfb9b3 | 2008-12-31 15:11:41 +0100 | [diff] [blame] | 124 | 	irq_enter(); | 
| Heiko Carstens | 5a62b19 | 2008-04-17 07:46:25 +0200 | [diff] [blame] | 125 | 	if (S390_lowcore.int_clock >= S390_lowcore.clock_comparator) | 
 | 126 | 		/* Serve timer interrupts first. */ | 
 | 127 | 		clock_comparator_work(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | 	kstat_cpu(smp_processor_id()).irqs[EXTERNAL_INTERRUPT]++; | 
| Heiko Carstens | 99b2d8d | 2005-07-27 11:45:00 -0700 | [diff] [blame] | 129 |         index = ext_hash(code); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | 	for (p = ext_int_hash[index]; p; p = p->next) { | 
| Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 131 | 		if (likely(p->code == code)) | 
 | 132 | 			p->handler(code); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | 	} | 
 | 134 | 	irq_exit(); | 
| Heiko Carstens | 9d0a57c | 2006-10-11 15:31:26 +0200 | [diff] [blame] | 135 | 	set_irq_regs(old_regs); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | } | 
 | 137 |  | 
 | 138 | EXPORT_SYMBOL(register_external_interrupt); | 
 | 139 | EXPORT_SYMBOL(unregister_external_interrupt); |