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