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 union irq_ctx *hardirq_ctx[NR_CPUS];
81 union irq_ctx *softirq_ctx[NR_CPUS];
84 * Special irq handlers.
87 irqreturn_t no_action(int cpl, void *dev_id, struct pt_regs *regs)
91 * Generic no controller code
94 static void enable_none(unsigned int irq) { }
95 static unsigned int startup_none(unsigned int irq) { return 0; }
96 static void disable_none(unsigned int irq) { }
97 static void ack_none(unsigned int irq)
100 * 'what should we do if we get a hw irq event on an illegal vector'.
101 * each architecture has to answer this themselves, it doesn't deserve
102 * a generic callback i think.
105 printk("unexpected IRQ trap at vector %02x\n", irq);
106 #ifdef CONFIG_X86_LOCAL_APIC
108 * Currently unexpected vectors happen only on SMP and APIC.
109 * We _must_ ack these because every local APIC has only N
110 * irq slots per priority level, and a 'hanging, unacked' IRQ
111 * holds up an irq slot - in excessive cases (when multiple
112 * unexpected vectors occur) that might lock up the APIC
120 /* startup is the same as "enable", shutdown is same as "disable" */
121 #define shutdown_none disable_none
122 #define end_none enable_none
124 struct hw_interrupt_type no_irq_type = {
134 atomic_t irq_err_count;
135 #if defined(CONFIG_X86_IO_APIC) && defined(APIC_MISMATCH_DEBUG)
136 atomic_t irq_mis_count;
140 * Generic, controller-independent functions:
143 int show_interrupts(struct seq_file *p, void *v)
145 int i = *(loff_t *) v, j;
146 struct irqaction * action;
151 for (j=0; j<NR_CPUS; j++)
153 seq_printf(p, "CPU%d ",j);
158 spin_lock_irqsave(&irq_desc[i].lock, flags);
159 action = irq_desc[i].action;
162 seq_printf(p, "%3d: ",i);
164 seq_printf(p, "%10u ", kstat_irqs(i));
166 for (j = 0; j < NR_CPUS; j++)
168 seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
170 seq_printf(p, " %14s", irq_desc[i].handler->typename);
171 seq_printf(p, " %s", action->name);
173 for (action=action->next; action; action = action->next)
174 seq_printf(p, ", %s", action->name);
178 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
179 } else if (i == NR_IRQS) {
180 seq_printf(p, "NMI: ");
181 for (j = 0; j < NR_CPUS; j++)
183 seq_printf(p, "%10u ", nmi_count(j));
185 #ifdef CONFIG_X86_LOCAL_APIC
186 seq_printf(p, "LOC: ");
187 for (j = 0; j < NR_CPUS; j++)
189 seq_printf(p, "%10u ", irq_stat[j].apic_timer_irqs);
192 seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
193 #if defined(CONFIG_X86_IO_APIC) && defined(APIC_MISMATCH_DEBUG)
194 seq_printf(p, "MIS: %10u\n", atomic_read(&irq_mis_count));
204 inline void synchronize_irq(unsigned int irq)
206 while (irq_desc[irq].status & IRQ_INPROGRESS)
212 * This should really return information about whether
213 * we should do bottom half handling etc. Right now we
214 * end up _always_ checking the bottom half, which is a
215 * waste of time and is not what some drivers would
218 asmlinkage int handle_IRQ_event(unsigned int irq,
219 struct pt_regs *regs, struct irqaction *action)
221 int status = 1; /* Force the "do bottom halves" bit */
225 status |= action->flags;
226 retval |= action->handler(irq, action->dev_id, regs);
227 action = action->next;
229 if (status & SA_SAMPLE_RANDOM)
230 add_interrupt_randomness(irq);
235 static void __report_bad_irq(int irq, irq_desc_t *desc, irqreturn_t action_ret)
237 struct irqaction *action;
239 if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
240 printk(KERN_ERR "irq event %d: bogus return value %x\n",
243 printk(KERN_ERR "irq %d: nobody cared! (screaming interrupt?)\n", irq);
246 printk(KERN_ERR "handlers:\n");
247 action = desc->action;
249 printk(KERN_ERR "[<%p>]", action->handler);
250 print_symbol(" (%s)",
251 (unsigned long)action->handler);
253 action = action->next;
257 static void report_bad_irq(int irq, irq_desc_t *desc, irqreturn_t action_ret)
259 static int count = 100;
263 __report_bad_irq(irq, desc, action_ret);
267 static int noirqdebug;
269 static int __init noirqdebug_setup(char *str)
272 printk("IRQ lockup detection disabled\n");
276 __setup("noirqdebug", noirqdebug_setup);
279 * If 99,900 of the previous 100,000 interrupts have not been handled then
280 * assume that the IRQ is stuck in some manner. Drop a diagnostic and try to
283 * (The other 100-of-100,000 interrupts may have been a correctly-functioning
284 * device sharing an IRQ with the failing one)
286 * Called under desc->lock
288 static void note_interrupt(int irq, irq_desc_t *desc, irqreturn_t action_ret)
290 if (action_ret != IRQ_HANDLED) {
291 desc->irqs_unhandled++;
292 if (action_ret != IRQ_NONE)
293 report_bad_irq(irq, desc, action_ret);
297 if (desc->irq_count < 100000)
301 if (desc->irqs_unhandled > 99900) {
303 * The interrupt is stuck
305 __report_bad_irq(irq, desc, action_ret);
309 printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
310 desc->status |= IRQ_DISABLED;
311 desc->handler->disable(irq);
313 desc->irqs_unhandled = 0;
317 * Generic enable/disable code: this just calls
318 * down into the PIC-specific version for the actual
319 * hardware disable after having gotten the irq
324 * disable_irq_nosync - disable an irq without waiting
325 * @irq: Interrupt to disable
327 * Disable the selected interrupt line. Disables and Enables are
329 * Unlike disable_irq(), this function does not ensure existing
330 * instances of the IRQ handler have completed before returning.
332 * This function may be called from IRQ context.
335 inline void disable_irq_nosync(unsigned int irq)
337 irq_desc_t *desc = irq_desc + irq;
340 spin_lock_irqsave(&desc->lock, flags);
341 if (!desc->depth++) {
342 desc->status |= IRQ_DISABLED;
343 desc->handler->disable(irq);
345 spin_unlock_irqrestore(&desc->lock, flags);
349 * disable_irq - disable an irq and wait for completion
350 * @irq: Interrupt to disable
352 * Disable the selected interrupt line. Enables and Disables are
354 * This function waits for any pending IRQ handlers for this interrupt
355 * to complete before returning. If you use this function while
356 * holding a resource the IRQ handler may need you will deadlock.
358 * This function may be called - with care - from IRQ context.
361 void disable_irq(unsigned int irq)
363 irq_desc_t *desc = irq_desc + irq;
364 disable_irq_nosync(irq);
366 synchronize_irq(irq);
370 * enable_irq - enable handling of an irq
371 * @irq: Interrupt to enable
373 * Undoes the effect of one call to disable_irq(). If this
374 * matches the last disable, processing of interrupts on this
375 * IRQ line is re-enabled.
377 * This function may be called from IRQ context.
380 void enable_irq(unsigned int irq)
382 irq_desc_t *desc = irq_desc + irq;
385 spin_lock_irqsave(&desc->lock, flags);
386 switch (desc->depth) {
388 unsigned int status = desc->status & ~IRQ_DISABLED;
389 desc->status = status;
390 if ((status & (IRQ_PENDING | IRQ_REPLAY)) == IRQ_PENDING) {
391 desc->status = status | IRQ_REPLAY;
392 hw_resend_irq(desc->handler,irq);
394 desc->handler->enable(irq);
401 printk("enable_irq(%u) unbalanced from %p\n", irq,
402 __builtin_return_address(0));
404 spin_unlock_irqrestore(&desc->lock, flags);
408 * do_IRQ handles all normal device IRQ's (the special
409 * SMP cross-CPU interrupts have their own specific
412 asmlinkage unsigned int do_IRQ(struct pt_regs regs)
415 * We ack quickly, we don't want the irq controller
416 * thinking we're snobs just because some other CPU has
417 * disabled global interrupts (we have already done the
418 * INT_ACK cycles, it's too late to try to pretend to the
419 * controller that we aren't taking the interrupt).
421 * 0 return value means that this irq is already being
422 * handled by some other CPU. (or is disabled)
424 int irq = regs.orig_eax & 0xff; /* high bits used in ret_from_ code */
425 irq_desc_t *desc = irq_desc + irq;
426 struct irqaction * action;
431 #ifdef CONFIG_DEBUG_STACKOVERFLOW
432 /* Debugging check for stack overflow: is there less than 1KB free? */
436 __asm__ __volatile__("andl %%esp,%0" :
437 "=r" (esp) : "0" (THREAD_SIZE - 1));
438 if (unlikely(esp < (sizeof(struct thread_info) + STACK_WARN))) {
439 printk("do_IRQ: stack overflow: %ld\n",
440 esp - sizeof(struct thread_info));
445 kstat_this_cpu.irqs[irq]++;
446 spin_lock(&desc->lock);
447 desc->handler->ack(irq);
449 REPLAY is when Linux resends an IRQ that was dropped earlier
450 WAITING is used by probe to mark irqs that are being tested
452 status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
453 status |= IRQ_PENDING; /* we _want_ to handle it */
456 * If the IRQ is disabled for whatever reason, we cannot
457 * use the action we have.
460 if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
461 action = desc->action;
462 status &= ~IRQ_PENDING; /* we commit to handling */
463 status |= IRQ_INPROGRESS; /* we are handling it */
465 desc->status = status;
468 * If there is no IRQ handler or it was disabled, exit early.
469 Since we set PENDING, if another processor is handling
470 a different instance of this same irq, the other processor
471 will take care of it.
473 if (unlikely(!action))
477 * Edge triggered interrupts need to remember
479 * This applies to any hw interrupts that allow a second
480 * instance of the same irq to arrive while we are in do_IRQ
481 * or in the handler. But the code here only handles the _second_
482 * instance of the irq, not the third or fourth. So it is mostly
483 * useful for irq hardware that does not mask cleanly in an
488 irqreturn_t action_ret;
490 union irq_ctx * curctx;
491 union irq_ctx * irqctx;
493 curctx = (union irq_ctx *) current_thread_info();
494 irqctx = hardirq_ctx[smp_processor_id()];
496 spin_unlock(&desc->lock);
499 * this is where we switch to the IRQ stack. However, if we are already using
500 * the IRQ stack (because we interrupted a hardirq handler) we can't do that
501 * and just have to keep using the current stack (which is the irq stack already
505 if (curctx == irqctx)
506 action_ret = handle_IRQ_event(irq, ®s, action);
508 /* build the stack frame on the IRQ stack */
509 isp = (u32*) ((char*)irqctx + sizeof(*irqctx));
510 irqctx->tinfo.task = curctx->tinfo.task;
511 irqctx->tinfo.real_stack = curctx->tinfo.real_stack;
512 irqctx->tinfo.virtual_stack = curctx->tinfo.virtual_stack;
513 irqctx->tinfo.previous_esp = current_stack_pointer();
515 *--isp = (u32) action;
516 *--isp = (u32) ®s;
520 " xchgl %%ebx,%%esp \n"
521 " call handle_IRQ_event \n"
522 " xchgl %%ebx,%%esp \n"
525 : "memory", "cc", "edx", "ecx"
530 spin_lock(&desc->lock);
532 note_interrupt(irq, desc, action_ret);
533 if (curctx != irqctx)
534 irqctx->tinfo.task = NULL;
535 if (likely(!(desc->status & IRQ_PENDING)))
537 desc->status &= ~IRQ_PENDING;
540 desc->status &= ~IRQ_INPROGRESS;
544 * The ->end() handler has to deal with interrupts which got
545 * disabled while the handler was running.
547 desc->handler->end(irq);
548 spin_unlock(&desc->lock);
555 int can_request_irq(unsigned int irq, unsigned long irqflags)
557 struct irqaction *action;
561 action = irq_desc[irq].action;
563 if (irqflags & action->flags & SA_SHIRQ)
570 * request_irq - allocate an interrupt line
571 * @irq: Interrupt line to allocate
572 * @handler: Function to be called when the IRQ occurs
573 * @irqflags: Interrupt type flags
574 * @devname: An ascii name for the claiming device
575 * @dev_id: A cookie passed back to the handler function
577 * This call allocates interrupt resources and enables the
578 * interrupt line and IRQ handling. From the point this
579 * call is made your handler function may be invoked. Since
580 * your handler function must clear any interrupt the board
581 * raises, you must take care both to initialise your hardware
582 * and to set up the interrupt handler in the right order.
584 * Dev_id must be globally unique. Normally the address of the
585 * device data structure is used as the cookie. Since the handler
586 * receives this value it makes sense to use it.
588 * If your interrupt is shared you must pass a non NULL dev_id
589 * as this is required when freeing the interrupt.
593 * SA_SHIRQ Interrupt is shared
595 * SA_INTERRUPT Disable local interrupts while processing
597 * SA_SAMPLE_RANDOM The interrupt can be used for entropy
601 int request_irq(unsigned int irq,
602 irqreturn_t (*handler)(int, void *, struct pt_regs *),
603 unsigned long irqflags,
604 const char * devname,
608 struct irqaction * action;
612 * Sanity-check: shared interrupts should REALLY pass in
613 * a real dev-ID, otherwise we'll have trouble later trying
614 * to figure out which interrupt is which (messes up the
615 * interrupt freeing logic etc).
617 if (irqflags & SA_SHIRQ) {
619 printk("Bad boy: %s (at 0x%x) called us without a dev_id!\n", devname, (&irq)[-1]);
628 action = (struct irqaction *)
629 kmalloc(sizeof(struct irqaction), GFP_ATOMIC);
633 action->handler = handler;
634 action->flags = irqflags;
636 action->name = devname;
638 action->dev_id = dev_id;
640 retval = setup_irq(irq, action);
646 EXPORT_SYMBOL(request_irq);
649 * free_irq - free an interrupt
650 * @irq: Interrupt line to free
651 * @dev_id: Device identity to free
653 * Remove an interrupt handler. The handler is removed and if the
654 * interrupt line is no longer in use by any driver it is disabled.
655 * On a shared IRQ the caller must ensure the interrupt is disabled
656 * on the card it drives before calling this function. The function
657 * does not return until any executing interrupts for this IRQ
660 * This function must not be called from interrupt context.
663 void free_irq(unsigned int irq, void *dev_id)
666 struct irqaction **p;
672 desc = irq_desc + irq;
673 spin_lock_irqsave(&desc->lock,flags);
676 struct irqaction * action = *p;
678 struct irqaction **pp = p;
680 if (action->dev_id != dev_id)
683 /* Found it - now remove it from the list of entries */
686 desc->status |= IRQ_DISABLED;
687 desc->handler->shutdown(irq);
689 spin_unlock_irqrestore(&desc->lock,flags);
691 /* Wait to make sure it's not being used on another CPU */
692 synchronize_irq(irq);
696 printk("Trying to free free IRQ%d\n",irq);
697 spin_unlock_irqrestore(&desc->lock,flags);
702 EXPORT_SYMBOL(free_irq);
705 * IRQ autodetection code..
707 * This depends on the fact that any interrupt that
708 * comes in on to an unassigned handler will get stuck
709 * with "IRQ_WAITING" cleared and the interrupt
713 static DECLARE_MUTEX(probe_sem);
716 * probe_irq_on - begin an interrupt autodetect
718 * Commence probing for an interrupt. The interrupts are scanned
719 * and a mask of potential interrupt lines is returned.
723 unsigned long probe_irq_on(void)
732 * something may have generated an irq long ago and we want to
733 * flush such a longstanding irq before considering it as spurious.
735 for (i = NR_IRQS-1; i > 0; i--) {
738 spin_lock_irq(&desc->lock);
739 if (!irq_desc[i].action)
740 irq_desc[i].handler->startup(i);
741 spin_unlock_irq(&desc->lock);
744 /* Wait for longstanding interrupts to trigger. */
745 for (delay = jiffies + HZ/50; time_after(delay, jiffies); )
746 /* about 20ms delay */ barrier();
749 * enable any unassigned irqs
750 * (we must startup again here because if a longstanding irq
751 * happened in the previous stage, it may have masked itself)
753 for (i = NR_IRQS-1; i > 0; i--) {
756 spin_lock_irq(&desc->lock);
758 desc->status |= IRQ_AUTODETECT | IRQ_WAITING;
759 if (desc->handler->startup(i))
760 desc->status |= IRQ_PENDING;
762 spin_unlock_irq(&desc->lock);
766 * Wait for spurious interrupts to trigger
768 for (delay = jiffies + HZ/10; time_after(delay, jiffies); )
769 /* about 100ms delay */ barrier();
772 * Now filter out any obviously spurious interrupts
775 for (i = 0; i < NR_IRQS; i++) {
776 irq_desc_t *desc = irq_desc + i;
779 spin_lock_irq(&desc->lock);
780 status = desc->status;
782 if (status & IRQ_AUTODETECT) {
783 /* It triggered already - consider it spurious. */
784 if (!(status & IRQ_WAITING)) {
785 desc->status = status & ~IRQ_AUTODETECT;
786 desc->handler->shutdown(i);
791 spin_unlock_irq(&desc->lock);
797 EXPORT_SYMBOL(probe_irq_on);
800 * Return a mask of triggered interrupts (this
801 * can handle only legacy ISA interrupts).
805 * probe_irq_mask - scan a bitmap of interrupt lines
806 * @val: mask of interrupts to consider
808 * Scan the ISA bus interrupt lines and return a bitmap of
809 * active interrupts. The interrupt probe logic state is then
810 * returned to its previous value.
812 * Note: we need to scan all the irq's even though we will
813 * only return ISA irq numbers - just so that we reset them
814 * all to a known state.
816 unsigned int probe_irq_mask(unsigned long val)
822 for (i = 0; i < NR_IRQS; i++) {
823 irq_desc_t *desc = irq_desc + i;
826 spin_lock_irq(&desc->lock);
827 status = desc->status;
829 if (status & IRQ_AUTODETECT) {
830 if (i < 16 && !(status & IRQ_WAITING))
833 desc->status = status & ~IRQ_AUTODETECT;
834 desc->handler->shutdown(i);
836 spin_unlock_irq(&desc->lock);
844 * Return the one interrupt that triggered (this can
845 * handle any interrupt source).
849 * probe_irq_off - end an interrupt autodetect
850 * @val: mask of potential interrupts (unused)
852 * Scans the unused interrupt lines and returns the line which
853 * appears to have triggered the interrupt. If no interrupt was
854 * found then zero is returned. If more than one interrupt is
855 * found then minus the first candidate is returned to indicate
858 * The interrupt probe logic state is returned to its previous
861 * BUGS: When used in a module (which arguably shouldnt happen)
862 * nothing prevents two IRQ probe callers from overlapping. The
863 * results of this are non-optimal.
866 int probe_irq_off(unsigned long val)
868 int i, irq_found, nr_irqs;
872 for (i = 0; i < NR_IRQS; i++) {
873 irq_desc_t *desc = irq_desc + i;
876 spin_lock_irq(&desc->lock);
877 status = desc->status;
879 if (status & IRQ_AUTODETECT) {
880 if (!(status & IRQ_WAITING)) {
885 desc->status = status & ~IRQ_AUTODETECT;
886 desc->handler->shutdown(i);
888 spin_unlock_irq(&desc->lock);
893 irq_found = -irq_found;
897 EXPORT_SYMBOL(probe_irq_off);
899 /* this was setup_x86_irq but it seems pretty generic */
900 int setup_irq(unsigned int irq, struct irqaction * new)
904 struct irqaction *old, **p;
905 irq_desc_t *desc = irq_desc + irq;
907 if (desc->handler == &no_irq_type)
910 * Some drivers like serial.c use request_irq() heavily,
911 * so we have to be careful not to interfere with a
914 if (new->flags & SA_SAMPLE_RANDOM) {
916 * This function might sleep, we want to call it first,
917 * outside of the atomic block.
918 * Yes, this might clear the entropy pool if the wrong
919 * driver is attempted to be loaded, without actually
920 * installing a new handler, but is this really a problem,
921 * only the sysadmin is able to do this.
923 rand_initialize_irq(irq);
927 * The following block of code has to be executed atomically
929 spin_lock_irqsave(&desc->lock,flags);
931 if ((old = *p) != NULL) {
932 /* Can't share interrupts unless both agree to */
933 if (!(old->flags & new->flags & SA_SHIRQ)) {
934 spin_unlock_irqrestore(&desc->lock,flags);
938 /* add new interrupt at end of irq queue */
950 desc->status &= ~(IRQ_DISABLED | IRQ_AUTODETECT | IRQ_WAITING | IRQ_INPROGRESS);
951 desc->handler->startup(irq);
953 spin_unlock_irqrestore(&desc->lock,flags);
955 register_irq_proc(irq);
959 static struct proc_dir_entry * root_irq_dir;
960 static struct proc_dir_entry * irq_dir [NR_IRQS];
964 static struct proc_dir_entry *smp_affinity_entry[NR_IRQS];
966 cpumask_t irq_affinity[NR_IRQS] = { [0 ... NR_IRQS-1] = CPU_MASK_ALL };
968 static int irq_affinity_read_proc(char *page, char **start, off_t off,
969 int count, int *eof, void *data)
971 int len = cpumask_scnprintf(page, count, irq_affinity[(long)data]);
974 len += sprintf(page + len, "\n");
978 static int irq_affinity_write_proc(struct file *file, const char __user *buffer,
979 unsigned long count, void *data)
981 int irq = (long)data, full_count = count, err;
982 cpumask_t new_value, tmp;
984 if (!irq_desc[irq].handler->set_affinity)
987 err = cpumask_parse(buffer, count, new_value);
992 * Do not allow disabling IRQs completely - it's a too easy
993 * way to make the system unusable accidentally :-) At least
994 * one online CPU still has to be targeted.
996 cpus_and(tmp, new_value, cpu_online_map);
1000 irq_affinity[irq] = new_value;
1001 irq_desc[irq].handler->set_affinity(irq,
1002 cpumask_of_cpu(first_cpu(new_value)));
1009 static int prof_cpu_mask_read_proc (char *page, char **start, off_t off,
1010 int count, int *eof, void *data)
1012 int len = cpumask_scnprintf(page, count, *(cpumask_t *)data);
1013 if (count - len < 2)
1015 len += sprintf(page + len, "\n");
1019 static int prof_cpu_mask_write_proc (struct file *file, const char __user *buffer,
1020 unsigned long count, void *data)
1022 cpumask_t *mask = (cpumask_t *)data;
1023 unsigned long full_count = count, err;
1024 cpumask_t new_value;
1026 err = cpumask_parse(buffer, count, new_value);
1034 #define MAX_NAMELEN 10
1036 static void register_irq_proc (unsigned int irq)
1038 char name [MAX_NAMELEN];
1040 if (!root_irq_dir || (irq_desc[irq].handler == &no_irq_type) ||
1044 memset(name, 0, MAX_NAMELEN);
1045 sprintf(name, "%d", irq);
1047 /* create /proc/irq/1234 */
1048 irq_dir[irq] = proc_mkdir(name, root_irq_dir);
1052 struct proc_dir_entry *entry;
1054 /* create /proc/irq/1234/smp_affinity */
1055 entry = create_proc_entry("smp_affinity", 0600, irq_dir[irq]);
1059 entry->data = (void *)(long)irq;
1060 entry->read_proc = irq_affinity_read_proc;
1061 entry->write_proc = irq_affinity_write_proc;
1064 smp_affinity_entry[irq] = entry;
1069 unsigned long prof_cpu_mask = -1;
1071 void init_irq_proc (void)
1073 struct proc_dir_entry *entry;
1076 /* create /proc/irq */
1077 root_irq_dir = proc_mkdir("irq", 0);
1079 /* create /proc/irq/prof_cpu_mask */
1080 entry = create_proc_entry("prof_cpu_mask", 0600, root_irq_dir);
1086 entry->data = (void *)&prof_cpu_mask;
1087 entry->read_proc = prof_cpu_mask_read_proc;
1088 entry->write_proc = prof_cpu_mask_write_proc;
1091 * Create entries for all existing IRQs.
1093 for (i = 0; i < NR_IRQS; i++)
1094 register_irq_proc(i);
1098 static char softirq_stack[NR_CPUS * THREAD_SIZE] __attribute__((__aligned__(THREAD_SIZE), __section__(".bss.page_aligned")));
1099 static char hardirq_stack[NR_CPUS * THREAD_SIZE] __attribute__((__aligned__(THREAD_SIZE), __section__(".bss.page_aligned")));
1102 * allocate per-cpu stacks for hardirq and for softirq processing
1104 void irq_ctx_init(int cpu)
1106 union irq_ctx *irqctx;
1108 if (hardirq_ctx[cpu])
1111 irqctx = (union irq_ctx*) &hardirq_stack[cpu*THREAD_SIZE];
1112 irqctx->tinfo.task = NULL;
1113 irqctx->tinfo.exec_domain = NULL;
1114 irqctx->tinfo.cpu = cpu;
1115 irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
1116 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
1118 hardirq_ctx[cpu] = irqctx;
1120 irqctx = (union irq_ctx*) &softirq_stack[cpu*THREAD_SIZE];
1121 irqctx->tinfo.task = NULL;
1122 irqctx->tinfo.exec_domain = NULL;
1123 irqctx->tinfo.cpu = cpu;
1124 irqctx->tinfo.preempt_count = SOFTIRQ_OFFSET;
1125 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
1127 softirq_ctx[cpu] = irqctx;
1129 printk("CPU %u irqstacks, hard=%p soft=%p\n",
1130 cpu,hardirq_ctx[cpu],softirq_ctx[cpu]);
1133 extern asmlinkage void __do_softirq(void);
1135 asmlinkage void do_softirq(void)
1137 unsigned long flags;
1138 struct thread_info *curctx;
1139 union irq_ctx *irqctx;
1145 local_irq_save(flags);
1147 if (local_softirq_pending()) {
1148 curctx = current_thread_info();
1149 irqctx = softirq_ctx[smp_processor_id()];
1150 irqctx->tinfo.task = curctx->task;
1151 irqctx->tinfo.real_stack = curctx->real_stack;
1152 irqctx->tinfo.virtual_stack = curctx->virtual_stack;
1153 irqctx->tinfo.previous_esp = current_stack_pointer();
1155 /* build the stack frame on the softirq stack */
1156 isp = (u32*) ((char*)irqctx + sizeof(*irqctx));
1160 " xchgl %%ebx,%%esp \n"
1161 " call __do_softirq \n"
1162 " movl %%ebx,%%esp \n"
1165 : "memory", "cc", "edx", "ecx", "eax"
1169 local_irq_restore(flags);
1172 EXPORT_SYMBOL(do_softirq);