irq.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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/smp.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/irq_regs.h>
  29. #include <asm/signal.h>
  30. #include <asm/system.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. 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 void ack_bcm1480_irq(unsigned int irq);
  47. #ifdef CONFIG_SMP
  48. static int bcm1480_set_affinity(unsigned int irq, const struct cpumask *mask);
  49. #endif
  50. #ifdef CONFIG_PCI
  51. extern unsigned long ht_eoi_space;
  52. #endif
  53. static struct irq_chip bcm1480_irq_type = {
  54. .name = "BCM1480-IMR",
  55. .ack = ack_bcm1480_irq,
  56. .mask = disable_bcm1480_irq,
  57. .mask_ack = ack_bcm1480_irq,
  58. .unmask = enable_bcm1480_irq,
  59. .end = end_bcm1480_irq,
  60. #ifdef CONFIG_SMP
  61. .set_affinity = bcm1480_set_affinity
  62. #endif
  63. };
  64. /* Store the CPU id (not the logical number) */
  65. int bcm1480_irq_owner[BCM1480_NR_IRQS];
  66. DEFINE_SPINLOCK(bcm1480_imr_lock);
  67. void bcm1480_mask_irq(int cpu, int irq)
  68. {
  69. unsigned long flags, hl_spacing;
  70. u64 cur_ints;
  71. spin_lock_irqsave(&bcm1480_imr_lock, flags);
  72. hl_spacing = 0;
  73. if ((irq >= BCM1480_NR_IRQS_HALF) && (irq <= BCM1480_NR_IRQS)) {
  74. hl_spacing = BCM1480_IMR_HL_SPACING;
  75. irq -= BCM1480_NR_IRQS_HALF;
  76. }
  77. cur_ints = ____raw_readq(IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + hl_spacing));
  78. cur_ints |= (((u64) 1) << irq);
  79. ____raw_writeq(cur_ints, IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + hl_spacing));
  80. spin_unlock_irqrestore(&bcm1480_imr_lock, flags);
  81. }
  82. void bcm1480_unmask_irq(int cpu, int irq)
  83. {
  84. unsigned long flags, hl_spacing;
  85. u64 cur_ints;
  86. spin_lock_irqsave(&bcm1480_imr_lock, flags);
  87. hl_spacing = 0;
  88. if ((irq >= BCM1480_NR_IRQS_HALF) && (irq <= BCM1480_NR_IRQS)) {
  89. hl_spacing = BCM1480_IMR_HL_SPACING;
  90. irq -= BCM1480_NR_IRQS_HALF;
  91. }
  92. cur_ints = ____raw_readq(IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + hl_spacing));
  93. cur_ints &= ~(((u64) 1) << irq);
  94. ____raw_writeq(cur_ints, IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + hl_spacing));
  95. spin_unlock_irqrestore(&bcm1480_imr_lock, flags);
  96. }
  97. #ifdef CONFIG_SMP
  98. static int bcm1480_set_affinity(unsigned int irq, const struct cpumask *mask)
  99. {
  100. int i = 0, old_cpu, cpu, int_on, k;
  101. u64 cur_ints;
  102. unsigned long flags;
  103. unsigned int irq_dirty;
  104. if (cpumask_weight(mask) != 1) {
  105. printk("attempted to set irq affinity for irq %d to multiple CPUs\n", irq);
  106. return -1;
  107. }
  108. i = cpumask_first(mask);
  109. /* Convert logical CPU to physical CPU */
  110. cpu = cpu_logical_map(i);
  111. /* Protect against other affinity changers and IMR manipulation */
  112. spin_lock_irqsave(&bcm1480_imr_lock, flags);
  113. /* Swizzle each CPU's IMR (but leave the IP selection alone) */
  114. old_cpu = bcm1480_irq_owner[irq];
  115. irq_dirty = irq;
  116. if ((irq_dirty >= BCM1480_NR_IRQS_HALF) && (irq_dirty <= BCM1480_NR_IRQS)) {
  117. irq_dirty -= BCM1480_NR_IRQS_HALF;
  118. }
  119. for (k=0; k<2; k++) { /* Loop through high and low interrupt mask register */
  120. cur_ints = ____raw_readq(IOADDR(A_BCM1480_IMR_MAPPER(old_cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + (k*BCM1480_IMR_HL_SPACING)));
  121. int_on = !(cur_ints & (((u64) 1) << irq_dirty));
  122. if (int_on) {
  123. /* If it was on, mask it */
  124. cur_ints |= (((u64) 1) << irq_dirty);
  125. ____raw_writeq(cur_ints, IOADDR(A_BCM1480_IMR_MAPPER(old_cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + (k*BCM1480_IMR_HL_SPACING)));
  126. }
  127. bcm1480_irq_owner[irq] = cpu;
  128. if (int_on) {
  129. /* unmask for the new CPU */
  130. cur_ints = ____raw_readq(IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + (k*BCM1480_IMR_HL_SPACING)));
  131. cur_ints &= ~(((u64) 1) << irq_dirty);
  132. ____raw_writeq(cur_ints, IOADDR(A_BCM1480_IMR_MAPPER(cpu) + R_BCM1480_IMR_INTERRUPT_MASK_H + (k*BCM1480_IMR_HL_SPACING)));
  133. }
  134. }
  135. spin_unlock_irqrestore(&bcm1480_imr_lock, flags);
  136. return 0;
  137. }
  138. #endif
  139. /*****************************************************************************/
  140. static void disable_bcm1480_irq(unsigned int irq)
  141. {
  142. bcm1480_mask_irq(bcm1480_irq_owner[irq], irq);
  143. }
  144. static void enable_bcm1480_irq(unsigned int irq)
  145. {
  146. bcm1480_unmask_irq(bcm1480_irq_owner[irq], irq);
  147. }
  148. static void ack_bcm1480_irq(unsigned int irq)
  149. {
  150. u64 pending;
  151. unsigned int irq_dirty;
  152. int k;
  153. /*
  154. * If the interrupt was an HT interrupt, now is the time to
  155. * clear it. NOTE: we assume the HT bridge was set up to
  156. * deliver the interrupts to all CPUs (which makes affinity
  157. * changing easier for us)
  158. */
  159. irq_dirty = irq;
  160. if ((irq_dirty >= BCM1480_NR_IRQS_HALF) && (irq_dirty <= BCM1480_NR_IRQS)) {
  161. irq_dirty -= BCM1480_NR_IRQS_HALF;
  162. }
  163. for (k=0; k<2; k++) { /* Loop through high and low LDT interrupts */
  164. pending = __raw_readq(IOADDR(A_BCM1480_IMR_REGISTER(bcm1480_irq_owner[irq],
  165. R_BCM1480_IMR_LDT_INTERRUPT_H + (k*BCM1480_IMR_HL_SPACING))));
  166. pending &= ((u64)1 << (irq_dirty));
  167. if (pending) {
  168. #ifdef CONFIG_SMP
  169. int i;
  170. for (i=0; i<NR_CPUS; i++) {
  171. /*
  172. * Clear for all CPUs so an affinity switch
  173. * doesn't find an old status
  174. */
  175. __raw_writeq(pending, IOADDR(A_BCM1480_IMR_REGISTER(cpu_logical_map(i),
  176. R_BCM1480_IMR_LDT_INTERRUPT_CLR_H + (k*BCM1480_IMR_HL_SPACING))));
  177. }
  178. #else
  179. __raw_writeq(pending, IOADDR(A_BCM1480_IMR_REGISTER(0, R_BCM1480_IMR_LDT_INTERRUPT_CLR_H + (k*BCM1480_IMR_HL_SPACING))));
  180. #endif
  181. /*
  182. * Generate EOI. For Pass 1 parts, EOI is a nop. For
  183. * Pass 2, the LDT world may be edge-triggered, but
  184. * this EOI shouldn't hurt. If they are
  185. * level-sensitive, the EOI is required.
  186. */
  187. #ifdef CONFIG_PCI
  188. if (ht_eoi_space)
  189. *(uint32_t *)(ht_eoi_space+(irq<<16)+(7<<2)) = 0;
  190. #endif
  191. }
  192. }
  193. bcm1480_mask_irq(bcm1480_irq_owner[irq], irq);
  194. }
  195. static void end_bcm1480_irq(unsigned int irq)
  196. {
  197. if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
  198. bcm1480_unmask_irq(bcm1480_irq_owner[irq], irq);
  199. }
  200. }
  201. void __init init_bcm1480_irqs(void)
  202. {
  203. int i;
  204. for (i = 0; i < BCM1480_NR_IRQS; i++) {
  205. set_irq_chip_and_handler(i, &bcm1480_irq_type, handle_level_irq);
  206. bcm1480_irq_owner[i] = 0;
  207. }
  208. }
  209. /*
  210. * init_IRQ is called early in the boot sequence from init/main.c. It
  211. * is responsible for setting up the interrupt mapper and installing the
  212. * handler that will be responsible for dispatching interrupts to the
  213. * "right" place.
  214. */
  215. /*
  216. * For now, map all interrupts to IP[2]. We could save
  217. * some cycles by parceling out system interrupts to different
  218. * IP lines, but keep it simple for bringup. We'll also direct
  219. * all interrupts to a single CPU; we should probably route
  220. * PCI and LDT to one cpu and everything else to the other
  221. * to balance the load a bit.
  222. *
  223. * On the second cpu, everything is set to IP5, which is
  224. * ignored, EXCEPT the mailbox interrupt. That one is
  225. * set to IP[2] so it is handled. This is needed so we
  226. * can do cross-cpu function calls, as requred by SMP
  227. */
  228. #define IMR_IP2_VAL K_BCM1480_INT_MAP_I0
  229. #define IMR_IP3_VAL K_BCM1480_INT_MAP_I1
  230. #define IMR_IP4_VAL K_BCM1480_INT_MAP_I2
  231. #define IMR_IP5_VAL K_BCM1480_INT_MAP_I3
  232. #define IMR_IP6_VAL K_BCM1480_INT_MAP_I4
  233. void __init arch_init_irq(void)
  234. {
  235. unsigned int i, cpu;
  236. u64 tmp;
  237. unsigned int imask = STATUSF_IP4 | STATUSF_IP3 | STATUSF_IP2 |
  238. STATUSF_IP1 | STATUSF_IP0;
  239. /* Default everything to IP2 */
  240. /* Start with _high registers which has no bit 0 interrupt source */
  241. for (i = 1; i < BCM1480_NR_IRQS_HALF; i++) { /* was I0 */
  242. for (cpu = 0; cpu < 4; cpu++) {
  243. __raw_writeq(IMR_IP2_VAL,
  244. IOADDR(A_BCM1480_IMR_REGISTER(cpu,
  245. R_BCM1480_IMR_INTERRUPT_MAP_BASE_H) + (i << 3)));
  246. }
  247. }
  248. /* Now do _low registers */
  249. for (i = 0; i < BCM1480_NR_IRQS_HALF; i++) {
  250. for (cpu = 0; cpu < 4; cpu++) {
  251. __raw_writeq(IMR_IP2_VAL,
  252. IOADDR(A_BCM1480_IMR_REGISTER(cpu,
  253. R_BCM1480_IMR_INTERRUPT_MAP_BASE_L) + (i << 3)));
  254. }
  255. }
  256. init_bcm1480_irqs();
  257. /*
  258. * Map the high 16 bits of mailbox_0 registers to IP[3], for
  259. * inter-cpu messages
  260. */
  261. /* Was I1 */
  262. for (cpu = 0; cpu < 4; cpu++) {
  263. __raw_writeq(IMR_IP3_VAL, IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_INTERRUPT_MAP_BASE_H) +
  264. (K_BCM1480_INT_MBOX_0_0 << 3)));
  265. }
  266. /* Clear the mailboxes. The firmware may leave them dirty */
  267. for (cpu = 0; cpu < 4; cpu++) {
  268. __raw_writeq(0xffffffffffffffffULL,
  269. IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_MAILBOX_0_CLR_CPU)));
  270. __raw_writeq(0xffffffffffffffffULL,
  271. IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_MAILBOX_1_CLR_CPU)));
  272. }
  273. /* Mask everything except the high 16 bit of mailbox_0 registers for all cpus */
  274. tmp = ~((u64) 0) ^ ( (((u64) 1) << K_BCM1480_INT_MBOX_0_0));
  275. for (cpu = 0; cpu < 4; cpu++) {
  276. __raw_writeq(tmp, IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_INTERRUPT_MASK_H)));
  277. }
  278. tmp = ~((u64) 0);
  279. for (cpu = 0; cpu < 4; cpu++) {
  280. __raw_writeq(tmp, IOADDR(A_BCM1480_IMR_REGISTER(cpu, R_BCM1480_IMR_INTERRUPT_MASK_L)));
  281. }
  282. /*
  283. * Note that the timer interrupts are also mapped, but this is
  284. * done in bcm1480_time_init(). Also, the profiling driver
  285. * does its own management of IP7.
  286. */
  287. /* Enable necessary IPs, disable the rest */
  288. change_c0_status(ST0_IM, imask);
  289. }
  290. extern void bcm1480_mailbox_interrupt(void);
  291. static inline void dispatch_ip2(void)
  292. {
  293. unsigned long long mask_h, mask_l;
  294. unsigned int cpu = smp_processor_id();
  295. unsigned long base;
  296. /*
  297. * Default...we've hit an IP[2] interrupt, which means we've got to
  298. * check the 1480 interrupt registers to figure out what to do. Need
  299. * to detect which CPU we're on, now that smp_affinity is supported.
  300. */
  301. base = A_BCM1480_IMR_MAPPER(cpu);
  302. mask_h = __raw_readq(
  303. IOADDR(base + R_BCM1480_IMR_INTERRUPT_STATUS_BASE_H));
  304. mask_l = __raw_readq(
  305. IOADDR(base + R_BCM1480_IMR_INTERRUPT_STATUS_BASE_L));
  306. if (mask_h) {
  307. if (mask_h ^ 1)
  308. do_IRQ(fls64(mask_h) - 1);
  309. else if (mask_l)
  310. do_IRQ(63 + fls64(mask_l));
  311. }
  312. }
  313. asmlinkage void plat_irq_dispatch(void)
  314. {
  315. unsigned int cpu = smp_processor_id();
  316. unsigned int pending;
  317. #ifdef CONFIG_SIBYTE_BCM1480_PROF
  318. /* Set compare to count to silence count/compare timer interrupts */
  319. write_c0_compare(read_c0_count());
  320. #endif
  321. pending = read_c0_cause() & read_c0_status();
  322. #ifdef CONFIG_SIBYTE_BCM1480_PROF
  323. if (pending & CAUSEF_IP7) /* Cpu performance counter interrupt */
  324. sbprof_cpu_intr();
  325. else
  326. #endif
  327. if (pending & CAUSEF_IP4)
  328. do_IRQ(K_BCM1480_INT_TIMER_0 + cpu);
  329. #ifdef CONFIG_SMP
  330. else if (pending & CAUSEF_IP3)
  331. bcm1480_mailbox_interrupt();
  332. #endif
  333. else if (pending & CAUSEF_IP2)
  334. dispatch_ip2();
  335. }