irq.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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/irq.h>
  15. #include <asm/processor.h>
  16. #include <asm/machvec.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 < sh_mv.mv_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 == sh_mv.mv_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 int irq, struct pt_regs *regs)
  76. {
  77. struct pt_regs *old_regs = set_irq_regs(regs);
  78. #ifdef CONFIG_4KSTACKS
  79. union irq_ctx *curctx, *irqctx;
  80. #endif
  81. irq_enter();
  82. #ifdef CONFIG_DEBUG_STACKOVERFLOW
  83. /* Debugging check for stack overflow: is there less than 1KB free? */
  84. {
  85. long sp;
  86. __asm__ __volatile__ ("and r15, %0" :
  87. "=r" (sp) : "0" (THREAD_SIZE - 1));
  88. if (unlikely(sp < (sizeof(struct thread_info) + STACK_WARN))) {
  89. printk("do_IRQ: stack overflow: %ld\n",
  90. sp - sizeof(struct thread_info));
  91. dump_stack();
  92. }
  93. }
  94. #endif
  95. irq = irq_demux(evt2irq(irq));
  96. #ifdef CONFIG_4KSTACKS
  97. curctx = (union irq_ctx *)current_thread_info();
  98. irqctx = hardirq_ctx[smp_processor_id()];
  99. /*
  100. * this is where we switch to the IRQ stack. However, if we are
  101. * already using the IRQ stack (because we interrupted a hardirq
  102. * handler) we can't do that and just have to keep using the
  103. * current stack (which is the irq stack already after all)
  104. */
  105. if (curctx != irqctx) {
  106. u32 *isp;
  107. isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
  108. irqctx->tinfo.task = curctx->tinfo.task;
  109. irqctx->tinfo.previous_sp = current_stack_pointer;
  110. /*
  111. * Copy the softirq bits in preempt_count so that the
  112. * softirq checks work in the hardirq context.
  113. */
  114. irqctx->tinfo.preempt_count =
  115. (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
  116. (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
  117. __asm__ __volatile__ (
  118. "mov %0, r4 \n"
  119. "mov r15, r8 \n"
  120. "jsr @%1 \n"
  121. /* swith to the irq stack */
  122. " mov %2, r15 \n"
  123. /* restore the stack (ring zero) */
  124. "mov r8, r15 \n"
  125. : /* no outputs */
  126. : "r" (irq), "r" (generic_handle_irq), "r" (isp)
  127. : "memory", "r0", "r1", "r2", "r3", "r4",
  128. "r5", "r6", "r7", "r8", "t", "pr"
  129. );
  130. } else
  131. #endif
  132. generic_handle_irq(irq);
  133. irq_exit();
  134. set_irq_regs(old_regs);
  135. return 1;
  136. }
  137. #ifdef CONFIG_4KSTACKS
  138. static char softirq_stack[NR_CPUS * THREAD_SIZE]
  139. __attribute__((__section__(".bss.page_aligned")));
  140. static char hardirq_stack[NR_CPUS * THREAD_SIZE]
  141. __attribute__((__section__(".bss.page_aligned")));
  142. /*
  143. * allocate per-cpu stacks for hardirq and for softirq processing
  144. */
  145. void irq_ctx_init(int cpu)
  146. {
  147. union irq_ctx *irqctx;
  148. if (hardirq_ctx[cpu])
  149. return;
  150. irqctx = (union irq_ctx *)&hardirq_stack[cpu * THREAD_SIZE];
  151. irqctx->tinfo.task = NULL;
  152. irqctx->tinfo.exec_domain = NULL;
  153. irqctx->tinfo.cpu = cpu;
  154. irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
  155. irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
  156. hardirq_ctx[cpu] = irqctx;
  157. irqctx = (union irq_ctx *)&softirq_stack[cpu * THREAD_SIZE];
  158. irqctx->tinfo.task = NULL;
  159. irqctx->tinfo.exec_domain = NULL;
  160. irqctx->tinfo.cpu = cpu;
  161. irqctx->tinfo.preempt_count = 0;
  162. irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
  163. softirq_ctx[cpu] = irqctx;
  164. printk("CPU %u irqstacks, hard=%p soft=%p\n",
  165. cpu, hardirq_ctx[cpu], softirq_ctx[cpu]);
  166. }
  167. void irq_ctx_exit(int cpu)
  168. {
  169. hardirq_ctx[cpu] = NULL;
  170. }
  171. extern asmlinkage void __do_softirq(void);
  172. asmlinkage void do_softirq(void)
  173. {
  174. unsigned long flags;
  175. struct thread_info *curctx;
  176. union irq_ctx *irqctx;
  177. u32 *isp;
  178. if (in_interrupt())
  179. return;
  180. local_irq_save(flags);
  181. if (local_softirq_pending()) {
  182. curctx = current_thread_info();
  183. irqctx = softirq_ctx[smp_processor_id()];
  184. irqctx->tinfo.task = curctx->task;
  185. irqctx->tinfo.previous_sp = current_stack_pointer;
  186. /* build the stack frame on the softirq stack */
  187. isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
  188. __asm__ __volatile__ (
  189. "mov r15, r9 \n"
  190. "jsr @%0 \n"
  191. /* switch to the softirq stack */
  192. " mov %1, r15 \n"
  193. /* restore the thread stack */
  194. "mov r9, r15 \n"
  195. : /* no outputs */
  196. : "r" (__do_softirq), "r" (isp)
  197. : "memory", "r0", "r1", "r2", "r3", "r4",
  198. "r5", "r6", "r7", "r8", "r9", "r15", "t", "pr"
  199. );
  200. /*
  201. * Shouldnt happen, we returned above if in_interrupt():
  202. */
  203. WARN_ON_ONCE(softirq_count());
  204. }
  205. local_irq_restore(flags);
  206. }
  207. #endif
  208. void __init init_IRQ(void)
  209. {
  210. #ifdef CONFIG_CPU_HAS_PINT_IRQ
  211. init_IRQ_pint();
  212. #endif
  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. }