irq-armada-370-xp.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * Marvell Armada 370 and Armada XP SoC IRQ handling
  3. *
  4. * Copyright (C) 2012 Marvell
  5. *
  6. * Lior Amsalem <alior@marvell.com>
  7. * Gregory CLEMENT <gregory.clement@free-electrons.com>
  8. * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  9. * Ben Dooks <ben.dooks@codethink.co.uk>
  10. *
  11. * This file is licensed under the terms of the GNU General Public
  12. * License version 2. This program is licensed "as is" without any
  13. * warranty of any kind, whether express or implied.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/module.h>
  17. #include <linux/init.h>
  18. #include <linux/irq.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/io.h>
  21. #include <linux/of_address.h>
  22. #include <linux/of_irq.h>
  23. #include <linux/irqdomain.h>
  24. #include <asm/mach/arch.h>
  25. #include <asm/exception.h>
  26. #include <asm/smp_plat.h>
  27. #include <asm/hardware/cache-l2x0.h>
  28. /* Interrupt Controller Registers Map */
  29. #define ARMADA_370_XP_INT_SET_MASK_OFFS (0x48)
  30. #define ARMADA_370_XP_INT_CLEAR_MASK_OFFS (0x4C)
  31. #define ARMADA_370_XP_INT_CONTROL (0x00)
  32. #define ARMADA_370_XP_INT_SET_ENABLE_OFFS (0x30)
  33. #define ARMADA_370_XP_INT_CLEAR_ENABLE_OFFS (0x34)
  34. #define ARMADA_370_XP_CPU_INTACK_OFFS (0x44)
  35. #define ARMADA_370_XP_SW_TRIG_INT_OFFS (0x4)
  36. #define ARMADA_370_XP_IN_DRBEL_MSK_OFFS (0xc)
  37. #define ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS (0x8)
  38. #define ACTIVE_DOORBELLS (8)
  39. static void __iomem *per_cpu_int_base;
  40. static void __iomem *main_int_base;
  41. static struct irq_domain *armada_370_xp_mpic_domain;
  42. static void armada_370_xp_irq_mask(struct irq_data *d)
  43. {
  44. writel(irqd_to_hwirq(d),
  45. per_cpu_int_base + ARMADA_370_XP_INT_SET_MASK_OFFS);
  46. }
  47. static void armada_370_xp_irq_unmask(struct irq_data *d)
  48. {
  49. writel(irqd_to_hwirq(d),
  50. per_cpu_int_base + ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
  51. }
  52. #ifdef CONFIG_SMP
  53. static int armada_xp_set_affinity(struct irq_data *d,
  54. const struct cpumask *mask_val, bool force)
  55. {
  56. return 0;
  57. }
  58. #endif
  59. static struct irq_chip armada_370_xp_irq_chip = {
  60. .name = "armada_370_xp_irq",
  61. .irq_mask = armada_370_xp_irq_mask,
  62. .irq_mask_ack = armada_370_xp_irq_mask,
  63. .irq_unmask = armada_370_xp_irq_unmask,
  64. #ifdef CONFIG_SMP
  65. .irq_set_affinity = armada_xp_set_affinity,
  66. #endif
  67. };
  68. static int armada_370_xp_mpic_irq_map(struct irq_domain *h,
  69. unsigned int virq, irq_hw_number_t hw)
  70. {
  71. armada_370_xp_irq_mask(irq_get_irq_data(virq));
  72. writel(hw, main_int_base + ARMADA_370_XP_INT_SET_ENABLE_OFFS);
  73. irq_set_chip_and_handler(virq, &armada_370_xp_irq_chip,
  74. handle_level_irq);
  75. irq_set_status_flags(virq, IRQ_LEVEL);
  76. set_irq_flags(virq, IRQF_VALID | IRQF_PROBE);
  77. return 0;
  78. }
  79. #ifdef CONFIG_SMP
  80. void armada_mpic_send_doorbell(const struct cpumask *mask, unsigned int irq)
  81. {
  82. int cpu;
  83. unsigned long map = 0;
  84. /* Convert our logical CPU mask into a physical one. */
  85. for_each_cpu(cpu, mask)
  86. map |= 1 << cpu_logical_map(cpu);
  87. /*
  88. * Ensure that stores to Normal memory are visible to the
  89. * other CPUs before issuing the IPI.
  90. */
  91. dsb();
  92. /* submit softirq */
  93. writel((map << 8) | irq, main_int_base +
  94. ARMADA_370_XP_SW_TRIG_INT_OFFS);
  95. }
  96. void armada_xp_mpic_smp_cpu_init(void)
  97. {
  98. /* Clear pending IPIs */
  99. writel(0, per_cpu_int_base + ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS);
  100. /* Enable first 8 IPIs */
  101. writel((1 << ACTIVE_DOORBELLS) - 1, per_cpu_int_base +
  102. ARMADA_370_XP_IN_DRBEL_MSK_OFFS);
  103. /* Unmask IPI interrupt */
  104. writel(0, per_cpu_int_base + ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
  105. }
  106. #endif /* CONFIG_SMP */
  107. static struct irq_domain_ops armada_370_xp_mpic_irq_ops = {
  108. .map = armada_370_xp_mpic_irq_map,
  109. .xlate = irq_domain_xlate_onecell,
  110. };
  111. static int __init armada_370_xp_mpic_of_init(struct device_node *node,
  112. struct device_node *parent)
  113. {
  114. u32 control;
  115. main_int_base = of_iomap(node, 0);
  116. per_cpu_int_base = of_iomap(node, 1);
  117. BUG_ON(!main_int_base);
  118. BUG_ON(!per_cpu_int_base);
  119. control = readl(main_int_base + ARMADA_370_XP_INT_CONTROL);
  120. armada_370_xp_mpic_domain =
  121. irq_domain_add_linear(node, (control >> 2) & 0x3ff,
  122. &armada_370_xp_mpic_irq_ops, NULL);
  123. if (!armada_370_xp_mpic_domain)
  124. panic("Unable to add Armada_370_Xp MPIC irq domain (DT)\n");
  125. irq_set_default_host(armada_370_xp_mpic_domain);
  126. #ifdef CONFIG_SMP
  127. armada_xp_mpic_smp_cpu_init();
  128. #endif
  129. return 0;
  130. }
  131. asmlinkage void __exception_irq_entry armada_370_xp_handle_irq(struct pt_regs
  132. *regs)
  133. {
  134. u32 irqstat, irqnr;
  135. do {
  136. irqstat = readl_relaxed(per_cpu_int_base +
  137. ARMADA_370_XP_CPU_INTACK_OFFS);
  138. irqnr = irqstat & 0x3FF;
  139. if (irqnr > 1022)
  140. break;
  141. if (irqnr >= 8) {
  142. irqnr = irq_find_mapping(armada_370_xp_mpic_domain,
  143. irqnr);
  144. handle_IRQ(irqnr, regs);
  145. continue;
  146. }
  147. #ifdef CONFIG_SMP
  148. /* IPI Handling */
  149. if (irqnr == 0) {
  150. u32 ipimask, ipinr;
  151. ipimask = readl_relaxed(per_cpu_int_base +
  152. ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS)
  153. & 0xFF;
  154. writel(0x0, per_cpu_int_base +
  155. ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS);
  156. /* Handle all pending doorbells */
  157. for (ipinr = 0; ipinr < ACTIVE_DOORBELLS; ipinr++) {
  158. if (ipimask & (0x1 << ipinr))
  159. handle_IPI(ipinr, regs);
  160. }
  161. continue;
  162. }
  163. #endif
  164. } while (1);
  165. }
  166. static const struct of_device_id mpic_of_match[] __initconst = {
  167. {.compatible = "marvell,mpic", .data = armada_370_xp_mpic_of_init},
  168. {},
  169. };
  170. void __init armada_370_xp_init_irq(void)
  171. {
  172. of_irq_init(mpic_of_match);
  173. #ifdef CONFIG_CACHE_L2X0
  174. l2x0_of_init(0, ~0UL);
  175. #endif
  176. }