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