irq.c 6.3 KB

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