int.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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/config.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 <asm/gdb-stub.h>
  37. #include <int.h>
  38. #include <uart.h>
  39. static DEFINE_SPINLOCK(irq_lock);
  40. /* default prio for interrupts */
  41. /* first one is a no-no so therefore always prio 0 (disabled) */
  42. static char gic_prio[PNX8550_INT_GIC_TOTINT] = {
  43. 0, 1, 1, 1, 1, 15, 1, 1, 1, 1, // 0 - 9
  44. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 10 - 19
  45. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 20 - 29
  46. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 30 - 39
  47. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 40 - 49
  48. 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, // 50 - 59
  49. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 60 - 69
  50. 1 // 70
  51. };
  52. static void hw0_irqdispatch(int irq, struct pt_regs *regs)
  53. {
  54. /* find out which interrupt */
  55. irq = PNX8550_GIC_VECTOR_0 >> 3;
  56. if (irq == 0) {
  57. printk("hw0_irqdispatch: irq 0, spurious interrupt?\n");
  58. return;
  59. }
  60. do_IRQ(PNX8550_INT_GIC_MIN + irq, regs);
  61. }
  62. static void timer_irqdispatch(int irq, struct pt_regs *regs)
  63. {
  64. irq = (0x01c0 & read_c0_config7()) >> 6;
  65. if (irq == 0) {
  66. printk("timer_irqdispatch: irq 0, spurious interrupt?\n");
  67. return;
  68. }
  69. if (irq & 0x1) {
  70. do_IRQ(PNX8550_INT_TIMER1, regs);
  71. }
  72. if (irq & 0x2) {
  73. do_IRQ(PNX8550_INT_TIMER2, regs);
  74. }
  75. if (irq & 0x4) {
  76. do_IRQ(PNX8550_INT_TIMER3, regs);
  77. }
  78. }
  79. asmlinkage void plat_irq_dispatch(struct pt_regs *regs)
  80. {
  81. unsigned int pending = read_c0_status() & read_c0_cause();
  82. if (pending & STATUSF_IP2)
  83. do_IRQ(2, regs);
  84. else if (pending & STATUSF_IP7) {
  85. if (read_c0_config7() & 0x01c0)
  86. timer_irqdispatch(7, regs);
  87. }
  88. spurious_interrupt(regs);
  89. }
  90. static inline void modify_cp0_intmask(unsigned clr_mask, unsigned set_mask)
  91. {
  92. unsigned long status = read_c0_status();
  93. status &= ~((clr_mask & 0xFF) << 8);
  94. status |= (set_mask & 0xFF) << 8;
  95. write_c0_status(status);
  96. }
  97. static inline void mask_gic_int(unsigned int irq_nr)
  98. {
  99. /* interrupt disabled, bit 26(WE_ENABLE)=1 and bit 16(enable)=0 */
  100. PNX8550_GIC_REQ(irq_nr) = 1<<28; /* set priority to 0 */
  101. }
  102. static inline void unmask_gic_int(unsigned int irq_nr)
  103. {
  104. /* set prio mask to lower four bits and enable interrupt */
  105. PNX8550_GIC_REQ(irq_nr) = (1<<26 | 1<<16) | (1<<28) | gic_prio[irq_nr];
  106. }
  107. static inline void mask_irq(unsigned int irq_nr)
  108. {
  109. if ((PNX8550_INT_CP0_MIN <= irq_nr) && (irq_nr <= PNX8550_INT_CP0_MAX)) {
  110. modify_cp0_intmask(1 << irq_nr, 0);
  111. } else if ((PNX8550_INT_GIC_MIN <= irq_nr) &&
  112. (irq_nr <= PNX8550_INT_GIC_MAX)) {
  113. mask_gic_int(irq_nr - PNX8550_INT_GIC_MIN);
  114. } else if ((PNX8550_INT_TIMER_MIN <= irq_nr) &&
  115. (irq_nr <= PNX8550_INT_TIMER_MAX)) {
  116. modify_cp0_intmask(1 << 7, 0);
  117. } else {
  118. printk("mask_irq: irq %d doesn't exist!\n", irq_nr);
  119. }
  120. }
  121. static inline void unmask_irq(unsigned int irq_nr)
  122. {
  123. if ((PNX8550_INT_CP0_MIN <= irq_nr) && (irq_nr <= PNX8550_INT_CP0_MAX)) {
  124. modify_cp0_intmask(0, 1 << irq_nr);
  125. } else if ((PNX8550_INT_GIC_MIN <= irq_nr) &&
  126. (irq_nr <= PNX8550_INT_GIC_MAX)) {
  127. unmask_gic_int(irq_nr - PNX8550_INT_GIC_MIN);
  128. } else if ((PNX8550_INT_TIMER_MIN <= irq_nr) &&
  129. (irq_nr <= PNX8550_INT_TIMER_MAX)) {
  130. modify_cp0_intmask(0, 1 << 7);
  131. } else {
  132. printk("mask_irq: irq %d doesn't exist!\n", irq_nr);
  133. }
  134. }
  135. #define pnx8550_disable pnx8550_ack
  136. static void pnx8550_ack(unsigned int irq)
  137. {
  138. unsigned long flags;
  139. spin_lock_irqsave(&irq_lock, flags);
  140. mask_irq(irq);
  141. spin_unlock_irqrestore(&irq_lock, flags);
  142. }
  143. #define pnx8550_enable pnx8550_unmask
  144. static void pnx8550_unmask(unsigned int irq)
  145. {
  146. unsigned long flags;
  147. spin_lock_irqsave(&irq_lock, flags);
  148. unmask_irq(irq);
  149. spin_unlock_irqrestore(&irq_lock, flags);
  150. }
  151. static unsigned int startup_irq(unsigned int irq_nr)
  152. {
  153. pnx8550_unmask(irq_nr);
  154. return 0;
  155. }
  156. static void shutdown_irq(unsigned int irq_nr)
  157. {
  158. pnx8550_ack(irq_nr);
  159. return;
  160. }
  161. int pnx8550_set_gic_priority(int irq, int priority)
  162. {
  163. int gic_irq = irq-PNX8550_INT_GIC_MIN;
  164. int prev_priority = PNX8550_GIC_REQ(gic_irq) & 0xf;
  165. gic_prio[gic_irq] = priority;
  166. PNX8550_GIC_REQ(gic_irq) |= (0x10000000 | gic_prio[gic_irq]);
  167. return prev_priority;
  168. }
  169. static inline void mask_and_ack_level_irq(unsigned int irq)
  170. {
  171. pnx8550_disable(irq);
  172. return;
  173. }
  174. static void end_irq(unsigned int irq)
  175. {
  176. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS))) {
  177. pnx8550_enable(irq);
  178. }
  179. }
  180. static struct hw_interrupt_type level_irq_type = {
  181. .typename = "PNX Level IRQ",
  182. .startup = startup_irq,
  183. .shutdown = shutdown_irq,
  184. .enable = pnx8550_enable,
  185. .disable = pnx8550_disable,
  186. .ack = mask_and_ack_level_irq,
  187. .end = end_irq,
  188. };
  189. static struct irqaction gic_action = {
  190. .handler = no_action,
  191. .flags = SA_INTERRUPT,
  192. .name = "GIC",
  193. };
  194. static struct irqaction timer_action = {
  195. .handler = no_action,
  196. .flags = SA_INTERRUPT,
  197. .name = "Timer",
  198. };
  199. void __init arch_init_irq(void)
  200. {
  201. int i;
  202. int configPR;
  203. for (i = 0; i < PNX8550_INT_CP0_TOTINT; i++) {
  204. irq_desc[i].handler = &level_irq_type;
  205. pnx8550_ack(i); /* mask the irq just in case */
  206. }
  207. /* init of GIC/IPC interrupts */
  208. /* should be done before cp0 since cp0 init enables the GIC int */
  209. for (i = PNX8550_INT_GIC_MIN; i <= PNX8550_INT_GIC_MAX; i++) {
  210. int gic_int_line = i - PNX8550_INT_GIC_MIN;
  211. if (gic_int_line == 0 )
  212. continue; // don't fiddle with int 0
  213. /*
  214. * enable change of TARGET, ENABLE and ACTIVE_LOW bits
  215. * set TARGET 0 to route through hw0 interrupt
  216. * set ACTIVE_LOW 0 active high (correct?)
  217. *
  218. * We really should setup an interrupt description table
  219. * to do this nicely.
  220. * Note, PCI INTA is active low on the bus, but inverted
  221. * in the GIC, so to us it's active high.
  222. */
  223. #ifdef CONFIG_PNX8550_V2PCI
  224. if (gic_int_line == (PNX8550_INT_GPIO0 - PNX8550_INT_GIC_MIN)) {
  225. /* PCI INT through gpio 8, which is setup in
  226. * pnx8550_setup.c and routed to GPIO
  227. * Interrupt Level 0 (GPIO Connection 58).
  228. * Set it active low. */
  229. PNX8550_GIC_REQ(gic_int_line) = 0x1E020000;
  230. } else
  231. #endif
  232. {
  233. PNX8550_GIC_REQ(i - PNX8550_INT_GIC_MIN) = 0x1E000000;
  234. }
  235. /* mask/priority is still 0 so we will not get any
  236. * interrupts until it is unmasked */
  237. irq_desc[i].handler = &level_irq_type;
  238. }
  239. /* Priority level 0 */
  240. PNX8550_GIC_PRIMASK_0 = PNX8550_GIC_PRIMASK_1 = 0;
  241. /* Set int vector table address */
  242. PNX8550_GIC_VECTOR_0 = PNX8550_GIC_VECTOR_1 = 0;
  243. irq_desc[MIPS_CPU_GIC_IRQ].handler = &level_irq_type;
  244. setup_irq(MIPS_CPU_GIC_IRQ, &gic_action);
  245. /* init of Timer interrupts */
  246. for (i = PNX8550_INT_TIMER_MIN; i <= PNX8550_INT_TIMER_MAX; i++) {
  247. irq_desc[i].handler = &level_irq_type;
  248. }
  249. /* Stop Timer 1-3 */
  250. configPR = read_c0_config7();
  251. configPR |= 0x00000038;
  252. write_c0_config7(configPR);
  253. irq_desc[MIPS_CPU_TIMER_IRQ].handler = &level_irq_type;
  254. setup_irq(MIPS_CPU_TIMER_IRQ, &timer_action);
  255. }
  256. EXPORT_SYMBOL(pnx8550_set_gic_priority);