irq.c 5.3 KB

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