irq.c 3.6 KB

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