atlas_int.c 6.8 KB

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