atlas_int.c 7.2 KB

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