ints.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * linux/arch/m68k/hp300/ints.c
  3. *
  4. * Copyright (C) 1998 Philip Blundell <philb@gnu.org>
  5. *
  6. * This file contains the HP300-specific interrupt handling.
  7. * We only use the autovector interrupts, and therefore we need to
  8. * maintain lists of devices sharing each ipl.
  9. * [ipl list code added by Peter Maydell <pmaydell@chiark.greenend.org.uk> 06/1998]
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/types.h>
  13. #include <linux/init.h>
  14. #include <linux/sched.h>
  15. #include <linux/kernel_stat.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/spinlock.h>
  18. #include <asm/machdep.h>
  19. #include <asm/irq.h>
  20. #include <asm/io.h>
  21. #include <asm/system.h>
  22. #include <asm/traps.h>
  23. #include <asm/ptrace.h>
  24. #include <asm/errno.h>
  25. #include "ints.h"
  26. /* Each ipl has a linked list of interrupt service routines.
  27. * Service routines are added via hp300_request_irq() and removed
  28. * via hp300_free_irq(). The device driver should set IRQ_FLG_FAST
  29. * if it needs to be serviced early (eg FIFOless UARTs); this will
  30. * cause it to be added at the front of the queue rather than
  31. * the back.
  32. * Currently IRQ_FLG_SLOW and flags=0 are treated identically; if
  33. * we needed three levels of priority we could distinguish them
  34. * but this strikes me as mildly ugly...
  35. */
  36. /* we start with no entries in any list */
  37. static irq_node_t *hp300_irq_list[HP300_NUM_IRQS];
  38. static spinlock_t irqlist_lock;
  39. /* This handler receives all interrupts, dispatching them to the registered handlers */
  40. static irqreturn_t hp300_int_handler(int irq, void *dev_id, struct pt_regs *fp)
  41. {
  42. irq_node_t *t;
  43. /* We just give every handler on the chain an opportunity to handle
  44. * the interrupt, in priority order.
  45. */
  46. for(t = hp300_irq_list[irq]; t; t=t->next)
  47. t->handler(irq, t->dev_id, fp);
  48. /* We could put in some accounting routines, checks for stray interrupts,
  49. * etc, in here. Note that currently we can't tell whether or not
  50. * a handler handles the interrupt, though.
  51. */
  52. return IRQ_HANDLED;
  53. }
  54. static irqreturn_t hp300_badint(int irq, void *dev_id, struct pt_regs *fp)
  55. {
  56. num_spurious += 1;
  57. return IRQ_NONE;
  58. }
  59. irqreturn_t (*hp300_default_handler[SYS_IRQS])(int, void *, struct pt_regs *) = {
  60. [0] = hp300_badint,
  61. [1] = hp300_int_handler,
  62. [2] = hp300_int_handler,
  63. [3] = hp300_int_handler,
  64. [4] = hp300_int_handler,
  65. [5] = hp300_int_handler,
  66. [6] = hp300_int_handler,
  67. [7] = hp300_int_handler
  68. };
  69. /* dev_id had better be unique to each handler because it's the only way we have
  70. * to distinguish handlers when removing them...
  71. *
  72. * It would be pretty easy to support IRQ_FLG_LOCK (handler is not replacable)
  73. * and IRQ_FLG_REPLACE (handler replaces existing one with this dev_id)
  74. * if we wanted to. IRQ_FLG_FAST is needed for devices where interrupt latency
  75. * matters (eg the dreaded FIFOless UART...)
  76. */
  77. int hp300_request_irq(unsigned int irq,
  78. irqreturn_t (*handler) (int, void *, struct pt_regs *),
  79. unsigned long flags, const char *devname, void *dev_id)
  80. {
  81. irq_node_t *t, *n = new_irq_node();
  82. if (!n) /* oops, no free nodes */
  83. return -ENOMEM;
  84. spin_lock_irqsave(&irqlist_lock, flags);
  85. if (!hp300_irq_list[irq]) {
  86. /* no list yet */
  87. hp300_irq_list[irq] = n;
  88. n->next = NULL;
  89. } else if (flags & IRQ_FLG_FAST) {
  90. /* insert at head of list */
  91. n->next = hp300_irq_list[irq];
  92. hp300_irq_list[irq] = n;
  93. } else {
  94. /* insert at end of list */
  95. for(t = hp300_irq_list[irq]; t->next; t = t->next)
  96. /* do nothing */;
  97. n->next = NULL;
  98. t->next = n;
  99. }
  100. /* Fill in n appropriately */
  101. n->handler = handler;
  102. n->flags = flags;
  103. n->dev_id = dev_id;
  104. n->devname = devname;
  105. spin_unlock_irqrestore(&irqlist_lock, flags);
  106. return 0;
  107. }
  108. void hp300_free_irq(unsigned int irq, void *dev_id)
  109. {
  110. irq_node_t *t;
  111. unsigned long flags;
  112. spin_lock_irqsave(&irqlist_lock, flags);
  113. t = hp300_irq_list[irq];
  114. if (!t) /* no handlers at all for that IRQ */
  115. {
  116. printk(KERN_ERR "hp300_free_irq: attempt to remove nonexistent handler for IRQ %d\n", irq);
  117. spin_unlock_irqrestore(&irqlist_lock, flags);
  118. return;
  119. }
  120. if (t->dev_id == dev_id)
  121. { /* removing first handler on chain */
  122. t->flags = IRQ_FLG_STD; /* we probably don't really need these */
  123. t->dev_id = NULL;
  124. t->devname = NULL;
  125. t->handler = NULL; /* frees this irq_node_t */
  126. hp300_irq_list[irq] = t->next;
  127. spin_unlock_irqrestore(&irqlist_lock, flags);
  128. return;
  129. }
  130. /* OK, must be removing from middle of the chain */
  131. for (t = hp300_irq_list[irq]; t->next && t->next->dev_id != dev_id; t = t->next)
  132. /* do nothing */;
  133. if (!t->next)
  134. {
  135. printk(KERN_ERR "hp300_free_irq: attempt to remove nonexistent handler for IRQ %d\n", irq);
  136. spin_unlock_irqrestore(&irqlist_lock, flags);
  137. return;
  138. }
  139. /* remove the entry after t: */
  140. t->next->flags = IRQ_FLG_STD;
  141. t->next->dev_id = NULL;
  142. t->next->devname = NULL;
  143. t->next->handler = NULL;
  144. t->next = t->next->next;
  145. spin_unlock_irqrestore(&irqlist_lock, flags);
  146. }
  147. int show_hp300_interrupts(struct seq_file *p, void *v)
  148. {
  149. return 0;
  150. }
  151. void __init hp300_init_IRQ(void)
  152. {
  153. spin_lock_init(&irqlist_lock);
  154. }