sead3-int.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. int gic_present;
  20. static unsigned long sead3_config_reg;
  21. /*
  22. * This table defines the setup for each external GIC interrupt. It is
  23. * indexed by interrupt number.
  24. */
  25. #define GIC_CPU_NMI GIC_MAP_TO_NMI_MSK
  26. static struct gic_intr_map gic_intr_map[GIC_NUM_INTRS] = {
  27. { 0, GIC_CPU_INT4, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
  28. { 0, GIC_CPU_INT3, 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_INT2, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
  31. { 0, GIC_CPU_INT1, 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. { 0, GIC_CPU_INT0, GIC_POL_POS, GIC_TRIG_LEVEL, GIC_FLAG_TRANSPARENT },
  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. { GIC_UNUSED, GIC_UNUSED, GIC_UNUSED, GIC_UNUSED, GIC_UNUSED },
  43. };
  44. asmlinkage void plat_irq_dispatch(void)
  45. {
  46. unsigned int pending = read_c0_cause() & read_c0_status() & ST0_IM;
  47. int irq;
  48. irq = (fls(pending) - CAUSEB_IP - 1);
  49. if (irq >= 0)
  50. do_IRQ(MIPS_CPU_IRQ_BASE + irq);
  51. else
  52. spurious_interrupt();
  53. }
  54. void __init arch_init_irq(void)
  55. {
  56. int i;
  57. if (!cpu_has_veic) {
  58. mips_cpu_irq_init();
  59. if (cpu_has_vint) {
  60. /* install generic handler */
  61. for (i = 0; i < 8; i++)
  62. set_vi_handler(i, plat_irq_dispatch);
  63. }
  64. }
  65. sead3_config_reg = (unsigned long)ioremap_nocache(SEAD_CONFIG_BASE,
  66. SEAD_CONFIG_SIZE);
  67. gic_present = (REG32(sead3_config_reg) & SEAD_CONFIG_GIC_PRESENT_MSK) >>
  68. SEAD_CONFIG_GIC_PRESENT_SHF;
  69. pr_info("GIC: %spresent\n", (gic_present) ? "" : "not ");
  70. pr_info("EIC: %s\n",
  71. (current_cpu_data.options & MIPS_CPU_VEIC) ? "on" : "off");
  72. if (gic_present)
  73. gic_init(GIC_BASE_ADDR, GIC_ADDRSPACE_SZ, gic_intr_map,
  74. ARRAY_SIZE(gic_intr_map), MIPS_GIC_IRQ_BASE);
  75. }
  76. void gic_enable_interrupt(int irq_vec)
  77. {
  78. unsigned int i, irq_source;
  79. /* enable all the interrupts associated with this vector */
  80. for (i = 0; i < gic_shared_intr_map[irq_vec].num_shared_intr; i++) {
  81. irq_source = gic_shared_intr_map[irq_vec].intr_list[i];
  82. GIC_SET_INTR_MASK(irq_source);
  83. }
  84. /* enable all local interrupts associated with this vector */
  85. if (gic_shared_intr_map[irq_vec].local_intr_mask) {
  86. GICWRITE(GIC_REG(VPE_LOCAL, GIC_VPE_OTHER_ADDR), 0);
  87. GICWRITE(GIC_REG(VPE_OTHER, GIC_VPE_SMASK),
  88. gic_shared_intr_map[irq_vec].local_intr_mask);
  89. }
  90. }
  91. void gic_disable_interrupt(int irq_vec)
  92. {
  93. unsigned int i, irq_source;
  94. /* disable all the interrupts associated with this vector */
  95. for (i = 0; i < gic_shared_intr_map[irq_vec].num_shared_intr; i++) {
  96. irq_source = gic_shared_intr_map[irq_vec].intr_list[i];
  97. GIC_CLR_INTR_MASK(irq_source);
  98. }
  99. /* disable all local interrupts associated with this vector */
  100. if (gic_shared_intr_map[irq_vec].local_intr_mask) {
  101. GICWRITE(GIC_REG(VPE_LOCAL, GIC_VPE_OTHER_ADDR), 0);
  102. GICWRITE(GIC_REG(VPE_OTHER, GIC_VPE_RMASK),
  103. gic_shared_intr_map[irq_vec].local_intr_mask);
  104. }
  105. }
  106. void gic_irq_ack(struct irq_data *d)
  107. {
  108. GIC_CLR_INTR_MASK(d->irq - gic_irq_base);
  109. }
  110. void gic_finish_irq(struct irq_data *d)
  111. {
  112. unsigned int irq = (d->irq - gic_irq_base);
  113. unsigned int i, irq_source;
  114. /* Clear edge detectors. */
  115. for (i = 0; i < gic_shared_intr_map[irq].num_shared_intr; i++) {
  116. irq_source = gic_shared_intr_map[irq].intr_list[i];
  117. if (gic_irq_flags[irq_source] & GIC_TRIG_EDGE)
  118. GICWRITE(GIC_REG(SHARED, GIC_SH_WEDGE), irq_source);
  119. }
  120. /* Enable interrupts. */
  121. GIC_SET_INTR_MASK(irq);
  122. }
  123. void __init gic_platform_init(int irqs, struct irq_chip *irq_controller)
  124. {
  125. int i;
  126. /*
  127. * For non-EIC mode, we want to setup the GIC in pass-through
  128. * mode, as if the GIC didn't exist. Do not map any interrupts
  129. * for an external interrupt controller.
  130. */
  131. if (!cpu_has_veic)
  132. return;
  133. for (i = gic_irq_base; i < (gic_irq_base + irqs); i++)
  134. irq_set_chip_and_handler(i, irq_controller, handle_percpu_irq);
  135. }