irq.c 11 KB

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