interrupt.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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/sched.h>
  23. #include <linux/slab.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/kernel_stat.h>
  26. #include <asm/bootinfo.h>
  27. #include <asm/irq.h>
  28. #include <asm/lasat/lasatint.h>
  29. #include <asm/gdb-stub.h>
  30. static volatile int *lasat_int_status = NULL;
  31. static volatile int *lasat_int_mask = NULL;
  32. static volatile int lasat_int_mask_shift;
  33. extern asmlinkage void lasatIRQ(void);
  34. void disable_lasat_irq(unsigned int irq_nr)
  35. {
  36. unsigned long flags;
  37. local_irq_save(flags);
  38. *lasat_int_mask &= ~(1 << irq_nr) << lasat_int_mask_shift;
  39. local_irq_restore(flags);
  40. }
  41. void enable_lasat_irq(unsigned int irq_nr)
  42. {
  43. unsigned long flags;
  44. local_irq_save(flags);
  45. *lasat_int_mask |= (1 << irq_nr) << lasat_int_mask_shift;
  46. local_irq_restore(flags);
  47. }
  48. static unsigned int startup_lasat_irq(unsigned int irq)
  49. {
  50. enable_lasat_irq(irq);
  51. return 0; /* never anything pending */
  52. }
  53. #define shutdown_lasat_irq disable_lasat_irq
  54. #define mask_and_ack_lasat_irq disable_lasat_irq
  55. static void end_lasat_irq(unsigned int irq)
  56. {
  57. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  58. enable_lasat_irq(irq);
  59. }
  60. static struct hw_interrupt_type lasat_irq_type = {
  61. .typename = "Lasat",
  62. .startup = startup_lasat_irq,
  63. .shutdown = shutdown_lasat_irq,
  64. .enable = enable_lasat_irq,
  65. .disable = disable_lasat_irq,
  66. .ack = mask_and_ack_lasat_irq,
  67. .end = end_lasat_irq,
  68. };
  69. static inline int ls1bit32(unsigned int x)
  70. {
  71. int b = 31, s;
  72. s = 16; if (x << 16 == 0) s = 0; b -= s; x <<= s;
  73. s = 8; if (x << 8 == 0) s = 0; b -= s; x <<= s;
  74. s = 4; if (x << 4 == 0) s = 0; b -= s; x <<= s;
  75. s = 2; if (x << 2 == 0) s = 0; b -= s; x <<= s;
  76. s = 1; if (x << 1 == 0) s = 0; b -= s;
  77. return b;
  78. }
  79. static unsigned long (* get_int_status)(void);
  80. static unsigned long get_int_status_100(void)
  81. {
  82. return *lasat_int_status & *lasat_int_mask;
  83. }
  84. static unsigned long get_int_status_200(void)
  85. {
  86. unsigned long int_status;
  87. int_status = *lasat_int_status;
  88. int_status &= (int_status >> LASATINT_MASK_SHIFT_200) & 0xffff;
  89. return int_status;
  90. }
  91. void lasat_hw0_irqdispatch(struct pt_regs *regs)
  92. {
  93. unsigned long int_status;
  94. int irq;
  95. int_status = get_int_status();
  96. /* if int_status == 0, then the interrupt has already been cleared */
  97. if (int_status) {
  98. irq = ls1bit32(int_status);
  99. do_IRQ(irq, regs);
  100. }
  101. }
  102. void __init arch_init_irq(void)
  103. {
  104. int i;
  105. switch (mips_machtype) {
  106. case MACH_LASAT_100:
  107. lasat_int_status = (void *)LASAT_INT_STATUS_REG_100;
  108. lasat_int_mask = (void *)LASAT_INT_MASK_REG_100;
  109. lasat_int_mask_shift = LASATINT_MASK_SHIFT_100;
  110. get_int_status = get_int_status_100;
  111. *lasat_int_mask = 0;
  112. break;
  113. case MACH_LASAT_200:
  114. lasat_int_status = (void *)LASAT_INT_STATUS_REG_200;
  115. lasat_int_mask = (void *)LASAT_INT_MASK_REG_200;
  116. lasat_int_mask_shift = LASATINT_MASK_SHIFT_200;
  117. get_int_status = get_int_status_200;
  118. *lasat_int_mask &= 0xffff;
  119. break;
  120. default:
  121. panic("arch_init_irq: mips_machtype incorrect");
  122. }
  123. /* Now safe to set the exception vector. */
  124. set_except_vector(0, lasatIRQ);
  125. for (i = 0; i <= LASATINT_END; i++) {
  126. irq_desc[i].status = IRQ_DISABLED;
  127. irq_desc[i].action = 0;
  128. irq_desc[i].depth = 1;
  129. irq_desc[i].handler = &lasat_irq_type;
  130. }
  131. }