irq.c 9.2 KB

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