blob: a48e00e345d74e6e910a646eff081cca254d67aa [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
Eric W. Biederman3a16d712006-10-04 02:16:37 -070024/**
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010025 * irq_set_chip - set the irq chip for an irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070026 * @irq: irq number
27 * @chip: pointer to irq chip description structure
28 */
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010029int irq_set_chip(unsigned int irq, struct irq_chip *chip)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070030{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070031 unsigned long flags;
Marc Zyngier31d9d9b2011-09-23 17:03:06 +010032 struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070033
Thomas Gleixner02725e72011-02-12 10:37:36 +010034 if (!desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070035 return -EINVAL;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070036
37 if (!chip)
38 chip = &no_irq_chip;
39
Thomas Gleixner6b8ff312010-10-01 12:58:38 +020040 desc->irq_data.chip = chip;
Thomas Gleixner02725e72011-02-12 10:37:36 +010041 irq_put_desc_unlock(desc, flags);
David Daneyd72274e2011-03-25 12:38:48 -070042 /*
43 * For !CONFIG_SPARSE_IRQ make the irq show up in
Thomas Gleixnerf63b6a02014-05-07 15:44:21 +000044 * allocated_irqs.
David Daneyd72274e2011-03-25 12:38:48 -070045 */
Thomas Gleixnerf63b6a02014-05-07 15:44:21 +000046 irq_mark_irq(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070047 return 0;
48}
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010049EXPORT_SYMBOL(irq_set_chip);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070050
51/**
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010052 * irq_set_type - set the irq trigger type for an irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070053 * @irq: irq number
David Brownell0c5d1eb2008-10-01 14:46:18 -070054 * @type: IRQ_TYPE_{LEVEL,EDGE}_* value - see include/linux/irq.h
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070055 */
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010056int irq_set_irq_type(unsigned int irq, unsigned int type)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070057{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070058 unsigned long flags;
Marc Zyngier31d9d9b2011-09-23 17:03:06 +010059 struct irq_desc *desc = irq_get_desc_buslock(irq, &flags, IRQ_GET_DESC_CHECK_GLOBAL);
Thomas Gleixner02725e72011-02-12 10:37:36 +010060 int ret = 0;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070061
Thomas Gleixner02725e72011-02-12 10:37:36 +010062 if (!desc)
63 return -EINVAL;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070064
David Brownellf2b662d2008-12-01 14:31:38 -080065 type &= IRQ_TYPE_SENSE_MASK;
Jiang Liua1ff5412015-06-23 19:47:29 +020066 ret = __irq_set_trigger(desc, type);
Thomas Gleixner02725e72011-02-12 10:37:36 +010067 irq_put_desc_busunlock(desc, flags);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070068 return ret;
69}
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010070EXPORT_SYMBOL(irq_set_irq_type);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070071
72/**
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010073 * irq_set_handler_data - set irq handler data for an irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070074 * @irq: Interrupt number
75 * @data: Pointer to interrupt specific data
76 *
77 * Set the hardware irq controller data for an irq
78 */
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010079int irq_set_handler_data(unsigned int irq, void *data)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070080{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070081 unsigned long flags;
Marc Zyngier31d9d9b2011-09-23 17:03:06 +010082 struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070083
Thomas Gleixner02725e72011-02-12 10:37:36 +010084 if (!desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070085 return -EINVAL;
Jiang Liuaf7080e2015-06-01 16:05:21 +080086 desc->irq_common_data.handler_data = data;
Thomas Gleixner02725e72011-02-12 10:37:36 +010087 irq_put_desc_unlock(desc, flags);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070088 return 0;
89}
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010090EXPORT_SYMBOL(irq_set_handler_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070091
92/**
Alexander Gordeev51906e72012-11-19 16:01:29 +010093 * irq_set_msi_desc_off - set MSI descriptor data for an irq at offset
94 * @irq_base: Interrupt number base
95 * @irq_offset: Interrupt number offset
96 * @entry: Pointer to MSI descriptor data
97 *
98 * Set the MSI descriptor entry for an irq at offset
99 */
100int irq_set_msi_desc_off(unsigned int irq_base, unsigned int irq_offset,
101 struct msi_desc *entry)
102{
103 unsigned long flags;
104 struct irq_desc *desc = irq_get_desc_lock(irq_base + irq_offset, &flags, IRQ_GET_DESC_CHECK_GLOBAL);
105
106 if (!desc)
107 return -EINVAL;
108 desc->irq_data.msi_desc = entry;
109 if (entry && !irq_offset)
110 entry->irq = irq_base;
111 irq_put_desc_unlock(desc, flags);
112 return 0;
113}
114
115/**
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +0100116 * irq_set_msi_desc - set MSI descriptor data for an irq
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700117 * @irq: Interrupt number
Randy Dunlap472900b2007-02-16 01:28:25 -0800118 * @entry: Pointer to MSI descriptor data
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700119 *
Liuweni24b26d42009-11-04 20:11:05 +0800120 * Set the MSI descriptor entry for an irq
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700121 */
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +0100122int irq_set_msi_desc(unsigned int irq, struct msi_desc *entry)
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700123{
Alexander Gordeev51906e72012-11-19 16:01:29 +0100124 return irq_set_msi_desc_off(irq, 0, entry);
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700125}
126
127/**
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +0100128 * irq_set_chip_data - set irq chip data for an irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700129 * @irq: Interrupt number
130 * @data: Pointer to chip specific data
131 *
132 * Set the hardware irq chip data for an irq
133 */
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +0100134int irq_set_chip_data(unsigned int irq, void *data)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700135{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700136 unsigned long flags;
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100137 struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700138
Thomas Gleixner02725e72011-02-12 10:37:36 +0100139 if (!desc)
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700140 return -EINVAL;
Thomas Gleixner6b8ff312010-10-01 12:58:38 +0200141 desc->irq_data.chip_data = data;
Thomas Gleixner02725e72011-02-12 10:37:36 +0100142 irq_put_desc_unlock(desc, flags);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700143 return 0;
144}
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +0100145EXPORT_SYMBOL(irq_set_chip_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700146
Thomas Gleixnerf303a6d2010-09-28 17:34:01 +0200147struct irq_data *irq_get_irq_data(unsigned int irq)
148{
149 struct irq_desc *desc = irq_to_desc(irq);
150
151 return desc ? &desc->irq_data : NULL;
152}
153EXPORT_SYMBOL_GPL(irq_get_irq_data);
154
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100155static void irq_state_clr_disabled(struct irq_desc *desc)
156{
Thomas Gleixner801a0e92011-03-27 11:02:49 +0200157 irqd_clear(&desc->irq_data, IRQD_IRQ_DISABLED);
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100158}
159
160static void irq_state_set_disabled(struct irq_desc *desc)
161{
Thomas Gleixner801a0e92011-03-27 11:02:49 +0200162 irqd_set(&desc->irq_data, IRQD_IRQ_DISABLED);
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100163}
164
Thomas Gleixner6e402622011-02-08 12:36:06 +0100165static void irq_state_clr_masked(struct irq_desc *desc)
166{
Thomas Gleixner32f41252011-03-28 14:10:52 +0200167 irqd_clear(&desc->irq_data, IRQD_IRQ_MASKED);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100168}
169
170static void irq_state_set_masked(struct irq_desc *desc)
171{
Thomas Gleixner32f41252011-03-28 14:10:52 +0200172 irqd_set(&desc->irq_data, IRQD_IRQ_MASKED);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100173}
174
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +0100175int irq_startup(struct irq_desc *desc, bool resend)
Thomas Gleixner46999232011-02-02 21:41:14 +0000176{
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +0100177 int ret = 0;
178
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100179 irq_state_clr_disabled(desc);
Thomas Gleixner46999232011-02-02 21:41:14 +0000180 desc->depth = 0;
181
Jiang Liuf8264e32014-11-06 22:20:14 +0800182 irq_domain_activate_irq(&desc->irq_data);
Thomas Gleixner3aae9942011-02-04 10:17:52 +0100183 if (desc->irq_data.chip->irq_startup) {
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +0100184 ret = desc->irq_data.chip->irq_startup(&desc->irq_data);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100185 irq_state_clr_masked(desc);
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +0100186 } else {
187 irq_enable(desc);
Thomas Gleixner3aae9942011-02-04 10:17:52 +0100188 }
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +0100189 if (resend)
Jiang Liu0798abe2015-06-04 12:13:27 +0800190 check_irq_resend(desc);
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +0100191 return ret;
Thomas Gleixner46999232011-02-02 21:41:14 +0000192}
193
194void irq_shutdown(struct irq_desc *desc)
195{
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100196 irq_state_set_disabled(desc);
Thomas Gleixner46999232011-02-02 21:41:14 +0000197 desc->depth = 1;
Thomas Gleixner50f7c032011-02-03 13:23:54 +0100198 if (desc->irq_data.chip->irq_shutdown)
199 desc->irq_data.chip->irq_shutdown(&desc->irq_data);
Geert Uytterhoevened585a62011-09-11 13:59:27 +0200200 else if (desc->irq_data.chip->irq_disable)
Thomas Gleixner50f7c032011-02-03 13:23:54 +0100201 desc->irq_data.chip->irq_disable(&desc->irq_data);
202 else
203 desc->irq_data.chip->irq_mask(&desc->irq_data);
Jiang Liuf8264e32014-11-06 22:20:14 +0800204 irq_domain_deactivate_irq(&desc->irq_data);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100205 irq_state_set_masked(desc);
Thomas Gleixner46999232011-02-02 21:41:14 +0000206}
207
Thomas Gleixner87923472011-02-03 12:27:44 +0100208void irq_enable(struct irq_desc *desc)
209{
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100210 irq_state_clr_disabled(desc);
Thomas Gleixner50f7c032011-02-03 13:23:54 +0100211 if (desc->irq_data.chip->irq_enable)
212 desc->irq_data.chip->irq_enable(&desc->irq_data);
213 else
214 desc->irq_data.chip->irq_unmask(&desc->irq_data);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100215 irq_state_clr_masked(desc);
Thomas Gleixner87923472011-02-03 12:27:44 +0100216}
217
Andreas Fenkartd671a602013-05-10 12:21:30 +0200218/**
Xie XiuQif788e7b2013-10-18 09:12:04 +0800219 * irq_disable - Mark interrupt disabled
Andreas Fenkartd671a602013-05-10 12:21:30 +0200220 * @desc: irq descriptor which should be disabled
221 *
222 * If the chip does not implement the irq_disable callback, we
223 * use a lazy disable approach. That means we mark the interrupt
224 * disabled, but leave the hardware unmasked. That's an
225 * optimization because we avoid the hardware access for the
226 * common case where no interrupt happens after we marked it
227 * disabled. If an interrupt happens, then the interrupt flow
228 * handler masks the line at the hardware level and marks it
229 * pending.
230 */
Thomas Gleixner87923472011-02-03 12:27:44 +0100231void irq_disable(struct irq_desc *desc)
232{
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100233 irq_state_set_disabled(desc);
Thomas Gleixner50f7c032011-02-03 13:23:54 +0100234 if (desc->irq_data.chip->irq_disable) {
235 desc->irq_data.chip->irq_disable(&desc->irq_data);
Thomas Gleixnera61d8252011-02-21 12:54:34 +0100236 irq_state_set_masked(desc);
Thomas Gleixner50f7c032011-02-03 13:23:54 +0100237 }
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100238}
239
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100240void irq_percpu_enable(struct irq_desc *desc, unsigned int cpu)
241{
242 if (desc->irq_data.chip->irq_enable)
243 desc->irq_data.chip->irq_enable(&desc->irq_data);
244 else
245 desc->irq_data.chip->irq_unmask(&desc->irq_data);
246 cpumask_set_cpu(cpu, desc->percpu_enabled);
247}
248
249void irq_percpu_disable(struct irq_desc *desc, unsigned int cpu)
250{
251 if (desc->irq_data.chip->irq_disable)
252 desc->irq_data.chip->irq_disable(&desc->irq_data);
253 else
254 desc->irq_data.chip->irq_mask(&desc->irq_data);
255 cpumask_clear_cpu(cpu, desc->percpu_enabled);
256}
257
Thomas Gleixner9205e312010-09-27 12:44:50 +0000258static inline void mask_ack_irq(struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700259{
Thomas Gleixner9205e312010-09-27 12:44:50 +0000260 if (desc->irq_data.chip->irq_mask_ack)
261 desc->irq_data.chip->irq_mask_ack(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700262 else {
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000263 desc->irq_data.chip->irq_mask(&desc->irq_data);
Thomas Gleixner22a49162010-09-27 12:44:47 +0000264 if (desc->irq_data.chip->irq_ack)
265 desc->irq_data.chip->irq_ack(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700266 }
Thomas Gleixner6e402622011-02-08 12:36:06 +0100267 irq_state_set_masked(desc);
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100268}
269
Thomas Gleixnerd4d5e082011-02-10 13:16:14 +0100270void mask_irq(struct irq_desc *desc)
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100271{
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000272 if (desc->irq_data.chip->irq_mask) {
273 desc->irq_data.chip->irq_mask(&desc->irq_data);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100274 irq_state_set_masked(desc);
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100275 }
276}
277
Thomas Gleixnerd4d5e082011-02-10 13:16:14 +0100278void unmask_irq(struct irq_desc *desc)
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100279{
Thomas Gleixner0eda58b2010-09-27 12:44:44 +0000280 if (desc->irq_data.chip->irq_unmask) {
281 desc->irq_data.chip->irq_unmask(&desc->irq_data);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100282 irq_state_clr_masked(desc);
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100283 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700284}
285
Thomas Gleixner328a4972014-03-13 19:03:51 +0100286void unmask_threaded_irq(struct irq_desc *desc)
287{
288 struct irq_chip *chip = desc->irq_data.chip;
289
290 if (chip->flags & IRQCHIP_EOI_THREADED)
291 chip->irq_eoi(&desc->irq_data);
292
293 if (chip->irq_unmask) {
294 chip->irq_unmask(&desc->irq_data);
295 irq_state_clr_masked(desc);
296 }
297}
298
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200299/*
300 * handle_nested_irq - Handle a nested irq from a irq thread
301 * @irq: the interrupt number
302 *
303 * Handle interrupts which are nested into a threaded interrupt
304 * handler. The handler function is called inside the calling
305 * threads context.
306 */
307void handle_nested_irq(unsigned int irq)
308{
309 struct irq_desc *desc = irq_to_desc(irq);
310 struct irqaction *action;
311 irqreturn_t action_ret;
312
313 might_sleep();
314
Thomas Gleixner239007b2009-11-17 16:46:45 +0100315 raw_spin_lock_irq(&desc->lock);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200316
Thomas Gleixner293a7a02012-10-16 15:07:49 -0700317 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Jiang Liub51bf952015-06-04 12:13:25 +0800318 kstat_incr_irqs_this_cpu(desc);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200319
320 action = desc->action;
Ning Jiang23812b92012-05-22 00:19:20 +0800321 if (unlikely(!action || irqd_irq_disabled(&desc->irq_data))) {
322 desc->istate |= IRQS_PENDING;
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200323 goto out_unlock;
Ning Jiang23812b92012-05-22 00:19:20 +0800324 }
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200325
Thomas Gleixner32f41252011-03-28 14:10:52 +0200326 irqd_set(&desc->irq_data, IRQD_IRQ_INPROGRESS);
Thomas Gleixner239007b2009-11-17 16:46:45 +0100327 raw_spin_unlock_irq(&desc->lock);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200328
329 action_ret = action->thread_fn(action->irq, action->dev_id);
330 if (!noirqdebug)
Jiang Liu0dcdbc92015-06-04 12:13:28 +0800331 note_interrupt(desc, action_ret);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200332
Thomas Gleixner239007b2009-11-17 16:46:45 +0100333 raw_spin_lock_irq(&desc->lock);
Thomas Gleixner32f41252011-03-28 14:10:52 +0200334 irqd_clear(&desc->irq_data, IRQD_IRQ_INPROGRESS);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200335
336out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100337 raw_spin_unlock_irq(&desc->lock);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200338}
339EXPORT_SYMBOL_GPL(handle_nested_irq);
340
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100341static bool irq_check_poll(struct irq_desc *desc)
342{
Thomas Gleixner6954b752011-02-07 20:55:35 +0100343 if (!(desc->istate & IRQS_POLL_INPROGRESS))
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100344 return false;
345 return irq_wait_for_poll(desc);
346}
347
Thomas Gleixnerc7bd3ec02014-08-29 13:39:37 +0200348static bool irq_may_run(struct irq_desc *desc)
349{
Thomas Gleixner9ce7a252014-08-29 14:00:16 +0200350 unsigned int mask = IRQD_IRQ_INPROGRESS | IRQD_WAKEUP_ARMED;
351
352 /*
353 * If the interrupt is not in progress and is not an armed
354 * wakeup interrupt, proceed.
355 */
356 if (!irqd_has_set(&desc->irq_data, mask))
Thomas Gleixnerc7bd3ec02014-08-29 13:39:37 +0200357 return true;
Thomas Gleixner9ce7a252014-08-29 14:00:16 +0200358
359 /*
360 * If the interrupt is an armed wakeup source, mark it pending
361 * and suspended, disable it and notify the pm core about the
362 * event.
363 */
364 if (irq_pm_check_wakeup(desc))
365 return false;
366
367 /*
368 * Handle a potential concurrent poll on a different core.
369 */
Thomas Gleixnerc7bd3ec02014-08-29 13:39:37 +0200370 return irq_check_poll(desc);
371}
372
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700373/**
374 * handle_simple_irq - Simple and software-decoded IRQs.
375 * @irq: the interrupt number
376 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700377 *
378 * Simple interrupts are either sent from a demultiplexing interrupt
379 * handler or come from hardware, where no interrupt hardware control
380 * is necessary.
381 *
382 * Note: The caller is expected to handle the ack, clear, mask and
383 * unmask issues if necessary.
384 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800385void
David Howells7d12e782006-10-05 14:55:46 +0100386handle_simple_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700387{
Thomas Gleixner239007b2009-11-17 16:46:45 +0100388 raw_spin_lock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700389
Thomas Gleixnerc7bd3ec02014-08-29 13:39:37 +0200390 if (!irq_may_run(desc))
391 goto out_unlock;
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100392
Thomas Gleixner163ef302011-02-08 11:39:15 +0100393 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Jiang Liub51bf952015-06-04 12:13:25 +0800394 kstat_incr_irqs_this_cpu(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700395
Ning Jiang23812b92012-05-22 00:19:20 +0800396 if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) {
397 desc->istate |= IRQS_PENDING;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700398 goto out_unlock;
Ning Jiang23812b92012-05-22 00:19:20 +0800399 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700400
Thomas Gleixner107781e2011-02-07 01:21:02 +0100401 handle_irq_event(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700402
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700403out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100404 raw_spin_unlock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700405}
Jonathan Cameronedf76f82011-05-18 10:39:04 +0100406EXPORT_SYMBOL_GPL(handle_simple_irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700407
Thomas Gleixnerac563762012-02-07 17:58:03 +0100408/*
409 * Called unconditionally from handle_level_irq() and only for oneshot
410 * interrupts from handle_fasteoi_irq()
411 */
412static void cond_unmask_irq(struct irq_desc *desc)
413{
414 /*
415 * We need to unmask in the following cases:
416 * - Standard level irq (IRQF_ONESHOT is not set)
417 * - Oneshot irq which did not wake the thread (caused by a
418 * spurious interrupt or a primary handler handling it
419 * completely).
420 */
421 if (!irqd_irq_disabled(&desc->irq_data) &&
422 irqd_irq_masked(&desc->irq_data) && !desc->threads_oneshot)
423 unmask_irq(desc);
424}
425
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700426/**
427 * handle_level_irq - Level type irq handler
428 * @irq: the interrupt number
429 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700430 *
431 * Level type interrupts are active as long as the hardware line has
432 * the active level. This may require to mask the interrupt and unmask
433 * it after the associated handler has acknowledged the device, so the
434 * interrupt line is back to inactive.
435 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800436void
David Howells7d12e782006-10-05 14:55:46 +0100437handle_level_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700438{
Thomas Gleixner239007b2009-11-17 16:46:45 +0100439 raw_spin_lock(&desc->lock);
Thomas Gleixner9205e312010-09-27 12:44:50 +0000440 mask_ack_irq(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700441
Thomas Gleixnerc7bd3ec02014-08-29 13:39:37 +0200442 if (!irq_may_run(desc))
443 goto out_unlock;
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100444
Thomas Gleixner163ef302011-02-08 11:39:15 +0100445 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Jiang Liub51bf952015-06-04 12:13:25 +0800446 kstat_incr_irqs_this_cpu(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700447
448 /*
449 * If its disabled or no action available
450 * keep it masked and get out of here
451 */
Thomas Gleixnerd4dc0f92012-04-25 12:54:54 +0200452 if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) {
453 desc->istate |= IRQS_PENDING;
Ingo Molnar86998aa2006-09-19 11:14:34 +0200454 goto out_unlock;
Thomas Gleixnerd4dc0f92012-04-25 12:54:54 +0200455 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700456
Thomas Gleixner15298662011-02-07 01:22:17 +0100457 handle_irq_event(desc);
Thomas Gleixnerb25c3402009-08-13 12:17:22 +0200458
Thomas Gleixnerac563762012-02-07 17:58:03 +0100459 cond_unmask_irq(desc);
460
Ingo Molnar86998aa2006-09-19 11:14:34 +0200461out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100462 raw_spin_unlock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700463}
Ingo Molnar14819ea2009-01-14 12:34:21 +0100464EXPORT_SYMBOL_GPL(handle_level_irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700465
Thomas Gleixner78129572011-02-10 15:14:20 +0100466#ifdef CONFIG_IRQ_PREFLOW_FASTEOI
467static inline void preflow_handler(struct irq_desc *desc)
468{
469 if (desc->preflow_handler)
470 desc->preflow_handler(&desc->irq_data);
471}
472#else
473static inline void preflow_handler(struct irq_desc *desc) { }
474#endif
475
Thomas Gleixner328a4972014-03-13 19:03:51 +0100476static void cond_unmask_eoi_irq(struct irq_desc *desc, struct irq_chip *chip)
477{
478 if (!(desc->istate & IRQS_ONESHOT)) {
479 chip->irq_eoi(&desc->irq_data);
480 return;
481 }
482 /*
483 * We need to unmask in the following cases:
484 * - Oneshot irq which did not wake the thread (caused by a
485 * spurious interrupt or a primary handler handling it
486 * completely).
487 */
488 if (!irqd_irq_disabled(&desc->irq_data) &&
489 irqd_irq_masked(&desc->irq_data) && !desc->threads_oneshot) {
490 chip->irq_eoi(&desc->irq_data);
491 unmask_irq(desc);
492 } else if (!(chip->flags & IRQCHIP_EOI_THREADED)) {
493 chip->irq_eoi(&desc->irq_data);
494 }
495}
496
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700497/**
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700498 * handle_fasteoi_irq - irq handler for transparent controllers
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700499 * @irq: the interrupt number
500 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700501 *
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700502 * Only a single callback will be issued to the chip: an ->eoi()
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700503 * call when the interrupt has been serviced. This enables support
504 * for modern forms of interrupt handlers, which handle the flow
505 * details in hardware, transparently.
506 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800507void
David Howells7d12e782006-10-05 14:55:46 +0100508handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700509{
Thomas Gleixner328a4972014-03-13 19:03:51 +0100510 struct irq_chip *chip = desc->irq_data.chip;
511
Thomas Gleixner239007b2009-11-17 16:46:45 +0100512 raw_spin_lock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700513
Thomas Gleixnerc7bd3ec02014-08-29 13:39:37 +0200514 if (!irq_may_run(desc))
515 goto out;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700516
Thomas Gleixner163ef302011-02-08 11:39:15 +0100517 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Jiang Liub51bf952015-06-04 12:13:25 +0800518 kstat_incr_irqs_this_cpu(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700519
520 /*
521 * If its disabled or no action available
Ingo Molnar76d21602007-02-16 01:28:24 -0800522 * then mask it and get out of here:
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700523 */
Thomas Gleixner32f41252011-03-28 14:10:52 +0200524 if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) {
Thomas Gleixner2a0d6fb2011-02-08 12:17:57 +0100525 desc->istate |= IRQS_PENDING;
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000526 mask_irq(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700527 goto out;
Benjamin Herrenschmidt98bb2442006-06-29 02:25:01 -0700528 }
Thomas Gleixnerc69e3752011-03-02 11:49:21 +0100529
530 if (desc->istate & IRQS_ONESHOT)
531 mask_irq(desc);
532
Thomas Gleixner78129572011-02-10 15:14:20 +0100533 preflow_handler(desc);
Thomas Gleixnera7ae4de2011-02-07 01:23:07 +0100534 handle_irq_event(desc);
Thomas Gleixner77694b42011-02-15 10:33:57 +0100535
Thomas Gleixner328a4972014-03-13 19:03:51 +0100536 cond_unmask_eoi_irq(desc, chip);
Thomas Gleixnerac563762012-02-07 17:58:03 +0100537
Thomas Gleixner239007b2009-11-17 16:46:45 +0100538 raw_spin_unlock(&desc->lock);
Thomas Gleixner77694b42011-02-15 10:33:57 +0100539 return;
540out:
Thomas Gleixner328a4972014-03-13 19:03:51 +0100541 if (!(chip->flags & IRQCHIP_EOI_IF_HANDLED))
542 chip->irq_eoi(&desc->irq_data);
543 raw_spin_unlock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700544}
Vincent Stehlé7cad45e2014-08-22 01:31:20 +0200545EXPORT_SYMBOL_GPL(handle_fasteoi_irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700546
547/**
548 * handle_edge_irq - edge type IRQ handler
549 * @irq: the interrupt number
550 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700551 *
552 * Interrupt occures on the falling and/or rising edge of a hardware
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300553 * signal. The occurrence is latched into the irq controller hardware
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700554 * and must be acked in order to be reenabled. After the ack another
555 * interrupt can happen on the same source even before the first one
Uwe Kleine-Königdfff0612010-02-12 21:58:11 +0100556 * is handled by the associated event handler. If this happens it
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700557 * might be necessary to disable (mask) the interrupt depending on the
558 * controller hardware. This requires to reenable the interrupt inside
559 * of the loop which handles the interrupts which have arrived while
560 * the handler was running. If all pending interrupts are handled, the
561 * loop is left.
562 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800563void
David Howells7d12e782006-10-05 14:55:46 +0100564handle_edge_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700565{
Thomas Gleixner239007b2009-11-17 16:46:45 +0100566 raw_spin_lock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700567
Thomas Gleixner163ef302011-02-08 11:39:15 +0100568 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Thomas Gleixnerc3d7acd2014-08-29 13:46:08 +0200569
Thomas Gleixnerc7bd3ec02014-08-29 13:39:37 +0200570 if (!irq_may_run(desc)) {
571 desc->istate |= IRQS_PENDING;
572 mask_ack_irq(desc);
573 goto out_unlock;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700574 }
Thomas Gleixnerc3d7acd2014-08-29 13:46:08 +0200575
576 /*
577 * If its disabled or no action available then mask it and get
578 * out of here.
579 */
580 if (irqd_irq_disabled(&desc->irq_data) || !desc->action) {
581 desc->istate |= IRQS_PENDING;
582 mask_ack_irq(desc);
583 goto out_unlock;
584 }
585
Jiang Liub51bf952015-06-04 12:13:25 +0800586 kstat_incr_irqs_this_cpu(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700587
588 /* Start handling the irq */
Thomas Gleixner22a49162010-09-27 12:44:47 +0000589 desc->irq_data.chip->irq_ack(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700590
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700591 do {
Thomas Gleixnera60a5dc2011-02-07 01:24:07 +0100592 if (unlikely(!desc->action)) {
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000593 mask_irq(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700594 goto out_unlock;
595 }
596
597 /*
598 * When another irq arrived while we were handling
599 * one, we could have masked the irq.
600 * Renable it, if it was not disabled in meantime.
601 */
Thomas Gleixner2a0d6fb2011-02-08 12:17:57 +0100602 if (unlikely(desc->istate & IRQS_PENDING)) {
Thomas Gleixner32f41252011-03-28 14:10:52 +0200603 if (!irqd_irq_disabled(&desc->irq_data) &&
604 irqd_irq_masked(&desc->irq_data))
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100605 unmask_irq(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700606 }
607
Thomas Gleixnera60a5dc2011-02-07 01:24:07 +0100608 handle_irq_event(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700609
Thomas Gleixner2a0d6fb2011-02-08 12:17:57 +0100610 } while ((desc->istate & IRQS_PENDING) &&
Thomas Gleixner32f41252011-03-28 14:10:52 +0200611 !irqd_irq_disabled(&desc->irq_data));
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700612
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700613out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100614 raw_spin_unlock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700615}
Jiri Kosina3911ff32012-05-13 12:13:15 +0200616EXPORT_SYMBOL(handle_edge_irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700617
Thomas Gleixner0521c8f2011-03-28 16:13:24 +0200618#ifdef CONFIG_IRQ_EDGE_EOI_HANDLER
619/**
620 * handle_edge_eoi_irq - edge eoi type IRQ handler
621 * @irq: the interrupt number
622 * @desc: the interrupt description structure for this irq
623 *
624 * Similar as the above handle_edge_irq, but using eoi and w/o the
625 * mask/unmask logic.
626 */
627void handle_edge_eoi_irq(unsigned int irq, struct irq_desc *desc)
628{
629 struct irq_chip *chip = irq_desc_get_chip(desc);
630
631 raw_spin_lock(&desc->lock);
632
633 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Thomas Gleixnerc3d7acd2014-08-29 13:46:08 +0200634
Thomas Gleixnerc7bd3ec02014-08-29 13:39:37 +0200635 if (!irq_may_run(desc)) {
636 desc->istate |= IRQS_PENDING;
637 goto out_eoi;
Thomas Gleixner0521c8f2011-03-28 16:13:24 +0200638 }
Thomas Gleixnerc3d7acd2014-08-29 13:46:08 +0200639
640 /*
641 * If its disabled or no action available then mask it and get
642 * out of here.
643 */
644 if (irqd_irq_disabled(&desc->irq_data) || !desc->action) {
645 desc->istate |= IRQS_PENDING;
646 goto out_eoi;
647 }
648
Jiang Liub51bf952015-06-04 12:13:25 +0800649 kstat_incr_irqs_this_cpu(desc);
Thomas Gleixner0521c8f2011-03-28 16:13:24 +0200650
651 do {
652 if (unlikely(!desc->action))
653 goto out_eoi;
654
655 handle_irq_event(desc);
656
657 } while ((desc->istate & IRQS_PENDING) &&
658 !irqd_irq_disabled(&desc->irq_data));
659
Stephen Rothwellac0e0442011-03-30 10:55:12 +1100660out_eoi:
Thomas Gleixner0521c8f2011-03-28 16:13:24 +0200661 chip->irq_eoi(&desc->irq_data);
662 raw_spin_unlock(&desc->lock);
663}
664#endif
665
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700666/**
Liuweni24b26d42009-11-04 20:11:05 +0800667 * handle_percpu_irq - Per CPU local irq handler
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700668 * @irq: the interrupt number
669 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700670 *
671 * Per CPU interrupts on SMP machines without locking requirements
672 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800673void
David Howells7d12e782006-10-05 14:55:46 +0100674handle_percpu_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700675{
Thomas Gleixner35e857c2011-02-10 12:20:23 +0100676 struct irq_chip *chip = irq_desc_get_chip(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700677
Jiang Liub51bf952015-06-04 12:13:25 +0800678 kstat_incr_irqs_this_cpu(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700679
Thomas Gleixner849f0612011-02-07 01:25:41 +0100680 if (chip->irq_ack)
681 chip->irq_ack(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700682
Thomas Gleixner849f0612011-02-07 01:25:41 +0100683 handle_irq_event_percpu(desc, desc->action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700684
Thomas Gleixner849f0612011-02-07 01:25:41 +0100685 if (chip->irq_eoi)
686 chip->irq_eoi(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700687}
688
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100689/**
690 * handle_percpu_devid_irq - Per CPU local irq handler with per cpu dev ids
691 * @irq: the interrupt number
692 * @desc: the interrupt description structure for this irq
693 *
694 * Per CPU interrupts on SMP machines without locking requirements. Same as
695 * handle_percpu_irq() above but with the following extras:
696 *
697 * action->percpu_dev_id is a pointer to percpu variables which
698 * contain the real device id for the cpu on which this handler is
699 * called
700 */
701void handle_percpu_devid_irq(unsigned int irq, struct irq_desc *desc)
702{
703 struct irq_chip *chip = irq_desc_get_chip(desc);
704 struct irqaction *action = desc->action;
Christoph Lameter532d0d02014-08-17 12:30:39 -0500705 void *dev_id = raw_cpu_ptr(action->percpu_dev_id);
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100706 irqreturn_t res;
707
Jiang Liub51bf952015-06-04 12:13:25 +0800708 kstat_incr_irqs_this_cpu(desc);
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100709
710 if (chip->irq_ack)
711 chip->irq_ack(&desc->irq_data);
712
713 trace_irq_handler_entry(irq, action);
714 res = action->handler(irq, dev_id);
715 trace_irq_handler_exit(irq, action, res);
716
717 if (chip->irq_eoi)
718 chip->irq_eoi(&desc->irq_data);
719}
720
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700721void
Russell King3b0f95b2015-06-16 23:06:20 +0100722__irq_do_set_handler(struct irq_desc *desc, irq_flow_handler_t handle,
723 int is_chained, const char *name)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700724{
Thomas Gleixner091738a2011-02-14 20:16:43 +0100725 if (!handle) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700726 handle = handle_bad_irq;
Thomas Gleixner091738a2011-02-14 20:16:43 +0100727 } else {
Marc Zyngierf86eff22014-11-15 10:49:13 +0000728 struct irq_data *irq_data = &desc->irq_data;
729#ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
730 /*
731 * With hierarchical domains we might run into a
732 * situation where the outermost chip is not yet set
733 * up, but the inner chips are there. Instead of
734 * bailing we install the handler, but obviously we
735 * cannot enable/startup the interrupt at this point.
736 */
737 while (irq_data) {
738 if (irq_data->chip != &no_irq_chip)
739 break;
740 /*
741 * Bail out if the outer chip is not set up
742 * and the interrrupt supposed to be started
743 * right away.
744 */
745 if (WARN_ON(is_chained))
Russell King3b0f95b2015-06-16 23:06:20 +0100746 return;
Marc Zyngierf86eff22014-11-15 10:49:13 +0000747 /* Try the parent */
748 irq_data = irq_data->parent_data;
749 }
750#endif
751 if (WARN_ON(!irq_data || irq_data->chip == &no_irq_chip))
Russell King3b0f95b2015-06-16 23:06:20 +0100752 return;
Thomas Gleixnerf8b54732006-07-01 22:30:08 +0100753 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700754
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700755 /* Uninstall? */
756 if (handle == handle_bad_irq) {
Thomas Gleixner6b8ff312010-10-01 12:58:38 +0200757 if (desc->irq_data.chip != &no_irq_chip)
Thomas Gleixner9205e312010-09-27 12:44:50 +0000758 mask_ack_irq(desc);
Thomas Gleixner801a0e92011-03-27 11:02:49 +0200759 irq_state_set_disabled(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700760 desc->depth = 1;
761 }
762 desc->handle_irq = handle;
Ingo Molnara460e742006-10-17 00:10:03 -0700763 desc->name = name;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700764
765 if (handle != handle_bad_irq && is_chained) {
Thomas Gleixner1ccb4e62011-02-09 14:44:17 +0100766 irq_settings_set_noprobe(desc);
767 irq_settings_set_norequest(desc);
Paul Mundt7f1b1242011-04-07 06:01:44 +0900768 irq_settings_set_nothread(desc);
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +0100769 irq_startup(desc, true);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700770 }
Russell King3b0f95b2015-06-16 23:06:20 +0100771}
772
773void
774__irq_set_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
775 const char *name)
776{
777 unsigned long flags;
778 struct irq_desc *desc = irq_get_desc_buslock(irq, &flags, 0);
779
780 if (!desc)
781 return;
782
783 __irq_do_set_handler(desc, handle, is_chained, name);
Thomas Gleixner02725e72011-02-12 10:37:36 +0100784 irq_put_desc_busunlock(desc, flags);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700785}
Thomas Gleixner3836ca02011-02-14 20:09:19 +0100786EXPORT_SYMBOL_GPL(__irq_set_handler);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700787
788void
Russell King3b0f95b2015-06-16 23:06:20 +0100789irq_set_chained_handler_and_data(unsigned int irq, irq_flow_handler_t handle,
790 void *data)
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, 1, NULL);
Jiang Liuaf7080e2015-06-01 16:05:21 +0800799 desc->irq_common_data.handler_data = data;
Russell King3b0f95b2015-06-16 23:06:20 +0100800
801 irq_put_desc_busunlock(desc, flags);
802}
803EXPORT_SYMBOL_GPL(irq_set_chained_handler_and_data);
804
805void
Thomas Gleixner3836ca02011-02-14 20:09:19 +0100806irq_set_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
Ingo Molnara460e742006-10-17 00:10:03 -0700807 irq_flow_handler_t handle, const char *name)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700808{
Thomas Gleixner35e857c2011-02-10 12:20:23 +0100809 irq_set_chip(irq, chip);
Thomas Gleixner3836ca02011-02-14 20:09:19 +0100810 __irq_set_handler(irq, handle, 0, name);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700811}
Kuninori Morimotob3ae66f2012-07-30 22:39:06 -0700812EXPORT_SYMBOL_GPL(irq_set_chip_and_handler_name);
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800813
Thomas Gleixner44247182010-09-28 10:40:18 +0200814void irq_modify_status(unsigned int irq, unsigned long clr, unsigned long set)
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800815{
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800816 unsigned long flags;
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100817 struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0);
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800818
Thomas Gleixner44247182010-09-28 10:40:18 +0200819 if (!desc)
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800820 return;
Thomas Gleixnera0056772011-02-08 17:11:03 +0100821 irq_settings_clr_and_set(desc, clr, set);
822
Thomas Gleixner876dbd42011-02-08 17:28:12 +0100823 irqd_clear(&desc->irq_data, IRQD_NO_BALANCING | IRQD_PER_CPU |
Thomas Gleixnere1ef8242011-02-10 22:25:31 +0100824 IRQD_TRIGGER_MASK | IRQD_LEVEL | IRQD_MOVE_PCNTXT);
Thomas Gleixnera0056772011-02-08 17:11:03 +0100825 if (irq_settings_has_no_balance_set(desc))
826 irqd_set(&desc->irq_data, IRQD_NO_BALANCING);
827 if (irq_settings_is_per_cpu(desc))
828 irqd_set(&desc->irq_data, IRQD_PER_CPU);
Thomas Gleixnere1ef8242011-02-10 22:25:31 +0100829 if (irq_settings_can_move_pcntxt(desc))
830 irqd_set(&desc->irq_data, IRQD_MOVE_PCNTXT);
Thomas Gleixner0ef5ca12011-03-28 21:59:37 +0200831 if (irq_settings_is_level(desc))
832 irqd_set(&desc->irq_data, IRQD_LEVEL);
Thomas Gleixnera0056772011-02-08 17:11:03 +0100833
Thomas Gleixner876dbd42011-02-08 17:28:12 +0100834 irqd_set(&desc->irq_data, irq_settings_get_trigger_mask(desc));
835
Thomas Gleixner02725e72011-02-12 10:37:36 +0100836 irq_put_desc_unlock(desc, flags);
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800837}
Jonathan Cameronedf76f82011-05-18 10:39:04 +0100838EXPORT_SYMBOL_GPL(irq_modify_status);
David Daney0fdb4b22011-03-25 12:38:49 -0700839
840/**
841 * irq_cpu_online - Invoke all irq_cpu_online functions.
842 *
843 * Iterate through all irqs and invoke the chip.irq_cpu_online()
844 * for each.
845 */
846void irq_cpu_online(void)
847{
848 struct irq_desc *desc;
849 struct irq_chip *chip;
850 unsigned long flags;
851 unsigned int irq;
852
853 for_each_active_irq(irq) {
854 desc = irq_to_desc(irq);
855 if (!desc)
856 continue;
857
858 raw_spin_lock_irqsave(&desc->lock, flags);
859
860 chip = irq_data_get_irq_chip(&desc->irq_data);
Thomas Gleixnerb3d42232011-03-27 16:05:36 +0200861 if (chip && chip->irq_cpu_online &&
862 (!(chip->flags & IRQCHIP_ONOFFLINE_ENABLED) ||
Thomas Gleixner32f41252011-03-28 14:10:52 +0200863 !irqd_irq_disabled(&desc->irq_data)))
David Daney0fdb4b22011-03-25 12:38:49 -0700864 chip->irq_cpu_online(&desc->irq_data);
865
866 raw_spin_unlock_irqrestore(&desc->lock, flags);
867 }
868}
869
870/**
871 * irq_cpu_offline - Invoke all irq_cpu_offline functions.
872 *
873 * Iterate through all irqs and invoke the chip.irq_cpu_offline()
874 * for each.
875 */
876void irq_cpu_offline(void)
877{
878 struct irq_desc *desc;
879 struct irq_chip *chip;
880 unsigned long flags;
881 unsigned int irq;
882
883 for_each_active_irq(irq) {
884 desc = irq_to_desc(irq);
885 if (!desc)
886 continue;
887
888 raw_spin_lock_irqsave(&desc->lock, flags);
889
890 chip = irq_data_get_irq_chip(&desc->irq_data);
Thomas Gleixnerb3d42232011-03-27 16:05:36 +0200891 if (chip && chip->irq_cpu_offline &&
892 (!(chip->flags & IRQCHIP_ONOFFLINE_ENABLED) ||
Thomas Gleixner32f41252011-03-28 14:10:52 +0200893 !irqd_irq_disabled(&desc->irq_data)))
David Daney0fdb4b22011-03-25 12:38:49 -0700894 chip->irq_cpu_offline(&desc->irq_data);
895
896 raw_spin_unlock_irqrestore(&desc->lock, flags);
897 }
898}
Jiang Liu85f08c12014-11-06 22:20:16 +0800899
900#ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
901/**
Stefan Agner3cfeffc2015-05-16 11:44:14 +0200902 * irq_chip_enable_parent - Enable the parent interrupt (defaults to unmask if
903 * NULL)
904 * @data: Pointer to interrupt specific data
905 */
906void irq_chip_enable_parent(struct irq_data *data)
907{
908 data = data->parent_data;
909 if (data->chip->irq_enable)
910 data->chip->irq_enable(data);
911 else
912 data->chip->irq_unmask(data);
913}
914
915/**
916 * irq_chip_disable_parent - Disable the parent interrupt (defaults to mask if
917 * NULL)
918 * @data: Pointer to interrupt specific data
919 */
920void irq_chip_disable_parent(struct irq_data *data)
921{
922 data = data->parent_data;
923 if (data->chip->irq_disable)
924 data->chip->irq_disable(data);
925 else
926 data->chip->irq_mask(data);
927}
928
929/**
Jiang Liu85f08c12014-11-06 22:20:16 +0800930 * irq_chip_ack_parent - Acknowledge the parent interrupt
931 * @data: Pointer to interrupt specific data
932 */
933void irq_chip_ack_parent(struct irq_data *data)
934{
935 data = data->parent_data;
936 data->chip->irq_ack(data);
937}
938
939/**
Yingjoe Chen56e8aba2014-11-13 23:37:05 +0800940 * irq_chip_mask_parent - Mask the parent interrupt
941 * @data: Pointer to interrupt specific data
942 */
943void irq_chip_mask_parent(struct irq_data *data)
944{
945 data = data->parent_data;
946 data->chip->irq_mask(data);
947}
948
949/**
950 * irq_chip_unmask_parent - Unmask the parent interrupt
951 * @data: Pointer to interrupt specific data
952 */
953void irq_chip_unmask_parent(struct irq_data *data)
954{
955 data = data->parent_data;
956 data->chip->irq_unmask(data);
957}
958
959/**
960 * irq_chip_eoi_parent - Invoke EOI on the parent interrupt
961 * @data: Pointer to interrupt specific data
962 */
963void irq_chip_eoi_parent(struct irq_data *data)
964{
965 data = data->parent_data;
966 data->chip->irq_eoi(data);
967}
968
969/**
970 * irq_chip_set_affinity_parent - Set affinity on the parent interrupt
971 * @data: Pointer to interrupt specific data
972 * @dest: The affinity mask to set
973 * @force: Flag to enforce setting (disable online checks)
974 *
975 * Conditinal, as the underlying parent chip might not implement it.
976 */
977int irq_chip_set_affinity_parent(struct irq_data *data,
978 const struct cpumask *dest, bool force)
979{
980 data = data->parent_data;
981 if (data->chip->irq_set_affinity)
982 return data->chip->irq_set_affinity(data, dest, force);
983
984 return -ENOSYS;
985}
986
987/**
Grygorii Strashkob7560de2015-08-14 15:20:26 +0300988 * irq_chip_set_type_parent - Set IRQ type on the parent interrupt
989 * @data: Pointer to interrupt specific data
990 * @type: IRQ_TYPE_{LEVEL,EDGE}_* value - see include/linux/irq.h
991 *
992 * Conditional, as the underlying parent chip might not implement it.
993 */
994int irq_chip_set_type_parent(struct irq_data *data, unsigned int type)
995{
996 data = data->parent_data;
997
998 if (data->chip->irq_set_type)
999 return data->chip->irq_set_type(data, type);
1000
1001 return -ENOSYS;
1002}
1003
1004/**
Jiang Liu85f08c12014-11-06 22:20:16 +08001005 * irq_chip_retrigger_hierarchy - Retrigger an interrupt in hardware
1006 * @data: Pointer to interrupt specific data
1007 *
1008 * Iterate through the domain hierarchy of the interrupt and check
1009 * whether a hw retrigger function exists. If yes, invoke it.
1010 */
1011int irq_chip_retrigger_hierarchy(struct irq_data *data)
1012{
1013 for (data = data->parent_data; data; data = data->parent_data)
1014 if (data->chip && data->chip->irq_retrigger)
1015 return data->chip->irq_retrigger(data);
1016
Grygorii Strashko6d4affe2015-08-14 15:20:25 +03001017 return 0;
Jiang Liu85f08c12014-11-06 22:20:16 +08001018}
Marc Zyngier08b55e22015-03-11 15:43:43 +00001019
1020/**
Jiang Liu0a4377d2015-05-19 17:07:14 +08001021 * irq_chip_set_vcpu_affinity_parent - Set vcpu affinity on the parent interrupt
1022 * @data: Pointer to interrupt specific data
Masanari Iida8505a812015-07-29 19:09:36 +09001023 * @vcpu_info: The vcpu affinity information
Jiang Liu0a4377d2015-05-19 17:07:14 +08001024 */
1025int irq_chip_set_vcpu_affinity_parent(struct irq_data *data, void *vcpu_info)
1026{
1027 data = data->parent_data;
1028 if (data->chip->irq_set_vcpu_affinity)
1029 return data->chip->irq_set_vcpu_affinity(data, vcpu_info);
1030
1031 return -ENOSYS;
1032}
1033
1034/**
Marc Zyngier08b55e22015-03-11 15:43:43 +00001035 * irq_chip_set_wake_parent - Set/reset wake-up on the parent interrupt
1036 * @data: Pointer to interrupt specific data
1037 * @on: Whether to set or reset the wake-up capability of this irq
1038 *
1039 * Conditional, as the underlying parent chip might not implement it.
1040 */
1041int irq_chip_set_wake_parent(struct irq_data *data, unsigned int on)
1042{
1043 data = data->parent_data;
1044 if (data->chip->irq_set_wake)
1045 return data->chip->irq_set_wake(data, on);
1046
1047 return -ENOSYS;
1048}
Jiang Liu85f08c12014-11-06 22:20:16 +08001049#endif
Jiang Liu515085e2014-11-06 22:20:17 +08001050
1051/**
1052 * irq_chip_compose_msi_msg - Componse msi message for a irq chip
1053 * @data: Pointer to interrupt specific data
1054 * @msg: Pointer to the MSI message
1055 *
1056 * For hierarchical domains we find the first chip in the hierarchy
1057 * which implements the irq_compose_msi_msg callback. For non
1058 * hierarchical we use the top level chip.
1059 */
1060int irq_chip_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
1061{
1062 struct irq_data *pos = NULL;
1063
1064#ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
1065 for (; data; data = data->parent_data)
1066#endif
1067 if (data->chip && data->chip->irq_compose_msi_msg)
1068 pos = data;
1069 if (!pos)
1070 return -ENOSYS;
1071
1072 pos->chip->irq_compose_msi_msg(pos, msg);
1073
1074 return 0;
1075}