blob: 3aca9f29d30ef4c5089ad97740588a31462fd22d [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/**
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010093 * irq_set_msi_desc - set MSI descriptor data for an irq
Eric W. Biederman5b912c12007-01-28 12:52:03 -070094 * @irq: Interrupt number
Randy Dunlap472900b2007-02-16 01:28:25 -080095 * @entry: Pointer to MSI descriptor data
Eric W. Biederman5b912c12007-01-28 12:52:03 -070096 *
Liuweni24b26d42009-11-04 20:11:05 +080097 * Set the MSI descriptor entry for an irq
Eric W. Biederman5b912c12007-01-28 12:52:03 -070098 */
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010099int irq_set_msi_desc(unsigned int irq, struct msi_desc *entry)
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700100{
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700101 unsigned long flags;
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100102 struct irq_desc *desc = irq_get_desc_lock(irq, &flags, IRQ_GET_DESC_CHECK_GLOBAL);
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700103
Thomas Gleixner02725e72011-02-12 10:37:36 +0100104 if (!desc)
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700105 return -EINVAL;
Thomas Gleixner6b8ff312010-10-01 12:58:38 +0200106 desc->irq_data.msi_desc = entry;
Michael Ellerman7fe37302007-04-18 19:39:21 +1000107 if (entry)
108 entry->irq = irq;
Thomas Gleixner02725e72011-02-12 10:37:36 +0100109 irq_put_desc_unlock(desc, flags);
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700110 return 0;
111}
112
113/**
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +0100114 * irq_set_chip_data - set irq chip data for an irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700115 * @irq: Interrupt number
116 * @data: Pointer to chip specific data
117 *
118 * Set the hardware irq chip data for an irq
119 */
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +0100120int irq_set_chip_data(unsigned int irq, void *data)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700121{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700122 unsigned long flags;
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100123 struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700124
Thomas Gleixner02725e72011-02-12 10:37:36 +0100125 if (!desc)
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700126 return -EINVAL;
Thomas Gleixner6b8ff312010-10-01 12:58:38 +0200127 desc->irq_data.chip_data = data;
Thomas Gleixner02725e72011-02-12 10:37:36 +0100128 irq_put_desc_unlock(desc, flags);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700129 return 0;
130}
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +0100131EXPORT_SYMBOL(irq_set_chip_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700132
Thomas Gleixnerf303a6d2010-09-28 17:34:01 +0200133struct irq_data *irq_get_irq_data(unsigned int irq)
134{
135 struct irq_desc *desc = irq_to_desc(irq);
136
137 return desc ? &desc->irq_data : NULL;
138}
139EXPORT_SYMBOL_GPL(irq_get_irq_data);
140
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100141static void irq_state_clr_disabled(struct irq_desc *desc)
142{
Thomas Gleixner801a0e92011-03-27 11:02:49 +0200143 irqd_clear(&desc->irq_data, IRQD_IRQ_DISABLED);
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100144}
145
146static void irq_state_set_disabled(struct irq_desc *desc)
147{
Thomas Gleixner801a0e92011-03-27 11:02:49 +0200148 irqd_set(&desc->irq_data, IRQD_IRQ_DISABLED);
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100149}
150
Thomas Gleixner6e402622011-02-08 12:36:06 +0100151static void irq_state_clr_masked(struct irq_desc *desc)
152{
Thomas Gleixner32f41252011-03-28 14:10:52 +0200153 irqd_clear(&desc->irq_data, IRQD_IRQ_MASKED);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100154}
155
156static void irq_state_set_masked(struct irq_desc *desc)
157{
Thomas Gleixner32f41252011-03-28 14:10:52 +0200158 irqd_set(&desc->irq_data, IRQD_IRQ_MASKED);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100159}
160
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +0100161int irq_startup(struct irq_desc *desc, bool resend)
Thomas Gleixner46999232011-02-02 21:41:14 +0000162{
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +0100163 int ret = 0;
164
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100165 irq_state_clr_disabled(desc);
Thomas Gleixner46999232011-02-02 21:41:14 +0000166 desc->depth = 0;
167
Thomas Gleixner3aae9942011-02-04 10:17:52 +0100168 if (desc->irq_data.chip->irq_startup) {
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +0100169 ret = desc->irq_data.chip->irq_startup(&desc->irq_data);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100170 irq_state_clr_masked(desc);
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +0100171 } else {
172 irq_enable(desc);
Thomas Gleixner3aae9942011-02-04 10:17:52 +0100173 }
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +0100174 if (resend)
175 check_irq_resend(desc, desc->irq_data.irq);
176 return ret;
Thomas Gleixner46999232011-02-02 21:41:14 +0000177}
178
179void irq_shutdown(struct irq_desc *desc)
180{
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100181 irq_state_set_disabled(desc);
Thomas Gleixner46999232011-02-02 21:41:14 +0000182 desc->depth = 1;
Thomas Gleixner50f7c032011-02-03 13:23:54 +0100183 if (desc->irq_data.chip->irq_shutdown)
184 desc->irq_data.chip->irq_shutdown(&desc->irq_data);
Geert Uytterhoevened585a62011-09-11 13:59:27 +0200185 else if (desc->irq_data.chip->irq_disable)
Thomas Gleixner50f7c032011-02-03 13:23:54 +0100186 desc->irq_data.chip->irq_disable(&desc->irq_data);
187 else
188 desc->irq_data.chip->irq_mask(&desc->irq_data);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100189 irq_state_set_masked(desc);
Thomas Gleixner46999232011-02-02 21:41:14 +0000190}
191
Thomas Gleixner87923472011-02-03 12:27:44 +0100192void irq_enable(struct irq_desc *desc)
193{
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100194 irq_state_clr_disabled(desc);
Thomas Gleixner50f7c032011-02-03 13:23:54 +0100195 if (desc->irq_data.chip->irq_enable)
196 desc->irq_data.chip->irq_enable(&desc->irq_data);
197 else
198 desc->irq_data.chip->irq_unmask(&desc->irq_data);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100199 irq_state_clr_masked(desc);
Thomas Gleixner87923472011-02-03 12:27:44 +0100200}
201
202void irq_disable(struct irq_desc *desc)
203{
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100204 irq_state_set_disabled(desc);
Thomas Gleixner50f7c032011-02-03 13:23:54 +0100205 if (desc->irq_data.chip->irq_disable) {
206 desc->irq_data.chip->irq_disable(&desc->irq_data);
Thomas Gleixnera61d8252011-02-21 12:54:34 +0100207 irq_state_set_masked(desc);
Thomas Gleixner50f7c032011-02-03 13:23:54 +0100208 }
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100209}
210
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100211void irq_percpu_enable(struct irq_desc *desc, unsigned int cpu)
212{
213 if (desc->irq_data.chip->irq_enable)
214 desc->irq_data.chip->irq_enable(&desc->irq_data);
215 else
216 desc->irq_data.chip->irq_unmask(&desc->irq_data);
217 cpumask_set_cpu(cpu, desc->percpu_enabled);
218}
219
220void irq_percpu_disable(struct irq_desc *desc, unsigned int cpu)
221{
222 if (desc->irq_data.chip->irq_disable)
223 desc->irq_data.chip->irq_disable(&desc->irq_data);
224 else
225 desc->irq_data.chip->irq_mask(&desc->irq_data);
226 cpumask_clear_cpu(cpu, desc->percpu_enabled);
227}
228
Thomas Gleixner9205e312010-09-27 12:44:50 +0000229static inline void mask_ack_irq(struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700230{
Thomas Gleixner9205e312010-09-27 12:44:50 +0000231 if (desc->irq_data.chip->irq_mask_ack)
232 desc->irq_data.chip->irq_mask_ack(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700233 else {
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000234 desc->irq_data.chip->irq_mask(&desc->irq_data);
Thomas Gleixner22a49162010-09-27 12:44:47 +0000235 if (desc->irq_data.chip->irq_ack)
236 desc->irq_data.chip->irq_ack(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700237 }
Thomas Gleixner6e402622011-02-08 12:36:06 +0100238 irq_state_set_masked(desc);
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100239}
240
Thomas Gleixnerd4d5e082011-02-10 13:16:14 +0100241void mask_irq(struct irq_desc *desc)
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100242{
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000243 if (desc->irq_data.chip->irq_mask) {
244 desc->irq_data.chip->irq_mask(&desc->irq_data);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100245 irq_state_set_masked(desc);
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100246 }
247}
248
Thomas Gleixnerd4d5e082011-02-10 13:16:14 +0100249void unmask_irq(struct irq_desc *desc)
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100250{
Thomas Gleixner0eda58b2010-09-27 12:44:44 +0000251 if (desc->irq_data.chip->irq_unmask) {
252 desc->irq_data.chip->irq_unmask(&desc->irq_data);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100253 irq_state_clr_masked(desc);
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100254 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700255}
256
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200257/*
258 * handle_nested_irq - Handle a nested irq from a irq thread
259 * @irq: the interrupt number
260 *
261 * Handle interrupts which are nested into a threaded interrupt
262 * handler. The handler function is called inside the calling
263 * threads context.
264 */
265void handle_nested_irq(unsigned int irq)
266{
267 struct irq_desc *desc = irq_to_desc(irq);
268 struct irqaction *action;
269 irqreturn_t action_ret;
270
271 might_sleep();
272
Thomas Gleixner239007b2009-11-17 16:46:45 +0100273 raw_spin_lock_irq(&desc->lock);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200274
Thomas Gleixner293a7a02012-10-16 15:07:49 -0700275 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200276 kstat_incr_irqs_this_cpu(irq, desc);
277
278 action = desc->action;
Ning Jiang23812b92012-05-22 00:19:20 +0800279 if (unlikely(!action || irqd_irq_disabled(&desc->irq_data))) {
280 desc->istate |= IRQS_PENDING;
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200281 goto out_unlock;
Ning Jiang23812b92012-05-22 00:19:20 +0800282 }
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200283
Thomas Gleixner32f41252011-03-28 14:10:52 +0200284 irqd_set(&desc->irq_data, IRQD_IRQ_INPROGRESS);
Thomas Gleixner239007b2009-11-17 16:46:45 +0100285 raw_spin_unlock_irq(&desc->lock);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200286
287 action_ret = action->thread_fn(action->irq, action->dev_id);
288 if (!noirqdebug)
289 note_interrupt(irq, desc, action_ret);
290
Thomas Gleixner239007b2009-11-17 16:46:45 +0100291 raw_spin_lock_irq(&desc->lock);
Thomas Gleixner32f41252011-03-28 14:10:52 +0200292 irqd_clear(&desc->irq_data, IRQD_IRQ_INPROGRESS);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200293
294out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100295 raw_spin_unlock_irq(&desc->lock);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200296}
297EXPORT_SYMBOL_GPL(handle_nested_irq);
298
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100299static bool irq_check_poll(struct irq_desc *desc)
300{
Thomas Gleixner6954b752011-02-07 20:55:35 +0100301 if (!(desc->istate & IRQS_POLL_INPROGRESS))
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100302 return false;
303 return irq_wait_for_poll(desc);
304}
305
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700306/**
307 * handle_simple_irq - Simple and software-decoded IRQs.
308 * @irq: the interrupt number
309 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700310 *
311 * Simple interrupts are either sent from a demultiplexing interrupt
312 * handler or come from hardware, where no interrupt hardware control
313 * is necessary.
314 *
315 * Note: The caller is expected to handle the ack, clear, mask and
316 * unmask issues if necessary.
317 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800318void
David Howells7d12e782006-10-05 14:55:46 +0100319handle_simple_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700320{
Thomas Gleixner239007b2009-11-17 16:46:45 +0100321 raw_spin_lock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700322
Thomas Gleixner32f41252011-03-28 14:10:52 +0200323 if (unlikely(irqd_irq_inprogress(&desc->irq_data)))
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100324 if (!irq_check_poll(desc))
325 goto out_unlock;
326
Thomas Gleixner163ef302011-02-08 11:39:15 +0100327 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200328 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700329
Ning Jiang23812b92012-05-22 00:19:20 +0800330 if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) {
331 desc->istate |= IRQS_PENDING;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700332 goto out_unlock;
Ning Jiang23812b92012-05-22 00:19:20 +0800333 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700334
Thomas Gleixner107781e2011-02-07 01:21:02 +0100335 handle_irq_event(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700336
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700337out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100338 raw_spin_unlock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700339}
Jonathan Cameronedf76f82011-05-18 10:39:04 +0100340EXPORT_SYMBOL_GPL(handle_simple_irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700341
Thomas Gleixnerac563762012-02-07 17:58:03 +0100342/*
343 * Called unconditionally from handle_level_irq() and only for oneshot
344 * interrupts from handle_fasteoi_irq()
345 */
346static void cond_unmask_irq(struct irq_desc *desc)
347{
348 /*
349 * We need to unmask in the following cases:
350 * - Standard level irq (IRQF_ONESHOT is not set)
351 * - Oneshot irq which did not wake the thread (caused by a
352 * spurious interrupt or a primary handler handling it
353 * completely).
354 */
355 if (!irqd_irq_disabled(&desc->irq_data) &&
356 irqd_irq_masked(&desc->irq_data) && !desc->threads_oneshot)
357 unmask_irq(desc);
358}
359
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700360/**
361 * handle_level_irq - Level type irq handler
362 * @irq: the interrupt number
363 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700364 *
365 * Level type interrupts are active as long as the hardware line has
366 * the active level. This may require to mask the interrupt and unmask
367 * it after the associated handler has acknowledged the device, so the
368 * interrupt line is back to inactive.
369 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800370void
David Howells7d12e782006-10-05 14:55:46 +0100371handle_level_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700372{
Thomas Gleixner239007b2009-11-17 16:46:45 +0100373 raw_spin_lock(&desc->lock);
Thomas Gleixner9205e312010-09-27 12:44:50 +0000374 mask_ack_irq(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700375
Thomas Gleixner32f41252011-03-28 14:10:52 +0200376 if (unlikely(irqd_irq_inprogress(&desc->irq_data)))
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100377 if (!irq_check_poll(desc))
378 goto out_unlock;
379
Thomas Gleixner163ef302011-02-08 11:39:15 +0100380 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200381 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700382
383 /*
384 * If its disabled or no action available
385 * keep it masked and get out of here
386 */
Thomas Gleixnerd4dc0f92012-04-25 12:54:54 +0200387 if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) {
388 desc->istate |= IRQS_PENDING;
Ingo Molnar86998aa2006-09-19 11:14:34 +0200389 goto out_unlock;
Thomas Gleixnerd4dc0f92012-04-25 12:54:54 +0200390 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700391
Thomas Gleixner15298662011-02-07 01:22:17 +0100392 handle_irq_event(desc);
Thomas Gleixnerb25c3402009-08-13 12:17:22 +0200393
Thomas Gleixnerac563762012-02-07 17:58:03 +0100394 cond_unmask_irq(desc);
395
Ingo Molnar86998aa2006-09-19 11:14:34 +0200396out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100397 raw_spin_unlock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700398}
Ingo Molnar14819ea2009-01-14 12:34:21 +0100399EXPORT_SYMBOL_GPL(handle_level_irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700400
Thomas Gleixner78129572011-02-10 15:14:20 +0100401#ifdef CONFIG_IRQ_PREFLOW_FASTEOI
402static inline void preflow_handler(struct irq_desc *desc)
403{
404 if (desc->preflow_handler)
405 desc->preflow_handler(&desc->irq_data);
406}
407#else
408static inline void preflow_handler(struct irq_desc *desc) { }
409#endif
410
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700411/**
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700412 * handle_fasteoi_irq - irq handler for transparent controllers
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700413 * @irq: the interrupt number
414 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700415 *
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700416 * Only a single callback will be issued to the chip: an ->eoi()
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700417 * call when the interrupt has been serviced. This enables support
418 * for modern forms of interrupt handlers, which handle the flow
419 * details in hardware, transparently.
420 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800421void
David Howells7d12e782006-10-05 14:55:46 +0100422handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700423{
Thomas Gleixner239007b2009-11-17 16:46:45 +0100424 raw_spin_lock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700425
Thomas Gleixner32f41252011-03-28 14:10:52 +0200426 if (unlikely(irqd_irq_inprogress(&desc->irq_data)))
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100427 if (!irq_check_poll(desc))
428 goto out;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700429
Thomas Gleixner163ef302011-02-08 11:39:15 +0100430 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200431 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700432
433 /*
434 * If its disabled or no action available
Ingo Molnar76d21602007-02-16 01:28:24 -0800435 * then mask it and get out of here:
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700436 */
Thomas Gleixner32f41252011-03-28 14:10:52 +0200437 if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) {
Thomas Gleixner2a0d6fb2011-02-08 12:17:57 +0100438 desc->istate |= IRQS_PENDING;
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000439 mask_irq(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700440 goto out;
Benjamin Herrenschmidt98bb2442006-06-29 02:25:01 -0700441 }
Thomas Gleixnerc69e3752011-03-02 11:49:21 +0100442
443 if (desc->istate & IRQS_ONESHOT)
444 mask_irq(desc);
445
Thomas Gleixner78129572011-02-10 15:14:20 +0100446 preflow_handler(desc);
Thomas Gleixnera7ae4de2011-02-07 01:23:07 +0100447 handle_irq_event(desc);
Thomas Gleixner77694b42011-02-15 10:33:57 +0100448
Thomas Gleixnerac563762012-02-07 17:58:03 +0100449 if (desc->istate & IRQS_ONESHOT)
450 cond_unmask_irq(desc);
451
Thomas Gleixner77694b42011-02-15 10:33:57 +0100452out_eoi:
Thomas Gleixner0c5c1552010-09-27 12:44:53 +0000453 desc->irq_data.chip->irq_eoi(&desc->irq_data);
Thomas Gleixner77694b42011-02-15 10:33:57 +0100454out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100455 raw_spin_unlock(&desc->lock);
Thomas Gleixner77694b42011-02-15 10:33:57 +0100456 return;
457out:
458 if (!(desc->irq_data.chip->flags & IRQCHIP_EOI_IF_HANDLED))
459 goto out_eoi;
460 goto out_unlock;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700461}
462
463/**
464 * handle_edge_irq - edge type IRQ handler
465 * @irq: the interrupt number
466 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700467 *
468 * Interrupt occures on the falling and/or rising edge of a hardware
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300469 * signal. The occurrence is latched into the irq controller hardware
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700470 * and must be acked in order to be reenabled. After the ack another
471 * interrupt can happen on the same source even before the first one
Uwe Kleine-Königdfff0612010-02-12 21:58:11 +0100472 * is handled by the associated event handler. If this happens it
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700473 * might be necessary to disable (mask) the interrupt depending on the
474 * controller hardware. This requires to reenable the interrupt inside
475 * of the loop which handles the interrupts which have arrived while
476 * the handler was running. If all pending interrupts are handled, the
477 * loop is left.
478 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800479void
David Howells7d12e782006-10-05 14:55:46 +0100480handle_edge_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700481{
Thomas Gleixner239007b2009-11-17 16:46:45 +0100482 raw_spin_lock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700483
Thomas Gleixner163ef302011-02-08 11:39:15 +0100484 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700485 /*
486 * If we're currently running this IRQ, or its disabled,
487 * we shouldn't process the IRQ. Mark it pending, handle
488 * the necessary masking and go out
489 */
Thomas Gleixner32f41252011-03-28 14:10:52 +0200490 if (unlikely(irqd_irq_disabled(&desc->irq_data) ||
491 irqd_irq_inprogress(&desc->irq_data) || !desc->action)) {
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100492 if (!irq_check_poll(desc)) {
Thomas Gleixner2a0d6fb2011-02-08 12:17:57 +0100493 desc->istate |= IRQS_PENDING;
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100494 mask_ack_irq(desc);
495 goto out_unlock;
496 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700497 }
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200498 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700499
500 /* Start handling the irq */
Thomas Gleixner22a49162010-09-27 12:44:47 +0000501 desc->irq_data.chip->irq_ack(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700502
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700503 do {
Thomas Gleixnera60a5dc2011-02-07 01:24:07 +0100504 if (unlikely(!desc->action)) {
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000505 mask_irq(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700506 goto out_unlock;
507 }
508
509 /*
510 * When another irq arrived while we were handling
511 * one, we could have masked the irq.
512 * Renable it, if it was not disabled in meantime.
513 */
Thomas Gleixner2a0d6fb2011-02-08 12:17:57 +0100514 if (unlikely(desc->istate & IRQS_PENDING)) {
Thomas Gleixner32f41252011-03-28 14:10:52 +0200515 if (!irqd_irq_disabled(&desc->irq_data) &&
516 irqd_irq_masked(&desc->irq_data))
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100517 unmask_irq(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700518 }
519
Thomas Gleixnera60a5dc2011-02-07 01:24:07 +0100520 handle_irq_event(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700521
Thomas Gleixner2a0d6fb2011-02-08 12:17:57 +0100522 } while ((desc->istate & IRQS_PENDING) &&
Thomas Gleixner32f41252011-03-28 14:10:52 +0200523 !irqd_irq_disabled(&desc->irq_data));
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700524
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700525out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100526 raw_spin_unlock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700527}
Jiri Kosina3911ff32012-05-13 12:13:15 +0200528EXPORT_SYMBOL(handle_edge_irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700529
Thomas Gleixner0521c8f2011-03-28 16:13:24 +0200530#ifdef CONFIG_IRQ_EDGE_EOI_HANDLER
531/**
532 * handle_edge_eoi_irq - edge eoi type IRQ handler
533 * @irq: the interrupt number
534 * @desc: the interrupt description structure for this irq
535 *
536 * Similar as the above handle_edge_irq, but using eoi and w/o the
537 * mask/unmask logic.
538 */
539void handle_edge_eoi_irq(unsigned int irq, struct irq_desc *desc)
540{
541 struct irq_chip *chip = irq_desc_get_chip(desc);
542
543 raw_spin_lock(&desc->lock);
544
545 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
546 /*
547 * If we're currently running this IRQ, or its disabled,
548 * we shouldn't process the IRQ. Mark it pending, handle
549 * the necessary masking and go out
550 */
551 if (unlikely(irqd_irq_disabled(&desc->irq_data) ||
552 irqd_irq_inprogress(&desc->irq_data) || !desc->action)) {
553 if (!irq_check_poll(desc)) {
554 desc->istate |= IRQS_PENDING;
555 goto out_eoi;
556 }
557 }
558 kstat_incr_irqs_this_cpu(irq, desc);
559
560 do {
561 if (unlikely(!desc->action))
562 goto out_eoi;
563
564 handle_irq_event(desc);
565
566 } while ((desc->istate & IRQS_PENDING) &&
567 !irqd_irq_disabled(&desc->irq_data));
568
Stephen Rothwellac0e0442011-03-30 10:55:12 +1100569out_eoi:
Thomas Gleixner0521c8f2011-03-28 16:13:24 +0200570 chip->irq_eoi(&desc->irq_data);
571 raw_spin_unlock(&desc->lock);
572}
573#endif
574
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700575/**
Liuweni24b26d42009-11-04 20:11:05 +0800576 * handle_percpu_irq - Per CPU local irq handler
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700577 * @irq: the interrupt number
578 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700579 *
580 * Per CPU interrupts on SMP machines without locking requirements
581 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800582void
David Howells7d12e782006-10-05 14:55:46 +0100583handle_percpu_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700584{
Thomas Gleixner35e857c2011-02-10 12:20:23 +0100585 struct irq_chip *chip = irq_desc_get_chip(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700586
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200587 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700588
Thomas Gleixner849f0612011-02-07 01:25:41 +0100589 if (chip->irq_ack)
590 chip->irq_ack(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700591
Thomas Gleixner849f0612011-02-07 01:25:41 +0100592 handle_irq_event_percpu(desc, desc->action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700593
Thomas Gleixner849f0612011-02-07 01:25:41 +0100594 if (chip->irq_eoi)
595 chip->irq_eoi(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700596}
597
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100598/**
599 * handle_percpu_devid_irq - Per CPU local irq handler with per cpu dev ids
600 * @irq: the interrupt number
601 * @desc: the interrupt description structure for this irq
602 *
603 * Per CPU interrupts on SMP machines without locking requirements. Same as
604 * handle_percpu_irq() above but with the following extras:
605 *
606 * action->percpu_dev_id is a pointer to percpu variables which
607 * contain the real device id for the cpu on which this handler is
608 * called
609 */
610void handle_percpu_devid_irq(unsigned int irq, struct irq_desc *desc)
611{
612 struct irq_chip *chip = irq_desc_get_chip(desc);
613 struct irqaction *action = desc->action;
614 void *dev_id = __this_cpu_ptr(action->percpu_dev_id);
615 irqreturn_t res;
616
617 kstat_incr_irqs_this_cpu(irq, desc);
618
619 if (chip->irq_ack)
620 chip->irq_ack(&desc->irq_data);
621
622 trace_irq_handler_entry(irq, action);
623 res = action->handler(irq, dev_id);
624 trace_irq_handler_exit(irq, action, res);
625
626 if (chip->irq_eoi)
627 chip->irq_eoi(&desc->irq_data);
628}
629
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700630void
Thomas Gleixner3836ca02011-02-14 20:09:19 +0100631__irq_set_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
Ingo Molnara460e742006-10-17 00:10:03 -0700632 const char *name)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700633{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700634 unsigned long flags;
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100635 struct irq_desc *desc = irq_get_desc_buslock(irq, &flags, 0);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700636
Thomas Gleixner02725e72011-02-12 10:37:36 +0100637 if (!desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700638 return;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700639
Thomas Gleixner091738a2011-02-14 20:16:43 +0100640 if (!handle) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700641 handle = handle_bad_irq;
Thomas Gleixner091738a2011-02-14 20:16:43 +0100642 } else {
643 if (WARN_ON(desc->irq_data.chip == &no_irq_chip))
Thomas Gleixner02725e72011-02-12 10:37:36 +0100644 goto out;
Thomas Gleixnerf8b54732006-07-01 22:30:08 +0100645 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700646
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700647 /* Uninstall? */
648 if (handle == handle_bad_irq) {
Thomas Gleixner6b8ff312010-10-01 12:58:38 +0200649 if (desc->irq_data.chip != &no_irq_chip)
Thomas Gleixner9205e312010-09-27 12:44:50 +0000650 mask_ack_irq(desc);
Thomas Gleixner801a0e92011-03-27 11:02:49 +0200651 irq_state_set_disabled(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700652 desc->depth = 1;
653 }
654 desc->handle_irq = handle;
Ingo Molnara460e742006-10-17 00:10:03 -0700655 desc->name = name;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700656
657 if (handle != handle_bad_irq && is_chained) {
Thomas Gleixner1ccb4e62011-02-09 14:44:17 +0100658 irq_settings_set_noprobe(desc);
659 irq_settings_set_norequest(desc);
Paul Mundt7f1b1242011-04-07 06:01:44 +0900660 irq_settings_set_nothread(desc);
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +0100661 irq_startup(desc, true);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700662 }
Thomas Gleixner02725e72011-02-12 10:37:36 +0100663out:
664 irq_put_desc_busunlock(desc, flags);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700665}
Thomas Gleixner3836ca02011-02-14 20:09:19 +0100666EXPORT_SYMBOL_GPL(__irq_set_handler);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700667
668void
Thomas Gleixner3836ca02011-02-14 20:09:19 +0100669irq_set_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
Ingo Molnara460e742006-10-17 00:10:03 -0700670 irq_flow_handler_t handle, const char *name)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700671{
Thomas Gleixner35e857c2011-02-10 12:20:23 +0100672 irq_set_chip(irq, chip);
Thomas Gleixner3836ca02011-02-14 20:09:19 +0100673 __irq_set_handler(irq, handle, 0, name);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700674}
Kuninori Morimotob3ae66f2012-07-30 22:39:06 -0700675EXPORT_SYMBOL_GPL(irq_set_chip_and_handler_name);
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800676
Thomas Gleixner44247182010-09-28 10:40:18 +0200677void irq_modify_status(unsigned int irq, unsigned long clr, unsigned long set)
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800678{
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800679 unsigned long flags;
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100680 struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0);
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800681
Thomas Gleixner44247182010-09-28 10:40:18 +0200682 if (!desc)
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800683 return;
Thomas Gleixnera0056772011-02-08 17:11:03 +0100684 irq_settings_clr_and_set(desc, clr, set);
685
Thomas Gleixner876dbd42011-02-08 17:28:12 +0100686 irqd_clear(&desc->irq_data, IRQD_NO_BALANCING | IRQD_PER_CPU |
Thomas Gleixnere1ef8242011-02-10 22:25:31 +0100687 IRQD_TRIGGER_MASK | IRQD_LEVEL | IRQD_MOVE_PCNTXT);
Thomas Gleixnera0056772011-02-08 17:11:03 +0100688 if (irq_settings_has_no_balance_set(desc))
689 irqd_set(&desc->irq_data, IRQD_NO_BALANCING);
690 if (irq_settings_is_per_cpu(desc))
691 irqd_set(&desc->irq_data, IRQD_PER_CPU);
Thomas Gleixnere1ef8242011-02-10 22:25:31 +0100692 if (irq_settings_can_move_pcntxt(desc))
693 irqd_set(&desc->irq_data, IRQD_MOVE_PCNTXT);
Thomas Gleixner0ef5ca12011-03-28 21:59:37 +0200694 if (irq_settings_is_level(desc))
695 irqd_set(&desc->irq_data, IRQD_LEVEL);
Thomas Gleixnera0056772011-02-08 17:11:03 +0100696
Thomas Gleixner876dbd42011-02-08 17:28:12 +0100697 irqd_set(&desc->irq_data, irq_settings_get_trigger_mask(desc));
698
Thomas Gleixner02725e72011-02-12 10:37:36 +0100699 irq_put_desc_unlock(desc, flags);
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800700}
Jonathan Cameronedf76f82011-05-18 10:39:04 +0100701EXPORT_SYMBOL_GPL(irq_modify_status);
David Daney0fdb4b22011-03-25 12:38:49 -0700702
703/**
704 * irq_cpu_online - Invoke all irq_cpu_online functions.
705 *
706 * Iterate through all irqs and invoke the chip.irq_cpu_online()
707 * for each.
708 */
709void irq_cpu_online(void)
710{
711 struct irq_desc *desc;
712 struct irq_chip *chip;
713 unsigned long flags;
714 unsigned int irq;
715
716 for_each_active_irq(irq) {
717 desc = irq_to_desc(irq);
718 if (!desc)
719 continue;
720
721 raw_spin_lock_irqsave(&desc->lock, flags);
722
723 chip = irq_data_get_irq_chip(&desc->irq_data);
Thomas Gleixnerb3d42232011-03-27 16:05:36 +0200724 if (chip && chip->irq_cpu_online &&
725 (!(chip->flags & IRQCHIP_ONOFFLINE_ENABLED) ||
Thomas Gleixner32f41252011-03-28 14:10:52 +0200726 !irqd_irq_disabled(&desc->irq_data)))
David Daney0fdb4b22011-03-25 12:38:49 -0700727 chip->irq_cpu_online(&desc->irq_data);
728
729 raw_spin_unlock_irqrestore(&desc->lock, flags);
730 }
731}
732
733/**
734 * irq_cpu_offline - Invoke all irq_cpu_offline functions.
735 *
736 * Iterate through all irqs and invoke the chip.irq_cpu_offline()
737 * for each.
738 */
739void irq_cpu_offline(void)
740{
741 struct irq_desc *desc;
742 struct irq_chip *chip;
743 unsigned long flags;
744 unsigned int irq;
745
746 for_each_active_irq(irq) {
747 desc = irq_to_desc(irq);
748 if (!desc)
749 continue;
750
751 raw_spin_lock_irqsave(&desc->lock, flags);
752
753 chip = irq_data_get_irq_chip(&desc->irq_data);
Thomas Gleixnerb3d42232011-03-27 16:05:36 +0200754 if (chip && chip->irq_cpu_offline &&
755 (!(chip->flags & IRQCHIP_ONOFFLINE_ENABLED) ||
Thomas Gleixner32f41252011-03-28 14:10:52 +0200756 !irqd_irq_disabled(&desc->irq_data)))
David Daney0fdb4b22011-03-25 12:38:49 -0700757 chip->irq_cpu_offline(&desc->irq_data);
758
759 raw_spin_unlock_irqrestore(&desc->lock, flags);
760 }
761}