intc-arcv2.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2014 Synopsys, Inc. (www.synopsys.com)
  4. */
  5. #include <linux/interrupt.h>
  6. #include <linux/module.h>
  7. #include <linux/of.h>
  8. #include <linux/irqdomain.h>
  9. #include <linux/irqchip.h>
  10. #include <asm/irq.h>
  11. #define NR_EXCEPTIONS 16
  12. struct bcr_irq_arcv2 {
  13. #ifdef CONFIG_CPU_BIG_ENDIAN
  14. unsigned int pad:3, firq:1, prio:4, exts:8, irqs:8, ver:8;
  15. #else
  16. unsigned int ver:8, irqs:8, exts:8, prio:4, firq:1, pad:3;
  17. #endif
  18. };
  19. /*
  20. * Early Hardware specific Interrupt setup
  21. * -Called very early (start_kernel -> setup_arch -> setup_processor)
  22. * -Platform Independent (must for any ARC Core)
  23. * -Needed for each CPU (hence not foldable into init_IRQ)
  24. */
  25. void arc_init_IRQ(void)
  26. {
  27. unsigned int tmp, irq_prio, i;
  28. struct bcr_irq_arcv2 irq_bcr;
  29. struct aux_irq_ctrl {
  30. #ifdef CONFIG_CPU_BIG_ENDIAN
  31. unsigned int res3:18, save_idx_regs:1, res2:1,
  32. save_u_to_u:1, save_lp_regs:1, save_blink:1,
  33. res:4, save_nr_gpr_pairs:5;
  34. #else
  35. unsigned int save_nr_gpr_pairs:5, res:4,
  36. save_blink:1, save_lp_regs:1, save_u_to_u:1,
  37. res2:1, save_idx_regs:1, res3:18;
  38. #endif
  39. } ictrl;
  40. *(unsigned int *)&ictrl = 0;
  41. #ifndef CONFIG_ARC_IRQ_NO_AUTOSAVE
  42. ictrl.save_nr_gpr_pairs = 6; /* r0 to r11 (r12 saved manually) */
  43. ictrl.save_blink = 1;
  44. ictrl.save_lp_regs = 1; /* LP_COUNT, LP_START, LP_END */
  45. ictrl.save_u_to_u = 0; /* user ctxt saved on kernel stack */
  46. ictrl.save_idx_regs = 1; /* JLI, LDI, EI */
  47. #endif
  48. WRITE_AUX(AUX_IRQ_CTRL, ictrl);
  49. /*
  50. * ARCv2 core intc provides multiple interrupt priorities (upto 16).
  51. * Typical builds though have only two levels (0-high, 1-low)
  52. * Linux by default uses lower prio 1 for most irqs, reserving 0 for
  53. * NMI style interrupts in future (say perf)
  54. */
  55. READ_BCR(ARC_REG_IRQ_BCR, irq_bcr);
  56. irq_prio = irq_bcr.prio; /* Encoded as N-1 for N levels */
  57. pr_info("archs-intc\t: %d priority levels (default %d)%s\n",
  58. irq_prio + 1, ARCV2_IRQ_DEF_PRIO,
  59. irq_bcr.firq ? " FIRQ (not used)":"");
  60. /*
  61. * Set a default priority for all available interrupts to prevent
  62. * switching of register banks if Fast IRQ and multiple register banks
  63. * are supported by CPU.
  64. * Also disable private-per-core IRQ lines so faulty external HW won't
  65. * trigger interrupt that kernel is not ready to handle.
  66. */
  67. for (i = NR_EXCEPTIONS; i < irq_bcr.irqs + NR_EXCEPTIONS; i++) {
  68. write_aux_reg(AUX_IRQ_SELECT, i);
  69. write_aux_reg(AUX_IRQ_PRIORITY, ARCV2_IRQ_DEF_PRIO);
  70. /*
  71. * Only mask cpu private IRQs here.
  72. * "common" interrupts are masked at IDU, otherwise it would
  73. * need to be unmasked at each cpu, with IPIs
  74. */
  75. if (i < FIRST_EXT_IRQ)
  76. write_aux_reg(AUX_IRQ_ENABLE, 0);
  77. }
  78. /* setup status32, don't enable intr yet as kernel doesn't want */
  79. tmp = read_aux_reg(ARC_REG_STATUS32);
  80. tmp |= ARCV2_IRQ_DEF_PRIO << 1;
  81. tmp &= ~STATUS_IE_MASK;
  82. asm volatile("kflag %0 \n"::"r"(tmp));
  83. }
  84. static void arcv2_irq_mask(struct irq_data *data)
  85. {
  86. write_aux_reg(AUX_IRQ_SELECT, data->hwirq);
  87. write_aux_reg(AUX_IRQ_ENABLE, 0);
  88. }
  89. static void arcv2_irq_unmask(struct irq_data *data)
  90. {
  91. write_aux_reg(AUX_IRQ_SELECT, data->hwirq);
  92. write_aux_reg(AUX_IRQ_ENABLE, 1);
  93. }
  94. void arcv2_irq_enable(struct irq_data *data)
  95. {
  96. /* set default priority */
  97. write_aux_reg(AUX_IRQ_SELECT, data->hwirq);
  98. write_aux_reg(AUX_IRQ_PRIORITY, ARCV2_IRQ_DEF_PRIO);
  99. /*
  100. * hw auto enables (linux unmask) all by default
  101. * So no need to do IRQ_ENABLE here
  102. * XXX: However OSCI LAN need it
  103. */
  104. write_aux_reg(AUX_IRQ_ENABLE, 1);
  105. }
  106. static struct irq_chip arcv2_irq_chip = {
  107. .name = "ARCv2 core Intc",
  108. .irq_mask = arcv2_irq_mask,
  109. .irq_unmask = arcv2_irq_unmask,
  110. .irq_enable = arcv2_irq_enable
  111. };
  112. static int arcv2_irq_map(struct irq_domain *d, unsigned int irq,
  113. irq_hw_number_t hw)
  114. {
  115. /*
  116. * core intc IRQs [16, 23]:
  117. * Statically assigned always private-per-core (Timers, WDT, IPI, PCT)
  118. */
  119. if (hw < FIRST_EXT_IRQ) {
  120. /*
  121. * A subsequent request_percpu_irq() fails if percpu_devid is
  122. * not set. That in turns sets NOAUTOEN, meaning each core needs
  123. * to call enable_percpu_irq()
  124. */
  125. irq_set_percpu_devid(irq);
  126. irq_set_chip_and_handler(irq, &arcv2_irq_chip, handle_percpu_irq);
  127. } else {
  128. irq_set_chip_and_handler(irq, &arcv2_irq_chip, handle_level_irq);
  129. }
  130. return 0;
  131. }
  132. static const struct irq_domain_ops arcv2_irq_ops = {
  133. .xlate = irq_domain_xlate_onecell,
  134. .map = arcv2_irq_map,
  135. };
  136. static int __init
  137. init_onchip_IRQ(struct device_node *intc, struct device_node *parent)
  138. {
  139. struct irq_domain *root_domain;
  140. struct bcr_irq_arcv2 irq_bcr;
  141. unsigned int nr_cpu_irqs;
  142. READ_BCR(ARC_REG_IRQ_BCR, irq_bcr);
  143. nr_cpu_irqs = irq_bcr.irqs + NR_EXCEPTIONS;
  144. if (parent)
  145. panic("DeviceTree incore intc not a root irq controller\n");
  146. root_domain = irq_domain_add_linear(intc, nr_cpu_irqs, &arcv2_irq_ops, NULL);
  147. if (!root_domain)
  148. panic("root irq domain not avail\n");
  149. /*
  150. * Needed for primary domain lookup to succeed
  151. * This is a primary irqchip, and can never have a parent
  152. */
  153. irq_set_default_host(root_domain);
  154. #ifdef CONFIG_SMP
  155. irq_create_mapping(root_domain, IPI_IRQ);
  156. #endif
  157. irq_create_mapping(root_domain, SOFTIRQ_IRQ);
  158. return 0;
  159. }
  160. IRQCHIP_DECLARE(arc_intc, "snps,archs-intc", init_onchip_IRQ);