genirq: Consolidate disable/enable
[linux-flexiantxendom0-3.2.10.git] / kernel / irq / chip.c
1 /*
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>
14 #include <linux/msi.h>
15 #include <linux/module.h>
16 #include <linux/interrupt.h>
17 #include <linux/kernel_stat.h>
18
19 #include "internals.h"
20
21 /**
22  *      irq_set_chip - set the irq chip for an irq
23  *      @irq:   irq number
24  *      @chip:  pointer to irq chip description structure
25  */
26 int irq_set_chip(unsigned int irq, struct irq_chip *chip)
27 {
28         struct irq_desc *desc = irq_to_desc(irq);
29         unsigned long flags;
30
31         if (!desc) {
32                 WARN(1, KERN_ERR "Trying to install chip for IRQ%d\n", irq);
33                 return -EINVAL;
34         }
35
36         if (!chip)
37                 chip = &no_irq_chip;
38
39         raw_spin_lock_irqsave(&desc->lock, flags);
40         irq_chip_set_defaults(chip);
41         desc->irq_data.chip = chip;
42         raw_spin_unlock_irqrestore(&desc->lock, flags);
43
44         return 0;
45 }
46 EXPORT_SYMBOL(irq_set_chip);
47
48 /**
49  *      irq_set_type - set the irq trigger type for an irq
50  *      @irq:   irq number
51  *      @type:  IRQ_TYPE_{LEVEL,EDGE}_* value - see include/linux/irq.h
52  */
53 int irq_set_irq_type(unsigned int irq, unsigned int type)
54 {
55         struct irq_desc *desc = irq_to_desc(irq);
56         unsigned long flags;
57         int ret = -ENXIO;
58
59         if (!desc) {
60                 printk(KERN_ERR "Trying to set irq type for IRQ%d\n", irq);
61                 return -ENODEV;
62         }
63
64         type &= IRQ_TYPE_SENSE_MASK;
65         if (type == IRQ_TYPE_NONE)
66                 return 0;
67
68         chip_bus_lock(desc);
69         raw_spin_lock_irqsave(&desc->lock, flags);
70         ret = __irq_set_trigger(desc, irq, type);
71         raw_spin_unlock_irqrestore(&desc->lock, flags);
72         chip_bus_sync_unlock(desc);
73         return ret;
74 }
75 EXPORT_SYMBOL(irq_set_irq_type);
76
77 /**
78  *      irq_set_handler_data - set irq handler data for an irq
79  *      @irq:   Interrupt number
80  *      @data:  Pointer to interrupt specific data
81  *
82  *      Set the hardware irq controller data for an irq
83  */
84 int irq_set_handler_data(unsigned int irq, void *data)
85 {
86         struct irq_desc *desc = irq_to_desc(irq);
87         unsigned long flags;
88
89         if (!desc) {
90                 printk(KERN_ERR
91                        "Trying to install controller data for IRQ%d\n", irq);
92                 return -EINVAL;
93         }
94
95         raw_spin_lock_irqsave(&desc->lock, flags);
96         desc->irq_data.handler_data = data;
97         raw_spin_unlock_irqrestore(&desc->lock, flags);
98         return 0;
99 }
100 EXPORT_SYMBOL(irq_set_handler_data);
101
102 /**
103  *      irq_set_msi_desc - set MSI descriptor data for an irq
104  *      @irq:   Interrupt number
105  *      @entry: Pointer to MSI descriptor data
106  *
107  *      Set the MSI descriptor entry for an irq
108  */
109 int irq_set_msi_desc(unsigned int irq, struct msi_desc *entry)
110 {
111         struct irq_desc *desc = irq_to_desc(irq);
112         unsigned long flags;
113
114         if (!desc) {
115                 printk(KERN_ERR
116                        "Trying to install msi data for IRQ%d\n", irq);
117                 return -EINVAL;
118         }
119
120         raw_spin_lock_irqsave(&desc->lock, flags);
121         desc->irq_data.msi_desc = entry;
122         if (entry)
123                 entry->irq = irq;
124         raw_spin_unlock_irqrestore(&desc->lock, flags);
125         return 0;
126 }
127
128 /**
129  *      irq_set_chip_data - set irq chip data for an irq
130  *      @irq:   Interrupt number
131  *      @data:  Pointer to chip specific data
132  *
133  *      Set the hardware irq chip data for an irq
134  */
135 int irq_set_chip_data(unsigned int irq, void *data)
136 {
137         struct irq_desc *desc = irq_to_desc(irq);
138         unsigned long flags;
139
140         if (!desc) {
141                 printk(KERN_ERR
142                        "Trying to install chip data for IRQ%d\n", irq);
143                 return -EINVAL;
144         }
145
146         if (!desc->irq_data.chip) {
147                 printk(KERN_ERR "BUG: bad set_irq_chip_data(IRQ#%d)\n", irq);
148                 return -EINVAL;
149         }
150
151         raw_spin_lock_irqsave(&desc->lock, flags);
152         desc->irq_data.chip_data = data;
153         raw_spin_unlock_irqrestore(&desc->lock, flags);
154
155         return 0;
156 }
157 EXPORT_SYMBOL(irq_set_chip_data);
158
159 struct 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 }
165 EXPORT_SYMBOL_GPL(irq_get_irq_data);
166
167 /**
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  */
178 void 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
186         raw_spin_lock_irqsave(&desc->lock, flags);
187         if (nest)
188                 desc->status |= IRQ_NESTED_THREAD;
189         else
190                 desc->status &= ~IRQ_NESTED_THREAD;
191         raw_spin_unlock_irqrestore(&desc->lock, flags);
192 }
193 EXPORT_SYMBOL_GPL(set_irq_nested_thread);
194
195 int 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
203         irq_enable(desc);
204         return 0;
205 }
206
207 void 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
214 void irq_enable(struct irq_desc *desc)
215 {
216         desc->irq_data.chip->irq_enable(&desc->irq_data);
217 }
218
219 void irq_disable(struct irq_desc *desc)
220 {
221         desc->irq_data.chip->irq_disable(&desc->irq_data);
222 }
223
224 /*
225  * default enable function
226  */
227 static void default_enable(struct irq_data *data)
228 {
229         struct irq_desc *desc = irq_data_to_desc(data);
230
231         desc->irq_data.chip->irq_unmask(&desc->irq_data);
232         desc->status &= ~IRQ_MASKED;
233 }
234
235 /*
236  * default disable function
237  */
238 static void default_disable(struct irq_data *data)
239 {
240 }
241
242 /*
243  * default shutdown function
244  */
245 static void default_shutdown(struct irq_data *data)
246 {
247         struct irq_desc *desc = irq_data_to_desc(data);
248
249         desc->irq_data.chip->irq_mask(&desc->irq_data);
250 }
251
252 #ifndef CONFIG_GENERIC_HARDIRQS_NO_DEPRECATED
253 /* Temporary migration helpers */
254 static void compat_irq_mask(struct irq_data *data)
255 {
256         data->chip->mask(data->irq);
257 }
258
259 static void compat_irq_unmask(struct irq_data *data)
260 {
261         data->chip->unmask(data->irq);
262 }
263
264 static void compat_irq_ack(struct irq_data *data)
265 {
266         data->chip->ack(data->irq);
267 }
268
269 static void compat_irq_mask_ack(struct irq_data *data)
270 {
271         data->chip->mask_ack(data->irq);
272 }
273
274 static void compat_irq_eoi(struct irq_data *data)
275 {
276         data->chip->eoi(data->irq);
277 }
278
279 static void compat_irq_enable(struct irq_data *data)
280 {
281         data->chip->enable(data->irq);
282 }
283
284 static void compat_irq_disable(struct irq_data *data)
285 {
286         data->chip->disable(data->irq);
287 }
288
289 static void compat_irq_shutdown(struct irq_data *data)
290 {
291         data->chip->shutdown(data->irq);
292 }
293
294 static unsigned int compat_irq_startup(struct irq_data *data)
295 {
296         return data->chip->startup(data->irq);
297 }
298
299 static 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
305 static int compat_irq_set_type(struct irq_data *data, unsigned int type)
306 {
307         return data->chip->set_type(data->irq, type);
308 }
309
310 static int compat_irq_set_wake(struct irq_data *data, unsigned int on)
311 {
312         return data->chip->set_wake(data->irq, on);
313 }
314
315 static int compat_irq_retrigger(struct irq_data *data)
316 {
317         return data->chip->retrigger(data->irq);
318 }
319
320 static void compat_bus_lock(struct irq_data *data)
321 {
322         data->chip->bus_lock(data->irq);
323 }
324
325 static void compat_bus_sync_unlock(struct irq_data *data)
326 {
327         data->chip->bus_sync_unlock(data->irq);
328 }
329 #endif
330
331 /*
332  * Fixup enable/disable function pointers
333  */
334 void irq_chip_set_defaults(struct irq_chip *chip)
335 {
336 #ifndef CONFIG_GENERIC_HARDIRQS_NO_DEPRECATED
337         /*
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;
343         if (chip->disable)
344                 chip->irq_disable = compat_irq_disable;
345         if (chip->shutdown)
346                 chip->irq_shutdown = compat_irq_shutdown;
347         if (chip->startup)
348                 chip->irq_startup = compat_irq_startup;
349 #endif
350         /*
351          * The real defaults
352          */
353         if (!chip->irq_enable)
354                 chip->irq_enable = default_enable;
355         if (!chip->irq_disable)
356                 chip->irq_disable = default_disable;
357         /*
358          * 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
360          * to use default_shutdown, otherwise the irq line is not
361          * disabled on free_irq():
362          */
363         if (!chip->irq_shutdown)
364                 chip->irq_shutdown = chip->irq_disable != default_disable ?
365                         chip->irq_disable : default_shutdown;
366
367 #ifndef CONFIG_GENERIC_HARDIRQS_NO_DEPRECATED
368         if (!chip->end)
369                 chip->end = dummy_irq_chip.end;
370
371         /*
372          * Now fix up the remaining compat handlers
373          */
374         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;
378         if (chip->mask)
379                 chip->irq_mask = compat_irq_mask;
380         if (chip->unmask)
381                 chip->irq_unmask = compat_irq_unmask;
382         if (chip->ack)
383                 chip->irq_ack = compat_irq_ack;
384         if (chip->mask_ack)
385                 chip->irq_mask_ack = compat_irq_mask_ack;
386         if (chip->eoi)
387                 chip->irq_eoi = compat_irq_eoi;
388         if (chip->set_affinity)
389                 chip->irq_set_affinity = compat_irq_set_affinity;
390         if (chip->set_type)
391                 chip->irq_set_type = compat_irq_set_type;
392         if (chip->set_wake)
393                 chip->irq_set_wake = compat_irq_set_wake;
394         if (chip->retrigger)
395                 chip->irq_retrigger = compat_irq_retrigger;
396 #endif
397 }
398
399 static inline void mask_ack_irq(struct irq_desc *desc)
400 {
401         if (desc->irq_data.chip->irq_mask_ack)
402                 desc->irq_data.chip->irq_mask_ack(&desc->irq_data);
403         else {
404                 desc->irq_data.chip->irq_mask(&desc->irq_data);
405                 if (desc->irq_data.chip->irq_ack)
406                         desc->irq_data.chip->irq_ack(&desc->irq_data);
407         }
408         desc->status |= IRQ_MASKED;
409 }
410
411 static inline void mask_irq(struct irq_desc *desc)
412 {
413         if (desc->irq_data.chip->irq_mask) {
414                 desc->irq_data.chip->irq_mask(&desc->irq_data);
415                 desc->status |= IRQ_MASKED;
416         }
417 }
418
419 static inline void unmask_irq(struct irq_desc *desc)
420 {
421         if (desc->irq_data.chip->irq_unmask) {
422                 desc->irq_data.chip->irq_unmask(&desc->irq_data);
423                 desc->status &= ~IRQ_MASKED;
424         }
425 }
426
427 /*
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  */
435 void 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
443         raw_spin_lock_irq(&desc->lock);
444
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;
452         raw_spin_unlock_irq(&desc->lock);
453
454         action_ret = action->thread_fn(action->irq, action->dev_id);
455         if (!noirqdebug)
456                 note_interrupt(irq, desc, action_ret);
457
458         raw_spin_lock_irq(&desc->lock);
459         desc->status &= ~IRQ_INPROGRESS;
460
461 out_unlock:
462         raw_spin_unlock_irq(&desc->lock);
463 }
464 EXPORT_SYMBOL_GPL(handle_nested_irq);
465
466 static 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
473 /**
474  *      handle_simple_irq - Simple and software-decoded IRQs.
475  *      @irq:   the interrupt number
476  *      @desc:  the interrupt description structure for this irq
477  *
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  */
485 void
486 handle_simple_irq(unsigned int irq, struct irq_desc *desc)
487 {
488         struct irqaction *action;
489         irqreturn_t action_ret;
490
491         raw_spin_lock(&desc->lock);
492
493         if (unlikely(desc->status & IRQ_INPROGRESS))
494                 if (!irq_check_poll(desc))
495                         goto out_unlock;
496
497         desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
498         kstat_incr_irqs_this_cpu(irq, desc);
499
500         action = desc->action;
501         if (unlikely(!action || (desc->status & IRQ_DISABLED)))
502                 goto out_unlock;
503
504         desc->status |= IRQ_INPROGRESS;
505         raw_spin_unlock(&desc->lock);
506
507         action_ret = handle_IRQ_event(irq, action);
508         if (!noirqdebug)
509                 note_interrupt(irq, desc, action_ret);
510
511         raw_spin_lock(&desc->lock);
512         desc->status &= ~IRQ_INPROGRESS;
513 out_unlock:
514         raw_spin_unlock(&desc->lock);
515 }
516
517 /**
518  *      handle_level_irq - Level type irq handler
519  *      @irq:   the interrupt number
520  *      @desc:  the interrupt description structure for this irq
521  *
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  */
527 void
528 handle_level_irq(unsigned int irq, struct irq_desc *desc)
529 {
530         struct irqaction *action;
531         irqreturn_t action_ret;
532
533         raw_spin_lock(&desc->lock);
534         mask_ack_irq(desc);
535
536         if (unlikely(desc->status & IRQ_INPROGRESS))
537                 if (!irq_check_poll(desc))
538                         goto out_unlock;
539
540         desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
541         kstat_incr_irqs_this_cpu(irq, desc);
542
543         /*
544          * If its disabled or no action available
545          * keep it masked and get out of here
546          */
547         action = desc->action;
548         if (unlikely(!action || (desc->status & IRQ_DISABLED)))
549                 goto out_unlock;
550
551         desc->status |= IRQ_INPROGRESS;
552         raw_spin_unlock(&desc->lock);
553
554         action_ret = handle_IRQ_event(irq, action);
555         if (!noirqdebug)
556                 note_interrupt(irq, desc, action_ret);
557
558         raw_spin_lock(&desc->lock);
559         desc->status &= ~IRQ_INPROGRESS;
560
561         if (!(desc->status & (IRQ_DISABLED | IRQ_ONESHOT)))
562                 unmask_irq(desc);
563 out_unlock:
564         raw_spin_unlock(&desc->lock);
565 }
566 EXPORT_SYMBOL_GPL(handle_level_irq);
567
568 /**
569  *      handle_fasteoi_irq - irq handler for transparent controllers
570  *      @irq:   the interrupt number
571  *      @desc:  the interrupt description structure for this irq
572  *
573  *      Only a single callback will be issued to the chip: an ->eoi()
574  *      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  */
578 void
579 handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc)
580 {
581         struct irqaction *action;
582         irqreturn_t action_ret;
583
584         raw_spin_lock(&desc->lock);
585
586         if (unlikely(desc->status & IRQ_INPROGRESS))
587                 if (!irq_check_poll(desc))
588                         goto out;
589
590         desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
591         kstat_incr_irqs_this_cpu(irq, desc);
592
593         /*
594          * If its disabled or no action available
595          * then mask it and get out of here:
596          */
597         action = desc->action;
598         if (unlikely(!action || (desc->status & IRQ_DISABLED))) {
599                 desc->status |= IRQ_PENDING;
600                 mask_irq(desc);
601                 goto out;
602         }
603
604         desc->status |= IRQ_INPROGRESS;
605         desc->status &= ~IRQ_PENDING;
606         raw_spin_unlock(&desc->lock);
607
608         action_ret = handle_IRQ_event(irq, action);
609         if (!noirqdebug)
610                 note_interrupt(irq, desc, action_ret);
611
612         raw_spin_lock(&desc->lock);
613         desc->status &= ~IRQ_INPROGRESS;
614 out:
615         desc->irq_data.chip->irq_eoi(&desc->irq_data);
616
617         raw_spin_unlock(&desc->lock);
618 }
619
620 /**
621  *      handle_edge_irq - edge type IRQ handler
622  *      @irq:   the interrupt number
623  *      @desc:  the interrupt description structure for this irq
624  *
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
629  *      is handled by the associated event handler. If this happens it
630  *      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  */
636 void
637 handle_edge_irq(unsigned int irq, struct irq_desc *desc)
638 {
639         raw_spin_lock(&desc->lock);
640
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)) {
650                 if (!irq_check_poll(desc)) {
651                         desc->status |= (IRQ_PENDING | IRQ_MASKED);
652                         mask_ack_irq(desc);
653                         goto out_unlock;
654                 }
655         }
656         kstat_incr_irqs_this_cpu(irq, desc);
657
658         /* Start handling the irq */
659         desc->irq_data.chip->irq_ack(&desc->irq_data);
660
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)) {
669                         mask_irq(desc);
670                         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))) {
681                         unmask_irq(desc);
682                 }
683
684                 desc->status &= ~IRQ_PENDING;
685                 raw_spin_unlock(&desc->lock);
686                 action_ret = handle_IRQ_event(irq, action);
687                 if (!noirqdebug)
688                         note_interrupt(irq, desc, action_ret);
689                 raw_spin_lock(&desc->lock);
690
691         } while ((desc->status & (IRQ_PENDING | IRQ_DISABLED)) == IRQ_PENDING);
692
693         desc->status &= ~IRQ_INPROGRESS;
694 out_unlock:
695         raw_spin_unlock(&desc->lock);
696 }
697
698 /**
699  *      handle_percpu_irq - Per CPU local irq handler
700  *      @irq:   the interrupt number
701  *      @desc:  the interrupt description structure for this irq
702  *
703  *      Per CPU interrupts on SMP machines without locking requirements
704  */
705 void
706 handle_percpu_irq(unsigned int irq, struct irq_desc *desc)
707 {
708         irqreturn_t action_ret;
709
710         kstat_incr_irqs_this_cpu(irq, desc);
711
712         if (desc->irq_data.chip->irq_ack)
713                 desc->irq_data.chip->irq_ack(&desc->irq_data);
714
715         action_ret = handle_IRQ_event(irq, desc->action);
716         if (!noirqdebug)
717                 note_interrupt(irq, desc, action_ret);
718
719         if (desc->irq_data.chip->irq_eoi)
720                 desc->irq_data.chip->irq_eoi(&desc->irq_data);
721 }
722
723 void
724 __set_irq_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
725                   const char *name)
726 {
727         struct irq_desc *desc = irq_to_desc(irq);
728         unsigned long flags;
729
730         if (!desc) {
731                 printk(KERN_ERR
732                        "Trying to install type control for IRQ%d\n", irq);
733                 return;
734         }
735
736         if (!handle)
737                 handle = handle_bad_irq;
738         else if (desc->irq_data.chip == &no_irq_chip) {
739                 printk(KERN_WARNING "Trying to install %sinterrupt handler "
740                        "for IRQ%d\n", is_chained ? "chained " : "", irq);
741                 /*
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                  */
748                 desc->irq_data.chip = &dummy_irq_chip;
749         }
750
751         chip_bus_lock(desc);
752         raw_spin_lock_irqsave(&desc->lock, flags);
753
754         /* Uninstall? */
755         if (handle == handle_bad_irq) {
756                 if (desc->irq_data.chip != &no_irq_chip)
757                         mask_ack_irq(desc);
758                 desc->status |= IRQ_DISABLED;
759                 desc->depth = 1;
760         }
761         desc->handle_irq = handle;
762         desc->name = name;
763
764         if (handle != handle_bad_irq && is_chained) {
765                 desc->status |= IRQ_NOREQUEST | IRQ_NOPROBE;
766                 irq_startup(desc);
767         }
768         raw_spin_unlock_irqrestore(&desc->lock, flags);
769         chip_bus_sync_unlock(desc);
770 }
771 EXPORT_SYMBOL_GPL(__set_irq_handler);
772
773 void
774 set_irq_chip_and_handler(unsigned int irq, struct irq_chip *chip,
775                          irq_flow_handler_t handle)
776 {
777         set_irq_chip(irq, chip);
778         __set_irq_handler(irq, handle, 0, NULL);
779 }
780
781 void
782 set_irq_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
783                               irq_flow_handler_t handle, const char *name)
784 {
785         set_irq_chip(irq, chip);
786         __set_irq_handler(irq, handle, 0, name);
787 }
788
789 void irq_modify_status(unsigned int irq, unsigned long clr, unsigned long set)
790 {
791         struct irq_desc *desc = irq_to_desc(irq);
792         unsigned long flags;
793
794         if (!desc)
795                 return;
796
797         /* Sanitize flags */
798         set &= IRQF_MODIFY_MASK;
799         clr &= IRQF_MODIFY_MASK;
800
801         raw_spin_lock_irqsave(&desc->lock, flags);
802         desc->status &= ~clr;
803         desc->status |= set;
804         raw_spin_unlock_irqrestore(&desc->lock, flags);
805 }