intc-arcv2.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. /*
  16. * Early Hardware specific Interrupt setup
  17. * -Called very early (start_kernel -> setup_arch -> setup_processor)
  18. * -Platform Independent (must for any ARC Core)
  19. * -Needed for each CPU (hence not foldable into init_IRQ)
  20. */
  21. void arc_init_IRQ(void)
  22. {
  23. unsigned int tmp;
  24. struct aux_irq_ctrl {
  25. #ifdef CONFIG_CPU_BIG_ENDIAN
  26. unsigned int res3:18, save_idx_regs:1, res2:1,
  27. save_u_to_u:1, save_lp_regs:1, save_blink:1,
  28. res:4, save_nr_gpr_pairs:5;
  29. #else
  30. unsigned int save_nr_gpr_pairs:5, res:4,
  31. save_blink:1, save_lp_regs:1, save_u_to_u:1,
  32. res2:1, save_idx_regs:1, res3:18;
  33. #endif
  34. } ictrl;
  35. *(unsigned int *)&ictrl = 0;
  36. ictrl.save_nr_gpr_pairs = 6; /* r0 to r11 (r12 saved manually) */
  37. ictrl.save_blink = 1;
  38. ictrl.save_lp_regs = 1; /* LP_COUNT, LP_START, LP_END */
  39. ictrl.save_u_to_u = 0; /* user ctxt saved on kernel stack */
  40. ictrl.save_idx_regs = 1; /* JLI, LDI, EI */
  41. WRITE_AUX(AUX_IRQ_CTRL, ictrl);
  42. /* setup status32, don't enable intr yet as kernel doesn't want */
  43. tmp = read_aux_reg(0xa);
  44. tmp |= ISA_INIT_STATUS_BITS;
  45. tmp &= ~STATUS_IE_MASK;
  46. asm volatile("flag %0 \n"::"r"(tmp));
  47. /*
  48. * ARCv2 core intc provides multiple interrupt priorities (upto 16).
  49. * Typical builds though have only two levels (0-high, 1-low)
  50. * Linux by default uses lower prio 1 for most irqs, reserving 0 for
  51. * NMI style interrupts in future (say perf)
  52. *
  53. * Read the intc BCR to confirm that Linux default priority is avail
  54. * in h/w
  55. *
  56. * Note:
  57. * IRQ_BCR[27..24] contains N-1 (for N priority levels) and prio level
  58. * is 0 based.
  59. */
  60. tmp = (read_aux_reg(ARC_REG_IRQ_BCR) >> 24 ) & 0xF;
  61. if (ARCV2_IRQ_DEF_PRIO > tmp)
  62. panic("Linux default irq prio incorrect\n");
  63. }
  64. static void arcv2_irq_mask(struct irq_data *data)
  65. {
  66. write_aux_reg(AUX_IRQ_SELECT, data->irq);
  67. write_aux_reg(AUX_IRQ_ENABLE, 0);
  68. }
  69. static void arcv2_irq_unmask(struct irq_data *data)
  70. {
  71. write_aux_reg(AUX_IRQ_SELECT, data->irq);
  72. write_aux_reg(AUX_IRQ_ENABLE, 1);
  73. }
  74. void arcv2_irq_enable(struct irq_data *data)
  75. {
  76. /* set default priority */
  77. write_aux_reg(AUX_IRQ_SELECT, data->irq);
  78. write_aux_reg(AUX_IRQ_PRIORITY, ARCV2_IRQ_DEF_PRIO);
  79. /*
  80. * hw auto enables (linux unmask) all by default
  81. * So no need to do IRQ_ENABLE here
  82. * XXX: However OSCI LAN need it
  83. */
  84. write_aux_reg(AUX_IRQ_ENABLE, 1);
  85. }
  86. static struct irq_chip arcv2_irq_chip = {
  87. .name = "ARCv2 core Intc",
  88. .irq_mask = arcv2_irq_mask,
  89. .irq_unmask = arcv2_irq_unmask,
  90. .irq_enable = arcv2_irq_enable
  91. };
  92. static int arcv2_irq_map(struct irq_domain *d, unsigned int irq,
  93. irq_hw_number_t hw)
  94. {
  95. /*
  96. * core intc IRQs [16, 23]:
  97. * Statically assigned always private-per-core (Timers, WDT, IPI, PCT)
  98. */
  99. if (hw < 24) {
  100. /*
  101. * A subsequent request_percpu_irq() fails if percpu_devid is
  102. * not set. That in turns sets NOAUTOEN, meaning each core needs
  103. * to call enable_percpu_irq()
  104. */
  105. irq_set_percpu_devid(irq);
  106. irq_set_chip_and_handler(irq, &arcv2_irq_chip, handle_percpu_irq);
  107. } else {
  108. irq_set_chip_and_handler(irq, &arcv2_irq_chip, handle_level_irq);
  109. }
  110. return 0;
  111. }
  112. static const struct irq_domain_ops arcv2_irq_ops = {
  113. .xlate = irq_domain_xlate_onecell,
  114. .map = arcv2_irq_map,
  115. };
  116. static struct irq_domain *root_domain;
  117. static int __init
  118. init_onchip_IRQ(struct device_node *intc, struct device_node *parent)
  119. {
  120. if (parent)
  121. panic("DeviceTree incore intc not a root irq controller\n");
  122. root_domain = irq_domain_add_legacy(intc, NR_CPU_IRQS, 0, 0,
  123. &arcv2_irq_ops, NULL);
  124. if (!root_domain)
  125. panic("root irq domain not avail\n");
  126. /* with this we don't need to export root_domain */
  127. irq_set_default_host(root_domain);
  128. return 0;
  129. }
  130. IRQCHIP_DECLARE(arc_intc, "snps,archs-intc", init_onchip_IRQ);