irq.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. atomic_t irq_err_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. #ifdef CONFIG_SMP
  52. show_ipi_list(p, prec);
  53. #endif
  54. seq_printf(p, "%*s: ", prec, "ERR");
  55. seq_printf(p, "%10u\n", atomic_read(&irq_err_count));
  56. return 0;
  57. }
  58. int xtensa_irq_domain_xlate(const u32 *intspec, unsigned int intsize,
  59. unsigned long int_irq, unsigned long ext_irq,
  60. unsigned long *out_hwirq, unsigned int *out_type)
  61. {
  62. if (WARN_ON(intsize < 1 || intsize > 2))
  63. return -EINVAL;
  64. if (intsize == 2 && intspec[1] == 1) {
  65. int_irq = xtensa_map_ext_irq(ext_irq);
  66. if (int_irq < XCHAL_NUM_INTERRUPTS)
  67. *out_hwirq = int_irq;
  68. else
  69. return -EINVAL;
  70. } else {
  71. *out_hwirq = int_irq;
  72. }
  73. *out_type = IRQ_TYPE_NONE;
  74. return 0;
  75. }
  76. int xtensa_irq_map(struct irq_domain *d, unsigned int irq,
  77. irq_hw_number_t hw)
  78. {
  79. struct irq_chip *irq_chip = d->host_data;
  80. u32 mask = 1 << hw;
  81. if (mask & XCHAL_INTTYPE_MASK_SOFTWARE) {
  82. irq_set_chip_and_handler_name(irq, irq_chip,
  83. handle_simple_irq, "level");
  84. irq_set_status_flags(irq, IRQ_LEVEL);
  85. } else if (mask & XCHAL_INTTYPE_MASK_EXTERN_EDGE) {
  86. irq_set_chip_and_handler_name(irq, irq_chip,
  87. handle_edge_irq, "edge");
  88. irq_clear_status_flags(irq, IRQ_LEVEL);
  89. } else if (mask & XCHAL_INTTYPE_MASK_EXTERN_LEVEL) {
  90. irq_set_chip_and_handler_name(irq, irq_chip,
  91. handle_level_irq, "level");
  92. irq_set_status_flags(irq, IRQ_LEVEL);
  93. } else if (mask & XCHAL_INTTYPE_MASK_TIMER) {
  94. irq_set_chip_and_handler_name(irq, irq_chip,
  95. handle_percpu_irq, "timer");
  96. irq_clear_status_flags(irq, IRQ_LEVEL);
  97. } else {/* XCHAL_INTTYPE_MASK_WRITE_ERROR */
  98. /* XCHAL_INTTYPE_MASK_NMI */
  99. irq_set_chip_and_handler_name(irq, irq_chip,
  100. handle_level_irq, "level");
  101. irq_set_status_flags(irq, IRQ_LEVEL);
  102. }
  103. return 0;
  104. }
  105. unsigned xtensa_map_ext_irq(unsigned ext_irq)
  106. {
  107. unsigned mask = XCHAL_INTTYPE_MASK_EXTERN_EDGE |
  108. XCHAL_INTTYPE_MASK_EXTERN_LEVEL;
  109. unsigned i;
  110. for (i = 0; mask; ++i, mask >>= 1) {
  111. if ((mask & 1) && ext_irq-- == 0)
  112. return i;
  113. }
  114. return XCHAL_NUM_INTERRUPTS;
  115. }
  116. unsigned xtensa_get_ext_irq_no(unsigned irq)
  117. {
  118. unsigned mask = (XCHAL_INTTYPE_MASK_EXTERN_EDGE |
  119. XCHAL_INTTYPE_MASK_EXTERN_LEVEL) &
  120. ((1u << irq) - 1);
  121. return hweight32(mask);
  122. }
  123. void __init init_IRQ(void)
  124. {
  125. #ifdef CONFIG_OF
  126. irqchip_init();
  127. #else
  128. #ifdef CONFIG_HAVE_SMP
  129. xtensa_mx_init_legacy(NULL);
  130. #else
  131. xtensa_pic_init_legacy(NULL);
  132. #endif
  133. #endif
  134. #ifdef CONFIG_SMP
  135. ipi_init();
  136. #endif
  137. variant_init_irq();
  138. }
  139. #ifdef CONFIG_HOTPLUG_CPU
  140. /*
  141. * The CPU has been marked offline. Migrate IRQs off this CPU. If
  142. * the affinity settings do not allow other CPUs, force them onto any
  143. * available CPU.
  144. */
  145. void migrate_irqs(void)
  146. {
  147. unsigned int i, cpu = smp_processor_id();
  148. for_each_active_irq(i) {
  149. struct irq_data *data = irq_get_irq_data(i);
  150. unsigned int newcpu;
  151. if (irqd_is_per_cpu(data))
  152. continue;
  153. if (!cpumask_test_cpu(cpu, data->affinity))
  154. continue;
  155. newcpu = cpumask_any_and(data->affinity, cpu_online_mask);
  156. if (newcpu >= nr_cpu_ids) {
  157. pr_info_ratelimited("IRQ%u no longer affine to CPU%u\n",
  158. i, cpu);
  159. cpumask_setall(data->affinity);
  160. }
  161. irq_set_affinity(i, data->affinity);
  162. }
  163. }
  164. #endif /* CONFIG_HOTPLUG_CPU */