blob: 86c8e42f7fe416718f26ee1e0270df6713fa37b4 [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 Gleixnerd3c60042008-10-16 09:55:00 +020028 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070029 unsigned long flags;
30
Yinghai Lu7d94f7c2008-08-19 20:50:14 -070031 if (!desc) {
Arjan van de Ven261c40c2008-07-25 19:45:37 -070032 WARN(1, KERN_ERR "Trying to install chip for IRQ%d\n", irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070033 return -EINVAL;
34 }
35
36 if (!chip)
37 chip = &no_irq_chip;
38
Thomas Gleixner239007b2009-11-17 16:46:45 +010039 raw_spin_lock_irqsave(&desc->lock, flags);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070040 irq_chip_set_defaults(chip);
Thomas Gleixner6b8ff312010-10-01 12:58:38 +020041 desc->irq_data.chip = chip;
Thomas Gleixner239007b2009-11-17 16:46:45 +010042 raw_spin_unlock_irqrestore(&desc->lock, flags);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070043
44 return 0;
45}
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010046EXPORT_SYMBOL(irq_set_chip);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070047
48/**
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010049 * irq_set_type - set the irq trigger type for an irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070050 * @irq: irq number
David Brownell0c5d1eb2008-10-01 14:46:18 -070051 * @type: IRQ_TYPE_{LEVEL,EDGE}_* value - see include/linux/irq.h
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070052 */
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010053int irq_set_irq_type(unsigned int irq, unsigned int type)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070054{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +020055 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070056 unsigned long flags;
57 int ret = -ENXIO;
58
Yinghai Lu7d94f7c2008-08-19 20:50:14 -070059 if (!desc) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070060 printk(KERN_ERR "Trying to set irq type for IRQ%d\n", irq);
61 return -ENODEV;
62 }
63
David Brownellf2b662d2008-12-01 14:31:38 -080064 type &= IRQ_TYPE_SENSE_MASK;
David Brownell0c5d1eb2008-10-01 14:46:18 -070065 if (type == IRQ_TYPE_NONE)
66 return 0;
67
Thomas Gleixner43abe432011-02-12 12:10:49 +010068 chip_bus_lock(desc);
Thomas Gleixner239007b2009-11-17 16:46:45 +010069 raw_spin_lock_irqsave(&desc->lock, flags);
Chris Friesen0b3682ba32008-10-20 12:41:58 -060070 ret = __irq_set_trigger(desc, irq, type);
Thomas Gleixner239007b2009-11-17 16:46:45 +010071 raw_spin_unlock_irqrestore(&desc->lock, flags);
Thomas Gleixner43abe432011-02-12 12:10:49 +010072 chip_bus_sync_unlock(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070073 return ret;
74}
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010075EXPORT_SYMBOL(irq_set_irq_type);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070076
77/**
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010078 * irq_set_handler_data - set irq handler data for an irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070079 * @irq: Interrupt number
80 * @data: Pointer to interrupt specific data
81 *
82 * Set the hardware irq controller data for an irq
83 */
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +010084int irq_set_handler_data(unsigned int irq, void *data)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070085{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +020086 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070087 unsigned long flags;
88
Yinghai Lu7d94f7c2008-08-19 20:50:14 -070089 if (!desc) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070090 printk(KERN_ERR
91 "Trying to install controller data for IRQ%d\n", irq);
92 return -EINVAL;
93 }
94
Thomas Gleixner239007b2009-11-17 16:46:45 +010095 raw_spin_lock_irqsave(&desc->lock, flags);
Thomas Gleixner6b8ff312010-10-01 12:58:38 +020096 desc->irq_data.handler_data = data;
Thomas Gleixner239007b2009-11-17 16:46:45 +010097 raw_spin_unlock_irqrestore(&desc->lock, flags);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070098 return 0;
99}
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +0100100EXPORT_SYMBOL(irq_set_handler_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700101
102/**
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +0100103 * irq_set_msi_desc - set MSI descriptor data for an irq
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700104 * @irq: Interrupt number
Randy Dunlap472900b2007-02-16 01:28:25 -0800105 * @entry: Pointer to MSI descriptor data
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700106 *
Liuweni24b26d42009-11-04 20:11:05 +0800107 * Set the MSI descriptor entry for an irq
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700108 */
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +0100109int irq_set_msi_desc(unsigned int irq, struct msi_desc *entry)
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700110{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200111 struct irq_desc *desc = irq_to_desc(irq);
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700112 unsigned long flags;
113
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700114 if (!desc) {
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700115 printk(KERN_ERR
116 "Trying to install msi data for IRQ%d\n", irq);
117 return -EINVAL;
118 }
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700119
Thomas Gleixner239007b2009-11-17 16:46:45 +0100120 raw_spin_lock_irqsave(&desc->lock, flags);
Thomas Gleixner6b8ff312010-10-01 12:58:38 +0200121 desc->irq_data.msi_desc = entry;
Michael Ellerman7fe37302007-04-18 19:39:21 +1000122 if (entry)
123 entry->irq = irq;
Thomas Gleixner239007b2009-11-17 16:46:45 +0100124 raw_spin_unlock_irqrestore(&desc->lock, flags);
Eric W. Biederman5b912c12007-01-28 12:52:03 -0700125 return 0;
126}
127
128/**
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +0100129 * irq_set_chip_data - set irq chip data for an irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700130 * @irq: Interrupt number
131 * @data: Pointer to chip specific data
132 *
133 * Set the hardware irq chip data for an irq
134 */
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +0100135int irq_set_chip_data(unsigned int irq, void *data)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700136{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200137 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700138 unsigned long flags;
139
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700140 if (!desc) {
141 printk(KERN_ERR
142 "Trying to install chip data for IRQ%d\n", irq);
143 return -EINVAL;
144 }
145
Thomas Gleixner6b8ff312010-10-01 12:58:38 +0200146 if (!desc->irq_data.chip) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700147 printk(KERN_ERR "BUG: bad set_irq_chip_data(IRQ#%d)\n", irq);
148 return -EINVAL;
149 }
150
Thomas Gleixner239007b2009-11-17 16:46:45 +0100151 raw_spin_lock_irqsave(&desc->lock, flags);
Thomas Gleixner6b8ff312010-10-01 12:58:38 +0200152 desc->irq_data.chip_data = data;
Thomas Gleixner239007b2009-11-17 16:46:45 +0100153 raw_spin_unlock_irqrestore(&desc->lock, flags);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700154
155 return 0;
156}
Thomas Gleixnera0cd9ca2011-02-10 11:36:33 +0100157EXPORT_SYMBOL(irq_set_chip_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700158
Thomas Gleixnerf303a6d2010-09-28 17:34:01 +0200159struct irq_data *irq_get_irq_data(unsigned int irq)
160{
161 struct irq_desc *desc = irq_to_desc(irq);
162
163 return desc ? &desc->irq_data : NULL;
164}
165EXPORT_SYMBOL_GPL(irq_get_irq_data);
166
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200167/**
168 * set_irq_nested_thread - Set/Reset the IRQ_NESTED_THREAD flag of an irq
169 *
170 * @irq: Interrupt number
171 * @nest: 0 to clear / 1 to set the IRQ_NESTED_THREAD flag
172 *
173 * The IRQ_NESTED_THREAD flag indicates that on
174 * request_threaded_irq() no separate interrupt thread should be
175 * created for the irq as the handler are called nested in the
176 * context of a demultiplexing interrupt handler thread.
177 */
178void set_irq_nested_thread(unsigned int irq, int nest)
179{
180 struct irq_desc *desc = irq_to_desc(irq);
181 unsigned long flags;
182
183 if (!desc)
184 return;
185
Thomas Gleixner239007b2009-11-17 16:46:45 +0100186 raw_spin_lock_irqsave(&desc->lock, flags);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200187 if (nest)
188 desc->status |= IRQ_NESTED_THREAD;
189 else
190 desc->status &= ~IRQ_NESTED_THREAD;
Thomas Gleixner239007b2009-11-17 16:46:45 +0100191 raw_spin_unlock_irqrestore(&desc->lock, flags);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200192}
193EXPORT_SYMBOL_GPL(set_irq_nested_thread);
194
Thomas Gleixner46999232011-02-02 21:41:14 +0000195int irq_startup(struct irq_desc *desc)
196{
197 desc->status &= ~(IRQ_MASKED | IRQ_DISABLED);
198 desc->depth = 0;
199
200 if (desc->irq_data.chip->irq_startup)
201 return desc->irq_data.chip->irq_startup(&desc->irq_data);
202
Thomas Gleixner87923472011-02-03 12:27:44 +0100203 irq_enable(desc);
Thomas Gleixner46999232011-02-02 21:41:14 +0000204 return 0;
205}
206
207void irq_shutdown(struct irq_desc *desc)
208{
209 desc->status |= IRQ_MASKED | IRQ_DISABLED;
210 desc->depth = 1;
211 desc->irq_data.chip->irq_shutdown(&desc->irq_data);
212}
213
Thomas Gleixner87923472011-02-03 12:27:44 +0100214void irq_enable(struct irq_desc *desc)
215{
216 desc->irq_data.chip->irq_enable(&desc->irq_data);
217}
218
219void irq_disable(struct irq_desc *desc)
220{
221 desc->irq_data.chip->irq_disable(&desc->irq_data);
222}
223
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700224/*
225 * default enable function
226 */
Thomas Gleixnerc5f75632010-09-27 12:44:56 +0000227static void default_enable(struct irq_data *data)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700228{
Thomas Gleixnerc5f75632010-09-27 12:44:56 +0000229 struct irq_desc *desc = irq_data_to_desc(data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700230
Thomas Gleixner0eda58b2010-09-27 12:44:44 +0000231 desc->irq_data.chip->irq_unmask(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700232 desc->status &= ~IRQ_MASKED;
233}
234
235/*
236 * default disable function
237 */
Thomas Gleixnerbc310dd2010-09-27 12:45:02 +0000238static void default_disable(struct irq_data *data)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700239{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700240}
241
242/*
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100243 * default shutdown function
244 */
Thomas Gleixnerbc310dd2010-09-27 12:45:02 +0000245static void default_shutdown(struct irq_data *data)
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100246{
Thomas Gleixnerbc310dd2010-09-27 12:45:02 +0000247 struct irq_desc *desc = irq_data_to_desc(data);
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100248
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000249 desc->irq_data.chip->irq_mask(&desc->irq_data);
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100250}
251
Thomas Gleixnerbd151412010-10-01 15:17:14 +0200252#ifndef CONFIG_GENERIC_HARDIRQS_NO_DEPRECATED
Thomas Gleixner3876ec92010-09-27 12:44:35 +0000253/* Temporary migration helpers */
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000254static void compat_irq_mask(struct irq_data *data)
255{
256 data->chip->mask(data->irq);
257}
258
Thomas Gleixner0eda58b2010-09-27 12:44:44 +0000259static void compat_irq_unmask(struct irq_data *data)
260{
261 data->chip->unmask(data->irq);
262}
263
Thomas Gleixner22a49162010-09-27 12:44:47 +0000264static void compat_irq_ack(struct irq_data *data)
265{
266 data->chip->ack(data->irq);
267}
268
Thomas Gleixner9205e312010-09-27 12:44:50 +0000269static void compat_irq_mask_ack(struct irq_data *data)
270{
271 data->chip->mask_ack(data->irq);
272}
273
Thomas Gleixner0c5c1552010-09-27 12:44:53 +0000274static void compat_irq_eoi(struct irq_data *data)
275{
276 data->chip->eoi(data->irq);
277}
278
Thomas Gleixnerc5f75632010-09-27 12:44:56 +0000279static void compat_irq_enable(struct irq_data *data)
280{
281 data->chip->enable(data->irq);
282}
283
Thomas Gleixnerbc310dd2010-09-27 12:45:02 +0000284static void compat_irq_disable(struct irq_data *data)
285{
286 data->chip->disable(data->irq);
287}
288
289static void compat_irq_shutdown(struct irq_data *data)
290{
291 data->chip->shutdown(data->irq);
292}
293
Thomas Gleixner37e12df2010-09-27 12:45:38 +0000294static unsigned int compat_irq_startup(struct irq_data *data)
295{
296 return data->chip->startup(data->irq);
297}
298
Thomas Gleixnerc96b3b32010-09-27 12:45:41 +0000299static int compat_irq_set_affinity(struct irq_data *data,
300 const struct cpumask *dest, bool force)
301{
302 return data->chip->set_affinity(data->irq, dest);
303}
304
Thomas Gleixnerb2ba2c32010-09-27 12:45:47 +0000305static int compat_irq_set_type(struct irq_data *data, unsigned int type)
306{
307 return data->chip->set_type(data->irq, type);
308}
309
Thomas Gleixner2f7e99b2010-09-27 12:45:50 +0000310static int compat_irq_set_wake(struct irq_data *data, unsigned int on)
311{
312 return data->chip->set_wake(data->irq, on);
313}
314
Thomas Gleixner21e2b8c2010-09-27 12:45:53 +0000315static int compat_irq_retrigger(struct irq_data *data)
316{
317 return data->chip->retrigger(data->irq);
318}
319
Thomas Gleixner3876ec92010-09-27 12:44:35 +0000320static void compat_bus_lock(struct irq_data *data)
321{
322 data->chip->bus_lock(data->irq);
323}
324
325static void compat_bus_sync_unlock(struct irq_data *data)
326{
327 data->chip->bus_sync_unlock(data->irq);
328}
Thomas Gleixnerbd151412010-10-01 15:17:14 +0200329#endif
Thomas Gleixner3876ec92010-09-27 12:44:35 +0000330
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100331/*
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700332 * Fixup enable/disable function pointers
333 */
334void irq_chip_set_defaults(struct irq_chip *chip)
335{
Thomas Gleixnerbd151412010-10-01 15:17:14 +0200336#ifndef CONFIG_GENERIC_HARDIRQS_NO_DEPRECATED
Thomas Gleixnerc5f75632010-09-27 12:44:56 +0000337 /*
338 * Compat fixup functions need to be before we set the
339 * defaults for enable/disable/startup/shutdown
340 */
341 if (chip->enable)
342 chip->irq_enable = compat_irq_enable;
Thomas Gleixnerbc310dd2010-09-27 12:45:02 +0000343 if (chip->disable)
344 chip->irq_disable = compat_irq_disable;
345 if (chip->shutdown)
346 chip->irq_shutdown = compat_irq_shutdown;
Thomas Gleixner37e12df2010-09-27 12:45:38 +0000347 if (chip->startup)
348 chip->irq_startup = compat_irq_startup;
Thomas Gleixnerbd151412010-10-01 15:17:14 +0200349#endif
Thomas Gleixnerc5f75632010-09-27 12:44:56 +0000350 /*
351 * The real defaults
352 */
353 if (!chip->irq_enable)
354 chip->irq_enable = default_enable;
Thomas Gleixnerbc310dd2010-09-27 12:45:02 +0000355 if (!chip->irq_disable)
356 chip->irq_disable = default_disable;
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100357 /*
Thomas Gleixnerbc310dd2010-09-27 12:45:02 +0000358 * We use chip->irq_disable, when the user provided its own. When
359 * we have default_disable set for chip->irq_disable, then we need
Thomas Gleixner89d694b2008-02-18 18:25:17 +0100360 * to use default_shutdown, otherwise the irq line is not
361 * disabled on free_irq():
362 */
Thomas Gleixnerbc310dd2010-09-27 12:45:02 +0000363 if (!chip->irq_shutdown)
364 chip->irq_shutdown = chip->irq_disable != default_disable ?
365 chip->irq_disable : default_shutdown;
Thomas Gleixnerbd151412010-10-01 15:17:14 +0200366
367#ifndef CONFIG_GENERIC_HARDIRQS_NO_DEPRECATED
Zhang, Yanminb86432b2006-11-16 01:19:10 -0800368 if (!chip->end)
369 chip->end = dummy_irq_chip.end;
Thomas Gleixner3876ec92010-09-27 12:44:35 +0000370
Thomas Gleixnerbc310dd2010-09-27 12:45:02 +0000371 /*
372 * Now fix up the remaining compat handlers
373 */
Thomas Gleixner3876ec92010-09-27 12:44:35 +0000374 if (chip->bus_lock)
375 chip->irq_bus_lock = compat_bus_lock;
376 if (chip->bus_sync_unlock)
377 chip->irq_bus_sync_unlock = compat_bus_sync_unlock;
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000378 if (chip->mask)
379 chip->irq_mask = compat_irq_mask;
Thomas Gleixner0eda58b2010-09-27 12:44:44 +0000380 if (chip->unmask)
381 chip->irq_unmask = compat_irq_unmask;
Thomas Gleixner22a49162010-09-27 12:44:47 +0000382 if (chip->ack)
383 chip->irq_ack = compat_irq_ack;
Thomas Gleixner9205e312010-09-27 12:44:50 +0000384 if (chip->mask_ack)
385 chip->irq_mask_ack = compat_irq_mask_ack;
Thomas Gleixner0c5c1552010-09-27 12:44:53 +0000386 if (chip->eoi)
387 chip->irq_eoi = compat_irq_eoi;
Thomas Gleixnerc96b3b32010-09-27 12:45:41 +0000388 if (chip->set_affinity)
389 chip->irq_set_affinity = compat_irq_set_affinity;
Thomas Gleixnerb2ba2c32010-09-27 12:45:47 +0000390 if (chip->set_type)
391 chip->irq_set_type = compat_irq_set_type;
Thomas Gleixner2f7e99b2010-09-27 12:45:50 +0000392 if (chip->set_wake)
393 chip->irq_set_wake = compat_irq_set_wake;
Thomas Gleixner21e2b8c2010-09-27 12:45:53 +0000394 if (chip->retrigger)
395 chip->irq_retrigger = compat_irq_retrigger;
Thomas Gleixnerbd151412010-10-01 15:17:14 +0200396#endif
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700397}
398
Thomas Gleixner9205e312010-09-27 12:44:50 +0000399static inline void mask_ack_irq(struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700400{
Thomas Gleixner9205e312010-09-27 12:44:50 +0000401 if (desc->irq_data.chip->irq_mask_ack)
402 desc->irq_data.chip->irq_mask_ack(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700403 else {
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000404 desc->irq_data.chip->irq_mask(&desc->irq_data);
Thomas Gleixner22a49162010-09-27 12:44:47 +0000405 if (desc->irq_data.chip->irq_ack)
406 desc->irq_data.chip->irq_ack(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700407 }
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100408 desc->status |= IRQ_MASKED;
409}
410
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000411static inline void mask_irq(struct irq_desc *desc)
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100412{
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000413 if (desc->irq_data.chip->irq_mask) {
414 desc->irq_data.chip->irq_mask(&desc->irq_data);
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100415 desc->status |= IRQ_MASKED;
416 }
417}
418
Thomas Gleixner0eda58b2010-09-27 12:44:44 +0000419static inline void unmask_irq(struct irq_desc *desc)
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100420{
Thomas Gleixner0eda58b2010-09-27 12:44:44 +0000421 if (desc->irq_data.chip->irq_unmask) {
422 desc->irq_data.chip->irq_unmask(&desc->irq_data);
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100423 desc->status &= ~IRQ_MASKED;
424 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700425}
426
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200427/*
428 * handle_nested_irq - Handle a nested irq from a irq thread
429 * @irq: the interrupt number
430 *
431 * Handle interrupts which are nested into a threaded interrupt
432 * handler. The handler function is called inside the calling
433 * threads context.
434 */
435void handle_nested_irq(unsigned int irq)
436{
437 struct irq_desc *desc = irq_to_desc(irq);
438 struct irqaction *action;
439 irqreturn_t action_ret;
440
441 might_sleep();
442
Thomas Gleixner239007b2009-11-17 16:46:45 +0100443 raw_spin_lock_irq(&desc->lock);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200444
445 kstat_incr_irqs_this_cpu(irq, desc);
446
447 action = desc->action;
448 if (unlikely(!action || (desc->status & IRQ_DISABLED)))
449 goto out_unlock;
450
451 desc->status |= IRQ_INPROGRESS;
Thomas Gleixner239007b2009-11-17 16:46:45 +0100452 raw_spin_unlock_irq(&desc->lock);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200453
454 action_ret = action->thread_fn(action->irq, action->dev_id);
455 if (!noirqdebug)
456 note_interrupt(irq, desc, action_ret);
457
Thomas Gleixner239007b2009-11-17 16:46:45 +0100458 raw_spin_lock_irq(&desc->lock);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200459 desc->status &= ~IRQ_INPROGRESS;
460
461out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100462 raw_spin_unlock_irq(&desc->lock);
Thomas Gleixner399b5da2009-08-13 13:21:38 +0200463}
464EXPORT_SYMBOL_GPL(handle_nested_irq);
465
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100466static bool irq_check_poll(struct irq_desc *desc)
467{
468 if (!(desc->status & IRQ_POLL_INPROGRESS))
469 return false;
470 return irq_wait_for_poll(desc);
471}
472
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700473/**
474 * handle_simple_irq - Simple and software-decoded IRQs.
475 * @irq: the interrupt number
476 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700477 *
478 * Simple interrupts are either sent from a demultiplexing interrupt
479 * handler or come from hardware, where no interrupt hardware control
480 * is necessary.
481 *
482 * Note: The caller is expected to handle the ack, clear, mask and
483 * unmask issues if necessary.
484 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800485void
David Howells7d12e782006-10-05 14:55:46 +0100486handle_simple_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700487{
488 struct irqaction *action;
489 irqreturn_t action_ret;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700490
Thomas Gleixner239007b2009-11-17 16:46:45 +0100491 raw_spin_lock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700492
493 if (unlikely(desc->status & IRQ_INPROGRESS))
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100494 if (!irq_check_poll(desc))
495 goto out_unlock;
496
Steven Rostedt971e5b35f2007-12-18 18:05:58 +0100497 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200498 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700499
500 action = desc->action;
Steven Rostedt971e5b35f2007-12-18 18:05:58 +0100501 if (unlikely(!action || (desc->status & IRQ_DISABLED)))
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700502 goto out_unlock;
503
504 desc->status |= IRQ_INPROGRESS;
Thomas Gleixner239007b2009-11-17 16:46:45 +0100505 raw_spin_unlock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700506
David Howells7d12e782006-10-05 14:55:46 +0100507 action_ret = handle_IRQ_event(irq, action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700508 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100509 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700510
Thomas Gleixner239007b2009-11-17 16:46:45 +0100511 raw_spin_lock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700512 desc->status &= ~IRQ_INPROGRESS;
513out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100514 raw_spin_unlock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700515}
516
517/**
518 * handle_level_irq - Level type irq handler
519 * @irq: the interrupt number
520 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700521 *
522 * Level type interrupts are active as long as the hardware line has
523 * the active level. This may require to mask the interrupt and unmask
524 * it after the associated handler has acknowledged the device, so the
525 * interrupt line is back to inactive.
526 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800527void
David Howells7d12e782006-10-05 14:55:46 +0100528handle_level_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700529{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700530 struct irqaction *action;
531 irqreturn_t action_ret;
532
Thomas Gleixner239007b2009-11-17 16:46:45 +0100533 raw_spin_lock(&desc->lock);
Thomas Gleixner9205e312010-09-27 12:44:50 +0000534 mask_ack_irq(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700535
536 if (unlikely(desc->status & IRQ_INPROGRESS))
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100537 if (!irq_check_poll(desc))
538 goto out_unlock;
539
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700540 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200541 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700542
543 /*
544 * If its disabled or no action available
545 * keep it masked and get out of here
546 */
547 action = desc->action;
Thomas Gleixner49663422007-08-12 15:46:34 +0000548 if (unlikely(!action || (desc->status & IRQ_DISABLED)))
Ingo Molnar86998aa2006-09-19 11:14:34 +0200549 goto out_unlock;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700550
551 desc->status |= IRQ_INPROGRESS;
Thomas Gleixner239007b2009-11-17 16:46:45 +0100552 raw_spin_unlock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700553
David Howells7d12e782006-10-05 14:55:46 +0100554 action_ret = handle_IRQ_event(irq, action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700555 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100556 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700557
Thomas Gleixner239007b2009-11-17 16:46:45 +0100558 raw_spin_lock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700559 desc->status &= ~IRQ_INPROGRESS;
Thomas Gleixnerb25c3402009-08-13 12:17:22 +0200560
Thomas Gleixner0b1adaa2010-03-09 19:45:54 +0100561 if (!(desc->status & (IRQ_DISABLED | IRQ_ONESHOT)))
Thomas Gleixner0eda58b2010-09-27 12:44:44 +0000562 unmask_irq(desc);
Ingo Molnar86998aa2006-09-19 11:14:34 +0200563out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100564 raw_spin_unlock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700565}
Ingo Molnar14819ea2009-01-14 12:34:21 +0100566EXPORT_SYMBOL_GPL(handle_level_irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700567
568/**
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700569 * handle_fasteoi_irq - irq handler for transparent controllers
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700570 * @irq: the interrupt number
571 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700572 *
Ingo Molnar47c2a3a2006-06-29 02:25:03 -0700573 * Only a single callback will be issued to the chip: an ->eoi()
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700574 * call when the interrupt has been serviced. This enables support
575 * for modern forms of interrupt handlers, which handle the flow
576 * details in hardware, transparently.
577 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800578void
David Howells7d12e782006-10-05 14:55:46 +0100579handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700580{
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700581 struct irqaction *action;
582 irqreturn_t action_ret;
583
Thomas Gleixner239007b2009-11-17 16:46:45 +0100584 raw_spin_lock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700585
586 if (unlikely(desc->status & IRQ_INPROGRESS))
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100587 if (!irq_check_poll(desc))
588 goto out;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700589
590 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200591 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700592
593 /*
594 * If its disabled or no action available
Ingo Molnar76d21602007-02-16 01:28:24 -0800595 * then mask it and get out of here:
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700596 */
597 action = desc->action;
Benjamin Herrenschmidt98bb2442006-06-29 02:25:01 -0700598 if (unlikely(!action || (desc->status & IRQ_DISABLED))) {
599 desc->status |= IRQ_PENDING;
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000600 mask_irq(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700601 goto out;
Benjamin Herrenschmidt98bb2442006-06-29 02:25:01 -0700602 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700603
604 desc->status |= IRQ_INPROGRESS;
Benjamin Herrenschmidt98bb2442006-06-29 02:25:01 -0700605 desc->status &= ~IRQ_PENDING;
Thomas Gleixner239007b2009-11-17 16:46:45 +0100606 raw_spin_unlock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700607
David Howells7d12e782006-10-05 14:55:46 +0100608 action_ret = handle_IRQ_event(irq, action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700609 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100610 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700611
Thomas Gleixner239007b2009-11-17 16:46:45 +0100612 raw_spin_lock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700613 desc->status &= ~IRQ_INPROGRESS;
614out:
Thomas Gleixner0c5c1552010-09-27 12:44:53 +0000615 desc->irq_data.chip->irq_eoi(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700616
Thomas Gleixner239007b2009-11-17 16:46:45 +0100617 raw_spin_unlock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700618}
619
620/**
621 * handle_edge_irq - edge type IRQ handler
622 * @irq: the interrupt number
623 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700624 *
625 * Interrupt occures on the falling and/or rising edge of a hardware
626 * signal. The occurence is latched into the irq controller hardware
627 * and must be acked in order to be reenabled. After the ack another
628 * interrupt can happen on the same source even before the first one
Uwe Kleine-Königdfff0612010-02-12 21:58:11 +0100629 * is handled by the associated event handler. If this happens it
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700630 * might be necessary to disable (mask) the interrupt depending on the
631 * controller hardware. This requires to reenable the interrupt inside
632 * of the loop which handles the interrupts which have arrived while
633 * the handler was running. If all pending interrupts are handled, the
634 * loop is left.
635 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800636void
David Howells7d12e782006-10-05 14:55:46 +0100637handle_edge_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700638{
Thomas Gleixner239007b2009-11-17 16:46:45 +0100639 raw_spin_lock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700640
641 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
642
643 /*
644 * If we're currently running this IRQ, or its disabled,
645 * we shouldn't process the IRQ. Mark it pending, handle
646 * the necessary masking and go out
647 */
648 if (unlikely((desc->status & (IRQ_INPROGRESS | IRQ_DISABLED)) ||
649 !desc->action)) {
Thomas Gleixnerfe200ae2011-02-07 10:34:30 +0100650 if (!irq_check_poll(desc)) {
651 desc->status |= (IRQ_PENDING | IRQ_MASKED);
652 mask_ack_irq(desc);
653 goto out_unlock;
654 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700655 }
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200656 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700657
658 /* Start handling the irq */
Thomas Gleixner22a49162010-09-27 12:44:47 +0000659 desc->irq_data.chip->irq_ack(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700660
661 /* Mark the IRQ currently in progress.*/
662 desc->status |= IRQ_INPROGRESS;
663
664 do {
665 struct irqaction *action = desc->action;
666 irqreturn_t action_ret;
667
668 if (unlikely(!action)) {
Thomas Gleixnere2c0f8f2010-09-27 12:44:42 +0000669 mask_irq(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700670 goto out_unlock;
671 }
672
673 /*
674 * When another irq arrived while we were handling
675 * one, we could have masked the irq.
676 * Renable it, if it was not disabled in meantime.
677 */
678 if (unlikely((desc->status &
679 (IRQ_PENDING | IRQ_MASKED | IRQ_DISABLED)) ==
680 (IRQ_PENDING | IRQ_MASKED))) {
Thomas Gleixner0eda58b2010-09-27 12:44:44 +0000681 unmask_irq(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700682 }
683
684 desc->status &= ~IRQ_PENDING;
Thomas Gleixner239007b2009-11-17 16:46:45 +0100685 raw_spin_unlock(&desc->lock);
David Howells7d12e782006-10-05 14:55:46 +0100686 action_ret = handle_IRQ_event(irq, action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700687 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100688 note_interrupt(irq, desc, action_ret);
Thomas Gleixner239007b2009-11-17 16:46:45 +0100689 raw_spin_lock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700690
691 } while ((desc->status & (IRQ_PENDING | IRQ_DISABLED)) == IRQ_PENDING);
692
693 desc->status &= ~IRQ_INPROGRESS;
694out_unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +0100695 raw_spin_unlock(&desc->lock);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700696}
697
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700698/**
Liuweni24b26d42009-11-04 20:11:05 +0800699 * handle_percpu_irq - Per CPU local irq handler
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700700 * @irq: the interrupt number
701 * @desc: the interrupt description structure for this irq
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700702 *
703 * Per CPU interrupts on SMP machines without locking requirements
704 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800705void
David Howells7d12e782006-10-05 14:55:46 +0100706handle_percpu_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700707{
708 irqreturn_t action_ret;
709
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200710 kstat_incr_irqs_this_cpu(irq, desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700711
Thomas Gleixner22a49162010-09-27 12:44:47 +0000712 if (desc->irq_data.chip->irq_ack)
713 desc->irq_data.chip->irq_ack(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700714
David Howells7d12e782006-10-05 14:55:46 +0100715 action_ret = handle_IRQ_event(irq, desc->action);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700716 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100717 note_interrupt(irq, desc, action_ret);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700718
Thomas Gleixner0c5c1552010-09-27 12:44:53 +0000719 if (desc->irq_data.chip->irq_eoi)
720 desc->irq_data.chip->irq_eoi(&desc->irq_data);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700721}
722
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700723void
Ingo Molnara460e742006-10-17 00:10:03 -0700724__set_irq_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
725 const char *name)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700726{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200727 struct irq_desc *desc = irq_to_desc(irq);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700728 unsigned long flags;
729
Yinghai Lu7d94f7c2008-08-19 20:50:14 -0700730 if (!desc) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700731 printk(KERN_ERR
732 "Trying to install type control for IRQ%d\n", irq);
733 return;
734 }
735
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700736 if (!handle)
737 handle = handle_bad_irq;
Thomas Gleixner6b8ff312010-10-01 12:58:38 +0200738 else if (desc->irq_data.chip == &no_irq_chip) {
Thomas Gleixnerf8b54732006-07-01 22:30:08 +0100739 printk(KERN_WARNING "Trying to install %sinterrupt handler "
Geert Uytterhoevenb039db82006-12-20 15:59:48 +0100740 "for IRQ%d\n", is_chained ? "chained " : "", irq);
Thomas Gleixnerf8b54732006-07-01 22:30:08 +0100741 /*
742 * Some ARM implementations install a handler for really dumb
743 * interrupt hardware without setting an irq_chip. This worked
744 * with the ARM no_irq_chip but the check in setup_irq would
745 * prevent us to setup the interrupt at all. Switch it to
746 * dummy_irq_chip for easy transition.
747 */
Thomas Gleixner6b8ff312010-10-01 12:58:38 +0200748 desc->irq_data.chip = &dummy_irq_chip;
Thomas Gleixnerf8b54732006-07-01 22:30:08 +0100749 }
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700750
Thomas Gleixner3876ec92010-09-27 12:44:35 +0000751 chip_bus_lock(desc);
Thomas Gleixner239007b2009-11-17 16:46:45 +0100752 raw_spin_lock_irqsave(&desc->lock, flags);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700753
754 /* Uninstall? */
755 if (handle == handle_bad_irq) {
Thomas Gleixner6b8ff312010-10-01 12:58:38 +0200756 if (desc->irq_data.chip != &no_irq_chip)
Thomas Gleixner9205e312010-09-27 12:44:50 +0000757 mask_ack_irq(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700758 desc->status |= IRQ_DISABLED;
759 desc->depth = 1;
760 }
761 desc->handle_irq = handle;
Ingo Molnara460e742006-10-17 00:10:03 -0700762 desc->name = name;
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700763
764 if (handle != handle_bad_irq && is_chained) {
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700765 desc->status |= IRQ_NOREQUEST | IRQ_NOPROBE;
Thomas Gleixner46999232011-02-02 21:41:14 +0000766 irq_startup(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700767 }
Thomas Gleixner239007b2009-11-17 16:46:45 +0100768 raw_spin_unlock_irqrestore(&desc->lock, flags);
Thomas Gleixner3876ec92010-09-27 12:44:35 +0000769 chip_bus_sync_unlock(desc);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700770}
Ingo Molnar14819ea2009-01-14 12:34:21 +0100771EXPORT_SYMBOL_GPL(__set_irq_handler);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700772
773void
774set_irq_chip_and_handler(unsigned int irq, struct irq_chip *chip,
David Howells57a58a92006-10-05 13:06:34 +0100775 irq_flow_handler_t handle)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700776{
777 set_irq_chip(irq, chip);
Ingo Molnara460e742006-10-17 00:10:03 -0700778 __set_irq_handler(irq, handle, 0, NULL);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700779}
780
Ingo Molnara460e742006-10-17 00:10:03 -0700781void
782set_irq_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
783 irq_flow_handler_t handle, const char *name)
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700784{
Ingo Molnara460e742006-10-17 00:10:03 -0700785 set_irq_chip(irq, chip);
786 __set_irq_handler(irq, handle, 0, name);
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -0700787}
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800788
Thomas Gleixner44247182010-09-28 10:40:18 +0200789void irq_modify_status(unsigned int irq, unsigned long clr, unsigned long set)
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800790{
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200791 struct irq_desc *desc = irq_to_desc(irq);
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800792 unsigned long flags;
793
Thomas Gleixner44247182010-09-28 10:40:18 +0200794 if (!desc)
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800795 return;
Thomas Gleixner44247182010-09-28 10:40:18 +0200796
797 /* Sanitize flags */
798 set &= IRQF_MODIFY_MASK;
799 clr &= IRQF_MODIFY_MASK;
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800800
Thomas Gleixner239007b2009-11-17 16:46:45 +0100801 raw_spin_lock_irqsave(&desc->lock, flags);
Thomas Gleixner44247182010-09-28 10:40:18 +0200802 desc->status &= ~clr;
803 desc->status |= set;
Thomas Gleixner239007b2009-11-17 16:46:45 +0100804 raw_spin_unlock_irqrestore(&desc->lock, flags);
Ralf Baechle46f4f8f2008-02-08 04:22:01 -0800805}