irq.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * OpenRISC irq.c
  3. *
  4. * Linux architectural port borrowing liberally from similar works of
  5. * others. All original copyrights apply as per the original source
  6. * declaration.
  7. *
  8. * Modifications for the OpenRISC architecture:
  9. * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version
  14. * 2 of the License, or (at your option) any later version.
  15. */
  16. #include <linux/ptrace.h>
  17. #include <linux/errno.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/init.h>
  20. #include <linux/of.h>
  21. #include <linux/ftrace.h>
  22. #include <linux/irq.h>
  23. #include <linux/seq_file.h>
  24. #include <linux/kernel_stat.h>
  25. #include <linux/irqflags.h>
  26. /* read interrupt enabled status */
  27. unsigned long arch_local_save_flags(void)
  28. {
  29. return mfspr(SPR_SR) & (SPR_SR_IEE|SPR_SR_TEE);
  30. }
  31. EXPORT_SYMBOL(arch_local_save_flags);
  32. /* set interrupt enabled status */
  33. void arch_local_irq_restore(unsigned long flags)
  34. {
  35. mtspr(SPR_SR, ((mfspr(SPR_SR) & ~(SPR_SR_IEE|SPR_SR_TEE)) | flags));
  36. }
  37. EXPORT_SYMBOL(arch_local_irq_restore);
  38. /* OR1K PIC implementation */
  39. /* We're a couple of cycles faster than the generic implementations with
  40. * these 'fast' versions.
  41. */
  42. static void or1k_pic_mask(struct irq_data *data)
  43. {
  44. mtspr(SPR_PICMR, mfspr(SPR_PICMR) & ~(1UL << data->irq));
  45. }
  46. static void or1k_pic_unmask(struct irq_data *data)
  47. {
  48. mtspr(SPR_PICMR, mfspr(SPR_PICMR) | (1UL << data->irq));
  49. }
  50. static void or1k_pic_ack(struct irq_data *data)
  51. {
  52. /* EDGE-triggered interrupts need to be ack'ed in order to clear
  53. * the latch.
  54. * LEVER-triggered interrupts do not need to be ack'ed; however,
  55. * ack'ing the interrupt has no ill-effect and is quicker than
  56. * trying to figure out what type it is...
  57. */
  58. /* The OpenRISC 1000 spec says to write a 1 to the bit to ack the
  59. * interrupt, but the OR1200 does this backwards and requires a 0
  60. * to be written...
  61. */
  62. #ifdef CONFIG_OR1K_1200
  63. /* There are two oddities with the OR1200 PIC implementation:
  64. * i) LEVEL-triggered interrupts are latched and need to be cleared
  65. * ii) the interrupt latch is cleared by writing a 0 to the bit,
  66. * as opposed to a 1 as mandated by the spec
  67. */
  68. mtspr(SPR_PICSR, mfspr(SPR_PICSR) & ~(1UL << data->irq));
  69. #else
  70. WARN(1, "Interrupt handling possibily broken\n");
  71. mtspr(SPR_PICSR, (1UL << irq));
  72. #endif
  73. }
  74. static void or1k_pic_mask_ack(struct irq_data *data)
  75. {
  76. /* Comments for pic_ack apply here, too */
  77. #ifdef CONFIG_OR1K_1200
  78. mtspr(SPR_PICSR, mfspr(SPR_PICSR) & ~(1UL << data->irq));
  79. #else
  80. WARN(1, "Interrupt handling possibily broken\n");
  81. mtspr(SPR_PICSR, (1UL << irq));
  82. #endif
  83. }
  84. static int or1k_pic_set_type(struct irq_data *data, unsigned int flow_type)
  85. {
  86. /* There's nothing to do in the PIC configuration when changing
  87. * flow type. Level and edge-triggered interrupts are both
  88. * supported, but it's PIC-implementation specific which type
  89. * is handled. */
  90. return irq_setup_alt_chip(data, flow_type);
  91. }
  92. static inline int pic_get_irq(int first)
  93. {
  94. int irq;
  95. irq = ffs(mfspr(SPR_PICSR) >> first);
  96. return irq ? irq + first - 1 : NO_IRQ;
  97. }
  98. static void __init or1k_irq_init(void)
  99. {
  100. struct irq_chip_generic *gc;
  101. struct irq_chip_type *ct;
  102. /* Disable all interrupts until explicitly requested */
  103. mtspr(SPR_PICMR, (0UL));
  104. gc = irq_alloc_generic_chip("or1k-PIC", 1, 0, 0, handle_level_irq);
  105. ct = gc->chip_types;
  106. ct->chip.irq_unmask = or1k_pic_unmask;
  107. ct->chip.irq_mask = or1k_pic_mask;
  108. ct->chip.irq_ack = or1k_pic_ack;
  109. ct->chip.irq_mask_ack = or1k_pic_mask_ack;
  110. ct->chip.irq_set_type = or1k_pic_set_type;
  111. /* The OR1K PIC can handle both level and edge trigged
  112. * interrupts in roughly the same manner
  113. */
  114. #if 0
  115. /* FIXME: chip.type??? */
  116. ct->chip.type = IRQ_TYPE_EDGE_BOTH | IRQ_TYPE_LEVEL_MASK;
  117. #endif
  118. irq_setup_generic_chip(gc, IRQ_MSK(NR_IRQS), 0,
  119. IRQ_NOREQUEST, IRQ_LEVEL | IRQ_NOPROBE);
  120. }
  121. void __init init_IRQ(void)
  122. {
  123. or1k_irq_init();
  124. }
  125. void __irq_entry do_IRQ(struct pt_regs *regs)
  126. {
  127. int irq = -1;
  128. struct pt_regs *old_regs = set_irq_regs(regs);
  129. irq_enter();
  130. while ((irq = pic_get_irq(irq + 1)) != NO_IRQ)
  131. generic_handle_irq(irq);
  132. irq_exit();
  133. set_irq_regs(old_regs);
  134. }
  135. unsigned int irq_create_of_mapping(struct device_node *controller,
  136. const u32 *intspec, unsigned int intsize)
  137. {
  138. return intspec[0];
  139. }
  140. EXPORT_SYMBOL_GPL(irq_create_of_mapping);