irq.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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/export.h>
  26. #include <linux/irqflags.h>
  27. /* read interrupt enabled status */
  28. unsigned long arch_local_save_flags(void)
  29. {
  30. return mfspr(SPR_SR) & (SPR_SR_IEE|SPR_SR_TEE);
  31. }
  32. EXPORT_SYMBOL(arch_local_save_flags);
  33. /* set interrupt enabled status */
  34. void arch_local_irq_restore(unsigned long flags)
  35. {
  36. mtspr(SPR_SR, ((mfspr(SPR_SR) & ~(SPR_SR_IEE|SPR_SR_TEE)) | flags));
  37. }
  38. EXPORT_SYMBOL(arch_local_irq_restore);
  39. /* OR1K PIC implementation */
  40. /* We're a couple of cycles faster than the generic implementations with
  41. * these 'fast' versions.
  42. */
  43. static void or1k_pic_mask(struct irq_data *data)
  44. {
  45. mtspr(SPR_PICMR, mfspr(SPR_PICMR) & ~(1UL << data->irq));
  46. }
  47. static void or1k_pic_unmask(struct irq_data *data)
  48. {
  49. mtspr(SPR_PICMR, mfspr(SPR_PICMR) | (1UL << data->irq));
  50. }
  51. static void or1k_pic_ack(struct irq_data *data)
  52. {
  53. /* EDGE-triggered interrupts need to be ack'ed in order to clear
  54. * the latch.
  55. * LEVER-triggered interrupts do not need to be ack'ed; however,
  56. * ack'ing the interrupt has no ill-effect and is quicker than
  57. * trying to figure out what type it is...
  58. */
  59. /* The OpenRISC 1000 spec says to write a 1 to the bit to ack the
  60. * interrupt, but the OR1200 does this backwards and requires a 0
  61. * to be written...
  62. */
  63. #ifdef CONFIG_OR1K_1200
  64. /* There are two oddities with the OR1200 PIC implementation:
  65. * i) LEVEL-triggered interrupts are latched and need to be cleared
  66. * ii) the interrupt latch is cleared by writing a 0 to the bit,
  67. * as opposed to a 1 as mandated by the spec
  68. */
  69. mtspr(SPR_PICSR, mfspr(SPR_PICSR) & ~(1UL << data->irq));
  70. #else
  71. WARN(1, "Interrupt handling possibily broken\n");
  72. mtspr(SPR_PICSR, (1UL << irq));
  73. #endif
  74. }
  75. static void or1k_pic_mask_ack(struct irq_data *data)
  76. {
  77. /* Comments for pic_ack apply here, too */
  78. #ifdef CONFIG_OR1K_1200
  79. mtspr(SPR_PICSR, mfspr(SPR_PICSR) & ~(1UL << data->irq));
  80. #else
  81. WARN(1, "Interrupt handling possibily broken\n");
  82. mtspr(SPR_PICSR, (1UL << irq));
  83. #endif
  84. }
  85. static int or1k_pic_set_type(struct irq_data *data, unsigned int flow_type)
  86. {
  87. /* There's nothing to do in the PIC configuration when changing
  88. * flow type. Level and edge-triggered interrupts are both
  89. * supported, but it's PIC-implementation specific which type
  90. * is handled. */
  91. return irq_setup_alt_chip(data, flow_type);
  92. }
  93. static inline int pic_get_irq(int first)
  94. {
  95. int irq;
  96. irq = ffs(mfspr(SPR_PICSR) >> first);
  97. return irq ? irq + first - 1 : NO_IRQ;
  98. }
  99. static void __init or1k_irq_init(void)
  100. {
  101. struct irq_chip_generic *gc;
  102. struct irq_chip_type *ct;
  103. /* Disable all interrupts until explicitly requested */
  104. mtspr(SPR_PICMR, (0UL));
  105. gc = irq_alloc_generic_chip("or1k-PIC", 1, 0, 0, handle_level_irq);
  106. ct = gc->chip_types;
  107. ct->chip.irq_unmask = or1k_pic_unmask;
  108. ct->chip.irq_mask = or1k_pic_mask;
  109. ct->chip.irq_ack = or1k_pic_ack;
  110. ct->chip.irq_mask_ack = or1k_pic_mask_ack;
  111. ct->chip.irq_set_type = or1k_pic_set_type;
  112. /* The OR1K PIC can handle both level and edge trigged
  113. * interrupts in roughly the same manner
  114. */
  115. #if 0
  116. /* FIXME: chip.type??? */
  117. ct->chip.type = IRQ_TYPE_EDGE_BOTH | IRQ_TYPE_LEVEL_MASK;
  118. #endif
  119. irq_setup_generic_chip(gc, IRQ_MSK(NR_IRQS), 0,
  120. IRQ_NOREQUEST, IRQ_LEVEL | IRQ_NOPROBE);
  121. }
  122. void __init init_IRQ(void)
  123. {
  124. or1k_irq_init();
  125. }
  126. void __irq_entry do_IRQ(struct pt_regs *regs)
  127. {
  128. int irq = -1;
  129. struct pt_regs *old_regs = set_irq_regs(regs);
  130. irq_enter();
  131. while ((irq = pic_get_irq(irq + 1)) != NO_IRQ)
  132. generic_handle_irq(irq);
  133. irq_exit();
  134. set_irq_regs(old_regs);
  135. }
  136. unsigned int irq_create_of_mapping(struct device_node *controller,
  137. const u32 *intspec, unsigned int intsize)
  138. {
  139. return intspec[0];
  140. }
  141. EXPORT_SYMBOL_GPL(irq_create_of_mapping);