ints.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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. #include <asm/cacheflush.h>
  41. #ifdef CONFIG_Q40
  42. #include <asm/q40ints.h>
  43. #endif
  44. extern u32 auto_irqhandler_fixup[];
  45. extern u32 user_irqhandler_fixup[];
  46. extern u16 user_irqvec_fixup[];
  47. /* table for system interrupt handlers */
  48. static struct irq_node *irq_list[NR_IRQS];
  49. static struct irq_controller *irq_controller[NR_IRQS];
  50. static int irq_depth[NR_IRQS];
  51. static int m68k_first_user_vec;
  52. static struct irq_controller auto_irq_controller = {
  53. .name = "auto",
  54. .lock = SPIN_LOCK_UNLOCKED,
  55. .startup = m68k_irq_startup,
  56. .shutdown = m68k_irq_shutdown,
  57. };
  58. static struct irq_controller user_irq_controller = {
  59. .name = "user",
  60. .lock = SPIN_LOCK_UNLOCKED,
  61. .startup = m68k_irq_startup,
  62. .shutdown = m68k_irq_shutdown,
  63. };
  64. #define NUM_IRQ_NODES 100
  65. static irq_node_t nodes[NUM_IRQ_NODES];
  66. /*
  67. * void init_IRQ(void)
  68. *
  69. * Parameters: None
  70. *
  71. * Returns: Nothing
  72. *
  73. * This function should be called during kernel startup to initialize
  74. * the IRQ handling routines.
  75. */
  76. void __init init_IRQ(void)
  77. {
  78. int i;
  79. /* assembly irq entry code relies on this... */
  80. if (HARDIRQ_MASK != 0x00ff0000) {
  81. extern void hardirq_mask_is_broken(void);
  82. hardirq_mask_is_broken();
  83. }
  84. for (i = IRQ_AUTO_1; i <= IRQ_AUTO_7; i++)
  85. irq_controller[i] = &auto_irq_controller;
  86. mach_init_IRQ();
  87. }
  88. /**
  89. * m68k_setup_auto_interrupt
  90. * @handler: called from auto vector interrupts
  91. *
  92. * setup the handler to be called from auto vector interrupts instead of the
  93. * standard m68k_handle_int(), it will be called with irq numbers in the range
  94. * from IRQ_AUTO_1 - IRQ_AUTO_7.
  95. */
  96. void __init m68k_setup_auto_interrupt(void (*handler)(unsigned int, struct pt_regs *))
  97. {
  98. if (handler)
  99. *auto_irqhandler_fixup = (u32)handler;
  100. flush_icache();
  101. }
  102. /**
  103. * m68k_setup_user_interrupt
  104. * @vec: first user vector interrupt to handle
  105. * @cnt: number of active user vector interrupts
  106. * @handler: called from user vector interrupts
  107. *
  108. * setup user vector interrupts, this includes activating the specified range
  109. * of interrupts, only then these interrupts can be requested (note: this is
  110. * different from auto vector interrupts). An optional handler can be installed
  111. * to be called instead of the default m68k_handle_int(), it will be called
  112. * with irq numbers starting from IRQ_USER.
  113. */
  114. void __init m68k_setup_user_interrupt(unsigned int vec, unsigned int cnt,
  115. void (*handler)(unsigned int, struct pt_regs *))
  116. {
  117. int i;
  118. m68k_first_user_vec = vec;
  119. for (i = 0; i < cnt; i++)
  120. irq_controller[IRQ_USER + i] = &user_irq_controller;
  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_controller
  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_controller(struct irq_controller *contr, unsigned int irq,
  137. unsigned int cnt)
  138. {
  139. int i;
  140. for (i = 0; i < cnt; i++)
  141. irq_controller[irq + i] = contr;
  142. }
  143. irq_node_t *new_irq_node(void)
  144. {
  145. irq_node_t *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_controller *contr;
  159. struct irq_node **prev;
  160. unsigned long flags;
  161. if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
  162. printk("%s: Incorrect IRQ %d from %s\n",
  163. __FUNCTION__, irq, node->devname);
  164. return -ENXIO;
  165. }
  166. spin_lock_irqsave(&contr->lock, flags);
  167. prev = irq_list + irq;
  168. if (*prev) {
  169. /* Can't share interrupts unless both agree to */
  170. if (!((*prev)->flags & node->flags & SA_SHIRQ)) {
  171. spin_unlock_irqrestore(&contr->lock, flags);
  172. return -EBUSY;
  173. }
  174. while (*prev)
  175. prev = &(*prev)->next;
  176. }
  177. if (!irq_list[irq]) {
  178. if (contr->startup)
  179. contr->startup(irq);
  180. else
  181. contr->enable(irq);
  182. }
  183. node->next = NULL;
  184. *prev = node;
  185. spin_unlock_irqrestore(&contr->lock, flags);
  186. return 0;
  187. }
  188. int request_irq(unsigned int irq,
  189. irqreturn_t (*handler) (int, void *, struct pt_regs *),
  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_controller *contr;
  210. struct irq_node **p, *node;
  211. unsigned long flags;
  212. if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
  213. printk("%s: Incorrect IRQ %d\n", __FUNCTION__, irq);
  214. return;
  215. }
  216. spin_lock_irqsave(&contr->lock, 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. __FUNCTION__, irq);
  229. if (!irq_list[irq]) {
  230. if (contr->shutdown)
  231. contr->shutdown(irq);
  232. else
  233. contr->disable(irq);
  234. }
  235. spin_unlock_irqrestore(&contr->lock, flags);
  236. }
  237. EXPORT_SYMBOL(free_irq);
  238. void enable_irq(unsigned int irq)
  239. {
  240. struct irq_controller *contr;
  241. unsigned long flags;
  242. if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
  243. printk("%s: Incorrect IRQ %d\n",
  244. __FUNCTION__, irq);
  245. return;
  246. }
  247. spin_lock_irqsave(&contr->lock, flags);
  248. if (irq_depth[irq]) {
  249. if (!--irq_depth[irq]) {
  250. if (contr->enable)
  251. contr->enable(irq);
  252. }
  253. } else
  254. WARN_ON(1);
  255. spin_unlock_irqrestore(&contr->lock, flags);
  256. }
  257. EXPORT_SYMBOL(enable_irq);
  258. void disable_irq(unsigned int irq)
  259. {
  260. struct irq_controller *contr;
  261. unsigned long flags;
  262. if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
  263. printk("%s: Incorrect IRQ %d\n",
  264. __FUNCTION__, irq);
  265. return;
  266. }
  267. spin_lock_irqsave(&contr->lock, flags);
  268. if (!irq_depth[irq]++) {
  269. if (contr->disable)
  270. contr->disable(irq);
  271. }
  272. spin_unlock_irqrestore(&contr->lock, flags);
  273. }
  274. EXPORT_SYMBOL(disable_irq);
  275. int m68k_irq_startup(unsigned int irq)
  276. {
  277. if (irq <= IRQ_AUTO_7)
  278. vectors[VEC_SPUR + irq] = auto_inthandler;
  279. else
  280. vectors[m68k_first_user_vec + irq - IRQ_USER] = user_inthandler;
  281. return 0;
  282. }
  283. void m68k_irq_shutdown(unsigned int irq)
  284. {
  285. if (irq <= IRQ_AUTO_7)
  286. vectors[VEC_SPUR + irq] = bad_inthandler;
  287. else
  288. vectors[m68k_first_user_vec + irq - IRQ_USER] = bad_inthandler;
  289. }
  290. /*
  291. * Do we need these probe functions on the m68k?
  292. *
  293. * ... may be useful with ISA devices
  294. */
  295. unsigned long probe_irq_on (void)
  296. {
  297. #ifdef CONFIG_Q40
  298. if (MACH_IS_Q40)
  299. return q40_probe_irq_on();
  300. #endif
  301. return 0;
  302. }
  303. EXPORT_SYMBOL(probe_irq_on);
  304. int probe_irq_off (unsigned long irqs)
  305. {
  306. #ifdef CONFIG_Q40
  307. if (MACH_IS_Q40)
  308. return q40_probe_irq_off(irqs);
  309. #endif
  310. return 0;
  311. }
  312. EXPORT_SYMBOL(probe_irq_off);
  313. unsigned int irq_canonicalize(unsigned int irq)
  314. {
  315. #ifdef CONFIG_Q40
  316. if (MACH_IS_Q40 && irq == 11)
  317. irq = 10;
  318. #endif
  319. return irq;
  320. }
  321. EXPORT_SYMBOL(irq_canonicalize);
  322. asmlinkage void m68k_handle_int(unsigned int irq, struct pt_regs *regs)
  323. {
  324. struct irq_node *node;
  325. kstat_cpu(0).irqs[irq]++;
  326. node = irq_list[irq];
  327. do {
  328. node->handler(irq, node->dev_id, regs);
  329. node = node->next;
  330. } while (node);
  331. }
  332. asmlinkage void handle_badint(struct pt_regs *regs)
  333. {
  334. kstat_cpu(0).irqs[0]++;
  335. printk("unexpected interrupt from %u\n", regs->vector);
  336. }
  337. int show_interrupts(struct seq_file *p, void *v)
  338. {
  339. struct irq_controller *contr;
  340. struct irq_node *node;
  341. int i = *(loff_t *) v;
  342. /* autovector interrupts */
  343. if (irq_list[i]) {
  344. contr = irq_controller[i];
  345. node = irq_list[i];
  346. seq_printf(p, "%-8s %3u: %10u %s", contr->name, i, kstat_cpu(0).irqs[i], node->devname);
  347. while ((node = node->next))
  348. seq_printf(p, ", %s", node->devname);
  349. seq_puts(p, "\n");
  350. }
  351. return 0;
  352. }
  353. void init_irq_proc(void)
  354. {
  355. /* Insert /proc/irq driver here */
  356. }