irq.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 (j=0; j<NR_CPUS; j++)
  70. if (cpu_online(j))
  71. seq_printf(p, "CPU%d ",j);
  72. seq_putc(p, '\n');
  73. }
  74. if (i < NR_IRQS) {
  75. spin_lock_irqsave(&irq_desc[i].lock, flags);
  76. action = irq_desc[i].action;
  77. if (!action)
  78. goto skip;
  79. seq_printf(p, "%3d: ",i);
  80. #ifndef CONFIG_SMP
  81. seq_printf(p, "%10u ", kstat_irqs(i));
  82. #else
  83. for (j = 0; j < NR_CPUS; j++)
  84. if (cpu_online(j))
  85. seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
  86. #endif
  87. seq_printf(p, " %14s", irq_desc[i].handler->typename);
  88. seq_printf(p, " %s", action->name);
  89. for (action=action->next; action; action = action->next)
  90. seq_printf(p, ", %s", action->name);
  91. seq_putc(p, '\n');
  92. skip:
  93. spin_unlock_irqrestore(&irq_desc[i].lock, flags);
  94. } else if (i == NR_IRQS) {
  95. seq_printf(p, "NMI: ");
  96. for (j = 0; j < NR_CPUS; j++)
  97. if (cpu_online(j))
  98. seq_printf(p, "%10u ", nmi_count(j));
  99. seq_putc(p, '\n');
  100. seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
  101. }
  102. return 0;
  103. }
  104. /* shutdown is same as "disable" */
  105. #define shutdown_xtensa_irq disable_xtensa_irq
  106. static unsigned int startup_xtensa_irq(unsigned int irq)
  107. {
  108. enable_xtensa_irq(irq);
  109. return 0; /* never anything pending */
  110. }
  111. static struct hw_interrupt_type xtensa_irq_type = {
  112. "Xtensa-IRQ",
  113. startup_xtensa_irq,
  114. shutdown_xtensa_irq,
  115. enable_xtensa_irq,
  116. disable_xtensa_irq,
  117. mask_and_ack_xtensa,
  118. end_xtensa_irq
  119. };
  120. static inline void mask_irq(unsigned int irq)
  121. {
  122. cached_irq_mask &= ~(1 << irq);
  123. set_sr (cached_irq_mask, INTENABLE);
  124. }
  125. static inline void unmask_irq(unsigned int irq)
  126. {
  127. cached_irq_mask |= 1 << irq;
  128. set_sr (cached_irq_mask, INTENABLE);
  129. }
  130. static void disable_xtensa_irq(unsigned int irq)
  131. {
  132. unsigned long flags;
  133. local_save_flags(flags);
  134. mask_irq(irq);
  135. local_irq_restore(flags);
  136. }
  137. static void enable_xtensa_irq(unsigned int irq)
  138. {
  139. unsigned long flags;
  140. local_save_flags(flags);
  141. unmask_irq(irq);
  142. local_irq_restore(flags);
  143. }
  144. static void mask_and_ack_xtensa(unsigned int irq)
  145. {
  146. disable_xtensa_irq(irq);
  147. }
  148. static void end_xtensa_irq(unsigned int irq)
  149. {
  150. enable_xtensa_irq(irq);
  151. }
  152. void __init init_IRQ(void)
  153. {
  154. int i;
  155. for (i=0; i < XTENSA_NR_IRQS; i++)
  156. irq_desc[i].handler = &xtensa_irq_type;
  157. cached_irq_mask = 0;
  158. platform_init_irq();
  159. }