blob: 0a890bdd9c63f181a4de9132cec3e4ce9709e17a [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
19#include "internals.h"
20
Eric W. Biederman3a16d712006-10-04 02:16:37 -070021/**
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010022 * irq_set_chip - set the irq chip for an irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070023 * @irq: irq number
24 * @chip: pointer to irq chip description structure
25 */
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010026int irq_set_chip(unsigned int irq, struct irq_chip *chip)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070027{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070028 unsigned long flags;
Thomas Gleixner02725e72011-02-12 10:37:36 +010029 struct irq_desc *desc = irq_get_desc_lock(irq, &flags);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070030
Thomas Gleixner02725e72011-02-12 10:37:36 +010031 if (!desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070032 return -EINVAL;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070033
34 if (!chip)
35 chip = &no_irq_chip;
36
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070037 irq_chip_set_defaults(chip);
Thomas Gleixner6b8ff312010-10-01 12:58:38 +020038 desc->irq_data.chip = chip;
Thomas Gleixner02725e72011-02-12 10:37:36 +010039 irq_put_desc_unlock(desc, flags);
David Daneyd72274e2011-03-25 12:38:48 -070040 /*
41 * For !CONFIG_SPARSE_IRQ make the irq show up in
42 * allocated_irqs. For the CONFIG_SPARSE_IRQ case, it is
43 * already marked, and this call is harmless.
44 */
45 irq_reserve_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;
Thomas Gleixner02725e72011-02-12 10:37:36 +010058 struct irq_desc *desc = irq_get_desc_buslock(irq, &flags);
59 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;
Thomas Gleixner02725e72011-02-12 10:37:36 +010065 if (type != IRQ_TYPE_NONE)
66 ret = __irq_set_trigger(desc, irq, type);
67 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;
Thomas Gleixner02725e72011-02-12 10:37:36 +010082 struct irq_desc *desc = irq_get_desc_lock(irq, &flags);
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;
Thomas Gleixner02725e72011-02-12 10:37:36 +0100102 struct irq_desc *desc = irq_get_desc_lock(irq, &flags);
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;
Thomas Gleixner02725e72011-02-12 10:37:36 +0100123 struct irq_desc *desc = irq_get_desc_lock(irq, &flags);
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{
143 desc->istate &= ~IRQS_DISABLED;
Thomas Gleixner801a0e92011-03-27 11:02:49 +0200144 irqd_clear(&desc->irq_data, IRQD_IRQ_DISABLED);
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100145 irq_compat_clr_disabled(desc);
146}
147
148static void irq_state_set_disabled(struct irq_desc *desc)
149{
150 desc->istate |= IRQS_DISABLED;
Thomas Gleixner801a0e92011-03-27 11:02:49 +0200151 irqd_set(&desc->irq_data, IRQD_IRQ_DISABLED);
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100152 irq_compat_set_disabled(desc);
153}
154
Thomas Gleixner6e402622011-02-08 12:36:06 +0100155static void irq_state_clr_masked(struct irq_desc *desc)
156{
157 desc->istate &= ~IRQS_MASKED;
158 irq_compat_clr_masked(desc);
159}
160
161static void irq_state_set_masked(struct irq_desc *desc)
162{
163 desc->istate |= IRQS_MASKED;
164 irq_compat_set_masked(desc);
165}
166
Thomas Gleixner46999232011-02-02 21:41:14 +0000167int irq_startup(struct irq_desc *desc)
168{
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100169 irq_state_clr_disabled(desc);
Thomas Gleixner46999232011-02-02 21:41:14 +0000170 desc->depth = 0;
171
Thomas Gleixner3aae9942011-02-04 10:17:52 +0100172 if (desc->irq_data.chip->irq_startup) {
173 int ret = desc->irq_data.chip->irq_startup(&desc->irq_data);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100174 irq_state_clr_masked(desc);
Thomas Gleixner3aae9942011-02-04 10:17:52 +0100175 return ret;
176 }
Thomas Gleixner46999232011-02-02 21:41:14 +0000177
Thomas Gleixner87923472011-02-03 12:27:44 +0100178 irq_enable(desc);
Thomas Gleixner46999232011-02-02 21:41:14 +0000179 return 0;
180}
181
182void irq_shutdown(struct irq_desc *desc)
183{
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100184 irq_state_set_disabled(desc);
Thomas Gleixner46999232011-02-02 21:41:14 +0000185 desc->depth = 1;
Thomas Gleixner50f7c032011-02-03 13:23:54 +0100186 if (desc->irq_data.chip->irq_shutdown)
187 desc->irq_data.chip->irq_shutdown(&desc->irq_data);
188 if (desc->irq_data.chip->irq_disable)
189 desc->irq_data.chip->irq_disable(&desc->irq_data);
190 else
191 desc->irq_data.chip->irq_mask(&desc->irq_data);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100192 irq_state_set_masked(desc);
Thomas Gleixner46999232011-02-02 21:41:14 +0000193}
194
Thomas Gleixner87923472011-02-03 12:27:44 +0100195void irq_enable(struct irq_desc *desc)
196{
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100197 irq_state_clr_disabled(desc);
Thomas Gleixner50f7c032011-02-03 13:23:54 +0100198 if (desc->irq_data.chip->irq_enable)
199 desc->irq_data.chip->irq_enable(&desc->irq_data);
200 else
201 desc->irq_data.chip->irq_unmask(&desc->irq_data);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100202 irq_state_clr_masked(desc);
Thomas Gleixner87923472011-02-03 12:27:44 +0100203}
204
205void irq_disable(struct irq_desc *desc)
206{
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100207 irq_state_set_disabled(desc);
Thomas Gleixner50f7c032011-02-03 13:23:54 +0100208 if (desc->irq_data.chip->irq_disable) {
209 desc->irq_data.chip->irq_disable(&desc->irq_data);
Thomas Gleixnera61d8252011-02-21 12:54:34 +0100210 irq_state_set_masked(desc);
Thomas Gleixner50f7c032011-02-03 13:23:54 +0100211 }
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100212}
213
Thomas Gleixnerbd151412010-10-01 15:17:14 +0200214#ifndef CONFIG_GENERIC_HARDIRQS_NO_DEPRECATED
Thomas Gleixner3876ec92010-09-27 12:44:35 +0000215/* Temporary migration helpers */
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000216static void compat_irq_mask(struct irq_data *data)
217{
218 data->chip->mask(data->irq);
219}
220
Thomas Gleixner0eda58b2010-09-27 12:44:44 +0000221static void compat_irq_unmask(struct irq_data *data)
222{
223 data->chip->unmask(data->irq);
224}
225
Thomas Gleixner22a49162010-09-27 12:44:47 +0000226static void compat_irq_ack(struct irq_data *data)
227{
228 data->chip->ack(data->irq);
229}
230
Thomas Gleixner9205e312010-09-27 12:44:50 +0000231static void compat_irq_mask_ack(struct irq_data *data)
232{
233 data->chip->mask_ack(data->irq);
234}
235
Thomas Gleixner0c5c1552010-09-27 12:44:53 +0000236static void compat_irq_eoi(struct irq_data *data)
237{
238 data->chip->eoi(data->irq);
239}
240
Thomas Gleixnerc5f75632010-09-27 12:44:56 +0000241static void compat_irq_enable(struct irq_data *data)
242{
243 data->chip->enable(data->irq);
244}
245
Thomas Gleixnerbc310dd2010-09-27 12:45:02 +0000246static void compat_irq_disable(struct irq_data *data)
247{
248 data->chip->disable(data->irq);
249}
250
251static void compat_irq_shutdown(struct irq_data *data)
252{
253 data->chip->shutdown(data->irq);
254}
255
Thomas Gleixner37e12df2010-09-27 12:45:38 +0000256static unsigned int compat_irq_startup(struct irq_data *data)
257{
258 return data->chip->startup(data->irq);
259}
260
Thomas Gleixnerc96b3b32010-09-27 12:45:41 +0000261static int compat_irq_set_affinity(struct irq_data *data,
262 const struct cpumask *dest, bool force)
263{
264 return data->chip->set_affinity(data->irq, dest);
265}
266
Thomas Gleixnerb2ba2c32010-09-27 12:45:47 +0000267static int compat_irq_set_type(struct irq_data *data, unsigned int type)
268{
269 return data->chip->set_type(data->irq, type);
270}
271
Thomas Gleixner2f7e99b2010-09-27 12:45:50 +0000272static int compat_irq_set_wake(struct irq_data *data, unsigned int on)
273{
274 return data->chip->set_wake(data->irq, on);
275}
276
Thomas Gleixner21e2b8c2010-09-27 12:45:53 +0000277static int compat_irq_retrigger(struct irq_data *data)
278{
279 return data->chip->retrigger(data->irq);
280}
281
Thomas Gleixner3876ec92010-09-27 12:44:35 +0000282static void compat_bus_lock(struct irq_data *data)
283{
284 data->chip->bus_lock(data->irq);
285}
286
287static void compat_bus_sync_unlock(struct irq_data *data)
288{
289 data->chip->bus_sync_unlock(data->irq);
290}
Thomas Gleixnerbd151412010-10-01 15:17:14 +0200291#endif
Thomas Gleixner3876ec92010-09-27 12:44:35 +0000292
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100293/*
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700294 * Fixup enable/disable function pointers
295 */
296void irq_chip_set_defaults(struct irq_chip *chip)
297{
Thomas Gleixnerbd151412010-10-01 15:17:14 +0200298#ifndef CONFIG_GENERIC_HARDIRQS_NO_DEPRECATED
Thomas Gleixnerc5f75632010-09-27 12:44:56 +0000299 if (chip->enable)
300 chip->irq_enable = compat_irq_enable;
Thomas Gleixnerbc310dd2010-09-27 12:45:02 +0000301 if (chip->disable)
302 chip->irq_disable = compat_irq_disable;
303 if (chip->shutdown)
304 chip->irq_shutdown = compat_irq_shutdown;
Thomas Gleixner37e12df2010-09-27 12:45:38 +0000305 if (chip->startup)
306 chip->irq_startup = compat_irq_startup;
Zhang, Yanminb86432b2006-11-16 01:19:10 -0800307 if (!chip->end)
308 chip->end = dummy_irq_chip.end;
Thomas Gleixner3876ec92010-09-27 12:44:35 +0000309 if (chip->bus_lock)
310 chip->irq_bus_lock = compat_bus_lock;
311 if (chip->bus_sync_unlock)
312 chip->irq_bus_sync_unlock = compat_bus_sync_unlock;
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000313 if (chip->mask)
314 chip->irq_mask = compat_irq_mask;
Thomas Gleixner0eda58b2010-09-27 12:44:44 +0000315 if (chip->unmask)
316 chip->irq_unmask = compat_irq_unmask;
Thomas Gleixner22a49162010-09-27 12:44:47 +0000317 if (chip->ack)
318 chip->irq_ack = compat_irq_ack;
Thomas Gleixner9205e312010-09-27 12:44:50 +0000319 if (chip->mask_ack)
320 chip->irq_mask_ack = compat_irq_mask_ack;
Thomas Gleixner0c5c1552010-09-27 12:44:53 +0000321 if (chip->eoi)
322 chip->irq_eoi = compat_irq_eoi;
Thomas Gleixnerc96b3b32010-09-27 12:45:41 +0000323 if (chip->set_affinity)
324 chip->irq_set_affinity = compat_irq_set_affinity;
Thomas Gleixnerb2ba2c32010-09-27 12:45:47 +0000325 if (chip->set_type)
326 chip->irq_set_type = compat_irq_set_type;
Thomas Gleixner2f7e99b2010-09-27 12:45:50 +0000327 if (chip->set_wake)
328 chip->irq_set_wake = compat_irq_set_wake;
Thomas Gleixner21e2b8c2010-09-27 12:45:53 +0000329 if (chip->retrigger)
330 chip->irq_retrigger = compat_irq_retrigger;
Thomas Gleixnerbd151412010-10-01 15:17:14 +0200331#endif
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700332}
333
Thomas Gleixner9205e312010-09-27 12:44:50 +0000334static inline void mask_ack_irq(struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700335{
Thomas Gleixner9205e312010-09-27 12:44:50 +0000336 if (desc->irq_data.chip->irq_mask_ack)
337 desc->irq_data.chip->irq_mask_ack(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700338 else {
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000339 desc->irq_data.chip->irq_mask(&desc->irq_data);
Thomas Gleixner22a49162010-09-27 12:44:47 +0000340 if (desc->irq_data.chip->irq_ack)
341 desc->irq_data.chip->irq_ack(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700342 }
Thomas Gleixner6e402622011-02-08 12:36:06 +0100343 irq_state_set_masked(desc);
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100344}
345
Thomas Gleixnerd4d5e082011-02-10 13:16:14 +0100346void mask_irq(struct irq_desc *desc)
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100347{
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000348 if (desc->irq_data.chip->irq_mask) {
349 desc->irq_data.chip->irq_mask(&desc->irq_data);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100350 irq_state_set_masked(desc);
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100351 }
352}
353
Thomas Gleixnerd4d5e082011-02-10 13:16:14 +0100354void unmask_irq(struct irq_desc *desc)
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100355{
Thomas Gleixner0eda58b2010-09-27 12:44:44 +0000356 if (desc->irq_data.chip->irq_unmask) {
357 desc->irq_data.chip->irq_unmask(&desc->irq_data);
Thomas Gleixner6e402622011-02-08 12:36:06 +0100358 irq_state_clr_masked(desc);
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100359 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700360}
361
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200362/*
363 * handle_nested_irq - Handle a nested irq from a irq thread
364 * @irq: the interrupt number
365 *
366 * Handle interrupts which are nested into a threaded interrupt
367 * handler. The handler function is called inside the calling
368 * threads context.
369 */
370void handle_nested_irq(unsigned int irq)
371{
372 struct irq_desc *desc = irq_to_desc(irq);
373 struct irqaction *action;
374 irqreturn_t action_ret;
375
376 might_sleep();
377
Thomas Gleixner239007b2009-11-17 16:46:45 +0100378 raw_spin_lock_irq(&desc->lock);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200379
380 kstat_incr_irqs_this_cpu(irq, desc);
381
382 action = desc->action;
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100383 if (unlikely(!action || (desc->istate & IRQS_DISABLED)))
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200384 goto out_unlock;
385
Thomas Gleixner009b4c32011-02-07 21:48:49 +0100386 irq_compat_set_progress(desc);
387 desc->istate |= IRQS_INPROGRESS;
Thomas Gleixner239007b2009-11-17 16:46:45 +0100388 raw_spin_unlock_irq(&desc->lock);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200389
390 action_ret = action->thread_fn(action->irq, action->dev_id);
391 if (!noirqdebug)
392 note_interrupt(irq, desc, action_ret);
393
Thomas Gleixner239007b2009-11-17 16:46:45 +0100394 raw_spin_lock_irq(&desc->lock);
Thomas Gleixner009b4c32011-02-07 21:48:49 +0100395 desc->istate &= ~IRQS_INPROGRESS;
396 irq_compat_clr_progress(desc);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200397
398out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100399 raw_spin_unlock_irq(&desc->lock);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200400}
401EXPORT_SYMBOL_GPL(handle_nested_irq);
402
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100403static bool irq_check_poll(struct irq_desc *desc)
404{
Thomas Gleixner6954b752011-02-07 20:55:35 +0100405 if (!(desc->istate & IRQS_POLL_INPROGRESS))
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100406 return false;
407 return irq_wait_for_poll(desc);
408}
409
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700410/**
411 * handle_simple_irq - Simple and software-decoded IRQs.
412 * @irq: the interrupt number
413 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700414 *
415 * Simple interrupts are either sent from a demultiplexing interrupt
416 * handler or come from hardware, where no interrupt hardware control
417 * is necessary.
418 *
419 * Note: The caller is expected to handle the ack, clear, mask and
420 * unmask issues if necessary.
421 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800422void
David Howells7d12e782006-10-05 14:55:46 +0100423handle_simple_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700424{
Thomas Gleixner239007b2009-11-17 16:46:45 +0100425 raw_spin_lock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700426
Thomas Gleixner009b4c32011-02-07 21:48:49 +0100427 if (unlikely(desc->istate & IRQS_INPROGRESS))
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100428 if (!irq_check_poll(desc))
429 goto out_unlock;
430
Thomas Gleixner163ef302011-02-08 11:39:15 +0100431 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200432 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700433
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100434 if (unlikely(!desc->action || (desc->istate & IRQS_DISABLED)))
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700435 goto out_unlock;
436
Thomas Gleixner107781e2011-02-07 01:21:02 +0100437 handle_irq_event(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700438
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700439out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100440 raw_spin_unlock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700441}
442
443/**
444 * handle_level_irq - Level type irq handler
445 * @irq: the interrupt number
446 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700447 *
448 * Level type interrupts are active as long as the hardware line has
449 * the active level. This may require to mask the interrupt and unmask
450 * it after the associated handler has acknowledged the device, so the
451 * interrupt line is back to inactive.
452 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800453void
David Howells7d12e782006-10-05 14:55:46 +0100454handle_level_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700455{
Thomas Gleixner239007b2009-11-17 16:46:45 +0100456 raw_spin_lock(&desc->lock);
Thomas Gleixner9205e312010-09-27 12:44:50 +0000457 mask_ack_irq(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700458
Thomas Gleixner009b4c32011-02-07 21:48:49 +0100459 if (unlikely(desc->istate & IRQS_INPROGRESS))
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100460 if (!irq_check_poll(desc))
461 goto out_unlock;
462
Thomas Gleixner163ef302011-02-08 11:39:15 +0100463 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200464 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700465
466 /*
467 * If its disabled or no action available
468 * keep it masked and get out of here
469 */
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100470 if (unlikely(!desc->action || (desc->istate & IRQS_DISABLED)))
Ingo Molnar86998aa2006-09-19 11:14:34 +0200471 goto out_unlock;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700472
Thomas Gleixner15298662011-02-07 01:22:17 +0100473 handle_irq_event(desc);
Thomas Gleixnerb25c3402009-08-13 12:17:22 +0200474
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100475 if (!(desc->istate & (IRQS_DISABLED | IRQS_ONESHOT)))
Thomas Gleixner0eda58b2010-09-27 12:44:44 +0000476 unmask_irq(desc);
Ingo Molnar86998aa2006-09-19 11:14:34 +0200477out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100478 raw_spin_unlock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700479}
Ingo Molnar14819ea2009-01-14 12:34:21 +0100480EXPORT_SYMBOL_GPL(handle_level_irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700481
Thomas Gleixner78129572011-02-10 15:14:20 +0100482#ifdef CONFIG_IRQ_PREFLOW_FASTEOI
483static inline void preflow_handler(struct irq_desc *desc)
484{
485 if (desc->preflow_handler)
486 desc->preflow_handler(&desc->irq_data);
487}
488#else
489static inline void preflow_handler(struct irq_desc *desc) { }
490#endif
491
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700492/**
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700493 * handle_fasteoi_irq - irq handler for transparent controllers
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700494 * @irq: the interrupt number
495 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700496 *
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700497 * Only a single callback will be issued to the chip: an ->eoi()
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700498 * call when the interrupt has been serviced. This enables support
499 * for modern forms of interrupt handlers, which handle the flow
500 * details in hardware, transparently.
501 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800502void
David Howells7d12e782006-10-05 14:55:46 +0100503handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700504{
Thomas Gleixner239007b2009-11-17 16:46:45 +0100505 raw_spin_lock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700506
Thomas Gleixner009b4c32011-02-07 21:48:49 +0100507 if (unlikely(desc->istate & IRQS_INPROGRESS))
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100508 if (!irq_check_poll(desc))
509 goto out;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700510
Thomas Gleixner163ef302011-02-08 11:39:15 +0100511 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200512 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700513
514 /*
515 * If its disabled or no action available
Ingo Molnar76d21602007-02-16 01:28:24 -0800516 * then mask it and get out of here:
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700517 */
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100518 if (unlikely(!desc->action || (desc->istate & IRQS_DISABLED))) {
Thomas Gleixner2a0d6fb2011-02-08 12:17:57 +0100519 irq_compat_set_pending(desc);
520 desc->istate |= IRQS_PENDING;
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000521 mask_irq(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700522 goto out;
Benjamin Herrenschmidt98bb2442006-06-29 02:25:01 -0700523 }
Thomas Gleixnerc69e3752011-03-02 11:49:21 +0100524
525 if (desc->istate & IRQS_ONESHOT)
526 mask_irq(desc);
527
Thomas Gleixner78129572011-02-10 15:14:20 +0100528 preflow_handler(desc);
Thomas Gleixnera7ae4de2011-02-07 01:23:07 +0100529 handle_irq_event(desc);
Thomas Gleixner77694b42011-02-15 10:33:57 +0100530
531out_eoi:
Thomas Gleixner0c5c1552010-09-27 12:44:53 +0000532 desc->irq_data.chip->irq_eoi(&desc->irq_data);
Thomas Gleixner77694b42011-02-15 10:33:57 +0100533out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100534 raw_spin_unlock(&desc->lock);
Thomas Gleixner77694b42011-02-15 10:33:57 +0100535 return;
536out:
537 if (!(desc->irq_data.chip->flags & IRQCHIP_EOI_IF_HANDLED))
538 goto out_eoi;
539 goto out_unlock;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700540}
541
542/**
543 * handle_edge_irq - edge type IRQ handler
544 * @irq: the interrupt number
545 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700546 *
547 * Interrupt occures on the falling and/or rising edge of a hardware
548 * signal. The occurence is latched into the irq controller hardware
549 * and must be acked in order to be reenabled. After the ack another
550 * interrupt can happen on the same source even before the first one
Uwe Kleine-Königdfff0612010-02-12 21:58:11 +0100551 * is handled by the associated event handler. If this happens it
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700552 * might be necessary to disable (mask) the interrupt depending on the
553 * controller hardware. This requires to reenable the interrupt inside
554 * of the loop which handles the interrupts which have arrived while
555 * the handler was running. If all pending interrupts are handled, the
556 * loop is left.
557 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800558void
David Howells7d12e782006-10-05 14:55:46 +0100559handle_edge_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700560{
Thomas Gleixner239007b2009-11-17 16:46:45 +0100561 raw_spin_lock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700562
Thomas Gleixner163ef302011-02-08 11:39:15 +0100563 desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700564 /*
565 * If we're currently running this IRQ, or its disabled,
566 * we shouldn't process the IRQ. Mark it pending, handle
567 * the necessary masking and go out
568 */
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100569 if (unlikely((desc->istate & (IRQS_DISABLED | IRQS_INPROGRESS) ||
570 !desc->action))) {
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100571 if (!irq_check_poll(desc)) {
Thomas Gleixner2a0d6fb2011-02-08 12:17:57 +0100572 irq_compat_set_pending(desc);
573 desc->istate |= IRQS_PENDING;
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100574 mask_ack_irq(desc);
575 goto out_unlock;
576 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700577 }
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200578 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700579
580 /* Start handling the irq */
Thomas Gleixner22a49162010-09-27 12:44:47 +0000581 desc->irq_data.chip->irq_ack(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700582
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700583 do {
Thomas Gleixnera60a5dc2011-02-07 01:24:07 +0100584 if (unlikely(!desc->action)) {
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000585 mask_irq(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700586 goto out_unlock;
587 }
588
589 /*
590 * When another irq arrived while we were handling
591 * one, we could have masked the irq.
592 * Renable it, if it was not disabled in meantime.
593 */
Thomas Gleixner2a0d6fb2011-02-08 12:17:57 +0100594 if (unlikely(desc->istate & IRQS_PENDING)) {
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100595 if (!(desc->istate & IRQS_DISABLED) &&
Thomas Gleixner6e402622011-02-08 12:36:06 +0100596 (desc->istate & IRQS_MASKED))
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100597 unmask_irq(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700598 }
599
Thomas Gleixnera60a5dc2011-02-07 01:24:07 +0100600 handle_irq_event(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700601
Thomas Gleixner2a0d6fb2011-02-08 12:17:57 +0100602 } while ((desc->istate & IRQS_PENDING) &&
Thomas Gleixnerc1594b72011-02-07 22:11:30 +0100603 !(desc->istate & IRQS_DISABLED));
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700604
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700605out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100606 raw_spin_unlock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700607}
608
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700609/**
Liuweni24b26d42009-11-04 20:11:05 +0800610 * handle_percpu_irq - Per CPU local irq handler
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700611 * @irq: the interrupt number
612 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700613 *
614 * Per CPU interrupts on SMP machines without locking requirements
615 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800616void
David Howells7d12e782006-10-05 14:55:46 +0100617handle_percpu_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700618{
Thomas Gleixner35e857c2011-02-10 12:20:23 +0100619 struct irq_chip *chip = irq_desc_get_chip(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700620
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200621 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700622
Thomas Gleixner849f0612011-02-07 01:25:41 +0100623 if (chip->irq_ack)
624 chip->irq_ack(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700625
Thomas Gleixner849f0612011-02-07 01:25:41 +0100626 handle_irq_event_percpu(desc, desc->action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700627
Thomas Gleixner849f0612011-02-07 01:25:41 +0100628 if (chip->irq_eoi)
629 chip->irq_eoi(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700630}
631
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700632void
Thomas Gleixner3836ca02011-02-14 20:09:19 +0100633__irq_set_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
Ingo Molnara460e742006-10-17 00:10:03 -0700634 const char *name)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700635{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700636 unsigned long flags;
Thomas Gleixner02725e72011-02-12 10:37:36 +0100637 struct irq_desc *desc = irq_get_desc_buslock(irq, &flags);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700638
Thomas Gleixner02725e72011-02-12 10:37:36 +0100639 if (!desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700640 return;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700641
Thomas Gleixner091738a2011-02-14 20:16:43 +0100642 if (!handle) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700643 handle = handle_bad_irq;
Thomas Gleixner091738a2011-02-14 20:16:43 +0100644 } else {
645 if (WARN_ON(desc->irq_data.chip == &no_irq_chip))
Thomas Gleixner02725e72011-02-12 10:37:36 +0100646 goto out;
Thomas Gleixnerf8b54732006-07-01 22:30:08 +0100647 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700648
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700649 /* Uninstall? */
650 if (handle == handle_bad_irq) {
Thomas Gleixner6b8ff312010-10-01 12:58:38 +0200651 if (desc->irq_data.chip != &no_irq_chip)
Thomas Gleixner9205e312010-09-27 12:44:50 +0000652 mask_ack_irq(desc);
Thomas Gleixner801a0e92011-03-27 11:02:49 +0200653 irq_state_set_disabled(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700654 desc->depth = 1;
655 }
656 desc->handle_irq = handle;
Ingo Molnara460e742006-10-17 00:10:03 -0700657 desc->name = name;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700658
659 if (handle != handle_bad_irq && is_chained) {
Thomas Gleixner1ccb4e62011-02-09 14:44:17 +0100660 irq_settings_set_noprobe(desc);
661 irq_settings_set_norequest(desc);
Thomas Gleixner46999232011-02-02 21:41:14 +0000662 irq_startup(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700663 }
Thomas Gleixner02725e72011-02-12 10:37:36 +0100664out:
665 irq_put_desc_busunlock(desc, flags);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700666}
Thomas Gleixner3836ca02011-02-14 20:09:19 +0100667EXPORT_SYMBOL_GPL(__irq_set_handler);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700668
669void
Thomas Gleixner3836ca02011-02-14 20:09:19 +0100670irq_set_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
Ingo Molnara460e742006-10-17 00:10:03 -0700671 irq_flow_handler_t handle, const char *name)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700672{
Thomas Gleixner35e857c2011-02-10 12:20:23 +0100673 irq_set_chip(irq, chip);
Thomas Gleixner3836ca02011-02-14 20:09:19 +0100674 __irq_set_handler(irq, handle, 0, name);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700675}
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;
Thomas Gleixner02725e72011-02-12 10:37:36 +0100680 struct irq_desc *desc = irq_get_desc_lock(irq, &flags);
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 Gleixnera0056772011-02-08 17:11:03 +0100694
Thomas Gleixner876dbd42011-02-08 17:28:12 +0100695 irqd_set(&desc->irq_data, irq_settings_get_trigger_mask(desc));
696
Thomas Gleixner02725e72011-02-12 10:37:36 +0100697 irq_put_desc_unlock(desc, flags);
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800698}