irq.c 12 KB

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