irq.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Interrupt handing routines for NEC VR4100 series.
  3. *
  4. * Copyright (C) 2005-2007 Yoichi Yuasa <yuasa@linux-mips.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/interrupt.h>
  21. #include <linux/module.h>
  22. #include <linux/irq.h>
  23. #include <asm/irq_cpu.h>
  24. #include <asm/system.h>
  25. #include <asm/vr41xx/irq.h>
  26. typedef struct irq_cascade {
  27. int (*get_irq)(unsigned int);
  28. } irq_cascade_t;
  29. static irq_cascade_t irq_cascade[NR_IRQS] __cacheline_aligned;
  30. static struct irqaction cascade_irqaction = {
  31. .handler = no_action,
  32. .name = "cascade",
  33. .flags = IRQF_NO_THREAD,
  34. };
  35. int cascade_irq(unsigned int irq, int (*get_irq)(unsigned int))
  36. {
  37. int retval = 0;
  38. if (irq >= NR_IRQS)
  39. return -EINVAL;
  40. if (irq_cascade[irq].get_irq != NULL)
  41. free_irq(irq, NULL);
  42. irq_cascade[irq].get_irq = get_irq;
  43. if (get_irq != NULL) {
  44. retval = setup_irq(irq, &cascade_irqaction);
  45. if (retval < 0)
  46. irq_cascade[irq].get_irq = NULL;
  47. }
  48. return retval;
  49. }
  50. EXPORT_SYMBOL_GPL(cascade_irq);
  51. static void irq_dispatch(unsigned int irq)
  52. {
  53. irq_cascade_t *cascade;
  54. if (irq >= NR_IRQS) {
  55. atomic_inc(&irq_err_count);
  56. return;
  57. }
  58. cascade = irq_cascade + irq;
  59. if (cascade->get_irq != NULL) {
  60. struct irq_desc *desc = irq_to_desc(irq);
  61. struct irq_data *idata = irq_desc_get_irq_data(desc);
  62. struct irq_chip *chip = irq_desc_get_chip(desc);
  63. int ret;
  64. if (chip->irq_mask_ack)
  65. chip->irq_mask_ack(idata);
  66. else {
  67. chip->irq_mask(idata);
  68. chip->irq_ack(idata);
  69. }
  70. ret = cascade->get_irq(irq);
  71. irq = ret;
  72. if (ret < 0)
  73. atomic_inc(&irq_err_count);
  74. else
  75. irq_dispatch(irq);
  76. if (!irqd_irq_disabled(idata) && chip->irq_unmask)
  77. chip->irq_unmask(idata);
  78. } else
  79. do_IRQ(irq);
  80. }
  81. asmlinkage void plat_irq_dispatch(void)
  82. {
  83. unsigned int pending = read_c0_cause() & read_c0_status() & ST0_IM;
  84. if (pending & CAUSEF_IP7)
  85. do_IRQ(TIMER_IRQ);
  86. else if (pending & 0x7800) {
  87. if (pending & CAUSEF_IP3)
  88. irq_dispatch(INT1_IRQ);
  89. else if (pending & CAUSEF_IP4)
  90. irq_dispatch(INT2_IRQ);
  91. else if (pending & CAUSEF_IP5)
  92. irq_dispatch(INT3_IRQ);
  93. else if (pending & CAUSEF_IP6)
  94. irq_dispatch(INT4_IRQ);
  95. } else if (pending & CAUSEF_IP2)
  96. irq_dispatch(INT0_IRQ);
  97. else if (pending & CAUSEF_IP0)
  98. do_IRQ(MIPS_SOFTINT0_IRQ);
  99. else if (pending & CAUSEF_IP1)
  100. do_IRQ(MIPS_SOFTINT1_IRQ);
  101. else
  102. spurious_interrupt();
  103. }
  104. void __init arch_init_irq(void)
  105. {
  106. mips_cpu_irq_init();
  107. }