irq.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 - 2006 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 unsigned int cached_irq_mask;
  23. atomic_t irq_err_count;
  24. /*
  25. * 'what should we do if we get a hw irq event on an illegal vector'.
  26. * each architecture has to answer this themselves.
  27. */
  28. void ack_bad_irq(unsigned int irq)
  29. {
  30. printk("unexpected IRQ trap at vector %02x\n", irq);
  31. }
  32. /*
  33. * do_IRQ handles all normal device IRQ's (the special
  34. * SMP cross-CPU interrupts have their own specific
  35. * handlers).
  36. */
  37. asmlinkage void do_IRQ(int irq, struct pt_regs *regs)
  38. {
  39. struct pt_regs *old_regs = set_irq_regs(regs);
  40. struct irq_desc *desc = irq_desc + irq;
  41. if (irq >= NR_IRQS) {
  42. printk(KERN_EMERG "%s: cannot handle IRQ %d\n",
  43. __FUNCTION__, irq);
  44. }
  45. irq_enter();
  46. #ifdef CONFIG_DEBUG_STACKOVERFLOW
  47. /* Debugging check for stack overflow: is there less than 1KB free? */
  48. {
  49. unsigned long sp;
  50. __asm__ __volatile__ ("mov %0, a1\n" : "=a" (sp));
  51. sp &= THREAD_SIZE - 1;
  52. if (unlikely(sp < (sizeof(thread_info) + 1024)))
  53. printk("Stack overflow in do_IRQ: %ld\n",
  54. sp - sizeof(struct thread_info));
  55. }
  56. #endif
  57. desc->handle_irq(irq, desc);
  58. irq_exit();
  59. set_irq_regs(old_regs);
  60. }
  61. /*
  62. * Generic, controller-independent functions:
  63. */
  64. int show_interrupts(struct seq_file *p, void *v)
  65. {
  66. int i = *(loff_t *) v, j;
  67. struct irqaction * action;
  68. unsigned long flags;
  69. if (i == 0) {
  70. seq_printf(p, " ");
  71. for_each_online_cpu(j)
  72. seq_printf(p, "CPU%d ",j);
  73. seq_putc(p, '\n');
  74. }
  75. if (i < NR_IRQS) {
  76. spin_lock_irqsave(&irq_desc[i].lock, flags);
  77. action = irq_desc[i].action;
  78. if (!action)
  79. goto skip;
  80. seq_printf(p, "%3d: ",i);
  81. #ifndef CONFIG_SMP
  82. seq_printf(p, "%10u ", kstat_irqs(i));
  83. #else
  84. for_each_online_cpu(j)
  85. seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
  86. #endif
  87. seq_printf(p, " %14s", irq_desc[i].chip->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_each_online_cpu(j)
  97. seq_printf(p, "%10u ", nmi_count(j));
  98. seq_putc(p, '\n');
  99. seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
  100. }
  101. return 0;
  102. }
  103. static void xtensa_irq_mask(unsigned int irq)
  104. {
  105. cached_irq_mask &= ~(1 << irq);
  106. set_sr (cached_irq_mask, INTENABLE);
  107. }
  108. static void xtensa_irq_unmask(unsigned int irq)
  109. {
  110. cached_irq_mask |= 1 << irq;
  111. set_sr (cached_irq_mask, INTENABLE);
  112. }
  113. static void xtensa_irq_ack(unsigned int irq)
  114. {
  115. set_sr(1 << irq, INTCLEAR);
  116. }
  117. static int xtensa_irq_retrigger(unsigned int irq)
  118. {
  119. set_sr (1 << irq, INTSET);
  120. return 1;
  121. }
  122. static struct irq_chip xtensa_irq_chip = {
  123. .name = "xtensa",
  124. .mask = xtensa_irq_mask,
  125. .unmask = xtensa_irq_unmask,
  126. .ack = xtensa_irq_ack,
  127. .retrigger = xtensa_irq_retrigger,
  128. };
  129. void __init init_IRQ(void)
  130. {
  131. int index;
  132. for (index = 0; index < XTENSA_NR_IRQS; index++) {
  133. int mask = 1 << index;
  134. if (mask & XCHAL_INTTYPE_MASK_SOFTWARE)
  135. set_irq_chip_and_handler(index, &xtensa_irq_chip,
  136. handle_simple_irq);
  137. else if (mask & XCHAL_INTTYPE_MASK_EXTERN_EDGE)
  138. set_irq_chip_and_handler(index, &xtensa_irq_chip,
  139. handle_edge_irq);
  140. else if (mask & XCHAL_INTTYPE_MASK_EXTERN_LEVEL)
  141. set_irq_chip_and_handler(index, &xtensa_irq_chip,
  142. handle_level_irq);
  143. else if (mask & XCHAL_INTTYPE_MASK_TIMER)
  144. set_irq_chip_and_handler(index, &xtensa_irq_chip,
  145. handle_edge_irq);
  146. else /* XCHAL_INTTYPE_MASK_WRITE_ERROR */
  147. /* XCHAL_INTTYPE_MASK_NMI */
  148. set_irq_chip_and_handler(index, &xtensa_irq_chip,
  149. handle_level_irq);
  150. }
  151. cached_irq_mask = 0;
  152. }