aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/irq/manage.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/irq/manage.c')
-rw-r--r--kernel/irq/manage.c202
1 files changed, 110 insertions, 92 deletions
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index cd0cd8dcb345..ea119effe096 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -15,17 +15,9 @@
15 15
16#include "internals.h" 16#include "internals.h"
17 17
18#ifdef CONFIG_SMP 18#if defined(CONFIG_SMP) && defined(CONFIG_GENERIC_HARDIRQS)
19cpumask_var_t irq_default_affinity; 19cpumask_var_t irq_default_affinity;
20 20
21static int init_irq_default_affinity(void)
22{
23 alloc_cpumask_var(&irq_default_affinity, GFP_KERNEL);
24 cpumask_setall(irq_default_affinity);
25 return 0;
26}
27core_initcall(init_irq_default_affinity);
28
29/** 21/**
30 * synchronize_irq - wait for pending IRQ handlers (on other CPUs) 22 * synchronize_irq - wait for pending IRQ handlers (on other CPUs)
31 * @irq: interrupt number to wait for 23 * @irq: interrupt number to wait for
@@ -117,7 +109,7 @@ int irq_set_affinity(unsigned int irq, const struct cpumask *cpumask)
117/* 109/*
118 * Generic version of the affinity autoselector. 110 * Generic version of the affinity autoselector.
119 */ 111 */
120int do_irq_select_affinity(unsigned int irq, struct irq_desc *desc) 112static int setup_affinity(unsigned int irq, struct irq_desc *desc)
121{ 113{
122 if (!irq_can_set_affinity(irq)) 114 if (!irq_can_set_affinity(irq))
123 return 0; 115 return 0;
@@ -141,7 +133,7 @@ set_affinity:
141 return 0; 133 return 0;
142} 134}
143#else 135#else
144static inline int do_irq_select_affinity(unsigned int irq, struct irq_desc *d) 136static inline int setup_affinity(unsigned int irq, struct irq_desc *d)
145{ 137{
146 return irq_select_affinity(irq); 138 return irq_select_affinity(irq);
147} 139}
@@ -157,14 +149,14 @@ int irq_select_affinity_usr(unsigned int irq)
157 int ret; 149 int ret;
158 150
159 spin_lock_irqsave(&desc->lock, flags); 151 spin_lock_irqsave(&desc->lock, flags);
160 ret = do_irq_select_affinity(irq, desc); 152 ret = setup_affinity(irq, desc);
161 spin_unlock_irqrestore(&desc->lock, flags); 153 spin_unlock_irqrestore(&desc->lock, flags);
162 154
163 return ret; 155 return ret;
164} 156}
165 157
166#else 158#else
167static inline int do_irq_select_affinity(int irq, struct irq_desc *desc) 159static inline int setup_affinity(unsigned int irq, struct irq_desc *desc)
168{ 160{
169 return 0; 161 return 0;
170} 162}
@@ -397,9 +389,9 @@ int __irq_set_trigger(struct irq_desc *desc, unsigned int irq,
397 * allocate special interrupts that are part of the architecture. 389 * allocate special interrupts that are part of the architecture.
398 */ 390 */
399static int 391static int
400__setup_irq(unsigned int irq, struct irq_desc * desc, struct irqaction *new) 392__setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
401{ 393{
402 struct irqaction *old, **p; 394 struct irqaction *old, **old_ptr;
403 const char *old_name = NULL; 395 const char *old_name = NULL;
404 unsigned long flags; 396 unsigned long flags;
405 int shared = 0; 397 int shared = 0;
@@ -431,8 +423,8 @@ __setup_irq(unsigned int irq, struct irq_desc * desc, struct irqaction *new)
431 * The following block of code has to be executed atomically 423 * The following block of code has to be executed atomically
432 */ 424 */
433 spin_lock_irqsave(&desc->lock, flags); 425 spin_lock_irqsave(&desc->lock, flags);
434 p = &desc->action; 426 old_ptr = &desc->action;
435 old = *p; 427 old = *old_ptr;
436 if (old) { 428 if (old) {
437 /* 429 /*
438 * Can't share interrupts unless both agree to and are 430 * Can't share interrupts unless both agree to and are
@@ -455,8 +447,8 @@ __setup_irq(unsigned int irq, struct irq_desc * desc, struct irqaction *new)
455 447
456 /* add new interrupt at end of irq queue */ 448 /* add new interrupt at end of irq queue */
457 do { 449 do {
458 p = &old->next; 450 old_ptr = &old->next;
459 old = *p; 451 old = *old_ptr;
460 } while (old); 452 } while (old);
461 shared = 1; 453 shared = 1;
462 } 454 }
@@ -496,7 +488,7 @@ __setup_irq(unsigned int irq, struct irq_desc * desc, struct irqaction *new)
496 desc->status |= IRQ_NO_BALANCING; 488 desc->status |= IRQ_NO_BALANCING;
497 489
498 /* Set default affinity mask once everything is setup */ 490 /* Set default affinity mask once everything is setup */
499 do_irq_select_affinity(irq, desc); 491 setup_affinity(irq, desc);
500 492
501 } else if ((new->flags & IRQF_TRIGGER_MASK) 493 } else if ((new->flags & IRQF_TRIGGER_MASK)
502 && (new->flags & IRQF_TRIGGER_MASK) 494 && (new->flags & IRQF_TRIGGER_MASK)
@@ -507,7 +499,7 @@ __setup_irq(unsigned int irq, struct irq_desc * desc, struct irqaction *new)
507 (int)(new->flags & IRQF_TRIGGER_MASK)); 499 (int)(new->flags & IRQF_TRIGGER_MASK));
508 } 500 }
509 501
510 *p = new; 502 *old_ptr = new;
511 503
512 /* Reset broken irq detection when installing new handler */ 504 /* Reset broken irq detection when installing new handler */
513 desc->irq_count = 0; 505 desc->irq_count = 0;
@@ -557,90 +549,117 @@ int setup_irq(unsigned int irq, struct irqaction *act)
557 549
558 return __setup_irq(irq, desc, act); 550 return __setup_irq(irq, desc, act);
559} 551}
552EXPORT_SYMBOL_GPL(setup_irq);
560 553
561/** 554 /*
562 * free_irq - free an interrupt 555 * Internal function to unregister an irqaction - used to free
563 * @irq: Interrupt line to free 556 * regular and special interrupts that are part of the architecture.
564 * @dev_id: Device identity to free
565 *
566 * Remove an interrupt handler. The handler is removed and if the
567 * interrupt line is no longer in use by any driver it is disabled.
568 * On a shared IRQ the caller must ensure the interrupt is disabled
569 * on the card it drives before calling this function. The function
570 * does not return until any executing interrupts for this IRQ
571 * have completed.
572 *
573 * This function must not be called from interrupt context.
574 */ 557 */
575void free_irq(unsigned int irq, void *dev_id) 558static struct irqaction *__free_irq(unsigned int irq, void *dev_id)
576{ 559{
577 struct irq_desc *desc = irq_to_desc(irq); 560 struct irq_desc *desc = irq_to_desc(irq);
578 struct irqaction **p; 561 struct irqaction *action, **action_ptr;
579 unsigned long flags; 562 unsigned long flags;
580 563
581 WARN_ON(in_interrupt()); 564 WARN(in_interrupt(), "Trying to free IRQ %d from IRQ context!\n", irq);
582 565
583 if (!desc) 566 if (!desc)
584 return; 567 return NULL;
585 568
586 spin_lock_irqsave(&desc->lock, flags); 569 spin_lock_irqsave(&desc->lock, flags);
587 p = &desc->action; 570
571 /*
572 * There can be multiple actions per IRQ descriptor, find the right
573 * one based on the dev_id:
574 */
575 action_ptr = &desc->action;
588 for (;;) { 576 for (;;) {
589 struct irqaction *action = *p; 577 action = *action_ptr;
590 578
591 if (action) { 579 if (!action) {
592 struct irqaction **pp = p; 580 WARN(1, "Trying to free already-free IRQ %d\n", irq);
581 spin_unlock_irqrestore(&desc->lock, flags);
593 582
594 p = &action->next; 583 return NULL;
595 if (action->dev_id != dev_id) 584 }
596 continue;
597 585
598 /* Found it - now remove it from the list of entries */ 586 if (action->dev_id == dev_id)
599 *pp = action->next; 587 break;
588 action_ptr = &action->next;
589 }
590
591 /* Found it - now remove it from the list of entries: */
592 *action_ptr = action->next;
600 593
601 /* Currently used only by UML, might disappear one day.*/ 594 /* Currently used only by UML, might disappear one day: */
602#ifdef CONFIG_IRQ_RELEASE_METHOD 595#ifdef CONFIG_IRQ_RELEASE_METHOD
603 if (desc->chip->release) 596 if (desc->chip->release)
604 desc->chip->release(irq, dev_id); 597 desc->chip->release(irq, dev_id);
605#endif 598#endif
606 599
607 if (!desc->action) { 600 /* If this was the last handler, shut down the IRQ line: */
608 desc->status |= IRQ_DISABLED; 601 if (!desc->action) {
609 if (desc->chip->shutdown) 602 desc->status |= IRQ_DISABLED;
610 desc->chip->shutdown(irq); 603 if (desc->chip->shutdown)
611 else 604 desc->chip->shutdown(irq);
612 desc->chip->disable(irq); 605 else
613 } 606 desc->chip->disable(irq);
614 spin_unlock_irqrestore(&desc->lock, flags); 607 }
615 unregister_handler_proc(irq, action); 608 spin_unlock_irqrestore(&desc->lock, flags);
609
610 unregister_handler_proc(irq, action);
611
612 /* Make sure it's not being used on another CPU: */
613 synchronize_irq(irq);
616 614
617 /* Make sure it's not being used on another CPU */
618 synchronize_irq(irq);
619#ifdef CONFIG_DEBUG_SHIRQ
620 /*
621 * It's a shared IRQ -- the driver ought to be
622 * prepared for it to happen even now it's
623 * being freed, so let's make sure.... We do
624 * this after actually deregistering it, to
625 * make sure that a 'real' IRQ doesn't run in
626 * parallel with our fake
627 */
628 if (action->flags & IRQF_SHARED) {
629 local_irq_save(flags);
630 action->handler(irq, dev_id);
631 local_irq_restore(flags);
632 }
633#endif
634 kfree(action);
635 return;
636 }
637 printk(KERN_ERR "Trying to free already-free IRQ %d\n", irq);
638#ifdef CONFIG_DEBUG_SHIRQ 615#ifdef CONFIG_DEBUG_SHIRQ
639 dump_stack(); 616 /*
640#endif 617 * It's a shared IRQ -- the driver ought to be prepared for an IRQ
641 spin_unlock_irqrestore(&desc->lock, flags); 618 * event to happen even now it's being freed, so let's make sure that
642 return; 619 * is so by doing an extra call to the handler ....
620 *
621 * ( We do this after actually deregistering it, to make sure that a
622 * 'real' IRQ doesn't run in * parallel with our fake. )
623 */
624 if (action->flags & IRQF_SHARED) {
625 local_irq_save(flags);
626 action->handler(irq, dev_id);
627 local_irq_restore(flags);
643 } 628 }
629#endif
630 return action;
631}
632
633/**
634 * remove_irq - free an interrupt
635 * @irq: Interrupt line to free
636 * @act: irqaction for the interrupt
637 *
638 * Used to remove interrupts statically setup by the early boot process.
639 */
640void remove_irq(unsigned int irq, struct irqaction *act)
641{
642 __free_irq(irq, act->dev_id);
643}
644EXPORT_SYMBOL_GPL(remove_irq);
645
646/**
647 * free_irq - free an interrupt allocated with request_irq
648 * @irq: Interrupt line to free
649 * @dev_id: Device identity to free
650 *
651 * Remove an interrupt handler. The handler is removed and if the
652 * interrupt line is no longer in use by any driver it is disabled.
653 * On a shared IRQ the caller must ensure the interrupt is disabled
654 * on the card it drives before calling this function. The function
655 * does not return until any executing interrupts for this IRQ
656 * have completed.
657 *
658 * This function must not be called from interrupt context.
659 */
660void free_irq(unsigned int irq, void *dev_id)
661{
662 kfree(__free_irq(irq, dev_id));
644} 663}
645EXPORT_SYMBOL(free_irq); 664EXPORT_SYMBOL(free_irq);
646 665
@@ -687,11 +706,12 @@ int request_irq(unsigned int irq, irq_handler_t handler,
687 * the behavior is classified as "will not fix" so we need to 706 * the behavior is classified as "will not fix" so we need to
688 * start nudging drivers away from using that idiom. 707 * start nudging drivers away from using that idiom.
689 */ 708 */
690 if ((irqflags & (IRQF_SHARED|IRQF_DISABLED)) 709 if ((irqflags & (IRQF_SHARED|IRQF_DISABLED)) ==
691 == (IRQF_SHARED|IRQF_DISABLED)) 710 (IRQF_SHARED|IRQF_DISABLED)) {
692 pr_warning("IRQ %d/%s: IRQF_DISABLED is not " 711 pr_warning(
693 "guaranteed on shared IRQs\n", 712 "IRQ %d/%s: IRQF_DISABLED is not guaranteed on shared IRQs\n",
694 irq, devname); 713 irq, devname);
714 }
695 715
696#ifdef CONFIG_LOCKDEP 716#ifdef CONFIG_LOCKDEP
697 /* 717 /*
@@ -717,15 +737,13 @@ int request_irq(unsigned int irq, irq_handler_t handler,
717 if (!handler) 737 if (!handler)
718 return -EINVAL; 738 return -EINVAL;
719 739
720 action = kmalloc(sizeof(struct irqaction), GFP_ATOMIC); 740 action = kzalloc(sizeof(struct irqaction), GFP_KERNEL);
721 if (!action) 741 if (!action)
722 return -ENOMEM; 742 return -ENOMEM;
723 743
724 action->handler = handler; 744 action->handler = handler;
725 action->flags = irqflags; 745 action->flags = irqflags;
726 cpus_clear(action->mask);
727 action->name = devname; 746 action->name = devname;
728 action->next = NULL;
729 action->dev_id = dev_id; 747 action->dev_id = dev_id;
730 748
731 retval = __setup_irq(irq, desc, action); 749 retval = __setup_irq(irq, desc, action);