irq.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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/irq.h>
  15. #include <asm/processor.h>
  16. #include <asm/uaccess.h>
  17. #include <asm/thread_info.h>
  18. #include <asm/cpu/mmu_context.h>
  19. /*
  20. * 'what should we do if we get a hw irq event on an illegal vector'.
  21. * each architecture has to answer this themselves, it doesn't deserve
  22. * a generic callback i think.
  23. */
  24. void ack_bad_irq(unsigned int irq)
  25. {
  26. printk("unexpected IRQ trap at vector %02x\n", irq);
  27. }
  28. #if defined(CONFIG_PROC_FS)
  29. int show_interrupts(struct seq_file *p, void *v)
  30. {
  31. int i = *(loff_t *) v, j;
  32. struct irqaction * action;
  33. unsigned long flags;
  34. if (i == 0) {
  35. seq_puts(p, " ");
  36. for_each_online_cpu(j)
  37. seq_printf(p, "CPU%d ",j);
  38. seq_putc(p, '\n');
  39. }
  40. if (i < NR_IRQS) {
  41. spin_lock_irqsave(&irq_desc[i].lock, flags);
  42. action = irq_desc[i].action;
  43. if (!action)
  44. goto unlock;
  45. seq_printf(p, "%3d: ",i);
  46. seq_printf(p, "%10u ", kstat_irqs(i));
  47. seq_printf(p, " %14s", irq_desc[i].chip->typename);
  48. seq_printf(p, " %s", action->name);
  49. for (action=action->next; action; action = action->next)
  50. seq_printf(p, ", %s", action->name);
  51. seq_putc(p, '\n');
  52. unlock:
  53. spin_unlock_irqrestore(&irq_desc[i].lock, flags);
  54. }
  55. return 0;
  56. }
  57. #endif
  58. #ifdef CONFIG_4KSTACKS
  59. /*
  60. * per-CPU IRQ handling contexts (thread information and stack)
  61. */
  62. union irq_ctx {
  63. struct thread_info tinfo;
  64. u32 stack[THREAD_SIZE/sizeof(u32)];
  65. };
  66. static union irq_ctx *hardirq_ctx[NR_CPUS];
  67. static union irq_ctx *softirq_ctx[NR_CPUS];
  68. #endif
  69. asmlinkage int do_IRQ(unsigned long r4, unsigned long r5,
  70. unsigned long r6, unsigned long r7,
  71. struct pt_regs regs)
  72. {
  73. int irq = r4;
  74. #ifdef CONFIG_4KSTACKS
  75. union irq_ctx *curctx, *irqctx;
  76. #endif
  77. irq_enter();
  78. #ifdef CONFIG_DEBUG_STACKOVERFLOW
  79. /* Debugging check for stack overflow: is there less than 1KB free? */
  80. {
  81. long sp;
  82. __asm__ __volatile__ ("and r15, %0" :
  83. "=r" (sp) : "0" (THREAD_SIZE - 1));
  84. if (unlikely(sp < (sizeof(struct thread_info) + STACK_WARN))) {
  85. printk("do_IRQ: stack overflow: %ld\n",
  86. sp - sizeof(struct thread_info));
  87. dump_stack();
  88. }
  89. }
  90. #endif
  91. #ifdef CONFIG_CPU_HAS_INTEVT
  92. __asm__ __volatile__ (
  93. #ifdef CONFIG_CPU_HAS_SR_RB
  94. "stc r2_bank, %0\n\t"
  95. #else
  96. "mov.l @%1, %0\n\t"
  97. #endif
  98. "shlr2 %0\n\t"
  99. "shlr2 %0\n\t"
  100. "shlr %0\n\t"
  101. "add #-16, %0\n\t"
  102. : "=z" (irq), "=r" (r4)
  103. : "1" (INTEVT)
  104. : "memory"
  105. );
  106. #endif
  107. irq = irq_demux(irq);
  108. #ifdef CONFIG_4KSTACKS
  109. curctx = (union irq_ctx *)current_thread_info();
  110. irqctx = hardirq_ctx[smp_processor_id()];
  111. /*
  112. * this is where we switch to the IRQ stack. However, if we are
  113. * already using the IRQ stack (because we interrupted a hardirq
  114. * handler) we can't do that and just have to keep using the
  115. * current stack (which is the irq stack already after all)
  116. */
  117. if (curctx != irqctx) {
  118. u32 *isp;
  119. isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
  120. irqctx->tinfo.task = curctx->tinfo.task;
  121. irqctx->tinfo.previous_sp = current_stack_pointer;
  122. __asm__ __volatile__ (
  123. "mov %0, r4 \n"
  124. "mov %1, r5 \n"
  125. "mov r15, r9 \n"
  126. "jsr @%2 \n"
  127. /* swith to the irq stack */
  128. " mov %3, r15 \n"
  129. /* restore the stack (ring zero) */
  130. "mov r9, r15 \n"
  131. : /* no outputs */
  132. : "r" (irq), "r" (&regs), "r" (__do_IRQ), "r" (isp)
  133. /* XXX: A somewhat excessive clobber list? -PFM */
  134. : "memory", "r0", "r1", "r2", "r3", "r4",
  135. "r5", "r6", "r7", "r8", "t", "pr"
  136. );
  137. } else
  138. #endif
  139. __do_IRQ(irq, &regs);
  140. irq_exit();
  141. return 1;
  142. }
  143. #ifdef CONFIG_4KSTACKS
  144. /*
  145. * These should really be __section__(".bss.page_aligned") as well, but
  146. * gcc's 3.0 and earlier don't handle that correctly.
  147. */
  148. static char softirq_stack[NR_CPUS * THREAD_SIZE]
  149. __attribute__((__aligned__(THREAD_SIZE)));
  150. static char hardirq_stack[NR_CPUS * THREAD_SIZE]
  151. __attribute__((__aligned__(THREAD_SIZE)));
  152. /*
  153. * allocate per-cpu stacks for hardirq and for softirq processing
  154. */
  155. void irq_ctx_init(int cpu)
  156. {
  157. union irq_ctx *irqctx;
  158. if (hardirq_ctx[cpu])
  159. return;
  160. irqctx = (union irq_ctx *)&hardirq_stack[cpu * THREAD_SIZE];
  161. irqctx->tinfo.task = NULL;
  162. irqctx->tinfo.exec_domain = NULL;
  163. irqctx->tinfo.cpu = cpu;
  164. irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
  165. irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
  166. hardirq_ctx[cpu] = irqctx;
  167. irqctx = (union irq_ctx *)&softirq_stack[cpu * THREAD_SIZE];
  168. irqctx->tinfo.task = NULL;
  169. irqctx->tinfo.exec_domain = NULL;
  170. irqctx->tinfo.cpu = cpu;
  171. irqctx->tinfo.preempt_count = SOFTIRQ_OFFSET;
  172. irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
  173. softirq_ctx[cpu] = irqctx;
  174. printk("CPU %u irqstacks, hard=%p soft=%p\n",
  175. cpu, hardirq_ctx[cpu], softirq_ctx[cpu]);
  176. }
  177. void irq_ctx_exit(int cpu)
  178. {
  179. hardirq_ctx[cpu] = NULL;
  180. }
  181. extern asmlinkage void __do_softirq(void);
  182. asmlinkage void do_softirq(void)
  183. {
  184. unsigned long flags;
  185. struct thread_info *curctx;
  186. union irq_ctx *irqctx;
  187. u32 *isp;
  188. if (in_interrupt())
  189. return;
  190. local_irq_save(flags);
  191. if (local_softirq_pending()) {
  192. curctx = current_thread_info();
  193. irqctx = softirq_ctx[smp_processor_id()];
  194. irqctx->tinfo.task = curctx->task;
  195. irqctx->tinfo.previous_sp = current_stack_pointer;
  196. /* build the stack frame on the softirq stack */
  197. isp = (u32 *)((char *)irqctx + sizeof(*irqctx));
  198. __asm__ __volatile__ (
  199. "mov r15, r9 \n"
  200. "jsr @%0 \n"
  201. /* switch to the softirq stack */
  202. " mov %1, r15 \n"
  203. /* restore the thread stack */
  204. "mov r9, r15 \n"
  205. : /* no outputs */
  206. : "r" (__do_softirq), "r" (isp)
  207. /* XXX: A somewhat excessive clobber list? -PFM */
  208. : "memory", "r0", "r1", "r2", "r3", "r4",
  209. "r5", "r6", "r7", "r8", "r9", "r15", "t", "pr"
  210. );
  211. }
  212. local_irq_restore(flags);
  213. }
  214. EXPORT_SYMBOL(do_softirq);
  215. #endif