irq.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. /*
  2. * Copyright (C) 2000, 2001, 2002, 2003 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/smp.h>
  25. #include <linux/mm.h>
  26. #include <linux/slab.h>
  27. #include <linux/kernel_stat.h>
  28. #include <asm/errno.h>
  29. #include <asm/signal.h>
  30. #include <asm/system.h>
  31. #include <asm/ptrace.h>
  32. #include <asm/io.h>
  33. #include <asm/sibyte/sb1250_regs.h>
  34. #include <asm/sibyte/sb1250_int.h>
  35. #include <asm/sibyte/sb1250_uart.h>
  36. #include <asm/sibyte/sb1250_scd.h>
  37. #include <asm/sibyte/sb1250.h>
  38. /*
  39. * These are the routines that handle all the low level interrupt stuff.
  40. * Actions handled here are: initialization of the interrupt map, requesting of
  41. * interrupt lines by handlers, dispatching if interrupts to handlers, probing
  42. * for interrupt lines
  43. */
  44. #define shutdown_sb1250_irq disable_sb1250_irq
  45. static void end_sb1250_irq(unsigned int irq);
  46. static void enable_sb1250_irq(unsigned int irq);
  47. static void disable_sb1250_irq(unsigned int irq);
  48. static unsigned int startup_sb1250_irq(unsigned int irq);
  49. static void ack_sb1250_irq(unsigned int irq);
  50. #ifdef CONFIG_SMP
  51. static void sb1250_set_affinity(unsigned int irq, unsigned long mask);
  52. #endif
  53. #ifdef CONFIG_SIBYTE_HAS_LDT
  54. extern unsigned long ldt_eoi_space;
  55. #endif
  56. #ifdef CONFIG_KGDB
  57. static int kgdb_irq;
  58. /* Default to UART1 */
  59. int kgdb_port = 1;
  60. #ifdef CONFIG_SIBYTE_SB1250_DUART
  61. extern char sb1250_duart_present[];
  62. #endif
  63. #endif
  64. static struct hw_interrupt_type sb1250_irq_type = {
  65. .typename = "SB1250-IMR",
  66. .startup = startup_sb1250_irq,
  67. .shutdown = shutdown_sb1250_irq,
  68. .enable = enable_sb1250_irq,
  69. .disable = disable_sb1250_irq,
  70. .ack = ack_sb1250_irq,
  71. .end = end_sb1250_irq,
  72. #ifdef CONFIG_SMP
  73. .set_affinity = sb1250_set_affinity
  74. #endif
  75. };
  76. /* Store the CPU id (not the logical number) */
  77. int sb1250_irq_owner[SB1250_NR_IRQS];
  78. DEFINE_SPINLOCK(sb1250_imr_lock);
  79. void sb1250_mask_irq(int cpu, int irq)
  80. {
  81. unsigned long flags;
  82. u64 cur_ints;
  83. spin_lock_irqsave(&sb1250_imr_lock, flags);
  84. cur_ints = ____raw_readq(IOADDR(A_IMR_MAPPER(cpu) +
  85. R_IMR_INTERRUPT_MASK));
  86. cur_ints |= (((u64) 1) << irq);
  87. ____raw_writeq(cur_ints, IOADDR(A_IMR_MAPPER(cpu) +
  88. R_IMR_INTERRUPT_MASK));
  89. spin_unlock_irqrestore(&sb1250_imr_lock, flags);
  90. }
  91. void sb1250_unmask_irq(int cpu, int irq)
  92. {
  93. unsigned long flags;
  94. u64 cur_ints;
  95. spin_lock_irqsave(&sb1250_imr_lock, flags);
  96. cur_ints = ____raw_readq(IOADDR(A_IMR_MAPPER(cpu) +
  97. R_IMR_INTERRUPT_MASK));
  98. cur_ints &= ~(((u64) 1) << irq);
  99. ____raw_writeq(cur_ints, IOADDR(A_IMR_MAPPER(cpu) +
  100. R_IMR_INTERRUPT_MASK));
  101. spin_unlock_irqrestore(&sb1250_imr_lock, flags);
  102. }
  103. #ifdef CONFIG_SMP
  104. static void sb1250_set_affinity(unsigned int irq, unsigned long mask)
  105. {
  106. int i = 0, old_cpu, cpu, int_on;
  107. u64 cur_ints;
  108. irq_desc_t *desc = irq_desc + irq;
  109. unsigned long flags;
  110. while (mask) {
  111. if (mask & 1) {
  112. mask >>= 1;
  113. break;
  114. }
  115. mask >>= 1;
  116. i++;
  117. }
  118. if (mask) {
  119. printk("attempted to set irq affinity for irq %d to multiple CPUs\n", irq);
  120. return;
  121. }
  122. /* Convert logical CPU to physical CPU */
  123. cpu = cpu_logical_map(i);
  124. /* Protect against other affinity changers and IMR manipulation */
  125. spin_lock_irqsave(&desc->lock, flags);
  126. spin_lock(&sb1250_imr_lock);
  127. /* Swizzle each CPU's IMR (but leave the IP selection alone) */
  128. old_cpu = sb1250_irq_owner[irq];
  129. cur_ints = ____raw_readq(IOADDR(A_IMR_MAPPER(old_cpu) +
  130. R_IMR_INTERRUPT_MASK));
  131. int_on = !(cur_ints & (((u64) 1) << irq));
  132. if (int_on) {
  133. /* If it was on, mask it */
  134. cur_ints |= (((u64) 1) << irq);
  135. ____raw_writeq(cur_ints, IOADDR(A_IMR_MAPPER(old_cpu) +
  136. R_IMR_INTERRUPT_MASK));
  137. }
  138. sb1250_irq_owner[irq] = cpu;
  139. if (int_on) {
  140. /* unmask for the new CPU */
  141. cur_ints = ____raw_readq(IOADDR(A_IMR_MAPPER(cpu) +
  142. R_IMR_INTERRUPT_MASK));
  143. cur_ints &= ~(((u64) 1) << irq);
  144. ____raw_writeq(cur_ints, IOADDR(A_IMR_MAPPER(cpu) +
  145. R_IMR_INTERRUPT_MASK));
  146. }
  147. spin_unlock(&sb1250_imr_lock);
  148. spin_unlock_irqrestore(&desc->lock, flags);
  149. }
  150. #endif
  151. /* Defined in arch/mips/sibyte/sb1250/irq_handler.S */
  152. extern void sb1250_irq_handler(void);
  153. /*****************************************************************************/
  154. static unsigned int startup_sb1250_irq(unsigned int irq)
  155. {
  156. sb1250_unmask_irq(sb1250_irq_owner[irq], irq);
  157. return 0; /* never anything pending */
  158. }
  159. static void disable_sb1250_irq(unsigned int irq)
  160. {
  161. sb1250_mask_irq(sb1250_irq_owner[irq], irq);
  162. }
  163. static void enable_sb1250_irq(unsigned int irq)
  164. {
  165. sb1250_unmask_irq(sb1250_irq_owner[irq], irq);
  166. }
  167. static void ack_sb1250_irq(unsigned int irq)
  168. {
  169. #ifdef CONFIG_SIBYTE_HAS_LDT
  170. u64 pending;
  171. /*
  172. * If the interrupt was an HT interrupt, now is the time to
  173. * clear it. NOTE: we assume the HT bridge was set up to
  174. * deliver the interrupts to all CPUs (which makes affinity
  175. * changing easier for us)
  176. */
  177. pending = __raw_readq(IOADDR(A_IMR_REGISTER(sb1250_irq_owner[irq],
  178. R_IMR_LDT_INTERRUPT)));
  179. pending &= ((u64)1 << (irq));
  180. if (pending) {
  181. int i;
  182. for (i=0; i<NR_CPUS; i++) {
  183. int cpu;
  184. #ifdef CONFIG_SMP
  185. cpu = cpu_logical_map(i);
  186. #else
  187. cpu = i;
  188. #endif
  189. /*
  190. * Clear for all CPUs so an affinity switch
  191. * doesn't find an old status
  192. */
  193. __raw_writeq(pending,
  194. IOADDR(A_IMR_REGISTER(cpu,
  195. R_IMR_LDT_INTERRUPT_CLR)));
  196. }
  197. /*
  198. * Generate EOI. For Pass 1 parts, EOI is a nop. For
  199. * Pass 2, the LDT world may be edge-triggered, but
  200. * this EOI shouldn't hurt. If they are
  201. * level-sensitive, the EOI is required.
  202. */
  203. *(uint32_t *)(ldt_eoi_space+(irq<<16)+(7<<2)) = 0;
  204. }
  205. #endif
  206. sb1250_mask_irq(sb1250_irq_owner[irq], irq);
  207. }
  208. static void end_sb1250_irq(unsigned int irq)
  209. {
  210. if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
  211. sb1250_unmask_irq(sb1250_irq_owner[irq], irq);
  212. }
  213. }
  214. void __init init_sb1250_irqs(void)
  215. {
  216. int i;
  217. for (i = 0; i < NR_IRQS; i++) {
  218. irq_desc[i].status = IRQ_DISABLED;
  219. irq_desc[i].action = 0;
  220. irq_desc[i].depth = 1;
  221. if (i < SB1250_NR_IRQS) {
  222. irq_desc[i].handler = &sb1250_irq_type;
  223. sb1250_irq_owner[i] = 0;
  224. } else {
  225. irq_desc[i].handler = &no_irq_type;
  226. }
  227. }
  228. }
  229. static irqreturn_t sb1250_dummy_handler(int irq, void *dev_id,
  230. struct pt_regs *regs)
  231. {
  232. return IRQ_NONE;
  233. }
  234. static struct irqaction sb1250_dummy_action = {
  235. .handler = sb1250_dummy_handler,
  236. .flags = 0,
  237. .mask = CPU_MASK_NONE,
  238. .name = "sb1250-private",
  239. .next = NULL,
  240. .dev_id = 0
  241. };
  242. int sb1250_steal_irq(int irq)
  243. {
  244. irq_desc_t *desc = irq_desc + irq;
  245. unsigned long flags;
  246. int retval = 0;
  247. if (irq >= SB1250_NR_IRQS)
  248. return -EINVAL;
  249. spin_lock_irqsave(&desc->lock,flags);
  250. /* Don't allow sharing at all for these */
  251. if (desc->action != NULL)
  252. retval = -EBUSY;
  253. else {
  254. desc->action = &sb1250_dummy_action;
  255. desc->depth = 0;
  256. }
  257. spin_unlock_irqrestore(&desc->lock,flags);
  258. return 0;
  259. }
  260. /*
  261. * arch_init_irq is called early in the boot sequence from init/main.c via
  262. * init_IRQ. It is responsible for setting up the interrupt mapper and
  263. * installing the handler that will be responsible for dispatching interrupts
  264. * to the "right" place.
  265. */
  266. /*
  267. * For now, map all interrupts to IP[2]. We could save
  268. * some cycles by parceling out system interrupts to different
  269. * IP lines, but keep it simple for bringup. We'll also direct
  270. * all interrupts to a single CPU; we should probably route
  271. * PCI and LDT to one cpu and everything else to the other
  272. * to balance the load a bit.
  273. *
  274. * On the second cpu, everything is set to IP5, which is
  275. * ignored, EXCEPT the mailbox interrupt. That one is
  276. * set to IP[2] so it is handled. This is needed so we
  277. * can do cross-cpu function calls, as requred by SMP
  278. */
  279. #define IMR_IP2_VAL K_INT_MAP_I0
  280. #define IMR_IP3_VAL K_INT_MAP_I1
  281. #define IMR_IP4_VAL K_INT_MAP_I2
  282. #define IMR_IP5_VAL K_INT_MAP_I3
  283. #define IMR_IP6_VAL K_INT_MAP_I4
  284. void __init arch_init_irq(void)
  285. {
  286. unsigned int i;
  287. u64 tmp;
  288. unsigned int imask = STATUSF_IP4 | STATUSF_IP3 | STATUSF_IP2 |
  289. STATUSF_IP1 | STATUSF_IP0;
  290. /* Default everything to IP2 */
  291. for (i = 0; i < SB1250_NR_IRQS; i++) { /* was I0 */
  292. __raw_writeq(IMR_IP2_VAL,
  293. IOADDR(A_IMR_REGISTER(0,
  294. R_IMR_INTERRUPT_MAP_BASE) +
  295. (i << 3)));
  296. __raw_writeq(IMR_IP2_VAL,
  297. IOADDR(A_IMR_REGISTER(1,
  298. R_IMR_INTERRUPT_MAP_BASE) +
  299. (i << 3)));
  300. }
  301. init_sb1250_irqs();
  302. /*
  303. * Map the high 16 bits of the mailbox registers to IP[3], for
  304. * inter-cpu messages
  305. */
  306. /* Was I1 */
  307. __raw_writeq(IMR_IP3_VAL,
  308. IOADDR(A_IMR_REGISTER(0, R_IMR_INTERRUPT_MAP_BASE) +
  309. (K_INT_MBOX_0 << 3)));
  310. __raw_writeq(IMR_IP3_VAL,
  311. IOADDR(A_IMR_REGISTER(1, R_IMR_INTERRUPT_MAP_BASE) +
  312. (K_INT_MBOX_0 << 3)));
  313. /* Clear the mailboxes. The firmware may leave them dirty */
  314. __raw_writeq(0xffffffffffffffffULL,
  315. IOADDR(A_IMR_REGISTER(0, R_IMR_MAILBOX_CLR_CPU)));
  316. __raw_writeq(0xffffffffffffffffULL,
  317. IOADDR(A_IMR_REGISTER(1, R_IMR_MAILBOX_CLR_CPU)));
  318. /* Mask everything except the mailbox registers for both cpus */
  319. tmp = ~((u64) 0) ^ (((u64) 1) << K_INT_MBOX_0);
  320. __raw_writeq(tmp, IOADDR(A_IMR_REGISTER(0, R_IMR_INTERRUPT_MASK)));
  321. __raw_writeq(tmp, IOADDR(A_IMR_REGISTER(1, R_IMR_INTERRUPT_MASK)));
  322. sb1250_steal_irq(K_INT_MBOX_0);
  323. /*
  324. * Note that the timer interrupts are also mapped, but this is
  325. * done in sb1250_time_init(). Also, the profiling driver
  326. * does its own management of IP7.
  327. */
  328. #ifdef CONFIG_KGDB
  329. imask |= STATUSF_IP6;
  330. #endif
  331. /* Enable necessary IPs, disable the rest */
  332. change_c0_status(ST0_IM, imask);
  333. set_except_vector(0, sb1250_irq_handler);
  334. #ifdef CONFIG_KGDB
  335. if (kgdb_flag) {
  336. kgdb_irq = K_INT_UART_0 + kgdb_port;
  337. #ifdef CONFIG_SIBYTE_SB1250_DUART
  338. sb1250_duart_present[kgdb_port] = 0;
  339. #endif
  340. /* Setup uart 1 settings, mapper */
  341. __raw_writeq(M_DUART_IMR_BRK,
  342. IOADDR(A_DUART_IMRREG(kgdb_port)));
  343. sb1250_steal_irq(kgdb_irq);
  344. __raw_writeq(IMR_IP6_VAL,
  345. IOADDR(A_IMR_REGISTER(0,
  346. R_IMR_INTERRUPT_MAP_BASE) +
  347. (kgdb_irq << 3)));
  348. sb1250_unmask_irq(0, kgdb_irq);
  349. }
  350. #endif
  351. }
  352. #ifdef CONFIG_KGDB
  353. #include <linux/delay.h>
  354. #define duart_out(reg, val) csr_out32(val, IOADDR(A_DUART_CHANREG(kgdb_port,reg)))
  355. #define duart_in(reg) csr_in32(IOADDR(A_DUART_CHANREG(kgdb_port,reg)))
  356. void sb1250_kgdb_interrupt(struct pt_regs *regs)
  357. {
  358. /*
  359. * Clear break-change status (allow some time for the remote
  360. * host to stop the break, since we would see another
  361. * interrupt on the end-of-break too)
  362. */
  363. kstat_this_cpu.irqs[kgdb_irq]++;
  364. mdelay(500);
  365. duart_out(R_DUART_CMD, V_DUART_MISC_CMD_RESET_BREAK_INT |
  366. M_DUART_RX_EN | M_DUART_TX_EN);
  367. set_async_breakpoint(&regs->cp0_epc);
  368. }
  369. #endif /* CONFIG_KGDB */