irq.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. /*
  2. * Copyright (C) 2000, 2001, 2002, 2003 Broadcom Corporation
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/init.h>
  20. #include <linux/linkage.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/spinlock.h>
  23. #include <linux/smp.h>
  24. #include <linux/mm.h>
  25. #include <linux/kernel_stat.h>
  26. #include <asm/errno.h>
  27. #include <asm/signal.h>
  28. #include <asm/time.h>
  29. #include <asm/io.h>
  30. #include <asm/sibyte/sb1250_regs.h>
  31. #include <asm/sibyte/sb1250_int.h>
  32. #include <asm/sibyte/sb1250_uart.h>
  33. #include <asm/sibyte/sb1250_scd.h>
  34. #include <asm/sibyte/sb1250.h>
  35. /*
  36. * These are the routines that handle all the low level interrupt stuff.
  37. * Actions handled here are: initialization of the interrupt map, requesting of
  38. * interrupt lines by handlers, dispatching if interrupts to handlers, probing
  39. * for interrupt lines
  40. */
  41. #ifdef CONFIG_SIBYTE_HAS_LDT
  42. extern unsigned long ldt_eoi_space;
  43. #endif
  44. /* Store the CPU id (not the logical number) */
  45. int sb1250_irq_owner[SB1250_NR_IRQS];
  46. static DEFINE_RAW_SPINLOCK(sb1250_imr_lock);
  47. void sb1250_mask_irq(int cpu, int irq)
  48. {
  49. unsigned long flags;
  50. u64 cur_ints;
  51. raw_spin_lock_irqsave(&sb1250_imr_lock, flags);
  52. cur_ints = ____raw_readq(IOADDR(A_IMR_MAPPER(cpu) +
  53. R_IMR_INTERRUPT_MASK));
  54. cur_ints |= (((u64) 1) << irq);
  55. ____raw_writeq(cur_ints, IOADDR(A_IMR_MAPPER(cpu) +
  56. R_IMR_INTERRUPT_MASK));
  57. raw_spin_unlock_irqrestore(&sb1250_imr_lock, flags);
  58. }
  59. void sb1250_unmask_irq(int cpu, int irq)
  60. {
  61. unsigned long flags;
  62. u64 cur_ints;
  63. raw_spin_lock_irqsave(&sb1250_imr_lock, flags);
  64. cur_ints = ____raw_readq(IOADDR(A_IMR_MAPPER(cpu) +
  65. R_IMR_INTERRUPT_MASK));
  66. cur_ints &= ~(((u64) 1) << irq);
  67. ____raw_writeq(cur_ints, IOADDR(A_IMR_MAPPER(cpu) +
  68. R_IMR_INTERRUPT_MASK));
  69. raw_spin_unlock_irqrestore(&sb1250_imr_lock, flags);
  70. }
  71. #ifdef CONFIG_SMP
  72. static int sb1250_set_affinity(struct irq_data *d, const struct cpumask *mask,
  73. bool force)
  74. {
  75. int i = 0, old_cpu, cpu, int_on;
  76. unsigned int irq = d->irq;
  77. u64 cur_ints;
  78. unsigned long flags;
  79. i = cpumask_first_and(mask, cpu_online_mask);
  80. /* Convert logical CPU to physical CPU */
  81. cpu = cpu_logical_map(i);
  82. /* Protect against other affinity changers and IMR manipulation */
  83. raw_spin_lock_irqsave(&sb1250_imr_lock, flags);
  84. /* Swizzle each CPU's IMR (but leave the IP selection alone) */
  85. old_cpu = sb1250_irq_owner[irq];
  86. cur_ints = ____raw_readq(IOADDR(A_IMR_MAPPER(old_cpu) +
  87. R_IMR_INTERRUPT_MASK));
  88. int_on = !(cur_ints & (((u64) 1) << irq));
  89. if (int_on) {
  90. /* If it was on, mask it */
  91. cur_ints |= (((u64) 1) << irq);
  92. ____raw_writeq(cur_ints, IOADDR(A_IMR_MAPPER(old_cpu) +
  93. R_IMR_INTERRUPT_MASK));
  94. }
  95. sb1250_irq_owner[irq] = cpu;
  96. if (int_on) {
  97. /* unmask for the new CPU */
  98. cur_ints = ____raw_readq(IOADDR(A_IMR_MAPPER(cpu) +
  99. R_IMR_INTERRUPT_MASK));
  100. cur_ints &= ~(((u64) 1) << irq);
  101. ____raw_writeq(cur_ints, IOADDR(A_IMR_MAPPER(cpu) +
  102. R_IMR_INTERRUPT_MASK));
  103. }
  104. raw_spin_unlock_irqrestore(&sb1250_imr_lock, flags);
  105. return 0;
  106. }
  107. #endif
  108. static void disable_sb1250_irq(struct irq_data *d)
  109. {
  110. unsigned int irq = d->irq;
  111. sb1250_mask_irq(sb1250_irq_owner[irq], irq);
  112. }
  113. static void enable_sb1250_irq(struct irq_data *d)
  114. {
  115. unsigned int irq = d->irq;
  116. sb1250_unmask_irq(sb1250_irq_owner[irq], irq);
  117. }
  118. static void ack_sb1250_irq(struct irq_data *d)
  119. {
  120. unsigned int irq = d->irq;
  121. #ifdef CONFIG_SIBYTE_HAS_LDT
  122. u64 pending;
  123. /*
  124. * If the interrupt was an HT interrupt, now is the time to
  125. * clear it. NOTE: we assume the HT bridge was set up to
  126. * deliver the interrupts to all CPUs (which makes affinity
  127. * changing easier for us)
  128. */
  129. pending = __raw_readq(IOADDR(A_IMR_REGISTER(sb1250_irq_owner[irq],
  130. R_IMR_LDT_INTERRUPT)));
  131. pending &= ((u64)1 << (irq));
  132. if (pending) {
  133. int i;
  134. for (i=0; i<NR_CPUS; i++) {
  135. int cpu;
  136. #ifdef CONFIG_SMP
  137. cpu = cpu_logical_map(i);
  138. #else
  139. cpu = i;
  140. #endif
  141. /*
  142. * Clear for all CPUs so an affinity switch
  143. * doesn't find an old status
  144. */
  145. __raw_writeq(pending,
  146. IOADDR(A_IMR_REGISTER(cpu,
  147. R_IMR_LDT_INTERRUPT_CLR)));
  148. }
  149. /*
  150. * Generate EOI. For Pass 1 parts, EOI is a nop. For
  151. * Pass 2, the LDT world may be edge-triggered, but
  152. * this EOI shouldn't hurt. If they are
  153. * level-sensitive, the EOI is required.
  154. */
  155. *(uint32_t *)(ldt_eoi_space+(irq<<16)+(7<<2)) = 0;
  156. }
  157. #endif
  158. sb1250_mask_irq(sb1250_irq_owner[irq], irq);
  159. }
  160. static struct irq_chip sb1250_irq_type = {
  161. .name = "SB1250-IMR",
  162. .irq_mask_ack = ack_sb1250_irq,
  163. .irq_unmask = enable_sb1250_irq,
  164. .irq_mask = disable_sb1250_irq,
  165. #ifdef CONFIG_SMP
  166. .irq_set_affinity = sb1250_set_affinity
  167. #endif
  168. };
  169. void __init init_sb1250_irqs(void)
  170. {
  171. int i;
  172. for (i = 0; i < SB1250_NR_IRQS; i++) {
  173. irq_set_chip_and_handler(i, &sb1250_irq_type,
  174. handle_level_irq);
  175. sb1250_irq_owner[i] = 0;
  176. }
  177. }
  178. /*
  179. * arch_init_irq is called early in the boot sequence from init/main.c via
  180. * init_IRQ. It is responsible for setting up the interrupt mapper and
  181. * installing the handler that will be responsible for dispatching interrupts
  182. * to the "right" place.
  183. */
  184. /*
  185. * For now, map all interrupts to IP[2]. We could save
  186. * some cycles by parceling out system interrupts to different
  187. * IP lines, but keep it simple for bringup. We'll also direct
  188. * all interrupts to a single CPU; we should probably route
  189. * PCI and LDT to one cpu and everything else to the other
  190. * to balance the load a bit.
  191. *
  192. * On the second cpu, everything is set to IP5, which is
  193. * ignored, EXCEPT the mailbox interrupt. That one is
  194. * set to IP[2] so it is handled. This is needed so we
  195. * can do cross-cpu function calls, as required by SMP
  196. */
  197. #define IMR_IP2_VAL K_INT_MAP_I0
  198. #define IMR_IP3_VAL K_INT_MAP_I1
  199. #define IMR_IP4_VAL K_INT_MAP_I2
  200. #define IMR_IP5_VAL K_INT_MAP_I3
  201. #define IMR_IP6_VAL K_INT_MAP_I4
  202. void __init arch_init_irq(void)
  203. {
  204. unsigned int i;
  205. u64 tmp;
  206. unsigned int imask = STATUSF_IP4 | STATUSF_IP3 | STATUSF_IP2 |
  207. STATUSF_IP1 | STATUSF_IP0;
  208. /* Default everything to IP2 */
  209. for (i = 0; i < SB1250_NR_IRQS; i++) { /* was I0 */
  210. __raw_writeq(IMR_IP2_VAL,
  211. IOADDR(A_IMR_REGISTER(0,
  212. R_IMR_INTERRUPT_MAP_BASE) +
  213. (i << 3)));
  214. __raw_writeq(IMR_IP2_VAL,
  215. IOADDR(A_IMR_REGISTER(1,
  216. R_IMR_INTERRUPT_MAP_BASE) +
  217. (i << 3)));
  218. }
  219. init_sb1250_irqs();
  220. /*
  221. * Map the high 16 bits of the mailbox registers to IP[3], for
  222. * inter-cpu messages
  223. */
  224. /* Was I1 */
  225. __raw_writeq(IMR_IP3_VAL,
  226. IOADDR(A_IMR_REGISTER(0, R_IMR_INTERRUPT_MAP_BASE) +
  227. (K_INT_MBOX_0 << 3)));
  228. __raw_writeq(IMR_IP3_VAL,
  229. IOADDR(A_IMR_REGISTER(1, R_IMR_INTERRUPT_MAP_BASE) +
  230. (K_INT_MBOX_0 << 3)));
  231. /* Clear the mailboxes. The firmware may leave them dirty */
  232. __raw_writeq(0xffffffffffffffffULL,
  233. IOADDR(A_IMR_REGISTER(0, R_IMR_MAILBOX_CLR_CPU)));
  234. __raw_writeq(0xffffffffffffffffULL,
  235. IOADDR(A_IMR_REGISTER(1, R_IMR_MAILBOX_CLR_CPU)));
  236. /* Mask everything except the mailbox registers for both cpus */
  237. tmp = ~((u64) 0) ^ (((u64) 1) << K_INT_MBOX_0);
  238. __raw_writeq(tmp, IOADDR(A_IMR_REGISTER(0, R_IMR_INTERRUPT_MASK)));
  239. __raw_writeq(tmp, IOADDR(A_IMR_REGISTER(1, R_IMR_INTERRUPT_MASK)));
  240. /*
  241. * Note that the timer interrupts are also mapped, but this is
  242. * done in sb1250_time_init(). Also, the profiling driver
  243. * does its own management of IP7.
  244. */
  245. /* Enable necessary IPs, disable the rest */
  246. change_c0_status(ST0_IM, imask);
  247. }
  248. extern void sb1250_mailbox_interrupt(void);
  249. static inline void dispatch_ip2(void)
  250. {
  251. unsigned int cpu = smp_processor_id();
  252. unsigned long long mask;
  253. /*
  254. * Default...we've hit an IP[2] interrupt, which means we've got to
  255. * check the 1250 interrupt registers to figure out what to do. Need
  256. * to detect which CPU we're on, now that smp_affinity is supported.
  257. */
  258. mask = __raw_readq(IOADDR(A_IMR_REGISTER(cpu,
  259. R_IMR_INTERRUPT_STATUS_BASE)));
  260. if (mask)
  261. do_IRQ(fls64(mask) - 1);
  262. }
  263. asmlinkage void plat_irq_dispatch(void)
  264. {
  265. unsigned int cpu = smp_processor_id();
  266. unsigned int pending;
  267. /*
  268. * What a pain. We have to be really careful saving the upper 32 bits
  269. * of any * register across function calls if we don't want them
  270. * trashed--since were running in -o32, the calling routing never saves
  271. * the full 64 bits of a register across a function call. Being the
  272. * interrupt handler, we're guaranteed that interrupts are disabled
  273. * during this code so we don't have to worry about random interrupts
  274. * blasting the high 32 bits.
  275. */
  276. pending = read_c0_cause() & read_c0_status() & ST0_IM;
  277. if (pending & CAUSEF_IP7) /* CPU performance counter interrupt */
  278. do_IRQ(MIPS_CPU_IRQ_BASE + 7);
  279. else if (pending & CAUSEF_IP4)
  280. do_IRQ(K_INT_TIMER_0 + cpu); /* sb1250_timer_interrupt() */
  281. #ifdef CONFIG_SMP
  282. else if (pending & CAUSEF_IP3)
  283. sb1250_mailbox_interrupt();
  284. #endif
  285. else if (pending & CAUSEF_IP2)
  286. dispatch_ip2();
  287. else
  288. spurious_interrupt();
  289. }