irq.c 8.8 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(d->affinity, cpu_online_mask);
  78. CROSS_GxICR(irq, irq_affinity_online[irq]) =
  79. (tmp & (GxICR_LEVEL | GxICR_ENABLE)) | GxICR_DETECT;
  80. tmp = CROSS_GxICR(irq, irq_affinity_online[irq]);
  81. }
  82. arch_local_irq_restore(flags);
  83. #else /* CONFIG_SMP */
  84. __mask_and_set_icr(irq, GxICR_LEVEL, GxICR_DETECT);
  85. #endif /* CONFIG_SMP */
  86. }
  87. static void mn10300_cpupic_unmask(struct irq_data *d)
  88. {
  89. __mask_and_set_icr(d->irq, GxICR_LEVEL, GxICR_ENABLE);
  90. }
  91. static void mn10300_cpupic_unmask_clear(struct irq_data *d)
  92. {
  93. unsigned int irq = d->irq;
  94. /* the MN10300 PIC latches its interrupt request bit, even after the
  95. * device has ceased to assert its interrupt line and the interrupt
  96. * channel has been disabled in the PIC, so for level-triggered
  97. * interrupts we need to clear the request bit when we re-enable */
  98. #ifdef CONFIG_SMP
  99. unsigned long flags;
  100. u16 tmp;
  101. flags = arch_local_cli_save();
  102. if (!test_and_clear_bit(irq, irq_affinity_request)) {
  103. tmp = GxICR(irq);
  104. GxICR(irq) = (tmp & GxICR_LEVEL) | GxICR_ENABLE | GxICR_DETECT;
  105. tmp = GxICR(irq);
  106. } else {
  107. tmp = GxICR(irq);
  108. irq_affinity_online[irq] = cpumask_any_and(d->affinity,
  109. cpu_online_mask);
  110. CROSS_GxICR(irq, irq_affinity_online[irq]) = (tmp & GxICR_LEVEL) | GxICR_ENABLE | GxICR_DETECT;
  111. tmp = CROSS_GxICR(irq, irq_affinity_online[irq]);
  112. }
  113. arch_local_irq_restore(flags);
  114. #else /* CONFIG_SMP */
  115. __mask_and_set_icr(irq, GxICR_LEVEL, GxICR_ENABLE | GxICR_DETECT);
  116. #endif /* CONFIG_SMP */
  117. }
  118. #ifdef CONFIG_SMP
  119. static int
  120. mn10300_cpupic_setaffinity(struct irq_data *d, const struct cpumask *mask,
  121. bool force)
  122. {
  123. unsigned long flags;
  124. flags = arch_local_cli_save();
  125. set_bit(d->irq, irq_affinity_request);
  126. arch_local_irq_restore(flags);
  127. return 0;
  128. }
  129. #endif /* CONFIG_SMP */
  130. /*
  131. * MN10300 PIC level-triggered IRQ handling.
  132. *
  133. * The PIC has no 'ACK' function per se. It is possible to clear individual
  134. * channel latches, but each latch relatches whether or not the channel is
  135. * masked, so we need to clear the latch when we unmask the channel.
  136. *
  137. * Also for this reason, we don't supply an ack() op (it's unused anyway if
  138. * mask_ack() is provided), and mask_ack() just masks.
  139. */
  140. static struct irq_chip mn10300_cpu_pic_level = {
  141. .name = "cpu_l",
  142. .irq_disable = mn10300_cpupic_mask,
  143. .irq_enable = mn10300_cpupic_unmask_clear,
  144. .irq_ack = NULL,
  145. .irq_mask = mn10300_cpupic_mask,
  146. .irq_mask_ack = mn10300_cpupic_mask,
  147. .irq_unmask = mn10300_cpupic_unmask_clear,
  148. #ifdef CONFIG_SMP
  149. .irq_set_affinity = mn10300_cpupic_setaffinity,
  150. #endif
  151. };
  152. /*
  153. * MN10300 PIC edge-triggered IRQ handling.
  154. *
  155. * We use the latch clearing function of the PIC as the 'ACK' function.
  156. */
  157. static struct irq_chip mn10300_cpu_pic_edge = {
  158. .name = "cpu_e",
  159. .irq_disable = mn10300_cpupic_mask,
  160. .irq_enable = mn10300_cpupic_unmask,
  161. .irq_ack = mn10300_cpupic_ack,
  162. .irq_mask = mn10300_cpupic_mask,
  163. .irq_mask_ack = mn10300_cpupic_mask_ack,
  164. .irq_unmask = mn10300_cpupic_unmask,
  165. #ifdef CONFIG_SMP
  166. .irq_set_affinity = mn10300_cpupic_setaffinity,
  167. #endif
  168. };
  169. /*
  170. * 'what should we do if we get a hw irq event on an illegal vector'.
  171. * each architecture has to answer this themselves.
  172. */
  173. void ack_bad_irq(int irq)
  174. {
  175. printk(KERN_WARNING "unexpected IRQ trap at vector %02x\n", irq);
  176. }
  177. /*
  178. * change the level at which an IRQ executes
  179. * - must not be called whilst interrupts are being processed!
  180. */
  181. void set_intr_level(int irq, u16 level)
  182. {
  183. BUG_ON(in_interrupt());
  184. __mask_and_set_icr(irq, GxICR_ENABLE, level);
  185. }
  186. /*
  187. * mark an interrupt to be ACK'd after interrupt handlers have been run rather
  188. * than before
  189. */
  190. void mn10300_set_lateack_irq_type(int irq)
  191. {
  192. irq_set_chip_and_handler(irq, &mn10300_cpu_pic_level,
  193. handle_level_irq);
  194. }
  195. /*
  196. * initialise the interrupt system
  197. */
  198. void __init init_IRQ(void)
  199. {
  200. int irq;
  201. for (irq = 0; irq < NR_IRQS; irq++)
  202. if (irq_get_chip(irq) == &no_irq_chip)
  203. /* due to the PIC latching interrupt requests, even
  204. * when the IRQ is disabled, IRQ_PENDING is superfluous
  205. * and we can use handle_level_irq() for edge-triggered
  206. * interrupts */
  207. irq_set_chip_and_handler(irq, &mn10300_cpu_pic_edge,
  208. handle_level_irq);
  209. unit_init_IRQ();
  210. }
  211. /*
  212. * handle normal device IRQs
  213. */
  214. asmlinkage void do_IRQ(void)
  215. {
  216. unsigned long sp, epsw, irq_disabled_epsw, old_irq_enabled_epsw;
  217. unsigned int cpu_id = smp_processor_id();
  218. int irq;
  219. sp = current_stack_pointer();
  220. BUG_ON(sp - (sp & ~(THREAD_SIZE - 1)) < STACK_WARN);
  221. /* make sure local_irq_enable() doesn't muck up the interrupt priority
  222. * setting in EPSW */
  223. old_irq_enabled_epsw = __mn10300_irq_enabled_epsw[cpu_id];
  224. local_save_flags(epsw);
  225. __mn10300_irq_enabled_epsw[cpu_id] = EPSW_IE | (EPSW_IM & epsw);
  226. irq_disabled_epsw = EPSW_IE | MN10300_CLI_LEVEL;
  227. #ifdef CONFIG_MN10300_WD_TIMER
  228. __IRQ_STAT(cpu_id, __irq_count)++;
  229. #endif
  230. irq_enter();
  231. for (;;) {
  232. /* ask the interrupt controller for the next IRQ to process
  233. * - the result we get depends on EPSW.IM
  234. */
  235. irq = IAGR & IAGR_GN;
  236. if (!irq)
  237. break;
  238. local_irq_restore(irq_disabled_epsw);
  239. generic_handle_irq(irq >> 2);
  240. /* restore IRQ controls for IAGR access */
  241. local_irq_restore(epsw);
  242. }
  243. __mn10300_irq_enabled_epsw[cpu_id] = old_irq_enabled_epsw;
  244. irq_exit();
  245. }
  246. /*
  247. * Display interrupt management information through /proc/interrupts
  248. */
  249. int arch_show_interrupts(struct seq_file *p, int prec)
  250. {
  251. #ifdef CONFIG_MN10300_WD_TIMER
  252. int j;
  253. seq_printf(p, "%*s: ", prec, "NMI");
  254. for (j = 0; j < NR_CPUS; j++)
  255. if (cpu_online(j))
  256. seq_printf(p, "%10u ", nmi_count(j));
  257. seq_putc(p, '\n');
  258. #endif
  259. seq_printf(p, "%*s: ", prec, "ERR");
  260. seq_printf(p, "%10u\n", atomic_read(&irq_err_count));
  261. return 0;
  262. }
  263. #ifdef CONFIG_HOTPLUG_CPU
  264. void migrate_irqs(void)
  265. {
  266. int irq;
  267. unsigned int self, new;
  268. unsigned long flags;
  269. self = smp_processor_id();
  270. for (irq = 0; irq < NR_IRQS; irq++) {
  271. struct irq_data *data = irq_get_irq_data(irq);
  272. if (irqd_is_per_cpu(data))
  273. continue;
  274. if (cpumask_test_cpu(self, data->affinity) &&
  275. !cpumask_intersects(&irq_affinity[irq], cpu_online_mask)) {
  276. int cpu_id;
  277. cpu_id = cpumask_first(cpu_online_mask);
  278. cpumask_set_cpu(cpu_id, data->affinity);
  279. }
  280. /* We need to operate irq_affinity_online atomically. */
  281. arch_local_cli_save(flags);
  282. if (irq_affinity_online[irq] == self) {
  283. u16 x, tmp;
  284. x = GxICR(irq);
  285. GxICR(irq) = x & GxICR_LEVEL;
  286. tmp = GxICR(irq);
  287. new = cpumask_any_and(data->affinity,
  288. cpu_online_mask);
  289. irq_affinity_online[irq] = new;
  290. CROSS_GxICR(irq, new) =
  291. (x & GxICR_LEVEL) | GxICR_DETECT;
  292. tmp = CROSS_GxICR(irq, new);
  293. x &= GxICR_LEVEL | GxICR_ENABLE;
  294. if (GxICR(irq) & GxICR_REQUEST)
  295. x |= GxICR_REQUEST | GxICR_DETECT;
  296. CROSS_GxICR(irq, new) = x;
  297. tmp = CROSS_GxICR(irq, new);
  298. }
  299. arch_local_irq_restore(flags);
  300. }
  301. }
  302. #endif /* CONFIG_HOTPLUG_CPU */