irq.c 6.6 KB

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