irq.c 11 KB

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