irq.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 - 2013 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/irqchip.h>
  21. #include <linux/irqchip/xtensa-mx.h>
  22. #include <linux/irqchip/xtensa-pic.h>
  23. #include <linux/irqdomain.h>
  24. #include <linux/of.h>
  25. #include <asm/mxregs.h>
  26. #include <linux/uaccess.h>
  27. #include <asm/platform.h>
  28. DECLARE_PER_CPU(unsigned long, nmi_count);
  29. asmlinkage void do_IRQ(int hwirq, struct pt_regs *regs)
  30. {
  31. int irq = irq_find_mapping(NULL, hwirq);
  32. if (hwirq >= NR_IRQS) {
  33. printk(KERN_EMERG "%s: cannot handle IRQ %d\n",
  34. __func__, hwirq);
  35. }
  36. #ifdef CONFIG_DEBUG_STACKOVERFLOW
  37. /* Debugging check for stack overflow: is there less than 1KB free? */
  38. {
  39. unsigned long sp;
  40. __asm__ __volatile__ ("mov %0, a1\n" : "=a" (sp));
  41. sp &= THREAD_SIZE - 1;
  42. if (unlikely(sp < (sizeof(thread_info) + 1024)))
  43. printk("Stack overflow in do_IRQ: %ld\n",
  44. sp - sizeof(struct thread_info));
  45. }
  46. #endif
  47. generic_handle_irq(irq);
  48. }
  49. int arch_show_interrupts(struct seq_file *p, int prec)
  50. {
  51. unsigned cpu __maybe_unused;
  52. #ifdef CONFIG_SMP
  53. show_ipi_list(p, prec);
  54. #endif
  55. #if XTENSA_FAKE_NMI
  56. seq_printf(p, "%*s:", prec, "NMI");
  57. for_each_online_cpu(cpu)
  58. seq_printf(p, " %10lu", per_cpu(nmi_count, cpu));
  59. seq_puts(p, " Non-maskable interrupts\n");
  60. #endif
  61. return 0;
  62. }
  63. int xtensa_irq_domain_xlate(const u32 *intspec, unsigned int intsize,
  64. unsigned long int_irq, unsigned long ext_irq,
  65. unsigned long *out_hwirq, unsigned int *out_type)
  66. {
  67. if (WARN_ON(intsize < 1 || intsize > 2))
  68. return -EINVAL;
  69. if (intsize == 2 && intspec[1] == 1) {
  70. int_irq = xtensa_map_ext_irq(ext_irq);
  71. if (int_irq < XCHAL_NUM_INTERRUPTS)
  72. *out_hwirq = int_irq;
  73. else
  74. return -EINVAL;
  75. } else {
  76. *out_hwirq = int_irq;
  77. }
  78. *out_type = IRQ_TYPE_NONE;
  79. return 0;
  80. }
  81. int xtensa_irq_map(struct irq_domain *d, unsigned int irq,
  82. irq_hw_number_t hw)
  83. {
  84. struct irq_chip *irq_chip = d->host_data;
  85. u32 mask = 1 << hw;
  86. if (mask & XCHAL_INTTYPE_MASK_SOFTWARE) {
  87. irq_set_chip_and_handler_name(irq, irq_chip,
  88. handle_simple_irq, "level");
  89. irq_set_status_flags(irq, IRQ_LEVEL);
  90. } else if (mask & XCHAL_INTTYPE_MASK_EXTERN_EDGE) {
  91. irq_set_chip_and_handler_name(irq, irq_chip,
  92. handle_edge_irq, "edge");
  93. irq_clear_status_flags(irq, IRQ_LEVEL);
  94. } else if (mask & XCHAL_INTTYPE_MASK_EXTERN_LEVEL) {
  95. irq_set_chip_and_handler_name(irq, irq_chip,
  96. handle_level_irq, "level");
  97. irq_set_status_flags(irq, IRQ_LEVEL);
  98. } else if (mask & XCHAL_INTTYPE_MASK_TIMER) {
  99. irq_set_chip_and_handler_name(irq, irq_chip,
  100. handle_percpu_irq, "timer");
  101. irq_clear_status_flags(irq, IRQ_LEVEL);
  102. #ifdef XCHAL_INTTYPE_MASK_PROFILING
  103. } else if (mask & XCHAL_INTTYPE_MASK_PROFILING) {
  104. irq_set_chip_and_handler_name(irq, irq_chip,
  105. handle_percpu_irq, "profiling");
  106. irq_set_status_flags(irq, IRQ_LEVEL);
  107. #endif
  108. } else {/* XCHAL_INTTYPE_MASK_WRITE_ERROR */
  109. /* XCHAL_INTTYPE_MASK_NMI */
  110. irq_set_chip_and_handler_name(irq, irq_chip,
  111. handle_level_irq, "level");
  112. irq_set_status_flags(irq, IRQ_LEVEL);
  113. }
  114. return 0;
  115. }
  116. unsigned xtensa_map_ext_irq(unsigned ext_irq)
  117. {
  118. unsigned mask = XCHAL_INTTYPE_MASK_EXTERN_EDGE |
  119. XCHAL_INTTYPE_MASK_EXTERN_LEVEL;
  120. unsigned i;
  121. for (i = 0; mask; ++i, mask >>= 1) {
  122. if ((mask & 1) && ext_irq-- == 0)
  123. return i;
  124. }
  125. return XCHAL_NUM_INTERRUPTS;
  126. }
  127. unsigned xtensa_get_ext_irq_no(unsigned irq)
  128. {
  129. unsigned mask = (XCHAL_INTTYPE_MASK_EXTERN_EDGE |
  130. XCHAL_INTTYPE_MASK_EXTERN_LEVEL) &
  131. ((1u << irq) - 1);
  132. return hweight32(mask);
  133. }
  134. void __init init_IRQ(void)
  135. {
  136. #ifdef CONFIG_OF
  137. irqchip_init();
  138. #else
  139. #ifdef CONFIG_HAVE_SMP
  140. xtensa_mx_init_legacy(NULL);
  141. #else
  142. xtensa_pic_init_legacy(NULL);
  143. #endif
  144. #endif
  145. #ifdef CONFIG_SMP
  146. ipi_init();
  147. #endif
  148. variant_init_irq();
  149. }
  150. #ifdef CONFIG_HOTPLUG_CPU
  151. /*
  152. * The CPU has been marked offline. Migrate IRQs off this CPU. If
  153. * the affinity settings do not allow other CPUs, force them onto any
  154. * available CPU.
  155. */
  156. void migrate_irqs(void)
  157. {
  158. unsigned int i, cpu = smp_processor_id();
  159. for_each_active_irq(i) {
  160. struct irq_data *data = irq_get_irq_data(i);
  161. struct cpumask *mask;
  162. unsigned int newcpu;
  163. if (irqd_is_per_cpu(data))
  164. continue;
  165. mask = irq_data_get_affinity_mask(data);
  166. if (!cpumask_test_cpu(cpu, mask))
  167. continue;
  168. newcpu = cpumask_any_and(mask, cpu_online_mask);
  169. if (newcpu >= nr_cpu_ids) {
  170. pr_info_ratelimited("IRQ%u no longer affine to CPU%u\n",
  171. i, cpu);
  172. cpumask_setall(mask);
  173. }
  174. irq_set_affinity(i, mask);
  175. }
  176. }
  177. #endif /* CONFIG_HOTPLUG_CPU */