irq.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #include <loongson.h>
  2. #include <irq.h>
  3. #include <linux/interrupt.h>
  4. #include <linux/module.h>
  5. #include <asm/irq_cpu.h>
  6. #include <asm/i8259.h>
  7. #include <asm/mipsregs.h>
  8. #include "smp.h"
  9. unsigned int ht_irq[] = {0, 1, 3, 4, 5, 6, 7, 8, 12, 14, 15};
  10. static void ht_irqdispatch(void)
  11. {
  12. unsigned int i, irq;
  13. irq = LOONGSON_HT1_INT_VECTOR(0);
  14. LOONGSON_HT1_INT_VECTOR(0) = irq; /* Acknowledge the IRQs */
  15. for (i = 0; i < ARRAY_SIZE(ht_irq); i++) {
  16. if (irq & (0x1 << ht_irq[i]))
  17. do_IRQ(ht_irq[i]);
  18. }
  19. }
  20. #define UNUSED_IPS (CAUSEF_IP5 | CAUSEF_IP4 | CAUSEF_IP1 | CAUSEF_IP0)
  21. void mach_irq_dispatch(unsigned int pending)
  22. {
  23. if (pending & CAUSEF_IP7)
  24. do_IRQ(LOONGSON_TIMER_IRQ);
  25. #if defined(CONFIG_SMP)
  26. if (pending & CAUSEF_IP6)
  27. loongson3_ipi_interrupt(NULL);
  28. #endif
  29. if (pending & CAUSEF_IP3)
  30. ht_irqdispatch();
  31. if (pending & CAUSEF_IP2)
  32. do_IRQ(LOONGSON_UART_IRQ);
  33. if (pending & UNUSED_IPS) {
  34. pr_err("%s : spurious interrupt\n", __func__);
  35. spurious_interrupt();
  36. }
  37. }
  38. static struct irqaction cascade_irqaction = {
  39. .handler = no_action,
  40. .flags = IRQF_NO_SUSPEND,
  41. .name = "cascade",
  42. };
  43. static inline void mask_loongson_irq(struct irq_data *d)
  44. {
  45. clear_c0_status(0x100 << (d->irq - MIPS_CPU_IRQ_BASE));
  46. irq_disable_hazard();
  47. /* Workaround: UART IRQ may deliver to any core */
  48. if (d->irq == LOONGSON_UART_IRQ) {
  49. int cpu = smp_processor_id();
  50. int node_id = cpu_logical_map(cpu) / loongson_sysconf.cores_per_node;
  51. int core_id = cpu_logical_map(cpu) % loongson_sysconf.cores_per_node;
  52. u64 intenclr_addr = smp_group[node_id] |
  53. (u64)(&LOONGSON_INT_ROUTER_INTENCLR);
  54. u64 introuter_lpc_addr = smp_group[node_id] |
  55. (u64)(&LOONGSON_INT_ROUTER_LPC);
  56. *(volatile u32 *)intenclr_addr = 1 << 10;
  57. *(volatile u8 *)introuter_lpc_addr = 0x10 + (1<<core_id);
  58. }
  59. }
  60. static inline void unmask_loongson_irq(struct irq_data *d)
  61. {
  62. /* Workaround: UART IRQ may deliver to any core */
  63. if (d->irq == LOONGSON_UART_IRQ) {
  64. int cpu = smp_processor_id();
  65. int node_id = cpu_logical_map(cpu) / loongson_sysconf.cores_per_node;
  66. int core_id = cpu_logical_map(cpu) % loongson_sysconf.cores_per_node;
  67. u64 intenset_addr = smp_group[node_id] |
  68. (u64)(&LOONGSON_INT_ROUTER_INTENSET);
  69. u64 introuter_lpc_addr = smp_group[node_id] |
  70. (u64)(&LOONGSON_INT_ROUTER_LPC);
  71. *(volatile u32 *)intenset_addr = 1 << 10;
  72. *(volatile u8 *)introuter_lpc_addr = 0x10 + (1<<core_id);
  73. }
  74. set_c0_status(0x100 << (d->irq - MIPS_CPU_IRQ_BASE));
  75. irq_enable_hazard();
  76. }
  77. /* For MIPS IRQs which shared by all cores */
  78. static struct irq_chip loongson_irq_chip = {
  79. .name = "Loongson",
  80. .irq_ack = mask_loongson_irq,
  81. .irq_mask = mask_loongson_irq,
  82. .irq_mask_ack = mask_loongson_irq,
  83. .irq_unmask = unmask_loongson_irq,
  84. .irq_eoi = unmask_loongson_irq,
  85. };
  86. void irq_router_init(void)
  87. {
  88. int i;
  89. /* route LPC int to cpu core0 int 0 */
  90. LOONGSON_INT_ROUTER_LPC =
  91. LOONGSON_INT_COREx_INTy(loongson_sysconf.boot_cpu_id, 0);
  92. /* route HT1 int0 ~ int7 to cpu core0 INT1*/
  93. for (i = 0; i < 8; i++)
  94. LOONGSON_INT_ROUTER_HT1(i) =
  95. LOONGSON_INT_COREx_INTy(loongson_sysconf.boot_cpu_id, 1);
  96. /* enable HT1 interrupt */
  97. LOONGSON_HT1_INTN_EN(0) = 0xffffffff;
  98. /* enable router interrupt intenset */
  99. LOONGSON_INT_ROUTER_INTENSET =
  100. LOONGSON_INT_ROUTER_INTEN | (0xffff << 16) | 0x1 << 10;
  101. }
  102. void __init mach_init_irq(void)
  103. {
  104. clear_c0_status(ST0_IM | ST0_BEV);
  105. irq_router_init();
  106. mips_cpu_irq_init();
  107. init_i8259_irqs();
  108. irq_set_chip_and_handler(LOONGSON_UART_IRQ,
  109. &loongson_irq_chip, handle_level_irq);
  110. /* setup HT1 irq */
  111. setup_irq(LOONGSON_HT1_IRQ, &cascade_irqaction);
  112. set_c0_status(STATUSF_IP2 | STATUSF_IP6);
  113. }
  114. #ifdef CONFIG_HOTPLUG_CPU
  115. void fixup_irqs(void)
  116. {
  117. irq_cpu_offline();
  118. clear_c0_status(ST0_IM);
  119. }
  120. #endif