]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - kernel/irq/internals.h
Merge tag 'irqchip-4.13' of git://git.kernel.org/pub/scm/linux/kernel/git/maz/arm...
[mirror_ubuntu-artful-kernel.git] / kernel / irq / internals.h
CommitLineData
1da177e4
LT
1/*
2 * IRQ subsystem internal functions and variables:
dbec07ba
TG
3 *
4 * Do not ever include this file from anything else than
5 * kernel/irq/. Do not even think about using any information outside
6 * of this file for your non core code.
1da177e4 7 */
e144710b 8#include <linux/irqdesc.h>
8f945a33 9#include <linux/kernel_stat.h>
be45beb2 10#include <linux/pm_runtime.h>
1da177e4 11
c1ee6264
TG
12#ifdef CONFIG_SPARSE_IRQ
13# define IRQ_BITMAP_BITS (NR_IRQS + 8196)
14#else
15# define IRQ_BITMAP_BITS NR_IRQS
16#endif
17
dbec07ba
TG
18#define istate core_internal_state__do_not_mess_with_it
19
2329abfa 20extern bool noirqdebug;
1da177e4 21
e509bd7d
MW
22extern struct irqaction chained_action;
23
1535dfac
TG
24/*
25 * Bits used by threaded handlers:
26 * IRQTF_RUNTHREAD - signals that the interrupt handler thread should run
1535dfac
TG
27 * IRQTF_WARNED - warning "IRQ_WAKE_THREAD w/o thread_fn" has been printed
28 * IRQTF_AFFINITY - irq thread is requested to adjust affinity
8d32a307 29 * IRQTF_FORCED_THREAD - irq action is force threaded
1535dfac
TG
30 */
31enum {
32 IRQTF_RUNTHREAD,
1535dfac
TG
33 IRQTF_WARNED,
34 IRQTF_AFFINITY,
8d32a307 35 IRQTF_FORCED_THREAD,
1535dfac
TG
36};
37
bd062e76 38/*
a257954b 39 * Bit masks for desc->core_internal_state__do_not_mess_with_it
bd062e76
TG
40 *
41 * IRQS_AUTODETECT - autodetection in progress
7acdd53e
TG
42 * IRQS_SPURIOUS_DISABLED - was disabled due to spurious interrupt
43 * detection
6954b75b 44 * IRQS_POLL_INPROGRESS - polling in progress
3d67baec 45 * IRQS_ONESHOT - irq is not unmasked in primary handler
163ef309
TG
46 * IRQS_REPLAY - irq is replayed
47 * IRQS_WAITING - irq is waiting
2a0d6fb3 48 * IRQS_PENDING - irq is pending and replayed later
c531e836 49 * IRQS_SUSPENDED - irq is suspended
bd062e76
TG
50 */
51enum {
52 IRQS_AUTODETECT = 0x00000001,
7acdd53e 53 IRQS_SPURIOUS_DISABLED = 0x00000002,
6954b75b 54 IRQS_POLL_INPROGRESS = 0x00000008,
3d67baec 55 IRQS_ONESHOT = 0x00000020,
163ef309
TG
56 IRQS_REPLAY = 0x00000040,
57 IRQS_WAITING = 0x00000080,
2a0d6fb3 58 IRQS_PENDING = 0x00000200,
c531e836 59 IRQS_SUSPENDED = 0x00000800,
bd062e76
TG
60};
61
1ce6068d
TG
62#include "debug.h"
63#include "settings.h"
64
a1ff541a 65extern int __irq_set_trigger(struct irq_desc *desc, unsigned long flags);
79ff1cda
JL
66extern void __disable_irq(struct irq_desc *desc);
67extern void __enable_irq(struct irq_desc *desc);
0c5d1eb7 68
4cde9c6b
TG
69#define IRQ_RESEND true
70#define IRQ_NORESEND false
71
72#define IRQ_START_FORCE true
73#define IRQ_START_COND false
74
75extern int irq_startup(struct irq_desc *desc, bool resend, bool force);
76
46999238 77extern void irq_shutdown(struct irq_desc *desc);
87923470
TG
78extern void irq_enable(struct irq_desc *desc);
79extern void irq_disable(struct irq_desc *desc);
31d9d9b6
MZ
80extern void irq_percpu_enable(struct irq_desc *desc, unsigned int cpu);
81extern void irq_percpu_disable(struct irq_desc *desc, unsigned int cpu);
d4d5e089
TG
82extern void mask_irq(struct irq_desc *desc);
83extern void unmask_irq(struct irq_desc *desc);
328a4978 84extern void unmask_threaded_irq(struct irq_desc *desc);
46999238 85
f63b6a05
TG
86#ifdef CONFIG_SPARSE_IRQ
87static inline void irq_mark_irq(unsigned int irq) { }
88#else
89extern void irq_mark_irq(unsigned int irq);
90#endif
91
85ac16d0 92extern void init_kstat_irqs(struct irq_desc *desc, int node, int nr);
0fa0ebbf 93
edd14cfe 94irqreturn_t __handle_irq_event_percpu(struct irq_desc *desc, unsigned int *flags);
71f64340 95irqreturn_t handle_irq_event_percpu(struct irq_desc *desc);
4912609f
TG
96irqreturn_t handle_irq_event(struct irq_desc *desc);
97
e144710b 98/* Resending of interrupts :*/
0798abeb 99void check_irq_resend(struct irq_desc *desc);
fe200ae4 100bool irq_wait_for_poll(struct irq_desc *desc);
a92444c6 101void __irq_wake_thread(struct irq_desc *desc, struct irqaction *action);
e144710b 102
1da177e4 103#ifdef CONFIG_PROC_FS
2c6927a3 104extern void register_irq_proc(unsigned int irq, struct irq_desc *desc);
13bfe99e 105extern void unregister_irq_proc(unsigned int irq, struct irq_desc *desc);
1da177e4
LT
106extern void register_handler_proc(unsigned int irq, struct irqaction *action);
107extern void unregister_handler_proc(unsigned int irq, struct irqaction *action);
108#else
2c6927a3 109static inline void register_irq_proc(unsigned int irq, struct irq_desc *desc) { }
13bfe99e 110static inline void unregister_irq_proc(unsigned int irq, struct irq_desc *desc) { }
1da177e4
LT
111static inline void register_handler_proc(unsigned int irq,
112 struct irqaction *action) { }
113static inline void unregister_handler_proc(unsigned int irq,
114 struct irqaction *action) { }
115#endif
116
9c255583
TG
117extern bool irq_can_set_affinity_usr(unsigned int irq);
118
cba4235e 119extern int irq_select_affinity_usr(unsigned int irq);
f6d87f4b 120
591d2fb0 121extern void irq_set_thread_affinity(struct irq_desc *desc);
57b150cc 122
818b0f3b
JL
123extern int irq_do_set_affinity(struct irq_data *data,
124 const struct cpumask *dest, bool force);
125
43564bd9
TG
126#ifdef CONFIG_SMP
127extern int irq_setup_affinity(struct irq_desc *desc);
128#else
129static inline int irq_setup_affinity(struct irq_desc *desc) { return 0; }
130#endif
131
70aedd24 132/* Inline functions for support of irq chips on slow busses */
3876ec9e 133static inline void chip_bus_lock(struct irq_desc *desc)
70aedd24 134{
3876ec9e
TG
135 if (unlikely(desc->irq_data.chip->irq_bus_lock))
136 desc->irq_data.chip->irq_bus_lock(&desc->irq_data);
70aedd24
TG
137}
138
3876ec9e 139static inline void chip_bus_sync_unlock(struct irq_desc *desc)
70aedd24 140{
3876ec9e
TG
141 if (unlikely(desc->irq_data.chip->irq_bus_sync_unlock))
142 desc->irq_data.chip->irq_bus_sync_unlock(&desc->irq_data);
70aedd24
TG
143}
144
31d9d9b6
MZ
145#define _IRQ_DESC_CHECK (1 << 0)
146#define _IRQ_DESC_PERCPU (1 << 1)
147
148#define IRQ_GET_DESC_CHECK_GLOBAL (_IRQ_DESC_CHECK)
149#define IRQ_GET_DESC_CHECK_PERCPU (_IRQ_DESC_CHECK | _IRQ_DESC_PERCPU)
150
f944b5a7
DL
151#define for_each_action_of_desc(desc, act) \
152 for (act = desc->act; act; act = act->next)
153
d5eb4ad2 154struct irq_desc *
31d9d9b6
MZ
155__irq_get_desc_lock(unsigned int irq, unsigned long *flags, bool bus,
156 unsigned int check);
d5eb4ad2
TG
157void __irq_put_desc_unlock(struct irq_desc *desc, unsigned long flags, bool bus);
158
159static inline struct irq_desc *
31d9d9b6 160irq_get_desc_buslock(unsigned int irq, unsigned long *flags, unsigned int check)
d5eb4ad2 161{
31d9d9b6 162 return __irq_get_desc_lock(irq, flags, true, check);
d5eb4ad2
TG
163}
164
165static inline void
166irq_put_desc_busunlock(struct irq_desc *desc, unsigned long flags)
167{
168 __irq_put_desc_unlock(desc, flags, true);
169}
170
171static inline struct irq_desc *
31d9d9b6 172irq_get_desc_lock(unsigned int irq, unsigned long *flags, unsigned int check)
d5eb4ad2 173{
31d9d9b6 174 return __irq_get_desc_lock(irq, flags, false, check);
d5eb4ad2
TG
175}
176
177static inline void
178irq_put_desc_unlock(struct irq_desc *desc, unsigned long flags)
179{
180 __irq_put_desc_unlock(desc, flags, false);
181}
182
b354286e
BF
183#define __irqd_to_state(d) ACCESS_PRIVATE((d)->common, state_use_accessors)
184
087cdfb6
TG
185static inline unsigned int irqd_get(struct irq_data *d)
186{
187 return __irqd_to_state(d);
188}
189
f230b6d5
TG
190/*
191 * Manipulation functions for irq_data.state
192 */
193static inline void irqd_set_move_pending(struct irq_data *d)
194{
0d0b4c86 195 __irqd_to_state(d) |= IRQD_SETAFFINITY_PENDING;
f230b6d5
TG
196}
197
198static inline void irqd_clr_move_pending(struct irq_data *d)
199{
0d0b4c86 200 __irqd_to_state(d) &= ~IRQD_SETAFFINITY_PENDING;
f230b6d5 201}
a005677b 202
54fdf6a0
TG
203static inline void irqd_set_managed_shutdown(struct irq_data *d)
204{
205 __irqd_to_state(d) |= IRQD_MANAGED_SHUTDOWN;
206}
207
208static inline void irqd_clr_managed_shutdown(struct irq_data *d)
209{
210 __irqd_to_state(d) &= ~IRQD_MANAGED_SHUTDOWN;
211}
212
a005677b
TG
213static inline void irqd_clear(struct irq_data *d, unsigned int mask)
214{
0d0b4c86 215 __irqd_to_state(d) &= ~mask;
a005677b
TG
216}
217
218static inline void irqd_set(struct irq_data *d, unsigned int mask)
219{
0d0b4c86 220 __irqd_to_state(d) |= mask;
a005677b
TG
221}
222
2bdd1055
TG
223static inline bool irqd_has_set(struct irq_data *d, unsigned int mask)
224{
0d0b4c86 225 return __irqd_to_state(d) & mask;
2bdd1055 226}
8f945a33 227
b354286e
BF
228#undef __irqd_to_state
229
b51bf95c 230static inline void kstat_incr_irqs_this_cpu(struct irq_desc *desc)
8f945a33
TG
231{
232 __this_cpu_inc(*desc->kstat_irqs);
233 __this_cpu_inc(kstat.irqs_sum);
234}
cab303be 235
6783011b
JL
236static inline int irq_desc_get_node(struct irq_desc *desc)
237{
449e9cae 238 return irq_common_data_get_node(&desc->irq_common_data);
6783011b
JL
239}
240
4717f133
GS
241static inline int irq_desc_is_chained(struct irq_desc *desc)
242{
243 return (desc->action && desc->action == &chained_action);
244}
245
cab303be 246#ifdef CONFIG_PM_SLEEP
9ce7a258 247bool irq_pm_check_wakeup(struct irq_desc *desc);
cab303be
TG
248void irq_pm_install_action(struct irq_desc *desc, struct irqaction *action);
249void irq_pm_remove_action(struct irq_desc *desc, struct irqaction *action);
250#else
9ce7a258 251static inline bool irq_pm_check_wakeup(struct irq_desc *desc) { return false; }
cab303be
TG
252static inline void
253irq_pm_install_action(struct irq_desc *desc, struct irqaction *action) { }
254static inline void
255irq_pm_remove_action(struct irq_desc *desc, struct irqaction *action) { }
256#endif
f1602039
BG
257
258#ifdef CONFIG_GENERIC_IRQ_CHIP
259void irq_init_generic_chip(struct irq_chip_generic *gc, const char *name,
260 int num_ct, unsigned int irq_base,
261 void __iomem *reg_base, irq_flow_handler_t handler);
262#else
263static inline void
264irq_init_generic_chip(struct irq_chip_generic *gc, const char *name,
265 int num_ct, unsigned int irq_base,
266 void __iomem *reg_base, irq_flow_handler_t handler) { }
267#endif /* CONFIG_GENERIC_IRQ_CHIP */
087cdfb6 268
137221df
CH
269#ifdef CONFIG_GENERIC_PENDING_IRQ
270static inline bool irq_can_move_pcntxt(struct irq_data *data)
271{
272 return irqd_can_move_in_process_context(data);
273}
274static inline bool irq_move_pending(struct irq_data *data)
275{
276 return irqd_is_setaffinity_pending(data);
277}
278static inline void
279irq_copy_pending(struct irq_desc *desc, const struct cpumask *mask)
280{
281 cpumask_copy(desc->pending_mask, mask);
282}
283static inline void
284irq_get_pending(struct cpumask *mask, struct irq_desc *desc)
285{
286 cpumask_copy(mask, desc->pending_mask);
287}
f0383c24
TG
288static inline struct cpumask *irq_desc_get_pending_mask(struct irq_desc *desc)
289{
290 return desc->pending_mask;
291}
36d84fb4 292bool irq_fixup_move_pending(struct irq_desc *desc, bool force_clear);
137221df
CH
293#else /* CONFIG_GENERIC_PENDING_IRQ */
294static inline bool irq_can_move_pcntxt(struct irq_data *data)
295{
296 return true;
297}
298static inline bool irq_move_pending(struct irq_data *data)
299{
300 return false;
301}
302static inline void
303irq_copy_pending(struct irq_desc *desc, const struct cpumask *mask)
304{
305}
306static inline void
307irq_get_pending(struct cpumask *mask, struct irq_desc *desc)
308{
309}
f0383c24
TG
310static inline struct cpumask *irq_desc_get_pending_mask(struct irq_desc *desc)
311{
312 return NULL;
313}
36d84fb4
TG
314static inline bool irq_fixup_move_pending(struct irq_desc *desc, bool fclear)
315{
316 return false;
317}
f0383c24 318#endif /* !CONFIG_GENERIC_PENDING_IRQ */
137221df 319
087cdfb6
TG
320#ifdef CONFIG_GENERIC_IRQ_DEBUGFS
321void irq_add_debugfs_entry(unsigned int irq, struct irq_desc *desc);
322void irq_remove_debugfs_entry(struct irq_desc *desc);
323# ifdef CONFIG_IRQ_DOMAIN
324void irq_domain_debugfs_init(struct dentry *root);
325# else
326static inline void irq_domain_debugfs_init(struct dentry *root);
327# endif
328#else /* CONFIG_GENERIC_IRQ_DEBUGFS */
329static inline void irq_add_debugfs_entry(unsigned int irq, struct irq_desc *d)
330{
331}
332static inline void irq_remove_debugfs_entry(struct irq_desc *d)
333{
334}
335#endif /* CONFIG_GENERIC_IRQ_DEBUGFS */