irq.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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(unsigned int irq)
  36. {
  37. unsigned long flags;
  38. u16 tmp;
  39. flags = arch_local_cli_save();
  40. GxICR_u8(irq) = GxICR_DETECT;
  41. tmp = GxICR(irq);
  42. arch_local_irq_restore(flags);
  43. }
  44. static void __mask_and_set_icr(unsigned int irq,
  45. unsigned int mask, unsigned int set)
  46. {
  47. unsigned long flags;
  48. u16 tmp;
  49. flags = arch_local_cli_save();
  50. tmp = GxICR(irq);
  51. GxICR(irq) = (tmp & mask) | set;
  52. tmp = GxICR(irq);
  53. arch_local_irq_restore(flags);
  54. }
  55. static void mn10300_cpupic_mask(unsigned int irq)
  56. {
  57. __mask_and_set_icr(irq, GxICR_LEVEL, 0);
  58. }
  59. static void mn10300_cpupic_mask_ack(unsigned int irq)
  60. {
  61. #ifdef CONFIG_SMP
  62. unsigned long flags;
  63. u16 tmp;
  64. flags = arch_local_cli_save();
  65. if (!test_and_clear_bit(irq, irq_affinity_request)) {
  66. tmp = GxICR(irq);
  67. GxICR(irq) = (tmp & GxICR_LEVEL) | GxICR_DETECT;
  68. tmp = GxICR(irq);
  69. } else {
  70. u16 tmp2;
  71. tmp = GxICR(irq);
  72. GxICR(irq) = (tmp & GxICR_LEVEL);
  73. tmp2 = GxICR(irq);
  74. irq_affinity_online[irq] =
  75. any_online_cpu(*irq_desc[irq].affinity);
  76. CROSS_GxICR(irq, irq_affinity_online[irq]) =
  77. (tmp & (GxICR_LEVEL | GxICR_ENABLE)) | GxICR_DETECT;
  78. tmp = CROSS_GxICR(irq, irq_affinity_online[irq]);
  79. }
  80. arch_local_irq_restore(flags);
  81. #else /* CONFIG_SMP */
  82. __mask_and_set_icr(irq, GxICR_LEVEL, GxICR_DETECT);
  83. #endif /* CONFIG_SMP */
  84. }
  85. static void mn10300_cpupic_unmask(unsigned int irq)
  86. {
  87. __mask_and_set_icr(irq, GxICR_LEVEL, GxICR_ENABLE);
  88. }
  89. static void mn10300_cpupic_unmask_clear(unsigned int irq)
  90. {
  91. /* the MN10300 PIC latches its interrupt request bit, even after the
  92. * device has ceased to assert its interrupt line and the interrupt
  93. * channel has been disabled in the PIC, so for level-triggered
  94. * interrupts we need to clear the request bit when we re-enable */
  95. #ifdef CONFIG_SMP
  96. unsigned long flags;
  97. u16 tmp;
  98. flags = arch_local_cli_save();
  99. if (!test_and_clear_bit(irq, irq_affinity_request)) {
  100. tmp = GxICR(irq);
  101. GxICR(irq) = (tmp & GxICR_LEVEL) | GxICR_ENABLE | GxICR_DETECT;
  102. tmp = GxICR(irq);
  103. } else {
  104. tmp = GxICR(irq);
  105. irq_affinity_online[irq] = any_online_cpu(*irq_desc[irq].affinity);
  106. CROSS_GxICR(irq, irq_affinity_online[irq]) = (tmp & GxICR_LEVEL) | GxICR_ENABLE | GxICR_DETECT;
  107. tmp = CROSS_GxICR(irq, irq_affinity_online[irq]);
  108. }
  109. arch_local_irq_restore(flags);
  110. #else /* CONFIG_SMP */
  111. __mask_and_set_icr(irq, GxICR_LEVEL, GxICR_ENABLE | GxICR_DETECT);
  112. #endif /* CONFIG_SMP */
  113. }
  114. #ifdef CONFIG_SMP
  115. static int
  116. mn10300_cpupic_setaffinity(unsigned int irq, const struct cpumask *mask)
  117. {
  118. unsigned long flags;
  119. int err;
  120. flags = arch_local_cli_save();
  121. /* check irq no */
  122. switch (irq) {
  123. case TMJCIRQ:
  124. case RESCHEDULE_IPI:
  125. case CALL_FUNC_SINGLE_IPI:
  126. case LOCAL_TIMER_IPI:
  127. case FLUSH_CACHE_IPI:
  128. case CALL_FUNCTION_NMI_IPI:
  129. case GDB_NMI_IPI:
  130. #ifdef CONFIG_MN10300_TTYSM0
  131. case SC0RXIRQ:
  132. case SC0TXIRQ:
  133. #ifdef CONFIG_MN10300_TTYSM0_TIMER8
  134. case TM8IRQ:
  135. #elif CONFIG_MN10300_TTYSM0_TIMER2
  136. case TM2IRQ:
  137. #endif /* CONFIG_MN10300_TTYSM0_TIMER8 */
  138. #endif /* CONFIG_MN10300_TTYSM0 */
  139. #ifdef CONFIG_MN10300_TTYSM1
  140. case SC1RXIRQ:
  141. case SC1TXIRQ:
  142. #ifdef CONFIG_MN10300_TTYSM1_TIMER12
  143. case TM12IRQ:
  144. #elif CONFIG_MN10300_TTYSM1_TIMER9
  145. case TM9IRQ:
  146. #elif CONFIG_MN10300_TTYSM1_TIMER3
  147. case TM3IRQ:
  148. #endif /* CONFIG_MN10300_TTYSM1_TIMER12 */
  149. #endif /* CONFIG_MN10300_TTYSM1 */
  150. #ifdef CONFIG_MN10300_TTYSM2
  151. case SC2RXIRQ:
  152. case SC2TXIRQ:
  153. case TM10IRQ:
  154. #endif /* CONFIG_MN10300_TTYSM2 */
  155. err = -1;
  156. break;
  157. default:
  158. set_bit(irq, irq_affinity_request);
  159. err = 0;
  160. break;
  161. }
  162. arch_local_irq_restore(flags);
  163. return err;
  164. }
  165. #endif /* CONFIG_SMP */
  166. /*
  167. * MN10300 PIC level-triggered IRQ handling.
  168. *
  169. * The PIC has no 'ACK' function per se. It is possible to clear individual
  170. * channel latches, but each latch relatches whether or not the channel is
  171. * masked, so we need to clear the latch when we unmask the channel.
  172. *
  173. * Also for this reason, we don't supply an ack() op (it's unused anyway if
  174. * mask_ack() is provided), and mask_ack() just masks.
  175. */
  176. static struct irq_chip mn10300_cpu_pic_level = {
  177. .name = "cpu_l",
  178. .disable = mn10300_cpupic_mask,
  179. .enable = mn10300_cpupic_unmask_clear,
  180. .ack = NULL,
  181. .mask = mn10300_cpupic_mask,
  182. .mask_ack = mn10300_cpupic_mask,
  183. .unmask = mn10300_cpupic_unmask_clear,
  184. #ifdef CONFIG_SMP
  185. .set_affinity = mn10300_cpupic_setaffinity,
  186. #endif
  187. };
  188. /*
  189. * MN10300 PIC edge-triggered IRQ handling.
  190. *
  191. * We use the latch clearing function of the PIC as the 'ACK' function.
  192. */
  193. static struct irq_chip mn10300_cpu_pic_edge = {
  194. .name = "cpu_e",
  195. .disable = mn10300_cpupic_mask,
  196. .enable = mn10300_cpupic_unmask,
  197. .ack = mn10300_cpupic_ack,
  198. .mask = mn10300_cpupic_mask,
  199. .mask_ack = mn10300_cpupic_mask_ack,
  200. .unmask = mn10300_cpupic_unmask,
  201. #ifdef CONFIG_SMP
  202. .set_affinity = mn10300_cpupic_setaffinity,
  203. #endif
  204. };
  205. /*
  206. * 'what should we do if we get a hw irq event on an illegal vector'.
  207. * each architecture has to answer this themselves.
  208. */
  209. void ack_bad_irq(int irq)
  210. {
  211. printk(KERN_WARNING "unexpected IRQ trap at vector %02x\n", irq);
  212. }
  213. /*
  214. * change the level at which an IRQ executes
  215. * - must not be called whilst interrupts are being processed!
  216. */
  217. void set_intr_level(int irq, u16 level)
  218. {
  219. BUG_ON(in_interrupt());
  220. __mask_and_set_icr(irq, GxICR_ENABLE, level);
  221. }
  222. void mn10300_intc_set_level(unsigned int irq, unsigned int level)
  223. {
  224. set_intr_level(irq, NUM2GxICR_LEVEL(level) & GxICR_LEVEL);
  225. }
  226. void mn10300_intc_clear(unsigned int irq)
  227. {
  228. __mask_and_set_icr(irq, GxICR_LEVEL | GxICR_ENABLE, GxICR_DETECT);
  229. }
  230. void mn10300_intc_set(unsigned int irq)
  231. {
  232. __mask_and_set_icr(irq, 0, GxICR_REQUEST | GxICR_DETECT);
  233. }
  234. void mn10300_intc_enable(unsigned int irq)
  235. {
  236. mn10300_cpupic_unmask(irq);
  237. }
  238. void mn10300_intc_disable(unsigned int irq)
  239. {
  240. mn10300_cpupic_mask(irq);
  241. }
  242. /*
  243. * mark an interrupt to be ACK'd after interrupt handlers have been run rather
  244. * than before
  245. * - see Documentation/mn10300/features.txt
  246. */
  247. void mn10300_set_lateack_irq_type(int irq)
  248. {
  249. set_irq_chip_and_handler(irq, &mn10300_cpu_pic_level,
  250. handle_level_irq);
  251. }
  252. /*
  253. * initialise the interrupt system
  254. */
  255. void __init init_IRQ(void)
  256. {
  257. int irq;
  258. for (irq = 0; irq < NR_IRQS; irq++)
  259. if (irq_desc[irq].chip == &no_irq_chip)
  260. /* due to the PIC latching interrupt requests, even
  261. * when the IRQ is disabled, IRQ_PENDING is superfluous
  262. * and we can use handle_level_irq() for edge-triggered
  263. * interrupts */
  264. set_irq_chip_and_handler(irq, &mn10300_cpu_pic_edge,
  265. handle_level_irq);
  266. unit_init_IRQ();
  267. }
  268. /*
  269. * handle normal device IRQs
  270. */
  271. asmlinkage void do_IRQ(void)
  272. {
  273. unsigned long sp, epsw, irq_disabled_epsw, old_irq_enabled_epsw;
  274. unsigned int cpu_id = smp_processor_id();
  275. int irq;
  276. sp = current_stack_pointer();
  277. BUG_ON(sp - (sp & ~(THREAD_SIZE - 1)) < STACK_WARN);
  278. /* make sure local_irq_enable() doesn't muck up the interrupt priority
  279. * setting in EPSW */
  280. old_irq_enabled_epsw = __mn10300_irq_enabled_epsw[cpu_id];
  281. local_save_flags(epsw);
  282. __mn10300_irq_enabled_epsw[cpu_id] = EPSW_IE | (EPSW_IM & epsw);
  283. irq_disabled_epsw = EPSW_IE | MN10300_CLI_LEVEL;
  284. #ifdef CONFIG_MN10300_WD_TIMER
  285. __IRQ_STAT(cpu_id, __irq_count)++;
  286. #endif
  287. irq_enter();
  288. for (;;) {
  289. /* ask the interrupt controller for the next IRQ to process
  290. * - the result we get depends on EPSW.IM
  291. */
  292. irq = IAGR & IAGR_GN;
  293. if (!irq)
  294. break;
  295. local_irq_restore(irq_disabled_epsw);
  296. generic_handle_irq(irq >> 2);
  297. /* restore IRQ controls for IAGR access */
  298. local_irq_restore(epsw);
  299. }
  300. __mn10300_irq_enabled_epsw[cpu_id] = old_irq_enabled_epsw;
  301. irq_exit();
  302. }
  303. /*
  304. * Display interrupt management information through /proc/interrupts
  305. */
  306. int show_interrupts(struct seq_file *p, void *v)
  307. {
  308. int i = *(loff_t *) v, j, cpu;
  309. struct irqaction *action;
  310. unsigned long flags;
  311. switch (i) {
  312. /* display column title bar naming CPUs */
  313. case 0:
  314. seq_printf(p, " ");
  315. for (j = 0; j < NR_CPUS; j++)
  316. if (cpu_online(j))
  317. seq_printf(p, "CPU%d ", j);
  318. seq_putc(p, '\n');
  319. break;
  320. /* display information rows, one per active CPU */
  321. case 1 ... NR_IRQS - 1:
  322. raw_spin_lock_irqsave(&irq_desc[i].lock, flags);
  323. action = irq_desc[i].action;
  324. if (action) {
  325. seq_printf(p, "%3d: ", i);
  326. for_each_present_cpu(cpu)
  327. seq_printf(p, "%10u ", kstat_irqs_cpu(i, cpu));
  328. if (i < NR_CPU_IRQS)
  329. seq_printf(p, " %14s.%u",
  330. irq_desc[i].chip->name,
  331. (GxICR(i) & GxICR_LEVEL) >>
  332. GxICR_LEVEL_SHIFT);
  333. else
  334. seq_printf(p, " %14s",
  335. irq_desc[i].chip->name);
  336. seq_printf(p, " %s", action->name);
  337. for (action = action->next;
  338. action;
  339. action = action->next)
  340. seq_printf(p, ", %s", action->name);
  341. seq_putc(p, '\n');
  342. }
  343. raw_spin_unlock_irqrestore(&irq_desc[i].lock, flags);
  344. break;
  345. /* polish off with NMI and error counters */
  346. case NR_IRQS:
  347. #ifdef CONFIG_MN10300_WD_TIMER
  348. seq_printf(p, "NMI: ");
  349. for (j = 0; j < NR_CPUS; j++)
  350. if (cpu_online(j))
  351. seq_printf(p, "%10u ", nmi_count(j));
  352. seq_putc(p, '\n');
  353. #endif
  354. seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
  355. break;
  356. }
  357. return 0;
  358. }
  359. #ifdef CONFIG_HOTPLUG_CPU
  360. void migrate_irqs(void)
  361. {
  362. irq_desc_t *desc;
  363. int irq;
  364. unsigned int self, new;
  365. unsigned long flags;
  366. self = smp_processor_id();
  367. for (irq = 0; irq < NR_IRQS; irq++) {
  368. desc = irq_desc + irq;
  369. if (desc->status == IRQ_PER_CPU)
  370. continue;
  371. if (cpu_isset(self, irq_desc[irq].affinity) &&
  372. !cpus_intersects(irq_affinity[irq], cpu_online_map)) {
  373. int cpu_id;
  374. cpu_id = first_cpu(cpu_online_map);
  375. cpu_set(cpu_id, irq_desc[irq].affinity);
  376. }
  377. /* We need to operate irq_affinity_online atomically. */
  378. arch_local_cli_save(flags);
  379. if (irq_affinity_online[irq] == self) {
  380. u16 x, tmp;
  381. x = GxICR(irq);
  382. GxICR(irq) = x & GxICR_LEVEL;
  383. tmp = GxICR(irq);
  384. new = any_online_cpu(irq_desc[irq].affinity);
  385. irq_affinity_online[irq] = new;
  386. CROSS_GxICR(irq, new) =
  387. (x & GxICR_LEVEL) | GxICR_DETECT;
  388. tmp = CROSS_GxICR(irq, new);
  389. x &= GxICR_LEVEL | GxICR_ENABLE;
  390. if (GxICR(irq) & GxICR_REQUEST)
  391. x |= GxICR_REQUEST | GxICR_DETECT;
  392. CROSS_GxICR(irq, new) = x;
  393. tmp = CROSS_GxICR(irq, new);
  394. }
  395. arch_local_irq_restore(flags);
  396. }
  397. }
  398. #endif /* CONFIG_HOTPLUG_CPU */