ints.c 10 KB

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