irq.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (C) 2007 Lemote Inc. & Insititute of Computing Technology
  3. * Author: Fuxin Zhang, zhangfx@lemote.com
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. */
  10. #include <linux/delay.h>
  11. #include <linux/interrupt.h>
  12. #include <asm/irq_cpu.h>
  13. #include <asm/i8259.h>
  14. #include <loongson.h>
  15. /*
  16. * the first level int-handler will jump here if it is a bonito irq
  17. */
  18. static void bonito_irqdispatch(void)
  19. {
  20. u32 int_status;
  21. int i;
  22. /* workaround the IO dma problem: let cpu looping to allow DMA finish */
  23. int_status = BONITO_INTISR;
  24. if (int_status & (1 << 10)) {
  25. while (int_status & (1 << 10)) {
  26. udelay(1);
  27. int_status = BONITO_INTISR;
  28. }
  29. }
  30. /* Get pending sources, masked by current enables */
  31. int_status = BONITO_INTISR & BONITO_INTEN;
  32. if (int_status != 0) {
  33. i = __ffs(int_status);
  34. int_status &= ~(1 << i);
  35. do_IRQ(BONITO_IRQ_BASE + i);
  36. }
  37. }
  38. static void i8259_irqdispatch(void)
  39. {
  40. int irq;
  41. irq = i8259_irq();
  42. if (irq >= 0)
  43. do_IRQ(irq);
  44. else
  45. spurious_interrupt();
  46. }
  47. asmlinkage void plat_irq_dispatch(void)
  48. {
  49. unsigned int pending = read_c0_cause() & read_c0_status() & ST0_IM;
  50. if (pending & CAUSEF_IP7)
  51. do_IRQ(MIPS_CPU_IRQ_BASE + 7);
  52. else if (pending & CAUSEF_IP5)
  53. i8259_irqdispatch();
  54. else if (pending & CAUSEF_IP2)
  55. bonito_irqdispatch();
  56. else
  57. spurious_interrupt();
  58. }
  59. static struct irqaction cascade_irqaction = {
  60. .handler = no_action,
  61. .name = "cascade",
  62. };
  63. void __init arch_init_irq(void)
  64. {
  65. /*
  66. * Clear all of the interrupts while we change the able around a bit.
  67. * int-handler is not on bootstrap
  68. */
  69. clear_c0_status(ST0_IM | ST0_BEV);
  70. local_irq_disable();
  71. /* most bonito irq should be level triggered */
  72. BONITO_INTEDGE = BONITO_ICU_SYSTEMERR | BONITO_ICU_MASTERERR |
  73. BONITO_ICU_RETRYERR | BONITO_ICU_MBOXES;
  74. BONITO_INTSTEER = 0;
  75. /*
  76. * Mask out all interrupt by writing "1" to all bit position in
  77. * the interrupt reset reg.
  78. */
  79. BONITO_INTENCLR = ~0;
  80. /* init all controller
  81. * 0-15 ------> i8259 interrupt
  82. * 16-23 ------> mips cpu interrupt
  83. * 32-63 ------> bonito irq
  84. */
  85. /* Sets the first-level interrupt dispatcher. */
  86. mips_cpu_irq_init();
  87. init_i8259_irqs();
  88. bonito_irq_init();
  89. /* bonito irq at IP2 */
  90. setup_irq(MIPS_CPU_IRQ_BASE + 2, &cascade_irqaction);
  91. /* 8259 irq at IP5 */
  92. setup_irq(MIPS_CPU_IRQ_BASE + 5, &cascade_irqaction);
  93. }