irq.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. /*
  2. * Copyright (C) 2000,2001,2002,2003,2004 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/smp.h>
  23. #include <linux/spinlock.h>
  24. #include <linux/mm.h>
  25. #include <linux/slab.h>
  26. #include <linux/kernel_stat.h>
  27. #include <asm/errno.h>
  28. #include <asm/irq_regs.h>
  29. #include <asm/signal.h>
  30. #include <asm/system.h>
  31. #include <asm/io.h>
  32. #include <asm/sibyte/bcm1480_regs.h>
  33. #include <asm/sibyte/bcm1480_int.h>
  34. #include <asm/sibyte/bcm1480_scd.h>
  35. #include <asm/sibyte/sb1250_uart.h>
  36. #include <asm/sibyte/sb1250.h>
  37. /*
  38. * These are the routines that handle all the low level interrupt stuff.
  39. * Actions handled here are: initialization of the interrupt map, requesting of
  40. * interrupt lines by handlers, dispatching if interrupts to handlers, probing
  41. * for interrupt lines
  42. */
  43. static void end_bcm1480_irq(unsigned int irq);
  44. static void enable_bcm1480_irq(unsigned int irq);
  45. static void disable_bcm1480_irq(unsigned int irq);
  46. static void ack_bcm1480_irq(unsigned int irq);
  47. #ifdef CONFIG_SMP
  48. static int bcm1480_set_affinity(unsigned int irq, const struct cpumask *mask);
  49. #endif
  50. #ifdef CONFIG_PCI
  51. extern unsigned long ht_eoi_space;
  52. #endif
  53. static struct irq_chip bcm1480_irq_type = {
  54. .name = "BCM1480-IMR",
  55. .ack = ack_bcm1480_irq,
  56. .mask = disable_bcm1480_irq,
  57. .mask_ack = ack_bcm1480_irq,
  58. .unmask = enable_bcm1480_irq,
  59. .end = end_bcm1480_irq,
  60. #ifdef CONFIG_SMP
  61. .set_affinity = bcm1480_set_affinity
  62. #endif
  63. };
  64. /* Store the CPU id (not the logical number) */
  65. int bcm1480_irq_owner[BCM1480_NR_IRQS];
  66. DEFINE_SPINLOCK(bcm1480_imr_lock);
  67. void bcm1480_mask_irq(int cpu, int irq)
  68. {
  69. unsigned long flags, hl_spacing;
  70. u64 cur_ints;
  71. spin_lock_irqsave(&bcm1480_imr_lock, flags);
  72. hl_spacing = 0;
  73. if ((irq >= BCM1480_NR_IRQS_HALF) && (irq <= BCM1480_NR_IRQS)) {
  74. hl_spacing = BCM1480_IMR_HL_SPACING;
  75. irq -= BCM1480_NR_IRQS_HALF;
  76. }
  77. cur_ints = ____raw_readq(IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + hl_spacing));
  78. cur_ints |= (((u64) 1) << irq);
  79. ____raw_writeq(cur_ints, IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + hl_spacing));
  80. spin_unlock_irqrestore(&bcm1480_imr_lock, flags);
  81. }
  82. void bcm1480_unmask_irq(int cpu, int irq)
  83. {
  84. unsigned long flags, hl_spacing;
  85. u64 cur_ints;
  86. spin_lock_irqsave(&bcm1480_imr_lock, flags);
  87. hl_spacing = 0;
  88. if ((irq >= BCM1480_NR_IRQS_HALF) && (irq <= BCM1480_NR_IRQS)) {
  89. hl_spacing = BCM1480_IMR_HL_SPACING;
  90. irq -= BCM1480_NR_IRQS_HALF;
  91. }
  92. cur_ints = ____raw_readq(IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + hl_spacing));
  93. cur_ints &= ~(((u64) 1) << irq);
  94. ____raw_writeq(cur_ints, IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + hl_spacing));
  95. spin_unlock_irqrestore(&bcm1480_imr_lock, flags);
  96. }
  97. #ifdef CONFIG_SMP
  98. static int bcm1480_set_affinity(unsigned int irq, const struct cpumask *mask)
  99. {
  100. int i = 0, old_cpu, cpu, int_on, k;
  101. u64 cur_ints;
  102. unsigned long flags;
  103. unsigned int irq_dirty;
  104. i = cpumask_first(mask);
  105. /* Convert logical CPU to physical CPU */
  106. cpu = cpu_logical_map(i);
  107. /* Protect against other affinity changers and IMR manipulation */
  108. spin_lock_irqsave(&bcm1480_imr_lock, flags);
  109. /* Swizzle each CPU's IMR (but leave the IP selection alone) */
  110. old_cpu = bcm1480_irq_owner[irq];
  111. irq_dirty = irq;
  112. if ((irq_dirty >= BCM1480_NR_IRQS_HALF) && (irq_dirty <= BCM1480_NR_IRQS)) {
  113. irq_dirty -= BCM1480_NR_IRQS_HALF;
  114. }
  115. for (k=0; k<2; k++) { /* Loop through high and low interrupt mask register */
  116. cur_ints = ____raw_readq(IOADDR(A_BCM1480_IMR_MAPPER(old_cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + (k*BCM1480_IMR_HL_SPACING)));
  117. int_on = !(cur_ints & (((u64) 1) << irq_dirty));
  118. if (int_on) {
  119. /* If it was on, mask it */
  120. cur_ints |= (((u64) 1) << irq_dirty);
  121. ____raw_writeq(cur_ints, IOADDR(A_BCM1480_IMR_MAPPER(old_cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + (k*BCM1480_IMR_HL_SPACING)));
  122. }
  123. bcm1480_irq_owner[irq] = cpu;
  124. if (int_on) {
  125. /* unmask for the new CPU */
  126. cur_ints = ____raw_readq(IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + (k*BCM1480_IMR_HL_SPACING)));
  127. cur_ints &= ~(((u64) 1) << irq_dirty);
  128. ____raw_writeq(cur_ints, IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + (k*BCM1480_IMR_HL_SPACING)));
  129. }
  130. }
  131. spin_unlock_irqrestore(&bcm1480_imr_lock, flags);
  132. return 0;
  133. }
  134. #endif
  135. /*****************************************************************************/
  136. static void disable_bcm1480_irq(unsigned int irq)
  137. {
  138. bcm1480_mask_irq(bcm1480_irq_owner[irq], irq);
  139. }
  140. static void enable_bcm1480_irq(unsigned int irq)
  141. {
  142. bcm1480_unmask_irq(bcm1480_irq_owner[irq], irq);
  143. }
  144. static void ack_bcm1480_irq(unsigned int irq)
  145. {
  146. u64 pending;
  147. unsigned int irq_dirty;
  148. int k;
  149. /*
  150. * If the interrupt was an HT interrupt, now is the time to
  151. * clear it. NOTE: we assume the HT bridge was set up to
  152. * deliver the interrupts to all CPUs (which makes affinity
  153. * changing easier for us)
  154. */
  155. irq_dirty = irq;
  156. if ((irq_dirty >= BCM1480_NR_IRQS_HALF) && (irq_dirty <= BCM1480_NR_IRQS)) {
  157. irq_dirty -= BCM1480_NR_IRQS_HALF;
  158. }
  159. for (k=0; k<2; k++) { /* Loop through high and low LDT interrupts */
  160. pending = __raw_readq(IOADDR(A_BCM1480_IMR_REGISTER(bcm1480_irq_owner[irq],
  161. R_BCM1480_IMR_LDT_INTERRUPT_H + (k*BCM1480_IMR_HL_SPACING))));
  162. pending &= ((u64)1 << (irq_dirty));
  163. if (pending) {
  164. #ifdef CONFIG_SMP
  165. int i;
  166. for (i=0; i<NR_CPUS; i++) {
  167. /*
  168. * Clear for all CPUs so an affinity switch
  169. * doesn't find an old status
  170. */
  171. __raw_writeq(pending, IOADDR(A_BCM1480_IMR_REGISTER(cpu_logical_map(i),
  172. R_BCM1480_IMR_LDT_INTERRUPT_CLR_H + (k*BCM1480_IMR_HL_SPACING))));
  173. }
  174. #else
  175. __raw_writeq(pending, IOADDR(A_BCM1480_IMR_REGISTER(0, R_BCM1480_IMR_LDT_INTERRUPT_CLR_H + (k*BCM1480_IMR_HL_SPACING))));
  176. #endif
  177. /*
  178. * Generate EOI. For Pass 1 parts, EOI is a nop. For
  179. * Pass 2, the LDT world may be edge-triggered, but
  180. * this EOI shouldn't hurt. If they are
  181. * level-sensitive, the EOI is required.
  182. */
  183. #ifdef CONFIG_PCI
  184. if (ht_eoi_space)
  185. *(uint32_t *)(ht_eoi_space+(irq<<16)+(7<<2)) = 0;
  186. #endif
  187. }
  188. }
  189. bcm1480_mask_irq(bcm1480_irq_owner[irq], irq);
  190. }
  191. static void end_bcm1480_irq(unsigned int irq)
  192. {
  193. if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
  194. bcm1480_unmask_irq(bcm1480_irq_owner[irq], irq);
  195. }
  196. }
  197. void __init init_bcm1480_irqs(void)
  198. {
  199. int i;
  200. for (i = 0; i < BCM1480_NR_IRQS; i++) {
  201. set_irq_chip_and_handler(i, &bcm1480_irq_type, handle_level_irq);
  202. bcm1480_irq_owner[i] = 0;
  203. }
  204. }
  205. /*
  206. * init_IRQ is called early in the boot sequence from init/main.c. It
  207. * is responsible for setting up the interrupt mapper and installing the
  208. * handler that will be responsible for dispatching interrupts to the
  209. * "right" place.
  210. */
  211. /*
  212. * For now, map all interrupts to IP[2]. We could save
  213. * some cycles by parceling out system interrupts to different
  214. * IP lines, but keep it simple for bringup. We'll also direct
  215. * all interrupts to a single CPU; we should probably route
  216. * PCI and LDT to one cpu and everything else to the other
  217. * to balance the load a bit.
  218. *
  219. * On the second cpu, everything is set to IP5, which is
  220. * ignored, EXCEPT the mailbox interrupt. That one is
  221. * set to IP[2] so it is handled. This is needed so we
  222. * can do cross-cpu function calls, as requred by SMP
  223. */
  224. #define IMR_IP2_VAL K_BCM1480_INT_MAP_I0
  225. #define IMR_IP3_VAL K_BCM1480_INT_MAP_I1
  226. #define IMR_IP4_VAL K_BCM1480_INT_MAP_I2
  227. #define IMR_IP5_VAL K_BCM1480_INT_MAP_I3
  228. #define IMR_IP6_VAL K_BCM1480_INT_MAP_I4
  229. void __init arch_init_irq(void)
  230. {
  231. unsigned int i, cpu;
  232. u64 tmp;
  233. unsigned int imask = STATUSF_IP4 | STATUSF_IP3 | STATUSF_IP2 |
  234. STATUSF_IP1 | STATUSF_IP0;
  235. /* Default everything to IP2 */
  236. /* Start with _high registers which has no bit 0 interrupt source */
  237. for (i = 1; i < BCM1480_NR_IRQS_HALF; i++) { /* was I0 */
  238. for (cpu = 0; cpu < 4; cpu++) {
  239. __raw_writeq(IMR_IP2_VAL,
  240. IOADDR(A_BCM1480_IMR_REGISTER(cpu,
  241. R_BCM1480_IMR_INTERRUPT_MAP_BASE_H) + (i << 3)));
  242. }
  243. }
  244. /* Now do _low registers */
  245. for (i = 0; i < BCM1480_NR_IRQS_HALF; i++) {
  246. for (cpu = 0; cpu < 4; cpu++) {
  247. __raw_writeq(IMR_IP2_VAL,
  248. IOADDR(A_BCM1480_IMR_REGISTER(cpu,
  249. R_BCM1480_IMR_INTERRUPT_MAP_BASE_L) + (i << 3)));
  250. }
  251. }
  252. init_bcm1480_irqs();
  253. /*
  254. * Map the high 16 bits of mailbox_0 registers to IP[3], for
  255. * inter-cpu messages
  256. */
  257. /* Was I1 */
  258. for (cpu = 0; cpu < 4; cpu++) {
  259. __raw_writeq(IMR_IP3_VAL, IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_INTERRUPT_MAP_BASE_H) +
  260. (K_BCM1480_INT_MBOX_0_0 << 3)));
  261. }
  262. /* Clear the mailboxes. The firmware may leave them dirty */
  263. for (cpu = 0; cpu < 4; cpu++) {
  264. __raw_writeq(0xffffffffffffffffULL,
  265. IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_MAILBOX_0_CLR_CPU)));
  266. __raw_writeq(0xffffffffffffffffULL,
  267. IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_MAILBOX_1_CLR_CPU)));
  268. }
  269. /* Mask everything except the high 16 bit of mailbox_0 registers for all cpus */
  270. tmp = ~((u64) 0) ^ ( (((u64) 1) << K_BCM1480_INT_MBOX_0_0));
  271. for (cpu = 0; cpu < 4; cpu++) {
  272. __raw_writeq(tmp, IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_INTERRUPT_MASK_H)));
  273. }
  274. tmp = ~((u64) 0);
  275. for (cpu = 0; cpu < 4; cpu++) {
  276. __raw_writeq(tmp, IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_INTERRUPT_MASK_L)));
  277. }
  278. /*
  279. * Note that the timer interrupts are also mapped, but this is
  280. * done in bcm1480_time_init(). Also, the profiling driver
  281. * does its own management of IP7.
  282. */
  283. /* Enable necessary IPs, disable the rest */
  284. change_c0_status(ST0_IM, imask);
  285. }
  286. extern void bcm1480_mailbox_interrupt(void);
  287. static inline void dispatch_ip2(void)
  288. {
  289. unsigned long long mask_h, mask_l;
  290. unsigned int cpu = smp_processor_id();
  291. unsigned long base;
  292. /*
  293. * Default...we've hit an IP[2] interrupt, which means we've got to
  294. * check the 1480 interrupt registers to figure out what to do. Need
  295. * to detect which CPU we're on, now that smp_affinity is supported.
  296. */
  297. base = A_BCM1480_IMR_MAPPER(cpu);
  298. mask_h = __raw_readq(
  299. IOADDR(base + R_BCM1480_IMR_INTERRUPT_STATUS_BASE_H));
  300. mask_l = __raw_readq(
  301. IOADDR(base + R_BCM1480_IMR_INTERRUPT_STATUS_BASE_L));
  302. if (mask_h) {
  303. if (mask_h ^ 1)
  304. do_IRQ(fls64(mask_h) - 1);
  305. else if (mask_l)
  306. do_IRQ(63 + fls64(mask_l));
  307. }
  308. }
  309. asmlinkage void plat_irq_dispatch(void)
  310. {
  311. unsigned int cpu = smp_processor_id();
  312. unsigned int pending;
  313. #ifdef CONFIG_SIBYTE_BCM1480_PROF
  314. /* Set compare to count to silence count/compare timer interrupts */
  315. write_c0_compare(read_c0_count());
  316. #endif
  317. pending = read_c0_cause() & read_c0_status();
  318. #ifdef CONFIG_SIBYTE_BCM1480_PROF
  319. if (pending & CAUSEF_IP7) /* Cpu performance counter interrupt */
  320. sbprof_cpu_intr();
  321. else
  322. #endif
  323. if (pending & CAUSEF_IP4)
  324. do_IRQ(K_BCM1480_INT_TIMER_0 + cpu);
  325. #ifdef CONFIG_SMP
  326. else if (pending & CAUSEF_IP3)
  327. bcm1480_mailbox_interrupt();
  328. #endif
  329. else if (pending & CAUSEF_IP2)
  330. dispatch_ip2();
  331. }