Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / 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 #include <linux/typecheck.h>
15 #include <asm/irqflags.h>
16
17 #ifdef CONFIG_TRACE_IRQFLAGS
18   extern void trace_softirqs_on(unsigned long ip);
19   extern void trace_softirqs_off(unsigned long ip);
20   extern void trace_hardirqs_on(void);
21   extern void trace_hardirqs_off(void);
22 # define trace_hardirq_context(p)       ((p)->hardirq_context)
23 # define trace_softirq_context(p)       ((p)->softirq_context)
24 # define trace_hardirqs_enabled(p)      ((p)->hardirqs_enabled)
25 # define trace_softirqs_enabled(p)      ((p)->softirqs_enabled)
26 # define trace_hardirq_enter()  do { current->hardirq_context++; } while (0)
27 # define trace_hardirq_exit()   do { current->hardirq_context--; } while (0)
28 # define INIT_TRACE_IRQFLAGS    .softirqs_enabled = 1,
29 #else
30 # define trace_hardirqs_on()            do { } while (0)
31 # define trace_hardirqs_off()           do { } while (0)
32 # define trace_softirqs_on(ip)          do { } while (0)
33 # define trace_softirqs_off(ip)         do { } while (0)
34 # define trace_hardirq_context(p)       0
35 # define trace_softirq_context(p)       0
36 # define trace_hardirqs_enabled(p)      0
37 # define trace_softirqs_enabled(p)      0
38 # define trace_hardirq_enter()          do { } while (0)
39 # define trace_hardirq_exit()           do { } while (0)
40 # define INIT_TRACE_IRQFLAGS
41 #endif
42
43 #if defined(CONFIG_TRACE_IRQFLAGS) && !defined(CONFIG_PREEMPT_RT_FULL)
44 # define lockdep_softirq_enter() do { current->softirq_context++; } while (0)
45 # define lockdep_softirq_exit()  do { current->softirq_context--; } while (0)
46 #else
47 # define lockdep_softirq_enter()        do { } while (0)
48 # define lockdep_softirq_exit()         do { } while (0)
49 #endif
50
51 #if defined(CONFIG_IRQSOFF_TRACER) || \
52         defined(CONFIG_PREEMPT_TRACER)
53  extern void stop_critical_timings(void);
54  extern void start_critical_timings(void);
55 #else
56 # define stop_critical_timings() do { } while (0)
57 # define start_critical_timings() do { } while (0)
58 #endif
59
60 /*
61  * Wrap the arch provided IRQ routines to provide appropriate checks.
62  */
63 #define raw_local_irq_disable()         arch_local_irq_disable()
64 #define raw_local_irq_enable()          arch_local_irq_enable()
65 #define raw_local_irq_save(flags)                       \
66         do {                                            \
67                 typecheck(unsigned long, flags);        \
68                 flags = arch_local_irq_save();          \
69         } while (0)
70 #define raw_local_irq_restore(flags)                    \
71         do {                                            \
72                 typecheck(unsigned long, flags);        \
73                 arch_local_irq_restore(flags);          \
74         } while (0)
75 #define raw_local_save_flags(flags)                     \
76         do {                                            \
77                 typecheck(unsigned long, flags);        \
78                 flags = arch_local_save_flags();        \
79         } while (0)
80 #define raw_irqs_disabled_flags(flags)                  \
81         ({                                              \
82                 typecheck(unsigned long, flags);        \
83                 arch_irqs_disabled_flags(flags);        \
84         })
85 #define raw_irqs_disabled()             (arch_irqs_disabled())
86 #define raw_safe_halt()                 arch_safe_halt()
87
88 /*
89  * The local_irq_*() APIs are equal to the raw_local_irq*()
90  * if !TRACE_IRQFLAGS.
91  */
92 #ifdef CONFIG_TRACE_IRQFLAGS
93 #define local_irq_enable() \
94         do { trace_hardirqs_on(); raw_local_irq_enable(); } while (0)
95 #define local_irq_disable() \
96         do { raw_local_irq_disable(); trace_hardirqs_off(); } while (0)
97 #define local_irq_save(flags)                           \
98         do {                                            \
99                 raw_local_irq_save(flags);              \
100                 trace_hardirqs_off();                   \
101         } while (0)
102
103
104 #define local_irq_restore(flags)                        \
105         do {                                            \
106                 if (raw_irqs_disabled_flags(flags)) {   \
107                         raw_local_irq_restore(flags);   \
108                         trace_hardirqs_off();           \
109                 } else {                                \
110                         trace_hardirqs_on();            \
111                         raw_local_irq_restore(flags);   \
112                 }                                       \
113         } while (0)
114
115 #define safe_halt()                             \
116         do {                                    \
117                 trace_hardirqs_on();            \
118                 raw_safe_halt();                \
119         } while (0)
120
121
122 #else /* !CONFIG_TRACE_IRQFLAGS */
123
124 #define local_irq_enable()      do { raw_local_irq_enable(); } while (0)
125 #define local_irq_disable()     do { raw_local_irq_disable(); } while (0)
126 #define local_irq_save(flags)                                   \
127         do {                                                    \
128                 raw_local_irq_save(flags);                      \
129         } while (0)
130 #define local_irq_restore(flags) do { raw_local_irq_restore(flags); } while (0)
131 #define safe_halt()             do { raw_safe_halt(); } while (0)
132
133 #endif /* CONFIG_TRACE_IRQFLAGS */
134
135 #define local_save_flags(flags) raw_local_save_flags(flags)
136
137 /*
138  * Some architectures don't define arch_irqs_disabled(), so even if either
139  * definition would be fine we need to use different ones for the time being
140  * to avoid build issues.
141  */
142 #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
143 #define irqs_disabled()                                 \
144         ({                                              \
145                 unsigned long _flags;                   \
146                 raw_local_save_flags(_flags);           \
147                 raw_irqs_disabled_flags(_flags);        \
148         })
149 #else /* !CONFIG_TRACE_IRQFLAGS_SUPPORT */
150 #define irqs_disabled() raw_irqs_disabled()
151 #endif /* CONFIG_TRACE_IRQFLAGS_SUPPORT */
152
153 #define irqs_disabled_flags(flags) raw_irqs_disabled_flags(flags)
154
155 /*
156  * local_irq* variants depending on RT/!RT
157  */
158 #ifdef CONFIG_PREEMPT_RT_FULL
159 # define local_irq_disable_nort()       do { } while (0)
160 # define local_irq_enable_nort()        do { } while (0)
161 # define local_irq_save_nort(flags)     local_save_flags(flags)
162 # define local_irq_restore_nort(flags)  (void)(flags)
163 # define local_irq_disable_rt()         local_irq_disable()
164 # define local_irq_enable_rt()          local_irq_enable()
165 #else
166 # define local_irq_disable_nort()       local_irq_disable()
167 # define local_irq_enable_nort()        local_irq_enable()
168 # define local_irq_save_nort(flags)     local_irq_save(flags)
169 # define local_irq_restore_nort(flags)  local_irq_restore(flags)
170 # define local_irq_disable_rt()         do { } while (0)
171 # define local_irq_enable_rt()          do { } while (0)
172 #endif
173
174 #endif