irq.c 6.0 KB

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