4fe740bf4eae2299ecca76b1b7a8ff50af9c4cd5
[sfrench/cifs-2.6.git] / include / linux / irqflags.h
1 /*
2  * include/linux/irqflags.h
3  *
4  * IRQ flags tracing: follow the state of the hardirq and softirq flags and
5  * provide callbacks for transitions between ON and OFF states.
6  *
7  * This file gets included from lowlevel asm headers too, to provide
8  * wrapped versions of the local_irq_*() APIs, based on the
9  * raw_local_irq_*() macros from the lowlevel headers.
10  */
11 #ifndef _LINUX_TRACE_IRQFLAGS_H
12 #define _LINUX_TRACE_IRQFLAGS_H
13
14 #define BUILD_CHECK_IRQ_FLAGS(flags)                                    \
15         do {                                                            \
16                 BUILD_BUG_ON(sizeof(flags) != sizeof(unsigned long));   \
17                 typecheck(unsigned long, flags);                        \
18         } while (0)
19
20 #ifdef CONFIG_TRACE_IRQFLAGS
21   extern void trace_hardirqs_on(void);
22   extern void trace_hardirqs_off(void);
23   extern void trace_softirqs_on(unsigned long ip);
24   extern void trace_softirqs_off(unsigned long ip);
25 # define trace_hardirq_context(p)       ((p)->hardirq_context)
26 # define trace_softirq_context(p)       ((p)->softirq_context)
27 # define trace_hardirqs_enabled(p)      ((p)->hardirqs_enabled)
28 # define trace_softirqs_enabled(p)      ((p)->softirqs_enabled)
29 # define trace_hardirq_enter()  do { current->hardirq_context++; } while (0)
30 # define trace_hardirq_exit()   do { current->hardirq_context--; } while (0)
31 # define trace_softirq_enter()  do { current->softirq_context++; } while (0)
32 # define trace_softirq_exit()   do { current->softirq_context--; } while (0)
33 # define INIT_TRACE_IRQFLAGS    .softirqs_enabled = 1,
34 #else
35 # define trace_hardirqs_on()            do { } while (0)
36 # define trace_hardirqs_off()           do { } while (0)
37 # define trace_softirqs_on(ip)          do { } while (0)
38 # define trace_softirqs_off(ip)         do { } while (0)
39 # define trace_hardirq_context(p)       0
40 # define trace_softirq_context(p)       0
41 # define trace_hardirqs_enabled(p)      0
42 # define trace_softirqs_enabled(p)      0
43 # define trace_hardirq_enter()          do { } while (0)
44 # define trace_hardirq_exit()           do { } while (0)
45 # define trace_softirq_enter()          do { } while (0)
46 # define trace_softirq_exit()           do { } while (0)
47 # define INIT_TRACE_IRQFLAGS
48 #endif
49
50 #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
51
52 #include <asm/irqflags.h>
53
54 #define local_irq_enable() \
55         do { trace_hardirqs_on(); raw_local_irq_enable(); } while (0)
56 #define local_irq_disable() \
57         do { raw_local_irq_disable(); trace_hardirqs_off(); } while (0)
58 #define local_irq_save(flags) \
59         do {                                    \
60                 BUILD_CHECK_IRQ_FLAGS(flags);   \
61                 raw_local_irq_save(flags);      \
62                 trace_hardirqs_off();           \
63         } while (0)
64
65 #define local_irq_restore(flags)                                \
66         do {                                                    \
67                 BUILD_CHECK_IRQ_FLAGS(flags);                   \
68                 if (raw_irqs_disabled_flags(flags)) {           \
69                         raw_local_irq_restore(flags);           \
70                         trace_hardirqs_off();                   \
71                 } else {                                        \
72                         trace_hardirqs_on();                    \
73                         raw_local_irq_restore(flags);           \
74                 }                                               \
75         } while (0)
76 #else /* !CONFIG_TRACE_IRQFLAGS_SUPPORT */
77 /*
78  * The local_irq_*() APIs are equal to the raw_local_irq*()
79  * if !TRACE_IRQFLAGS.
80  */
81 # define raw_local_irq_disable()        local_irq_disable()
82 # define raw_local_irq_enable()         local_irq_enable()
83 # define raw_local_irq_save(flags)              \
84         do {                                    \
85                 BUILD_CHECK_IRQ_FLAGS(flags);   \
86                 local_irq_save(flags);          \
87         } while (0)
88 # define raw_local_irq_restore(flags)           \
89         do {                                    \
90                 BUILD_CHECK_IRQ_FLAGS(flags);   \
91                 local_irq_restore(flags);       \
92         } while (0)
93 #endif /* CONFIG_TRACE_IRQFLAGS_SUPPORT */
94
95 #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
96 #define safe_halt()                                             \
97         do {                                                    \
98                 trace_hardirqs_on();                            \
99                 raw_safe_halt();                                \
100         } while (0)
101
102 #define local_save_flags(flags)                 \
103         do {                                    \
104                 BUILD_CHECK_IRQ_FLAGS(flags);   \
105                 raw_local_save_flags(flags);    \
106         } while (0)
107
108 #define irqs_disabled()                                         \
109 ({                                                              \
110         unsigned long flags;                                    \
111                                                                 \
112         raw_local_save_flags(flags);                            \
113         raw_irqs_disabled_flags(flags);                         \
114 })
115
116 #define irqs_disabled_flags(flags)      \
117 ({                                      \
118         BUILD_CHECK_IRQ_FLAGS(flags);   \
119         raw_irqs_disabled_flags(flags); \
120 })
121 #endif          /* CONFIG_X86 */
122
123 #endif