blob: a3bb14fbe5c61fec344a166f8b542571dab4704c [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>
18
Steven Rostedtf0696862012-01-25 20:18:55 -050019#include <trace/events/irq.h>
20
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070021#include "internals.h"
22
Eric W. Biederman3a16d712006-10-04 02:16:37 -070023/**
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010024 * irq_set_chip - set the irq chip for an irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070025 * @irq: irq number
26 * @chip: pointer to irq chip description structure
27 */
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010028int irq_set_chip(unsigned int irq, struct irq_chip *chip)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070029{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070030 unsigned long flags;
Marc Zyngier31d9d9b2011-09-23 17:03:06 +010031 struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070032
Thomas Gleixner02725e72011-02-12 10:37:36 +010033 if (!desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070034 return -EINVAL;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070035
36 if (!chip)
37 chip = &no_irq_chip;
38
Thomas Gleixner6b8ff312010-10-01 12:58:38 +020039 desc->irq_data.chip = chip;
Thomas Gleixner02725e72011-02-12 10:37:36 +010040 irq_put_desc_unlock(desc, flags);
David Daneyd72274e2011-03-25 12:38:48 -070041 /*
42 * For !CONFIG_SPARSE_IRQ make the irq show up in
43 * allocated_irqs. For the CONFIG_SPARSE_IRQ case, it is
44 * already marked, and this call is harmless.
45 */
46 irq_reserve_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;
Russell Kinga09b6592012-03-05 15:07:25 -080066 ret = __irq_set_trigger(desc, irq, 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;
Thomas Gleixner6b8ff312010-10-01 12:58:38 +020086 desc->irq_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
Thomas Gleixner3aae9942011-02-04 10:17:52 +0100182 if (desc->irq_data.chip->irq_startup) {
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +0100183 ret = desc->irq_data.chip->irq_startup(&desc->irq_data);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100184 irq_state_clr_masked(desc);
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +0100185 } else {
186 irq_enable(desc);
Thomas Gleixner3aae9942011-02-04 10:17:52 +0100187 }
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +0100188 if (resend)
189 check_irq_resend(desc, desc->irq_data.irq);
190 return ret;
Thomas Gleixner46999232011-02-02 21:41:14 +0000191}
192
193void irq_shutdown(struct irq_desc *desc)
194{
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100195 irq_state_set_disabled(desc);
Thomas Gleixner46999232011-02-02 21:41:14 +0000196 desc->depth = 1;
Thomas Gleixner50f7c032011-02-03 13:23:54 +0100197 if (desc->irq_data.chip->irq_shutdown)
198 desc->irq_data.chip->irq_shutdown(&desc->irq_data);
Geert Uytterhoevened585a62011-09-11 13:59:27 +0200199 else if (desc->irq_data.chip->irq_disable)
Thomas Gleixner50f7c032011-02-03 13:23:54 +0100200 desc->irq_data.chip->irq_disable(&desc->irq_data);
201 else
202 desc->irq_data.chip->irq_mask(&desc->irq_data);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100203 irq_state_set_masked(desc);
Thomas Gleixner46999232011-02-02 21:41:14 +0000204}
205
Thomas Gleixner87923472011-02-03 12:27:44 +0100206void irq_enable(struct irq_desc *desc)
207{
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100208 irq_state_clr_disabled(desc);
Thomas Gleixner50f7c032011-02-03 13:23:54 +0100209 if (desc->irq_data.chip->irq_enable)
210 desc->irq_data.chip->irq_enable(&desc->irq_data);
211 else
212 desc->irq_data.chip->irq_unmask(&desc->irq_data);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100213 irq_state_clr_masked(desc);
Thomas Gleixner87923472011-02-03 12:27:44 +0100214}
215
Andreas Fenkartd671a602013-05-10 12:21:30 +0200216/**
217 * irq_disable - Mark interupt disabled
218 * @desc: irq descriptor which should be disabled
219 *
220 * If the chip does not implement the irq_disable callback, we
221 * use a lazy disable approach. That means we mark the interrupt
222 * disabled, but leave the hardware unmasked. That's an
223 * optimization because we avoid the hardware access for the
224 * common case where no interrupt happens after we marked it
225 * disabled. If an interrupt happens, then the interrupt flow
226 * handler masks the line at the hardware level and marks it
227 * pending.
228 */
Thomas Gleixner87923472011-02-03 12:27:44 +0100229void irq_disable(struct irq_desc *desc)
230{
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100231 irq_state_set_disabled(desc);
Thomas Gleixner50f7c032011-02-03 13:23:54 +0100232 if (desc->irq_data.chip->irq_disable) {
233 desc->irq_data.chip->irq_disable(&desc->irq_data);
Thomas Gleixnera61d8252011-02-21 12:54:34 +0100234 irq_state_set_masked(desc);
Thomas Gleixner50f7c032011-02-03 13:23:54 +0100235 }
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100236}
237
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100238void irq_percpu_enable(struct irq_desc *desc, unsigned int cpu)
239{
240 if (desc->irq_data.chip->irq_enable)
241 desc->irq_data.chip->irq_enable(&desc->irq_data);
242 else
243 desc->irq_data.chip->irq_unmask(&desc->irq_data);
244 cpumask_set_cpu(cpu, desc->percpu_enabled);
245}
246
247void irq_percpu_disable(struct irq_desc *desc, unsigned int cpu)
248{
249 if (desc->irq_data.chip->irq_disable)
250 desc->irq_data.chip->irq_disable(&desc->irq_data);
251 else
252 desc->irq_data.chip->irq_mask(&desc->irq_data);
253 cpumask_clear_cpu(cpu, desc->percpu_enabled);
254}
255
Thomas Gleixner9205e312010-09-27 12:44:50 +0000256static inline void mask_ack_irq(struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700257{
Thomas Gleixner9205e312010-09-27 12:44:50 +0000258 if (desc->irq_data.chip->irq_mask_ack)
259 desc->irq_data.chip->irq_mask_ack(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700260 else {
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000261 desc->irq_data.chip->irq_mask(&desc->irq_data);
Thomas Gleixner22a49162010-09-27 12:44:47 +0000262 if (desc->irq_data.chip->irq_ack)
263 desc->irq_data.chip->irq_ack(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700264 }
Thomas Gleixner6e402622011-02-08 12:36:06 +0100265 irq_state_set_masked(desc);
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100266}
267
Thomas Gleixnerd4d5e082011-02-10 13:16:14 +0100268void mask_irq(struct irq_desc *desc)
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100269{
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000270 if (desc->irq_data.chip->irq_mask) {
271 desc->irq_data.chip->irq_mask(&desc->irq_data);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100272 irq_state_set_masked(desc);
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100273 }
274}
275
Thomas Gleixnerd4d5e082011-02-10 13:16:14 +0100276void unmask_irq(struct irq_desc *desc)
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100277{
Thomas Gleixner0eda58b2010-09-27 12:44:44 +0000278 if (desc->irq_data.chip->irq_unmask) {
279 desc->irq_data.chip->irq_unmask(&desc->irq_data);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100280 irq_state_clr_masked(desc);
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100281 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700282}
283
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200284/*
285 * handle_nested_irq - Handle a nested irq from a irq thread
286 * @irq: the interrupt number
287 *
288 * Handle interrupts which are nested into a threaded interrupt
289 * handler. The handler function is called inside the calling
290 * threads context.
291 */
292void handle_nested_irq(unsigned int irq)
293{
294 struct irq_desc *desc = irq_to_desc(irq);
295 struct irqaction *action;
296 irqreturn_t action_ret;
297
298 might_sleep();
299
Thomas Gleixner239007b2009-11-17 16:46:45 +0100300 raw_spin_lock_irq(&desc->lock);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200301
Thomas Gleixner293a7a02012-10-16 15:07:49 -0700302 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200303 kstat_incr_irqs_this_cpu(irq, desc);
304
305 action = desc->action;
Ning Jiang23812b92012-05-22 00:19:20 +0800306 if (unlikely(!action || irqd_irq_disabled(&desc->irq_data))) {
307 desc->istate |= IRQS_PENDING;
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200308 goto out_unlock;
Ning Jiang23812b92012-05-22 00:19:20 +0800309 }
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200310
Thomas Gleixner32f41252011-03-28 14:10:52 +0200311 irqd_set(&desc->irq_data, IRQD_IRQ_INPROGRESS);
Thomas Gleixner239007b2009-11-17 16:46:45 +0100312 raw_spin_unlock_irq(&desc->lock);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200313
314 action_ret = action->thread_fn(action->irq, action->dev_id);
315 if (!noirqdebug)
316 note_interrupt(irq, desc, action_ret);
317
Thomas Gleixner239007b2009-11-17 16:46:45 +0100318 raw_spin_lock_irq(&desc->lock);
Thomas Gleixner32f41252011-03-28 14:10:52 +0200319 irqd_clear(&desc->irq_data, IRQD_IRQ_INPROGRESS);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200320
321out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100322 raw_spin_unlock_irq(&desc->lock);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200323}
324EXPORT_SYMBOL_GPL(handle_nested_irq);
325
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100326static bool irq_check_poll(struct irq_desc *desc)
327{
Thomas Gleixner6954b752011-02-07 20:55:35 +0100328 if (!(desc->istate & IRQS_POLL_INPROGRESS))
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100329 return false;
330 return irq_wait_for_poll(desc);
331}
332
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700333/**
334 * handle_simple_irq - Simple and software-decoded IRQs.
335 * @irq: the interrupt number
336 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700337 *
338 * Simple interrupts are either sent from a demultiplexing interrupt
339 * handler or come from hardware, where no interrupt hardware control
340 * is necessary.
341 *
342 * Note: The caller is expected to handle the ack, clear, mask and
343 * unmask issues if necessary.
344 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800345void
David Howells7d12e782006-10-05 14:55:46 +0100346handle_simple_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700347{
Thomas Gleixner239007b2009-11-17 16:46:45 +0100348 raw_spin_lock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700349
Thomas Gleixner32f41252011-03-28 14:10:52 +0200350 if (unlikely(irqd_irq_inprogress(&desc->irq_data)))
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100351 if (!irq_check_poll(desc))
352 goto out_unlock;
353
Thomas Gleixner163ef302011-02-08 11:39:15 +0100354 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200355 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700356
Ning Jiang23812b92012-05-22 00:19:20 +0800357 if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) {
358 desc->istate |= IRQS_PENDING;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700359 goto out_unlock;
Ning Jiang23812b92012-05-22 00:19:20 +0800360 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700361
Thomas Gleixner107781e2011-02-07 01:21:02 +0100362 handle_irq_event(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700363
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700364out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100365 raw_spin_unlock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700366}
Jonathan Cameronedf76f82011-05-18 10:39:04 +0100367EXPORT_SYMBOL_GPL(handle_simple_irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700368
Thomas Gleixnerac563762012-02-07 17:58:03 +0100369/*
370 * Called unconditionally from handle_level_irq() and only for oneshot
371 * interrupts from handle_fasteoi_irq()
372 */
373static void cond_unmask_irq(struct irq_desc *desc)
374{
375 /*
376 * We need to unmask in the following cases:
377 * - Standard level irq (IRQF_ONESHOT is not set)
378 * - Oneshot irq which did not wake the thread (caused by a
379 * spurious interrupt or a primary handler handling it
380 * completely).
381 */
382 if (!irqd_irq_disabled(&desc->irq_data) &&
383 irqd_irq_masked(&desc->irq_data) && !desc->threads_oneshot)
384 unmask_irq(desc);
385}
386
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700387/**
388 * handle_level_irq - Level type irq handler
389 * @irq: the interrupt number
390 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700391 *
392 * Level type interrupts are active as long as the hardware line has
393 * the active level. This may require to mask the interrupt and unmask
394 * it after the associated handler has acknowledged the device, so the
395 * interrupt line is back to inactive.
396 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800397void
David Howells7d12e782006-10-05 14:55:46 +0100398handle_level_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700399{
Thomas Gleixner239007b2009-11-17 16:46:45 +0100400 raw_spin_lock(&desc->lock);
Thomas Gleixner9205e312010-09-27 12:44:50 +0000401 mask_ack_irq(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700402
Thomas Gleixner32f41252011-03-28 14:10:52 +0200403 if (unlikely(irqd_irq_inprogress(&desc->irq_data)))
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100404 if (!irq_check_poll(desc))
405 goto out_unlock;
406
Thomas Gleixner163ef302011-02-08 11:39:15 +0100407 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200408 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700409
410 /*
411 * If its disabled or no action available
412 * keep it masked and get out of here
413 */
Thomas Gleixnerd4dc0f92012-04-25 12:54:54 +0200414 if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) {
415 desc->istate |= IRQS_PENDING;
Ingo Molnar86998aa2006-09-19 11:14:34 +0200416 goto out_unlock;
Thomas Gleixnerd4dc0f92012-04-25 12:54:54 +0200417 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700418
Thomas Gleixner15298662011-02-07 01:22:17 +0100419 handle_irq_event(desc);
Thomas Gleixnerb25c3402009-08-13 12:17:22 +0200420
Thomas Gleixnerac563762012-02-07 17:58:03 +0100421 cond_unmask_irq(desc);
422
Ingo Molnar86998aa2006-09-19 11:14:34 +0200423out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100424 raw_spin_unlock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700425}
Ingo Molnar14819ea2009-01-14 12:34:21 +0100426EXPORT_SYMBOL_GPL(handle_level_irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700427
Thomas Gleixner78129572011-02-10 15:14:20 +0100428#ifdef CONFIG_IRQ_PREFLOW_FASTEOI
429static inline void preflow_handler(struct irq_desc *desc)
430{
431 if (desc->preflow_handler)
432 desc->preflow_handler(&desc->irq_data);
433}
434#else
435static inline void preflow_handler(struct irq_desc *desc) { }
436#endif
437
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700438/**
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700439 * handle_fasteoi_irq - irq handler for transparent controllers
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700440 * @irq: the interrupt number
441 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700442 *
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700443 * Only a single callback will be issued to the chip: an ->eoi()
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700444 * call when the interrupt has been serviced. This enables support
445 * for modern forms of interrupt handlers, which handle the flow
446 * details in hardware, transparently.
447 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800448void
David Howells7d12e782006-10-05 14:55:46 +0100449handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700450{
Thomas Gleixner239007b2009-11-17 16:46:45 +0100451 raw_spin_lock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700452
Thomas Gleixner32f41252011-03-28 14:10:52 +0200453 if (unlikely(irqd_irq_inprogress(&desc->irq_data)))
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100454 if (!irq_check_poll(desc))
455 goto out;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700456
Thomas Gleixner163ef302011-02-08 11:39:15 +0100457 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200458 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700459
460 /*
461 * If its disabled or no action available
Ingo Molnar76d21602007-02-16 01:28:24 -0800462 * then mask it and get out of here:
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700463 */
Thomas Gleixner32f41252011-03-28 14:10:52 +0200464 if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) {
Thomas Gleixner2a0d6fb2011-02-08 12:17:57 +0100465 desc->istate |= IRQS_PENDING;
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000466 mask_irq(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700467 goto out;
Benjamin Herrenschmidt98bb2442006-06-29 02:25:01 -0700468 }
Thomas Gleixnerc69e3752011-03-02 11:49:21 +0100469
470 if (desc->istate & IRQS_ONESHOT)
471 mask_irq(desc);
472
Thomas Gleixner78129572011-02-10 15:14:20 +0100473 preflow_handler(desc);
Thomas Gleixnera7ae4de2011-02-07 01:23:07 +0100474 handle_irq_event(desc);
Thomas Gleixner77694b42011-02-15 10:33:57 +0100475
Thomas Gleixnerac563762012-02-07 17:58:03 +0100476 if (desc->istate & IRQS_ONESHOT)
477 cond_unmask_irq(desc);
478
Thomas Gleixner77694b42011-02-15 10:33:57 +0100479out_eoi:
Thomas Gleixner0c5c1552010-09-27 12:44:53 +0000480 desc->irq_data.chip->irq_eoi(&desc->irq_data);
Thomas Gleixner77694b42011-02-15 10:33:57 +0100481out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100482 raw_spin_unlock(&desc->lock);
Thomas Gleixner77694b42011-02-15 10:33:57 +0100483 return;
484out:
485 if (!(desc->irq_data.chip->flags & IRQCHIP_EOI_IF_HANDLED))
486 goto out_eoi;
487 goto out_unlock;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700488}
489
490/**
491 * handle_edge_irq - edge type IRQ handler
492 * @irq: the interrupt number
493 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700494 *
495 * Interrupt occures on the falling and/or rising edge of a hardware
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300496 * signal. The occurrence is latched into the irq controller hardware
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700497 * and must be acked in order to be reenabled. After the ack another
498 * interrupt can happen on the same source even before the first one
Uwe Kleine-Königdfff0612010-02-12 21:58:11 +0100499 * is handled by the associated event handler. If this happens it
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700500 * might be necessary to disable (mask) the interrupt depending on the
501 * controller hardware. This requires to reenable the interrupt inside
502 * of the loop which handles the interrupts which have arrived while
503 * the handler was running. If all pending interrupts are handled, the
504 * loop is left.
505 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800506void
David Howells7d12e782006-10-05 14:55:46 +0100507handle_edge_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700508{
Thomas Gleixner239007b2009-11-17 16:46:45 +0100509 raw_spin_lock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700510
Thomas Gleixner163ef302011-02-08 11:39:15 +0100511 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700512 /*
513 * If we're currently running this IRQ, or its disabled,
514 * we shouldn't process the IRQ. Mark it pending, handle
515 * the necessary masking and go out
516 */
Thomas Gleixner32f41252011-03-28 14:10:52 +0200517 if (unlikely(irqd_irq_disabled(&desc->irq_data) ||
518 irqd_irq_inprogress(&desc->irq_data) || !desc->action)) {
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100519 if (!irq_check_poll(desc)) {
Thomas Gleixner2a0d6fb2011-02-08 12:17:57 +0100520 desc->istate |= IRQS_PENDING;
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100521 mask_ack_irq(desc);
522 goto out_unlock;
523 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700524 }
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200525 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700526
527 /* Start handling the irq */
Thomas Gleixner22a49162010-09-27 12:44:47 +0000528 desc->irq_data.chip->irq_ack(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700529
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700530 do {
Thomas Gleixnera60a5dc2011-02-07 01:24:07 +0100531 if (unlikely(!desc->action)) {
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000532 mask_irq(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700533 goto out_unlock;
534 }
535
536 /*
537 * When another irq arrived while we were handling
538 * one, we could have masked the irq.
539 * Renable it, if it was not disabled in meantime.
540 */
Thomas Gleixner2a0d6fb2011-02-08 12:17:57 +0100541 if (unlikely(desc->istate & IRQS_PENDING)) {
Thomas Gleixner32f41252011-03-28 14:10:52 +0200542 if (!irqd_irq_disabled(&desc->irq_data) &&
543 irqd_irq_masked(&desc->irq_data))
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100544 unmask_irq(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700545 }
546
Thomas Gleixnera60a5dc2011-02-07 01:24:07 +0100547 handle_irq_event(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700548
Thomas Gleixner2a0d6fb2011-02-08 12:17:57 +0100549 } while ((desc->istate & IRQS_PENDING) &&
Thomas Gleixner32f41252011-03-28 14:10:52 +0200550 !irqd_irq_disabled(&desc->irq_data));
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700551
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700552out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100553 raw_spin_unlock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700554}
Jiri Kosina3911ff32012-05-13 12:13:15 +0200555EXPORT_SYMBOL(handle_edge_irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700556
Thomas Gleixner0521c8f2011-03-28 16:13:24 +0200557#ifdef CONFIG_IRQ_EDGE_EOI_HANDLER
558/**
559 * handle_edge_eoi_irq - edge eoi type IRQ handler
560 * @irq: the interrupt number
561 * @desc: the interrupt description structure for this irq
562 *
563 * Similar as the above handle_edge_irq, but using eoi and w/o the
564 * mask/unmask logic.
565 */
566void handle_edge_eoi_irq(unsigned int irq, struct irq_desc *desc)
567{
568 struct irq_chip *chip = irq_desc_get_chip(desc);
569
570 raw_spin_lock(&desc->lock);
571
572 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
573 /*
574 * If we're currently running this IRQ, or its disabled,
575 * we shouldn't process the IRQ. Mark it pending, handle
576 * the necessary masking and go out
577 */
578 if (unlikely(irqd_irq_disabled(&desc->irq_data) ||
579 irqd_irq_inprogress(&desc->irq_data) || !desc->action)) {
580 if (!irq_check_poll(desc)) {
581 desc->istate |= IRQS_PENDING;
582 goto out_eoi;
583 }
584 }
585 kstat_incr_irqs_this_cpu(irq, desc);
586
587 do {
588 if (unlikely(!desc->action))
589 goto out_eoi;
590
591 handle_irq_event(desc);
592
593 } while ((desc->istate & IRQS_PENDING) &&
594 !irqd_irq_disabled(&desc->irq_data));
595
Stephen Rothwellac0e0442011-03-30 10:55:12 +1100596out_eoi:
Thomas Gleixner0521c8f2011-03-28 16:13:24 +0200597 chip->irq_eoi(&desc->irq_data);
598 raw_spin_unlock(&desc->lock);
599}
600#endif
601
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700602/**
Liuweni24b26d42009-11-04 20:11:05 +0800603 * handle_percpu_irq - Per CPU local irq handler
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700604 * @irq: the interrupt number
605 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700606 *
607 * Per CPU interrupts on SMP machines without locking requirements
608 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800609void
David Howells7d12e782006-10-05 14:55:46 +0100610handle_percpu_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700611{
Thomas Gleixner35e857c2011-02-10 12:20:23 +0100612 struct irq_chip *chip = irq_desc_get_chip(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700613
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200614 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700615
Thomas Gleixner849f0612011-02-07 01:25:41 +0100616 if (chip->irq_ack)
617 chip->irq_ack(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700618
Thomas Gleixner849f0612011-02-07 01:25:41 +0100619 handle_irq_event_percpu(desc, desc->action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700620
Thomas Gleixner849f0612011-02-07 01:25:41 +0100621 if (chip->irq_eoi)
622 chip->irq_eoi(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700623}
624
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100625/**
626 * handle_percpu_devid_irq - Per CPU local irq handler with per cpu dev ids
627 * @irq: the interrupt number
628 * @desc: the interrupt description structure for this irq
629 *
630 * Per CPU interrupts on SMP machines without locking requirements. Same as
631 * handle_percpu_irq() above but with the following extras:
632 *
633 * action->percpu_dev_id is a pointer to percpu variables which
634 * contain the real device id for the cpu on which this handler is
635 * called
636 */
637void handle_percpu_devid_irq(unsigned int irq, struct irq_desc *desc)
638{
639 struct irq_chip *chip = irq_desc_get_chip(desc);
640 struct irqaction *action = desc->action;
641 void *dev_id = __this_cpu_ptr(action->percpu_dev_id);
642 irqreturn_t res;
643
644 kstat_incr_irqs_this_cpu(irq, desc);
645
646 if (chip->irq_ack)
647 chip->irq_ack(&desc->irq_data);
648
649 trace_irq_handler_entry(irq, action);
650 res = action->handler(irq, dev_id);
651 trace_irq_handler_exit(irq, action, res);
652
653 if (chip->irq_eoi)
654 chip->irq_eoi(&desc->irq_data);
655}
656
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700657void
Thomas Gleixner3836ca02011-02-14 20:09:19 +0100658__irq_set_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
Ingo Molnara460e742006-10-17 00:10:03 -0700659 const char *name)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700660{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700661 unsigned long flags;
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100662 struct irq_desc *desc = irq_get_desc_buslock(irq, &flags, 0);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700663
Thomas Gleixner02725e72011-02-12 10:37:36 +0100664 if (!desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700665 return;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700666
Thomas Gleixner091738a2011-02-14 20:16:43 +0100667 if (!handle) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700668 handle = handle_bad_irq;
Thomas Gleixner091738a2011-02-14 20:16:43 +0100669 } else {
670 if (WARN_ON(desc->irq_data.chip == &no_irq_chip))
Thomas Gleixner02725e72011-02-12 10:37:36 +0100671 goto out;
Thomas Gleixnerf8b54732006-07-01 22:30:08 +0100672 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700673
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700674 /* Uninstall? */
675 if (handle == handle_bad_irq) {
Thomas Gleixner6b8ff312010-10-01 12:58:38 +0200676 if (desc->irq_data.chip != &no_irq_chip)
Thomas Gleixner9205e312010-09-27 12:44:50 +0000677 mask_ack_irq(desc);
Thomas Gleixner801a0e92011-03-27 11:02:49 +0200678 irq_state_set_disabled(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700679 desc->depth = 1;
680 }
681 desc->handle_irq = handle;
Ingo Molnara460e742006-10-17 00:10:03 -0700682 desc->name = name;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700683
684 if (handle != handle_bad_irq && is_chained) {
Thomas Gleixner1ccb4e62011-02-09 14:44:17 +0100685 irq_settings_set_noprobe(desc);
686 irq_settings_set_norequest(desc);
Paul Mundt7f1b1242011-04-07 06:01:44 +0900687 irq_settings_set_nothread(desc);
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +0100688 irq_startup(desc, true);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700689 }
Thomas Gleixner02725e72011-02-12 10:37:36 +0100690out:
691 irq_put_desc_busunlock(desc, flags);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700692}
Thomas Gleixner3836ca02011-02-14 20:09:19 +0100693EXPORT_SYMBOL_GPL(__irq_set_handler);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700694
695void
Thomas Gleixner3836ca02011-02-14 20:09:19 +0100696irq_set_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
Ingo Molnara460e742006-10-17 00:10:03 -0700697 irq_flow_handler_t handle, const char *name)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700698{
Thomas Gleixner35e857c2011-02-10 12:20:23 +0100699 irq_set_chip(irq, chip);
Thomas Gleixner3836ca02011-02-14 20:09:19 +0100700 __irq_set_handler(irq, handle, 0, name);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700701}
Kuninori Morimotob3ae66f2012-07-30 22:39:06 -0700702EXPORT_SYMBOL_GPL(irq_set_chip_and_handler_name);
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800703
Thomas Gleixner44247182010-09-28 10:40:18 +0200704void irq_modify_status(unsigned int irq, unsigned long clr, unsigned long set)
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800705{
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800706 unsigned long flags;
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100707 struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0);
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800708
Thomas Gleixner44247182010-09-28 10:40:18 +0200709 if (!desc)
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800710 return;
Thomas Gleixnera0056772011-02-08 17:11:03 +0100711 irq_settings_clr_and_set(desc, clr, set);
712
Thomas Gleixner876dbd42011-02-08 17:28:12 +0100713 irqd_clear(&desc->irq_data, IRQD_NO_BALANCING | IRQD_PER_CPU |
Thomas Gleixnere1ef8242011-02-10 22:25:31 +0100714 IRQD_TRIGGER_MASK | IRQD_LEVEL | IRQD_MOVE_PCNTXT);
Thomas Gleixnera0056772011-02-08 17:11:03 +0100715 if (irq_settings_has_no_balance_set(desc))
716 irqd_set(&desc->irq_data, IRQD_NO_BALANCING);
717 if (irq_settings_is_per_cpu(desc))
718 irqd_set(&desc->irq_data, IRQD_PER_CPU);
Thomas Gleixnere1ef8242011-02-10 22:25:31 +0100719 if (irq_settings_can_move_pcntxt(desc))
720 irqd_set(&desc->irq_data, IRQD_MOVE_PCNTXT);
Thomas Gleixner0ef5ca12011-03-28 21:59:37 +0200721 if (irq_settings_is_level(desc))
722 irqd_set(&desc->irq_data, IRQD_LEVEL);
Thomas Gleixnera0056772011-02-08 17:11:03 +0100723
Thomas Gleixner876dbd42011-02-08 17:28:12 +0100724 irqd_set(&desc->irq_data, irq_settings_get_trigger_mask(desc));
725
Thomas Gleixner02725e72011-02-12 10:37:36 +0100726 irq_put_desc_unlock(desc, flags);
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800727}
Jonathan Cameronedf76f82011-05-18 10:39:04 +0100728EXPORT_SYMBOL_GPL(irq_modify_status);
David Daney0fdb4b22011-03-25 12:38:49 -0700729
730/**
731 * irq_cpu_online - Invoke all irq_cpu_online functions.
732 *
733 * Iterate through all irqs and invoke the chip.irq_cpu_online()
734 * for each.
735 */
736void irq_cpu_online(void)
737{
738 struct irq_desc *desc;
739 struct irq_chip *chip;
740 unsigned long flags;
741 unsigned int irq;
742
743 for_each_active_irq(irq) {
744 desc = irq_to_desc(irq);
745 if (!desc)
746 continue;
747
748 raw_spin_lock_irqsave(&desc->lock, flags);
749
750 chip = irq_data_get_irq_chip(&desc->irq_data);
Thomas Gleixnerb3d42232011-03-27 16:05:36 +0200751 if (chip && chip->irq_cpu_online &&
752 (!(chip->flags & IRQCHIP_ONOFFLINE_ENABLED) ||
Thomas Gleixner32f41252011-03-28 14:10:52 +0200753 !irqd_irq_disabled(&desc->irq_data)))
David Daney0fdb4b22011-03-25 12:38:49 -0700754 chip->irq_cpu_online(&desc->irq_data);
755
756 raw_spin_unlock_irqrestore(&desc->lock, flags);
757 }
758}
759
760/**
761 * irq_cpu_offline - Invoke all irq_cpu_offline functions.
762 *
763 * Iterate through all irqs and invoke the chip.irq_cpu_offline()
764 * for each.
765 */
766void irq_cpu_offline(void)
767{
768 struct irq_desc *desc;
769 struct irq_chip *chip;
770 unsigned long flags;
771 unsigned int irq;
772
773 for_each_active_irq(irq) {
774 desc = irq_to_desc(irq);
775 if (!desc)
776 continue;
777
778 raw_spin_lock_irqsave(&desc->lock, flags);
779
780 chip = irq_data_get_irq_chip(&desc->irq_data);
Thomas Gleixnerb3d42232011-03-27 16:05:36 +0200781 if (chip && chip->irq_cpu_offline &&
782 (!(chip->flags & IRQCHIP_ONOFFLINE_ENABLED) ||
Thomas Gleixner32f41252011-03-28 14:10:52 +0200783 !irqd_irq_disabled(&desc->irq_data)))
David Daney0fdb4b22011-03-25 12:38:49 -0700784 chip->irq_cpu_offline(&desc->irq_data);
785
786 raw_spin_unlock_irqrestore(&desc->lock, flags);
787 }
788}