irq_cpu.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * Copyright 2001 MontaVista Software Inc.
  3. * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
  4. *
  5. * Copyright (C) 2001 Ralf Baechle
  6. * Copyright (C) 2005 MIPS Technologies, Inc. All rights reserved.
  7. * Author: Maciej W. Rozycki <macro@mips.com>
  8. *
  9. * This file define the irq handler for MIPS CPU interrupts.
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License as published by the
  13. * Free Software Foundation; either version 2 of the License, or (at your
  14. * option) any later version.
  15. */
  16. /*
  17. * Almost all MIPS CPUs define 8 interrupt sources. They are typically
  18. * level triggered (i.e., cannot be cleared from CPU; must be cleared from
  19. * device). The first two are software interrupts which we don't really
  20. * use or support. The last one is usually the CPU timer interrupt if
  21. * counter register is present or, for CPUs with an external FPU, by
  22. * convention it's the FPU exception interrupt.
  23. *
  24. * Don't even think about using this on SMP. You have been warned.
  25. *
  26. * This file exports one global function:
  27. * void mips_cpu_irq_init(int irq_base);
  28. */
  29. #include <linux/init.h>
  30. #include <linux/interrupt.h>
  31. #include <linux/kernel.h>
  32. #include <asm/irq_cpu.h>
  33. #include <asm/mipsregs.h>
  34. #include <asm/mipsmtregs.h>
  35. #include <asm/system.h>
  36. static int mips_cpu_irq_base;
  37. static inline void unmask_mips_irq(unsigned int irq)
  38. {
  39. set_c0_status(0x100 << (irq - mips_cpu_irq_base));
  40. irq_enable_hazard();
  41. }
  42. static inline void mask_mips_irq(unsigned int irq)
  43. {
  44. clear_c0_status(0x100 << (irq - mips_cpu_irq_base));
  45. irq_disable_hazard();
  46. }
  47. static inline void mips_cpu_irq_enable(unsigned int irq)
  48. {
  49. unsigned long flags;
  50. local_irq_save(flags);
  51. unmask_mips_irq(irq);
  52. back_to_back_c0_hazard();
  53. local_irq_restore(flags);
  54. }
  55. static void mips_cpu_irq_disable(unsigned int irq)
  56. {
  57. unsigned long flags;
  58. local_irq_save(flags);
  59. mask_mips_irq(irq);
  60. back_to_back_c0_hazard();
  61. local_irq_restore(flags);
  62. }
  63. static unsigned int mips_cpu_irq_startup(unsigned int irq)
  64. {
  65. mips_cpu_irq_enable(irq);
  66. return 0;
  67. }
  68. #define mips_cpu_irq_shutdown mips_cpu_irq_disable
  69. /*
  70. * While we ack the interrupt interrupts are disabled and thus we don't need
  71. * to deal with concurrency issues. Same for mips_cpu_irq_end.
  72. */
  73. static void mips_cpu_irq_ack(unsigned int irq)
  74. {
  75. mask_mips_irq(irq);
  76. }
  77. static void mips_cpu_irq_end(unsigned int irq)
  78. {
  79. if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
  80. unmask_mips_irq(irq);
  81. }
  82. static hw_irq_controller mips_cpu_irq_controller = {
  83. .typename = "MIPS",
  84. .startup = mips_cpu_irq_startup,
  85. .shutdown = mips_cpu_irq_shutdown,
  86. .enable = mips_cpu_irq_enable,
  87. .disable = mips_cpu_irq_disable,
  88. .ack = mips_cpu_irq_ack,
  89. .end = mips_cpu_irq_end,
  90. };
  91. /*
  92. * Basically the same as above but taking care of all the MT stuff
  93. */
  94. #define unmask_mips_mt_irq unmask_mips_irq
  95. #define mask_mips_mt_irq mask_mips_irq
  96. #define mips_mt_cpu_irq_enable mips_cpu_irq_enable
  97. #define mips_mt_cpu_irq_disable mips_cpu_irq_disable
  98. static unsigned int mips_mt_cpu_irq_startup(unsigned int irq)
  99. {
  100. unsigned int vpflags = dvpe();
  101. clear_c0_cause(0x100 << (irq - mips_cpu_irq_base));
  102. evpe(vpflags);
  103. mips_mt_cpu_irq_enable(irq);
  104. return 0;
  105. }
  106. #define mips_mt_cpu_irq_shutdown mips_mt_cpu_irq_disable
  107. /*
  108. * While we ack the interrupt interrupts are disabled and thus we don't need
  109. * to deal with concurrency issues. Same for mips_cpu_irq_end.
  110. */
  111. static void mips_mt_cpu_irq_ack(unsigned int irq)
  112. {
  113. unsigned int vpflags = dvpe();
  114. clear_c0_cause(0x100 << (irq - mips_cpu_irq_base));
  115. evpe(vpflags);
  116. mask_mips_mt_irq(irq);
  117. }
  118. #define mips_mt_cpu_irq_end mips_cpu_irq_end
  119. static hw_irq_controller mips_mt_cpu_irq_controller = {
  120. .typename = "MIPS",
  121. .startup = mips_mt_cpu_irq_startup,
  122. .shutdown = mips_mt_cpu_irq_shutdown,
  123. .enable = mips_mt_cpu_irq_enable,
  124. .disable = mips_mt_cpu_irq_disable,
  125. .ack = mips_mt_cpu_irq_ack,
  126. .end = mips_mt_cpu_irq_end,
  127. };
  128. void __init mips_cpu_irq_init(int irq_base)
  129. {
  130. int i;
  131. /* Mask interrupts. */
  132. clear_c0_status(ST0_IM);
  133. clear_c0_cause(CAUSEF_IP);
  134. /*
  135. * Only MT is using the software interrupts currently, so we just
  136. * leave them uninitialized for other processors.
  137. */
  138. if (cpu_has_mipsmt)
  139. for (i = irq_base; i < irq_base + 2; i++) {
  140. irq_desc[i].status = IRQ_DISABLED;
  141. irq_desc[i].action = NULL;
  142. irq_desc[i].depth = 1;
  143. irq_desc[i].handler = &mips_mt_cpu_irq_controller;
  144. }
  145. for (i = irq_base + 2; i < irq_base + 8; i++) {
  146. irq_desc[i].status = IRQ_DISABLED;
  147. irq_desc[i].action = NULL;
  148. irq_desc[i].depth = 1;
  149. irq_desc[i].handler = &mips_cpu_irq_controller;
  150. }
  151. mips_cpu_irq_base = irq_base;
  152. }