irq.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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 <linux/slab.h>
  41. #include <linux/irq.h>
  42. #include <asm/errno.h>
  43. #include <asm/signal.h>
  44. #include <asm/ptrace.h>
  45. #include <asm/mipsregs.h>
  46. #include <asm/thread_info.h>
  47. #include <asm/netlogic/mips-extns.h>
  48. #include <asm/netlogic/interrupt.h>
  49. #include <asm/netlogic/haldefs.h>
  50. #include <asm/netlogic/common.h>
  51. #if defined(CONFIG_CPU_XLP)
  52. #include <asm/netlogic/xlp-hal/iomap.h>
  53. #include <asm/netlogic/xlp-hal/xlp.h>
  54. #include <asm/netlogic/xlp-hal/pic.h>
  55. #elif defined(CONFIG_CPU_XLR)
  56. #include <asm/netlogic/xlr/iomap.h>
  57. #include <asm/netlogic/xlr/pic.h>
  58. #else
  59. #error "Unknown CPU"
  60. #endif
  61. /*
  62. * These are the routines that handle all the low level interrupt stuff.
  63. * Actions handled here are: initialization of the interrupt map, requesting of
  64. * interrupt lines by handlers, dispatching if interrupts to handlers, probing
  65. * for interrupt lines
  66. */
  67. /* Globals */
  68. static void xlp_pic_enable(struct irq_data *d)
  69. {
  70. unsigned long flags;
  71. struct nlm_soc_info *nodep;
  72. int irt;
  73. nodep = nlm_current_node();
  74. irt = nlm_irq_to_irt(d->irq);
  75. if (irt == -1)
  76. return;
  77. spin_lock_irqsave(&nodep->piclock, flags);
  78. nlm_pic_enable_irt(nodep->picbase, irt);
  79. spin_unlock_irqrestore(&nodep->piclock, flags);
  80. }
  81. static void xlp_pic_disable(struct irq_data *d)
  82. {
  83. struct nlm_soc_info *nodep;
  84. unsigned long flags;
  85. int irt;
  86. nodep = nlm_current_node();
  87. irt = nlm_irq_to_irt(d->irq);
  88. if (irt == -1)
  89. return;
  90. spin_lock_irqsave(&nodep->piclock, flags);
  91. nlm_pic_disable_irt(nodep->picbase, irt);
  92. spin_unlock_irqrestore(&nodep->piclock, flags);
  93. }
  94. static void xlp_pic_mask_ack(struct irq_data *d)
  95. {
  96. uint64_t mask = 1ull << d->irq;
  97. write_c0_eirr(mask); /* ack by writing EIRR */
  98. }
  99. static void xlp_pic_unmask(struct irq_data *d)
  100. {
  101. void *hd = irq_data_get_irq_handler_data(d);
  102. struct nlm_soc_info *nodep;
  103. int irt;
  104. nodep = nlm_current_node();
  105. irt = nlm_irq_to_irt(d->irq);
  106. if (irt == -1)
  107. return;
  108. if (hd) {
  109. void (*extra_ack)(void *) = hd;
  110. extra_ack(d);
  111. }
  112. /* Ack is a single write, no need to lock */
  113. nlm_pic_ack(nodep->picbase, irt);
  114. }
  115. static struct irq_chip xlp_pic = {
  116. .name = "XLP-PIC",
  117. .irq_enable = xlp_pic_enable,
  118. .irq_disable = xlp_pic_disable,
  119. .irq_mask_ack = xlp_pic_mask_ack,
  120. .irq_unmask = xlp_pic_unmask,
  121. };
  122. static void cpuintr_disable(struct irq_data *d)
  123. {
  124. uint64_t eimr;
  125. uint64_t mask = 1ull << d->irq;
  126. eimr = read_c0_eimr();
  127. write_c0_eimr(eimr & ~mask);
  128. }
  129. static void cpuintr_enable(struct irq_data *d)
  130. {
  131. uint64_t eimr;
  132. uint64_t mask = 1ull << d->irq;
  133. eimr = read_c0_eimr();
  134. write_c0_eimr(eimr | mask);
  135. }
  136. static void cpuintr_ack(struct irq_data *d)
  137. {
  138. uint64_t mask = 1ull << d->irq;
  139. write_c0_eirr(mask);
  140. }
  141. static void cpuintr_nop(struct irq_data *d)
  142. {
  143. WARN(d->irq >= PIC_IRQ_BASE, "Bad irq %d", d->irq);
  144. }
  145. /*
  146. * Chip definition for CPU originated interrupts(timer, msg) and
  147. * IPIs
  148. */
  149. struct irq_chip nlm_cpu_intr = {
  150. .name = "XLP-CPU-INTR",
  151. .irq_enable = cpuintr_enable,
  152. .irq_disable = cpuintr_disable,
  153. .irq_mask = cpuintr_nop,
  154. .irq_ack = cpuintr_nop,
  155. .irq_eoi = cpuintr_ack,
  156. };
  157. void __init init_nlm_common_irqs(void)
  158. {
  159. int i, irq, irt;
  160. uint64_t irqmask;
  161. struct nlm_soc_info *nodep;
  162. nodep = nlm_current_node();
  163. irqmask = (1ULL << IRQ_TIMER);
  164. for (i = 0; i < PIC_IRT_FIRST_IRQ; i++)
  165. irq_set_chip_and_handler(i, &nlm_cpu_intr, handle_percpu_irq);
  166. for (i = PIC_IRT_FIRST_IRQ; i <= PIC_IRT_LAST_IRQ ; i++)
  167. irq_set_chip_and_handler(i, &xlp_pic, handle_level_irq);
  168. #ifdef CONFIG_SMP
  169. irq_set_chip_and_handler(IRQ_IPI_SMP_FUNCTION, &nlm_cpu_intr,
  170. nlm_smp_function_ipi_handler);
  171. irq_set_chip_and_handler(IRQ_IPI_SMP_RESCHEDULE, &nlm_cpu_intr,
  172. nlm_smp_resched_ipi_handler);
  173. irqmask |=
  174. ((1ULL << IRQ_IPI_SMP_FUNCTION) | (1ULL << IRQ_IPI_SMP_RESCHEDULE));
  175. #endif
  176. for (irq = PIC_IRT_FIRST_IRQ; irq <= PIC_IRT_LAST_IRQ; irq++) {
  177. irt = nlm_irq_to_irt(irq);
  178. if (irt == -1)
  179. continue;
  180. irqmask |= (1ULL << irq);
  181. nlm_pic_init_irt(nodep->picbase, irt, irq, 0);
  182. }
  183. nodep->irqmask = irqmask;
  184. }
  185. void __init arch_init_irq(void)
  186. {
  187. /* Initialize the irq descriptors */
  188. init_nlm_common_irqs();
  189. write_c0_eimr(nlm_current_node()->irqmask);
  190. }
  191. void __cpuinit nlm_smp_irq_init(void)
  192. {
  193. /* set interrupt mask for non-zero cpus */
  194. write_c0_eimr(nlm_current_node()->irqmask);
  195. }
  196. asmlinkage void plat_irq_dispatch(void)
  197. {
  198. uint64_t eirr;
  199. int i, node;
  200. node = nlm_nodeid();
  201. eirr = read_c0_eirr() & read_c0_eimr();
  202. if (eirr & (1 << IRQ_TIMER)) {
  203. do_IRQ(IRQ_TIMER);
  204. return;
  205. }
  206. #ifdef CONFIG_SMP
  207. if (eirr & IRQ_IPI_SMP_FUNCTION) {
  208. do_IRQ(IRQ_IPI_SMP_FUNCTION);
  209. return;
  210. }
  211. if (eirr & IRQ_IPI_SMP_RESCHEDULE) {
  212. do_IRQ(IRQ_IPI_SMP_RESCHEDULE);
  213. return;
  214. }
  215. #endif
  216. i = __ilog2_u64(eirr);
  217. if (i == -1)
  218. return;
  219. do_IRQ(nlm_irq_to_xirq(node, i));
  220. }