irq.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Interrupt handing routines for NEC VR4100 series.
  3. *
  4. * Copyright (C) 2005 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
  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 <asm/irq_cpu.h>
  23. #include <asm/system.h>
  24. #include <asm/vr41xx/vr41xx.h>
  25. typedef struct irq_cascade {
  26. int (*get_irq)(unsigned int, struct pt_regs *);
  27. } irq_cascade_t;
  28. static irq_cascade_t irq_cascade[NR_IRQS] __cacheline_aligned;
  29. static struct irqaction cascade_irqaction = {
  30. .handler = no_action,
  31. .mask = CPU_MASK_NONE,
  32. .name = "cascade",
  33. };
  34. int cascade_irq(unsigned int irq, int (*get_irq)(unsigned int, struct pt_regs *))
  35. {
  36. int retval = 0;
  37. if (irq >= NR_IRQS)
  38. return -EINVAL;
  39. if (irq_cascade[irq].get_irq != NULL)
  40. free_irq(irq, NULL);
  41. irq_cascade[irq].get_irq = get_irq;
  42. if (get_irq != NULL) {
  43. retval = setup_irq(irq, &cascade_irqaction);
  44. if (retval < 0)
  45. irq_cascade[irq].get_irq = NULL;
  46. }
  47. return retval;
  48. }
  49. EXPORT_SYMBOL_GPL(cascade_irq);
  50. static void irq_dispatch(unsigned int irq, struct pt_regs *regs)
  51. {
  52. irq_cascade_t *cascade;
  53. irq_desc_t *desc;
  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. unsigned int source_irq = irq;
  61. desc = irq_desc + source_irq;
  62. desc->handler->ack(source_irq);
  63. irq = cascade->get_irq(irq, regs);
  64. if (irq < 0)
  65. atomic_inc(&irq_err_count);
  66. else
  67. irq_dispatch(irq, regs);
  68. desc->handler->end(source_irq);
  69. } else
  70. do_IRQ(irq, regs);
  71. }
  72. asmlinkage void plat_irq_dispatch(struct pt_regs *regs)
  73. {
  74. unsigned int pending = read_c0_cause() & read_c0_status() & ST0_IM;
  75. if (pending & CAUSEF_IP7)
  76. do_IRQ(7, regs);
  77. else if (pending & 0x7800) {
  78. if (pending & CAUSEF_IP3)
  79. irq_dispatch(3, regs);
  80. else if (pending & CAUSEF_IP4)
  81. irq_dispatch(4, regs);
  82. else if (pending & CAUSEF_IP5)
  83. irq_dispatch(5, regs);
  84. else if (pending & CAUSEF_IP6)
  85. irq_dispatch(6, regs);
  86. } else if (pending & CAUSEF_IP2)
  87. irq_dispatch(2, regs);
  88. else if (pending & CAUSEF_IP0)
  89. do_IRQ(0, regs);
  90. else if (pending & CAUSEF_IP1)
  91. do_IRQ(1, regs);
  92. else
  93. spurious_interrupt(regs);
  94. }
  95. void __init arch_init_irq(void)
  96. {
  97. mips_cpu_irq_init(MIPS_CPU_IRQ_BASE);
  98. }