irq.c 4.6 KB

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