irq_cpu.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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/system.h>
  35. static int mips_cpu_irq_base;
  36. static inline void unmask_mips_irq(unsigned int irq)
  37. {
  38. set_c0_status(0x100 << (irq - mips_cpu_irq_base));
  39. irq_enable_hazard();
  40. }
  41. static inline void mask_mips_irq(unsigned int irq)
  42. {
  43. clear_c0_status(0x100 << (irq - mips_cpu_irq_base));
  44. irq_disable_hazard();
  45. }
  46. static inline void mips_cpu_irq_enable(unsigned int irq)
  47. {
  48. unsigned long flags;
  49. local_irq_save(flags);
  50. unmask_mips_irq(irq);
  51. back_to_back_c0_hazard();
  52. local_irq_restore(flags);
  53. }
  54. static void mips_cpu_irq_disable(unsigned int irq)
  55. {
  56. unsigned long flags;
  57. local_irq_save(flags);
  58. mask_mips_irq(irq);
  59. back_to_back_c0_hazard();
  60. local_irq_restore(flags);
  61. }
  62. static unsigned int mips_cpu_irq_startup(unsigned int irq)
  63. {
  64. mips_cpu_irq_enable(irq);
  65. return 0;
  66. }
  67. #define mips_cpu_irq_shutdown mips_cpu_irq_disable
  68. /*
  69. * While we ack the interrupt interrupts are disabled and thus we don't need
  70. * to deal with concurrency issues. Same for mips_cpu_irq_end.
  71. */
  72. static void mips_cpu_irq_ack(unsigned int irq)
  73. {
  74. /* Only necessary for soft interrupts */
  75. clear_c0_cause(0x100 << (irq - mips_cpu_irq_base));
  76. mask_mips_irq(irq);
  77. }
  78. static void mips_cpu_irq_end(unsigned int irq)
  79. {
  80. if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
  81. unmask_mips_irq(irq);
  82. }
  83. static hw_irq_controller mips_cpu_irq_controller = {
  84. .typename = "MIPS",
  85. .startup = mips_cpu_irq_startup,
  86. .shutdown = mips_cpu_irq_shutdown,
  87. .enable = mips_cpu_irq_enable,
  88. .disable = mips_cpu_irq_disable,
  89. .ack = mips_cpu_irq_ack,
  90. .end = mips_cpu_irq_end,
  91. };
  92. void __init mips_cpu_irq_init(int irq_base)
  93. {
  94. int i;
  95. /* Mask interrupts. */
  96. clear_c0_status(ST0_IM);
  97. clear_c0_cause(CAUSEF_IP);
  98. for (i = irq_base; i < irq_base + 8; i++) {
  99. irq_desc[i].status = IRQ_DISABLED;
  100. irq_desc[i].action = NULL;
  101. irq_desc[i].depth = 1;
  102. irq_desc[i].handler = &mips_cpu_irq_controller;
  103. }
  104. mips_cpu_irq_base = irq_base;
  105. }