2 * linux/arch/ia64/kernel/irq.c
4 * Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar
6 * This file contains the code used by various IRQ handling routines:
7 * asking for different IRQ's should be done through these routines
8 * instead of just grabbing them. Thus setups with different IRQ numbers
9 * shouldn't result in any weird surprises, and installing new handlers
12 * Copyright (C) Ashok Raj<ashok.raj@intel.com>, Intel Corporation 2004
14 * 4/14/2004: Added code to handle cpu migration and do safe irq
15 * migration without lossing interrupts for iosapic
20 * (mostly architecture independent, will move to kernel/irq.c in 2.5.)
22 * IRQs are in fact implemented a bit like signal handlers for the kernel.
23 * Naturally it's not a 1:1 relation, but there are similarities.
26 #include <linux/config.h>
27 #include <linux/errno.h>
28 #include <linux/module.h>
29 #include <linux/signal.h>
30 #include <linux/sched.h>
31 #include <linux/ioport.h>
32 #include <linux/interrupt.h>
33 #include <linux/timex.h>
34 #include <linux/slab.h>
35 #include <linux/random.h>
36 #include <linux/cpu.h>
37 #include <linux/ctype.h>
38 #include <linux/smp_lock.h>
39 #include <linux/init.h>
40 #include <linux/kernel_stat.h>
41 #include <linux/irq.h>
42 #include <linux/proc_fs.h>
43 #include <linux/seq_file.h>
44 #include <linux/kallsyms.h>
45 #include <linux/notifier.h>
47 #include <asm/atomic.h>
51 #include <asm/system.h>
52 #include <asm/bitops.h>
53 #include <asm/uaccess.h>
54 #include <asm/pgalloc.h>
55 #include <asm/tlbflush.h>
56 #include <asm/delay.h>
61 * Linux has a controller-independent x86 interrupt architecture.
62 * every controller has a 'controller-template', that is used
63 * by the main code to do the right thing. Each driver-visible
64 * interrupt source is transparently wired to the appropriate
65 * controller. Thus drivers need not be aware of the
66 * interrupt-controller.
68 * Various interrupt controllers we handle: 8259 PIC, SMP IO-APIC,
69 * PIIX4's internal 8259 PIC and SGI's Visual Workstation Cobalt (IO-)APIC.
70 * (IO-APICs assumed to be messaging to Pentium local-APICs)
72 * the code is designed to be easily extended with new/different
73 * interrupt controllers, without having to do assembly magic.
77 * Controller mappings for all interrupt sources:
79 irq_desc_t _irq_desc[NR_IRQS] __cacheline_aligned = {
81 .status = IRQ_DISABLED,
82 .handler = &no_irq_type,
83 .lock = SPIN_LOCK_UNLOCKED
89 * This is updated when the user sets irq affinity via /proc
91 cpumask_t __cacheline_aligned pending_irq_cpumask[NR_IRQS];
92 static unsigned long pending_irq_redir[BITS_TO_LONGS(NR_IRQS)];
95 #ifdef CONFIG_IA64_GENERIC
96 irq_desc_t * __ia64_irq_desc (unsigned int irq)
98 return _irq_desc + irq;
101 ia64_vector __ia64_irq_to_vector (unsigned int irq)
103 return (ia64_vector) irq;
106 unsigned int __ia64_local_vector_to_irq (ia64_vector vec)
108 return (unsigned int) vec;
112 static void register_irq_proc (unsigned int irq);
115 * Special irq handlers.
118 irqreturn_t no_action(int cpl, void *dev_id, struct pt_regs *regs)
122 * Generic no controller code
125 static void enable_none(unsigned int irq) { }
126 static unsigned int startup_none(unsigned int irq) { return 0; }
127 static void disable_none(unsigned int irq) { }
128 static void ack_none(unsigned int irq)
131 * 'what should we do if we get a hw irq event on an illegal vector'.
132 * each architecture has to answer this themselves, it doesn't deserve
133 * a generic callback i think.
136 printk(KERN_ERR "unexpected IRQ trap at vector %02x\n", irq);
137 #ifdef CONFIG_X86_LOCAL_APIC
139 * Currently unexpected vectors happen only on SMP and APIC.
140 * We _must_ ack these because every local APIC has only N
141 * irq slots per priority level, and a 'hanging, unacked' IRQ
142 * holds up an irq slot - in excessive cases (when multiple
143 * unexpected vectors occur) that might lock up the APIC
150 printk(KERN_ERR "Unexpected irq vector 0x%x on CPU %u!\n", irq, smp_processor_id());
154 /* startup is the same as "enable", shutdown is same as "disable" */
155 #define shutdown_none disable_none
156 #define end_none enable_none
158 struct hw_interrupt_type no_irq_type = {
168 atomic_t irq_err_count;
169 #ifdef CONFIG_X86_IO_APIC
170 #ifdef APIC_MISMATCH_DEBUG
171 atomic_t irq_mis_count;
176 * Generic, controller-independent functions:
179 int show_interrupts(struct seq_file *p, void *v)
181 int j, i = *(loff_t *) v;
182 struct irqaction * action;
188 for (j=0; j<NR_CPUS; j++)
190 seq_printf(p, "CPU%d ",j);
195 idesc = irq_descp(i);
196 spin_lock_irqsave(&idesc->lock, flags);
197 action = idesc->action;
200 seq_printf(p, "%3d: ",i);
202 seq_printf(p, "%10u ", kstat_irqs(i));
204 for (j = 0; j < NR_CPUS; j++)
206 seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
208 seq_printf(p, " %14s", idesc->handler->typename);
209 seq_printf(p, " %s", action->name);
211 for (action=action->next; action; action = action->next)
212 seq_printf(p, ", %s", action->name);
216 spin_unlock_irqrestore(&idesc->lock, flags);
217 } else if (i == NR_IRQS) {
218 seq_puts(p, "NMI: ");
219 for (j = 0; j < NR_CPUS; j++)
221 seq_printf(p, "%10u ", nmi_count(j));
223 #ifdef CONFIG_X86_LOCAL_APIC
224 seq_puts(p, "LOC: ");
225 for (j = 0; j < NR_CPUS; j++)
227 seq_printf(p, "%10u ", irq_stat[j].apic_timer_irqs);
230 seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
231 #ifdef CONFIG_X86_IO_APIC
232 #ifdef APIC_MISMATCH_DEBUG
233 seq_printf(p, "MIS: %10u\n", atomic_read(&irq_mis_count));
241 inline void synchronize_irq(unsigned int irq)
243 while (irq_descp(irq)->status & IRQ_INPROGRESS)
246 EXPORT_SYMBOL(synchronize_irq);
250 * This should really return information about whether
251 * we should do bottom half handling etc. Right now we
252 * end up _always_ checking the bottom half, which is a
253 * waste of time and is not what some drivers would
256 int handle_IRQ_event(unsigned int irq,
257 struct pt_regs *regs, struct irqaction *action)
259 int status = 1; /* Force the "do bottom halves" bit */
262 if (!(action->flags & SA_INTERRUPT))
266 ret = action->handler(irq, action->dev_id, regs);
267 if (ret == IRQ_HANDLED)
268 status |= action->flags;
270 action = action->next;
272 if (status & SA_SAMPLE_RANDOM)
273 add_interrupt_randomness(irq);
278 static void __report_bad_irq(int irq, irq_desc_t *desc, irqreturn_t action_ret)
280 struct irqaction *action;
282 if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
283 printk(KERN_ERR "irq event %d: bogus return value %x\n",
286 printk(KERN_ERR "irq %d: nobody cared!\n", irq);
289 printk(KERN_ERR "handlers:\n");
290 action = desc->action;
292 printk(KERN_ERR "[<%p>]", action->handler);
293 print_symbol(" (%s)",
294 (unsigned long)action->handler);
296 action = action->next;
300 static void report_bad_irq(int irq, irq_desc_t *desc, irqreturn_t action_ret)
302 static int count = 100;
306 __report_bad_irq(irq, desc, action_ret);
310 static int noirqdebug;
312 static int __init noirqdebug_setup(char *str)
315 printk("IRQ lockup detection disabled\n");
319 __setup("noirqdebug", noirqdebug_setup);
322 * If 99,900 of the previous 100,000 interrupts have not been handled then
323 * assume that the IRQ is stuck in some manner. Drop a diagnostic and try to
326 * (The other 100-of-100,000 interrupts may have been a correctly-functioning
327 * device sharing an IRQ with the failing one)
329 * Called under desc->lock
331 static void note_interrupt(int irq, irq_desc_t *desc, irqreturn_t action_ret)
333 if (action_ret != IRQ_HANDLED) {
334 desc->irqs_unhandled++;
335 if (action_ret != IRQ_NONE)
336 report_bad_irq(irq, desc, action_ret);
340 if (desc->irq_count < 100000)
344 if (desc->irqs_unhandled > 99900) {
346 * The interrupt is stuck
348 __report_bad_irq(irq, desc, action_ret);
352 printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
353 desc->status |= IRQ_DISABLED;
354 desc->handler->disable(irq);
356 desc->irqs_unhandled = 0;
360 * Generic enable/disable code: this just calls
361 * down into the PIC-specific version for the actual
362 * hardware disable after having gotten the irq
367 * disable_irq_nosync - disable an irq without waiting
368 * @irq: Interrupt to disable
370 * Disable the selected interrupt line. Disables and Enables are
372 * Unlike disable_irq(), this function does not ensure existing
373 * instances of the IRQ handler have completed before returning.
375 * This function may be called from IRQ context.
378 inline void disable_irq_nosync(unsigned int irq)
380 irq_desc_t *desc = irq_descp(irq);
383 spin_lock_irqsave(&desc->lock, flags);
384 if (!desc->depth++) {
385 desc->status |= IRQ_DISABLED;
386 desc->handler->disable(irq);
388 spin_unlock_irqrestore(&desc->lock, flags);
390 EXPORT_SYMBOL(disable_irq_nosync);
393 * disable_irq - disable an irq and wait for completion
394 * @irq: Interrupt to disable
396 * Disable the selected interrupt line. Enables and Disables are
398 * This function waits for any pending IRQ handlers for this interrupt
399 * to complete before returning. If you use this function while
400 * holding a resource the IRQ handler may need you will deadlock.
402 * This function may be called - with care - from IRQ context.
405 void disable_irq(unsigned int irq)
407 irq_desc_t *desc = irq_descp(irq);
409 disable_irq_nosync(irq);
411 synchronize_irq(irq);
413 EXPORT_SYMBOL(disable_irq);
416 * enable_irq - enable handling of an irq
417 * @irq: Interrupt to enable
419 * Undoes the effect of one call to disable_irq(). If this
420 * matches the last disable, processing of interrupts on this
421 * IRQ line is re-enabled.
423 * This function may be called from IRQ context.
426 void enable_irq(unsigned int irq)
428 irq_desc_t *desc = irq_descp(irq);
431 spin_lock_irqsave(&desc->lock, flags);
432 switch (desc->depth) {
434 unsigned int status = desc->status & ~IRQ_DISABLED;
435 desc->status = status;
436 if ((status & (IRQ_PENDING | IRQ_REPLAY)) == IRQ_PENDING) {
437 desc->status = status | IRQ_REPLAY;
438 hw_resend_irq(desc->handler,irq);
440 desc->handler->enable(irq);
447 printk(KERN_ERR "enable_irq(%u) unbalanced from %p\n",
448 irq, (void *) __builtin_return_address(0));
450 spin_unlock_irqrestore(&desc->lock, flags);
452 EXPORT_SYMBOL(enable_irq);
455 * do_IRQ handles all normal device IRQ's (the special
456 * SMP cross-CPU interrupts have their own specific
459 unsigned int do_IRQ(unsigned long irq, struct pt_regs *regs)
462 * We ack quickly, we don't want the irq controller
463 * thinking we're snobs just because some other CPU has
464 * disabled global interrupts (we have already done the
465 * INT_ACK cycles, it's too late to try to pretend to the
466 * controller that we aren't taking the interrupt).
468 * 0 return value means that this irq is already being
469 * handled by some other CPU. (or is disabled)
471 irq_desc_t *desc = irq_descp(irq);
472 struct irqaction * action;
473 irqreturn_t action_ret;
477 cpu = smp_processor_id(); /* for CONFIG_PREEMPT, this must come after irq_enter()! */
479 kstat_cpu(cpu).irqs[irq]++;
481 if (desc->status & IRQ_PER_CPU) {
482 /* no locking required for CPU-local interrupts: */
483 desc->handler->ack(irq);
484 action_ret = handle_IRQ_event(irq, regs, desc->action);
485 desc->handler->end(irq);
487 spin_lock(&desc->lock);
488 desc->handler->ack(irq);
490 * REPLAY is when Linux resends an IRQ that was dropped earlier
491 * WAITING is used by probe to mark irqs that are being tested
493 status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
494 status |= IRQ_PENDING; /* we _want_ to handle it */
497 * If the IRQ is disabled for whatever reason, we cannot
498 * use the action we have.
501 if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
502 action = desc->action;
503 status &= ~IRQ_PENDING; /* we commit to handling */
504 status |= IRQ_INPROGRESS; /* we are handling it */
506 desc->status = status;
509 * If there is no IRQ handler or it was disabled, exit early.
510 * Since we set PENDING, if another processor is handling
511 * a different instance of this same irq, the other processor
512 * will take care of it.
514 if (unlikely(!action))
518 * Edge triggered interrupts need to remember
520 * This applies to any hw interrupts that allow a second
521 * instance of the same irq to arrive while we are in do_IRQ
522 * or in the handler. But the code here only handles the _second_
523 * instance of the irq, not the third or fourth. So it is mostly
524 * useful for irq hardware that does not mask cleanly in an
528 spin_unlock(&desc->lock);
529 action_ret = handle_IRQ_event(irq, regs, action);
530 spin_lock(&desc->lock);
532 note_interrupt(irq, desc, action_ret);
533 if (!(desc->status & IRQ_PENDING))
535 desc->status &= ~IRQ_PENDING;
537 desc->status &= ~IRQ_INPROGRESS;
540 * The ->end() handler has to deal with interrupts which got
541 * disabled while the handler was running.
543 desc->handler->end(irq);
544 spin_unlock(&desc->lock);
550 * request_irq - allocate an interrupt line
551 * @irq: Interrupt line to allocate
552 * @handler: Function to be called when the IRQ occurs
553 * @irqflags: Interrupt type flags
554 * @devname: An ascii name for the claiming device
555 * @dev_id: A cookie passed back to the handler function
557 * This call allocates interrupt resources and enables the
558 * interrupt line and IRQ handling. From the point this
559 * call is made your handler function may be invoked. Since
560 * your handler function must clear any interrupt the board
561 * raises, you must take care both to initialise your hardware
562 * and to set up the interrupt handler in the right order.
564 * Dev_id must be globally unique. Normally the address of the
565 * device data structure is used as the cookie. Since the handler
566 * receives this value it makes sense to use it.
568 * If your interrupt is shared you must pass a non NULL dev_id
569 * as this is required when freeing the interrupt.
573 * SA_SHIRQ Interrupt is shared
575 * SA_INTERRUPT Disable local interrupts while processing
577 * SA_SAMPLE_RANDOM The interrupt can be used for entropy
581 int request_irq(unsigned int irq,
582 irqreturn_t (*handler)(int, void *, struct pt_regs *),
583 unsigned long irqflags,
584 const char * devname,
588 struct irqaction * action;
592 * Sanity-check: shared interrupts should REALLY pass in
593 * a real dev-ID, otherwise we'll have trouble later trying
594 * to figure out which interrupt is which (messes up the
595 * interrupt freeing logic etc).
597 if (irqflags & SA_SHIRQ) {
599 printk(KERN_ERR "Bad boy: %s called us without a dev_id!\n", devname);
608 action = (struct irqaction *)
609 kmalloc(sizeof(struct irqaction), GFP_ATOMIC);
613 action->handler = handler;
614 action->flags = irqflags;
615 cpus_clear(action->mask);
616 action->name = devname;
618 action->dev_id = dev_id;
620 retval = setup_irq(irq, action);
626 EXPORT_SYMBOL(request_irq);
629 * free_irq - free an interrupt
630 * @irq: Interrupt line to free
631 * @dev_id: Device identity to free
633 * Remove an interrupt handler. The handler is removed and if the
634 * interrupt line is no longer in use by any driver it is disabled.
635 * On a shared IRQ the caller must ensure the interrupt is disabled
636 * on the card it drives before calling this function. The function
637 * does not return until any executing interrupts for this IRQ
640 * This function must not be called from interrupt context.
643 void free_irq(unsigned int irq, void *dev_id)
646 struct irqaction **p;
652 desc = irq_descp(irq);
653 spin_lock_irqsave(&desc->lock,flags);
656 struct irqaction * action = *p;
658 struct irqaction **pp = p;
660 if (action->dev_id != dev_id)
663 /* Found it - now remove it from the list of entries */
666 desc->status |= IRQ_DISABLED;
667 desc->handler->shutdown(irq);
669 spin_unlock_irqrestore(&desc->lock,flags);
671 /* Wait to make sure it's not being used on another CPU */
672 synchronize_irq(irq);
676 printk(KERN_ERR "Trying to free free IRQ%d\n",irq);
677 spin_unlock_irqrestore(&desc->lock,flags);
682 EXPORT_SYMBOL(free_irq);
685 * IRQ autodetection code..
687 * This depends on the fact that any interrupt that
688 * comes in on to an unassigned handler will get stuck
689 * with "IRQ_WAITING" cleared and the interrupt
693 static DECLARE_MUTEX(probe_sem);
696 * probe_irq_on - begin an interrupt autodetect
698 * Commence probing for an interrupt. The interrupts are scanned
699 * and a mask of potential interrupt lines is returned.
703 unsigned long probe_irq_on(void)
712 * something may have generated an irq long ago and we want to
713 * flush such a longstanding irq before considering it as spurious.
715 for (i = NR_IRQS-1; i > 0; i--) {
718 spin_lock_irq(&desc->lock);
720 desc->handler->startup(i);
721 spin_unlock_irq(&desc->lock);
724 /* Wait for longstanding interrupts to trigger. */
725 for (delay = jiffies + HZ/50; time_after(delay, jiffies); )
726 /* about 20ms delay */ barrier();
729 * enable any unassigned irqs
730 * (we must startup again here because if a longstanding irq
731 * happened in the previous stage, it may have masked itself)
733 for (i = NR_IRQS-1; i > 0; i--) {
736 spin_lock_irq(&desc->lock);
738 desc->status |= IRQ_AUTODETECT | IRQ_WAITING;
739 if (desc->handler->startup(i))
740 desc->status |= IRQ_PENDING;
742 spin_unlock_irq(&desc->lock);
746 * Wait for spurious interrupts to trigger
748 for (delay = jiffies + HZ/10; time_after(delay, jiffies); )
749 /* about 100ms delay */ barrier();
752 * Now filter out any obviously spurious interrupts
755 for (i = 0; i < NR_IRQS; i++) {
756 irq_desc_t *desc = irq_descp(i);
759 spin_lock_irq(&desc->lock);
760 status = desc->status;
762 if (status & IRQ_AUTODETECT) {
763 /* It triggered already - consider it spurious. */
764 if (!(status & IRQ_WAITING)) {
765 desc->status = status & ~IRQ_AUTODETECT;
766 desc->handler->shutdown(i);
771 spin_unlock_irq(&desc->lock);
777 EXPORT_SYMBOL(probe_irq_on);
780 * probe_irq_mask - scan a bitmap of interrupt lines
781 * @val: mask of interrupts to consider
783 * Scan the ISA bus interrupt lines and return a bitmap of
784 * active interrupts. The interrupt probe logic state is then
785 * returned to its previous value.
787 * Note: we need to scan all the irq's even though we will
788 * only return ISA irq numbers - just so that we reset them
789 * all to a known state.
791 unsigned int probe_irq_mask(unsigned long val)
797 for (i = 0; i < 16; i++) {
798 irq_desc_t *desc = irq_descp(i);
801 spin_lock_irq(&desc->lock);
802 status = desc->status;
804 if (status & IRQ_AUTODETECT) {
805 if (!(status & IRQ_WAITING))
808 desc->status = status & ~IRQ_AUTODETECT;
809 desc->handler->shutdown(i);
811 spin_unlock_irq(&desc->lock);
817 EXPORT_SYMBOL(probe_irq_mask);
820 * probe_irq_off - end an interrupt autodetect
821 * @val: mask of potential interrupts (unused)
823 * Scans the unused interrupt lines and returns the line which
824 * appears to have triggered the interrupt. If no interrupt was
825 * found then zero is returned. If more than one interrupt is
826 * found then minus the first candidate is returned to indicate
829 * The interrupt probe logic state is returned to its previous
832 * BUGS: When used in a module (which arguably shouldn't happen)
833 * nothing prevents two IRQ probe callers from overlapping. The
834 * results of this are non-optimal.
837 int probe_irq_off(unsigned long val)
839 int i, irq_found, nr_irqs;
843 for (i = 0; i < NR_IRQS; i++) {
844 irq_desc_t *desc = irq_descp(i);
847 spin_lock_irq(&desc->lock);
848 status = desc->status;
850 if (status & IRQ_AUTODETECT) {
851 if (!(status & IRQ_WAITING)) {
856 desc->status = status & ~IRQ_AUTODETECT;
857 desc->handler->shutdown(i);
859 spin_unlock_irq(&desc->lock);
864 irq_found = -irq_found;
868 EXPORT_SYMBOL(probe_irq_off);
870 int setup_irq(unsigned int irq, struct irqaction * new)
874 struct irqaction *old, **p;
875 irq_desc_t *desc = irq_descp(irq);
877 if (desc->handler == &no_irq_type)
880 * Some drivers like serial.c use request_irq() heavily,
881 * so we have to be careful not to interfere with a
884 if (new->flags & SA_SAMPLE_RANDOM) {
886 * This function might sleep, we want to call it first,
887 * outside of the atomic block.
888 * Yes, this might clear the entropy pool if the wrong
889 * driver is attempted to be loaded, without actually
890 * installing a new handler, but is this really a problem,
891 * only the sysadmin is able to do this.
893 rand_initialize_irq(irq);
896 if (new->flags & SA_PERCPU_IRQ) {
897 desc->status |= IRQ_PER_CPU;
898 desc->handler = &irq_type_ia64_lsapic;
902 * The following block of code has to be executed atomically
904 spin_lock_irqsave(&desc->lock,flags);
906 if ((old = *p) != NULL) {
907 /* Can't share interrupts unless both agree to */
908 if (!(old->flags & new->flags & SA_SHIRQ)) {
909 spin_unlock_irqrestore(&desc->lock,flags);
913 /* add new interrupt at end of irq queue */
925 desc->status &= ~(IRQ_DISABLED | IRQ_AUTODETECT | IRQ_WAITING | IRQ_INPROGRESS);
926 desc->handler->startup(irq);
928 spin_unlock_irqrestore(&desc->lock,flags);
930 register_irq_proc(irq);
934 static struct proc_dir_entry * root_irq_dir;
935 static struct proc_dir_entry * irq_dir [NR_IRQS];
939 static struct proc_dir_entry * smp_affinity_entry [NR_IRQS];
941 static cpumask_t irq_affinity [NR_IRQS] = { [0 ... NR_IRQS-1] = CPU_MASK_ALL };
943 static char irq_redir [NR_IRQS]; // = { [0 ... NR_IRQS-1] = 1 };
945 void set_irq_affinity_info (unsigned int irq, int hwid, int redir)
947 cpumask_t mask = CPU_MASK_NONE;
949 cpu_set(cpu_logical_id(hwid), mask);
952 irq_affinity[irq] = mask;
953 irq_redir[irq] = (char) (redir & 0xff);
957 static int irq_affinity_read_proc (char *page, char **start, off_t off,
958 int count, int *eof, void *data)
960 int len = sprintf(page, "%s", irq_redir[(long)data] ? "r " : "");
962 len += cpumask_scnprintf(page+len, count, irq_affinity[(long)data]);
965 len += sprintf(page + len, "\n");
969 static int irq_affinity_write_proc (struct file *file, const char __user *buffer,
970 unsigned long count, void *data)
972 unsigned int irq = (unsigned long) data;
973 int full_count = count, err;
974 cpumask_t new_value, tmp;
975 # define R_PREFIX_LEN 16
976 char rbuf[R_PREFIX_LEN];
979 irq_desc_t *desc = irq_descp(irq);
983 if (!desc->handler->set_affinity)
987 * If string being written starts with a prefix of 'r' or 'R'
988 * and some limited number of spaces, set IA64_IRQ_REDIRECTED.
989 * If more than (R_PREFIX_LEN - 2) spaces are passed, they won't
990 * all be trimmed as part of prelen, the untrimmed spaces will
991 * cause the hex parsing to fail, and this write() syscall will
997 rlen = min(sizeof(rbuf)-1, count);
998 if (copy_from_user(rbuf, buffer, rlen))
1002 if (tolower(*rbuf) == 'r') {
1003 prelen = strspn(rbuf, "Rr ");
1007 err = cpumask_parse(buffer+prelen, count-prelen, new_value);
1012 * Do not allow disabling IRQs completely - it's a too easy
1013 * way to make the system unusable accidentally :-) At least
1014 * one online CPU still has to be targeted.
1016 cpus_and(tmp, new_value, cpu_online_map);
1017 if (cpus_empty(tmp))
1020 spin_lock_irqsave(&desc->lock, flags);
1021 pending_irq_cpumask[irq] = new_value;
1023 set_bit(irq, pending_irq_redir);
1025 clear_bit(irq, pending_irq_redir);
1026 spin_unlock_irqrestore(&desc->lock, flags);
1031 void move_irq(int irq)
1033 /* note - we hold desc->lock */
1035 irq_desc_t *desc = irq_descp(irq);
1036 int redir = test_bit(irq, pending_irq_redir);
1038 if (!cpus_empty(pending_irq_cpumask[irq])) {
1039 cpus_and(tmp, pending_irq_cpumask[irq], cpu_online_map);
1040 if (unlikely(!cpus_empty(tmp))) {
1041 desc->handler->set_affinity(irq | (redir ? IA64_IRQ_REDIRECTED : 0),
1042 pending_irq_cpumask[irq]);
1044 cpus_clear(pending_irq_cpumask[irq]);
1049 #endif /* CONFIG_SMP */
1051 #ifdef CONFIG_HOTPLUG_CPU
1052 unsigned int vectors_in_migration[NR_IRQS];
1055 * Since cpu_online_map is already updated, we just need to check for
1056 * affinity that has zeros
1058 static void migrate_irqs(void)
1064 for (irq=0; irq < NR_IRQS; irq++) {
1065 desc = irq_descp(irq);
1068 * No handling for now.
1069 * TBD: Implement a disable function so we can now
1070 * tell CPU not to respond to these local intr sources.
1071 * such as ITV,CPEI,MCA etc.
1073 if (desc->status == IRQ_PER_CPU)
1076 cpus_and(mask, irq_affinity[irq], cpu_online_map);
1077 if (any_online_cpu(mask) == NR_CPUS) {
1079 * Save it for phase 2 processing
1081 vectors_in_migration[irq] = irq;
1083 new_cpu = any_online_cpu(cpu_online_map);
1084 mask = cpumask_of_cpu(new_cpu);
1087 * Al three are essential, currently WARN_ON.. maybe panic?
1089 if (desc->handler && desc->handler->disable &&
1090 desc->handler->enable && desc->handler->set_affinity) {
1091 desc->handler->disable(irq);
1092 desc->handler->set_affinity(irq, mask);
1093 desc->handler->enable(irq);
1095 WARN_ON((!(desc->handler) || !(desc->handler->disable) ||
1096 !(desc->handler->enable) ||
1097 !(desc->handler->set_affinity)));
1103 void fixup_irqs(void)
1106 extern void ia64_process_pending_intr(void);
1108 ia64_set_itv(1<<16);
1110 * Phase 1: Locate irq's bound to this cpu and
1111 * relocate them for cpu removal.
1116 * Phase 2: Perform interrupt processing for all entries reported in
1119 ia64_process_pending_intr();
1122 * Phase 3: Now handle any interrupts not captured in local APIC.
1123 * This is to account for cases that device interrupted during the time the
1124 * rte was being disabled and re-programmed.
1126 for (irq=0; irq < NR_IRQS; irq++) {
1127 if (vectors_in_migration[irq]) {
1128 vectors_in_migration[irq]=0;
1134 * Now let processor die. We do irq disable and max_xtp() to
1135 * ensure there is no more interrupts routed to this processor.
1136 * But the local timer interrupt can have 1 pending which we
1137 * take care in timer_interrupt().
1140 local_irq_disable();
1144 #define MAX_NAMELEN 10
1146 static void register_irq_proc (unsigned int irq)
1148 char name [MAX_NAMELEN];
1150 if (!root_irq_dir || (irq_descp(irq)->handler == &no_irq_type) || irq_dir[irq])
1153 memset(name, 0, MAX_NAMELEN);
1154 sprintf(name, "%d", irq);
1156 /* create /proc/irq/1234 */
1157 irq_dir[irq] = proc_mkdir(name, root_irq_dir);
1161 struct proc_dir_entry *entry;
1163 /* create /proc/irq/1234/smp_affinity */
1164 entry = create_proc_entry("smp_affinity", 0600, irq_dir[irq]);
1168 entry->data = (void *)(long)irq;
1169 entry->read_proc = irq_affinity_read_proc;
1170 entry->write_proc = irq_affinity_write_proc;
1173 smp_affinity_entry[irq] = entry;
1178 void init_irq_proc (void)
1182 /* create /proc/irq */
1183 root_irq_dir = proc_mkdir("irq", NULL);
1185 /* create /proc/irq/prof_cpu_mask */
1186 create_prof_cpu_mask(root_irq_dir);
1189 * Create entries for all existing IRQs.
1191 for (i = 0; i < NR_IRQS; i++) {
1192 if (irq_descp(i)->handler == &no_irq_type)
1194 register_irq_proc(i);