intc-arcv2.c 5.3 KB

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