irq.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. #else
  58. #error "Unknown CPU"
  59. #endif
  60. #ifdef CONFIG_SMP
  61. #define SMP_IRQ_MASK ((1ULL << IRQ_IPI_SMP_FUNCTION) | \
  62. (1ULL << IRQ_IPI_SMP_RESCHEDULE))
  63. #else
  64. #define SMP_IRQ_MASK 0
  65. #endif
  66. #define PERCPU_IRQ_MASK (SMP_IRQ_MASK | (1ull << IRQ_TIMER))
  67. struct nlm_pic_irq {
  68. void (*extra_ack)(struct irq_data *);
  69. struct nlm_soc_info *node;
  70. int picirq;
  71. int irt;
  72. int flags;
  73. };
  74. static void xlp_pic_enable(struct irq_data *d)
  75. {
  76. unsigned long flags;
  77. struct nlm_pic_irq *pd = irq_data_get_irq_handler_data(d);
  78. BUG_ON(!pd);
  79. spin_lock_irqsave(&pd->node->piclock, flags);
  80. nlm_pic_enable_irt(pd->node->picbase, pd->irt);
  81. spin_unlock_irqrestore(&pd->node->piclock, flags);
  82. }
  83. static void xlp_pic_disable(struct irq_data *d)
  84. {
  85. struct nlm_pic_irq *pd = irq_data_get_irq_handler_data(d);
  86. unsigned long flags;
  87. BUG_ON(!pd);
  88. spin_lock_irqsave(&pd->node->piclock, flags);
  89. nlm_pic_disable_irt(pd->node->picbase, pd->irt);
  90. spin_unlock_irqrestore(&pd->node->piclock, flags);
  91. }
  92. static void xlp_pic_mask_ack(struct irq_data *d)
  93. {
  94. struct nlm_pic_irq *pd = irq_data_get_irq_handler_data(d);
  95. uint64_t mask = 1ull << pd->picirq;
  96. write_c0_eirr(mask); /* ack by writing EIRR */
  97. }
  98. static void xlp_pic_unmask(struct irq_data *d)
  99. {
  100. struct nlm_pic_irq *pd = irq_data_get_irq_handler_data(d);
  101. if (!pd)
  102. return;
  103. if (pd->extra_ack)
  104. pd->extra_ack(d);
  105. /* Ack is a single write, no need to lock */
  106. nlm_pic_ack(pd->node->picbase, pd->irt);
  107. }
  108. static struct irq_chip xlp_pic = {
  109. .name = "XLP-PIC",
  110. .irq_enable = xlp_pic_enable,
  111. .irq_disable = xlp_pic_disable,
  112. .irq_mask_ack = xlp_pic_mask_ack,
  113. .irq_unmask = xlp_pic_unmask,
  114. };
  115. static void cpuintr_disable(struct irq_data *d)
  116. {
  117. uint64_t eimr;
  118. uint64_t mask = 1ull << d->irq;
  119. eimr = read_c0_eimr();
  120. write_c0_eimr(eimr & ~mask);
  121. }
  122. static void cpuintr_enable(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_ack(struct irq_data *d)
  130. {
  131. uint64_t mask = 1ull << d->irq;
  132. write_c0_eirr(mask);
  133. }
  134. static void cpuintr_nop(struct irq_data *d)
  135. {
  136. WARN(d->irq >= PIC_IRQ_BASE, "Bad irq %d", d->irq);
  137. }
  138. /*
  139. * Chip definition for CPU originated interrupts(timer, msg) and
  140. * IPIs
  141. */
  142. struct irq_chip nlm_cpu_intr = {
  143. .name = "XLP-CPU-INTR",
  144. .irq_enable = cpuintr_enable,
  145. .irq_disable = cpuintr_disable,
  146. .irq_mask = cpuintr_nop,
  147. .irq_ack = cpuintr_nop,
  148. .irq_eoi = cpuintr_ack,
  149. };
  150. static void __init nlm_init_percpu_irqs(void)
  151. {
  152. int i;
  153. for (i = 0; i < PIC_IRT_FIRST_IRQ; i++)
  154. irq_set_chip_and_handler(i, &nlm_cpu_intr, handle_percpu_irq);
  155. #ifdef CONFIG_SMP
  156. irq_set_chip_and_handler(IRQ_IPI_SMP_FUNCTION, &nlm_cpu_intr,
  157. nlm_smp_function_ipi_handler);
  158. irq_set_chip_and_handler(IRQ_IPI_SMP_RESCHEDULE, &nlm_cpu_intr,
  159. nlm_smp_resched_ipi_handler);
  160. #endif
  161. }
  162. void nlm_setup_pic_irq(int node, int picirq, int irq, int irt)
  163. {
  164. struct nlm_pic_irq *pic_data;
  165. int xirq;
  166. xirq = nlm_irq_to_xirq(node, irq);
  167. pic_data = kzalloc(sizeof(*pic_data), GFP_KERNEL);
  168. BUG_ON(pic_data == NULL);
  169. pic_data->irt = irt;
  170. pic_data->picirq = picirq;
  171. pic_data->node = nlm_get_node(node);
  172. irq_set_chip_and_handler(xirq, &xlp_pic, handle_level_irq);
  173. irq_set_handler_data(xirq, pic_data);
  174. }
  175. void nlm_set_pic_extra_ack(int node, int irq, void (*xack)(struct irq_data *))
  176. {
  177. struct nlm_pic_irq *pic_data;
  178. int xirq;
  179. xirq = nlm_irq_to_xirq(node, irq);
  180. pic_data = irq_get_handler_data(xirq);
  181. pic_data->extra_ack = xack;
  182. }
  183. static void nlm_init_node_irqs(int node)
  184. {
  185. int i, irt;
  186. uint64_t irqmask;
  187. struct nlm_soc_info *nodep;
  188. pr_info("Init IRQ for node %d\n", node);
  189. nodep = nlm_get_node(node);
  190. irqmask = PERCPU_IRQ_MASK;
  191. for (i = PIC_IRT_FIRST_IRQ; i <= PIC_IRT_LAST_IRQ; i++) {
  192. irt = nlm_irq_to_irt(i);
  193. if (irt == -1)
  194. continue;
  195. nlm_setup_pic_irq(node, i, i, irt);
  196. /* set interrupts to first cpu in node */
  197. nlm_pic_init_irt(nodep->picbase, irt, i,
  198. node * NLM_CPUS_PER_NODE);
  199. irqmask |= (1ull << i);
  200. }
  201. nodep->irqmask = irqmask;
  202. }
  203. void __init arch_init_irq(void)
  204. {
  205. /* Initialize the irq descriptors */
  206. nlm_init_percpu_irqs();
  207. nlm_init_node_irqs(0);
  208. write_c0_eimr(nlm_current_node()->irqmask);
  209. }
  210. void nlm_smp_irq_init(int hwcpuid)
  211. {
  212. int node, cpu;
  213. node = hwcpuid / NLM_CPUS_PER_NODE;
  214. cpu = hwcpuid % NLM_CPUS_PER_NODE;
  215. if (cpu == 0 && node != 0)
  216. nlm_init_node_irqs(node);
  217. write_c0_eimr(nlm_current_node()->irqmask);
  218. }
  219. asmlinkage void plat_irq_dispatch(void)
  220. {
  221. uint64_t eirr;
  222. int i, node;
  223. node = nlm_nodeid();
  224. eirr = read_c0_eirr() & read_c0_eimr();
  225. i = __ilog2_u64(eirr);
  226. if (i == -1)
  227. return;
  228. /* per-CPU IRQs don't need translation */
  229. if (eirr & PERCPU_IRQ_MASK) {
  230. do_IRQ(i);
  231. return;
  232. }
  233. /* top level irq handling */
  234. do_IRQ(nlm_irq_to_xirq(node, i));
  235. }