irq.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  11. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  12. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  13. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  14. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  15. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  16. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  17. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  18. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  19. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20. *
  21. * You should have received a copy of the GNU General Public License along
  22. * with this program; if not, write to the Free Software Foundation, Inc.,
  23. * 675 Mass Ave, Cambridge, MA 02139, USA.
  24. *
  25. */
  26. #include <linux/delay.h>
  27. #include <linux/io.h>
  28. #include <linux/irq.h>
  29. #include <linux/init.h>
  30. #include <linux/interrupt.h>
  31. #include <linux/irq.h>
  32. #include <asm/irq_cpu.h>
  33. #include <asm/i8259.h>
  34. #include <asm/mipsregs.h>
  35. #include <asm/mips-boards/bonito64.h>
  36. /*
  37. * the first level int-handler will jump here if it is a bonito irq
  38. */
  39. static void bonito_irqdispatch(void)
  40. {
  41. u32 int_status;
  42. int i;
  43. /* workaround the IO dma problem: let cpu looping to allow DMA finish */
  44. int_status = BONITO_INTISR;
  45. if (int_status & (1 << 10)) {
  46. while (int_status & (1 << 10)) {
  47. udelay(1);
  48. int_status = BONITO_INTISR;
  49. }
  50. }
  51. /* Get pending sources, masked by current enables */
  52. int_status = BONITO_INTISR & BONITO_INTEN;
  53. if (int_status != 0) {
  54. i = __ffs(int_status);
  55. int_status &= ~(1 << i);
  56. do_IRQ(BONITO_IRQ_BASE + i);
  57. }
  58. }
  59. static void i8259_irqdispatch(void)
  60. {
  61. int irq;
  62. irq = i8259_irq();
  63. if (irq >= 0) {
  64. do_IRQ(irq);
  65. } else {
  66. spurious_interrupt();
  67. }
  68. }
  69. asmlinkage void plat_irq_dispatch(void)
  70. {
  71. unsigned int pending = read_c0_cause() & read_c0_status() & ST0_IM;
  72. if (pending & CAUSEF_IP7) {
  73. do_IRQ(MIPS_CPU_IRQ_BASE + 7);
  74. } else if (pending & CAUSEF_IP5) {
  75. i8259_irqdispatch();
  76. } else if (pending & CAUSEF_IP2) {
  77. bonito_irqdispatch();
  78. } else {
  79. spurious_interrupt();
  80. }
  81. }
  82. static struct irqaction cascade_irqaction = {
  83. .handler = no_action,
  84. .mask = CPU_MASK_NONE,
  85. .name = "cascade",
  86. };
  87. void __init arch_init_irq(void)
  88. {
  89. extern void bonito_irq_init(void);
  90. /*
  91. * Clear all of the interrupts while we change the able around a bit.
  92. * int-handler is not on bootstrap
  93. */
  94. clear_c0_status(ST0_IM | ST0_BEV);
  95. local_irq_disable();
  96. /* most bonito irq should be level triggered */
  97. BONITO_INTEDGE = BONITO_ICU_SYSTEMERR | BONITO_ICU_MASTERERR |
  98. BONITO_ICU_RETRYERR | BONITO_ICU_MBOXES;
  99. BONITO_INTSTEER = 0;
  100. /*
  101. * Mask out all interrupt by writing "1" to all bit position in
  102. * the interrupt reset reg.
  103. */
  104. BONITO_INTENCLR = ~0;
  105. /* init all controller
  106. * 0-15 ------> i8259 interrupt
  107. * 16-23 ------> mips cpu interrupt
  108. * 32-63 ------> bonito irq
  109. */
  110. /* Sets the first-level interrupt dispatcher. */
  111. mips_cpu_irq_init();
  112. init_i8259_irqs();
  113. bonito_irq_init();
  114. /*
  115. printk("GPIODATA=%x, GPIOIE=%x\n", BONITO_GPIODATA, BONITO_GPIOIE);
  116. printk("INTEN=%x, INTSET=%x, INTCLR=%x, INTISR=%x\n",
  117. BONITO_INTEN, BONITO_INTENSET,
  118. BONITO_INTENCLR, BONITO_INTISR);
  119. */
  120. /* bonito irq at IP2 */
  121. setup_irq(MIPS_CPU_IRQ_BASE + 2, &cascade_irqaction);
  122. /* 8259 irq at IP5 */
  123. setup_irq(MIPS_CPU_IRQ_BASE + 5, &cascade_irqaction);
  124. }