ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / asm-s390 / hardirq.h
1 /*
2  *  include/asm-s390/hardirq.h
3  *
4  *  S390 version
5  *    Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
6  *    Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
7  *               Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
8  *
9  *  Derived from "include/asm-i386/hardirq.h"
10  */
11
12 #ifndef __ASM_HARDIRQ_H
13 #define __ASM_HARDIRQ_H
14
15 #include <linux/config.h>
16 #include <linux/threads.h>
17 #include <linux/sched.h>
18 #include <linux/cache.h>
19 #include <asm/lowcore.h>
20
21 /* irq_cpustat_t is unused currently, but could be converted
22  * into a percpu variable instead of storing softirq_pending
23  * on the lowcore */
24 typedef struct {
25         unsigned int __softirq_pending;
26 } irq_cpustat_t;
27
28 #define local_softirq_pending() (S390_lowcore.softirq_pending)
29
30 /* this is always called with cpu == smp_processor_id() at the moment */
31 static inline __u32
32 softirq_pending(unsigned int cpu)
33 {
34         if (cpu == smp_processor_id())
35                 return local_softirq_pending();
36         return lowcore_ptr[cpu]->softirq_pending;
37 }
38
39 #define __ARCH_IRQ_STAT
40
41 /*
42  * We put the hardirq and softirq counter into the preemption
43  * counter. The bitmask has the following meaning:
44  *
45  * - bits 0-7 are the preemption count (max preemption depth: 256)
46  * - bits 8-15 are the softirq count (max # of softirqs: 256)
47  * - bits 16-23 are the hardirq count (max # of hardirqs: 256)
48  *
49  * - ( bit 26 is the PREEMPT_ACTIVE flag. )
50  *
51  * PREEMPT_MASK: 0x000000ff
52  * SOFTIRQ_MASK: 0x0000ff00
53  * HARDIRQ_MASK: 0x00ff0000
54  */
55
56 #define PREEMPT_BITS    8
57 #define SOFTIRQ_BITS    8
58 #define HARDIRQ_BITS    8
59
60 #define PREEMPT_SHIFT   0
61 #define SOFTIRQ_SHIFT   (PREEMPT_SHIFT + PREEMPT_BITS)
62 #define HARDIRQ_SHIFT   (SOFTIRQ_SHIFT + SOFTIRQ_BITS)
63
64 #define __MASK(x)       ((1UL << (x))-1)
65
66 #define PREEMPT_MASK    (__MASK(PREEMPT_BITS) << PREEMPT_SHIFT)
67 #define SOFTIRQ_MASK    (__MASK(SOFTIRQ_BITS) << SOFTIRQ_SHIFT)
68 #define HARDIRQ_MASK    (__MASK(HARDIRQ_BITS) << HARDIRQ_SHIFT)
69
70 #define hardirq_count() (preempt_count() & HARDIRQ_MASK)
71 #define softirq_count() (preempt_count() & SOFTIRQ_MASK)
72 #define irq_count()     (preempt_count() & (HARDIRQ_MASK | SOFTIRQ_MASK))
73
74 #define PREEMPT_OFFSET  (1UL << PREEMPT_SHIFT)
75 #define SOFTIRQ_OFFSET  (1UL << SOFTIRQ_SHIFT)
76 #define HARDIRQ_OFFSET  (1UL << HARDIRQ_SHIFT)
77
78 /*
79  * Are we doing bottom half or hardware interrupt processing?
80  * Are we in a softirq context? Interrupt context?
81  */
82 #define in_irq()                (hardirq_count())
83 #define in_softirq()            (softirq_count())
84 #define in_interrupt()          (irq_count())
85
86
87 #define hardirq_trylock()       (!in_interrupt())
88 #define hardirq_endlock()       do { } while (0)
89
90 #define irq_enter()                                                     \
91 do {                                                                    \
92         (preempt_count() += HARDIRQ_OFFSET);                            \
93 } while(0)
94         
95
96 extern void do_call_softirq(void);
97 extern void account_ticks(struct pt_regs *);
98
99 #define invoke_softirq() do_call_softirq()
100
101 #ifdef CONFIG_PREEMPT
102 # define in_atomic()    ((preempt_count() & ~PREEMPT_ACTIVE) != kernel_locked())
103 # define IRQ_EXIT_OFFSET (HARDIRQ_OFFSET-1)
104 #else
105 # define in_atomic()    (preempt_count() != 0)
106 # define IRQ_EXIT_OFFSET HARDIRQ_OFFSET
107 #endif
108
109 #define irq_exit()                                                      \
110 do {                                                                    \
111         preempt_count() -= IRQ_EXIT_OFFSET;                             \
112         if (!in_interrupt() && local_softirq_pending())                 \
113                 /* Use the async. stack for softirq */                  \
114                 do_call_softirq();                                      \
115         preempt_enable_no_resched();                                    \
116 } while (0)
117
118 #endif /* __ASM_HARDIRQ_H */