asic_int.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Carsten Langgaard, carstenl@mips.com
  3. * Copyright (C) 2000, 2001, 2004 MIPS Technologies, Inc.
  4. * Copyright (C) 2001 Ralf Baechle
  5. * Portions copyright (C) 2009 Cisco Systems, Inc.
  6. *
  7. * This program is free software; you can distribute it and/or modify it
  8. * under the terms of the GNU General Public License (Version 2) as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  14. * for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  19. *
  20. * Routines for generic manipulation of the interrupts found on the PowerTV
  21. * platform.
  22. *
  23. * The interrupt controller is located in the South Bridge a PIIX4 device
  24. * with two internal 82C95 interrupt controllers.
  25. */
  26. #include <linux/init.h>
  27. #include <linux/irq.h>
  28. #include <linux/sched.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/kernel_stat.h>
  31. #include <linux/kernel.h>
  32. #include <linux/random.h>
  33. #include <asm/irq_cpu.h>
  34. #include <linux/io.h>
  35. #include <asm/irq_regs.h>
  36. #include <asm/setup.h>
  37. #include <asm/mips-boards/generic.h>
  38. #include <asm/mach-powertv/asic_regs.h>
  39. static DEFINE_RAW_SPINLOCK(asic_irq_lock);
  40. static inline int get_int(void)
  41. {
  42. unsigned long flags;
  43. int irq;
  44. raw_spin_lock_irqsave(&asic_irq_lock, flags);
  45. irq = (asic_read(int_int_scan) >> 4) - 1;
  46. if (irq == 0 || irq >= NR_IRQS)
  47. irq = -1;
  48. raw_spin_unlock_irqrestore(&asic_irq_lock, flags);
  49. return irq;
  50. }
  51. static void asic_irqdispatch(void)
  52. {
  53. int irq;
  54. irq = get_int();
  55. if (irq < 0)
  56. return; /* interrupt has already been cleared */
  57. do_IRQ(irq);
  58. }
  59. static inline int clz(unsigned long x)
  60. {
  61. __asm__(
  62. " .set push \n"
  63. " .set mips32 \n"
  64. " clz %0, %1 \n"
  65. " .set pop \n"
  66. : "=r" (x)
  67. : "r" (x));
  68. return x;
  69. }
  70. /*
  71. * Version of ffs that only looks at bits 12..15.
  72. */
  73. static inline unsigned int irq_ffs(unsigned int pending)
  74. {
  75. return fls(pending) - 1 + CAUSEB_IP;
  76. }
  77. /*
  78. * TODO: check how it works under EIC mode.
  79. */
  80. asmlinkage void plat_irq_dispatch(void)
  81. {
  82. unsigned int pending = read_c0_cause() & read_c0_status() & ST0_IM;
  83. int irq;
  84. irq = irq_ffs(pending);
  85. if (irq == CAUSEF_IP3)
  86. asic_irqdispatch();
  87. else if (irq >= 0)
  88. do_IRQ(irq);
  89. else
  90. spurious_interrupt();
  91. }
  92. void __init arch_init_irq(void)
  93. {
  94. int i;
  95. asic_irq_init();
  96. /*
  97. * Initialize interrupt exception vectors.
  98. */
  99. if (cpu_has_veic || cpu_has_vint) {
  100. int nvec = cpu_has_veic ? 64 : 8;
  101. for (i = 0; i < nvec; i++)
  102. set_vi_handler(i, asic_irqdispatch);
  103. }
  104. }