irq.c 4.6 KB

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