atlas_int.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*
  2. * Carsten Langgaard, carstenl@mips.com
  3. * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
  4. *
  5. * ########################################################################
  6. *
  7. * This program is free software; you can distribute it and/or modify it
  8. * under the terms of the GNU General Public License (Version 2) as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  14. * for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  19. *
  20. * ########################################################################
  21. *
  22. * Routines for generic manipulation of the interrupts found on the MIPS
  23. * Atlas board.
  24. *
  25. */
  26. #include <linux/compiler.h>
  27. #include <linux/init.h>
  28. #include <linux/sched.h>
  29. #include <linux/slab.h>
  30. #include <linux/interrupt.h>
  31. #include <linux/kernel_stat.h>
  32. #include <asm/irq.h>
  33. #include <asm/io.h>
  34. #include <asm/mips-boards/atlas.h>
  35. #include <asm/mips-boards/atlasint.h>
  36. #include <asm/gdb-stub.h>
  37. static struct atlas_ictrl_regs *atlas_hw0_icregs;
  38. #if 0
  39. #define DEBUG_INT(x...) printk(x)
  40. #else
  41. #define DEBUG_INT(x...)
  42. #endif
  43. void disable_atlas_irq(unsigned int irq_nr)
  44. {
  45. atlas_hw0_icregs->intrsten = (1 << (irq_nr-ATLASINT_BASE));
  46. iob();
  47. }
  48. void enable_atlas_irq(unsigned int irq_nr)
  49. {
  50. atlas_hw0_icregs->intseten = (1 << (irq_nr-ATLASINT_BASE));
  51. iob();
  52. }
  53. static unsigned int startup_atlas_irq(unsigned int irq)
  54. {
  55. enable_atlas_irq(irq);
  56. return 0; /* never anything pending */
  57. }
  58. #define shutdown_atlas_irq disable_atlas_irq
  59. #define mask_and_ack_atlas_irq disable_atlas_irq
  60. static void end_atlas_irq(unsigned int irq)
  61. {
  62. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  63. enable_atlas_irq(irq);
  64. }
  65. static struct hw_interrupt_type atlas_irq_type = {
  66. .typename = "Atlas",
  67. .startup = startup_atlas_irq,
  68. .shutdown = shutdown_atlas_irq,
  69. .enable = enable_atlas_irq,
  70. .disable = disable_atlas_irq,
  71. .ack = mask_and_ack_atlas_irq,
  72. .end = end_atlas_irq,
  73. };
  74. static inline int ls1bit32(unsigned int x)
  75. {
  76. int b = 31, s;
  77. s = 16; if (x << 16 == 0) s = 0; b -= s; x <<= s;
  78. s = 8; if (x << 8 == 0) s = 0; b -= s; x <<= s;
  79. s = 4; if (x << 4 == 0) s = 0; b -= s; x <<= s;
  80. s = 2; if (x << 2 == 0) s = 0; b -= s; x <<= s;
  81. s = 1; if (x << 1 == 0) s = 0; b -= s;
  82. return b;
  83. }
  84. static inline void atlas_hw0_irqdispatch(struct pt_regs *regs)
  85. {
  86. unsigned long int_status;
  87. int irq;
  88. int_status = atlas_hw0_icregs->intstatus;
  89. /* if int_status == 0, then the interrupt has already been cleared */
  90. if (unlikely(int_status == 0))
  91. return;
  92. irq = ATLASINT_BASE + ls1bit32(int_status);
  93. DEBUG_INT("atlas_hw0_irqdispatch: irq=%d\n", irq);
  94. do_IRQ(irq, regs);
  95. }
  96. static inline int clz(unsigned long x)
  97. {
  98. __asm__ (
  99. " .set push \n"
  100. " .set mips32 \n"
  101. " clz %0, %1 \n"
  102. " .set pop \n"
  103. : "=r" (x)
  104. : "r" (x));
  105. return x;
  106. }
  107. /*
  108. * Version of ffs that only looks at bits 12..15.
  109. */
  110. static inline unsigned int irq_ffs(unsigned int pending)
  111. {
  112. #if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
  113. return -clz(pending) + 31 - CAUSEB_IP;
  114. #else
  115. unsigned int a0 = 7;
  116. unsigned int t0;
  117. t0 = s0 & 0xf000;
  118. t0 = t0 < 1;
  119. t0 = t0 << 2;
  120. a0 = a0 - t0;
  121. s0 = s0 << t0;
  122. t0 = s0 & 0xc000;
  123. t0 = t0 < 1;
  124. t0 = t0 << 1;
  125. a0 = a0 - t0;
  126. s0 = s0 << t0;
  127. t0 = s0 & 0x8000;
  128. t0 = t0 < 1;
  129. //t0 = t0 << 2;
  130. a0 = a0 - t0;
  131. //s0 = s0 << t0;
  132. return a0;
  133. #endif
  134. }
  135. /*
  136. * IRQs on the Atlas board look basically (barring software IRQs which we
  137. * don't use at all and all external interrupt sources are combined together
  138. * on hardware interrupt 0 (MIPS IRQ 2)) like:
  139. *
  140. * MIPS IRQ Source
  141. * -------- ------
  142. * 0 Software (ignored)
  143. * 1 Software (ignored)
  144. * 2 Combined hardware interrupt (hw0)
  145. * 3 Hardware (ignored)
  146. * 4 Hardware (ignored)
  147. * 5 Hardware (ignored)
  148. * 6 Hardware (ignored)
  149. * 7 R4k timer (what we use)
  150. *
  151. * We handle the IRQ according to _our_ priority which is:
  152. *
  153. * Highest ---- R4k Timer
  154. * Lowest ---- Combined hardware interrupt
  155. *
  156. * then we just return, if multiple IRQs are pending then we will just take
  157. * another exception, big deal.
  158. */
  159. asmlinkage void plat_irq_dispatch(struct pt_regs *regs)
  160. {
  161. unsigned int pending = read_c0_cause() & read_c0_status() & ST0_IM;
  162. int irq;
  163. irq = irq_ffs(pending);
  164. if (irq == MIPSCPU_INT_ATLAS)
  165. atlas_hw0_irqdispatch(regs);
  166. else if (irq > 0)
  167. do_IRQ(MIPSCPU_INT_BASE + irq, regs);
  168. else
  169. spurious_interrupt(regs);
  170. }
  171. void __init arch_init_irq(void)
  172. {
  173. int i;
  174. atlas_hw0_icregs = (struct atlas_ictrl_regs *)ioremap (ATLAS_ICTRL_REGS_BASE, 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 = ATLASINT_BASE; i <= ATLASINT_END; i++) {
  181. irq_desc[i].status = IRQ_DISABLED;
  182. irq_desc[i].action = 0;
  183. irq_desc[i].depth = 1;
  184. irq_desc[i].handler = &atlas_irq_type;
  185. spin_lock_init(&irq_desc[i].lock);
  186. }
  187. }