irq.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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. static irqreturn_t bcm1480_dummy_handler(int irq, void *dev_id)
  232. {
  233. return IRQ_NONE;
  234. }
  235. static struct irqaction bcm1480_dummy_action = {
  236. .handler = bcm1480_dummy_handler,
  237. .flags = 0,
  238. .mask = CPU_MASK_NONE,
  239. .name = "bcm1480-private",
  240. .next = NULL,
  241. .dev_id = 0
  242. };
  243. int bcm1480_steal_irq(int irq)
  244. {
  245. struct irq_desc *desc = irq_desc + irq;
  246. unsigned long flags;
  247. int retval = 0;
  248. if (irq >= BCM1480_NR_IRQS)
  249. return -EINVAL;
  250. spin_lock_irqsave(&desc->lock,flags);
  251. /* Don't allow sharing at all for these */
  252. if (desc->action != NULL)
  253. retval = -EBUSY;
  254. else {
  255. desc->action = &bcm1480_dummy_action;
  256. desc->depth = 0;
  257. }
  258. spin_unlock_irqrestore(&desc->lock,flags);
  259. return 0;
  260. }
  261. /*
  262. * init_IRQ is called early in the boot sequence from init/main.c. It
  263. * is responsible for setting up the interrupt mapper and installing the
  264. * handler that will be responsible for dispatching interrupts to the
  265. * "right" place.
  266. */
  267. /*
  268. * For now, map all interrupts to IP[2]. We could save
  269. * some cycles by parceling out system interrupts to different
  270. * IP lines, but keep it simple for bringup. We'll also direct
  271. * all interrupts to a single CPU; we should probably route
  272. * PCI and LDT to one cpu and everything else to the other
  273. * to balance the load a bit.
  274. *
  275. * On the second cpu, everything is set to IP5, which is
  276. * ignored, EXCEPT the mailbox interrupt. That one is
  277. * set to IP[2] so it is handled. This is needed so we
  278. * can do cross-cpu function calls, as requred by SMP
  279. */
  280. #define IMR_IP2_VAL K_BCM1480_INT_MAP_I0
  281. #define IMR_IP3_VAL K_BCM1480_INT_MAP_I1
  282. #define IMR_IP4_VAL K_BCM1480_INT_MAP_I2
  283. #define IMR_IP5_VAL K_BCM1480_INT_MAP_I3
  284. #define IMR_IP6_VAL K_BCM1480_INT_MAP_I4
  285. void __init arch_init_irq(void)
  286. {
  287. unsigned int i, cpu;
  288. u64 tmp;
  289. unsigned int imask = STATUSF_IP4 | STATUSF_IP3 | STATUSF_IP2 |
  290. STATUSF_IP1 | STATUSF_IP0;
  291. /* Default everything to IP2 */
  292. /* Start with _high registers which has no bit 0 interrupt source */
  293. for (i = 1; i < BCM1480_NR_IRQS_HALF; i++) { /* was I0 */
  294. for (cpu = 0; cpu < 4; cpu++) {
  295. __raw_writeq(IMR_IP2_VAL,
  296. IOADDR(A_BCM1480_IMR_REGISTER(cpu,
  297. R_BCM1480_IMR_INTERRUPT_MAP_BASE_H) + (i << 3)));
  298. }
  299. }
  300. /* Now do _low registers */
  301. for (i = 0; i < BCM1480_NR_IRQS_HALF; i++) {
  302. for (cpu = 0; cpu < 4; cpu++) {
  303. __raw_writeq(IMR_IP2_VAL,
  304. IOADDR(A_BCM1480_IMR_REGISTER(cpu,
  305. R_BCM1480_IMR_INTERRUPT_MAP_BASE_L) + (i << 3)));
  306. }
  307. }
  308. init_bcm1480_irqs();
  309. /*
  310. * Map the high 16 bits of mailbox_0 registers to IP[3], for
  311. * inter-cpu messages
  312. */
  313. /* Was I1 */
  314. for (cpu = 0; cpu < 4; cpu++) {
  315. __raw_writeq(IMR_IP3_VAL, IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_INTERRUPT_MAP_BASE_H) +
  316. (K_BCM1480_INT_MBOX_0_0 << 3)));
  317. }
  318. /* Clear the mailboxes. The firmware may leave them dirty */
  319. for (cpu = 0; cpu < 4; cpu++) {
  320. __raw_writeq(0xffffffffffffffffULL,
  321. IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_MAILBOX_0_CLR_CPU)));
  322. __raw_writeq(0xffffffffffffffffULL,
  323. IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_MAILBOX_1_CLR_CPU)));
  324. }
  325. /* Mask everything except the high 16 bit of mailbox_0 registers for all cpus */
  326. tmp = ~((u64) 0) ^ ( (((u64) 1) << K_BCM1480_INT_MBOX_0_0));
  327. for (cpu = 0; cpu < 4; cpu++) {
  328. __raw_writeq(tmp, IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_INTERRUPT_MASK_H)));
  329. }
  330. tmp = ~((u64) 0);
  331. for (cpu = 0; cpu < 4; cpu++) {
  332. __raw_writeq(tmp, IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_INTERRUPT_MASK_L)));
  333. }
  334. bcm1480_steal_irq(K_BCM1480_INT_MBOX_0_0);
  335. /*
  336. * Note that the timer interrupts are also mapped, but this is
  337. * done in bcm1480_time_init(). Also, the profiling driver
  338. * does its own management of IP7.
  339. */
  340. #ifdef CONFIG_KGDB
  341. imask |= STATUSF_IP6;
  342. #endif
  343. /* Enable necessary IPs, disable the rest */
  344. change_c0_status(ST0_IM, imask);
  345. #ifdef CONFIG_KGDB
  346. if (kgdb_flag) {
  347. kgdb_irq = K_BCM1480_INT_UART_0 + kgdb_port;
  348. #ifdef CONFIG_SERIAL_SB1250_DUART
  349. sb1250_duart_present[kgdb_port] = 0;
  350. #endif
  351. /* Setup uart 1 settings, mapper */
  352. /* QQQ FIXME */
  353. __raw_writeq(M_DUART_IMR_BRK, IO_SPACE_BASE + A_DUART_IMRREG(kgdb_port));
  354. bcm1480_steal_irq(kgdb_irq);
  355. __raw_writeq(IMR_IP6_VAL,
  356. IO_SPACE_BASE + A_BCM1480_IMR_REGISTER(0, R_BCM1480_IMR_INTERRUPT_MAP_BASE_H) +
  357. (kgdb_irq<<3));
  358. bcm1480_unmask_irq(0, kgdb_irq);
  359. #ifdef CONFIG_GDB_CONSOLE
  360. register_gdb_console();
  361. #endif
  362. printk("Waiting for GDB on UART port %d\n", kgdb_port);
  363. set_debug_traps();
  364. breakpoint();
  365. }
  366. #endif
  367. }
  368. #ifdef CONFIG_KGDB
  369. #include <linux/delay.h>
  370. #define duart_out(reg, val) csr_out32(val, IOADDR(A_DUART_CHANREG(kgdb_port,reg)))
  371. #define duart_in(reg) csr_in32(IOADDR(A_DUART_CHANREG(kgdb_port,reg)))
  372. static void bcm1480_kgdb_interrupt(void)
  373. {
  374. /*
  375. * Clear break-change status (allow some time for the remote
  376. * host to stop the break, since we would see another
  377. * interrupt on the end-of-break too)
  378. */
  379. kstat.irqs[smp_processor_id()][kgdb_irq]++;
  380. mdelay(500);
  381. duart_out(R_DUART_CMD, V_DUART_MISC_CMD_RESET_BREAK_INT |
  382. M_DUART_RX_EN | M_DUART_TX_EN);
  383. set_async_breakpoint(&get_irq_regs()->cp0_epc);
  384. }
  385. #endif /* CONFIG_KGDB */
  386. extern void bcm1480_timer_interrupt(void);
  387. extern void bcm1480_mailbox_interrupt(void);
  388. asmlinkage void plat_irq_dispatch(void)
  389. {
  390. unsigned int pending;
  391. #ifdef CONFIG_SIBYTE_BCM1480_PROF
  392. /* Set compare to count to silence count/compare timer interrupts */
  393. write_c0_compare(read_c0_count());
  394. #endif
  395. pending = read_c0_cause() & read_c0_status();
  396. #ifdef CONFIG_SIBYTE_BCM1480_PROF
  397. if (pending & CAUSEF_IP7) /* Cpu performance counter interrupt */
  398. sbprof_cpu_intr();
  399. else
  400. #endif
  401. if (pending & CAUSEF_IP4)
  402. bcm1480_timer_interrupt();
  403. #ifdef CONFIG_SMP
  404. else if (pending & CAUSEF_IP3)
  405. bcm1480_mailbox_interrupt();
  406. #endif
  407. #ifdef CONFIG_KGDB
  408. else if (pending & CAUSEF_IP6)
  409. bcm1480_kgdb_interrupt(); /* KGDB (uart 1) */
  410. #endif
  411. else if (pending & CAUSEF_IP2) {
  412. unsigned long long mask_h, mask_l;
  413. unsigned long base;
  414. /*
  415. * Default...we've hit an IP[2] interrupt, which means we've
  416. * got to check the 1480 interrupt registers to figure out what
  417. * to do. Need to detect which CPU we're on, now that
  418. * smp_affinity is supported.
  419. */
  420. base = A_BCM1480_IMR_MAPPER(smp_processor_id());
  421. mask_h = __raw_readq(
  422. IOADDR(base + R_BCM1480_IMR_INTERRUPT_STATUS_BASE_H));
  423. mask_l = __raw_readq(
  424. IOADDR(base + R_BCM1480_IMR_INTERRUPT_STATUS_BASE_L));
  425. if (mask_h) {
  426. if (mask_h ^ 1)
  427. do_IRQ(fls64(mask_h) - 1);
  428. else
  429. do_IRQ(63 + fls64(mask_l));
  430. }
  431. }
  432. }