irq.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * linux/arch/xtensa/kernel/irq.c
  3. *
  4. * Xtensa built-in interrupt controller and some generic functions copied
  5. * from i386.
  6. *
  7. * Copyright (C) 2002 - 2006 Tensilica, Inc.
  8. * Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar
  9. *
  10. *
  11. * Chris Zankel <chris@zankel.net>
  12. * Kevin Chea
  13. *
  14. */
  15. #include <linux/module.h>
  16. #include <linux/seq_file.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/irq.h>
  19. #include <linux/kernel_stat.h>
  20. #include <linux/irqdomain.h>
  21. #include <linux/of.h>
  22. #include <asm/uaccess.h>
  23. #include <asm/platform.h>
  24. static unsigned int cached_irq_mask;
  25. atomic_t irq_err_count;
  26. static struct irq_domain *root_domain;
  27. /*
  28. * do_IRQ handles all normal device IRQ's (the special
  29. * SMP cross-CPU interrupts have their own specific
  30. * handlers).
  31. */
  32. asmlinkage void do_IRQ(int hwirq, struct pt_regs *regs)
  33. {
  34. struct pt_regs *old_regs = set_irq_regs(regs);
  35. int irq = irq_find_mapping(root_domain, hwirq);
  36. if (hwirq >= NR_IRQS) {
  37. printk(KERN_EMERG "%s: cannot handle IRQ %d\n",
  38. __func__, hwirq);
  39. }
  40. irq_enter();
  41. #ifdef CONFIG_DEBUG_STACKOVERFLOW
  42. /* Debugging check for stack overflow: is there less than 1KB free? */
  43. {
  44. unsigned long sp;
  45. __asm__ __volatile__ ("mov %0, a1\n" : "=a" (sp));
  46. sp &= THREAD_SIZE - 1;
  47. if (unlikely(sp < (sizeof(thread_info) + 1024)))
  48. printk("Stack overflow in do_IRQ: %ld\n",
  49. sp - sizeof(struct thread_info));
  50. }
  51. #endif
  52. generic_handle_irq(irq);
  53. irq_exit();
  54. set_irq_regs(old_regs);
  55. }
  56. int arch_show_interrupts(struct seq_file *p, int prec)
  57. {
  58. seq_printf(p, "%*s: ", prec, "ERR");
  59. seq_printf(p, "%10u\n", atomic_read(&irq_err_count));
  60. return 0;
  61. }
  62. static void xtensa_irq_mask(struct irq_data *d)
  63. {
  64. cached_irq_mask &= ~(1 << d->hwirq);
  65. set_sr (cached_irq_mask, intenable);
  66. }
  67. static void xtensa_irq_unmask(struct irq_data *d)
  68. {
  69. cached_irq_mask |= 1 << d->hwirq;
  70. set_sr (cached_irq_mask, intenable);
  71. }
  72. static void xtensa_irq_enable(struct irq_data *d)
  73. {
  74. variant_irq_enable(d->hwirq);
  75. xtensa_irq_unmask(d);
  76. }
  77. static void xtensa_irq_disable(struct irq_data *d)
  78. {
  79. xtensa_irq_mask(d);
  80. variant_irq_disable(d->hwirq);
  81. }
  82. static void xtensa_irq_ack(struct irq_data *d)
  83. {
  84. set_sr(1 << d->hwirq, intclear);
  85. }
  86. static int xtensa_irq_retrigger(struct irq_data *d)
  87. {
  88. set_sr(1 << d->hwirq, intset);
  89. return 1;
  90. }
  91. static struct irq_chip xtensa_irq_chip = {
  92. .name = "xtensa",
  93. .irq_enable = xtensa_irq_enable,
  94. .irq_disable = xtensa_irq_disable,
  95. .irq_mask = xtensa_irq_mask,
  96. .irq_unmask = xtensa_irq_unmask,
  97. .irq_ack = xtensa_irq_ack,
  98. .irq_retrigger = xtensa_irq_retrigger,
  99. };
  100. static int xtensa_irq_map(struct irq_domain *d, unsigned int irq,
  101. irq_hw_number_t hw)
  102. {
  103. u32 mask = 1 << hw;
  104. if (mask & XCHAL_INTTYPE_MASK_SOFTWARE) {
  105. irq_set_chip_and_handler_name(irq, &xtensa_irq_chip,
  106. handle_simple_irq, "level");
  107. irq_set_status_flags(irq, IRQ_LEVEL);
  108. } else if (mask & XCHAL_INTTYPE_MASK_EXTERN_EDGE) {
  109. irq_set_chip_and_handler_name(irq, &xtensa_irq_chip,
  110. handle_edge_irq, "edge");
  111. irq_clear_status_flags(irq, IRQ_LEVEL);
  112. } else if (mask & XCHAL_INTTYPE_MASK_EXTERN_LEVEL) {
  113. irq_set_chip_and_handler_name(irq, &xtensa_irq_chip,
  114. handle_level_irq, "level");
  115. irq_set_status_flags(irq, IRQ_LEVEL);
  116. } else if (mask & XCHAL_INTTYPE_MASK_TIMER) {
  117. irq_set_chip_and_handler_name(irq, &xtensa_irq_chip,
  118. handle_edge_irq, "edge");
  119. irq_clear_status_flags(irq, IRQ_LEVEL);
  120. } else {/* XCHAL_INTTYPE_MASK_WRITE_ERROR */
  121. /* XCHAL_INTTYPE_MASK_NMI */
  122. irq_set_chip_and_handler_name(irq, &xtensa_irq_chip,
  123. handle_level_irq, "level");
  124. irq_set_status_flags(irq, IRQ_LEVEL);
  125. }
  126. return 0;
  127. }
  128. static unsigned map_ext_irq(unsigned ext_irq)
  129. {
  130. unsigned mask = XCHAL_INTTYPE_MASK_EXTERN_EDGE |
  131. XCHAL_INTTYPE_MASK_EXTERN_LEVEL;
  132. unsigned i;
  133. for (i = 0; mask; ++i, mask >>= 1) {
  134. if ((mask & 1) && ext_irq-- == 0)
  135. return i;
  136. }
  137. return XCHAL_NUM_INTERRUPTS;
  138. }
  139. /*
  140. * Device Tree IRQ specifier translation function which works with one or
  141. * two cell bindings. First cell value maps directly to the hwirq number.
  142. * Second cell if present specifies whether hwirq number is external (1) or
  143. * internal (0).
  144. */
  145. int xtensa_irq_domain_xlate(struct irq_domain *d, struct device_node *ctrlr,
  146. const u32 *intspec, unsigned int intsize,
  147. unsigned long *out_hwirq, unsigned int *out_type)
  148. {
  149. if (WARN_ON(intsize < 1 || intsize > 2))
  150. return -EINVAL;
  151. if (intsize == 2 && intspec[1] == 1) {
  152. unsigned int_irq = map_ext_irq(intspec[0]);
  153. if (int_irq < XCHAL_NUM_INTERRUPTS)
  154. *out_hwirq = int_irq;
  155. else
  156. return -EINVAL;
  157. } else {
  158. *out_hwirq = intspec[0];
  159. }
  160. *out_type = IRQ_TYPE_NONE;
  161. return 0;
  162. }
  163. static const struct irq_domain_ops xtensa_irq_domain_ops = {
  164. .xlate = xtensa_irq_domain_xlate,
  165. .map = xtensa_irq_map,
  166. };
  167. void __init init_IRQ(void)
  168. {
  169. struct device_node *intc = NULL;
  170. cached_irq_mask = 0;
  171. set_sr(~0, intclear);
  172. #ifdef CONFIG_OF
  173. /* The interrupt controller device node is mandatory */
  174. intc = of_find_compatible_node(NULL, NULL, "xtensa,pic");
  175. BUG_ON(!intc);
  176. root_domain = irq_domain_add_linear(intc, NR_IRQS,
  177. &xtensa_irq_domain_ops, NULL);
  178. #else
  179. root_domain = irq_domain_add_legacy(intc, NR_IRQS, 0, 0,
  180. &xtensa_irq_domain_ops, NULL);
  181. #endif
  182. irq_set_default_host(root_domain);
  183. variant_init_irq();
  184. }