irq.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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 <asm/processor.h>
  17. #include <asm/machvec.h>
  18. #include <asm/uaccess.h>
  19. #include <asm/thread_info.h>
  20. #include <cpu/mmu_context.h>
  21. atomic_t irq_err_count;
  22. /*
  23. * 'what should we do if we get a hw irq event on an illegal vector'.
  24. * each architecture has to answer this themselves, it doesn't deserve
  25. * a generic callback i think.
  26. */
  27. void ack_bad_irq(unsigned int irq)
  28. {
  29. atomic_inc(&irq_err_count);
  30. printk("unexpected IRQ trap at vector %02x\n", irq);
  31. }
  32. #if defined(CONFIG_PROC_FS)
  33. /*
  34. * /proc/interrupts printing for arch specific interrupts
  35. */
  36. int arch_show_interrupts(struct seq_file *p, int prec)
  37. {
  38. int j;
  39. seq_printf(p, "%*s: ", prec, "NMI");
  40. for_each_online_cpu(j)
  41. seq_printf(p, "%10u ", irq_stat[j].__nmi_count);
  42. seq_printf(p, " Non-maskable interrupts\n");
  43. seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
  44. return 0;
  45. }
  46. #endif
  47. #ifdef CONFIG_IRQSTACKS
  48. /*
  49. * per-CPU IRQ handling contexts (thread information and stack)
  50. */
  51. union irq_ctx {
  52. struct thread_info tinfo;
  53. u32 stack[THREAD_SIZE/sizeof(u32)];
  54. };
  55. static union irq_ctx *hardirq_ctx[NR_CPUS] __read_mostly;
  56. static union irq_ctx *softirq_ctx[NR_CPUS] __read_mostly;
  57. static char softirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
  58. static char hardirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
  59. static inline void handle_one_irq(unsigned int irq)
  60. {
  61. union irq_ctx *curctx, *irqctx;
  62. curctx = (union irq_ctx *)current_thread_info();
  63. irqctx = hardirq_ctx[smp_processor_id()];
  64. /*
  65. * this is where we switch to the IRQ stack. However, if we are
  66. * already using the IRQ stack (because we interrupted a hardirq
  67. * handler) we can't do that and just have to keep using the
  68. * current stack (which is the irq stack already after all)
  69. */
  70. if (curctx != irqctx) {
  71. u32 *isp;
  72. isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
  73. irqctx->tinfo.task = curctx->tinfo.task;
  74. irqctx->tinfo.previous_sp = current_stack_pointer;
  75. /*
  76. * Copy the softirq bits in preempt_count so that the
  77. * softirq checks work in the hardirq context.
  78. */
  79. irqctx->tinfo.preempt_count =
  80. (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
  81. (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
  82. __asm__ __volatile__ (
  83. "mov %0, r4 \n"
  84. "mov r15, r8 \n"
  85. "jsr @%1 \n"
  86. /* swith to the irq stack */
  87. " mov %2, r15 \n"
  88. /* restore the stack (ring zero) */
  89. "mov r8, r15 \n"
  90. : /* no outputs */
  91. : "r" (irq), "r" (generic_handle_irq), "r" (isp)
  92. : "memory", "r0", "r1", "r2", "r3", "r4",
  93. "r5", "r6", "r7", "r8", "t", "pr"
  94. );
  95. } else
  96. generic_handle_irq(irq);
  97. }
  98. /*
  99. * allocate per-cpu stacks for hardirq and for softirq processing
  100. */
  101. void irq_ctx_init(int cpu)
  102. {
  103. union irq_ctx *irqctx;
  104. if (hardirq_ctx[cpu])
  105. return;
  106. irqctx = (union irq_ctx *)&hardirq_stack[cpu * THREAD_SIZE];
  107. irqctx->tinfo.task = NULL;
  108. irqctx->tinfo.exec_domain = 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.exec_domain = NULL;
  116. irqctx->tinfo.cpu = cpu;
  117. irqctx->tinfo.preempt_count = 0;
  118. irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
  119. softirq_ctx[cpu] = irqctx;
  120. printk("CPU %u irqstacks, hard=%p soft=%p\n",
  121. cpu, hardirq_ctx[cpu], softirq_ctx[cpu]);
  122. }
  123. void irq_ctx_exit(int cpu)
  124. {
  125. hardirq_ctx[cpu] = NULL;
  126. }
  127. asmlinkage void do_softirq(void)
  128. {
  129. unsigned long flags;
  130. struct thread_info *curctx;
  131. union irq_ctx *irqctx;
  132. u32 *isp;
  133. if (in_interrupt())
  134. return;
  135. local_irq_save(flags);
  136. if (local_softirq_pending()) {
  137. curctx = current_thread_info();
  138. irqctx = softirq_ctx[smp_processor_id()];
  139. irqctx->tinfo.task = curctx->task;
  140. irqctx->tinfo.previous_sp = current_stack_pointer;
  141. /* build the stack frame on the softirq stack */
  142. isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
  143. __asm__ __volatile__ (
  144. "mov r15, r9 \n"
  145. "jsr @%0 \n"
  146. /* switch to the softirq stack */
  147. " mov %1, r15 \n"
  148. /* restore the thread stack */
  149. "mov r9, r15 \n"
  150. : /* no outputs */
  151. : "r" (__do_softirq), "r" (isp)
  152. : "memory", "r0", "r1", "r2", "r3", "r4",
  153. "r5", "r6", "r7", "r8", "r9", "r15", "t", "pr"
  154. );
  155. /*
  156. * Shouldnt happen, we returned above if in_interrupt():
  157. */
  158. WARN_ON_ONCE(softirq_count());
  159. }
  160. local_irq_restore(flags);
  161. }
  162. #else
  163. static inline void handle_one_irq(unsigned int irq)
  164. {
  165. generic_handle_irq(irq);
  166. }
  167. #endif
  168. asmlinkage __irq_entry int do_IRQ(unsigned int irq, struct pt_regs *regs)
  169. {
  170. struct pt_regs *old_regs = set_irq_regs(regs);
  171. irq_enter();
  172. irq = irq_demux(irq_lookup(irq));
  173. if (irq != NO_IRQ_IGNORE) {
  174. handle_one_irq(irq);
  175. irq_finish(irq);
  176. }
  177. irq_exit();
  178. set_irq_regs(old_regs);
  179. return IRQ_HANDLED;
  180. }
  181. void __init init_IRQ(void)
  182. {
  183. plat_irq_setup();
  184. /* Perform the machine specific initialisation */
  185. if (sh_mv.mv_init_irq)
  186. sh_mv.mv_init_irq();
  187. intc_finalize();
  188. irq_ctx_init(smp_processor_id());
  189. }
  190. #ifdef CONFIG_SPARSE_IRQ
  191. int __init arch_probe_nr_irqs(void)
  192. {
  193. nr_irqs = sh_mv.mv_nr_irqs;
  194. return NR_IRQS_LEGACY;
  195. }
  196. #endif
  197. #ifdef CONFIG_HOTPLUG_CPU
  198. static void route_irq(struct irq_data *data, unsigned int irq, unsigned int cpu)
  199. {
  200. struct irq_desc *desc = irq_to_desc(irq);
  201. struct irq_chip *chip = irq_data_get_irq_chip(data);
  202. printk(KERN_INFO "IRQ%u: moving from cpu%u to cpu%u\n",
  203. irq, data->node, cpu);
  204. raw_spin_lock_irq(&desc->lock);
  205. chip->irq_set_affinity(data, cpumask_of(cpu), false);
  206. raw_spin_unlock_irq(&desc->lock);
  207. }
  208. /*
  209. * The CPU has been marked offline. Migrate IRQs off this CPU. If
  210. * the affinity settings do not allow other CPUs, force them onto any
  211. * available CPU.
  212. */
  213. void migrate_irqs(void)
  214. {
  215. unsigned int irq, cpu = smp_processor_id();
  216. for_each_active_irq(irq) {
  217. struct irq_data *data = irq_get_irq_data(irq);
  218. if (data->node == cpu) {
  219. unsigned int newcpu = cpumask_any_and(data->affinity,
  220. cpu_online_mask);
  221. if (newcpu >= nr_cpu_ids) {
  222. if (printk_ratelimit())
  223. printk(KERN_INFO "IRQ%u no longer affine to CPU%u\n",
  224. irq, cpu);
  225. cpumask_setall(data->affinity);
  226. newcpu = cpumask_any_and(data->affinity,
  227. cpu_online_mask);
  228. }
  229. route_irq(data, irq, newcpu);
  230. }
  231. }
  232. }
  233. #endif