irq_cpu.c 3.0 KB

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