irq.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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/spinlock.h>
  23. #include <linux/mm.h>
  24. #include <linux/slab.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 void bcm1480_set_affinity(unsigned int irq, cpumask_t mask);
  48. #endif
  49. #ifdef CONFIG_PCI
  50. extern unsigned long ht_eoi_space;
  51. #endif
  52. #ifdef CONFIG_KGDB
  53. #include <asm/gdb-stub.h>
  54. extern void breakpoint(void);
  55. static int kgdb_irq;
  56. #ifdef CONFIG_GDB_CONSOLE
  57. extern void register_gdb_console(void);
  58. #endif
  59. /* kgdb is on when configured. Pass "nokgdb" kernel arg to turn it off */
  60. static int kgdb_flag = 1;
  61. static int __init nokgdb(char *str)
  62. {
  63. kgdb_flag = 0;
  64. return 1;
  65. }
  66. __setup("nokgdb", nokgdb);
  67. /* Default to UART1 */
  68. int kgdb_port = 1;
  69. #ifdef CONFIG_SERIAL_SB1250_DUART
  70. extern char sb1250_duart_present[];
  71. #endif
  72. #endif
  73. static struct irq_chip bcm1480_irq_type = {
  74. .name = "BCM1480-IMR",
  75. .ack = ack_bcm1480_irq,
  76. .mask = disable_bcm1480_irq,
  77. .mask_ack = ack_bcm1480_irq,
  78. .unmask = enable_bcm1480_irq,
  79. .end = end_bcm1480_irq,
  80. #ifdef CONFIG_SMP
  81. .set_affinity = bcm1480_set_affinity
  82. #endif
  83. };
  84. /* Store the CPU id (not the logical number) */
  85. int bcm1480_irq_owner[BCM1480_NR_IRQS];
  86. DEFINE_SPINLOCK(bcm1480_imr_lock);
  87. void bcm1480_mask_irq(int cpu, int irq)
  88. {
  89. unsigned long flags, hl_spacing;
  90. u64 cur_ints;
  91. spin_lock_irqsave(&bcm1480_imr_lock, flags);
  92. hl_spacing = 0;
  93. if ((irq >= BCM1480_NR_IRQS_HALF) && (irq <= BCM1480_NR_IRQS)) {
  94. hl_spacing = BCM1480_IMR_HL_SPACING;
  95. irq -= BCM1480_NR_IRQS_HALF;
  96. }
  97. cur_ints = ____raw_readq(IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + hl_spacing));
  98. cur_ints |= (((u64) 1) << irq);
  99. ____raw_writeq(cur_ints, IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + hl_spacing));
  100. spin_unlock_irqrestore(&bcm1480_imr_lock, flags);
  101. }
  102. void bcm1480_unmask_irq(int cpu, int irq)
  103. {
  104. unsigned long flags, hl_spacing;
  105. u64 cur_ints;
  106. spin_lock_irqsave(&bcm1480_imr_lock, flags);
  107. hl_spacing = 0;
  108. if ((irq >= BCM1480_NR_IRQS_HALF) && (irq <= BCM1480_NR_IRQS)) {
  109. hl_spacing = BCM1480_IMR_HL_SPACING;
  110. irq -= BCM1480_NR_IRQS_HALF;
  111. }
  112. cur_ints = ____raw_readq(IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + hl_spacing));
  113. cur_ints &= ~(((u64) 1) << irq);
  114. ____raw_writeq(cur_ints, IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + hl_spacing));
  115. spin_unlock_irqrestore(&bcm1480_imr_lock, flags);
  116. }
  117. #ifdef CONFIG_SMP
  118. static void bcm1480_set_affinity(unsigned int irq, cpumask_t mask)
  119. {
  120. int i = 0, old_cpu, cpu, int_on, k;
  121. u64 cur_ints;
  122. struct irq_desc *desc = irq_desc + irq;
  123. unsigned long flags;
  124. unsigned int irq_dirty;
  125. if (cpus_weight(mask) != 1) {
  126. printk("attempted to set irq affinity for irq %d to multiple CPUs\n", irq);
  127. return;
  128. }
  129. i = first_cpu(mask);
  130. /* Convert logical CPU to physical CPU */
  131. cpu = cpu_logical_map(i);
  132. /* Protect against other affinity changers and IMR manipulation */
  133. spin_lock_irqsave(&desc->lock, flags);
  134. spin_lock(&bcm1480_imr_lock);
  135. /* Swizzle each CPU's IMR (but leave the IP selection alone) */
  136. old_cpu = bcm1480_irq_owner[irq];
  137. irq_dirty = irq;
  138. if ((irq_dirty >= BCM1480_NR_IRQS_HALF) && (irq_dirty <= BCM1480_NR_IRQS)) {
  139. irq_dirty -= BCM1480_NR_IRQS_HALF;
  140. }
  141. for (k=0; k<2; k++) { /* Loop through high and low interrupt mask register */
  142. cur_ints = ____raw_readq(IOADDR(A_BCM1480_IMR_MAPPER(old_cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + (k*BCM1480_IMR_HL_SPACING)));
  143. int_on = !(cur_ints & (((u64) 1) << irq_dirty));
  144. if (int_on) {
  145. /* If it was on, mask it */
  146. cur_ints |= (((u64) 1) << irq_dirty);
  147. ____raw_writeq(cur_ints, IOADDR(A_BCM1480_IMR_MAPPER(old_cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + (k*BCM1480_IMR_HL_SPACING)));
  148. }
  149. bcm1480_irq_owner[irq] = cpu;
  150. if (int_on) {
  151. /* unmask for the new CPU */
  152. cur_ints = ____raw_readq(IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + (k*BCM1480_IMR_HL_SPACING)));
  153. cur_ints &= ~(((u64) 1) << irq_dirty);
  154. ____raw_writeq(cur_ints, IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + (k*BCM1480_IMR_HL_SPACING)));
  155. }
  156. }
  157. spin_unlock(&bcm1480_imr_lock);
  158. spin_unlock_irqrestore(&desc->lock, flags);
  159. }
  160. #endif
  161. /*****************************************************************************/
  162. static void disable_bcm1480_irq(unsigned int irq)
  163. {
  164. bcm1480_mask_irq(bcm1480_irq_owner[irq], irq);
  165. }
  166. static void enable_bcm1480_irq(unsigned int irq)
  167. {
  168. bcm1480_unmask_irq(bcm1480_irq_owner[irq], irq);
  169. }
  170. static void ack_bcm1480_irq(unsigned int irq)
  171. {
  172. u64 pending;
  173. unsigned int irq_dirty;
  174. int k;
  175. /*
  176. * If the interrupt was an HT interrupt, now is the time to
  177. * clear it. NOTE: we assume the HT bridge was set up to
  178. * deliver the interrupts to all CPUs (which makes affinity
  179. * changing easier for us)
  180. */
  181. irq_dirty = irq;
  182. if ((irq_dirty >= BCM1480_NR_IRQS_HALF) && (irq_dirty <= BCM1480_NR_IRQS)) {
  183. irq_dirty -= BCM1480_NR_IRQS_HALF;
  184. }
  185. for (k=0; k<2; k++) { /* Loop through high and low LDT interrupts */
  186. pending = __raw_readq(IOADDR(A_BCM1480_IMR_REGISTER(bcm1480_irq_owner[irq],
  187. R_BCM1480_IMR_LDT_INTERRUPT_H + (k*BCM1480_IMR_HL_SPACING))));
  188. pending &= ((u64)1 << (irq_dirty));
  189. if (pending) {
  190. #ifdef CONFIG_SMP
  191. int i;
  192. for (i=0; i<NR_CPUS; i++) {
  193. /*
  194. * Clear for all CPUs so an affinity switch
  195. * doesn't find an old status
  196. */
  197. __raw_writeq(pending, IOADDR(A_BCM1480_IMR_REGISTER(cpu_logical_map(i),
  198. R_BCM1480_IMR_LDT_INTERRUPT_CLR_H + (k*BCM1480_IMR_HL_SPACING))));
  199. }
  200. #else
  201. __raw_writeq(pending, IOADDR(A_BCM1480_IMR_REGISTER(0, R_BCM1480_IMR_LDT_INTERRUPT_CLR_H + (k*BCM1480_IMR_HL_SPACING))));
  202. #endif
  203. /*
  204. * Generate EOI. For Pass 1 parts, EOI is a nop. For
  205. * Pass 2, the LDT world may be edge-triggered, but
  206. * this EOI shouldn't hurt. If they are
  207. * level-sensitive, the EOI is required.
  208. */
  209. #ifdef CONFIG_PCI
  210. if (ht_eoi_space)
  211. *(uint32_t *)(ht_eoi_space+(irq<<16)+(7<<2)) = 0;
  212. #endif
  213. }
  214. }
  215. bcm1480_mask_irq(bcm1480_irq_owner[irq], irq);
  216. }
  217. static void end_bcm1480_irq(unsigned int irq)
  218. {
  219. if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
  220. bcm1480_unmask_irq(bcm1480_irq_owner[irq], irq);
  221. }
  222. }
  223. void __init init_bcm1480_irqs(void)
  224. {
  225. int i;
  226. for (i = 0; i < BCM1480_NR_IRQS; i++) {
  227. set_irq_chip(i, &bcm1480_irq_type);
  228. bcm1480_irq_owner[i] = 0;
  229. }
  230. }
  231. /*
  232. * init_IRQ is called early in the boot sequence from init/main.c. It
  233. * is responsible for setting up the interrupt mapper and installing the
  234. * handler that will be responsible for dispatching interrupts to the
  235. * "right" place.
  236. */
  237. /*
  238. * For now, map all interrupts to IP[2]. We could save
  239. * some cycles by parceling out system interrupts to different
  240. * IP lines, but keep it simple for bringup. We'll also direct
  241. * all interrupts to a single CPU; we should probably route
  242. * PCI and LDT to one cpu and everything else to the other
  243. * to balance the load a bit.
  244. *
  245. * On the second cpu, everything is set to IP5, which is
  246. * ignored, EXCEPT the mailbox interrupt. That one is
  247. * set to IP[2] so it is handled. This is needed so we
  248. * can do cross-cpu function calls, as requred by SMP
  249. */
  250. #define IMR_IP2_VAL K_BCM1480_INT_MAP_I0
  251. #define IMR_IP3_VAL K_BCM1480_INT_MAP_I1
  252. #define IMR_IP4_VAL K_BCM1480_INT_MAP_I2
  253. #define IMR_IP5_VAL K_BCM1480_INT_MAP_I3
  254. #define IMR_IP6_VAL K_BCM1480_INT_MAP_I4
  255. void __init arch_init_irq(void)
  256. {
  257. unsigned int i, cpu;
  258. u64 tmp;
  259. unsigned int imask = STATUSF_IP4 | STATUSF_IP3 | STATUSF_IP2 |
  260. STATUSF_IP1 | STATUSF_IP0;
  261. /* Default everything to IP2 */
  262. /* Start with _high registers which has no bit 0 interrupt source */
  263. for (i = 1; i < BCM1480_NR_IRQS_HALF; i++) { /* was I0 */
  264. for (cpu = 0; cpu < 4; cpu++) {
  265. __raw_writeq(IMR_IP2_VAL,
  266. IOADDR(A_BCM1480_IMR_REGISTER(cpu,
  267. R_BCM1480_IMR_INTERRUPT_MAP_BASE_H) + (i << 3)));
  268. }
  269. }
  270. /* Now do _low registers */
  271. for (i = 0; i < BCM1480_NR_IRQS_HALF; i++) {
  272. for (cpu = 0; cpu < 4; cpu++) {
  273. __raw_writeq(IMR_IP2_VAL,
  274. IOADDR(A_BCM1480_IMR_REGISTER(cpu,
  275. R_BCM1480_IMR_INTERRUPT_MAP_BASE_L) + (i << 3)));
  276. }
  277. }
  278. init_bcm1480_irqs();
  279. /*
  280. * Map the high 16 bits of mailbox_0 registers to IP[3], for
  281. * inter-cpu messages
  282. */
  283. /* Was I1 */
  284. for (cpu = 0; cpu < 4; cpu++) {
  285. __raw_writeq(IMR_IP3_VAL, IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_INTERRUPT_MAP_BASE_H) +
  286. (K_BCM1480_INT_MBOX_0_0 << 3)));
  287. }
  288. /* Clear the mailboxes. The firmware may leave them dirty */
  289. for (cpu = 0; cpu < 4; cpu++) {
  290. __raw_writeq(0xffffffffffffffffULL,
  291. IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_MAILBOX_0_CLR_CPU)));
  292. __raw_writeq(0xffffffffffffffffULL,
  293. IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_MAILBOX_1_CLR_CPU)));
  294. }
  295. /* Mask everything except the high 16 bit of mailbox_0 registers for all cpus */
  296. tmp = ~((u64) 0) ^ ( (((u64) 1) << K_BCM1480_INT_MBOX_0_0));
  297. for (cpu = 0; cpu < 4; cpu++) {
  298. __raw_writeq(tmp, IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_INTERRUPT_MASK_H)));
  299. }
  300. tmp = ~((u64) 0);
  301. for (cpu = 0; cpu < 4; cpu++) {
  302. __raw_writeq(tmp, IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_INTERRUPT_MASK_L)));
  303. }
  304. /*
  305. * Note that the timer interrupts are also mapped, but this is
  306. * done in bcm1480_time_init(). Also, the profiling driver
  307. * does its own management of IP7.
  308. */
  309. #ifdef CONFIG_KGDB
  310. imask |= STATUSF_IP6;
  311. #endif
  312. /* Enable necessary IPs, disable the rest */
  313. change_c0_status(ST0_IM, imask);
  314. #ifdef CONFIG_KGDB
  315. if (kgdb_flag) {
  316. kgdb_irq = K_BCM1480_INT_UART_0 + kgdb_port;
  317. #ifdef CONFIG_SERIAL_SB1250_DUART
  318. sb1250_duart_present[kgdb_port] = 0;
  319. #endif
  320. /* Setup uart 1 settings, mapper */
  321. /* QQQ FIXME */
  322. __raw_writeq(M_DUART_IMR_BRK, IOADDR(A_DUART_IMRREG(kgdb_port)));
  323. __raw_writeq(IMR_IP6_VAL,
  324. IOADDR(A_BCM1480_IMR_REGISTER(0, R_BCM1480_IMR_INTERRUPT_MAP_BASE_H) +
  325. (kgdb_irq << 3)));
  326. bcm1480_unmask_irq(0, kgdb_irq);
  327. #ifdef CONFIG_GDB_CONSOLE
  328. register_gdb_console();
  329. #endif
  330. printk("Waiting for GDB on UART port %d\n", kgdb_port);
  331. set_debug_traps();
  332. breakpoint();
  333. }
  334. #endif
  335. }
  336. #ifdef CONFIG_KGDB
  337. #include <linux/delay.h>
  338. #define duart_out(reg, val) csr_out32(val, IOADDR(A_DUART_CHANREG(kgdb_port, reg)))
  339. #define duart_in(reg) csr_in32(IOADDR(A_DUART_CHANREG(kgdb_port, reg)))
  340. static void bcm1480_kgdb_interrupt(void)
  341. {
  342. /*
  343. * Clear break-change status (allow some time for the remote
  344. * host to stop the break, since we would see another
  345. * interrupt on the end-of-break too)
  346. */
  347. kstat.irqs[smp_processor_id()][kgdb_irq]++;
  348. mdelay(500);
  349. duart_out(R_DUART_CMD, V_DUART_MISC_CMD_RESET_BREAK_INT |
  350. M_DUART_RX_EN | M_DUART_TX_EN);
  351. set_async_breakpoint(&get_irq_regs()->cp0_epc);
  352. }
  353. #endif /* CONFIG_KGDB */
  354. extern void bcm1480_mailbox_interrupt(void);
  355. static inline void dispatch_ip2(void)
  356. {
  357. unsigned long long mask_h, mask_l;
  358. unsigned int cpu = smp_processor_id();
  359. unsigned long base;
  360. /*
  361. * Default...we've hit an IP[2] interrupt, which means we've got to
  362. * check the 1480 interrupt registers to figure out what to do. Need
  363. * to detect which CPU we're on, now that smp_affinity is supported.
  364. */
  365. base = A_BCM1480_IMR_MAPPER(cpu);
  366. mask_h = __raw_readq(
  367. IOADDR(base + R_BCM1480_IMR_INTERRUPT_STATUS_BASE_H));
  368. mask_l = __raw_readq(
  369. IOADDR(base + R_BCM1480_IMR_INTERRUPT_STATUS_BASE_L));
  370. if (mask_h) {
  371. if (mask_h ^ 1)
  372. do_IRQ(fls64(mask_h) - 1);
  373. else if (mask_l)
  374. do_IRQ(63 + fls64(mask_l));
  375. }
  376. }
  377. asmlinkage void plat_irq_dispatch(void)
  378. {
  379. unsigned int cpu = smp_processor_id();
  380. unsigned int pending;
  381. #ifdef CONFIG_SIBYTE_BCM1480_PROF
  382. /* Set compare to count to silence count/compare timer interrupts */
  383. write_c0_compare(read_c0_count());
  384. #endif
  385. pending = read_c0_cause() & read_c0_status();
  386. #ifdef CONFIG_SIBYTE_BCM1480_PROF
  387. if (pending & CAUSEF_IP7) /* Cpu performance counter interrupt */
  388. sbprof_cpu_intr();
  389. else
  390. #endif
  391. if (pending & CAUSEF_IP4)
  392. do_IRQ(K_BCM1480_INT_TIMER_0 + cpu);
  393. #ifdef CONFIG_SMP
  394. else if (pending & CAUSEF_IP3)
  395. bcm1480_mailbox_interrupt();
  396. #endif
  397. #ifdef CONFIG_KGDB
  398. else if (pending & CAUSEF_IP6)
  399. bcm1480_kgdb_interrupt(); /* KGDB (uart 1) */
  400. #endif
  401. else if (pending & CAUSEF_IP2)
  402. dispatch_ip2();
  403. }