irq.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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_chip_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_chip_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_chip_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_chip_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_chip_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_chip_data(xirq);
  176. if (WARN_ON(!pic_data))
  177. return;
  178. pic_data->extra_ack = xack;
  179. }
  180. static void nlm_init_node_irqs(int node)
  181. {
  182. struct nlm_soc_info *nodep;
  183. int i, irt;
  184. pr_info("Init IRQ for node %d\n", node);
  185. nodep = nlm_get_node(node);
  186. nodep->irqmask = PERCPU_IRQ_MASK;
  187. for (i = PIC_IRT_FIRST_IRQ; i <= PIC_IRT_LAST_IRQ; i++) {
  188. irt = nlm_irq_to_irt(i);
  189. if (irt == -1) /* unused irq */
  190. continue;
  191. nodep->irqmask |= 1ull << i;
  192. if (irt == -2) /* not a direct PIC irq */
  193. continue;
  194. nlm_pic_init_irt(nodep->picbase, irt, i,
  195. node * nlm_threads_per_node(), 0);
  196. nlm_setup_pic_irq(node, i, i, irt);
  197. }
  198. }
  199. void nlm_smp_irq_init(int hwtid)
  200. {
  201. int cpu, node;
  202. cpu = hwtid % nlm_threads_per_node();
  203. node = hwtid / nlm_threads_per_node();
  204. if (cpu == 0 && node != 0)
  205. nlm_init_node_irqs(node);
  206. write_c0_eimr(nlm_get_node(node)->irqmask);
  207. }
  208. asmlinkage void plat_irq_dispatch(void)
  209. {
  210. uint64_t eirr;
  211. int i, node;
  212. node = nlm_nodeid();
  213. eirr = read_c0_eirr_and_eimr();
  214. if (eirr == 0)
  215. return;
  216. i = __ffs64(eirr);
  217. /* per-CPU IRQs don't need translation */
  218. if (i < PIC_IRQ_BASE) {
  219. do_IRQ(i);
  220. return;
  221. }
  222. #if defined(CONFIG_PCI_MSI) && defined(CONFIG_CPU_XLP)
  223. /* PCI interrupts need a second level dispatch for MSI bits */
  224. if (i >= PIC_PCIE_LINK_MSI_IRQ(0) && i <= PIC_PCIE_LINK_MSI_IRQ(3)) {
  225. nlm_dispatch_msi(node, i);
  226. return;
  227. }
  228. if (i >= PIC_PCIE_MSIX_IRQ(0) && i <= PIC_PCIE_MSIX_IRQ(3)) {
  229. nlm_dispatch_msix(node, i);
  230. return;
  231. }
  232. #endif
  233. /* top level irq handling */
  234. do_IRQ(nlm_irq_to_xirq(node, i));
  235. }
  236. #ifdef CONFIG_CPU_XLP
  237. static const struct irq_domain_ops xlp_pic_irq_domain_ops = {
  238. .xlate = irq_domain_xlate_onetwocell,
  239. };
  240. static int __init xlp_of_pic_init(struct device_node *node,
  241. struct device_node *parent)
  242. {
  243. const int n_picirqs = PIC_IRT_LAST_IRQ - PIC_IRQ_BASE + 1;
  244. struct irq_domain *xlp_pic_domain;
  245. struct resource res;
  246. int socid, ret, bus;
  247. /* we need a hack to get the PIC's SoC chip id */
  248. ret = of_address_to_resource(node, 0, &res);
  249. if (ret < 0) {
  250. pr_err("PIC %s: reg property not found!\n", node->name);
  251. return -EINVAL;
  252. }
  253. if (cpu_is_xlp9xx()) {
  254. bus = (res.start >> 20) & 0xf;
  255. for (socid = 0; socid < NLM_NR_NODES; socid++) {
  256. if (!nlm_node_present(socid))
  257. continue;
  258. if (nlm_get_node(socid)->socbus == bus)
  259. break;
  260. }
  261. if (socid == NLM_NR_NODES) {
  262. pr_err("PIC %s: Node mapping for bus %d not found!\n",
  263. node->name, bus);
  264. return -EINVAL;
  265. }
  266. } else {
  267. socid = (res.start >> 18) & 0x3;
  268. if (!nlm_node_present(socid)) {
  269. pr_err("PIC %s: node %d does not exist!\n",
  270. node->name, socid);
  271. return -EINVAL;
  272. }
  273. }
  274. if (!nlm_node_present(socid)) {
  275. pr_err("PIC %s: node %d does not exist!\n", node->name, socid);
  276. return -EINVAL;
  277. }
  278. xlp_pic_domain = irq_domain_add_legacy(node, n_picirqs,
  279. nlm_irq_to_xirq(socid, PIC_IRQ_BASE), PIC_IRQ_BASE,
  280. &xlp_pic_irq_domain_ops, NULL);
  281. if (xlp_pic_domain == NULL) {
  282. pr_err("PIC %s: Creating legacy domain failed!\n", node->name);
  283. return -EINVAL;
  284. }
  285. pr_info("Node %d: IRQ domain created for PIC@%pR\n", socid, &res);
  286. return 0;
  287. }
  288. static struct of_device_id __initdata xlp_pic_irq_ids[] = {
  289. { .compatible = "netlogic,xlp-pic", .data = xlp_of_pic_init },
  290. {},
  291. };
  292. #endif
  293. void __init arch_init_irq(void)
  294. {
  295. /* Initialize the irq descriptors */
  296. nlm_init_percpu_irqs();
  297. nlm_init_node_irqs(0);
  298. write_c0_eimr(nlm_current_node()->irqmask);
  299. #if defined(CONFIG_CPU_XLR)
  300. nlm_setup_fmn_irq();
  301. #endif
  302. #ifdef CONFIG_CPU_XLP
  303. of_irq_init(xlp_pic_irq_ids);
  304. #endif
  305. }