ints.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /*
  2. * linux/arch/m68knommu/kernel/ints.c -- General interrupt handling code
  3. *
  4. * Copyright (C) 1999-2002 Greg Ungerer (gerg@snapgear.com)
  5. * Copyright (C) 1998 D. Jeff Dionne <jeff@lineo.ca>,
  6. * Kenneth Albanowski <kjahds@kjahds.com>,
  7. * Copyright (C) 2000 Lineo Inc. (www.lineo.com)
  8. *
  9. * Based on:
  10. *
  11. * linux/arch/m68k/kernel/ints.c -- Linux/m68k general interrupt handling code
  12. *
  13. * This file is subject to the terms and conditions of the GNU General Public
  14. * License. See the file COPYING in the main directory of this archive
  15. * for more details.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/types.h>
  19. #include <linux/init.h>
  20. #include <linux/sched.h>
  21. #include <linux/kernel_stat.h>
  22. #include <linux/errno.h>
  23. #include <linux/seq_file.h>
  24. #include <asm/system.h>
  25. #include <asm/irq.h>
  26. #include <asm/irqnode.h>
  27. #include <asm/traps.h>
  28. #include <asm/page.h>
  29. #include <asm/machdep.h>
  30. /*
  31. * This table stores the address info for each vector handler.
  32. */
  33. struct irq_entry irq_list[SYS_IRQS];
  34. #define NUM_IRQ_NODES 16
  35. static irq_node_t nodes[NUM_IRQ_NODES];
  36. /* The number of spurious interrupts */
  37. volatile unsigned int num_spurious;
  38. unsigned int local_bh_count[NR_CPUS];
  39. unsigned int local_irq_count[NR_CPUS];
  40. static irqreturn_t default_irq_handler(int irq, void *ptr)
  41. {
  42. #if 1
  43. printk(KERN_INFO "%s(%d): default irq handler vec=%d [0x%x]\n",
  44. __FILE__, __LINE__, irq, irq);
  45. #endif
  46. return(IRQ_HANDLED);
  47. }
  48. /*
  49. * void init_IRQ(void)
  50. *
  51. * Parameters: None
  52. *
  53. * Returns: Nothing
  54. *
  55. * This function should be called during kernel startup to initialize
  56. * the IRQ handling routines.
  57. */
  58. void __init init_IRQ(void)
  59. {
  60. int i;
  61. for (i = 0; i < SYS_IRQS; i++) {
  62. if (mach_default_handler)
  63. irq_list[i].handler = mach_default_handler;
  64. else
  65. irq_list[i].handler = default_irq_handler;
  66. irq_list[i].flags = IRQ_FLG_STD;
  67. irq_list[i].dev_id = NULL;
  68. irq_list[i].devname = NULL;
  69. }
  70. for (i = 0; i < NUM_IRQ_NODES; i++)
  71. nodes[i].handler = NULL;
  72. if (mach_init_IRQ)
  73. mach_init_IRQ();
  74. }
  75. irq_node_t *new_irq_node(void)
  76. {
  77. irq_node_t *node;
  78. short i;
  79. for (node = nodes, i = NUM_IRQ_NODES-1; i >= 0; node++, i--)
  80. if (!node->handler)
  81. return node;
  82. printk(KERN_INFO "new_irq_node: out of nodes\n");
  83. return NULL;
  84. }
  85. int request_irq(
  86. unsigned int irq,
  87. irq_handler_t handler,
  88. unsigned long flags,
  89. const char *devname,
  90. void *dev_id)
  91. {
  92. if (irq < 0 || irq >= NR_IRQS) {
  93. printk(KERN_WARNING "%s: Incorrect IRQ %d from %s\n", __FUNCTION__,
  94. irq, devname);
  95. return -ENXIO;
  96. }
  97. if (!(irq_list[irq].flags & IRQ_FLG_STD)) {
  98. if (irq_list[irq].flags & IRQ_FLG_LOCK) {
  99. printk(KERN_WARNING "%s: IRQ %d from %s is not replaceable\n",
  100. __FUNCTION__, irq, irq_list[irq].devname);
  101. return -EBUSY;
  102. }
  103. if (flags & IRQ_FLG_REPLACE) {
  104. printk(KERN_WARNING "%s: %s can't replace IRQ %d from %s\n",
  105. __FUNCTION__, devname, irq, irq_list[irq].devname);
  106. return -EBUSY;
  107. }
  108. }
  109. if (flags & IRQ_FLG_FAST) {
  110. extern asmlinkage void fasthandler(void);
  111. extern void set_evector(int vecnum, void (*handler)(void));
  112. set_evector(irq, fasthandler);
  113. }
  114. irq_list[irq].handler = handler;
  115. irq_list[irq].flags = flags;
  116. irq_list[irq].dev_id = dev_id;
  117. irq_list[irq].devname = devname;
  118. return 0;
  119. }
  120. EXPORT_SYMBOL(request_irq);
  121. void free_irq(unsigned int irq, void *dev_id)
  122. {
  123. if (irq >= NR_IRQS) {
  124. printk(KERN_WARNING "%s: Incorrect IRQ %d\n", __FUNCTION__, irq);
  125. return;
  126. }
  127. if (irq_list[irq].dev_id != dev_id)
  128. printk(KERN_WARNING "%s: Removing probably wrong IRQ %d from %s\n",
  129. __FUNCTION__, irq, irq_list[irq].devname);
  130. if (irq_list[irq].flags & IRQ_FLG_FAST) {
  131. extern asmlinkage void inthandler(void);
  132. extern void set_evector(int vecnum, void (*handler)(void));
  133. set_evector(irq, inthandler);
  134. }
  135. if (mach_default_handler)
  136. irq_list[irq].handler = mach_default_handler;
  137. else
  138. irq_list[irq].handler = default_irq_handler;
  139. irq_list[irq].flags = IRQ_FLG_STD;
  140. irq_list[irq].dev_id = NULL;
  141. irq_list[irq].devname = NULL;
  142. }
  143. EXPORT_SYMBOL(free_irq);
  144. int sys_request_irq(unsigned int irq, irq_handler_t handler,
  145. unsigned long flags, const char *devname, void *dev_id)
  146. {
  147. if (irq > IRQ7) {
  148. printk(KERN_WARNING "%s: Incorrect IRQ %d from %s\n",
  149. __FUNCTION__, irq, devname);
  150. return -ENXIO;
  151. }
  152. #if 0
  153. if (!(irq_list[irq].flags & IRQ_FLG_STD)) {
  154. if (irq_list[irq].flags & IRQ_FLG_LOCK) {
  155. printk(KERN_WARNING "%s: IRQ %d from %s is not replaceable\n",
  156. __FUNCTION__, irq, irq_list[irq].devname);
  157. return -EBUSY;
  158. }
  159. if (!(flags & IRQ_FLG_REPLACE)) {
  160. printk(KERN_WARNING "%s: %s can't replace IRQ %d from %s\n",
  161. __FUNCTION__, devname, irq, irq_list[irq].devname);
  162. return -EBUSY;
  163. }
  164. }
  165. #endif
  166. irq_list[irq].handler = handler;
  167. irq_list[irq].flags = flags;
  168. irq_list[irq].dev_id = dev_id;
  169. irq_list[irq].devname = devname;
  170. return 0;
  171. }
  172. void sys_free_irq(unsigned int irq, void *dev_id)
  173. {
  174. if (irq > IRQ7) {
  175. printk(KERN_WARNING "%s: Incorrect IRQ %d\n", __FUNCTION__, irq);
  176. return;
  177. }
  178. if (irq_list[irq].dev_id != dev_id)
  179. printk(KERN_WARNING "%s: Removing probably wrong IRQ %d from %s\n",
  180. __FUNCTION__, irq, irq_list[irq].devname);
  181. irq_list[irq].handler = mach_default_handler;
  182. irq_list[irq].flags = 0;
  183. irq_list[irq].dev_id = NULL;
  184. irq_list[irq].devname = NULL;
  185. }
  186. /*
  187. * Do we need these probe functions on the m68k?
  188. *
  189. * ... may be useful with ISA devices
  190. */
  191. unsigned long probe_irq_on (void)
  192. {
  193. return 0;
  194. }
  195. EXPORT_SYMBOL(probe_irq_on);
  196. int probe_irq_off (unsigned long irqs)
  197. {
  198. return 0;
  199. }
  200. EXPORT_SYMBOL(probe_irq_off);
  201. asmlinkage void process_int(unsigned long vec, struct pt_regs *fp)
  202. {
  203. if (vec >= VEC_INT1 && vec <= VEC_INT7) {
  204. vec -= VEC_SPUR;
  205. kstat_cpu(0).irqs[vec]++;
  206. irq_list[vec].handler(vec, irq_list[vec].dev_id);
  207. } else {
  208. if (mach_process_int)
  209. mach_process_int(vec, fp);
  210. else
  211. panic("Can't process interrupt vector %ld\n", vec);
  212. return;
  213. }
  214. }
  215. int show_interrupts(struct seq_file *p, void *v)
  216. {
  217. int i = *(loff_t *) v;
  218. if (i < NR_IRQS) {
  219. if (! (irq_list[i].flags & IRQ_FLG_STD)) {
  220. seq_printf(p, "%3d: %10u ", i,
  221. (i ? kstat_cpu(0).irqs[i] : num_spurious));
  222. if (irq_list[i].flags & IRQ_FLG_LOCK)
  223. seq_printf(p, "L ");
  224. else
  225. seq_printf(p, " ");
  226. seq_printf(p, "%s\n", irq_list[i].devname);
  227. }
  228. }
  229. if (i == NR_IRQS && mach_get_irq_list)
  230. mach_get_irq_list(p, v);
  231. return 0;
  232. }
  233. void init_irq_proc(void)
  234. {
  235. /* Insert /proc/irq driver here */
  236. }