irq.c 15 KB

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