irq.c 6.0 KB

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