ints.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  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/module.h>
  28. #include <linux/types.h>
  29. #include <linux/sched.h>
  30. #include <linux/interrupt.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. #include <asm/cacheflush.h>
  41. #include <asm/irq_regs.h>
  42. #ifdef CONFIG_Q40
  43. #include <asm/q40ints.h>
  44. #endif
  45. extern u32 auto_irqhandler_fixup[];
  46. extern u32 user_irqhandler_fixup[];
  47. extern u16 user_irqvec_fixup[];
  48. /* table for system interrupt handlers */
  49. static struct irq_node *irq_list[NR_IRQS];
  50. static struct irq_chip *irq_chip[NR_IRQS];
  51. static int irq_depth[NR_IRQS];
  52. static int m68k_first_user_vec;
  53. static struct irq_chip auto_irq_chip = {
  54. .name = "auto",
  55. .irq_startup = m68k_irq_startup,
  56. .irq_shutdown = m68k_irq_shutdown,
  57. };
  58. static struct irq_chip user_irq_chip = {
  59. .name = "user",
  60. .irq_startup = m68k_irq_startup,
  61. .irq_shutdown = m68k_irq_shutdown,
  62. };
  63. #define NUM_IRQ_NODES 100
  64. static struct irq_node nodes[NUM_IRQ_NODES];
  65. /*
  66. * void init_IRQ(void)
  67. *
  68. * Parameters: None
  69. *
  70. * Returns: Nothing
  71. *
  72. * This function should be called during kernel startup to initialize
  73. * the IRQ handling routines.
  74. */
  75. void __init init_IRQ(void)
  76. {
  77. int i;
  78. /* assembly irq entry code relies on this... */
  79. if (HARDIRQ_MASK != 0x00ff0000) {
  80. extern void hardirq_mask_is_broken(void);
  81. hardirq_mask_is_broken();
  82. }
  83. for (i = IRQ_AUTO_1; i <= IRQ_AUTO_7; i++)
  84. irq_chip[i] = &auto_irq_chip;
  85. mach_init_IRQ();
  86. }
  87. /**
  88. * m68k_setup_auto_interrupt
  89. * @handler: called from auto vector interrupts
  90. *
  91. * setup the handler to be called from auto vector interrupts instead of the
  92. * standard __m68k_handle_int(), it will be called with irq numbers in the range
  93. * from IRQ_AUTO_1 - IRQ_AUTO_7.
  94. */
  95. void __init m68k_setup_auto_interrupt(void (*handler)(unsigned int, struct pt_regs *))
  96. {
  97. if (handler)
  98. *auto_irqhandler_fixup = (u32)handler;
  99. flush_icache();
  100. }
  101. /**
  102. * m68k_setup_user_interrupt
  103. * @vec: first user vector interrupt to handle
  104. * @cnt: number of active user vector interrupts
  105. * @handler: called from user vector interrupts
  106. *
  107. * setup user vector interrupts, this includes activating the specified range
  108. * of interrupts, only then these interrupts can be requested (note: this is
  109. * different from auto vector interrupts). An optional handler can be installed
  110. * to be called instead of the default __m68k_handle_int(), it will be called
  111. * with irq numbers starting from IRQ_USER.
  112. */
  113. void __init m68k_setup_user_interrupt(unsigned int vec, unsigned int cnt,
  114. void (*handler)(unsigned int, struct pt_regs *))
  115. {
  116. int i;
  117. BUG_ON(IRQ_USER + cnt > NR_IRQS);
  118. m68k_first_user_vec = vec;
  119. for (i = 0; i < cnt; i++)
  120. irq_chip[IRQ_USER + i] = &user_irq_chip;
  121. *user_irqvec_fixup = vec - IRQ_USER;
  122. if (handler)
  123. *user_irqhandler_fixup = (u32)handler;
  124. flush_icache();
  125. }
  126. /**
  127. * m68k_setup_irq_chip
  128. * @contr: irq controller which controls specified irq
  129. * @irq: first irq to be managed by the controller
  130. *
  131. * Change the controller for the specified range of irq, which will be used to
  132. * manage these irq. auto/user irq already have a default controller, which can
  133. * be changed as well, but the controller probably should use m68k_irq_startup/
  134. * m68k_irq_shutdown.
  135. */
  136. void m68k_setup_irq_chip(struct irq_chip *contr, unsigned int irq,
  137. unsigned int cnt)
  138. {
  139. int i;
  140. for (i = 0; i < cnt; i++)
  141. irq_chip[irq + i] = contr;
  142. }
  143. struct irq_node *new_irq_node(void)
  144. {
  145. struct irq_node *node;
  146. short i;
  147. for (node = nodes, i = NUM_IRQ_NODES-1; i >= 0; node++, i--) {
  148. if (!node->handler) {
  149. memset(node, 0, sizeof(*node));
  150. return node;
  151. }
  152. }
  153. printk ("new_irq_node: out of nodes\n");
  154. return NULL;
  155. }
  156. int setup_irq(unsigned int irq, struct irq_node *node)
  157. {
  158. struct irq_chip *contr;
  159. struct irq_node **prev;
  160. unsigned long flags;
  161. if (irq >= NR_IRQS || !(contr = irq_chip[irq])) {
  162. printk("%s: Incorrect IRQ %d from %s\n",
  163. __func__, irq, node->devname);
  164. return -ENXIO;
  165. }
  166. local_irq_save(flags);
  167. prev = irq_list + irq;
  168. if (*prev) {
  169. /* Can't share interrupts unless both agree to */
  170. if (!((*prev)->flags & node->flags & IRQF_SHARED)) {
  171. local_irq_restore(flags);
  172. return -EBUSY;
  173. }
  174. while (*prev)
  175. prev = &(*prev)->next;
  176. }
  177. if (!irq_list[irq]) {
  178. if (contr->irq_startup)
  179. contr->irq_startup(irq);
  180. else
  181. contr->irq_enable(irq);
  182. }
  183. node->next = NULL;
  184. *prev = node;
  185. local_irq_restore(flags);
  186. return 0;
  187. }
  188. int request_irq(unsigned int irq,
  189. irq_handler_t handler,
  190. unsigned long flags, const char *devname, void *dev_id)
  191. {
  192. struct irq_node *node;
  193. int res;
  194. node = new_irq_node();
  195. if (!node)
  196. return -ENOMEM;
  197. node->handler = handler;
  198. node->flags = flags;
  199. node->dev_id = dev_id;
  200. node->devname = devname;
  201. res = setup_irq(irq, node);
  202. if (res)
  203. node->handler = NULL;
  204. return res;
  205. }
  206. EXPORT_SYMBOL(request_irq);
  207. void free_irq(unsigned int irq, void *dev_id)
  208. {
  209. struct irq_chip *contr;
  210. struct irq_node **p, *node;
  211. unsigned long flags;
  212. if (irq >= NR_IRQS || !(contr = irq_chip[irq])) {
  213. printk("%s: Incorrect IRQ %d\n", __func__, irq);
  214. return;
  215. }
  216. local_irq_save(flags);
  217. p = irq_list + irq;
  218. while ((node = *p)) {
  219. if (node->dev_id == dev_id)
  220. break;
  221. p = &node->next;
  222. }
  223. if (node) {
  224. *p = node->next;
  225. node->handler = NULL;
  226. } else
  227. printk("%s: Removing probably wrong IRQ %d\n",
  228. __func__, irq);
  229. if (!irq_list[irq]) {
  230. if (contr->irq_shutdown)
  231. contr->irq_shutdown(irq);
  232. else
  233. contr->irq_disable(irq);
  234. }
  235. local_irq_restore(flags);
  236. }
  237. EXPORT_SYMBOL(free_irq);
  238. void enable_irq(unsigned int irq)
  239. {
  240. struct irq_chip *contr;
  241. unsigned long flags;
  242. if (irq >= NR_IRQS || !(contr = irq_chip[irq])) {
  243. printk("%s: Incorrect IRQ %d\n",
  244. __func__, irq);
  245. return;
  246. }
  247. local_irq_save(flags);
  248. if (irq_depth[irq]) {
  249. if (!--irq_depth[irq]) {
  250. if (contr->irq_enable)
  251. contr->irq_enable(irq);
  252. }
  253. } else
  254. WARN_ON(1);
  255. local_irq_restore(flags);
  256. }
  257. EXPORT_SYMBOL(enable_irq);
  258. void disable_irq(unsigned int irq)
  259. {
  260. struct irq_chip *contr;
  261. unsigned long flags;
  262. if (irq >= NR_IRQS || !(contr = irq_chip[irq])) {
  263. printk("%s: Incorrect IRQ %d\n",
  264. __func__, irq);
  265. return;
  266. }
  267. local_irq_save(flags);
  268. if (!irq_depth[irq]++) {
  269. if (contr->irq_disable)
  270. contr->irq_disable(irq);
  271. }
  272. local_irq_restore(flags);
  273. }
  274. EXPORT_SYMBOL(disable_irq);
  275. void disable_irq_nosync(unsigned int irq) __attribute__((alias("disable_irq")));
  276. EXPORT_SYMBOL(disable_irq_nosync);
  277. unsigned int m68k_irq_startup(unsigned int irq)
  278. {
  279. if (irq <= IRQ_AUTO_7)
  280. vectors[VEC_SPUR + irq] = auto_inthandler;
  281. else
  282. vectors[m68k_first_user_vec + irq - IRQ_USER] = user_inthandler;
  283. return 0;
  284. }
  285. void m68k_irq_shutdown(unsigned int irq)
  286. {
  287. if (irq <= IRQ_AUTO_7)
  288. vectors[VEC_SPUR + irq] = bad_inthandler;
  289. else
  290. vectors[m68k_first_user_vec + irq - IRQ_USER] = bad_inthandler;
  291. }
  292. /*
  293. * Do we need these probe functions on the m68k?
  294. *
  295. * ... may be useful with ISA devices
  296. */
  297. unsigned long probe_irq_on (void)
  298. {
  299. #ifdef CONFIG_Q40
  300. if (MACH_IS_Q40)
  301. return q40_probe_irq_on();
  302. #endif
  303. return 0;
  304. }
  305. EXPORT_SYMBOL(probe_irq_on);
  306. int probe_irq_off (unsigned long irqs)
  307. {
  308. #ifdef CONFIG_Q40
  309. if (MACH_IS_Q40)
  310. return q40_probe_irq_off(irqs);
  311. #endif
  312. return 0;
  313. }
  314. EXPORT_SYMBOL(probe_irq_off);
  315. unsigned int irq_canonicalize(unsigned int irq)
  316. {
  317. #ifdef CONFIG_Q40
  318. if (MACH_IS_Q40 && irq == 11)
  319. irq = 10;
  320. #endif
  321. return irq;
  322. }
  323. EXPORT_SYMBOL(irq_canonicalize);
  324. asmlinkage void m68k_handle_int(unsigned int irq)
  325. {
  326. struct irq_node *node;
  327. kstat_cpu(0).irqs[irq]++;
  328. node = irq_list[irq];
  329. do {
  330. node->handler(irq, node->dev_id);
  331. node = node->next;
  332. } while (node);
  333. }
  334. asmlinkage void __m68k_handle_int(unsigned int irq, struct pt_regs *regs)
  335. {
  336. struct pt_regs *old_regs;
  337. old_regs = set_irq_regs(regs);
  338. m68k_handle_int(irq);
  339. set_irq_regs(old_regs);
  340. }
  341. asmlinkage void handle_badint(struct pt_regs *regs)
  342. {
  343. kstat_cpu(0).irqs[0]++;
  344. printk("unexpected interrupt from %u\n", regs->vector);
  345. }
  346. int show_interrupts(struct seq_file *p, void *v)
  347. {
  348. struct irq_chip *contr;
  349. struct irq_node *node;
  350. int i = *(loff_t *) v;
  351. /* autovector interrupts */
  352. if (irq_list[i]) {
  353. contr = irq_chip[i];
  354. node = irq_list[i];
  355. seq_printf(p, "%-8s %3u: %10u %s", contr->name, i, kstat_cpu(0).irqs[i], node->devname);
  356. while ((node = node->next))
  357. seq_printf(p, ", %s", node->devname);
  358. seq_puts(p, "\n");
  359. }
  360. return 0;
  361. }
  362. #ifdef CONFIG_PROC_FS
  363. void init_irq_proc(void)
  364. {
  365. /* Insert /proc/irq driver here */
  366. }
  367. #endif