blob: 2f9f2b0e79f2d9be7901546e8fc991d048d5fc0a [file] [log] [blame]
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -07001/*
2 * linux/kernel/irq/chip.c
3 *
4 * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar
5 * Copyright (C) 2005-2006, Thomas Gleixner, Russell King
6 *
7 * This file contains the core interrupt handling code, for irq-chip
8 * based architectures.
9 *
10 * Detailed information is available in Documentation/DocBook/genericirq
11 */
12
13#include <linux/irq.h>
Michael Ellerman7fe37302007-04-18 19:39:21 +100014#include <linux/msi.h>
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070015#include <linux/module.h>
16#include <linux/interrupt.h>
17#include <linux/kernel_stat.h>
Jiang Liuf8264e32014-11-06 22:20:14 +080018#include <linux/irqdomain.h>
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070019
Steven Rostedtf0696862012-01-25 20:18:55 -050020#include <trace/events/irq.h>
21
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070022#include "internals.h"
23
Mika Westerberge509bd72015-10-05 13:12:15 +030024static irqreturn_t bad_chained_irq(int irq, void *dev_id)
25{
26 WARN_ONCE(1, "Chained irq %d should not call an action\n", irq);
27 return IRQ_NONE;
28}
29
30/*
31 * Chained handlers should never call action on their IRQ. This default
32 * action will emit warning if such thing happens.
33 */
34struct irqaction chained_action = {
35 .handler = bad_chained_irq,
36};
37
Eric W. Biederman3a16d712006-10-04 02:16:37 -070038/**
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010039 * irq_set_chip - set the irq chip for an irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070040 * @irq: irq number
41 * @chip: pointer to irq chip description structure
42 */
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010043int irq_set_chip(unsigned int irq, struct irq_chip *chip)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070044{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070045 unsigned long flags;
Marc Zyngier31d9d9b2011-09-23 17:03:06 +010046 struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070047
Thomas Gleixner02725e72011-02-12 10:37:36 +010048 if (!desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070049 return -EINVAL;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070050
51 if (!chip)
52 chip = &no_irq_chip;
53
Thomas Gleixner6b8ff312010-10-01 12:58:38 +020054 desc->irq_data.chip = chip;
Thomas Gleixner02725e72011-02-12 10:37:36 +010055 irq_put_desc_unlock(desc, flags);
David Daneyd72274e2011-03-25 12:38:48 -070056 /*
57 * For !CONFIG_SPARSE_IRQ make the irq show up in
Thomas Gleixnerf63b6a02014-05-07 15:44:21 +000058 * allocated_irqs.
David Daneyd72274e2011-03-25 12:38:48 -070059 */
Thomas Gleixnerf63b6a02014-05-07 15:44:21 +000060 irq_mark_irq(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070061 return 0;
62}
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010063EXPORT_SYMBOL(irq_set_chip);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070064
65/**
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010066 * irq_set_type - set the irq trigger type for an irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070067 * @irq: irq number
David Brownell0c5d1eb2008-10-01 14:46:18 -070068 * @type: IRQ_TYPE_{LEVEL,EDGE}_* value - see include/linux/irq.h
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070069 */
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010070int irq_set_irq_type(unsigned int irq, unsigned int type)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070071{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070072 unsigned long flags;
Marc Zyngier31d9d9b2011-09-23 17:03:06 +010073 struct irq_desc *desc = irq_get_desc_buslock(irq, &flags, IRQ_GET_DESC_CHECK_GLOBAL);
Thomas Gleixner02725e72011-02-12 10:37:36 +010074 int ret = 0;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070075
Thomas Gleixner02725e72011-02-12 10:37:36 +010076 if (!desc)
77 return -EINVAL;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070078
David Brownellf2b662d2008-12-01 14:31:38 -080079 type &= IRQ_TYPE_SENSE_MASK;
Jiang Liua1ff5412015-06-23 19:47:29 +020080 ret = __irq_set_trigger(desc, type);
Thomas Gleixner02725e72011-02-12 10:37:36 +010081 irq_put_desc_busunlock(desc, flags);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070082 return ret;
83}
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010084EXPORT_SYMBOL(irq_set_irq_type);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070085
86/**
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010087 * irq_set_handler_data - set irq handler data for an irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070088 * @irq: Interrupt number
89 * @data: Pointer to interrupt specific data
90 *
91 * Set the hardware irq controller data for an irq
92 */
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010093int irq_set_handler_data(unsigned int irq, void *data)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070094{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070095 unsigned long flags;
Marc Zyngier31d9d9b2011-09-23 17:03:06 +010096 struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070097
Thomas Gleixner02725e72011-02-12 10:37:36 +010098 if (!desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070099 return -EINVAL;
Jiang Liuaf7080e2015-06-01 16:05:21 +0800100 desc->irq_common_data.handler_data = data;
Thomas Gleixner02725e72011-02-12 10:37:36 +0100101 irq_put_desc_unlock(desc, flags);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700102 return 0;
103}
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +0100104EXPORT_SYMBOL(irq_set_handler_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700105
106/**
Alexander Gordeev51906e72012-11-19 16:01:29 +0100107 * irq_set_msi_desc_off - set MSI descriptor data for an irq at offset
108 * @irq_base: Interrupt number base
109 * @irq_offset: Interrupt number offset
110 * @entry: Pointer to MSI descriptor data
111 *
112 * Set the MSI descriptor entry for an irq at offset
113 */
114int irq_set_msi_desc_off(unsigned int irq_base, unsigned int irq_offset,
115 struct msi_desc *entry)
116{
117 unsigned long flags;
118 struct irq_desc *desc = irq_get_desc_lock(irq_base + irq_offset, &flags, IRQ_GET_DESC_CHECK_GLOBAL);
119
120 if (!desc)
121 return -EINVAL;
Jiang Liub2377212015-06-01 16:05:43 +0800122 desc->irq_common_data.msi_desc = entry;
Alexander Gordeev51906e72012-11-19 16:01:29 +0100123 if (entry && !irq_offset)
124 entry->irq = irq_base;
125 irq_put_desc_unlock(desc, flags);
126 return 0;
127}
128
129/**
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +0100130 * irq_set_msi_desc - set MSI descriptor data for an irq
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700131 * @irq: Interrupt number
Randy Dunlap472900b2007-02-16 01:28:25 -0800132 * @entry: Pointer to MSI descriptor data
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700133 *
Liuweni24b26d42009-11-04 20:11:05 +0800134 * Set the MSI descriptor entry for an irq
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700135 */
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +0100136int irq_set_msi_desc(unsigned int irq, struct msi_desc *entry)
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700137{
Alexander Gordeev51906e72012-11-19 16:01:29 +0100138 return irq_set_msi_desc_off(irq, 0, entry);
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700139}
140
141/**
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +0100142 * irq_set_chip_data - set irq chip data for an irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700143 * @irq: Interrupt number
144 * @data: Pointer to chip specific data
145 *
146 * Set the hardware irq chip data for an irq
147 */
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +0100148int irq_set_chip_data(unsigned int irq, void *data)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700149{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700150 unsigned long flags;
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100151 struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700152
Thomas Gleixner02725e72011-02-12 10:37:36 +0100153 if (!desc)
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700154 return -EINVAL;
Thomas Gleixner6b8ff312010-10-01 12:58:38 +0200155 desc->irq_data.chip_data = data;
Thomas Gleixner02725e72011-02-12 10:37:36 +0100156 irq_put_desc_unlock(desc, flags);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700157 return 0;
158}
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +0100159EXPORT_SYMBOL(irq_set_chip_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700160
Thomas Gleixnerf303a6d2010-09-28 17:34:01 +0200161struct irq_data *irq_get_irq_data(unsigned int irq)
162{
163 struct irq_desc *desc = irq_to_desc(irq);
164
165 return desc ? &desc->irq_data : NULL;
166}
167EXPORT_SYMBOL_GPL(irq_get_irq_data);
168
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100169static void irq_state_clr_disabled(struct irq_desc *desc)
170{
Thomas Gleixner801a0e92011-03-27 11:02:49 +0200171 irqd_clear(&desc->irq_data, IRQD_IRQ_DISABLED);
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100172}
173
174static void irq_state_set_disabled(struct irq_desc *desc)
175{
Thomas Gleixner801a0e92011-03-27 11:02:49 +0200176 irqd_set(&desc->irq_data, IRQD_IRQ_DISABLED);
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100177}
178
Thomas Gleixner6e402622011-02-08 12:36:06 +0100179static void irq_state_clr_masked(struct irq_desc *desc)
180{
Thomas Gleixner32f41252011-03-28 14:10:52 +0200181 irqd_clear(&desc->irq_data, IRQD_IRQ_MASKED);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100182}
183
184static void irq_state_set_masked(struct irq_desc *desc)
185{
Thomas Gleixner32f41252011-03-28 14:10:52 +0200186 irqd_set(&desc->irq_data, IRQD_IRQ_MASKED);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100187}
188
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +0100189int irq_startup(struct irq_desc *desc, bool resend)
Thomas Gleixner46999232011-02-02 21:41:14 +0000190{
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +0100191 int ret = 0;
192
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100193 irq_state_clr_disabled(desc);
Thomas Gleixner46999232011-02-02 21:41:14 +0000194 desc->depth = 0;
195
Jiang Liuf8264e32014-11-06 22:20:14 +0800196 irq_domain_activate_irq(&desc->irq_data);
Thomas Gleixner3aae994f2011-02-04 10:17:52 +0100197 if (desc->irq_data.chip->irq_startup) {
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +0100198 ret = desc->irq_data.chip->irq_startup(&desc->irq_data);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100199 irq_state_clr_masked(desc);
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +0100200 } else {
201 irq_enable(desc);
Thomas Gleixner3aae994f2011-02-04 10:17:52 +0100202 }
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +0100203 if (resend)
Jiang Liu0798abe2015-06-04 12:13:27 +0800204 check_irq_resend(desc);
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +0100205 return ret;
Thomas Gleixner46999232011-02-02 21:41:14 +0000206}
207
208void irq_shutdown(struct irq_desc *desc)
209{
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100210 irq_state_set_disabled(desc);
Thomas Gleixner46999232011-02-02 21:41:14 +0000211 desc->depth = 1;
Thomas Gleixner50f7c032011-02-03 13:23:54 +0100212 if (desc->irq_data.chip->irq_shutdown)
213 desc->irq_data.chip->irq_shutdown(&desc->irq_data);
Geert Uytterhoevened585a62011-09-11 13:59:27 +0200214 else if (desc->irq_data.chip->irq_disable)
Thomas Gleixner50f7c032011-02-03 13:23:54 +0100215 desc->irq_data.chip->irq_disable(&desc->irq_data);
216 else
217 desc->irq_data.chip->irq_mask(&desc->irq_data);
Jiang Liuf8264e32014-11-06 22:20:14 +0800218 irq_domain_deactivate_irq(&desc->irq_data);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100219 irq_state_set_masked(desc);
Thomas Gleixner46999232011-02-02 21:41:14 +0000220}
221
Thomas Gleixner87923472011-02-03 12:27:44 +0100222void irq_enable(struct irq_desc *desc)
223{
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100224 irq_state_clr_disabled(desc);
Thomas Gleixner50f7c032011-02-03 13:23:54 +0100225 if (desc->irq_data.chip->irq_enable)
226 desc->irq_data.chip->irq_enable(&desc->irq_data);
227 else
228 desc->irq_data.chip->irq_unmask(&desc->irq_data);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100229 irq_state_clr_masked(desc);
Thomas Gleixner87923472011-02-03 12:27:44 +0100230}
231
Andreas Fenkartd671a602013-05-10 12:21:30 +0200232/**
Xie XiuQif788e7b2013-10-18 09:12:04 +0800233 * irq_disable - Mark interrupt disabled
Andreas Fenkartd671a602013-05-10 12:21:30 +0200234 * @desc: irq descriptor which should be disabled
235 *
236 * If the chip does not implement the irq_disable callback, we
237 * use a lazy disable approach. That means we mark the interrupt
238 * disabled, but leave the hardware unmasked. That's an
239 * optimization because we avoid the hardware access for the
240 * common case where no interrupt happens after we marked it
241 * disabled. If an interrupt happens, then the interrupt flow
242 * handler masks the line at the hardware level and marks it
243 * pending.
Thomas Gleixnere9849772015-10-09 23:28:58 +0200244 *
245 * If the interrupt chip does not implement the irq_disable callback,
246 * a driver can disable the lazy approach for a particular irq line by
247 * calling 'irq_set_status_flags(irq, IRQ_DISABLE_UNLAZY)'. This can
248 * be used for devices which cannot disable the interrupt at the
249 * device level under certain circumstances and have to use
250 * disable_irq[_nosync] instead.
Andreas Fenkartd671a602013-05-10 12:21:30 +0200251 */
Thomas Gleixner87923472011-02-03 12:27:44 +0100252void irq_disable(struct irq_desc *desc)
253{
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100254 irq_state_set_disabled(desc);
Thomas Gleixner50f7c032011-02-03 13:23:54 +0100255 if (desc->irq_data.chip->irq_disable) {
256 desc->irq_data.chip->irq_disable(&desc->irq_data);
Thomas Gleixnera61d8252011-02-21 12:54:34 +0100257 irq_state_set_masked(desc);
Thomas Gleixnere9849772015-10-09 23:28:58 +0200258 } else if (irq_settings_disable_unlazy(desc)) {
259 mask_irq(desc);
Thomas Gleixner50f7c032011-02-03 13:23:54 +0100260 }
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100261}
262
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100263void irq_percpu_enable(struct irq_desc *desc, unsigned int cpu)
264{
265 if (desc->irq_data.chip->irq_enable)
266 desc->irq_data.chip->irq_enable(&desc->irq_data);
267 else
268 desc->irq_data.chip->irq_unmask(&desc->irq_data);
269 cpumask_set_cpu(cpu, desc->percpu_enabled);
270}
271
272void irq_percpu_disable(struct irq_desc *desc, unsigned int cpu)
273{
274 if (desc->irq_data.chip->irq_disable)
275 desc->irq_data.chip->irq_disable(&desc->irq_data);
276 else
277 desc->irq_data.chip->irq_mask(&desc->irq_data);
278 cpumask_clear_cpu(cpu, desc->percpu_enabled);
279}
280
Thomas Gleixner9205e312010-09-27 12:44:50 +0000281static inline void mask_ack_irq(struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700282{
Thomas Gleixner9205e312010-09-27 12:44:50 +0000283 if (desc->irq_data.chip->irq_mask_ack)
284 desc->irq_data.chip->irq_mask_ack(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700285 else {
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000286 desc->irq_data.chip->irq_mask(&desc->irq_data);
Thomas Gleixner22a49162010-09-27 12:44:47 +0000287 if (desc->irq_data.chip->irq_ack)
288 desc->irq_data.chip->irq_ack(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700289 }
Thomas Gleixner6e402622011-02-08 12:36:06 +0100290 irq_state_set_masked(desc);
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100291}
292
Thomas Gleixnerd4d5e082011-02-10 13:16:14 +0100293void mask_irq(struct irq_desc *desc)
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100294{
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000295 if (desc->irq_data.chip->irq_mask) {
296 desc->irq_data.chip->irq_mask(&desc->irq_data);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100297 irq_state_set_masked(desc);
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100298 }
299}
300
Thomas Gleixnerd4d5e082011-02-10 13:16:14 +0100301void unmask_irq(struct irq_desc *desc)
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100302{
Thomas Gleixner0eda58b2010-09-27 12:44:44 +0000303 if (desc->irq_data.chip->irq_unmask) {
304 desc->irq_data.chip->irq_unmask(&desc->irq_data);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100305 irq_state_clr_masked(desc);
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100306 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700307}
308
Thomas Gleixner328a4972014-03-13 19:03:51 +0100309void unmask_threaded_irq(struct irq_desc *desc)
310{
311 struct irq_chip *chip = desc->irq_data.chip;
312
313 if (chip->flags & IRQCHIP_EOI_THREADED)
314 chip->irq_eoi(&desc->irq_data);
315
316 if (chip->irq_unmask) {
317 chip->irq_unmask(&desc->irq_data);
318 irq_state_clr_masked(desc);
319 }
320}
321
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200322/*
323 * handle_nested_irq - Handle a nested irq from a irq thread
324 * @irq: the interrupt number
325 *
326 * Handle interrupts which are nested into a threaded interrupt
327 * handler. The handler function is called inside the calling
328 * threads context.
329 */
330void handle_nested_irq(unsigned int irq)
331{
332 struct irq_desc *desc = irq_to_desc(irq);
333 struct irqaction *action;
334 irqreturn_t action_ret;
335
336 might_sleep();
337
Thomas Gleixner239007b2009-11-17 16:46:45 +0100338 raw_spin_lock_irq(&desc->lock);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200339
Thomas Gleixner293a7a02012-10-16 15:07:49 -0700340 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200341
342 action = desc->action;
Ning Jiang23812b92012-05-22 00:19:20 +0800343 if (unlikely(!action || irqd_irq_disabled(&desc->irq_data))) {
344 desc->istate |= IRQS_PENDING;
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200345 goto out_unlock;
Ning Jiang23812b92012-05-22 00:19:20 +0800346 }
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200347
Sudeep Hollaa946e8c2015-11-04 18:32:37 +0000348 kstat_incr_irqs_this_cpu(desc);
Thomas Gleixner32f41252011-03-28 14:10:52 +0200349 irqd_set(&desc->irq_data, IRQD_IRQ_INPROGRESS);
Thomas Gleixner239007b2009-11-17 16:46:45 +0100350 raw_spin_unlock_irq(&desc->lock);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200351
352 action_ret = action->thread_fn(action->irq, action->dev_id);
353 if (!noirqdebug)
Jiang Liu0dcdbc92015-06-04 12:13:28 +0800354 note_interrupt(desc, action_ret);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200355
Thomas Gleixner239007b2009-11-17 16:46:45 +0100356 raw_spin_lock_irq(&desc->lock);
Thomas Gleixner32f41252011-03-28 14:10:52 +0200357 irqd_clear(&desc->irq_data, IRQD_IRQ_INPROGRESS);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200358
359out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100360 raw_spin_unlock_irq(&desc->lock);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200361}
362EXPORT_SYMBOL_GPL(handle_nested_irq);
363
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100364static bool irq_check_poll(struct irq_desc *desc)
365{
Thomas Gleixner6954b752011-02-07 20:55:35 +0100366 if (!(desc->istate & IRQS_POLL_INPROGRESS))
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100367 return false;
368 return irq_wait_for_poll(desc);
369}
370
Thomas Gleixnerc7bd3ec02014-08-29 13:39:37 +0200371static bool irq_may_run(struct irq_desc *desc)
372{
Thomas Gleixner9ce7a252014-08-29 14:00:16 +0200373 unsigned int mask = IRQD_IRQ_INPROGRESS | IRQD_WAKEUP_ARMED;
374
375 /*
376 * If the interrupt is not in progress and is not an armed
377 * wakeup interrupt, proceed.
378 */
379 if (!irqd_has_set(&desc->irq_data, mask))
Thomas Gleixnerc7bd3ec02014-08-29 13:39:37 +0200380 return true;
Thomas Gleixner9ce7a252014-08-29 14:00:16 +0200381
382 /*
383 * If the interrupt is an armed wakeup source, mark it pending
384 * and suspended, disable it and notify the pm core about the
385 * event.
386 */
387 if (irq_pm_check_wakeup(desc))
388 return false;
389
390 /*
391 * Handle a potential concurrent poll on a different core.
392 */
Thomas Gleixnerc7bd3ec02014-08-29 13:39:37 +0200393 return irq_check_poll(desc);
394}
395
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700396/**
397 * handle_simple_irq - Simple and software-decoded IRQs.
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700398 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700399 *
400 * Simple interrupts are either sent from a demultiplexing interrupt
401 * handler or come from hardware, where no interrupt hardware control
402 * is necessary.
403 *
404 * Note: The caller is expected to handle the ack, clear, mask and
405 * unmask issues if necessary.
406 */
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +0200407void handle_simple_irq(struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700408{
Thomas Gleixner239007b2009-11-17 16:46:45 +0100409 raw_spin_lock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700410
Thomas Gleixnerc7bd3ec02014-08-29 13:39:37 +0200411 if (!irq_may_run(desc))
412 goto out_unlock;
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100413
Thomas Gleixner163ef302011-02-08 11:39:15 +0100414 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700415
Ning Jiang23812b92012-05-22 00:19:20 +0800416 if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) {
417 desc->istate |= IRQS_PENDING;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700418 goto out_unlock;
Ning Jiang23812b92012-05-22 00:19:20 +0800419 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700420
Sudeep Hollaa946e8c2015-11-04 18:32:37 +0000421 kstat_incr_irqs_this_cpu(desc);
Thomas Gleixner107781e2011-02-07 01:21:02 +0100422 handle_irq_event(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700423
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700424out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100425 raw_spin_unlock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700426}
Jonathan Cameronedf76f82011-05-18 10:39:04 +0100427EXPORT_SYMBOL_GPL(handle_simple_irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700428
Thomas Gleixnerac563762012-02-07 17:58:03 +0100429/*
430 * Called unconditionally from handle_level_irq() and only for oneshot
431 * interrupts from handle_fasteoi_irq()
432 */
433static void cond_unmask_irq(struct irq_desc *desc)
434{
435 /*
436 * We need to unmask in the following cases:
437 * - Standard level irq (IRQF_ONESHOT is not set)
438 * - Oneshot irq which did not wake the thread (caused by a
439 * spurious interrupt or a primary handler handling it
440 * completely).
441 */
442 if (!irqd_irq_disabled(&desc->irq_data) &&
443 irqd_irq_masked(&desc->irq_data) && !desc->threads_oneshot)
444 unmask_irq(desc);
445}
446
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700447/**
448 * handle_level_irq - Level type irq handler
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700449 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700450 *
451 * Level type interrupts are active as long as the hardware line has
452 * the active level. This may require to mask the interrupt and unmask
453 * it after the associated handler has acknowledged the device, so the
454 * interrupt line is back to inactive.
455 */
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +0200456void handle_level_irq(struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700457{
Thomas Gleixner239007b2009-11-17 16:46:45 +0100458 raw_spin_lock(&desc->lock);
Thomas Gleixner9205e312010-09-27 12:44:50 +0000459 mask_ack_irq(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700460
Thomas Gleixnerc7bd3ec02014-08-29 13:39:37 +0200461 if (!irq_may_run(desc))
462 goto out_unlock;
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100463
Thomas Gleixner163ef302011-02-08 11:39:15 +0100464 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700465
466 /*
467 * If its disabled or no action available
468 * keep it masked and get out of here
469 */
Thomas Gleixnerd4dc0f92012-04-25 12:54:54 +0200470 if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) {
471 desc->istate |= IRQS_PENDING;
Ingo Molnar86998aa2006-09-19 11:14:34 +0200472 goto out_unlock;
Thomas Gleixnerd4dc0f92012-04-25 12:54:54 +0200473 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700474
Sudeep Hollaa946e8c2015-11-04 18:32:37 +0000475 kstat_incr_irqs_this_cpu(desc);
Thomas Gleixner15298662011-02-07 01:22:17 +0100476 handle_irq_event(desc);
Thomas Gleixnerb25c3402009-08-13 12:17:22 +0200477
Thomas Gleixnerac563762012-02-07 17:58:03 +0100478 cond_unmask_irq(desc);
479
Ingo Molnar86998aa2006-09-19 11:14:34 +0200480out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100481 raw_spin_unlock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700482}
Ingo Molnar14819ea2009-01-14 12:34:21 +0100483EXPORT_SYMBOL_GPL(handle_level_irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700484
Thomas Gleixner78129572011-02-10 15:14:20 +0100485#ifdef CONFIG_IRQ_PREFLOW_FASTEOI
486static inline void preflow_handler(struct irq_desc *desc)
487{
488 if (desc->preflow_handler)
489 desc->preflow_handler(&desc->irq_data);
490}
491#else
492static inline void preflow_handler(struct irq_desc *desc) { }
493#endif
494
Thomas Gleixner328a4972014-03-13 19:03:51 +0100495static void cond_unmask_eoi_irq(struct irq_desc *desc, struct irq_chip *chip)
496{
497 if (!(desc->istate & IRQS_ONESHOT)) {
498 chip->irq_eoi(&desc->irq_data);
499 return;
500 }
501 /*
502 * We need to unmask in the following cases:
503 * - Oneshot irq which did not wake the thread (caused by a
504 * spurious interrupt or a primary handler handling it
505 * completely).
506 */
507 if (!irqd_irq_disabled(&desc->irq_data) &&
508 irqd_irq_masked(&desc->irq_data) && !desc->threads_oneshot) {
509 chip->irq_eoi(&desc->irq_data);
510 unmask_irq(desc);
511 } else if (!(chip->flags & IRQCHIP_EOI_THREADED)) {
512 chip->irq_eoi(&desc->irq_data);
513 }
514}
515
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700516/**
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700517 * handle_fasteoi_irq - irq handler for transparent controllers
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700518 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700519 *
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700520 * Only a single callback will be issued to the chip: an ->eoi()
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700521 * call when the interrupt has been serviced. This enables support
522 * for modern forms of interrupt handlers, which handle the flow
523 * details in hardware, transparently.
524 */
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +0200525void handle_fasteoi_irq(struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700526{
Thomas Gleixner328a4972014-03-13 19:03:51 +0100527 struct irq_chip *chip = desc->irq_data.chip;
528
Thomas Gleixner239007b2009-11-17 16:46:45 +0100529 raw_spin_lock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700530
Thomas Gleixnerc7bd3ec02014-08-29 13:39:37 +0200531 if (!irq_may_run(desc))
532 goto out;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700533
Thomas Gleixner163ef302011-02-08 11:39:15 +0100534 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700535
536 /*
537 * If its disabled or no action available
Ingo Molnar76d21602007-02-16 01:28:24 -0800538 * then mask it and get out of here:
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700539 */
Thomas Gleixner32f41252011-03-28 14:10:52 +0200540 if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) {
Thomas Gleixner2a0d6fb2011-02-08 12:17:57 +0100541 desc->istate |= IRQS_PENDING;
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000542 mask_irq(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700543 goto out;
Benjamin Herrenschmidt98bb2442006-06-29 02:25:01 -0700544 }
Thomas Gleixnerc69e3752011-03-02 11:49:21 +0100545
Sudeep Hollaa946e8c2015-11-04 18:32:37 +0000546 kstat_incr_irqs_this_cpu(desc);
Thomas Gleixnerc69e3752011-03-02 11:49:21 +0100547 if (desc->istate & IRQS_ONESHOT)
548 mask_irq(desc);
549
Thomas Gleixner78129572011-02-10 15:14:20 +0100550 preflow_handler(desc);
Thomas Gleixnera7ae4de2011-02-07 01:23:07 +0100551 handle_irq_event(desc);
Thomas Gleixner77694b42011-02-15 10:33:57 +0100552
Thomas Gleixner328a4972014-03-13 19:03:51 +0100553 cond_unmask_eoi_irq(desc, chip);
Thomas Gleixnerac563762012-02-07 17:58:03 +0100554
Thomas Gleixner239007b2009-11-17 16:46:45 +0100555 raw_spin_unlock(&desc->lock);
Thomas Gleixner77694b42011-02-15 10:33:57 +0100556 return;
557out:
Thomas Gleixner328a4972014-03-13 19:03:51 +0100558 if (!(chip->flags & IRQCHIP_EOI_IF_HANDLED))
559 chip->irq_eoi(&desc->irq_data);
560 raw_spin_unlock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700561}
Vincent Stehlé7cad45e2014-08-22 01:31:20 +0200562EXPORT_SYMBOL_GPL(handle_fasteoi_irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700563
564/**
565 * handle_edge_irq - edge type IRQ handler
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700566 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700567 *
568 * Interrupt occures on the falling and/or rising edge of a hardware
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300569 * signal. The occurrence is latched into the irq controller hardware
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700570 * and must be acked in order to be reenabled. After the ack another
571 * interrupt can happen on the same source even before the first one
Uwe Kleine-Königdfff0612010-02-12 21:58:11 +0100572 * is handled by the associated event handler. If this happens it
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700573 * might be necessary to disable (mask) the interrupt depending on the
574 * controller hardware. This requires to reenable the interrupt inside
575 * of the loop which handles the interrupts which have arrived while
576 * the handler was running. If all pending interrupts are handled, the
577 * loop is left.
578 */
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +0200579void handle_edge_irq(struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700580{
Thomas Gleixner239007b2009-11-17 16:46:45 +0100581 raw_spin_lock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700582
Thomas Gleixner163ef302011-02-08 11:39:15 +0100583 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Thomas Gleixnerc3d7acd2014-08-29 13:46:08 +0200584
Thomas Gleixnerc7bd3ec02014-08-29 13:39:37 +0200585 if (!irq_may_run(desc)) {
586 desc->istate |= IRQS_PENDING;
587 mask_ack_irq(desc);
588 goto out_unlock;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700589 }
Thomas Gleixnerc3d7acd2014-08-29 13:46:08 +0200590
591 /*
592 * If its disabled or no action available then mask it and get
593 * out of here.
594 */
595 if (irqd_irq_disabled(&desc->irq_data) || !desc->action) {
596 desc->istate |= IRQS_PENDING;
597 mask_ack_irq(desc);
598 goto out_unlock;
599 }
600
Jiang Liub51bf952015-06-04 12:13:25 +0800601 kstat_incr_irqs_this_cpu(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700602
603 /* Start handling the irq */
Thomas Gleixner22a49162010-09-27 12:44:47 +0000604 desc->irq_data.chip->irq_ack(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700605
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700606 do {
Thomas Gleixnera60a5dc2011-02-07 01:24:07 +0100607 if (unlikely(!desc->action)) {
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000608 mask_irq(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700609 goto out_unlock;
610 }
611
612 /*
613 * When another irq arrived while we were handling
614 * one, we could have masked the irq.
615 * Renable it, if it was not disabled in meantime.
616 */
Thomas Gleixner2a0d6fb2011-02-08 12:17:57 +0100617 if (unlikely(desc->istate & IRQS_PENDING)) {
Thomas Gleixner32f41252011-03-28 14:10:52 +0200618 if (!irqd_irq_disabled(&desc->irq_data) &&
619 irqd_irq_masked(&desc->irq_data))
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100620 unmask_irq(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700621 }
622
Thomas Gleixnera60a5dc2011-02-07 01:24:07 +0100623 handle_irq_event(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700624
Thomas Gleixner2a0d6fb2011-02-08 12:17:57 +0100625 } while ((desc->istate & IRQS_PENDING) &&
Thomas Gleixner32f41252011-03-28 14:10:52 +0200626 !irqd_irq_disabled(&desc->irq_data));
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700627
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700628out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100629 raw_spin_unlock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700630}
Jiri Kosina3911ff32012-05-13 12:13:15 +0200631EXPORT_SYMBOL(handle_edge_irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700632
Thomas Gleixner0521c8f2011-03-28 16:13:24 +0200633#ifdef CONFIG_IRQ_EDGE_EOI_HANDLER
634/**
635 * handle_edge_eoi_irq - edge eoi type IRQ handler
Thomas Gleixner0521c8f2011-03-28 16:13:24 +0200636 * @desc: the interrupt description structure for this irq
637 *
638 * Similar as the above handle_edge_irq, but using eoi and w/o the
639 * mask/unmask logic.
640 */
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +0200641void handle_edge_eoi_irq(struct irq_desc *desc)
Thomas Gleixner0521c8f2011-03-28 16:13:24 +0200642{
643 struct irq_chip *chip = irq_desc_get_chip(desc);
644
645 raw_spin_lock(&desc->lock);
646
647 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Thomas Gleixnerc3d7acd2014-08-29 13:46:08 +0200648
Thomas Gleixnerc7bd3ec02014-08-29 13:39:37 +0200649 if (!irq_may_run(desc)) {
650 desc->istate |= IRQS_PENDING;
651 goto out_eoi;
Thomas Gleixner0521c8f2011-03-28 16:13:24 +0200652 }
Thomas Gleixnerc3d7acd2014-08-29 13:46:08 +0200653
654 /*
655 * If its disabled or no action available then mask it and get
656 * out of here.
657 */
658 if (irqd_irq_disabled(&desc->irq_data) || !desc->action) {
659 desc->istate |= IRQS_PENDING;
660 goto out_eoi;
661 }
662
Jiang Liub51bf952015-06-04 12:13:25 +0800663 kstat_incr_irqs_this_cpu(desc);
Thomas Gleixner0521c8f2011-03-28 16:13:24 +0200664
665 do {
666 if (unlikely(!desc->action))
667 goto out_eoi;
668
669 handle_irq_event(desc);
670
671 } while ((desc->istate & IRQS_PENDING) &&
672 !irqd_irq_disabled(&desc->irq_data));
673
Stephen Rothwellac0e0442011-03-30 10:55:12 +1100674out_eoi:
Thomas Gleixner0521c8f2011-03-28 16:13:24 +0200675 chip->irq_eoi(&desc->irq_data);
676 raw_spin_unlock(&desc->lock);
677}
678#endif
679
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700680/**
Liuweni24b26d42009-11-04 20:11:05 +0800681 * handle_percpu_irq - Per CPU local irq handler
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700682 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700683 *
684 * Per CPU interrupts on SMP machines without locking requirements
685 */
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +0200686void handle_percpu_irq(struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700687{
Thomas Gleixner35e857c2011-02-10 12:20:23 +0100688 struct irq_chip *chip = irq_desc_get_chip(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700689
Jiang Liub51bf952015-06-04 12:13:25 +0800690 kstat_incr_irqs_this_cpu(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700691
Thomas Gleixner849f0612011-02-07 01:25:41 +0100692 if (chip->irq_ack)
693 chip->irq_ack(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700694
Huang Shijie71f64342015-09-02 10:24:55 +0800695 handle_irq_event_percpu(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700696
Thomas Gleixner849f0612011-02-07 01:25:41 +0100697 if (chip->irq_eoi)
698 chip->irq_eoi(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700699}
700
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100701/**
702 * handle_percpu_devid_irq - Per CPU local irq handler with per cpu dev ids
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100703 * @desc: the interrupt description structure for this irq
704 *
705 * Per CPU interrupts on SMP machines without locking requirements. Same as
706 * handle_percpu_irq() above but with the following extras:
707 *
708 * action->percpu_dev_id is a pointer to percpu variables which
709 * contain the real device id for the cpu on which this handler is
710 * called
711 */
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +0200712void handle_percpu_devid_irq(struct irq_desc *desc)
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100713{
714 struct irq_chip *chip = irq_desc_get_chip(desc);
715 struct irqaction *action = desc->action;
Christoph Lameter532d0d02014-08-17 12:30:39 -0500716 void *dev_id = raw_cpu_ptr(action->percpu_dev_id);
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +0200717 unsigned int irq = irq_desc_get_irq(desc);
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100718 irqreturn_t res;
719
Jiang Liub51bf952015-06-04 12:13:25 +0800720 kstat_incr_irqs_this_cpu(desc);
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100721
722 if (chip->irq_ack)
723 chip->irq_ack(&desc->irq_data);
724
725 trace_irq_handler_entry(irq, action);
726 res = action->handler(irq, dev_id);
727 trace_irq_handler_exit(irq, action, res);
728
729 if (chip->irq_eoi)
730 chip->irq_eoi(&desc->irq_data);
731}
732
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700733void
Russell King3b0f95b2015-06-16 23:06:20 +0100734__irq_do_set_handler(struct irq_desc *desc, irq_flow_handler_t handle,
735 int is_chained, const char *name)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700736{
Thomas Gleixner091738a2011-02-14 20:16:43 +0100737 if (!handle) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700738 handle = handle_bad_irq;
Thomas Gleixner091738a2011-02-14 20:16:43 +0100739 } else {
Marc Zyngierf86eff22014-11-15 10:49:13 +0000740 struct irq_data *irq_data = &desc->irq_data;
741#ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
742 /*
743 * With hierarchical domains we might run into a
744 * situation where the outermost chip is not yet set
745 * up, but the inner chips are there. Instead of
746 * bailing we install the handler, but obviously we
747 * cannot enable/startup the interrupt at this point.
748 */
749 while (irq_data) {
750 if (irq_data->chip != &no_irq_chip)
751 break;
752 /*
753 * Bail out if the outer chip is not set up
754 * and the interrrupt supposed to be started
755 * right away.
756 */
757 if (WARN_ON(is_chained))
Russell King3b0f95b2015-06-16 23:06:20 +0100758 return;
Marc Zyngierf86eff22014-11-15 10:49:13 +0000759 /* Try the parent */
760 irq_data = irq_data->parent_data;
761 }
762#endif
763 if (WARN_ON(!irq_data || irq_data->chip == &no_irq_chip))
Russell King3b0f95b2015-06-16 23:06:20 +0100764 return;
Thomas Gleixnerf8b54732006-07-01 22:30:08 +0100765 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700766
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700767 /* Uninstall? */
768 if (handle == handle_bad_irq) {
Thomas Gleixner6b8ff312010-10-01 12:58:38 +0200769 if (desc->irq_data.chip != &no_irq_chip)
Thomas Gleixner9205e312010-09-27 12:44:50 +0000770 mask_ack_irq(desc);
Thomas Gleixner801a0e92011-03-27 11:02:49 +0200771 irq_state_set_disabled(desc);
Mika Westerberge509bd72015-10-05 13:12:15 +0300772 if (is_chained)
773 desc->action = NULL;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700774 desc->depth = 1;
775 }
776 desc->handle_irq = handle;
Ingo Molnara460e742006-10-17 00:10:03 -0700777 desc->name = name;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700778
779 if (handle != handle_bad_irq && is_chained) {
Thomas Gleixner1ccb4e612011-02-09 14:44:17 +0100780 irq_settings_set_noprobe(desc);
781 irq_settings_set_norequest(desc);
Paul Mundt7f1b1242011-04-07 06:01:44 +0900782 irq_settings_set_nothread(desc);
Mika Westerberge509bd72015-10-05 13:12:15 +0300783 desc->action = &chained_action;
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +0100784 irq_startup(desc, true);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700785 }
Russell King3b0f95b2015-06-16 23:06:20 +0100786}
787
788void
789__irq_set_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
790 const char *name)
791{
792 unsigned long flags;
793 struct irq_desc *desc = irq_get_desc_buslock(irq, &flags, 0);
794
795 if (!desc)
796 return;
797
798 __irq_do_set_handler(desc, handle, is_chained, name);
Thomas Gleixner02725e72011-02-12 10:37:36 +0100799 irq_put_desc_busunlock(desc, flags);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700800}
Thomas Gleixner3836ca02011-02-14 20:09:19 +0100801EXPORT_SYMBOL_GPL(__irq_set_handler);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700802
803void
Russell King3b0f95b2015-06-16 23:06:20 +0100804irq_set_chained_handler_and_data(unsigned int irq, irq_flow_handler_t handle,
805 void *data)
806{
807 unsigned long flags;
808 struct irq_desc *desc = irq_get_desc_buslock(irq, &flags, 0);
809
810 if (!desc)
811 return;
812
813 __irq_do_set_handler(desc, handle, 1, NULL);
Jiang Liuaf7080e2015-06-01 16:05:21 +0800814 desc->irq_common_data.handler_data = data;
Russell King3b0f95b2015-06-16 23:06:20 +0100815
816 irq_put_desc_busunlock(desc, flags);
817}
818EXPORT_SYMBOL_GPL(irq_set_chained_handler_and_data);
819
820void
Thomas Gleixner3836ca02011-02-14 20:09:19 +0100821irq_set_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
Ingo Molnara460e742006-10-17 00:10:03 -0700822 irq_flow_handler_t handle, const char *name)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700823{
Thomas Gleixner35e857c2011-02-10 12:20:23 +0100824 irq_set_chip(irq, chip);
Thomas Gleixner3836ca02011-02-14 20:09:19 +0100825 __irq_set_handler(irq, handle, 0, name);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700826}
Kuninori Morimotob3ae66f2012-07-30 22:39:06 -0700827EXPORT_SYMBOL_GPL(irq_set_chip_and_handler_name);
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800828
Thomas Gleixner44247182010-09-28 10:40:18 +0200829void irq_modify_status(unsigned int irq, unsigned long clr, unsigned long set)
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800830{
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800831 unsigned long flags;
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100832 struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0);
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800833
Thomas Gleixner44247182010-09-28 10:40:18 +0200834 if (!desc)
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800835 return;
Thomas Gleixnera0056772011-02-08 17:11:03 +0100836 irq_settings_clr_and_set(desc, clr, set);
837
Thomas Gleixner876dbd42011-02-08 17:28:12 +0100838 irqd_clear(&desc->irq_data, IRQD_NO_BALANCING | IRQD_PER_CPU |
Thomas Gleixnere1ef8242011-02-10 22:25:31 +0100839 IRQD_TRIGGER_MASK | IRQD_LEVEL | IRQD_MOVE_PCNTXT);
Thomas Gleixnera0056772011-02-08 17:11:03 +0100840 if (irq_settings_has_no_balance_set(desc))
841 irqd_set(&desc->irq_data, IRQD_NO_BALANCING);
842 if (irq_settings_is_per_cpu(desc))
843 irqd_set(&desc->irq_data, IRQD_PER_CPU);
Thomas Gleixnere1ef8242011-02-10 22:25:31 +0100844 if (irq_settings_can_move_pcntxt(desc))
845 irqd_set(&desc->irq_data, IRQD_MOVE_PCNTXT);
Thomas Gleixner0ef5ca12011-03-28 21:59:37 +0200846 if (irq_settings_is_level(desc))
847 irqd_set(&desc->irq_data, IRQD_LEVEL);
Thomas Gleixnera0056772011-02-08 17:11:03 +0100848
Thomas Gleixner876dbd42011-02-08 17:28:12 +0100849 irqd_set(&desc->irq_data, irq_settings_get_trigger_mask(desc));
850
Thomas Gleixner02725e72011-02-12 10:37:36 +0100851 irq_put_desc_unlock(desc, flags);
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800852}
Jonathan Cameronedf76f82011-05-18 10:39:04 +0100853EXPORT_SYMBOL_GPL(irq_modify_status);
David Daney0fdb4b22011-03-25 12:38:49 -0700854
855/**
856 * irq_cpu_online - Invoke all irq_cpu_online functions.
857 *
858 * Iterate through all irqs and invoke the chip.irq_cpu_online()
859 * for each.
860 */
861void irq_cpu_online(void)
862{
863 struct irq_desc *desc;
864 struct irq_chip *chip;
865 unsigned long flags;
866 unsigned int irq;
867
868 for_each_active_irq(irq) {
869 desc = irq_to_desc(irq);
870 if (!desc)
871 continue;
872
873 raw_spin_lock_irqsave(&desc->lock, flags);
874
875 chip = irq_data_get_irq_chip(&desc->irq_data);
Thomas Gleixnerb3d42232011-03-27 16:05:36 +0200876 if (chip && chip->irq_cpu_online &&
877 (!(chip->flags & IRQCHIP_ONOFFLINE_ENABLED) ||
Thomas Gleixner32f41252011-03-28 14:10:52 +0200878 !irqd_irq_disabled(&desc->irq_data)))
David Daney0fdb4b22011-03-25 12:38:49 -0700879 chip->irq_cpu_online(&desc->irq_data);
880
881 raw_spin_unlock_irqrestore(&desc->lock, flags);
882 }
883}
884
885/**
886 * irq_cpu_offline - Invoke all irq_cpu_offline functions.
887 *
888 * Iterate through all irqs and invoke the chip.irq_cpu_offline()
889 * for each.
890 */
891void irq_cpu_offline(void)
892{
893 struct irq_desc *desc;
894 struct irq_chip *chip;
895 unsigned long flags;
896 unsigned int irq;
897
898 for_each_active_irq(irq) {
899 desc = irq_to_desc(irq);
900 if (!desc)
901 continue;
902
903 raw_spin_lock_irqsave(&desc->lock, flags);
904
905 chip = irq_data_get_irq_chip(&desc->irq_data);
Thomas Gleixnerb3d42232011-03-27 16:05:36 +0200906 if (chip && chip->irq_cpu_offline &&
907 (!(chip->flags & IRQCHIP_ONOFFLINE_ENABLED) ||
Thomas Gleixner32f41252011-03-28 14:10:52 +0200908 !irqd_irq_disabled(&desc->irq_data)))
David Daney0fdb4b22011-03-25 12:38:49 -0700909 chip->irq_cpu_offline(&desc->irq_data);
910
911 raw_spin_unlock_irqrestore(&desc->lock, flags);
912 }
913}
Jiang Liu85f08c12014-11-06 22:20:16 +0800914
915#ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
916/**
Stefan Agner3cfeffc2015-05-16 11:44:14 +0200917 * irq_chip_enable_parent - Enable the parent interrupt (defaults to unmask if
918 * NULL)
919 * @data: Pointer to interrupt specific data
920 */
921void irq_chip_enable_parent(struct irq_data *data)
922{
923 data = data->parent_data;
924 if (data->chip->irq_enable)
925 data->chip->irq_enable(data);
926 else
927 data->chip->irq_unmask(data);
928}
929
930/**
931 * irq_chip_disable_parent - Disable the parent interrupt (defaults to mask if
932 * NULL)
933 * @data: Pointer to interrupt specific data
934 */
935void irq_chip_disable_parent(struct irq_data *data)
936{
937 data = data->parent_data;
938 if (data->chip->irq_disable)
939 data->chip->irq_disable(data);
940 else
941 data->chip->irq_mask(data);
942}
943
944/**
Jiang Liu85f08c12014-11-06 22:20:16 +0800945 * irq_chip_ack_parent - Acknowledge the parent interrupt
946 * @data: Pointer to interrupt specific data
947 */
948void irq_chip_ack_parent(struct irq_data *data)
949{
950 data = data->parent_data;
951 data->chip->irq_ack(data);
952}
Jake Oshinsa4289dc2015-12-10 17:52:59 +0000953EXPORT_SYMBOL_GPL(irq_chip_ack_parent);
Jiang Liu85f08c12014-11-06 22:20:16 +0800954
955/**
Yingjoe Chen56e8aba2014-11-13 23:37:05 +0800956 * irq_chip_mask_parent - Mask the parent interrupt
957 * @data: Pointer to interrupt specific data
958 */
959void irq_chip_mask_parent(struct irq_data *data)
960{
961 data = data->parent_data;
962 data->chip->irq_mask(data);
963}
Quan Nguyen52b2a052016-03-03 21:56:52 +0700964EXPORT_SYMBOL_GPL(irq_chip_mask_parent);
Yingjoe Chen56e8aba2014-11-13 23:37:05 +0800965
966/**
967 * irq_chip_unmask_parent - Unmask the parent interrupt
968 * @data: Pointer to interrupt specific data
969 */
970void irq_chip_unmask_parent(struct irq_data *data)
971{
972 data = data->parent_data;
973 data->chip->irq_unmask(data);
974}
Quan Nguyen52b2a052016-03-03 21:56:52 +0700975EXPORT_SYMBOL_GPL(irq_chip_unmask_parent);
Yingjoe Chen56e8aba2014-11-13 23:37:05 +0800976
977/**
978 * irq_chip_eoi_parent - Invoke EOI on the parent interrupt
979 * @data: Pointer to interrupt specific data
980 */
981void irq_chip_eoi_parent(struct irq_data *data)
982{
983 data = data->parent_data;
984 data->chip->irq_eoi(data);
985}
Quan Nguyen52b2a052016-03-03 21:56:52 +0700986EXPORT_SYMBOL_GPL(irq_chip_eoi_parent);
Yingjoe Chen56e8aba2014-11-13 23:37:05 +0800987
988/**
989 * irq_chip_set_affinity_parent - Set affinity on the parent interrupt
990 * @data: Pointer to interrupt specific data
991 * @dest: The affinity mask to set
992 * @force: Flag to enforce setting (disable online checks)
993 *
994 * Conditinal, as the underlying parent chip might not implement it.
995 */
996int irq_chip_set_affinity_parent(struct irq_data *data,
997 const struct cpumask *dest, bool force)
998{
999 data = data->parent_data;
1000 if (data->chip->irq_set_affinity)
1001 return data->chip->irq_set_affinity(data, dest, force);
1002
1003 return -ENOSYS;
1004}
1005
1006/**
Grygorii Strashkob7560de2015-08-14 15:20:26 +03001007 * irq_chip_set_type_parent - Set IRQ type on the parent interrupt
1008 * @data: Pointer to interrupt specific data
1009 * @type: IRQ_TYPE_{LEVEL,EDGE}_* value - see include/linux/irq.h
1010 *
1011 * Conditional, as the underlying parent chip might not implement it.
1012 */
1013int irq_chip_set_type_parent(struct irq_data *data, unsigned int type)
1014{
1015 data = data->parent_data;
1016
1017 if (data->chip->irq_set_type)
1018 return data->chip->irq_set_type(data, type);
1019
1020 return -ENOSYS;
1021}
Quan Nguyen52b2a052016-03-03 21:56:52 +07001022EXPORT_SYMBOL_GPL(irq_chip_set_type_parent);
Grygorii Strashkob7560de2015-08-14 15:20:26 +03001023
1024/**
Jiang Liu85f08c12014-11-06 22:20:16 +08001025 * irq_chip_retrigger_hierarchy - Retrigger an interrupt in hardware
1026 * @data: Pointer to interrupt specific data
1027 *
1028 * Iterate through the domain hierarchy of the interrupt and check
1029 * whether a hw retrigger function exists. If yes, invoke it.
1030 */
1031int irq_chip_retrigger_hierarchy(struct irq_data *data)
1032{
1033 for (data = data->parent_data; data; data = data->parent_data)
1034 if (data->chip && data->chip->irq_retrigger)
1035 return data->chip->irq_retrigger(data);
1036
Grygorii Strashko6d4affe2015-08-14 15:20:25 +03001037 return 0;
Jiang Liu85f08c12014-11-06 22:20:16 +08001038}
Marc Zyngier08b55e22015-03-11 15:43:43 +00001039
1040/**
Jiang Liu0a4377d2015-05-19 17:07:14 +08001041 * irq_chip_set_vcpu_affinity_parent - Set vcpu affinity on the parent interrupt
1042 * @data: Pointer to interrupt specific data
Masanari Iida8505a812015-07-29 19:09:36 +09001043 * @vcpu_info: The vcpu affinity information
Jiang Liu0a4377d2015-05-19 17:07:14 +08001044 */
1045int irq_chip_set_vcpu_affinity_parent(struct irq_data *data, void *vcpu_info)
1046{
1047 data = data->parent_data;
1048 if (data->chip->irq_set_vcpu_affinity)
1049 return data->chip->irq_set_vcpu_affinity(data, vcpu_info);
1050
1051 return -ENOSYS;
1052}
1053
1054/**
Marc Zyngier08b55e22015-03-11 15:43:43 +00001055 * irq_chip_set_wake_parent - Set/reset wake-up on the parent interrupt
1056 * @data: Pointer to interrupt specific data
1057 * @on: Whether to set or reset the wake-up capability of this irq
1058 *
1059 * Conditional, as the underlying parent chip might not implement it.
1060 */
1061int irq_chip_set_wake_parent(struct irq_data *data, unsigned int on)
1062{
1063 data = data->parent_data;
1064 if (data->chip->irq_set_wake)
1065 return data->chip->irq_set_wake(data, on);
1066
1067 return -ENOSYS;
1068}
Jiang Liu85f08c12014-11-06 22:20:16 +08001069#endif
Jiang Liu515085e2014-11-06 22:20:17 +08001070
1071/**
1072 * irq_chip_compose_msi_msg - Componse msi message for a irq chip
1073 * @data: Pointer to interrupt specific data
1074 * @msg: Pointer to the MSI message
1075 *
1076 * For hierarchical domains we find the first chip in the hierarchy
1077 * which implements the irq_compose_msi_msg callback. For non
1078 * hierarchical we use the top level chip.
1079 */
1080int irq_chip_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
1081{
1082 struct irq_data *pos = NULL;
1083
1084#ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
1085 for (; data; data = data->parent_data)
1086#endif
1087 if (data->chip && data->chip->irq_compose_msi_msg)
1088 pos = data;
1089 if (!pos)
1090 return -ENOSYS;
1091
1092 pos->chip->irq_compose_msi_msg(pos, msg);
1093
1094 return 0;
1095}