irq.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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 <asm/setup.h>
  16. unsigned long __mn10300_irq_enabled_epsw = EPSW_IE | EPSW_IM_7;
  17. EXPORT_SYMBOL(__mn10300_irq_enabled_epsw);
  18. atomic_t irq_err_count;
  19. /*
  20. * MN10300 interrupt controller operations
  21. */
  22. static void mn10300_cpupic_ack(unsigned int irq)
  23. {
  24. u16 tmp;
  25. *(volatile u8 *) &GxICR(irq) = GxICR_DETECT;
  26. tmp = GxICR(irq);
  27. }
  28. static void mn10300_cpupic_mask(unsigned int irq)
  29. {
  30. u16 tmp = GxICR(irq);
  31. GxICR(irq) = (tmp & GxICR_LEVEL);
  32. tmp = GxICR(irq);
  33. }
  34. static void mn10300_cpupic_mask_ack(unsigned int irq)
  35. {
  36. u16 tmp = GxICR(irq);
  37. GxICR(irq) = (tmp & GxICR_LEVEL) | GxICR_DETECT;
  38. tmp = GxICR(irq);
  39. }
  40. static void mn10300_cpupic_unmask(unsigned int irq)
  41. {
  42. u16 tmp = GxICR(irq);
  43. GxICR(irq) = (tmp & GxICR_LEVEL) | GxICR_ENABLE;
  44. tmp = GxICR(irq);
  45. }
  46. static void mn10300_cpupic_unmask_clear(unsigned int irq)
  47. {
  48. /* the MN10300 PIC latches its interrupt request bit, even after the
  49. * device has ceased to assert its interrupt line and the interrupt
  50. * channel has been disabled in the PIC, so for level-triggered
  51. * interrupts we need to clear the request bit when we re-enable */
  52. u16 tmp = GxICR(irq);
  53. GxICR(irq) = (tmp & GxICR_LEVEL) | GxICR_ENABLE | GxICR_DETECT;
  54. tmp = GxICR(irq);
  55. }
  56. /*
  57. * MN10300 PIC level-triggered IRQ handling.
  58. *
  59. * The PIC has no 'ACK' function per se. It is possible to clear individual
  60. * channel latches, but each latch relatches whether or not the channel is
  61. * masked, so we need to clear the latch when we unmask the channel.
  62. *
  63. * Also for this reason, we don't supply an ack() op (it's unused anyway if
  64. * mask_ack() is provided), and mask_ack() just masks.
  65. */
  66. static struct irq_chip mn10300_cpu_pic_level = {
  67. .name = "cpu_l",
  68. .disable = mn10300_cpupic_mask,
  69. .enable = mn10300_cpupic_unmask_clear,
  70. .ack = NULL,
  71. .mask = mn10300_cpupic_mask,
  72. .mask_ack = mn10300_cpupic_mask,
  73. .unmask = mn10300_cpupic_unmask_clear,
  74. };
  75. /*
  76. * MN10300 PIC edge-triggered IRQ handling.
  77. *
  78. * We use the latch clearing function of the PIC as the 'ACK' function.
  79. */
  80. static struct irq_chip mn10300_cpu_pic_edge = {
  81. .name = "cpu_e",
  82. .disable = mn10300_cpupic_mask,
  83. .enable = mn10300_cpupic_unmask,
  84. .ack = mn10300_cpupic_ack,
  85. .mask = mn10300_cpupic_mask,
  86. .mask_ack = mn10300_cpupic_mask_ack,
  87. .unmask = mn10300_cpupic_unmask,
  88. };
  89. /*
  90. * 'what should we do if we get a hw irq event on an illegal vector'.
  91. * each architecture has to answer this themselves.
  92. */
  93. void ack_bad_irq(int irq)
  94. {
  95. printk(KERN_WARNING "unexpected IRQ trap at vector %02x\n", irq);
  96. }
  97. /*
  98. * change the level at which an IRQ executes
  99. * - must not be called whilst interrupts are being processed!
  100. */
  101. void set_intr_level(int irq, u16 level)
  102. {
  103. u16 tmp;
  104. if (in_interrupt())
  105. BUG();
  106. tmp = GxICR(irq);
  107. GxICR(irq) = (tmp & GxICR_ENABLE) | level;
  108. tmp = GxICR(irq);
  109. }
  110. /*
  111. * mark an interrupt to be ACK'd after interrupt handlers have been run rather
  112. * than before
  113. * - see Documentation/mn10300/features.txt
  114. */
  115. void set_intr_postackable(int irq)
  116. {
  117. set_irq_chip_and_handler(irq, &mn10300_cpu_pic_level,
  118. handle_level_irq);
  119. }
  120. /*
  121. * initialise the interrupt system
  122. */
  123. void __init init_IRQ(void)
  124. {
  125. int irq;
  126. for (irq = 0; irq < NR_IRQS; irq++)
  127. if (irq_desc[irq].chip == &no_irq_type)
  128. /* due to the PIC latching interrupt requests, even
  129. * when the IRQ is disabled, IRQ_PENDING is superfluous
  130. * and we can use handle_level_irq() for edge-triggered
  131. * interrupts */
  132. set_irq_chip_and_handler(irq, &mn10300_cpu_pic_edge,
  133. handle_level_irq);
  134. unit_init_IRQ();
  135. }
  136. /*
  137. * handle normal device IRQs
  138. */
  139. asmlinkage void do_IRQ(void)
  140. {
  141. unsigned long sp, epsw, irq_disabled_epsw, old_irq_enabled_epsw;
  142. int irq;
  143. sp = current_stack_pointer();
  144. if (sp - (sp & ~(THREAD_SIZE - 1)) < STACK_WARN)
  145. BUG();
  146. /* make sure local_irq_enable() doesn't muck up the interrupt priority
  147. * setting in EPSW */
  148. old_irq_enabled_epsw = __mn10300_irq_enabled_epsw;
  149. local_save_flags(epsw);
  150. __mn10300_irq_enabled_epsw = EPSW_IE | (EPSW_IM & epsw);
  151. irq_disabled_epsw = EPSW_IE | MN10300_CLI_LEVEL;
  152. __IRQ_STAT(smp_processor_id(), __irq_count)++;
  153. irq_enter();
  154. for (;;) {
  155. /* ask the interrupt controller for the next IRQ to process
  156. * - the result we get depends on EPSW.IM
  157. */
  158. irq = IAGR & IAGR_GN;
  159. if (!irq)
  160. break;
  161. local_irq_restore(irq_disabled_epsw);
  162. generic_handle_irq(irq >> 2);
  163. /* restore IRQ controls for IAGR access */
  164. local_irq_restore(epsw);
  165. }
  166. __mn10300_irq_enabled_epsw = old_irq_enabled_epsw;
  167. irq_exit();
  168. }
  169. /*
  170. * Display interrupt management information through /proc/interrupts
  171. */
  172. int show_interrupts(struct seq_file *p, void *v)
  173. {
  174. int i = *(loff_t *) v, j, cpu;
  175. struct irqaction *action;
  176. unsigned long flags;
  177. switch (i) {
  178. /* display column title bar naming CPUs */
  179. case 0:
  180. seq_printf(p, " ");
  181. for (j = 0; j < NR_CPUS; j++)
  182. if (cpu_online(j))
  183. seq_printf(p, "CPU%d ", j);
  184. seq_putc(p, '\n');
  185. break;
  186. /* display information rows, one per active CPU */
  187. case 1 ... NR_IRQS - 1:
  188. spin_lock_irqsave(&irq_desc[i].lock, flags);
  189. action = irq_desc[i].action;
  190. if (action) {
  191. seq_printf(p, "%3d: ", i);
  192. for_each_present_cpu(cpu)
  193. seq_printf(p, "%10u ", kstat_cpu(cpu).irqs[i]);
  194. seq_printf(p, " %14s.%u", irq_desc[i].chip->name,
  195. (GxICR(i) & GxICR_LEVEL) >>
  196. GxICR_LEVEL_SHIFT);
  197. seq_printf(p, " %s", action->name);
  198. for (action = action->next;
  199. action;
  200. action = action->next)
  201. seq_printf(p, ", %s", action->name);
  202. seq_putc(p, '\n');
  203. }
  204. spin_unlock_irqrestore(&irq_desc[i].lock, flags);
  205. break;
  206. /* polish off with NMI and error counters */
  207. case NR_IRQS:
  208. seq_printf(p, "NMI: ");
  209. for (j = 0; j < NR_CPUS; j++)
  210. if (cpu_online(j))
  211. seq_printf(p, "%10u ", nmi_count(j));
  212. seq_putc(p, '\n');
  213. seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
  214. break;
  215. }
  216. return 0;
  217. }