irq.c 12 KB

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