blob: bc226e783bd236b1e1a98a523deef673b7d56635 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * IRQ subsystem internal functions and variables:
Thomas Gleixnerdbec07b2011-02-07 20:19:55 +01003 *
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.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
Thomas Gleixnere1447102010-10-01 16:03:45 +02008#include <linux/irqdesc.h>
Thomas Gleixner8f945a32014-02-23 21:40:23 +00009#include <linux/kernel_stat.h>
Jon Hunterbe45beb2016-06-07 16:12:29 +010010#include <linux/pm_runtime.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Thomas Gleixnerc1ee6262011-02-17 17:45:15 +010012#ifdef CONFIG_SPARSE_IRQ
13# define IRQ_BITMAP_BITS (NR_IRQS + 8196)
14#else
15# define IRQ_BITMAP_BITS NR_IRQS
16#endif
17
Thomas Gleixnerdbec07b2011-02-07 20:19:55 +010018#define istate core_internal_state__do_not_mess_with_it
19
Rusty Russell2329abf2012-01-13 09:32:18 +103020extern bool noirqdebug;
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Mika Westerberge509bd72015-10-05 13:12:15 +030022extern struct irqaction chained_action;
23
Thomas Gleixner1535dfa2011-02-07 01:55:43 +010024/*
25 * Bits used by threaded handlers:
26 * IRQTF_RUNTHREAD - signals that the interrupt handler thread should run
Thomas Gleixner1535dfa2011-02-07 01:55:43 +010027 * IRQTF_WARNED - warning "IRQ_WAKE_THREAD w/o thread_fn" has been printed
28 * IRQTF_AFFINITY - irq thread is requested to adjust affinity
Thomas Gleixner8d32a302011-02-23 23:52:23 +000029 * IRQTF_FORCED_THREAD - irq action is force threaded
Thomas Gleixner1535dfa2011-02-07 01:55:43 +010030 */
31enum {
32 IRQTF_RUNTHREAD,
Thomas Gleixner1535dfa2011-02-07 01:55:43 +010033 IRQTF_WARNED,
34 IRQTF_AFFINITY,
Thomas Gleixner8d32a302011-02-23 23:52:23 +000035 IRQTF_FORCED_THREAD,
Thomas Gleixner1535dfa2011-02-07 01:55:43 +010036};
37
Thomas Gleixnerbd062e72011-02-07 20:25:25 +010038/*
Jiang Liua2579542014-05-27 16:07:37 +080039 * Bit masks for desc->core_internal_state__do_not_mess_with_it
Thomas Gleixnerbd062e72011-02-07 20:25:25 +010040 *
41 * IRQS_AUTODETECT - autodetection in progress
Thomas Gleixner7acdd532011-02-07 20:40:54 +010042 * IRQS_SPURIOUS_DISABLED - was disabled due to spurious interrupt
43 * detection
Thomas Gleixner6954b752011-02-07 20:55:35 +010044 * IRQS_POLL_INPROGRESS - polling in progress
Thomas Gleixner3d67bae2011-02-07 21:02:10 +010045 * IRQS_ONESHOT - irq is not unmasked in primary handler
Thomas Gleixner163ef302011-02-08 11:39:15 +010046 * IRQS_REPLAY - irq is replayed
47 * IRQS_WAITING - irq is waiting
Thomas Gleixner2a0d6fb2011-02-08 12:17:57 +010048 * IRQS_PENDING - irq is pending and replayed later
Thomas Gleixnerc531e832011-02-08 12:44:58 +010049 * IRQS_SUSPENDED - irq is suspended
Thomas Gleixnerbd062e72011-02-07 20:25:25 +010050 */
51enum {
52 IRQS_AUTODETECT = 0x00000001,
Thomas Gleixner7acdd532011-02-07 20:40:54 +010053 IRQS_SPURIOUS_DISABLED = 0x00000002,
Thomas Gleixner6954b752011-02-07 20:55:35 +010054 IRQS_POLL_INPROGRESS = 0x00000008,
Thomas Gleixner3d67bae2011-02-07 21:02:10 +010055 IRQS_ONESHOT = 0x00000020,
Thomas Gleixner163ef302011-02-08 11:39:15 +010056 IRQS_REPLAY = 0x00000040,
57 IRQS_WAITING = 0x00000080,
Thomas Gleixner2a0d6fb2011-02-08 12:17:57 +010058 IRQS_PENDING = 0x00000200,
Thomas Gleixnerc531e832011-02-08 12:44:58 +010059 IRQS_SUSPENDED = 0x00000800,
Thomas Gleixnerbd062e72011-02-07 20:25:25 +010060};
61
Thomas Gleixner1ce60682011-02-09 20:44:21 +010062#include "debug.h"
63#include "settings.h"
64
Jiang Liua1ff5412015-06-23 19:47:29 +020065extern int __irq_set_trigger(struct irq_desc *desc, unsigned long flags);
Jiang Liu79ff1cd2015-06-23 19:52:36 +020066extern void __disable_irq(struct irq_desc *desc);
67extern void __enable_irq(struct irq_desc *desc);
David Brownell0c5d1eb2008-10-01 14:46:18 -070068
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +010069extern int irq_startup(struct irq_desc *desc, bool resend);
Thomas Gleixner46999232011-02-02 21:41:14 +000070extern void irq_shutdown(struct irq_desc *desc);
Thomas Gleixner87923472011-02-03 12:27:44 +010071extern void irq_enable(struct irq_desc *desc);
72extern void irq_disable(struct irq_desc *desc);
Marc Zyngier31d9d9b2011-09-23 17:03:06 +010073extern void irq_percpu_enable(struct irq_desc *desc, unsigned int cpu);
74extern void irq_percpu_disable(struct irq_desc *desc, unsigned int cpu);
Thomas Gleixnerd4d5e082011-02-10 13:16:14 +010075extern void mask_irq(struct irq_desc *desc);
76extern void unmask_irq(struct irq_desc *desc);
Thomas Gleixner328a4972014-03-13 19:03:51 +010077extern void unmask_threaded_irq(struct irq_desc *desc);
Thomas Gleixner46999232011-02-02 21:41:14 +000078
Thomas Gleixnerf63b6a02014-05-07 15:44:21 +000079#ifdef CONFIG_SPARSE_IRQ
80static inline void irq_mark_irq(unsigned int irq) { }
81#else
82extern void irq_mark_irq(unsigned int irq);
83#endif
84
Yinghai Lu85ac16d2009-04-27 18:00:38 -070085extern void init_kstat_irqs(struct irq_desc *desc, int node, int nr);
Mike Travis0fa0ebb2009-01-10 22:24:06 -080086
Keith Buschedd14cf2016-06-17 16:00:20 -060087irqreturn_t __handle_irq_event_percpu(struct irq_desc *desc, unsigned int *flags);
Huang Shijie71f64342015-09-02 10:24:55 +080088irqreturn_t handle_irq_event_percpu(struct irq_desc *desc);
Thomas Gleixner49126092011-02-07 01:08:49 +010089irqreturn_t handle_irq_event(struct irq_desc *desc);
90
Thomas Gleixnere1447102010-10-01 16:03:45 +020091/* Resending of interrupts :*/
Jiang Liu0798abe2015-06-04 12:13:27 +080092void check_irq_resend(struct irq_desc *desc);
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +010093bool irq_wait_for_poll(struct irq_desc *desc);
Thomas Gleixnera92444c2014-02-15 00:55:19 +000094void __irq_wake_thread(struct irq_desc *desc, struct irqaction *action);
Thomas Gleixnere1447102010-10-01 16:03:45 +020095
Linus Torvalds1da177e2005-04-16 15:20:36 -070096#ifdef CONFIG_PROC_FS
Yinghai Lu2c6927a2008-08-19 20:50:11 -070097extern void register_irq_proc(unsigned int irq, struct irq_desc *desc);
Thomas Gleixner13bfe992010-09-30 02:46:07 +020098extern void unregister_irq_proc(unsigned int irq, struct irq_desc *desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099extern void register_handler_proc(unsigned int irq, struct irqaction *action);
100extern void unregister_handler_proc(unsigned int irq, struct irqaction *action);
101#else
Yinghai Lu2c6927a2008-08-19 20:50:11 -0700102static inline void register_irq_proc(unsigned int irq, struct irq_desc *desc) { }
Thomas Gleixner13bfe992010-09-30 02:46:07 +0200103static inline void unregister_irq_proc(unsigned int irq, struct irq_desc *desc) { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104static inline void register_handler_proc(unsigned int irq,
105 struct irqaction *action) { }
106static inline void unregister_handler_proc(unsigned int irq,
107 struct irqaction *action) { }
108#endif
109
Thomas Gleixner9c255582016-07-04 17:39:23 +0900110extern bool irq_can_set_affinity_usr(unsigned int irq);
111
Thomas Gleixner3b8249e2011-02-07 16:02:20 +0100112extern int irq_select_affinity_usr(unsigned int irq, struct cpumask *mask);
Thomas Gleixnerf6d87f42008-11-07 13:18:30 +0100113
Thomas Gleixner591d2fb2009-07-21 11:09:39 +0200114extern void irq_set_thread_affinity(struct irq_desc *desc);
Yinghai Lu57b150c2009-04-27 17:59:53 -0700115
Jiang Liu818b0f32012-03-30 23:11:34 +0800116extern int irq_do_set_affinity(struct irq_data *data,
117 const struct cpumask *dest, bool force);
118
Thomas Gleixner70aedd22009-08-13 12:17:48 +0200119/* Inline functions for support of irq chips on slow busses */
Thomas Gleixner3876ec92010-09-27 12:44:35 +0000120static inline void chip_bus_lock(struct irq_desc *desc)
Thomas Gleixner70aedd22009-08-13 12:17:48 +0200121{
Thomas Gleixner3876ec92010-09-27 12:44:35 +0000122 if (unlikely(desc->irq_data.chip->irq_bus_lock))
123 desc->irq_data.chip->irq_bus_lock(&desc->irq_data);
Thomas Gleixner70aedd22009-08-13 12:17:48 +0200124}
125
Thomas Gleixner3876ec92010-09-27 12:44:35 +0000126static inline void chip_bus_sync_unlock(struct irq_desc *desc)
Thomas Gleixner70aedd22009-08-13 12:17:48 +0200127{
Thomas Gleixner3876ec92010-09-27 12:44:35 +0000128 if (unlikely(desc->irq_data.chip->irq_bus_sync_unlock))
129 desc->irq_data.chip->irq_bus_sync_unlock(&desc->irq_data);
Thomas Gleixner70aedd22009-08-13 12:17:48 +0200130}
131
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100132#define _IRQ_DESC_CHECK (1 << 0)
133#define _IRQ_DESC_PERCPU (1 << 1)
134
135#define IRQ_GET_DESC_CHECK_GLOBAL (_IRQ_DESC_CHECK)
136#define IRQ_GET_DESC_CHECK_PERCPU (_IRQ_DESC_CHECK | _IRQ_DESC_PERCPU)
137
Daniel Lezcanof944b5a2016-01-14 10:54:13 +0100138#define for_each_action_of_desc(desc, act) \
139 for (act = desc->act; act; act = act->next)
140
Thomas Gleixnerd5eb4ad22011-02-12 12:16:16 +0100141struct irq_desc *
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100142__irq_get_desc_lock(unsigned int irq, unsigned long *flags, bool bus,
143 unsigned int check);
Thomas Gleixnerd5eb4ad22011-02-12 12:16:16 +0100144void __irq_put_desc_unlock(struct irq_desc *desc, unsigned long flags, bool bus);
145
146static inline struct irq_desc *
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100147irq_get_desc_buslock(unsigned int irq, unsigned long *flags, unsigned int check)
Thomas Gleixnerd5eb4ad22011-02-12 12:16:16 +0100148{
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100149 return __irq_get_desc_lock(irq, flags, true, check);
Thomas Gleixnerd5eb4ad22011-02-12 12:16:16 +0100150}
151
152static inline void
153irq_put_desc_busunlock(struct irq_desc *desc, unsigned long flags)
154{
155 __irq_put_desc_unlock(desc, flags, true);
156}
157
158static inline struct irq_desc *
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100159irq_get_desc_lock(unsigned int irq, unsigned long *flags, unsigned int check)
Thomas Gleixnerd5eb4ad22011-02-12 12:16:16 +0100160{
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100161 return __irq_get_desc_lock(irq, flags, false, check);
Thomas Gleixnerd5eb4ad22011-02-12 12:16:16 +0100162}
163
164static inline void
165irq_put_desc_unlock(struct irq_desc *desc, unsigned long flags)
166{
167 __irq_put_desc_unlock(desc, flags, false);
168}
169
Boqun Fengb3542862015-12-29 12:18:48 +0800170#define __irqd_to_state(d) ACCESS_PRIVATE((d)->common, state_use_accessors)
171
Ingo Molnar43f77752006-06-29 02:24:58 -0700172/*
Thomas Gleixnerf230b6d2011-02-05 15:20:04 +0100173 * Manipulation functions for irq_data.state
174 */
175static inline void irqd_set_move_pending(struct irq_data *d)
176{
Jiang Liu0d0b4c82015-06-01 16:05:12 +0800177 __irqd_to_state(d) |= IRQD_SETAFFINITY_PENDING;
Thomas Gleixnerf230b6d2011-02-05 15:20:04 +0100178}
179
180static inline void irqd_clr_move_pending(struct irq_data *d)
181{
Jiang Liu0d0b4c82015-06-01 16:05:12 +0800182 __irqd_to_state(d) &= ~IRQD_SETAFFINITY_PENDING;
Thomas Gleixnerf230b6d2011-02-05 15:20:04 +0100183}
Thomas Gleixnera0056772011-02-08 17:11:03 +0100184
185static inline void irqd_clear(struct irq_data *d, unsigned int mask)
186{
Jiang Liu0d0b4c82015-06-01 16:05:12 +0800187 __irqd_to_state(d) &= ~mask;
Thomas Gleixnera0056772011-02-08 17:11:03 +0100188}
189
190static inline void irqd_set(struct irq_data *d, unsigned int mask)
191{
Jiang Liu0d0b4c82015-06-01 16:05:12 +0800192 __irqd_to_state(d) |= mask;
Thomas Gleixnera0056772011-02-08 17:11:03 +0100193}
194
Thomas Gleixner2bdd1052011-02-08 17:22:00 +0100195static inline bool irqd_has_set(struct irq_data *d, unsigned int mask)
196{
Jiang Liu0d0b4c82015-06-01 16:05:12 +0800197 return __irqd_to_state(d) & mask;
Thomas Gleixner2bdd1052011-02-08 17:22:00 +0100198}
Thomas Gleixner8f945a32014-02-23 21:40:23 +0000199
Boqun Fengb3542862015-12-29 12:18:48 +0800200#undef __irqd_to_state
201
Jiang Liub51bf952015-06-04 12:13:25 +0800202static inline void kstat_incr_irqs_this_cpu(struct irq_desc *desc)
Thomas Gleixner8f945a32014-02-23 21:40:23 +0000203{
204 __this_cpu_inc(*desc->kstat_irqs);
205 __this_cpu_inc(kstat.irqs_sum);
206}
Thomas Gleixnercab303b2014-08-28 11:44:31 +0200207
Jiang Liu67830112015-06-01 16:05:13 +0800208static inline int irq_desc_get_node(struct irq_desc *desc)
209{
Jiang Liu449e9ca2015-06-01 16:05:16 +0800210 return irq_common_data_get_node(&desc->irq_common_data);
Jiang Liu67830112015-06-01 16:05:13 +0800211}
212
Grygorii Strashko4717f132015-11-10 11:58:12 +0200213static inline int irq_desc_is_chained(struct irq_desc *desc)
214{
215 return (desc->action && desc->action == &chained_action);
216}
217
Thomas Gleixnercab303b2014-08-28 11:44:31 +0200218#ifdef CONFIG_PM_SLEEP
Thomas Gleixner9ce7a252014-08-29 14:00:16 +0200219bool irq_pm_check_wakeup(struct irq_desc *desc);
Thomas Gleixnercab303b2014-08-28 11:44:31 +0200220void irq_pm_install_action(struct irq_desc *desc, struct irqaction *action);
221void irq_pm_remove_action(struct irq_desc *desc, struct irqaction *action);
222#else
Thomas Gleixner9ce7a252014-08-29 14:00:16 +0200223static inline bool irq_pm_check_wakeup(struct irq_desc *desc) { return false; }
Thomas Gleixnercab303b2014-08-28 11:44:31 +0200224static inline void
225irq_pm_install_action(struct irq_desc *desc, struct irqaction *action) { }
226static inline void
227irq_pm_remove_action(struct irq_desc *desc, struct irqaction *action) { }
228#endif