irq.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. * do_IRQ handles all normal device IRQ's (the special
  26. * SMP cross-CPU interrupts have their own specific
  27. * handlers).
  28. */
  29. asmlinkage void do_IRQ(int irq, struct pt_regs *regs)
  30. {
  31. struct pt_regs *old_regs = set_irq_regs(regs);
  32. if (irq >= NR_IRQS) {
  33. printk(KERN_EMERG "%s: cannot handle IRQ %d\n",
  34. __func__, irq);
  35. }
  36. irq_enter();
  37. #ifdef CONFIG_DEBUG_STACKOVERFLOW
  38. /* Debugging check for stack overflow: is there less than 1KB free? */
  39. {
  40. unsigned long sp;
  41. __asm__ __volatile__ ("mov %0, a1\n" : "=a" (sp));
  42. sp &= THREAD_SIZE - 1;
  43. if (unlikely(sp < (sizeof(thread_info) + 1024)))
  44. printk("Stack overflow in do_IRQ: %ld\n",
  45. sp - sizeof(struct thread_info));
  46. }
  47. #endif
  48. generic_handle_irq(irq);
  49. irq_exit();
  50. set_irq_regs(old_regs);
  51. }
  52. int arch_show_interrupts(struct seq_file *p, int prec)
  53. {
  54. seq_printf(p, "%*s: ", prec, "ERR");
  55. seq_printf(p, "%10u\n", atomic_read(&irq_err_count));
  56. return 0;
  57. }
  58. static void xtensa_irq_mask(struct irq_data *d)
  59. {
  60. cached_irq_mask &= ~(1 << d->irq);
  61. set_sr (cached_irq_mask, INTENABLE);
  62. }
  63. static void xtensa_irq_unmask(struct irq_data *d)
  64. {
  65. cached_irq_mask |= 1 << d->irq;
  66. set_sr (cached_irq_mask, INTENABLE);
  67. }
  68. static void xtensa_irq_enable(struct irq_data *d)
  69. {
  70. variant_irq_enable(d->irq);
  71. xtensa_irq_unmask(d->irq);
  72. }
  73. static void xtensa_irq_disable(struct irq_data *d)
  74. {
  75. xtensa_irq_mask(d->irq);
  76. variant_irq_disable(d->irq);
  77. }
  78. static void xtensa_irq_ack(struct irq_data *d)
  79. {
  80. set_sr(1 << d->irq, INTCLEAR);
  81. }
  82. static int xtensa_irq_retrigger(struct irq_data *d)
  83. {
  84. set_sr (1 << d->irq, INTSET);
  85. return 1;
  86. }
  87. static struct irq_chip xtensa_irq_chip = {
  88. .name = "xtensa",
  89. .irq_enable = xtensa_irq_enable,
  90. .irq_disable = xtensa_irq_disable,
  91. .irq_mask = xtensa_irq_mask,
  92. .irq_unmask = xtensa_irq_unmask,
  93. .irq_ack = xtensa_irq_ack,
  94. .irq_retrigger = xtensa_irq_retrigger,
  95. };
  96. void __init init_IRQ(void)
  97. {
  98. int index;
  99. for (index = 0; index < XTENSA_NR_IRQS; index++) {
  100. int mask = 1 << index;
  101. if (mask & XCHAL_INTTYPE_MASK_SOFTWARE)
  102. irq_set_chip_and_handler(index, &xtensa_irq_chip,
  103. handle_simple_irq);
  104. else if (mask & XCHAL_INTTYPE_MASK_EXTERN_EDGE)
  105. irq_set_chip_and_handler(index, &xtensa_irq_chip,
  106. handle_edge_irq);
  107. else if (mask & XCHAL_INTTYPE_MASK_EXTERN_LEVEL)
  108. irq_set_chip_and_handler(index, &xtensa_irq_chip,
  109. handle_level_irq);
  110. else if (mask & XCHAL_INTTYPE_MASK_TIMER)
  111. irq_set_chip_and_handler(index, &xtensa_irq_chip,
  112. handle_edge_irq);
  113. else /* XCHAL_INTTYPE_MASK_WRITE_ERROR */
  114. /* XCHAL_INTTYPE_MASK_NMI */
  115. irq_set_chip_and_handler(index, &xtensa_irq_chip,
  116. handle_level_irq);
  117. }
  118. cached_irq_mask = 0;
  119. variant_init_irq();
  120. }