interrupt.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Carsten Langgaard, carstenl@mips.com
  3. * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
  4. *
  5. * This program is free software; you can distribute it and/or modify it
  6. * under the terms of the GNU General Public License (Version 2) as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  17. *
  18. * Routines for generic manipulation of the interrupts found on the
  19. * Lasat boards.
  20. */
  21. #include <linux/init.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/irq.h>
  24. #include <asm/irq_cpu.h>
  25. #include <asm/lasat/lasat.h>
  26. #include <asm/lasat/lasatint.h>
  27. #include <irq.h>
  28. static volatile int *lasat_int_status;
  29. static volatile int *lasat_int_mask;
  30. static volatile int lasat_int_mask_shift;
  31. void disable_lasat_irq(struct irq_data *d)
  32. {
  33. unsigned int irq_nr = d->irq - LASAT_IRQ_BASE;
  34. *lasat_int_mask &= ~(1 << irq_nr) << lasat_int_mask_shift;
  35. }
  36. void enable_lasat_irq(struct irq_data *d)
  37. {
  38. unsigned int irq_nr = d->irq - LASAT_IRQ_BASE;
  39. *lasat_int_mask |= (1 << irq_nr) << lasat_int_mask_shift;
  40. }
  41. static struct irq_chip lasat_irq_type = {
  42. .name = "Lasat",
  43. .irq_mask = disable_lasat_irq,
  44. .irq_unmask = enable_lasat_irq,
  45. };
  46. static inline int ls1bit32(unsigned int x)
  47. {
  48. int b = 31, s;
  49. s = 16; if (x << 16 == 0) s = 0; b -= s; x <<= s;
  50. s = 8; if (x << 8 == 0) s = 0; b -= s; x <<= s;
  51. s = 4; if (x << 4 == 0) s = 0; b -= s; x <<= s;
  52. s = 2; if (x << 2 == 0) s = 0; b -= s; x <<= s;
  53. s = 1; if (x << 1 == 0) s = 0; b -= s;
  54. return b;
  55. }
  56. static unsigned long (*get_int_status)(void);
  57. static unsigned long get_int_status_100(void)
  58. {
  59. return *lasat_int_status & *lasat_int_mask;
  60. }
  61. static unsigned long get_int_status_200(void)
  62. {
  63. unsigned long int_status;
  64. int_status = *lasat_int_status;
  65. int_status &= (int_status >> LASATINT_MASK_SHIFT_200) & 0xffff;
  66. return int_status;
  67. }
  68. asmlinkage void plat_irq_dispatch(void)
  69. {
  70. unsigned long int_status;
  71. unsigned int cause = read_c0_cause();
  72. int irq;
  73. if (cause & CAUSEF_IP7) { /* R4000 count / compare IRQ */
  74. do_IRQ(7);
  75. return;
  76. }
  77. int_status = get_int_status();
  78. /* if int_status == 0, then the interrupt has already been cleared */
  79. if (int_status) {
  80. irq = LASAT_IRQ_BASE + ls1bit32(int_status);
  81. do_IRQ(irq);
  82. }
  83. }
  84. static struct irqaction cascade = {
  85. .handler = no_action,
  86. .name = "cascade",
  87. .flags = IRQF_NO_THREAD,
  88. };
  89. void __init arch_init_irq(void)
  90. {
  91. int i;
  92. if (IS_LASAT_200()) {
  93. lasat_int_status = (void *)LASAT_INT_STATUS_REG_200;
  94. lasat_int_mask = (void *)LASAT_INT_MASK_REG_200;
  95. lasat_int_mask_shift = LASATINT_MASK_SHIFT_200;
  96. get_int_status = get_int_status_200;
  97. *lasat_int_mask &= 0xffff;
  98. } else {
  99. lasat_int_status = (void *)LASAT_INT_STATUS_REG_100;
  100. lasat_int_mask = (void *)LASAT_INT_MASK_REG_100;
  101. lasat_int_mask_shift = LASATINT_MASK_SHIFT_100;
  102. get_int_status = get_int_status_100;
  103. *lasat_int_mask = 0;
  104. }
  105. mips_cpu_irq_init();
  106. for (i = LASAT_IRQ_BASE; i <= LASAT_IRQ_END; i++)
  107. irq_set_chip_and_handler(i, &lasat_irq_type, handle_level_irq);
  108. setup_irq(LASAT_CASCADE_IRQ, &cascade);
  109. }