irq.c 6.5 KB

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