2 * arch/s390/kernel/irq.c
5 * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
6 * Author(s): Ingo Adlung (adlung@de.ibm.com)
8 * Derived from "arch/i386/kernel/irq.c"
9 * Copyright (C) 1992, 1999 Linus Torvalds, Ingo Molnar
11 * S/390 I/O interrupt processing and I/O request processing is
12 * implemented in arch/s390/kernel/s390io.c
14 #include <linux/module.h>
15 #include <linux/config.h>
16 #include <linux/ptrace.h>
17 #include <linux/errno.h>
18 #include <linux/kernel_stat.h>
19 #include <linux/signal.h>
20 #include <linux/sched.h>
21 #include <linux/ioport.h>
22 #include <linux/interrupt.h>
23 #include <linux/timex.h>
24 #include <linux/slab.h>
25 #include <linux/string.h>
26 #include <linux/random.h>
27 #include <linux/smp.h>
28 #include <linux/threads.h>
29 #include <linux/smp_lock.h>
30 #include <linux/init.h>
32 #include <asm/system.h>
35 #include <asm/bitops.h>
37 #include <asm/pgtable.h>
38 #include <asm/delay.h>
39 #include <asm/lowcore.h>
41 void s390_init_IRQ ( void );
42 void s390_free_irq ( unsigned int irq, void *dev_id);
43 int s390_request_irq( unsigned int irq,
44 void (*handler)(int, void *, struct pt_regs *),
45 unsigned long irqflags,
51 * The following vectors are part of the Linux architecture, there
52 * is no hardware IRQ pin equivalent for them, they are triggered
53 * through the ICC by us (IPIs), via smp_message_pass():
55 BUILD_SMP_INTERRUPT(reschedule_interrupt)
56 BUILD_SMP_INTERRUPT(invalidate_interrupt)
57 BUILD_SMP_INTERRUPT(stop_cpu_interrupt)
58 BUILD_SMP_INTERRUPT(mtrr_interrupt)
59 BUILD_SMP_INTERRUPT(spurious_interrupt)
63 * Global interrupt locks for SMP. Allow interrupts to come in on any
64 * CPU, yet make cli/sti act globally to protect critical regions..
67 atomic_t global_irq_holder = ATOMIC_INIT(NO_PROC_ID);
68 atomic_t global_irq_lock = ATOMIC_INIT(0);
69 atomic_t global_irq_count = ATOMIC_INIT(0);
70 atomic_t global_bh_count;
73 * "global_cli()" is a special case, in that it can hold the
74 * interrupts disabled for a longish time, and also because
75 * we may be doing TLB invalidates when holding the global
76 * IRQ lock for historical reasons. Thus we may need to check
77 * SMP invalidate events specially by hand here (but not in
78 * any normal spinlocks)
80 * Thankfully we don't need this as we can deliver flush tlbs with
81 * interrupts disabled DJB :-)
83 #define check_smp_invalidate(cpu)
85 static void show(char * str)
89 int cpu = smp_processor_id();
91 printk("\n%s, CPU %d:\n", str, cpu);
92 printk("irq: %d [%d]\n",
93 atomic_read(&global_irq_count),local_irq_count(smp_processor_id()));
94 printk("bh: %d [%d]\n",
95 atomic_read(&global_bh_count),local_bh_count(smp_processor_id()));
96 stack = (unsigned long *) &str;
97 for (i = 40; i ; i--) {
98 unsigned long x = *++stack;
99 if (x > (unsigned long) &init_task_union && x < (unsigned long) &vsprintf) {
100 printk("<[%08lx]> ", x);
105 #define MAXCOUNT 100000000
107 static inline void wait_on_bh(void)
109 int count = MAXCOUNT;
115 /* nothing .. wait for the other bh's to go away */
116 } while (atomic_read(&global_bh_count) != 0);
119 static inline void wait_on_irq(int cpu)
121 int count = MAXCOUNT;
126 * Wait until all interrupts are gone. Wait
127 * for bottom half handlers unless we're
128 * already executing in one..
130 if (!atomic_read(&global_irq_count)) {
131 if (local_bh_count(cpu)||
132 !atomic_read(&global_bh_count))
136 /* Duh, we have to loop. Release the lock to avoid deadlocks */
137 atomic_set(&global_irq_lock, 0);
145 SYNC_OTHER_CORES(cpu);
147 check_smp_invalidate(cpu);
148 if (atomic_read(&global_irq_count))
150 if (atomic_read(&global_irq_lock))
152 if (!local_bh_count(cpu)
153 && atomic_read(&global_bh_count))
155 if (!atomic_compare_and_swap(0, 1, &global_irq_lock))
162 * This is called when we want to synchronize with
163 * bottom half handlers. We need to wait until
164 * no other CPU is executing any bottom half handler.
166 * Don't wait if we're already running in an interrupt
167 * context or are inside a bh handler.
169 void synchronize_bh(void)
171 if (atomic_read(&global_bh_count) && !in_interrupt())
176 * This is called when we want to synchronize with
177 * interrupts. We may for example tell a device to
178 * stop sending interrupts: but to make sure there
179 * are no interrupts that are executing on another
180 * CPU we need to call this function.
182 void synchronize_irq(void)
184 if (atomic_read(&global_irq_count)) {
185 /* Stupid approach */
191 static inline void get_irqlock(int cpu)
193 if (atomic_compare_and_swap(0, 1, &global_irq_lock) != 0) {
194 /* do we already hold the lock? */
195 if ( cpu == atomic_read(&global_irq_holder))
197 /* Uhhuh.. Somebody else got it. Wait.. */
199 check_smp_invalidate(cpu);
200 } while (atomic_compare_and_swap(0, 1, &global_irq_lock) != 0);
203 * We also to make sure that nobody else is running
204 * in an interrupt context.
211 atomic_set(&global_irq_holder,cpu);
214 #define EFLAGS_I_SHIFT 25
217 * A global "cli()" while in an interrupt context
218 * turns into just a local cli(). Interrupts
219 * should use spinlocks for the (very unlikely)
220 * case that they ever want to protect against
223 * If we already have local interrupts disabled,
224 * this will not turn a local disable into a
225 * global one (problems with spinlocks: this makes
226 * save_flags+cli+sti usable inside a spinlock).
228 void __global_cli(void)
233 if (flags & (1 << EFLAGS_I_SHIFT)) {
234 int cpu = smp_processor_id();
241 void __global_sti(void)
245 release_irqlock(smp_processor_id());
250 * SMP flags value to restore to:
256 unsigned long __global_save_flags(void)
263 local_enabled = (flags >> EFLAGS_I_SHIFT) & 1;
264 /* default to local */
265 retval = 2 + local_enabled;
267 /* check for global flags if we're not in an interrupt */
272 if (atomic_read(&global_irq_holder)== smp_processor_id())
278 void __global_restore_flags(unsigned long flags)
294 printk("global_restore_flags: %08lx (%08lx)\n",
295 flags, (&flags)[-1]);
302 void __init init_IRQ(void)
308 void free_irq(unsigned int irq, void *dev_id)
310 s390_free_irq( irq, dev_id);
314 int request_irq( unsigned int irq,
315 void (*handler)(int, void *, struct pt_regs *),
316 unsigned long irqflags,
320 return( s390_request_irq( irq, handler, irqflags, devname, dev_id ) );
324 void init_irq_proc(void)
326 /* For now, nothing... */
330 EXPORT_SYMBOL(__global_cli);
331 EXPORT_SYMBOL(__global_sti);
332 EXPORT_SYMBOL(__global_save_flags);
333 EXPORT_SYMBOL(__global_restore_flags);
334 EXPORT_SYMBOL(global_irq_holder);
335 EXPORT_SYMBOL(global_irq_lock);
336 EXPORT_SYMBOL(global_irq_count);
337 EXPORT_SYMBOL(global_bh_count);
340 EXPORT_SYMBOL(global_bh_lock);