irq.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /*
  2. * Copyright 2003-2011 NetLogic Microsystems, Inc. (NetLogic). All rights
  3. * reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the NetLogic
  9. * license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. *
  15. * 1. Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright
  18. * notice, this list of conditions and the following disclaimer in
  19. * the documentation and/or other materials provided with the
  20. * distribution.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY NETLOGIC ``AS IS'' AND ANY EXPRESS OR
  23. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  24. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL NETLOGIC OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  29. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  30. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  31. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  32. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <linux/kernel.h>
  35. #include <linux/init.h>
  36. #include <linux/linkage.h>
  37. #include <linux/interrupt.h>
  38. #include <linux/spinlock.h>
  39. #include <linux/mm.h>
  40. #include <asm/mipsregs.h>
  41. #include <asm/netlogic/xlr/iomap.h>
  42. #include <asm/netlogic/xlr/pic.h>
  43. #include <asm/netlogic/xlr/xlr.h>
  44. #include <asm/netlogic/interrupt.h>
  45. #include <asm/netlogic/mips-extns.h>
  46. static u64 nlm_irq_mask;
  47. static DEFINE_SPINLOCK(nlm_pic_lock);
  48. static void xlr_pic_enable(struct irq_data *d)
  49. {
  50. nlm_reg_t *mmio = netlogic_io_mmio(NETLOGIC_IO_PIC_OFFSET);
  51. unsigned long flags;
  52. nlm_reg_t reg;
  53. int irq = d->irq;
  54. WARN(!PIC_IRQ_IS_IRT(irq), "Bad irq %d", irq);
  55. spin_lock_irqsave(&nlm_pic_lock, flags);
  56. reg = netlogic_read_reg(mmio, PIC_IRT_1_BASE + irq - PIC_IRQ_BASE);
  57. netlogic_write_reg(mmio, PIC_IRT_1_BASE + irq - PIC_IRQ_BASE,
  58. reg | (1 << 6) | (1 << 30) | (1 << 31));
  59. spin_unlock_irqrestore(&nlm_pic_lock, flags);
  60. }
  61. static void xlr_pic_mask(struct irq_data *d)
  62. {
  63. nlm_reg_t *mmio = netlogic_io_mmio(NETLOGIC_IO_PIC_OFFSET);
  64. unsigned long flags;
  65. nlm_reg_t reg;
  66. int irq = d->irq;
  67. WARN(!PIC_IRQ_IS_IRT(irq), "Bad irq %d", irq);
  68. spin_lock_irqsave(&nlm_pic_lock, flags);
  69. reg = netlogic_read_reg(mmio, PIC_IRT_1_BASE + irq - PIC_IRQ_BASE);
  70. netlogic_write_reg(mmio, PIC_IRT_1_BASE + irq - PIC_IRQ_BASE,
  71. reg | (1 << 6) | (1 << 30) | (0 << 31));
  72. spin_unlock_irqrestore(&nlm_pic_lock, flags);
  73. }
  74. #ifdef CONFIG_PCI
  75. /* Extra ACK needed for XLR on chip PCI controller */
  76. static void xlr_pci_ack(struct irq_data *d)
  77. {
  78. nlm_reg_t *pci_mmio = netlogic_io_mmio(NETLOGIC_IO_PCIX_OFFSET);
  79. netlogic_read_reg(pci_mmio, (0x140 >> 2));
  80. }
  81. /* Extra ACK needed for XLS on chip PCIe controller */
  82. static void xls_pcie_ack(struct irq_data *d)
  83. {
  84. nlm_reg_t *pcie_mmio_le = netlogic_io_mmio(NETLOGIC_IO_PCIE_1_OFFSET);
  85. switch (d->irq) {
  86. case PIC_PCIE_LINK0_IRQ:
  87. netlogic_write_reg(pcie_mmio_le, (0x90 >> 2), 0xffffffff);
  88. break;
  89. case PIC_PCIE_LINK1_IRQ:
  90. netlogic_write_reg(pcie_mmio_le, (0x94 >> 2), 0xffffffff);
  91. break;
  92. case PIC_PCIE_LINK2_IRQ:
  93. netlogic_write_reg(pcie_mmio_le, (0x190 >> 2), 0xffffffff);
  94. break;
  95. case PIC_PCIE_LINK3_IRQ:
  96. netlogic_write_reg(pcie_mmio_le, (0x194 >> 2), 0xffffffff);
  97. break;
  98. }
  99. }
  100. /* For XLS B silicon, the 3,4 PCI interrupts are different */
  101. static void xls_pcie_ack_b(struct irq_data *d)
  102. {
  103. nlm_reg_t *pcie_mmio_le = netlogic_io_mmio(NETLOGIC_IO_PCIE_1_OFFSET);
  104. switch (d->irq) {
  105. case PIC_PCIE_LINK0_IRQ:
  106. netlogic_write_reg(pcie_mmio_le, (0x90 >> 2), 0xffffffff);
  107. break;
  108. case PIC_PCIE_LINK1_IRQ:
  109. netlogic_write_reg(pcie_mmio_le, (0x94 >> 2), 0xffffffff);
  110. break;
  111. case PIC_PCIE_XLSB0_LINK2_IRQ:
  112. netlogic_write_reg(pcie_mmio_le, (0x190 >> 2), 0xffffffff);
  113. break;
  114. case PIC_PCIE_XLSB0_LINK3_IRQ:
  115. netlogic_write_reg(pcie_mmio_le, (0x194 >> 2), 0xffffffff);
  116. break;
  117. }
  118. }
  119. #endif
  120. static void xlr_pic_ack(struct irq_data *d)
  121. {
  122. unsigned long flags;
  123. nlm_reg_t *mmio;
  124. int irq = d->irq;
  125. void *hd = irq_data_get_irq_handler_data(d);
  126. WARN(!PIC_IRQ_IS_IRT(irq), "Bad irq %d", irq);
  127. if (hd) {
  128. void (*extra_ack)(void *) = hd;
  129. extra_ack(d);
  130. }
  131. mmio = netlogic_io_mmio(NETLOGIC_IO_PIC_OFFSET);
  132. spin_lock_irqsave(&nlm_pic_lock, flags);
  133. netlogic_write_reg(mmio, PIC_INT_ACK, (1 << (irq - PIC_IRQ_BASE)));
  134. spin_unlock_irqrestore(&nlm_pic_lock, flags);
  135. }
  136. /*
  137. * This chip definition handles interrupts routed thru the XLR
  138. * hardware PIC, currently IRQs 8-39 are mapped to hardware intr
  139. * 0-31 wired the XLR PIC
  140. */
  141. static struct irq_chip xlr_pic = {
  142. .name = "XLR-PIC",
  143. .irq_enable = xlr_pic_enable,
  144. .irq_mask = xlr_pic_mask,
  145. .irq_ack = xlr_pic_ack,
  146. };
  147. static void rsvd_irq_handler(struct irq_data *d)
  148. {
  149. WARN(d->irq >= PIC_IRQ_BASE, "Bad irq %d", d->irq);
  150. }
  151. /*
  152. * Chip definition for CPU originated interrupts(timer, msg) and
  153. * IPIs
  154. */
  155. struct irq_chip nlm_cpu_intr = {
  156. .name = "XLR-CPU-INTR",
  157. .irq_enable = rsvd_irq_handler,
  158. .irq_mask = rsvd_irq_handler,
  159. .irq_ack = rsvd_irq_handler,
  160. };
  161. void __init init_xlr_irqs(void)
  162. {
  163. nlm_reg_t *mmio = netlogic_io_mmio(NETLOGIC_IO_PIC_OFFSET);
  164. uint32_t thread_mask = 1;
  165. int level, i;
  166. pr_info("Interrupt thread mask [%x]\n", thread_mask);
  167. for (i = 0; i < PIC_NUM_IRTS; i++) {
  168. level = PIC_IRQ_IS_EDGE_TRIGGERED(i);
  169. /* Bind all PIC irqs to boot cpu */
  170. netlogic_write_reg(mmio, PIC_IRT_0_BASE + i, thread_mask);
  171. /*
  172. * Use local scheduling and high polarity for all IRTs
  173. * Invalidate all IRTs, by default
  174. */
  175. netlogic_write_reg(mmio, PIC_IRT_1_BASE + i,
  176. (level << 30) | (1 << 6) | (PIC_IRQ_BASE + i));
  177. }
  178. /* Make all IRQs as level triggered by default */
  179. for (i = 0; i < NR_IRQS; i++) {
  180. if (PIC_IRQ_IS_IRT(i))
  181. irq_set_chip_and_handler(i, &xlr_pic, handle_level_irq);
  182. else
  183. irq_set_chip_and_handler(i, &nlm_cpu_intr,
  184. handle_percpu_irq);
  185. }
  186. #ifdef CONFIG_SMP
  187. irq_set_chip_and_handler(IRQ_IPI_SMP_FUNCTION, &nlm_cpu_intr,
  188. nlm_smp_function_ipi_handler);
  189. irq_set_chip_and_handler(IRQ_IPI_SMP_RESCHEDULE, &nlm_cpu_intr,
  190. nlm_smp_resched_ipi_handler);
  191. nlm_irq_mask |=
  192. ((1ULL << IRQ_IPI_SMP_FUNCTION) | (1ULL << IRQ_IPI_SMP_RESCHEDULE));
  193. #endif
  194. #ifdef CONFIG_PCI
  195. /*
  196. * For PCI interrupts, we need to ack the PIC controller too, overload
  197. * irq handler data to do this
  198. */
  199. if (nlm_chip_is_xls()) {
  200. if (nlm_chip_is_xls_b()) {
  201. irq_set_handler_data(PIC_PCIE_LINK0_IRQ,
  202. xls_pcie_ack_b);
  203. irq_set_handler_data(PIC_PCIE_LINK1_IRQ,
  204. xls_pcie_ack_b);
  205. irq_set_handler_data(PIC_PCIE_XLSB0_LINK2_IRQ,
  206. xls_pcie_ack_b);
  207. irq_set_handler_data(PIC_PCIE_XLSB0_LINK3_IRQ,
  208. xls_pcie_ack_b);
  209. } else {
  210. irq_set_handler_data(PIC_PCIE_LINK0_IRQ, xls_pcie_ack);
  211. irq_set_handler_data(PIC_PCIE_LINK1_IRQ, xls_pcie_ack);
  212. irq_set_handler_data(PIC_PCIE_LINK2_IRQ, xls_pcie_ack);
  213. irq_set_handler_data(PIC_PCIE_LINK3_IRQ, xls_pcie_ack);
  214. }
  215. } else {
  216. /* XLR PCI controller ACK */
  217. irq_set_handler_data(PIC_PCIE_XLSB0_LINK3_IRQ, xlr_pci_ack);
  218. }
  219. #endif
  220. /* unmask all PIC related interrupts. If no handler is installed by the
  221. * drivers, it'll just ack the interrupt and return
  222. */
  223. for (i = PIC_IRT_FIRST_IRQ; i <= PIC_IRT_LAST_IRQ; i++)
  224. nlm_irq_mask |= (1ULL << i);
  225. nlm_irq_mask |= (1ULL << IRQ_TIMER);
  226. }
  227. void __init arch_init_irq(void)
  228. {
  229. /* Initialize the irq descriptors */
  230. init_xlr_irqs();
  231. write_c0_eimr(nlm_irq_mask);
  232. }
  233. void __cpuinit nlm_smp_irq_init(void)
  234. {
  235. /* set interrupt mask for non-zero cpus */
  236. write_c0_eimr(nlm_irq_mask);
  237. }
  238. asmlinkage void plat_irq_dispatch(void)
  239. {
  240. uint64_t eirr;
  241. int i;
  242. eirr = read_c0_eirr() & read_c0_eimr();
  243. if (!eirr)
  244. return;
  245. /* no need of EIRR here, writing compare clears interrupt */
  246. if (eirr & (1 << IRQ_TIMER)) {
  247. do_IRQ(IRQ_TIMER);
  248. return;
  249. }
  250. /* use dcltz: optimize below code */
  251. for (i = 63; i != -1; i--) {
  252. if (eirr & (1ULL << i))
  253. break;
  254. }
  255. if (i == -1) {
  256. pr_err("no interrupt !!\n");
  257. return;
  258. }
  259. /* Ack eirr */
  260. write_c0_eirr(1ULL << i);
  261. do_IRQ(i);
  262. }