interrupt.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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(unsigned int irq_nr)
  32. {
  33. irq_nr -= LASAT_IRQ_BASE;
  34. *lasat_int_mask &= ~(1 << irq_nr) << lasat_int_mask_shift;
  35. }
  36. void enable_lasat_irq(unsigned int irq_nr)
  37. {
  38. irq_nr -= 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. .ack = disable_lasat_irq,
  44. .mask = disable_lasat_irq,
  45. .mask_ack = disable_lasat_irq,
  46. .unmask = enable_lasat_irq,
  47. };
  48. static inline int ls1bit32(unsigned int x)
  49. {
  50. int b = 31, s;
  51. s = 16; if (x << 16 == 0) s = 0; b -= s; x <<= s;
  52. s = 8; if (x << 8 == 0) s = 0; b -= s; x <<= s;
  53. s = 4; if (x << 4 == 0) s = 0; b -= s; x <<= s;
  54. s = 2; if (x << 2 == 0) s = 0; b -= s; x <<= s;
  55. s = 1; if (x << 1 == 0) s = 0; b -= s;
  56. return b;
  57. }
  58. static unsigned long (*get_int_status)(void);
  59. static unsigned long get_int_status_100(void)
  60. {
  61. return *lasat_int_status & *lasat_int_mask;
  62. }
  63. static unsigned long get_int_status_200(void)
  64. {
  65. unsigned long int_status;
  66. int_status = *lasat_int_status;
  67. int_status &= (int_status >> LASATINT_MASK_SHIFT_200) & 0xffff;
  68. return int_status;
  69. }
  70. asmlinkage void plat_irq_dispatch(void)
  71. {
  72. unsigned long int_status;
  73. unsigned int cause = read_c0_cause();
  74. int irq;
  75. if (cause & CAUSEF_IP7) { /* R4000 count / compare IRQ */
  76. do_IRQ(7);
  77. return;
  78. }
  79. int_status = get_int_status();
  80. /* if int_status == 0, then the interrupt has already been cleared */
  81. if (int_status) {
  82. irq = LASAT_IRQ_BASE + ls1bit32(int_status);
  83. do_IRQ(irq);
  84. }
  85. }
  86. static struct irqaction cascade = {
  87. .handler = no_action,
  88. .mask = CPU_MASK_NONE,
  89. .name = "cascade",
  90. };
  91. void __init arch_init_irq(void)
  92. {
  93. int i;
  94. if (IS_LASAT_200()) {
  95. lasat_int_status = (void *)LASAT_INT_STATUS_REG_200;
  96. lasat_int_mask = (void *)LASAT_INT_MASK_REG_200;
  97. lasat_int_mask_shift = LASATINT_MASK_SHIFT_200;
  98. get_int_status = get_int_status_200;
  99. *lasat_int_mask &= 0xffff;
  100. } else {
  101. lasat_int_status = (void *)LASAT_INT_STATUS_REG_100;
  102. lasat_int_mask = (void *)LASAT_INT_MASK_REG_100;
  103. lasat_int_mask_shift = LASATINT_MASK_SHIFT_100;
  104. get_int_status = get_int_status_100;
  105. *lasat_int_mask = 0;
  106. }
  107. mips_cpu_irq_init();
  108. for (i = LASAT_IRQ_BASE; i <= LASAT_IRQ_END; i++)
  109. set_irq_chip_and_handler(i, &lasat_irq_type, handle_level_irq);
  110. setup_irq(LASAT_CASCADE_IRQ, &cascade);
  111. }