kernel.org linux-2.6.10
[linux-2.6.git] / include / linux / hardirq.h
1 #ifndef LINUX_HARDIRQ_H
2 #define LINUX_HARDIRQ_H
3
4 #include <linux/config.h>
5 #include <linux/smp_lock.h>
6 #include <asm/hardirq.h>
7
8 /*
9  * We put the hardirq and softirq counter into the preemption
10  * counter. The bitmask has the following meaning:
11  *
12  * - bits 0-7 are the preemption count (max preemption depth: 256)
13  * - bits 8-15 are the softirq count (max # of softirqs: 256)
14  *
15  * The hardirq count can be overridden per architecture, the default is:
16  *
17  * - bits 16-27 are the hardirq count (max # of hardirqs: 4096)
18  * - ( bit 28 is the PREEMPT_ACTIVE flag. )
19  *
20  * PREEMPT_MASK: 0x000000ff
21  * SOFTIRQ_MASK: 0x0000ff00
22  * HARDIRQ_MASK: 0x0fff0000
23  */
24 #define PREEMPT_BITS    8
25 #define SOFTIRQ_BITS    8
26
27 #ifndef HARDIRQ_BITS
28 #define HARDIRQ_BITS    12
29 /*
30  * The hardirq mask has to be large enough to have space for potentially
31  * all IRQ sources in the system nesting on a single CPU.
32  */
33 #if (1 << HARDIRQ_BITS) < NR_IRQS
34 # error HARDIRQ_BITS is too low!
35 #endif
36 #endif
37
38 #define PREEMPT_SHIFT   0
39 #define SOFTIRQ_SHIFT   (PREEMPT_SHIFT + PREEMPT_BITS)
40 #define HARDIRQ_SHIFT   (SOFTIRQ_SHIFT + SOFTIRQ_BITS)
41
42 #define __IRQ_MASK(x)   ((1UL << (x))-1)
43
44 #define PREEMPT_MASK    (__IRQ_MASK(PREEMPT_BITS) << PREEMPT_SHIFT)
45 #define HARDIRQ_MASK    (__IRQ_MASK(HARDIRQ_BITS) << HARDIRQ_SHIFT)
46 #define SOFTIRQ_MASK    (__IRQ_MASK(SOFTIRQ_BITS) << SOFTIRQ_SHIFT)
47
48 #define PREEMPT_OFFSET  (1UL << PREEMPT_SHIFT)
49 #define SOFTIRQ_OFFSET  (1UL << SOFTIRQ_SHIFT)
50 #define HARDIRQ_OFFSET  (1UL << HARDIRQ_SHIFT)
51
52 #define hardirq_count() (preempt_count() & HARDIRQ_MASK)
53 #define softirq_count() (preempt_count() & SOFTIRQ_MASK)
54 #define irq_count()     (preempt_count() & (HARDIRQ_MASK | SOFTIRQ_MASK))
55
56 /*
57  * Are we doing bottom half or hardware interrupt processing?
58  * Are we in a softirq context? Interrupt context?
59  */
60 #define in_irq()                (hardirq_count())
61 #define in_softirq()            (softirq_count())
62 #define in_interrupt()          (irq_count())
63
64 #ifdef CONFIG_PREEMPT
65 # define in_atomic()    ((preempt_count() & ~PREEMPT_ACTIVE) != kernel_locked())
66 # define preemptible()  (preempt_count() == 0 && !irqs_disabled())
67 # define IRQ_EXIT_OFFSET (HARDIRQ_OFFSET-1)
68 #else
69 # define in_atomic()    (preempt_count() != 0)
70 # define preemptible()  0
71 # define IRQ_EXIT_OFFSET HARDIRQ_OFFSET
72 #endif
73
74 #ifdef CONFIG_SMP
75 extern void synchronize_irq(unsigned int irq);
76 #else
77 # define synchronize_irq(irq)   barrier()
78 #endif
79
80 #ifdef CONFIG_GENERIC_HARDIRQS
81 #define nmi_enter()             (preempt_count() += HARDIRQ_OFFSET)
82 #define nmi_exit()              (preempt_count() -= HARDIRQ_OFFSET)
83
84 #define irq_enter()             (preempt_count() += HARDIRQ_OFFSET)
85 extern void irq_exit(void);
86 #endif
87
88 #endif /* LINUX_HARDIRQ_H */