irq.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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 <linux/irqdomain.h>
  42. #include <linux/of_address.h>
  43. #include <linux/of_irq.h>
  44. #include <asm/errno.h>
  45. #include <asm/signal.h>
  46. #include <asm/ptrace.h>
  47. #include <asm/mipsregs.h>
  48. #include <asm/thread_info.h>
  49. #include <asm/netlogic/mips-extns.h>
  50. #include <asm/netlogic/interrupt.h>
  51. #include <asm/netlogic/haldefs.h>
  52. #include <asm/netlogic/common.h>
  53. #if defined(CONFIG_CPU_XLP)
  54. #include <asm/netlogic/xlp-hal/iomap.h>
  55. #include <asm/netlogic/xlp-hal/xlp.h>
  56. #include <asm/netlogic/xlp-hal/pic.h>
  57. #elif defined(CONFIG_CPU_XLR)
  58. #include <asm/netlogic/xlr/iomap.h>
  59. #include <asm/netlogic/xlr/pic.h>
  60. #include <asm/netlogic/xlr/fmn.h>
  61. #else
  62. #error "Unknown CPU"
  63. #endif
  64. #ifdef CONFIG_SMP
  65. #define SMP_IRQ_MASK ((1ULL << IRQ_IPI_SMP_FUNCTION) | \
  66. (1ULL << IRQ_IPI_SMP_RESCHEDULE))
  67. #else
  68. #define SMP_IRQ_MASK 0
  69. #endif
  70. #define PERCPU_IRQ_MASK (SMP_IRQ_MASK | (1ull << IRQ_TIMER) | \
  71. (1ull << IRQ_FMN))
  72. struct nlm_pic_irq {
  73. void (*extra_ack)(struct irq_data *);
  74. struct nlm_soc_info *node;
  75. int picirq;
  76. int irt;
  77. int flags;
  78. };
  79. static void xlp_pic_enable(struct irq_data *d)
  80. {
  81. unsigned long flags;
  82. struct nlm_pic_irq *pd = irq_data_get_irq_handler_data(d);
  83. BUG_ON(!pd);
  84. spin_lock_irqsave(&pd->node->piclock, flags);
  85. nlm_pic_enable_irt(pd->node->picbase, pd->irt);
  86. spin_unlock_irqrestore(&pd->node->piclock, flags);
  87. }
  88. static void xlp_pic_disable(struct irq_data *d)
  89. {
  90. struct nlm_pic_irq *pd = irq_data_get_irq_handler_data(d);
  91. unsigned long flags;
  92. BUG_ON(!pd);
  93. spin_lock_irqsave(&pd->node->piclock, flags);
  94. nlm_pic_disable_irt(pd->node->picbase, pd->irt);
  95. spin_unlock_irqrestore(&pd->node->piclock, flags);
  96. }
  97. static void xlp_pic_mask_ack(struct irq_data *d)
  98. {
  99. struct nlm_pic_irq *pd = irq_data_get_irq_handler_data(d);
  100. clear_c0_eimr(pd->picirq);
  101. ack_c0_eirr(pd->picirq);
  102. }
  103. static void xlp_pic_unmask(struct irq_data *d)
  104. {
  105. struct nlm_pic_irq *pd = irq_data_get_irq_handler_data(d);
  106. BUG_ON(!pd);
  107. if (pd->extra_ack)
  108. pd->extra_ack(d);
  109. /* re-enable the intr on this cpu */
  110. set_c0_eimr(pd->picirq);
  111. /* Ack is a single write, no need to lock */
  112. nlm_pic_ack(pd->node->picbase, pd->irt);
  113. }
  114. static struct irq_chip xlp_pic = {
  115. .name = "XLP-PIC",
  116. .irq_enable = xlp_pic_enable,
  117. .irq_disable = xlp_pic_disable,
  118. .irq_mask_ack = xlp_pic_mask_ack,
  119. .irq_unmask = xlp_pic_unmask,
  120. };
  121. static void cpuintr_disable(struct irq_data *d)
  122. {
  123. clear_c0_eimr(d->irq);
  124. }
  125. static void cpuintr_enable(struct irq_data *d)
  126. {
  127. set_c0_eimr(d->irq);
  128. }
  129. static void cpuintr_ack(struct irq_data *d)
  130. {
  131. ack_c0_eirr(d->irq);
  132. }
  133. /*
  134. * Chip definition for CPU originated interrupts(timer, msg) and
  135. * IPIs
  136. */
  137. struct irq_chip nlm_cpu_intr = {
  138. .name = "XLP-CPU-INTR",
  139. .irq_enable = cpuintr_enable,
  140. .irq_disable = cpuintr_disable,
  141. .irq_mask = cpuintr_disable,
  142. .irq_ack = cpuintr_ack,
  143. .irq_eoi = cpuintr_enable,
  144. };
  145. static void __init nlm_init_percpu_irqs(void)
  146. {
  147. int i;
  148. for (i = 0; i < PIC_IRT_FIRST_IRQ; i++)
  149. irq_set_chip_and_handler(i, &nlm_cpu_intr, handle_percpu_irq);
  150. #ifdef CONFIG_SMP
  151. irq_set_chip_and_handler(IRQ_IPI_SMP_FUNCTION, &nlm_cpu_intr,
  152. nlm_smp_function_ipi_handler);
  153. irq_set_chip_and_handler(IRQ_IPI_SMP_RESCHEDULE, &nlm_cpu_intr,
  154. nlm_smp_resched_ipi_handler);
  155. #endif
  156. }
  157. void nlm_setup_pic_irq(int node, int picirq, int irq, int irt)
  158. {
  159. struct nlm_pic_irq *pic_data;
  160. int xirq;
  161. xirq = nlm_irq_to_xirq(node, irq);
  162. pic_data = kzalloc(sizeof(*pic_data), GFP_KERNEL);
  163. BUG_ON(pic_data == NULL);
  164. pic_data->irt = irt;
  165. pic_data->picirq = picirq;
  166. pic_data->node = nlm_get_node(node);
  167. irq_set_chip_and_handler(xirq, &xlp_pic, handle_level_irq);
  168. irq_set_handler_data(xirq, pic_data);
  169. }
  170. void nlm_set_pic_extra_ack(int node, int irq, void (*xack)(struct irq_data *))
  171. {
  172. struct nlm_pic_irq *pic_data;
  173. int xirq;
  174. xirq = nlm_irq_to_xirq(node, irq);
  175. pic_data = irq_get_handler_data(xirq);
  176. pic_data->extra_ack = xack;
  177. }
  178. static void nlm_init_node_irqs(int node)
  179. {
  180. struct nlm_soc_info *nodep;
  181. int i, irt;
  182. pr_info("Init IRQ for node %d\n", node);
  183. nodep = nlm_get_node(node);
  184. nodep->irqmask = PERCPU_IRQ_MASK;
  185. for (i = PIC_IRT_FIRST_IRQ; i <= PIC_IRT_LAST_IRQ; i++) {
  186. irt = nlm_irq_to_irt(i);
  187. if (irt == -1) /* unused irq */
  188. continue;
  189. nodep->irqmask |= 1ull << i;
  190. if (irt == -2) /* not a direct PIC irq */
  191. continue;
  192. nlm_pic_init_irt(nodep->picbase, irt, i,
  193. node * nlm_threads_per_node(), 0);
  194. nlm_setup_pic_irq(node, i, i, irt);
  195. }
  196. }
  197. void nlm_smp_irq_init(int hwcpuid)
  198. {
  199. int node, cpu;
  200. node = nlm_cpuid_to_node(hwcpuid);
  201. cpu = hwcpuid % nlm_threads_per_node();
  202. if (cpu == 0 && node != 0)
  203. nlm_init_node_irqs(node);
  204. write_c0_eimr(nlm_current_node()->irqmask);
  205. }
  206. asmlinkage void plat_irq_dispatch(void)
  207. {
  208. uint64_t eirr;
  209. int i, node;
  210. node = nlm_nodeid();
  211. eirr = read_c0_eirr_and_eimr();
  212. if (eirr == 0)
  213. return;
  214. i = __ffs64(eirr);
  215. /* per-CPU IRQs don't need translation */
  216. if (i < PIC_IRQ_BASE) {
  217. do_IRQ(i);
  218. return;
  219. }
  220. #if defined(CONFIG_PCI_MSI) && defined(CONFIG_CPU_XLP)
  221. /* PCI interrupts need a second level dispatch for MSI bits */
  222. if (i >= PIC_PCIE_LINK_MSI_IRQ(0) && i <= PIC_PCIE_LINK_MSI_IRQ(3)) {
  223. nlm_dispatch_msi(node, i);
  224. return;
  225. }
  226. if (i >= PIC_PCIE_MSIX_IRQ(0) && i <= PIC_PCIE_MSIX_IRQ(3)) {
  227. nlm_dispatch_msix(node, i);
  228. return;
  229. }
  230. #endif
  231. /* top level irq handling */
  232. do_IRQ(nlm_irq_to_xirq(node, i));
  233. }
  234. #ifdef CONFIG_OF
  235. static const struct irq_domain_ops xlp_pic_irq_domain_ops = {
  236. .xlate = irq_domain_xlate_onetwocell,
  237. };
  238. static int __init xlp_of_pic_init(struct device_node *node,
  239. struct device_node *parent)
  240. {
  241. const int n_picirqs = PIC_IRT_LAST_IRQ - PIC_IRQ_BASE + 1;
  242. struct irq_domain *xlp_pic_domain;
  243. struct resource res;
  244. int socid, ret, bus;
  245. /* we need a hack to get the PIC's SoC chip id */
  246. ret = of_address_to_resource(node, 0, &res);
  247. if (ret < 0) {
  248. pr_err("PIC %s: reg property not found!\n", node->name);
  249. return -EINVAL;
  250. }
  251. if (cpu_is_xlp9xx()) {
  252. bus = (res.start >> 20) & 0xf;
  253. for (socid = 0; socid < NLM_NR_NODES; socid++) {
  254. if (!nlm_node_present(socid))
  255. continue;
  256. if (nlm_get_node(socid)->socbus == bus)
  257. break;
  258. }
  259. if (socid == NLM_NR_NODES) {
  260. pr_err("PIC %s: Node mapping for bus %d not found!\n",
  261. node->name, bus);
  262. return -EINVAL;
  263. }
  264. } else {
  265. socid = (res.start >> 18) & 0x3;
  266. if (!nlm_node_present(socid)) {
  267. pr_err("PIC %s: node %d does not exist!\n",
  268. node->name, socid);
  269. return -EINVAL;
  270. }
  271. }
  272. if (!nlm_node_present(socid)) {
  273. pr_err("PIC %s: node %d does not exist!\n", node->name, socid);
  274. return -EINVAL;
  275. }
  276. xlp_pic_domain = irq_domain_add_legacy(node, n_picirqs,
  277. nlm_irq_to_xirq(socid, PIC_IRQ_BASE), PIC_IRQ_BASE,
  278. &xlp_pic_irq_domain_ops, NULL);
  279. if (xlp_pic_domain == NULL) {
  280. pr_err("PIC %s: Creating legacy domain failed!\n", node->name);
  281. return -EINVAL;
  282. }
  283. pr_info("Node %d: IRQ domain created for PIC@%pR\n", socid, &res);
  284. return 0;
  285. }
  286. static struct of_device_id __initdata xlp_pic_irq_ids[] = {
  287. { .compatible = "netlogic,xlp-pic", .data = xlp_of_pic_init },
  288. {},
  289. };
  290. #endif
  291. void __init arch_init_irq(void)
  292. {
  293. /* Initialize the irq descriptors */
  294. nlm_init_percpu_irqs();
  295. nlm_init_node_irqs(0);
  296. write_c0_eimr(nlm_current_node()->irqmask);
  297. #if defined(CONFIG_CPU_XLR)
  298. nlm_setup_fmn_irq();
  299. #endif
  300. #if defined(CONFIG_OF)
  301. of_irq_init(xlp_pic_irq_ids);
  302. #endif
  303. }