irq.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * linux/arch/sh/kernel/irq.c
  3. *
  4. * Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar
  5. *
  6. *
  7. * SuperH version: Copyright (C) 1999 Niibe Yutaka
  8. */
  9. #include <linux/irq.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/module.h>
  12. #include <linux/kernel_stat.h>
  13. #include <linux/seq_file.h>
  14. #include <linux/ftrace.h>
  15. #include <linux/delay.h>
  16. #include <linux/ratelimit.h>
  17. #include <asm/processor.h>
  18. #include <asm/machvec.h>
  19. #include <asm/uaccess.h>
  20. #include <asm/thread_info.h>
  21. #include <cpu/mmu_context.h>
  22. atomic_t irq_err_count;
  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, it doesn't deserve
  26. * a generic callback i think.
  27. */
  28. void ack_bad_irq(unsigned int irq)
  29. {
  30. atomic_inc(&irq_err_count);
  31. printk("unexpected IRQ trap at vector %02x\n", irq);
  32. }
  33. #if defined(CONFIG_PROC_FS)
  34. /*
  35. * /proc/interrupts printing for arch specific interrupts
  36. */
  37. int arch_show_interrupts(struct seq_file *p, int prec)
  38. {
  39. int j;
  40. seq_printf(p, "%*s: ", prec, "NMI");
  41. for_each_online_cpu(j)
  42. seq_printf(p, "%10u ", irq_stat[j].__nmi_count);
  43. seq_printf(p, " Non-maskable interrupts\n");
  44. seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
  45. return 0;
  46. }
  47. #endif
  48. #ifdef CONFIG_IRQSTACKS
  49. /*
  50. * per-CPU IRQ handling contexts (thread information and stack)
  51. */
  52. union irq_ctx {
  53. struct thread_info tinfo;
  54. u32 stack[THREAD_SIZE/sizeof(u32)];
  55. };
  56. static union irq_ctx *hardirq_ctx[NR_CPUS] __read_mostly;
  57. static union irq_ctx *softirq_ctx[NR_CPUS] __read_mostly;
  58. static char softirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
  59. static char hardirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
  60. static inline void handle_one_irq(unsigned int irq)
  61. {
  62. union irq_ctx *curctx, *irqctx;
  63. curctx = (union irq_ctx *)current_thread_info();
  64. irqctx = hardirq_ctx[smp_processor_id()];
  65. /*
  66. * this is where we switch to the IRQ stack. However, if we are
  67. * already using the IRQ stack (because we interrupted a hardirq
  68. * handler) we can't do that and just have to keep using the
  69. * current stack (which is the irq stack already after all)
  70. */
  71. if (curctx != irqctx) {
  72. u32 *isp;
  73. isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
  74. irqctx->tinfo.task = curctx->tinfo.task;
  75. irqctx->tinfo.previous_sp = current_stack_pointer;
  76. /*
  77. * Copy the softirq bits in preempt_count so that the
  78. * softirq checks work in the hardirq context.
  79. */
  80. irqctx->tinfo.preempt_count =
  81. (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
  82. (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
  83. __asm__ __volatile__ (
  84. "mov %0, r4 \n"
  85. "mov r15, r8 \n"
  86. "jsr @%1 \n"
  87. /* swith to the irq stack */
  88. " mov %2, r15 \n"
  89. /* restore the stack (ring zero) */
  90. "mov r8, r15 \n"
  91. : /* no outputs */
  92. : "r" (irq), "r" (generic_handle_irq), "r" (isp)
  93. : "memory", "r0", "r1", "r2", "r3", "r4",
  94. "r5", "r6", "r7", "r8", "t", "pr"
  95. );
  96. } else
  97. generic_handle_irq(irq);
  98. }
  99. /*
  100. * allocate per-cpu stacks for hardirq and for softirq processing
  101. */
  102. void irq_ctx_init(int cpu)
  103. {
  104. union irq_ctx *irqctx;
  105. if (hardirq_ctx[cpu])
  106. return;
  107. irqctx = (union irq_ctx *)&hardirq_stack[cpu * THREAD_SIZE];
  108. irqctx->tinfo.task = NULL;
  109. irqctx->tinfo.cpu = cpu;
  110. irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
  111. irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
  112. hardirq_ctx[cpu] = irqctx;
  113. irqctx = (union irq_ctx *)&softirq_stack[cpu * THREAD_SIZE];
  114. irqctx->tinfo.task = NULL;
  115. irqctx->tinfo.cpu = cpu;
  116. irqctx->tinfo.preempt_count = 0;
  117. irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
  118. softirq_ctx[cpu] = irqctx;
  119. printk("CPU %u irqstacks, hard=%p soft=%p\n",
  120. cpu, hardirq_ctx[cpu], softirq_ctx[cpu]);
  121. }
  122. void irq_ctx_exit(int cpu)
  123. {
  124. hardirq_ctx[cpu] = NULL;
  125. }
  126. void do_softirq_own_stack(void)
  127. {
  128. struct thread_info *curctx;
  129. union irq_ctx *irqctx;
  130. u32 *isp;
  131. curctx = current_thread_info();
  132. irqctx = softirq_ctx[smp_processor_id()];
  133. irqctx->tinfo.task = curctx->task;
  134. irqctx->tinfo.previous_sp = current_stack_pointer;
  135. /* build the stack frame on the softirq stack */
  136. isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
  137. __asm__ __volatile__ (
  138. "mov r15, r9 \n"
  139. "jsr @%0 \n"
  140. /* switch to the softirq stack */
  141. " mov %1, r15 \n"
  142. /* restore the thread stack */
  143. "mov r9, r15 \n"
  144. : /* no outputs */
  145. : "r" (__do_softirq), "r" (isp)
  146. : "memory", "r0", "r1", "r2", "r3", "r4",
  147. "r5", "r6", "r7", "r8", "r9", "r15", "t", "pr"
  148. );
  149. }
  150. #else
  151. static inline void handle_one_irq(unsigned int irq)
  152. {
  153. generic_handle_irq(irq);
  154. }
  155. #endif
  156. asmlinkage __irq_entry int do_IRQ(unsigned int irq, struct pt_regs *regs)
  157. {
  158. struct pt_regs *old_regs = set_irq_regs(regs);
  159. irq_enter();
  160. irq = irq_demux(irq_lookup(irq));
  161. if (irq != NO_IRQ_IGNORE) {
  162. handle_one_irq(irq);
  163. irq_finish(irq);
  164. }
  165. irq_exit();
  166. set_irq_regs(old_regs);
  167. return IRQ_HANDLED;
  168. }
  169. void __init init_IRQ(void)
  170. {
  171. plat_irq_setup();
  172. /* Perform the machine specific initialisation */
  173. if (sh_mv.mv_init_irq)
  174. sh_mv.mv_init_irq();
  175. intc_finalize();
  176. irq_ctx_init(smp_processor_id());
  177. }
  178. #ifdef CONFIG_HOTPLUG_CPU
  179. /*
  180. * The CPU has been marked offline. Migrate IRQs off this CPU. If
  181. * the affinity settings do not allow other CPUs, force them onto any
  182. * available CPU.
  183. */
  184. void migrate_irqs(void)
  185. {
  186. unsigned int irq, cpu = smp_processor_id();
  187. for_each_active_irq(irq) {
  188. struct irq_data *data = irq_get_irq_data(irq);
  189. if (irq_data_get_node(data) == cpu) {
  190. struct cpumask *mask = irq_data_get_affinity_mask(data);
  191. unsigned int newcpu = cpumask_any_and(mask,
  192. cpu_online_mask);
  193. if (newcpu >= nr_cpu_ids) {
  194. pr_info_ratelimited("IRQ%u no longer affine to CPU%u\n",
  195. irq, cpu);
  196. cpumask_setall(mask);
  197. }
  198. irq_set_affinity(irq, mask);
  199. }
  200. }
  201. }
  202. #endif