int.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. *
  3. * Copyright (C) 2005 Embedded Alley Solutions, Inc
  4. * Ported to 2.6.
  5. *
  6. * Per Hallsmark, per.hallsmark@mvista.com
  7. * Copyright (C) 2000, 2001 MIPS Technologies, Inc.
  8. * Copyright (C) 2001 Ralf Baechle
  9. *
  10. * Cleaned up and bug fixing: Pete Popov, ppopov@embeddedalley.com
  11. *
  12. * This program is free software; you can distribute it and/or modify it
  13. * under the terms of the GNU General Public License (Version 2) as
  14. * published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope it will be useful, but WITHOUT
  17. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  18. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  19. * for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License along
  22. * with this program; if not, write to the Free Software Foundation, Inc.,
  23. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  24. *
  25. */
  26. #include <linux/compiler.h>
  27. #include <linux/init.h>
  28. #include <linux/irq.h>
  29. #include <linux/sched.h>
  30. #include <linux/slab.h>
  31. #include <linux/interrupt.h>
  32. #include <linux/kernel_stat.h>
  33. #include <linux/random.h>
  34. #include <linux/module.h>
  35. #include <asm/io.h>
  36. #include <int.h>
  37. #include <uart.h>
  38. /* default prio for interrupts */
  39. /* first one is a no-no so therefore always prio 0 (disabled) */
  40. static char gic_prio[PNX8550_INT_GIC_TOTINT] = {
  41. 0, 1, 1, 1, 1, 15, 1, 1, 1, 1, // 0 - 9
  42. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 10 - 19
  43. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 20 - 29
  44. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 30 - 39
  45. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 40 - 49
  46. 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, // 50 - 59
  47. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 60 - 69
  48. 1 // 70
  49. };
  50. static void hw0_irqdispatch(int irq)
  51. {
  52. /* find out which interrupt */
  53. irq = PNX8550_GIC_VECTOR_0 >> 3;
  54. if (irq == 0) {
  55. printk("hw0_irqdispatch: irq 0, spurious interrupt?\n");
  56. return;
  57. }
  58. do_IRQ(PNX8550_INT_GIC_MIN + irq);
  59. }
  60. static void timer_irqdispatch(int irq)
  61. {
  62. irq = (0x01c0 & read_c0_config7()) >> 6;
  63. if (unlikely(irq == 0)) {
  64. printk("timer_irqdispatch: irq 0, spurious interrupt?\n");
  65. return;
  66. }
  67. if (irq & 0x1)
  68. do_IRQ(PNX8550_INT_TIMER1);
  69. if (irq & 0x2)
  70. do_IRQ(PNX8550_INT_TIMER2);
  71. if (irq & 0x4)
  72. do_IRQ(PNX8550_INT_TIMER3);
  73. }
  74. asmlinkage void plat_irq_dispatch(void)
  75. {
  76. unsigned int pending = read_c0_status() & read_c0_cause() & ST0_IM;
  77. if (pending & STATUSF_IP2)
  78. hw0_irqdispatch(2);
  79. else if (pending & STATUSF_IP7) {
  80. if (read_c0_config7() & 0x01c0)
  81. timer_irqdispatch(7);
  82. } else
  83. spurious_interrupt();
  84. }
  85. static inline void modify_cp0_intmask(unsigned clr_mask, unsigned set_mask)
  86. {
  87. unsigned long status = read_c0_status();
  88. status &= ~((clr_mask & 0xFF) << 8);
  89. status |= (set_mask & 0xFF) << 8;
  90. write_c0_status(status);
  91. }
  92. static inline void mask_gic_int(unsigned int irq_nr)
  93. {
  94. /* interrupt disabled, bit 26(WE_ENABLE)=1 and bit 16(enable)=0 */
  95. PNX8550_GIC_REQ(irq_nr) = 1<<28; /* set priority to 0 */
  96. }
  97. static inline void unmask_gic_int(unsigned int irq_nr)
  98. {
  99. /* set prio mask to lower four bits and enable interrupt */
  100. PNX8550_GIC_REQ(irq_nr) = (1<<26 | 1<<16) | (1<<28) | gic_prio[irq_nr];
  101. }
  102. static inline void mask_irq(unsigned int irq_nr)
  103. {
  104. if ((PNX8550_INT_CP0_MIN <= irq_nr) && (irq_nr <= PNX8550_INT_CP0_MAX)) {
  105. modify_cp0_intmask(1 << irq_nr, 0);
  106. } else if ((PNX8550_INT_GIC_MIN <= irq_nr) &&
  107. (irq_nr <= PNX8550_INT_GIC_MAX)) {
  108. mask_gic_int(irq_nr - PNX8550_INT_GIC_MIN);
  109. } else if ((PNX8550_INT_TIMER_MIN <= irq_nr) &&
  110. (irq_nr <= PNX8550_INT_TIMER_MAX)) {
  111. modify_cp0_intmask(1 << 7, 0);
  112. } else {
  113. printk("mask_irq: irq %d doesn't exist!\n", irq_nr);
  114. }
  115. }
  116. static inline void unmask_irq(unsigned int irq_nr)
  117. {
  118. if ((PNX8550_INT_CP0_MIN <= irq_nr) && (irq_nr <= PNX8550_INT_CP0_MAX)) {
  119. modify_cp0_intmask(0, 1 << irq_nr);
  120. } else if ((PNX8550_INT_GIC_MIN <= irq_nr) &&
  121. (irq_nr <= PNX8550_INT_GIC_MAX)) {
  122. unmask_gic_int(irq_nr - PNX8550_INT_GIC_MIN);
  123. } else if ((PNX8550_INT_TIMER_MIN <= irq_nr) &&
  124. (irq_nr <= PNX8550_INT_TIMER_MAX)) {
  125. modify_cp0_intmask(0, 1 << 7);
  126. } else {
  127. printk("mask_irq: irq %d doesn't exist!\n", irq_nr);
  128. }
  129. }
  130. int pnx8550_set_gic_priority(int irq, int priority)
  131. {
  132. int gic_irq = irq-PNX8550_INT_GIC_MIN;
  133. int prev_priority = PNX8550_GIC_REQ(gic_irq) & 0xf;
  134. gic_prio[gic_irq] = priority;
  135. PNX8550_GIC_REQ(gic_irq) |= (0x10000000 | gic_prio[gic_irq]);
  136. return prev_priority;
  137. }
  138. static struct irq_chip level_irq_type = {
  139. .name = "PNX Level IRQ",
  140. .ack = mask_irq,
  141. .mask = mask_irq,
  142. .mask_ack = mask_irq,
  143. .unmask = unmask_irq,
  144. };
  145. static struct irqaction gic_action = {
  146. .handler = no_action,
  147. .flags = IRQF_DISABLED,
  148. .name = "GIC",
  149. };
  150. static struct irqaction timer_action = {
  151. .handler = no_action,
  152. .flags = IRQF_DISABLED,
  153. .name = "Timer",
  154. };
  155. void __init arch_init_irq(void)
  156. {
  157. int i;
  158. int configPR;
  159. for (i = 0; i < PNX8550_INT_CP0_TOTINT; i++) {
  160. set_irq_chip_and_handler(i, &level_irq_type, handle_level_irq);
  161. mask_irq(i); /* mask the irq just in case */
  162. }
  163. /* init of GIC/IPC interrupts */
  164. /* should be done before cp0 since cp0 init enables the GIC int */
  165. for (i = PNX8550_INT_GIC_MIN; i <= PNX8550_INT_GIC_MAX; i++) {
  166. int gic_int_line = i - PNX8550_INT_GIC_MIN;
  167. if (gic_int_line == 0 )
  168. continue; // don't fiddle with int 0
  169. /*
  170. * enable change of TARGET, ENABLE and ACTIVE_LOW bits
  171. * set TARGET 0 to route through hw0 interrupt
  172. * set ACTIVE_LOW 0 active high (correct?)
  173. *
  174. * We really should setup an interrupt description table
  175. * to do this nicely.
  176. * Note, PCI INTA is active low on the bus, but inverted
  177. * in the GIC, so to us it's active high.
  178. */
  179. PNX8550_GIC_REQ(i - PNX8550_INT_GIC_MIN) = 0x1E000000;
  180. /* mask/priority is still 0 so we will not get any
  181. * interrupts until it is unmasked */
  182. set_irq_chip_and_handler(i, &level_irq_type, handle_level_irq);
  183. }
  184. /* Priority level 0 */
  185. PNX8550_GIC_PRIMASK_0 = PNX8550_GIC_PRIMASK_1 = 0;
  186. /* Set int vector table address */
  187. PNX8550_GIC_VECTOR_0 = PNX8550_GIC_VECTOR_1 = 0;
  188. set_irq_chip_and_handler(MIPS_CPU_GIC_IRQ, &level_irq_type,
  189. handle_level_irq);
  190. setup_irq(MIPS_CPU_GIC_IRQ, &gic_action);
  191. /* init of Timer interrupts */
  192. for (i = PNX8550_INT_TIMER_MIN; i <= PNX8550_INT_TIMER_MAX; i++)
  193. set_irq_chip_and_handler(i, &level_irq_type, handle_level_irq);
  194. /* Stop Timer 1-3 */
  195. configPR = read_c0_config7();
  196. configPR |= 0x00000038;
  197. write_c0_config7(configPR);
  198. set_irq_chip_and_handler(MIPS_CPU_TIMER_IRQ, &level_irq_type,
  199. handle_level_irq);
  200. setup_irq(MIPS_CPU_TIMER_IRQ, &timer_action);
  201. }
  202. EXPORT_SYMBOL(pnx8550_set_gic_priority);