irq.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 - 2005 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 <asm/uaccess.h>
  21. #include <asm/platform.h>
  22. static void enable_xtensa_irq(unsigned int irq);
  23. static void disable_xtensa_irq(unsigned int irq);
  24. static void mask_and_ack_xtensa(unsigned int irq);
  25. static void end_xtensa_irq(unsigned int irq);
  26. static unsigned int cached_irq_mask;
  27. atomic_t irq_err_count;
  28. /*
  29. * 'what should we do if we get a hw irq event on an illegal vector'.
  30. * each architecture has to answer this themselves.
  31. */
  32. void ack_bad_irq(unsigned int irq)
  33. {
  34. printk("unexpected IRQ trap at vector %02x\n", irq);
  35. }
  36. /*
  37. * do_IRQ handles all normal device IRQ's (the special
  38. * SMP cross-CPU interrupts have their own specific
  39. * handlers).
  40. */
  41. unsigned int do_IRQ(int irq, struct pt_regs *regs)
  42. {
  43. irq_enter();
  44. #ifdef CONFIG_DEBUG_STACKOVERFLOW
  45. /* Debugging check for stack overflow: is there less than 1KB free? */
  46. {
  47. unsigned long sp;
  48. __asm__ __volatile__ ("mov %0, a1\n" : "=a" (sp));
  49. sp &= THREAD_SIZE - 1;
  50. if (unlikely(sp < (sizeof(thread_info) + 1024)))
  51. printk("Stack overflow in do_IRQ: %ld\n",
  52. sp - sizeof(struct thread_info));
  53. }
  54. #endif
  55. __do_IRQ(irq, regs);
  56. irq_exit();
  57. return 1;
  58. }
  59. /*
  60. * Generic, controller-independent functions:
  61. */
  62. int show_interrupts(struct seq_file *p, void *v)
  63. {
  64. int i = *(loff_t *) v, j;
  65. struct irqaction * action;
  66. unsigned long flags;
  67. if (i == 0) {
  68. seq_printf(p, " ");
  69. for_each_online_cpu(j)
  70. seq_printf(p, "CPU%d ",j);
  71. seq_putc(p, '\n');
  72. }
  73. if (i < NR_IRQS) {
  74. spin_lock_irqsave(&irq_desc[i].lock, flags);
  75. action = irq_desc[i].action;
  76. if (!action)
  77. goto skip;
  78. seq_printf(p, "%3d: ",i);
  79. #ifndef CONFIG_SMP
  80. seq_printf(p, "%10u ", kstat_irqs(i));
  81. #else
  82. for_each_online_cpu(j)
  83. seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
  84. #endif
  85. seq_printf(p, " %14s", irq_desc[i].chip->typename);
  86. seq_printf(p, " %s", action->name);
  87. for (action=action->next; action; action = action->next)
  88. seq_printf(p, ", %s", action->name);
  89. seq_putc(p, '\n');
  90. skip:
  91. spin_unlock_irqrestore(&irq_desc[i].lock, flags);
  92. } else if (i == NR_IRQS) {
  93. seq_printf(p, "NMI: ");
  94. for_each_online_cpu(j)
  95. seq_printf(p, "%10u ", nmi_count(j));
  96. seq_putc(p, '\n');
  97. seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
  98. }
  99. return 0;
  100. }
  101. /* shutdown is same as "disable" */
  102. #define shutdown_xtensa_irq disable_xtensa_irq
  103. static unsigned int startup_xtensa_irq(unsigned int irq)
  104. {
  105. enable_xtensa_irq(irq);
  106. return 0; /* never anything pending */
  107. }
  108. static struct hw_interrupt_type xtensa_irq_type = {
  109. "Xtensa-IRQ",
  110. startup_xtensa_irq,
  111. shutdown_xtensa_irq,
  112. enable_xtensa_irq,
  113. disable_xtensa_irq,
  114. mask_and_ack_xtensa,
  115. end_xtensa_irq
  116. };
  117. static inline void mask_irq(unsigned int irq)
  118. {
  119. cached_irq_mask &= ~(1 << irq);
  120. set_sr (cached_irq_mask, INTENABLE);
  121. }
  122. static inline void unmask_irq(unsigned int irq)
  123. {
  124. cached_irq_mask |= 1 << irq;
  125. set_sr (cached_irq_mask, INTENABLE);
  126. }
  127. static void disable_xtensa_irq(unsigned int irq)
  128. {
  129. unsigned long flags;
  130. local_save_flags(flags);
  131. mask_irq(irq);
  132. local_irq_restore(flags);
  133. }
  134. static void enable_xtensa_irq(unsigned int irq)
  135. {
  136. unsigned long flags;
  137. local_save_flags(flags);
  138. unmask_irq(irq);
  139. local_irq_restore(flags);
  140. }
  141. static void mask_and_ack_xtensa(unsigned int irq)
  142. {
  143. disable_xtensa_irq(irq);
  144. }
  145. static void end_xtensa_irq(unsigned int irq)
  146. {
  147. enable_xtensa_irq(irq);
  148. }
  149. void __init init_IRQ(void)
  150. {
  151. int i;
  152. for (i=0; i < XTENSA_NR_IRQS; i++)
  153. irq_desc[i].chip = &xtensa_irq_type;
  154. cached_irq_mask = 0;
  155. platform_init_irq();
  156. }