irq.c 13 KB

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