patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / include / asm-sparc / hardirq.h
1 /* hardirq.h: 32-bit Sparc hard IRQ support.
2  *
3  * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
4  * Copyright (C) 1998-2000 Anton Blanchard (anton@samba.org)
5  */
6
7 #ifndef __SPARC_HARDIRQ_H
8 #define __SPARC_HARDIRQ_H
9
10 #include <linux/config.h>
11 #include <linux/threads.h>
12 #include <linux/spinlock.h>
13 #include <linux/cache.h>
14
15 /* entry.S is sensitive to the offsets of these fields */ /* XXX P3 Is it? */
16 typedef struct {
17         unsigned int __softirq_pending;
18 } ____cacheline_aligned irq_cpustat_t;
19
20 #include <linux/irq_cpustat.h>  /* Standard mappings for irq_cpustat_t above */
21
22 /*
23  * We put the hardirq and softirq counter into the preemption
24  * counter. The bitmask has the following meaning:
25  *
26  * - bits 0-7 are the preemption count (max preemption depth: 256)
27  * - bits 8-15 are the softirq count (max # of softirqs: 256)
28  * - bits 16-23 are the hardirq count (max # of hardirqs: 256)
29  *
30  * - ( bit 26 is the PREEMPT_ACTIVE flag. )
31  *
32  * PREEMPT_MASK: 0x000000ff
33  * SOFTIRQ_MASK: 0x0000ff00
34  * HARDIRQ_MASK: 0x00ff0000
35  */
36
37 #define PREEMPT_BITS    8
38 #define SOFTIRQ_BITS    8
39 #define HARDIRQ_BITS    8
40
41 #define PREEMPT_SHIFT   0
42 #define SOFTIRQ_SHIFT   (PREEMPT_SHIFT + PREEMPT_BITS)
43 #define HARDIRQ_SHIFT   (SOFTIRQ_SHIFT + SOFTIRQ_BITS)
44
45 #define __MASK(x)       ((1UL << (x))-1)
46
47 #define PREEMPT_MASK    (__MASK(PREEMPT_BITS) << PREEMPT_SHIFT)
48 #define HARDIRQ_MASK    (__MASK(HARDIRQ_BITS) << HARDIRQ_SHIFT)
49 #define SOFTIRQ_MASK    (__MASK(SOFTIRQ_BITS) << SOFTIRQ_SHIFT)
50
51 #define hardirq_count() (preempt_count() & HARDIRQ_MASK)
52 #define softirq_count() (preempt_count() & SOFTIRQ_MASK)
53 #define irq_count()     (preempt_count() & (HARDIRQ_MASK | SOFTIRQ_MASK))
54
55 #define PREEMPT_OFFSET  (1UL << PREEMPT_SHIFT)
56 #define SOFTIRQ_OFFSET  (1UL << SOFTIRQ_SHIFT)
57 #define HARDIRQ_OFFSET  (1UL << HARDIRQ_SHIFT)
58
59 /*
60  * Are we doing bottom half or hardware interrupt processing?
61  * Are we in a softirq context? Interrupt context?
62  */
63 #define in_irq()                (hardirq_count())
64 #define in_softirq()            (softirq_count())
65 #define in_interrupt()          (irq_count())
66
67
68 #define hardirq_trylock()       (!in_interrupt())
69 #define hardirq_endlock()       do { } while (0)
70
71 #define irq_enter()             (preempt_count() += HARDIRQ_OFFSET)
72
73 #ifdef CONFIG_PREEMPT
74 #include <linux/smp_lock.h>
75 # define in_atomic()    ((preempt_count() & ~PREEMPT_ACTIVE) != kernel_locked())
76 # define IRQ_EXIT_OFFSET (HARDIRQ_OFFSET-1)
77 #else
78 # define in_atomic()    (preempt_count() != 0)
79 # define IRQ_EXIT_OFFSET HARDIRQ_OFFSET
80 #endif
81 #define irq_exit()                                                      \
82 do {                                                                    \
83                 preempt_count() -= IRQ_EXIT_OFFSET;                     \
84                 if (!in_interrupt() && softirq_pending(smp_processor_id())) \
85                         do_softirq();                                   \
86                 preempt_enable_no_resched();                            \
87 } while (0)
88
89 #ifndef CONFIG_SMP
90 # define synchronize_irq(irq)   barrier()
91 #else /* SMP */
92 extern void synchronize_irq(unsigned int irq);
93 #endif /* SMP */
94
95 #endif /* __SPARC_HARDIRQ_H */