intc-arcv2.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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, irq_prio;
  24. struct irq_build {
  25. #ifdef CONFIG_CPU_BIG_ENDIAN
  26. unsigned int pad:3, firq:1, prio:4, exts:8, irqs:8, ver:8;
  27. #else
  28. unsigned int ver:8, irqs:8, exts:8, prio:4, firq:1, pad:3;
  29. #endif
  30. } irq_bcr;
  31. struct aux_irq_ctrl {
  32. #ifdef CONFIG_CPU_BIG_ENDIAN
  33. unsigned int res3:18, save_idx_regs:1, res2:1,
  34. save_u_to_u:1, save_lp_regs:1, save_blink:1,
  35. res:4, save_nr_gpr_pairs:5;
  36. #else
  37. unsigned int save_nr_gpr_pairs:5, res:4,
  38. save_blink:1, save_lp_regs:1, save_u_to_u:1,
  39. res2:1, save_idx_regs:1, res3:18;
  40. #endif
  41. } ictrl;
  42. *(unsigned int *)&ictrl = 0;
  43. ictrl.save_nr_gpr_pairs = 6; /* r0 to r11 (r12 saved manually) */
  44. ictrl.save_blink = 1;
  45. ictrl.save_lp_regs = 1; /* LP_COUNT, LP_START, LP_END */
  46. ictrl.save_u_to_u = 0; /* user ctxt saved on kernel stack */
  47. ictrl.save_idx_regs = 1; /* JLI, LDI, EI */
  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. /* setup status32, don't enable intr yet as kernel doesn't want */
  61. tmp = read_aux_reg(0xa);
  62. tmp |= STATUS_AD_MASK | (ARCV2_IRQ_DEF_PRIO << 1);
  63. tmp &= ~STATUS_IE_MASK;
  64. asm volatile("kflag %0 \n"::"r"(tmp));
  65. }
  66. static void arcv2_irq_mask(struct irq_data *data)
  67. {
  68. write_aux_reg(AUX_IRQ_SELECT, data->hwirq);
  69. write_aux_reg(AUX_IRQ_ENABLE, 0);
  70. }
  71. static void arcv2_irq_unmask(struct irq_data *data)
  72. {
  73. write_aux_reg(AUX_IRQ_SELECT, data->hwirq);
  74. write_aux_reg(AUX_IRQ_ENABLE, 1);
  75. }
  76. void arcv2_irq_enable(struct irq_data *data)
  77. {
  78. /* set default priority */
  79. write_aux_reg(AUX_IRQ_SELECT, data->hwirq);
  80. write_aux_reg(AUX_IRQ_PRIORITY, ARCV2_IRQ_DEF_PRIO);
  81. /*
  82. * hw auto enables (linux unmask) all by default
  83. * So no need to do IRQ_ENABLE here
  84. * XXX: However OSCI LAN need it
  85. */
  86. write_aux_reg(AUX_IRQ_ENABLE, 1);
  87. }
  88. static struct irq_chip arcv2_irq_chip = {
  89. .name = "ARCv2 core Intc",
  90. .irq_mask = arcv2_irq_mask,
  91. .irq_unmask = arcv2_irq_unmask,
  92. .irq_enable = arcv2_irq_enable
  93. };
  94. static int arcv2_irq_map(struct irq_domain *d, unsigned int irq,
  95. irq_hw_number_t hw)
  96. {
  97. /*
  98. * core intc IRQs [16, 23]:
  99. * Statically assigned always private-per-core (Timers, WDT, IPI, PCT)
  100. */
  101. if (hw < 24) {
  102. /*
  103. * A subsequent request_percpu_irq() fails if percpu_devid is
  104. * not set. That in turns sets NOAUTOEN, meaning each core needs
  105. * to call enable_percpu_irq()
  106. */
  107. irq_set_percpu_devid(irq);
  108. irq_set_chip_and_handler(irq, &arcv2_irq_chip, handle_percpu_irq);
  109. } else {
  110. irq_set_chip_and_handler(irq, &arcv2_irq_chip, handle_level_irq);
  111. }
  112. return 0;
  113. }
  114. static const struct irq_domain_ops arcv2_irq_ops = {
  115. .xlate = irq_domain_xlate_onecell,
  116. .map = arcv2_irq_map,
  117. };
  118. static int __init
  119. init_onchip_IRQ(struct device_node *intc, struct device_node *parent)
  120. {
  121. struct irq_domain *root_domain;
  122. if (parent)
  123. panic("DeviceTree incore intc not a root irq controller\n");
  124. root_domain = irq_domain_add_linear(intc, NR_CPU_IRQS, &arcv2_irq_ops, NULL);
  125. if (!root_domain)
  126. panic("root irq domain not avail\n");
  127. /*
  128. * Needed for primary domain lookup to succeed
  129. * This is a primary irqchip, and can never have a parent
  130. */
  131. irq_set_default_host(root_domain);
  132. #ifdef CONFIG_SMP
  133. irq_create_mapping(root_domain, IPI_IRQ);
  134. #endif
  135. irq_create_mapping(root_domain, SOFTIRQ_IRQ);
  136. return 0;
  137. }
  138. IRQCHIP_DECLARE(arc_intc, "snps,archs-intc", init_onchip_IRQ);