ints.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /*
  2. * linux/arch/m68k/kernel/ints.c -- Linux/m68k general interrupt handling code
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file COPYING in the main directory of this archive
  6. * for more details.
  7. *
  8. * 07/03/96: Timer initialization, and thus mach_sched_init(),
  9. * removed from request_irq() and moved to init_time().
  10. * We should therefore consider renaming our add_isr() and
  11. * remove_isr() to request_irq() and free_irq()
  12. * respectively, so they are compliant with the other
  13. * architectures. /Jes
  14. * 11/07/96: Changed all add_/remove_isr() to request_/free_irq() calls.
  15. * Removed irq list support, if any machine needs an irq server
  16. * it must implement this itself (as it's already done), instead
  17. * only default handler are used with mach_default_handler.
  18. * request_irq got some flags different from other architectures:
  19. * - IRQ_FLG_REPLACE : Replace an existing handler (the default one
  20. * can be replaced without this flag)
  21. * - IRQ_FLG_LOCK : handler can't be replaced
  22. * There are other machine depending flags, see there
  23. * If you want to replace a default handler you should know what
  24. * you're doing, since it might handle different other irq sources
  25. * which must be served /Roman Zippel
  26. */
  27. #include <linux/config.h>
  28. #include <linux/module.h>
  29. #include <linux/types.h>
  30. #include <linux/sched.h>
  31. #include <linux/kernel_stat.h>
  32. #include <linux/errno.h>
  33. #include <linux/init.h>
  34. #include <asm/setup.h>
  35. #include <asm/system.h>
  36. #include <asm/irq.h>
  37. #include <asm/traps.h>
  38. #include <asm/page.h>
  39. #include <asm/machdep.h>
  40. #ifdef CONFIG_Q40
  41. #include <asm/q40ints.h>
  42. #endif
  43. /* table for system interrupt handlers */
  44. static struct irq_node *irq_list[SYS_IRQS];
  45. static struct irq_controller *irq_controller[SYS_IRQS];
  46. static struct irq_controller auto_irq_controller = {
  47. .name = "auto",
  48. .lock = SPIN_LOCK_UNLOCKED,
  49. .startup = m68k_irq_startup,
  50. .shutdown = m68k_irq_shutdown,
  51. };
  52. static const char *default_names[SYS_IRQS] = {
  53. [0] = "spurious int",
  54. [1] = "int1 handler",
  55. [2] = "int2 handler",
  56. [3] = "int3 handler",
  57. [4] = "int4 handler",
  58. [5] = "int5 handler",
  59. [6] = "int6 handler",
  60. [7] = "int7 handler"
  61. };
  62. /* The number of spurious interrupts */
  63. volatile unsigned int num_spurious;
  64. #define NUM_IRQ_NODES 100
  65. static irq_node_t nodes[NUM_IRQ_NODES];
  66. static void dummy_enable_irq(unsigned int irq);
  67. static void dummy_disable_irq(unsigned int irq);
  68. static int dummy_request_irq(unsigned int irq,
  69. irqreturn_t (*handler) (int, void *, struct pt_regs *),
  70. unsigned long flags, const char *devname, void *dev_id);
  71. static void dummy_free_irq(unsigned int irq, void *dev_id);
  72. void (*enable_irq) (unsigned int) = dummy_enable_irq;
  73. void (*disable_irq) (unsigned int) = dummy_disable_irq;
  74. int (*mach_request_irq) (unsigned int, irqreturn_t (*)(int, void *, struct pt_regs *),
  75. unsigned long, const char *, void *) = dummy_request_irq;
  76. void (*mach_free_irq) (unsigned int, void *) = dummy_free_irq;
  77. void init_irq_proc(void);
  78. /*
  79. * void init_IRQ(void)
  80. *
  81. * Parameters: None
  82. *
  83. * Returns: Nothing
  84. *
  85. * This function should be called during kernel startup to initialize
  86. * the IRQ handling routines.
  87. */
  88. void __init init_IRQ(void)
  89. {
  90. int i;
  91. /* assembly irq entry code relies on this... */
  92. if (HARDIRQ_MASK != 0x00ff0000) {
  93. extern void hardirq_mask_is_broken(void);
  94. hardirq_mask_is_broken();
  95. }
  96. for (i = IRQ_AUTO_1; i <= IRQ_AUTO_7; i++) {
  97. irq_controller[i] = &auto_irq_controller;
  98. if (mach_default_handler && (*mach_default_handler)[i])
  99. cpu_request_irq(i, (*mach_default_handler)[i],
  100. 0, default_names[i], NULL);
  101. }
  102. mach_init_IRQ ();
  103. }
  104. irq_node_t *new_irq_node(void)
  105. {
  106. irq_node_t *node;
  107. short i;
  108. for (node = nodes, i = NUM_IRQ_NODES-1; i >= 0; node++, i--) {
  109. if (!node->handler) {
  110. memset(node, 0, sizeof(*node));
  111. return node;
  112. }
  113. }
  114. printk ("new_irq_node: out of nodes\n");
  115. return NULL;
  116. }
  117. /*
  118. * We will keep these functions until I have convinced Linus to move
  119. * the declaration of them from include/linux/sched.h to
  120. * include/asm/irq.h.
  121. */
  122. int request_irq(unsigned int irq,
  123. irqreturn_t (*handler) (int, void *, struct pt_regs *),
  124. unsigned long flags, const char *devname, void *dev_id)
  125. {
  126. return mach_request_irq(irq, handler, flags, devname, dev_id);
  127. }
  128. EXPORT_SYMBOL(request_irq);
  129. void free_irq(unsigned int irq, void *dev_id)
  130. {
  131. mach_free_irq(irq, dev_id);
  132. }
  133. EXPORT_SYMBOL(free_irq);
  134. int setup_irq(unsigned int irq, struct irq_node *node)
  135. {
  136. struct irq_controller *contr;
  137. struct irq_node **prev;
  138. unsigned long flags;
  139. if (irq >= SYS_IRQS || !(contr = irq_controller[irq])) {
  140. printk("%s: Incorrect IRQ %d from %s\n",
  141. __FUNCTION__, irq, node->devname);
  142. return -ENXIO;
  143. }
  144. spin_lock_irqsave(&contr->lock, flags);
  145. prev = irq_list + irq;
  146. if (*prev) {
  147. /* Can't share interrupts unless both agree to */
  148. if (!((*prev)->flags & node->flags & SA_SHIRQ)) {
  149. spin_unlock_irqrestore(&contr->lock, flags);
  150. return -EBUSY;
  151. }
  152. while (*prev)
  153. prev = &(*prev)->next;
  154. }
  155. if (!irq_list[irq]) {
  156. if (contr->startup)
  157. contr->startup(irq);
  158. else
  159. contr->enable(irq);
  160. }
  161. node->next = NULL;
  162. *prev = node;
  163. spin_unlock_irqrestore(&contr->lock, flags);
  164. return 0;
  165. }
  166. int cpu_request_irq(unsigned int irq,
  167. irqreturn_t (*handler)(int, void *, struct pt_regs *),
  168. unsigned long flags, const char *devname, void *dev_id)
  169. {
  170. struct irq_node *node;
  171. int res;
  172. node = new_irq_node();
  173. if (!node)
  174. return -ENOMEM;
  175. node->handler = handler;
  176. node->flags = flags;
  177. node->dev_id = dev_id;
  178. node->devname = devname;
  179. res = setup_irq(irq, node);
  180. if (res)
  181. node->handler = NULL;
  182. return res;
  183. }
  184. void cpu_free_irq(unsigned int irq, void *dev_id)
  185. {
  186. struct irq_controller *contr;
  187. struct irq_node **p, *node;
  188. unsigned long flags;
  189. if (irq >= SYS_IRQS || !(contr = irq_controller[irq])) {
  190. printk("%s: Incorrect IRQ %d\n", __FUNCTION__, irq);
  191. return;
  192. }
  193. spin_lock_irqsave(&contr->lock, flags);
  194. p = irq_list + irq;
  195. while ((node = *p)) {
  196. if (node->dev_id == dev_id)
  197. break;
  198. p = &node->next;
  199. }
  200. if (node) {
  201. *p = node->next;
  202. node->handler = NULL;
  203. } else
  204. printk("%s: Removing probably wrong IRQ %d\n",
  205. __FUNCTION__, irq);
  206. if (!irq_list[irq])
  207. contr->shutdown(irq);
  208. spin_unlock_irqrestore(&contr->lock, flags);
  209. }
  210. int m68k_irq_startup(unsigned int irq)
  211. {
  212. if (irq <= IRQ_AUTO_7)
  213. vectors[VEC_SPUR + irq] = auto_inthandler;
  214. return 0;
  215. }
  216. void m68k_irq_shutdown(unsigned int irq)
  217. {
  218. if (irq <= IRQ_AUTO_7)
  219. vectors[VEC_SPUR + irq] = bad_inthandler;
  220. }
  221. /*
  222. * Do we need these probe functions on the m68k?
  223. *
  224. * ... may be useful with ISA devices
  225. */
  226. unsigned long probe_irq_on (void)
  227. {
  228. #ifdef CONFIG_Q40
  229. if (MACH_IS_Q40)
  230. return q40_probe_irq_on();
  231. #endif
  232. return 0;
  233. }
  234. EXPORT_SYMBOL(probe_irq_on);
  235. int probe_irq_off (unsigned long irqs)
  236. {
  237. #ifdef CONFIG_Q40
  238. if (MACH_IS_Q40)
  239. return q40_probe_irq_off(irqs);
  240. #endif
  241. return 0;
  242. }
  243. EXPORT_SYMBOL(probe_irq_off);
  244. static void dummy_enable_irq(unsigned int irq)
  245. {
  246. printk("calling uninitialized enable_irq()\n");
  247. }
  248. static void dummy_disable_irq(unsigned int irq)
  249. {
  250. printk("calling uninitialized disable_irq()\n");
  251. }
  252. static int dummy_request_irq(unsigned int irq,
  253. irqreturn_t (*handler) (int, void *, struct pt_regs *),
  254. unsigned long flags, const char *devname, void *dev_id)
  255. {
  256. printk("calling uninitialized request_irq()\n");
  257. return 0;
  258. }
  259. static void dummy_free_irq(unsigned int irq, void *dev_id)
  260. {
  261. printk("calling uninitialized disable_irq()\n");
  262. }
  263. asmlinkage void m68k_handle_int(unsigned int irq, struct pt_regs *regs)
  264. {
  265. struct irq_node *node;
  266. kstat_cpu(0).irqs[irq]++;
  267. node = irq_list[irq];
  268. do {
  269. node->handler(irq, node->dev_id, regs);
  270. node = node->next;
  271. } while (node);
  272. }
  273. asmlinkage void handle_badint(struct pt_regs *regs)
  274. {
  275. kstat_cpu(0).irqs[0]++;
  276. printk("unexpected interrupt from %u\n", regs->vector);
  277. }
  278. int show_interrupts(struct seq_file *p, void *v)
  279. {
  280. struct irq_controller *contr;
  281. struct irq_node *node;
  282. int i = *(loff_t *) v;
  283. /* autovector interrupts */
  284. if (i < SYS_IRQS && irq_list[i]) {
  285. contr = irq_controller[i];
  286. node = irq_list[i];
  287. seq_printf(p, "%s %u: %10u %s", contr->name, i, kstat_cpu(0).irqs[i], node->devname);
  288. while ((node = node->next))
  289. seq_printf(p, ", %s", node->devname);
  290. seq_puts(p, "\n");
  291. } else if (i == SYS_IRQS)
  292. mach_get_irq_list(p, v);
  293. return 0;
  294. }
  295. void init_irq_proc(void)
  296. {
  297. /* Insert /proc/irq driver here */
  298. }