irq.c 4.9 KB

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