sead3-int.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved.
  7. */
  8. #include <linux/init.h>
  9. #include <linux/irq.h>
  10. #include <linux/io.h>
  11. #include <asm/gic.h>
  12. #include <asm/irq_cpu.h>
  13. #include <asm/setup.h>
  14. #include <asm/mips-boards/sead3int.h>
  15. #define SEAD_CONFIG_GIC_PRESENT_SHF 1
  16. #define SEAD_CONFIG_GIC_PRESENT_MSK (1 << SEAD_CONFIG_GIC_PRESENT_SHF)
  17. #define SEAD_CONFIG_BASE 0x1b100110
  18. #define SEAD_CONFIG_SIZE 4
  19. static unsigned long sead3_config_reg;
  20. /*
  21. * This table defines the setup for each external GIC interrupt. It is
  22. * indexed by interrupt number.
  23. */
  24. #define GIC_CPU_NMI GIC_MAP_TO_NMI_MSK
  25. static struct gic_intr_map gic_intr_map[GIC_NUM_INTRS] = {
  26. { 0, GIC_CPU_INT4, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
  27. { 0, GIC_CPU_INT3, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
  28. { 0, GIC_CPU_INT2, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
  29. { 0, GIC_CPU_INT2, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
  30. { 0, GIC_CPU_INT1, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
  31. { 0, GIC_CPU_INT0, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
  32. { 0, GIC_CPU_INT0, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
  33. { 0, GIC_CPU_INT0, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
  34. { 0, GIC_CPU_INT0, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
  35. { GIC_UNUSED, GIC_UNUSED, GIC_UNUSED, GIC_UNUSED, GIC_UNUSED },
  36. { GIC_UNUSED, GIC_UNUSED, GIC_UNUSED, GIC_UNUSED, GIC_UNUSED },
  37. { GIC_UNUSED, GIC_UNUSED, GIC_UNUSED, GIC_UNUSED, GIC_UNUSED },
  38. { GIC_UNUSED, GIC_UNUSED, GIC_UNUSED, GIC_UNUSED, GIC_UNUSED },
  39. { GIC_UNUSED, GIC_UNUSED, GIC_UNUSED, GIC_UNUSED, GIC_UNUSED },
  40. { GIC_UNUSED, GIC_UNUSED, GIC_UNUSED, GIC_UNUSED, GIC_UNUSED },
  41. { GIC_UNUSED, GIC_UNUSED, GIC_UNUSED, GIC_UNUSED, GIC_UNUSED },
  42. };
  43. asmlinkage void plat_irq_dispatch(void)
  44. {
  45. unsigned int pending = read_c0_cause() & read_c0_status() & ST0_IM;
  46. int irq;
  47. irq = (fls(pending) - CAUSEB_IP - 1);
  48. if (irq >= 0)
  49. do_IRQ(MIPS_CPU_IRQ_BASE + irq);
  50. else
  51. spurious_interrupt();
  52. }
  53. void __init arch_init_irq(void)
  54. {
  55. int i;
  56. if (!cpu_has_veic) {
  57. mips_cpu_irq_init();
  58. if (cpu_has_vint) {
  59. /* install generic handler */
  60. for (i = 0; i < 8; i++)
  61. set_vi_handler(i, plat_irq_dispatch);
  62. }
  63. }
  64. sead3_config_reg = (unsigned long)ioremap_nocache(SEAD_CONFIG_BASE,
  65. SEAD_CONFIG_SIZE);
  66. gic_present = (REG32(sead3_config_reg) & SEAD_CONFIG_GIC_PRESENT_MSK) >>
  67. SEAD_CONFIG_GIC_PRESENT_SHF;
  68. pr_info("GIC: %spresent\n", (gic_present) ? "" : "not ");
  69. pr_info("EIC: %s\n",
  70. (current_cpu_data.options & MIPS_CPU_VEIC) ? "on" : "off");
  71. if (gic_present)
  72. gic_init(GIC_BASE_ADDR, GIC_ADDRSPACE_SZ, gic_intr_map,
  73. ARRAY_SIZE(gic_intr_map), MIPS_GIC_IRQ_BASE);
  74. }
  75. void gic_enable_interrupt(int irq_vec)
  76. {
  77. unsigned int i, irq_source;
  78. /* enable all the interrupts associated with this vector */
  79. for (i = 0; i < gic_shared_intr_map[irq_vec].num_shared_intr; i++) {
  80. irq_source = gic_shared_intr_map[irq_vec].intr_list[i];
  81. GIC_SET_INTR_MASK(irq_source);
  82. }
  83. /* enable all local interrupts associated with this vector */
  84. if (gic_shared_intr_map[irq_vec].local_intr_mask) {
  85. GICWRITE(GIC_REG(VPE_LOCAL, GIC_VPE_OTHER_ADDR), 0);
  86. GICWRITE(GIC_REG(VPE_OTHER, GIC_VPE_SMASK),
  87. gic_shared_intr_map[irq_vec].local_intr_mask);
  88. }
  89. }
  90. void gic_disable_interrupt(int irq_vec)
  91. {
  92. unsigned int i, irq_source;
  93. /* disable all the interrupts associated with this vector */
  94. for (i = 0; i < gic_shared_intr_map[irq_vec].num_shared_intr; i++) {
  95. irq_source = gic_shared_intr_map[irq_vec].intr_list[i];
  96. GIC_CLR_INTR_MASK(irq_source);
  97. }
  98. /* disable all local interrupts associated with this vector */
  99. if (gic_shared_intr_map[irq_vec].local_intr_mask) {
  100. GICWRITE(GIC_REG(VPE_LOCAL, GIC_VPE_OTHER_ADDR), 0);
  101. GICWRITE(GIC_REG(VPE_OTHER, GIC_VPE_RMASK),
  102. gic_shared_intr_map[irq_vec].local_intr_mask);
  103. }
  104. }
  105. void gic_irq_ack(struct irq_data *d)
  106. {
  107. GIC_CLR_INTR_MASK(d->irq - gic_irq_base);
  108. }
  109. void gic_finish_irq(struct irq_data *d)
  110. {
  111. unsigned int irq = (d->irq - gic_irq_base);
  112. unsigned int i, irq_source;
  113. /* Clear edge detectors. */
  114. for (i = 0; i < gic_shared_intr_map[irq].num_shared_intr; i++) {
  115. irq_source = gic_shared_intr_map[irq].intr_list[i];
  116. if (gic_irq_flags[irq_source] & GIC_TRIG_EDGE)
  117. GICWRITE(GIC_REG(SHARED, GIC_SH_WEDGE), irq_source);
  118. }
  119. /* Enable interrupts. */
  120. GIC_SET_INTR_MASK(irq);
  121. }
  122. void __init gic_platform_init(int irqs, struct irq_chip *irq_controller)
  123. {
  124. int i;
  125. /*
  126. * For non-EIC mode, we want to setup the GIC in pass-through
  127. * mode, as if the GIC didn't exist. Do not map any interrupts
  128. * for an external interrupt controller.
  129. */
  130. if (!cpu_has_veic)
  131. return;
  132. for (i = gic_irq_base; i < (gic_irq_base + irqs); i++)
  133. irq_set_chip_and_handler(i, irq_controller, handle_percpu_irq);
  134. }