int.c 7.5 KB

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