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
88 * This is updated when the user sets irq affinity via /proc
90 cpumask_t __cacheline_aligned pending_irq_cpumask[NR_IRQS];
92 #ifdef CONFIG_IA64_GENERIC
93 irq_desc_t * __ia64_irq_desc (unsigned int irq)
95 return _irq_desc + irq;
98 ia64_vector __ia64_irq_to_vector (unsigned int irq)
100 return (ia64_vector) irq;
103 unsigned int __ia64_local_vector_to_irq (ia64_vector vec)
105 return (unsigned int) vec;
109 static void register_irq_proc (unsigned int irq);
112 * Special irq handlers.
115 irqreturn_t no_action(int cpl, void *dev_id, struct pt_regs *regs)
119 * Generic no controller code
122 static void enable_none(unsigned int irq) { }
123 static unsigned int startup_none(unsigned int irq) { return 0; }
124 static void disable_none(unsigned int irq) { }
125 static void ack_none(unsigned int irq)
128 * 'what should we do if we get a hw irq event on an illegal vector'.
129 * each architecture has to answer this themselves, it doesn't deserve
130 * a generic callback i think.
133 printk(KERN_ERR "unexpected IRQ trap at vector %02x\n", irq);
134 #ifdef CONFIG_X86_LOCAL_APIC
136 * Currently unexpected vectors happen only on SMP and APIC.
137 * We _must_ ack these because every local APIC has only N
138 * irq slots per priority level, and a 'hanging, unacked' IRQ
139 * holds up an irq slot - in excessive cases (when multiple
140 * unexpected vectors occur) that might lock up the APIC
147 printk(KERN_ERR "Unexpected irq vector 0x%x on CPU %u!\n", irq, smp_processor_id());
151 /* startup is the same as "enable", shutdown is same as "disable" */
152 #define shutdown_none disable_none
153 #define end_none enable_none
155 struct hw_interrupt_type no_irq_type = {
165 atomic_t irq_err_count;
166 #ifdef CONFIG_X86_IO_APIC
167 #ifdef APIC_MISMATCH_DEBUG
168 atomic_t irq_mis_count;
173 * Generic, controller-independent functions:
176 int show_interrupts(struct seq_file *p, void *v)
178 int j, i = *(loff_t *) v;
179 struct irqaction * action;
185 for (j=0; j<NR_CPUS; j++)
187 seq_printf(p, "CPU%d ",j);
192 idesc = irq_descp(i);
193 spin_lock_irqsave(&idesc->lock, flags);
194 action = idesc->action;
197 seq_printf(p, "%3d: ",i);
199 seq_printf(p, "%10u ", kstat_irqs(i));
201 for (j = 0; j < NR_CPUS; j++)
203 seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
205 seq_printf(p, " %14s", idesc->handler->typename);
206 seq_printf(p, " %s", action->name);
208 for (action=action->next; action; action = action->next)
209 seq_printf(p, ", %s", action->name);
213 spin_unlock_irqrestore(&idesc->lock, flags);
214 } else if (i == NR_IRQS) {
215 seq_puts(p, "NMI: ");
216 for (j = 0; j < NR_CPUS; j++)
218 seq_printf(p, "%10u ", nmi_count(j));
220 #ifdef CONFIG_X86_LOCAL_APIC
221 seq_puts(p, "LOC: ");
222 for (j = 0; j < NR_CPUS; j++)
224 seq_printf(p, "%10u ", irq_stat[j].apic_timer_irqs);
227 seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
228 #ifdef CONFIG_X86_IO_APIC
229 #ifdef APIC_MISMATCH_DEBUG
230 seq_printf(p, "MIS: %10u\n", atomic_read(&irq_mis_count));
238 inline void synchronize_irq(unsigned int irq)
240 while (irq_descp(irq)->status & IRQ_INPROGRESS)
243 EXPORT_SYMBOL(synchronize_irq);
247 * This should really return information about whether
248 * we should do bottom half handling etc. Right now we
249 * end up _always_ checking the bottom half, which is a
250 * waste of time and is not what some drivers would
253 int handle_IRQ_event(unsigned int irq,
254 struct pt_regs *regs, struct irqaction *action)
256 int status = 1; /* Force the "do bottom halves" bit */
259 if (!(action->flags & SA_INTERRUPT))
263 status |= action->flags;
264 retval |= action->handler(irq, action->dev_id, regs);
265 action = action->next;
267 if (status & SA_SAMPLE_RANDOM)
268 add_interrupt_randomness(irq);
273 static void __report_bad_irq(int irq, irq_desc_t *desc, irqreturn_t action_ret)
275 struct irqaction *action;
277 if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
278 printk(KERN_ERR "irq event %d: bogus return value %x\n",
281 printk(KERN_ERR "irq %d: nobody cared!\n", irq);
284 printk(KERN_ERR "handlers:\n");
285 action = desc->action;
287 printk(KERN_ERR "[<%p>]", action->handler);
288 print_symbol(" (%s)",
289 (unsigned long)action->handler);
291 action = action->next;
295 static void report_bad_irq(int irq, irq_desc_t *desc, irqreturn_t action_ret)
297 static int count = 100;
301 __report_bad_irq(irq, desc, action_ret);
305 static int noirqdebug;
307 static int __init noirqdebug_setup(char *str)
310 printk("IRQ lockup detection disabled\n");
314 __setup("noirqdebug", noirqdebug_setup);
317 * If 99,900 of the previous 100,000 interrupts have not been handled then
318 * assume that the IRQ is stuck in some manner. Drop a diagnostic and try to
321 * (The other 100-of-100,000 interrupts may have been a correctly-functioning
322 * device sharing an IRQ with the failing one)
324 * Called under desc->lock
326 static void note_interrupt(int irq, irq_desc_t *desc, irqreturn_t action_ret)
328 if (action_ret != IRQ_HANDLED) {
329 desc->irqs_unhandled++;
330 if (action_ret != IRQ_NONE)
331 report_bad_irq(irq, desc, action_ret);
335 if (desc->irq_count < 100000)
339 if (desc->irqs_unhandled > 99900) {
341 * The interrupt is stuck
343 __report_bad_irq(irq, desc, action_ret);
347 printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
348 desc->status |= IRQ_DISABLED;
349 desc->handler->disable(irq);
351 desc->irqs_unhandled = 0;
355 * Generic enable/disable code: this just calls
356 * down into the PIC-specific version for the actual
357 * hardware disable after having gotten the irq
362 * disable_irq_nosync - disable an irq without waiting
363 * @irq: Interrupt to disable
365 * Disable the selected interrupt line. Disables and Enables are
367 * Unlike disable_irq(), this function does not ensure existing
368 * instances of the IRQ handler have completed before returning.
370 * This function may be called from IRQ context.
373 inline void disable_irq_nosync(unsigned int irq)
375 irq_desc_t *desc = irq_descp(irq);
378 spin_lock_irqsave(&desc->lock, flags);
379 if (!desc->depth++) {
380 desc->status |= IRQ_DISABLED;
381 desc->handler->disable(irq);
383 spin_unlock_irqrestore(&desc->lock, flags);
385 EXPORT_SYMBOL(disable_irq_nosync);
388 * disable_irq - disable an irq and wait for completion
389 * @irq: Interrupt to disable
391 * Disable the selected interrupt line. Enables and Disables are
393 * This function waits for any pending IRQ handlers for this interrupt
394 * to complete before returning. If you use this function while
395 * holding a resource the IRQ handler may need you will deadlock.
397 * This function may be called - with care - from IRQ context.
400 void disable_irq(unsigned int irq)
402 irq_desc_t *desc = irq_descp(irq);
404 disable_irq_nosync(irq);
406 synchronize_irq(irq);
408 EXPORT_SYMBOL(disable_irq);
411 * enable_irq - enable handling of an irq
412 * @irq: Interrupt to enable
414 * Undoes the effect of one call to disable_irq(). If this
415 * matches the last disable, processing of interrupts on this
416 * IRQ line is re-enabled.
418 * This function may be called from IRQ context.
421 void enable_irq(unsigned int irq)
423 irq_desc_t *desc = irq_descp(irq);
426 spin_lock_irqsave(&desc->lock, flags);
427 switch (desc->depth) {
429 unsigned int status = desc->status & ~IRQ_DISABLED;
430 desc->status = status;
431 if ((status & (IRQ_PENDING | IRQ_REPLAY)) == IRQ_PENDING) {
432 desc->status = status | IRQ_REPLAY;
433 hw_resend_irq(desc->handler,irq);
435 desc->handler->enable(irq);
442 printk(KERN_ERR "enable_irq(%u) unbalanced from %p\n",
443 irq, (void *) __builtin_return_address(0));
445 spin_unlock_irqrestore(&desc->lock, flags);
447 EXPORT_SYMBOL(enable_irq);
450 * do_IRQ handles all normal device IRQ's (the special
451 * SMP cross-CPU interrupts have their own specific
454 unsigned int do_IRQ(unsigned long irq, struct pt_regs *regs)
457 * We ack quickly, we don't want the irq controller
458 * thinking we're snobs just because some other CPU has
459 * disabled global interrupts (we have already done the
460 * INT_ACK cycles, it's too late to try to pretend to the
461 * controller that we aren't taking the interrupt).
463 * 0 return value means that this irq is already being
464 * handled by some other CPU. (or is disabled)
466 irq_desc_t *desc = irq_descp(irq);
467 struct irqaction * action;
468 irqreturn_t action_ret;
472 cpu = smp_processor_id(); /* for CONFIG_PREEMPT, this must come after irq_enter()! */
474 kstat_cpu(cpu).irqs[irq]++;
476 if (desc->status & IRQ_PER_CPU) {
477 /* no locking required for CPU-local interrupts: */
478 desc->handler->ack(irq);
479 action_ret = handle_IRQ_event(irq, regs, desc->action);
480 desc->handler->end(irq);
482 spin_lock(&desc->lock);
483 desc->handler->ack(irq);
485 * REPLAY is when Linux resends an IRQ that was dropped earlier
486 * WAITING is used by probe to mark irqs that are being tested
488 status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
489 status |= IRQ_PENDING; /* we _want_ to handle it */
492 * If the IRQ is disabled for whatever reason, we cannot
493 * use the action we have.
496 if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
497 action = desc->action;
498 status &= ~IRQ_PENDING; /* we commit to handling */
499 status |= IRQ_INPROGRESS; /* we are handling it */
501 desc->status = status;
504 * If there is no IRQ handler or it was disabled, exit early.
505 * Since we set PENDING, if another processor is handling
506 * a different instance of this same irq, the other processor
507 * will take care of it.
509 if (unlikely(!action))
513 * Edge triggered interrupts need to remember
515 * This applies to any hw interrupts that allow a second
516 * instance of the same irq to arrive while we are in do_IRQ
517 * or in the handler. But the code here only handles the _second_
518 * instance of the irq, not the third or fourth. So it is mostly
519 * useful for irq hardware that does not mask cleanly in an
523 spin_unlock(&desc->lock);
524 action_ret = handle_IRQ_event(irq, regs, action);
525 spin_lock(&desc->lock);
527 note_interrupt(irq, desc, action_ret);
528 if (!(desc->status & IRQ_PENDING))
530 desc->status &= ~IRQ_PENDING;
532 desc->status &= ~IRQ_INPROGRESS;
535 * The ->end() handler has to deal with interrupts which got
536 * disabled while the handler was running.
538 desc->handler->end(irq);
539 spin_unlock(&desc->lock);
545 * request_irq - allocate an interrupt line
546 * @irq: Interrupt line to allocate
547 * @handler: Function to be called when the IRQ occurs
548 * @irqflags: Interrupt type flags
549 * @devname: An ascii name for the claiming device
550 * @dev_id: A cookie passed back to the handler function
552 * This call allocates interrupt resources and enables the
553 * interrupt line and IRQ handling. From the point this
554 * call is made your handler function may be invoked. Since
555 * your handler function must clear any interrupt the board
556 * raises, you must take care both to initialise your hardware
557 * and to set up the interrupt handler in the right order.
559 * Dev_id must be globally unique. Normally the address of the
560 * device data structure is used as the cookie. Since the handler
561 * receives this value it makes sense to use it.
563 * If your interrupt is shared you must pass a non NULL dev_id
564 * as this is required when freeing the interrupt.
568 * SA_SHIRQ Interrupt is shared
570 * SA_INTERRUPT Disable local interrupts while processing
572 * SA_SAMPLE_RANDOM The interrupt can be used for entropy
576 int request_irq(unsigned int irq,
577 irqreturn_t (*handler)(int, void *, struct pt_regs *),
578 unsigned long irqflags,
579 const char * devname,
583 struct irqaction * action;
587 * Sanity-check: shared interrupts should REALLY pass in
588 * a real dev-ID, otherwise we'll have trouble later trying
589 * to figure out which interrupt is which (messes up the
590 * interrupt freeing logic etc).
592 if (irqflags & SA_SHIRQ) {
594 printk(KERN_ERR "Bad boy: %s called us without a dev_id!\n", devname);
603 action = (struct irqaction *)
604 kmalloc(sizeof(struct irqaction), GFP_ATOMIC);
608 action->handler = handler;
609 action->flags = irqflags;
611 action->name = devname;
613 action->dev_id = dev_id;
615 retval = setup_irq(irq, action);
621 EXPORT_SYMBOL(request_irq);
624 * free_irq - free an interrupt
625 * @irq: Interrupt line to free
626 * @dev_id: Device identity to free
628 * Remove an interrupt handler. The handler is removed and if the
629 * interrupt line is no longer in use by any driver it is disabled.
630 * On a shared IRQ the caller must ensure the interrupt is disabled
631 * on the card it drives before calling this function. The function
632 * does not return until any executing interrupts for this IRQ
635 * This function must not be called from interrupt context.
638 void free_irq(unsigned int irq, void *dev_id)
641 struct irqaction **p;
647 desc = irq_descp(irq);
648 spin_lock_irqsave(&desc->lock,flags);
651 struct irqaction * action = *p;
653 struct irqaction **pp = p;
655 if (action->dev_id != dev_id)
658 /* Found it - now remove it from the list of entries */
661 desc->status |= IRQ_DISABLED;
662 desc->handler->shutdown(irq);
664 spin_unlock_irqrestore(&desc->lock,flags);
666 /* Wait to make sure it's not being used on another CPU */
667 synchronize_irq(irq);
671 printk(KERN_ERR "Trying to free free IRQ%d\n",irq);
672 spin_unlock_irqrestore(&desc->lock,flags);
677 EXPORT_SYMBOL(free_irq);
680 * IRQ autodetection code..
682 * This depends on the fact that any interrupt that
683 * comes in on to an unassigned handler will get stuck
684 * with "IRQ_WAITING" cleared and the interrupt
688 static DECLARE_MUTEX(probe_sem);
691 * probe_irq_on - begin an interrupt autodetect
693 * Commence probing for an interrupt. The interrupts are scanned
694 * and a mask of potential interrupt lines is returned.
698 unsigned long probe_irq_on(void)
707 * something may have generated an irq long ago and we want to
708 * flush such a longstanding irq before considering it as spurious.
710 for (i = NR_IRQS-1; i > 0; i--) {
713 spin_lock_irq(&desc->lock);
715 desc->handler->startup(i);
716 spin_unlock_irq(&desc->lock);
719 /* Wait for longstanding interrupts to trigger. */
720 for (delay = jiffies + HZ/50; time_after(delay, jiffies); )
721 /* about 20ms delay */ barrier();
724 * enable any unassigned irqs
725 * (we must startup again here because if a longstanding irq
726 * happened in the previous stage, it may have masked itself)
728 for (i = NR_IRQS-1; i > 0; i--) {
731 spin_lock_irq(&desc->lock);
733 desc->status |= IRQ_AUTODETECT | IRQ_WAITING;
734 if (desc->handler->startup(i))
735 desc->status |= IRQ_PENDING;
737 spin_unlock_irq(&desc->lock);
741 * Wait for spurious interrupts to trigger
743 for (delay = jiffies + HZ/10; time_after(delay, jiffies); )
744 /* about 100ms delay */ barrier();
747 * Now filter out any obviously spurious interrupts
750 for (i = 0; i < NR_IRQS; i++) {
751 irq_desc_t *desc = irq_descp(i);
754 spin_lock_irq(&desc->lock);
755 status = desc->status;
757 if (status & IRQ_AUTODETECT) {
758 /* It triggered already - consider it spurious. */
759 if (!(status & IRQ_WAITING)) {
760 desc->status = status & ~IRQ_AUTODETECT;
761 desc->handler->shutdown(i);
766 spin_unlock_irq(&desc->lock);
772 EXPORT_SYMBOL(probe_irq_on);
775 * probe_irq_mask - scan a bitmap of interrupt lines
776 * @val: mask of interrupts to consider
778 * Scan the ISA bus interrupt lines and return a bitmap of
779 * active interrupts. The interrupt probe logic state is then
780 * returned to its previous value.
782 * Note: we need to scan all the irq's even though we will
783 * only return ISA irq numbers - just so that we reset them
784 * all to a known state.
786 unsigned int probe_irq_mask(unsigned long val)
792 for (i = 0; i < 16; i++) {
793 irq_desc_t *desc = irq_descp(i);
796 spin_lock_irq(&desc->lock);
797 status = desc->status;
799 if (status & IRQ_AUTODETECT) {
800 if (!(status & IRQ_WAITING))
803 desc->status = status & ~IRQ_AUTODETECT;
804 desc->handler->shutdown(i);
806 spin_unlock_irq(&desc->lock);
812 EXPORT_SYMBOL(probe_irq_mask);
815 * probe_irq_off - end an interrupt autodetect
816 * @val: mask of potential interrupts (unused)
818 * Scans the unused interrupt lines and returns the line which
819 * appears to have triggered the interrupt. If no interrupt was
820 * found then zero is returned. If more than one interrupt is
821 * found then minus the first candidate is returned to indicate
824 * The interrupt probe logic state is returned to its previous
827 * BUGS: When used in a module (which arguably shouldn't happen)
828 * nothing prevents two IRQ probe callers from overlapping. The
829 * results of this are non-optimal.
832 int probe_irq_off(unsigned long val)
834 int i, irq_found, nr_irqs;
838 for (i = 0; i < NR_IRQS; i++) {
839 irq_desc_t *desc = irq_descp(i);
842 spin_lock_irq(&desc->lock);
843 status = desc->status;
845 if (status & IRQ_AUTODETECT) {
846 if (!(status & IRQ_WAITING)) {
851 desc->status = status & ~IRQ_AUTODETECT;
852 desc->handler->shutdown(i);
854 spin_unlock_irq(&desc->lock);
859 irq_found = -irq_found;
863 EXPORT_SYMBOL(probe_irq_off);
865 int setup_irq(unsigned int irq, struct irqaction * new)
869 struct irqaction *old, **p;
870 irq_desc_t *desc = irq_descp(irq);
872 if (desc->handler == &no_irq_type)
875 * Some drivers like serial.c use request_irq() heavily,
876 * so we have to be careful not to interfere with a
879 if (new->flags & SA_SAMPLE_RANDOM) {
881 * This function might sleep, we want to call it first,
882 * outside of the atomic block.
883 * Yes, this might clear the entropy pool if the wrong
884 * driver is attempted to be loaded, without actually
885 * installing a new handler, but is this really a problem,
886 * only the sysadmin is able to do this.
888 rand_initialize_irq(irq);
891 if (new->flags & SA_PERCPU_IRQ) {
892 desc->status |= IRQ_PER_CPU;
893 desc->handler = &irq_type_ia64_lsapic;
897 * The following block of code has to be executed atomically
899 spin_lock_irqsave(&desc->lock,flags);
901 if ((old = *p) != NULL) {
902 /* Can't share interrupts unless both agree to */
903 if (!(old->flags & new->flags & SA_SHIRQ)) {
904 spin_unlock_irqrestore(&desc->lock,flags);
908 /* add new interrupt at end of irq queue */
920 desc->status &= ~(IRQ_DISABLED | IRQ_AUTODETECT | IRQ_WAITING | IRQ_INPROGRESS);
921 desc->handler->startup(irq);
923 spin_unlock_irqrestore(&desc->lock,flags);
925 register_irq_proc(irq);
929 static struct proc_dir_entry * root_irq_dir;
930 static struct proc_dir_entry * irq_dir [NR_IRQS];
934 static struct proc_dir_entry * smp_affinity_entry [NR_IRQS];
936 static cpumask_t irq_affinity [NR_IRQS] = { [0 ... NR_IRQS-1] = CPU_MASK_ALL };
938 static char irq_redir [NR_IRQS]; // = { [0 ... NR_IRQS-1] = 1 };
940 void set_irq_affinity_info (unsigned int irq, int hwid, int redir)
942 cpumask_t mask = CPU_MASK_NONE;
944 cpu_set(cpu_logical_id(hwid), mask);
947 irq_affinity[irq] = mask;
948 irq_redir[irq] = (char) (redir & 0xff);
952 static int irq_affinity_read_proc (char *page, char **start, off_t off,
953 int count, int *eof, void *data)
955 int len = sprintf(page, "%s", irq_redir[(long)data] ? "r " : "");
957 len += cpumask_scnprintf(page+len, count, irq_affinity[(long)data]);
960 len += sprintf(page + len, "\n");
964 static int irq_affinity_write_proc (struct file *file, const char *buffer,
965 unsigned long count, void *data)
967 unsigned int irq = (unsigned long) data;
968 int full_count = count, err;
969 cpumask_t new_value, tmp;
970 # define R_PREFIX_LEN 16
971 char rbuf[R_PREFIX_LEN];
974 irq_desc_t *desc = irq_descp(irq);
977 if (!desc->handler->set_affinity)
981 * If string being written starts with a prefix of 'r' or 'R'
982 * and some limited number of spaces, set IA64_IRQ_REDIRECTED.
983 * If more than (R_PREFIX_LEN - 2) spaces are passed, they won't
984 * all be trimmed as part of prelen, the untrimmed spaces will
985 * cause the hex parsing to fail, and this write() syscall will
991 rlen = min(sizeof(rbuf)-1, count);
992 if (copy_from_user(rbuf, buffer, rlen))
996 if (tolower(*rbuf) == 'r') {
997 prelen = strspn(rbuf, "Rr ");
998 irq |= IA64_IRQ_REDIRECTED;
1001 err = cpumask_parse(buffer+prelen, count-prelen, new_value);
1006 * Do not allow disabling IRQs completely - it's a too easy
1007 * way to make the system unusable accidentally :-) At least
1008 * one online CPU still has to be targeted.
1010 cpus_and(tmp, new_value, cpu_online_map);
1011 if (cpus_empty(tmp))
1014 spin_lock_irqsave(&desc->lock, flags);
1015 pending_irq_cpumask[irq] = new_value;
1016 spin_unlock_irqrestore(&desc->lock, flags);
1021 #endif /* CONFIG_SMP */
1023 #ifdef CONFIG_HOTPLUG_CPU
1024 unsigned int vectors_in_migration[NR_IRQS];
1027 * Since cpu_online_map is already updated, we just need to check for
1028 * affinity that has zeros
1030 static void migrate_irqs(void)
1036 for (irq=0; irq < NR_IRQS; irq++) {
1037 desc = irq_descp(irq);
1040 * No handling for now.
1041 * TBD: Implement a disable function so we can now
1042 * tell CPU not to respond to these local intr sources.
1043 * such as ITV,CPEI,MCA etc.
1045 if (desc->status == IRQ_PER_CPU)
1048 cpus_and(mask, irq_affinity[irq], cpu_online_map);
1049 if (any_online_cpu(mask) == NR_CPUS) {
1051 * Save it for phase 2 processing
1053 vectors_in_migration[irq] = irq;
1055 new_cpu = any_online_cpu(cpu_online_map);
1056 mask = cpumask_of_cpu(new_cpu);
1059 * Al three are essential, currently WARN_ON.. maybe panic?
1061 if (desc->handler && desc->handler->disable &&
1062 desc->handler->enable && desc->handler->set_affinity) {
1063 desc->handler->disable(irq);
1064 desc->handler->set_affinity(irq, mask);
1065 desc->handler->enable(irq);
1067 WARN_ON((!(desc->handler) || !(desc->handler->disable) ||
1068 !(desc->handler->enable) ||
1069 !(desc->handler->set_affinity)));
1075 void fixup_irqs(void)
1078 extern void ia64_process_pending_intr(void);
1080 ia64_set_itv(1<<16);
1082 * Phase 1: Locate irq's bound to this cpu and
1083 * relocate them for cpu removal.
1088 * Phase 2: Perform interrupt processing for all entries reported in
1091 ia64_process_pending_intr();
1094 * Phase 3: Now handle any interrupts not captured in local APIC.
1095 * This is to account for cases that device interrupted during the time the
1096 * rte was being disabled and re-programmed.
1098 for (irq=0; irq < NR_IRQS; irq++) {
1099 if (vectors_in_migration[irq]) {
1100 vectors_in_migration[irq]=0;
1106 * Now let processor die. We do irq disable and max_xtp() to
1107 * ensure there is no more interrupts routed to this processor.
1108 * But the local timer interrupt can have 1 pending which we
1109 * take care in timer_interrupt().
1112 local_irq_disable();
1116 static int prof_cpu_mask_read_proc (char *page, char **start, off_t off,
1117 int count, int *eof, void *data)
1119 int len = cpumask_scnprintf(page, count, *(cpumask_t *)data);
1120 if (count - len < 2)
1122 len += sprintf(page + len, "\n");
1126 static int prof_cpu_mask_write_proc (struct file *file, const char *buffer,
1127 unsigned long count, void *data)
1129 cpumask_t *mask = (cpumask_t *)data;
1130 unsigned long full_count = count, err;
1131 cpumask_t new_value;
1133 err = cpumask_parse(buffer, count, new_value);
1141 #define MAX_NAMELEN 10
1143 static void register_irq_proc (unsigned int irq)
1145 char name [MAX_NAMELEN];
1147 if (!root_irq_dir || (irq_descp(irq)->handler == &no_irq_type) || irq_dir[irq])
1150 memset(name, 0, MAX_NAMELEN);
1151 sprintf(name, "%d", irq);
1153 /* create /proc/irq/1234 */
1154 irq_dir[irq] = proc_mkdir(name, root_irq_dir);
1158 struct proc_dir_entry *entry;
1160 /* create /proc/irq/1234/smp_affinity */
1161 entry = create_proc_entry("smp_affinity", 0600, irq_dir[irq]);
1165 entry->data = (void *)(long)irq;
1166 entry->read_proc = irq_affinity_read_proc;
1167 entry->write_proc = irq_affinity_write_proc;
1170 smp_affinity_entry[irq] = entry;
1175 cpumask_t prof_cpu_mask = CPU_MASK_ALL;
1177 void init_irq_proc (void)
1179 struct proc_dir_entry *entry;
1182 /* create /proc/irq */
1183 root_irq_dir = proc_mkdir("irq", 0);
1185 /* create /proc/irq/prof_cpu_mask */
1186 entry = create_proc_entry("prof_cpu_mask", 0600, root_irq_dir);
1192 entry->data = (void *)&prof_cpu_mask;
1193 entry->read_proc = prof_cpu_mask_read_proc;
1194 entry->write_proc = prof_cpu_mask_write_proc;
1197 * Create entries for all existing IRQs.
1199 for (i = 0; i < NR_IRQS; i++) {
1200 if (irq_descp(i)->handler == &no_irq_type)
1202 register_irq_proc(i);