irq.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  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. set_irq_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 (get_irq_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. set_irq_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 show_interrupts(struct seq_file *p, void *v)
  291. {
  292. int i = *(loff_t *) v, j, cpu;
  293. struct irqaction *action;
  294. unsigned long flags;
  295. switch (i) {
  296. /* display column title bar naming CPUs */
  297. case 0:
  298. seq_printf(p, " ");
  299. for (j = 0; j < NR_CPUS; j++)
  300. if (cpu_online(j))
  301. seq_printf(p, "CPU%d ", j);
  302. seq_putc(p, '\n');
  303. break;
  304. /* display information rows, one per active CPU */
  305. case 1 ... NR_IRQS - 1:
  306. raw_spin_lock_irqsave(&irq_desc[i].lock, flags);
  307. action = irq_desc[i].action;
  308. if (action) {
  309. seq_printf(p, "%3d: ", i);
  310. for_each_present_cpu(cpu)
  311. seq_printf(p, "%10u ", kstat_irqs_cpu(i, cpu));
  312. if (i < NR_CPU_IRQS)
  313. seq_printf(p, " %14s.%u",
  314. irq_desc[i].irq_data.chip->name,
  315. (GxICR(i) & GxICR_LEVEL) >>
  316. GxICR_LEVEL_SHIFT);
  317. else
  318. seq_printf(p, " %14s",
  319. irq_desc[i].irq_data.chip->name);
  320. seq_printf(p, " %s", action->name);
  321. for (action = action->next;
  322. action;
  323. action = action->next)
  324. seq_printf(p, ", %s", action->name);
  325. seq_putc(p, '\n');
  326. }
  327. raw_spin_unlock_irqrestore(&irq_desc[i].lock, flags);
  328. break;
  329. /* polish off with NMI and error counters */
  330. case NR_IRQS:
  331. #ifdef CONFIG_MN10300_WD_TIMER
  332. seq_printf(p, "NMI: ");
  333. for (j = 0; j < NR_CPUS; j++)
  334. if (cpu_online(j))
  335. seq_printf(p, "%10u ", nmi_count(j));
  336. seq_putc(p, '\n');
  337. #endif
  338. seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
  339. break;
  340. }
  341. return 0;
  342. }
  343. #ifdef CONFIG_HOTPLUG_CPU
  344. void migrate_irqs(void)
  345. {
  346. irq_desc_t *desc;
  347. int irq;
  348. unsigned int self, new;
  349. unsigned long flags;
  350. self = smp_processor_id();
  351. for (irq = 0; irq < NR_IRQS; irq++) {
  352. desc = irq_desc + irq;
  353. if (desc->status == IRQ_PER_CPU)
  354. continue;
  355. if (cpu_isset(self, irq_desc[irq].affinity) &&
  356. !cpus_intersects(irq_affinity[irq], cpu_online_map)) {
  357. int cpu_id;
  358. cpu_id = first_cpu(cpu_online_map);
  359. cpu_set(cpu_id, irq_desc[irq].affinity);
  360. }
  361. /* We need to operate irq_affinity_online atomically. */
  362. arch_local_cli_save(flags);
  363. if (irq_affinity_online[irq] == self) {
  364. u16 x, tmp;
  365. x = GxICR(irq);
  366. GxICR(irq) = x & GxICR_LEVEL;
  367. tmp = GxICR(irq);
  368. new = any_online_cpu(irq_desc[irq].affinity);
  369. irq_affinity_online[irq] = new;
  370. CROSS_GxICR(irq, new) =
  371. (x & GxICR_LEVEL) | GxICR_DETECT;
  372. tmp = CROSS_GxICR(irq, new);
  373. x &= GxICR_LEVEL | GxICR_ENABLE;
  374. if (GxICR(irq) & GxICR_REQUEST)
  375. x |= GxICR_REQUEST | GxICR_DETECT;
  376. CROSS_GxICR(irq, new) = x;
  377. tmp = CROSS_GxICR(irq, new);
  378. }
  379. arch_local_irq_restore(flags);
  380. }
  381. }
  382. #endif /* CONFIG_HOTPLUG_CPU */