ints.c 10 KB

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