interrupt.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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/irq.h>
  23. #include <linux/sched.h>
  24. #include <linux/slab.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/kernel_stat.h>
  27. #include <asm/bootinfo.h>
  28. #include <asm/irq_cpu.h>
  29. #include <asm/lasat/lasatint.h>
  30. #include <asm/time.h>
  31. #include <asm/gdb-stub.h>
  32. static volatile int *lasat_int_status;
  33. static volatile int *lasat_int_mask;
  34. static volatile int lasat_int_mask_shift;
  35. void disable_lasat_irq(unsigned int irq_nr)
  36. {
  37. *lasat_int_mask &= ~(1 << irq_nr) << lasat_int_mask_shift;
  38. }
  39. void enable_lasat_irq(unsigned int irq_nr)
  40. {
  41. *lasat_int_mask |= (1 << irq_nr) << lasat_int_mask_shift;
  42. }
  43. static struct irq_chip lasat_irq_type = {
  44. .name = "Lasat",
  45. .ack = disable_lasat_irq,
  46. .mask = disable_lasat_irq,
  47. .mask_ack = disable_lasat_irq,
  48. .unmask = enable_lasat_irq,
  49. };
  50. static inline int ls1bit32(unsigned int x)
  51. {
  52. int b = 31, s;
  53. s = 16; if (x << 16 == 0) s = 0; b -= s; x <<= s;
  54. s = 8; if (x << 8 == 0) s = 0; b -= s; x <<= s;
  55. s = 4; if (x << 4 == 0) s = 0; b -= s; x <<= s;
  56. s = 2; if (x << 2 == 0) s = 0; b -= s; x <<= s;
  57. s = 1; if (x << 1 == 0) s = 0; b -= s;
  58. return b;
  59. }
  60. static unsigned long (*get_int_status)(void);
  61. static unsigned long get_int_status_100(void)
  62. {
  63. return *lasat_int_status & *lasat_int_mask;
  64. }
  65. static unsigned long get_int_status_200(void)
  66. {
  67. unsigned long int_status;
  68. int_status = *lasat_int_status;
  69. int_status &= (int_status >> LASATINT_MASK_SHIFT_200) & 0xffff;
  70. return int_status;
  71. }
  72. asmlinkage void plat_irq_dispatch(void)
  73. {
  74. unsigned long int_status;
  75. unsigned int cause = read_c0_cause();
  76. int irq;
  77. if (cause & CAUSEF_IP7) { /* R4000 count / compare IRQ */
  78. do_IRQ(7);
  79. return;
  80. }
  81. int_status = get_int_status();
  82. /* if int_status == 0, then the interrupt has already been cleared */
  83. if (int_status) {
  84. irq = LASATINT_BASE + ls1bit32(int_status);
  85. do_IRQ(irq);
  86. }
  87. }
  88. void __init arch_init_irq(void)
  89. {
  90. int i;
  91. switch (mips_machtype) {
  92. case MACH_LASAT_100:
  93. lasat_int_status = (void *)LASAT_INT_STATUS_REG_100;
  94. lasat_int_mask = (void *)LASAT_INT_MASK_REG_100;
  95. lasat_int_mask_shift = LASATINT_MASK_SHIFT_100;
  96. get_int_status = get_int_status_100;
  97. *lasat_int_mask = 0;
  98. break;
  99. case MACH_LASAT_200:
  100. lasat_int_status = (void *)LASAT_INT_STATUS_REG_200;
  101. lasat_int_mask = (void *)LASAT_INT_MASK_REG_200;
  102. lasat_int_mask_shift = LASATINT_MASK_SHIFT_200;
  103. get_int_status = get_int_status_200;
  104. *lasat_int_mask &= 0xffff;
  105. break;
  106. default:
  107. panic("arch_init_irq: mips_machtype incorrect");
  108. }
  109. mips_cpu_irq_init();
  110. for (i = LASATINT_BASE; i <= LASATINT_END; i++)
  111. set_irq_chip_and_handler(i, &lasat_irq_type, handle_level_irq);
  112. }