irq.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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.cpu = cpu;
  109. irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
  110. irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
  111. hardirq_ctx[cpu] = irqctx;
  112. irqctx = (union irq_ctx *) &softirq_stack[cpu * THREAD_SIZE];
  113. irqctx->tinfo.task = NULL;
  114. irqctx->tinfo.cpu = cpu;
  115. irqctx->tinfo.preempt_count = 0;
  116. irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
  117. softirq_ctx[cpu] = irqctx;
  118. pr_info("CPU %u irqstacks, hard=%p soft=%p\n",
  119. cpu, hardirq_ctx[cpu], softirq_ctx[cpu]);
  120. }
  121. void irq_ctx_exit(int cpu)
  122. {
  123. hardirq_ctx[smp_processor_id()] = NULL;
  124. }
  125. extern asmlinkage void __do_softirq(void);
  126. void do_softirq_own_stack(void)
  127. {
  128. struct thread_info *curctx;
  129. union irq_ctx *irqctx;
  130. u32 *isp;
  131. curctx = current_thread_info();
  132. irqctx = softirq_ctx[smp_processor_id()];
  133. irqctx->tinfo.task = curctx->task;
  134. /* build the stack frame on the softirq stack */
  135. isp = (u32 *) ((char *)irqctx + sizeof(struct thread_info));
  136. asm volatile (
  137. "MOV D0.5,%0\n"
  138. "SWAP A0StP,D0.5\n"
  139. "CALLR D1RtP,___do_softirq\n"
  140. "MOV A0StP,D0.5\n"
  141. :
  142. : "r" (isp)
  143. : "memory", "cc", "D1Ar1", "D0Ar2", "D1Ar3", "D0Ar4",
  144. "D1Ar5", "D0Ar6", "D0Re0", "D1Re0", "D0.4", "D1RtP",
  145. "D0.5"
  146. );
  147. }
  148. #endif
  149. static struct irq_chip meta_irq_type = {
  150. .name = "META-IRQ",
  151. .irq_startup = startup_meta_irq,
  152. .irq_shutdown = shutdown_meta_irq,
  153. };
  154. /**
  155. * tbisig_map() - Map a TBI signal number to a virtual IRQ number.
  156. * @hw: Number of the TBI signal. Must be in range.
  157. *
  158. * Returns: The virtual IRQ number of the TBI signal number IRQ specified by
  159. * @hw.
  160. */
  161. int tbisig_map(unsigned int hw)
  162. {
  163. return irq_create_mapping(root_domain, hw);
  164. }
  165. /**
  166. * metag_tbisig_map() - map a tbi signal to a Linux virtual IRQ number
  167. * @d: root irq domain
  168. * @irq: virtual irq number
  169. * @hw: hardware irq number (TBI signal number)
  170. *
  171. * This sets up a virtual irq for a specified TBI signal number.
  172. */
  173. static int metag_tbisig_map(struct irq_domain *d, unsigned int irq,
  174. irq_hw_number_t hw)
  175. {
  176. #ifdef CONFIG_SMP
  177. irq_set_chip_and_handler(irq, &meta_irq_type, handle_percpu_irq);
  178. #else
  179. irq_set_chip_and_handler(irq, &meta_irq_type, handle_simple_irq);
  180. #endif
  181. return 0;
  182. }
  183. static const struct irq_domain_ops metag_tbisig_domain_ops = {
  184. .map = metag_tbisig_map,
  185. };
  186. /*
  187. * void init_IRQ(void)
  188. *
  189. * Parameters: None
  190. *
  191. * Returns: Nothing
  192. *
  193. * This function should be called during kernel startup to initialize
  194. * the IRQ handling routines.
  195. */
  196. void __init init_IRQ(void)
  197. {
  198. root_domain = irq_domain_add_linear(NULL, 32,
  199. &metag_tbisig_domain_ops, NULL);
  200. if (unlikely(!root_domain))
  201. panic("init_IRQ: cannot add root IRQ domain");
  202. irq_ctx_init(smp_processor_id());
  203. init_internal_IRQ();
  204. init_external_IRQ();
  205. if (machine_desc->init_irq)
  206. machine_desc->init_irq();
  207. }
  208. int __init arch_probe_nr_irqs(void)
  209. {
  210. if (machine_desc->nr_irqs)
  211. nr_irqs = machine_desc->nr_irqs;
  212. return 0;
  213. }
  214. #ifdef CONFIG_HOTPLUG_CPU
  215. /*
  216. * The CPU has been marked offline. Migrate IRQs off this CPU. If
  217. * the affinity settings do not allow other CPUs, force them onto any
  218. * available CPU.
  219. */
  220. void migrate_irqs(void)
  221. {
  222. unsigned int i, cpu = smp_processor_id();
  223. for_each_active_irq(i) {
  224. struct irq_data *data = irq_get_irq_data(i);
  225. unsigned int newcpu;
  226. if (irqd_is_per_cpu(data))
  227. continue;
  228. if (!cpumask_test_cpu(cpu, data->affinity))
  229. continue;
  230. newcpu = cpumask_any_and(data->affinity, cpu_online_mask);
  231. if (newcpu >= nr_cpu_ids) {
  232. pr_info_ratelimited("IRQ%u no longer affine to CPU%u\n",
  233. i, cpu);
  234. cpumask_setall(data->affinity);
  235. }
  236. irq_set_affinity(i, data->affinity);
  237. }
  238. }
  239. #endif /* CONFIG_HOTPLUG_CPU */