irq_cpu.c 3.1 KB

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