2 * linux/arch/i386/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
14 * (mostly architecture independent, will move to kernel/irq.c in 2.5.)
16 * IRQs are in fact implemented a bit like signal handlers for the kernel.
17 * Naturally it's not a 1:1 relation, but there are similarities.
20 #include <linux/config.h>
21 #include <linux/errno.h>
22 #include <linux/module.h>
23 #include <linux/signal.h>
24 #include <linux/sched.h>
25 #include <linux/ioport.h>
26 #include <linux/interrupt.h>
27 #include <linux/timex.h>
28 #include <linux/slab.h>
29 #include <linux/random.h>
30 #include <linux/smp_lock.h>
31 #include <linux/init.h>
32 #include <linux/kernel_stat.h>
33 #include <linux/irq.h>
34 #include <linux/proc_fs.h>
35 #include <linux/seq_file.h>
36 #include <linux/kallsyms.h>
38 #include <asm/atomic.h>
41 #include <asm/system.h>
42 #include <asm/bitops.h>
43 #include <asm/uaccess.h>
44 #include <asm/pgalloc.h>
45 #include <asm/delay.h>
50 * Linux has a controller-independent x86 interrupt architecture.
51 * every controller has a 'controller-template', that is used
52 * by the main code to do the right thing. Each driver-visible
53 * interrupt source is transparently wired to the apropriate
54 * controller. Thus drivers need not be aware of the
55 * interrupt-controller.
57 * Various interrupt controllers we handle: 8259 PIC, SMP IO-APIC,
58 * PIIX4's internal 8259 PIC and SGI's Visual Workstation Cobalt (IO-)APIC.
59 * (IO-APICs assumed to be messaging to Pentium local-APICs)
61 * the code is designed to be easily extended with new/different
62 * interrupt controllers, without having to do assembly magic.
66 * Controller mappings for all interrupt sources:
68 irq_desc_t irq_desc[NR_IRQS] __cacheline_aligned = {
70 .handler = &no_irq_type,
71 .lock = SPIN_LOCK_UNLOCKED
75 static void register_irq_proc (unsigned int irq);
78 * per-CPU IRQ handling stacks
80 #ifdef CONFIG_4KSTACKS
81 union irq_ctx *hardirq_ctx[NR_CPUS];
82 union irq_ctx *softirq_ctx[NR_CPUS];
86 * Special irq handlers.
89 irqreturn_t no_action(int cpl, void *dev_id, struct pt_regs *regs)
93 * Generic no controller code
96 static void enable_none(unsigned int irq) { }
97 static unsigned int startup_none(unsigned int irq) { return 0; }
98 static void disable_none(unsigned int irq) { }
99 static void ack_none(unsigned int irq)
102 * 'what should we do if we get a hw irq event on an illegal vector'.
103 * each architecture has to answer this themselves, it doesn't deserve
104 * a generic callback i think.
107 printk("unexpected IRQ trap at vector %02x\n", irq);
108 #ifdef CONFIG_X86_LOCAL_APIC
110 * Currently unexpected vectors happen only on SMP and APIC.
111 * We _must_ ack these because every local APIC has only N
112 * irq slots per priority level, and a 'hanging, unacked' IRQ
113 * holds up an irq slot - in excessive cases (when multiple
114 * unexpected vectors occur) that might lock up the APIC
122 /* startup is the same as "enable", shutdown is same as "disable" */
123 #define shutdown_none disable_none
124 #define end_none enable_none
126 struct hw_interrupt_type no_irq_type = {
136 atomic_t irq_err_count;
137 #if defined(CONFIG_X86_IO_APIC) && defined(APIC_MISMATCH_DEBUG)
138 atomic_t irq_mis_count;
142 * Generic, controller-independent functions:
145 int show_interrupts(struct seq_file *p, void *v)
147 int i = *(loff_t *) v, j;
148 struct irqaction * action;
153 for (j=0; j<NR_CPUS; j++)
155 seq_printf(p, "CPU%d ",j);
160 spin_lock_irqsave(&irq_desc[i].lock, flags);
161 action = irq_desc[i].action;
164 seq_printf(p, "%3d: ",i);
166 seq_printf(p, "%10u ", kstat_irqs(i));
168 for (j = 0; j < NR_CPUS; j++)
170 seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
172 seq_printf(p, " %14s", irq_desc[i].handler->typename);
173 seq_printf(p, " %s", action->name);
175 for (action=action->next; action; action = action->next)
176 seq_printf(p, ", %s", action->name);
180 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
181 } else if (i == NR_IRQS) {
182 seq_printf(p, "NMI: ");
183 for (j = 0; j < NR_CPUS; j++)
185 seq_printf(p, "%10u ", nmi_count(j));
187 #ifdef CONFIG_X86_LOCAL_APIC
188 seq_printf(p, "LOC: ");
189 for (j = 0; j < NR_CPUS; j++)
191 seq_printf(p, "%10u ", irq_stat[j].apic_timer_irqs);
194 seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
195 #if defined(CONFIG_X86_IO_APIC) && defined(APIC_MISMATCH_DEBUG)
196 seq_printf(p, "MIS: %10u\n", atomic_read(&irq_mis_count));
206 inline void synchronize_irq(unsigned int irq)
208 while (irq_desc[irq].status & IRQ_INPROGRESS)
214 * This should really return information about whether
215 * we should do bottom half handling etc. Right now we
216 * end up _always_ checking the bottom half, which is a
217 * waste of time and is not what some drivers would
220 asmlinkage int handle_IRQ_event(unsigned int irq,
221 struct pt_regs *regs, struct irqaction *action)
223 int status = 1; /* Force the "do bottom halves" bit */
226 if (!(action->flags & SA_INTERRUPT))
230 status |= action->flags;
231 retval |= action->handler(irq, action->dev_id, regs);
232 action = action->next;
234 if (status & SA_SAMPLE_RANDOM)
235 add_interrupt_randomness(irq);
240 static void __report_bad_irq(int irq, irq_desc_t *desc, irqreturn_t action_ret)
242 struct irqaction *action;
244 if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
245 printk(KERN_ERR "irq event %d: bogus return value %x\n",
248 printk(KERN_ERR "irq %d: nobody cared!\n", irq);
251 printk(KERN_ERR "handlers:\n");
252 action = desc->action;
254 printk(KERN_ERR "[<%p>]", action->handler);
255 print_symbol(" (%s)",
256 (unsigned long)action->handler);
258 action = action->next;
262 static void report_bad_irq(int irq, irq_desc_t *desc, irqreturn_t action_ret)
264 static int count = 100;
268 __report_bad_irq(irq, desc, action_ret);
272 static int noirqdebug;
274 static int __init noirqdebug_setup(char *str)
277 printk("IRQ lockup detection disabled\n");
281 __setup("noirqdebug", noirqdebug_setup);
284 * If 99,900 of the previous 100,000 interrupts have not been handled then
285 * assume that the IRQ is stuck in some manner. Drop a diagnostic and try to
288 * (The other 100-of-100,000 interrupts may have been a correctly-functioning
289 * device sharing an IRQ with the failing one)
291 * Called under desc->lock
293 static void note_interrupt(int irq, irq_desc_t *desc, irqreturn_t action_ret)
295 if (action_ret != IRQ_HANDLED) {
296 desc->irqs_unhandled++;
297 if (action_ret != IRQ_NONE)
298 report_bad_irq(irq, desc, action_ret);
302 if (desc->irq_count < 100000)
306 if (desc->irqs_unhandled > 99900) {
308 * The interrupt is stuck
310 __report_bad_irq(irq, desc, action_ret);
314 printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
315 desc->status |= IRQ_DISABLED;
316 desc->handler->disable(irq);
318 desc->irqs_unhandled = 0;
322 * Generic enable/disable code: this just calls
323 * down into the PIC-specific version for the actual
324 * hardware disable after having gotten the irq
329 * disable_irq_nosync - disable an irq without waiting
330 * @irq: Interrupt to disable
332 * Disable the selected interrupt line. Disables and Enables are
334 * Unlike disable_irq(), this function does not ensure existing
335 * instances of the IRQ handler have completed before returning.
337 * This function may be called from IRQ context.
340 inline void disable_irq_nosync(unsigned int irq)
342 irq_desc_t *desc = irq_desc + irq;
345 spin_lock_irqsave(&desc->lock, flags);
346 if (!desc->depth++) {
347 desc->status |= IRQ_DISABLED;
348 desc->handler->disable(irq);
350 spin_unlock_irqrestore(&desc->lock, flags);
354 * disable_irq - disable an irq and wait for completion
355 * @irq: Interrupt to disable
357 * Disable the selected interrupt line. Enables and Disables are
359 * This function waits for any pending IRQ handlers for this interrupt
360 * to complete before returning. If you use this function while
361 * holding a resource the IRQ handler may need you will deadlock.
363 * This function may be called - with care - from IRQ context.
366 void disable_irq(unsigned int irq)
368 irq_desc_t *desc = irq_desc + irq;
369 disable_irq_nosync(irq);
371 synchronize_irq(irq);
375 * enable_irq - enable handling of an irq
376 * @irq: Interrupt to enable
378 * Undoes the effect of one call to disable_irq(). If this
379 * matches the last disable, processing of interrupts on this
380 * IRQ line is re-enabled.
382 * This function may be called from IRQ context.
385 void enable_irq(unsigned int irq)
387 irq_desc_t *desc = irq_desc + irq;
390 spin_lock_irqsave(&desc->lock, flags);
391 switch (desc->depth) {
393 unsigned int status = desc->status & ~IRQ_DISABLED;
394 desc->status = status;
395 if ((status & (IRQ_PENDING | IRQ_REPLAY)) == IRQ_PENDING) {
396 desc->status = status | IRQ_REPLAY;
397 hw_resend_irq(desc->handler,irq);
399 desc->handler->enable(irq);
406 printk("enable_irq(%u) unbalanced from %p\n", irq,
407 __builtin_return_address(0));
409 spin_unlock_irqrestore(&desc->lock, flags);
413 * do_IRQ handles all normal device IRQ's (the special
414 * SMP cross-CPU interrupts have their own specific
417 asmlinkage unsigned int do_IRQ(struct pt_regs regs)
420 * We ack quickly, we don't want the irq controller
421 * thinking we're snobs just because some other CPU has
422 * disabled global interrupts (we have already done the
423 * INT_ACK cycles, it's too late to try to pretend to the
424 * controller that we aren't taking the interrupt).
426 * 0 return value means that this irq is already being
427 * handled by some other CPU. (or is disabled)
429 int irq = regs.orig_eax & 0xff; /* high bits used in ret_from_ code */
430 irq_desc_t *desc = irq_desc + irq;
431 struct irqaction * action;
436 #ifdef CONFIG_DEBUG_STACKOVERFLOW
437 /* Debugging check for stack overflow: is there less than 1KB free? */
441 __asm__ __volatile__("andl %%esp,%0" :
442 "=r" (esp) : "0" (THREAD_SIZE - 1));
443 if (unlikely(esp < (sizeof(struct thread_info) + STACK_WARN))) {
444 printk("do_IRQ: stack overflow: %ld\n",
445 esp - sizeof(struct thread_info));
450 kstat_this_cpu.irqs[irq]++;
451 spin_lock(&desc->lock);
452 desc->handler->ack(irq);
454 REPLAY is when Linux resends an IRQ that was dropped earlier
455 WAITING is used by probe to mark irqs that are being tested
457 status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
458 status |= IRQ_PENDING; /* we _want_ to handle it */
461 * If the IRQ is disabled for whatever reason, we cannot
462 * use the action we have.
465 if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
466 action = desc->action;
467 status &= ~IRQ_PENDING; /* we commit to handling */
468 status |= IRQ_INPROGRESS; /* we are handling it */
470 desc->status = status;
473 * If there is no IRQ handler or it was disabled, exit early.
474 Since we set PENDING, if another processor is handling
475 a different instance of this same irq, the other processor
476 will take care of it.
478 if (unlikely(!action))
482 * Edge triggered interrupts need to remember
484 * This applies to any hw interrupts that allow a second
485 * instance of the same irq to arrive while we are in do_IRQ
486 * or in the handler. But the code here only handles the _second_
487 * instance of the irq, not the third or fourth. So it is mostly
488 * useful for irq hardware that does not mask cleanly in an
491 #ifdef CONFIG_4KSTACKS
494 irqreturn_t action_ret;
496 union irq_ctx * curctx;
497 union irq_ctx * irqctx;
499 curctx = (union irq_ctx *) current_thread_info();
500 irqctx = hardirq_ctx[smp_processor_id()];
502 spin_unlock(&desc->lock);
505 * this is where we switch to the IRQ stack. However, if we are already using
506 * the IRQ stack (because we interrupted a hardirq handler) we can't do that
507 * and just have to keep using the current stack (which is the irq stack already
511 if (curctx == irqctx)
512 action_ret = handle_IRQ_event(irq, ®s, action);
514 /* build the stack frame on the IRQ stack */
515 isp = (u32*) ((char*)irqctx + sizeof(*irqctx));
516 irqctx->tinfo.task = curctx->tinfo.task;
517 irqctx->tinfo.previous_esp = current_stack_pointer();
519 *--isp = (u32) action;
520 *--isp = (u32) ®s;
524 " xchgl %%ebx,%%esp \n"
525 " call handle_IRQ_event \n"
526 " xchgl %%ebx,%%esp \n"
529 : "memory", "cc", "edx", "ecx"
534 spin_lock(&desc->lock);
536 note_interrupt(irq, desc, action_ret);
537 if (curctx != irqctx)
538 irqctx->tinfo.task = NULL;
539 if (likely(!(desc->status & IRQ_PENDING)))
541 desc->status &= ~IRQ_PENDING;
547 irqreturn_t action_ret;
549 spin_unlock(&desc->lock);
551 action_ret = handle_IRQ_event(irq, ®s, action);
553 spin_lock(&desc->lock);
555 note_interrupt(irq, desc, action_ret);
556 if (likely(!(desc->status & IRQ_PENDING)))
558 desc->status &= ~IRQ_PENDING;
561 desc->status &= ~IRQ_INPROGRESS;
565 * The ->end() handler has to deal with interrupts which got
566 * disabled while the handler was running.
568 desc->handler->end(irq);
569 spin_unlock(&desc->lock);
576 int can_request_irq(unsigned int irq, unsigned long irqflags)
578 struct irqaction *action;
582 action = irq_desc[irq].action;
584 if (irqflags & action->flags & SA_SHIRQ)
591 * request_irq - allocate an interrupt line
592 * @irq: Interrupt line to allocate
593 * @handler: Function to be called when the IRQ occurs
594 * @irqflags: Interrupt type flags
595 * @devname: An ascii name for the claiming device
596 * @dev_id: A cookie passed back to the handler function
598 * This call allocates interrupt resources and enables the
599 * interrupt line and IRQ handling. From the point this
600 * call is made your handler function may be invoked. Since
601 * your handler function must clear any interrupt the board
602 * raises, you must take care both to initialise your hardware
603 * and to set up the interrupt handler in the right order.
605 * Dev_id must be globally unique. Normally the address of the
606 * device data structure is used as the cookie. Since the handler
607 * receives this value it makes sense to use it.
609 * If your interrupt is shared you must pass a non NULL dev_id
610 * as this is required when freeing the interrupt.
614 * SA_SHIRQ Interrupt is shared
616 * SA_INTERRUPT Disable local interrupts while processing
618 * SA_SAMPLE_RANDOM The interrupt can be used for entropy
622 int request_irq(unsigned int irq,
623 irqreturn_t (*handler)(int, void *, struct pt_regs *),
624 unsigned long irqflags,
625 const char * devname,
629 struct irqaction * action;
633 * Sanity-check: shared interrupts should REALLY pass in
634 * a real dev-ID, otherwise we'll have trouble later trying
635 * to figure out which interrupt is which (messes up the
636 * interrupt freeing logic etc).
638 if (irqflags & SA_SHIRQ) {
640 printk("Bad boy: %s (at 0x%x) called us without a dev_id!\n", devname, (&irq)[-1]);
649 action = (struct irqaction *)
650 kmalloc(sizeof(struct irqaction), GFP_ATOMIC);
654 action->handler = handler;
655 action->flags = irqflags;
657 action->name = devname;
659 action->dev_id = dev_id;
661 retval = setup_irq(irq, action);
667 EXPORT_SYMBOL(request_irq);
670 * free_irq - free an interrupt
671 * @irq: Interrupt line to free
672 * @dev_id: Device identity to free
674 * Remove an interrupt handler. The handler is removed and if the
675 * interrupt line is no longer in use by any driver it is disabled.
676 * On a shared IRQ the caller must ensure the interrupt is disabled
677 * on the card it drives before calling this function. The function
678 * does not return until any executing interrupts for this IRQ
681 * This function must not be called from interrupt context.
684 void free_irq(unsigned int irq, void *dev_id)
687 struct irqaction **p;
693 desc = irq_desc + irq;
694 spin_lock_irqsave(&desc->lock,flags);
697 struct irqaction * action = *p;
699 struct irqaction **pp = p;
701 if (action->dev_id != dev_id)
704 /* Found it - now remove it from the list of entries */
707 desc->status |= IRQ_DISABLED;
708 desc->handler->shutdown(irq);
710 spin_unlock_irqrestore(&desc->lock,flags);
712 /* Wait to make sure it's not being used on another CPU */
713 synchronize_irq(irq);
717 printk("Trying to free free IRQ%d\n",irq);
718 spin_unlock_irqrestore(&desc->lock,flags);
723 EXPORT_SYMBOL(free_irq);
726 * IRQ autodetection code..
728 * This depends on the fact that any interrupt that
729 * comes in on to an unassigned handler will get stuck
730 * with "IRQ_WAITING" cleared and the interrupt
734 static DECLARE_MUTEX(probe_sem);
737 * probe_irq_on - begin an interrupt autodetect
739 * Commence probing for an interrupt. The interrupts are scanned
740 * and a mask of potential interrupt lines is returned.
744 unsigned long probe_irq_on(void)
753 * something may have generated an irq long ago and we want to
754 * flush such a longstanding irq before considering it as spurious.
756 for (i = NR_IRQS-1; i > 0; i--) {
759 spin_lock_irq(&desc->lock);
760 if (!irq_desc[i].action)
761 irq_desc[i].handler->startup(i);
762 spin_unlock_irq(&desc->lock);
765 /* Wait for longstanding interrupts to trigger. */
766 for (delay = jiffies + HZ/50; time_after(delay, jiffies); )
767 /* about 20ms delay */ barrier();
770 * enable any unassigned irqs
771 * (we must startup again here because if a longstanding irq
772 * happened in the previous stage, it may have masked itself)
774 for (i = NR_IRQS-1; i > 0; i--) {
777 spin_lock_irq(&desc->lock);
779 desc->status |= IRQ_AUTODETECT | IRQ_WAITING;
780 if (desc->handler->startup(i))
781 desc->status |= IRQ_PENDING;
783 spin_unlock_irq(&desc->lock);
787 * Wait for spurious interrupts to trigger
789 for (delay = jiffies + HZ/10; time_after(delay, jiffies); )
790 /* about 100ms delay */ barrier();
793 * Now filter out any obviously spurious interrupts
796 for (i = 0; i < NR_IRQS; i++) {
797 irq_desc_t *desc = irq_desc + i;
800 spin_lock_irq(&desc->lock);
801 status = desc->status;
803 if (status & IRQ_AUTODETECT) {
804 /* It triggered already - consider it spurious. */
805 if (!(status & IRQ_WAITING)) {
806 desc->status = status & ~IRQ_AUTODETECT;
807 desc->handler->shutdown(i);
812 spin_unlock_irq(&desc->lock);
818 EXPORT_SYMBOL(probe_irq_on);
821 * Return a mask of triggered interrupts (this
822 * can handle only legacy ISA interrupts).
826 * probe_irq_mask - scan a bitmap of interrupt lines
827 * @val: mask of interrupts to consider
829 * Scan the ISA bus interrupt lines and return a bitmap of
830 * active interrupts. The interrupt probe logic state is then
831 * returned to its previous value.
833 * Note: we need to scan all the irq's even though we will
834 * only return ISA irq numbers - just so that we reset them
835 * all to a known state.
837 unsigned int probe_irq_mask(unsigned long val)
843 for (i = 0; i < NR_IRQS; i++) {
844 irq_desc_t *desc = irq_desc + i;
847 spin_lock_irq(&desc->lock);
848 status = desc->status;
850 if (status & IRQ_AUTODETECT) {
851 if (i < 16 && !(status & IRQ_WAITING))
854 desc->status = status & ~IRQ_AUTODETECT;
855 desc->handler->shutdown(i);
857 spin_unlock_irq(&desc->lock);
865 * Return the one interrupt that triggered (this can
866 * handle any interrupt source).
870 * probe_irq_off - end an interrupt autodetect
871 * @val: mask of potential interrupts (unused)
873 * Scans the unused interrupt lines and returns the line which
874 * appears to have triggered the interrupt. If no interrupt was
875 * found then zero is returned. If more than one interrupt is
876 * found then minus the first candidate is returned to indicate
879 * The interrupt probe logic state is returned to its previous
882 * BUGS: When used in a module (which arguably shouldnt happen)
883 * nothing prevents two IRQ probe callers from overlapping. The
884 * results of this are non-optimal.
887 int probe_irq_off(unsigned long val)
889 int i, irq_found, nr_irqs;
893 for (i = 0; i < NR_IRQS; i++) {
894 irq_desc_t *desc = irq_desc + i;
897 spin_lock_irq(&desc->lock);
898 status = desc->status;
900 if (status & IRQ_AUTODETECT) {
901 if (!(status & IRQ_WAITING)) {
906 desc->status = status & ~IRQ_AUTODETECT;
907 desc->handler->shutdown(i);
909 spin_unlock_irq(&desc->lock);
914 irq_found = -irq_found;
918 EXPORT_SYMBOL(probe_irq_off);
920 /* this was setup_x86_irq but it seems pretty generic */
921 int setup_irq(unsigned int irq, struct irqaction * new)
925 struct irqaction *old, **p;
926 irq_desc_t *desc = irq_desc + irq;
928 if (desc->handler == &no_irq_type)
931 * Some drivers like serial.c use request_irq() heavily,
932 * so we have to be careful not to interfere with a
935 if (new->flags & SA_SAMPLE_RANDOM) {
937 * This function might sleep, we want to call it first,
938 * outside of the atomic block.
939 * Yes, this might clear the entropy pool if the wrong
940 * driver is attempted to be loaded, without actually
941 * installing a new handler, but is this really a problem,
942 * only the sysadmin is able to do this.
944 rand_initialize_irq(irq);
948 * The following block of code has to be executed atomically
950 spin_lock_irqsave(&desc->lock,flags);
952 if ((old = *p) != NULL) {
953 /* Can't share interrupts unless both agree to */
954 if (!(old->flags & new->flags & SA_SHIRQ)) {
955 spin_unlock_irqrestore(&desc->lock,flags);
959 /* add new interrupt at end of irq queue */
971 desc->status &= ~(IRQ_DISABLED | IRQ_AUTODETECT | IRQ_WAITING | IRQ_INPROGRESS);
972 desc->handler->startup(irq);
974 spin_unlock_irqrestore(&desc->lock,flags);
976 register_irq_proc(irq);
980 static struct proc_dir_entry * root_irq_dir;
981 static struct proc_dir_entry * irq_dir [NR_IRQS];
985 static struct proc_dir_entry *smp_affinity_entry[NR_IRQS];
987 cpumask_t irq_affinity[NR_IRQS] = { [0 ... NR_IRQS-1] = CPU_MASK_ALL };
989 static int irq_affinity_read_proc(char *page, char **start, off_t off,
990 int count, int *eof, void *data)
992 int len = cpumask_scnprintf(page, count, irq_affinity[(long)data]);
995 len += sprintf(page + len, "\n");
999 static int irq_affinity_write_proc(struct file *file, const char __user *buffer,
1000 unsigned long count, void *data)
1002 int irq = (long)data, full_count = count, err;
1003 cpumask_t new_value, tmp;
1005 if (!irq_desc[irq].handler->set_affinity)
1008 err = cpumask_parse(buffer, count, new_value);
1013 * Do not allow disabling IRQs completely - it's a too easy
1014 * way to make the system unusable accidentally :-) At least
1015 * one online CPU still has to be targeted.
1017 cpus_and(tmp, new_value, cpu_online_map);
1018 if (cpus_empty(tmp))
1021 irq_affinity[irq] = new_value;
1022 irq_desc[irq].handler->set_affinity(irq,
1023 cpumask_of_cpu(first_cpu(new_value)));
1030 static int prof_cpu_mask_read_proc (char *page, char **start, off_t off,
1031 int count, int *eof, void *data)
1033 int len = cpumask_scnprintf(page, count, *(cpumask_t *)data);
1034 if (count - len < 2)
1036 len += sprintf(page + len, "\n");
1040 static int prof_cpu_mask_write_proc (struct file *file, const char __user *buffer,
1041 unsigned long count, void *data)
1043 cpumask_t *mask = (cpumask_t *)data;
1044 unsigned long full_count = count, err;
1045 cpumask_t new_value;
1047 err = cpumask_parse(buffer, count, new_value);
1055 #define MAX_NAMELEN 10
1057 static void register_irq_proc (unsigned int irq)
1059 char name [MAX_NAMELEN];
1061 if (!root_irq_dir || (irq_desc[irq].handler == &no_irq_type) ||
1065 memset(name, 0, MAX_NAMELEN);
1066 sprintf(name, "%d", irq);
1068 /* create /proc/irq/1234 */
1069 irq_dir[irq] = proc_mkdir(name, root_irq_dir);
1073 struct proc_dir_entry *entry;
1075 /* create /proc/irq/1234/smp_affinity */
1076 entry = create_proc_entry("smp_affinity", 0600, irq_dir[irq]);
1080 entry->data = (void *)(long)irq;
1081 entry->read_proc = irq_affinity_read_proc;
1082 entry->write_proc = irq_affinity_write_proc;
1085 smp_affinity_entry[irq] = entry;
1090 unsigned long prof_cpu_mask = -1;
1092 void init_irq_proc (void)
1094 struct proc_dir_entry *entry;
1097 /* create /proc/irq */
1098 root_irq_dir = proc_mkdir("irq", 0);
1100 /* create /proc/irq/prof_cpu_mask */
1101 entry = create_proc_entry("prof_cpu_mask", 0600, root_irq_dir);
1107 entry->data = (void *)&prof_cpu_mask;
1108 entry->read_proc = prof_cpu_mask_read_proc;
1109 entry->write_proc = prof_cpu_mask_write_proc;
1112 * Create entries for all existing IRQs.
1114 for (i = 0; i < NR_IRQS; i++)
1115 register_irq_proc(i);
1119 #ifdef CONFIG_4KSTACKS
1120 static char softirq_stack[NR_CPUS * THREAD_SIZE] __attribute__((__aligned__(THREAD_SIZE)));
1121 static char hardirq_stack[NR_CPUS * THREAD_SIZE] __attribute__((__aligned__(THREAD_SIZE)));
1124 * allocate per-cpu stacks for hardirq and for softirq processing
1126 void irq_ctx_init(int cpu)
1128 union irq_ctx *irqctx;
1130 if (hardirq_ctx[cpu])
1133 irqctx = (union irq_ctx*) &hardirq_stack[cpu*THREAD_SIZE];
1134 irqctx->tinfo.task = NULL;
1135 irqctx->tinfo.exec_domain = NULL;
1136 irqctx->tinfo.cpu = cpu;
1137 irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
1138 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
1140 hardirq_ctx[cpu] = irqctx;
1142 irqctx = (union irq_ctx*) &softirq_stack[cpu*THREAD_SIZE];
1143 irqctx->tinfo.task = NULL;
1144 irqctx->tinfo.exec_domain = NULL;
1145 irqctx->tinfo.cpu = cpu;
1146 irqctx->tinfo.preempt_count = SOFTIRQ_OFFSET;
1147 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
1149 softirq_ctx[cpu] = irqctx;
1151 printk("CPU %u irqstacks, hard=%p soft=%p\n",
1152 cpu,hardirq_ctx[cpu],softirq_ctx[cpu]);
1155 extern asmlinkage void __do_softirq(void);
1157 asmlinkage void do_softirq(void)
1159 unsigned long flags;
1160 struct thread_info *curctx;
1161 union irq_ctx *irqctx;
1167 local_irq_save(flags);
1169 if (local_softirq_pending()) {
1170 curctx = current_thread_info();
1171 irqctx = softirq_ctx[smp_processor_id()];
1172 irqctx->tinfo.task = curctx->task;
1173 irqctx->tinfo.previous_esp = current_stack_pointer();
1175 /* build the stack frame on the softirq stack */
1176 isp = (u32*) ((char*)irqctx + sizeof(*irqctx));
1180 " xchgl %%ebx,%%esp \n"
1181 " call __do_softirq \n"
1182 " movl %%ebx,%%esp \n"
1185 : "memory", "cc", "edx", "ecx", "eax"
1189 local_irq_restore(flags);
1192 EXPORT_SYMBOL(do_softirq);