irq.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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/irqdomain.h>
  27. #include <linux/irqflags.h>
  28. /* read interrupt enabled status */
  29. unsigned long arch_local_save_flags(void)
  30. {
  31. return mfspr(SPR_SR) & (SPR_SR_IEE|SPR_SR_TEE);
  32. }
  33. EXPORT_SYMBOL(arch_local_save_flags);
  34. /* set interrupt enabled status */
  35. void arch_local_irq_restore(unsigned long flags)
  36. {
  37. mtspr(SPR_SR, ((mfspr(SPR_SR) & ~(SPR_SR_IEE|SPR_SR_TEE)) | flags));
  38. }
  39. EXPORT_SYMBOL(arch_local_irq_restore);
  40. /* OR1K PIC implementation */
  41. /* We're a couple of cycles faster than the generic implementations with
  42. * these 'fast' versions.
  43. */
  44. static void or1k_pic_mask(struct irq_data *data)
  45. {
  46. mtspr(SPR_PICMR, mfspr(SPR_PICMR) & ~(1UL << data->irq));
  47. }
  48. static void or1k_pic_unmask(struct irq_data *data)
  49. {
  50. mtspr(SPR_PICMR, mfspr(SPR_PICMR) | (1UL << data->irq));
  51. }
  52. static void or1k_pic_ack(struct irq_data *data)
  53. {
  54. /* EDGE-triggered interrupts need to be ack'ed in order to clear
  55. * the latch.
  56. * LEVER-triggered interrupts do not need to be ack'ed; however,
  57. * ack'ing the interrupt has no ill-effect and is quicker than
  58. * trying to figure out what type it is...
  59. */
  60. /* The OpenRISC 1000 spec says to write a 1 to the bit to ack the
  61. * interrupt, but the OR1200 does this backwards and requires a 0
  62. * to be written...
  63. */
  64. #ifdef CONFIG_OR1K_1200
  65. /* There are two oddities with the OR1200 PIC implementation:
  66. * i) LEVEL-triggered interrupts are latched and need to be cleared
  67. * ii) the interrupt latch is cleared by writing a 0 to the bit,
  68. * as opposed to a 1 as mandated by the spec
  69. */
  70. mtspr(SPR_PICSR, mfspr(SPR_PICSR) & ~(1UL << data->irq));
  71. #else
  72. WARN(1, "Interrupt handling possibily broken\n");
  73. mtspr(SPR_PICSR, (1UL << irq));
  74. #endif
  75. }
  76. static void or1k_pic_mask_ack(struct irq_data *data)
  77. {
  78. /* Comments for pic_ack apply here, too */
  79. #ifdef CONFIG_OR1K_1200
  80. mtspr(SPR_PICSR, mfspr(SPR_PICSR) & ~(1UL << data->irq));
  81. #else
  82. WARN(1, "Interrupt handling possibily broken\n");
  83. mtspr(SPR_PICSR, (1UL << irq));
  84. #endif
  85. }
  86. #if 0
  87. static int or1k_pic_set_type(struct irq_data *data, unsigned int flow_type)
  88. {
  89. /* There's nothing to do in the PIC configuration when changing
  90. * flow type. Level and edge-triggered interrupts are both
  91. * supported, but it's PIC-implementation specific which type
  92. * is handled. */
  93. return irq_setup_alt_chip(data, flow_type);
  94. }
  95. #endif
  96. static struct irq_chip or1k_dev = {
  97. .name = "or1k-PIC",
  98. .irq_unmask = or1k_pic_unmask,
  99. .irq_mask = or1k_pic_mask,
  100. .irq_ack = or1k_pic_ack,
  101. .irq_mask_ack = or1k_pic_mask_ack,
  102. };
  103. static struct irq_domain *root_domain;
  104. static inline int pic_get_irq(int first)
  105. {
  106. int hwirq;
  107. hwirq = ffs(mfspr(SPR_PICSR) >> first);
  108. if (!hwirq)
  109. return NO_IRQ;
  110. else
  111. hwirq = hwirq + first -1;
  112. return irq_find_mapping(root_domain, hwirq);
  113. }
  114. static int or1k_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hw)
  115. {
  116. irq_set_chip_and_handler_name(irq, &or1k_dev,
  117. handle_level_irq, "level");
  118. irq_set_status_flags(irq, IRQ_LEVEL | IRQ_NOPROBE);
  119. return 0;
  120. }
  121. static const struct irq_domain_ops or1k_irq_domain_ops = {
  122. .xlate = irq_domain_xlate_onecell,
  123. .map = or1k_map,
  124. };
  125. /*
  126. * This sets up the IRQ domain for the PIC built in to the OpenRISC
  127. * 1000 CPU. This is the "root" domain as these are the interrupts
  128. * that directly trigger an exception in the CPU.
  129. */
  130. static void __init or1k_irq_init(void)
  131. {
  132. struct device_node *intc = NULL;
  133. /* The interrupt controller device node is mandatory */
  134. intc = of_find_compatible_node(NULL, NULL, "opencores,or1k-pic");
  135. BUG_ON(!intc);
  136. /* Disable all interrupts until explicitly requested */
  137. mtspr(SPR_PICMR, (0UL));
  138. root_domain = irq_domain_add_linear(intc, 32,
  139. &or1k_irq_domain_ops, NULL);
  140. }
  141. void __init init_IRQ(void)
  142. {
  143. or1k_irq_init();
  144. }
  145. void __irq_entry do_IRQ(struct pt_regs *regs)
  146. {
  147. int irq = -1;
  148. struct pt_regs *old_regs = set_irq_regs(regs);
  149. irq_enter();
  150. while ((irq = pic_get_irq(irq + 1)) != NO_IRQ)
  151. generic_handle_irq(irq);
  152. irq_exit();
  153. set_irq_regs(old_regs);
  154. }