irq.c 6.0 KB

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