ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / asm-ppc64 / hardirq.h
1 #ifdef __KERNEL__
2 #ifndef __ASM_HARDIRQ_H
3 #define __ASM_HARDIRQ_H
4
5 /*
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version
9  * 2 of the License, or (at your option) any later version.
10  */
11
12 #include <linux/config.h>
13 #include <linux/cache.h>
14 #include <linux/preempt.h>
15
16 typedef struct {
17         unsigned int __softirq_pending;
18         struct task_struct * __ksoftirqd_task;
19 } ____cacheline_aligned irq_cpustat_t;
20
21 #include <linux/irq_cpustat.h>  /* Standard mappings for irq_cpustat_t above */
22
23 /*
24  * We put the hardirq and softirq counter into the preemption
25  * counter. The bitmask has the following meaning:
26  *
27  * - bits 0-7 are the preemption count (max preemption depth: 256)
28  * - bits 8-15 are the softirq count (max # of softirqs: 256)
29  * - bits 16-24 are the hardirq count (max # of hardirqs: 512)
30  *
31  * - ( bit 26 is the PREEMPT_ACTIVE flag. )
32  *
33  * PREEMPT_MASK: 0x000000ff
34  * SOFTIRQ_MASK: 0x0000ff00
35  * HARDIRQ_MASK: 0x01ff0000
36  */
37
38 #define PREEMPT_BITS    8
39 #define SOFTIRQ_BITS    8
40 #define HARDIRQ_BITS    9
41
42 #define PREEMPT_SHIFT   0
43 #define SOFTIRQ_SHIFT   (PREEMPT_SHIFT + PREEMPT_BITS)
44 #define HARDIRQ_SHIFT   (SOFTIRQ_SHIFT + SOFTIRQ_BITS)
45
46 #define __HARDIRQ_MASK(x)       ((1UL << (x))-1)
47
48 #define PREEMPT_MASK    (__HARDIRQ_MASK(PREEMPT_BITS) << PREEMPT_SHIFT)
49 #define SOFTIRQ_MASK    (__HARDIRQ_MASK(SOFTIRQ_BITS) << SOFTIRQ_SHIFT)
50 #define HARDIRQ_MASK    (__HARDIRQ_MASK(HARDIRQ_BITS) << 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 #define PREEMPT_OFFSET  (1UL << PREEMPT_SHIFT)
57 #define SOFTIRQ_OFFSET  (1UL << SOFTIRQ_SHIFT)
58 #define HARDIRQ_OFFSET  (1UL << HARDIRQ_SHIFT)
59
60 /*
61  * The hardirq mask has to be large enough to have
62  * space for potentially all IRQ sources in the system
63  * nesting on a single CPU:
64  */
65 #if (1 << HARDIRQ_BITS) < NR_IRQS
66 # error HARDIRQ_BITS is too low!
67 #endif
68
69 /*
70  * Are we doing bottom half or hardware interrupt processing?
71  * Are we in a softirq context? Interrupt context?
72  */
73 #define in_irq()                (hardirq_count())
74 #define in_softirq()            (softirq_count())
75 #define in_interrupt()          (irq_count())
76
77
78 #define hardirq_trylock()       (!in_interrupt())
79 #define hardirq_endlock()       do { } while (0)
80
81 #define irq_enter()             (preempt_count() += HARDIRQ_OFFSET)
82
83 #ifdef CONFIG_PREEMPT
84 # define in_atomic()    ((preempt_count() & ~PREEMPT_ACTIVE) != kernel_locked())
85 # define IRQ_EXIT_OFFSET (HARDIRQ_OFFSET-1)
86 #else
87 # define in_atomic()    (preempt_count() != 0)
88 # define IRQ_EXIT_OFFSET HARDIRQ_OFFSET
89 #endif
90 #define irq_exit()                                                      \
91 do {                                                                    \
92                 preempt_count() -= IRQ_EXIT_OFFSET;                     \
93                 if (!in_interrupt() && softirq_pending(smp_processor_id())) \
94                         do_softirq();                                   \
95                 preempt_enable_no_resched();                            \
96 } while (0)
97
98 #ifndef CONFIG_SMP
99 # define synchronize_irq(irq)   barrier()
100 #else
101   extern void synchronize_irq(unsigned int irq);
102 #endif /* CONFIG_SMP */
103
104 #endif /* __KERNEL__ */
105         
106 #endif /* __ASM_HARDIRQ_H */