irq.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  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. "SB1250-IMR",
  66. startup_sb1250_irq,
  67. shutdown_sb1250_irq,
  68. enable_sb1250_irq,
  69. disable_sb1250_irq,
  70. ack_sb1250_irq,
  71. end_sb1250_irq,
  72. #ifdef CONFIG_SMP
  73. sb1250_set_affinity
  74. #else
  75. NULL
  76. #endif
  77. };
  78. /* Store the CPU id (not the logical number) */
  79. int sb1250_irq_owner[SB1250_NR_IRQS];
  80. DEFINE_SPINLOCK(sb1250_imr_lock);
  81. void sb1250_mask_irq(int cpu, int irq)
  82. {
  83. unsigned long flags;
  84. u64 cur_ints;
  85. spin_lock_irqsave(&sb1250_imr_lock, flags);
  86. cur_ints = __bus_readq(IOADDR(A_IMR_MAPPER(cpu) +
  87. R_IMR_INTERRUPT_MASK));
  88. cur_ints |= (((u64) 1) << irq);
  89. __bus_writeq(cur_ints, IOADDR(A_IMR_MAPPER(cpu) +
  90. R_IMR_INTERRUPT_MASK));
  91. spin_unlock_irqrestore(&sb1250_imr_lock, flags);
  92. }
  93. void sb1250_unmask_irq(int cpu, int irq)
  94. {
  95. unsigned long flags;
  96. u64 cur_ints;
  97. spin_lock_irqsave(&sb1250_imr_lock, flags);
  98. cur_ints = __bus_readq(IOADDR(A_IMR_MAPPER(cpu) +
  99. R_IMR_INTERRUPT_MASK));
  100. cur_ints &= ~(((u64) 1) << irq);
  101. __bus_writeq(cur_ints, IOADDR(A_IMR_MAPPER(cpu) +
  102. R_IMR_INTERRUPT_MASK));
  103. spin_unlock_irqrestore(&sb1250_imr_lock, flags);
  104. }
  105. #ifdef CONFIG_SMP
  106. static void sb1250_set_affinity(unsigned int irq, unsigned long mask)
  107. {
  108. int i = 0, old_cpu, cpu, int_on;
  109. u64 cur_ints;
  110. irq_desc_t *desc = irq_desc + irq;
  111. unsigned long flags;
  112. while (mask) {
  113. if (mask & 1) {
  114. mask >>= 1;
  115. break;
  116. }
  117. mask >>= 1;
  118. i++;
  119. }
  120. if (mask) {
  121. printk("attempted to set irq affinity for irq %d to multiple CPUs\n", irq);
  122. return;
  123. }
  124. /* Convert logical CPU to physical CPU */
  125. cpu = cpu_logical_map(i);
  126. /* Protect against other affinity changers and IMR manipulation */
  127. spin_lock_irqsave(&desc->lock, flags);
  128. spin_lock(&sb1250_imr_lock);
  129. /* Swizzle each CPU's IMR (but leave the IP selection alone) */
  130. old_cpu = sb1250_irq_owner[irq];
  131. cur_ints = __bus_readq(IOADDR(A_IMR_MAPPER(old_cpu) +
  132. R_IMR_INTERRUPT_MASK));
  133. int_on = !(cur_ints & (((u64) 1) << irq));
  134. if (int_on) {
  135. /* If it was on, mask it */
  136. cur_ints |= (((u64) 1) << irq);
  137. __bus_writeq(cur_ints, IOADDR(A_IMR_MAPPER(old_cpu) +
  138. R_IMR_INTERRUPT_MASK));
  139. }
  140. sb1250_irq_owner[irq] = cpu;
  141. if (int_on) {
  142. /* unmask for the new CPU */
  143. cur_ints = __bus_readq(IOADDR(A_IMR_MAPPER(cpu) +
  144. R_IMR_INTERRUPT_MASK));
  145. cur_ints &= ~(((u64) 1) << irq);
  146. __bus_writeq(cur_ints, IOADDR(A_IMR_MAPPER(cpu) +
  147. R_IMR_INTERRUPT_MASK));
  148. }
  149. spin_unlock(&sb1250_imr_lock);
  150. spin_unlock_irqrestore(&desc->lock, flags);
  151. }
  152. #endif
  153. /* Defined in arch/mips/sibyte/sb1250/irq_handler.S */
  154. extern void sb1250_irq_handler(void);
  155. /*****************************************************************************/
  156. static unsigned int startup_sb1250_irq(unsigned int irq)
  157. {
  158. sb1250_unmask_irq(sb1250_irq_owner[irq], irq);
  159. return 0; /* never anything pending */
  160. }
  161. static void disable_sb1250_irq(unsigned int irq)
  162. {
  163. sb1250_mask_irq(sb1250_irq_owner[irq], irq);
  164. }
  165. static void enable_sb1250_irq(unsigned int irq)
  166. {
  167. sb1250_unmask_irq(sb1250_irq_owner[irq], irq);
  168. }
  169. static void ack_sb1250_irq(unsigned int irq)
  170. {
  171. #ifdef CONFIG_SIBYTE_HAS_LDT
  172. u64 pending;
  173. /*
  174. * If the interrupt was an HT interrupt, now is the time to
  175. * clear it. NOTE: we assume the HT bridge was set up to
  176. * deliver the interrupts to all CPUs (which makes affinity
  177. * changing easier for us)
  178. */
  179. pending = bus_readq(IOADDR(A_IMR_REGISTER(sb1250_irq_owner[irq],
  180. R_IMR_LDT_INTERRUPT)));
  181. pending &= ((u64)1 << (irq));
  182. if (pending) {
  183. int i;
  184. for (i=0; i<NR_CPUS; i++) {
  185. int cpu;
  186. #ifdef CONFIG_SMP
  187. cpu = cpu_logical_map(i);
  188. #else
  189. cpu = i;
  190. #endif
  191. /*
  192. * Clear for all CPUs so an affinity switch
  193. * doesn't find an old status
  194. */
  195. bus_writeq(pending,
  196. IOADDR(A_IMR_REGISTER(cpu,
  197. R_IMR_LDT_INTERRUPT_CLR)));
  198. }
  199. /*
  200. * Generate EOI. For Pass 1 parts, EOI is a nop. For
  201. * Pass 2, the LDT world may be edge-triggered, but
  202. * this EOI shouldn't hurt. If they are
  203. * level-sensitive, the EOI is required.
  204. */
  205. *(uint32_t *)(ldt_eoi_space+(irq<<16)+(7<<2)) = 0;
  206. }
  207. #endif
  208. sb1250_mask_irq(sb1250_irq_owner[irq], irq);
  209. }
  210. static void end_sb1250_irq(unsigned int irq)
  211. {
  212. if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
  213. sb1250_unmask_irq(sb1250_irq_owner[irq], irq);
  214. }
  215. }
  216. void __init init_sb1250_irqs(void)
  217. {
  218. int i;
  219. for (i = 0; i < NR_IRQS; i++) {
  220. irq_desc[i].status = IRQ_DISABLED;
  221. irq_desc[i].action = 0;
  222. irq_desc[i].depth = 1;
  223. if (i < SB1250_NR_IRQS) {
  224. irq_desc[i].handler = &sb1250_irq_type;
  225. sb1250_irq_owner[i] = 0;
  226. } else {
  227. irq_desc[i].handler = &no_irq_type;
  228. }
  229. }
  230. }
  231. static irqreturn_t sb1250_dummy_handler(int irq, void *dev_id,
  232. struct pt_regs *regs)
  233. {
  234. return IRQ_NONE;
  235. }
  236. static struct irqaction sb1250_dummy_action = {
  237. .handler = sb1250_dummy_handler,
  238. .flags = 0,
  239. .mask = CPU_MASK_NONE,
  240. .name = "sb1250-private",
  241. .next = NULL,
  242. .dev_id = 0
  243. };
  244. int sb1250_steal_irq(int irq)
  245. {
  246. irq_desc_t *desc = irq_desc + irq;
  247. unsigned long flags;
  248. int retval = 0;
  249. if (irq >= SB1250_NR_IRQS)
  250. return -EINVAL;
  251. spin_lock_irqsave(&desc->lock,flags);
  252. /* Don't allow sharing at all for these */
  253. if (desc->action != NULL)
  254. retval = -EBUSY;
  255. else {
  256. desc->action = &sb1250_dummy_action;
  257. desc->depth = 0;
  258. }
  259. spin_unlock_irqrestore(&desc->lock,flags);
  260. return 0;
  261. }
  262. /*
  263. * arch_init_irq is called early in the boot sequence from init/main.c via
  264. * init_IRQ. It is responsible for setting up the interrupt mapper and
  265. * installing the handler that will be responsible for dispatching interrupts
  266. * to the "right" place.
  267. */
  268. /*
  269. * For now, map all interrupts to IP[2]. We could save
  270. * some cycles by parceling out system interrupts to different
  271. * IP lines, but keep it simple for bringup. We'll also direct
  272. * all interrupts to a single CPU; we should probably route
  273. * PCI and LDT to one cpu and everything else to the other
  274. * to balance the load a bit.
  275. *
  276. * On the second cpu, everything is set to IP5, which is
  277. * ignored, EXCEPT the mailbox interrupt. That one is
  278. * set to IP[2] so it is handled. This is needed so we
  279. * can do cross-cpu function calls, as requred by SMP
  280. */
  281. #define IMR_IP2_VAL K_INT_MAP_I0
  282. #define IMR_IP3_VAL K_INT_MAP_I1
  283. #define IMR_IP4_VAL K_INT_MAP_I2
  284. #define IMR_IP5_VAL K_INT_MAP_I3
  285. #define IMR_IP6_VAL K_INT_MAP_I4
  286. void __init arch_init_irq(void)
  287. {
  288. unsigned int i;
  289. u64 tmp;
  290. unsigned int imask = STATUSF_IP4 | STATUSF_IP3 | STATUSF_IP2 |
  291. STATUSF_IP1 | STATUSF_IP0;
  292. /* Default everything to IP2 */
  293. for (i = 0; i < SB1250_NR_IRQS; i++) { /* was I0 */
  294. bus_writeq(IMR_IP2_VAL,
  295. IOADDR(A_IMR_REGISTER(0, R_IMR_INTERRUPT_MAP_BASE) +
  296. (i << 3)));
  297. bus_writeq(IMR_IP2_VAL,
  298. IOADDR(A_IMR_REGISTER(1, 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. bus_writeq(IMR_IP3_VAL,
  308. IOADDR(A_IMR_REGISTER(0, R_IMR_INTERRUPT_MAP_BASE) +
  309. (K_INT_MBOX_0 << 3)));
  310. bus_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. bus_writeq(0xffffffffffffffffULL,
  315. IOADDR(A_IMR_REGISTER(0, R_IMR_MAILBOX_CLR_CPU)));
  316. bus_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. bus_writeq(tmp, IOADDR(A_IMR_REGISTER(0, R_IMR_INTERRUPT_MASK)));
  321. bus_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. bus_writeq(M_DUART_IMR_BRK, IOADDR(A_DUART_IMRREG(kgdb_port)));
  342. sb1250_steal_irq(kgdb_irq);
  343. bus_writeq(IMR_IP6_VAL,
  344. IOADDR(A_IMR_REGISTER(0, R_IMR_INTERRUPT_MAP_BASE) +
  345. (kgdb_irq<<3)));
  346. sb1250_unmask_irq(0, kgdb_irq);
  347. }
  348. #endif
  349. }
  350. #ifdef CONFIG_KGDB
  351. #include <linux/delay.h>
  352. #define duart_out(reg, val) csr_out32(val, IOADDR(A_DUART_CHANREG(kgdb_port,reg)))
  353. #define duart_in(reg) csr_in32(IOADDR(A_DUART_CHANREG(kgdb_port,reg)))
  354. void sb1250_kgdb_interrupt(struct pt_regs *regs)
  355. {
  356. /*
  357. * Clear break-change status (allow some time for the remote
  358. * host to stop the break, since we would see another
  359. * interrupt on the end-of-break too)
  360. */
  361. kstat_this_cpu.irqs[kgdb_irq]++;
  362. mdelay(500);
  363. duart_out(R_DUART_CMD, V_DUART_MISC_CMD_RESET_BREAK_INT |
  364. M_DUART_RX_EN | M_DUART_TX_EN);
  365. set_async_breakpoint(&regs->cp0_epc);
  366. }
  367. #endif /* CONFIG_KGDB */