atlas_int.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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 <asm/gdb-stub.h>
  36. #include <asm/io.h>
  37. #include <asm/irq_cpu.h>
  38. #include <asm/msc01_ic.h>
  39. #include <asm/mips-boards/atlas.h>
  40. #include <asm/mips-boards/atlasint.h>
  41. #include <asm/mips-boards/generic.h>
  42. static struct atlas_ictrl_regs *atlas_hw0_icregs;
  43. #if 0
  44. #define DEBUG_INT(x...) printk(x)
  45. #else
  46. #define DEBUG_INT(x...)
  47. #endif
  48. void disable_atlas_irq(unsigned int irq_nr)
  49. {
  50. atlas_hw0_icregs->intrsten = 1 << (irq_nr - ATLAS_INT_BASE);
  51. iob();
  52. }
  53. void enable_atlas_irq(unsigned int irq_nr)
  54. {
  55. atlas_hw0_icregs->intseten = 1 << (irq_nr - ATLAS_INT_BASE);
  56. iob();
  57. }
  58. static void end_atlas_irq(unsigned int irq)
  59. {
  60. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  61. enable_atlas_irq(irq);
  62. }
  63. static struct irq_chip atlas_irq_type = {
  64. .typename = "Atlas",
  65. .ack = disable_atlas_irq,
  66. .mask = disable_atlas_irq,
  67. .mask_ack = disable_atlas_irq,
  68. .unmask = enable_atlas_irq,
  69. .eoi = enable_atlas_irq,
  70. .end = end_atlas_irq,
  71. };
  72. static inline int ls1bit32(unsigned int x)
  73. {
  74. int b = 31, s;
  75. s = 16; if (x << 16 == 0) s = 0; b -= s; x <<= s;
  76. s = 8; if (x << 8 == 0) s = 0; b -= s; x <<= s;
  77. s = 4; if (x << 4 == 0) s = 0; b -= s; x <<= s;
  78. s = 2; if (x << 2 == 0) s = 0; b -= s; x <<= s;
  79. s = 1; if (x << 1 == 0) s = 0; b -= s;
  80. return b;
  81. }
  82. static inline void atlas_hw0_irqdispatch(void)
  83. {
  84. unsigned long int_status;
  85. int irq;
  86. int_status = atlas_hw0_icregs->intstatus;
  87. /* if int_status == 0, then the interrupt has already been cleared */
  88. if (unlikely(int_status == 0))
  89. return;
  90. irq = ATLAS_INT_BASE + ls1bit32(int_status);
  91. DEBUG_INT("atlas_hw0_irqdispatch: irq=%d\n", irq);
  92. do_IRQ(irq);
  93. }
  94. static inline int clz(unsigned long x)
  95. {
  96. __asm__ (
  97. " .set push \n"
  98. " .set mips32 \n"
  99. " clz %0, %1 \n"
  100. " .set pop \n"
  101. : "=r" (x)
  102. : "r" (x));
  103. return x;
  104. }
  105. /*
  106. * Version of ffs that only looks at bits 12..15.
  107. */
  108. static inline unsigned int irq_ffs(unsigned int pending)
  109. {
  110. #if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
  111. return -clz(pending) + 31 - CAUSEB_IP;
  112. #else
  113. unsigned int a0 = 7;
  114. unsigned int t0;
  115. t0 = s0 & 0xf000;
  116. t0 = t0 < 1;
  117. t0 = t0 << 2;
  118. a0 = a0 - t0;
  119. s0 = s0 << t0;
  120. t0 = s0 & 0xc000;
  121. t0 = t0 < 1;
  122. t0 = t0 << 1;
  123. a0 = a0 - t0;
  124. s0 = s0 << t0;
  125. t0 = s0 & 0x8000;
  126. t0 = t0 < 1;
  127. //t0 = t0 << 2;
  128. a0 = a0 - t0;
  129. //s0 = s0 << t0;
  130. return a0;
  131. #endif
  132. }
  133. /*
  134. * IRQs on the Atlas board look basically like (all external interrupt
  135. * sources are combined together on hardware interrupt 0 (MIPS IRQ 2)):
  136. *
  137. * MIPS IRQ Source
  138. * -------- ------
  139. * 0 Software 0 (reschedule IPI on MT)
  140. * 1 Software 1 (remote call IPI on MT)
  141. * 2 Combined Atlas hardware interrupt (hw0)
  142. * 3 Hardware (ignored)
  143. * 4 Hardware (ignored)
  144. * 5 Hardware (ignored)
  145. * 6 Hardware (ignored)
  146. * 7 R4k timer (what we use)
  147. *
  148. * We handle the IRQ according to _our_ priority which is:
  149. *
  150. * Highest ---- R4k Timer
  151. * Lowest ---- Software 0
  152. *
  153. * then we just return, if multiple IRQs are pending then we will just take
  154. * another exception, big deal.
  155. */
  156. asmlinkage void plat_irq_dispatch(void)
  157. {
  158. unsigned int pending = read_c0_cause() & read_c0_status() & ST0_IM;
  159. int irq;
  160. irq = irq_ffs(pending);
  161. if (irq == MIPSCPU_INT_ATLAS)
  162. atlas_hw0_irqdispatch();
  163. else if (irq >= 0)
  164. do_IRQ(MIPSCPU_INT_BASE + irq);
  165. else
  166. spurious_interrupt();
  167. }
  168. static inline void init_atlas_irqs (int base)
  169. {
  170. int i;
  171. atlas_hw0_icregs = (struct atlas_ictrl_regs *)
  172. ioremap(ATLAS_ICTRL_REGS_BASE,
  173. sizeof(struct atlas_ictrl_regs *));
  174. /*
  175. * Mask out all interrupt by writing "1" to all bit position in
  176. * the interrupt reset reg.
  177. */
  178. atlas_hw0_icregs->intrsten = 0xffffffff;
  179. for (i = ATLAS_INT_BASE; i <= ATLAS_INT_END; i++)
  180. set_irq_chip_and_handler(i, &atlas_irq_type, handle_level_irq);
  181. }
  182. static struct irqaction atlasirq = {
  183. .handler = no_action,
  184. .name = "Atlas cascade"
  185. };
  186. msc_irqmap_t __initdata msc_irqmap[] = {
  187. {MSC01C_INT_TMR, MSC01_IRQ_EDGE, 0},
  188. {MSC01C_INT_PCI, MSC01_IRQ_LEVEL, 0},
  189. };
  190. int __initdata msc_nr_irqs = sizeof(msc_irqmap) / sizeof(*msc_irqmap);
  191. msc_irqmap_t __initdata msc_eicirqmap[] = {
  192. {MSC01E_INT_SW0, MSC01_IRQ_LEVEL, 0},
  193. {MSC01E_INT_SW1, MSC01_IRQ_LEVEL, 0},
  194. {MSC01E_INT_ATLAS, MSC01_IRQ_LEVEL, 0},
  195. {MSC01E_INT_TMR, MSC01_IRQ_EDGE, 0},
  196. {MSC01E_INT_PCI, MSC01_IRQ_LEVEL, 0},
  197. {MSC01E_INT_PERFCTR, MSC01_IRQ_LEVEL, 0},
  198. {MSC01E_INT_CPUCTR, MSC01_IRQ_LEVEL, 0}
  199. };
  200. int __initdata msc_nr_eicirqs = sizeof(msc_eicirqmap) / sizeof(*msc_eicirqmap);
  201. void __init arch_init_irq(void)
  202. {
  203. init_atlas_irqs(ATLAS_INT_BASE);
  204. if (!cpu_has_veic)
  205. mips_cpu_irq_init();
  206. switch(mips_revision_corid) {
  207. case MIPS_REVISION_CORID_CORE_MSC:
  208. case MIPS_REVISION_CORID_CORE_FPGA2:
  209. case MIPS_REVISION_CORID_CORE_FPGA3:
  210. case MIPS_REVISION_CORID_CORE_24K:
  211. case MIPS_REVISION_CORID_CORE_EMUL_MSC:
  212. if (cpu_has_veic)
  213. init_msc_irqs (MSC01E_INT_BASE,
  214. msc_eicirqmap, msc_nr_eicirqs);
  215. else
  216. init_msc_irqs (MSC01C_INT_BASE,
  217. msc_irqmap, msc_nr_irqs);
  218. }
  219. if (cpu_has_veic) {
  220. set_vi_handler (MSC01E_INT_ATLAS, atlas_hw0_irqdispatch);
  221. setup_irq (MSC01E_INT_BASE + MSC01E_INT_ATLAS, &atlasirq);
  222. } else if (cpu_has_vint) {
  223. set_vi_handler (MIPSCPU_INT_ATLAS, atlas_hw0_irqdispatch);
  224. #ifdef CONFIG_MIPS_MT_SMTC
  225. setup_irq_smtc (MIPSCPU_INT_BASE + MIPSCPU_INT_ATLAS,
  226. &atlasirq, (0x100 << MIPSCPU_INT_ATLAS));
  227. #else /* Not SMTC */
  228. setup_irq(MIPSCPU_INT_BASE + MIPSCPU_INT_ATLAS, &atlasirq);
  229. #endif /* CONFIG_MIPS_MT_SMTC */
  230. } else
  231. setup_irq(MIPSCPU_INT_BASE + MIPSCPU_INT_ATLAS, &atlasirq);
  232. }