atlas_int.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. * Copyright (C) 1999, 2000, 2006 MIPS Technologies, Inc.
  3. * All rights reserved.
  4. * Authors: Carsten Langgaard <carstenl@mips.com>
  5. * Maciej W. Rozycki <macro@mips.com>
  6. *
  7. * ########################################################################
  8. *
  9. * This program is free software; you can distribute it and/or modify it
  10. * under the terms of the GNU General Public License (Version 2) as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  16. * for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  21. *
  22. * ########################################################################
  23. *
  24. * Routines for generic manipulation of the interrupts found on the MIPS
  25. * Atlas board.
  26. *
  27. */
  28. #include <linux/compiler.h>
  29. #include <linux/init.h>
  30. #include <linux/irq.h>
  31. #include <linux/sched.h>
  32. #include <linux/slab.h>
  33. #include <linux/interrupt.h>
  34. #include <linux/kernel_stat.h>
  35. #include <linux/kernel.h>
  36. #include <asm/gdb-stub.h>
  37. #include <asm/io.h>
  38. #include <asm/irq_cpu.h>
  39. #include <asm/msc01_ic.h>
  40. #include <asm/mips-boards/atlas.h>
  41. #include <asm/mips-boards/atlasint.h>
  42. #include <asm/mips-boards/generic.h>
  43. static struct atlas_ictrl_regs *atlas_hw0_icregs;
  44. #if 0
  45. #define DEBUG_INT(x...) printk(x)
  46. #else
  47. #define DEBUG_INT(x...)
  48. #endif
  49. void disable_atlas_irq(unsigned int irq_nr)
  50. {
  51. atlas_hw0_icregs->intrsten = 1 << (irq_nr - ATLAS_INT_BASE);
  52. iob();
  53. }
  54. void enable_atlas_irq(unsigned int irq_nr)
  55. {
  56. atlas_hw0_icregs->intseten = 1 << (irq_nr - ATLAS_INT_BASE);
  57. iob();
  58. }
  59. static void end_atlas_irq(unsigned int irq)
  60. {
  61. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  62. enable_atlas_irq(irq);
  63. }
  64. static struct irq_chip atlas_irq_type = {
  65. .name = "Atlas",
  66. .ack = disable_atlas_irq,
  67. .mask = disable_atlas_irq,
  68. .mask_ack = disable_atlas_irq,
  69. .unmask = enable_atlas_irq,
  70. .eoi = enable_atlas_irq,
  71. .end = end_atlas_irq,
  72. };
  73. static inline int ls1bit32(unsigned int x)
  74. {
  75. int b = 31, s;
  76. s = 16; if (x << 16 == 0) s = 0; b -= s; x <<= s;
  77. s = 8; if (x << 8 == 0) s = 0; b -= s; x <<= s;
  78. s = 4; if (x << 4 == 0) s = 0; b -= s; x <<= s;
  79. s = 2; if (x << 2 == 0) s = 0; b -= s; x <<= s;
  80. s = 1; if (x << 1 == 0) s = 0; b -= s;
  81. return b;
  82. }
  83. static inline void atlas_hw0_irqdispatch(void)
  84. {
  85. unsigned long int_status;
  86. int irq;
  87. int_status = atlas_hw0_icregs->intstatus;
  88. /* if int_status == 0, then the interrupt has already been cleared */
  89. if (unlikely(int_status == 0))
  90. return;
  91. irq = ATLAS_INT_BASE + ls1bit32(int_status);
  92. DEBUG_INT("atlas_hw0_irqdispatch: irq=%d\n", irq);
  93. do_IRQ(irq);
  94. }
  95. static inline int clz(unsigned long x)
  96. {
  97. __asm__(
  98. " .set push \n"
  99. " .set mips32 \n"
  100. " clz %0, %1 \n"
  101. " .set pop \n"
  102. : "=r" (x)
  103. : "r" (x));
  104. return x;
  105. }
  106. /*
  107. * Version of ffs that only looks at bits 12..15.
  108. */
  109. static inline unsigned int irq_ffs(unsigned int pending)
  110. {
  111. #if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
  112. return -clz(pending) + 31 - CAUSEB_IP;
  113. #else
  114. unsigned int a0 = 7;
  115. unsigned int t0;
  116. t0 = s0 & 0xf000;
  117. t0 = t0 < 1;
  118. t0 = t0 << 2;
  119. a0 = a0 - t0;
  120. s0 = s0 << t0;
  121. t0 = s0 & 0xc000;
  122. t0 = t0 < 1;
  123. t0 = t0 << 1;
  124. a0 = a0 - t0;
  125. s0 = s0 << t0;
  126. t0 = s0 & 0x8000;
  127. t0 = t0 < 1;
  128. //t0 = t0 << 2;
  129. a0 = a0 - t0;
  130. //s0 = s0 << t0;
  131. return a0;
  132. #endif
  133. }
  134. /*
  135. * IRQs on the Atlas board look basically like (all external interrupt
  136. * sources are combined together on hardware interrupt 0 (MIPS IRQ 2)):
  137. *
  138. * MIPS IRQ Source
  139. * -------- ------
  140. * 0 Software 0 (reschedule IPI on MT)
  141. * 1 Software 1 (remote call IPI on MT)
  142. * 2 Combined Atlas hardware interrupt (hw0)
  143. * 3 Hardware (ignored)
  144. * 4 Hardware (ignored)
  145. * 5 Hardware (ignored)
  146. * 6 Hardware (ignored)
  147. * 7 R4k timer (what we use)
  148. *
  149. * We handle the IRQ according to _our_ priority which is:
  150. *
  151. * Highest ---- R4k Timer
  152. * Lowest ---- Software 0
  153. *
  154. * then we just return, if multiple IRQs are pending then we will just take
  155. * another exception, big deal.
  156. */
  157. asmlinkage void plat_irq_dispatch(void)
  158. {
  159. unsigned int pending = read_c0_cause() & read_c0_status() & ST0_IM;
  160. int irq;
  161. irq = irq_ffs(pending);
  162. if (irq == MIPSCPU_INT_ATLAS)
  163. atlas_hw0_irqdispatch();
  164. else if (irq >= 0)
  165. do_IRQ(MIPS_CPU_IRQ_BASE + irq);
  166. else
  167. spurious_interrupt();
  168. }
  169. static inline void init_atlas_irqs(int base)
  170. {
  171. int i;
  172. atlas_hw0_icregs = (struct atlas_ictrl_regs *)
  173. ioremap(ATLAS_ICTRL_REGS_BASE,
  174. sizeof(struct atlas_ictrl_regs *));
  175. /*
  176. * Mask out all interrupt by writing "1" to all bit position in
  177. * the interrupt reset reg.
  178. */
  179. atlas_hw0_icregs->intrsten = 0xffffffff;
  180. for (i = ATLAS_INT_BASE; i <= ATLAS_INT_END; i++)
  181. set_irq_chip_and_handler(i, &atlas_irq_type, handle_level_irq);
  182. }
  183. static struct irqaction atlasirq = {
  184. .handler = no_action,
  185. .name = "Atlas cascade"
  186. };
  187. msc_irqmap_t __initdata msc_irqmap[] = {
  188. {MSC01C_INT_TMR, MSC01_IRQ_EDGE, 0},
  189. {MSC01C_INT_PCI, MSC01_IRQ_LEVEL, 0},
  190. };
  191. int __initdata msc_nr_irqs = ARRAY_SIZE(msc_irqmap);
  192. msc_irqmap_t __initdata msc_eicirqmap[] = {
  193. {MSC01E_INT_SW0, MSC01_IRQ_LEVEL, 0},
  194. {MSC01E_INT_SW1, MSC01_IRQ_LEVEL, 0},
  195. {MSC01E_INT_ATLAS, MSC01_IRQ_LEVEL, 0},
  196. {MSC01E_INT_TMR, MSC01_IRQ_EDGE, 0},
  197. {MSC01E_INT_PCI, MSC01_IRQ_LEVEL, 0},
  198. {MSC01E_INT_PERFCTR, MSC01_IRQ_LEVEL, 0},
  199. {MSC01E_INT_CPUCTR, MSC01_IRQ_LEVEL, 0}
  200. };
  201. int __initdata msc_nr_eicirqs = ARRAY_SIZE(msc_eicirqmap);
  202. void __init arch_init_irq(void)
  203. {
  204. init_atlas_irqs(ATLAS_INT_BASE);
  205. if (!cpu_has_veic)
  206. mips_cpu_irq_init();
  207. switch(mips_revision_corid) {
  208. case MIPS_REVISION_CORID_CORE_MSC:
  209. case MIPS_REVISION_CORID_CORE_FPGA2:
  210. case MIPS_REVISION_CORID_CORE_FPGA3:
  211. case MIPS_REVISION_CORID_CORE_FPGA4:
  212. case MIPS_REVISION_CORID_CORE_24K:
  213. case MIPS_REVISION_CORID_CORE_EMUL_MSC:
  214. if (cpu_has_veic)
  215. init_msc_irqs(MSC01E_INT_BASE, MSC01E_INT_BASE,
  216. msc_eicirqmap, msc_nr_eicirqs);
  217. else
  218. init_msc_irqs(MSC01E_INT_BASE, MSC01C_INT_BASE,
  219. msc_irqmap, msc_nr_irqs);
  220. }
  221. if (cpu_has_veic) {
  222. set_vi_handler(MSC01E_INT_ATLAS, atlas_hw0_irqdispatch);
  223. setup_irq(MSC01E_INT_BASE + MSC01E_INT_ATLAS, &atlasirq);
  224. } else if (cpu_has_vint) {
  225. set_vi_handler(MIPSCPU_INT_ATLAS, atlas_hw0_irqdispatch);
  226. #ifdef CONFIG_MIPS_MT_SMTC
  227. setup_irq_smtc(MIPS_CPU_IRQ_BASE + MIPSCPU_INT_ATLAS,
  228. &atlasirq, (0x100 << MIPSCPU_INT_ATLAS));
  229. #else /* Not SMTC */
  230. setup_irq(MIPS_CPU_IRQ_BASE + MIPSCPU_INT_ATLAS, &atlasirq);
  231. #endif /* CONFIG_MIPS_MT_SMTC */
  232. } else
  233. setup_irq(MIPS_CPU_IRQ_BASE + MIPSCPU_INT_ATLAS, &atlasirq);
  234. }