irq.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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/mm.h>
  39. #include <linux/slab.h>
  40. #include <linux/irq.h>
  41. #include <asm/errno.h>
  42. #include <asm/signal.h>
  43. #include <asm/ptrace.h>
  44. #include <asm/mipsregs.h>
  45. #include <asm/thread_info.h>
  46. #include <asm/netlogic/mips-extns.h>
  47. #include <asm/netlogic/interrupt.h>
  48. #include <asm/netlogic/haldefs.h>
  49. #include <asm/netlogic/common.h>
  50. #if defined(CONFIG_CPU_XLP)
  51. #include <asm/netlogic/xlp-hal/iomap.h>
  52. #include <asm/netlogic/xlp-hal/xlp.h>
  53. #include <asm/netlogic/xlp-hal/pic.h>
  54. #elif defined(CONFIG_CPU_XLR)
  55. #include <asm/netlogic/xlr/iomap.h>
  56. #include <asm/netlogic/xlr/pic.h>
  57. #include <asm/netlogic/xlr/fmn.h>
  58. #else
  59. #error "Unknown CPU"
  60. #endif
  61. #ifdef CONFIG_SMP
  62. #define SMP_IRQ_MASK ((1ULL << IRQ_IPI_SMP_FUNCTION) | \
  63. (1ULL << IRQ_IPI_SMP_RESCHEDULE))
  64. #else
  65. #define SMP_IRQ_MASK 0
  66. #endif
  67. #define PERCPU_IRQ_MASK (SMP_IRQ_MASK | (1ull << IRQ_TIMER) | \
  68. (1ull << IRQ_FMN))
  69. struct nlm_pic_irq {
  70. void (*extra_ack)(struct irq_data *);
  71. struct nlm_soc_info *node;
  72. int picirq;
  73. int irt;
  74. int flags;
  75. };
  76. static void xlp_pic_enable(struct irq_data *d)
  77. {
  78. unsigned long flags;
  79. struct nlm_pic_irq *pd = irq_data_get_irq_handler_data(d);
  80. BUG_ON(!pd);
  81. spin_lock_irqsave(&pd->node->piclock, flags);
  82. nlm_pic_enable_irt(pd->node->picbase, pd->irt);
  83. spin_unlock_irqrestore(&pd->node->piclock, flags);
  84. }
  85. static void xlp_pic_disable(struct irq_data *d)
  86. {
  87. struct nlm_pic_irq *pd = irq_data_get_irq_handler_data(d);
  88. unsigned long flags;
  89. BUG_ON(!pd);
  90. spin_lock_irqsave(&pd->node->piclock, flags);
  91. nlm_pic_disable_irt(pd->node->picbase, pd->irt);
  92. spin_unlock_irqrestore(&pd->node->piclock, flags);
  93. }
  94. static void xlp_pic_mask_ack(struct irq_data *d)
  95. {
  96. struct nlm_pic_irq *pd = irq_data_get_irq_handler_data(d);
  97. clear_c0_eimr(pd->picirq);
  98. ack_c0_eirr(pd->picirq);
  99. }
  100. static void xlp_pic_unmask(struct irq_data *d)
  101. {
  102. struct nlm_pic_irq *pd = irq_data_get_irq_handler_data(d);
  103. BUG_ON(!pd);
  104. if (pd->extra_ack)
  105. pd->extra_ack(d);
  106. /* re-enable the intr on this cpu */
  107. set_c0_eimr(pd->picirq);
  108. /* Ack is a single write, no need to lock */
  109. nlm_pic_ack(pd->node->picbase, pd->irt);
  110. }
  111. static struct irq_chip xlp_pic = {
  112. .name = "XLP-PIC",
  113. .irq_enable = xlp_pic_enable,
  114. .irq_disable = xlp_pic_disable,
  115. .irq_mask_ack = xlp_pic_mask_ack,
  116. .irq_unmask = xlp_pic_unmask,
  117. };
  118. static void cpuintr_disable(struct irq_data *d)
  119. {
  120. clear_c0_eimr(d->irq);
  121. }
  122. static void cpuintr_enable(struct irq_data *d)
  123. {
  124. set_c0_eimr(d->irq);
  125. }
  126. static void cpuintr_ack(struct irq_data *d)
  127. {
  128. ack_c0_eirr(d->irq);
  129. }
  130. /*
  131. * Chip definition for CPU originated interrupts(timer, msg) and
  132. * IPIs
  133. */
  134. struct irq_chip nlm_cpu_intr = {
  135. .name = "XLP-CPU-INTR",
  136. .irq_enable = cpuintr_enable,
  137. .irq_disable = cpuintr_disable,
  138. .irq_mask = cpuintr_disable,
  139. .irq_ack = cpuintr_ack,
  140. .irq_eoi = cpuintr_enable,
  141. };
  142. static void __init nlm_init_percpu_irqs(void)
  143. {
  144. int i;
  145. for (i = 0; i < PIC_IRT_FIRST_IRQ; i++)
  146. irq_set_chip_and_handler(i, &nlm_cpu_intr, handle_percpu_irq);
  147. #ifdef CONFIG_SMP
  148. irq_set_chip_and_handler(IRQ_IPI_SMP_FUNCTION, &nlm_cpu_intr,
  149. nlm_smp_function_ipi_handler);
  150. irq_set_chip_and_handler(IRQ_IPI_SMP_RESCHEDULE, &nlm_cpu_intr,
  151. nlm_smp_resched_ipi_handler);
  152. #endif
  153. }
  154. void nlm_setup_pic_irq(int node, int picirq, int irq, int irt)
  155. {
  156. struct nlm_pic_irq *pic_data;
  157. int xirq;
  158. xirq = nlm_irq_to_xirq(node, irq);
  159. pic_data = kzalloc(sizeof(*pic_data), GFP_KERNEL);
  160. BUG_ON(pic_data == NULL);
  161. pic_data->irt = irt;
  162. pic_data->picirq = picirq;
  163. pic_data->node = nlm_get_node(node);
  164. irq_set_chip_and_handler(xirq, &xlp_pic, handle_level_irq);
  165. irq_set_handler_data(xirq, pic_data);
  166. }
  167. void nlm_set_pic_extra_ack(int node, int irq, void (*xack)(struct irq_data *))
  168. {
  169. struct nlm_pic_irq *pic_data;
  170. int xirq;
  171. xirq = nlm_irq_to_xirq(node, irq);
  172. pic_data = irq_get_handler_data(xirq);
  173. pic_data->extra_ack = xack;
  174. }
  175. static void nlm_init_node_irqs(int node)
  176. {
  177. int i, irt;
  178. uint64_t irqmask;
  179. struct nlm_soc_info *nodep;
  180. pr_info("Init IRQ for node %d\n", node);
  181. nodep = nlm_get_node(node);
  182. irqmask = PERCPU_IRQ_MASK;
  183. for (i = PIC_IRT_FIRST_IRQ; i <= PIC_IRT_LAST_IRQ; i++) {
  184. irt = nlm_irq_to_irt(i);
  185. if (irt == -1)
  186. continue;
  187. nlm_setup_pic_irq(node, i, i, irt);
  188. /* set interrupts to first cpu in node */
  189. nlm_pic_init_irt(nodep->picbase, irt, i,
  190. node * NLM_CPUS_PER_NODE, 0);
  191. irqmask |= (1ull << i);
  192. }
  193. nodep->irqmask = irqmask;
  194. }
  195. void __init arch_init_irq(void)
  196. {
  197. /* Initialize the irq descriptors */
  198. nlm_init_percpu_irqs();
  199. nlm_init_node_irqs(0);
  200. write_c0_eimr(nlm_current_node()->irqmask);
  201. #if defined(CONFIG_CPU_XLR)
  202. nlm_setup_fmn_irq();
  203. #endif
  204. }
  205. void nlm_smp_irq_init(int hwcpuid)
  206. {
  207. int node, cpu;
  208. node = hwcpuid / NLM_CPUS_PER_NODE;
  209. cpu = hwcpuid % NLM_CPUS_PER_NODE;
  210. if (cpu == 0 && node != 0)
  211. nlm_init_node_irqs(node);
  212. write_c0_eimr(nlm_current_node()->irqmask);
  213. }
  214. asmlinkage void plat_irq_dispatch(void)
  215. {
  216. uint64_t eirr;
  217. int i, node;
  218. node = nlm_nodeid();
  219. eirr = read_c0_eirr_and_eimr();
  220. i = __ilog2_u64(eirr);
  221. if (i == -1)
  222. return;
  223. /* per-CPU IRQs don't need translation */
  224. if (eirr & PERCPU_IRQ_MASK) {
  225. do_IRQ(i);
  226. return;
  227. }
  228. /* top level irq handling */
  229. do_IRQ(nlm_irq_to_xirq(node, i));
  230. }