irq.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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. any_online_cpu(*d->affinity);
  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] = any_online_cpu(*d->affinity);
  109. CROSS_GxICR(irq, irq_affinity_online[irq]) = (tmp & GxICR_LEVEL) | GxICR_ENABLE | GxICR_DETECT;
  110. tmp = CROSS_GxICR(irq, irq_affinity_online[irq]);
  111. }
  112. arch_local_irq_restore(flags);
  113. #else /* CONFIG_SMP */
  114. __mask_and_set_icr(irq, GxICR_LEVEL, GxICR_ENABLE | GxICR_DETECT);
  115. #endif /* CONFIG_SMP */
  116. }
  117. #ifdef CONFIG_SMP
  118. static int
  119. mn10300_cpupic_setaffinity(struct irq_data *d, const struct cpumask *mask,
  120. bool force)
  121. {
  122. unsigned long flags;
  123. int err;
  124. flags = arch_local_cli_save();
  125. /* check irq no */
  126. switch (d->irq) {
  127. case TMJCIRQ:
  128. case RESCHEDULE_IPI:
  129. case CALL_FUNC_SINGLE_IPI:
  130. case LOCAL_TIMER_IPI:
  131. case FLUSH_CACHE_IPI:
  132. case CALL_FUNCTION_NMI_IPI:
  133. case DEBUGGER_NMI_IPI:
  134. #ifdef CONFIG_MN10300_TTYSM0
  135. case SC0RXIRQ:
  136. case SC0TXIRQ:
  137. #ifdef CONFIG_MN10300_TTYSM0_TIMER8
  138. case TM8IRQ:
  139. #elif CONFIG_MN10300_TTYSM0_TIMER2
  140. case TM2IRQ:
  141. #endif /* CONFIG_MN10300_TTYSM0_TIMER8 */
  142. #endif /* CONFIG_MN10300_TTYSM0 */
  143. #ifdef CONFIG_MN10300_TTYSM1
  144. case SC1RXIRQ:
  145. case SC1TXIRQ:
  146. #ifdef CONFIG_MN10300_TTYSM1_TIMER12
  147. case TM12IRQ:
  148. #elif CONFIG_MN10300_TTYSM1_TIMER9
  149. case TM9IRQ:
  150. #elif CONFIG_MN10300_TTYSM1_TIMER3
  151. case TM3IRQ:
  152. #endif /* CONFIG_MN10300_TTYSM1_TIMER12 */
  153. #endif /* CONFIG_MN10300_TTYSM1 */
  154. #ifdef CONFIG_MN10300_TTYSM2
  155. case SC2RXIRQ:
  156. case SC2TXIRQ:
  157. case TM10IRQ:
  158. #endif /* CONFIG_MN10300_TTYSM2 */
  159. err = -1;
  160. break;
  161. default:
  162. set_bit(d->irq, irq_affinity_request);
  163. err = 0;
  164. break;
  165. }
  166. arch_local_irq_restore(flags);
  167. return err;
  168. }
  169. #endif /* CONFIG_SMP */
  170. /*
  171. * MN10300 PIC level-triggered IRQ handling.
  172. *
  173. * The PIC has no 'ACK' function per se. It is possible to clear individual
  174. * channel latches, but each latch relatches whether or not the channel is
  175. * masked, so we need to clear the latch when we unmask the channel.
  176. *
  177. * Also for this reason, we don't supply an ack() op (it's unused anyway if
  178. * mask_ack() is provided), and mask_ack() just masks.
  179. */
  180. static struct irq_chip mn10300_cpu_pic_level = {
  181. .name = "cpu_l",
  182. .irq_disable = mn10300_cpupic_mask,
  183. .irq_enable = mn10300_cpupic_unmask_clear,
  184. .irq_ack = NULL,
  185. .irq_mask = mn10300_cpupic_mask,
  186. .irq_mask_ack = mn10300_cpupic_mask,
  187. .irq_unmask = mn10300_cpupic_unmask_clear,
  188. #ifdef CONFIG_SMP
  189. .irq_set_affinity = mn10300_cpupic_setaffinity,
  190. #endif
  191. };
  192. /*
  193. * MN10300 PIC edge-triggered IRQ handling.
  194. *
  195. * We use the latch clearing function of the PIC as the 'ACK' function.
  196. */
  197. static struct irq_chip mn10300_cpu_pic_edge = {
  198. .name = "cpu_e",
  199. .irq_disable = mn10300_cpupic_mask,
  200. .irq_enable = mn10300_cpupic_unmask,
  201. .irq_ack = mn10300_cpupic_ack,
  202. .irq_mask = mn10300_cpupic_mask,
  203. .irq_mask_ack = mn10300_cpupic_mask_ack,
  204. .irq_unmask = mn10300_cpupic_unmask,
  205. #ifdef CONFIG_SMP
  206. .irq_set_affinity = mn10300_cpupic_setaffinity,
  207. #endif
  208. };
  209. /*
  210. * 'what should we do if we get a hw irq event on an illegal vector'.
  211. * each architecture has to answer this themselves.
  212. */
  213. void ack_bad_irq(int irq)
  214. {
  215. printk(KERN_WARNING "unexpected IRQ trap at vector %02x\n", irq);
  216. }
  217. /*
  218. * change the level at which an IRQ executes
  219. * - must not be called whilst interrupts are being processed!
  220. */
  221. void set_intr_level(int irq, u16 level)
  222. {
  223. BUG_ON(in_interrupt());
  224. __mask_and_set_icr(irq, GxICR_ENABLE, level);
  225. }
  226. /*
  227. * mark an interrupt to be ACK'd after interrupt handlers have been run rather
  228. * than before
  229. * - see Documentation/mn10300/features.txt
  230. */
  231. void mn10300_set_lateack_irq_type(int irq)
  232. {
  233. irq_set_chip_and_handler(irq, &mn10300_cpu_pic_level,
  234. handle_level_irq);
  235. }
  236. /*
  237. * initialise the interrupt system
  238. */
  239. void __init init_IRQ(void)
  240. {
  241. int irq;
  242. for (irq = 0; irq < NR_IRQS; irq++)
  243. if (irq_get_chip(irq) == &no_irq_chip)
  244. /* due to the PIC latching interrupt requests, even
  245. * when the IRQ is disabled, IRQ_PENDING is superfluous
  246. * and we can use handle_level_irq() for edge-triggered
  247. * interrupts */
  248. irq_set_chip_and_handler(irq, &mn10300_cpu_pic_edge,
  249. handle_level_irq);
  250. unit_init_IRQ();
  251. }
  252. /*
  253. * handle normal device IRQs
  254. */
  255. asmlinkage void do_IRQ(void)
  256. {
  257. unsigned long sp, epsw, irq_disabled_epsw, old_irq_enabled_epsw;
  258. unsigned int cpu_id = smp_processor_id();
  259. int irq;
  260. sp = current_stack_pointer();
  261. BUG_ON(sp - (sp & ~(THREAD_SIZE - 1)) < STACK_WARN);
  262. /* make sure local_irq_enable() doesn't muck up the interrupt priority
  263. * setting in EPSW */
  264. old_irq_enabled_epsw = __mn10300_irq_enabled_epsw[cpu_id];
  265. local_save_flags(epsw);
  266. __mn10300_irq_enabled_epsw[cpu_id] = EPSW_IE | (EPSW_IM & epsw);
  267. irq_disabled_epsw = EPSW_IE | MN10300_CLI_LEVEL;
  268. #ifdef CONFIG_MN10300_WD_TIMER
  269. __IRQ_STAT(cpu_id, __irq_count)++;
  270. #endif
  271. irq_enter();
  272. for (;;) {
  273. /* ask the interrupt controller for the next IRQ to process
  274. * - the result we get depends on EPSW.IM
  275. */
  276. irq = IAGR & IAGR_GN;
  277. if (!irq)
  278. break;
  279. local_irq_restore(irq_disabled_epsw);
  280. generic_handle_irq(irq >> 2);
  281. /* restore IRQ controls for IAGR access */
  282. local_irq_restore(epsw);
  283. }
  284. __mn10300_irq_enabled_epsw[cpu_id] = old_irq_enabled_epsw;
  285. irq_exit();
  286. }
  287. /*
  288. * Display interrupt management information through /proc/interrupts
  289. */
  290. int arch_show_interrupts(struct seq_file *p, int prec)
  291. {
  292. #ifdef CONFIG_MN10300_WD_TIMER
  293. int j;
  294. seq_printf(p, "%*s: ", prec, "NMI");
  295. for (j = 0; j < NR_CPUS; j++)
  296. if (cpu_online(j))
  297. seq_printf(p, "%10u ", nmi_count(j));
  298. seq_putc(p, '\n');
  299. #endif
  300. seq_printf(p, "%*s: ", prec, "ERR");
  301. seq_printf(p, "%10u\n", atomic_read(&irq_err_count));
  302. return 0;
  303. }
  304. #ifdef CONFIG_HOTPLUG_CPU
  305. void migrate_irqs(void)
  306. {
  307. int irq;
  308. unsigned int self, new;
  309. unsigned long flags;
  310. self = smp_processor_id();
  311. for (irq = 0; irq < NR_IRQS; irq++) {
  312. struct irq_data *data = irq_get_irq_data(irq);
  313. if (irqd_is_per_cpu(data))
  314. continue;
  315. if (cpu_isset(self, data->affinity) &&
  316. !cpus_intersects(irq_affinity[irq], cpu_online_map)) {
  317. int cpu_id;
  318. cpu_id = first_cpu(cpu_online_map);
  319. cpu_set(cpu_id, data->affinity);
  320. }
  321. /* We need to operate irq_affinity_online atomically. */
  322. arch_local_cli_save(flags);
  323. if (irq_affinity_online[irq] == self) {
  324. u16 x, tmp;
  325. x = GxICR(irq);
  326. GxICR(irq) = x & GxICR_LEVEL;
  327. tmp = GxICR(irq);
  328. new = any_online_cpu(data->affinity);
  329. irq_affinity_online[irq] = new;
  330. CROSS_GxICR(irq, new) =
  331. (x & GxICR_LEVEL) | GxICR_DETECT;
  332. tmp = CROSS_GxICR(irq, new);
  333. x &= GxICR_LEVEL | GxICR_ENABLE;
  334. if (GxICR(irq) & GxICR_REQUEST)
  335. x |= GxICR_REQUEST | GxICR_DETECT;
  336. CROSS_GxICR(irq, new) = x;
  337. tmp = CROSS_GxICR(irq, new);
  338. }
  339. arch_local_irq_restore(flags);
  340. }
  341. }
  342. #endif /* CONFIG_HOTPLUG_CPU */