irq.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /*
  2. * Linux/Meta general interrupt handling code
  3. *
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/interrupt.h>
  7. #include <linux/init.h>
  8. #include <linux/irqchip/metag-ext.h>
  9. #include <linux/irqchip/metag.h>
  10. #include <linux/irqdomain.h>
  11. #include <linux/ratelimit.h>
  12. #include <asm/core_reg.h>
  13. #include <asm/mach/arch.h>
  14. #include <asm/uaccess.h>
  15. #ifdef CONFIG_4KSTACKS
  16. union irq_ctx {
  17. struct thread_info tinfo;
  18. u32 stack[THREAD_SIZE/sizeof(u32)];
  19. };
  20. static union irq_ctx *hardirq_ctx[NR_CPUS] __read_mostly;
  21. static union irq_ctx *softirq_ctx[NR_CPUS] __read_mostly;
  22. #endif
  23. static struct irq_domain *root_domain;
  24. static unsigned int startup_meta_irq(struct irq_data *data)
  25. {
  26. tbi_startup_interrupt(data->hwirq);
  27. return 0;
  28. }
  29. static void shutdown_meta_irq(struct irq_data *data)
  30. {
  31. tbi_shutdown_interrupt(data->hwirq);
  32. }
  33. void do_IRQ(int irq, struct pt_regs *regs)
  34. {
  35. struct pt_regs *old_regs = set_irq_regs(regs);
  36. #ifdef CONFIG_4KSTACKS
  37. struct irq_desc *desc;
  38. union irq_ctx *curctx, *irqctx;
  39. u32 *isp;
  40. #endif
  41. irq_enter();
  42. irq = irq_linear_revmap(root_domain, irq);
  43. #ifdef CONFIG_DEBUG_STACKOVERFLOW
  44. /* Debugging check for stack overflow: is there less than 1KB free? */
  45. {
  46. unsigned long sp;
  47. sp = __core_reg_get(A0StP);
  48. sp &= THREAD_SIZE - 1;
  49. if (unlikely(sp > (THREAD_SIZE - 1024)))
  50. pr_err("Stack overflow in do_IRQ: %ld\n", sp);
  51. }
  52. #endif
  53. #ifdef CONFIG_4KSTACKS
  54. curctx = (union irq_ctx *) current_thread_info();
  55. irqctx = hardirq_ctx[smp_processor_id()];
  56. /*
  57. * this is where we switch to the IRQ stack. However, if we are
  58. * already using the IRQ stack (because we interrupted a hardirq
  59. * handler) we can't do that and just have to keep using the
  60. * current stack (which is the irq stack already after all)
  61. */
  62. if (curctx != irqctx) {
  63. /* build the stack frame on the IRQ stack */
  64. isp = (u32 *) ((char *)irqctx + sizeof(struct thread_info));
  65. irqctx->tinfo.task = curctx->tinfo.task;
  66. /*
  67. * Copy the softirq bits in preempt_count so that the
  68. * softirq checks work in the hardirq context.
  69. */
  70. irqctx->tinfo.preempt_count =
  71. (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
  72. (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
  73. desc = irq_to_desc(irq);
  74. asm volatile (
  75. "MOV D0.5,%0\n"
  76. "MOV D1Ar1,%1\n"
  77. "MOV D1RtP,%2\n"
  78. "MOV D0Ar2,%3\n"
  79. "SWAP A0StP,D0.5\n"
  80. "SWAP PC,D1RtP\n"
  81. "MOV A0StP,D0.5\n"
  82. :
  83. : "r" (isp), "r" (irq), "r" (desc->handle_irq),
  84. "r" (desc)
  85. : "memory", "cc", "D1Ar1", "D0Ar2", "D1Ar3", "D0Ar4",
  86. "D1Ar5", "D0Ar6", "D0Re0", "D1Re0", "D0.4", "D1RtP",
  87. "D0.5"
  88. );
  89. } else
  90. #endif
  91. generic_handle_irq(irq);
  92. irq_exit();
  93. set_irq_regs(old_regs);
  94. }
  95. #ifdef CONFIG_4KSTACKS
  96. static char softirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
  97. static char hardirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
  98. /*
  99. * allocate per-cpu stacks for hardirq and for softirq processing
  100. */
  101. void irq_ctx_init(int cpu)
  102. {
  103. union irq_ctx *irqctx;
  104. if (hardirq_ctx[cpu])
  105. return;
  106. irqctx = (union irq_ctx *) &hardirq_stack[cpu * THREAD_SIZE];
  107. irqctx->tinfo.task = NULL;
  108. irqctx->tinfo.exec_domain = NULL;
  109. irqctx->tinfo.cpu = cpu;
  110. irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
  111. irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
  112. hardirq_ctx[cpu] = irqctx;
  113. irqctx = (union irq_ctx *) &softirq_stack[cpu * THREAD_SIZE];
  114. irqctx->tinfo.task = NULL;
  115. irqctx->tinfo.exec_domain = NULL;
  116. irqctx->tinfo.cpu = cpu;
  117. irqctx->tinfo.preempt_count = 0;
  118. irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
  119. softirq_ctx[cpu] = irqctx;
  120. pr_info("CPU %u irqstacks, hard=%p soft=%p\n",
  121. cpu, hardirq_ctx[cpu], softirq_ctx[cpu]);
  122. }
  123. void irq_ctx_exit(int cpu)
  124. {
  125. hardirq_ctx[smp_processor_id()] = NULL;
  126. }
  127. extern asmlinkage void __do_softirq(void);
  128. void do_softirq_own_stack(void)
  129. {
  130. struct thread_info *curctx;
  131. union irq_ctx *irqctx;
  132. u32 *isp;
  133. curctx = current_thread_info();
  134. irqctx = softirq_ctx[smp_processor_id()];
  135. irqctx->tinfo.task = curctx->task;
  136. /* build the stack frame on the softirq stack */
  137. isp = (u32 *) ((char *)irqctx + sizeof(struct thread_info));
  138. asm volatile (
  139. "MOV D0.5,%0\n"
  140. "SWAP A0StP,D0.5\n"
  141. "CALLR D1RtP,___do_softirq\n"
  142. "MOV A0StP,D0.5\n"
  143. :
  144. : "r" (isp)
  145. : "memory", "cc", "D1Ar1", "D0Ar2", "D1Ar3", "D0Ar4",
  146. "D1Ar5", "D0Ar6", "D0Re0", "D1Re0", "D0.4", "D1RtP",
  147. "D0.5"
  148. );
  149. }
  150. #endif
  151. static struct irq_chip meta_irq_type = {
  152. .name = "META-IRQ",
  153. .irq_startup = startup_meta_irq,
  154. .irq_shutdown = shutdown_meta_irq,
  155. };
  156. /**
  157. * tbisig_map() - Map a TBI signal number to a virtual IRQ number.
  158. * @hw: Number of the TBI signal. Must be in range.
  159. *
  160. * Returns: The virtual IRQ number of the TBI signal number IRQ specified by
  161. * @hw.
  162. */
  163. int tbisig_map(unsigned int hw)
  164. {
  165. return irq_create_mapping(root_domain, hw);
  166. }
  167. /**
  168. * metag_tbisig_map() - map a tbi signal to a Linux virtual IRQ number
  169. * @d: root irq domain
  170. * @irq: virtual irq number
  171. * @hw: hardware irq number (TBI signal number)
  172. *
  173. * This sets up a virtual irq for a specified TBI signal number.
  174. */
  175. static int metag_tbisig_map(struct irq_domain *d, unsigned int irq,
  176. irq_hw_number_t hw)
  177. {
  178. #ifdef CONFIG_SMP
  179. irq_set_chip_and_handler(irq, &meta_irq_type, handle_percpu_irq);
  180. #else
  181. irq_set_chip_and_handler(irq, &meta_irq_type, handle_simple_irq);
  182. #endif
  183. return 0;
  184. }
  185. static const struct irq_domain_ops metag_tbisig_domain_ops = {
  186. .map = metag_tbisig_map,
  187. };
  188. /*
  189. * void init_IRQ(void)
  190. *
  191. * Parameters: None
  192. *
  193. * Returns: Nothing
  194. *
  195. * This function should be called during kernel startup to initialize
  196. * the IRQ handling routines.
  197. */
  198. void __init init_IRQ(void)
  199. {
  200. root_domain = irq_domain_add_linear(NULL, 32,
  201. &metag_tbisig_domain_ops, NULL);
  202. if (unlikely(!root_domain))
  203. panic("init_IRQ: cannot add root IRQ domain");
  204. irq_ctx_init(smp_processor_id());
  205. init_internal_IRQ();
  206. init_external_IRQ();
  207. if (machine_desc->init_irq)
  208. machine_desc->init_irq();
  209. }
  210. int __init arch_probe_nr_irqs(void)
  211. {
  212. if (machine_desc->nr_irqs)
  213. nr_irqs = machine_desc->nr_irqs;
  214. return 0;
  215. }
  216. #ifdef CONFIG_HOTPLUG_CPU
  217. /*
  218. * The CPU has been marked offline. Migrate IRQs off this CPU. If
  219. * the affinity settings do not allow other CPUs, force them onto any
  220. * available CPU.
  221. */
  222. void migrate_irqs(void)
  223. {
  224. unsigned int i, cpu = smp_processor_id();
  225. for_each_active_irq(i) {
  226. struct irq_data *data = irq_get_irq_data(i);
  227. unsigned int newcpu;
  228. if (irqd_is_per_cpu(data))
  229. continue;
  230. if (!cpumask_test_cpu(cpu, data->affinity))
  231. continue;
  232. newcpu = cpumask_any_and(data->affinity, cpu_online_mask);
  233. if (newcpu >= nr_cpu_ids) {
  234. pr_info_ratelimited("IRQ%u no longer affine to CPU%u\n",
  235. i, cpu);
  236. cpumask_setall(data->affinity);
  237. }
  238. irq_set_affinity(i, data->affinity);
  239. }
  240. }
  241. #endif /* CONFIG_HOTPLUG_CPU */