irq.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. /* MN10300 Arch-specific interrupt handling
  2. *
  3. * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public Licence
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the Licence, or (at your option) any later version.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/kernel_stat.h>
  14. #include <linux/seq_file.h>
  15. #include <linux/cpumask.h>
  16. #include <asm/setup.h>
  17. #include <asm/serial-regs.h>
  18. unsigned long __mn10300_irq_enabled_epsw[NR_CPUS] __cacheline_aligned_in_smp = {
  19. [0 ... NR_CPUS - 1] = EPSW_IE | EPSW_IM_7
  20. };
  21. EXPORT_SYMBOL(__mn10300_irq_enabled_epsw);
  22. #ifdef CONFIG_SMP
  23. static char irq_affinity_online[NR_IRQS] = {
  24. [0 ... NR_IRQS - 1] = 0
  25. };
  26. #define NR_IRQ_WORDS ((NR_IRQS + 31) / 32)
  27. static unsigned long irq_affinity_request[NR_IRQ_WORDS] = {
  28. [0 ... NR_IRQ_WORDS - 1] = 0
  29. };
  30. #endif /* CONFIG_SMP */
  31. atomic_t irq_err_count;
  32. /*
  33. * MN10300 interrupt controller operations
  34. */
  35. static void mn10300_cpupic_ack(struct irq_data *d)
  36. {
  37. unsigned int irq = d->irq;
  38. unsigned long flags;
  39. u16 tmp;
  40. flags = arch_local_cli_save();
  41. GxICR_u8(irq) = GxICR_DETECT;
  42. tmp = GxICR(irq);
  43. arch_local_irq_restore(flags);
  44. }
  45. static void __mask_and_set_icr(unsigned int irq,
  46. unsigned int mask, unsigned int set)
  47. {
  48. unsigned long flags;
  49. u16 tmp;
  50. flags = arch_local_cli_save();
  51. tmp = GxICR(irq);
  52. GxICR(irq) = (tmp & mask) | set;
  53. tmp = GxICR(irq);
  54. arch_local_irq_restore(flags);
  55. }
  56. static void mn10300_cpupic_mask(struct irq_data *d)
  57. {
  58. __mask_and_set_icr(d->irq, GxICR_LEVEL, 0);
  59. }
  60. static void mn10300_cpupic_mask_ack(struct irq_data *d)
  61. {
  62. unsigned int irq = d->irq;
  63. #ifdef CONFIG_SMP
  64. unsigned long flags;
  65. u16 tmp;
  66. flags = arch_local_cli_save();
  67. if (!test_and_clear_bit(irq, irq_affinity_request)) {
  68. tmp = GxICR(irq);
  69. GxICR(irq) = (tmp & GxICR_LEVEL) | GxICR_DETECT;
  70. tmp = GxICR(irq);
  71. } else {
  72. u16 tmp2;
  73. tmp = GxICR(irq);
  74. GxICR(irq) = (tmp & GxICR_LEVEL);
  75. tmp2 = GxICR(irq);
  76. irq_affinity_online[irq] =
  77. cpumask_any_and(irq_data_get_affinity_mask(d),
  78. cpu_online_mask);
  79. CROSS_GxICR(irq, irq_affinity_online[irq]) =
  80. (tmp & (GxICR_LEVEL | GxICR_ENABLE)) | GxICR_DETECT;
  81. tmp = CROSS_GxICR(irq, irq_affinity_online[irq]);
  82. }
  83. arch_local_irq_restore(flags);
  84. #else /* CONFIG_SMP */
  85. __mask_and_set_icr(irq, GxICR_LEVEL, GxICR_DETECT);
  86. #endif /* CONFIG_SMP */
  87. }
  88. static void mn10300_cpupic_unmask(struct irq_data *d)
  89. {
  90. __mask_and_set_icr(d->irq, GxICR_LEVEL, GxICR_ENABLE);
  91. }
  92. static void mn10300_cpupic_unmask_clear(struct irq_data *d)
  93. {
  94. unsigned int irq = d->irq;
  95. /* the MN10300 PIC latches its interrupt request bit, even after the
  96. * device has ceased to assert its interrupt line and the interrupt
  97. * channel has been disabled in the PIC, so for level-triggered
  98. * interrupts we need to clear the request bit when we re-enable */
  99. #ifdef CONFIG_SMP
  100. unsigned long flags;
  101. u16 tmp;
  102. flags = arch_local_cli_save();
  103. if (!test_and_clear_bit(irq, irq_affinity_request)) {
  104. tmp = GxICR(irq);
  105. GxICR(irq) = (tmp & GxICR_LEVEL) | GxICR_ENABLE | GxICR_DETECT;
  106. tmp = GxICR(irq);
  107. } else {
  108. tmp = GxICR(irq);
  109. irq_affinity_online[irq] = cpumask_any_and(irq_data_get_affinity_mask(d),
  110. cpu_online_mask);
  111. CROSS_GxICR(irq, irq_affinity_online[irq]) = (tmp & GxICR_LEVEL) | GxICR_ENABLE | GxICR_DETECT;
  112. tmp = CROSS_GxICR(irq, irq_affinity_online[irq]);
  113. }
  114. arch_local_irq_restore(flags);
  115. #else /* CONFIG_SMP */
  116. __mask_and_set_icr(irq, GxICR_LEVEL, GxICR_ENABLE | GxICR_DETECT);
  117. #endif /* CONFIG_SMP */
  118. }
  119. #ifdef CONFIG_SMP
  120. static int
  121. mn10300_cpupic_setaffinity(struct irq_data *d, const struct cpumask *mask,
  122. bool force)
  123. {
  124. unsigned long flags;
  125. flags = arch_local_cli_save();
  126. set_bit(d->irq, irq_affinity_request);
  127. arch_local_irq_restore(flags);
  128. return 0;
  129. }
  130. #endif /* CONFIG_SMP */
  131. /*
  132. * MN10300 PIC level-triggered IRQ handling.
  133. *
  134. * The PIC has no 'ACK' function per se. It is possible to clear individual
  135. * channel latches, but each latch relatches whether or not the channel is
  136. * masked, so we need to clear the latch when we unmask the channel.
  137. *
  138. * Also for this reason, we don't supply an ack() op (it's unused anyway if
  139. * mask_ack() is provided), and mask_ack() just masks.
  140. */
  141. static struct irq_chip mn10300_cpu_pic_level = {
  142. .name = "cpu_l",
  143. .irq_disable = mn10300_cpupic_mask,
  144. .irq_enable = mn10300_cpupic_unmask_clear,
  145. .irq_ack = NULL,
  146. .irq_mask = mn10300_cpupic_mask,
  147. .irq_mask_ack = mn10300_cpupic_mask,
  148. .irq_unmask = mn10300_cpupic_unmask_clear,
  149. #ifdef CONFIG_SMP
  150. .irq_set_affinity = mn10300_cpupic_setaffinity,
  151. #endif
  152. };
  153. /*
  154. * MN10300 PIC edge-triggered IRQ handling.
  155. *
  156. * We use the latch clearing function of the PIC as the 'ACK' function.
  157. */
  158. static struct irq_chip mn10300_cpu_pic_edge = {
  159. .name = "cpu_e",
  160. .irq_disable = mn10300_cpupic_mask,
  161. .irq_enable = mn10300_cpupic_unmask,
  162. .irq_ack = mn10300_cpupic_ack,
  163. .irq_mask = mn10300_cpupic_mask,
  164. .irq_mask_ack = mn10300_cpupic_mask_ack,
  165. .irq_unmask = mn10300_cpupic_unmask,
  166. #ifdef CONFIG_SMP
  167. .irq_set_affinity = mn10300_cpupic_setaffinity,
  168. #endif
  169. };
  170. /*
  171. * 'what should we do if we get a hw irq event on an illegal vector'.
  172. * each architecture has to answer this themselves.
  173. */
  174. void ack_bad_irq(int irq)
  175. {
  176. printk(KERN_WARNING "unexpected IRQ trap at vector %02x\n", irq);
  177. }
  178. /*
  179. * change the level at which an IRQ executes
  180. * - must not be called whilst interrupts are being processed!
  181. */
  182. void set_intr_level(int irq, u16 level)
  183. {
  184. BUG_ON(in_interrupt());
  185. __mask_and_set_icr(irq, GxICR_ENABLE, level);
  186. }
  187. /*
  188. * mark an interrupt to be ACK'd after interrupt handlers have been run rather
  189. * than before
  190. */
  191. void mn10300_set_lateack_irq_type(int irq)
  192. {
  193. irq_set_chip_and_handler(irq, &mn10300_cpu_pic_level,
  194. handle_level_irq);
  195. }
  196. /*
  197. * initialise the interrupt system
  198. */
  199. void __init init_IRQ(void)
  200. {
  201. int irq;
  202. for (irq = 0; irq < NR_IRQS; irq++)
  203. if (irq_get_chip(irq) == &no_irq_chip)
  204. /* due to the PIC latching interrupt requests, even
  205. * when the IRQ is disabled, IRQ_PENDING is superfluous
  206. * and we can use handle_level_irq() for edge-triggered
  207. * interrupts */
  208. irq_set_chip_and_handler(irq, &mn10300_cpu_pic_edge,
  209. handle_level_irq);
  210. unit_init_IRQ();
  211. }
  212. /*
  213. * handle normal device IRQs
  214. */
  215. asmlinkage void do_IRQ(void)
  216. {
  217. unsigned long sp, epsw, irq_disabled_epsw, old_irq_enabled_epsw;
  218. unsigned int cpu_id = smp_processor_id();
  219. int irq;
  220. sp = current_stack_pointer();
  221. BUG_ON(sp - (sp & ~(THREAD_SIZE - 1)) < STACK_WARN);
  222. /* make sure local_irq_enable() doesn't muck up the interrupt priority
  223. * setting in EPSW */
  224. old_irq_enabled_epsw = __mn10300_irq_enabled_epsw[cpu_id];
  225. local_save_flags(epsw);
  226. __mn10300_irq_enabled_epsw[cpu_id] = EPSW_IE | (EPSW_IM & epsw);
  227. irq_disabled_epsw = EPSW_IE | MN10300_CLI_LEVEL;
  228. #ifdef CONFIG_MN10300_WD_TIMER
  229. __IRQ_STAT(cpu_id, __irq_count)++;
  230. #endif
  231. irq_enter();
  232. for (;;) {
  233. /* ask the interrupt controller for the next IRQ to process
  234. * - the result we get depends on EPSW.IM
  235. */
  236. irq = IAGR & IAGR_GN;
  237. if (!irq)
  238. break;
  239. local_irq_restore(irq_disabled_epsw);
  240. generic_handle_irq(irq >> 2);
  241. /* restore IRQ controls for IAGR access */
  242. local_irq_restore(epsw);
  243. }
  244. __mn10300_irq_enabled_epsw[cpu_id] = old_irq_enabled_epsw;
  245. irq_exit();
  246. }
  247. /*
  248. * Display interrupt management information through /proc/interrupts
  249. */
  250. int arch_show_interrupts(struct seq_file *p, int prec)
  251. {
  252. #ifdef CONFIG_MN10300_WD_TIMER
  253. int j;
  254. seq_printf(p, "%*s: ", prec, "NMI");
  255. for (j = 0; j < NR_CPUS; j++)
  256. if (cpu_online(j))
  257. seq_printf(p, "%10u ", nmi_count(j));
  258. seq_putc(p, '\n');
  259. #endif
  260. seq_printf(p, "%*s: ", prec, "ERR");
  261. seq_printf(p, "%10u\n", atomic_read(&irq_err_count));
  262. return 0;
  263. }
  264. #ifdef CONFIG_HOTPLUG_CPU
  265. void migrate_irqs(void)
  266. {
  267. int irq;
  268. unsigned int self, new;
  269. unsigned long flags;
  270. self = smp_processor_id();
  271. for (irq = 0; irq < NR_IRQS; irq++) {
  272. struct irq_data *data = irq_get_irq_data(irq);
  273. struct cpumask *mask = irq_data_get_affinity_mask(data);
  274. if (irqd_is_per_cpu(data))
  275. continue;
  276. if (cpumask_test_cpu(self, mask) &&
  277. !cpumask_intersects(&irq_affinity[irq], cpu_online_mask)) {
  278. int cpu_id;
  279. cpu_id = cpumask_first(cpu_online_mask);
  280. cpumask_set_cpu(cpu_id, mask);
  281. }
  282. /* We need to operate irq_affinity_online atomically. */
  283. arch_local_cli_save(flags);
  284. if (irq_affinity_online[irq] == self) {
  285. u16 x, tmp;
  286. x = GxICR(irq);
  287. GxICR(irq) = x & GxICR_LEVEL;
  288. tmp = GxICR(irq);
  289. new = cpumask_any_and(mask, cpu_online_mask);
  290. irq_affinity_online[irq] = new;
  291. CROSS_GxICR(irq, new) =
  292. (x & GxICR_LEVEL) | GxICR_DETECT;
  293. tmp = CROSS_GxICR(irq, new);
  294. x &= GxICR_LEVEL | GxICR_ENABLE;
  295. if (GxICR(irq) & GxICR_REQUEST)
  296. x |= GxICR_REQUEST | GxICR_DETECT;
  297. CROSS_GxICR(irq, new) = x;
  298. tmp = CROSS_GxICR(irq, new);
  299. }
  300. arch_local_irq_restore(flags);
  301. }
  302. }
  303. #endif /* CONFIG_HOTPLUG_CPU */