irq.c 12 KB

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