blob: f10c2e58a786e406e2f78e5ffa08b20062106026 [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
Thomas Gleixnerf63b6a02014-05-07 15:44:21 +000043 * allocated_irqs.
David Daneyd72274e2011-03-25 12:38:48 -070044 */
Thomas Gleixnerf63b6a02014-05-07 15:44:21 +000045 irq_mark_irq(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070046 return 0;
47}
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010048EXPORT_SYMBOL(irq_set_chip);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070049
50/**
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010051 * irq_set_type - set the irq trigger type for an irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070052 * @irq: irq number
David Brownell0c5d1eb2008-10-01 14:46:18 -070053 * @type: IRQ_TYPE_{LEVEL,EDGE}_* value - see include/linux/irq.h
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070054 */
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010055int irq_set_irq_type(unsigned int irq, unsigned int type)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070056{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070057 unsigned long flags;
Marc Zyngier31d9d9b2011-09-23 17:03:06 +010058 struct irq_desc *desc = irq_get_desc_buslock(irq, &flags, IRQ_GET_DESC_CHECK_GLOBAL);
Thomas Gleixner02725e72011-02-12 10:37:36 +010059 int ret = 0;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070060
Thomas Gleixner02725e72011-02-12 10:37:36 +010061 if (!desc)
62 return -EINVAL;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070063
David Brownellf2b662d2008-12-01 14:31:38 -080064 type &= IRQ_TYPE_SENSE_MASK;
Russell Kinga09b6592012-03-05 15:07:25 -080065 ret = __irq_set_trigger(desc, irq, type);
Thomas Gleixner02725e72011-02-12 10:37:36 +010066 irq_put_desc_busunlock(desc, flags);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070067 return ret;
68}
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010069EXPORT_SYMBOL(irq_set_irq_type);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070070
71/**
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010072 * irq_set_handler_data - set irq handler data for an irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070073 * @irq: Interrupt number
74 * @data: Pointer to interrupt specific data
75 *
76 * Set the hardware irq controller data for an irq
77 */
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010078int irq_set_handler_data(unsigned int irq, void *data)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070079{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070080 unsigned long flags;
Marc Zyngier31d9d9b2011-09-23 17:03:06 +010081 struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070082
Thomas Gleixner02725e72011-02-12 10:37:36 +010083 if (!desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070084 return -EINVAL;
Thomas Gleixner6b8ff312010-10-01 12:58:38 +020085 desc->irq_data.handler_data = data;
Thomas Gleixner02725e72011-02-12 10:37:36 +010086 irq_put_desc_unlock(desc, flags);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070087 return 0;
88}
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010089EXPORT_SYMBOL(irq_set_handler_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070090
91/**
Alexander Gordeev51906e72012-11-19 16:01:29 +010092 * irq_set_msi_desc_off - set MSI descriptor data for an irq at offset
93 * @irq_base: Interrupt number base
94 * @irq_offset: Interrupt number offset
95 * @entry: Pointer to MSI descriptor data
96 *
97 * Set the MSI descriptor entry for an irq at offset
98 */
99int irq_set_msi_desc_off(unsigned int irq_base, unsigned int irq_offset,
100 struct msi_desc *entry)
101{
102 unsigned long flags;
103 struct irq_desc *desc = irq_get_desc_lock(irq_base + irq_offset, &flags, IRQ_GET_DESC_CHECK_GLOBAL);
104
105 if (!desc)
106 return -EINVAL;
107 desc->irq_data.msi_desc = entry;
108 if (entry && !irq_offset)
109 entry->irq = irq_base;
110 irq_put_desc_unlock(desc, flags);
111 return 0;
112}
113
114/**
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +0100115 * irq_set_msi_desc - set MSI descriptor data for an irq
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700116 * @irq: Interrupt number
Randy Dunlap472900b2007-02-16 01:28:25 -0800117 * @entry: Pointer to MSI descriptor data
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700118 *
Liuweni24b26d42009-11-04 20:11:05 +0800119 * Set the MSI descriptor entry for an irq
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700120 */
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +0100121int irq_set_msi_desc(unsigned int irq, struct msi_desc *entry)
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700122{
Alexander Gordeev51906e72012-11-19 16:01:29 +0100123 return irq_set_msi_desc_off(irq, 0, entry);
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700124}
125
126/**
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +0100127 * irq_set_chip_data - set irq chip data for an irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700128 * @irq: Interrupt number
129 * @data: Pointer to chip specific data
130 *
131 * Set the hardware irq chip data for an irq
132 */
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +0100133int irq_set_chip_data(unsigned int irq, void *data)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700134{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700135 unsigned long flags;
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100136 struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700137
Thomas Gleixner02725e72011-02-12 10:37:36 +0100138 if (!desc)
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700139 return -EINVAL;
Thomas Gleixner6b8ff312010-10-01 12:58:38 +0200140 desc->irq_data.chip_data = data;
Thomas Gleixner02725e72011-02-12 10:37:36 +0100141 irq_put_desc_unlock(desc, flags);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700142 return 0;
143}
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +0100144EXPORT_SYMBOL(irq_set_chip_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700145
Thomas Gleixnerf303a6d2010-09-28 17:34:01 +0200146struct irq_data *irq_get_irq_data(unsigned int irq)
147{
148 struct irq_desc *desc = irq_to_desc(irq);
149
150 return desc ? &desc->irq_data : NULL;
151}
152EXPORT_SYMBOL_GPL(irq_get_irq_data);
153
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100154static void irq_state_clr_disabled(struct irq_desc *desc)
155{
Thomas Gleixner801a0e92011-03-27 11:02:49 +0200156 irqd_clear(&desc->irq_data, IRQD_IRQ_DISABLED);
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100157}
158
159static void irq_state_set_disabled(struct irq_desc *desc)
160{
Thomas Gleixner801a0e92011-03-27 11:02:49 +0200161 irqd_set(&desc->irq_data, IRQD_IRQ_DISABLED);
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100162}
163
Thomas Gleixner6e402622011-02-08 12:36:06 +0100164static void irq_state_clr_masked(struct irq_desc *desc)
165{
Thomas Gleixner32f41252011-03-28 14:10:52 +0200166 irqd_clear(&desc->irq_data, IRQD_IRQ_MASKED);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100167}
168
169static void irq_state_set_masked(struct irq_desc *desc)
170{
Thomas Gleixner32f41252011-03-28 14:10:52 +0200171 irqd_set(&desc->irq_data, IRQD_IRQ_MASKED);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100172}
173
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +0100174int irq_startup(struct irq_desc *desc, bool resend)
Thomas Gleixner46999232011-02-02 21:41:14 +0000175{
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +0100176 int ret = 0;
177
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100178 irq_state_clr_disabled(desc);
Thomas Gleixner46999232011-02-02 21:41:14 +0000179 desc->depth = 0;
180
Thomas Gleixner3aae9942011-02-04 10:17:52 +0100181 if (desc->irq_data.chip->irq_startup) {
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +0100182 ret = desc->irq_data.chip->irq_startup(&desc->irq_data);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100183 irq_state_clr_masked(desc);
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +0100184 } else {
185 irq_enable(desc);
Thomas Gleixner3aae9942011-02-04 10:17:52 +0100186 }
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +0100187 if (resend)
188 check_irq_resend(desc, desc->irq_data.irq);
189 return ret;
Thomas Gleixner46999232011-02-02 21:41:14 +0000190}
191
192void irq_shutdown(struct irq_desc *desc)
193{
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100194 irq_state_set_disabled(desc);
Thomas Gleixner46999232011-02-02 21:41:14 +0000195 desc->depth = 1;
Thomas Gleixner50f7c032011-02-03 13:23:54 +0100196 if (desc->irq_data.chip->irq_shutdown)
197 desc->irq_data.chip->irq_shutdown(&desc->irq_data);
Geert Uytterhoevened585a62011-09-11 13:59:27 +0200198 else if (desc->irq_data.chip->irq_disable)
Thomas Gleixner50f7c032011-02-03 13:23:54 +0100199 desc->irq_data.chip->irq_disable(&desc->irq_data);
200 else
201 desc->irq_data.chip->irq_mask(&desc->irq_data);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100202 irq_state_set_masked(desc);
Thomas Gleixner46999232011-02-02 21:41:14 +0000203}
204
Thomas Gleixner87923472011-02-03 12:27:44 +0100205void irq_enable(struct irq_desc *desc)
206{
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100207 irq_state_clr_disabled(desc);
Thomas Gleixner50f7c032011-02-03 13:23:54 +0100208 if (desc->irq_data.chip->irq_enable)
209 desc->irq_data.chip->irq_enable(&desc->irq_data);
210 else
211 desc->irq_data.chip->irq_unmask(&desc->irq_data);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100212 irq_state_clr_masked(desc);
Thomas Gleixner87923472011-02-03 12:27:44 +0100213}
214
Andreas Fenkartd671a602013-05-10 12:21:30 +0200215/**
Xie XiuQif788e7b2013-10-18 09:12:04 +0800216 * irq_disable - Mark interrupt disabled
Andreas Fenkartd671a602013-05-10 12:21:30 +0200217 * @desc: irq descriptor which should be disabled
218 *
219 * If the chip does not implement the irq_disable callback, we
220 * use a lazy disable approach. That means we mark the interrupt
221 * disabled, but leave the hardware unmasked. That's an
222 * optimization because we avoid the hardware access for the
223 * common case where no interrupt happens after we marked it
224 * disabled. If an interrupt happens, then the interrupt flow
225 * handler masks the line at the hardware level and marks it
226 * pending.
227 */
Thomas Gleixner87923472011-02-03 12:27:44 +0100228void irq_disable(struct irq_desc *desc)
229{
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100230 irq_state_set_disabled(desc);
Thomas Gleixner50f7c032011-02-03 13:23:54 +0100231 if (desc->irq_data.chip->irq_disable) {
232 desc->irq_data.chip->irq_disable(&desc->irq_data);
Thomas Gleixnera61d8252011-02-21 12:54:34 +0100233 irq_state_set_masked(desc);
Thomas Gleixner50f7c032011-02-03 13:23:54 +0100234 }
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100235}
236
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100237void irq_percpu_enable(struct irq_desc *desc, unsigned int cpu)
238{
239 if (desc->irq_data.chip->irq_enable)
240 desc->irq_data.chip->irq_enable(&desc->irq_data);
241 else
242 desc->irq_data.chip->irq_unmask(&desc->irq_data);
243 cpumask_set_cpu(cpu, desc->percpu_enabled);
244}
245
246void irq_percpu_disable(struct irq_desc *desc, unsigned int cpu)
247{
248 if (desc->irq_data.chip->irq_disable)
249 desc->irq_data.chip->irq_disable(&desc->irq_data);
250 else
251 desc->irq_data.chip->irq_mask(&desc->irq_data);
252 cpumask_clear_cpu(cpu, desc->percpu_enabled);
253}
254
Thomas Gleixner9205e312010-09-27 12:44:50 +0000255static inline void mask_ack_irq(struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700256{
Thomas Gleixner9205e312010-09-27 12:44:50 +0000257 if (desc->irq_data.chip->irq_mask_ack)
258 desc->irq_data.chip->irq_mask_ack(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700259 else {
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000260 desc->irq_data.chip->irq_mask(&desc->irq_data);
Thomas Gleixner22a49162010-09-27 12:44:47 +0000261 if (desc->irq_data.chip->irq_ack)
262 desc->irq_data.chip->irq_ack(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700263 }
Thomas Gleixner6e402622011-02-08 12:36:06 +0100264 irq_state_set_masked(desc);
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100265}
266
Thomas Gleixnerd4d5e082011-02-10 13:16:14 +0100267void mask_irq(struct irq_desc *desc)
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100268{
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000269 if (desc->irq_data.chip->irq_mask) {
270 desc->irq_data.chip->irq_mask(&desc->irq_data);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100271 irq_state_set_masked(desc);
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100272 }
273}
274
Thomas Gleixnerd4d5e082011-02-10 13:16:14 +0100275void unmask_irq(struct irq_desc *desc)
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100276{
Thomas Gleixner0eda58b2010-09-27 12:44:44 +0000277 if (desc->irq_data.chip->irq_unmask) {
278 desc->irq_data.chip->irq_unmask(&desc->irq_data);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100279 irq_state_clr_masked(desc);
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100280 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700281}
282
Thomas Gleixner328a4972014-03-13 19:03:51 +0100283void unmask_threaded_irq(struct irq_desc *desc)
284{
285 struct irq_chip *chip = desc->irq_data.chip;
286
287 if (chip->flags & IRQCHIP_EOI_THREADED)
288 chip->irq_eoi(&desc->irq_data);
289
290 if (chip->irq_unmask) {
291 chip->irq_unmask(&desc->irq_data);
292 irq_state_clr_masked(desc);
293 }
294}
295
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200296/*
297 * handle_nested_irq - Handle a nested irq from a irq thread
298 * @irq: the interrupt number
299 *
300 * Handle interrupts which are nested into a threaded interrupt
301 * handler. The handler function is called inside the calling
302 * threads context.
303 */
304void handle_nested_irq(unsigned int irq)
305{
306 struct irq_desc *desc = irq_to_desc(irq);
307 struct irqaction *action;
308 irqreturn_t action_ret;
309
310 might_sleep();
311
Thomas Gleixner239007b2009-11-17 16:46:45 +0100312 raw_spin_lock_irq(&desc->lock);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200313
Thomas Gleixner293a7a02012-10-16 15:07:49 -0700314 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200315 kstat_incr_irqs_this_cpu(irq, desc);
316
317 action = desc->action;
Ning Jiang23812b92012-05-22 00:19:20 +0800318 if (unlikely(!action || irqd_irq_disabled(&desc->irq_data))) {
319 desc->istate |= IRQS_PENDING;
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200320 goto out_unlock;
Ning Jiang23812b92012-05-22 00:19:20 +0800321 }
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200322
Thomas Gleixner32f41252011-03-28 14:10:52 +0200323 irqd_set(&desc->irq_data, IRQD_IRQ_INPROGRESS);
Thomas Gleixner239007b2009-11-17 16:46:45 +0100324 raw_spin_unlock_irq(&desc->lock);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200325
326 action_ret = action->thread_fn(action->irq, action->dev_id);
327 if (!noirqdebug)
328 note_interrupt(irq, desc, action_ret);
329
Thomas Gleixner239007b2009-11-17 16:46:45 +0100330 raw_spin_lock_irq(&desc->lock);
Thomas Gleixner32f41252011-03-28 14:10:52 +0200331 irqd_clear(&desc->irq_data, IRQD_IRQ_INPROGRESS);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200332
333out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100334 raw_spin_unlock_irq(&desc->lock);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200335}
336EXPORT_SYMBOL_GPL(handle_nested_irq);
337
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100338static bool irq_check_poll(struct irq_desc *desc)
339{
Thomas Gleixner6954b752011-02-07 20:55:35 +0100340 if (!(desc->istate & IRQS_POLL_INPROGRESS))
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100341 return false;
342 return irq_wait_for_poll(desc);
343}
344
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700345/**
346 * handle_simple_irq - Simple and software-decoded IRQs.
347 * @irq: the interrupt number
348 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700349 *
350 * Simple interrupts are either sent from a demultiplexing interrupt
351 * handler or come from hardware, where no interrupt hardware control
352 * is necessary.
353 *
354 * Note: The caller is expected to handle the ack, clear, mask and
355 * unmask issues if necessary.
356 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800357void
David Howells7d12e782006-10-05 14:55:46 +0100358handle_simple_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700359{
Thomas Gleixner239007b2009-11-17 16:46:45 +0100360 raw_spin_lock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700361
Thomas Gleixner32f41252011-03-28 14:10:52 +0200362 if (unlikely(irqd_irq_inprogress(&desc->irq_data)))
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100363 if (!irq_check_poll(desc))
364 goto out_unlock;
365
Thomas Gleixner163ef302011-02-08 11:39:15 +0100366 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200367 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700368
Ning Jiang23812b92012-05-22 00:19:20 +0800369 if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) {
370 desc->istate |= IRQS_PENDING;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700371 goto out_unlock;
Ning Jiang23812b92012-05-22 00:19:20 +0800372 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700373
Thomas Gleixner107781e2011-02-07 01:21:02 +0100374 handle_irq_event(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700375
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700376out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100377 raw_spin_unlock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700378}
Jonathan Cameronedf76f82011-05-18 10:39:04 +0100379EXPORT_SYMBOL_GPL(handle_simple_irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700380
Thomas Gleixnerac563762012-02-07 17:58:03 +0100381/*
382 * Called unconditionally from handle_level_irq() and only for oneshot
383 * interrupts from handle_fasteoi_irq()
384 */
385static void cond_unmask_irq(struct irq_desc *desc)
386{
387 /*
388 * We need to unmask in the following cases:
389 * - Standard level irq (IRQF_ONESHOT is not set)
390 * - Oneshot irq which did not wake the thread (caused by a
391 * spurious interrupt or a primary handler handling it
392 * completely).
393 */
394 if (!irqd_irq_disabled(&desc->irq_data) &&
395 irqd_irq_masked(&desc->irq_data) && !desc->threads_oneshot)
396 unmask_irq(desc);
397}
398
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700399/**
400 * handle_level_irq - Level type irq handler
401 * @irq: the interrupt number
402 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700403 *
404 * Level type interrupts are active as long as the hardware line has
405 * the active level. This may require to mask the interrupt and unmask
406 * it after the associated handler has acknowledged the device, so the
407 * interrupt line is back to inactive.
408 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800409void
David Howells7d12e782006-10-05 14:55:46 +0100410handle_level_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700411{
Thomas Gleixner239007b2009-11-17 16:46:45 +0100412 raw_spin_lock(&desc->lock);
Thomas Gleixner9205e312010-09-27 12:44:50 +0000413 mask_ack_irq(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700414
Thomas Gleixner32f41252011-03-28 14:10:52 +0200415 if (unlikely(irqd_irq_inprogress(&desc->irq_data)))
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100416 if (!irq_check_poll(desc))
417 goto out_unlock;
418
Thomas Gleixner163ef302011-02-08 11:39:15 +0100419 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200420 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700421
422 /*
423 * If its disabled or no action available
424 * keep it masked and get out of here
425 */
Thomas Gleixnerd4dc0f92012-04-25 12:54:54 +0200426 if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) {
427 desc->istate |= IRQS_PENDING;
Ingo Molnar86998aa2006-09-19 11:14:34 +0200428 goto out_unlock;
Thomas Gleixnerd4dc0f92012-04-25 12:54:54 +0200429 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700430
Thomas Gleixner15298662011-02-07 01:22:17 +0100431 handle_irq_event(desc);
Thomas Gleixnerb25c3402009-08-13 12:17:22 +0200432
Thomas Gleixnerac563762012-02-07 17:58:03 +0100433 cond_unmask_irq(desc);
434
Ingo Molnar86998aa2006-09-19 11:14:34 +0200435out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100436 raw_spin_unlock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700437}
Ingo Molnar14819ea2009-01-14 12:34:21 +0100438EXPORT_SYMBOL_GPL(handle_level_irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700439
Thomas Gleixner78129572011-02-10 15:14:20 +0100440#ifdef CONFIG_IRQ_PREFLOW_FASTEOI
441static inline void preflow_handler(struct irq_desc *desc)
442{
443 if (desc->preflow_handler)
444 desc->preflow_handler(&desc->irq_data);
445}
446#else
447static inline void preflow_handler(struct irq_desc *desc) { }
448#endif
449
Thomas Gleixner328a4972014-03-13 19:03:51 +0100450static void cond_unmask_eoi_irq(struct irq_desc *desc, struct irq_chip *chip)
451{
452 if (!(desc->istate & IRQS_ONESHOT)) {
453 chip->irq_eoi(&desc->irq_data);
454 return;
455 }
456 /*
457 * We need to unmask in the following cases:
458 * - Oneshot irq which did not wake the thread (caused by a
459 * spurious interrupt or a primary handler handling it
460 * completely).
461 */
462 if (!irqd_irq_disabled(&desc->irq_data) &&
463 irqd_irq_masked(&desc->irq_data) && !desc->threads_oneshot) {
464 chip->irq_eoi(&desc->irq_data);
465 unmask_irq(desc);
466 } else if (!(chip->flags & IRQCHIP_EOI_THREADED)) {
467 chip->irq_eoi(&desc->irq_data);
468 }
469}
470
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700471/**
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700472 * handle_fasteoi_irq - irq handler for transparent controllers
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700473 * @irq: the interrupt number
474 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700475 *
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700476 * Only a single callback will be issued to the chip: an ->eoi()
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700477 * call when the interrupt has been serviced. This enables support
478 * for modern forms of interrupt handlers, which handle the flow
479 * details in hardware, transparently.
480 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800481void
David Howells7d12e782006-10-05 14:55:46 +0100482handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700483{
Thomas Gleixner328a4972014-03-13 19:03:51 +0100484 struct irq_chip *chip = desc->irq_data.chip;
485
Thomas Gleixner239007b2009-11-17 16:46:45 +0100486 raw_spin_lock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700487
Thomas Gleixner32f41252011-03-28 14:10:52 +0200488 if (unlikely(irqd_irq_inprogress(&desc->irq_data)))
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100489 if (!irq_check_poll(desc))
490 goto out;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700491
Thomas Gleixner163ef302011-02-08 11:39:15 +0100492 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200493 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700494
495 /*
496 * If its disabled or no action available
Ingo Molnar76d21602007-02-16 01:28:24 -0800497 * then mask it and get out of here:
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700498 */
Thomas Gleixner32f41252011-03-28 14:10:52 +0200499 if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) {
Thomas Gleixner2a0d6fb2011-02-08 12:17:57 +0100500 desc->istate |= IRQS_PENDING;
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000501 mask_irq(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700502 goto out;
Benjamin Herrenschmidt98bb2442006-06-29 02:25:01 -0700503 }
Thomas Gleixnerc69e3752011-03-02 11:49:21 +0100504
505 if (desc->istate & IRQS_ONESHOT)
506 mask_irq(desc);
507
Thomas Gleixner78129572011-02-10 15:14:20 +0100508 preflow_handler(desc);
Thomas Gleixnera7ae4de2011-02-07 01:23:07 +0100509 handle_irq_event(desc);
Thomas Gleixner77694b42011-02-15 10:33:57 +0100510
Thomas Gleixner328a4972014-03-13 19:03:51 +0100511 cond_unmask_eoi_irq(desc, chip);
Thomas Gleixnerac563762012-02-07 17:58:03 +0100512
Thomas Gleixner239007b2009-11-17 16:46:45 +0100513 raw_spin_unlock(&desc->lock);
Thomas Gleixner77694b42011-02-15 10:33:57 +0100514 return;
515out:
Thomas Gleixner328a4972014-03-13 19:03:51 +0100516 if (!(chip->flags & IRQCHIP_EOI_IF_HANDLED))
517 chip->irq_eoi(&desc->irq_data);
518 raw_spin_unlock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700519}
520
521/**
522 * handle_edge_irq - edge type IRQ handler
523 * @irq: the interrupt number
524 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700525 *
526 * Interrupt occures on the falling and/or rising edge of a hardware
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300527 * signal. The occurrence is latched into the irq controller hardware
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700528 * and must be acked in order to be reenabled. After the ack another
529 * interrupt can happen on the same source even before the first one
Uwe Kleine-Königdfff0612010-02-12 21:58:11 +0100530 * is handled by the associated event handler. If this happens it
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700531 * might be necessary to disable (mask) the interrupt depending on the
532 * controller hardware. This requires to reenable the interrupt inside
533 * of the loop which handles the interrupts which have arrived while
534 * the handler was running. If all pending interrupts are handled, the
535 * loop is left.
536 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800537void
David Howells7d12e782006-10-05 14:55:46 +0100538handle_edge_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700539{
Thomas Gleixner239007b2009-11-17 16:46:45 +0100540 raw_spin_lock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700541
Thomas Gleixner163ef302011-02-08 11:39:15 +0100542 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Thomas Gleixnerc3d7acd2014-08-29 13:46:08 +0200543
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700544 /*
Thomas Gleixnerc3d7acd2014-08-29 13:46:08 +0200545 * If the handler is currently running, mark it pending,
546 * handle the necessary masking and go out
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700547 */
Thomas Gleixnerc3d7acd2014-08-29 13:46:08 +0200548 if (unlikely(irqd_irq_inprogress(&desc->irq_data))) {
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100549 if (!irq_check_poll(desc)) {
Thomas Gleixner2a0d6fb2011-02-08 12:17:57 +0100550 desc->istate |= IRQS_PENDING;
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100551 mask_ack_irq(desc);
552 goto out_unlock;
553 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700554 }
Thomas Gleixnerc3d7acd2014-08-29 13:46:08 +0200555
556 /*
557 * If its disabled or no action available then mask it and get
558 * out of here.
559 */
560 if (irqd_irq_disabled(&desc->irq_data) || !desc->action) {
561 desc->istate |= IRQS_PENDING;
562 mask_ack_irq(desc);
563 goto out_unlock;
564 }
565
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200566 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700567
568 /* Start handling the irq */
Thomas Gleixner22a49162010-09-27 12:44:47 +0000569 desc->irq_data.chip->irq_ack(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700570
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700571 do {
Thomas Gleixnera60a5dc2011-02-07 01:24:07 +0100572 if (unlikely(!desc->action)) {
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000573 mask_irq(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700574 goto out_unlock;
575 }
576
577 /*
578 * When another irq arrived while we were handling
579 * one, we could have masked the irq.
580 * Renable it, if it was not disabled in meantime.
581 */
Thomas Gleixner2a0d6fb2011-02-08 12:17:57 +0100582 if (unlikely(desc->istate & IRQS_PENDING)) {
Thomas Gleixner32f41252011-03-28 14:10:52 +0200583 if (!irqd_irq_disabled(&desc->irq_data) &&
584 irqd_irq_masked(&desc->irq_data))
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100585 unmask_irq(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700586 }
587
Thomas Gleixnera60a5dc2011-02-07 01:24:07 +0100588 handle_irq_event(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700589
Thomas Gleixner2a0d6fb2011-02-08 12:17:57 +0100590 } while ((desc->istate & IRQS_PENDING) &&
Thomas Gleixner32f41252011-03-28 14:10:52 +0200591 !irqd_irq_disabled(&desc->irq_data));
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700592
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700593out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100594 raw_spin_unlock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700595}
Jiri Kosina3911ff32012-05-13 12:13:15 +0200596EXPORT_SYMBOL(handle_edge_irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700597
Thomas Gleixner0521c8f2011-03-28 16:13:24 +0200598#ifdef CONFIG_IRQ_EDGE_EOI_HANDLER
599/**
600 * handle_edge_eoi_irq - edge eoi type IRQ handler
601 * @irq: the interrupt number
602 * @desc: the interrupt description structure for this irq
603 *
604 * Similar as the above handle_edge_irq, but using eoi and w/o the
605 * mask/unmask logic.
606 */
607void handle_edge_eoi_irq(unsigned int irq, struct irq_desc *desc)
608{
609 struct irq_chip *chip = irq_desc_get_chip(desc);
610
611 raw_spin_lock(&desc->lock);
612
613 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Thomas Gleixnerc3d7acd2014-08-29 13:46:08 +0200614
Thomas Gleixner0521c8f2011-03-28 16:13:24 +0200615 /*
Thomas Gleixnerc3d7acd2014-08-29 13:46:08 +0200616 * If the handler is currently running, mark it pending,
617 * handle the necessary masking and go out
Thomas Gleixner0521c8f2011-03-28 16:13:24 +0200618 */
Thomas Gleixnerc3d7acd2014-08-29 13:46:08 +0200619 if (unlikely(irqd_irq_inprogress(&desc->irq_data))) {
Thomas Gleixner0521c8f2011-03-28 16:13:24 +0200620 if (!irq_check_poll(desc)) {
621 desc->istate |= IRQS_PENDING;
622 goto out_eoi;
623 }
624 }
Thomas Gleixnerc3d7acd2014-08-29 13:46:08 +0200625
626 /*
627 * If its disabled or no action available then mask it and get
628 * out of here.
629 */
630 if (irqd_irq_disabled(&desc->irq_data) || !desc->action) {
631 desc->istate |= IRQS_PENDING;
632 goto out_eoi;
633 }
634
Thomas Gleixner0521c8f2011-03-28 16:13:24 +0200635 kstat_incr_irqs_this_cpu(irq, desc);
636
637 do {
638 if (unlikely(!desc->action))
639 goto out_eoi;
640
641 handle_irq_event(desc);
642
643 } while ((desc->istate & IRQS_PENDING) &&
644 !irqd_irq_disabled(&desc->irq_data));
645
Stephen Rothwellac0e0442011-03-30 10:55:12 +1100646out_eoi:
Thomas Gleixner0521c8f2011-03-28 16:13:24 +0200647 chip->irq_eoi(&desc->irq_data);
648 raw_spin_unlock(&desc->lock);
649}
650#endif
651
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700652/**
Liuweni24b26d42009-11-04 20:11:05 +0800653 * handle_percpu_irq - Per CPU local irq handler
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700654 * @irq: the interrupt number
655 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700656 *
657 * Per CPU interrupts on SMP machines without locking requirements
658 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800659void
David Howells7d12e782006-10-05 14:55:46 +0100660handle_percpu_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700661{
Thomas Gleixner35e857c2011-02-10 12:20:23 +0100662 struct irq_chip *chip = irq_desc_get_chip(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700663
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200664 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700665
Thomas Gleixner849f0612011-02-07 01:25:41 +0100666 if (chip->irq_ack)
667 chip->irq_ack(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700668
Thomas Gleixner849f0612011-02-07 01:25:41 +0100669 handle_irq_event_percpu(desc, desc->action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700670
Thomas Gleixner849f0612011-02-07 01:25:41 +0100671 if (chip->irq_eoi)
672 chip->irq_eoi(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700673}
674
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100675/**
676 * handle_percpu_devid_irq - Per CPU local irq handler with per cpu dev ids
677 * @irq: the interrupt number
678 * @desc: the interrupt description structure for this irq
679 *
680 * Per CPU interrupts on SMP machines without locking requirements. Same as
681 * handle_percpu_irq() above but with the following extras:
682 *
683 * action->percpu_dev_id is a pointer to percpu variables which
684 * contain the real device id for the cpu on which this handler is
685 * called
686 */
687void handle_percpu_devid_irq(unsigned int irq, struct irq_desc *desc)
688{
689 struct irq_chip *chip = irq_desc_get_chip(desc);
690 struct irqaction *action = desc->action;
691 void *dev_id = __this_cpu_ptr(action->percpu_dev_id);
692 irqreturn_t res;
693
694 kstat_incr_irqs_this_cpu(irq, desc);
695
696 if (chip->irq_ack)
697 chip->irq_ack(&desc->irq_data);
698
699 trace_irq_handler_entry(irq, action);
700 res = action->handler(irq, dev_id);
701 trace_irq_handler_exit(irq, action, res);
702
703 if (chip->irq_eoi)
704 chip->irq_eoi(&desc->irq_data);
705}
706
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700707void
Thomas Gleixner3836ca02011-02-14 20:09:19 +0100708__irq_set_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
Ingo Molnara460e742006-10-17 00:10:03 -0700709 const char *name)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700710{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700711 unsigned long flags;
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100712 struct irq_desc *desc = irq_get_desc_buslock(irq, &flags, 0);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700713
Thomas Gleixner02725e72011-02-12 10:37:36 +0100714 if (!desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700715 return;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700716
Thomas Gleixner091738a2011-02-14 20:16:43 +0100717 if (!handle) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700718 handle = handle_bad_irq;
Thomas Gleixner091738a2011-02-14 20:16:43 +0100719 } else {
720 if (WARN_ON(desc->irq_data.chip == &no_irq_chip))
Thomas Gleixner02725e72011-02-12 10:37:36 +0100721 goto out;
Thomas Gleixnerf8b54732006-07-01 22:30:08 +0100722 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700723
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700724 /* Uninstall? */
725 if (handle == handle_bad_irq) {
Thomas Gleixner6b8ff312010-10-01 12:58:38 +0200726 if (desc->irq_data.chip != &no_irq_chip)
Thomas Gleixner9205e312010-09-27 12:44:50 +0000727 mask_ack_irq(desc);
Thomas Gleixner801a0e92011-03-27 11:02:49 +0200728 irq_state_set_disabled(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700729 desc->depth = 1;
730 }
731 desc->handle_irq = handle;
Ingo Molnara460e742006-10-17 00:10:03 -0700732 desc->name = name;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700733
734 if (handle != handle_bad_irq && is_chained) {
Thomas Gleixner1ccb4e62011-02-09 14:44:17 +0100735 irq_settings_set_noprobe(desc);
736 irq_settings_set_norequest(desc);
Paul Mundt7f1b1242011-04-07 06:01:44 +0900737 irq_settings_set_nothread(desc);
Thomas Gleixnerb4bc7242012-02-08 11:57:52 +0100738 irq_startup(desc, true);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700739 }
Thomas Gleixner02725e72011-02-12 10:37:36 +0100740out:
741 irq_put_desc_busunlock(desc, flags);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700742}
Thomas Gleixner3836ca02011-02-14 20:09:19 +0100743EXPORT_SYMBOL_GPL(__irq_set_handler);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700744
745void
Thomas Gleixner3836ca02011-02-14 20:09:19 +0100746irq_set_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
Ingo Molnara460e742006-10-17 00:10:03 -0700747 irq_flow_handler_t handle, const char *name)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700748{
Thomas Gleixner35e857c2011-02-10 12:20:23 +0100749 irq_set_chip(irq, chip);
Thomas Gleixner3836ca02011-02-14 20:09:19 +0100750 __irq_set_handler(irq, handle, 0, name);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700751}
Kuninori Morimotob3ae66f2012-07-30 22:39:06 -0700752EXPORT_SYMBOL_GPL(irq_set_chip_and_handler_name);
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800753
Thomas Gleixner44247182010-09-28 10:40:18 +0200754void irq_modify_status(unsigned int irq, unsigned long clr, unsigned long set)
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800755{
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800756 unsigned long flags;
Marc Zyngier31d9d9b2011-09-23 17:03:06 +0100757 struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0);
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800758
Thomas Gleixner44247182010-09-28 10:40:18 +0200759 if (!desc)
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800760 return;
Thomas Gleixnera0056772011-02-08 17:11:03 +0100761 irq_settings_clr_and_set(desc, clr, set);
762
Thomas Gleixner876dbd42011-02-08 17:28:12 +0100763 irqd_clear(&desc->irq_data, IRQD_NO_BALANCING | IRQD_PER_CPU |
Thomas Gleixnere1ef8242011-02-10 22:25:31 +0100764 IRQD_TRIGGER_MASK | IRQD_LEVEL | IRQD_MOVE_PCNTXT);
Thomas Gleixnera0056772011-02-08 17:11:03 +0100765 if (irq_settings_has_no_balance_set(desc))
766 irqd_set(&desc->irq_data, IRQD_NO_BALANCING);
767 if (irq_settings_is_per_cpu(desc))
768 irqd_set(&desc->irq_data, IRQD_PER_CPU);
Thomas Gleixnere1ef8242011-02-10 22:25:31 +0100769 if (irq_settings_can_move_pcntxt(desc))
770 irqd_set(&desc->irq_data, IRQD_MOVE_PCNTXT);
Thomas Gleixner0ef5ca12011-03-28 21:59:37 +0200771 if (irq_settings_is_level(desc))
772 irqd_set(&desc->irq_data, IRQD_LEVEL);
Thomas Gleixnera0056772011-02-08 17:11:03 +0100773
Thomas Gleixner876dbd42011-02-08 17:28:12 +0100774 irqd_set(&desc->irq_data, irq_settings_get_trigger_mask(desc));
775
Thomas Gleixner02725e72011-02-12 10:37:36 +0100776 irq_put_desc_unlock(desc, flags);
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800777}
Jonathan Cameronedf76f82011-05-18 10:39:04 +0100778EXPORT_SYMBOL_GPL(irq_modify_status);
David Daney0fdb4b22011-03-25 12:38:49 -0700779
780/**
781 * irq_cpu_online - Invoke all irq_cpu_online functions.
782 *
783 * Iterate through all irqs and invoke the chip.irq_cpu_online()
784 * for each.
785 */
786void irq_cpu_online(void)
787{
788 struct irq_desc *desc;
789 struct irq_chip *chip;
790 unsigned long flags;
791 unsigned int irq;
792
793 for_each_active_irq(irq) {
794 desc = irq_to_desc(irq);
795 if (!desc)
796 continue;
797
798 raw_spin_lock_irqsave(&desc->lock, flags);
799
800 chip = irq_data_get_irq_chip(&desc->irq_data);
Thomas Gleixnerb3d42232011-03-27 16:05:36 +0200801 if (chip && chip->irq_cpu_online &&
802 (!(chip->flags & IRQCHIP_ONOFFLINE_ENABLED) ||
Thomas Gleixner32f41252011-03-28 14:10:52 +0200803 !irqd_irq_disabled(&desc->irq_data)))
David Daney0fdb4b22011-03-25 12:38:49 -0700804 chip->irq_cpu_online(&desc->irq_data);
805
806 raw_spin_unlock_irqrestore(&desc->lock, flags);
807 }
808}
809
810/**
811 * irq_cpu_offline - Invoke all irq_cpu_offline functions.
812 *
813 * Iterate through all irqs and invoke the chip.irq_cpu_offline()
814 * for each.
815 */
816void irq_cpu_offline(void)
817{
818 struct irq_desc *desc;
819 struct irq_chip *chip;
820 unsigned long flags;
821 unsigned int irq;
822
823 for_each_active_irq(irq) {
824 desc = irq_to_desc(irq);
825 if (!desc)
826 continue;
827
828 raw_spin_lock_irqsave(&desc->lock, flags);
829
830 chip = irq_data_get_irq_chip(&desc->irq_data);
Thomas Gleixnerb3d42232011-03-27 16:05:36 +0200831 if (chip && chip->irq_cpu_offline &&
832 (!(chip->flags & IRQCHIP_ONOFFLINE_ENABLED) ||
Thomas Gleixner32f41252011-03-28 14:10:52 +0200833 !irqd_irq_disabled(&desc->irq_data)))
David Daney0fdb4b22011-03-25 12:38:49 -0700834 chip->irq_cpu_offline(&desc->irq_data);
835
836 raw_spin_unlock_irqrestore(&desc->lock, flags);
837 }
838}