irq.c 11 KB

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