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/delay.h>
49 * Linux has a controller-independent x86 interrupt architecture.
50 * every controller has a 'controller-template', that is used
51 * by the main code to do the right thing. Each driver-visible
52 * interrupt source is transparently wired to the apropriate
53 * controller. Thus drivers need not be aware of the
54 * interrupt-controller.
56 * Various interrupt controllers we handle: 8259 PIC, SMP IO-APIC,
57 * PIIX4's internal 8259 PIC and SGI's Visual Workstation Cobalt (IO-)APIC.
58 * (IO-APICs assumed to be messaging to Pentium local-APICs)
60 * the code is designed to be easily extended with new/different
61 * interrupt controllers, without having to do assembly magic.
65 * Controller mappings for all interrupt sources:
67 irq_desc_t irq_desc[NR_IRQS] __cacheline_aligned = {
69 .handler = &no_irq_type,
70 .lock = SPIN_LOCK_UNLOCKED
74 static void register_irq_proc (unsigned int irq);
77 * per-CPU IRQ handling stacks
79 #ifdef CONFIG_4KSTACKS
80 union irq_ctx *hardirq_ctx[NR_CPUS];
81 union irq_ctx *softirq_ctx[NR_CPUS];
85 * Special irq handlers.
88 irqreturn_t no_action(int cpl, void *dev_id, struct pt_regs *regs)
92 * Generic no controller code
95 static void enable_none(unsigned int irq) { }
96 static unsigned int startup_none(unsigned int irq) { return 0; }
97 static void disable_none(unsigned int irq) { }
98 static void ack_none(unsigned int irq)
101 * 'what should we do if we get a hw irq event on an illegal vector'.
102 * each architecture has to answer this themselves, it doesn't deserve
103 * a generic callback i think.
106 printk("unexpected IRQ trap at vector %02x\n", irq);
107 #ifdef CONFIG_X86_LOCAL_APIC
109 * Currently unexpected vectors happen only on SMP and APIC.
110 * We _must_ ack these because every local APIC has only N
111 * irq slots per priority level, and a 'hanging, unacked' IRQ
112 * holds up an irq slot - in excessive cases (when multiple
113 * unexpected vectors occur) that might lock up the APIC
121 /* startup is the same as "enable", shutdown is same as "disable" */
122 #define shutdown_none disable_none
123 #define end_none enable_none
125 struct hw_interrupt_type no_irq_type = {
135 atomic_t irq_err_count;
136 #if defined(CONFIG_X86_IO_APIC) && defined(APIC_MISMATCH_DEBUG)
137 atomic_t irq_mis_count;
141 * Generic, controller-independent functions:
144 int show_interrupts(struct seq_file *p, void *v)
146 int i = *(loff_t *) v, j;
147 struct irqaction * action;
152 for (j=0; j<NR_CPUS; j++)
154 seq_printf(p, "CPU%d ",j);
159 spin_lock_irqsave(&irq_desc[i].lock, flags);
160 action = irq_desc[i].action;
163 seq_printf(p, "%3d: ",i);
165 seq_printf(p, "%10u ", kstat_irqs(i));
167 for (j = 0; j < NR_CPUS; j++)
169 seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
171 seq_printf(p, " %14s", irq_desc[i].handler->typename);
172 seq_printf(p, " %s", action->name);
174 for (action=action->next; action; action = action->next)
175 seq_printf(p, ", %s", action->name);
179 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
180 } else if (i == NR_IRQS) {
181 seq_printf(p, "NMI: ");
182 for (j = 0; j < NR_CPUS; j++)
184 seq_printf(p, "%10u ", nmi_count(j));
186 #ifdef CONFIG_X86_LOCAL_APIC
187 seq_printf(p, "LOC: ");
188 for (j = 0; j < NR_CPUS; j++)
190 seq_printf(p, "%10u ", irq_stat[j].apic_timer_irqs);
193 seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
194 #if defined(CONFIG_X86_IO_APIC) && defined(APIC_MISMATCH_DEBUG)
195 seq_printf(p, "MIS: %10u\n", atomic_read(&irq_mis_count));
205 inline void synchronize_irq(unsigned int irq)
207 while (irq_desc[irq].status & IRQ_INPROGRESS)
213 * This should really return information about whether
214 * we should do bottom half handling etc. Right now we
215 * end up _always_ checking the bottom half, which is a
216 * waste of time and is not what some drivers would
219 asmlinkage int handle_IRQ_event(unsigned int irq,
220 struct pt_regs *regs, struct irqaction *action)
222 int status = 1; /* Force the "do bottom halves" bit */
225 if (!(action->flags & SA_INTERRUPT))
229 status |= action->flags;
230 retval |= action->handler(irq, action->dev_id, regs);
231 action = action->next;
233 if (status & SA_SAMPLE_RANDOM)
234 add_interrupt_randomness(irq);
239 static void __report_bad_irq(int irq, irq_desc_t *desc, irqreturn_t action_ret)
241 struct irqaction *action;
243 if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
244 printk(KERN_ERR "irq event %d: bogus return value %x\n",
247 printk(KERN_ERR "irq %d: nobody cared!\n", irq);
250 printk(KERN_ERR "handlers:\n");
251 action = desc->action;
253 printk(KERN_ERR "[<%p>]", action->handler);
254 print_symbol(" (%s)",
255 (unsigned long)action->handler);
257 action = action->next;
261 static void report_bad_irq(int irq, irq_desc_t *desc, irqreturn_t action_ret)
263 static int count = 100;
267 __report_bad_irq(irq, desc, action_ret);
271 static int noirqdebug;
273 static int __init noirqdebug_setup(char *str)
276 printk("IRQ lockup detection disabled\n");
280 __setup("noirqdebug", noirqdebug_setup);
283 * If 99,900 of the previous 100,000 interrupts have not been handled then
284 * assume that the IRQ is stuck in some manner. Drop a diagnostic and try to
287 * (The other 100-of-100,000 interrupts may have been a correctly-functioning
288 * device sharing an IRQ with the failing one)
290 * Called under desc->lock
292 static void note_interrupt(int irq, irq_desc_t *desc, irqreturn_t action_ret)
294 if (action_ret != IRQ_HANDLED) {
295 desc->irqs_unhandled++;
296 if (action_ret != IRQ_NONE)
297 report_bad_irq(irq, desc, action_ret);
301 if (desc->irq_count < 100000)
305 if (desc->irqs_unhandled > 99900) {
307 * The interrupt is stuck
309 __report_bad_irq(irq, desc, action_ret);
313 printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
314 desc->status |= IRQ_DISABLED;
315 desc->handler->disable(irq);
317 desc->irqs_unhandled = 0;
321 * Generic enable/disable code: this just calls
322 * down into the PIC-specific version for the actual
323 * hardware disable after having gotten the irq
328 * disable_irq_nosync - disable an irq without waiting
329 * @irq: Interrupt to disable
331 * Disable the selected interrupt line. Disables and Enables are
333 * Unlike disable_irq(), this function does not ensure existing
334 * instances of the IRQ handler have completed before returning.
336 * This function may be called from IRQ context.
339 inline void disable_irq_nosync(unsigned int irq)
341 irq_desc_t *desc = irq_desc + irq;
344 spin_lock_irqsave(&desc->lock, flags);
345 if (!desc->depth++) {
346 desc->status |= IRQ_DISABLED;
347 desc->handler->disable(irq);
349 spin_unlock_irqrestore(&desc->lock, flags);
353 * disable_irq - disable an irq and wait for completion
354 * @irq: Interrupt to disable
356 * Disable the selected interrupt line. Enables and Disables are
358 * This function waits for any pending IRQ handlers for this interrupt
359 * to complete before returning. If you use this function while
360 * holding a resource the IRQ handler may need you will deadlock.
362 * This function may be called - with care - from IRQ context.
365 void disable_irq(unsigned int irq)
367 irq_desc_t *desc = irq_desc + irq;
368 disable_irq_nosync(irq);
370 synchronize_irq(irq);
374 * enable_irq - enable handling of an irq
375 * @irq: Interrupt to enable
377 * Undoes the effect of one call to disable_irq(). If this
378 * matches the last disable, processing of interrupts on this
379 * IRQ line is re-enabled.
381 * This function may be called from IRQ context.
384 void enable_irq(unsigned int irq)
386 irq_desc_t *desc = irq_desc + irq;
389 spin_lock_irqsave(&desc->lock, flags);
390 switch (desc->depth) {
392 unsigned int status = desc->status & ~IRQ_DISABLED;
393 desc->status = status;
394 if ((status & (IRQ_PENDING | IRQ_REPLAY)) == IRQ_PENDING) {
395 desc->status = status | IRQ_REPLAY;
396 hw_resend_irq(desc->handler,irq);
398 desc->handler->enable(irq);
405 printk("enable_irq(%u) unbalanced from %p\n", irq,
406 __builtin_return_address(0));
408 spin_unlock_irqrestore(&desc->lock, flags);
412 * do_IRQ handles all normal device IRQ's (the special
413 * SMP cross-CPU interrupts have their own specific
416 asmlinkage unsigned int do_IRQ(struct pt_regs regs)
419 * We ack quickly, we don't want the irq controller
420 * thinking we're snobs just because some other CPU has
421 * disabled global interrupts (we have already done the
422 * INT_ACK cycles, it's too late to try to pretend to the
423 * controller that we aren't taking the interrupt).
425 * 0 return value means that this irq is already being
426 * handled by some other CPU. (or is disabled)
428 int irq = regs.orig_eax & 0xff; /* high bits used in ret_from_ code */
429 irq_desc_t *desc = irq_desc + irq;
430 struct irqaction * action;
435 #ifdef CONFIG_DEBUG_STACKOVERFLOW
436 /* Debugging check for stack overflow: is there less than 1KB free? */
440 __asm__ __volatile__("andl %%esp,%0" :
441 "=r" (esp) : "0" (THREAD_SIZE - 1));
442 if (unlikely(esp < (sizeof(struct thread_info) + STACK_WARN))) {
443 printk("do_IRQ: stack overflow: %ld\n",
444 esp - sizeof(struct thread_info));
449 kstat_this_cpu.irqs[irq]++;
450 spin_lock(&desc->lock);
451 desc->handler->ack(irq);
453 REPLAY is when Linux resends an IRQ that was dropped earlier
454 WAITING is used by probe to mark irqs that are being tested
456 status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
457 status |= IRQ_PENDING; /* we _want_ to handle it */
460 * If the IRQ is disabled for whatever reason, we cannot
461 * use the action we have.
464 if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
465 action = desc->action;
466 status &= ~IRQ_PENDING; /* we commit to handling */
467 status |= IRQ_INPROGRESS; /* we are handling it */
469 desc->status = status;
472 * If there is no IRQ handler or it was disabled, exit early.
473 Since we set PENDING, if another processor is handling
474 a different instance of this same irq, the other processor
475 will take care of it.
477 if (unlikely(!action))
481 * Edge triggered interrupts need to remember
483 * This applies to any hw interrupts that allow a second
484 * instance of the same irq to arrive while we are in do_IRQ
485 * or in the handler. But the code here only handles the _second_
486 * instance of the irq, not the third or fourth. So it is mostly
487 * useful for irq hardware that does not mask cleanly in an
490 #ifdef CONFIG_4KSTACKS
493 irqreturn_t action_ret;
495 union irq_ctx * curctx;
496 union irq_ctx * irqctx;
498 curctx = (union irq_ctx *) current_thread_info();
499 irqctx = hardirq_ctx[smp_processor_id()];
501 spin_unlock(&desc->lock);
504 * this is where we switch to the IRQ stack. However, if we are already using
505 * the IRQ stack (because we interrupted a hardirq handler) we can't do that
506 * and just have to keep using the current stack (which is the irq stack already
510 if (curctx == irqctx)
511 action_ret = handle_IRQ_event(irq, ®s, action);
513 /* build the stack frame on the IRQ stack */
514 isp = (u32*) ((char*)irqctx + sizeof(*irqctx));
515 irqctx->tinfo.task = curctx->tinfo.task;
516 irqctx->tinfo.previous_esp = current_stack_pointer();
518 *--isp = (u32) action;
519 *--isp = (u32) ®s;
523 " xchgl %%ebx,%%esp \n"
524 " call handle_IRQ_event \n"
525 " xchgl %%ebx,%%esp \n"
528 : "memory", "cc", "edx", "ecx"
533 spin_lock(&desc->lock);
535 note_interrupt(irq, desc, action_ret);
536 if (curctx != irqctx)
537 irqctx->tinfo.task = NULL;
538 if (likely(!(desc->status & IRQ_PENDING)))
540 desc->status &= ~IRQ_PENDING;
546 irqreturn_t action_ret;
548 spin_unlock(&desc->lock);
550 action_ret = handle_IRQ_event(irq, ®s, action);
552 spin_lock(&desc->lock);
554 note_interrupt(irq, desc, action_ret);
555 if (likely(!(desc->status & IRQ_PENDING)))
557 desc->status &= ~IRQ_PENDING;
560 desc->status &= ~IRQ_INPROGRESS;
564 * The ->end() handler has to deal with interrupts which got
565 * disabled while the handler was running.
567 desc->handler->end(irq);
568 spin_unlock(&desc->lock);
575 int can_request_irq(unsigned int irq, unsigned long irqflags)
577 struct irqaction *action;
581 action = irq_desc[irq].action;
583 if (irqflags & action->flags & SA_SHIRQ)
590 * request_irq - allocate an interrupt line
591 * @irq: Interrupt line to allocate
592 * @handler: Function to be called when the IRQ occurs
593 * @irqflags: Interrupt type flags
594 * @devname: An ascii name for the claiming device
595 * @dev_id: A cookie passed back to the handler function
597 * This call allocates interrupt resources and enables the
598 * interrupt line and IRQ handling. From the point this
599 * call is made your handler function may be invoked. Since
600 * your handler function must clear any interrupt the board
601 * raises, you must take care both to initialise your hardware
602 * and to set up the interrupt handler in the right order.
604 * Dev_id must be globally unique. Normally the address of the
605 * device data structure is used as the cookie. Since the handler
606 * receives this value it makes sense to use it.
608 * If your interrupt is shared you must pass a non NULL dev_id
609 * as this is required when freeing the interrupt.
613 * SA_SHIRQ Interrupt is shared
615 * SA_INTERRUPT Disable local interrupts while processing
617 * SA_SAMPLE_RANDOM The interrupt can be used for entropy
621 int request_irq(unsigned int irq,
622 irqreturn_t (*handler)(int, void *, struct pt_regs *),
623 unsigned long irqflags,
624 const char * devname,
628 struct irqaction * action;
632 * Sanity-check: shared interrupts should REALLY pass in
633 * a real dev-ID, otherwise we'll have trouble later trying
634 * to figure out which interrupt is which (messes up the
635 * interrupt freeing logic etc).
637 if (irqflags & SA_SHIRQ) {
639 printk("Bad boy: %s (at 0x%x) called us without a dev_id!\n", devname, (&irq)[-1]);
648 action = (struct irqaction *)
649 kmalloc(sizeof(struct irqaction), GFP_ATOMIC);
653 action->handler = handler;
654 action->flags = irqflags;
655 cpus_clear(action->mask);
656 action->name = devname;
658 action->dev_id = dev_id;
660 retval = setup_irq(irq, action);
666 EXPORT_SYMBOL(request_irq);
669 * free_irq - free an interrupt
670 * @irq: Interrupt line to free
671 * @dev_id: Device identity to free
673 * Remove an interrupt handler. The handler is removed and if the
674 * interrupt line is no longer in use by any driver it is disabled.
675 * On a shared IRQ the caller must ensure the interrupt is disabled
676 * on the card it drives before calling this function. The function
677 * does not return until any executing interrupts for this IRQ
680 * This function must not be called from interrupt context.
683 void free_irq(unsigned int irq, void *dev_id)
686 struct irqaction **p;
692 desc = irq_desc + irq;
693 spin_lock_irqsave(&desc->lock,flags);
696 struct irqaction * action = *p;
698 struct irqaction **pp = p;
700 if (action->dev_id != dev_id)
703 /* Found it - now remove it from the list of entries */
706 desc->status |= IRQ_DISABLED;
707 desc->handler->shutdown(irq);
709 spin_unlock_irqrestore(&desc->lock,flags);
711 /* Wait to make sure it's not being used on another CPU */
712 synchronize_irq(irq);
716 printk("Trying to free free IRQ%d\n",irq);
717 spin_unlock_irqrestore(&desc->lock,flags);
722 EXPORT_SYMBOL(free_irq);
725 * IRQ autodetection code..
727 * This depends on the fact that any interrupt that
728 * comes in on to an unassigned handler will get stuck
729 * with "IRQ_WAITING" cleared and the interrupt
733 static DECLARE_MUTEX(probe_sem);
736 * probe_irq_on - begin an interrupt autodetect
738 * Commence probing for an interrupt. The interrupts are scanned
739 * and a mask of potential interrupt lines is returned.
743 unsigned long probe_irq_on(void)
752 * something may have generated an irq long ago and we want to
753 * flush such a longstanding irq before considering it as spurious.
755 for (i = NR_IRQS-1; i > 0; i--) {
758 spin_lock_irq(&desc->lock);
759 if (!irq_desc[i].action)
760 irq_desc[i].handler->startup(i);
761 spin_unlock_irq(&desc->lock);
764 /* Wait for longstanding interrupts to trigger. */
765 for (delay = jiffies + HZ/50; time_after(delay, jiffies); )
766 /* about 20ms delay */ barrier();
769 * enable any unassigned irqs
770 * (we must startup again here because if a longstanding irq
771 * happened in the previous stage, it may have masked itself)
773 for (i = NR_IRQS-1; i > 0; i--) {
776 spin_lock_irq(&desc->lock);
778 desc->status |= IRQ_AUTODETECT | IRQ_WAITING;
779 if (desc->handler->startup(i))
780 desc->status |= IRQ_PENDING;
782 spin_unlock_irq(&desc->lock);
786 * Wait for spurious interrupts to trigger
788 for (delay = jiffies + HZ/10; time_after(delay, jiffies); )
789 /* about 100ms delay */ barrier();
792 * Now filter out any obviously spurious interrupts
795 for (i = 0; i < NR_IRQS; i++) {
796 irq_desc_t *desc = irq_desc + i;
799 spin_lock_irq(&desc->lock);
800 status = desc->status;
802 if (status & IRQ_AUTODETECT) {
803 /* It triggered already - consider it spurious. */
804 if (!(status & IRQ_WAITING)) {
805 desc->status = status & ~IRQ_AUTODETECT;
806 desc->handler->shutdown(i);
811 spin_unlock_irq(&desc->lock);
817 EXPORT_SYMBOL(probe_irq_on);
820 * Return a mask of triggered interrupts (this
821 * can handle only legacy ISA interrupts).
825 * probe_irq_mask - scan a bitmap of interrupt lines
826 * @val: mask of interrupts to consider
828 * Scan the ISA bus interrupt lines and return a bitmap of
829 * active interrupts. The interrupt probe logic state is then
830 * returned to its previous value.
832 * Note: we need to scan all the irq's even though we will
833 * only return ISA irq numbers - just so that we reset them
834 * all to a known state.
836 unsigned int probe_irq_mask(unsigned long val)
842 for (i = 0; i < NR_IRQS; i++) {
843 irq_desc_t *desc = irq_desc + i;
846 spin_lock_irq(&desc->lock);
847 status = desc->status;
849 if (status & IRQ_AUTODETECT) {
850 if (i < 16 && !(status & IRQ_WAITING))
853 desc->status = status & ~IRQ_AUTODETECT;
854 desc->handler->shutdown(i);
856 spin_unlock_irq(&desc->lock);
864 * Return the one interrupt that triggered (this can
865 * handle any interrupt source).
869 * probe_irq_off - end an interrupt autodetect
870 * @val: mask of potential interrupts (unused)
872 * Scans the unused interrupt lines and returns the line which
873 * appears to have triggered the interrupt. If no interrupt was
874 * found then zero is returned. If more than one interrupt is
875 * found then minus the first candidate is returned to indicate
878 * The interrupt probe logic state is returned to its previous
881 * BUGS: When used in a module (which arguably shouldnt happen)
882 * nothing prevents two IRQ probe callers from overlapping. The
883 * results of this are non-optimal.
886 int probe_irq_off(unsigned long val)
888 int i, irq_found, nr_irqs;
892 for (i = 0; i < NR_IRQS; i++) {
893 irq_desc_t *desc = irq_desc + i;
896 spin_lock_irq(&desc->lock);
897 status = desc->status;
899 if (status & IRQ_AUTODETECT) {
900 if (!(status & IRQ_WAITING)) {
905 desc->status = status & ~IRQ_AUTODETECT;
906 desc->handler->shutdown(i);
908 spin_unlock_irq(&desc->lock);
913 irq_found = -irq_found;
917 EXPORT_SYMBOL(probe_irq_off);
919 /* this was setup_x86_irq but it seems pretty generic */
920 int setup_irq(unsigned int irq, struct irqaction * new)
924 struct irqaction *old, **p;
925 irq_desc_t *desc = irq_desc + irq;
927 if (desc->handler == &no_irq_type)
930 * Some drivers like serial.c use request_irq() heavily,
931 * so we have to be careful not to interfere with a
934 if (new->flags & SA_SAMPLE_RANDOM) {
936 * This function might sleep, we want to call it first,
937 * outside of the atomic block.
938 * Yes, this might clear the entropy pool if the wrong
939 * driver is attempted to be loaded, without actually
940 * installing a new handler, but is this really a problem,
941 * only the sysadmin is able to do this.
943 rand_initialize_irq(irq);
947 * The following block of code has to be executed atomically
949 spin_lock_irqsave(&desc->lock,flags);
951 if ((old = *p) != NULL) {
952 /* Can't share interrupts unless both agree to */
953 if (!(old->flags & new->flags & SA_SHIRQ)) {
954 spin_unlock_irqrestore(&desc->lock,flags);
958 /* add new interrupt at end of irq queue */
970 desc->status &= ~(IRQ_DISABLED | IRQ_AUTODETECT | IRQ_WAITING | IRQ_INPROGRESS);
971 desc->handler->startup(irq);
973 spin_unlock_irqrestore(&desc->lock,flags);
975 register_irq_proc(irq);
979 static struct proc_dir_entry * root_irq_dir;
980 static struct proc_dir_entry * irq_dir [NR_IRQS];
984 static struct proc_dir_entry *smp_affinity_entry[NR_IRQS];
986 cpumask_t irq_affinity[NR_IRQS] = { [0 ... NR_IRQS-1] = CPU_MASK_ALL };
988 static int irq_affinity_read_proc(char *page, char **start, off_t off,
989 int count, int *eof, void *data)
991 int len = cpumask_scnprintf(page, count, irq_affinity[(long)data]);
994 len += sprintf(page + len, "\n");
998 static int irq_affinity_write_proc(struct file *file, const char __user *buffer,
999 unsigned long count, void *data)
1001 int irq = (long)data, full_count = count, err;
1002 cpumask_t new_value, tmp;
1004 if (!irq_desc[irq].handler->set_affinity)
1007 err = cpumask_parse(buffer, count, 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 irq_affinity[irq] = new_value;
1021 irq_desc[irq].handler->set_affinity(irq,
1022 cpumask_of_cpu(first_cpu(new_value)));
1029 static int prof_cpu_mask_read_proc (char *page, char **start, off_t off,
1030 int count, int *eof, void *data)
1032 int len = cpumask_scnprintf(page, count, *(cpumask_t *)data);
1033 if (count - len < 2)
1035 len += sprintf(page + len, "\n");
1039 static int prof_cpu_mask_write_proc (struct file *file, const char __user *buffer,
1040 unsigned long count, void *data)
1042 cpumask_t *mask = (cpumask_t *)data;
1043 unsigned long full_count = count, err;
1044 cpumask_t new_value;
1046 err = cpumask_parse(buffer, count, new_value);
1054 #define MAX_NAMELEN 10
1056 static void register_irq_proc (unsigned int irq)
1058 char name [MAX_NAMELEN];
1060 if (!root_irq_dir || (irq_desc[irq].handler == &no_irq_type) ||
1064 memset(name, 0, MAX_NAMELEN);
1065 sprintf(name, "%d", irq);
1067 /* create /proc/irq/1234 */
1068 irq_dir[irq] = proc_mkdir(name, root_irq_dir);
1072 struct proc_dir_entry *entry;
1074 /* create /proc/irq/1234/smp_affinity */
1075 entry = create_proc_entry("smp_affinity", 0600, irq_dir[irq]);
1079 entry->data = (void *)(long)irq;
1080 entry->read_proc = irq_affinity_read_proc;
1081 entry->write_proc = irq_affinity_write_proc;
1084 smp_affinity_entry[irq] = entry;
1089 unsigned long prof_cpu_mask = -1;
1091 void init_irq_proc (void)
1093 struct proc_dir_entry *entry;
1096 /* create /proc/irq */
1097 root_irq_dir = proc_mkdir("irq", NULL);
1099 /* create /proc/irq/prof_cpu_mask */
1100 entry = create_proc_entry("prof_cpu_mask", 0600, root_irq_dir);
1106 entry->data = (void *)&prof_cpu_mask;
1107 entry->read_proc = prof_cpu_mask_read_proc;
1108 entry->write_proc = prof_cpu_mask_write_proc;
1111 * Create entries for all existing IRQs.
1113 for (i = 0; i < NR_IRQS; i++)
1114 register_irq_proc(i);
1118 #ifdef CONFIG_4KSTACKS
1120 * These should really be __section__(".bss.page_aligned") as well, but
1121 * gcc's 3.0 and earlier don't handle that correctly.
1123 static char softirq_stack[NR_CPUS * THREAD_SIZE] __attribute__((__aligned__(THREAD_SIZE)));
1124 static char hardirq_stack[NR_CPUS * THREAD_SIZE] __attribute__((__aligned__(THREAD_SIZE)));
1127 * allocate per-cpu stacks for hardirq and for softirq processing
1129 void irq_ctx_init(int cpu)
1131 union irq_ctx *irqctx;
1133 if (hardirq_ctx[cpu])
1136 irqctx = (union irq_ctx*) &hardirq_stack[cpu*THREAD_SIZE];
1137 irqctx->tinfo.task = NULL;
1138 irqctx->tinfo.exec_domain = NULL;
1139 irqctx->tinfo.cpu = cpu;
1140 irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
1141 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
1143 hardirq_ctx[cpu] = irqctx;
1145 irqctx = (union irq_ctx*) &softirq_stack[cpu*THREAD_SIZE];
1146 irqctx->tinfo.task = NULL;
1147 irqctx->tinfo.exec_domain = NULL;
1148 irqctx->tinfo.cpu = cpu;
1149 irqctx->tinfo.preempt_count = SOFTIRQ_OFFSET;
1150 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
1152 softirq_ctx[cpu] = irqctx;
1154 printk("CPU %u irqstacks, hard=%p soft=%p\n",
1155 cpu,hardirq_ctx[cpu],softirq_ctx[cpu]);
1158 extern asmlinkage void __do_softirq(void);
1160 asmlinkage void do_softirq(void)
1162 unsigned long flags;
1163 struct thread_info *curctx;
1164 union irq_ctx *irqctx;
1170 local_irq_save(flags);
1172 if (local_softirq_pending()) {
1173 curctx = current_thread_info();
1174 irqctx = softirq_ctx[smp_processor_id()];
1175 irqctx->tinfo.task = curctx->task;
1176 irqctx->tinfo.previous_esp = current_stack_pointer();
1178 /* build the stack frame on the softirq stack */
1179 isp = (u32*) ((char*)irqctx + sizeof(*irqctx));
1183 " xchgl %%ebx,%%esp \n"
1184 " call __do_softirq \n"
1185 " movl %%ebx,%%esp \n"
1188 : "memory", "cc", "edx", "ecx", "eax"
1192 local_irq_restore(flags);
1195 EXPORT_SYMBOL(do_softirq);