irq.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  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. #ifdef CONFIG_SMP
  19. #undef GxICR
  20. #define GxICR(X) CROSS_GxICR(X, irq_affinity_online[X])
  21. #undef GxICR_u8
  22. #define GxICR_u8(X) CROSS_GxICR_u8(X, irq_affinity_online[X])
  23. #endif /* CONFIG_SMP */
  24. unsigned long __mn10300_irq_enabled_epsw[NR_CPUS] __cacheline_aligned_in_smp = {
  25. [0 ... NR_CPUS - 1] = EPSW_IE | EPSW_IM_7
  26. };
  27. EXPORT_SYMBOL(__mn10300_irq_enabled_epsw);
  28. #ifdef CONFIG_SMP
  29. static char irq_affinity_online[NR_IRQS] = {
  30. [0 ... NR_IRQS - 1] = 0
  31. };
  32. #define NR_IRQ_WORDS ((NR_IRQS + 31) / 32)
  33. static unsigned long irq_affinity_request[NR_IRQ_WORDS] = {
  34. [0 ... NR_IRQ_WORDS - 1] = 0
  35. };
  36. #endif /* CONFIG_SMP */
  37. atomic_t irq_err_count;
  38. /*
  39. * MN10300 interrupt controller operations
  40. */
  41. static void mn10300_cpupic_ack(unsigned int irq)
  42. {
  43. unsigned long flags;
  44. u16 tmp;
  45. flags = arch_local_cli_save();
  46. GxICR_u8(irq) = GxICR_DETECT;
  47. tmp = GxICR(irq);
  48. arch_local_irq_restore(flags);
  49. }
  50. static void __mask_and_set_icr(unsigned int irq,
  51. unsigned int mask, unsigned int set)
  52. {
  53. unsigned long flags;
  54. u16 tmp;
  55. flags = arch_local_cli_save();
  56. tmp = GxICR(irq);
  57. GxICR(irq) = (tmp & mask) | set;
  58. tmp = GxICR(irq);
  59. arch_local_irq_restore(flags);
  60. }
  61. static void mn10300_cpupic_mask(unsigned int irq)
  62. {
  63. __mask_and_set_icr(irq, GxICR_LEVEL, 0);
  64. }
  65. static void mn10300_cpupic_mask_ack(unsigned int irq)
  66. {
  67. #ifdef CONFIG_SMP
  68. unsigned long flags;
  69. u16 tmp;
  70. flags = arch_local_cli_save();
  71. if (!test_and_clear_bit(irq, irq_affinity_request)) {
  72. tmp = GxICR(irq);
  73. GxICR(irq) = (tmp & GxICR_LEVEL) | GxICR_DETECT;
  74. tmp = GxICR(irq);
  75. } else {
  76. u16 tmp2;
  77. tmp = GxICR(irq);
  78. GxICR(irq) = (tmp & GxICR_LEVEL);
  79. tmp2 = GxICR(irq);
  80. irq_affinity_online[irq] = any_online_cpu(*irq_desc[irq].affinity);
  81. GxICR(irq) = (tmp & (GxICR_LEVEL | GxICR_ENABLE)) | GxICR_DETECT;
  82. tmp = GxICR(irq);
  83. }
  84. arch_local_irq_restore(flags);
  85. #else /* CONFIG_SMP */
  86. __mask_and_set_icr(irq, GxICR_LEVEL, GxICR_DETECT);
  87. #endif /* CONFIG_SMP */
  88. }
  89. static void mn10300_cpupic_unmask(unsigned int irq)
  90. {
  91. __mask_and_set_icr(irq, GxICR_LEVEL, GxICR_ENABLE);
  92. }
  93. static void mn10300_cpupic_unmask_clear(unsigned int irq)
  94. {
  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] = any_online_cpu(*irq_desc[irq].affinity);
  110. GxICR(irq) = (tmp & GxICR_LEVEL) | GxICR_ENABLE | GxICR_DETECT;
  111. tmp = GxICR(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(unsigned int irq, const struct cpumask *mask)
  121. {
  122. unsigned long flags;
  123. int err;
  124. flags = arch_local_cli_save();
  125. /* check irq no */
  126. switch (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 GDB_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(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. .disable = mn10300_cpupic_mask,
  183. .enable = mn10300_cpupic_unmask_clear,
  184. .ack = NULL,
  185. .mask = mn10300_cpupic_mask,
  186. .mask_ack = mn10300_cpupic_mask,
  187. .unmask = mn10300_cpupic_unmask_clear,
  188. #ifdef CONFIG_SMP
  189. .set_affinity = mn10300_cpupic_setaffinity,
  190. #endif /* CONFIG_SMP */
  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. .disable = mn10300_cpupic_mask,
  200. .enable = mn10300_cpupic_unmask,
  201. .ack = mn10300_cpupic_ack,
  202. .mask = mn10300_cpupic_mask,
  203. .mask_ack = mn10300_cpupic_mask_ack,
  204. .unmask = mn10300_cpupic_unmask,
  205. #ifdef CONFIG_SMP
  206. .set_affinity = mn10300_cpupic_setaffinity,
  207. #endif /* CONFIG_SMP */
  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. void mn10300_intc_set_level(unsigned int irq, unsigned int level)
  227. {
  228. set_intr_level(irq, NUM2GxICR_LEVEL(level) & GxICR_LEVEL);
  229. }
  230. void mn10300_intc_clear(unsigned int irq)
  231. {
  232. __mask_and_set_icr(irq, GxICR_LEVEL | GxICR_ENABLE, GxICR_DETECT);
  233. }
  234. void mn10300_intc_set(unsigned int irq)
  235. {
  236. __mask_and_set_icr(irq, 0, GxICR_REQUEST | GxICR_DETECT);
  237. }
  238. void mn10300_intc_enable(unsigned int irq)
  239. {
  240. mn10300_cpupic_unmask(irq);
  241. }
  242. void mn10300_intc_disable(unsigned int irq)
  243. {
  244. mn10300_cpupic_mask(irq);
  245. }
  246. /*
  247. * mark an interrupt to be ACK'd after interrupt handlers have been run rather
  248. * than before
  249. * - see Documentation/mn10300/features.txt
  250. */
  251. void mn10300_set_lateack_irq_type(int irq)
  252. {
  253. set_irq_chip_and_handler(irq, &mn10300_cpu_pic_level,
  254. handle_level_irq);
  255. }
  256. /*
  257. * initialise the interrupt system
  258. */
  259. void __init init_IRQ(void)
  260. {
  261. int irq;
  262. for (irq = 0; irq < NR_IRQS; irq++)
  263. if (irq_desc[irq].chip == &no_irq_chip)
  264. /* due to the PIC latching interrupt requests, even
  265. * when the IRQ is disabled, IRQ_PENDING is superfluous
  266. * and we can use handle_level_irq() for edge-triggered
  267. * interrupts */
  268. set_irq_chip_and_handler(irq, &mn10300_cpu_pic_edge,
  269. handle_level_irq);
  270. unit_init_IRQ();
  271. }
  272. /*
  273. * handle normal device IRQs
  274. */
  275. asmlinkage void do_IRQ(void)
  276. {
  277. unsigned long sp, epsw, irq_disabled_epsw, old_irq_enabled_epsw;
  278. unsigned int cpu_id = smp_processor_id();
  279. int irq;
  280. sp = current_stack_pointer();
  281. BUG_ON(sp - (sp & ~(THREAD_SIZE - 1)) < STACK_WARN);
  282. /* make sure local_irq_enable() doesn't muck up the interrupt priority
  283. * setting in EPSW */
  284. old_irq_enabled_epsw = __mn10300_irq_enabled_epsw[cpu_id];
  285. local_save_flags(epsw);
  286. __mn10300_irq_enabled_epsw[cpu_id] = EPSW_IE | (EPSW_IM & epsw);
  287. irq_disabled_epsw = EPSW_IE | MN10300_CLI_LEVEL;
  288. #ifdef CONFIG_MN10300_WD_TIMER
  289. __IRQ_STAT(cpu_id, __irq_count)++;
  290. #endif
  291. irq_enter();
  292. for (;;) {
  293. /* ask the interrupt controller for the next IRQ to process
  294. * - the result we get depends on EPSW.IM
  295. */
  296. irq = IAGR & IAGR_GN;
  297. if (!irq)
  298. break;
  299. local_irq_restore(irq_disabled_epsw);
  300. generic_handle_irq(irq >> 2);
  301. /* restore IRQ controls for IAGR access */
  302. local_irq_restore(epsw);
  303. }
  304. __mn10300_irq_enabled_epsw[cpu_id] = old_irq_enabled_epsw;
  305. irq_exit();
  306. }
  307. /*
  308. * Display interrupt management information through /proc/interrupts
  309. */
  310. int show_interrupts(struct seq_file *p, void *v)
  311. {
  312. int i = *(loff_t *) v, j, cpu;
  313. struct irqaction *action;
  314. unsigned long flags;
  315. switch (i) {
  316. /* display column title bar naming CPUs */
  317. case 0:
  318. seq_printf(p, " ");
  319. for (j = 0; j < NR_CPUS; j++)
  320. if (cpu_online(j))
  321. seq_printf(p, "CPU%d ", j);
  322. seq_putc(p, '\n');
  323. break;
  324. /* display information rows, one per active CPU */
  325. case 1 ... NR_IRQS - 1:
  326. raw_spin_lock_irqsave(&irq_desc[i].lock, flags);
  327. action = irq_desc[i].action;
  328. if (action) {
  329. seq_printf(p, "%3d: ", i);
  330. for_each_present_cpu(cpu)
  331. seq_printf(p, "%10u ", kstat_irqs_cpu(i, cpu));
  332. seq_printf(p, " %14s.%u", irq_desc[i].chip->name,
  333. (GxICR(i) & GxICR_LEVEL) >>
  334. GxICR_LEVEL_SHIFT);
  335. seq_printf(p, " %s", action->name);
  336. for (action = action->next;
  337. action;
  338. action = action->next)
  339. seq_printf(p, ", %s", action->name);
  340. seq_putc(p, '\n');
  341. }
  342. raw_spin_unlock_irqrestore(&irq_desc[i].lock, flags);
  343. break;
  344. /* polish off with NMI and error counters */
  345. case NR_IRQS:
  346. #ifdef CONFIG_MN10300_WD_TIMER
  347. seq_printf(p, "NMI: ");
  348. for (j = 0; j < NR_CPUS; j++)
  349. if (cpu_online(j))
  350. seq_printf(p, "%10u ", nmi_count(j));
  351. seq_putc(p, '\n');
  352. #endif
  353. seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
  354. break;
  355. }
  356. return 0;
  357. }
  358. #ifdef CONFIG_HOTPLUG_CPU
  359. void migrate_irqs(void)
  360. {
  361. irq_desc_t *desc;
  362. int irq;
  363. unsigned int self, new;
  364. unsigned long flags;
  365. self = smp_processor_id();
  366. for (irq = 0; irq < NR_IRQS; irq++) {
  367. desc = irq_desc + irq;
  368. if (desc->status == IRQ_PER_CPU)
  369. continue;
  370. if (cpu_isset(self, irq_desc[irq].affinity) &&
  371. !cpus_intersects(irq_affinity[irq], cpu_online_map)) {
  372. int cpu_id;
  373. cpu_id = first_cpu(cpu_online_map);
  374. cpu_set(cpu_id, irq_desc[irq].affinity);
  375. }
  376. /* We need to operate irq_affinity_online atomically. */
  377. arch_local_cli_save(flags);
  378. if (irq_affinity_online[irq] == self) {
  379. u16 x, tmp;
  380. x = CROSS_GxICR(irq, self);
  381. CROSS_GxICR(irq, self) = x & GxICR_LEVEL;
  382. tmp = CROSS_GxICR(irq, self);
  383. new = any_online_cpu(irq_desc[irq].affinity);
  384. irq_affinity_online[irq] = new;
  385. CROSS_GxICR(irq, new) =
  386. (x & GxICR_LEVEL) | GxICR_DETECT;
  387. tmp = CROSS_GxICR(irq, new);
  388. x &= GxICR_LEVEL | GxICR_ENABLE;
  389. if (CROSS_GxICR(irq, self) & GxICR_REQUEST)
  390. x |= GxICR_REQUEST | GxICR_DETECT;
  391. CROSS_GxICR(irq, new) = x;
  392. tmp = CROSS_GxICR(irq, new);
  393. }
  394. arch_local_irq_restore(flags);
  395. }
  396. }
  397. #endif /* CONFIG_HOTPLUG_CPU */