irq.c 9.8 KB

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