msp_irq_cic.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * Copyright 2010 PMC-Sierra, Inc, derived from irq_cpu.c
  3. *
  4. * This file define the irq handler for MSP CIC subsystem interrupts.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. */
  11. #include <linux/init.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/kernel.h>
  14. #include <linux/bitops.h>
  15. #include <linux/irq.h>
  16. #include <asm/mipsregs.h>
  17. #include <asm/system.h>
  18. #include <msp_cic_int.h>
  19. #include <msp_regs.h>
  20. /*
  21. * External API
  22. */
  23. extern void msp_per_irq_init(void);
  24. extern void msp_per_irq_dispatch(void);
  25. /*
  26. * Convenience Macro. Should be somewhere generic.
  27. */
  28. #define get_current_vpe() \
  29. ((read_c0_tcbind() >> TCBIND_CURVPE_SHIFT) & TCBIND_CURVPE)
  30. #ifdef CONFIG_SMP
  31. #define LOCK_VPE(flags, mtflags) \
  32. do { \
  33. local_irq_save(flags); \
  34. mtflags = dmt(); \
  35. } while (0)
  36. #define UNLOCK_VPE(flags, mtflags) \
  37. do { \
  38. emt(mtflags); \
  39. local_irq_restore(flags);\
  40. } while (0)
  41. #define LOCK_CORE(flags, mtflags) \
  42. do { \
  43. local_irq_save(flags); \
  44. mtflags = dvpe(); \
  45. } while (0)
  46. #define UNLOCK_CORE(flags, mtflags) \
  47. do { \
  48. evpe(mtflags); \
  49. local_irq_restore(flags);\
  50. } while (0)
  51. #else
  52. #define LOCK_VPE(flags, mtflags)
  53. #define UNLOCK_VPE(flags, mtflags)
  54. #endif
  55. /* ensure writes to cic are completed */
  56. static inline void cic_wmb(void)
  57. {
  58. const volatile void __iomem *cic_mem = CIC_VPE0_MSK_REG;
  59. volatile u32 dummy_read;
  60. wmb();
  61. dummy_read = __raw_readl(cic_mem);
  62. dummy_read++;
  63. }
  64. static void unmask_cic_irq(struct irq_data *d)
  65. {
  66. volatile u32 *cic_msk_reg = CIC_VPE0_MSK_REG;
  67. int vpe;
  68. #ifdef CONFIG_SMP
  69. unsigned int mtflags;
  70. unsigned long flags;
  71. /*
  72. * Make sure we have IRQ affinity. It may have changed while
  73. * we were processing the IRQ.
  74. */
  75. if (!cpumask_test_cpu(smp_processor_id(), d->affinity))
  76. return;
  77. #endif
  78. vpe = get_current_vpe();
  79. LOCK_VPE(flags, mtflags);
  80. cic_msk_reg[vpe] |= (1 << (d->irq - MSP_CIC_INTBASE));
  81. UNLOCK_VPE(flags, mtflags);
  82. cic_wmb();
  83. }
  84. static void mask_cic_irq(struct irq_data *d)
  85. {
  86. volatile u32 *cic_msk_reg = CIC_VPE0_MSK_REG;
  87. int vpe = get_current_vpe();
  88. #ifdef CONFIG_SMP
  89. unsigned long flags, mtflags;
  90. #endif
  91. LOCK_VPE(flags, mtflags);
  92. cic_msk_reg[vpe] &= ~(1 << (d->irq - MSP_CIC_INTBASE));
  93. UNLOCK_VPE(flags, mtflags);
  94. cic_wmb();
  95. }
  96. static void msp_cic_irq_ack(struct irq_data *d)
  97. {
  98. mask_cic_irq(d);
  99. /*
  100. * Only really necessary for 18, 16-14 and sometimes 3:0
  101. * (since these can be edge sensitive) but it doesn't
  102. * hurt for the others
  103. */
  104. *CIC_STS_REG = (1 << (d->irq - MSP_CIC_INTBASE));
  105. smtc_im_ack_irq(d->irq);
  106. }
  107. /*Note: Limiting to VSMP . Not tested in SMTC */
  108. #ifdef CONFIG_MIPS_MT_SMP
  109. static int msp_cic_irq_set_affinity(struct irq_data *d,
  110. const struct cpumask *cpumask, bool force)
  111. {
  112. int cpu;
  113. unsigned long flags;
  114. unsigned int mtflags;
  115. unsigned long imask = (1 << (irq - MSP_CIC_INTBASE));
  116. volatile u32 *cic_mask = (volatile u32 *)CIC_VPE0_MSK_REG;
  117. /* timer balancing should be disabled in kernel code */
  118. BUG_ON(irq == MSP_INT_VPE0_TIMER || irq == MSP_INT_VPE1_TIMER);
  119. LOCK_CORE(flags, mtflags);
  120. /* enable if any of each VPE's TCs require this IRQ */
  121. for_each_online_cpu(cpu) {
  122. if (cpumask_test_cpu(cpu, cpumask))
  123. cic_mask[cpu] |= imask;
  124. else
  125. cic_mask[cpu] &= ~imask;
  126. }
  127. UNLOCK_CORE(flags, mtflags);
  128. return 0;
  129. }
  130. #endif
  131. static struct irq_chip msp_cic_irq_controller = {
  132. .name = "MSP_CIC",
  133. .irq_mask = mask_cic_irq,
  134. .irq_mask_ack = msp_cic_irq_ack,
  135. .irq_unmask = unmask_cic_irq,
  136. .irq_ack = msp_cic_irq_ack,
  137. #ifdef CONFIG_MIPS_MT_SMP
  138. .irq_set_affinity = msp_cic_irq_set_affinity,
  139. #endif
  140. };
  141. void __init msp_cic_irq_init(void)
  142. {
  143. int i;
  144. /* Mask/clear interrupts. */
  145. *CIC_VPE0_MSK_REG = 0x00000000;
  146. *CIC_VPE1_MSK_REG = 0x00000000;
  147. *CIC_STS_REG = 0xFFFFFFFF;
  148. /*
  149. * The MSP7120 RG and EVBD boards use IRQ[6:4] for PCI.
  150. * These inputs map to EXT_INT_POL[6:4] inside the CIC.
  151. * They are to be active low, level sensitive.
  152. */
  153. *CIC_EXT_CFG_REG &= 0xFFFF8F8F;
  154. /* initialize all the IRQ descriptors */
  155. for (i = MSP_CIC_INTBASE ; i < MSP_CIC_INTBASE + 32 ; i++) {
  156. irq_set_chip_and_handler(i, &msp_cic_irq_controller,
  157. handle_level_irq);
  158. #ifdef CONFIG_MIPS_MT_SMTC
  159. /* Mask of CIC interrupt */
  160. irq_hwmask[i] = C_IRQ4;
  161. #endif
  162. }
  163. /* Initialize the PER interrupt sub-system */
  164. msp_per_irq_init();
  165. }
  166. /* CIC masked by CIC vector processing before dispatch called */
  167. void msp_cic_irq_dispatch(void)
  168. {
  169. volatile u32 *cic_msk_reg = (volatile u32 *)CIC_VPE0_MSK_REG;
  170. u32 cic_mask;
  171. u32 pending;
  172. int cic_status = *CIC_STS_REG;
  173. cic_mask = cic_msk_reg[get_current_vpe()];
  174. pending = cic_status & cic_mask;
  175. if (pending & (1 << (MSP_INT_VPE0_TIMER - MSP_CIC_INTBASE))) {
  176. do_IRQ(MSP_INT_VPE0_TIMER);
  177. } else if (pending & (1 << (MSP_INT_VPE1_TIMER - MSP_CIC_INTBASE))) {
  178. do_IRQ(MSP_INT_VPE1_TIMER);
  179. } else if (pending & (1 << (MSP_INT_PER - MSP_CIC_INTBASE))) {
  180. msp_per_irq_dispatch();
  181. } else if (pending) {
  182. do_IRQ(ffs(pending) + MSP_CIC_INTBASE - 1);
  183. } else{
  184. spurious_interrupt();
  185. }
  186. }