irq_32.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. /*
  2. * Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar
  3. *
  4. * This file contains the lowest level x86-specific interrupt
  5. * entry, irq-stacks and irq statistics code. All the remaining
  6. * irq logic is done by the generic kernel/irq/ code and
  7. * by the x86-specific irq controller code. (e.g. i8259.c and
  8. * io_apic.c.)
  9. */
  10. #include <linux/module.h>
  11. #include <linux/seq_file.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/kernel_stat.h>
  14. #include <linux/notifier.h>
  15. #include <linux/cpu.h>
  16. #include <linux/delay.h>
  17. #include <asm/apic.h>
  18. #include <asm/uaccess.h>
  19. DEFINE_PER_CPU_SHARED_ALIGNED(irq_cpustat_t, irq_stat);
  20. EXPORT_PER_CPU_SYMBOL(irq_stat);
  21. DEFINE_PER_CPU(struct pt_regs *, irq_regs);
  22. EXPORT_PER_CPU_SYMBOL(irq_regs);
  23. /*
  24. * 'what should we do if we get a hw irq event on an illegal vector'.
  25. * each architecture has to answer this themselves.
  26. */
  27. void ack_bad_irq(unsigned int irq)
  28. {
  29. printk(KERN_ERR "unexpected IRQ trap at vector %02x\n", irq);
  30. #ifdef CONFIG_X86_LOCAL_APIC
  31. /*
  32. * Currently unexpected vectors happen only on SMP and APIC.
  33. * We _must_ ack these because every local APIC has only N
  34. * irq slots per priority level, and a 'hanging, unacked' IRQ
  35. * holds up an irq slot - in excessive cases (when multiple
  36. * unexpected vectors occur) that might lock up the APIC
  37. * completely.
  38. * But only ack when the APIC is enabled -AK
  39. */
  40. if (cpu_has_apic)
  41. ack_APIC_irq();
  42. #endif
  43. }
  44. #ifdef CONFIG_4KSTACKS
  45. /*
  46. * per-CPU IRQ handling contexts (thread information and stack)
  47. */
  48. union irq_ctx {
  49. struct thread_info tinfo;
  50. u32 stack[THREAD_SIZE/sizeof(u32)];
  51. };
  52. static union irq_ctx *hardirq_ctx[NR_CPUS] __read_mostly;
  53. static union irq_ctx *softirq_ctx[NR_CPUS] __read_mostly;
  54. #endif
  55. /*
  56. * do_IRQ handles all normal device IRQ's (the special
  57. * SMP cross-CPU interrupts have their own specific
  58. * handlers).
  59. */
  60. fastcall unsigned int do_IRQ(struct pt_regs *regs)
  61. {
  62. struct pt_regs *old_regs;
  63. /* high bit used in ret_from_ code */
  64. int irq = ~regs->orig_eax;
  65. struct irq_desc *desc = irq_desc + irq;
  66. #ifdef CONFIG_4KSTACKS
  67. union irq_ctx *curctx, *irqctx;
  68. u32 *isp;
  69. #endif
  70. if (unlikely((unsigned)irq >= NR_IRQS)) {
  71. printk(KERN_EMERG "%s: cannot handle IRQ %d\n",
  72. __FUNCTION__, irq);
  73. BUG();
  74. }
  75. old_regs = set_irq_regs(regs);
  76. irq_enter();
  77. #ifdef CONFIG_DEBUG_STACKOVERFLOW
  78. /* Debugging check for stack overflow: is there less than 1KB free? */
  79. {
  80. long esp;
  81. __asm__ __volatile__("andl %%esp,%0" :
  82. "=r" (esp) : "0" (THREAD_SIZE - 1));
  83. if (unlikely(esp < (sizeof(struct thread_info) + STACK_WARN))) {
  84. printk("do_IRQ: stack overflow: %ld\n",
  85. esp - sizeof(struct thread_info));
  86. dump_stack();
  87. }
  88. }
  89. #endif
  90. #ifdef CONFIG_4KSTACKS
  91. curctx = (union irq_ctx *) current_thread_info();
  92. irqctx = hardirq_ctx[smp_processor_id()];
  93. /*
  94. * this is where we switch to the IRQ stack. However, if we are
  95. * already using the IRQ stack (because we interrupted a hardirq
  96. * handler) we can't do that and just have to keep using the
  97. * current stack (which is the irq stack already after all)
  98. */
  99. if (curctx != irqctx) {
  100. int arg1, arg2, ebx;
  101. /* build the stack frame on the IRQ stack */
  102. isp = (u32*) ((char*)irqctx + sizeof(*irqctx));
  103. irqctx->tinfo.task = curctx->tinfo.task;
  104. irqctx->tinfo.previous_esp = current_stack_pointer;
  105. /*
  106. * Copy the softirq bits in preempt_count so that the
  107. * softirq checks work in the hardirq context.
  108. */
  109. irqctx->tinfo.preempt_count =
  110. (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
  111. (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
  112. asm volatile(
  113. " xchgl %%ebx,%%esp \n"
  114. " call *%%edi \n"
  115. " movl %%ebx,%%esp \n"
  116. : "=a" (arg1), "=d" (arg2), "=b" (ebx)
  117. : "0" (irq), "1" (desc), "2" (isp),
  118. "D" (desc->handle_irq)
  119. : "memory", "cc"
  120. );
  121. } else
  122. #endif
  123. desc->handle_irq(irq, desc);
  124. irq_exit();
  125. set_irq_regs(old_regs);
  126. return 1;
  127. }
  128. #ifdef CONFIG_4KSTACKS
  129. static char softirq_stack[NR_CPUS * THREAD_SIZE]
  130. __attribute__((__section__(".bss.page_aligned")));
  131. static char hardirq_stack[NR_CPUS * THREAD_SIZE]
  132. __attribute__((__section__(".bss.page_aligned")));
  133. /*
  134. * allocate per-cpu stacks for hardirq and for softirq processing
  135. */
  136. void irq_ctx_init(int cpu)
  137. {
  138. union irq_ctx *irqctx;
  139. if (hardirq_ctx[cpu])
  140. return;
  141. irqctx = (union irq_ctx*) &hardirq_stack[cpu*THREAD_SIZE];
  142. irqctx->tinfo.task = NULL;
  143. irqctx->tinfo.exec_domain = NULL;
  144. irqctx->tinfo.cpu = cpu;
  145. irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
  146. irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
  147. hardirq_ctx[cpu] = irqctx;
  148. irqctx = (union irq_ctx*) &softirq_stack[cpu*THREAD_SIZE];
  149. irqctx->tinfo.task = NULL;
  150. irqctx->tinfo.exec_domain = NULL;
  151. irqctx->tinfo.cpu = cpu;
  152. irqctx->tinfo.preempt_count = 0;
  153. irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
  154. softirq_ctx[cpu] = irqctx;
  155. printk("CPU %u irqstacks, hard=%p soft=%p\n",
  156. cpu,hardirq_ctx[cpu],softirq_ctx[cpu]);
  157. }
  158. void irq_ctx_exit(int cpu)
  159. {
  160. hardirq_ctx[cpu] = NULL;
  161. }
  162. extern asmlinkage void __do_softirq(void);
  163. asmlinkage void do_softirq(void)
  164. {
  165. unsigned long flags;
  166. struct thread_info *curctx;
  167. union irq_ctx *irqctx;
  168. u32 *isp;
  169. if (in_interrupt())
  170. return;
  171. local_irq_save(flags);
  172. if (local_softirq_pending()) {
  173. curctx = current_thread_info();
  174. irqctx = softirq_ctx[smp_processor_id()];
  175. irqctx->tinfo.task = curctx->task;
  176. irqctx->tinfo.previous_esp = current_stack_pointer;
  177. /* build the stack frame on the softirq stack */
  178. isp = (u32*) ((char*)irqctx + sizeof(*irqctx));
  179. asm volatile(
  180. " xchgl %%ebx,%%esp \n"
  181. " call __do_softirq \n"
  182. " movl %%ebx,%%esp \n"
  183. : "=b"(isp)
  184. : "0"(isp)
  185. : "memory", "cc", "edx", "ecx", "eax"
  186. );
  187. /*
  188. * Shouldnt happen, we returned above if in_interrupt():
  189. */
  190. WARN_ON_ONCE(softirq_count());
  191. }
  192. local_irq_restore(flags);
  193. }
  194. #endif
  195. /*
  196. * Interrupt statistics:
  197. */
  198. atomic_t irq_err_count;
  199. /*
  200. * /proc/interrupts printing:
  201. */
  202. int show_interrupts(struct seq_file *p, void *v)
  203. {
  204. int i = *(loff_t *) v, j;
  205. struct irqaction * action;
  206. unsigned long flags;
  207. if (i == 0) {
  208. seq_printf(p, " ");
  209. for_each_online_cpu(j)
  210. seq_printf(p, "CPU%-8d",j);
  211. seq_putc(p, '\n');
  212. }
  213. if (i < NR_IRQS) {
  214. unsigned any_count = 0;
  215. spin_lock_irqsave(&irq_desc[i].lock, flags);
  216. #ifndef CONFIG_SMP
  217. any_count = kstat_irqs(i);
  218. #else
  219. for_each_online_cpu(j)
  220. any_count |= kstat_cpu(j).irqs[i];
  221. #endif
  222. action = irq_desc[i].action;
  223. if (!action && !any_count)
  224. goto skip;
  225. seq_printf(p, "%3d: ",i);
  226. #ifndef CONFIG_SMP
  227. seq_printf(p, "%10u ", kstat_irqs(i));
  228. #else
  229. for_each_online_cpu(j)
  230. seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
  231. #endif
  232. seq_printf(p, " %8s", irq_desc[i].chip->name);
  233. seq_printf(p, "-%-8s", irq_desc[i].name);
  234. if (action) {
  235. seq_printf(p, " %s", action->name);
  236. while ((action = action->next) != NULL)
  237. seq_printf(p, ", %s", action->name);
  238. }
  239. seq_putc(p, '\n');
  240. skip:
  241. spin_unlock_irqrestore(&irq_desc[i].lock, flags);
  242. } else if (i == NR_IRQS) {
  243. seq_printf(p, "NMI: ");
  244. for_each_online_cpu(j)
  245. seq_printf(p, "%10u ", nmi_count(j));
  246. seq_printf(p, " Non-maskable interrupts\n");
  247. #ifdef CONFIG_X86_LOCAL_APIC
  248. seq_printf(p, "LOC: ");
  249. for_each_online_cpu(j)
  250. seq_printf(p, "%10u ",
  251. per_cpu(irq_stat,j).apic_timer_irqs);
  252. seq_printf(p, " Local timer interrupts\n");
  253. #endif
  254. #ifdef CONFIG_SMP
  255. seq_printf(p, "RES: ");
  256. for_each_online_cpu(j)
  257. seq_printf(p, "%10u ",
  258. per_cpu(irq_stat,j).irq_resched_count);
  259. seq_printf(p, " Rescheduling interrupts\n");
  260. seq_printf(p, "CAL: ");
  261. for_each_online_cpu(j)
  262. seq_printf(p, "%10u ",
  263. per_cpu(irq_stat,j).irq_call_count);
  264. seq_printf(p, " function call interrupts\n");
  265. seq_printf(p, "TLB: ");
  266. for_each_online_cpu(j)
  267. seq_printf(p, "%10u ",
  268. per_cpu(irq_stat,j).irq_tlb_count);
  269. seq_printf(p, " TLB shootdowns\n");
  270. #endif
  271. seq_printf(p, "TRM: ");
  272. for_each_online_cpu(j)
  273. seq_printf(p, "%10u ",
  274. per_cpu(irq_stat,j).irq_thermal_count);
  275. seq_printf(p, " Thermal event interrupts\n");
  276. seq_printf(p, "SPU: ");
  277. for_each_online_cpu(j)
  278. seq_printf(p, "%10u ",
  279. per_cpu(irq_stat,j).irq_spurious_count);
  280. seq_printf(p, " Spurious interrupts\n");
  281. seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
  282. #if defined(CONFIG_X86_IO_APIC)
  283. seq_printf(p, "MIS: %10u\n", atomic_read(&irq_mis_count));
  284. #endif
  285. }
  286. return 0;
  287. }
  288. #ifdef CONFIG_HOTPLUG_CPU
  289. #include <mach_apic.h>
  290. void fixup_irqs(cpumask_t map)
  291. {
  292. unsigned int irq;
  293. static int warned;
  294. for (irq = 0; irq < NR_IRQS; irq++) {
  295. cpumask_t mask;
  296. if (irq == 2)
  297. continue;
  298. cpus_and(mask, irq_desc[irq].affinity, map);
  299. if (any_online_cpu(mask) == NR_CPUS) {
  300. printk("Breaking affinity for irq %i\n", irq);
  301. mask = map;
  302. }
  303. if (irq_desc[irq].chip->set_affinity)
  304. irq_desc[irq].chip->set_affinity(irq, mask);
  305. else if (irq_desc[irq].action && !(warned++))
  306. printk("Cannot set affinity for irq %i\n", irq);
  307. }
  308. #if 0
  309. barrier();
  310. /* Ingo Molnar says: "after the IO-APIC masks have been redirected
  311. [note the nop - the interrupt-enable boundary on x86 is two
  312. instructions from sti] - to flush out pending hardirqs and
  313. IPIs. After this point nothing is supposed to reach this CPU." */
  314. __asm__ __volatile__("sti; nop; cli");
  315. barrier();
  316. #else
  317. /* That doesn't seem sufficient. Give it 1ms. */
  318. local_irq_enable();
  319. mdelay(1);
  320. local_irq_disable();
  321. #endif
  322. }
  323. #endif